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)
}
}