Skip to content

Commit

Permalink
feat(CostSurface): More tweaks after rebase
Browse files Browse the repository at this point in the history
  • Loading branch information
KevSanchez committed Sep 29, 2023
1 parent 3cb485b commit 112d801
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 17 deletions.
6 changes: 3 additions & 3 deletions api/apps/api/test/project/clone-project.e2e-spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -121,9 +121,9 @@ export const getFixtures = async () => {
};

const completeSchedueleImportPieces = async () => {
commandBus.subscribe((command) => {
commandBus.subscribe(async (command) => {
if (command instanceof SchedulePieceImport) {
commandBus.execute(
await commandBus.execute(
new CompleteImportPiece(command.importId, command.componentId),
);
}
Expand Down Expand Up @@ -159,7 +159,7 @@ export const getFixtures = async () => {
organizationId = result.organizationId;
},
GivenCloneWasRequested: async () => {
completeSchedueleImportPieces();
await completeSchedueleImportPieces();

const response = await request(app.getHttpServer())
.post(`/api/v1/projects/${projectId}/clone`)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ export class ScenarioMetadataPieceExporter implements ExportPieceProcessor {
'status',
'ran_at_least_once',
'solutions_are_locked',
'cost_surface_id',
])
.from('scenarios', 's')
.where('s.id = :scenarioId', { scenarioId })
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,58 +66,67 @@ describe(ScenarioMetadataPieceImporter, () => {

it('imports scenario metadata creating a new scenario (project import process)', async () => {
const resourceKind = ResourceKind.Project;
await fixtures.GivenProject();
const costSurfaceId = v4();
await fixtures.GivenProject(costSurfaceId);
await fixtures.GivenUser();

const archiveLocation = await fixtures.GivenValidScenarioMetadataFile(
resourceKind,
costSurfaceId,
);
const input = fixtures.GivenJobInput(archiveLocation, resourceKind);
await fixtures
.WhenPieceImporterIsInvoked(input)
.ThenScenarioMetadataShouldBeImported();
.ThenScenarioMetadataShouldBeImported(costSurfaceId);
});

it('imports scenario metadata creating a new scenario with solutions locked (project import process)', async () => {
const resourceKind = ResourceKind.Project;
const solutionsAreLocked = true;
await fixtures.GivenProject();
const costSurfaceId = v4();
await fixtures.GivenProject(costSurfaceId);

await fixtures.GivenUser();

const archiveLocation = await fixtures.GivenValidScenarioMetadataFile(
resourceKind,
costSurfaceId,
);
const input = fixtures.GivenJobInput(archiveLocation, resourceKind);
await fixtures
.WhenPieceImporterIsInvoked(input)
.ThenScenarioMetadataShouldBeImported();
.ThenScenarioMetadataShouldBeImported(costSurfaceId);
});

it('imports scenario metadata updating an existing scenario (scenario cloning process)', async () => {
const resourceKind = ResourceKind.Scenario;
await fixtures.GivenScenario();
const costSurfaceId = v4();
await fixtures.GivenScenario(costSurfaceId);
await fixtures.GivenUser();

const archiveLocation = await fixtures.GivenValidScenarioMetadataFile(
resourceKind,
costSurfaceId,
);
const input = fixtures.GivenJobInput(
archiveLocation,
ResourceKind.Scenario,
);
await fixtures
.WhenPieceImporterIsInvoked(input)
.ThenScenarioMetadataShouldBeImported();
.ThenScenarioMetadataShouldBeImported(costSurfaceId);
});

it('imports scenario metadata updating an existing scenario with solutions locked (scenario cloning process)', async () => {
const resourceKind = ResourceKind.Scenario;
const solutionsAreLocked = true;
await fixtures.GivenScenario();
const costSurfaceId = v4();
await fixtures.GivenScenario(costSurfaceId);
await fixtures.GivenUser();

const archiveLocation = await fixtures.GivenValidScenarioMetadataFile(
resourceKind,
costSurfaceId,
solutionsAreLocked,
);
const input = fixtures.GivenJobInput(
Expand All @@ -126,7 +135,7 @@ describe(ScenarioMetadataPieceImporter, () => {
);
await fixtures
.WhenPieceImporterIsInvoked(input)
.ThenScenarioMetadataShouldBeImported(solutionsAreLocked);
.ThenScenarioMetadataShouldBeImported(costSurfaceId, solutionsAreLocked);
});
});

Expand All @@ -151,7 +160,6 @@ const getFixtures = async () => {
const organizationId = v4();
const oldScenarioId = v4();
const userId = v4();
const costSurfaceId = v4();

const sut = sandbox.get(ScenarioMetadataPieceImporter);
const fileRepository = sandbox.get(CloningFilesRepository);
Expand All @@ -161,8 +169,12 @@ const getFixtures = async () => {
);

const validScenarioMetadataFileContent: (
costSurfaceId: string,
solutionsAreLocked: boolean,
) => ScenarioMetadataContent = (solutionsAreLocked = false) => ({
) => ScenarioMetadataContent = (
costSurfaceId: string,
solutionsAreLocked = false,
) => ({
name: `test scenario - ${scenarioId}`,
description: 'scenario description',
blm: 10,
Expand Down Expand Up @@ -190,10 +202,16 @@ const getFixtures = async () => {
await DeleteUser(entityManager, userId);
},
GivenUser: () => GivenUserExists(entityManager, userId, projectId),
GivenProject: () => {
return GivenProjectExists(entityManager, projectId, organizationId);
GivenProject: (costSurfaceId: string) => {
return GivenProjectExists(
entityManager,
projectId,
organizationId,
{},
costSurfaceId,
);
},
GivenScenario: () => {
GivenScenario: (costSurfaceId: string) => {
return GivenScenarioExists(
entityManager,
scenarioId,
Expand Down Expand Up @@ -240,6 +258,7 @@ const getFixtures = async () => {
},
GivenValidScenarioMetadataFile: async (
resourceKind: ResourceKind,
costSurfaceId: string,
solutionsAreLocked = false,
) => {
const relativePath = ClonePieceRelativePathResolver.resolveFor(
Expand All @@ -252,7 +271,9 @@ const getFixtures = async () => {
const uriOrError = await fileRepository.saveCloningFile(
exportId,
Readable.from(
JSON.stringify(validScenarioMetadataFileContent(solutionsAreLocked)),
JSON.stringify(
validScenarioMetadataFileContent(costSurfaceId, solutionsAreLocked),
),
),
relativePath,
);
Expand All @@ -271,6 +292,7 @@ const getFixtures = async () => {
);
},
ThenScenarioMetadataShouldBeImported: async (
costSurfaceId: string,
solutionsAreLocked = false,
) => {
await sut.run(input);
Expand All @@ -285,6 +307,7 @@ const getFixtures = async () => {
.execute();

const validScenarioMetadataContent = validScenarioMetadataFileContent(
costSurfaceId,
solutionsAreLocked,
);
expect(scenario.name).toEqual(validScenarioMetadataContent.name);
Expand Down

0 comments on commit 112d801

Please sign in to comment.