-
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 Split the loading of activities from the related users
- Loading branch information
1 parent
eac52fd
commit c2066b8
Showing
7 changed files
with
76 additions
and
20 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,22 @@ | ||
import { QuizlordContext } from '..'; | ||
import { authorisationService, activityService } from '../service.locator'; | ||
import { authorisationService, activityService, userService } from '../service.locator'; | ||
import { RecentActivityItem } from './activity.service'; | ||
|
||
async function activityFeed(_: unknown, _params: Record<string, never>, context: QuizlordContext) { | ||
authorisationService.requireUserRole(context, 'USER'); | ||
|
||
return activityService.getRecentActivity(); | ||
} | ||
|
||
// eslint-disable-next-line @typescript-eslint/no-unused-vars | ||
async function activityFeedUser(parent: RecentActivityItem, _params: Record<string, never>, _context: QuizlordContext) { | ||
return userService.getUsersForActivity(parent); | ||
} | ||
|
||
export const activityQueries = { | ||
activityFeed, | ||
}; | ||
|
||
export const activityChildren = { | ||
users: activityFeedUser, | ||
}; |
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 |
---|---|---|
|
@@ -14,6 +14,7 @@ describe('activity', () => { | |
it('must work when there is only an upload', async () => { | ||
mockQuizService.getRecentQuizUploads.mockResolvedValueOnce([ | ||
{ | ||
id: 'fake-quiz-id', | ||
date: new Date('2020-06-07'), | ||
uploadedAt: new Date('2021-01-01'), | ||
uploadedBy: { name: 'Grant', email: '[email protected]' }, | ||
|
@@ -27,14 +28,17 @@ describe('activity', () => { | |
expect(actual).toEqual([ | ||
{ | ||
date: new Date('2021-01-01'), | ||
text: 'New SHARK quiz from June 7, 2020 uploaded by Grant', | ||
actionType: 'QUIZ_UPLOADED', | ||
resourceId: 'fake-quiz-id', | ||
text: 'New SHARK quiz from June 7, 2020 uploaded', | ||
}, | ||
]); | ||
}); | ||
it('must work when there is only a completion', async () => { | ||
mockQuizService.getRecentQuizUploads.mockResolvedValueOnce([]); | ||
mockQuizService.getRecentQuizCompletions.mockResolvedValueOnce([ | ||
{ | ||
id: 'fake-completion-id', | ||
quizDate: new Date('2020-03-23'), | ||
quizType: 'SHARK', | ||
score: 12, | ||
|
@@ -48,25 +52,30 @@ describe('activity', () => { | |
expect(actual).toEqual([ | ||
{ | ||
date: new Date('2021-01-01'), | ||
text: 'Master, Beginner & [email protected] scored 12 on the SHARK quiz from March 23, 2020', | ||
actionType: 'QUIZ_COMPLETED', | ||
resourceId: 'fake-completion-id', | ||
text: 'SHARK quiz from March 23, 2020 completed with score 12', | ||
}, | ||
]); | ||
}); | ||
it('must call quizService.getRecentQuizUploads and quizService.getRecentQuizCompletions and combine the results', async () => { | ||
mockQuizService.getRecentQuizUploads.mockResolvedValueOnce([ | ||
{ | ||
id: 'fake-quiz-id-one', | ||
date: new Date('2020-06-07'), | ||
uploadedAt: new Date('2021-01-21'), | ||
uploadedBy: { name: 'Bob', email: '[email protected]' }, | ||
type: 'BRAINWAVES', | ||
}, | ||
{ | ||
id: 'fake-quiz-id-two', | ||
date: new Date('2020-08-08'), | ||
uploadedAt: new Date('2021-01-11'), | ||
uploadedBy: { name: 'Tracey', email: '[email protected]' }, | ||
type: 'SHARK', | ||
}, | ||
{ | ||
id: 'fake-quiz-id-three', | ||
date: new Date('2020-10-11'), | ||
uploadedAt: new Date('2021-01-02'), | ||
uploadedBy: { name: 'Grant', email: '[email protected]' }, | ||
|
@@ -75,20 +84,23 @@ describe('activity', () => { | |
]); | ||
mockQuizService.getRecentQuizCompletions.mockResolvedValueOnce([ | ||
{ | ||
id: 'fake-completion-id-one', | ||
quizDate: new Date('2020-03-23'), | ||
quizType: 'BRAINWAVES', | ||
score: 19, | ||
completedBy: [{ name: 'Chloe' }], | ||
completionDate: new Date('2021-01-31'), | ||
}, | ||
{ | ||
id: 'fake-completion-id-two', | ||
quizDate: new Date('2020-03-23'), | ||
quizType: 'SHARK', | ||
score: 12, | ||
completedBy: [{ name: 'Daniel' }], | ||
completionDate: new Date('2021-01-05'), | ||
}, | ||
{ | ||
id: 'fake-completion-id-three', | ||
quizDate: new Date('2020-03-23'), | ||
quizType: 'SHARK', | ||
score: 9, | ||
|
@@ -102,23 +114,33 @@ describe('activity', () => { | |
expect(actual).toEqual([ | ||
{ | ||
date: new Date('2021-01-31'), | ||
text: 'Chloe scored 19 on the BRAINWAVES quiz from March 23, 2020', | ||
actionType: 'QUIZ_COMPLETED', | ||
resourceId: 'fake-completion-id-one', | ||
text: 'BRAINWAVES quiz from March 23, 2020 completed with score 19', | ||
}, | ||
{ | ||
date: new Date('2021-01-21'), | ||
text: 'New BRAINWAVES quiz from June 7, 2020 uploaded by Bob', | ||
actionType: 'QUIZ_UPLOADED', | ||
resourceId: 'fake-quiz-id-one', | ||
text: 'New BRAINWAVES quiz from June 7, 2020 uploaded', | ||
}, | ||
{ | ||
date: new Date('2021-01-11'), | ||
text: 'New SHARK quiz from August 8, 2020 uploaded by Tracey', | ||
actionType: 'QUIZ_UPLOADED', | ||
resourceId: 'fake-quiz-id-two', | ||
text: 'New SHARK quiz from August 8, 2020 uploaded', | ||
}, | ||
{ | ||
date: new Date('2021-01-05'), | ||
text: 'Daniel scored 12 on the SHARK quiz from March 23, 2020', | ||
actionType: 'QUIZ_COMPLETED', | ||
resourceId: 'fake-completion-id-two', | ||
text: 'SHARK quiz from March 23, 2020 completed with score 12', | ||
}, | ||
{ | ||
date: new Date('2021-01-02'), | ||
text: 'New SHARK quiz from October 11, 2020 uploaded by Grant', | ||
actionType: 'QUIZ_UPLOADED', | ||
resourceId: 'fake-quiz-id-three', | ||
text: 'New SHARK quiz from October 11, 2020 uploaded', | ||
}, | ||
]); | ||
}); | ||
|
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
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 |
---|---|---|
|
@@ -321,6 +321,7 @@ describe('quiz', () => { | |
it('must call getRecentQuizCompletions on persistence with correct arguments and transform the result', async () => { | ||
mockPersistence.getRecentQuizCompletions.mockResolvedValueOnce([ | ||
{ | ||
id: 'fake-completion-id', | ||
completedAt: new Date('2023-01-01'), | ||
score: new Decimal(12), | ||
completedBy: [ | ||
|
@@ -332,6 +333,7 @@ describe('quiz', () => { | |
}, | ||
], | ||
quiz: { | ||
id: 'fake-quiz-id', | ||
type: 'SHARK', | ||
date: new Date('2022-12-12'), | ||
}, | ||
|
@@ -345,9 +347,10 @@ describe('quiz', () => { | |
|
||
expect(actual).toEqual([ | ||
{ | ||
id: 'fake-completion-id', | ||
completionDate: new Date('2023-01-01'), | ||
score: 12, | ||
completedBy: [{ email: '[email protected]', name: 'Quiz Master' }], | ||
quizId: 'fake-quiz-id', | ||
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