Skip to content

Commit e356ba8

Browse files
committed
test
1 parent 00275dd commit e356ba8

File tree

1 file changed

+35
-0
lines changed

1 file changed

+35
-0
lines changed

coderd/users_test.go

+35
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import (
1010

1111
"github.com/coder/coder/v2/coderd"
1212
"github.com/coder/coder/v2/coderd/coderdtest/oidctest"
13+
"github.com/coder/coder/v2/coderd/notifications"
1314
"github.com/coder/coder/v2/coderd/rbac/policy"
1415
"github.com/coder/serpent"
1516

@@ -598,6 +599,40 @@ func TestPostUsers(t *testing.T) {
598599
})
599600
}
600601

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+
601636
func TestUpdateUserProfile(t *testing.T) {
602637
t.Parallel()
603638
t.Run("UserNotFound", func(t *testing.T) {

0 commit comments

Comments
 (0)