Skip to content

Commit

Permalink
chore: improved tests with search on features service
Browse files Browse the repository at this point in the history
  • Loading branch information
claustres committed Aug 20, 2024
1 parent e353e92 commit d8e87ec
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 3 deletions.
2 changes: 1 addition & 1 deletion core/api/hooks/hooks.model.js
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,7 @@ export function setExpireAfter (delayInSeconds) {
export async function distinct (hook) {
const params = hook.params
const query = params.query
if (!query.$distinct) return hook
if (!query || !query.$distinct) return hook
const collection = hook.service.Model
hook.result = await collection.distinct(query.$distinct, _.omit(query, ['$distinct']))
return hook
Expand Down
4 changes: 3 additions & 1 deletion test/api/map/config/layers.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
"attribution" : "",
"type" : "OverlayLayer",
"service": "vigicrues-stations",
"featureId": "CdStationH"
"featureId": "CdStationH",
"featureLabel": "LbStationH"
},
{
"name": "vigicrues-observations",
Expand All @@ -14,6 +15,7 @@
"type" : "OverlayLayer",
"service": "vigicrues-observations",
"featureId": "CdStationH",
"featureLabel": "LbStationH",
"variables": ["H"],
"history": 604800
},
Expand Down
19 changes: 18 additions & 1 deletion test/api/map/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,8 @@ describe('map:services', () => {
expect(vigicruesStationsLayer.service === 'vigicrues-stations').beTrue()
await createFeaturesService.call(app, {
collection: vigicruesStationsLayer.service,
featureId: vigicruesStationsLayer.featureId
featureId: vigicruesStationsLayer.featureId,
featureLabel: vigicruesStationsLayer.featureLabel
})
vigicruesStationsService = app.getService(vigicruesStationsLayer.service)
expect(vigicruesStationsService).toExist()
Expand All @@ -194,6 +195,7 @@ describe('map:services', () => {
await createFeaturesService.call(app, {
collection: vigicruesObsLayer.service,
featureId: vigicruesObsLayer.featureId,
featureLabel: vigicruesObsLayer.featureLabel,
variables: vigicruesObsLayer.variables,
// Raise simplified events
skipEvents: ['updated'],
Expand All @@ -210,6 +212,21 @@ describe('map:services', () => {
// Let enough time to process
.timeout(5000)

it('search on the vigicrues observations service', async () => {
// Fuzzy search
let result = await vigicruesStationsService.find({ query: { 'properties.LbStationH': { $search: 'Châtel' } }, paginate: false })
expect(result.features).toExist()
expect(result.features.length).to.equal(2)
// Diacritic search
result = await vigicruesStationsService.find({ query: { 'properties.LbStationH': { $search: 'Chatel' } }, paginate: false })
expect(result.features.length).to.equal(2)
// Distinct search
result = await vigicruesStationsService.find({ query: { $distinct: 'properties.LbStationH' } })
expect(result.length).to.equal(nbStations)
})
// Let enough time to process
.timeout(5000)

it('the vigicrues observations should send simplified events', async () => {
const min = moment.utc('2018-10-22T22:00:00.000Z')
const max = moment.utc('2018-11-23T08:06:00.000Z')
Expand Down

0 comments on commit d8e87ec

Please sign in to comment.