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

Function TestInboxNotifications_MarkAllAsRead

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

Source from the content-addressed store, hash-verified

856}
857
858func 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,

Callers

nothing calls this directly

Calls 13

NewWithAPIFunction · 0.92
CreateFirstUserFunction · 0.92
CreateAnotherUserFunction · 0.92
NotificationInboxFunction · 0.92
NowFunction · 0.92
SkipMethod · 0.80
RunMethod · 0.65
NewMethod · 0.65
EqualMethod · 0.45
EmptyMethod · 0.45

Tested by

no test coverage detected