chore: enable coder inbox by default (#17077)

Add a flag to enable Coder Inbox by default, as well as supporting disabling the feature.
This commit is contained in:
Danielle Maywood
2025-03-25 12:51:26 +00:00
committed by GitHub
parent 5f3a53f01b
commit cd19e79d9b
15 changed files with 260 additions and 42 deletions

View File

@ -1856,6 +1856,90 @@ func TestNotificationDuplicates(t *testing.T) {
require.NoError(t, err)
}
func TestNotificationTargetMatrix(t *testing.T) {
t.Parallel()
tests := []struct {
name string
defaultMethod database.NotificationMethod
defaultEnabled bool
inboxEnabled bool
expectedEnqueued int
}{
{
name: "NoDefaultAndNoInbox",
defaultMethod: database.NotificationMethodSmtp,
defaultEnabled: false,
inboxEnabled: false,
expectedEnqueued: 0,
},
{
name: "DefaultAndNoInbox",
defaultMethod: database.NotificationMethodSmtp,
defaultEnabled: true,
inboxEnabled: false,
expectedEnqueued: 1,
},
{
name: "NoDefaultAndInbox",
defaultMethod: database.NotificationMethodSmtp,
defaultEnabled: false,
inboxEnabled: true,
expectedEnqueued: 1,
},
{
name: "DefaultAndInbox",
defaultMethod: database.NotificationMethodSmtp,
defaultEnabled: true,
inboxEnabled: true,
expectedEnqueued: 2,
},
}
for _, tt := range tests {
tt := tt
t.Run(tt.name, func(t *testing.T) {
t.Parallel()
// nolint:gocritic // Unit test.
ctx := dbauthz.AsNotifier(testutil.Context(t, testutil.WaitSuperLong))
store, pubsub := dbtestutil.NewDB(t)
logger := testutil.Logger(t)
cfg := defaultNotificationsConfig(tt.defaultMethod)
cfg.Inbox.Enabled = serpent.Bool(tt.inboxEnabled)
// If the default method is not enabled, we want to ensure the config
// is wiped out.
if !tt.defaultEnabled {
cfg.SMTP = codersdk.NotificationsEmailConfig{}
cfg.Webhook = codersdk.NotificationsWebhookConfig{}
}
mgr, err := notifications.NewManager(cfg, store, pubsub, defaultHelpers(), createMetrics(), logger.Named("manager"))
require.NoError(t, err)
t.Cleanup(func() {
assert.NoError(t, mgr.Stop(ctx))
})
// Set the time to a known value.
mClock := quartz.NewMock(t)
mClock.Set(time.Date(2024, 1, 15, 9, 0, 0, 0, time.UTC))
enq, err := notifications.NewStoreEnqueuer(cfg, store, defaultHelpers(), logger.Named("enqueuer"), mClock)
require.NoError(t, err)
user := createSampleUser(t, store)
// When: A notification is enqueued, it enqueues the correct amount of notifications.
enqueued, err := enq.Enqueue(ctx, user.ID, notifications.TemplateWorkspaceDeleted,
map[string]string{"initiator": "danny"}, "test", user.ID)
require.NoError(t, err)
require.Len(t, enqueued, tt.expectedEnqueued)
})
}
}
type fakeHandler struct {
mu sync.RWMutex
succeeded, failed []string