-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
225 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,101 @@ | ||
import { TestManager } from '../../utils/test-manager'; | ||
import { HttpStatus } from '@nestjs/common'; | ||
import { Project } from '@shared/entities/projects.entity'; | ||
import { Country } from '@shared/entities/country.entity'; | ||
import { projectsContract } from '@shared/contracts/projects.contract'; | ||
import { ECOSYSTEM } from '@shared/entities/base-data.entity'; | ||
|
||
describe('Project Map', () => { | ||
let testManager: TestManager; | ||
|
||
beforeAll(async () => { | ||
testManager = await TestManager.createTestManager(); | ||
await testManager.ingestCountries(); | ||
}); | ||
|
||
afterEach(async () => { | ||
await testManager.clearTablesByEntities([Project]); | ||
}); | ||
|
||
afterAll(async () => { | ||
await testManager.clearDatabase(); | ||
await testManager.close(); | ||
}); | ||
|
||
test('Should return unique country geometries, with project cost aggregated values', async () => { | ||
const countries = await testManager | ||
.getDataSource() | ||
.getRepository(Country) | ||
.find({ take: 2 }); | ||
|
||
for (const [index, country] of Object.entries(countries)) { | ||
await testManager.mocks().createProject({ | ||
countryCode: country.code, | ||
totalCost: 1000 + parseInt(index), | ||
abatementPotential: 2000 + parseInt(index), | ||
}); | ||
await testManager.mocks().createProject({ | ||
countryCode: country.code, | ||
totalCost: 1000 + parseInt(index), | ||
abatementPotential: 2000 + parseInt(index), | ||
}); | ||
} | ||
|
||
const response = await testManager | ||
.request() | ||
.get(projectsContract.getProjectsMap.path); | ||
|
||
expect(response.status).toBe(HttpStatus.OK); | ||
expect(response.body.features.length).toBe(2); | ||
expect(response.body.features[0].properties.cost).toBe(2000); | ||
expect(response.body.features[0].properties.abatementPotential).toBe(4000); | ||
expect(response.body.features[1].properties.cost).toBe(2002); | ||
expect(response.body.features[1].properties.abatementPotential).toBe(4002); | ||
}); | ||
|
||
test('Should return the aggregated values for the filtered projects', async () => { | ||
const mangroveProjectInSpain1 = await testManager.mocks().createProject({ | ||
countryCode: 'ESP', | ||
totalCost: 1111, | ||
abatementPotential: 2222, | ||
ecosystem: ECOSYSTEM.MANGROVE, | ||
}); | ||
const mangroveProjectInSpain2 = await testManager.mocks().createProject({ | ||
countryCode: 'ESP', | ||
totalCost: 3333, | ||
abatementPotential: 4444, | ||
ecosystem: ECOSYSTEM.MANGROVE, | ||
}); | ||
const seagrassProjectInSpain = await testManager.mocks().createProject({ | ||
countryCode: 'ESP', | ||
totalCost: 5555, | ||
abatementPotential: 6666, | ||
ecosystem: ECOSYSTEM.SEAGRASS, | ||
}); | ||
const mangroveProjectInPortugal = await testManager.mocks().createProject({ | ||
countryCode: 'PRT', | ||
totalCost: 7777, | ||
abatementPotential: 8888, | ||
ecosystem: ECOSYSTEM.MANGROVE, | ||
}); | ||
const seagrassProjectInPortugal = await testManager.mocks().createProject({ | ||
countryCode: 'PRT', | ||
totalCost: 9999, | ||
abatementPotential: 10000, | ||
ecosystem: ECOSYSTEM.SEAGRASS, | ||
}); | ||
|
||
const response = await testManager | ||
.request() | ||
.get(projectsContract.getProjectsMap.path) | ||
.query({ filter: { ecosystem: [ECOSYSTEM.MANGROVE] } }); | ||
|
||
expect(response.body.features).toHaveLength(2); | ||
expect(response.body.features[0].properties.cost).toBe( | ||
mangroveProjectInSpain1.totalCost + mangroveProjectInSpain2.totalCost, | ||
); | ||
expect(response.body.features[1].properties.abatementPotential).toBe( | ||
mangroveProjectInPortugal.abatementPotential, | ||
); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,23 @@ | ||
import { z } from "zod"; | ||
import { FeatureCollection, Geometry } from "geojson"; | ||
import { ProjectGeoPropertiesSchema } from "@shared/schemas/geometries/projects"; | ||
import { ACTIVITY, ECOSYSTEM } from "@shared/entities/base-data.entity"; | ||
import { | ||
PROJECT_PRICE_TYPE, | ||
PROJECT_SIZE_FILTER, | ||
} from "@shared/entities/projects.entity"; | ||
|
||
export type ProjectGeoProperties = z.infer<typeof ProjectGeoPropertiesSchema>; | ||
|
||
export type ProjectMap = FeatureCollection<Geometry, ProjectGeoProperties>; | ||
|
||
export type ProjectMapFilters = { | ||
countryCode?: string[]; | ||
totalCost?: number[]; | ||
abatementPotential?: number[]; | ||
activity?: ACTIVITY; | ||
activitySubtype?: string[]; | ||
ecosystem?: ECOSYSTEM; | ||
projectSizeFilter?: PROJECT_SIZE_FILTER; | ||
priceType?: PROJECT_PRICE_TYPE; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,18 @@ | ||
import { z } from "zod"; | ||
import { FeatureCollection, Geometry } from "geojson"; | ||
|
||
export const ProjectGeoPropertiesSchema = z.object({ | ||
abatementPotential: z.number(), | ||
cost: z.number(), | ||
country: z.string(), | ||
}); | ||
|
||
export type ProjectGeoProperties = z.infer<typeof ProjectGeoPropertiesSchema>; | ||
|
||
export type ProjectMap = FeatureCollection<Geometry, ProjectGeoProperties>; | ||
export const ProjectMapQuerySchema = z.object({ | ||
countryCode: z.string().array(), | ||
totalCost: z.number().array(), | ||
abatementPotential: z.number().array(), | ||
activity: z.string().array(), | ||
activitySubtype: z.string().array(), | ||
ecosystem: z.string().array(), | ||
projectSizeFilter: z.number().array(), | ||
priceType: z.string().array(), | ||
}); |