Skip to content

Commit

Permalink
fix(projects): can't update project info
Browse files Browse the repository at this point in the history
Refs MARXAN-874, MARXAN-769
  • Loading branch information
MaciejSikorski committed Oct 13, 2021
1 parent d47e9cd commit 241a23f
Show file tree
Hide file tree
Showing 4 changed files with 78 additions and 9 deletions.
13 changes: 5 additions & 8 deletions api/apps/api/src/modules/projects/projects-crud.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -239,14 +239,11 @@ export class ProjectsCrudService extends AppBaseService<
...update,
planningAreaGeometryId: update.planningAreaId,
});
if (bbox || update.planningAreaId !== undefined) {
const updatedModel = await super.setDataUpdate(model, update, _);
if (bbox) updatedModel.bbox = bbox;
if (update.planningAreaId !== undefined)
updatedModel.planningAreaGeometryId = update.planningAreaId;
return updatedModel;
}
return model;
const updatedModel = await super.setDataUpdate(model, update, _);
if (bbox) updatedModel.bbox = bbox;
if (update.planningAreaId !== undefined)
updatedModel.planningAreaGeometryId = update.planningAreaId;
return updatedModel;
}

async extendGetByIdResult(
Expand Down
20 changes: 20 additions & 0 deletions api/apps/api/test/project/update-project.e2e-spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import { FixtureType } from '@marxan/utils/tests/fixture-type';
import { getFixtures } from './update-project.fixtures';

let fixtures: FixtureType<typeof getFixtures>;

beforeEach(async () => {
fixtures = await getFixtures();
});

afterEach(async () => {
await fixtures?.cleanup();
});

test(`updating a project should work`, async () => {
await fixtures.GivenProjectWasCreated();

await fixtures.WhenProjectIsUpdated();

await fixtures.ThenWhenReadingProjectItHasNewData();
});
52 changes: 52 additions & 0 deletions api/apps/api/test/project/update-project.fixtures.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
import { bootstrapApplication } from '../utils/api-application';
import { GivenUserIsLoggedIn } from '../steps/given-user-is-logged-in';
import { OrganizationsTestUtils } from '../utils/organizations.test.utils';
import { E2E_CONFIG } from '../e2e.config';
import { ProjectsTestUtils } from '../utils/projects.test.utils';
import * as request from 'supertest';

export const getFixtures = async () => {
const app = await bootstrapApplication();
const token = await GivenUserIsLoggedIn(app);
const organizationId = (
await OrganizationsTestUtils.createOrganization(app, token, {
...E2E_CONFIG.organizations.valid.minimal(),
name: `Org name ${Date.now()}`,
})
).data.id;
let projectId: string;
return {
cleanup: async () => {
await ProjectsTestUtils.deleteProject(app, token, projectId);
await OrganizationsTestUtils.deleteOrganization(
app,
token,
organizationId,
);
await app.close();
},
GivenProjectWasCreated: async () => {
projectId = (
await ProjectsTestUtils.createProject(app, token, {
name: `Test`,
organizationId,
metadata: {},
})
).data.id;
},
WhenProjectIsUpdated: async () =>
await request(app.getHttpServer())
.patch(`/api/v1/projects/${projectId}`)
.set('Authorization', `Bearer ${token}`)
.send({
name: 'Test updated',
}),
ThenWhenReadingProjectItHasNewData: async () => {
const projectData = await request(app.getHttpServer())
.get(`/api/v1/projects/${projectId}`)
.set('Authorization', `Bearer ${token}`);

expect(projectData.body.data.attributes.name).toBe('Test updated');
},
};
};
2 changes: 1 addition & 1 deletion api/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -214,4 +214,4 @@
"@marxan/planning-unit-features": "<rootDir>/libs/planning-unit-features/src"
}
}
}
}

0 comments on commit 241a23f

Please sign in to comment.