From f60462ffb0973cb165dd913403a77dfd6f53d7e3 Mon Sep 17 00:00:00 2001 From: Nicolas Lepage <19571875+nlepage@users.noreply.github.com> Date: Tue, 26 Nov 2024 12:07:39 +0100 Subject: [PATCH] fix(api): seeds for RA crashing on nock dependency --- .../database-builder/factory/learning-content/build.js | 10 +++++++--- api/tests/test-helper.js | 3 +++ 2 files changed, 10 insertions(+), 3 deletions(-) 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];