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