MCPcopy Create free account
hub / github.com/auth0/auth0-cli / TestOrganizationPickerOptionsForGrant

Function TestOrganizationPickerOptionsForGrant

internal/cli/test_test.go:16–76  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

14)
15
16func TestOrganizationPickerOptionsForGrant(t *testing.T) {
17 const audience = "https://cli-demo.us.auth0.com/api/v2/"
18
19 tests := []struct {
20 name string
21 orgList *management.OrganizationList
22 apiError error
23 expectedError string
24 expectedOpts pickerOptions
25 }{
26 {
27 name: "api error fetching organizations",
28 apiError: errors.New("unexpected error"),
29 expectedError: "unexpected error",
30 },
31 {
32 name: "no organizations exist",
33 orgList: &management.OrganizationList{},
34 expectedError: "the client grant for " + audience + " requires an organization, but no organizations exist on this tenant.\n\n" +
35 "Create one by running: 'auth0 orgs create'",
36 },
37 {
38 name: "organizations exist",
39 orgList: &management.OrganizationList{
40 Organizations: []*management.Organization{
41 {ID: auth0.String("org_abc123"), Name: auth0.String("My Org")},
42 {ID: auth0.String("org_def456"), Name: auth0.String("Other Org")},
43 },
44 },
45 expectedOpts: pickerOptions{
46 {value: "org_abc123", label: "My Org (org_abc123)"},
47 {value: "org_def456", label: "Other Org (org_def456)"},
48 },
49 },
50 }
51
52 for _, test := range tests {
53 t.Run(test.name, func(t *testing.T) {
54 ctrl := gomock.NewController(t)
55 defer ctrl.Finish()
56
57 orgAPI := mock.NewMockOrganizationAPI(ctrl)
58 orgAPI.EXPECT().
59 List(gomock.Any(), gomock.Any()).
60 Return(test.orgList, test.apiError)
61
62 cli := &cli{
63 api: &auth0.API{Organization: orgAPI},
64 }
65
66 opts, err := cli.organizationPickerOptionsForGrant(audience)(context.Background())
67
68 if test.expectedError != "" {
69 assert.ErrorContains(t, err, test.expectedError)
70 } else {
71 assert.NoError(t, err)
72 assert.Equal(t, test.expectedOpts, opts)
73 }

Callers

nothing calls this directly

Calls 4

EXPECTMethod · 0.95
NewMockOrganizationAPIFunction · 0.92
ListMethod · 0.65

Tested by

no test coverage detected