Skip to content

Commit

Permalink
fix(api): seeds for RA crashing on nock dependency
Browse files Browse the repository at this point in the history
  • Loading branch information
nlepage committed Nov 26, 2024
1 parent 28d9e40 commit f60462f
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
10 changes: 7 additions & 3 deletions api/db/database-builder/factory/learning-content/build.js
Original file line number Diff line number Diff line change
@@ -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';
Expand All @@ -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);
Expand All @@ -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;
}
3 changes: 3 additions & 0 deletions api/tests/test-helper.js
Original file line number Diff line number Diff line change
Expand Up @@ -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];
Expand Down

0 comments on commit f60462f

Please sign in to comment.