Skip to content

Commit 138aaf7

Browse files
committed
test: cover sdk idempotency key forwarding
1 parent 7bb04af commit 138aaf7

2 files changed

Lines changed: 76 additions & 0 deletions

File tree

sdks/typescript/src/clients/admin/admin-client.test.ts

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -164,5 +164,47 @@ describe('AdminClient', () => {
164164
})
165165
);
166166
});
167+
168+
it('should forward idempotencyKey in batch requests', async () => {
169+
const bulkSpy = jest.spyOn(client.client, 'bulkTriggerWorkflow').mockResolvedValue({
170+
workflowRunIds: ['run-1'],
171+
});
172+
173+
await client.runWorkflows([
174+
{
175+
workflowName: 'workflowName',
176+
input: { hello: 'world' },
177+
options: {
178+
idempotencyKey: 'idem-batch-1',
179+
},
180+
},
181+
]);
182+
183+
expect(bulkSpy).toHaveBeenCalledWith(
184+
expect.objectContaining({
185+
workflows: [
186+
expect.objectContaining({
187+
idempotencyKey: 'idem-batch-1',
188+
}),
189+
],
190+
})
191+
);
192+
});
193+
});
194+
195+
describe('runWorkflow', () => {
196+
it('should forward idempotencyKey in single requests', async () => {
197+
const triggerSpy = jest
198+
.spyOn(client.client, 'triggerWorkflow')
199+
.mockResolvedValue('run-1' as any);
200+
201+
await client.runWorkflow('workflowName', { hello: 'world' }, { idempotencyKey: 'idem-1' });
202+
203+
expect(triggerSpy).toHaveBeenCalledWith(
204+
expect.objectContaining({
205+
idempotencyKey: 'idem-1',
206+
})
207+
);
208+
});
167209
});
168210
});

sdks/typescript/src/v1/client/admin.test.ts

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,15 @@ describe('AdminClient workflow name normalization', () => {
5656
);
5757
});
5858

59+
it('runWorkflow forwards idempotencyKey', async () => {
60+
const admin = createMockAdmin();
61+
await admin.runWorkflow('my-workflow', {}, { idempotencyKey: 'idem-1' });
62+
63+
expect(admin.workflowsGrpc.triggerWorkflow).toHaveBeenCalledWith(
64+
expect.objectContaining({ idempotencyKey: 'idem-1' })
65+
);
66+
});
67+
5968
it('runWorkflows lowercases workflow names in batch', async () => {
6069
const admin = createMockAdmin();
6170
await admin.runWorkflows([
@@ -72,4 +81,29 @@ describe('AdminClient workflow name normalization', () => {
7281
})
7382
);
7483
});
84+
85+
it('runWorkflows forwards idempotencyKey in batch', async () => {
86+
const admin = createMockAdmin();
87+
await admin.runWorkflows([
88+
{
89+
workflowName: 'WorkflowOne',
90+
input: {},
91+
options: { idempotencyKey: 'idem-batch-1' },
92+
},
93+
{
94+
workflowName: 'WorkflowTwo',
95+
input: {},
96+
options: { idempotencyKey: 'idem-batch-2' },
97+
},
98+
]);
99+
100+
expect(admin.workflowsGrpc.bulkTriggerWorkflow).toHaveBeenCalledWith(
101+
expect.objectContaining({
102+
workflows: expect.arrayContaining([
103+
expect.objectContaining({ idempotencyKey: 'idem-batch-1' }),
104+
expect.objectContaining({ idempotencyKey: 'idem-batch-2' }),
105+
]),
106+
})
107+
);
108+
});
75109
});

0 commit comments

Comments
 (0)