@friggframework/devtools 2.0.0--canary.702.ef0dc8c.0 → 2.0.0--canary.710.7cfcf12.0

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.
Files changed (86) hide show
  1. package/README.md +0 -1
  2. package/frigg-cli/README.md +78 -76
  3. package/frigg-cli/__tests__/unit/commands/build.test.js +0 -3
  4. package/frigg-cli/__tests__/unit/commands/deploy.test.js +30 -27
  5. package/frigg-cli/__tests__/unit/commands/doctor.test.js +10 -6
  6. package/frigg-cli/__tests__/unit/commands/generate-iam.test.js +18 -0
  7. package/frigg-cli/__tests__/unit/commands/init.test.js +688 -0
  8. package/frigg-cli/__tests__/unit/commands/install.test.js +601 -341
  9. package/frigg-cli/__tests__/unit/commands/ui.test.js +31 -30
  10. package/frigg-cli/__tests__/unit/dependencies.test.js +6 -2
  11. package/frigg-cli/build-command/index.js +0 -6
  12. package/frigg-cli/deploy-command/index.js +0 -6
  13. package/frigg-cli/generate-command/index.js +1 -0
  14. package/frigg-cli/generate-iam-command.js +1 -0
  15. package/frigg-cli/index.js +10 -23
  16. package/frigg-cli/init-command/backend-first-handler.js +395 -531
  17. package/frigg-cli/init-command/deployment-modes.js +7 -0
  18. package/frigg-cli/init-command/index.js +82 -35
  19. package/frigg-cli/init-command/safe-path.js +58 -0
  20. package/frigg-cli/init-command/scaffold-dependencies.js +202 -0
  21. package/frigg-cli/install-command/app-definition.js +174 -0
  22. package/frigg-cli/install-command/commit-changes.js +40 -8
  23. package/frigg-cli/install-command/environment-variables.js +15 -0
  24. package/frigg-cli/install-command/index.js +96 -21
  25. package/frigg-cli/install-command/install-package.js +77 -4
  26. package/frigg-cli/install-command/integration-file.js +20 -11
  27. package/frigg-cli/install-command/resolve-module.js +69 -0
  28. package/frigg-cli/install-command/template.js +102 -75
  29. package/frigg-cli/install-command/validate-package.js +36 -4
  30. package/frigg-cli/package.json +1 -1
  31. package/frigg-cli/start-command/index.js +0 -4
  32. package/frigg-cli/start-command/start-command.test.js +0 -3
  33. package/frigg-cli/templates/backend/README.md +267 -0
  34. package/frigg-cli/templates/backend/env.example +20 -0
  35. package/frigg-cli/templates/backend/gitignore +10 -0
  36. package/frigg-cli/templates/backend/index.js +114 -0
  37. package/frigg-cli/templates/backend/infrastructure.js +20 -0
  38. package/frigg-cli/test/init-command.test.js +9 -2
  39. package/infrastructure/__tests__/postgres-config.test.js +241 -835
  40. package/infrastructure/__tests__/scaffold-default-infrastructure.test.js +148 -0
  41. package/infrastructure/__tests__/template-generation.test.js +36 -8
  42. package/infrastructure/create-frigg-infrastructure.js +1 -4
  43. package/infrastructure/docs/POSTGRES-CONFIGURATION.md +118 -60
  44. package/infrastructure/domains/database/aurora-builder.js +13 -2
  45. package/infrastructure/domains/database/aurora-builder.test.js +22 -0
  46. package/infrastructure/domains/health/application/use-cases/__tests__/mismatch-analyzer-method-name.test.js +12 -8
  47. package/infrastructure/domains/health/application/use-cases/__tests__/repair-via-import-use-case.test.js +19 -7
  48. package/infrastructure/domains/health/application/use-cases/run-health-check-use-case.test.js +12 -8
  49. package/infrastructure/domains/health/domain/services/__tests__/import-progress-monitor.test.js +17 -18
  50. package/infrastructure/domains/health/domain/services/__tests__/update-progress-monitor.test.js +12 -2
  51. package/infrastructure/domains/health/infrastructure/adapters/__tests__/orphan-detection-relationship-analysis.test.js +8 -1
  52. package/infrastructure/domains/health/infrastructure/adapters/aws-property-reconciler.test.js +4 -2
  53. package/infrastructure/domains/health/infrastructure/adapters/aws-resource-detector.test.js +10 -0
  54. package/infrastructure/domains/networking/vpc-builder.js +18 -8
  55. package/infrastructure/domains/networking/vpc-builder.test.js +26 -12
  56. package/infrastructure/domains/security/iam-generator.js +112 -5
  57. package/infrastructure/domains/security/iam-generator.test.js +94 -0
  58. package/infrastructure/domains/shared/cloudformation-discovery.test.js +36 -6
  59. package/infrastructure/domains/shared/utilities/base-definition-factory.js +7 -2
  60. package/infrastructure/domains/shared/utilities/base-definition-factory.test.js +21 -0
  61. package/infrastructure/infrastructure-composer.test.js +268 -794
  62. package/infrastructure/scripts/build-prisma-layer.test.js +28 -7
  63. package/infrastructure/scripts/build-time-discovery.test.js +18 -3
  64. package/package.json +10 -8
  65. package/frigg-cli/__tests__/unit/commands/validate-wiring.test.js +0 -92
  66. package/frigg-cli/index.test.js +0 -158
  67. package/frigg-cli/validate-command/__tests__/init-validation.test.js +0 -63
  68. package/frigg-cli/validate-command/__tests__/integrations-checks.test.js +0 -133
  69. package/frigg-cli/validate-command/__tests__/validate-app-definition.test.js +0 -326
  70. package/frigg-cli/validate-command/__tests__/validate-command.test.js +0 -241
  71. package/frigg-cli/validate-command/__tests__/validate-module-command.test.js +0 -119
  72. package/frigg-cli/validate-command/checks/config.js +0 -468
  73. package/frigg-cli/validate-command/checks/integrations.js +0 -274
  74. package/frigg-cli/validate-command/fixtures/bad-module/index.js +0 -18
  75. package/frigg-cli/validate-command/fixtures/fathom-module/definition.js +0 -76
  76. package/frigg-cli/validate-command/fixtures/fathom-module/index.js +0 -6
  77. package/frigg-cli/validate-command/format-report.js +0 -60
  78. package/frigg-cli/validate-command/index.js +0 -151
  79. package/frigg-cli/validate-command/load-app-definition.js +0 -93
  80. package/frigg-cli/validate-command/load-module-definition.js +0 -64
  81. package/frigg-cli/validate-command/schema-issues.js +0 -154
  82. package/frigg-cli/validate-command/validate-app-definition.js +0 -60
  83. package/frigg-cli/validate-command/validate-module-definition.js +0 -46
  84. package/infrastructure/app-definition-schema-contract.test.js +0 -607
  85. package/infrastructure/create-frigg-infrastructure.test.js +0 -51
  86. package/infrastructure/integration.test.js +0 -381
