Skip to content

Commit 0be893f

Browse files
authored
feat: extend status parameter to an array of possible statuses (#723)
The `status` parameter in the Apify Core API has been extended on the following endpoints: - `/v2/acts/:actorId/runs` - `/v2/actor-runs` - `/v2/actor-tasks/:actorTaskId/runs` It is now a comma-separated string of possible statuses. This PR updates the js client accordingly by modifying the `RunCollectionClient.list()` method to reflect the API change. Corresponding tests have also been extended.
1 parent 843fea4 commit 0be893f

File tree

2 files changed

+32
-4
lines changed

2 files changed

+32
-4
lines changed

src/resource_clients/run_collection.ts

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import ow from 'ow';
22

3-
import { ACT_JOB_STATUSES } from '@apify/consts';
3+
import { ACTOR_JOB_STATUSES } from '@apify/consts';
44

55
import type { ApiClientOptionsWithOptionalResourcePath } from '../base/api_client';
66
import { ResourceCollectionClient } from '../base/resource_collection_client';
@@ -28,7 +28,10 @@ export class RunCollectionClient extends ResourceCollectionClient {
2828
limit: ow.optional.number,
2929
offset: ow.optional.number,
3030
desc: ow.optional.boolean,
31-
status: ow.optional.string.oneOf(Object.values(ACT_JOB_STATUSES)),
31+
status: ow.optional.any(
32+
ow.string.oneOf(Object.values(ACTOR_JOB_STATUSES)),
33+
ow.array.ofType(ow.string.oneOf(Object.values(ACTOR_JOB_STATUSES))),
34+
),
3235
}),
3336
);
3437

@@ -40,5 +43,7 @@ export interface RunCollectionListOptions {
4043
limit?: number;
4144
offset?: number;
4245
desc?: boolean;
43-
status?: (typeof ACT_JOB_STATUSES)[keyof typeof ACT_JOB_STATUSES];
46+
status?:
47+
| (typeof ACTOR_JOB_STATUSES)[keyof typeof ACTOR_JOB_STATUSES]
48+
| (typeof ACTOR_JOB_STATUSES)[keyof typeof ACTOR_JOB_STATUSES][];
4449
}

test/runs.test.js

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,11 +32,12 @@ describe('Run methods', () => {
3232
});
3333

3434
describe('runs()', () => {
35-
test('list() works', async () => {
35+
test('list() works single status', async () => {
3636
const query = {
3737
limit: 5,
3838
offset: 3,
3939
desc: true,
40+
status: 'SUCCEEDED',
4041
};
4142

4243
const res = await client.runs().list(query);
@@ -47,6 +48,28 @@ describe('Run methods', () => {
4748
expect(browserRes).toEqual(res);
4849
validateRequest(query);
4950
});
51+
52+
test('list() works multiple statuses', async () => {
53+
const query = {
54+
limit: 5,
55+
offset: 3,
56+
desc: true,
57+
status: ['SUCCEEDED', 'FAILED'],
58+
};
59+
60+
const expectedQuery = {
61+
...query,
62+
status: 'SUCCEEDED,FAILED', // This is what should be sent to the API
63+
};
64+
65+
const res = await client.runs().list(query);
66+
expect(res.id).toEqual('list-runs');
67+
validateRequest(expectedQuery);
68+
69+
const browserRes = await page.evaluate((opts) => client.runs().list(opts), query);
70+
expect(browserRes).toEqual(res);
71+
validateRequest(expectedQuery);
72+
});
5073
});
5174

5275
describe('run()', () => {

0 commit comments

Comments
 (0)