(t *testing.T)
| 2284 | } |
| 2285 | |
| 2286 | func 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) |
nothing calls this directly
no test coverage detected