- Notifications
You must be signed in to change notification settings - Fork914
feat(coderd): add mark-all-as-read endpoint for inbox notifications#16976
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
Uh oh!
There was an error while loading.Please reload this page.
Changes fromall commits
8d3ca0a
e4e2967
dd8ee20
8aaace3
0d98bf6
27ad10b
452e92b
deff124
0815e96
a1567a0
7881887
9d871fc
File filter
Filter by extension
Conversations
Uh oh!
There was an error while loading.Please reload this page.
Jump to
Uh oh!
There was an error while loading.Please reload this page.
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more abouthow customized files appear on GitHub.
Uh oh!
There was an error while loading.Please reload this page.
Some generated files are not rendered by default. Learn more abouthow customized files appear on GitHub.
Uh oh!
There was an error while loading.Please reload this page.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1389,6 +1389,7 @@ func New(options *Options) *API { | ||
r.Use(apiKeyMiddleware) | ||
r.Route("/inbox", func(r chi.Router) { | ||
r.Get("/", api.listInboxNotifications) | ||
r.Put("/mark-all-as-read", api.markAllInboxNotificationsAsRead) | ||
defelmnq marked this conversation as resolved. Show resolvedHide resolvedUh oh!There was an error while loading.Please reload this page. | ||
r.Get("/watch", api.watchInboxNotifications) | ||
r.Put("/{id}/read-status", api.updateInboxNotificationReadStatus) | ||
}) | ||
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -9498,6 +9498,21 @@ func (q *FakeQuerier) ListWorkspaceAgentPortShares(_ context.Context, workspaceI | ||
return shares, nil | ||
} | ||
func (q *FakeQuerier) MarkAllInboxNotificationsAsRead(_ context.Context, arg database.MarkAllInboxNotificationsAsReadParams) error { | ||
defelmnq marked this conversation as resolved. Show resolvedHide resolvedUh oh!There was an error while loading.Please reload this page. | ||
err := validateDatabaseType(arg) | ||
if err != nil { | ||
return err | ||
} | ||
for idx, notif := range q.inboxNotifications { | ||
if notif.UserID == arg.UserID && !notif.ReadAt.Valid { | ||
q.inboxNotifications[idx].ReadAt = arg.ReadAt | ||
} | ||
} | ||
return nil | ||
} | ||
// nolint:forcetypeassert | ||
func (q *FakeQuerier) OIDCClaimFieldValues(_ context.Context, args database.OIDCClaimFieldValuesParams) ([]string, error) { | ||
orgMembers := q.getOrganizationMemberNoLock(args.OrganizationID) | ||
Some generated files are not rendered by default. Learn more abouthow customized files appear on GitHub.
Uh oh!
There was an error while loading.Please reload this page.
Some generated files are not rendered by default. Learn more abouthow customized files appear on GitHub.
Uh oh!
There was an error while loading.Please reload this page.
Some generated files are not rendered by default. Learn more abouthow customized files appear on GitHub.
Uh oh!
There was an error while loading.Please reload this page.
Some generated files are not rendered by default. Learn more abouthow customized files appear on GitHub.
Uh oh!
There was an error while loading.Please reload this page.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -37,6 +37,7 @@ func TestInboxNotification_Watch(t *testing.T) { | ||
// I skip these tests specifically on windows as for now they are flaky - only on Windows. | ||
// For now the idea is that the runner takes too long to insert the entries, could be worth | ||
// investigating a manual Tx. | ||
// see: https://github.com/coder/internal/issues/503 | ||
if runtime.GOOS == "windows" { | ||
t.Skip("our runners are randomly taking too long to insert entries") | ||
} | ||
@@ -305,6 +306,7 @@ func TestInboxNotifications_List(t *testing.T) { | ||
// I skip these tests specifically on windows as for now they are flaky - only on Windows. | ||
// For now the idea is that the runner takes too long to insert the entries, could be worth | ||
// investigating a manual Tx. | ||
// see: https://github.com/coder/internal/issues/503 | ||
if runtime.GOOS == "windows" { | ||
t.Skip("our runners are randomly taking too long to insert entries") | ||
} | ||
@@ -588,6 +590,7 @@ func TestInboxNotifications_ReadStatus(t *testing.T) { | ||
// I skip these tests specifically on windows as for now they are flaky - only on Windows. | ||
// For now the idea is that the runner takes too long to insert the entries, could be worth | ||
// investigating a manual Tx. | ||
// see: https://github.com/coder/internal/issues/503 | ||
if runtime.GOOS == "windows" { | ||
t.Skip("our runners are randomly taking too long to insert entries") | ||
} | ||
@@ -723,3 +726,76 @@ func TestInboxNotifications_ReadStatus(t *testing.T) { | ||
require.Empty(t, updatedNotif.Notification) | ||
}) | ||
} | ||
func TestInboxNotifications_MarkAllAsRead(t *testing.T) { | ||
t.Parallel() | ||
// I skip these tests specifically on windows as for now they are flaky - only on Windows. | ||
// For now the idea is that the runner takes too long to insert the entries, could be worth | ||
// investigating a manual Tx. | ||
// see: https://github.com/coder/internal/issues/503 | ||
if runtime.GOOS == "windows" { | ||
t.Skip("our runners are randomly taking too long to insert entries") | ||
} | ||
t.Run("ok", func(t *testing.T) { | ||
defelmnq marked this conversation as resolved. Show resolvedHide resolvedUh oh!There was an error while loading.Please reload this page. | ||
t.Parallel() | ||
client, _, api := coderdtest.NewWithAPI(t, &coderdtest.Options{}) | ||
firstUser := coderdtest.CreateFirstUser(t, client) | ||
client, member := coderdtest.CreateAnotherUser(t, client, firstUser.OrganizationID) | ||
ctx, cancel := context.WithTimeout(context.Background(), testutil.WaitLong) | ||
defer cancel() | ||
notifs, err := client.ListInboxNotifications(ctx, codersdk.ListInboxNotificationsRequest{}) | ||
require.NoError(t, err) | ||
require.NotNil(t, notifs) | ||
require.Equal(t, 0, notifs.UnreadCount) | ||
require.Empty(t, notifs.Notifications) | ||
for i := range 20 { | ||
dbgen.NotificationInbox(t, api.Database, database.InsertInboxNotificationParams{ | ||
ID: uuid.New(), | ||
UserID: member.ID, | ||
TemplateID: notifications.TemplateWorkspaceOutOfMemory, | ||
Title: fmt.Sprintf("Notification %d", i), | ||
Actions: json.RawMessage("[]"), | ||
Content: fmt.Sprintf("Content of the notif %d", i), | ||
CreatedAt: dbtime.Now(), | ||
}) | ||
} | ||
notifs, err = client.ListInboxNotifications(ctx, codersdk.ListInboxNotificationsRequest{}) | ||
require.NoError(t, err) | ||
require.NotNil(t, notifs) | ||
require.Equal(t, 20, notifs.UnreadCount) | ||
require.Len(t, notifs.Notifications, 20) | ||
err = client.MarkAllInboxNotificationsAsRead(ctx) | ||
require.NoError(t, err) | ||
notifs, err = client.ListInboxNotifications(ctx, codersdk.ListInboxNotificationsRequest{}) | ||
require.NoError(t, err) | ||
require.NotNil(t, notifs) | ||
require.Equal(t, 0, notifs.UnreadCount) | ||
require.Len(t, notifs.Notifications, 20) | ||
for i := range 10 { | ||
dbgen.NotificationInbox(t, api.Database, database.InsertInboxNotificationParams{ | ||
ID: uuid.New(), | ||
UserID: member.ID, | ||
TemplateID: notifications.TemplateWorkspaceOutOfMemory, | ||
Title: fmt.Sprintf("Notification %d", i), | ||
Actions: json.RawMessage("[]"), | ||
Content: fmt.Sprintf("Content of the notif %d", i), | ||
CreatedAt: dbtime.Now(), | ||
}) | ||
} | ||
notifs, err = client.ListInboxNotifications(ctx, codersdk.ListInboxNotificationsRequest{}) | ||
require.NoError(t, err) | ||
require.NotNil(t, notifs) | ||
require.Equal(t, 10, notifs.UnreadCount) | ||
require.Len(t, notifs.Notifications, 25) | ||
}) | ||
} |
Some generated files are not rendered by default. Learn more abouthow customized files appear on GitHub.
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.