From 64110689fe5268fc2cb10407ba44e80a94d0b8bf Mon Sep 17 00:00:00 2001 From: dianeCdrPix Date: Thu, 19 Dec 2024 14:28:40 +0100 Subject: [PATCH] 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 () {