@@ -606,31 +606,85 @@ func TestNotifyCreatedUser(t *testing.T) {
606
606
t .Parallel ()
607
607
608
608
notifyEnq := & testutil.FakeNotificationsEnqueuer {}
609
- client := coderdtest .New (t , & coderdtest.Options {
609
+ adminClient := coderdtest .New (t , & coderdtest.Options {
610
610
NotificationsEnqueuer : notifyEnq ,
611
611
})
612
- firstUser := coderdtest .CreateFirstUser (t , client )
612
+ firstUser := coderdtest .CreateFirstUser (t , adminClient )
613
613
614
614
ctx , cancel := context .WithTimeout (context .Background (), testutil .WaitLong )
615
615
defer cancel ()
616
616
617
- user , err := client .CreateUser (ctx , codersdk.CreateUserRequest {
617
+ user , err := adminClient .CreateUser (ctx , codersdk.CreateUserRequest {
618
618
OrganizationID : firstUser .OrganizationID ,
619
619
Email : "another@user.org" ,
620
620
Username : "someone-else" ,
621
621
Password : "SomeSecurePassword!" ,
622
622
})
623
623
require .NoError (t , err )
624
624
625
- require .Len (t , user .OrganizationIDs , 1 )
626
- assert .Equal (t , firstUser .OrganizationID , user .OrganizationIDs [0 ])
627
-
628
625
require .Len (t , notifyEnq .Sent , 1 )
629
626
require .Equal (t , notifications .TemplateUserAccountCreated , notifyEnq .Sent [0 ].TemplateID )
630
627
require .Equal (t , firstUser .UserID , notifyEnq .Sent [0 ].UserID )
631
628
require .Contains (t , notifyEnq .Sent [0 ].Targets , user .ID )
632
629
require .Equal (t , user .Username , notifyEnq .Sent [0 ].Labels ["user_account_name" ])
633
630
})
631
+
632
+ t .Run ("UserAdminNotified" , func (t * testing.T ) {
633
+ t .Parallel ()
634
+
635
+ notifyEnq := & testutil.FakeNotificationsEnqueuer {}
636
+ adminClient := coderdtest .New (t , & coderdtest.Options {
637
+ NotificationsEnqueuer : notifyEnq ,
638
+ })
639
+ firstUser := coderdtest .CreateFirstUser (t , adminClient )
640
+
641
+ ctx , cancel := context .WithTimeout (context .Background (), testutil .WaitLong )
642
+ defer cancel ()
643
+
644
+ userAdmin , err := adminClient .CreateUser (ctx , codersdk.CreateUserRequest {
645
+ OrganizationID : firstUser .OrganizationID ,
646
+ Email : "user-admin@user.org" ,
647
+ Username : "mr-user-admin" ,
648
+ Password : "SomeSecurePassword!" ,
649
+ })
650
+ require .NoError (t , err )
651
+
652
+ _ , err = adminClient .UpdateUserRoles (ctx , userAdmin .Username , codersdk.UpdateRoles {
653
+ Roles : []string {
654
+ rbac .RoleUserAdmin ().String (),
655
+ },
656
+ })
657
+ require .NoError (t , err )
658
+
659
+ member , err := adminClient .CreateUser (ctx , codersdk.CreateUserRequest {
660
+ OrganizationID : firstUser .OrganizationID ,
661
+ Email : "another@user.org" ,
662
+ Username : "someone-else" ,
663
+ Password : "SomeSecurePassword!" ,
664
+ })
665
+ require .NoError (t , err )
666
+
667
+ require .Len (t , notifyEnq .Sent , 3 )
668
+
669
+ // "User admin" account created, "owner" notified
670
+ require .Equal (t , notifications .TemplateUserAccountCreated , notifyEnq .Sent [0 ].TemplateID )
671
+ require .Equal (t , firstUser .UserID , notifyEnq .Sent [0 ].UserID )
672
+ require .Contains (t , notifyEnq .Sent [0 ].Targets , userAdmin .ID )
673
+ require .Equal (t , userAdmin .Username , notifyEnq .Sent [0 ].Labels ["user_account_name" ])
674
+
675
+ // "Member" account created, "owner" notified
676
+ require .Equal (t , notifications .TemplateUserAccountCreated , notifyEnq .Sent [1 ].TemplateID )
677
+ require .Equal (t , firstUser .UserID , notifyEnq .Sent [1 ].UserID )
678
+ require .Contains (t , notifyEnq .Sent [1 ].Targets , member .ID )
679
+ require .Equal (t , member .Username , notifyEnq .Sent [1 ].Labels ["user_account_name" ])
680
+
681
+ // "Member" account created, "user admin" notified
682
+ require .Equal (t , notifications .TemplateUserAccountCreated , notifyEnq .Sent [1 ].TemplateID )
683
+ require .Equal (t , userAdmin .ID , notifyEnq .Sent [2 ].UserID )
684
+ require .Contains (t , notifyEnq .Sent [2 ].Targets , member .ID )
685
+ require .Equal (t , member .Username , notifyEnq .Sent [2 ].Labels ["user_account_name" ])
686
+
687
+ })
634
688
}
635
689
636
690
func TestUpdateUserProfile (t * testing.T ) {
0 commit comments