aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/tests/api/videos/videos-overview.ts
diff options
context:
space:
mode:
Diffstat (limited to 'server/tests/api/videos/videos-overview.ts')
-rw-r--r--server/tests/api/videos/videos-overview.ts71
1 files changed, 29 insertions, 42 deletions
diff --git a/server/tests/api/videos/videos-overview.ts b/server/tests/api/videos/videos-overview.ts
index c266a1dc5..c8e3df4bd 100644
--- a/server/tests/api/videos/videos-overview.ts
+++ b/server/tests/api/videos/videos-overview.ts
@@ -2,8 +2,9 @@
2 2
3import 'mocha' 3import 'mocha'
4import * as chai from 'chai' 4import * as chai from 'chai'
5 5import { Response } from 'superagent'
6import { 6import {
7 addAccountToAccountBlocklist,
7 cleanupTests, 8 cleanupTests,
8 flushAndRunServer, 9 flushAndRunServer,
9 generateUserAccessToken, 10 generateUserAccessToken,
@@ -11,20 +12,15 @@ import {
11 setAccessTokensToServers, 12 setAccessTokensToServers,
12 uploadVideo, 13 uploadVideo,
13 wait 14 wait
14} from '../../../../shared/extra-utils' 15} from '@shared/extra-utils'
15import { getVideosOverview, getVideosOverviewWithToken } from '../../../../shared/extra-utils/overviews/overviews' 16import { VideosOverview } from '@shared/models'
16import { VideosOverview } from '../../../../shared/models/overviews'
17import { addAccountToAccountBlocklist } from '@shared/extra-utils/users/blocklist'
18import { Response } from 'superagent'
19 17
20const expect = chai.expect 18const expect = chai.expect
21 19
22describe('Test a videos overview', function () { 20describe('Test a videos overview', function () {
23 let server: ServerInfo = null 21 let server: ServerInfo = null
24 22
25 function testOverviewCount (res: Response, expected: number) { 23 function testOverviewCount (overview: VideosOverview, expected: number) {
26 const overview: VideosOverview = res.body
27
28 expect(overview.tags).to.have.lengthOf(expected) 24 expect(overview.tags).to.have.lengthOf(expected)
29 expect(overview.categories).to.have.lengthOf(expected) 25 expect(overview.categories).to.have.lengthOf(expected)
30 expect(overview.channels).to.have.lengthOf(expected) 26 expect(overview.channels).to.have.lengthOf(expected)
@@ -39,9 +35,9 @@ describe('Test a videos overview', function () {
39 }) 35 })
40 36
41 it('Should send empty overview', async function () { 37 it('Should send empty overview', async function () {
42 const res = await getVideosOverview(server.url, 1) 38 const body = await server.overviewsCommand.getVideos({ page: 1 })
43 39
44 testOverviewCount(res, 0) 40 testOverviewCount(body, 0)
45 }) 41 })
46 42
47 it('Should upload 5 videos in a specific category, tag and channel but not include them in overview', async function () { 43 it('Should upload 5 videos in a specific category, tag and channel but not include them in overview', async function () {
@@ -55,34 +51,35 @@ describe('Test a videos overview', function () {
55 tags: [ 'coucou1', 'coucou2' ] 51 tags: [ 'coucou1', 'coucou2' ]
56 }) 52 })
57 53
58 const res = await getVideosOverview(server.url, 1) 54 const body = await server.overviewsCommand.getVideos({ page: 1 })
59 55
60 testOverviewCount(res, 0) 56 testOverviewCount(body, 0)
61 }) 57 })
62 58
63 it('Should upload another video and include all videos in the overview', async function () { 59 it('Should upload another video and include all videos in the overview', async function () {
64 this.timeout(30000) 60 this.timeout(30000)
65 61
66 for (let i = 1; i < 6; i++) { 62 {
67 await uploadVideo(server.url, server.accessToken, { 63 for (let i = 1; i < 6; i++) {
68 name: 'video ' + i, 64 await uploadVideo(server.url, server.accessToken, {
69 category: 3, 65 name: 'video ' + i,
70 tags: [ 'coucou1', 'coucou2' ] 66 category: 3,
71 }) 67 tags: [ 'coucou1', 'coucou2' ]
68 })
69 }
70
71 await wait(3000)
72 } 72 }
73 73
74 await wait(3000)
75
76 { 74 {
77 const res = await getVideosOverview(server.url, 1) 75 const body = await server.overviewsCommand.getVideos({ page: 1 })
78 76
79 testOverviewCount(res, 1) 77 testOverviewCount(body, 1)
80 } 78 }
81 79
82 { 80 {
83 const res = await getVideosOverview(server.url, 2) 81 const overview = await server.overviewsCommand.getVideos({ page: 2 })
84 82
85 const overview: VideosOverview = res.body
86 expect(overview.tags).to.have.lengthOf(1) 83 expect(overview.tags).to.have.lengthOf(1)
87 expect(overview.categories).to.have.lengthOf(0) 84 expect(overview.categories).to.have.lengthOf(0)
88 expect(overview.channels).to.have.lengthOf(0) 85 expect(overview.channels).to.have.lengthOf(0)
@@ -90,20 +87,10 @@ describe('Test a videos overview', function () {
90 }) 87 })
91 88
92 it('Should have the correct overview', async function () { 89 it('Should have the correct overview', async function () {
93 const res1 = await getVideosOverview(server.url, 1) 90 const overview1 = await server.overviewsCommand.getVideos({ page: 1 })
94 const res2 = await getVideosOverview(server.url, 2) 91 const overview2 = await server.overviewsCommand.getVideos({ page: 2 })
95
96 const overview1: VideosOverview = res1.body
97 const overview2: VideosOverview = res2.body
98
99 const tmp = [
100 overview1.tags,
101 overview1.categories,
102 overview1.channels,
103 overview2.tags
104 ]
105 92
106 for (const arr of tmp) { 93 for (const arr of [ overview1.tags, overview1.categories, overview1.channels, overview2.tags ]) {
107 expect(arr).to.have.lengthOf(1) 94 expect(arr).to.have.lengthOf(1)
108 95
109 const obj = arr[0] 96 const obj = arr[0]
@@ -132,15 +119,15 @@ describe('Test a videos overview', function () {
132 await addAccountToAccountBlocklist(server.url, token, 'root@' + server.host) 119 await addAccountToAccountBlocklist(server.url, token, 'root@' + server.host)
133 120
134 { 121 {
135 const res = await getVideosOverview(server.url, 1) 122 const body = await server.overviewsCommand.getVideos({ page: 1 })
136 123
137 testOverviewCount(res, 1) 124 testOverviewCount(body, 1)
138 } 125 }
139 126
140 { 127 {
141 const res = await getVideosOverviewWithToken(server.url, 1, token) 128 const body = await server.overviewsCommand.getVideos({ page: 1, token })
142 129
143 testOverviewCount(res, 0) 130 testOverviewCount(body, 0)
144 } 131 }
145 }) 132 })
146 133