From f07ae79318f6dd273fd7705857aa43d4bc7d8a7a Mon Sep 17 00:00:00 2001 From: Eric Lim Date: Wed, 18 Dec 2024 15:53:58 +0100 Subject: [PATCH 1/4] feat(api): add Expand model Co-authored-by: Diane Cordier --- .../devcomp/domain/models/element/Expand.js | 20 +++++++ .../unit/domain/models/element/Expand_test.js | 54 +++++++++++++++++++ 2 files changed, 74 insertions(+) create mode 100644 api/src/devcomp/domain/models/element/Expand.js create mode 100644 api/tests/devcomp/unit/domain/models/element/Expand_test.js diff --git a/api/src/devcomp/domain/models/element/Expand.js b/api/src/devcomp/domain/models/element/Expand.js new file mode 100644 index 00000000000..9cb8e065368 --- /dev/null +++ b/api/src/devcomp/domain/models/element/Expand.js @@ -0,0 +1,20 @@ +import { assertNotNullOrUndefined } from '../../../../shared/domain/models/asserts.js'; +import { Element } from './Element.js'; + +class Expand extends Element { + /** + * + * @param{string} id + * @param{string} title + * @param{string} content + */ + constructor({ id, title, content } = {}) { + super({ id, type: 'expand' }); + assertNotNullOrUndefined(title, 'The title is required for an Expand element'); + assertNotNullOrUndefined(content, 'The content is required for an Expand element'); + this.title = title; + this.content = content; + } +} + +export { Expand }; diff --git a/api/tests/devcomp/unit/domain/models/element/Expand_test.js b/api/tests/devcomp/unit/domain/models/element/Expand_test.js new file mode 100644 index 00000000000..311519c8a36 --- /dev/null +++ b/api/tests/devcomp/unit/domain/models/element/Expand_test.js @@ -0,0 +1,54 @@ +import { Expand } from '../../../../../../src/devcomp/domain/models/element/Expand.js'; +import { DomainError } from '../../../../../../src/shared/domain/errors.js'; +import { catchErrSync, expect } from '../../../../../test-helper.js'; + +describe('Unit | Devcomp | Domain | Models | Element | Expand', function () { + describe('#constructor', function () { + it('should create a valid Expand object', function () { + // given + const attributes = { + id: '39f28a81-290c-440c-b8b9-1762112fbde3', + content: '

My Content

', + title: 'Expand title', + }; + + // when + const result = new Expand(attributes); + + // then + expect(result.id).to.equal(attributes.id); + expect(result.content).to.equal(attributes.content); + expect(result.title).to.equal(attributes.title); + expect(result.type).to.equal('expand'); + }); + }); + + describe('An expand without a title', function () { + it('should throw an error', function () { + const attributes = { + id: '39f28a81-290c-440c-b8b9-1762112fbde3', + }; + // when + const error = catchErrSync(() => new Expand(attributes))(); + + // then + expect(error).to.be.instanceOf(DomainError); + expect(error.message).to.equal('The title is required for an Expand element'); + }); + }); + + describe('An expand without a content', function () { + it('should throw an error', function () { + const attributes = { + id: '39f28a81-290c-440c-b8b9-1762112fbde3', + title: 'A title', + }; + // when + const error = catchErrSync(() => new Expand(attributes))(); + + // then + expect(error).to.be.instanceOf(DomainError); + expect(error.message).to.equal('The content is required for an Expand element'); + }); + }); +}); From 233ca7e0e5dab88360f2eb9bb8f550943ea569fb Mon Sep 17 00:00:00 2001 From: Eric Lim Date: Wed, 18 Dec 2024 16:31:28 +0100 Subject: [PATCH 2/4] feat(api): update didacticiel with an Expand element Co-authored-by: Yann Bertrand Co-authored-by: Diane Cordier --- .../learning-content/modules/didacticiel-modulix.json | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/api/src/devcomp/infrastructure/datasources/learning-content/modules/didacticiel-modulix.json b/api/src/devcomp/infrastructure/datasources/learning-content/modules/didacticiel-modulix.json index 2b8f49ebb64..2caff3a51e4 100644 --- a/api/src/devcomp/infrastructure/datasources/learning-content/modules/didacticiel-modulix.json +++ b/api/src/devcomp/infrastructure/datasources/learning-content/modules/didacticiel-modulix.json @@ -96,6 +96,13 @@ ] } }, + {"type": "element", "element": { + "id": "5c468891-6b50-41c6-bb30-8639b52c5bca", + "type": "expand", + "title": "Voici un indice pour répondre à la magnifique flashcard", + "content": "

Souvent, pour s’amuser, les hommes d’équipage\nPrennent des albatros, vastes oiseaux des mers,\nQui suivent, indolents compagnons de voyage,\nLe navire glissant sur les gouffres amers.\n\nÀ peine les ont-ils déposés sur les planches,\nQue ces rois de l’azur, maladroits et honteux,\nLaissent piteusement leurs grandes ailes blanches\nComme des avirons traîner à côté d’eux.\n\nCe voyageur ailé, comme il est gauche et veule !\nLui, naguère si beau, qu’il est comique et laid !\nL’un agace son bec avec un brûle-gueule,\nL’autre mime, en boitant, l’infirme qui volait !\n\nLe Poète est semblable au prince des nuées\nQui hante la tempête et se rit de l’archer ;\nExilé sur le sol au milieu des huées,\nSes ailes de géant l’empêchent de marcher.

" + + }}, { "type": "element", "element": { From 9c88b14bbebe8872d8caa0a4e1a2cc02ef8cbc78 Mon Sep 17 00:00:00 2001 From: Eric Lim Date: Wed, 18 Dec 2024 17:03:46 +0100 Subject: [PATCH 3/4] feat(api): add expand schema Co-authored-by: Yann Bertrand Co-authored-by: Diane Cordier --- .../validation/element/expand-schema.js | 12 ++++++++++++ .../learning-content/validation/module-schema.js | 3 +++ 2 files changed, 15 insertions(+) create mode 100644 api/tests/devcomp/unit/infrastructure/datasources/learning-content/validation/element/expand-schema.js diff --git a/api/tests/devcomp/unit/infrastructure/datasources/learning-content/validation/element/expand-schema.js b/api/tests/devcomp/unit/infrastructure/datasources/learning-content/validation/element/expand-schema.js new file mode 100644 index 00000000000..51c7a51fb8d --- /dev/null +++ b/api/tests/devcomp/unit/infrastructure/datasources/learning-content/validation/element/expand-schema.js @@ -0,0 +1,12 @@ +import Joi from 'joi'; + +import { htmlSchema, uuidSchema } from '../utils.js'; + +const expandElementSchema = Joi.object({ + id: uuidSchema, + type: Joi.string().valid('expand').required(), + title: Joi.string().required(), + content: htmlSchema.required(), +}).required(); + +export { expandElementSchema }; diff --git a/api/tests/devcomp/unit/infrastructure/datasources/learning-content/validation/module-schema.js b/api/tests/devcomp/unit/infrastructure/datasources/learning-content/validation/module-schema.js index c48a69c38e8..ad26c50f831 100644 --- a/api/tests/devcomp/unit/infrastructure/datasources/learning-content/validation/module-schema.js +++ b/api/tests/devcomp/unit/infrastructure/datasources/learning-content/validation/module-schema.js @@ -2,6 +2,7 @@ import Joi from 'joi'; import { downloadElementSchema } from './element/download-schema.js'; import { embedElementSchema } from './element/embed-schema.js'; +import { expandElementSchema } from './element/expand-schema.js'; import { flashcardsElementSchema } from './element/flashcards-schema.js'; import { imageElementSchema } from './element/image-schema.js'; import { qcmElementSchema } from './element/qcm-schema.js'; @@ -30,6 +31,7 @@ const elementSchema = Joi.alternatives().conditional('.type', { switch: [ { is: 'download', then: downloadElementSchema }, { is: 'embed', then: embedElementSchema }, + { is: 'expand', then: expandElementSchema }, { is: 'flashcards', then: flashcardsElementSchema }, { is: 'image', then: imageElementSchema }, { is: 'qcu', then: qcuElementSchema }, @@ -44,6 +46,7 @@ const elementSchema = Joi.alternatives().conditional('.type', { const stepperElementSchema = Joi.alternatives().conditional('.type', { switch: [ { is: 'download', then: downloadElementSchema }, + { is: 'expand', then: expandElementSchema }, { is: 'image', then: imageElementSchema }, { is: 'qcu', then: qcuElementSchema }, { is: 'qcm', then: qcmElementSchema }, From 8f13553d4be6f9d40bb61a99f71a7dbee0e958de Mon Sep 17 00:00:00 2001 From: dianeCdrPix Date: Thu, 19 Dec 2024 14:28:40 +0100 Subject: [PATCH 4/4] feat(api): add Expand in ModuleFactory MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Clément Latzarus Co-authored-by: Eric Lim --- .../factories/module-factory.js | 12 +++++ .../factories/module-factory_test.js | 47 +++++++++++++++++++ 2 files changed, 59 insertions(+) diff --git a/api/src/devcomp/infrastructure/factories/module-factory.js b/api/src/devcomp/infrastructure/factories/module-factory.js index 569b4cc19ec..eecf1a9fa83 100644 --- a/api/src/devcomp/infrastructure/factories/module-factory.js +++ b/api/src/devcomp/infrastructure/factories/module-factory.js @@ -9,6 +9,7 @@ import { ComponentStepper } from '../../domain/models/component/ComponentStepper import { Step } from '../../domain/models/component/Step.js'; import { Download } from '../../domain/models/element/Download.js'; import { Embed } from '../../domain/models/element/Embed.js'; +import { Expand } from '../../domain/models/element/Expand.js'; import { Card } from '../../domain/models/element/flashcards/Card.js'; import { Flashcards } from '../../domain/models/element/flashcards/Flashcards.js'; import { Image } from '../../domain/models/element/Image.js'; @@ -91,6 +92,8 @@ export class ModuleFactory { return ModuleFactory.#buildDownload(element); case 'embed': return ModuleFactory.#buildEmbed(element); + case 'expand': + return ModuleFactory.#buildExpand(element); case 'image': return ModuleFactory.#buildImage(element); case 'separator': @@ -115,6 +118,7 @@ export class ModuleFactory { return undefined; } } + static #buildDownload(element) { return new Download({ id: element.id, @@ -133,6 +137,14 @@ export class ModuleFactory { }); } + static #buildExpand(element) { + return new Expand({ + id: element.id, + title: element.title, + content: element.content, + }); + } + static #buildImage(element) { return new Image({ id: element.id, diff --git a/api/tests/devcomp/unit/infrastructure/factories/module-factory_test.js b/api/tests/devcomp/unit/infrastructure/factories/module-factory_test.js index ec0df1f8778..772d4ff0aa5 100644 --- a/api/tests/devcomp/unit/infrastructure/factories/module-factory_test.js +++ b/api/tests/devcomp/unit/infrastructure/factories/module-factory_test.js @@ -877,6 +877,53 @@ describe('Unit | Devcomp | Infrastructure | Factories | Module ', function () { const expectedFlashcards = moduleData.grains[0].components[0].element; validateFlashcards(flashcards, expectedFlashcards); }); + + it('should instantiate a Module with a ComponentElement which contains a Expand Element', function () { + // given + const givenData = { + id: '6282925d-4775-4bca-b513-4c3009ec5886', + slug: 'title', + title: 'title', + isBeta: true, + details: { + image: 'https://images.pix.fr/modulix/placeholder-details.svg', + description: 'Description', + duration: 5, + level: 'Débutant', + tabletSupport: 'comfortable', + objectives: ['Objective 1'], + }, + grains: [ + { + id: 'f312c33d-e7c9-4a69-9ba0-913957b8f7dd', + type: 'lesson', + title: 'title', + components: [ + { + type: 'element', + element: { + id: '71de6394-ff88-4de3-8834-a40057a50ff4', + type: 'expand', + title: "Plus d'info sur la poésie", + content: '

La poésie c’est cool

', + }, + }, + ], + }, + ], + }; + + // when + const module = ModuleFactory.build(givenData); + + // then + const expand = module.grains[0].components[0].element; + const expectedExpand = givenData.grains[0].components[0].element; + expect(expand.id).to.equal(expectedExpand.id); + expect(expand.content).to.equal(expectedExpand.content); + expect(expand.title).to.equal(expectedExpand.title); + expect(expand.type).to.equal(expectedExpand.type); + }); }); describe('With ComponentStepper', function () {