From ba161b45ef997488b1ec7bfb8a6c25788cc45205 Mon Sep 17 00:00:00 2001 From: Marcos Castany Date: Tue, 23 Mar 2021 23:13:32 +0100 Subject: [PATCH] Applied feedback --- src/auth0/handlers/organizations.js | 19 +---------- tests/auth0/handlers/organizations.tests.js | 38 ++++----------------- 2 files changed, 7 insertions(+), 50 deletions(-) diff --git a/src/auth0/handlers/organizations.js b/src/auth0/handlers/organizations.js index a7ebf7e..03ba427 100644 --- a/src/auth0/handlers/organizations.js +++ b/src/auth0/handlers/organizations.js @@ -143,7 +143,7 @@ export default class OrganizationsHandler extends DefaultHandler { } try { - const organizations = await this.getAllOrganizations(); + const organizations = await this.client.organizations.getAll({ pagination: true }); for (let index = 0; index < organizations.length; index++) { const connections = await this.client.organizations.connections.get({ id: organizations[index].id }); organizations[index].connections = connections; @@ -158,23 +158,6 @@ export default class OrganizationsHandler extends DefaultHandler { } } - async getAllOrganizations() { - let result = []; - let initialPage = 0; - let data = await this.client.organizations.getAll({ include_totals: true }); - if (data && data.total !== 0) { - let pagesLeft = Math.ceil(data.total / data.limit) - 1; - result = data.organizations; - while (pagesLeft > 0) { - initialPage += 1; - data = await this.client.organizations.getAll({ page: initialPage, include_totals: true }); - result.push(...data.organizations); - pagesLeft -= 1; - } - } - return result; - } - // Run after connections @order('70') async processChanges(assets) { diff --git a/tests/auth0/handlers/organizations.tests.js b/tests/auth0/handlers/organizations.tests.js index aaca95e..b751d8e 100644 --- a/tests/auth0/handlers/organizations.tests.js +++ b/tests/auth0/handlers/organizations.tests.js @@ -116,7 +116,7 @@ describe('#organizations handler', () => { }, update: () => Promise.resolve([]), delete: () => Promise.resolve([]), - getAll: () => Promise.resolve({ organizations: [], total: 0, limit: 50 }), + getAll: () => Promise.resolve([]), addEnabledConnection: (org, connection) => { expect(org.id).to.equal('fake'); expect(connection).to.be.an('object'); @@ -151,13 +151,7 @@ describe('#organizations handler', () => { it('should get organizations', async () => { const auth0 = { organizations: { - getAll: () => Promise.resolve({ - organizations: [ - sampleOrg - ], - total: 1, - limit: 50 - }), + getAll: () => Promise.resolve([ sampleOrg ]), connections: { get: () => [ sampleConnection @@ -178,11 +172,7 @@ describe('#organizations handler', () => { const auth0 = { organizations: { - getAll: data => Promise.resolve({ - organizations: data.page ? organizationsPage2 : organizationsPage1, - total: 90, - limit: 50 - }), + getAll: () => Promise.resolve([ ...organizationsPage2, ...organizationsPage1 ]), connections: { get: () => Promise.resolve({}) } @@ -265,11 +255,7 @@ describe('#organizations handler', () => { organizations: { getAll: () => { if (!shouldThrow) { - return { - organizations: [ sampleOrg ], - total: 1, - limit: 50 - }; + return [ sampleOrg ]; } throw new Error('Unexpected'); @@ -301,13 +287,7 @@ describe('#organizations handler', () => { return Promise.resolve(data); }, delete: () => Promise.resolve([]), - getAll: () => Promise.resolve({ - organizations: [ - sampleOrg - ], - total: 1, - limit: 50 - }), + getAll: () => Promise.resolve([ sampleOrg ]), connections: { get: () => [ sampleConnection, @@ -370,13 +350,7 @@ describe('#organizations handler', () => { expect(data.id).to.equal(sampleOrg.id); return Promise.resolve(data); }, - getAll: () => Promise.resolve({ - organizations: [ - sampleOrg - ], - total: 1, - limit: 50 - }), + getAll: () => Promise.resolve([ sampleOrg ]), connections: { get: () => [] }