(t *testing.T)
| 2091 | } |
| 2092 | |
| 2093 | func TestTemplateNotifications(t *testing.T) { |
| 2094 | t.Parallel() |
| 2095 | |
| 2096 | t.Run("Delete", func(t *testing.T) { |
| 2097 | t.Parallel() |
| 2098 | |
| 2099 | t.Run("InitiatorIsNotNotified", func(t *testing.T) { |
| 2100 | t.Parallel() |
| 2101 | |
| 2102 | // Given: an initiator |
| 2103 | var ( |
| 2104 | notifyEnq = ¬ificationstest.FakeEnqueuer{} |
| 2105 | client = coderdtest.New(t, &coderdtest.Options{ |
| 2106 | IncludeProvisionerDaemon: true, |
| 2107 | NotificationsEnqueuer: notifyEnq, |
| 2108 | }) |
| 2109 | initiator = coderdtest.CreateFirstUser(t, client) |
| 2110 | version = coderdtest.CreateTemplateVersion(t, client, initiator.OrganizationID, nil) |
| 2111 | _ = coderdtest.AwaitTemplateVersionJobCompleted(t, client, version.ID) |
| 2112 | template = coderdtest.CreateTemplate(t, client, initiator.OrganizationID, version.ID) |
| 2113 | ctx = testutil.Context(t, testutil.WaitLong) |
| 2114 | ) |
| 2115 | |
| 2116 | // When: the template is deleted by the initiator |
| 2117 | err := client.DeleteTemplate(ctx, template.ID) |
| 2118 | require.NoError(t, err) |
| 2119 | |
| 2120 | // Then: the delete notification is not sent to the initiator. |
| 2121 | deleteNotifications := make([]*notificationstest.FakeNotification, 0) |
| 2122 | for _, n := range notifyEnq.Sent() { |
| 2123 | if n.TemplateID == notifications.TemplateTemplateDeleted { |
| 2124 | deleteNotifications = append(deleteNotifications, n) |
| 2125 | } |
| 2126 | } |
| 2127 | require.Len(t, deleteNotifications, 0) |
| 2128 | }) |
| 2129 | |
| 2130 | t.Run("OnlyOwnersAndAdminsAreNotified", func(t *testing.T) { |
| 2131 | t.Parallel() |
| 2132 | |
| 2133 | // Given: multiple users with different roles |
| 2134 | var ( |
| 2135 | notifyEnq = ¬ificationstest.FakeEnqueuer{} |
| 2136 | client = coderdtest.New(t, &coderdtest.Options{ |
| 2137 | IncludeProvisionerDaemon: true, |
| 2138 | NotificationsEnqueuer: notifyEnq, |
| 2139 | }) |
| 2140 | initiator = coderdtest.CreateFirstUser(t, client) |
| 2141 | ctx = testutil.Context(t, testutil.WaitLong) |
| 2142 | |
| 2143 | // Setup template |
| 2144 | version = coderdtest.CreateTemplateVersion(t, client, initiator.OrganizationID, nil) |
| 2145 | _ = coderdtest.AwaitTemplateVersionJobCompleted(t, client, version.ID) |
| 2146 | template = coderdtest.CreateTemplate(t, client, initiator.OrganizationID, version.ID, func(ctr *codersdk.CreateTemplateRequest) { |
| 2147 | ctr.DisplayName = "Bobby's Template" |
| 2148 | }) |
| 2149 | ) |
| 2150 |
nothing calls this directly
no test coverage detected