diff --git a/api/scripts/modulix/get-sample-image-element.js b/api/scripts/modulix/get-sample-image-element.js new file mode 100644 index 00000000000..e6621cd35d2 --- /dev/null +++ b/api/scripts/modulix/get-sample-image-element.js @@ -0,0 +1,6 @@ +import { getImageSample } from '../../src/devcomp/infrastructure/datasources/learning-content/samples/elements/image.sample.js'; + +console.log(''); +console.log(JSON.stringify(getImageSample(), null, 2)); +console.log(''); +console.log('Voici un joli élément image. Pensez à remplir les alternatives !'); diff --git a/api/scripts/modulix/get-sample-qcm-element.js b/api/scripts/modulix/get-sample-qcm-element.js new file mode 100644 index 00000000000..e1722a4a3c6 --- /dev/null +++ b/api/scripts/modulix/get-sample-qcm-element.js @@ -0,0 +1,6 @@ +import { getQcmSample } from '../../src/devcomp/infrastructure/datasources/learning-content/samples/elements/qcm.sample.js'; + +console.log(''); +console.log(JSON.stringify(getQcmSample(), null, 2)); +console.log(''); +console.log('Voici un petit QCM.'); diff --git a/api/scripts/modulix/get-sample-qcu-element.js b/api/scripts/modulix/get-sample-qcu-element.js new file mode 100644 index 00000000000..68919cc9172 --- /dev/null +++ b/api/scripts/modulix/get-sample-qcu-element.js @@ -0,0 +1,6 @@ +import { getQcuSample } from '../../src/devcomp/infrastructure/datasources/learning-content/samples/elements/qcu.sample.js'; + +console.log(''); +console.log(JSON.stringify(getQcuSample(), null, 2)); +console.log(''); +console.log('Voici un QCU.'); diff --git a/api/scripts/modulix/get-sample-qrocm-element.js b/api/scripts/modulix/get-sample-qrocm-element.js new file mode 100644 index 00000000000..42bd28377b2 --- /dev/null +++ b/api/scripts/modulix/get-sample-qrocm-element.js @@ -0,0 +1,6 @@ +import { getQrocmSample } from '../../src/devcomp/infrastructure/datasources/learning-content/samples/elements/qrocm.sample.js'; + +console.log(''); +console.log(JSON.stringify(getQrocmSample(), null, 2)); +console.log(''); +console.log('Voici un QROCM. Bon courage pour la contrib !'); diff --git a/api/scripts/modulix/get-sample-text-element.js b/api/scripts/modulix/get-sample-text-element.js new file mode 100644 index 00000000000..11d035e36d7 --- /dev/null +++ b/api/scripts/modulix/get-sample-text-element.js @@ -0,0 +1,6 @@ +import { getTextSample } from '../../src/devcomp/infrastructure/datasources/learning-content/samples/elements/text.sample.js'; + +console.log(''); +console.log(JSON.stringify(getTextSample(), null, 2)); +console.log(''); +console.log('Voici un petit texte.'); diff --git a/api/scripts/modulix/get-sample-video-element.js b/api/scripts/modulix/get-sample-video-element.js new file mode 100644 index 00000000000..80983b5a7eb --- /dev/null +++ b/api/scripts/modulix/get-sample-video-element.js @@ -0,0 +1,6 @@ +import { getVideoSample } from '../../src/devcomp/infrastructure/datasources/learning-content/samples/elements/video.sample.js'; + +console.log(''); +console.log(JSON.stringify(getVideoSample(), null, 2)); +console.log(''); +console.log("Voici un joli élément vidéo. N'oubliez pas de compléter la transcription !"); diff --git a/api/src/devcomp/infrastructure/datasources/learning-content/samples/elements/image.sample.js b/api/src/devcomp/infrastructure/datasources/learning-content/samples/elements/image.sample.js new file mode 100644 index 00000000000..39dc7d21598 --- /dev/null +++ b/api/src/devcomp/infrastructure/datasources/learning-content/samples/elements/image.sample.js @@ -0,0 +1,11 @@ +import { randomUUID } from 'node:crypto'; + +export function getImageSample() { + return { + id: randomUUID(), + type: 'image', + url: 'https://images.pix.fr/modulix/placeholder-image.svg', + alt: '', + alternativeText: '', + }; +} diff --git a/api/src/devcomp/infrastructure/datasources/learning-content/samples/elements/qcm.sample.js b/api/src/devcomp/infrastructure/datasources/learning-content/samples/elements/qcm.sample.js new file mode 100644 index 00000000000..2a421b2d1db --- /dev/null +++ b/api/src/devcomp/infrastructure/datasources/learning-content/samples/elements/qcm.sample.js @@ -0,0 +1,18 @@ +import { randomUUID } from 'node:crypto'; + +export function getQcmSample(nbOfProposals = 3) { + return { + id: randomUUID(), + type: 'qcm', + instruction: '
Une question à choix multiples ?
', + proposals: Array.from(Array(nbOfProposals)).map((_, i) => ({ + id: `${i + 1}`, + content: `Proposition ${i + 1}`, + })), + feedbacks: { + valid: 'Correct !
', + invalid: 'Incorrect !
', + }, + solutions: ['1', '2'], + }; +} diff --git a/api/src/devcomp/infrastructure/datasources/learning-content/samples/elements/qcu.sample.js b/api/src/devcomp/infrastructure/datasources/learning-content/samples/elements/qcu.sample.js new file mode 100644 index 00000000000..4b8461e86e0 --- /dev/null +++ b/api/src/devcomp/infrastructure/datasources/learning-content/samples/elements/qcu.sample.js @@ -0,0 +1,18 @@ +import { randomUUID } from 'node:crypto'; + +export function getQcuSample(nbOfProposals = 3) { + return { + id: randomUUID(), + type: 'qcu', + instruction: 'Une question à choix unique ?
', + proposals: Array.from(Array(nbOfProposals)).map((_, i) => ({ + id: `${i + 1}`, + content: `Proposition ${i + 1}`, + })), + feedbacks: { + valid: 'Correct !
', + invalid: 'Incorrect !
', + }, + solution: '1', + }; +} diff --git a/api/src/devcomp/infrastructure/datasources/learning-content/samples/elements/qrocm.sample.js b/api/src/devcomp/infrastructure/datasources/learning-content/samples/elements/qrocm.sample.js new file mode 100644 index 00000000000..f302e483bc9 --- /dev/null +++ b/api/src/devcomp/infrastructure/datasources/learning-content/samples/elements/qrocm.sample.js @@ -0,0 +1,59 @@ +import { randomUUID } from 'node:crypto'; + +export function getQrocmSample() { + return { + id: randomUUID(), + type: 'qrocm', + instruction: 'Complétez le texte ci-dessous.
', + proposals: [ + { + type: 'text', + content: "Il est possible d'utiliser des textes à champs libres :
", + }, + { + input: 'symbole-separateur-email', + type: 'input', + inputType: 'text', + size: 1, + display: 'inline', + placeholder: '', + ariaLabel: "Remplir avec le caractère qui permet de séparer les deux parties d'une adresse mail", + defaultValue: '', + tolerances: ['t1'], + solutions: ['@'], + }, + { + type: 'text', + content: 'On peut aussi utiliser des liste déroulantes :
', + }, + { + input: 'modulix', + type: 'select', + display: 'inline', + placeholder: '', + ariaLabel: "Choisir l'adjectif le plus adapté", + defaultValue: '', + tolerances: [], + options: [ + { + id: '1', + content: 'Génial', + }, + { + id: '2', + content: 'Incroyable', + }, + { + id: '2', + content: 'Légendaire', + }, + ], + solutions: ['3'], + }, + ], + feedbacks: { + valid: 'Correct !
', + invalid: 'Incorrect !
', + }, + }; +} diff --git a/api/src/devcomp/infrastructure/datasources/learning-content/samples/elements/text.sample.js b/api/src/devcomp/infrastructure/datasources/learning-content/samples/elements/text.sample.js new file mode 100644 index 00000000000..5c843803704 --- /dev/null +++ b/api/src/devcomp/infrastructure/datasources/learning-content/samples/elements/text.sample.js @@ -0,0 +1,9 @@ +import { randomUUID } from 'node:crypto'; + +export function getTextSample() { + return { + id: randomUUID(), + type: 'text', + content: "Ceci est un texte qui accepte de l'HTML.
", + }; +} diff --git a/api/src/devcomp/infrastructure/datasources/learning-content/samples/elements/video.sample.js b/api/src/devcomp/infrastructure/datasources/learning-content/samples/elements/video.sample.js new file mode 100644 index 00000000000..854eb6dc4bf --- /dev/null +++ b/api/src/devcomp/infrastructure/datasources/learning-content/samples/elements/video.sample.js @@ -0,0 +1,12 @@ +import { randomUUID } from 'node:crypto'; + +export function getVideoSample() { + return { + id: randomUUID(), + type: 'video', + title: 'Une vidéo', + url: 'https://videos.pix.fr/modulix/placeholder-video.mp4', + subtitles: 'https://videos.pix.fr/modulix/placeholder-video.vtt', + transcription: 'Vidéo manquante
', + }; +} diff --git a/api/tests/devcomp/unit/infrastructure/datasources/learning-content/validation/module-validation_test.js b/api/tests/devcomp/unit/infrastructure/datasources/learning-content/validation/module-validation_test.js new file mode 100644 index 00000000000..30231704d7f --- /dev/null +++ b/api/tests/devcomp/unit/infrastructure/datasources/learning-content/validation/module-validation_test.js @@ -0,0 +1,65 @@ +import { expect } from '../../../../../../test-helper.js'; +import { + imageElementSchema, + qcmElementSchema, + qcuElementSchema, + qrocmElementSchema, + textElementSchema, + videoElementSchema, +} from './element/index.js'; +import { getImageSample } from '../../../../../../../src/devcomp/infrastructure/datasources/learning-content/samples/elements/image.sample.js'; +import { getQcmSample } from '../../../../../../../src/devcomp/infrastructure/datasources/learning-content/samples/elements/qcm.sample.js'; +import { getQcuSample } from '../../../../../../../src/devcomp/infrastructure/datasources/learning-content/samples/elements/qcu.sample.js'; +import { getQrocmSample } from '../../../../../../../src/devcomp/infrastructure/datasources/learning-content/samples/elements/qrocm.sample.js'; +import { getTextSample } from '../../../../../../../src/devcomp/infrastructure/datasources/learning-content/samples/elements/text.sample.js'; +import { getVideoSample } from '../../../../../../../src/devcomp/infrastructure/datasources/learning-content/samples/elements/video.sample.js'; + +describe('Unit | Infrastructure | Datasources | Learning Content | Module Datasource | format validation', function () { + it('should validate sample image structure', function () { + // When + const result = imageElementSchema.validate(getImageSample()); + + // Then + expect(result.error).to.equal(undefined, result.error?.details.map((error) => error.message).join('. ')); + }); + + it('should validate sample qcm structure', function () { + // When + const result = qcmElementSchema.validate(getQcmSample()); + + // Then + expect(result.error).to.equal(undefined, result.error?.details.map((error) => error.message).join('. ')); + }); + + it('should validate sample qcu structure', function () { + // When + const result = qcuElementSchema.validate(getQcuSample()); + + // Then + expect(result.error).to.equal(undefined, result.error?.details.map((error) => error.message).join('. ')); + }); + + it('should validate sample qrocm structure', function () { + // When + const result = qrocmElementSchema.validate(getQrocmSample()); + + // Then + expect(result.error).to.equal(undefined, result.error?.details.map((error) => error.message).join('. ')); + }); + + it('should validate sample text structure', function () { + // When + const result = textElementSchema.validate(getTextSample()); + + // Then + expect(result.error).to.equal(undefined, result.error?.details.map((error) => error.message).join('. ')); + }); + + it('should validate sample video structure', function () { + // When + const result = videoElementSchema.validate(getVideoSample()); + + // Then + expect(result.error).to.equal(undefined, result.error?.details.map((error) => error.message).join('. ')); + }); +});