(t *testing.T)
| 366 | } |
| 367 | |
| 368 | func TestInboxNotifications_List(t *testing.T) { |
| 369 | t.Parallel() |
| 370 | |
| 371 | // I skip these tests specifically on windows as for now they are flaky - only on Windows. |
| 372 | // For now the idea is that the runner takes too long to insert the entries, could be worth |
| 373 | // investigating a manual Tx. |
| 374 | // see: https://github.com/coder/internal/issues/503 |
| 375 | if runtime.GOOS == "windows" { |
| 376 | t.Skip("our runners are randomly taking too long to insert entries") |
| 377 | } |
| 378 | |
| 379 | t.Run("Failure Modes", func(t *testing.T) { |
| 380 | tests := []struct { |
| 381 | name string |
| 382 | expectedError string |
| 383 | listTemplate string |
| 384 | listTarget string |
| 385 | listReadStatus string |
| 386 | listStartingBefore string |
| 387 | }{ |
| 388 | {"nok - wrong targets", `Query param "targets" has invalid values`, "", "wrong_target", "", ""}, |
| 389 | {"nok - wrong templates", `Query param "templates" has invalid values`, "wrong_template", "", "", ""}, |
| 390 | {"nok - wrong read status", "starting_before query parameter should be any of 'all', 'read', 'unread'", "", "", "erroneous", ""}, |
| 391 | {"nok - wrong starting before", `Query param "starting_before" must be a valid uuid`, "", "", "", "xxx-xxx-xxx"}, |
| 392 | } |
| 393 | |
| 394 | for _, tt := range tests { |
| 395 | t.Run(tt.name, func(t *testing.T) { |
| 396 | t.Parallel() |
| 397 | |
| 398 | client, _, api := coderdtest.NewWithAPI(t, &coderdtest.Options{}) |
| 399 | firstUser := coderdtest.CreateFirstUser(t, client) |
| 400 | client, member := coderdtest.CreateAnotherUser(t, client, firstUser.OrganizationID) |
| 401 | |
| 402 | ctx, cancel := context.WithTimeout(context.Background(), testutil.WaitLong) |
| 403 | defer cancel() |
| 404 | |
| 405 | notifs, err := client.ListInboxNotifications(ctx, codersdk.ListInboxNotificationsRequest{}) |
| 406 | require.NoError(t, err) |
| 407 | require.NotNil(t, notifs) |
| 408 | require.Equal(t, 0, notifs.UnreadCount) |
| 409 | require.Empty(t, notifs.Notifications) |
| 410 | |
| 411 | // create a new notifications to fill the database with data |
| 412 | for i := range 20 { |
| 413 | dbgen.NotificationInbox(t, api.Database, database.InsertInboxNotificationParams{ |
| 414 | ID: uuid.New(), |
| 415 | UserID: member.ID, |
| 416 | TemplateID: notifications.TemplateWorkspaceOutOfMemory, |
| 417 | Title: fmt.Sprintf("Notification %d", i), |
| 418 | Actions: json.RawMessage("[]"), |
| 419 | Content: fmt.Sprintf("Content of the notif %d", i), |
| 420 | CreatedAt: dbtime.Now(), |
| 421 | }) |
| 422 | } |
| 423 | |
| 424 | notifs, err = client.ListInboxNotifications(ctx, codersdk.ListInboxNotificationsRequest{ |
| 425 | Templates: tt.listTemplate, |
nothing calls this directly
no test coverage detected