MCPcopy Index your code
hub / github.com/coder/coder / TestUpdateNotificationsSettings

Function TestUpdateNotificationsSettings

coderd/notifications_test.go:29–110  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

27}
28
29func TestUpdateNotificationsSettings(t *testing.T) {
30 t.Parallel()
31
32 t.Run("Permissions denied", func(t *testing.T) {
33 t.Parallel()
34
35 api := coderdtest.New(t, createOpts(t))
36 firstUser := coderdtest.CreateFirstUser(t, api)
37 anotherClient, _ := coderdtest.CreateAnotherUser(t, api, firstUser.OrganizationID)
38
39 // given
40 expected := codersdk.NotificationsSettings{
41 NotifierPaused: true,
42 }
43
44 ctx := testutil.Context(t, testutil.WaitShort)
45
46 // when
47 err := anotherClient.PutNotificationsSettings(ctx, expected)
48
49 // then
50 var sdkError *codersdk.Error
51 require.Error(t, err)
52 require.ErrorAsf(t, err, &sdkError, "error should be of type *codersdk.Error")
53 require.Equal(t, http.StatusForbidden, sdkError.StatusCode())
54 })
55
56 t.Run("Settings modified", func(t *testing.T) {
57 t.Parallel()
58
59 client := coderdtest.New(t, createOpts(t))
60 _ = coderdtest.CreateFirstUser(t, client)
61
62 // given
63 expected := codersdk.NotificationsSettings{
64 NotifierPaused: true,
65 }
66
67 ctx := testutil.Context(t, testutil.WaitShort)
68
69 // when
70 err := client.PutNotificationsSettings(ctx, expected)
71 require.NoError(t, err)
72
73 // then
74 actual, err := client.GetNotificationsSettings(ctx)
75 require.NoError(t, err)
76 require.Equal(t, expected, actual)
77 })
78
79 t.Run("Settings not modified", func(t *testing.T) {
80 t.Parallel()
81
82 // Empty state: notifications Settings are undefined now (default).
83 client := coderdtest.New(t, createOpts(t))
84 _ = coderdtest.CreateFirstUser(t, client)
85 ctx := testutil.Context(t, testutil.WaitShort)
86

Callers

nothing calls this directly

Calls 11

StatusCodeMethod · 0.95
NewFunction · 0.92
CreateFirstUserFunction · 0.92
CreateAnotherUserFunction · 0.92
ContextFunction · 0.92
createOptsFunction · 0.70
RunMethod · 0.65
ErrorMethod · 0.45
EqualMethod · 0.45

Tested by

no test coverage detected