(t *testing.T)
| 30 | } |
| 31 | |
| 32 | func TestNotifications(t *testing.T) { |
| 33 | t.Parallel() |
| 34 | |
| 35 | tests := []struct { |
| 36 | name string |
| 37 | command string |
| 38 | expectPaused bool |
| 39 | }{ |
| 40 | { |
| 41 | name: "PauseNotifications", |
| 42 | command: "pause", |
| 43 | expectPaused: true, |
| 44 | }, |
| 45 | { |
| 46 | name: "ResumeNotifications", |
| 47 | command: "resume", |
| 48 | expectPaused: false, |
| 49 | }, |
| 50 | } |
| 51 | |
| 52 | for _, tt := range tests { |
| 53 | t.Run(tt.name, func(t *testing.T) { |
| 54 | t.Parallel() |
| 55 | |
| 56 | // given |
| 57 | ownerClient, db := coderdtest.NewWithDatabase(t, createOpts(t)) |
| 58 | _ = coderdtest.CreateFirstUser(t, ownerClient) |
| 59 | |
| 60 | // when |
| 61 | inv, root := clitest.New(t, "notifications", tt.command) |
| 62 | clitest.SetupConfig(t, ownerClient, root) |
| 63 | |
| 64 | var buf bytes.Buffer |
| 65 | inv.Stdout = &buf |
| 66 | err := inv.Run() |
| 67 | require.NoError(t, err) |
| 68 | |
| 69 | // then |
| 70 | ctx, cancel := context.WithTimeout(context.Background(), testutil.WaitShort) |
| 71 | t.Cleanup(cancel) |
| 72 | settingsJSON, err := db.GetNotificationsSettings(ctx) |
| 73 | require.NoError(t, err) |
| 74 | |
| 75 | var settings codersdk.NotificationsSettings |
| 76 | err = json.Unmarshal([]byte(settingsJSON), &settings) |
| 77 | require.NoError(t, err) |
| 78 | require.Equal(t, tt.expectPaused, settings.NotifierPaused) |
| 79 | }) |
| 80 | } |
| 81 | } |
| 82 | |
| 83 | func TestPauseNotifications_RegularUser(t *testing.T) { |
| 84 | t.Parallel() |
nothing calls this directly
no test coverage detected