|
| 1 | +import crypto from 'node:crypto'; |
| 2 | + |
1 | 3 | import { Module } from '../../../../src/devcomp/domain/models/module/Module.js';
|
2 | 4 | import moduleDatasource from '../../../../src/devcomp/infrastructure/datasources/learning-content/module-datasource.js';
|
3 | 5 | import { ModuleFactory } from '../../../../src/devcomp/infrastructure/factories/module-factory.js';
|
@@ -42,7 +44,7 @@ describe('Integration | DevComp | Repositories | ModuleRepository', function ()
|
42 | 44 | });
|
43 | 45 | });
|
44 | 46 |
|
45 |
| - it('should return a Module instance', async function () { |
| 47 | + it('should return a Module instance with its version', async function () { |
46 | 48 | const existingModuleSlug = 'bien-ecrire-son-adresse-mail';
|
47 | 49 | const expectedFoundModule = {
|
48 | 50 | id: 'f7b3a2e1-0d5c-4c6c-9c4d-1a3d8f7e9f5d',
|
@@ -87,15 +89,30 @@ describe('Integration | DevComp | Repositories | ModuleRepository', function ()
|
87 | 89 | moduleDatasourceStub.getBySlug.withArgs(existingModuleSlug).resolves(expectedFoundModule);
|
88 | 90 | sinon.spy(ModuleFactory, 'build');
|
89 | 91 |
|
| 92 | + const version = 'AZERTY123456'; |
| 93 | + const digestStub = sinon.stub().returns(version); |
| 94 | + const updateStub = sinon.stub(); |
| 95 | + const createHashStub = sinon.stub(crypto, 'createHash').returns({ |
| 96 | + copy: () => { |
| 97 | + return { |
| 98 | + digest: digestStub, |
| 99 | + }; |
| 100 | + }, |
| 101 | + update: updateStub, |
| 102 | + }); |
| 103 | + |
90 | 104 | // when
|
91 | 105 | const module = await moduleRepository.getBySlug({
|
92 | 106 | slug: existingModuleSlug,
|
93 | 107 | moduleDatasource: moduleDatasourceStub,
|
94 | 108 | });
|
95 | 109 |
|
96 | 110 | // then
|
97 |
| - expect(ModuleFactory.build).to.have.been.calledWith(expectedFoundModule); |
| 111 | + expect(ModuleFactory.build).to.have.been.calledWith({ ...expectedFoundModule, version }); |
98 | 112 | expect(module).to.be.instanceof(Module);
|
| 113 | + expect(createHashStub).to.have.been.calledOnceWith('sha256'); |
| 114 | + expect(updateStub).to.have.been.calledOnceWith(JSON.stringify(expectedFoundModule)); |
| 115 | + expect(digestStub).to.have.been.calledOnceWith('hex'); |
99 | 116 | });
|
100 | 117 | });
|
101 | 118 | });
|
0 commit comments