MCPcopy Index your code
hub / github.com/coder/coder / TestPostUsers

Function TestPostUsers

coderd/users_test.go:801–1045  ·  view source on GitHub ↗

nolint:bodyclose

(t *testing.T)

Source from the content-addressed store, hash-verified

799
800// nolint:bodyclose
801func TestPostUsers(t *testing.T) {
802 t.Parallel()
803 t.Run("NoAuth", func(t *testing.T) {
804 t.Parallel()
805 client := coderdtest.New(t, nil)
806
807 ctx, cancel := context.WithTimeout(context.Background(), testutil.WaitLong)
808 defer cancel()
809
810 _, err := client.CreateUserWithOrgs(ctx, codersdk.CreateUserRequestWithOrgs{})
811 require.Error(t, err)
812 })
813
814 t.Run("Conflicting", func(t *testing.T) {
815 t.Parallel()
816 client := coderdtest.New(t, nil)
817 coderdtest.CreateFirstUser(t, client)
818
819 ctx, cancel := context.WithTimeout(context.Background(), testutil.WaitLong)
820 defer cancel()
821
822 me, err := client.User(ctx, codersdk.Me)
823 require.NoError(t, err)
824 _, err = client.CreateUserWithOrgs(ctx, codersdk.CreateUserRequestWithOrgs{
825 Email: me.Email,
826 Username: me.Username,
827 Password: "MySecurePassword!",
828 OrganizationIDs: []uuid.UUID{uuid.New()},
829 })
830 var apiErr *codersdk.Error
831 require.ErrorAs(t, err, &apiErr)
832 require.Equal(t, http.StatusConflict, apiErr.StatusCode())
833 })
834
835 t.Run("OrganizationNotFound", func(t *testing.T) {
836 t.Parallel()
837 client := coderdtest.New(t, nil)
838 coderdtest.CreateFirstUser(t, client)
839
840 ctx, cancel := context.WithTimeout(context.Background(), testutil.WaitLong)
841 defer cancel()
842
843 _, err := client.CreateUserWithOrgs(ctx, codersdk.CreateUserRequestWithOrgs{
844 OrganizationIDs: []uuid.UUID{uuid.New()},
845 Email: "another@user.org",
846 Username: "someone-else",
847 Password: "SomeSecurePassword!",
848 })
849 var apiErr *codersdk.Error
850 require.ErrorAs(t, err, &apiErr)
851 require.Equal(t, http.StatusNotFound, apiErr.StatusCode())
852 })
853
854 t.Run("Create", func(t *testing.T) {
855 t.Parallel()
856 auditor := audit.NewMock()
857 client := coderdtest.New(t, &coderdtest.Options{Auditor: auditor})
858 numLogs := len(auditor.AuditLogs())

Callers

nothing calls this directly

Calls 15

StatusCodeMethod · 0.95
OIDCConfigMethod · 0.95
LoginMethod · 0.95
NewFunction · 0.92
CreateFirstUserFunction · 0.92
NewMockFunction · 0.92
RefFunction · 0.92
CreateAnotherUserFunction · 0.92
NowFunction · 0.92
NewFakeIDPFunction · 0.92
WithServingFunction · 0.92
CreateUserWithOrgsMethod · 0.80

Tested by

no test coverage detected