Skip to content

Commit 2345999

Browse files
authored
feat: add startedBefore and startedAfter to run list (#763)
This PR adds new options to RunCollectionClient.list(): `startedBefore` and `startedAfter`. Note: this is the first time we use dates in query in the API (correct me if I am wrong), so in case we'll add any dates to query params in future they should use the same logic. Based on agreement with @barjin we decided to allow users to pass dates in 2 formats: as Date object or as a string.
1 parent ac05927 commit 2345999

File tree

3 files changed

+49
-1
lines changed

3 files changed

+49
-1
lines changed

src/http_client.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,9 +69,12 @@ export class HttpClient {
6969
httpAgent: this.httpAgent,
7070
httpsAgent: this.httpsAgent,
7171
paramsSerializer: (params) => {
72-
const formattedParams: [string, string][] = Object.entries<string>(params)
72+
const formattedParams: [string, string][] = Object.entries<string | Date>(params)
7373
.filter(([, value]) => value !== undefined)
7474
.map(([key, value]) => {
75+
if (value instanceof Date) {
76+
return [key, value.toISOString()];
77+
}
7578
const updatedValue = typeof value === 'boolean' ? Number(value) : value;
7679
return [key, String(updatedValue)];
7780
});

src/resource_clients/run_collection.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@ export class RunCollectionClient extends ResourceCollectionClient {
3232
ow.string.oneOf(Object.values(ACTOR_JOB_STATUSES)),
3333
ow.array.ofType(ow.string.oneOf(Object.values(ACTOR_JOB_STATUSES))),
3434
),
35+
startedBefore: ow.optional.any(ow.optional.date, ow.optional.string),
36+
startedAfter: ow.optional.any(ow.optional.date, ow.optional.string),
3537
}),
3638
);
3739

@@ -46,4 +48,6 @@ export interface RunCollectionListOptions {
4648
status?:
4749
| (typeof ACTOR_JOB_STATUSES)[keyof typeof ACTOR_JOB_STATUSES]
4850
| (typeof ACTOR_JOB_STATUSES)[keyof typeof ACTOR_JOB_STATUSES][];
51+
startedBefore?: string;
52+
startedAfter?: string;
4953
}

test/runs.test.js

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,47 @@ describe('Run methods', () => {
7070
expect(browserRes).toEqual(res);
7171
validateRequest(expectedQuery);
7272
});
73+
74+
test('list() allows startedBefore and startedAfter to be passed as Date object', async () => {
75+
const now = new Date();
76+
const query = {
77+
startedBefore: now,
78+
startedAfter: now,
79+
};
80+
81+
const expectedQuery = {
82+
startedBefore: now.toISOString(),
83+
startedAfter: now.toISOString(),
84+
};
85+
86+
const res = await client.runs().list(query);
87+
expect(res.id).toEqual('list-runs');
88+
validateRequest(expectedQuery);
89+
90+
const browserRes = await page.evaluate((opts) => client.runs().list(opts), query);
91+
expect(browserRes).toEqual(res);
92+
validateRequest(expectedQuery);
93+
});
94+
95+
test('list() allows startedBefore and startedAfter to be passed as string', async () => {
96+
const now = new Date();
97+
const query = {
98+
startedBefore: now.toISOString(),
99+
startedAfter: now.toISOString(),
100+
};
101+
102+
const expectedQuery = {
103+
...query,
104+
};
105+
106+
const res = await client.runs().list(query);
107+
expect(res.id).toEqual('list-runs');
108+
validateRequest(expectedQuery);
109+
110+
const browserRes = await page.evaluate((opts) => client.runs().list(opts), query);
111+
expect(browserRes).toEqual(res);
112+
validateRequest(expectedQuery);
113+
});
73114
});
74115

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

0 commit comments

Comments
 (0)