Skip to content

feat: add notification deduplication trigger #14172

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 3 commits into from
Aug 21, 2024
Merged
Show file tree
Hide file tree
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
Merge branch 'main' of https://github.com/coder/coder into dk/notif-d…
…edupe
  • Loading branch information
dannykopping committed Aug 21, 2024
commit e9b2f3bef6340b5c75c4aa658cec44c1b35b33bf
4 changes: 1 addition & 3 deletions cli/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,6 @@ import (
"github.com/coder/serpent"
"github.com/coder/wgtunnel/tunnelsdk"

"github.com/coder/quartz"

"github.com/coder/coder/v2/buildinfo"
"github.com/coder/coder/v2/cli/clilog"
"github.com/coder/coder/v2/cli/cliui"
Expand Down Expand Up @@ -1007,7 +1005,7 @@ func (r *RootCmd) Server(newAPI func(context.Context, *coderd.Options) (*coderd.
helpers := templateHelpers(options)

// The enqueuer is responsible for enqueueing notifications to the given store.
enqueuer, err := notifications.NewStoreEnqueuer(cfg, options.Database, templateHelpers(options), logger.Named("notifications.enqueuer"), quartz.NewReal())
enqueuer, err := notifications.NewStoreEnqueuer(cfg, options.Database, helpers, logger.Named("notifications.enqueuer"), quartz.NewReal())
if err != nil {
return xerrors.Errorf("failed to instantiate notification store enqueuer: %w", err)
}
Expand Down
37 changes: 37 additions & 0 deletions coderd/notifications/notifications_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -999,6 +999,43 @@ func TestCustomNotificationMethod(t *testing.T) {
}, testutil.WaitLong, testutil.IntervalFast)
}

func TestNotificationsTemplates(t *testing.T) {
t.Parallel()

// SETUP
if !dbtestutil.WillUsePostgres() {
// Notification system templates are only served from the database and not dbmem at this time.
t.Skip("This test requires postgres; it relies on business-logic only implemented in the database")
}

ctx := testutil.Context(t, testutil.WaitLong)
api := coderdtest.New(t, createOpts(t))

// GIVEN: the first user (owner) and a regular member
firstUser := coderdtest.CreateFirstUser(t, api)
memberClient, _ := coderdtest.CreateAnotherUser(t, api, firstUser.OrganizationID, rbac.RoleMember())

// WHEN: requesting system notification templates as owner should work
templates, err := api.GetSystemNotificationTemplates(ctx)
require.NoError(t, err)
require.True(t, len(templates) > 1)

// WHEN: requesting system notification templates as member should work
templates, err = memberClient.GetSystemNotificationTemplates(ctx)
require.NoError(t, err)
require.True(t, len(templates) > 1)
}

func createOpts(t *testing.T) *coderdtest.Options {
t.Helper()

dt := coderdtest.DeploymentValues(t)
dt.Experiments = []string{string(codersdk.ExperimentNotifications)}
return &coderdtest.Options{
DeploymentValues: dt,
}
}

// TestNotificationDuplicates validates that identical notifications cannot be sent on the same day.
func TestNotificationDuplicates(t *testing.T) {
t.Parallel()
Expand Down
You are viewing a condensed version of this merge commit. You can view the full changes here.