Skip to content

chore: enable coder inbox by default #17077

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 8 commits into from
Mar 25, 2025
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
chore: add testing
  • Loading branch information
DanielleMaywood committed Mar 24, 2025
commit e04d0db23a2f9f8f3719bce009cd6b7db0f7fb8b
83 changes: 83 additions & 0 deletions coderd/notifications/notifications_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1854,6 +1854,89 @@
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()

ctx := dbauthz.AsNotifier(testutil.Context(t, testutil.WaitSuperLong))

Check failure on line 1903 in coderd/notifications/notifications_test.go

View workflow job for this annotation

GitHub Actions / lint

ruleguard: Using 'AsNotifier' is dangerous and should be accompanied by a comment explaining why it's ok and a nolint. (gocritic)
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
Expand Down
Loading