Skip to content

Commit 74966ad

Browse files
committed
test: cover approval-required error branch
1 parent d1628d7 commit 74966ad

1 file changed

Lines changed: 57 additions & 0 deletions

File tree

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

0 commit comments

Comments
 (0)