From f991f16e19e7c8f6995f6cc02f57cb96ce8f5633 Mon Sep 17 00:00:00 2001 From: Yann Bertrand <5855339+yannbertrand@users.noreply.github.com> Date: Thu, 15 Feb 2024 18:36:39 +0100 Subject: [PATCH 1/3] feat(api): create functions to generate sample modulix elements --- .../samples/elements/image.sample.js | 11 ++++ .../samples/elements/qcm.sample.js | 18 +++++ .../samples/elements/qcu.sample.js | 18 +++++ .../samples/elements/qrocm.sample.js | 59 +++++++++++++++++ .../samples/elements/text.sample.js | 9 +++ .../samples/elements/video.sample.js | 12 ++++ .../validation/module-validation_test.js | 65 +++++++++++++++++++ 7 files changed, 192 insertions(+) create mode 100644 api/src/devcomp/infrastructure/datasources/learning-content/samples/elements/image.sample.js create mode 100644 api/src/devcomp/infrastructure/datasources/learning-content/samples/elements/qcm.sample.js create mode 100644 api/src/devcomp/infrastructure/datasources/learning-content/samples/elements/qcu.sample.js create mode 100644 api/src/devcomp/infrastructure/datasources/learning-content/samples/elements/qrocm.sample.js create mode 100644 api/src/devcomp/infrastructure/datasources/learning-content/samples/elements/text.sample.js create mode 100644 api/src/devcomp/infrastructure/datasources/learning-content/samples/elements/video.sample.js create mode 100644 api/tests/devcomp/unit/infrastructure/datasources/learning-content/validation/module-validation_test.js 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('. ')); + }); +}); From 6cb32955f6a2b65b0046a92ebf160e8a10a0a19c Mon Sep 17 00:00:00 2001 From: Yann Bertrand <5855339+yannbertrand@users.noreply.github.com> Date: Fri, 16 Feb 2024 15:27:12 +0100 Subject: [PATCH 2/3] feat(scripts): add modulix elements cli generators --- api/scripts/modulix/get-sample-image-element.js | 8 ++++++++ api/scripts/modulix/get-sample-qcm-element.js | 8 ++++++++ api/scripts/modulix/get-sample-qcu-element.js | 8 ++++++++ api/scripts/modulix/get-sample-qrocm-element.js | 8 ++++++++ api/scripts/modulix/get-sample-text-element.js | 8 ++++++++ api/scripts/modulix/get-sample-video-element.js | 8 ++++++++ 6 files changed, 48 insertions(+) create mode 100755 api/scripts/modulix/get-sample-image-element.js create mode 100755 api/scripts/modulix/get-sample-qcm-element.js create mode 100755 api/scripts/modulix/get-sample-qcu-element.js create mode 100755 api/scripts/modulix/get-sample-qrocm-element.js create mode 100755 api/scripts/modulix/get-sample-text-element.js create mode 100755 api/scripts/modulix/get-sample-video-element.js diff --git a/api/scripts/modulix/get-sample-image-element.js b/api/scripts/modulix/get-sample-image-element.js new file mode 100755 index 00000000000..98937cd3bc6 --- /dev/null +++ b/api/scripts/modulix/get-sample-image-element.js @@ -0,0 +1,8 @@ +#!/usr/bin/env node + +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 100755 index 00000000000..3e0df8eb3d1 --- /dev/null +++ b/api/scripts/modulix/get-sample-qcm-element.js @@ -0,0 +1,8 @@ +#!/usr/bin/env node + +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 100755 index 00000000000..744bc014629 --- /dev/null +++ b/api/scripts/modulix/get-sample-qcu-element.js @@ -0,0 +1,8 @@ +#!/usr/bin/env node + +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 100755 index 00000000000..0a5792a9245 --- /dev/null +++ b/api/scripts/modulix/get-sample-qrocm-element.js @@ -0,0 +1,8 @@ +#!/usr/bin/env node + +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 100755 index 00000000000..2848db3bbef --- /dev/null +++ b/api/scripts/modulix/get-sample-text-element.js @@ -0,0 +1,8 @@ +#!/usr/bin/env node + +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 100755 index 00000000000..50532d03945 --- /dev/null +++ b/api/scripts/modulix/get-sample-video-element.js @@ -0,0 +1,8 @@ +#!/usr/bin/env node + +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 !"); From 59931fcec22e4101e8913f6142df0c4b383586e8 Mon Sep 17 00:00:00 2001 From: Yann Bertrand <5855339+yannbertrand@users.noreply.github.com> Date: Fri, 16 Feb 2024 18:14:02 +0100 Subject: [PATCH 3/3] chore(scripts): do not use shebangs as they are not allowed :( --- api/scripts/modulix/get-sample-image-element.js | 2 -- api/scripts/modulix/get-sample-qcm-element.js | 2 -- api/scripts/modulix/get-sample-qcu-element.js | 2 -- api/scripts/modulix/get-sample-qrocm-element.js | 2 -- api/scripts/modulix/get-sample-text-element.js | 2 -- api/scripts/modulix/get-sample-video-element.js | 2 -- 6 files changed, 12 deletions(-) mode change 100755 => 100644 api/scripts/modulix/get-sample-image-element.js mode change 100755 => 100644 api/scripts/modulix/get-sample-qcm-element.js mode change 100755 => 100644 api/scripts/modulix/get-sample-qcu-element.js mode change 100755 => 100644 api/scripts/modulix/get-sample-qrocm-element.js mode change 100755 => 100644 api/scripts/modulix/get-sample-text-element.js mode change 100755 => 100644 api/scripts/modulix/get-sample-video-element.js diff --git a/api/scripts/modulix/get-sample-image-element.js b/api/scripts/modulix/get-sample-image-element.js old mode 100755 new mode 100644 index 98937cd3bc6..e6621cd35d2 --- a/api/scripts/modulix/get-sample-image-element.js +++ b/api/scripts/modulix/get-sample-image-element.js @@ -1,5 +1,3 @@ -#!/usr/bin/env node - import { getImageSample } from '../../src/devcomp/infrastructure/datasources/learning-content/samples/elements/image.sample.js'; console.log(''); diff --git a/api/scripts/modulix/get-sample-qcm-element.js b/api/scripts/modulix/get-sample-qcm-element.js old mode 100755 new mode 100644 index 3e0df8eb3d1..e1722a4a3c6 --- a/api/scripts/modulix/get-sample-qcm-element.js +++ b/api/scripts/modulix/get-sample-qcm-element.js @@ -1,5 +1,3 @@ -#!/usr/bin/env node - import { getQcmSample } from '../../src/devcomp/infrastructure/datasources/learning-content/samples/elements/qcm.sample.js'; console.log(''); diff --git a/api/scripts/modulix/get-sample-qcu-element.js b/api/scripts/modulix/get-sample-qcu-element.js old mode 100755 new mode 100644 index 744bc014629..68919cc9172 --- a/api/scripts/modulix/get-sample-qcu-element.js +++ b/api/scripts/modulix/get-sample-qcu-element.js @@ -1,5 +1,3 @@ -#!/usr/bin/env node - import { getQcuSample } from '../../src/devcomp/infrastructure/datasources/learning-content/samples/elements/qcu.sample.js'; console.log(''); diff --git a/api/scripts/modulix/get-sample-qrocm-element.js b/api/scripts/modulix/get-sample-qrocm-element.js old mode 100755 new mode 100644 index 0a5792a9245..42bd28377b2 --- a/api/scripts/modulix/get-sample-qrocm-element.js +++ b/api/scripts/modulix/get-sample-qrocm-element.js @@ -1,5 +1,3 @@ -#!/usr/bin/env node - import { getQrocmSample } from '../../src/devcomp/infrastructure/datasources/learning-content/samples/elements/qrocm.sample.js'; console.log(''); diff --git a/api/scripts/modulix/get-sample-text-element.js b/api/scripts/modulix/get-sample-text-element.js old mode 100755 new mode 100644 index 2848db3bbef..11d035e36d7 --- a/api/scripts/modulix/get-sample-text-element.js +++ b/api/scripts/modulix/get-sample-text-element.js @@ -1,5 +1,3 @@ -#!/usr/bin/env node - import { getTextSample } from '../../src/devcomp/infrastructure/datasources/learning-content/samples/elements/text.sample.js'; console.log(''); diff --git a/api/scripts/modulix/get-sample-video-element.js b/api/scripts/modulix/get-sample-video-element.js old mode 100755 new mode 100644 index 50532d03945..80983b5a7eb --- a/api/scripts/modulix/get-sample-video-element.js +++ b/api/scripts/modulix/get-sample-video-element.js @@ -1,5 +1,3 @@ -#!/usr/bin/env node - import { getVideoSample } from '../../src/devcomp/infrastructure/datasources/learning-content/samples/elements/video.sample.js'; console.log('');