@friggframework/devtools 2.0.0-next.45 → 2.0.0-next.47
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/infrastructure/ARCHITECTURE.md +487 -0
- package/infrastructure/HEALTH.md +468 -0
- package/infrastructure/README.md +51 -0
- package/infrastructure/__tests__/postgres-config.test.js +914 -0
- package/infrastructure/__tests__/template-generation.test.js +687 -0
- package/infrastructure/create-frigg-infrastructure.js +1 -1
- package/infrastructure/docs/POSTGRES-CONFIGURATION.md +630 -0
- package/infrastructure/{DEPLOYMENT-INSTRUCTIONS.md → docs/deployment-instructions.md} +3 -3
- package/infrastructure/{IAM-POLICY-TEMPLATES.md → docs/iam-policy-templates.md} +9 -10
- package/infrastructure/domains/database/aurora-builder.js +809 -0
- package/infrastructure/domains/database/aurora-builder.test.js +950 -0
- package/infrastructure/domains/database/aurora-discovery.js +87 -0
- package/infrastructure/domains/database/aurora-discovery.test.js +188 -0
- package/infrastructure/domains/database/aurora-resolver.js +210 -0
- package/infrastructure/domains/database/aurora-resolver.test.js +347 -0
- package/infrastructure/domains/database/migration-builder.js +695 -0
- package/infrastructure/domains/database/migration-builder.test.js +294 -0
- package/infrastructure/domains/database/migration-resolver.js +163 -0
- package/infrastructure/domains/database/migration-resolver.test.js +337 -0
- package/infrastructure/domains/health/application/ports/IPropertyReconciler.js +164 -0
- package/infrastructure/domains/health/application/ports/IResourceDetector.js +129 -0
- package/infrastructure/domains/health/application/ports/IResourceImporter.js +142 -0
- package/infrastructure/domains/health/application/ports/IStackRepository.js +131 -0
- package/infrastructure/domains/health/application/ports/index.js +26 -0
- package/infrastructure/domains/health/application/use-cases/__tests__/execute-resource-import-use-case.test.js +679 -0
- package/infrastructure/domains/health/application/use-cases/__tests__/mismatch-analyzer-method-name.test.js +167 -0
- package/infrastructure/domains/health/application/use-cases/__tests__/repair-via-import-use-case.test.js +1130 -0
- package/infrastructure/domains/health/application/use-cases/execute-resource-import-use-case.js +221 -0
- package/infrastructure/domains/health/application/use-cases/reconcile-properties-use-case.js +152 -0
- package/infrastructure/domains/health/application/use-cases/reconcile-properties-use-case.test.js +343 -0
- package/infrastructure/domains/health/application/use-cases/repair-via-import-use-case.js +535 -0
- package/infrastructure/domains/health/application/use-cases/repair-via-import-use-case.test.js +376 -0
- package/infrastructure/domains/health/application/use-cases/run-health-check-use-case.js +213 -0
- package/infrastructure/domains/health/application/use-cases/run-health-check-use-case.test.js +441 -0
- package/infrastructure/domains/health/docs/ACME-DEV-DRIFT-ANALYSIS.md +267 -0
- package/infrastructure/domains/health/docs/BUILD-VS-DEPLOYED-TEMPLATE-ANALYSIS.md +324 -0
- package/infrastructure/domains/health/docs/ORPHAN-DETECTION-ANALYSIS.md +386 -0
- package/infrastructure/domains/health/docs/SPEC-CLEANUP-COMMAND.md +1419 -0
- package/infrastructure/domains/health/docs/TDD-IMPLEMENTATION-SUMMARY.md +391 -0
- package/infrastructure/domains/health/docs/TEMPLATE-COMPARISON-IMPLEMENTATION.md +551 -0
- package/infrastructure/domains/health/domain/entities/issue.js +299 -0
- package/infrastructure/domains/health/domain/entities/issue.test.js +528 -0
- package/infrastructure/domains/health/domain/entities/property-mismatch.js +108 -0
- package/infrastructure/domains/health/domain/entities/property-mismatch.test.js +275 -0
- package/infrastructure/domains/health/domain/entities/resource.js +159 -0
- package/infrastructure/domains/health/domain/entities/resource.test.js +432 -0
- package/infrastructure/domains/health/domain/entities/stack-health-report.js +306 -0
- package/infrastructure/domains/health/domain/entities/stack-health-report.test.js +601 -0
- package/infrastructure/domains/health/domain/services/__tests__/health-score-percentage-based.test.js +380 -0
- package/infrastructure/domains/health/domain/services/__tests__/import-progress-monitor.test.js +971 -0
- package/infrastructure/domains/health/domain/services/__tests__/import-template-generator.test.js +1150 -0
- package/infrastructure/domains/health/domain/services/__tests__/logical-id-mapper.test.js +672 -0
- package/infrastructure/domains/health/domain/services/__tests__/template-parser.test.js +496 -0
- package/infrastructure/domains/health/domain/services/__tests__/update-progress-monitor.test.js +419 -0
- package/infrastructure/domains/health/domain/services/health-score-calculator.js +248 -0
- package/infrastructure/domains/health/domain/services/health-score-calculator.test.js +504 -0
- package/infrastructure/domains/health/domain/services/import-progress-monitor.js +195 -0
- package/infrastructure/domains/health/domain/services/import-template-generator.js +435 -0
- package/infrastructure/domains/health/domain/services/logical-id-mapper.js +345 -0
- package/infrastructure/domains/health/domain/services/mismatch-analyzer.js +234 -0
- package/infrastructure/domains/health/domain/services/mismatch-analyzer.test.js +431 -0
- package/infrastructure/domains/health/domain/services/property-mutability-config.js +382 -0
- package/infrastructure/domains/health/domain/services/template-parser.js +245 -0
- package/infrastructure/domains/health/domain/services/update-progress-monitor.js +192 -0
- package/infrastructure/domains/health/domain/value-objects/health-score.js +138 -0
- package/infrastructure/domains/health/domain/value-objects/health-score.test.js +267 -0
- package/infrastructure/domains/health/domain/value-objects/property-mutability.js +161 -0
- package/infrastructure/domains/health/domain/value-objects/property-mutability.test.js +198 -0
- package/infrastructure/domains/health/domain/value-objects/resource-state.js +167 -0
- package/infrastructure/domains/health/domain/value-objects/resource-state.test.js +196 -0
- package/infrastructure/domains/health/domain/value-objects/stack-identifier.js +192 -0
- package/infrastructure/domains/health/domain/value-objects/stack-identifier.test.js +262 -0
- package/infrastructure/domains/health/infrastructure/adapters/__tests__/orphan-detection-cfn-tagged.test.js +312 -0
- package/infrastructure/domains/health/infrastructure/adapters/__tests__/orphan-detection-multi-stack.test.js +367 -0
- package/infrastructure/domains/health/infrastructure/adapters/__tests__/orphan-detection-relationship-analysis.test.js +432 -0
- package/infrastructure/domains/health/infrastructure/adapters/aws-property-reconciler.js +784 -0
- package/infrastructure/domains/health/infrastructure/adapters/aws-property-reconciler.test.js +1133 -0
- package/infrastructure/domains/health/infrastructure/adapters/aws-resource-detector.js +565 -0
- package/infrastructure/domains/health/infrastructure/adapters/aws-resource-detector.test.js +554 -0
- package/infrastructure/domains/health/infrastructure/adapters/aws-resource-importer.js +318 -0
- package/infrastructure/domains/health/infrastructure/adapters/aws-resource-importer.test.js +398 -0
- package/infrastructure/domains/health/infrastructure/adapters/aws-stack-repository.js +777 -0
- package/infrastructure/domains/health/infrastructure/adapters/aws-stack-repository.test.js +580 -0
- package/infrastructure/domains/integration/integration-builder.js +397 -0
- package/infrastructure/domains/integration/integration-builder.test.js +593 -0
- package/infrastructure/domains/integration/integration-resolver.js +170 -0
- package/infrastructure/domains/integration/integration-resolver.test.js +369 -0
- package/infrastructure/domains/integration/websocket-builder.js +69 -0
- package/infrastructure/domains/integration/websocket-builder.test.js +195 -0
- package/infrastructure/domains/networking/vpc-builder.js +1829 -0
- package/infrastructure/domains/networking/vpc-builder.test.js +1262 -0
- package/infrastructure/domains/networking/vpc-discovery.js +177 -0
- package/infrastructure/domains/networking/vpc-discovery.test.js +350 -0
- package/infrastructure/domains/networking/vpc-resolver.js +324 -0
- package/infrastructure/domains/networking/vpc-resolver.test.js +501 -0
- package/infrastructure/domains/parameters/ssm-builder.js +79 -0
- package/infrastructure/domains/parameters/ssm-builder.test.js +189 -0
- package/infrastructure/domains/parameters/ssm-discovery.js +84 -0
- package/infrastructure/domains/parameters/ssm-discovery.test.js +210 -0
- package/infrastructure/{iam-generator.js → domains/security/iam-generator.js} +2 -2
- package/infrastructure/domains/security/kms-builder.js +366 -0
- package/infrastructure/domains/security/kms-builder.test.js +374 -0
- package/infrastructure/domains/security/kms-discovery.js +80 -0
- package/infrastructure/domains/security/kms-discovery.test.js +177 -0
- package/infrastructure/domains/security/kms-resolver.js +96 -0
- package/infrastructure/domains/security/kms-resolver.test.js +216 -0
- package/infrastructure/domains/shared/base-builder.js +112 -0
- package/infrastructure/domains/shared/base-resolver.js +186 -0
- package/infrastructure/domains/shared/base-resolver.test.js +305 -0
- package/infrastructure/domains/shared/builder-orchestrator.js +212 -0
- package/infrastructure/domains/shared/builder-orchestrator.test.js +213 -0
- package/infrastructure/domains/shared/cloudformation-discovery-v2.js +334 -0
- package/infrastructure/domains/shared/cloudformation-discovery.js +375 -0
- package/infrastructure/domains/shared/cloudformation-discovery.test.js +590 -0
- package/infrastructure/domains/shared/environment-builder.js +119 -0
- package/infrastructure/domains/shared/environment-builder.test.js +247 -0
- package/infrastructure/domains/shared/providers/aws-provider-adapter.js +544 -0
- package/infrastructure/domains/shared/providers/aws-provider-adapter.test.js +377 -0
- package/infrastructure/domains/shared/providers/azure-provider-adapter.stub.js +93 -0
- package/infrastructure/domains/shared/providers/cloud-provider-adapter.js +136 -0
- package/infrastructure/domains/shared/providers/gcp-provider-adapter.stub.js +82 -0
- package/infrastructure/domains/shared/providers/provider-factory.js +108 -0
- package/infrastructure/domains/shared/providers/provider-factory.test.js +170 -0
- package/infrastructure/domains/shared/resource-discovery.js +192 -0
- package/infrastructure/domains/shared/resource-discovery.test.js +552 -0
- package/infrastructure/domains/shared/types/app-definition.js +205 -0
- package/infrastructure/domains/shared/types/discovery-result.js +106 -0
- package/infrastructure/domains/shared/types/discovery-result.test.js +258 -0
- package/infrastructure/domains/shared/types/index.js +46 -0
- package/infrastructure/domains/shared/types/resource-ownership.js +108 -0
- package/infrastructure/domains/shared/types/resource-ownership.test.js +101 -0
- package/infrastructure/domains/shared/utilities/base-definition-factory.js +380 -0
- package/infrastructure/domains/shared/utilities/base-definition-factory.js.bak +338 -0
- package/infrastructure/domains/shared/utilities/base-definition-factory.test.js +248 -0
- package/infrastructure/domains/shared/utilities/handler-path-resolver.js +134 -0
- package/infrastructure/domains/shared/utilities/handler-path-resolver.test.js +268 -0
- package/infrastructure/domains/shared/utilities/prisma-layer-manager.js +55 -0
- package/infrastructure/domains/shared/utilities/prisma-layer-manager.test.js +138 -0
- package/infrastructure/{env-validator.js → domains/shared/validation/env-validator.js} +2 -1
- package/infrastructure/domains/shared/validation/env-validator.test.js +173 -0
- package/infrastructure/esbuild.config.js +53 -0
- package/infrastructure/infrastructure-composer.js +87 -0
- package/infrastructure/{serverless-template.test.js → infrastructure-composer.test.js} +115 -24
- package/infrastructure/scripts/build-prisma-layer.js +553 -0
- package/infrastructure/scripts/build-prisma-layer.test.js +102 -0
- package/infrastructure/{build-time-discovery.js → scripts/build-time-discovery.js} +80 -48
- package/infrastructure/{build-time-discovery.test.js → scripts/build-time-discovery.test.js} +5 -4
- package/layers/prisma/nodejs/package.json +8 -0
- package/management-ui/server/utils/cliIntegration.js +1 -1
- package/management-ui/server/utils/environment/awsParameterStore.js +29 -18
- package/package.json +11 -11
- package/frigg-cli/.eslintrc.js +0 -141
- package/frigg-cli/__tests__/unit/commands/build.test.js +0 -251
- package/frigg-cli/__tests__/unit/commands/db-setup.test.js +0 -548
- package/frigg-cli/__tests__/unit/commands/install.test.js +0 -400
- package/frigg-cli/__tests__/unit/commands/ui.test.js +0 -346
- package/frigg-cli/__tests__/unit/utils/database-validator.test.js +0 -366
- package/frigg-cli/__tests__/unit/utils/error-messages.test.js +0 -304
- package/frigg-cli/__tests__/unit/utils/prisma-runner.test.js +0 -486
- package/frigg-cli/__tests__/utils/mock-factory.js +0 -270
- package/frigg-cli/__tests__/utils/prisma-mock.js +0 -194
- package/frigg-cli/__tests__/utils/test-fixtures.js +0 -463
- package/frigg-cli/__tests__/utils/test-setup.js +0 -287
- package/frigg-cli/build-command/index.js +0 -65
- package/frigg-cli/db-setup-command/index.js +0 -193
- package/frigg-cli/deploy-command/index.js +0 -175
- package/frigg-cli/generate-command/__tests__/generate-command.test.js +0 -301
- package/frigg-cli/generate-command/azure-generator.js +0 -43
- package/frigg-cli/generate-command/gcp-generator.js +0 -47
- package/frigg-cli/generate-command/index.js +0 -332
- package/frigg-cli/generate-command/terraform-generator.js +0 -555
- package/frigg-cli/generate-iam-command.js +0 -118
- package/frigg-cli/index.js +0 -75
- package/frigg-cli/index.test.js +0 -158
- package/frigg-cli/init-command/backend-first-handler.js +0 -756
- package/frigg-cli/init-command/index.js +0 -93
- package/frigg-cli/init-command/template-handler.js +0 -143
- package/frigg-cli/install-command/backend-js.js +0 -33
- package/frigg-cli/install-command/commit-changes.js +0 -16
- package/frigg-cli/install-command/environment-variables.js +0 -127
- package/frigg-cli/install-command/environment-variables.test.js +0 -136
- package/frigg-cli/install-command/index.js +0 -54
- package/frigg-cli/install-command/install-package.js +0 -13
- package/frigg-cli/install-command/integration-file.js +0 -30
- package/frigg-cli/install-command/logger.js +0 -12
- package/frigg-cli/install-command/template.js +0 -90
- package/frigg-cli/install-command/validate-package.js +0 -75
- package/frigg-cli/jest.config.js +0 -124
- package/frigg-cli/package.json +0 -54
- package/frigg-cli/start-command/index.js +0 -149
- package/frigg-cli/start-command/start-command.test.js +0 -297
- package/frigg-cli/test/init-command.test.js +0 -180
- package/frigg-cli/test/npm-registry.test.js +0 -319
- package/frigg-cli/ui-command/index.js +0 -154
- package/frigg-cli/utils/app-resolver.js +0 -319
- package/frigg-cli/utils/backend-path.js +0 -25
- package/frigg-cli/utils/database-validator.js +0 -161
- package/frigg-cli/utils/error-messages.js +0 -257
- package/frigg-cli/utils/npm-registry.js +0 -167
- package/frigg-cli/utils/prisma-runner.js +0 -280
- package/frigg-cli/utils/process-manager.js +0 -199
- package/frigg-cli/utils/repo-detection.js +0 -405
- package/infrastructure/aws-discovery.js +0 -1176
- package/infrastructure/aws-discovery.test.js +0 -1220
- package/infrastructure/serverless-template.js +0 -2094
- /package/infrastructure/{WEBSOCKET-CONFIGURATION.md → docs/WEBSOCKET-CONFIGURATION.md} +0 -0
- /package/infrastructure/{GENERATE-IAM-DOCS.md → docs/generate-iam-command.md} +0 -0
- /package/infrastructure/{iam-generator.test.js → domains/security/iam-generator.test.js} +0 -0
- /package/infrastructure/{frigg-deployment-iam-stack.yaml → domains/security/templates/frigg-deployment-iam-stack.yaml} +0 -0
- /package/infrastructure/{iam-policy-basic.json → domains/security/templates/iam-policy-basic.json} +0 -0
- /package/infrastructure/{iam-policy-full.json → domains/security/templates/iam-policy-full.json} +0 -0
- /package/infrastructure/{run-discovery.js → scripts/run-discovery.js} +0 -0
|
@@ -1,486 +0,0 @@
|
|
|
1
|
-
// Mock dependencies BEFORE requiring modules
|
|
2
|
-
jest.mock('child_process', () => ({
|
|
3
|
-
execSync: jest.fn(),
|
|
4
|
-
spawn: jest.fn()
|
|
5
|
-
}));
|
|
6
|
-
jest.mock('fs', () => ({
|
|
7
|
-
existsSync: jest.fn(),
|
|
8
|
-
readFileSync: jest.fn(),
|
|
9
|
-
writeFileSync: jest.fn()
|
|
10
|
-
}));
|
|
11
|
-
|
|
12
|
-
const { execSync, spawn } = require('child_process');
|
|
13
|
-
const fs = require('fs');
|
|
14
|
-
const {
|
|
15
|
-
getPrismaSchemaPath,
|
|
16
|
-
runPrismaGenerate,
|
|
17
|
-
checkDatabaseState,
|
|
18
|
-
runPrismaMigrate,
|
|
19
|
-
runPrismaDbPush,
|
|
20
|
-
getMigrationCommand
|
|
21
|
-
} = require('../../../utils/prisma-runner');
|
|
22
|
-
|
|
23
|
-
describe('Prisma Runner Utility', () => {
|
|
24
|
-
beforeEach(() => {
|
|
25
|
-
jest.clearAllMocks();
|
|
26
|
-
delete process.env.STAGE;
|
|
27
|
-
delete process.env.PRISMA_HIDE_UPDATE_MESSAGE;
|
|
28
|
-
});
|
|
29
|
-
|
|
30
|
-
afterEach(() => {
|
|
31
|
-
delete process.env.STAGE;
|
|
32
|
-
delete process.env.PRISMA_HIDE_UPDATE_MESSAGE;
|
|
33
|
-
});
|
|
34
|
-
|
|
35
|
-
describe('getPrismaSchemaPath()', () => {
|
|
36
|
-
it('should return correct path for MongoDB', () => {
|
|
37
|
-
fs.existsSync.mockReturnValue(true);
|
|
38
|
-
|
|
39
|
-
const path = getPrismaSchemaPath('mongodb');
|
|
40
|
-
|
|
41
|
-
expect(path).toContain('prisma-mongodb');
|
|
42
|
-
expect(path).toContain('schema.prisma');
|
|
43
|
-
expect(path).toContain('@friggframework/core');
|
|
44
|
-
});
|
|
45
|
-
|
|
46
|
-
it('should return correct path for PostgreSQL', () => {
|
|
47
|
-
fs.existsSync.mockReturnValue(true);
|
|
48
|
-
|
|
49
|
-
const path = getPrismaSchemaPath('postgresql');
|
|
50
|
-
|
|
51
|
-
expect(path).toContain('prisma-postgresql');
|
|
52
|
-
expect(path).toContain('schema.prisma');
|
|
53
|
-
expect(path).toContain('@friggframework/core');
|
|
54
|
-
});
|
|
55
|
-
|
|
56
|
-
it('should throw error when schema file does not exist', () => {
|
|
57
|
-
fs.existsSync.mockReturnValue(false);
|
|
58
|
-
|
|
59
|
-
expect(() => getPrismaSchemaPath('mongodb')).toThrow('Prisma schema not found');
|
|
60
|
-
});
|
|
61
|
-
|
|
62
|
-
it('should include helpful error message when schema missing', () => {
|
|
63
|
-
fs.existsSync.mockReturnValue(false);
|
|
64
|
-
|
|
65
|
-
expect(() => getPrismaSchemaPath('mongodb')).toThrow('@friggframework/core');
|
|
66
|
-
});
|
|
67
|
-
|
|
68
|
-
it('should use process.cwd() for base path', () => {
|
|
69
|
-
fs.existsSync.mockReturnValue(true);
|
|
70
|
-
const originalCwd = process.cwd();
|
|
71
|
-
|
|
72
|
-
const path = getPrismaSchemaPath('mongodb');
|
|
73
|
-
|
|
74
|
-
expect(path).toContain(originalCwd);
|
|
75
|
-
});
|
|
76
|
-
|
|
77
|
-
it('should accept custom project root', () => {
|
|
78
|
-
fs.existsSync.mockReturnValue(true);
|
|
79
|
-
const customRoot = '/custom/project';
|
|
80
|
-
|
|
81
|
-
const path = getPrismaSchemaPath('mongodb', customRoot);
|
|
82
|
-
|
|
83
|
-
expect(path).toContain(customRoot);
|
|
84
|
-
});
|
|
85
|
-
});
|
|
86
|
-
|
|
87
|
-
describe('runPrismaGenerate()', () => {
|
|
88
|
-
beforeEach(() => {
|
|
89
|
-
fs.existsSync.mockReturnValue(true);
|
|
90
|
-
});
|
|
91
|
-
|
|
92
|
-
it('should execute prisma generate successfully', async () => {
|
|
93
|
-
execSync.mockReturnValue('Generated successfully');
|
|
94
|
-
|
|
95
|
-
const result = await runPrismaGenerate('mongodb');
|
|
96
|
-
|
|
97
|
-
expect(result.success).toBe(true);
|
|
98
|
-
expect(execSync).toHaveBeenCalled();
|
|
99
|
-
});
|
|
100
|
-
|
|
101
|
-
it('should use correct schema path for MongoDB', async () => {
|
|
102
|
-
execSync.mockReturnValue('');
|
|
103
|
-
|
|
104
|
-
await runPrismaGenerate('mongodb');
|
|
105
|
-
|
|
106
|
-
const call = execSync.mock.calls[0][0];
|
|
107
|
-
expect(call).toContain('prisma generate');
|
|
108
|
-
expect(call).toContain('--schema');
|
|
109
|
-
expect(call).toContain('prisma-mongodb');
|
|
110
|
-
});
|
|
111
|
-
|
|
112
|
-
it('should use correct schema path for PostgreSQL', async () => {
|
|
113
|
-
execSync.mockReturnValue('');
|
|
114
|
-
|
|
115
|
-
await runPrismaGenerate('postgresql');
|
|
116
|
-
|
|
117
|
-
const call = execSync.mock.calls[0][0];
|
|
118
|
-
expect(call).toContain('prisma-postgresql');
|
|
119
|
-
});
|
|
120
|
-
|
|
121
|
-
it('should suppress telemetry when verbose false', async () => {
|
|
122
|
-
execSync.mockReturnValue('');
|
|
123
|
-
|
|
124
|
-
await runPrismaGenerate('mongodb', false);
|
|
125
|
-
|
|
126
|
-
const options = execSync.mock.calls[0][1];
|
|
127
|
-
expect(options.env.PRISMA_HIDE_UPDATE_MESSAGE).toBe('1');
|
|
128
|
-
});
|
|
129
|
-
|
|
130
|
-
it('should show output when verbose true', async () => {
|
|
131
|
-
execSync.mockReturnValue('Generated successfully');
|
|
132
|
-
|
|
133
|
-
await runPrismaGenerate('mongodb', true);
|
|
134
|
-
|
|
135
|
-
const options = execSync.mock.calls[0][1];
|
|
136
|
-
expect(options.stdio).toBe('inherit');
|
|
137
|
-
});
|
|
138
|
-
|
|
139
|
-
it('should hide output when verbose false', async () => {
|
|
140
|
-
execSync.mockReturnValue('');
|
|
141
|
-
|
|
142
|
-
await runPrismaGenerate('mongodb', false);
|
|
143
|
-
|
|
144
|
-
const options = execSync.mock.calls[0][1];
|
|
145
|
-
expect(options.stdio).toBe('pipe');
|
|
146
|
-
});
|
|
147
|
-
|
|
148
|
-
it('should handle generation failures with error details', async () => {
|
|
149
|
-
const error = new Error('Generation failed');
|
|
150
|
-
error.stdout = 'Schema validation error';
|
|
151
|
-
execSync.mockImplementation(() => {
|
|
152
|
-
throw error;
|
|
153
|
-
});
|
|
154
|
-
|
|
155
|
-
const result = await runPrismaGenerate('mongodb');
|
|
156
|
-
|
|
157
|
-
expect(result.success).toBe(false);
|
|
158
|
-
expect(result.error).toContain('Generation failed');
|
|
159
|
-
});
|
|
160
|
-
|
|
161
|
-
it('should include stdout in error output', async () => {
|
|
162
|
-
const error = new Error('Failed');
|
|
163
|
-
error.stdout = Buffer.from('Detailed error info');
|
|
164
|
-
execSync.mockImplementation(() => {
|
|
165
|
-
throw error;
|
|
166
|
-
});
|
|
167
|
-
|
|
168
|
-
const result = await runPrismaGenerate('mongodb');
|
|
169
|
-
|
|
170
|
-
expect(result.output).toContain('Detailed error info');
|
|
171
|
-
});
|
|
172
|
-
|
|
173
|
-
it('should handle schema syntax errors', async () => {
|
|
174
|
-
execSync.mockImplementation(() => {
|
|
175
|
-
throw new Error('Schema parsing failed');
|
|
176
|
-
});
|
|
177
|
-
|
|
178
|
-
const result = await runPrismaGenerate('mongodb');
|
|
179
|
-
|
|
180
|
-
expect(result.success).toBe(false);
|
|
181
|
-
expect(result.error).toBeDefined();
|
|
182
|
-
});
|
|
183
|
-
});
|
|
184
|
-
|
|
185
|
-
describe('checkDatabaseState()', () => {
|
|
186
|
-
beforeEach(() => {
|
|
187
|
-
fs.existsSync.mockReturnValue(true);
|
|
188
|
-
});
|
|
189
|
-
|
|
190
|
-
it('should return upToDate: true when migrations current (PostgreSQL)', async () => {
|
|
191
|
-
execSync.mockReturnValue('Database schema is up to date');
|
|
192
|
-
|
|
193
|
-
const result = await checkDatabaseState('postgresql');
|
|
194
|
-
|
|
195
|
-
expect(result.upToDate).toBe(true);
|
|
196
|
-
});
|
|
197
|
-
|
|
198
|
-
it('should return upToDate: true for MongoDB (N/A)', async () => {
|
|
199
|
-
const result = await checkDatabaseState('mongodb');
|
|
200
|
-
|
|
201
|
-
expect(result.upToDate).toBe(true);
|
|
202
|
-
});
|
|
203
|
-
|
|
204
|
-
it('should return pendingMigrations count when migrations pending', async () => {
|
|
205
|
-
execSync.mockReturnValue('3 migrations have not been applied');
|
|
206
|
-
|
|
207
|
-
const result = await checkDatabaseState('postgresql');
|
|
208
|
-
|
|
209
|
-
expect(result.upToDate).toBe(false);
|
|
210
|
-
expect(result.pendingMigrations).toBe(3);
|
|
211
|
-
});
|
|
212
|
-
|
|
213
|
-
it('should handle uninitialized database', async () => {
|
|
214
|
-
execSync.mockImplementation(() => {
|
|
215
|
-
throw new Error('No migrations found');
|
|
216
|
-
});
|
|
217
|
-
|
|
218
|
-
const result = await checkDatabaseState('postgresql');
|
|
219
|
-
|
|
220
|
-
expect(result.upToDate).toBe(false);
|
|
221
|
-
expect(result.error).toBeDefined();
|
|
222
|
-
});
|
|
223
|
-
|
|
224
|
-
it('should handle migrate status command errors', async () => {
|
|
225
|
-
execSync.mockImplementation(() => {
|
|
226
|
-
throw new Error('Migration status failed');
|
|
227
|
-
});
|
|
228
|
-
|
|
229
|
-
const result = await checkDatabaseState('postgresql');
|
|
230
|
-
|
|
231
|
-
expect(result.upToDate).toBe(false);
|
|
232
|
-
expect(result.error).toContain('Migration status failed');
|
|
233
|
-
});
|
|
234
|
-
|
|
235
|
-
it('should not run migrate status for MongoDB', async () => {
|
|
236
|
-
await checkDatabaseState('mongodb');
|
|
237
|
-
|
|
238
|
-
expect(execSync).not.toHaveBeenCalled();
|
|
239
|
-
});
|
|
240
|
-
});
|
|
241
|
-
|
|
242
|
-
describe('runPrismaMigrate()', () => {
|
|
243
|
-
let mockChildProcess;
|
|
244
|
-
|
|
245
|
-
beforeEach(() => {
|
|
246
|
-
fs.existsSync.mockReturnValue(true);
|
|
247
|
-
mockChildProcess = {
|
|
248
|
-
on: jest.fn((event, callback) => {
|
|
249
|
-
if (event === 'close') {
|
|
250
|
-
callback(0);
|
|
251
|
-
}
|
|
252
|
-
}),
|
|
253
|
-
stdout: { on: jest.fn() },
|
|
254
|
-
stderr: { on: jest.fn() }
|
|
255
|
-
};
|
|
256
|
-
spawn.mockReturnValue(mockChildProcess);
|
|
257
|
-
});
|
|
258
|
-
|
|
259
|
-
it('should run migrate dev successfully', async () => {
|
|
260
|
-
const result = await runPrismaMigrate('dev');
|
|
261
|
-
|
|
262
|
-
expect(result.success).toBe(true);
|
|
263
|
-
expect(spawn).toHaveBeenCalled();
|
|
264
|
-
});
|
|
265
|
-
|
|
266
|
-
it('should run migrate deploy successfully', async () => {
|
|
267
|
-
const result = await runPrismaMigrate('deploy');
|
|
268
|
-
|
|
269
|
-
expect(result.success).toBe(true);
|
|
270
|
-
expect(spawn).toHaveBeenCalled();
|
|
271
|
-
});
|
|
272
|
-
|
|
273
|
-
it('should use correct command for dev mode', async () => {
|
|
274
|
-
await runPrismaMigrate('dev');
|
|
275
|
-
|
|
276
|
-
const args = spawn.mock.calls[0][1];
|
|
277
|
-
expect(args).toContain('migrate');
|
|
278
|
-
expect(args).toContain('dev');
|
|
279
|
-
});
|
|
280
|
-
|
|
281
|
-
it('should use correct command for deploy mode', async () => {
|
|
282
|
-
await runPrismaMigrate('deploy');
|
|
283
|
-
|
|
284
|
-
const args = spawn.mock.calls[0][1];
|
|
285
|
-
expect(args).toContain('migrate');
|
|
286
|
-
expect(args).toContain('deploy');
|
|
287
|
-
});
|
|
288
|
-
|
|
289
|
-
it('should handle migration failures with error', async () => {
|
|
290
|
-
mockChildProcess.on.mockImplementation((event, callback) => {
|
|
291
|
-
if (event === 'close') {
|
|
292
|
-
callback(1); // Exit code 1
|
|
293
|
-
}
|
|
294
|
-
});
|
|
295
|
-
|
|
296
|
-
const result = await runPrismaMigrate('dev');
|
|
297
|
-
|
|
298
|
-
expect(result.success).toBe(false);
|
|
299
|
-
expect(result.error).toContain('exited with code 1');
|
|
300
|
-
});
|
|
301
|
-
|
|
302
|
-
it('should respect verbose flag', async () => {
|
|
303
|
-
await runPrismaMigrate('dev', true);
|
|
304
|
-
|
|
305
|
-
const options = spawn.mock.calls[0][2];
|
|
306
|
-
expect(options.stdio).toBe('inherit');
|
|
307
|
-
});
|
|
308
|
-
|
|
309
|
-
it('should handle process spawn errors', async () => {
|
|
310
|
-
mockChildProcess.on.mockImplementation((event, callback) => {
|
|
311
|
-
if (event === 'error') {
|
|
312
|
-
callback(new Error('Spawn failed'));
|
|
313
|
-
}
|
|
314
|
-
});
|
|
315
|
-
|
|
316
|
-
const result = await runPrismaMigrate('dev');
|
|
317
|
-
|
|
318
|
-
expect(result.success).toBe(false);
|
|
319
|
-
});
|
|
320
|
-
|
|
321
|
-
it('should hide telemetry messages', async () => {
|
|
322
|
-
await runPrismaMigrate('dev');
|
|
323
|
-
|
|
324
|
-
const options = spawn.mock.calls[0][2];
|
|
325
|
-
expect(options.env.PRISMA_HIDE_UPDATE_MESSAGE).toBe('1');
|
|
326
|
-
});
|
|
327
|
-
});
|
|
328
|
-
|
|
329
|
-
describe('runPrismaDbPush()', () => {
|
|
330
|
-
let mockChildProcess;
|
|
331
|
-
|
|
332
|
-
beforeEach(() => {
|
|
333
|
-
fs.existsSync.mockReturnValue(true);
|
|
334
|
-
mockChildProcess = {
|
|
335
|
-
on: jest.fn((event, callback) => {
|
|
336
|
-
if (event === 'close') {
|
|
337
|
-
callback(0);
|
|
338
|
-
}
|
|
339
|
-
}),
|
|
340
|
-
stdout: { on: jest.fn() },
|
|
341
|
-
stderr: { on: jest.fn() }
|
|
342
|
-
};
|
|
343
|
-
spawn.mockReturnValue(mockChildProcess);
|
|
344
|
-
});
|
|
345
|
-
|
|
346
|
-
it('should push schema successfully for MongoDB', async () => {
|
|
347
|
-
const result = await runPrismaDbPush();
|
|
348
|
-
|
|
349
|
-
expect(result.success).toBe(true);
|
|
350
|
-
expect(spawn).toHaveBeenCalled();
|
|
351
|
-
});
|
|
352
|
-
|
|
353
|
-
it('should use --skip-generate flag', async () => {
|
|
354
|
-
await runPrismaDbPush();
|
|
355
|
-
|
|
356
|
-
const args = spawn.mock.calls[0][1];
|
|
357
|
-
expect(args).toContain('--skip-generate');
|
|
358
|
-
});
|
|
359
|
-
|
|
360
|
-
it('should use db push command', async () => {
|
|
361
|
-
await runPrismaDbPush();
|
|
362
|
-
|
|
363
|
-
const args = spawn.mock.calls[0][1];
|
|
364
|
-
expect(args).toContain('db');
|
|
365
|
-
expect(args).toContain('push');
|
|
366
|
-
});
|
|
367
|
-
|
|
368
|
-
it('should handle push failures with error', async () => {
|
|
369
|
-
mockChildProcess.on.mockImplementation((event, callback) => {
|
|
370
|
-
if (event === 'close') {
|
|
371
|
-
callback(1);
|
|
372
|
-
}
|
|
373
|
-
});
|
|
374
|
-
|
|
375
|
-
const result = await runPrismaDbPush();
|
|
376
|
-
|
|
377
|
-
expect(result.success).toBe(false);
|
|
378
|
-
expect(result.error).toContain('exited with code 1');
|
|
379
|
-
});
|
|
380
|
-
|
|
381
|
-
it('should respect verbose flag', async () => {
|
|
382
|
-
await runPrismaDbPush(true);
|
|
383
|
-
|
|
384
|
-
const options = spawn.mock.calls[0][2];
|
|
385
|
-
expect(options.stdio).toBe('inherit');
|
|
386
|
-
});
|
|
387
|
-
|
|
388
|
-
it('should use interactive mode (stdio: inherit)', async () => {
|
|
389
|
-
await runPrismaDbPush();
|
|
390
|
-
|
|
391
|
-
const options = spawn.mock.calls[0][2];
|
|
392
|
-
expect(options.stdio).toBe('inherit');
|
|
393
|
-
});
|
|
394
|
-
|
|
395
|
-
it('should handle schema validation errors', async () => {
|
|
396
|
-
mockChildProcess.on.mockImplementation((event, callback) => {
|
|
397
|
-
if (event === 'close') {
|
|
398
|
-
callback(1);
|
|
399
|
-
}
|
|
400
|
-
});
|
|
401
|
-
|
|
402
|
-
const result = await runPrismaDbPush();
|
|
403
|
-
|
|
404
|
-
expect(result.success).toBe(false);
|
|
405
|
-
});
|
|
406
|
-
});
|
|
407
|
-
|
|
408
|
-
describe('getMigrationCommand()', () => {
|
|
409
|
-
it('should return dev for development stage', () => {
|
|
410
|
-
const command = getMigrationCommand('development');
|
|
411
|
-
|
|
412
|
-
expect(command).toBe('dev');
|
|
413
|
-
});
|
|
414
|
-
|
|
415
|
-
it('should return dev for dev stage', () => {
|
|
416
|
-
const command = getMigrationCommand('dev');
|
|
417
|
-
|
|
418
|
-
expect(command).toBe('dev');
|
|
419
|
-
});
|
|
420
|
-
|
|
421
|
-
it('should return dev for local stage', () => {
|
|
422
|
-
const command = getMigrationCommand('local');
|
|
423
|
-
|
|
424
|
-
expect(command).toBe('dev');
|
|
425
|
-
});
|
|
426
|
-
|
|
427
|
-
it('should return dev for test stage', () => {
|
|
428
|
-
const command = getMigrationCommand('test');
|
|
429
|
-
|
|
430
|
-
expect(command).toBe('dev');
|
|
431
|
-
});
|
|
432
|
-
|
|
433
|
-
it('should return deploy for production stage', () => {
|
|
434
|
-
const command = getMigrationCommand('production');
|
|
435
|
-
|
|
436
|
-
expect(command).toBe('deploy');
|
|
437
|
-
});
|
|
438
|
-
|
|
439
|
-
it('should return deploy for prod stage', () => {
|
|
440
|
-
const command = getMigrationCommand('prod');
|
|
441
|
-
|
|
442
|
-
expect(command).toBe('deploy');
|
|
443
|
-
});
|
|
444
|
-
|
|
445
|
-
it('should return deploy for staging stage', () => {
|
|
446
|
-
const command = getMigrationCommand('staging');
|
|
447
|
-
|
|
448
|
-
expect(command).toBe('deploy');
|
|
449
|
-
});
|
|
450
|
-
|
|
451
|
-
it('should default to dev when stage undefined', () => {
|
|
452
|
-
const command = getMigrationCommand();
|
|
453
|
-
|
|
454
|
-
expect(command).toBe('dev');
|
|
455
|
-
});
|
|
456
|
-
|
|
457
|
-
it('should read from STAGE environment variable when no argument', () => {
|
|
458
|
-
process.env.STAGE = 'production';
|
|
459
|
-
|
|
460
|
-
const command = getMigrationCommand();
|
|
461
|
-
|
|
462
|
-
expect(command).toBe('deploy');
|
|
463
|
-
});
|
|
464
|
-
|
|
465
|
-
it('should prioritize argument over STAGE env var', () => {
|
|
466
|
-
process.env.STAGE = 'production';
|
|
467
|
-
|
|
468
|
-
const command = getMigrationCommand('development');
|
|
469
|
-
|
|
470
|
-
expect(command).toBe('dev');
|
|
471
|
-
});
|
|
472
|
-
|
|
473
|
-
it('should handle case-insensitive stage names', () => {
|
|
474
|
-
expect(getMigrationCommand('DEVELOPMENT')).toBe('dev');
|
|
475
|
-
expect(getMigrationCommand('PRODUCTION')).toBe('deploy');
|
|
476
|
-
expect(getMigrationCommand('Dev')).toBe('dev');
|
|
477
|
-
expect(getMigrationCommand('Prod')).toBe('deploy');
|
|
478
|
-
});
|
|
479
|
-
|
|
480
|
-
it('should return deploy for unknown stages', () => {
|
|
481
|
-
const command = getMigrationCommand('unknown-stage');
|
|
482
|
-
|
|
483
|
-
expect(command).toBe('deploy');
|
|
484
|
-
});
|
|
485
|
-
});
|
|
486
|
-
});
|