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

fix(api): The project map now applies priceType and projectSizeFilter… #143

Merged
merged 1 commit into from
Dec 9, 2024
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
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,
);
});
});
Loading