Skip to content
This repository has been archived by the owner on Jul 31, 2021. It is now read-only.

Commit

Permalink
Applied feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
mcastany committed Mar 23, 2021
1 parent 80c6d6f commit ba161b4
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 50 deletions.
19 changes: 1 addition & 18 deletions src/auth0/handlers/organizations.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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) {
Expand Down
38 changes: 6 additions & 32 deletions tests/auth0/handlers/organizations.tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down Expand Up @@ -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
Expand All @@ -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({})
}
Expand Down Expand Up @@ -265,11 +255,7 @@ describe('#organizations handler', () => {
organizations: {
getAll: () => {
if (!shouldThrow) {
return {
organizations: [ sampleOrg ],
total: 1,
limit: 50
};
return [ sampleOrg ];
}

throw new Error('Unexpected');
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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: () => []
}
Expand Down

0 comments on commit ba161b4

Please sign in to comment.