diff --git a/core/api/hooks/hooks.model.js b/core/api/hooks/hooks.model.js index ec8b05cde..7135e7c24 100644 --- a/core/api/hooks/hooks.model.js +++ b/core/api/hooks/hooks.model.js @@ -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 diff --git a/test/api/map/config/layers.json b/test/api/map/config/layers.json index 3f597d8f3..ecc3cc8f7 100644 --- a/test/api/map/config/layers.json +++ b/test/api/map/config/layers.json @@ -5,7 +5,8 @@ "attribution" : "", "type" : "OverlayLayer", "service": "vigicrues-stations", - "featureId": "CdStationH" + "featureId": "CdStationH", + "featureLabel": "LbStationH" }, { "name": "vigicrues-observations", @@ -14,6 +15,7 @@ "type" : "OverlayLayer", "service": "vigicrues-observations", "featureId": "CdStationH", + "featureLabel": "LbStationH", "variables": ["H"], "history": 604800 }, diff --git a/test/api/map/index.test.js b/test/api/map/index.test.js index 60b546924..1233376e2 100644 --- a/test/api/map/index.test.js +++ b/test/api/map/index.test.js @@ -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() @@ -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'], @@ -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')