Skip to content
quarry Artifact [ee28cedc0d]
Login

Artifact [ee28cedc0d]

Artifact ee28cedc0ddfaeddeda366c862ba78d12a276aebb03d6a11ff199c04a524e77d:


package api

import (
	"context"
	"testing"
)

// Redeeming an invite tells every site admin with an address, and not
// the person who just joined, even when that person is an admin.
func TestAnInviteRedeemedTellsTheAdmins(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["quiet"] = Account{Name: "quiet", Admin: true}
	accts.accounts["eve"] = Account{Name: "eve", Email: "[email protected]"}
	accts.accounts["newbie"] = Account{Name: "newbie", Admin: true, Email: "[email protected]"}
	mail := &fakeMail{}
	d := Deps{Accounts: accts, Mail: mail}
	if n := d.InviteRedeemed(context.Background(), "newbie"); n != 2 {
		t.Errorf("FAIL: %d admins told, want 2: %+v", n, mail.sent)
	}
	if !mail.to("[email protected]") || !mail.to("[email protected]") {
		t.Errorf("FAIL: an admin was not told: %+v", mail.sent)
	}
	if mail.to("[email protected]") || mail.to("[email protected]") {
		t.Errorf("FAIL: a non-admin or the new account itself was mailed: %+v", mail.sent)
	}
	if n := (Deps{Accounts: accts}).InviteRedeemed(context.Background(), "newbie"); n != 0 {
		t.Error("FAIL: a forge with no mail provider reported mail sent")
	}
}