Skip to content

Commit

Permalink
feat(CostSurface): Adds CostSurface data to Scenario GET endpoints
Browse files Browse the repository at this point in the history
Modifies the Scenarios serializer config to account the possible inclusion of costSurfaces on the GET responses (by using FetchSpecification's include in the GET request)
  • Loading branch information
KevSanchez committed Oct 3, 2023
1 parent 0282d2c commit 1b5100c
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 1 deletion.
5 changes: 5 additions & 0 deletions api/apps/api/src/modules/scenarios/scenarios-crud.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ export class ScenariosCrudService extends AppBaseService<
'ranAtLeastOnce',
'solutionsAreLocked',
'projectScenarioId',
'costSurface',
],
keyForAttribute: 'camelCase',
project: {
Expand All @@ -88,6 +89,10 @@ export class ScenariosCrudService extends AppBaseService<
'lastModifiedAt',
],
},
costSurface: {
ref: 'id',
attributes: ['name', 'isDefault'],
},
users: {
ref: 'id',
attributes: ['fname', 'lname', 'email'],
Expand Down
47 changes: 46 additions & 1 deletion api/apps/api/test/project-scenarios.e2e-spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ let fixtures: FixtureType<typeof getFixtures>;

beforeEach(async () => {
fixtures = await getFixtures();
}, 12_000);
}, 10000000);

describe('ScenariosModule (e2e)', () => {
it('Creating a scenario with incomplete data should fail', async () => {
Expand Down Expand Up @@ -145,6 +145,18 @@ describe('ScenariosModule (e2e)', () => {
fixtures.ThenCorrectScenariosAreReturned(response, { scenarioId, name });
});

it('Getting scenarios response includes cost surface name', async () => {
await fixtures.GivenScenarioWasCreated('test plural');
await fixtures.GivenScenarioWasCreated('test plural2');
const response = await fixtures.WhenGettingScenariosWithCostSurfaceInfo();
fixtures.ThenCostSurfaceNameIsIncludedInPluralResponse(response);
}, 100000);
it('Getting scenario by id response includes cost surface name', async () => {
await fixtures.GivenScenarioWasCreated('test singular');
const response = await fixtures.WhenGettingScenarioByIdWithCostSurfaceInfo();
fixtures.ThenCostSurfaceNameIsIncludedInSingularResponse(response);
}, 100000);

it('Contributor fails to delete scenario', async () => {
const scenarioId = await fixtures.GivenScenarioWasCreated();
await fixtures.GivenContributorWasAddedToScenario(scenarioId);
Expand Down Expand Up @@ -344,6 +356,14 @@ async function getFixtures() {
return response;
},

WhenGettingScenarioByIdWithCostSurfaceInfo: async () =>
await request(app.getHttpServer())
.get(`/api/v1/scenarios/${scenarioId}?include=costSurface`)
.set('Authorization', `Bearer ${ownerToken}`),
WhenGettingScenariosWithCostSurfaceInfo: async () =>
await request(app.getHttpServer())
.get('/api/v1/scenarios?include=costSurface')
.set('Authorization', `Bearer ${ownerToken}`),
WhenGettingScenariosAsOwner: async () =>
await request(app.getHttpServer())
.get('/api/v1/scenarios')
Expand Down Expand Up @@ -499,6 +519,31 @@ async function getFixtures() {
});
},

ThenCostSurfaceNameIsIncludedInSingularResponse: (
response: request.Response,
) => {
const resource = response.body.data;
const includedEntity = response.body.included;
expect(resource.relationships.costSurface.data.id).toBeDefined();
expect(includedEntity[0].type).toBe('costSurfaces');
expect(includedEntity[0].attributes.name).toBeDefined();
expect(includedEntity[0].attributes.isDefault).toBeDefined();
},
ThenCostSurfaceNameIsIncludedInPluralResponse: (
response: request.Response,
) => {
const resources = response.body.data;
const includedEntities = response.body.included;
for (const resource of resources) {
expect(resource.relationships.costSurface.data.id).toBeDefined();
}
for (const includedEntity of includedEntities) {
expect(includedEntity.type).toBe('costSurfaces');
expect(includedEntity.attributes.name).toBeDefined();
expect(includedEntity.attributes.isDefault).toBeDefined();
}
},

ThenAllScenariosFromContributorAreReturned: (
response: request.Response,
) => {
Expand Down

0 comments on commit 1b5100c

Please sign in to comment.