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

Function TestEnterprisePostUser

enterprise/coderd/users_test.go:477–781  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

475}
476
477func TestEnterprisePostUser(t *testing.T) {
478 t.Parallel()
479
480 t.Run("OrganizationNoAccess", func(t *testing.T) {
481 t.Parallel()
482
483 dv := coderdtest.DeploymentValues(t)
484 client, first := coderdenttest.New(t, &coderdenttest.Options{
485 Options: &coderdtest.Options{
486 DeploymentValues: dv,
487 },
488 LicenseOptions: &coderdenttest.LicenseOptions{
489 Features: license.Features{
490 codersdk.FeatureMultipleOrganizations: 1,
491 },
492 },
493 })
494
495 notInOrg, _ := coderdtest.CreateAnotherUser(t, client, first.OrganizationID)
496 other, _ := coderdtest.CreateAnotherUser(t, client, first.OrganizationID, rbac.RoleOwner(), rbac.RoleMember())
497
498 ctx, cancel := context.WithTimeout(context.Background(), testutil.WaitLong)
499 defer cancel()
500
501 org := coderdenttest.CreateOrganization(t, other, coderdenttest.CreateOrganizationOptions{}, func(request *codersdk.CreateOrganizationRequest) {
502 request.Name = "another"
503 })
504
505 _, err := notInOrg.CreateUserWithOrgs(ctx, codersdk.CreateUserRequestWithOrgs{
506 Email: "some@domain.com",
507 Username: "anotheruser",
508 Password: "SomeSecurePassword!",
509 OrganizationIDs: []uuid.UUID{org.ID},
510 })
511 var apiErr *codersdk.Error
512 require.ErrorAs(t, err, &apiErr)
513 require.Equal(t, http.StatusNotFound, apiErr.StatusCode())
514 })
515
516 t.Run("OrganizationNoAccess", func(t *testing.T) {
517 t.Parallel()
518 dv := coderdtest.DeploymentValues(t)
519 client, first := coderdenttest.New(t, &coderdenttest.Options{
520 Options: &coderdtest.Options{
521 DeploymentValues: dv,
522 },
523 LicenseOptions: &coderdenttest.LicenseOptions{
524 Features: license.Features{
525 codersdk.FeatureMultipleOrganizations: 1,
526 },
527 },
528 })
529 notInOrg, _ := coderdtest.CreateAnotherUser(t, client, first.OrganizationID)
530 other, _ := coderdtest.CreateAnotherUser(t, client, first.OrganizationID, rbac.RoleOwner(), rbac.RoleMember())
531
532 ctx, cancel := context.WithTimeout(context.Background(), testutil.WaitLong)
533 defer cancel()
534

Callers

nothing calls this directly

Calls 15

StatusCodeMethod · 0.95
DeploymentValuesFunction · 0.92
NewFunction · 0.92
CreateAnotherUserFunction · 0.92
RoleOwnerFunction · 0.92
RoleMemberFunction · 0.92
CreateOrganizationFunction · 0.92
CreateUserWithOrgsMethod · 0.80
OrganizationsByUserMethod · 0.80
RunMethod · 0.65
UserMethod · 0.65
EqualMethod · 0.45

Tested by

no test coverage detected