Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 12 additions & 6 deletions src/tools/auth0/handlers/connections.ts
Original file line number Diff line number Diff line change
Expand Up @@ -158,18 +158,24 @@ export const updateConnectionEnabledClients = async (
): Promise<boolean> => {
if (!connectionId || !Array.isArray(enabledClientIds) || !enabledClientIds.length) return false;

const enabledClientUpdatePayload: Array<PatchClientsRequestInner> = enabledClientIds.map(
const enabledClientUpdatePayloads: Array<PatchClientsRequestInner> = enabledClientIds.map(
(clientId) => ({
client_id: clientId,
status: true,
})
);
const payloadChunks = _.chunk(enabledClientUpdatePayloads, 50);

try {
await auth0Client.connections.updateEnabledClients(
{
id: connectionId,
},
enabledClientUpdatePayload
await Promise.all(
payloadChunks.map((payload) =>
auth0Client.connections.updateEnabledClients(
{
id: connectionId,
},
payload
)
)
);
log.debug(`Updated enabled clients for ${typeName}: ${connectionId}`);
return true;
Expand Down
30 changes: 30 additions & 0 deletions test/tools/auth0/handlers/connections.tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -742,6 +742,36 @@ describe('#connections enabled clients functionality', () => {
]
);
});

it('should update enabled clients with more than 50 clients', async () => {
const connectionId = 'con_123';
const enabledClientIds = Array.from({ length: 60 }, (_, i) => `client_${i + 1}`);
const typeName = 'connection';

mockAuth0Client.connections.updateEnabledClients.resolves();

const result = await updateConnectionEnabledClients(
mockAuth0Client,
typeName,
connectionId,
enabledClientIds
);

expect(result).to.equal(true);
sinon.assert.calledTwice(mockAuth0Client.connections.updateEnabledClients);

const firstCall = mockAuth0Client.connections.updateEnabledClients.getCall(0);
expect(firstCall.args[0]).to.deep.equal({ id: connectionId });
expect(firstCall.args[1]).to.have.length(50);
expect(firstCall.args[1][0]).to.deep.equal({ client_id: 'client_1', status: true });
expect(firstCall.args[1][49]).to.deep.equal({ client_id: 'client_50', status: true });

const secondCall = mockAuth0Client.connections.updateEnabledClients.getCall(1);
expect(secondCall.args[0]).to.deep.equal({ id: connectionId });
expect(secondCall.args[1]).to.have.length(10);
expect(secondCall.args[1][0]).to.deep.equal({ client_id: 'client_51', status: true });
expect(secondCall.args[1][9]).to.deep.equal({ client_id: 'client_60', status: true });
});
});

describe('#processConnectionEnabledClients', () => {
Expand Down