-
Notifications
You must be signed in to change notification settings - Fork 57
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(api): refresh learning content cache writes learning content to pg
Co-authored-by: Laura Bergoens <[email protected]>
- Loading branch information
1 parent
90c1192
commit f167e84
Showing
3 changed files
with
69 additions
and
6 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
23 changes: 19 additions & 4 deletions
23
api/src/learning-content/domain/usecases/refresh-learning-content-cache.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 |
---|---|---|
@@ -1,4 +1,19 @@ | ||
/** @param {import('./dependencies.js').Dependencies} */ | ||
export async function refreshLearningContentCache({ LearningContentCache }) { | ||
await LearningContentCache.instance.reset(); | ||
} | ||
import { withTransaction } from '../../../shared/domain/DomainTransaction.js'; | ||
|
||
export const refreshLearningContentCache = withTransaction( | ||
/** @param {import('./dependencies.js').Dependencies} */ | ||
async function refreshLearningContentCache({ | ||
LearningContentCache, | ||
frameworkRepository, | ||
areaRepository, | ||
competenceRepository, | ||
thematicRepository, | ||
}) { | ||
const learningContent = await LearningContentCache.instance.reset(); | ||
|
||
await frameworkRepository.save(learningContent.frameworks); | ||
await areaRepository.save(learningContent.areas); | ||
await competenceRepository.save(learningContent.competences); | ||
await thematicRepository.save(learningContent.thematics); | ||
}, | ||
); |
44 changes: 42 additions & 2 deletions
44
api/tests/learning-content/unit/domain/usecases/refresh-learning-content-cache_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 |
---|---|---|
@@ -1,21 +1,61 @@ | ||
import { DomainTransaction } from '../../../../../lib/infrastructure/DomainTransaction.js'; | ||
import { refreshLearningContentCache } from '../../../../../src/learning-content/domain/usecases/refresh-learning-content-cache.js'; | ||
import { expect, sinon } from '../../../../test-helper.js'; | ||
|
||
describe('Unit | Domain | Usecase | Refresh learning content cache', function () { | ||
beforeEach(function () { | ||
sinon.stub(DomainTransaction, 'execute').callsFake((callback) => { | ||
return callback(); | ||
}); | ||
}); | ||
|
||
describe('#refreshLearningContentCache', function () { | ||
it('should trigger a reset of the learning content cache', async function () { | ||
// given | ||
const frameworks = Symbol('frameworks'); | ||
const areas = Symbol('areas'); | ||
const competences = Symbol('competences'); | ||
const thematics = Symbol('thematics'); | ||
|
||
const LearningContentCache = { | ||
instance: { | ||
reset: sinon.stub(), | ||
reset: sinon.stub().resolves({ | ||
frameworks, | ||
areas, | ||
competences, | ||
thematics, | ||
}), | ||
}, | ||
}; | ||
|
||
const frameworkRepository = { | ||
save: sinon.stub(), | ||
}; | ||
const areaRepository = { | ||
save: sinon.stub(), | ||
}; | ||
const competenceRepository = { | ||
save: sinon.stub(), | ||
}; | ||
const thematicRepository = { | ||
save: sinon.stub(), | ||
}; | ||
|
||
// when | ||
await refreshLearningContentCache({ LearningContentCache }); | ||
await refreshLearningContentCache({ | ||
LearningContentCache, | ||
frameworkRepository, | ||
areaRepository, | ||
competenceRepository, | ||
thematicRepository, | ||
}); | ||
|
||
// then | ||
expect(LearningContentCache.instance.reset).to.have.been.calledOnce; | ||
expect(frameworkRepository.save).to.have.been.calledOnceWithExactly(frameworks); | ||
expect(areaRepository.save).to.have.been.calledOnceWithExactly(areas); | ||
expect(competenceRepository.save).to.have.been.calledOnceWithExactly(competences); | ||
expect(thematicRepository.save).to.have.been.calledOnceWithExactly(thematics); | ||
}); | ||
}); | ||
}); |