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

Function TestPostOrganizationsByUser

enterprise/coderd/organizations_test.go:453–545  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

451}
452
453func TestPostOrganizationsByUser(t *testing.T) {
454 t.Parallel()
455 t.Run("Conflict", func(t *testing.T) {
456 t.Parallel()
457 client, user := coderdenttest.New(t, &coderdenttest.Options{
458 LicenseOptions: &coderdenttest.LicenseOptions{
459 Features: license.Features{
460 codersdk.FeatureMultipleOrganizations: 1,
461 },
462 },
463 })
464 ctx := testutil.Context(t, testutil.WaitLong)
465
466 //nolint:gocritic // using owner for below
467 org, err := client.Organization(ctx, user.OrganizationID)
468 require.NoError(t, err)
469
470 //nolint:gocritic // only owners can create orgs
471 _, err = client.CreateOrganization(ctx, codersdk.CreateOrganizationRequest{
472 Name: org.Name,
473 DisplayName: org.DisplayName,
474 })
475 var apiErr *codersdk.Error
476 require.ErrorAs(t, err, &apiErr)
477 require.Equal(t, http.StatusConflict, apiErr.StatusCode())
478 })
479
480 t.Run("InvalidName", func(t *testing.T) {
481 t.Parallel()
482 client, _ := coderdenttest.New(t, &coderdenttest.Options{
483 LicenseOptions: &coderdenttest.LicenseOptions{
484 Features: license.Features{
485 codersdk.FeatureMultipleOrganizations: 1,
486 },
487 },
488 })
489 ctx := testutil.Context(t, testutil.WaitLong)
490
491 //nolint:gocritic // only owners can create orgs
492 _, err := client.CreateOrganization(ctx, codersdk.CreateOrganizationRequest{
493 Name: "A name which is definitely not url safe",
494 DisplayName: "New",
495 })
496 var apiErr *codersdk.Error
497 require.ErrorAs(t, err, &apiErr)
498 require.Equal(t, http.StatusBadRequest, apiErr.StatusCode())
499 })
500
501 t.Run("Create", func(t *testing.T) {
502 t.Parallel()
503 client, _ := coderdenttest.New(t, &coderdenttest.Options{
504 LicenseOptions: &coderdenttest.LicenseOptions{
505 Features: license.Features{
506 codersdk.FeatureMultipleOrganizations: 1,
507 },
508 },
509 })
510 ctx := testutil.Context(t, testutil.WaitLong)

Callers

nothing calls this directly

Calls 7

StatusCodeMethod · 0.95
NewFunction · 0.92
ContextFunction · 0.92
CreateOrganizationMethod · 0.80
RunMethod · 0.65
OrganizationMethod · 0.45
EqualMethod · 0.45

Tested by

no test coverage detected