@@ -24,13 +24,15 @@ import (
2424
2525 "github.com/coder/serpent"
2626
27+ "github.com/coder/coder/v2/coderd/coderdtest"
2728 "github.com/coder/coder/v2/coderd/database"
2829 "github.com/coder/coder/v2/coderd/database/dbgen"
2930 "github.com/coder/coder/v2/coderd/database/dbtestutil"
3031 "github.com/coder/coder/v2/coderd/notifications"
3132 "github.com/coder/coder/v2/coderd/notifications/dispatch"
3233 "github.com/coder/coder/v2/coderd/notifications/render"
3334 "github.com/coder/coder/v2/coderd/notifications/types"
35+ "github.com/coder/coder/v2/coderd/rbac"
3436 "github.com/coder/coder/v2/coderd/util/syncmap"
3537 "github.com/coder/coder/v2/codersdk"
3638 "github.com/coder/coder/v2/testutil"
@@ -893,6 +895,43 @@ func TestCustomNotificationMethod(t *testing.T) {
893895 }, testutil .WaitLong , testutil .IntervalFast )
894896}
895897
898+ func TestNotificationsTemplates (t * testing.T ) {
899+ t .Parallel ()
900+
901+ // SETUP
902+ if ! dbtestutil .WillUsePostgres () {
903+ // Notification system templates are only served from the database and not dbmem at this time.
904+ t .Skip ("This test requires postgres; it relies on business-logic only implemented in the database" )
905+ }
906+
907+ ctx := testutil .Context (t , testutil .WaitLong )
908+ api := coderdtest .New (t , createOpts (t ))
909+
910+ // GIVEN: the first user (owner) and a regular member
911+ firstUser := coderdtest .CreateFirstUser (t , api )
912+ memberClient , _ := coderdtest .CreateAnotherUser (t , api , firstUser .OrganizationID , rbac .RoleMember ())
913+
914+ // WHEN: requesting system notification templates as owner should work
915+ templates , err := api .GetSystemNotificationTemplates (ctx )
916+ require .NoError (t , err )
917+ require .True (t , len (templates ) > 1 )
918+
919+ // WHEN: requesting system notification templates as member should work
920+ templates , err = memberClient .GetSystemNotificationTemplates (ctx )
921+ require .NoError (t , err )
922+ require .True (t , len (templates ) > 1 )
923+ }
924+
925+ func createOpts (t * testing.T ) * coderdtest.Options {
926+ t .Helper ()
927+
928+ dt := coderdtest .DeploymentValues (t )
929+ dt .Experiments = []string {string (codersdk .ExperimentNotifications )}
930+ return & coderdtest.Options {
931+ DeploymentValues : dt ,
932+ }
933+ }
934+
896935type fakeHandler struct {
897936 mu sync.RWMutex
898937 succeeded , failed []string
0 commit comments