Skip to content

Commit

Permalink
[TECH] Ecrire le contenu pédagogique dans la base de données PG dans …
Browse files Browse the repository at this point in the history
…les tests (PIX-15439)

 #10635
  • Loading branch information
pix-service-auto-merge authored Nov 25, 2024
2 parents b1f897f + bf30644 commit a57ffac
Show file tree
Hide file tree
Showing 157 changed files with 1,085 additions and 1,132 deletions.
7 changes: 7 additions & 0 deletions api/db/database-builder/database-builder.js
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,7 @@ class DatabaseBuilder {
}

const publicResults = await this.knex.raw(_constructRawQuery('public'));
const learningContentResults = await this.knex.raw(_constructRawQuery('learningcontent'));
const pgbossResults = await this.knex.raw(_constructRawQuery('pgboss'));

this.tablesOrderedByDependencyWithDirtinessMap = [];
Expand All @@ -202,6 +203,12 @@ class DatabaseBuilder {
isDirty: false,
});
});
learningContentResults.rows.forEach(({ table_name }) => {
this.tablesOrderedByDependencyWithDirtinessMap.push({
table: `learningcontent.${table_name}`,
isDirty: false,
});
});
pgbossResults.rows.forEach(({ table_name }) => {
if (table_name === 'version') return;
this.tablesOrderedByDependencyWithDirtinessMap.push({
Expand Down
2 changes: 2 additions & 0 deletions api/db/database-builder/factory/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { importNamedExportsFromDirectory } from '../../../src/shared/infrastruct
import * as buildDataProtectionOfficer from './build-data-protection-officer.js';
import * as campaignParticipationOverviewFactory from './campaign-participation-overview-factory.js';
import * as knowledgeElementSnapshotFactory from './knowledge-elements-snapshot-factory.js';
import * as learningContent from './learning-content/index.js';
import * as poleEmploiSendingFactory from './pole-emploi-sending-factory.js';

const path = dirname(fileURLToPath(import.meta.url));
Expand Down Expand Up @@ -47,4 +48,5 @@ export const factory = {
knowledgeElementSnapshotFactory,
poleEmploiSendingFactory,
buildDataProtectionOfficer,
learningContent,
};
25 changes: 25 additions & 0 deletions api/db/database-builder/factory/learning-content/build-area.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import { databaseBuffer } from '../../database-buffer.js';

export function buildArea({
id = 'areaIdA',
code = 'code Domaine A',
name = 'name Domaine A',
title_i18n = { fr: 'title FR Domaine A', en: 'title EN Domaine A' },
color = 'color Domaine A',
frameworkId = 'frameworkPix',
competenceIds = ['competenceIdA'],
} = {}) {
const values = {
id,
code,
name,
title_i18n,
color,
frameworkId,
competenceIds,
};
return databaseBuffer.pushInsertable({
tableName: 'learningcontent.areas',
values,
});
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
import { databaseBuffer } from '../../database-buffer.js';

export function buildChallenge({
id = 'challengeIdA',
instruction = 'instruction Epreuve A',
alternativeInstruction = 'alternativeInstruction Epreuve A',
proposals = 'proposals Epreuve A',
type = 'QCU',
solution = 'solution Epreuve A',
solutionToDisplay = 'solutionToDisplay Epreuve A',
t1Status = true,
t2Status = true,
t3Status = true,
status = 'archivé',
genealogy = 'genealogy Epreuve A',
accessibility1 = 'accessibility1 Epreuve A',
accessibility2 = 'accessibility2 Epreuve B',
requireGafamWebsiteAccess = true,
isIncompatibleIpadCertif = true,
deafAndHardOfHearing = 'deafAndHardOfHearing Epreuve A',
isAwarenessChallenge = true,
toRephrase = true,
alternativeVersion = 8,
shuffled = true,
illustrationAlt = 'illustrationAlt Epreuve A',
illustrationUrl = 'illustrationUrl Epreuve A',
attachments = ['attachment1', 'attachment2'],
responsive = 'responsive Epreuve A',
alpha = 1.1,
delta = 3.3,
autoReply = true,
focusable = true,
format = 'format Epreuve A',
timer = 180,
embedHeight = 800,
embedUrl = 'embedUrl Epreuve A',
embedTitle = 'embedTitle Epreuve A',
locales = ['fr'],
competenceId = 'competenceIdA',
skillId = 'skillIdA',
} = {}) {
const values = {
id,
instruction,
alternativeInstruction,
proposals,
type,
solution,
solutionToDisplay,
t1Status,
t2Status,
t3Status,
status,
genealogy,
accessibility1,
accessibility2,
requireGafamWebsiteAccess,
isIncompatibleIpadCertif,
deafAndHardOfHearing,
isAwarenessChallenge,
toRephrase,
alternativeVersion,
shuffled,
illustrationAlt,
illustrationUrl,
attachments,
responsive,
alpha,
delta,
autoReply,
focusable,
format,
timer,
embedHeight,
embedUrl,
embedTitle,
locales,
competenceId,
skillId,
};
return databaseBuffer.pushInsertable({
tableName: 'learningcontent.challenges',
values,
});
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import { databaseBuffer } from '../../database-buffer.js';

export function buildCompetence({
id = 'competenceIdA',
name_i18n = { fr: 'name FR Compétence A', en: 'name EN Compétence A' },
description_i18n = { fr: 'description FR Compétence A', en: 'description EN Compétence A' },
index = 'index Compétence A',
origin = 'origin Compétence A',
areaId = 'areaIdA',
skillIds = ['skillIdA'],
thematicIds = ['thematicIdA'],
} = {}) {
const values = {
id,
name_i18n,
description_i18n,
index,
origin,
areaId,
skillIds,
thematicIds,
};
return databaseBuffer.pushInsertable({
tableName: 'learningcontent.competences',
values,
});
}
23 changes: 23 additions & 0 deletions api/db/database-builder/factory/learning-content/build-course.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import { databaseBuffer } from '../../database-buffer.js';

export function buildCourse({
id = 'courseIdA',
name = 'instruction Test Statique A',
description = 'description Test Statique A',
isActive = true,
competences = ['competenceIdA'],
challenges = ['challengeIdA'],
} = {}) {
const values = {
id,
name,
description,
isActive,
competences,
challenges,
};
return databaseBuffer.pushInsertable({
tableName: 'learningcontent.courses',
values,
});
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { databaseBuffer } from '../../database-buffer.js';

export function buildFramework({ id = 'frameworkPix', name = 'Pix' } = {}) {
const values = {
id,
name,
};
return databaseBuffer.pushInsertable({
tableName: 'learningcontent.frameworks',
values,
});
}
33 changes: 33 additions & 0 deletions api/db/database-builder/factory/learning-content/build-mission.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import { databaseBuffer } from '../../database-buffer.js';

export function buildMission({
id = 'missionIdA',
status = 'status Mission A',
name_i18n = { fr: 'name FR Mission A', en: 'name EN Mission A' },
content = { some: 'content' },
learningObjectives_i18n = { fr: 'learningObjectives FR Mission A', en: 'learningObjectives EN Mission A' },
validatedObjectives_i18n = { fr: 'validatedObjectives FR Mission A', en: 'validatedObjectives EN Mission A' },
introductionMediaType = 'introductionMediaType Mission A',
introductionMediaAlt_i18n = { fr: 'introductionMediaAlt FR Mission A', en: 'introductionMediaAlt EN Mission A' },
documentationUrl = 'documentationUrl Mission A',
cardImageUrl = 'cardImageUrl Mission A',
competenceId = 'competenceIdA',
} = {}) {
const values = {
id,
status,
name_i18n,
content,
learningObjectives_i18n,
validatedObjectives_i18n,
introductionMediaType,
introductionMediaAlt_i18n,
documentationUrl,
cardImageUrl,
competenceId,
};
return databaseBuffer.pushInsertable({
tableName: 'learningcontent.missions',
values,
});
}
33 changes: 33 additions & 0 deletions api/db/database-builder/factory/learning-content/build-skill.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import { databaseBuffer } from '../../database-buffer.js';

export function buildSkill({
id = 'skillIdA',
name = 'name Acquis A',
status = 'status Acquis A',
pixValue = 2.9,
version = 5,
level = 2,
hintStatus = 'hintStatus Acquis A',
competenceId = 'competenceIdA',
tubeId = 'tubeIdA',
tutorialIds = ['tutorialIdA'],
learningMoreTutorialIds = [],
} = {}) {
const values = {
id,
name,
status,
pixValue,
version,
level,
hintStatus,
competenceId,
tubeId,
tutorialIds,
learningMoreTutorialIds,
};
return databaseBuffer.pushInsertable({
tableName: 'learningcontent.skills',
values,
});
}
21 changes: 21 additions & 0 deletions api/db/database-builder/factory/learning-content/build-thematic.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import { databaseBuffer } from '../../database-buffer.js';

export function buildThematic({
id = 'thematicIdA',
name_i18n = { fr: 'name FR Thématique A', en: 'name EN Thématique A' },
index = 8,
competenceId = 'competenceIdA',
tubeIds = ['tubeIdA'],
} = {}) {
const values = {
id,
name_i18n,
index,
competenceId,
tubeIds,
};
return databaseBuffer.pushInsertable({
tableName: 'learningcontent.thematics',
values,
});
}
33 changes: 33 additions & 0 deletions api/db/database-builder/factory/learning-content/build-tube.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import { databaseBuffer } from '../../database-buffer.js';

export function buildTube({
id = 'tubeIdA',
name = 'name Tube A',
title = 'title Tube A',
description = 'description Tube A',
practicalTitle_i18n = { fr: 'practicalTitle FR Tube A', en: 'practicalTitle EN Tube A' },
practicalDescription_i18n = { fr: 'practicalDescription FR Tube A', en: 'practicalDescription EN Tube A' },
competenceId = 'competenceIdA',
thematicId = 'thematicIdA',
skillIds = ['skillIdA'],
isMobileCompliant = true,
isTabletCompliant = true,
} = {}) {
const values = {
id,
name,
title,
description,
practicalTitle_i18n,
practicalDescription_i18n,
competenceId,
thematicId,
skillIds,
isMobileCompliant,
isTabletCompliant,
};
return databaseBuffer.pushInsertable({
tableName: 'learningcontent.tubes',
values,
});
}
25 changes: 25 additions & 0 deletions api/db/database-builder/factory/learning-content/build-tutorial.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import { databaseBuffer } from '../../database-buffer.js';

export function buildTutorial({
id = 'tutorialIdA',
duration = 'duration Tutoriel A',
format = 'format Tutoriel A',
title = 'title Tutoriel A',
source = 'source Tutoriel A',
link = 'link Tutoriel A',
locale = 'fr',
} = {}) {
const values = {
id,
duration,
format,
title,
source,
link,
locale,
};
return databaseBuffer.pushInsertable({
tableName: 'learningcontent.tutorials',
values,
});
}
30 changes: 30 additions & 0 deletions api/db/database-builder/factory/learning-content/build.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import nock from 'nock';

import { buildArea } from './build-area.js';
import { buildChallenge } from './build-challenge.js';
import { buildCompetence } from './build-competence.js';
import { buildCourse } from './build-course.js';
import { buildFramework } from './build-framework.js';
import { buildMission } from './build-mission.js';
import { buildSkill } from './build-skill.js';
import { buildThematic } from './build-thematic.js';
import { buildTube } from './build-tube.js';
import { buildTutorial } from './build-tutorial.js';

export function build(learningContent) {
learningContent.frameworks?.forEach(buildFramework);
learningContent.areas?.forEach(buildArea);
learningContent.competences?.forEach(buildCompetence);
learningContent.thematics?.forEach(buildThematic);
learningContent.tubes?.forEach(buildTube);
learningContent.skills?.forEach(buildSkill);
learningContent.challenges?.forEach(buildChallenge);
learningContent.courses?.forEach(buildCourse);
learningContent.tutorials?.forEach(buildTutorial);
learningContent.missions?.forEach(buildMission);

return nock('https://lcms-test.pix.fr/api')
.get('/releases/latest')
.matchHeader('Authorization', 'Bearer test-api-key')
.reply(200, { content: learningContent });
}
Loading

0 comments on commit a57ffac

Please sign in to comment.