Skip to content

Commit

Permalink
update tests to match desired behaviour
Browse files Browse the repository at this point in the history
  • Loading branch information
hotzevzl committed Oct 9, 2023
1 parent 52936be commit 128d051
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 28 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,9 @@ export class ProjectMetadataPieceExporter implements ExportPieceProcessor {
const warningMessage = `${ProjectMetadataPieceExporter.name} - Output Summary for project with id ${projectId} does not exist.`;
this.logger.log(warningMessage);
}
const summaryZip64 = outputSummary?.summaryZip ? outputSummary.summaryZip.toString('base64') : undefined;
const summaryZip64 = outputSummary?.summaryZip
? outputSummary.summaryZip.toString('base64')
: undefined;

const [blmRange]: [
SelectProjectBlmResult,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ export class ProjectMetadataPieceImporter implements ImportPieceProcessor {
.values({ id: projectId, ...projectMetadata.blmRange })
.execute();

if(projectMetadata?.outputSummaryZip) {
if (projectMetadata?.outputSummaryZip) {
await em
.createQueryBuilder()
.insert()
Expand All @@ -192,7 +192,9 @@ export class ProjectMetadataPieceImporter implements ImportPieceProcessor {
})
.execute();
} else {
this.logger.log(`No output summary data for project ${projectId}: the source project may not have any scenarios run yet.`);
this.logger.log(
`No output summary data for project ${projectId}: the source project may not have any scenarios run yet.`,
);
}
});
} catch (e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,12 +41,14 @@ describe(ProjectMetadataPieceExporter, () => {
.ThenAProjectExistErrorShouldBeThrown();
});

it('fails when project output summary is not found', async () => {
await fixtures.GivenProjectExist(ProjectSourcesEnum.marxanCloud);
it('saves file successfully even when project output summary was never created yet', async () => {
const marxanSource = ProjectSourcesEnum.marxanCloud;
const input = fixtures.GivenAProjectMetadataExportJob();
await fixtures.GivenProjectExist(marxanSource);
await fixtures.GivenProjectBlmRangeExists();
await fixtures
.WhenPieceExporterIsInvoked(input)
.ThenAnOtuputSummaryExistErrorShouldBeThrown();
.ThenProjectMetadataFileIsSaved(marxanSource);
});

it('fails when project blm range is not found', async () => {
Expand All @@ -62,7 +64,7 @@ describe(ProjectMetadataPieceExporter, () => {
const marxanSource = ProjectSourcesEnum.marxanCloud;
const input = fixtures.GivenAProjectMetadataExportJob();
await fixtures.GivenProjectExist(marxanSource);
await fixtures.GivenProjectBlmRangeExist();
await fixtures.GivenProjectBlmRangeExists();
await fixtures.GivenOutputProjectSummaryExists();
await fixtures
.WhenPieceExporterIsInvoked(input)
Expand All @@ -73,7 +75,7 @@ describe(ProjectMetadataPieceExporter, () => {
const legacySource = ProjectSourcesEnum.legacyImport;
const input = fixtures.GivenAProjectMetadataExportJob();
await fixtures.GivenProjectExist(legacySource);
await fixtures.GivenProjectBlmRangeExist();
await fixtures.GivenProjectBlmRangeExists();
await fixtures.GivenOutputProjectSummaryExists();
await fixtures
.WhenPieceExporterIsInvoked(input)
Expand Down Expand Up @@ -116,18 +118,27 @@ const getFixtures = async () => {

const expectedContent: (
sources: ProjectSourcesEnum,
) => ProjectMetadataContent = (sources: ProjectSourcesEnum) => ({
name: `test project - ${projectId}`,
planningUnitGridShape: PlanningUnitGridShape.Square,
blmRange: {
defaults: [0, 20, 40, 60, 80, 100],
range: [0, 100],
values: [],
},
outputSummaryZip: summaryZipEncoded,
metadata,
sources,
});
options?: { withProjectSummary?: boolean },
) => ProjectMetadataContent = (
sources: ProjectSourcesEnum,
options?: { withProjectSummary?: boolean },
) => {
const expected: ProjectMetadataContent = {
name: `test project - ${projectId}`,
planningUnitGridShape: PlanningUnitGridShape.Square,
blmRange: {
defaults: [0, 20, 40, 60, 80, 100],
range: [0, 100],
values: [],
},
metadata,
sources,
};
if (options?.withProjectSummary) {
expected.outputSummaryZip = summaryZipEncoded;
}
return expected;
};

return {
cleanUp: async () => {
Expand Down Expand Up @@ -155,7 +166,7 @@ const getFixtures = async () => {
sources,
});
},
GivenProjectBlmRangeExist: async () => {
GivenProjectBlmRangeExists: async () => {
return apiEntityManager
.createQueryBuilder()
.insert()
Expand Down Expand Up @@ -187,12 +198,10 @@ const getFixtures = async () => {
ThenAProjectBlmExistErrorShouldBeThrown: async () => {
await expect(sut.run(input)).rejects.toThrow(/blm.*does not exist/gi);
},
ThenAnOtuputSummaryExistErrorShouldBeThrown: async () => {
await expect(sut.run(input)).rejects.toThrow(
/Output Summary.*does not exist/gi,
);
},
ThenProjectMetadataFileIsSaved: async (sources: ProjectSourcesEnum) => {
ThenProjectMetadataFileIsSaved: async (
sources: ProjectSourcesEnum,
options?: { withProjectSummary?: boolean },
) => {
const result = await sut.run(input);
const file = await fileRepository.get(result.uris[0].uri);
expect((file as Right<Readable>).right).toBeDefined();
Expand All @@ -201,7 +210,11 @@ const getFixtures = async () => {
const content = await readSavedFile<ProjectMetadataContent>(
savedStrem,
);
expect(content).toMatchObject(expectedContent(sources));
expect(content).toMatchObject(
expectedContent(sources, {
withProjectSummary: options?.withProjectSummary,
}),
);
},
};
},
Expand Down

1 comment on commit 128d051

@vercel
Copy link

@vercel vercel bot commented on 128d051 Oct 9, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

marxan – ./

marxan-vizzuality1.vercel.app
marxan23.vercel.app
marxan-git-develop-vizzuality1.vercel.app

Please sign in to comment.