@@ -143,14 +143,35 @@ describe('getMigrationsPackages()', () => {
143
143
  });
144
144
 
145
145
  describe('getMigrationSourcePath()', () => {
146
- it('should return correct source path for database type', () => {
147
- const searchPaths = ['/workspace/packages/core'];
148
- const dbType = 'postgresql';
146
+ // getMigrationSourcePath() returns the first search path whose
147
+ // prisma-<dbType>/migrations directory exists on disk, so the test needs a
148
+ // real directory rather than a made-up absolute path.
149
+ const fs = require('fs');
150
+ const os = require('os');
151
+ const path = require('path');
152
+ let tmpRoot;
153
+
154
+ beforeEach(() => {
155
+ tmpRoot = fs.mkdtempSync(path.join(os.tmpdir(), 'frigg-prisma-layer-'));
156
+ });
149
157
 
150
- const sourcePath = getMigrationSourcePath(searchPaths, dbType);
151
- expect(sourcePath).toBe(
152
- '/workspace/packages/core/prisma-postgresql/migrations'
153
- );
158
+ afterEach(() => {
159
+ fs.rmSync(tmpRoot, { recursive: true, force: true });
160
+ });
161
+
162
+ it('should return the migrations path of the first search path that has one', () => {
163
+ const missing = path.join(tmpRoot, 'missing');
164
+ const core = path.join(tmpRoot, 'packages', 'core');
165
+ const expected = path.join(core, 'prisma-postgresql', 'migrations');
166
+ fs.mkdirSync(expected, { recursive: true });
167
+
168
+ const sourcePath = getMigrationSourcePath([missing, core], 'postgresql');
169
+ expect(sourcePath).toBe(expected);
170
+ });
171
+
172
+ it('should return null when no search path has migrations for the database type', () => {
173
+ const sourcePath = getMigrationSourcePath([tmpRoot], 'postgresql');
174
+ expect(sourcePath).toBeNull();
154
175
  });
155
176
  });
156
177
 
@@ -1,14 +1,29 @@
1
1
  const fs = require('fs');
2
2
  const path = require('path');
3
- const { BuildTimeDiscovery, runBuildTimeDiscovery } = require('./build-time-discovery');
4
- const { AWSDiscovery } = require('./aws-discovery');
3
+
4
+ // SKIPPED: BuildTimeDiscovery lazily requires './aws-discovery', which was
5
+ // deleted in the hexagonal infrastructure refactor (7b36f0f4). Discovery now
6
+ // lives in domains/shared/resource-discovery.js + providers/aws-provider-adapter.js,
7
+ // and nothing in devtools, the CLI or the serverless plugin invokes
8
+ // build-time-discovery.js / run-discovery.js any more, so this suite cannot load
9
+ // its subject. Either port BuildTimeDiscovery to gatherDiscoveredResources() and
10
+ // rewrite these tests, or delete the dead module and this suite.
11
+ // Tracked in https://github.com/friggframework/frigg/issues/708
12
+ let BuildTimeDiscovery;
13
+ let runBuildTimeDiscovery;
14
+ let AWSDiscovery;
5
15
 
6
16
  // Mock dependencies
7
17
  jest.mock('fs');
8
18
  // Mock will be updated when tests are rewritten for new provider architecture
9
19
  // jest.mock('./aws-discovery');
10
20
 
11
- describe('BuildTimeDiscovery', () => {
21
+ describe.skip('BuildTimeDiscovery', () => {
22
+ beforeAll(() => {
23
+ ({ BuildTimeDiscovery, runBuildTimeDiscovery } = require('./build-time-discovery'));
24
+ ({ AWSDiscovery } = require('./aws-discovery'));
25
+ });
26
+
12
27
  let buildTimeDiscovery;
13
28
  let mockAWSDiscovery;
14
29
  const originalEnv = process.env;
package/package.json CHANGED
@@ -1,12 +1,13 @@
1
1
  {
2
2
  "name": "@friggframework/devtools",
3
3
  "prettier": "@friggframework/prettier-config",
4
- "version": "2.0.0--canary.702.ef0dc8c.0",
4
+ "version": "2.0.0--canary.710.7cfcf12.0",
5
5
  "bin": {
6
6
  "frigg": "./frigg-cli/index.js"
7
7
  },
8
8
  "files": [
9
9
  "frigg-cli/",
10
+ "frigg-cli/templates/",
10
11
  "infrastructure/",
11
12
  "migrations/",
12
13
  "management-ui/dist/",
@@ -18,6 +19,7 @@
18
19
  "@aws-sdk/client-cloudformation": "^3.705.0",
19
20
  "@aws-sdk/client-ec2": "^3.835.0",
20
21
  "@aws-sdk/client-kms": "^3.835.0",
22
+ "@aws-sdk/client-lambda": "^3.714.0",
21
23
  "@aws-sdk/client-rds": "^3.906.0",
22
24
  "@aws-sdk/client-s3": "^3.917.0",
23
25
  "@aws-sdk/client-secrets-manager": "^3.906.0",
@@ -26,9 +28,9 @@
26
28
  "@babel/eslint-parser": "^7.18.9",
27
29
  "@babel/parser": "^7.25.3",
28
30
  "@babel/traverse": "^7.25.3",
29
- "@friggframework/core": "2.0.0--canary.702.ef0dc8c.0",
30
- "@friggframework/schemas": "2.0.0--canary.702.ef0dc8c.0",
31
- "@friggframework/test": "2.0.0--canary.702.ef0dc8c.0",
31
+ "@friggframework/core": "2.0.0--canary.710.7cfcf12.0",
32
+ "@friggframework/schemas": "2.0.0--canary.710.7cfcf12.0",
33
+ "@friggframework/test": "2.0.0--canary.710.7cfcf12.0",
32
34
  "@hapi/boom": "^10.0.1",
33
35
  "@inquirer/prompts": "^5.3.8",
34
36
  "axios": "^1.18.0",
@@ -56,12 +58,12 @@
56
58
  "validate-npm-package-name": "^5.0.0"
57
59
  },
58
60
  "devDependencies": {
59
- "@friggframework/eslint-config": "2.0.0--canary.702.ef0dc8c.0",
60
- "@friggframework/prettier-config": "2.0.0--canary.702.ef0dc8c.0",
61
+ "@friggframework/eslint-config": "2.0.0--canary.710.7cfcf12.0",
62
+ "@friggframework/prettier-config": "2.0.0--canary.710.7cfcf12.0",
61
63
  "aws-sdk-client-mock": "^4.1.0",
62
64
  "aws-sdk-client-mock-jest": "^4.1.0",
63
65
  "jest": "^30.1.3",
64
- "osls": "^3.58.0",
66
+ "osls": "^3.78.0",
65
67
  "prettier": "^2.7.1",
66
68
  "serverless-dotenv-plugin": "^6.0.0",
67
69
  "serverless-esbuild": "^1.54.3",
@@ -89,5 +91,5 @@
89
91
  "publishConfig": {
90
92
  "access": "public"
91
93
  },
92
- "gitHead": "ef0dc8cb6c6f56048a61b6759faad7322046925d"
94
+ "gitHead": "7cfcf1267a412053163b99b7f9a123f7e4e1bde3"
93
95
  }
@@ -1,92 +0,0 @@
1
- /**
2
- * build and deploy validate the app definition first and stop on errors;
3
- * start validates and only warns (ADR-051).
4
- */
5
-
6
- // child_process and node:child_process are one module to jest: one mock.
7
- const mockChildProcess = {
8
- spawnSync: jest.fn(() => ({ status: 0 })),
9
- spawn: jest.fn(),
10
- };
11
- jest.mock('child_process', () => mockChildProcess);
12
- jest.mock('node:child_process', () => mockChildProcess);
13
- jest.mock('../../../validate-command', () => ({
14
- preflightValidation: jest.fn(),
15
- }));
16
- jest.mock('../../../doctor-command', () => ({ doctorCommand: jest.fn() }));
17
- jest.mock('../../../utils/database-validator', () => ({
18
- validateDatabaseUrl: jest.fn(() => ({ valid: true })),
19
- getDatabaseType: jest.fn(() => ({ dbType: 'postgresql' })),
20
- checkPrismaClientGenerated: jest.fn(() => ({ generated: true })),
21
- }));
22
- jest.mock('dotenv', () => ({ config: jest.fn() }));
23
-
24
- const childProcess = mockChildProcess;
25
- const nodeChildProcess = mockChildProcess;
26
- const { preflightValidation } = require('../../../validate-command');
27
- const { buildCommand } = require('../../../build-command');
28
- const { deployCommand } = require('../../../deploy-command');
29
- const { startCommand } = require('../../../start-command');
30
-
31
- describe('validation before build, deploy and start', () => {
32
- beforeEach(() => {
33
- jest.clearAllMocks();
34
- jest.spyOn(console, 'log').mockImplementation(() => {});
35
- jest.spyOn(console, 'warn').mockImplementation(() => {});
36
- jest.spyOn(console, 'error').mockImplementation(() => {});
37
- jest.spyOn(process, 'exit').mockImplementation(() => {});
38
- });
39
-
40
- afterEach(() => jest.restoreAllMocks());
41
-
42
- it('build validates first and fails on errors', async () => {
43
- preflightValidation.mockReturnValue(false);
44
-
45
- await buildCommand({ stage: 'prod' });
46
-
47
- expect(preflightValidation).toHaveBeenCalledWith({
48
- command: 'build',
49
- options: { stage: 'prod' },
50
- failOnErrors: true,
51
- });
52
- expect(childProcess.spawnSync).not.toHaveBeenCalled();
53
- });
54
-
55
- it('build packages after a passing validation', async () => {
56
- preflightValidation.mockReturnValue(true);
57
-
58
- await buildCommand({ stage: 'prod' });
59
-
60
- expect(childProcess.spawnSync).toHaveBeenCalled();
61
- });
62
-
63
- it('deploy validates first and fails on errors', async () => {
64
- preflightValidation.mockReturnValue(false);
65
-
66
- await deployCommand({ stage: 'prod', skipValidate: false });
67
-
68
- expect(preflightValidation).toHaveBeenCalledWith({
69
- command: 'deploy',
70
- options: { stage: 'prod', skipValidate: false },
71
- failOnErrors: true,
72
- });
73
- expect(childProcess.spawn).not.toHaveBeenCalled();
74
- });
75
-
76
- it('start validates and only warns', async () => {
77
- preflightValidation.mockReturnValue(true);
78
- nodeChildProcess.spawn.mockReturnValue({ on: jest.fn() });
79
- const previous = process.env.DATABASE_URL;
80
- process.env.DATABASE_URL = 'postgresql://localhost/frigg';
81
-
82
- await startCommand({ stage: 'dev' });
83
-
84
- process.env.DATABASE_URL = previous;
85
- expect(preflightValidation).toHaveBeenCalledWith({
86
- command: 'start',
87
- options: { stage: 'dev' },
88
- failOnErrors: false,
89
- });
90
- expect(nodeChildProcess.spawn).toHaveBeenCalled();
91
- });
92
- });
@@ -1,158 +0,0 @@
1
- const { Command } = require('commander');
2
- const { installCommand } = require('./index');
3
- const { validatePackageExists } = require('./install-command/validate-package');
4
- const { findNearestBackendPackageJson, validateBackendPath } = require('@friggframework/core');
5
- const { installPackage } = require('./install-command/install-package');
6
- const { createIntegrationFile } = require('./install-command/integration-file');
7
- const { updateBackendJsFile } = require('./install-command/backend-js');
8
- const { commitChanges } = require('./install-command/commit-changes');
9
- const { logInfo, logError } = require('./install-command/logger');
10
-
11
- describe('CLI Command Tests', () => {
12
- it('should successfully install an API module when all steps complete without errors', async () => {
13
- const mockApiModuleName = 'testModule';
14
- const mockPackageName = `@friggframework/api-module-${mockApiModuleName}`;
15
- const mockBackendPath = '/mock/backend/path';
16
-
17
- jest.mock('./install-command/validate-package', () => ({
18
- validatePackageExists: jest.fn().mockResolvedValue(true),
19
- }));
20
- jest.mock('./utils/backend-path', () => ({
21
- findNearestBackendPackageJson: jest
22
- .fn()
23
- .mockReturnValue(mockBackendPath),
24
- validateBackendPath: jest.fn().mockReturnValue(true),
25
- }));
26
- jest.mock('./install-command/install-package', () => ({
27
- installPackage: jest.fn().mockReturnValue(true),
28
- }));
29
- jest.mock('./install-command/integration-file', () => ({
30
- createIntegrationFile: jest.fn().mockReturnValue(true),
31
- }));
32
- jest.mock('./install-command/backend-js', () => ({
33
- updateBackendJsFile: jest.fn().mockReturnValue(true),
34
- }));
35
- jest.mock('./install-command/commit-changes', () => ({
36
- commitChanges: jest.fn().mockReturnValue(true),
37
- }));
38
- jest.mock('./install-command/logger', () => ({
39
- logInfo: jest.fn(),
40
- logError: jest.fn(),
41
- }));
42
-
43
- const program = new Command();
44
- program
45
- .command('install <apiModuleName>')
46
- .description('Install an API module')
47
- .action(installCommand);
48
-
49
- await program.parseAsync(['node', 'install', mockApiModuleName]);
50
-
51
- expect(validatePackageExists).toHaveBeenCalledWith(mockPackageName);
52
- expect(findNearestBackendPackageJson).toHaveBeenCalled();
53
- expect(validateBackendPath).toHaveBeenCalledWith(mockBackendPath);
54
- expect(installPackage).toHaveBeenCalledWith(
55
- mockBackendPath,
56
- mockPackageName
57
- );
58
- expect(createIntegrationFile).toHaveBeenCalledWith(
59
- mockBackendPath,
60
- mockApiModuleName
61
- );
62
- expect(updateBackendJsFile).toHaveBeenCalledWith(
63
- mockBackendPath,
64
- mockApiModuleName
65
- );
66
- expect(commitChanges).toHaveBeenCalledWith(
67
- mockBackendPath,
68
- mockApiModuleName
69
- );
70
- expect(logInfo).toHaveBeenCalledWith(
71
- `Successfully installed ${mockPackageName} and updated the project.`
72
- );
73
- });
74
-
75
- it('should log an error and exit with code 1 if the package does not exist', async () => {
76
- const mockExit = jest
77
- .spyOn(process, 'exit')
78
- .mockImplementation(() => {});
79
- const mockLogError = jest
80
- .spyOn(require('./install-command/logger'), 'logError')
81
- .mockImplementation(() => {});
82
- const mockValidatePackageExists = jest
83
- .spyOn(
84
- require('./install-command/validate-package'),
85
- 'validatePackageExists'
86
- )
87
- .mockImplementation(() => {
88
- throw new Error('Package not found');
89
- });
90
-
91
- const program = new Command();
92
- program
93
- .command('install <apiModuleName>')
94
- .description('Install an API module')
95
- .action(installCommand);
96
-
97
- await program.parseAsync(['node', 'install', 'nonexistent-package']);
98
-
99
- expect(mockValidatePackageExists).toHaveBeenCalledWith(
100
- '@friggframework/api-module-nonexistent-package'
101
- );
102
- expect(mockLogError).toHaveBeenCalledWith(
103
- 'An error occurred:',
104
- expect.any(Error)
105
- );
106
- expect(mockExit).toHaveBeenCalledWith(1);
107
-
108
- mockExit.mockRestore();
109
- mockLogError.mockRestore();
110
- mockValidatePackageExists.mockRestore();
111
- });
112
-
113
- it('should log an error and exit with code 1 if the backend path is invalid', async () => {
114
- const mockLogError = jest
115
- .spyOn(require('./install-command/logger'), 'logError')
116
- .mockImplementation(() => {});
117
- const mockProcessExit = jest
118
- .spyOn(process, 'exit')
119
- .mockImplementation(() => {});
120
- const mockValidatePackageExists = jest
121
- .spyOn(
122
- require('./install-command/validate-package'),
123
- 'validatePackageExists'
124
- )
125
- .mockResolvedValue(true);
126
- const mockFindNearestBackendPackageJson = jest
127
- .spyOn(
128
- require('./utils/backend-path'),
129
- 'findNearestBackendPackageJson'
130
- )
131
- .mockReturnValue('/invalid/path');
132
- const mockValidateBackendPath = jest
133
- .spyOn(require('./utils/backend-path'), 'validateBackendPath')
134
- .mockImplementation(() => {
135
- throw new Error('Invalid backend path');
136
- });
137
-
138
- const program = new Command();
139
- program
140
- .command('install <apiModuleName>')
141
- .description('Install an API module')
142
- .action(installCommand);
143
-
144
- await program.parseAsync(['node', 'install', 'test-module']);
145
-
146
- expect(mockLogError).toHaveBeenCalledWith(
147
- 'An error occurred:',
148
- expect.any(Error)
149
- );
150
- expect(mockProcessExit).toHaveBeenCalledWith(1);
151
-
152
- mockLogError.mockRestore();
153
- mockProcessExit.mockRestore();
154
- mockValidatePackageExists.mockRestore();
155
- mockFindNearestBackendPackageJson.mockRestore();
156
- mockValidateBackendPath.mockRestore();
157
- });
158
- });
@@ -1,63 +0,0 @@
1
- /**
2
- * `frigg init` validates the generated app with the same code path as
3
- * `frigg validate`, and never fails because of it (ADR-051).
4
- */
5
- const fs = require('fs');
6
- const os = require('os');
7
- const path = require('path');
8
-
9
- jest.mock('@inquirer/prompts', () => ({}));
10
-
11
- const BackendFirstHandler = require('../../init-command/backend-first-handler');
12
-
13
- function writeApp(source) {
14
- const dir = fs.mkdtempSync(path.join(os.tmpdir(), 'frigg-init-'));
15
- fs.writeFileSync(path.join(dir, 'package.json'), '{"name":"backend"}');
16
- fs.writeFileSync(path.join(dir, 'index.js'), source);
17
- return dir;
18
- }
19
-
20
- describe('frigg init validation', () => {
21
- const dirs = [];
22
- let log;
23
-
24
- beforeEach(() => {
25
- log = jest.spyOn(console, 'log').mockImplementation(() => {});
26
- });
27
-
28
- afterEach(() => {
29
- jest.restoreAllMocks();
30
- for (const dir of dirs.splice(0))
31
- fs.rmSync(dir, { recursive: true, force: true });
32
- });
33
-
34
- it('validates the real generated definition, not a stand-in', async () => {
35
- const dir = writeApp(
36
- "module.exports = { Definition: { integrations: [], database: { postgres: { enable: true, management: 'create-new' } } } };"
37
- );
38
- dirs.push(dir);
39
- const handler = new BackendFirstHandler(dir, {});
40
-
41
- const ok = await handler.validateGeneratedAppDefinition(
42
- path.join(dir, 'index.js')
43
- );
44
-
45
- expect(ok).toBe(false);
46
- expect(log.mock.calls.flat().join('\n')).toContain(
47
- '/database/postgres/management'
48
- );
49
- });
50
-
51
- it('stays quiet before npm install, when index.js cannot load its dependencies', async () => {
52
- const dir = writeApp(
53
- "require('@friggframework/api-module-does-not-exist');"
54
- );
55
- dirs.push(dir);
56
- const handler = new BackendFirstHandler(dir, {});
57
-
58
- await expect(
59
- handler.validateGeneratedAppDefinition(path.join(dir, 'index.js'))
60
- ).resolves.toBe(true);
61
- expect(log).not.toHaveBeenCalled();
62
- });
63
- });
@@ -1,133 +0,0 @@
1
- const { checkIntegrations } = require('../checks/integrations');
2
-
3
- class FakeApi {
4
- static requesterType = 'oauth2';
5
- }
6
-
7
- const moduleDefinition = () => ({
8
- moduleName: 'acme',
9
- API: FakeApi,
10
- requiredAuthMethods: {
11
- getToken: async () => {},
12
- getEntityDetails: async () => {},
13
- getCredentialDetails: async () => {},
14
- testAuthRequest: async () => {},
15
- apiPropertiesToPersist: { credential: [], entity: [] },
16
- },
17
- });
18
-
19
- function integrationClass(definition) {
20
- return class Integration {
21
- static Definition = definition;
22
- };
23
- }
24
-
25
- const goodIntegration = () =>
26
- integrationClass({
27
- name: 'acme',
28
- version: '1.0.0',
29
- modules: { acme: { definition: moduleDefinition() } },
30
- });
31
-
32
- const codes = (issues) =>
33
- issues.map((i) => `${i.severity}:${i.code}:${i.pointer}`);
34
-
35
- describe('checkIntegrations', () => {
36
- it('accepts a well-formed integration class', () => {
37
- expect(
38
- checkIntegrations({ integrations: [goodIntegration()] })
39
- ).toEqual([]);
40
- });
41
-
42
- it('warns when the app lists no integrations', () => {
43
- expect(codes(checkIntegrations({ integrations: [] }))).toEqual([
44
- 'warning:no-integrations:/integrations',
45
- ]);
46
- });
47
-
48
- it('rejects an entry that is not a class', () => {
49
- expect(
50
- codes(
51
- checkIntegrations({
52
- integrations: [{ Definition: { name: 'x' } }],
53
- })
54
- )
55
- ).toEqual(['error:integration-not-a-class:/integrations/0']);
56
- });
57
-
58
- it('rejects a class without a static Definition', () => {
59
- class Bare {}
60
- expect(codes(checkIntegrations({ integrations: [Bare] }))).toEqual([
61
- 'error:integration-definition-missing:/integrations/0/Definition',
62
- ]);
63
- });
64
-
65
- it('requires a valid name and modules, and warns on a missing version', () => {
66
- const Cls = integrationClass({ name: '1 bad name' });
67
- expect(codes(checkIntegrations({ integrations: [Cls] }))).toEqual([
68
- 'error:integration-name-invalid:/integrations/0/Definition/name',
69
- 'warning:integration-version-missing:/integrations/0/Definition/version',
70
- 'error:integration-modules-missing:/integrations/0/Definition/modules',
71
- ]);
72
- });
73
-
74
- it('reports duplicate integration names', () => {
75
- expect(
76
- codes(
77
- checkIntegrations({
78
- integrations: [goodIntegration(), goodIntegration()],
79
- })
80
- )
81
- ).toEqual([
82
- 'error:integration-name-duplicate:/integrations/1/Definition/name',
83
- ]);
84
- });
85
-
86
- it('checks module definitions the way Module.validateDefinition does', () => {
87
- const definition = moduleDefinition();
88
- delete definition.requiredAuthMethods.getToken;
89
- delete definition.moduleName;
90
- const Cls = integrationClass({
91
- name: 'acme',
92
- version: '1',
93
- modules: { acme: { definition }, other: {} },
94
- });
95
-
96
- expect(codes(checkIntegrations({ integrations: [Cls] }))).toEqual([
97
- 'error:module-name-missing:/integrations/0/Definition/modules/acme/definition/moduleName',
98
- 'error:module-auth-method-missing:/integrations/0/Definition/modules/acme/definition/requiredAuthMethods/getToken',
99
- 'error:module-definition-missing:/integrations/0/Definition/modules/other/definition',
100
- ]);
101
- });
102
-
103
- it('does not require getToken for non-OAuth2 modules', () => {
104
- const definition = moduleDefinition();
105
- definition.API = class {
106
- static requesterType = 'apiKey';
107
- };
108
- delete definition.requiredAuthMethods.getToken;
109
- const Cls = integrationClass({
110
- name: 'acme',
111
- version: '1',
112
- modules: { acme: { definition } },
113
- });
114
-
115
- expect(checkIntegrations({ integrations: [Cls] })).toEqual([]);
116
- });
117
-
118
- it('warns that a module rateLimit is not applied', () => {
119
- const definition = {
120
- ...moduleDefinition(),
121
- rateLimit: { requests: 10, period: 'second' },
122
- };
123
- const Cls = integrationClass({
124
- name: 'acme',
125
- version: '1',
126
- modules: { acme: { definition } },
127
- });
128
-
129
- expect(codes(checkIntegrations({ integrations: [Cls] }))).toEqual([
130
- 'warning:module-rate-limit-ignored:/integrations/0/Definition/modules/acme/definition/rateLimit',
131
- ]);
132
- });
133
- });