Skip to content

Commit

Permalink
fix: project attributes
Browse files Browse the repository at this point in the history
  • Loading branch information
aciddaute committed May 5, 2022
1 parent 336b623 commit 0c13405
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,10 @@ export class ProjectMetadataPieceExporter implements ExportPieceProcessor {
name: string;
description: string;
planning_unit_grid_shape: PlanningUnitGridShape;
metadata: Record<string, unknown> | null;
}[] = await this.entityManager
.createQueryBuilder()
.select(['name', 'description', 'planning_unit_grid_shape'])
.select(['name', 'description', 'planning_unit_grid_shape', 'metadata'])
.from('projects', 'p')
.where('id = :projectId', { projectId })
.execute();
Expand All @@ -56,6 +57,7 @@ export class ProjectMetadataPieceExporter implements ExportPieceProcessor {
name: projectData.name,
description: projectData.description,
planningUnitGridShape: projectData.planning_unit_grid_shape,
metadata: projectData.metadata ?? undefined,
};

const relativePath = ClonePieceRelativePathResolver.resolveFor(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ export class ProjectMetadataPieceImporter implements ImportPieceProcessor {
projectId: string,
organizationId: string,
data: ProjectMetadataContent,
ownerId: string,
) {
return em
.createQueryBuilder()
Expand All @@ -54,6 +55,8 @@ export class ProjectMetadataPieceImporter implements ImportPieceProcessor {
description: data.description,
organization_id: organizationId,
planning_unit_grid_shape: data.planningUnitGridShape,
metadata: data.metadata,
created_by: ownerId,
})
.execute();
}
Expand All @@ -62,13 +65,16 @@ export class ProjectMetadataPieceImporter implements ImportPieceProcessor {
em: EntityManager,
projectId: string,
data: ProjectMetadataContent,
ownerId: string,
) {
return em
.createQueryBuilder()
.update('projects')
.set({
description: data.description,
planning_unit_grid_shape: data.planningUnitGridShape,
metadata: data.metadata,
created_by: ownerId,
})
.where('id = :projectId', { projectId })
.execute();
Expand Down Expand Up @@ -123,13 +129,14 @@ export class ProjectMetadataPieceImporter implements ImportPieceProcessor {
projectId,
);
if (projectAlreadyCreated) {
await this.updateProject(em, projectId, projectMetadata);
await this.updateProject(em, projectId, projectMetadata, ownerId);
} else {
await this.createProject(
em,
projectId,
organizationId,
projectMetadata,
ownerId,
);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,9 +70,12 @@ const getFixtures = async () => {
getEntityManagerToken(geoprocessingConnections.apiDB),
);
const fileRepository = sandbox.get(CloningFilesRepository);
const metadata = { foo: 'bar' };

const expectedContent: ProjectMetadataContent = {
name: `test project - ${projectId}`,
planningUnitGridShape: PlanningUnitGridShape.Square,
metadata,
};

return {
Expand All @@ -96,7 +99,9 @@ const getFixtures = async () => {
};
},
GivenProjectExist: async () => {
return GivenProjectExists(apiEntityManager, projectId, organizationId);
return GivenProjectExists(apiEntityManager, projectId, organizationId, {
metadata,
});
},
WhenPieceExporterIsInvoked: (input: ExportJobInput) => {
return {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ interface ProjectSelectResult {
name: string;
description: string;
planning_unit_grid_shape: PlanningUnitGridShape;
metadata: Record<string, unknown> | null;
created_by: string;
}

let fixtures: FixtureType<typeof getFixtures>;
Expand Down Expand Up @@ -113,10 +115,13 @@ const getFixtures = async () => {
const projectName = `test project - ${projectId}`;
const copyProjectName = projectName + ' - copy';

const expectedMetadata = { foo: 'bar' };

const validProjectMetadataFileContent: ProjectMetadataContent = {
name: projectName,
description: 'project description',
planningUnitGridShape: PlanningUnitGridShape.Hexagon,
metadata: expectedMetadata,
};

return {
Expand Down Expand Up @@ -210,6 +215,8 @@ const getFixtures = async () => {
expect(project.planning_unit_grid_shape).toEqual(
validProjectMetadataFileContent.planningUnitGridShape,
);
expect(project.metadata).toMatchObject(expectedMetadata);
expect(project.created_by).toEqual(userId);
},
};
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ export type ProjectMetadataContent = {
name: string;
description?: string;
planningUnitGridShape?: PlanningUnitGridShape;
metadata?: Record<string, unknown>;
};

export const projectMetadataRelativePath = 'project-metadata.json';

0 comments on commit 0c13405

Please sign in to comment.