Skip to content

Commit ebf361c

Browse files
authored
feat: Implement pagination for database enabled clients update in connections (#1127)
* feat: Implement pagination for database enabled clients update in connections * test: Add test for updating enabled clients with more than 50 clients
1 parent cc6b85d commit ebf361c

File tree

2 files changed

+42
-6
lines changed

2 files changed

+42
-6
lines changed

src/tools/auth0/handlers/connections.ts

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -158,18 +158,24 @@ export const updateConnectionEnabledClients = async (
158158
): Promise<boolean> => {
159159
if (!connectionId || !Array.isArray(enabledClientIds) || !enabledClientIds.length) return false;
160160

161-
const enabledClientUpdatePayload: Array<PatchClientsRequestInner> = enabledClientIds.map(
161+
const enabledClientUpdatePayloads: Array<PatchClientsRequestInner> = enabledClientIds.map(
162162
(clientId) => ({
163163
client_id: clientId,
164164
status: true,
165165
})
166166
);
167+
const payloadChunks = _.chunk(enabledClientUpdatePayloads, 50);
168+
167169
try {
168-
await auth0Client.connections.updateEnabledClients(
169-
{
170-
id: connectionId,
171-
},
172-
enabledClientUpdatePayload
170+
await Promise.all(
171+
payloadChunks.map((payload) =>
172+
auth0Client.connections.updateEnabledClients(
173+
{
174+
id: connectionId,
175+
},
176+
payload
177+
)
178+
)
173179
);
174180
log.debug(`Updated enabled clients for ${typeName}: ${connectionId}`);
175181
return true;

test/tools/auth0/handlers/connections.tests.js

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -742,6 +742,36 @@ describe('#connections enabled clients functionality', () => {
742742
]
743743
);
744744
});
745+
746+
it('should update enabled clients with more than 50 clients', async () => {
747+
const connectionId = 'con_123';
748+
const enabledClientIds = Array.from({ length: 60 }, (_, i) => `client_${i + 1}`);
749+
const typeName = 'connection';
750+
751+
mockAuth0Client.connections.updateEnabledClients.resolves();
752+
753+
const result = await updateConnectionEnabledClients(
754+
mockAuth0Client,
755+
typeName,
756+
connectionId,
757+
enabledClientIds
758+
);
759+
760+
expect(result).to.equal(true);
761+
sinon.assert.calledTwice(mockAuth0Client.connections.updateEnabledClients);
762+
763+
const firstCall = mockAuth0Client.connections.updateEnabledClients.getCall(0);
764+
expect(firstCall.args[0]).to.deep.equal({ id: connectionId });
765+
expect(firstCall.args[1]).to.have.length(50);
766+
expect(firstCall.args[1][0]).to.deep.equal({ client_id: 'client_1', status: true });
767+
expect(firstCall.args[1][49]).to.deep.equal({ client_id: 'client_50', status: true });
768+
769+
const secondCall = mockAuth0Client.connections.updateEnabledClients.getCall(1);
770+
expect(secondCall.args[0]).to.deep.equal({ id: connectionId });
771+
expect(secondCall.args[1]).to.have.length(10);
772+
expect(secondCall.args[1][0]).to.deep.equal({ client_id: 'client_51', status: true });
773+
expect(secondCall.args[1][9]).to.deep.equal({ client_id: 'client_60', status: true });
774+
});
745775
});
746776

747777
describe('#processConnectionEnabledClients', () => {

0 commit comments

Comments
 (0)