diff --git a/test/management/client.test.ts b/test/management/client.test.ts index 8bfca27f0..c0518df8a 100644 --- a/test/management/client.test.ts +++ b/test/management/client.test.ts @@ -12,6 +12,7 @@ import { PostCredentialsOperationRequest, PostCredentialsRequest, ManagementClient, + GetClientsRequest, } from '../../src/index.js'; import { RequiredError } from '../../src/lib/errors.js'; @@ -138,16 +139,25 @@ describe('ClientsManager', () => { it('should pass the parameters in the query-string', (done) => { nock.cleanAll(); + const queryParameters: GetClientsRequest | any = { + fields: 'name,email', + include_fields: true, + page: 0, + per_page: 50, + include_totals: false, + from: '12345', + take: 50, + is_global: true, + is_first_party: false, + app_type: 'web,mobile', + client_ids: 'client1,client2,client3', + q: 'name:John AND email:john@example.com', + }; + const data = [{ client_id: '1' }]; - const request = nock(API_URL) - .get('/clients') - .query({ - include_fields: true, - fields: 'test', - }) - .reply(200, data); + const request = nock(API_URL).get('/clients').query(queryParameters).reply(200, data); - clients.getAll({ include_fields: true, fields: 'test' }).then(() => { + clients.getAll({ ...queryParameters }).then(() => { expect(request.isDone()).toBe(true); done(); }); diff --git a/test/management/organizations.test.ts b/test/management/organizations.test.ts index 248c184c2..0fb9eef0b 100644 --- a/test/management/organizations.test.ts +++ b/test/management/organizations.test.ts @@ -2,7 +2,14 @@ import nock from 'nock'; const API_URL = 'https://tenant.auth0.com/api/v2'; -import { OrganizationsManager, ManagementClient, RequiredError } from '../../src/index.js'; +import { + OrganizationsManager, + ManagementClient, + RequiredError, + GetOrganizationClientGrantsRequest, + GetOrganizationClientGrants200Response, + ApiResponse, +} from '../../src/index.js'; describe('OrganizationsManager', () => { let organizations: OrganizationsManager; @@ -1386,4 +1393,85 @@ describe('OrganizationsManager', () => { }); }); }); + + describe('#getOrganizationClientGrants', () => { + const token = 'test_token'; + + const data: GetOrganizationClientGrantsRequest | any = { + id: 'org_123', + audience: 'audience', + client_id: 'client_id', + grant_ids: ['grant_id1', 'grant_id2'], + page: 1, + per_page: 10, + include_totals: true, + }; + + beforeEach(() => { + request = nock(API_URL) + .get(`/organizations/${data.id}/client-grants`) + .query({ + audience: data.audience, + client_id: data.client_id, + grant_ids: data.grant_ids, + page: data.page, + per_page: data.per_page, + include_totals: data.include_totals, + }) + .reply(200, { grants: [] }); + }); + + afterEach(() => { + nock.cleanAll(); + }); + + it('should return a promise if no callback is given', async () => { + const promise = organizations.getOrganizationClientGrants(data); + expect(promise).toBeInstanceOf(Promise); + await promise; + }); + + it('should perform a GET request to /api/v2/organizations/:id/client-grants', async () => { + await organizations.getOrganizationClientGrants(data); + expect(request.isDone()).toBe(true); + }); + + it('should include the token in the Authorization header', async () => { + const scope = nock(API_URL, { + reqheaders: { + authorization: `Bearer ${token}`, + }, + }) + .get(`/organizations/${data.id}/client-grants`) + .query({ + audience: data.audience, + client_id: data.client_id, + grant_ids: data.grant_ids, + page: data.page, + per_page: data.per_page, + include_totals: data.include_totals, + }) + .reply(200, { grants: [] }); + + const result: ApiResponse = + await organizations.getOrganizationClientGrants(data); + expect(result.status).toBe(200); + }); + + it('should pass the query parameters correctly', async () => { + await organizations.getOrganizationClientGrants(data); + expect(request.isDone()).toBe(true); + }); + + it('should pass any errors to the promise catch handler', async () => { + request = nock(API_URL) + .get(`/organizations/${data.id}/client-grants`) + .query(true) + .reply(500, {}); + + organizations.getOrganizationClientGrants(data).catch((err) => { + expect(err).toBeDefined(); + }); + }); + }); }); diff --git a/test/management/resource-servers.test.ts b/test/management/resource-servers.test.ts index 118710038..0be3df254 100644 --- a/test/management/resource-servers.test.ts +++ b/test/management/resource-servers.test.ts @@ -1,4 +1,5 @@ import nock from 'nock'; +import queryString from 'querystring'; const API_URL = 'https://tenant.auth0.com/api/v2'; @@ -81,18 +82,25 @@ describe('ResourceServersManager', () => { }); }); - it('should include the token in the Authorization header', (done) => { + it('should include the token in the Authorization header', async () => { nock.cleanAll(); + const queryParams = { + identifiers: ['123'], + page: 0, + per_page: 10, + include_totals: true, + include_fields: true, + }; + const request = nock(API_URL) - .get('/resource-servers') + .get(`/resource-servers?${queryString.stringify(queryParams)}`) .matchHeader('Authorization', `Bearer ${token}`) + // .query(queryParams) .reply(200, []); - resourceServers.getAll().then(() => { - expect(request.isDone()).toBe(true); - done(); - }); + await resourceServers.getAll(queryParams); + expect(request.isDone()).toBe(true); }); });