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

Function TestUserTaskNotificationAlertDismissed

coderd/users_test.go:2286–2352  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

2284}
2285
2286func TestUserTaskNotificationAlertDismissed(t *testing.T) {
2287 t.Parallel()
2288
2289 // Single instance shared across all sub-tests. Each sub-test
2290 // creates its own non-admin user for isolation.
2291 adminClient := coderdtest.New(t, nil)
2292 firstUser := coderdtest.CreateFirstUser(t, adminClient)
2293
2294 t.Run("defaults to false", func(t *testing.T) {
2295 t.Parallel()
2296
2297 client, _ := coderdtest.CreateAnotherUser(t, adminClient, firstUser.OrganizationID)
2298
2299 ctx, cancel := context.WithTimeout(context.Background(), testutil.WaitShort)
2300 defer cancel()
2301
2302 // When: getting user preference settings for a user
2303 settings, err := client.GetUserPreferenceSettings(ctx, codersdk.Me)
2304 require.NoError(t, err)
2305
2306 // Then: the task notification alert dismissed should default to false
2307 require.False(t, settings.TaskNotificationAlertDismissed)
2308 })
2309
2310 t.Run("update to true", func(t *testing.T) {
2311 t.Parallel()
2312
2313 client, _ := coderdtest.CreateAnotherUser(t, adminClient, firstUser.OrganizationID)
2314
2315 ctx, cancel := context.WithTimeout(context.Background(), testutil.WaitShort)
2316 defer cancel()
2317
2318 // When: user dismisses the task notification alert
2319 updated, err := client.UpdateUserPreferenceSettings(ctx, codersdk.Me, codersdk.UpdateUserPreferenceSettingsRequest{
2320 TaskNotificationAlertDismissed: ptr.Ref(true),
2321 })
2322 require.NoError(t, err)
2323
2324 // Then: the setting is updated to true
2325 require.True(t, updated.TaskNotificationAlertDismissed)
2326 })
2327
2328 t.Run("update to false", func(t *testing.T) {
2329 t.Parallel()
2330
2331 client, _ := coderdtest.CreateAnotherUser(t, adminClient, firstUser.OrganizationID)
2332
2333 ctx, cancel := context.WithTimeout(context.Background(), testutil.WaitShort)
2334 defer cancel()
2335
2336 // Given: user has dismissed the task notification alert
2337 _, err := client.UpdateUserPreferenceSettings(ctx, codersdk.Me, codersdk.UpdateUserPreferenceSettingsRequest{
2338 TaskNotificationAlertDismissed: ptr.Ref(true),
2339 })
2340 require.NoError(t, err)
2341
2342 // When: the task notification alert dismissal is cleared
2343 // (e.g., when user enables a task notification in the UI settings)

Callers

nothing calls this directly

Calls 7

NewFunction · 0.92
CreateFirstUserFunction · 0.92
CreateAnotherUserFunction · 0.92
RefFunction · 0.92
RunMethod · 0.65

Tested by

no test coverage detected