-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
#81 Add new quiz service function to get recent quiz completions
- Loading branch information
1 parent
a6291c9
commit 40931a1
Showing
3 changed files
with
84 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
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 |
---|---|---|
|
@@ -15,6 +15,7 @@ const mockPersistence = { | |
getCompletionScoreWithQuizTypesForUser: jest.fn(), | ||
getQuizzesWithUserResults: jest.fn(), | ||
getQuizByIdWithResults: jest.fn(), | ||
getRecentQuizCompletions: jest.fn(), | ||
}; | ||
const mockFileService = { | ||
createKey: jest.fn(), | ||
|
@@ -315,5 +316,42 @@ describe('quiz', () => { | |
}); | ||
}); | ||
}); | ||
describe('getRecentQuizCompletions', () => { | ||
it('must call getRecentQuizCompletions on persistence with correct arguments and transform the result', async () => { | ||
mockPersistence.getRecentQuizCompletions.mockResolvedValueOnce([ | ||
{ | ||
completedAt: new Date('2023-01-01'), | ||
score: new Decimal(12), | ||
completedBy: [ | ||
{ | ||
user: { | ||
email: '[email protected]', | ||
name: 'Quiz Master', | ||
}, | ||
}, | ||
], | ||
quiz: { | ||
type: 'SHARK', | ||
date: new Date('2022-12-12'), | ||
}, | ||
}, | ||
]); | ||
|
||
const actual = await sut.getRecentQuizCompletions(); | ||
|
||
expect(mockPersistence.getRecentQuizCompletions).toHaveBeenCalledTimes(1); | ||
expect(mockPersistence.getRecentQuizCompletions).toHaveBeenCalledWith({ limit: 20 }); | ||
|
||
expect(actual).toEqual([ | ||
{ | ||
completionDate: new Date('2023-01-01'), | ||
score: 12, | ||
participants: [{ email: '[email protected]', name: 'Quiz Master' }], | ||
quizDate: new Date('2022-12-12'), | ||
quizType: 'SHARK', | ||
}, | ||
]); | ||
}); | ||
}); | ||
}); | ||
}); |
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