package notifications import ( "context" "testing" "github.com/stretchr/testify/require" ) func TestEffective_PhoneAndEmailRideOnInbox(t *testing.T) { cases := []struct { in, want Channels }{ {Channels{true, true, true}, Channels{true, true, true}}, {Channels{true, false, true}, Channels{true, false, true}}, {Channels{false, true, true}, Channels{false, false, false}}, {Channels{false, false, false}, Channels{false, false, false}}, } for _, c := range cases { require.Equal(t, c.want, c.in.Effective(), "in=%+v", c.in) } } // The display order and the spec table must name the same kinds, or a kind // is either unreachable from settings or has no behaviour. func TestKinds_OrderAndSpecsAgree(t *testing.T) { require.Len(t, order, len(specs)) seen := map[Kind]bool{} for _, k := range Kinds() { require.True(t, k.Valid(), "%s in order but not in specs", k) require.False(t, seen[k], "%s listed twice", k) seen[k] = true } } func TestKinds_HealthKindsStayOutOfEmailAndCoalesce(t *testing.T) { // The burst-prone health kinds stay out of email unless an admin opts in. for _, k := range []Kind{KindScanFailed, KindTracksMissing, KindDuplicatesFound, KindDuplicatesResolved, KindPlaybackErrors} { require.True(t, k.AdminOnly(), k) require.False(t, k.Defaults().Email, k) require.NotEmpty(t, k.coalesceKey(), "%s should coalesce", k) } } // New music reaches everyone, goes out in the daily summary, and never buzzes // a phone unless the user asks. Each scan's notice is its own row, so a // notice that was already emailed never silently absorbs later arrivals. func TestKinds_NewMusicIsForEveryoneAndDailyByEmail(t *testing.T) { require.False(t, KindNewMusic.AdminOnly()) require.Equal(t, EmailSummary, KindNewMusic.EmailGroup()) require.Equal(t, Channels{Inbox: true, Email: true}, KindNewMusic.Defaults()) require.Empty(t, KindNewMusic.coalesceKey()) require.Equal(t, EmailBatch, KindQuarantineFlagged.EmailGroup()) } func TestNotify_NilNotifierIsANoOp(t *testing.T) { var n *Notifier require.NoError(t, n.Notify(context.Background(), KindNewMusic, Recipients{}, nil)) } func TestNotify_UnknownKindIsRefusedBeforeTouchingTheDB(t *testing.T) { n := New(nil, nil, nil) require.Error(t, n.Notify(context.Background(), Kind("bogus"), Recipients{}, nil)) }