(t *testing.T)
| 713 | } |
| 714 | |
| 715 | func TestInboxNotifications_ReadStatus(t *testing.T) { |
| 716 | t.Parallel() |
| 717 | |
| 718 | // I skip these tests specifically on windows as for now they are flaky - only on Windows. |
| 719 | // For now the idea is that the runner takes too long to insert the entries, could be worth |
| 720 | // investigating a manual Tx. |
| 721 | // see: https://github.com/coder/internal/issues/503 |
| 722 | if runtime.GOOS == "windows" { |
| 723 | t.Skip("our runners are randomly taking too long to insert entries") |
| 724 | } |
| 725 | |
| 726 | t.Run("ok", func(t *testing.T) { |
| 727 | t.Parallel() |
| 728 | client, _, api := coderdtest.NewWithAPI(t, &coderdtest.Options{}) |
| 729 | firstUser := coderdtest.CreateFirstUser(t, client) |
| 730 | client, member := coderdtest.CreateAnotherUser(t, client, firstUser.OrganizationID) |
| 731 | |
| 732 | ctx, cancel := context.WithTimeout(context.Background(), testutil.WaitLong) |
| 733 | defer cancel() |
| 734 | |
| 735 | notifs, err := client.ListInboxNotifications(ctx, codersdk.ListInboxNotificationsRequest{}) |
| 736 | require.NoError(t, err) |
| 737 | require.NotNil(t, notifs) |
| 738 | require.Equal(t, 0, notifs.UnreadCount) |
| 739 | require.Empty(t, notifs.Notifications) |
| 740 | |
| 741 | for i := range 20 { |
| 742 | dbgen.NotificationInbox(t, api.Database, database.InsertInboxNotificationParams{ |
| 743 | ID: uuid.New(), |
| 744 | UserID: member.ID, |
| 745 | TemplateID: notifications.TemplateWorkspaceOutOfMemory, |
| 746 | Title: fmt.Sprintf("Notification %d", i), |
| 747 | Actions: json.RawMessage("[]"), |
| 748 | Content: fmt.Sprintf("Content of the notif %d", i), |
| 749 | CreatedAt: dbtime.Now(), |
| 750 | }) |
| 751 | } |
| 752 | |
| 753 | notifs, err = client.ListInboxNotifications(ctx, codersdk.ListInboxNotificationsRequest{}) |
| 754 | require.NoError(t, err) |
| 755 | require.NotNil(t, notifs) |
| 756 | require.Equal(t, 20, notifs.UnreadCount) |
| 757 | require.Len(t, notifs.Notifications, 20) |
| 758 | |
| 759 | updatedNotif, err := client.UpdateInboxNotificationReadStatus(ctx, notifs.Notifications[19].ID.String(), codersdk.UpdateInboxNotificationReadStatusRequest{ |
| 760 | IsRead: true, |
| 761 | }) |
| 762 | require.NoError(t, err) |
| 763 | require.NotNil(t, updatedNotif) |
| 764 | require.NotZero(t, updatedNotif.Notification.ReadAt) |
| 765 | require.Equal(t, 19, updatedNotif.UnreadCount) |
| 766 | |
| 767 | updatedNotif, err = client.UpdateInboxNotificationReadStatus(ctx, notifs.Notifications[19].ID.String(), codersdk.UpdateInboxNotificationReadStatusRequest{ |
| 768 | IsRead: false, |
| 769 | }) |
| 770 | require.NoError(t, err) |
| 771 | require.NotNil(t, updatedNotif) |
| 772 | require.Nil(t, updatedNotif.Notification.ReadAt) |
nothing calls this directly
no test coverage detected