Skip to content

Commit

Permalink
fix(api): The project map now applies priceType and projectSizeFilter…
Browse files Browse the repository at this point in the history
… filters
  • Loading branch information
alepefe committed Dec 9, 2024
1 parent 0e4c438 commit d680ce9
Show file tree
Hide file tree
Showing 2 changed files with 87 additions and 1 deletion.
16 changes: 16 additions & 0 deletions api/src/modules/projects/projects-map.repository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,22 @@ export class ProjectsMapRepository extends Repository<Project> {
const { costRange, abatementPotentialRange, costRangeSelector } =
otherFilters;

if (projectSizeFilter) {
for (const projectSize of projectSizeFilter) {
queryBuilder.andWhere('p.project_size_filter = :projectSizeFilter', {
projectSizeFilter: projectSize,
});
}
}

if (priceType) {
for (const type of priceType) {
queryBuilder.andWhere('p.price_type = :priceType', {
priceType: type,
});
}
}

if (costRangeSelector === 'npv') {
queryBuilder.addSelect('SUM(p.total_cost_npv)', 'total_cost');
} else {
Expand Down
72 changes: 71 additions & 1 deletion api/test/integration/project-map/project-map.spec.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
import { TestManager } from '../../utils/test-manager';
import { HttpStatus } from '@nestjs/common';
import { Project } from '@shared/entities/projects.entity';
import {
Project,
PROJECT_PRICE_TYPE,
PROJECT_SIZE_FILTER,
} from '@shared/entities/projects.entity';
import { Country } from '@shared/entities/country.entity';
import { projectsContract } from '@shared/contracts/projects.contract';
import { ECOSYSTEM } from '@shared/entities/ecosystem.enum';
Expand Down Expand Up @@ -222,4 +226,70 @@ describe('Project Map', () => {
countries[1].name,
);
});

test('Should return the geometries of the countries filtered by priceType', async () => {
const countries = await testManager
.getDataSource()
.getRepository(Country)
.find({ take: 2 });

await Promise.all([
testManager.mocks().createProject({
priceType: PROJECT_PRICE_TYPE.MARKET_PRICE,
countryCode: countries[0].code,
}),
testManager.mocks().createProject({
priceType: PROJECT_PRICE_TYPE.OPEN_BREAK_EVEN_PRICE,
countryCode: countries[1].code,
}),
]);

const response = await testManager
.request()
.get(projectsContract.getProjectsMap.path)
.query({
filter: { priceType: [PROJECT_PRICE_TYPE.OPEN_BREAK_EVEN_PRICE] },
});

expect(response.status).toBe(HttpStatus.OK);
expect(response.body.features).toHaveLength(1);
expect(response.body.features[0].properties.country).toBe(
countries[1].name,
);
});

test('Should return the geometries of the countries filtered by projectSizeFilter', async () => {
const countries = await testManager
.getDataSource()
.getRepository(Country)
.find({ take: 2 });

await Promise.all([
testManager.mocks().createProject({
projectSizeFilter: PROJECT_SIZE_FILTER.MEDIUM,
priceType: PROJECT_PRICE_TYPE.MARKET_PRICE,
countryCode: countries[0].code,
}),
testManager.mocks().createProject({
projectSizeFilter: PROJECT_SIZE_FILTER.SMALL,
priceType: PROJECT_PRICE_TYPE.OPEN_BREAK_EVEN_PRICE,
countryCode: countries[1].code,
}),
]);

const response = await testManager
.request()
.get(projectsContract.getProjectsMap.path)
.query({
filter: {
projectSizeFilter: [PROJECT_SIZE_FILTER.SMALL],
},
});

expect(response.status).toBe(HttpStatus.OK);
expect(response.body.features).toHaveLength(1);
expect(response.body.features[0].properties.country).toBe(
countries[1].name,
);
});
});

0 comments on commit d680ce9

Please sign in to comment.