4
4
"bytes"
5
5
"context"
6
6
"net/http"
7
+ "slices"
7
8
"testing"
8
9
"time"
9
10
@@ -38,17 +39,19 @@ func TestTemplates(t *testing.T) {
38
39
t .Run ("Deprecated" ,func (t * testing.T ) {
39
40
t .Parallel ()
40
41
42
+ notifyEnq := & testutil.FakeNotificationsEnqueuer {}
41
43
owner ,user := coderdenttest .New (t ,& coderdenttest.Options {
42
44
Options :& coderdtest.Options {
43
45
IncludeProvisionerDaemon :true ,
46
+ NotificationsEnqueuer :notifyEnq ,
44
47
},
45
48
LicenseOptions :& coderdenttest.LicenseOptions {
46
49
Features : license.Features {
47
50
codersdk .FeatureAccessControl :1 ,
48
51
},
49
52
},
50
53
})
51
- client ,_ := coderdtest .CreateAnotherUser (t ,owner ,user .OrganizationID ,rbac .RoleTemplateAdmin ())
54
+ client ,anotherUser := coderdtest .CreateAnotherUser (t ,owner ,user .OrganizationID ,rbac .RoleTemplateAdmin ())
52
55
version := coderdtest .CreateTemplateVersion (t ,client ,user .OrganizationID ,nil )
53
56
template := coderdtest .CreateTemplate (t ,client ,user .OrganizationID ,version .ID )
54
57
coderdtest .AwaitTemplateVersionJobCompleted (t ,client ,version .ID )
@@ -65,6 +68,25 @@ func TestTemplates(t *testing.T) {
65
68
assert .True (t ,updated .Deprecated )
66
69
assert .NotEmpty (t ,updated .DeprecationMessage )
67
70
71
+ notifs := []* testutil.Notification {}
72
+ for _ ,notif := range notifyEnq .Sent {
73
+ if notif .TemplateID == notifications .TemplateTemplateDeprecated {
74
+ notifs = append (notifs ,notif )
75
+ }
76
+ }
77
+ require .Equal (t ,2 ,len (notifs ))
78
+
79
+ expectedSentTo := []string {user .UserID .String (),anotherUser .ID .String ()}
80
+ slices .Sort (expectedSentTo )
81
+
82
+ sentTo := []string {}
83
+ for _ ,notif := range notifs {
84
+ sentTo = append (sentTo ,notif .UserID .String ())
85
+ }
86
+ slices .Sort (sentTo )
87
+
88
+ assert .Equal (t ,expectedSentTo ,sentTo )
89
+
68
90
_ ,err = client .CreateWorkspace (ctx ,user .OrganizationID ,codersdk .Me , codersdk.CreateWorkspaceRequest {
69
91
TemplateID :template .ID ,
70
92
Name :"foobar" ,