(t *testing.T)
| 856 | } |
| 857 | |
| 858 | func TestInboxNotifications_MarkAllAsRead(t *testing.T) { |
| 859 | t.Parallel() |
| 860 | |
| 861 | // I skip these tests specifically on windows as for now they are flaky - only on Windows. |
| 862 | // For now the idea is that the runner takes too long to insert the entries, could be worth |
| 863 | // investigating a manual Tx. |
| 864 | // see: https://github.com/coder/internal/issues/503 |
| 865 | if runtime.GOOS == "windows" { |
| 866 | t.Skip("our runners are randomly taking too long to insert entries") |
| 867 | } |
| 868 | |
| 869 | t.Run("ok", func(t *testing.T) { |
| 870 | t.Parallel() |
| 871 | client, _, api := coderdtest.NewWithAPI(t, &coderdtest.Options{}) |
| 872 | firstUser := coderdtest.CreateFirstUser(t, client) |
| 873 | client, member := coderdtest.CreateAnotherUser(t, client, firstUser.OrganizationID) |
| 874 | |
| 875 | ctx, cancel := context.WithTimeout(context.Background(), testutil.WaitLong) |
| 876 | defer cancel() |
| 877 | |
| 878 | notifs, err := client.ListInboxNotifications(ctx, codersdk.ListInboxNotificationsRequest{}) |
| 879 | require.NoError(t, err) |
| 880 | require.NotNil(t, notifs) |
| 881 | require.Equal(t, 0, notifs.UnreadCount) |
| 882 | require.Empty(t, notifs.Notifications) |
| 883 | |
| 884 | for i := range 20 { |
| 885 | dbgen.NotificationInbox(t, api.Database, database.InsertInboxNotificationParams{ |
| 886 | ID: uuid.New(), |
| 887 | UserID: member.ID, |
| 888 | TemplateID: notifications.TemplateWorkspaceOutOfMemory, |
| 889 | Title: fmt.Sprintf("Notification %d", i), |
| 890 | Actions: json.RawMessage("[]"), |
| 891 | Content: fmt.Sprintf("Content of the notif %d", i), |
| 892 | CreatedAt: dbtime.Now(), |
| 893 | }) |
| 894 | } |
| 895 | |
| 896 | notifs, err = client.ListInboxNotifications(ctx, codersdk.ListInboxNotificationsRequest{}) |
| 897 | require.NoError(t, err) |
| 898 | require.NotNil(t, notifs) |
| 899 | require.Equal(t, 20, notifs.UnreadCount) |
| 900 | require.Len(t, notifs.Notifications, 20) |
| 901 | |
| 902 | err = client.MarkAllInboxNotificationsAsRead(ctx) |
| 903 | require.NoError(t, err) |
| 904 | |
| 905 | notifs, err = client.ListInboxNotifications(ctx, codersdk.ListInboxNotificationsRequest{}) |
| 906 | require.NoError(t, err) |
| 907 | require.NotNil(t, notifs) |
| 908 | require.Equal(t, 0, notifs.UnreadCount) |
| 909 | require.Len(t, notifs.Notifications, 20) |
| 910 | |
| 911 | for i := range 10 { |
| 912 | dbgen.NotificationInbox(t, api.Database, database.InsertInboxNotificationParams{ |
| 913 | ID: uuid.New(), |
| 914 | UserID: member.ID, |
| 915 | TemplateID: notifications.TemplateWorkspaceOutOfMemory, |
nothing calls this directly
no test coverage detected