import { fsImportAll } from '@adonisjs/core/helpers';
import logger from '@adonisjs/core/services/logger';
import nock from 'nock';
export const mockInsee = () => async function () {
    const siretToData = await fsImportAll(new URL('.', import.meta.url), {
        filter: (k) => k.endsWith('.json'),
    });
    nock('https://api.insee.fr/')
        .get((uri) => {
        const data = dataForUri(uri, siretToData);
        if (!data && uri.startsWith(`/api-sirene/3.11/siret`)) {
            logger.warn(`Not mocked : ${uri}`);
        }
        return data != undefined;
    })
        .reply(200, (uri) => dataForUri(uri, siretToData))
        .persist();
};
const dataForUri = (uri, siretToData) => {
    const siret = uri.startsWith(`/api-sirene/3.11/siret/`) ? uri.split('/').at(-1) : undefined;
    return siret ? siretToData[siret] : undefined;
};
//# sourceMappingURL=mock_insee.js.map