(t *testing.T)
| 5071 | } |
| 5072 | |
| 5073 | func TestWorkspaceNotifications(t *testing.T) { |
| 5074 | t.Parallel() |
| 5075 | |
| 5076 | t.Run("Dormant", func(t *testing.T) { |
| 5077 | t.Parallel() |
| 5078 | |
| 5079 | t.Run("InitiatorNotOwner", func(t *testing.T) { |
| 5080 | t.Parallel() |
| 5081 | |
| 5082 | // Given |
| 5083 | var ( |
| 5084 | notifyEnq = ¬ificationstest.FakeEnqueuer{} |
| 5085 | client = coderdtest.New(t, &coderdtest.Options{ |
| 5086 | IncludeProvisionerDaemon: true, |
| 5087 | NotificationsEnqueuer: notifyEnq, |
| 5088 | }) |
| 5089 | user = coderdtest.CreateFirstUser(t, client) |
| 5090 | memberClient, _ = coderdtest.CreateAnotherUser(t, client, user.OrganizationID, rbac.RoleOwner()) |
| 5091 | version = coderdtest.CreateTemplateVersion(t, client, user.OrganizationID, nil) |
| 5092 | _ = coderdtest.AwaitTemplateVersionJobCompleted(t, client, version.ID) |
| 5093 | template = coderdtest.CreateTemplate(t, client, user.OrganizationID, version.ID) |
| 5094 | workspace = coderdtest.CreateWorkspace(t, client, template.ID) |
| 5095 | _ = coderdtest.AwaitWorkspaceBuildJobCompleted(t, client, workspace.LatestBuild.ID) |
| 5096 | ) |
| 5097 | |
| 5098 | ctx, cancel := context.WithTimeout(context.Background(), testutil.WaitLong) |
| 5099 | t.Cleanup(cancel) |
| 5100 | |
| 5101 | // When |
| 5102 | err := memberClient.UpdateWorkspaceDormancy(ctx, workspace.ID, codersdk.UpdateWorkspaceDormancy{ |
| 5103 | Dormant: true, |
| 5104 | }) |
| 5105 | |
| 5106 | // Then |
| 5107 | require.NoError(t, err, "mark workspace as dormant") |
| 5108 | sent := notifyEnq.Sent(notificationstest.WithTemplateID(notifications.TemplateWorkspaceDormant)) |
| 5109 | require.Len(t, sent, 1) |
| 5110 | require.Equal(t, sent[0].TemplateID, notifications.TemplateWorkspaceDormant) |
| 5111 | require.Equal(t, sent[0].UserID, workspace.OwnerID) |
| 5112 | require.Contains(t, sent[0].Targets, template.ID) |
| 5113 | require.Contains(t, sent[0].Targets, workspace.ID) |
| 5114 | require.Contains(t, sent[0].Targets, workspace.OrganizationID) |
| 5115 | require.Contains(t, sent[0].Targets, workspace.OwnerID) |
| 5116 | }) |
| 5117 | |
| 5118 | t.Run("InitiatorIsOwner", func(t *testing.T) { |
| 5119 | t.Parallel() |
| 5120 | |
| 5121 | // Given |
| 5122 | var ( |
| 5123 | notifyEnq = ¬ificationstest.FakeEnqueuer{} |
| 5124 | client = coderdtest.New(t, &coderdtest.Options{ |
| 5125 | IncludeProvisionerDaemon: true, |
| 5126 | NotificationsEnqueuer: notifyEnq, |
| 5127 | }) |
| 5128 | user = coderdtest.CreateFirstUser(t, client) |
| 5129 | version = coderdtest.CreateTemplateVersion(t, client, user.OrganizationID, nil) |
| 5130 | _ = coderdtest.AwaitTemplateVersionJobCompleted(t, client, version.ID) |
nothing calls this directly
no test coverage detected