Skip to content

Commit

Permalink
Import all project columns
Browse files Browse the repository at this point in the history
  • Loading branch information
catalin-oancea committed Dec 18, 2024
1 parent 58a6a87 commit 25adc48
Show file tree
Hide file tree
Showing 4 changed files with 81 additions and 34 deletions.
2 changes: 1 addition & 1 deletion api/src/modules/import/dtos/excel-projects.dto.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,6 @@ export type ExcelProjects = {
total_cost: number;
cost_per_tco2e_npv: number;
cost_per_tco2e: number;
initial_price_assumption: string;
initial_price_assumption: number;
price_type: PROJECT_PRICE_TYPE;
};
4 changes: 0 additions & 4 deletions api/src/modules/projects/projects-scorecard.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,6 @@ import { Repository, SelectQueryBuilder } from 'typeorm';
import { z } from 'zod';
import { getProjectsQuerySchema } from '@shared/contracts/projects.contract';
import { ProjectScorecardView } from '@shared/entities/project-scorecard.view';
import {
OtherProjectFilters,
ProjectFilters,
} from '@shared/dtos/projects/projects-map.dto';

export type ProjectFetchSpecificacion = z.infer<typeof getProjectsQuerySchema>;

Expand Down
11 changes: 11 additions & 0 deletions api/src/modules/projects/projects.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,4 +90,15 @@ export class ProjectsController {
},
);
}

@TsRestHandler(projectsContract.getProjectWithScorecard)
async getProjectWithScorecard(): ControllerResponse {
return tsRestHandler(
projectsContract.getProjectWithScorecard,
async ({ params: { id }, query }) => {
const data = await this.projectsScorecardService.getById(id, query);
return { body: { data }, status: HttpStatus.OK };
},
);
}
}
98 changes: 69 additions & 29 deletions api/test/integration/projects/projects.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -324,39 +324,39 @@ describe('Projects', () => {
});
});

test('Should return a list of filtered projects with maximum values', async () => {
await testManager.mocks().createProject({
id: 'e934e9fe-a79c-40a5-8254-8817851764ad',
projectName: 'PROJ_ABC',
totalCost: 100,
totalCostNPV: 50,
abatementPotential: 10,
});
await testManager.mocks().createProject({
id: 'e934e9fe-a79c-40a5-8254-8817851764ae',
projectName: 'PROJ_DEF',
totalCost: 200,
totalCostNPV: 100,
abatementPotential: 20,
});

const response = await testManager
.request()
.get(projectsContract.getProjects.path)
.query({
withMaximums: true,
partialProjectName: 'PROJ',
describe('Filters for Projects', () => {
test('Should return a list of filtered projects with maximum values', async () => {
await testManager.mocks().createProject({
id: 'e934e9fe-a79c-40a5-8254-8817851764ad',
projectName: 'PROJ_ABC',
totalCost: 100,
totalCostNPV: 50,
abatementPotential: 10,
});
await testManager.mocks().createProject({
id: 'e934e9fe-a79c-40a5-8254-8817851764ae',
projectName: 'PROJ_DEF',
totalCost: 200,
totalCostNPV: 100,
abatementPotential: 20,
});

expect(response.status).toBe(HttpStatus.OK);
expect(response.body.data).toHaveLength(2);
expect(response.body.maximums).toEqual({
maxAbatementPotential: 20,
maxTotalCost: 300,
const response = await testManager
.request()
.get(projectsContract.getProjects.path)
.query({
withMaximums: true,
partialProjectName: 'PROJ',
});

expect(response.status).toBe(HttpStatus.OK);
expect(response.body.data).toHaveLength(2);
expect(response.body.maximums).toEqual({
maxAbatementPotential: 20,
maxTotalCost: 300,
});
});
});

describe('Filters for Projects', () => {
test('Should get a list of countries there are projects in', async () => {
const fiveCountriesWithNoGeometry = countriesInDb
.slice(0, 5)
Expand All @@ -377,4 +377,44 @@ describe('Projects', () => {
);
});
});

describe('Get Project', () => {
test('Should return a project', async () => {
const project = await testManager.mocks().createProject();
const response = await testManager
.request()
.get(projectsContract.getProject.path.replace(':id', project.id));

expect(response.status).toBe(HttpStatus.OK);
expect(response.body.data.projectName).toBe(project.projectName);
});

test('Should return a 400 if project does not exist', async () => {
const response = await testManager
.request()
.get(projectsContract.getProject.path.replace(':id', '123'));

expect(response.status).toBe(HttpStatus.BAD_REQUEST);
});

test('Should return a project with scorecard', async () => {
const project = await testManager.mocks().createProject();
await testManager.mocks().createProjectScorecard({
id: project.id,
});

const response = await testManager
.request()
.get(
projectsContract.getProjectWithScorecard.path.replace(
':id',
project.id,
),
);

expect(response.status).toBe(HttpStatus.OK);
expect(response.body.data.feasibilityAnalysisNPV).toBeDefined();
expect(response.body.data.socialFeasibility).toBeDefined();
});
});
});

0 comments on commit 25adc48

Please sign in to comment.