@@ -24,13 +24,15 @@ import (
24
24
25
25
"github.com/coder/serpent"
26
26
27
+ "github.com/coder/coder/v2/coderd/coderdtest"
27
28
"github.com/coder/coder/v2/coderd/database"
28
29
"github.com/coder/coder/v2/coderd/database/dbgen"
29
30
"github.com/coder/coder/v2/coderd/database/dbtestutil"
30
31
"github.com/coder/coder/v2/coderd/notifications"
31
32
"github.com/coder/coder/v2/coderd/notifications/dispatch"
32
33
"github.com/coder/coder/v2/coderd/notifications/render"
33
34
"github.com/coder/coder/v2/coderd/notifications/types"
35
+ "github.com/coder/coder/v2/coderd/rbac"
34
36
"github.com/coder/coder/v2/coderd/util/syncmap"
35
37
"github.com/coder/coder/v2/codersdk"
36
38
"github.com/coder/coder/v2/testutil"
@@ -893,6 +895,43 @@ func TestCustomNotificationMethod(t *testing.T) {
893
895
}, testutil .WaitLong , testutil .IntervalFast )
894
896
}
895
897
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
+
896
935
type fakeHandler struct {
897
936
mu sync.RWMutex
898
937
succeeded , failed []string
0 commit comments