-
Notifications
You must be signed in to change notification settings - Fork 17
Expand file tree
/
Copy pathhandler.test.ts
More file actions
80 lines (66 loc) · 1.96 KB
/
handler.test.ts
File metadata and controls
80 lines (66 loc) · 1.96 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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
import test from 'ava';
import mockfs from 'mock-fs';
import fs from 'node:fs';
import { MockAgent, setGlobalDispatcher } from 'undici';
import { createMockLogger } from '@openfn/logger';
import pullHandler from '../../src/pull/handler';
import { PullOptions } from '../../src/pull/command';
import { myProject_v1 } from '../projects/fixtures';
const ENDPOINT = 'https://app.openfn.org';
const PROJECT_UUID = 'e16c5f09-f0cb-4ba7-a4c2-73fcb2f29d00';
test.beforeEach(() => {
mockfs.restore();
});
test.afterEach(() => {
mockfs.restore();
});
let mockAgent = new MockAgent();
mockAgent.disableNetConnect();
setGlobalDispatcher(mockAgent);
test.before(() => {
const mockPool = mockAgent.get(ENDPOINT);
mockPool
.intercept({
path: `/api/provision/${PROJECT_UUID}?`,
method: 'GET',
})
.reply(200, {
data: myProject_v1,
})
.persist();
});
const options: PullOptions = {
beta: false,
command: 'pull',
configPath: '/tmp/config.json',
projectId: PROJECT_UUID,
confirm: false,
snapshots: [],
workspace: '/tmp', // needed in tests to drive other paths
};
test.serial(
'redirects to beta handler when openfn.yaml exists in cwd',
async (t) => {
const logger = createMockLogger('', { level: 'debug' });
mockfs({
['/tmp/config.json']: `{"apiKey": "123", "endpoint": "${ENDPOINT}"}`,
['/tmp/openfn.yaml']: `
project:
endpoint: ${ENDPOINT}`,
});
await pullHandler(options, logger);
t.true(fs.existsSync('/tmp/.projects/main@app.openfn.org.yaml'));
t.truthy(logger._find('always', /Detected openfn.yaml file/i));
}
);
test.serial('does not create credentials.yaml when redirecting', async (t) => {
const logger = createMockLogger('', { level: 'debug' });
mockfs({
['/tmp/config.json']: `{"apiKey": "123", "endpoint": "${ENDPOINT}"}`,
['/tmp/openfn.yaml']: `
project:
endpoint: ${ENDPOINT}`,
});
await pullHandler(options, logger);
t.false(fs.existsSync('/tmp/credentials.yaml'));
});