Skip to content
quarry Artifact [c0fd7bcb89]
Login

Artifact [c0fd7bcb89]

Artifact c0fd7bcb895d912b36309d4d8689948e65de121575a5a25ffe5730f7fd6b7335:


package api

import (
	"context"
	"testing"
)

// Accepting an invite tells exactly the accounts --join-notify names,
// never the person who just joined, and nobody when it names nobody.
func TestAnInviteRedeemedTellsTheNamedAccounts(t *testing.T) {
	accts := newFakeAccounts()
	accts.accounts["dan"] = Account{Name: "dan", Admin: true, Email: "[email protected]"}
	accts.accounts["zg"] = Account{Name: "zg", Admin: true, Email: "[email protected]"}
	accts.accounts["newbie"] = Account{Name: "newbie", Email: "[email protected]"}
	mail := &fakeMail{}
	d := Deps{Accounts: accts, Mail: mail, JoinNotify: []string{"dan", "newbie"}}
	if n := d.InviteRedeemed(context.Background(), "newbie"); n != 1 || !mail.to("[email protected]") {
		t.Errorf("FAIL: want only dan told, got %d: %+v", n, mail.sent)
	}
	if mail.to("[email protected]") || mail.to("[email protected]") {
		t.Errorf("FAIL: an unnamed admin or the new account was mailed: %+v", mail.sent)
	}
	quiet := &fakeMail{}
	if n := (Deps{Accounts: accts, Mail: quiet}).InviteRedeemed(context.Background(), "newbie"); n != 0 || len(quiet.sent) != 0 {
		t.Errorf("FAIL: with nobody named, mail went: %+v", quiet.sent)
	}
}