@friggframework/devtools 2.0.0--canary.710.7cfcf12.0 → 2.0.0--canary.682.451c957.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.
- package/frigg-cli/README.md +30 -77
- package/frigg-cli/__tests__/unit/commands/deploy.test.js +24 -30
- package/frigg-cli/__tests__/unit/commands/doctor.test.js +6 -10
- package/frigg-cli/__tests__/unit/commands/generate-iam.test.js +0 -18
- package/frigg-cli/__tests__/unit/commands/install.test.js +341 -601
- package/frigg-cli/__tests__/unit/commands/ui.test.js +30 -31
- package/frigg-cli/__tests__/unit/dependencies.test.js +2 -6
- package/frigg-cli/generate-command/index.js +0 -1
- package/frigg-cli/generate-iam-command.js +0 -1
- package/frigg-cli/index.js +4 -9
- package/frigg-cli/index.test.js +158 -0
- package/frigg-cli/init-command/backend-first-handler.js +554 -397
- package/frigg-cli/init-command/index.js +35 -82
- package/frigg-cli/install-command/commit-changes.js +8 -40
- package/frigg-cli/install-command/environment-variables.js +0 -15
- package/frigg-cli/install-command/index.js +21 -96
- package/frigg-cli/install-command/install-package.js +4 -77
- package/frigg-cli/install-command/integration-file.js +11 -20
- package/frigg-cli/install-command/template.js +75 -102
- package/frigg-cli/install-command/validate-package.js +4 -36
- package/frigg-cli/package.json +1 -1
- package/frigg-cli/test/init-command.test.js +2 -9
- package/infrastructure/__tests__/management-api-gateway-routes.test.js +335 -0
- package/infrastructure/__tests__/postgres-config.test.js +835 -241
- package/infrastructure/__tests__/template-generation.test.js +8 -36
- package/infrastructure/docs/POSTGRES-CONFIGURATION.md +1 -21
- package/infrastructure/domains/admin-scripts/admin-script-builder.js +2 -6
- package/infrastructure/domains/admin-scripts/admin-script-builder.test.js +0 -30
- package/infrastructure/domains/database/aurora-builder.js +2 -13
- package/infrastructure/domains/database/aurora-builder.test.js +0 -22
- package/infrastructure/domains/health/application/use-cases/__tests__/mismatch-analyzer-method-name.test.js +8 -12
- package/infrastructure/domains/health/application/use-cases/__tests__/repair-via-import-use-case.test.js +7 -19
- package/infrastructure/domains/health/application/use-cases/run-health-check-use-case.test.js +8 -12
- package/infrastructure/domains/health/domain/services/__tests__/import-progress-monitor.test.js +18 -17
- package/infrastructure/domains/health/domain/services/__tests__/update-progress-monitor.test.js +2 -12
- package/infrastructure/domains/health/infrastructure/adapters/__tests__/orphan-detection-relationship-analysis.test.js +1 -8
- package/infrastructure/domains/health/infrastructure/adapters/aws-property-reconciler.test.js +2 -4
- package/infrastructure/domains/health/infrastructure/adapters/aws-resource-detector.test.js +0 -10
- package/infrastructure/domains/networking/vpc-builder.js +8 -18
- package/infrastructure/domains/networking/vpc-builder.test.js +12 -26
- package/infrastructure/domains/security/iam-generator.js +5 -112
- package/infrastructure/domains/security/iam-generator.test.js +0 -94
- package/infrastructure/domains/shared/cloudformation-discovery.test.js +6 -36
- package/infrastructure/domains/shared/utilities/base-definition-factory.js +28 -17
- package/infrastructure/domains/shared/utilities/base-definition-factory.test.js +61 -22
- package/infrastructure/infrastructure-composer.test.js +794 -268
- package/infrastructure/integration.test.js +381 -0
- package/infrastructure/scripts/build-prisma-layer.test.js +7 -28
- package/infrastructure/scripts/build-time-discovery.test.js +3 -18
- package/package.json +8 -10
- package/frigg-cli/__tests__/unit/commands/init.test.js +0 -688
- package/frigg-cli/init-command/deployment-modes.js +0 -7
- package/frigg-cli/init-command/safe-path.js +0 -58
- package/frigg-cli/init-command/scaffold-dependencies.js +0 -202
- package/frigg-cli/install-command/app-definition.js +0 -174
- package/frigg-cli/install-command/resolve-module.js +0 -69
- package/frigg-cli/templates/backend/README.md +0 -267
- package/frigg-cli/templates/backend/env.example +0 -20
- package/frigg-cli/templates/backend/gitignore +0 -10
- package/frigg-cli/templates/backend/index.js +0 -114
- package/frigg-cli/templates/backend/infrastructure.js +0 -20
- package/infrastructure/__tests__/scaffold-default-infrastructure.test.js +0 -148
|
@@ -1,660 +1,400 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
2
|
+
* Test suite for install command
|
|
3
3
|
*
|
|
4
|
-
*
|
|
5
|
-
* -
|
|
6
|
-
* -
|
|
7
|
-
*
|
|
8
|
-
*
|
|
9
|
-
*
|
|
10
|
-
*
|
|
11
|
-
*
|
|
4
|
+
* Tests the ACTUAL Frigg implementation including:
|
|
5
|
+
* - Package search and selection (mocked - external npm)
|
|
6
|
+
* - Package installation via npm (mocked - external)
|
|
7
|
+
* - Integration file creation (REAL - tests actual file generation)
|
|
8
|
+
* - Backend.js updates (REAL - tests actual file parsing/updating)
|
|
9
|
+
* - Git commits (mocked - external)
|
|
10
|
+
* - Environment variable handling (mocked - interactive)
|
|
11
|
+
* - Label sanitization (REAL - tests actual regex logic)
|
|
12
12
|
*/
|
|
13
13
|
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
const fs = require('fs-extra');
|
|
17
|
-
const { spawnSync } = require('child_process');
|
|
18
|
-
|
|
14
|
+
// Mock ONLY external boundaries - let Frigg logic run!
|
|
15
|
+
jest.mock('fs-extra'); // Mock at I/O level
|
|
19
16
|
jest.mock('../../../install-command/install-package', () => ({
|
|
20
|
-
|
|
21
|
-
installPackage: jest.fn(),
|
|
17
|
+
installPackage: jest.fn() // External: npm install
|
|
22
18
|
}));
|
|
23
19
|
jest.mock('../../../install-command/commit-changes', () => ({
|
|
24
|
-
|
|
20
|
+
commitChanges: jest.fn() // External: git commands
|
|
25
21
|
}));
|
|
26
22
|
jest.mock('../../../install-command/environment-variables', () => ({
|
|
27
|
-
|
|
23
|
+
handleEnvVariables: jest.fn() // External: interactive prompts
|
|
28
24
|
}));
|
|
29
25
|
jest.mock('../../../install-command/validate-package', () => ({
|
|
30
|
-
|
|
31
|
-
|
|
26
|
+
validatePackageExists: jest.fn(), // External: npm registry
|
|
27
|
+
searchAndSelectPackage: jest.fn() // External: interactive selection
|
|
32
28
|
}));
|
|
33
|
-
jest.mock('@friggframework/core
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
if (!p) throw new Error('Could not find a backend package.json file.');
|
|
37
|
-
}),
|
|
29
|
+
jest.mock('@friggframework/core', () => ({
|
|
30
|
+
findNearestBackendPackageJson: jest.fn(),
|
|
31
|
+
validateBackendPath: jest.fn()
|
|
38
32
|
}));
|
|
39
33
|
|
|
34
|
+
// DON'T mock these - let them run to test actual Frigg logic:
|
|
35
|
+
// - createIntegrationFile (tests file generation)
|
|
36
|
+
// - updateBackendJsFile (tests file parsing)
|
|
37
|
+
// - logger (just console.log, we'll spy on console)
|
|
38
|
+
// - getIntegrationTemplate (tests template generation)
|
|
39
|
+
|
|
40
|
+
// Require after mocks
|
|
41
|
+
const fs = require('fs-extra');
|
|
40
42
|
const { installPackage } = require('../../../install-command/install-package');
|
|
41
43
|
const { commitChanges } = require('../../../install-command/commit-changes');
|
|
42
|
-
const {
|
|
43
|
-
|
|
44
|
-
} = require('
|
|
45
|
-
const {
|
|
46
|
-
validatePackageExists,
|
|
47
|
-
searchAndSelectPackage,
|
|
48
|
-
} = require('../../../install-command/validate-package');
|
|
49
|
-
const { findNearestBackendPackageJson } = require('@friggframework/core/utils');
|
|
44
|
+
const { handleEnvVariables } = require('../../../install-command/environment-variables');
|
|
45
|
+
const { validatePackageExists, searchAndSelectPackage } = require('../../../install-command/validate-package');
|
|
46
|
+
const { findNearestBackendPackageJson, validateBackendPath } = require('@friggframework/core');
|
|
50
47
|
const { installCommand } = require('../../../install-command');
|
|
51
48
|
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
const
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
fs.ensureDirSync(
|
|
71
|
-
fs.
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
49
|
+
describe('CLI Command: install', () => {
|
|
50
|
+
let processExitSpy;
|
|
51
|
+
let consoleLogSpy;
|
|
52
|
+
let consoleErrorSpy;
|
|
53
|
+
const mockBackendPath = '/mock/backend/package.json';
|
|
54
|
+
const mockBackendDir = '/mock/backend';
|
|
55
|
+
|
|
56
|
+
beforeEach(() => {
|
|
57
|
+
jest.clearAllMocks();
|
|
58
|
+
|
|
59
|
+
// Mock process.exit to prevent actual exit
|
|
60
|
+
processExitSpy = jest.spyOn(process, 'exit').mockImplementation();
|
|
61
|
+
|
|
62
|
+
// Spy on console for logger (don't mock logger - test it!)
|
|
63
|
+
consoleLogSpy = jest.spyOn(console, 'log').mockImplementation();
|
|
64
|
+
consoleErrorSpy = jest.spyOn(console, 'error').mockImplementation();
|
|
65
|
+
|
|
66
|
+
// Setup fs-extra mocks - Let Frigg code run, just mock I/O
|
|
67
|
+
fs.ensureDirSync = jest.fn();
|
|
68
|
+
fs.writeFileSync = jest.fn();
|
|
69
|
+
fs.readFileSync = jest.fn().mockReturnValue(`
|
|
70
|
+
// Sample backend.js file
|
|
71
|
+
const integrations = [
|
|
72
|
+
// Existing integrations
|
|
73
|
+
];
|
|
74
|
+
|
|
75
|
+
module.exports = {
|
|
76
|
+
integrations: []
|
|
77
|
+
};
|
|
78
|
+
`);
|
|
79
|
+
fs.existsSync = jest.fn().mockReturnValue(true);
|
|
80
|
+
|
|
81
|
+
// Setup default successful mocks for external boundaries
|
|
82
|
+
searchAndSelectPackage.mockResolvedValue(['@friggframework/api-module-slack']);
|
|
83
|
+
findNearestBackendPackageJson.mockReturnValue(mockBackendPath);
|
|
84
|
+
validateBackendPath.mockReturnValue(true);
|
|
85
|
+
validatePackageExists.mockResolvedValue(true);
|
|
86
|
+
installPackage.mockReturnValue(undefined);
|
|
87
|
+
handleEnvVariables.mockResolvedValue(undefined);
|
|
88
|
+
|
|
89
|
+
// Mock the dynamic require() of installed package using jest.doMock
|
|
90
|
+
const path = require('path');
|
|
91
|
+
const slackModulePath = path.resolve(mockBackendPath, '../../node_modules/@friggframework/api-module-slack');
|
|
92
|
+
|
|
93
|
+
jest.doMock(slackModulePath, () => ({
|
|
94
|
+
Config: { label: 'Slack' },
|
|
95
|
+
Api: class SlackApi {}
|
|
96
|
+
}), { virtual: true });
|
|
97
|
+
});
|
|
98
|
+
|
|
99
|
+
afterEach(() => {
|
|
100
|
+
processExitSpy.mockRestore();
|
|
101
|
+
consoleLogSpy.mockRestore();
|
|
102
|
+
consoleErrorSpy.mockRestore();
|
|
103
|
+
jest.resetModules(); // Clear module cache after each test
|
|
104
|
+
});
|
|
105
|
+
|
|
106
|
+
describe('Success Cases', () => {
|
|
107
|
+
it('should orchestrate complete installation workflow', async () => {
|
|
108
|
+
await installCommand('slack');
|
|
109
|
+
|
|
110
|
+
// Verify external boundaries called
|
|
111
|
+
expect(searchAndSelectPackage).toHaveBeenCalledWith('slack');
|
|
112
|
+
expect(findNearestBackendPackageJson).toHaveBeenCalled();
|
|
113
|
+
expect(validateBackendPath).toHaveBeenCalledWith(mockBackendPath);
|
|
114
|
+
expect(validatePackageExists).toHaveBeenCalledWith('@friggframework/api-module-slack');
|
|
115
|
+
expect(installPackage).toHaveBeenCalledWith(mockBackendPath, '@friggframework/api-module-slack');
|
|
75
116
|
});
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
}
|
|
104
|
-
|
|
105
|
-
/** A `frigg init` app: the real template's index.js plus a package.json. */
|
|
106
|
-
function makeScaffoldedApp({
|
|
107
|
-
coreRange = '2.0.0-next.115',
|
|
108
|
-
installedCoreVersion,
|
|
109
|
-
} = {}) {
|
|
110
|
-
const dir = makeTmpDir();
|
|
111
|
-
fs.copySync(
|
|
112
|
-
path.join(TEMPLATE_DIR, 'index.js'),
|
|
113
|
-
path.join(dir, 'index.js')
|
|
114
|
-
);
|
|
115
|
-
fs.writeJSONSync(path.join(dir, 'package.json'), {
|
|
116
|
-
name: 'my-app',
|
|
117
|
-
dependencies: { '@friggframework/core': coreRange },
|
|
117
|
+
|
|
118
|
+
it('should create integration file with correct path and content', async () => {
|
|
119
|
+
await installCommand('slack');
|
|
120
|
+
|
|
121
|
+
// Verify directory creation
|
|
122
|
+
expect(fs.ensureDirSync).toHaveBeenCalledWith(
|
|
123
|
+
expect.stringMatching(/src\/integrations$/)
|
|
124
|
+
);
|
|
125
|
+
|
|
126
|
+
// Verify integration file written with correct path
|
|
127
|
+
expect(fs.writeFileSync).toHaveBeenCalledWith(
|
|
128
|
+
expect.stringMatching(/SlackIntegration\.js$/),
|
|
129
|
+
expect.any(String)
|
|
130
|
+
);
|
|
131
|
+
|
|
132
|
+
// Get the actual content that was written
|
|
133
|
+
const writeCall = fs.writeFileSync.mock.calls.find(call =>
|
|
134
|
+
call[0].includes('SlackIntegration.js')
|
|
135
|
+
);
|
|
136
|
+
|
|
137
|
+
expect(writeCall).toBeDefined();
|
|
138
|
+
const [filePath, content] = writeCall;
|
|
139
|
+
|
|
140
|
+
// Verify file content contains valid integration class
|
|
141
|
+
expect(content).toContain('class SlackIntegration extends IntegrationBase');
|
|
142
|
+
expect(content).toContain('@friggframework/core');
|
|
143
|
+
expect(content).toContain('@friggframework/api-module-slack');
|
|
118
144
|
});
|
|
119
|
-
fs.ensureDirSync(path.join(dir, 'node_modules', '@friggframework'));
|
|
120
|
-
if (installedCoreVersion) {
|
|
121
|
-
// A stand-in core with a chosen version.
|
|
122
|
-
fs.outputJSONSync(
|
|
123
|
-
path.join(dir, 'node_modules/@friggframework/core/package.json'),
|
|
124
|
-
{ name: '@friggframework/core', version: installedCoreVersion }
|
|
125
|
-
);
|
|
126
|
-
return dir;
|
|
127
|
-
}
|
|
128
|
-
// Let the generated files load the real core.
|
|
129
|
-
fs.symlinkSync(
|
|
130
|
-
CORE_DIR,
|
|
131
|
-
path.join(dir, 'node_modules', '@friggframework', 'core')
|
|
132
|
-
);
|
|
133
|
-
return dir;
|
|
134
|
-
}
|
|
135
145
|
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
writeFakeModule(path.dirname(backendPath), name, modules[name]);
|
|
154
|
-
});
|
|
155
|
-
};
|
|
156
|
-
|
|
157
|
-
beforeEach(() => {
|
|
158
|
-
jest.clearAllMocks();
|
|
159
|
-
processExitSpy = jest.spyOn(process, 'exit').mockImplementation();
|
|
160
|
-
consoleLogSpy = jest.spyOn(console, 'log').mockImplementation();
|
|
161
|
-
consoleErrorSpy = jest.spyOn(console, 'error').mockImplementation();
|
|
162
|
-
modules = {
|
|
163
|
-
[HUBSPOT]: { label: 'HubSpot', moduleName: 'hubspot' },
|
|
164
|
-
'@friggframework/api-module-google-drive': {
|
|
165
|
-
label: 'Google Drive',
|
|
166
|
-
moduleName: 'google-drive',
|
|
167
|
-
},
|
|
168
|
-
};
|
|
169
|
-
searchAndSelectPackage.mockResolvedValue([HUBSPOT]);
|
|
170
|
-
validatePackageExists.mockResolvedValue(true);
|
|
171
|
-
handleEnvVariables.mockResolvedValue(undefined);
|
|
146
|
+
it('should generate valid JavaScript template', async () => {
|
|
147
|
+
await installCommand('slack');
|
|
148
|
+
|
|
149
|
+
const writeCall = fs.writeFileSync.mock.calls.find(call =>
|
|
150
|
+
call[0].includes('SlackIntegration.js')
|
|
151
|
+
);
|
|
152
|
+
|
|
153
|
+
const [, content] = writeCall;
|
|
154
|
+
|
|
155
|
+
// Verify template has required structure
|
|
156
|
+
expect(content).toMatch(/class \w+Integration extends IntegrationBase/);
|
|
157
|
+
expect(content).toContain('static Config =');
|
|
158
|
+
expect(content).toContain('static Options =');
|
|
159
|
+
expect(content).toContain('static modules =');
|
|
160
|
+
|
|
161
|
+
// Verify template is syntactically valid (no unclosed braces, etc)
|
|
162
|
+
expect(content.split('{').length).toBe(content.split('}').length);
|
|
172
163
|
});
|
|
173
164
|
|
|
174
|
-
|
|
175
|
-
|
|
165
|
+
it('should update backend.js with integration import', async () => {
|
|
166
|
+
await installCommand('slack');
|
|
167
|
+
|
|
168
|
+
// Verify backend.js was read
|
|
169
|
+
expect(fs.readFileSync).toHaveBeenCalledWith(
|
|
170
|
+
expect.stringMatching(/backend\.js$/),
|
|
171
|
+
'utf-8'
|
|
172
|
+
);
|
|
173
|
+
|
|
174
|
+
// Verify backend.js was written back with import
|
|
175
|
+
const backendWriteCall = fs.writeFileSync.mock.calls.find(call =>
|
|
176
|
+
call[0].includes('backend.js')
|
|
177
|
+
);
|
|
178
|
+
|
|
179
|
+
expect(backendWriteCall).toBeDefined();
|
|
180
|
+
const [, updatedBackend] = backendWriteCall;
|
|
181
|
+
|
|
182
|
+
// Verify import statement added
|
|
183
|
+
expect(updatedBackend).toContain('const SlackIntegration = require');
|
|
184
|
+
expect(updatedBackend).toContain('./src/integrations/SlackIntegration');
|
|
185
|
+
|
|
186
|
+
// Verify integration added to array
|
|
187
|
+
expect(updatedBackend).toContain('SlackIntegration,');
|
|
176
188
|
});
|
|
177
189
|
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
await installCommand('hubspot');
|
|
184
|
-
|
|
185
|
-
expect(processExitSpy).not.toHaveBeenCalled();
|
|
186
|
-
expect(installPackage).toHaveBeenCalledWith(
|
|
187
|
-
path.join(dir, 'package.json'),
|
|
188
|
-
`${HUBSPOT}@next`
|
|
189
|
-
);
|
|
190
|
-
expect(handleEnvVariables).toHaveBeenCalledWith(
|
|
191
|
-
path.join(dir, 'package.json'),
|
|
192
|
-
path.join(
|
|
193
|
-
dir,
|
|
194
|
-
'node_modules',
|
|
195
|
-
'@friggframework',
|
|
196
|
-
'api-module-hubspot'
|
|
197
|
-
)
|
|
198
|
-
);
|
|
199
|
-
});
|
|
200
|
-
|
|
201
|
-
it('installs the default version for an app on a stable release', async () => {
|
|
202
|
-
const dir = makeScaffoldedApp({
|
|
203
|
-
coreRange: '^2.0.1',
|
|
204
|
-
installedCoreVersion: '2.0.1',
|
|
205
|
-
});
|
|
206
|
-
useApp(dir);
|
|
207
|
-
|
|
208
|
-
await installCommand('hubspot');
|
|
209
|
-
|
|
210
|
-
expect(installPackage).toHaveBeenCalledWith(
|
|
211
|
-
path.join(dir, 'package.json'),
|
|
212
|
-
HUBSPOT
|
|
213
|
-
);
|
|
214
|
-
});
|
|
215
|
-
|
|
216
|
-
it('creates src/integrations/<Label>Integration.js and registers it in index.js', async () => {
|
|
217
|
-
const dir = makeScaffoldedApp();
|
|
218
|
-
useApp(dir);
|
|
219
|
-
|
|
220
|
-
await installCommand('hubspot');
|
|
221
|
-
|
|
222
|
-
const integrationFile = path.join(
|
|
223
|
-
dir,
|
|
224
|
-
'src/integrations/HubSpotIntegration.js'
|
|
225
|
-
);
|
|
226
|
-
expect(fs.existsSync(integrationFile)).toBe(true);
|
|
227
|
-
const index = fs.readFileSync(path.join(dir, 'index.js'), 'utf8');
|
|
228
|
-
expect(index).toContain(
|
|
229
|
-
"const HubSpotIntegration = require('./src/integrations/HubSpotIntegration');"
|
|
230
|
-
);
|
|
231
|
-
expect(index).toMatch(
|
|
232
|
-
/integrations: \[\n {8}HubSpotIntegration,\n/
|
|
233
|
-
);
|
|
234
|
-
expect(output()).toMatch(/Added HubSpotIntegration to index\.js/);
|
|
235
|
-
});
|
|
236
|
-
|
|
237
|
-
it('produces an app definition that loads, validates, and exposes the integration', async () => {
|
|
238
|
-
const dir = makeScaffoldedApp();
|
|
239
|
-
useApp(dir);
|
|
240
|
-
|
|
241
|
-
await installCommand('hubspot');
|
|
242
|
-
|
|
243
|
-
const { Definition } = require(path.join(dir, 'index.js'));
|
|
244
|
-
expect(Definition.integrations).toHaveLength(1);
|
|
245
|
-
const [Integration] = Definition.integrations;
|
|
246
|
-
const { IntegrationBase } = require('@friggframework/core');
|
|
247
|
-
expect(Object.getPrototypeOf(Integration)).toBe(IntegrationBase);
|
|
248
|
-
expect(Integration.Definition.name).toBe('hubspot');
|
|
249
|
-
expect(
|
|
250
|
-
Integration.Definition.modules.hubspot.definition.getName()
|
|
251
|
-
).toBe('hubspot');
|
|
252
|
-
// The shape the Management API lists integrations with.
|
|
253
|
-
expect(Integration.getOptionDetails()).toMatchObject({
|
|
254
|
-
type: 'hubspot',
|
|
255
|
-
display: {
|
|
256
|
-
name: 'HubSpot',
|
|
257
|
-
icon: 'https://example.com/logo.png',
|
|
258
|
-
},
|
|
259
|
-
});
|
|
260
|
-
});
|
|
261
|
-
|
|
262
|
-
it('turns a label into a valid identifier', async () => {
|
|
263
|
-
const dir = makeScaffoldedApp();
|
|
264
|
-
useApp(dir);
|
|
265
|
-
searchAndSelectPackage.mockResolvedValue([
|
|
266
|
-
'@friggframework/api-module-google-drive',
|
|
267
|
-
]);
|
|
268
|
-
|
|
269
|
-
await installCommand('google-drive');
|
|
270
|
-
|
|
271
|
-
const file = path.join(
|
|
272
|
-
dir,
|
|
273
|
-
'src/integrations/GoogleDriveIntegration.js'
|
|
274
|
-
);
|
|
275
|
-
const content = fs.readFileSync(file, 'utf8');
|
|
276
|
-
expect(content).toContain(
|
|
277
|
-
'class GoogleDriveIntegration extends IntegrationBase'
|
|
278
|
-
);
|
|
279
|
-
expect(content).toContain(
|
|
280
|
-
'googleDrive: { definition: googleDriveModule.Definition }'
|
|
281
|
-
);
|
|
282
|
-
const { Definition } = require(path.join(dir, 'index.js'));
|
|
283
|
-
expect(Definition.integrations[0].Definition.name).toBe(
|
|
284
|
-
'google-drive'
|
|
285
|
-
);
|
|
286
|
-
});
|
|
287
|
-
|
|
288
|
-
it('is idempotent: a second install keeps the file and does not register twice', async () => {
|
|
289
|
-
const dir = makeScaffoldedApp();
|
|
290
|
-
useApp(dir);
|
|
291
|
-
await installCommand('hubspot');
|
|
292
|
-
const file = path.join(
|
|
293
|
-
dir,
|
|
294
|
-
'src/integrations/HubSpotIntegration.js'
|
|
295
|
-
);
|
|
296
|
-
fs.appendFileSync(file, '// my edits\n');
|
|
297
|
-
const indexAfterFirst = fs.readFileSync(
|
|
298
|
-
path.join(dir, 'index.js'),
|
|
299
|
-
'utf8'
|
|
300
|
-
);
|
|
301
|
-
|
|
302
|
-
await installCommand('hubspot');
|
|
303
|
-
|
|
304
|
-
expect(fs.readFileSync(file, 'utf8')).toContain('// my edits');
|
|
305
|
-
expect(fs.readFileSync(path.join(dir, 'index.js'), 'utf8')).toBe(
|
|
306
|
-
indexAfterFirst
|
|
307
|
-
);
|
|
308
|
-
expect(output()).toMatch(
|
|
309
|
-
/HubSpotIntegration is already in index\.js/
|
|
310
|
-
);
|
|
311
|
-
});
|
|
312
|
-
|
|
313
|
-
it('prints the manual steps and leaves index.js alone when it cannot edit it safely', async () => {
|
|
314
|
-
const dir = makeScaffoldedApp();
|
|
315
|
-
const custom =
|
|
316
|
-
"const integrations = require('./list');\nmodule.exports = { Definition: { integrations } };\n";
|
|
317
|
-
fs.writeFileSync(path.join(dir, 'index.js'), custom);
|
|
318
|
-
useApp(dir);
|
|
319
|
-
|
|
320
|
-
await installCommand('hubspot');
|
|
321
|
-
|
|
322
|
-
expect(processExitSpy).not.toHaveBeenCalled();
|
|
323
|
-
expect(fs.readFileSync(path.join(dir, 'index.js'), 'utf8')).toBe(
|
|
324
|
-
custom
|
|
325
|
-
);
|
|
326
|
-
expect(
|
|
327
|
-
fs.existsSync(
|
|
328
|
-
path.join(dir, 'src/integrations/HubSpotIntegration.js')
|
|
329
|
-
)
|
|
330
|
-
).toBe(true);
|
|
331
|
-
expect(output()).toContain(
|
|
332
|
-
"const HubSpotIntegration = require('./src/integrations/HubSpotIntegration');"
|
|
333
|
-
);
|
|
334
|
-
expect(output()).toContain('integrations: [HubSpotIntegration]');
|
|
335
|
-
});
|
|
336
|
-
|
|
337
|
-
it('passes every changed file to the commit step', async () => {
|
|
338
|
-
const dir = makeScaffoldedApp();
|
|
339
|
-
useApp(dir);
|
|
340
|
-
|
|
341
|
-
await installCommand('hubspot');
|
|
342
|
-
|
|
343
|
-
expect(commitChanges).toHaveBeenCalledWith(
|
|
344
|
-
path.join(dir, 'package.json'),
|
|
345
|
-
'HubSpot',
|
|
346
|
-
[
|
|
347
|
-
path.join(dir, 'src/integrations/HubSpotIntegration.js'),
|
|
348
|
-
path.join(dir, 'index.js'),
|
|
349
|
-
path.join(dir, 'package.json'),
|
|
350
|
-
]
|
|
351
|
-
);
|
|
352
|
-
});
|
|
190
|
+
it('should commit changes after file operations', async () => {
|
|
191
|
+
await installCommand('slack');
|
|
192
|
+
|
|
193
|
+
expect(commitChanges).toHaveBeenCalledWith(mockBackendPath, 'Slack');
|
|
353
194
|
});
|
|
354
195
|
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
});
|
|
363
|
-
fs.writeFileSync(
|
|
364
|
-
path.join(dir, 'index.js'),
|
|
365
|
-
"module.exports = require('./backend');\n"
|
|
366
|
-
);
|
|
367
|
-
fs.writeFileSync(
|
|
368
|
-
path.join(dir, 'backend.js'),
|
|
369
|
-
'const appDefinition = {\n integrations: [],\n};\nmodule.exports = appDefinition;\n'
|
|
370
|
-
);
|
|
371
|
-
// Hoisted node_modules at the workspace root still resolves.
|
|
372
|
-
// (Created up front: Jest's resolver caches missing directories.)
|
|
373
|
-
fs.ensureDirSync(path.join(root, 'node_modules'));
|
|
374
|
-
findNearestBackendPackageJson.mockReturnValue(
|
|
375
|
-
path.join(dir, 'package.json')
|
|
376
|
-
);
|
|
377
|
-
installPackage.mockImplementation((backendPath, spec) => {
|
|
378
|
-
const name = spec.replace(/@(next|latest)$/, '');
|
|
379
|
-
writeFakeModule(root, name, modules[name]);
|
|
380
|
-
});
|
|
381
|
-
|
|
382
|
-
await installCommand('hubspot');
|
|
383
|
-
|
|
384
|
-
expect(consoleErrorSpy.mock.calls).toEqual([]);
|
|
385
|
-
expect(processExitSpy).not.toHaveBeenCalled();
|
|
386
|
-
const backendJs = fs.readFileSync(
|
|
387
|
-
path.join(dir, 'backend.js'),
|
|
388
|
-
'utf8'
|
|
389
|
-
);
|
|
390
|
-
expect(backendJs).toContain(
|
|
391
|
-
"const HubSpotIntegration = require('./src/integrations/HubSpotIntegration');"
|
|
392
|
-
);
|
|
393
|
-
expect(backendJs).toContain('HubSpotIntegration,');
|
|
394
|
-
expect(fs.readFileSync(path.join(dir, 'index.js'), 'utf8')).toBe(
|
|
395
|
-
"module.exports = require('./backend');\n"
|
|
396
|
-
);
|
|
397
|
-
expect(
|
|
398
|
-
fs.existsSync(
|
|
399
|
-
path.join(dir, 'src/integrations/HubSpotIntegration.js')
|
|
400
|
-
)
|
|
401
|
-
).toBe(true);
|
|
402
|
-
});
|
|
196
|
+
it('should handle environment variables after installation', async () => {
|
|
197
|
+
await installCommand('slack');
|
|
198
|
+
|
|
199
|
+
expect(handleEnvVariables).toHaveBeenCalledWith(
|
|
200
|
+
mockBackendPath,
|
|
201
|
+
expect.stringContaining('@friggframework/api-module-slack')
|
|
202
|
+
);
|
|
403
203
|
});
|
|
404
204
|
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
expect(findNearestBackendPackageJson).not.toHaveBeenCalled();
|
|
414
|
-
expect(installPackage).not.toHaveBeenCalled();
|
|
415
|
-
}
|
|
416
|
-
);
|
|
417
|
-
|
|
418
|
-
it('exits when no app package.json is found', async () => {
|
|
419
|
-
findNearestBackendPackageJson.mockReturnValue(null);
|
|
420
|
-
|
|
421
|
-
await installCommand('hubspot');
|
|
422
|
-
|
|
423
|
-
expect(consoleErrorSpy).toHaveBeenCalledWith(
|
|
424
|
-
'An error occurred:',
|
|
425
|
-
expect.any(Error)
|
|
426
|
-
);
|
|
427
|
-
expect(processExitSpy).toHaveBeenCalledWith(1);
|
|
428
|
-
});
|
|
429
|
-
|
|
430
|
-
it('exits when the package does not exist', async () => {
|
|
431
|
-
useApp(makeScaffoldedApp());
|
|
432
|
-
const error = new Error('Package not found');
|
|
433
|
-
validatePackageExists.mockRejectedValue(error);
|
|
434
|
-
|
|
435
|
-
await installCommand('hubspot');
|
|
436
|
-
|
|
437
|
-
expect(consoleErrorSpy).toHaveBeenCalledWith(
|
|
438
|
-
'An error occurred:',
|
|
439
|
-
error
|
|
440
|
-
);
|
|
441
|
-
expect(processExitSpy).toHaveBeenCalledWith(1);
|
|
442
|
-
});
|
|
443
|
-
|
|
444
|
-
it('exits when npm install fails', async () => {
|
|
445
|
-
useApp(makeScaffoldedApp());
|
|
446
|
-
const error = new Error('npm install exited with code 1');
|
|
447
|
-
installPackage.mockImplementation(() => {
|
|
448
|
-
throw error;
|
|
449
|
-
});
|
|
450
|
-
|
|
451
|
-
await installCommand('hubspot');
|
|
452
|
-
|
|
453
|
-
expect(consoleErrorSpy).toHaveBeenCalledWith(
|
|
454
|
-
'An error occurred:',
|
|
455
|
-
error
|
|
456
|
-
);
|
|
457
|
-
expect(processExitSpy).toHaveBeenCalledWith(1);
|
|
458
|
-
});
|
|
459
|
-
|
|
460
|
-
it('exits when the installed package is not a Frigg API module', async () => {
|
|
461
|
-
const dir = makeScaffoldedApp();
|
|
462
|
-
useApp(dir);
|
|
463
|
-
modules[HUBSPOT] = { withDefinition: false };
|
|
464
|
-
|
|
465
|
-
await installCommand('hubspot');
|
|
466
|
-
|
|
467
|
-
expect(output()).toMatch(/does not export a Definition/);
|
|
468
|
-
expect(processExitSpy).toHaveBeenCalledWith(1);
|
|
469
|
-
expect(fs.existsSync(path.join(dir, 'src/integrations'))).toBe(
|
|
470
|
-
false
|
|
471
|
-
);
|
|
472
|
-
});
|
|
205
|
+
it('should log info messages during installation', async () => {
|
|
206
|
+
await installCommand('slack');
|
|
207
|
+
|
|
208
|
+
// Verify logger actually logged (we spy on console)
|
|
209
|
+
expect(consoleLogSpy).toHaveBeenCalledWith(
|
|
210
|
+
expect.stringContaining('Successfully installed @friggframework/api-module-slack')
|
|
211
|
+
);
|
|
473
212
|
});
|
|
474
|
-
});
|
|
475
213
|
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
214
|
+
it('should install multiple packages sequentially', async () => {
|
|
215
|
+
searchAndSelectPackage.mockResolvedValue([
|
|
216
|
+
'@friggframework/api-module-slack',
|
|
217
|
+
'@friggframework/api-module-hubspot'
|
|
218
|
+
]);
|
|
219
|
+
|
|
220
|
+
// Mock HubSpot module (Slack already mocked in beforeEach)
|
|
221
|
+
const path = require('path');
|
|
222
|
+
const hubspotPath = path.resolve(mockBackendPath, '../../node_modules/@friggframework/api-module-hubspot');
|
|
223
|
+
|
|
224
|
+
jest.doMock(hubspotPath, () => ({
|
|
225
|
+
Config: { label: 'HubSpot' },
|
|
226
|
+
Api: class HubSpotApi {}
|
|
227
|
+
}), { virtual: true });
|
|
228
|
+
|
|
229
|
+
await installCommand('crm');
|
|
230
|
+
|
|
231
|
+
expect(validatePackageExists).toHaveBeenCalledTimes(2);
|
|
232
|
+
expect(installPackage).toHaveBeenCalledTimes(2);
|
|
233
|
+
|
|
234
|
+
// Verify TWO integration files created
|
|
235
|
+
const integrationFiles = fs.writeFileSync.mock.calls.filter(call =>
|
|
236
|
+
call[0].includes('Integration.js') && !call[0].includes('backend.js')
|
|
237
|
+
);
|
|
238
|
+
expect(integrationFiles.length).toBe(2);
|
|
239
|
+
|
|
240
|
+
// Verify both files have correct names
|
|
241
|
+
expect(integrationFiles[0][0]).toContain('SlackIntegration.js');
|
|
242
|
+
expect(integrationFiles[1][0]).toContain('HubSpotIntegration.js');
|
|
504
243
|
});
|
|
505
244
|
|
|
506
|
-
it('
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
245
|
+
it('should sanitize label by removing invalid characters', async () => {
|
|
246
|
+
// Mock different package with special characters in label
|
|
247
|
+
searchAndSelectPackage.mockResolvedValue(['@friggframework/api-module-google-drive']);
|
|
248
|
+
|
|
249
|
+
const path = require('path');
|
|
250
|
+
const googleDrivePath = path.resolve(mockBackendPath, '../../node_modules/@friggframework/api-module-google-drive');
|
|
251
|
+
|
|
252
|
+
jest.doMock(googleDrivePath, () => ({
|
|
253
|
+
Config: { label: 'Google<Drive>' }, // Has invalid characters
|
|
254
|
+
Api: class GoogleDriveApi {}
|
|
255
|
+
}), { virtual: true });
|
|
256
|
+
|
|
257
|
+
await installCommand('google-drive');
|
|
258
|
+
|
|
259
|
+
// Verify sanitized label used in file name
|
|
260
|
+
const writeCall = fs.writeFileSync.mock.calls.find(call =>
|
|
261
|
+
call[0].includes('Integration.js')
|
|
262
|
+
);
|
|
263
|
+
|
|
264
|
+
// Should be GoogleDrive, not Google<Drive>
|
|
265
|
+
expect(writeCall[0]).toContain('GoogleDriveIntegration.js');
|
|
266
|
+
expect(writeCall[0]).not.toContain('<');
|
|
267
|
+
expect(writeCall[0]).not.toContain('>');
|
|
268
|
+
|
|
269
|
+
// Verify content uses sanitized name
|
|
270
|
+
expect(writeCall[1]).toContain('class GoogleDriveIntegration');
|
|
271
|
+
expect(writeCall[1]).not.toContain('Google<Drive>');
|
|
517
272
|
});
|
|
518
273
|
|
|
519
|
-
it('
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
const file = write(source);
|
|
274
|
+
it('should sanitize label by removing spaces', async () => {
|
|
275
|
+
// Mock different package with spaces in label
|
|
276
|
+
searchAndSelectPackage.mockResolvedValue(['@friggframework/api-module-google-calendar']);
|
|
523
277
|
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
278
|
+
const path = require('path');
|
|
279
|
+
const googleCalendarPath = path.resolve(mockBackendPath, '../../node_modules/@friggframework/api-module-google-calendar');
|
|
280
|
+
|
|
281
|
+
jest.doMock(googleCalendarPath, () => ({
|
|
282
|
+
Config: { label: 'Google Calendar' }, // Has spaces
|
|
283
|
+
Api: class GoogleCalendarApi {}
|
|
284
|
+
}), { virtual: true });
|
|
285
|
+
|
|
286
|
+
await installCommand('google-calendar');
|
|
287
|
+
|
|
288
|
+
// Verify sanitized label used in file name (no spaces)
|
|
289
|
+
const writeCall = fs.writeFileSync.mock.calls.find(call =>
|
|
290
|
+
call[0].includes('Integration.js')
|
|
291
|
+
);
|
|
292
|
+
|
|
293
|
+
expect(writeCall[0]).toContain('GoogleCalendarIntegration.js');
|
|
294
|
+
expect(writeCall[0]).not.toContain(' ');
|
|
295
|
+
|
|
296
|
+
// Verify content uses sanitized name
|
|
297
|
+
expect(writeCall[1]).toContain('class GoogleCalendarIntegration');
|
|
298
|
+
expect(writeCall[1]).not.toMatch(/class Google Calendar/);
|
|
528
299
|
});
|
|
300
|
+
});
|
|
301
|
+
|
|
302
|
+
describe('Early Exit Cases', () => {
|
|
303
|
+
it('should return early when no packages selected', async () => {
|
|
304
|
+
searchAndSelectPackage.mockResolvedValue([]);
|
|
529
305
|
|
|
530
|
-
|
|
531
|
-
const file = write('module.exports = { integrations: [ };\n');
|
|
306
|
+
await installCommand('slack');
|
|
532
307
|
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
});
|
|
308
|
+
expect(findNearestBackendPackageJson).not.toHaveBeenCalled();
|
|
309
|
+
expect(validatePackageExists).not.toHaveBeenCalled();
|
|
310
|
+
expect(installPackage).not.toHaveBeenCalled();
|
|
537
311
|
});
|
|
538
312
|
|
|
539
|
-
it('
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
313
|
+
it('should return early when packages is null', async () => {
|
|
314
|
+
searchAndSelectPackage.mockResolvedValue(null);
|
|
315
|
+
|
|
316
|
+
await installCommand('slack');
|
|
543
317
|
|
|
544
|
-
|
|
545
|
-
status: 'manual',
|
|
546
|
-
});
|
|
318
|
+
expect(findNearestBackendPackageJson).not.toHaveBeenCalled();
|
|
547
319
|
});
|
|
548
|
-
});
|
|
549
320
|
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
fs.writeJSONSync(path.join(dir, 'package.json'), pkg);
|
|
557
|
-
return dir;
|
|
558
|
-
};
|
|
559
|
-
|
|
560
|
-
it.each([
|
|
561
|
-
['2.0.0-next.115', `${HUBSPOT}@next`],
|
|
562
|
-
['2.0.0--canary.639.abc1234.0', `${HUBSPOT}@next`],
|
|
563
|
-
['^2.0.1', HUBSPOT],
|
|
564
|
-
['^1.2.2', HUBSPOT],
|
|
565
|
-
])('core %s installs %s', (range, spec) => {
|
|
566
|
-
expect(
|
|
567
|
-
getInstallSpec(
|
|
568
|
-
HUBSPOT,
|
|
569
|
-
appWith({ dependencies: { '@friggframework/core': range } })
|
|
570
|
-
)
|
|
571
|
-
).toBe(spec);
|
|
321
|
+
it('should return early when packages is undefined', async () => {
|
|
322
|
+
searchAndSelectPackage.mockResolvedValue(undefined);
|
|
323
|
+
|
|
324
|
+
await installCommand('slack');
|
|
325
|
+
|
|
326
|
+
expect(findNearestBackendPackageJson).not.toHaveBeenCalled();
|
|
572
327
|
});
|
|
328
|
+
});
|
|
329
|
+
|
|
330
|
+
describe('Error Handling', () => {
|
|
331
|
+
it('should log error and exit on searchAndSelectPackage failure', async () => {
|
|
332
|
+
const error = new Error('Search failed');
|
|
333
|
+
searchAndSelectPackage.mockRejectedValue(error);
|
|
573
334
|
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
dir,
|
|
580
|
-
'node_modules',
|
|
581
|
-
'@friggframework',
|
|
582
|
-
'core'
|
|
583
|
-
);
|
|
584
|
-
fs.ensureDirSync(coreDir);
|
|
585
|
-
fs.writeJSONSync(path.join(coreDir, 'package.json'), {
|
|
586
|
-
name: '@friggframework/core',
|
|
587
|
-
version: '2.0.0-next.0',
|
|
588
|
-
});
|
|
589
|
-
|
|
590
|
-
expect(getInstallSpec(HUBSPOT, dir)).toBe(`${HUBSPOT}@next`);
|
|
335
|
+
await installCommand('slack');
|
|
336
|
+
|
|
337
|
+
// Verify error logged via console.error (we spy on it)
|
|
338
|
+
expect(consoleErrorSpy).toHaveBeenCalledWith('An error occurred:', error);
|
|
339
|
+
expect(processExitSpy).toHaveBeenCalledWith(1);
|
|
591
340
|
});
|
|
592
341
|
|
|
593
|
-
it('
|
|
594
|
-
|
|
342
|
+
it('should log error and exit on validatePackageExists failure', async () => {
|
|
343
|
+
const error = new Error('Package not found');
|
|
344
|
+
validatePackageExists.mockRejectedValue(error);
|
|
345
|
+
|
|
346
|
+
await installCommand('slack');
|
|
347
|
+
|
|
348
|
+
expect(consoleErrorSpy).toHaveBeenCalledWith('An error occurred:', error);
|
|
349
|
+
expect(processExitSpy).toHaveBeenCalledWith(1);
|
|
595
350
|
});
|
|
596
|
-
});
|
|
597
351
|
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
process.env.GIT_AUTHOR_NAME = process.env.GIT_COMMITTER_NAME = 'Test';
|
|
609
|
-
process.env.GIT_AUTHOR_EMAIL = process.env.GIT_COMMITTER_EMAIL =
|
|
610
|
-
'test@example.com';
|
|
352
|
+
it('should log error and exit on installPackage failure', async () => {
|
|
353
|
+
const error = new Error('Installation failed');
|
|
354
|
+
installPackage.mockImplementation(() => {
|
|
355
|
+
throw error;
|
|
356
|
+
});
|
|
357
|
+
|
|
358
|
+
await installCommand('slack');
|
|
359
|
+
|
|
360
|
+
expect(consoleErrorSpy).toHaveBeenCalledWith('An error occurred:', error);
|
|
361
|
+
expect(processExitSpy).toHaveBeenCalledWith(1);
|
|
611
362
|
});
|
|
612
363
|
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
364
|
+
it('should log error and exit on file write failure (createIntegrationFile)', async () => {
|
|
365
|
+
// Make fs.writeFileSync throw - tests REAL error path
|
|
366
|
+
const error = new Error('EACCES: permission denied');
|
|
367
|
+
fs.writeFileSync.mockImplementation(() => {
|
|
368
|
+
throw error;
|
|
369
|
+
});
|
|
370
|
+
|
|
371
|
+
await installCommand('slack');
|
|
372
|
+
|
|
373
|
+
expect(consoleErrorSpy).toHaveBeenCalledWith('An error occurred:', expect.any(Error));
|
|
374
|
+
expect(processExitSpy).toHaveBeenCalledWith(1);
|
|
616
375
|
});
|
|
617
376
|
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
git(['config', 'user.email', 'test@example.com'], dir);
|
|
630
|
-
git(['config', 'commit.gpgsign', 'false'], dir);
|
|
631
|
-
fs.writeFileSync(path.join(dir, 'package.json'), '{}');
|
|
632
|
-
fs.writeFileSync(path.join(dir, 'unrelated.txt'), 'wip');
|
|
633
|
-
git(['add', 'unrelated.txt'], dir);
|
|
634
|
-
|
|
635
|
-
const committed = realCommit(
|
|
636
|
-
path.join(dir, 'package.json'),
|
|
637
|
-
'HubSpot',
|
|
638
|
-
[path.join(dir, 'package.json')]
|
|
639
|
-
);
|
|
640
|
-
|
|
641
|
-
expect(committed).toBe(true);
|
|
642
|
-
expect(
|
|
643
|
-
git(['show', '--name-only', '--format=%s', 'HEAD'], dir).stdout
|
|
644
|
-
).toBe('Add HubSpot integration\n\npackage.json\n');
|
|
645
|
-
expect(git(['diff', '--cached', '--name-only'], dir).stdout).toBe(
|
|
646
|
-
'unrelated.txt\n'
|
|
647
|
-
);
|
|
377
|
+
it('should log error and exit on backend.js read failure', async () => {
|
|
378
|
+
// Make fs.readFileSync throw - tests REAL error path
|
|
379
|
+
const error = new Error('ENOENT: file not found');
|
|
380
|
+
fs.readFileSync.mockImplementation(() => {
|
|
381
|
+
throw error;
|
|
382
|
+
});
|
|
383
|
+
|
|
384
|
+
await installCommand('slack');
|
|
385
|
+
|
|
386
|
+
expect(consoleErrorSpy).toHaveBeenCalledWith('An error occurred:', expect.any(Error));
|
|
387
|
+
expect(processExitSpy).toHaveBeenCalledWith(1);
|
|
648
388
|
});
|
|
649
389
|
|
|
650
|
-
it('
|
|
651
|
-
|
|
652
|
-
|
|
390
|
+
it('should log error and exit on handleEnvVariables failure', async () => {
|
|
391
|
+
const error = new Error('Env variables failed');
|
|
392
|
+
handleEnvVariables.mockRejectedValue(error);
|
|
393
|
+
|
|
394
|
+
await installCommand('slack');
|
|
653
395
|
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
path.join(dir, 'package.json'),
|
|
657
|
-
])
|
|
658
|
-
).toBe(false);
|
|
396
|
+
expect(consoleErrorSpy).toHaveBeenCalledWith('An error occurred:', error);
|
|
397
|
+
expect(processExitSpy).toHaveBeenCalledWith(1);
|
|
659
398
|
});
|
|
399
|
+
});
|
|
660
400
|
});
|