-
Notifications
You must be signed in to change notification settings - Fork 3
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
152 additions
and
53 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import { createGeoRegion } from '../entity-mocks'; | ||
import { GeoRegion } from '../../src/modules/geo-regions/geo-region.entity'; | ||
|
||
const wkt = require('wellknown'); | ||
|
||
const geomstring = | ||
'MULTIPOLYGON (((-74.94038756755259 -8.789917036555973, -74.9404292564128 -8.78987345274758, -74.94037947090003 -8.789320280383404, -74.94007769168027 -8.78832128710426, -74.94014586742746 -8.788218619928239, -74.94016386858105 -8.78780352397087, -74.94010104117281 -8.787799975977926, -74.94010288471793 -8.78778799293464, -74.9395829026956 -8.787693953632717, -74.93871995380748 -8.787450557792479, -74.93826369227841 -8.787672292367361, -74.93588217957925 -8.78758885088354, -74.93581959017885 -8.787667135197673, -74.9357715871026 -8.788277919312772, -74.93494257105218 -8.78845185941805, -74.93498553672873 -8.788177110353425, -74.93374345713029 -8.788556626292976, -74.9326813890679 -8.788562556226449, -74.93185593961496 -8.788775235806332, -74.93064363729047 -8.789016035583105, -74.92945984843114 -8.789701969314692, -74.92933888309716 -8.79004576552706, -74.92900915373343 -8.790418620740047, -74.92907515796331 -8.791877374183946, -74.92920716642304 -8.792695696771696, -74.92975920180011 -8.793276823308746, -74.9315893190828 -8.793092997666013, -74.93331142944389 -8.792891382340077, -74.93551357056765 -8.792594889014318, -74.93895179090532 -8.79218572783506, -74.9395578297432 -8.79241699290495, -74.9406559001128 -8.79224502658469, -74.94093191780134 -8.79210863944635, -74.94088391472505 -8.79196039249988, -74.94060189665201 -8.791729127144945, -74.94034388011707 -8.791438562776397, -74.94015186781199 -8.791088699254734, -74.94014586742746 -8.790721045706444, -74.94026587511813 -8.790288162835186, -74.9404098843469 -8.78997980760475, -74.94038756755259 -8.789917036555973), (-74.9373868084098 -8.7894253831326, -74.9374531890935 -8.789707501038329, -74.93732595944972 -8.789840262405733, -74.93722085670055 -8.789856857576657, -74.93708256360951 -8.789541549329078, -74.9373868084098 -8.7894253831326)))'; | ||
|
||
export const GivenGeoRegionWithGeometry = async ( | ||
additionalData?: Partial<GeoRegion>, | ||
): Promise<GeoRegion> => { | ||
return await createGeoRegion({ | ||
theGeom: wkt.parse(geomstring), | ||
...additionalData, | ||
}); | ||
}; |
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,63 +1,90 @@ | ||
import { createGeoRegion, createSourcingLocation } from '../../entity-mocks'; | ||
import { TestApplication } from '../../utils/application-manager'; | ||
import { createSourcingLocation } from '../../entity-mocks'; | ||
import * as request from 'supertest'; | ||
import { GeoRegion } from '../../../src/modules/geo-regions/geo-region.entity'; | ||
import { LOCATION_TYPES } from '../../../src/modules/sourcing-locations/sourcing-location.entity'; | ||
import { TestManager } from '../../utils/test-manager'; | ||
import { Feature, Geometry } from 'geojson'; | ||
import { GivenGeoRegionWithGeometry } from '../../common-steps/given-geo-region'; | ||
|
||
export const geoRegionFixtures = () => ({ | ||
GivenGeoRegionsOfSourcingLocations: async () => { | ||
const geoRegion = await createGeoRegion({ | ||
name: 'Regular GeoRegion', | ||
export class GeoRegionsTestManager extends TestManager { | ||
constructor(manager: TestManager) { | ||
super(manager.testApp, manager.jwtToken, manager.dataSource); | ||
} | ||
|
||
GivenRegularSourcingLocationsWithGeoRegions = async () => { | ||
const geoRegion = await GivenGeoRegionWithGeometry(); | ||
const geoRegion2 = await GivenGeoRegionWithGeometry(); | ||
const sourcingLocation1 = await createSourcingLocation({ | ||
geoRegionId: geoRegion.id, | ||
locationType: LOCATION_TYPES.ADMINISTRATIVE_REGION_OF_PRODUCTION, | ||
}); | ||
const geoRegion2 = await createGeoRegion({ | ||
name: 'Regular GeoRegion 2', | ||
const sourcingLocation2 = await createSourcingLocation({ | ||
geoRegionId: geoRegion2.id, | ||
locationType: LOCATION_TYPES.PRODUCTION_AGGREGATION_POINT, | ||
}); | ||
await createSourcingLocation({ geoRegionId: geoRegion.id }); | ||
await createSourcingLocation({ geoRegionId: geoRegion2.id }); | ||
return { | ||
sourcingLocations: [sourcingLocation1, sourcingLocation2], | ||
geoRegions: [geoRegion, geoRegion2], | ||
}; | ||
}, | ||
GivenEUDRGeoRegions: async () => { | ||
const geoRegion = await createGeoRegion({ | ||
name: 'EUDR GeoRegion', | ||
}); | ||
const geoRegion2 = await createGeoRegion({ | ||
name: 'EUDR GeoRegion 2', | ||
}); | ||
await createSourcingLocation({ | ||
}; | ||
|
||
GivenEUDRSourcingLocationsWithGeoRegions = async () => { | ||
const geoRegion = await GivenGeoRegionWithGeometry(); | ||
const geoRegion2 = await GivenGeoRegionWithGeometry(); | ||
const sourcingLocation1 = await createSourcingLocation({ | ||
geoRegionId: geoRegion.id, | ||
locationType: LOCATION_TYPES.EUDR, | ||
}); | ||
await createSourcingLocation({ | ||
const sourcingLocation2 = await createSourcingLocation({ | ||
geoRegionId: geoRegion2.id, | ||
locationType: LOCATION_TYPES.EUDR, | ||
}); | ||
return { | ||
eudrGeoRegions: [geoRegion, geoRegion2], | ||
eudrSourcingLocations: [sourcingLocation1, sourcingLocation2], | ||
}; | ||
}, | ||
WhenIRequestEUDRGeoRegions: async (options: { | ||
app: TestApplication; | ||
jwtToken: string; | ||
}) => { | ||
return request(options.app.getHttpServer()) | ||
.get(`/api/v1/geo-regions/eudr`) | ||
.set('Authorization', `Bearer ${options.jwtToken}`); | ||
}, | ||
ThenIShouldOnlyReceiveEUDRGeoRegions: ( | ||
response: request.Response, | ||
}; | ||
|
||
WhenIRequestEUDRGeoFeatures = async (filters: { | ||
'geoRegionIds[]': string[]; | ||
collection?: boolean; | ||
}): Promise<void> => { | ||
this.response = await request(this.testApp.getHttpServer()) | ||
.get('/api/v1/eudr/geo-features') | ||
.query(filters) | ||
.set('Authorization', `Bearer ${this.jwtToken}`); | ||
}; | ||
|
||
WhenIRequestEUDRGeoFeatureCollection = async (filters: { | ||
'geoRegionIds[]': string[]; | ||
}): Promise<void> => { | ||
this.response = await request(this.testApp.getHttpServer()) | ||
.get('/api/v1/eudr/geo-features/collection') | ||
.query(filters) | ||
.set('Authorization', `Bearer ${this.jwtToken}`); | ||
}; | ||
|
||
ThenIShouldOnlyRecieveCorrespondingGeoFeatures = ( | ||
eudrGeoRegions: GeoRegion[], | ||
collection?: boolean, | ||
) => { | ||
expect(response.status).toBe(200); | ||
expect(response.body.data.length).toBe(eudrGeoRegions.length); | ||
for (const geoRegion of eudrGeoRegions) { | ||
expect( | ||
response.body.data.find( | ||
(geoRegionResponse: GeoRegion) => | ||
geoRegionResponse.id === geoRegion.id, | ||
), | ||
).toBeDefined(); | ||
expect(this.response!.status).toBe(200); | ||
if (collection) { | ||
expect(this.response!.body.geojson.type).toEqual('FeatureCollection'); | ||
expect(this.response!.body.geojson.features.length).toBe( | ||
eudrGeoRegions.length, | ||
); | ||
} else { | ||
expect(this.response!.body[0].geojson.type).toEqual('Feature'); | ||
expect(this.response!.body.length).toBe(eudrGeoRegions.length); | ||
for (const geoRegion of eudrGeoRegions) { | ||
expect( | ||
this.response!.body.find( | ||
(geoRegionResponse: { geojson: Feature }) => | ||
geoRegionResponse.geojson.properties?.id === geoRegion.id, | ||
), | ||
).toBeDefined(); | ||
} | ||
} | ||
}, | ||
}); | ||
}; | ||
} |
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,55 @@ | ||
import { GeoRegionsTestManager } from './fixtures'; | ||
|
||
describe('Admin Regions EUDR Filters (e2e)', () => { | ||
let testManager: GeoRegionsTestManager; | ||
|
||
beforeAll(async () => { | ||
testManager = await GeoRegionsTestManager.load(GeoRegionsTestManager); | ||
}); | ||
|
||
beforeEach(async () => { | ||
await testManager.refreshState(); | ||
}); | ||
|
||
afterEach(async () => { | ||
await testManager.clearDatabase(); | ||
}); | ||
|
||
afterAll(async () => { | ||
await testManager.close(); | ||
}); | ||
|
||
test('should only get geo-features that are part of EUDR data', async () => { | ||
await testManager.GivenRegularSourcingLocationsWithGeoRegions(); | ||
const { eudrGeoRegions } = | ||
await testManager.GivenEUDRSourcingLocationsWithGeoRegions(); | ||
await testManager.WhenIRequestEUDRGeoFeatures({ | ||
'geoRegionIds[]': eudrGeoRegions.map((r) => r.id), | ||
}); | ||
testManager.ThenIShouldOnlyRecieveCorrespondingGeoFeatures(eudrGeoRegions); | ||
}); | ||
|
||
test('should only get geo-features that are part of EUDR data and are filtered by geo region id', async () => { | ||
await testManager.GivenRegularSourcingLocationsWithGeoRegions(); | ||
const { eudrGeoRegions } = | ||
await testManager.GivenEUDRSourcingLocationsWithGeoRegions(); | ||
await testManager.WhenIRequestEUDRGeoFeatures({ | ||
'geoRegionIds[]': [eudrGeoRegions[0].id], | ||
}); | ||
testManager.ThenIShouldOnlyRecieveCorrespondingGeoFeatures([ | ||
eudrGeoRegions[0], | ||
]); | ||
}); | ||
test('sould only get EUDR geo-features as a FeatureCollection', async () => { | ||
await testManager.GivenRegularSourcingLocationsWithGeoRegions(); | ||
const { eudrGeoRegions } = | ||
await testManager.GivenEUDRSourcingLocationsWithGeoRegions(); | ||
await testManager.WhenIRequestEUDRGeoFeatureCollection({ | ||
'geoRegionIds[]': eudrGeoRegions.map((r) => r.id), | ||
}); | ||
testManager.ThenIShouldOnlyRecieveCorrespondingGeoFeatures( | ||
eudrGeoRegions, | ||
true, | ||
); | ||
}); | ||
}); |
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
2 changes: 1 addition & 1 deletion
2
api/test/utils/random-name.ts → api/test/utils/generate-random-name.ts
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