-
Notifications
You must be signed in to change notification settings - Fork 56
/
Copy pathmodule-datasource_test.js
47 lines (40 loc) · 1.92 KB
/
module-datasource_test.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
import moduleDatasource from '../../../../../../src/devcomp/infrastructure/datasources/learning-content/module-datasource.js';
import { expect } from '../../../../../test-helper.js';
import { LearningContentResourceNotFound } from '../../../../../../src/shared/infrastructure/datasources/learning-content/LearningContentResourceNotFound.js';
import { moduleSchema } from './validation/module.js';
const modules = await moduleDatasource.list();
describe('Unit | Infrastructure | Datasources | Learning Content | ModuleDatasource', function () {
describe('#getBySlug', function () {
describe('when exists', function () {
it('should return something', async function () {
// Given
const slug = 'bien-ecrire-son-adresse-mail';
const module = await moduleDatasource.getBySlug(slug);
// When & then
expect(module).to.exist;
});
});
describe("when doesn't exist", function () {
it('should throw an LearningContentResourceNotFound', async function () {
// given
const slug = 'dresser-un-pokemon';
// when & then
await expect(moduleDatasource.getBySlug(slug)).to.have.been.rejectedWith(LearningContentResourceNotFound);
});
});
});
describe('#list', function () {
describe('modules content', function () {
// Rule disabled to allow dynamic generated tests. See https://github.com/lo1tuma/eslint-plugin-mocha/blob/master/docs/rules/no-setup-in-describe.md#disallow-setup-in-describe-blocks-mochano-setup-in-describe
// eslint-disable-next-line mocha/no-setup-in-describe
modules.forEach((module) => {
it(`module "${module.slug}" should contain a valid structure`, function () {
// When
const result = moduleSchema.validate(module);
// Then
expect(result.error).to.equal(undefined, result.error?.details.map((error) => error.message).join('. '));
});
});
});
});
});