diff --git a/api/db/database-builder/factory/learning-content/build.js b/api/db/database-builder/factory/learning-content/build.js index cd1641122e4..7dea923ce23 100644 --- a/api/db/database-builder/factory/learning-content/build.js +++ b/api/db/database-builder/factory/learning-content/build.js @@ -1,5 +1,3 @@ -import nock from 'nock'; - import { buildArea } from './build-area.js'; import { buildChallenge } from './build-challenge.js'; import { buildCompetence } from './build-competence.js'; @@ -11,6 +9,8 @@ import { buildThematic } from './build-thematic.js'; import { buildTube } from './build-tube.js'; import { buildTutorial } from './build-tutorial.js'; +let nock; + export function build(learningContent) { learningContent.frameworks?.forEach(buildFramework); learningContent.areas?.forEach(buildArea); @@ -23,8 +23,12 @@ export function build(learningContent) { learningContent.tutorials?.forEach(buildTutorial); learningContent.missions?.forEach(buildMission); - return nock('https://lcms-test.pix.fr/api') + return nock?.('https://lcms-test.pix.fr/api') .get('/releases/latest') .matchHeader('Authorization', 'Bearer test-api-key') .reply(200, { content: learningContent }); } + +export function injectNock(value) { + nock = value; +} diff --git a/api/tests/test-helper.js b/api/tests/test-helper.js index ca2ea1b43f4..b488f1b30d1 100644 --- a/api/tests/test-helper.js +++ b/api/tests/test-helper.js @@ -56,6 +56,9 @@ const databaseBuilder = await DatabaseBuilder.create({ }, }); +// TEMPORARY WORKAROUND +databaseBuilder.factory.learningContent.injectNock(nock); + nock.disableNetConnect(); nock.enableNetConnect('localhost:9090'); const EMPTY_BLANK_AND_NULL = ['', '\t \n', null];