@@ -10,6 +10,7 @@ import (
10
10
11
11
"github.com/coder/coder/v2/coderd"
12
12
"github.com/coder/coder/v2/coderd/coderdtest/oidctest"
13
+ "github.com/coder/coder/v2/coderd/notifications"
13
14
"github.com/coder/coder/v2/coderd/rbac/policy"
14
15
"github.com/coder/serpent"
15
16
@@ -598,6 +599,40 @@ func TestPostUsers(t *testing.T) {
598
599
})
599
600
}
600
601
602
+ func TestNotifyCreatedUser (t * testing.T ) {
603
+ t .Parallel ()
604
+
605
+ t .Run ("OwnerNotified" , func (t * testing.T ) {
606
+ t .Parallel ()
607
+
608
+ notifyEnq := & testutil.FakeNotificationsEnqueuer {}
609
+ client := coderdtest .New (t , & coderdtest.Options {
610
+ NotificationsEnqueuer : notifyEnq ,
611
+ })
612
+ firstUser := coderdtest .CreateFirstUser (t , client )
613
+
614
+ ctx , cancel := context .WithTimeout (context .Background (), testutil .WaitLong )
615
+ defer cancel ()
616
+
617
+ user , err := client .CreateUser (ctx , codersdk.CreateUserRequest {
618
+ OrganizationID : firstUser .OrganizationID ,
619
+ Email : "another@user.org" ,
620
+ Username : "someone-else" ,
621
+ Password : "SomeSecurePassword!" ,
622
+ })
623
+ require .NoError (t , err )
624
+
625
+ require .Len (t , user .OrganizationIDs , 1 )
626
+ assert .Equal (t , firstUser .OrganizationID , user .OrganizationIDs [0 ])
627
+
628
+ require .Len (t , notifyEnq .Sent , 1 )
629
+ require .Equal (t , notifications .TemplateUserAccountCreated , notifyEnq .Sent [0 ].TemplateID )
630
+ require .Equal (t , firstUser .UserID , notifyEnq .Sent [0 ].UserID )
631
+ require .Contains (t , user .ID , notifyEnq .Sent [0 ].Targets )
632
+ require .Equal (t , user .Username , notifyEnq .Sent [0 ].Labels ["user_account_name" ])
633
+ })
634
+ }
635
+
601
636
func TestUpdateUserProfile (t * testing.T ) {
602
637
t .Parallel ()
603
638
t .Run ("UserNotFound" , func (t * testing.T ) {
0 commit comments