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_AdminKindsDefaultEmailOffExceptRequestQueue(t *testing.T) { // The burst-prone health kinds stay out of email unless an admin opts // in; the request queue and quarantine flags are things an admin acts on. for _, k := range []Kind{KindScanFailed, KindTracksMissing, KindDuplicatesFound, KindPlaybackErrors} { require.True(t, k.AdminOnly(), k) require.False(t, k.Defaults().Email, k) require.NotEmpty(t, k.coalesceKey(), "%s should coalesce", k) } for _, k := range []Kind{KindRequestApproved, KindRequestRejected, KindRequestCompleted} { require.False(t, k.AdminOnly(), k) require.Equal(t, Channels{true, true, true}, k.Defaults(), k) require.Empty(t, k.coalesceKey(), "%s must never coalesce: each request is its own news", k) } require.Equal(t, EmailSummary, KindRequestCompleted.EmailGroup()) require.Equal(t, EmailBatch, KindRequestApproved.EmailGroup()) } func TestNotify_NilNotifierIsANoOp(t *testing.T) { var n *Notifier require.NoError(t, n.Notify(context.Background(), KindRequestApproved, Recipients{}, nil)) } func TestNotify_UnknownKindIsRefusedBeforeTouchingTheDB(t *testing.T) { n := New(nil, nil, nil) require.Error(t, n.Notify(context.Background(), Kind("bogus"), Recipients{}, nil)) }