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 6, 2023
1 parent a5233ea commit 0e33606
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 23 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.GivenProjectBlmRangeExist();
await fixtures
.WhenPieceExporterIsInvoked(input)
.ThenAnOtuputSummaryExistErrorShouldBeThrown();
.ThenProjectMetadataFileIsSaved(marxanSource);
});

it('fails when project blm range is not found', async () => {
Expand Down Expand Up @@ -116,18 +118,28 @@ 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: [],
},
outputSummaryZip: summaryZipEncoded,
metadata,
sources,
};
if (options?.withProjectSummary) {
expected.outputSummaryZip = summaryZipEncoded;
}
return expected;
};

return {
cleanUp: async () => {
Expand Down Expand Up @@ -187,11 +199,6 @@ 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) => {
const result = await sut.run(input);
const file = await fileRepository.get(result.uris[0].uri);
Expand Down

0 comments on commit 0e33606

Please sign in to comment.