Skip to content

Commit c7723cb

Browse files
committed
fix: Fixed tests
1 parent bdc7398 commit c7723cb

6 files changed

Lines changed: 83 additions & 33 deletions

File tree

codify.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,8 @@
5656
"sshpass",
5757
"tart",
5858
"xz",
59-
"zstd"
59+
"zstd",
60+
"f1bonacc1/tap/process-compose"
6061
]
6162
},
6263
{ "version":"1.10.5","type":"terraform" },

src/orchestrators/destroy.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@ export class DestroyOrchestrator {
3434
? await DestroyOrchestrator.destroyExistingProject(reporter, initializationResult)
3535
: await DestroyOrchestrator.destroySpecificResources(typeIds, reporter, initializationResult)
3636

37-
3837
plan.sortByEvalOrder(project.evaluationOrder);
3938
destroyProject.removeNoopFromEvaluationOrder(plan);
4039

@@ -70,7 +69,8 @@ Open a new terminal or source '.zshrc' for the new changes to be reflected`);
7069
): Promise<{ plan: Plan, destroyProject: Project }> {
7170
const { project, pluginManager, typeIdsToDependenciesMap } = initializeResult;
7271

73-
const matchedTypes = this.matchTypeIds(typeIds, [...typeIdsToDependenciesMap.keys()])
72+
// TODO: In the future if a user supplies resourceId.name (naming a specific resource) destroy that resource instead of stripping the name out.
73+
const matchedTypes = this.matchTypeIds(typeIds.map((id) => id.split('.').at(0) ?? ''), [...typeIdsToDependenciesMap.keys()])
7474
await DestroyOrchestrator.validateTypeIds(matchedTypes, project, pluginManager, typeIdsToDependenciesMap);
7575

7676
const resourceInfoList = (await pluginManager.getMultipleResourceInfo(matchedTypes));
@@ -139,7 +139,7 @@ Open a new terminal or source '.zshrc' for the new changes to be reflected`);
139139
}
140140

