refactor: find i.p.v. filter
This commit is contained in:
parent
293c51bab3
commit
ac10518cb8
4 changed files with 10 additions and 8 deletions
|
@ -23,9 +23,9 @@ describe('AnswerRepository', () => {
|
|||
const id = new LearningObjectIdentifier('id05', Language.English, 1);
|
||||
const questions = await questionRepository.findAllQuestionsAboutLearningObject(id);
|
||||
|
||||
const question = questions.filter((it) => it.sequenceNumber === 2)[0];
|
||||
const question = questions.find((it) => it.sequenceNumber === 2);
|
||||
|
||||
const answers = await answerRepository.findAllAnswersToQuestion(question);
|
||||
const answers = await answerRepository.findAllAnswersToQuestion(question!);
|
||||
|
||||
expect(answers).toBeTruthy();
|
||||
expect(answers).toHaveLength(2);
|
||||
|
|
|
@ -39,8 +39,8 @@ describe('LearningPathService', () => {
|
|||
expect(result.success).toBeTruthy();
|
||||
expect(result.data?.filter((it) => it.hruid === TEST_DWENGO_LEARNING_PATH_HRUID).length).not.toBe(0);
|
||||
expect(result.data?.filter((it) => it.hruid === example.learningPath.hruid).length).not.toBe(0);
|
||||
expect(result.data?.filter((it) => it.hruid === TEST_DWENGO_LEARNING_PATH_HRUID)[0].title).toEqual(TEST_DWENGO_LEARNING_PATH_TITLE);
|
||||
expect(result.data?.filter((it) => it.hruid === example.learningPath.hruid)[0].title).toEqual(example.learningPath.title);
|
||||
expect(result.data?.find((it) => it.hruid === TEST_DWENGO_LEARNING_PATH_HRUID)?.title).toEqual(TEST_DWENGO_LEARNING_PATH_TITLE);
|
||||
expect(result.data?.find((it) => it.hruid === example.learningPath.hruid)?.title).toEqual(example.learningPath.title);
|
||||
});
|
||||
it('should include both the learning objects from the Dwengo API and learning objects from the database in its response', async () => {
|
||||
const result = await learningPathService.fetchLearningPaths([example.learningPath.hruid], example.learningPath.language, 'the source');
|
||||
|
|
|
@ -21,7 +21,7 @@ export function expectToBeCorrectEntity<T extends object>(actual: { entity: T; n
|
|||
}
|
||||
for (const property in expected.entity) {
|
||||
if (
|
||||
property! in IGNORE_PROPERTIES &&
|
||||
property in IGNORE_PROPERTIES &&
|
||||
expected.entity[property] !== undefined && // If we don't expect a certain value for a property, we assume it can be filled in by the database however it wants.
|
||||
typeof expected.entity[property] !== 'function' // Functions obviously are not persisted via the database
|
||||
) {
|
||||
|
@ -136,10 +136,10 @@ export function expectToBeCorrectLearningPath(
|
|||
version: node.version,
|
||||
};
|
||||
expect(expectedLearningPathNodes.keys()).toContainEqual(nodeKey);
|
||||
const expectedNode = [...expectedLearningPathNodes.entries()].filter(
|
||||
const expectedNode = [...expectedLearningPathNodes.entries()].find(
|
||||
([key, _]) => key.learningObjectHruid === nodeKey.learningObjectHruid && key.language === node.language && key.version === node.version
|
||||
)[0][1];
|
||||
expect(node.start_node).toEqual(expectedNode?.startNode);
|
||||
)![1];
|
||||
expect(node.start_node).toEqual(expectedNode.startNode);
|
||||
|
||||
expect(new Set(node.transitions.map((it) => it.next.hruid))).toEqual(
|
||||
new Set(expectedNode.transitions.map((it) => it.next.learningObjectHruid))
|
||||
|
|
|
@ -109,6 +109,8 @@ export default [
|
|||
|
||||
'@typescript-eslint/parameter-properties': 'off',
|
||||
|
||||
'@typescript-eslint/prefer-find': 'warn',
|
||||
|
||||
'@typescript-eslint/prefer-function-type': 'error',
|
||||
|
||||
'@typescript-eslint/prefer-readonly-parameter-types': 'off',
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue