Skip to content

Commit

Permalink
Updated recordings and test cases
Browse files Browse the repository at this point in the history
  • Loading branch information
duedares-rvj committed Aug 16, 2024
1 parent 26afb16 commit 88e6be3
Show file tree
Hide file tree
Showing 10 changed files with 1,689 additions and 1,928 deletions.
30 changes: 19 additions & 11 deletions management/organization_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"net/http"
"os"
"testing"
"time"

"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
Expand Down Expand Up @@ -480,12 +481,23 @@ func TestOrganizationManager_ClientGrantsWithOrg(t *testing.T) {
org := givenAnOrganization(t)
resourceServer := givenAResourceServer(t)

client := givenAClient(t)
client.DefaultOrganization = &DefaultOrganization{
&[]string{"client_credentials"},
auth0.String(org.GetID()),
client := &Client{
Name: auth0.Stringf("Test Client (%s)", time.Now().Format(time.StampMilli)),
Description: auth0.String("This is just a test client."),
OrganizationUsage: auth0.String("allow"),
DefaultOrganization: &DefaultOrganization{
&[]string{"client_credentials"},
auth0.String(org.GetID()),
},
}

err := api.Client.Create(context.Background(), client)
require.NoError(t, err)

t.Cleanup(func() {
cleanupClient(t, client.GetClientID())
})

clientGrant := &ClientGrant{
ClientID: client.ClientID,
Audience: resourceServer.Identifier,
Expand All @@ -494,7 +506,7 @@ func TestOrganizationManager_ClientGrantsWithOrg(t *testing.T) {
OrganizationUsage: auth0.String("allow"),
}

err := api.ClientGrant.Create(context.Background(), clientGrant)
err = api.ClientGrant.Create(context.Background(), clientGrant)
require.NoError(t, err)
t.Cleanup(func() {
cleanupClientGrant(t, clientGrant.GetID())
Expand All @@ -505,19 +517,15 @@ func TestOrganizationManager_ClientGrantsWithOrg(t *testing.T) {

associatedGrants, err := api.Organization.ClientGrants(context.Background(), org.GetID(), Parameter("grant_ids", clientGrant.GetID()))
require.NoError(t, err)
assert.Len(t, associatedGrants.ClientGrants, 1)
assert.Greater(t, len(associatedGrants.ClientGrants), 0)
assert.Equal(t, clientGrant.GetID(), associatedGrants.ClientGrants[0].GetID())

clients, err := api.Client.List(context.Background(), Parameter("q", fmt.Sprintf("client_grant.organization_id:%s", org.GetID())))
require.NoError(t, err)
assert.Equal(t, clients.Clients[0].GetClientID(), client.GetClientID())
assert.Equal(t, client.GetClientID(), clients.Clients[0].GetClientID())

err = api.Organization.RemoveClientGrant(context.Background(), org.GetID(), clientGrant.GetID())
require.NoError(t, err)

associatedGrants, err = api.Organization.ClientGrants(context.Background(), org.GetID())
require.NoError(t, err)
assert.Len(t, associatedGrants.ClientGrants, 0)
}

func givenAnOrganization(t *testing.T) *Organization {
Expand Down
14 changes: 4 additions & 10 deletions management/resource_server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -185,11 +185,11 @@ func TestResourceServer_List(t *testing.T) {
configureHTTPTestRecordings(t)

expectedResourceServer := givenAResourceServer(t)

resourceServerList, err := api.ResourceServer.List(context.Background(), IncludeFields("id"))

resourceServerList, err := api.ResourceServer.List(context.Background(), IncludeFields("id", "identifier"), Parameter("identifiers", expectedResourceServer.GetIdentifier()))
require.NoError(t, err)
assert.NotEqual(t, len(resourceServerList.ResourceServers), 0)
assert.NoError(t, err)
assert.Contains(t, resourceServerList.ResourceServers, &ResourceServer{ID: expectedResourceServer.ID})
assert.Contains(t, resourceServerList.ResourceServers, &ResourceServer{ID: expectedResourceServer.ID, Identifier: expectedResourceServer.Identifier})
}

func givenAResourceServer(t *testing.T) *ResourceServer {
Expand Down Expand Up @@ -218,12 +218,6 @@ func givenAResourceServer(t *testing.T) *ResourceServer {
err := api.ResourceServer.Create(context.Background(), resourceServer)
require.NoError(t, err)

resourceServerList, err := api.ResourceServer.List(context.Background(), Parameter("identifiers", resourceServer.GetIdentifier()))
require.NoError(t, err)
assert.NotEqual(t, len(resourceServerList.ResourceServers), 0)

assert.Equal(t, resourceServerList.ResourceServers[0].GetIdentifier(), resourceServer.GetIdentifier())

t.Cleanup(func() {
cleanupResourceServer(t, resourceServer.GetID())
})
Expand Down
Loading

0 comments on commit 88e6be3

Please sign in to comment.