|
@@ -10,19 +10,28 @@ import {
|
|
AddVideoViewArgs,
|
|
AddVideoViewArgs,
|
|
GET_CHANNEL_VIEWS,
|
|
GET_CHANNEL_VIEWS,
|
|
GET_MOST_VIEWED_CHANNELS,
|
|
GET_MOST_VIEWED_CHANNELS,
|
|
|
|
+ GET_MOST_VIEWED_CHANNELS_ALL_TIME,
|
|
GET_VIDEO_VIEWS,
|
|
GET_VIDEO_VIEWS,
|
|
GET_MOST_VIEWED_VIDEOS,
|
|
GET_MOST_VIEWED_VIDEOS,
|
|
|
|
+ GET_MOST_VIEWED_VIDEOS_ALL_TIME,
|
|
GET_MOST_VIEWED_CATEGORIES,
|
|
GET_MOST_VIEWED_CATEGORIES,
|
|
|
|
+ GET_MOST_VIEWED_CATEGORIES_ALL_TIME,
|
|
GetChannelViews,
|
|
GetChannelViews,
|
|
GetChannelViewsArgs,
|
|
GetChannelViewsArgs,
|
|
GetVideoViews,
|
|
GetVideoViews,
|
|
GetVideoViewsArgs,
|
|
GetVideoViewsArgs,
|
|
GetMostViewedVideosArgs,
|
|
GetMostViewedVideosArgs,
|
|
|
|
+ GetMostViewedVideosAllTimeArgs,
|
|
GetMostViewedChannelsArgs,
|
|
GetMostViewedChannelsArgs,
|
|
|
|
+ GetMostViewedChannelsAllTimeArgs,
|
|
GetMostViewedVideos,
|
|
GetMostViewedVideos,
|
|
|
|
+ GetMostViewedVideosAllTime,
|
|
GetMostViewedChannels,
|
|
GetMostViewedChannels,
|
|
- GetMostViewedCategoriessArgs,
|
|
|
|
|
|
+ GetMostViewedChannelsAllTime,
|
|
|
|
+ GetMostViewedCategoriesArgs,
|
|
|
|
+ GetMostViewedCategoriesAllTimeArgs,
|
|
GetMostViewedCategories,
|
|
GetMostViewedCategories,
|
|
|
|
+ GetMostViewedCategoriesAllTime,
|
|
} from './queries/views'
|
|
} from './queries/views'
|
|
import { EntityViewsInfo } from '../src/entities/EntityViewsInfo'
|
|
import { EntityViewsInfo } from '../src/entities/EntityViewsInfo'
|
|
import { VideoEventsBucketModel } from '../src/models/VideoEvent'
|
|
import { VideoEventsBucketModel } from '../src/models/VideoEvent'
|
|
@@ -83,6 +92,15 @@ describe('Video and channel views resolver', () => {
|
|
return mostViewedVideosResponse.data?.mostViewedVideos
|
|
return mostViewedVideosResponse.data?.mostViewedVideos
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ const getMostViewedVideosAllTime = async (limit: number) => {
|
|
|
|
+ const mostViewedVideosAllTimeResponse = await query<GetMostViewedVideosAllTime, GetMostViewedVideosAllTimeArgs>({
|
|
|
|
+ query: GET_MOST_VIEWED_VIDEOS_ALL_TIME,
|
|
|
|
+ variables: { limit },
|
|
|
|
+ })
|
|
|
|
+ expect(mostViewedVideosAllTimeResponse.errors).toBeUndefined()
|
|
|
|
+ return mostViewedVideosAllTimeResponse.data?.mostViewedVideosAllTime
|
|
|
|
+ }
|
|
|
|
+
|
|
const getChannelViews = async (channelId: string) => {
|
|
const getChannelViews = async (channelId: string) => {
|
|
const channelViewsResponse = await query<GetChannelViews, GetChannelViewsArgs>({
|
|
const channelViewsResponse = await query<GetChannelViews, GetChannelViewsArgs>({
|
|
query: GET_CHANNEL_VIEWS,
|
|
query: GET_CHANNEL_VIEWS,
|
|
@@ -101,8 +119,20 @@ describe('Video and channel views resolver', () => {
|
|
return mostViewedChannelsResponse.data?.mostViewedChannels
|
|
return mostViewedChannelsResponse.data?.mostViewedChannels
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ const getMostViewedChannelsAllTime = async (limit: number) => {
|
|
|
|
+ const mostViewedChannelsAllTimeResponse = await query<
|
|
|
|
+ GetMostViewedChannelsAllTime,
|
|
|
|
+ GetMostViewedChannelsAllTimeArgs
|
|
|
|
+ >({
|
|
|
|
+ query: GET_MOST_VIEWED_CHANNELS_ALL_TIME,
|
|
|
|
+ variables: { limit },
|
|
|
|
+ })
|
|
|
|
+ expect(mostViewedChannelsAllTimeResponse.errors).toBeUndefined()
|
|
|
|
+ return mostViewedChannelsAllTimeResponse.data?.mostViewedChannelsAllTime
|
|
|
|
+ }
|
|
|
|
+
|
|
const getMostViewedCategories = async (period: number) => {
|
|
const getMostViewedCategories = async (period: number) => {
|
|
- const mostViewedCategoriesResponse = await query<GetMostViewedCategories, GetMostViewedCategoriessArgs>({
|
|
|
|
|
|
+ const mostViewedCategoriesResponse = await query<GetMostViewedCategories, GetMostViewedCategoriesArgs>({
|
|
query: GET_MOST_VIEWED_CATEGORIES,
|
|
query: GET_MOST_VIEWED_CATEGORIES,
|
|
variables: { period },
|
|
variables: { period },
|
|
})
|
|
})
|
|
@@ -110,18 +140,36 @@ describe('Video and channel views resolver', () => {
|
|
return mostViewedCategoriesResponse.data?.mostViewedCategories
|
|
return mostViewedCategoriesResponse.data?.mostViewedCategories
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ const getMostViewedCategoriesAllTime = async (limit: number) => {
|
|
|
|
+ const mostViewedCategoriesAllTimeResponse = await query<
|
|
|
|
+ GetMostViewedCategoriesAllTime,
|
|
|
|
+ GetMostViewedCategoriesAllTimeArgs
|
|
|
|
+ >({
|
|
|
|
+ query: GET_MOST_VIEWED_CATEGORIES_ALL_TIME,
|
|
|
|
+ variables: { limit },
|
|
|
|
+ })
|
|
|
|
+ expect(mostViewedCategoriesAllTimeResponse.errors).toBeUndefined()
|
|
|
|
+ return mostViewedCategoriesAllTimeResponse.data?.mostViewedCategoriesAllTime
|
|
|
|
+ }
|
|
|
|
+
|
|
it('should return null for unknown video, channel and category views', async () => {
|
|
it('should return null for unknown video, channel and category views', async () => {
|
|
const videoViews = await getVideoViews(FIRST_VIDEO_ID)
|
|
const videoViews = await getVideoViews(FIRST_VIDEO_ID)
|
|
const mostViewedVideos = await getMostViewedVideos(30)
|
|
const mostViewedVideos = await getMostViewedVideos(30)
|
|
|
|
+ const mostViewedVideosAllTime = await getMostViewedVideosAllTime(10)
|
|
const channelViews = await getChannelViews(FIRST_CHANNEL_ID)
|
|
const channelViews = await getChannelViews(FIRST_CHANNEL_ID)
|
|
const mostViewedChannels = await getMostViewedChannels(30)
|
|
const mostViewedChannels = await getMostViewedChannels(30)
|
|
|
|
+ const mostViewedChannelsAllTime = await getMostViewedChannelsAllTime(10)
|
|
const mostViewedCategories = await getMostViewedCategories(30)
|
|
const mostViewedCategories = await getMostViewedCategories(30)
|
|
|
|
+ const mostViewedCategoriesAllTime = await getMostViewedCategoriesAllTime(10)
|
|
|
|
|
|
expect(videoViews).toBeNull()
|
|
expect(videoViews).toBeNull()
|
|
expect(mostViewedVideos).toHaveLength(0)
|
|
expect(mostViewedVideos).toHaveLength(0)
|
|
|
|
+ expect(mostViewedVideosAllTime).toHaveLength(0)
|
|
expect(channelViews).toBeNull()
|
|
expect(channelViews).toBeNull()
|
|
expect(mostViewedChannels).toHaveLength(0)
|
|
expect(mostViewedChannels).toHaveLength(0)
|
|
|
|
+ expect(mostViewedChannelsAllTime).toHaveLength(0)
|
|
expect(mostViewedCategories).toHaveLength(0)
|
|
expect(mostViewedCategories).toHaveLength(0)
|
|
|
|
+ expect(mostViewedCategoriesAllTime).toHaveLength(0)
|
|
})
|
|
})
|
|
|
|
|
|
it('should properly save video and channel views', async () => {
|
|
it('should properly save video and channel views', async () => {
|
|
@@ -140,15 +188,21 @@ describe('Video and channel views resolver', () => {
|
|
const checkViews = async () => {
|
|
const checkViews = async () => {
|
|
const videoViews = await getVideoViews(FIRST_VIDEO_ID)
|
|
const videoViews = await getVideoViews(FIRST_VIDEO_ID)
|
|
const mostViewedVideos = await getMostViewedVideos(30)
|
|
const mostViewedVideos = await getMostViewedVideos(30)
|
|
|
|
+ const mostViewedVideosAllTime = await getMostViewedVideosAllTime(10)
|
|
const channelViews = await getChannelViews(FIRST_CHANNEL_ID)
|
|
const channelViews = await getChannelViews(FIRST_CHANNEL_ID)
|
|
const mostViewedChannels = await getMostViewedChannels(30)
|
|
const mostViewedChannels = await getMostViewedChannels(30)
|
|
|
|
+ const mostViewedChannelsAllTime = await getMostViewedChannelsAllTime(10)
|
|
const mostViewedCategories = await getMostViewedCategories(30)
|
|
const mostViewedCategories = await getMostViewedCategories(30)
|
|
|
|
+ const mostViewedCategoriesAllTime = await getMostViewedCategoriesAllTime(10)
|
|
|
|
|
|
expect(videoViews).toEqual(expectedVideoViews)
|
|
expect(videoViews).toEqual(expectedVideoViews)
|
|
expect(mostViewedVideos).toEqual([expectedVideoViews])
|
|
expect(mostViewedVideos).toEqual([expectedVideoViews])
|
|
|
|
+ expect(mostViewedVideosAllTime).toEqual([expectedVideoViews])
|
|
expect(channelViews).toEqual(expectedChannelViews)
|
|
expect(channelViews).toEqual(expectedChannelViews)
|
|
expect(mostViewedChannels).toEqual([expectedChannelViews])
|
|
expect(mostViewedChannels).toEqual([expectedChannelViews])
|
|
|
|
+ expect(mostViewedChannelsAllTime).toEqual([expectedChannelViews])
|
|
expect(mostViewedCategories).toEqual([expectedCategoryViews])
|
|
expect(mostViewedCategories).toEqual([expectedCategoryViews])
|
|
|
|
+ expect(mostViewedCategoriesAllTime).toEqual([expectedCategoryViews])
|
|
}
|
|
}
|
|
|
|
|
|
let addVideoViewData = await addVideoView(FIRST_VIDEO_ID, FIRST_CHANNEL_ID, FIRST_CATEGORY_ID)
|
|
let addVideoViewData = await addVideoView(FIRST_VIDEO_ID, FIRST_CHANNEL_ID, FIRST_CATEGORY_ID)
|
|
@@ -189,10 +243,12 @@ describe('Video and channel views resolver', () => {
|
|
const firstVideoViews = await getVideoViews(FIRST_VIDEO_ID)
|
|
const firstVideoViews = await getVideoViews(FIRST_VIDEO_ID)
|
|
const secondVideoViews = await getVideoViews(SECOND_VIDEO_ID)
|
|
const secondVideoViews = await getVideoViews(SECOND_VIDEO_ID)
|
|
const mostViewedVideos = await getMostViewedVideos(30)
|
|
const mostViewedVideos = await getMostViewedVideos(30)
|
|
|
|
+ const mostViewedVideosAllTime = await getMostViewedVideosAllTime(10)
|
|
|
|
|
|
expect(firstVideoViews).toEqual(expectedFirstVideoViews)
|
|
expect(firstVideoViews).toEqual(expectedFirstVideoViews)
|
|
expect(secondVideoViews).toEqual(expectedSecondVideoViews)
|
|
expect(secondVideoViews).toEqual(expectedSecondVideoViews)
|
|
expect(mostViewedVideos).toEqual([expectedFirstVideoViews, expectedSecondVideoViews])
|
|
expect(mostViewedVideos).toEqual([expectedFirstVideoViews, expectedSecondVideoViews])
|
|
|
|
+ expect(mostViewedVideosAllTime).toEqual([expectedFirstVideoViews, expectedSecondVideoViews])
|
|
})
|
|
})
|
|
|
|
|
|
it('should distinct views of separate channels', async () => {
|
|
it('should distinct views of separate channels', async () => {
|
|
@@ -211,10 +267,12 @@ describe('Video and channel views resolver', () => {
|
|
const firstChannelViews = await getChannelViews(FIRST_CHANNEL_ID)
|
|
const firstChannelViews = await getChannelViews(FIRST_CHANNEL_ID)
|
|
const secondChannelViews = await getChannelViews(SECOND_CHANNEL_ID)
|
|
const secondChannelViews = await getChannelViews(SECOND_CHANNEL_ID)
|
|
const mostViewedChannels = await getMostViewedChannels(30)
|
|
const mostViewedChannels = await getMostViewedChannels(30)
|
|
|
|
+ const mostViewedChannelsAllTime = await getMostViewedChannelsAllTime(10)
|
|
|
|
|
|
expect(firstChannelViews).toEqual(expectedFirstChanelViews)
|
|
expect(firstChannelViews).toEqual(expectedFirstChanelViews)
|
|
expect(secondChannelViews).toEqual(expectedSecondChannelViews)
|
|
expect(secondChannelViews).toEqual(expectedSecondChannelViews)
|
|
expect(mostViewedChannels).toEqual([expectedFirstChanelViews, expectedSecondChannelViews])
|
|
expect(mostViewedChannels).toEqual([expectedFirstChanelViews, expectedSecondChannelViews])
|
|
|
|
+ expect(mostViewedChannelsAllTime).toEqual([expectedFirstChanelViews, expectedSecondChannelViews])
|
|
})
|
|
})
|
|
|
|
|
|
it('should properly aggregate views of a channel', async () => {
|
|
it('should properly aggregate views of a channel', async () => {
|
|
@@ -228,9 +286,11 @@ describe('Video and channel views resolver', () => {
|
|
|
|
|
|
const channelViews = await getChannelViews(FIRST_CHANNEL_ID)
|
|
const channelViews = await getChannelViews(FIRST_CHANNEL_ID)
|
|
const mostViewedChannels = await getMostViewedChannels(30)
|
|
const mostViewedChannels = await getMostViewedChannels(30)
|
|
|
|
+ const mostViewedChannelsAllTime = await getMostViewedChannelsAllTime(10)
|
|
|
|
|
|
expect(channelViews).toEqual(expectedChannelViews)
|
|
expect(channelViews).toEqual(expectedChannelViews)
|
|
expect(mostViewedChannels).toEqual([expectedChannelViews])
|
|
expect(mostViewedChannels).toEqual([expectedChannelViews])
|
|
|
|
+ expect(mostViewedChannelsAllTime).toEqual([expectedChannelViews])
|
|
})
|
|
})
|
|
|
|
|
|
it('should properly aggregate views of a category', async () => {
|
|
it('should properly aggregate views of a category', async () => {
|
|
@@ -243,8 +303,10 @@ describe('Video and channel views resolver', () => {
|
|
await addVideoView(SECOND_VIDEO_ID, FIRST_CHANNEL_ID, FIRST_CATEGORY_ID)
|
|
await addVideoView(SECOND_VIDEO_ID, FIRST_CHANNEL_ID, FIRST_CATEGORY_ID)
|
|
|
|
|
|
const mostViewedCategories = await getMostViewedCategories(30)
|
|
const mostViewedCategories = await getMostViewedCategories(30)
|
|
|
|
+ const mostViewedCategoriesAllTime = await getMostViewedCategoriesAllTime(10)
|
|
|
|
|
|
expect(mostViewedCategories).toEqual([expectedChannelViews])
|
|
expect(mostViewedCategories).toEqual([expectedChannelViews])
|
|
|
|
+ expect(mostViewedCategoriesAllTime).toEqual([expectedChannelViews])
|
|
})
|
|
})
|
|
|
|
|
|
it('should properly rebuild the aggregate', async () => {
|
|
it('should properly rebuild the aggregate', async () => {
|
|
@@ -270,15 +332,21 @@ describe('Video and channel views resolver', () => {
|
|
const secondVideoViews = await getVideoViews(SECOND_VIDEO_ID)
|
|
const secondVideoViews = await getVideoViews(SECOND_VIDEO_ID)
|
|
const channelViews = await getChannelViews(FIRST_CHANNEL_ID)
|
|
const channelViews = await getChannelViews(FIRST_CHANNEL_ID)
|
|
const mostViewedVideos = await getMostViewedVideos(30)
|
|
const mostViewedVideos = await getMostViewedVideos(30)
|
|
|
|
+ const mostViewedVideosAllTime = await getMostViewedVideosAllTime(10)
|
|
const mostViewedChannels = await getMostViewedChannels(30)
|
|
const mostViewedChannels = await getMostViewedChannels(30)
|
|
|
|
+ const mostViewedChannelsAllTime = await getMostViewedChannelsAllTime(10)
|
|
const mostViewedCategories = await getMostViewedCategories(30)
|
|
const mostViewedCategories = await getMostViewedCategories(30)
|
|
|
|
+ const mostViewedCategoriesAllTime = await getMostViewedCategoriesAllTime(10)
|
|
|
|
|
|
expect(firstVideoViews).toEqual(expectedFirstVideoViews)
|
|
expect(firstVideoViews).toEqual(expectedFirstVideoViews)
|
|
expect(secondVideoViews).toEqual(expectedSecondVideoViews)
|
|
expect(secondVideoViews).toEqual(expectedSecondVideoViews)
|
|
expect(mostViewedVideos).toEqual([expectedSecondVideoViews, expectedFirstVideoViews])
|
|
expect(mostViewedVideos).toEqual([expectedSecondVideoViews, expectedFirstVideoViews])
|
|
|
|
+ expect(mostViewedVideosAllTime).toEqual([expectedSecondVideoViews, expectedFirstVideoViews])
|
|
expect(channelViews).toEqual(expectedChannelViews)
|
|
expect(channelViews).toEqual(expectedChannelViews)
|
|
expect(mostViewedChannels).toEqual([expectedChannelViews])
|
|
expect(mostViewedChannels).toEqual([expectedChannelViews])
|
|
|
|
+ expect(mostViewedChannelsAllTime).toEqual([expectedChannelViews])
|
|
expect(mostViewedCategories).toEqual([expectedCategoryViews])
|
|
expect(mostViewedCategories).toEqual([expectedCategoryViews])
|
|
|
|
+ expect(mostViewedCategoriesAllTime).toEqual([expectedCategoryViews])
|
|
}
|
|
}
|
|
|
|
|
|
await addVideoView(FIRST_VIDEO_ID, FIRST_CHANNEL_ID, FIRST_CATEGORY_ID)
|
|
await addVideoView(FIRST_VIDEO_ID, FIRST_CHANNEL_ID, FIRST_CATEGORY_ID)
|
|
@@ -315,7 +383,9 @@ describe('Video and channel views resolver', () => {
|
|
|
|
|
|
const videoViews = await getVideoViews(FIRST_VIDEO_ID)
|
|
const videoViews = await getVideoViews(FIRST_VIDEO_ID)
|
|
const mostViewedVideos = await getMostViewedVideos(30)
|
|
const mostViewedVideos = await getMostViewedVideos(30)
|
|
|
|
+ const mostViewedVideosAllTime = await getMostViewedVideosAllTime(10)
|
|
expect(videoViews).toEqual(expectedVideoViews)
|
|
expect(videoViews).toEqual(expectedVideoViews)
|
|
expect(mostViewedVideos).toEqual([expectedVideoViews])
|
|
expect(mostViewedVideos).toEqual([expectedVideoViews])
|
|
|
|
+ expect(mostViewedVideosAllTime).toEqual([expectedVideoViews])
|
|
})
|
|
})
|
|
})
|
|
})
|