Voici la documentation : https://geoplateforme.pages.gpf-tech.ign.fr/documentation

Skip to content
Extraits de code Groupes Projets
Vérifiée Valider a61bed6d rédigé par Cédric Pronzola's avatar Cédric Pronzola
Parcourir les fichiers

Prevent invalid indexes in dispatchRequestToIndexes & add tests

parent a88369d3
Aucune branche associée trouvée
Aucune étiquette associée trouvée
1 requête de fusion!5Prevent invalid indexes in dispatchRequestToIndexes & add tests
import test from 'ava'
import {dispatchRequestToIndexes} from '../indexes/index.js'
test('dispatchRequestToIndexes / search operation', async t => {
const params = {
indexes: ['address', 'poi', 'parcel']
}
const indexes = {
address: {
async search() {
return 'search address'
}
},
poi: {
async search() {
return 'search poi'
}
},
parcel: {
async search() {
return 'search parcel'
}
}
}
const result = await dispatchRequestToIndexes(params, 'search', indexes)
t.deepEqual(result, {
address: 'search address',
poi: 'search poi',
parcel: 'search parcel'
})
})
test('dispatchRequestToIndexes / reverse operation', async t => {
const params = {
indexes: ['address', 'poi', 'parcel']
}
const indexes = {
address: {
async reverse() {
return 'reverse address'
}
},
poi: {
async reverse() {
return 'reverse poi'
}
},
parcel: {
async reverse() {
return 'reverse parcel'
}
}
}
const result = await dispatchRequestToIndexes(params, 'reverse', indexes)
t.deepEqual(result, {
address: 'reverse address',
poi: 'reverse poi',
parcel: 'reverse parcel'
})
})
test('dispatchRequestToIndexes / invalid index', async t => {
const params = {
indexes: ['address', 'poi', 'invalid']
}
const indexes = {
address: {
async search() {
return 'address'
}
},
poi: {
async search() {
return 'poi'
}
},
parcel: {
async search() {
return 'parcel'
}
}
}
await t.throwsAsync(
() => dispatchRequestToIndexes(params, 'search', indexes),
{message: 'Unsupported index type: invalid'}
)
})
......@@ -8,10 +8,15 @@ const INDEX_CONSTRUCTORS = {
parcel: createParcelIndex
}
async function dispatchRequestToIndexes(params, operation, indexes) {
export async function dispatchRequestToIndexes(params, operation, indexes) {
const allowedIndexes = new Set(Object.keys(INDEX_CONSTRUCTORS))
const results = {}
await Promise.all(params.indexes.map(async indexName => {
if (!allowedIndexes.has(indexName)) {
throw new Error('Unsupported index type: ' + indexName)
}
const indexResult = await indexes[indexName][operation](params)
results[indexName] = indexResult
}))
......
0% Chargement en cours ou .
You are about to add 0 people to the discussion. Proceed with caution.
Terminez d'abord l'édition de ce message.
Veuillez vous inscrire ou vous pour commenter