nango 0.40.0 → 0.40.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cli.d.ts +16 -4
- package/dist/cli.js +46 -50
- package/dist/cli.js.map +1 -1
- package/dist/index.js +29 -19
- package/dist/index.js.map +1 -1
- package/dist/services/compile.service.d.ts +11 -5
- package/dist/services/compile.service.js +51 -36
- package/dist/services/compile.service.js.map +1 -1
- package/dist/services/compile.service.unit.test.js +17 -7
- package/dist/services/compile.service.unit.test.js.map +1 -1
- package/dist/services/config.service.d.ts +1 -1
- package/dist/services/config.service.js +2 -3
- package/dist/services/config.service.js.map +1 -1
- package/dist/services/deploy.service.d.ts +11 -2
- package/dist/services/deploy.service.js +8 -8
- package/dist/services/deploy.service.js.map +1 -1
- package/dist/services/dryrun.service.js +2 -2
- package/dist/services/dryrun.service.js.map +1 -1
- package/dist/services/model.service.d.ts +4 -1
- package/dist/services/model.service.js +13 -6
- package/dist/services/model.service.js.map +1 -1
- package/dist/services/verification.service.d.ts +9 -2
- package/dist/services/verification.service.js +14 -16
- package/dist/services/verification.service.js.map +1 -1
- package/dist/sync.unit.cli-test.js +168 -155
- package/dist/sync.unit.cli-test.js.map +1 -1
- package/dist/templates/nango.yaml +1 -2
- package/package.json +3 -3
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { expect, describe, it,
|
|
1
|
+
import { expect, describe, it, beforeAll } from 'vitest';
|
|
2
2
|
import path from 'path';
|
|
3
|
-
import
|
|
3
|
+
import fs from 'fs';
|
|
4
4
|
import yaml from 'js-yaml';
|
|
5
5
|
import { SyncConfigType } from '@nangohq/shared';
|
|
6
6
|
import { init, generate } from './cli.js';
|
|
@@ -10,37 +10,41 @@ import { compileAllFiles, compileSingleFile, getFileToCompile } from './services
|
|
|
10
10
|
import { getNangoRootPath } from './utils.js';
|
|
11
11
|
import parserService from './services/parser.service.js';
|
|
12
12
|
import { copyDirectoryAndContents } from './tests/helpers.js';
|
|
13
|
+
function getTestDirectory(name) {
|
|
14
|
+
const dir = `/tmp/${name}/nango-integrations/`;
|
|
15
|
+
fs.mkdirSync(dir, { recursive: true });
|
|
16
|
+
fs.rmSync(dir, { recursive: true, force: true });
|
|
17
|
+
return dir;
|
|
18
|
+
}
|
|
13
19
|
describe('generate function tests', () => {
|
|
14
|
-
const testDirectory = './nango-integrations';
|
|
15
20
|
const fixturesPath = './packages/cli/fixtures';
|
|
16
21
|
beforeAll(async () => {
|
|
17
22
|
if (!fs.existsSync('./packages/cli/dist/nango-sync.d.ts')) {
|
|
18
23
|
await fs.promises.writeFile('./packages/cli/dist/nango-sync.d.ts', '', 'utf8');
|
|
19
24
|
}
|
|
20
25
|
});
|
|
21
|
-
afterEach(async () => {
|
|
22
|
-
await fs.promises.rm(testDirectory, { recursive: true, force: true });
|
|
23
|
-
});
|
|
24
26
|
it('should init the expected files in the nango-integrations directory', async () => {
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
expect(fs.existsSync(
|
|
28
|
-
expect(fs.existsSync(
|
|
27
|
+
const dir = getTestDirectory('init');
|
|
28
|
+
await init({ absolutePath: path.resolve(dir, '..'), debug: false });
|
|
29
|
+
expect(fs.existsSync(`${dir}/demo-github-integration/syncs/${exampleSyncName}.ts`)).toBe(true);
|
|
30
|
+
expect(fs.existsSync(`${dir}/.env`)).toBe(true);
|
|
31
|
+
expect(fs.existsSync(`${dir}/nango.yaml`)).toBe(true);
|
|
29
32
|
});
|
|
30
33
|
it('should not overwrite existing integration files', async () => {
|
|
31
|
-
|
|
32
|
-
await
|
|
33
|
-
await fs.promises.writeFile(`${
|
|
34
|
+
const dir = getTestDirectory('overwrite');
|
|
35
|
+
await init({ absolutePath: dir, debug: false });
|
|
36
|
+
await fs.promises.writeFile(`${dir}/${exampleSyncName}.ts`, 'dummy fake content', 'utf8');
|
|
34
37
|
const dummyContent = 'This is dummy content. Do not overwrite!';
|
|
35
|
-
const exampleFilePath = path.join(
|
|
38
|
+
const exampleFilePath = path.join(dir, `${exampleSyncName}.ts`);
|
|
36
39
|
await fs.promises.writeFile(exampleFilePath, dummyContent, 'utf8');
|
|
37
|
-
await init();
|
|
40
|
+
await init({ absolutePath: dir });
|
|
38
41
|
expect(fs.existsSync(exampleFilePath)).toBe(true);
|
|
39
42
|
const fileContentAfterInit = await fs.promises.readFile(exampleFilePath, 'utf8');
|
|
40
43
|
expect(fileContentAfterInit).toBe(dummyContent);
|
|
41
44
|
});
|
|
42
45
|
it('should generate a different sync correctly', async () => {
|
|
43
|
-
|
|
46
|
+
const dir = getTestDirectory('generate');
|
|
47
|
+
await init({ absolutePath: dir });
|
|
44
48
|
const data = {
|
|
45
49
|
integrations: {
|
|
46
50
|
'demo-github-integration': {
|
|
@@ -68,12 +72,13 @@ describe('generate function tests', () => {
|
|
|
68
72
|
}
|
|
69
73
|
};
|
|
70
74
|
const yamlData = yaml.dump(data);
|
|
71
|
-
await fs.promises.writeFile(`${
|
|
72
|
-
await generate(false,
|
|
73
|
-
expect(fs.existsSync(`${
|
|
75
|
+
await fs.promises.writeFile(`${dir}/nango.yaml`, yamlData, 'utf8');
|
|
76
|
+
await generate({ debug: false, fullPath: dir });
|
|
77
|
+
expect(fs.existsSync(`${dir}/some-other-sync.ts`)).toBe(true);
|
|
74
78
|
});
|
|
75
79
|
it('should support a single model return in v1 format', async () => {
|
|
76
|
-
|
|
80
|
+
const dir = getTestDirectory('single-model-v1');
|
|
81
|
+
await init({ absolutePath: dir });
|
|
77
82
|
const data = {
|
|
78
83
|
integrations: {
|
|
79
84
|
'demo-github-integration': {
|
|
@@ -101,20 +106,20 @@ describe('generate function tests', () => {
|
|
|
101
106
|
}
|
|
102
107
|
};
|
|
103
108
|
const yamlData = yaml.dump(data);
|
|
104
|
-
await fs.promises.writeFile(`${
|
|
105
|
-
await generate(false,
|
|
106
|
-
expect(fs.existsSync(`${
|
|
109
|
+
await fs.promises.writeFile(`${dir}/nango.yaml`, yamlData, 'utf8');
|
|
110
|
+
await generate({ debug: false, fullPath: dir });
|
|
111
|
+
expect(fs.existsSync(`${dir}/single-model-return.ts`)).toBe(true);
|
|
107
112
|
});
|
|
108
113
|
it('should support a single model return in v2 format', async () => {
|
|
109
|
-
|
|
114
|
+
const dir = getTestDirectory('single-model-v2');
|
|
115
|
+
await init({ absolutePath: dir });
|
|
110
116
|
const data = {
|
|
111
117
|
integrations: {
|
|
112
118
|
'demo-github-integration': {
|
|
113
119
|
syncs: {
|
|
114
120
|
'single-model-return': {
|
|
115
|
-
type: 'sync',
|
|
116
121
|
runs: 'every half hour',
|
|
117
|
-
endpoint: '/issues',
|
|
122
|
+
endpoint: 'GET /issues',
|
|
118
123
|
output: 'GithubIssue'
|
|
119
124
|
}
|
|
120
125
|
}
|
|
@@ -137,12 +142,13 @@ describe('generate function tests', () => {
|
|
|
137
142
|
}
|
|
138
143
|
};
|
|
139
144
|
const yamlData = yaml.dump(data);
|
|
140
|
-
await fs.promises.writeFile(`${
|
|
141
|
-
await generate(false,
|
|
142
|
-
expect(fs.existsSync(`${
|
|
145
|
+
await fs.promises.writeFile(`${dir}/nango.yaml`, yamlData, 'utf8');
|
|
146
|
+
await generate({ debug: false, fullPath: dir });
|
|
147
|
+
expect(fs.existsSync(`${dir}/demo-github-integration/syncs/single-model-return.ts`)).toBe(true);
|
|
143
148
|
});
|
|
144
149
|
it('should not create a file if endpoint is missing from a v2 config', async () => {
|
|
145
|
-
|
|
150
|
+
const dir = getTestDirectory('endpoint-missing-v2');
|
|
151
|
+
await init({ absolutePath: dir });
|
|
146
152
|
const data = {
|
|
147
153
|
integrations: {
|
|
148
154
|
'demo-github-integration': {
|
|
@@ -172,17 +178,17 @@ describe('generate function tests', () => {
|
|
|
172
178
|
}
|
|
173
179
|
};
|
|
174
180
|
const yamlData = yaml.dump(data);
|
|
175
|
-
await fs.promises.writeFile(`${
|
|
176
|
-
expect(fs.existsSync(`${
|
|
181
|
+
await fs.promises.writeFile(`${dir}/nango.yaml`, yamlData, 'utf8');
|
|
182
|
+
expect(fs.existsSync(`${dir}/demo-github-integration/syncs/single-model-return.ts`)).toBe(false);
|
|
177
183
|
});
|
|
178
184
|
it('should generate missing from a v2 config', async () => {
|
|
179
|
-
|
|
185
|
+
const dir = getTestDirectory('v2-incremental-compile');
|
|
186
|
+
await init({ absolutePath: dir });
|
|
180
187
|
const data = {
|
|
181
188
|
integrations: {
|
|
182
189
|
'demo-github-integration': {
|
|
183
190
|
syncs: {
|
|
184
191
|
'single-model-issue-output': {
|
|
185
|
-
type: 'sync',
|
|
186
192
|
runs: 'every half hour',
|
|
187
193
|
endpoint: 'GET /tickets/issue',
|
|
188
194
|
output: 'GithubIssue'
|
|
@@ -207,12 +213,13 @@ describe('generate function tests', () => {
|
|
|
207
213
|
}
|
|
208
214
|
};
|
|
209
215
|
const yamlData = yaml.dump(data);
|
|
210
|
-
await fs.promises.writeFile(`${
|
|
211
|
-
await generate(false,
|
|
212
|
-
expect(fs.existsSync(`${
|
|
216
|
+
await fs.promises.writeFile(`${dir}/nango.yaml`, yamlData, 'utf8');
|
|
217
|
+
await generate({ debug: false, fullPath: dir });
|
|
218
|
+
expect(fs.existsSync(`${dir}/demo-github-integration/syncs/single-model-issue-output.ts`)).toBe(true);
|
|
213
219
|
});
|
|
214
220
|
it('should throw an error if a model is missing an id that is actively used', async () => {
|
|
215
|
-
|
|
221
|
+
const dir = getTestDirectory('missing-id');
|
|
222
|
+
await init({ absolutePath: dir });
|
|
216
223
|
const data = {
|
|
217
224
|
integrations: {
|
|
218
225
|
'demo-github-integration': {
|
|
@@ -239,11 +246,12 @@ describe('generate function tests', () => {
|
|
|
239
246
|
}
|
|
240
247
|
};
|
|
241
248
|
const yamlData = yaml.dump(data);
|
|
242
|
-
await fs.promises.writeFile(`${
|
|
243
|
-
await expect(generate(false,
|
|
249
|
+
await fs.promises.writeFile(`${dir}/nango.yaml`, yamlData, 'utf8');
|
|
250
|
+
await expect(generate({ debug: false, fullPath: dir })).rejects.toThrow(`Model "GithubIssue" doesn't have an id field. This is required to be able to uniquely identify the data record.`);
|
|
244
251
|
});
|
|
245
|
-
it('should allow models to end
|
|
246
|
-
|
|
252
|
+
it('should allow models to end with an "s"', async () => {
|
|
253
|
+
const dir = getTestDirectory('model-with-an-s');
|
|
254
|
+
await init({ absolutePath: dir });
|
|
247
255
|
const data = {
|
|
248
256
|
integrations: {
|
|
249
257
|
'demo-github-integration': {
|
|
@@ -271,13 +279,14 @@ describe('generate function tests', () => {
|
|
|
271
279
|
}
|
|
272
280
|
};
|
|
273
281
|
const yamlData = yaml.dump(data);
|
|
274
|
-
await fs.promises.writeFile(`${
|
|
275
|
-
await generate(false,
|
|
276
|
-
const modelsFile = await fs.promises.readFile(`${
|
|
282
|
+
await fs.promises.writeFile(`${dir}/nango.yaml`, yamlData, 'utf8');
|
|
283
|
+
await generate({ debug: false, fullPath: dir });
|
|
284
|
+
const modelsFile = await fs.promises.readFile(`${dir}/models.ts`, 'utf8');
|
|
277
285
|
expect(modelsFile).toContain('export interface GithubIssues');
|
|
278
286
|
});
|
|
279
287
|
it('should not throw an error if a model is missing an id for an action', async () => {
|
|
280
|
-
|
|
288
|
+
const dir = getTestDirectory('missing-id-action');
|
|
289
|
+
await init({ absolutePath: dir });
|
|
281
290
|
const data = {
|
|
282
291
|
integrations: {
|
|
283
292
|
'demo-github-integration': {
|
|
@@ -303,11 +312,12 @@ describe('generate function tests', () => {
|
|
|
303
312
|
}
|
|
304
313
|
};
|
|
305
314
|
const yamlData = yaml.dump(data);
|
|
306
|
-
await fs.promises.writeFile(`${
|
|
307
|
-
await generate(false,
|
|
315
|
+
await fs.promises.writeFile(`${dir}/nango.yaml`, yamlData, 'utf8');
|
|
316
|
+
await generate({ debug: false, fullPath: dir });
|
|
308
317
|
});
|
|
309
318
|
it('should allow javascript primitives as a return type with no model', async () => {
|
|
310
|
-
|
|
319
|
+
const dir = getTestDirectory('model-returns-primitives');
|
|
320
|
+
await init({ absolutePath: dir });
|
|
311
321
|
const data = {
|
|
312
322
|
integrations: {
|
|
313
323
|
'demo-github-integration': {
|
|
@@ -323,11 +333,12 @@ describe('generate function tests', () => {
|
|
|
323
333
|
}
|
|
324
334
|
};
|
|
325
335
|
const yamlData = yaml.dump(data);
|
|
326
|
-
await fs.promises.writeFile(`${
|
|
327
|
-
await generate(false,
|
|
336
|
+
await fs.promises.writeFile(`${dir}/nango.yaml`, yamlData, 'utf8');
|
|
337
|
+
await generate({ debug: false, fullPath: dir });
|
|
328
338
|
});
|
|
329
339
|
it('should catch non javascript primitives in the config', async () => {
|
|
330
|
-
|
|
340
|
+
const dir = getTestDirectory('model-returns-invalid-primitives');
|
|
341
|
+
await init({ absolutePath: dir });
|
|
331
342
|
const data = {
|
|
332
343
|
integrations: {
|
|
333
344
|
'demo-github-integration': {
|
|
@@ -343,8 +354,8 @@ describe('generate function tests', () => {
|
|
|
343
354
|
}
|
|
344
355
|
};
|
|
345
356
|
const yamlData = yaml.dump(data);
|
|
346
|
-
await fs.promises.writeFile(`${
|
|
347
|
-
expect(await generate(false,
|
|
357
|
+
await fs.promises.writeFile(`${dir}/nango.yaml`, yamlData, 'utf8');
|
|
358
|
+
expect(await generate({ debug: false, fullPath: dir })).toBeUndefined();
|
|
348
359
|
});
|
|
349
360
|
it('should not complain of try catch not being awaited', () => {
|
|
350
361
|
const awaiting = parserService.callsAreUsedCorrectly(`${fixturesPath}/sync.ts`, SyncConfigType.SYNC, ['GithubIssue']);
|
|
@@ -392,14 +403,16 @@ describe('generate function tests', () => {
|
|
|
392
403
|
expect(config).toMatchSnapshot();
|
|
393
404
|
});
|
|
394
405
|
it('v1 - should complain about commas at the end of declared types', async () => {
|
|
395
|
-
|
|
396
|
-
await
|
|
397
|
-
|
|
406
|
+
const dir = getTestDirectory('v1-no-commas');
|
|
407
|
+
await init({ absolutePath: dir });
|
|
408
|
+
await fs.promises.copyFile(`${fixturesPath}/nango-yaml/v1/no-commas/nango.yaml`, `${dir}/nango.yaml`);
|
|
409
|
+
await expect(generate({ debug: false, fullPath: dir })).rejects.toThrow(`Field "integer," in the model GithubIssue ends with a comma or semicolon which is not allowed.`);
|
|
398
410
|
});
|
|
399
411
|
it('v1 - should complain about semi colons at the end of declared types', async () => {
|
|
400
|
-
|
|
401
|
-
await
|
|
402
|
-
|
|
412
|
+
const dir = getTestDirectory('v1-no-semi-colons');
|
|
413
|
+
await init({ absolutePath: dir });
|
|
414
|
+
await fs.promises.copyFile(`${fixturesPath}/nango-yaml/v1/no-semi-colons/nango.yaml`, `${dir}/nango.yaml`);
|
|
415
|
+
await expect(generate({ debug: false, fullPath: dir })).rejects.toThrow(`Field "integer;" in the model GithubIssue ends with a comma or semicolon which is not allowed.`);
|
|
403
416
|
});
|
|
404
417
|
it('should parse a nango.yaml file that is version 2 as expected', async () => {
|
|
405
418
|
const { response: config } = await configService.load(path.resolve(__dirname, `../fixtures/nango-yaml/v2/valid`));
|
|
@@ -410,7 +423,7 @@ describe('generate function tests', () => {
|
|
|
410
423
|
const { response: config, error } = await configService.load(path.resolve(__dirname, `../fixtures/nango-yaml/v2/invalid.1`));
|
|
411
424
|
expect(config).toBeNull();
|
|
412
425
|
expect(error).toBeDefined();
|
|
413
|
-
expect(error?.message).
|
|
426
|
+
expect(error?.message).toMatchSnapshot();
|
|
414
427
|
});
|
|
415
428
|
it('should throw a validation error on a nango.yaml file that is not formatted correctly -- webhook subscriptions are not allowed in an action', async () => {
|
|
416
429
|
const { response: config, error } = await configService.load(path.resolve(__dirname, `../fixtures/nango-yaml/v2/invalid.2`));
|
|
@@ -419,32 +432,36 @@ describe('generate function tests', () => {
|
|
|
419
432
|
expect(error?.message).toEqual('Problem validating the nango.yaml file.');
|
|
420
433
|
});
|
|
421
434
|
it('should correctly interpret a string union literal type', async () => {
|
|
422
|
-
|
|
423
|
-
await
|
|
424
|
-
|
|
425
|
-
|
|
435
|
+
const dir = getTestDirectory('validation-string-union');
|
|
436
|
+
await init({ absolutePath: dir });
|
|
437
|
+
await fs.promises.copyFile(`${fixturesPath}/nango-yaml/v2/string-literal/nango.yaml`, `${dir}/nango.yaml`);
|
|
438
|
+
await expect(generate({ debug: false, fullPath: dir })).resolves.toBeUndefined();
|
|
439
|
+
const modelsFile = await fs.promises.readFile(`${dir}/models.ts`, 'utf8');
|
|
426
440
|
expect(modelsFile).toContain(`gender: 'male' | 'female';`);
|
|
427
441
|
});
|
|
428
442
|
it('should correctly interpret a union literal type with a string and a primitive', async () => {
|
|
429
|
-
|
|
430
|
-
await
|
|
431
|
-
|
|
432
|
-
|
|
443
|
+
const dir = getTestDirectory('validation-string-primitve');
|
|
444
|
+
await init({ absolutePath: dir });
|
|
445
|
+
await fs.promises.copyFile(`${fixturesPath}/nango-yaml/v2/mixed-literal/nango.yaml`, `${dir}/nango.yaml`);
|
|
446
|
+
await expect(generate({ debug: false, fullPath: dir })).resolves.toBeUndefined();
|
|
447
|
+
const modelsFile = await fs.promises.readFile(`${dir}/models.ts`, 'utf8');
|
|
433
448
|
expect(modelsFile).toContain(`gender: 'male' | null;`);
|
|
434
449
|
});
|
|
435
450
|
it('should correctly interpret a union literal type with a string and a model', async () => {
|
|
436
|
-
|
|
437
|
-
await
|
|
438
|
-
|
|
439
|
-
|
|
451
|
+
const dir = getTestDirectory('validation-string-model');
|
|
452
|
+
await init({ absolutePath: dir });
|
|
453
|
+
await fs.promises.copyFile(`${fixturesPath}/nango-yaml/v2/mixed-literal-model/nango.yaml`, `${dir}/nango.yaml`);
|
|
454
|
+
await expect(generate({ debug: false, fullPath: dir })).resolves.toBeUndefined();
|
|
455
|
+
const modelsFile = await fs.promises.readFile(`${dir}/models.ts`, 'utf8');
|
|
440
456
|
expect(modelsFile).toContain(`gender: 'male' | Other`);
|
|
441
457
|
expect(modelsFile).toContain(`user: User | Account`);
|
|
442
458
|
});
|
|
443
459
|
it('should correctly interpret a union types, array types, and record types', async () => {
|
|
444
|
-
|
|
445
|
-
await
|
|
446
|
-
|
|
447
|
-
|
|
460
|
+
const dir = getTestDirectory('validation-array-records');
|
|
461
|
+
await init({ absolutePath: dir });
|
|
462
|
+
await fs.promises.copyFile(`${fixturesPath}/nango-yaml/v2/mixed-types/nango.yaml`, `${dir}/nango.yaml`);
|
|
463
|
+
await expect(generate({ debug: false, fullPath: dir })).resolves.toBeUndefined();
|
|
464
|
+
const modelsFile = await fs.promises.readFile(`${dir}/models.ts`, 'utf8');
|
|
448
465
|
expect(modelsFile).toContain(`record: Record<string, string>;`);
|
|
449
466
|
expect(modelsFile).toContain(`und: string | null | undefined;`);
|
|
450
467
|
expect(modelsFile).toContain(`def: 'male' | string | null | undefined;`);
|
|
@@ -452,112 +469,108 @@ describe('generate function tests', () => {
|
|
|
452
469
|
expect(modelsFile).toContain(`nullableDate: Date | null;`);
|
|
453
470
|
});
|
|
454
471
|
it('should correctly interpret a union type with an array model', async () => {
|
|
455
|
-
|
|
456
|
-
await
|
|
457
|
-
|
|
458
|
-
|
|
472
|
+
const dir = getTestDirectory('validation-array-model');
|
|
473
|
+
await init({ absolutePath: dir });
|
|
474
|
+
await fs.promises.copyFile(`${fixturesPath}/nango-yaml/v2/model-array-types/nango.yaml`, `${dir}/nango.yaml`);
|
|
475
|
+
await expect(generate({ debug: false, fullPath: dir })).resolves.toBeUndefined();
|
|
476
|
+
const modelsFile = await fs.promises.readFile(`${dir}/models.ts`, 'utf8');
|
|
459
477
|
expect(modelsFile).not.toContain(`'Other[]' | null | undefined;`);
|
|
460
478
|
expect(modelsFile).toContain(`Other[] | null | undefined;`);
|
|
461
479
|
});
|
|
462
480
|
it('should be able to compile files in nested directories', async () => {
|
|
463
|
-
|
|
464
|
-
await
|
|
465
|
-
await copyDirectoryAndContents(`${fixturesPath}/nango-yaml/v2/nested-integrations/hubspot`,
|
|
466
|
-
await copyDirectoryAndContents(`${fixturesPath}/nango-yaml/v2/nested-integrations/github`,
|
|
467
|
-
await fs.promises.copyFile(`${fixturesPath}/nango-yaml/v2/nested-integrations/nango.yaml`,
|
|
468
|
-
const success = await compileAllFiles({ debug: true });
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
await fs.promises.rm('./models.ts', { force: true });
|
|
481
|
+
const dir = getTestDirectory('nested');
|
|
482
|
+
await init({ absolutePath: dir });
|
|
483
|
+
await copyDirectoryAndContents(`${fixturesPath}/nango-yaml/v2/nested-integrations/hubspot`, `${dir}/hubspot`);
|
|
484
|
+
await copyDirectoryAndContents(`${fixturesPath}/nango-yaml/v2/nested-integrations/github`, `${dir}/github`);
|
|
485
|
+
await fs.promises.copyFile(`${fixturesPath}/nango-yaml/v2/nested-integrations/nango.yaml`, `${dir}/nango.yaml`);
|
|
486
|
+
const success = await compileAllFiles({ fullPath: dir, debug: true });
|
|
487
|
+
expect(fs.existsSync(path.join(dir, 'models.ts'))).toBe(true);
|
|
488
|
+
expect(fs.existsSync(path.join(dir, 'hubspot/syncs/contacts.ts'))).toBe(true);
|
|
489
|
+
expect(fs.existsSync(path.join(dir, 'dist/contacts-hubspot.js'))).toBe(true);
|
|
490
|
+
expect(fs.existsSync(path.join(dir, 'dist/issues-github.js'))).toBe(true);
|
|
474
491
|
expect(success).toBe(true);
|
|
475
492
|
});
|
|
476
493
|
it('should be backwards compatible with the single directory for integration files', async () => {
|
|
477
|
-
|
|
478
|
-
await
|
|
479
|
-
await copyDirectoryAndContents(`${fixturesPath}/nango-yaml/v2/non-nested-integrations`,
|
|
480
|
-
const success = await compileAllFiles({ debug:
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
await fs.promises.rm('./contacts.ts', { force: true });
|
|
485
|
-
await fs.promises.rm('./create-contact.ts', { force: true });
|
|
486
|
-
await fs.promises.rm('./create-issue.ts', { force: true });
|
|
487
|
-
await fs.promises.rm('./issues.ts', { force: true });
|
|
494
|
+
const dir = getTestDirectory('old-directory');
|
|
495
|
+
await init({ absolutePath: dir });
|
|
496
|
+
await copyDirectoryAndContents(`${fixturesPath}/nango-yaml/v2/non-nested-integrations`, dir);
|
|
497
|
+
const success = await compileAllFiles({ fullPath: dir, debug: false });
|
|
498
|
+
expect(fs.existsSync(path.join(dir, 'models.ts'))).toBe(true);
|
|
499
|
+
expect(fs.existsSync(path.join(dir, 'contacts.ts'))).toBe(true);
|
|
500
|
+
expect(fs.existsSync(path.join(dir, 'dist/contacts-hubspot.js'))).toBe(true);
|
|
488
501
|
expect(success).toBe(true);
|
|
489
502
|
});
|
|
490
503
|
it('should be able to compile and run imported files', async () => {
|
|
491
|
-
|
|
492
|
-
await
|
|
493
|
-
await copyDirectoryAndContents(`${fixturesPath}/nango-yaml/v2/relative-imports/github`,
|
|
494
|
-
await fs.promises.copyFile(`${fixturesPath}/nango-yaml/v2/relative-imports/nango.yaml`,
|
|
495
|
-
const success = await compileAllFiles({ debug:
|
|
496
|
-
|
|
497
|
-
const module = await import('./dist/issues.cjs');
|
|
504
|
+
const dir = getTestDirectory('relative-imports');
|
|
505
|
+
await init({ absolutePath: dir });
|
|
506
|
+
await copyDirectoryAndContents(`${fixturesPath}/nango-yaml/v2/relative-imports/github`, `${dir}/github`);
|
|
507
|
+
await fs.promises.copyFile(`${fixturesPath}/nango-yaml/v2/relative-imports/nango.yaml`, `${dir}/nango.yaml`);
|
|
508
|
+
const success = await compileAllFiles({ fullPath: dir, debug: false });
|
|
509
|
+
const module = await import(`${dir}dist/issues-github.js`);
|
|
498
510
|
const result = module.default.default();
|
|
499
511
|
expect(result).toBe('Hello, world!');
|
|
500
|
-
await fs.promises.rm('./github', { recursive: true, force: true });
|
|
501
|
-
await fs.promises.rm('./dist', { recursive: true, force: true });
|
|
502
|
-
await fs.promises.rm('./nango.yaml', { force: true });
|
|
503
|
-
await fs.promises.rm('./models.ts', { force: true });
|
|
504
512
|
expect(success).toBe(true);
|
|
505
513
|
});
|
|
506
514
|
it('should compile helper functions and throw an error if there is a complication error with an imported file', async () => {
|
|
507
515
|
const name = 'relative-imports-with-error';
|
|
508
|
-
|
|
509
|
-
await
|
|
510
|
-
await copyDirectoryAndContents(`${fixturesPath}/nango-yaml/v2/${name}/github`,
|
|
511
|
-
await fs.promises.copyFile(`${fixturesPath}/nango-yaml/v2/${name}/nango.yaml`,
|
|
516
|
+
const dir = getTestDirectory('relative-imports-with-error');
|
|
517
|
+
await init({ absolutePath: dir });
|
|
518
|
+
await copyDirectoryAndContents(`${fixturesPath}/nango-yaml/v2/${name}/github`, `${dir}/github`);
|
|
519
|
+
await fs.promises.copyFile(`${fixturesPath}/nango-yaml/v2/${name}/nango.yaml`, `${dir}/nango.yaml`);
|
|
512
520
|
const tsconfig = fs.readFileSync(`${getNangoRootPath()}/tsconfig.dev.json`, 'utf8');
|
|
513
521
|
const { response: config } = await configService.load(path.resolve(`${fixturesPath}/nango-yaml/v2/${name}`));
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
522
|
+
expect(config).not.toBeNull();
|
|
523
|
+
const modelNames = configService.getModelNames(config);
|
|
524
|
+
const result = await compileSingleFile({
|
|
525
|
+
fullPath: dir,
|
|
526
|
+
file: getFileToCompile({ fullPath: dir, filePath: path.join(dir, './github/actions/gh-issues.ts') }),
|
|
527
|
+
tsconfig,
|
|
528
|
+
config: config,
|
|
529
|
+
modelNames,
|
|
530
|
+
debug: false
|
|
531
|
+
});
|
|
532
|
+
expect(result).toBe(false);
|
|
523
533
|
});
|
|
524
534
|
it('should complain if a nango call is used incorrectly in a nested file', async () => {
|
|
525
535
|
const name = 'relative-imports-with-nango-misuse';
|
|
526
|
-
|
|
527
|
-
await
|
|
528
|
-
await copyDirectoryAndContents(`${fixturesPath}/nango-yaml/v2/${name}/github`,
|
|
529
|
-
await fs.promises.copyFile(`${fixturesPath}/nango-yaml/v2/${name}/nango.yaml`,
|
|
536
|
+
const dir = getTestDirectory('relative-imports-with-nango-misuse');
|
|
537
|
+
await init({ absolutePath: dir });
|
|
538
|
+
await copyDirectoryAndContents(`${fixturesPath}/nango-yaml/v2/${name}/github`, `${dir}/github`);
|
|
539
|
+
await fs.promises.copyFile(`${fixturesPath}/nango-yaml/v2/${name}/nango.yaml`, `${dir}/nango.yaml`);
|
|
530
540
|
const tsconfig = fs.readFileSync(`${getNangoRootPath()}/tsconfig.dev.json`, 'utf8');
|
|
531
541
|
const { response: config } = await configService.load(path.resolve(`${fixturesPath}/nango-yaml/v2/${name}`));
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
542
|
+
expect(config).not.toBeNull();
|
|
543
|
+
const modelNames = configService.getModelNames(config);
|
|
544
|
+
const result = await compileSingleFile({
|
|
545
|
+
fullPath: dir,
|
|
546
|
+
file: getFileToCompile({ fullPath: dir, filePath: path.join(dir, './github/actions/gh-issues.ts') }),
|
|
547
|
+
tsconfig,
|
|
548
|
+
config: config,
|
|
549
|
+
modelNames,
|
|
550
|
+
debug: false
|
|
551
|
+
});
|
|
552
|
+
expect(result).toBe(false);
|
|
541
553
|
});
|
|
542
554
|
it('should not allow imports higher than the current directory', async () => {
|
|
543
555
|
const name = 'relative-imports-with-higher-import';
|
|
544
|
-
|
|
545
|
-
await
|
|
546
|
-
await copyDirectoryAndContents(`${fixturesPath}/nango-yaml/v2/${name}/github`,
|
|
547
|
-
await fs.promises.copyFile(`${fixturesPath}/nango-yaml/v2/${name}/nango.yaml`,
|
|
548
|
-
await fs.promises.copyFile(`${fixturesPath}/nango-yaml/v2/${name}/github/actions/welcomer.ts`,
|
|
556
|
+
const dir = getTestDirectory('relative-imports-with-higher-import');
|
|
557
|
+
await init({ absolutePath: dir });
|
|
558
|
+
await copyDirectoryAndContents(`${fixturesPath}/nango-yaml/v2/${name}/github`, `${dir}/github`);
|
|
559
|
+
await fs.promises.copyFile(`${fixturesPath}/nango-yaml/v2/${name}/nango.yaml`, `${dir}/nango.yaml`);
|
|
560
|
+
await fs.promises.copyFile(`${fixturesPath}/nango-yaml/v2/${name}/github/actions/welcomer.ts`, `${dir}/welcomer.ts`);
|
|
549
561
|
const tsconfig = fs.readFileSync(`${getNangoRootPath()}/tsconfig.dev.json`, 'utf8');
|
|
550
562
|
const { response: config } = await configService.load(path.resolve(`${fixturesPath}/nango-yaml/v2/${name}`));
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
563
|
+
expect(config).not.toBeNull();
|
|
564
|
+
const modelNames = configService.getModelNames(config);
|
|
565
|
+
const result = await compileSingleFile({
|
|
566
|
+
fullPath: dir,
|
|
567
|
+
file: getFileToCompile({ fullPath: dir, filePath: path.join(dir, './github/actions/gh-issues.ts') }),
|
|
568
|
+
tsconfig,
|
|
569
|
+
config: config,
|
|
570
|
+
modelNames,
|
|
571
|
+
debug: false
|
|
572
|
+
});
|
|
573
|
+
expect(result).toBe(false);
|
|
561
574
|
});
|
|
562
575
|
});
|
|
563
576
|
//# sourceMappingURL=sync.unit.cli-test.js.map
|