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

Function TestInboxNotifications_ReadStatus

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

Source from the content-addressed store, hash-verified

713}
714
715func 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)

Callers

nothing calls this directly

Calls 14

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