1 import { RecentVideosRecommendationService } from '@app/videos/recommendations/recent-videos-recommendation.service'
2 import { VideosProvider } from '@app/shared/video/video.service'
3 import { EMPTY, of } from 'rxjs'
4 import Mock = jest.Mock
6 describe('"Recent Videos" Recommender', () => {
7 describe('getRecommendations', () => {
8 let videosService: VideosProvider
9 let service: RecentVideosRecommendationService
10 let getVideosMock: Mock<any>
12 getVideosMock = jest.fn(() => EMPTY)
14 getVideos: getVideosMock
16 service = new RecentVideosRecommendationService(videosService)
18 it('should filter out the given UUID from the results', async (done) => {
23 getVideosMock.mockReturnValueOnce(of({ videos: vids }))
24 const result = await service.getRecommendations({ uuid: 'uuid1' }).toPromise()
25 const uuids = result.map(v => v.uuid)
26 expect(uuids).toEqual(['uuid2'])
29 it('should return 5 results when the given UUID is NOT in the first 5 results', async (done) => {
38 getVideosMock.mockReturnValueOnce(of({ videos: vids }))
39 const result = await service.getRecommendations({ uuid: 'uuid1' }).toPromise()
40 expect(result.length).toEqual(5)
43 it('should return 5 results when the given UUID IS PRESENT in the first 5 results', async (done) => {
53 .mockReturnValueOnce(of({ videos: vids }))
54 const result = await service.getRecommendations({ uuid: 'uuid1' }).toPromise()
55 expect(result.length).toEqual(5)
58 it('should fetch an extra result in case the given UUID is in the list', async (done) => {
59 await service.getRecommendations({ uuid: 'uuid1' }).toPromise()
60 let expectedSize = service.pageSize + 1
61 let params = { currentPage: jasmine.anything(), itemsPerPage: expectedSize }
62 expect(getVideosMock).toHaveBeenCalledWith(params, jasmine.anything())