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

Function TestInboxNotification_Watch

coderd/inboxnotifications_test.go:34–366  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

32var failingPaginationUUID = uuid.MustParse("fba6966a-9061-4111-8e1a-f6a9fbea4b16")
33
34func TestInboxNotification_Watch(t *testing.T) {
35 t.Parallel()
36
37 // I skip these tests specifically on windows as for now they are flaky - only on Windows.
38 // For now the idea is that the runner takes too long to insert the entries, could be worth
39 // investigating a manual Tx.
40 // see: https://github.com/coder/internal/issues/503
41 if runtime.GOOS == "windows" {
42 t.Skip("our runners are randomly taking too long to insert entries")
43 }
44
45 t.Run("Failure Modes", func(t *testing.T) {
46 tests := []struct {
47 name string
48 expectedError string
49 listTemplate string
50 listTarget string
51 listReadStatus string
52 listStartingBefore string
53 }{
54 {"nok - wrong targets", `Query param "targets" has invalid values`, "", "wrong_target", "", ""},
55 {"nok - wrong templates", `Query param "templates" has invalid values`, "wrong_template", "", "", ""},
56 {"nok - wrong read status", "starting_before query parameter should be any of 'all', 'read', 'unread'", "", "", "erroneous", ""},
57 }
58
59 for _, tt := range tests {
60 t.Run(tt.name, func(t *testing.T) {
61 t.Parallel()
62
63 client, _, _ := coderdtest.NewWithAPI(t, &coderdtest.Options{})
64 firstUser := coderdtest.CreateFirstUser(t, client)
65 client, _ = coderdtest.CreateAnotherUser(t, client, firstUser.OrganizationID)
66
67 ctx, cancel := context.WithTimeout(context.Background(), testutil.WaitLong)
68 defer cancel()
69
70 resp, err := client.Request(ctx, http.MethodGet, "/api/v2/notifications/inbox/watch", nil,
71 codersdk.ListInboxNotificationsRequestToQueryParams(codersdk.ListInboxNotificationsRequest{
72 Targets: tt.listTarget,
73 Templates: tt.listTemplate,
74 ReadStatus: tt.listReadStatus,
75 StartingBefore: tt.listStartingBefore,
76 })...)
77 require.NoError(t, err)
78 defer resp.Body.Close()
79
80 err = codersdk.ReadBodyAsError(resp)
81 require.ErrorContains(t, err, tt.expectedError)
82 })
83 }
84 })
85
86 t.Run("OK", func(t *testing.T) {
87 t.Parallel()
88
89 ctx := testutil.Context(t, testutil.WaitLong)
90 logger := testutil.Logger(t)
91

Callers

nothing calls this directly

Calls 15

DispatcherMethod · 0.95
NewWithAPIFunction · 0.92
CreateFirstUserFunction · 0.92
CreateAnotherUserFunction · 0.92
ReadBodyAsErrorFunction · 0.92
ContextFunction · 0.92
LoggerFunction · 0.92
NewDBFunction · 0.92
RoleTemplateAdminFunction · 0.92
NewInboxHandlerFunction · 0.92
SkipMethod · 0.80

Tested by

no test coverage detected