Skip to content
quarry Artifact [f854d8749a]
Login

Artifact [f854d8749a]

Artifact f854d8749ab5d3b8dad126a255e4936cf66fd2644e6765adbdc26933b156dff4:


package oltp

import "testing"

// What a person hears from a channel: no row is mentions, a choice is
// one row, and it goes with the account and with the repository.
func TestChatNotifyIsAChoicePerPersonAndChannel(t *testing.T) {
	d := testDB(t)
	if err := d.AddRepo("saur0n", t.TempDir(), "", Public); err != nil {
		t.Fatal(err)
	}
	if got := d.ChatNotify("saur0n", "dan"); got != ChatMentions {
		t.Fatalf("FAIL: an untouched choice reads %q, want mentions", got)
	}
	for _, c := range []struct{ who, mode string }{{"dan", ChatEvery}, {"eve", ChatEvery}, {"fay", ChatOff}} {
		if err := d.SetChatNotify("saur0n", c.who, c.mode); err != nil {
			t.Fatal(err)
		}
	}
	if err := d.SetChatNotify("saur0n", "dan", "loud"); err == nil {
		t.Fatal("FAIL: an unknown choice was stored")
	}
	if got, _ := d.ChatNotifyEvery("saur0n"); len(got) != 2 || got[0] != "dan" || got[1] != "eve" {
		t.Fatalf("FAIL: followers = %v, want dan, eve", got)
	}
	if err := d.SetChatNotify("saur0n", "eve", ChatMentions); err != nil {
		t.Fatal(err)
	}
	if got := d.ChatNotify("saur0n", "eve"); got != ChatMentions {
		t.Fatalf("FAIL: back to mentions reads %q", got)
	}
	t.Log("ok: a choice is stored, read back and undone")

	if err := d.AddAccount("dan", "a-long-enough-password", false); err != nil {
		t.Fatal(err)
	}
	if err := d.DeleteAccount("dan"); err != nil {
		t.Fatal(err)
	}
	if got, _ := d.ChatNotifyEvery("saur0n"); len(got) != 0 {
		t.Fatalf("FAIL: a deleted account still follows: %v", got)
	}
	if err := d.PurgeRepo("saur0n"); err != nil {
		t.Fatal(err)
	}
	if got := d.ChatNotify("saur0n", "fay"); got != ChatMentions {
		t.Fatalf("FAIL: a purged repository still holds fay's choice %q", got)
	}
	t.Log("ok: a choice goes with its account and its repository")
}