-
Notifications
You must be signed in to change notification settings - Fork 46
Expand file tree
/
Copy pathrun-on-cloud.test.ts
More file actions
57 lines (46 loc) · 1.62 KB
/
run-on-cloud.test.ts
File metadata and controls
57 lines (46 loc) · 1.62 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
import type { ApifyClient } from 'apify-client';
import { runActorOrTaskOnCloud } from '../../../src/lib/commands/run-on-cloud.js';
const fakeClientThatThrows = (error: unknown) =>
({
actor: () => ({
start: async () => {
throw error;
},
}),
}) as unknown as ApifyClient;
const callAndCatch = async (apiError: unknown) => {
const iterator = runActorOrTaskOnCloud(fakeClientThatThrows(apiError), {
actorOrTaskData: { id: 'abc', userFriendlyId: 'apify/test-actor' },
runOptions: {},
type: 'Actor',
silent: true,
});
try {
for await (const _ of iterator) {
// drain
}
} catch (err) {
return err as Error;
}
throw new Error('Expected runActorOrTaskOnCloud to throw');
};
describe('runActorOrTaskOnCloud', () => {
it('surfaces approval URL when Actor requires full account access', async () => {
const approvalUrl = 'https://console.apify.com/actors/abc?approvePermissions=true';
const apiError = Object.assign(new Error('This Actor requires full access to your account.'), {
type: 'full-permission-actor-not-approved',
data: { approvalUrl },
});
const err = await callAndCatch(apiError);
expect(err.message).toMatch(/has not been approved yet/);
expect(err.message).toContain(approvalUrl);
});
it('falls back to bare message when API response has no approvalUrl', async () => {
const apiError = Object.assign(new Error('This Actor requires full access to your account.'), {
type: 'full-permission-actor-not-approved',
});
const err = await callAndCatch(apiError);
expect(err.message).toMatch(/has not been approved yet/);
expect(err.message).not.toMatch(/Approve here/);
});
});