-
Notifications
You must be signed in to change notification settings - Fork 56
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[FEATURE] Pouvoir créer un élément Expand dans le contenu d'un Module (…
- Loading branch information
Showing
7 changed files
with
155 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
54 changes: 54 additions & 0 deletions
54
api/tests/devcomp/unit/domain/models/element/Expand_test.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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: '<p> My Content </p>', | ||
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'); | ||
}); | ||
}); | ||
}); |
12 changes: 12 additions & 0 deletions
12
...comp/unit/infrastructure/datasources/learning-content/validation/element/expand-schema.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters