Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(CostSurface): Adds CostSurface data to Scenario GET endpoints [MRXN23-110] #1535

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
45 changes: 45 additions & 0 deletions api/apps/api/test/project-scenarios.e2e-spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,18 @@ describe('ScenariosModule (e2e)', () => {
fixtures.ThenCorrectScenariosAreReturned(response, { scenarioId, name });
});

it('Getting scenario by id response includes cost surface name', async () => {
await fixtures.GivenScenarioWasCreated('test singular');
const response = await fixtures.WhenGettingScenarioByIdWithCostSurfaceInfo();
fixtures.ThenCostSurfaceNameIsIncludedInSingularResponse(response);
});
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);
});

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