141141
if (unsupportedTypeIds.length > 0) {
142-
throw new Error(`The following resources cannot be imported. No plugins found that support the following types:
142+
throw new Error(`The following resources cannot be destroyed. No plugins found that support the following types:
143143
${JSON.stringify(unsupportedTypeIds)}`);
144144
}
145145

src/ui/components/multi-select/MultiSelect.test.tsx

Lines changed: 0 additions & 21 deletions
This file was deleted.

test/orchestrator/destroy/destroy.test.ts

Lines changed: 49 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ import { ResourceOperation } from 'codify-schemas';
88
import { MockReporter } from '../mocks/reporter.js';
99
import { MockResource, MockResourceConfig } from '../mocks/resource';
1010
import { ResourceSettings } from 'codify-plugin-lib';
11+
import { ResourceInfo } from '../../../src/entities/resource-info';
12+
import { ResourceConfig } from '../../../src/entities/resource-config';
1113

1214
vi.mock('../mocks/get-mock-resources.js', async () => {
1315
return {
@@ -39,6 +41,21 @@ describe('Destroy orchestrator tests', () => {
3941
expect(plan.getResourcePlan('mock')).toMatchObject({
4042
operation: ResourceOperation.DESTROY,
4143
});
44+
},
45+
promptUserForValues(info: ResourceInfo[]): ResourceConfig[] {
46+
expect(info.length).to.eq(1);
47+
expect(info[0]).toMatchObject({
48+
type: 'mock',
49+
importAndDestroy: {
50+
requiredParameters: expect.arrayContaining(['propB']),
51+
}
52+
})
53+
54+
return [new ResourceConfig({
55+
type: 'mock',
56+
propA: 'current',
57+
propB: 1,
58+
})]
4259
}
4360
});
4461

@@ -62,12 +79,24 @@ describe('Destroy orchestrator tests', () => {
6279
it('Can handle a destroy call on a resource that doesn\'t exist', { timeout: 3000000 }, async () => {
6380
const reporter = new MockReporter({
6481
validatePlan(plan: Plan) {
65-
expect(plan.getResourcePlan('mock.0')).toMatchObject({
66-
operation: ResourceOperation.NOOP,
67-
});
68-
expect(plan.getResourcePlan('mock.1')).toMatchObject({
82+
expect(plan.getResourcePlan('mock')).toMatchObject({
6983
operation: ResourceOperation.NOOP,
7084
});
85+
},
86+
promptUserForValues(info: ResourceInfo[]): ResourceConfig[] {
87+
expect(info.length).to.eq(1);
88+
expect(info[0]).toMatchObject({
89+
type: 'mock',
90+
importAndDestroy: {
91+
requiredParameters: expect.arrayContaining(['propB']),
92+
}
93+
})
94+
95+
return [new ResourceConfig({
96+
type: 'mock',
97+
propA: 'current',
98+
propB: 1,
99+
})]
71100
}
72101
});
73102

@@ -82,10 +111,24 @@ describe('Destroy orchestrator tests', () => {
82111
it('Can handle destroying only one resource', async () => {
83112
const reporter = new MockReporter({
84113
validatePlan(plan: Plan) {
85-
expect(plan.getResourcePlan('mock.0')).toMatchObject({
114+
expect(plan.getResourcePlan('mock')).toMatchObject({
86115
operation: ResourceOperation.DESTROY,
87116
});
88-
expect(plan.getResourcePlan('mock.1')).to.be.null;
117+
},
118+
promptUserForValues(info: ResourceInfo[]): ResourceConfig[] {
119+
expect(info.length).to.eq(1);
120+
expect(info[0]).toMatchObject({
121+
type: 'mock',
122+
importAndDestroy: {
123+
requiredParameters: expect.arrayContaining(['propB']),
124+
}
125+
})
126+
127+
return [new ResourceConfig({
128+
type: 'mock',
129+
propA: 'current',
130+
propB: 1,
131+
})]
89132
}
90133
});
91134

test/orchestrator/import/import.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -224,7 +224,7 @@ describe('Import orchestrator tests', () => {
224224
name: 'requiredProp',
225225
type: 'string',
226226
value: "this-jenv",
227-
isRequired: true,
227+
isRequiredForImport: true,
228228
}),
229229
]))
230230

@@ -594,7 +594,7 @@ describe('Import orchestrator tests', () => {
594594
name: 'requiredProp',
595595
type: 'string',
596596
value: "this-jenv",
597-
isRequired: true,
597+
isRequiredForImport: true,
598598
}),
599599
]))
600600

test/orchestrator/mocks/reporter.ts

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,14 @@ export interface MockReporterConfig {
1515
promptConfirmation?: () => boolean;
1616
promptOptions?: (message: string, options: string[]) => number;
1717
promptUserForValues?: (resourceInfo: ResourceInfo[]) => Promise<ResourceConfig[]> | ResourceConfig[];
18+
promptInput?: (prompt: string, error?: string | undefined, validation?: (() => Promise<boolean>) | undefined, autoComplete?: ((input: string) => string[]) | undefined) => Promise<string>
19+
promptInitResultSelection?: (availableTypes: string[]) => Promise<void> | void;
20+
hide?: () => void;
1821
displayImportResult?: (importResult: ImportResult, showConfigs: boolean) => Promise<void> | void;
1922
displayFileModifications?: (diff: { file: string; modification: FileModificationResult; }[]) => void,
2023
displayImportWarning?: (requiresParameters: string[], noParametersRequired: string[]) => void
24+
displayInitBanner?: () => void;
25+
displayProgress?: () => void;
2126
}
2227

2328
export class MockReporter implements Reporter {
@@ -27,6 +32,28 @@ export class MockReporter implements Reporter {
2732
this.config = config ?? null;
2833
}
2934

35+
async displayInitBanner(): Promise<void> {
36+
this.config?.displayInitBanner?.();
37+
}
38+
39+
async displayProgress(): Promise<void> {
40+
this.config?.displayProgress?.();
41+
}
42+
43+
async hide(): Promise<void> {
44+
this.config?.hide?.();
45+
}
46+
47+
async promptInitResultSelection(availableTypes: string[]): Promise<string[]> {
48+
return (await this.config?.promptInitResultSelection?.(availableTypes)) ?? [];
49+
}
50+
51+
async promptInput(prompt: string, error?: string | undefined, validation?: (() => Promise<boolean>) | undefined, autoComplete?: ((input: string) => string[]) | undefined): Promise<string> {
52+
return (await this.config?.promptInput?.(prompt, error, validation)) ?? '';
53+
}
54+
55+
async promptPressKeyToContinue(message?: string | undefined): Promise<void> {}
56+
3057
async displayImportWarning(requiresParameters: string[], noParametersRequired: string[]): Promise<void> {
3158
console.log('Display import warning');
3259
console.log(requiresParameters);

0 commit comments

Comments
 (0)