]>
Commit | Line | Data |
---|---|---|
a1587156 | 1 | /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */ |
2d3741d6 | 2 | |
2d3741d6 | 3 | import 'mocha' |
52a350a1 C |
4 | import * as chai from 'chai' |
5 | ||
6 | import { | |
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' | |
2d3741d6 | 16 | import { VideosOverview } from '../../../../shared/models/overviews' |
52a350a1 C |
17 | import { addAccountToAccountBlocklist } from '@shared/extra-utils/users/blocklist' |
18 | import { Response } from 'superagent' | |
2d3741d6 C |
19 | |
20 | const expect = chai.expect | |
21 | ||
22 | describe('Test a videos overview', function () { | |
23 | let server: ServerInfo = null | |
24 | ||
52a350a1 C |
25 | function testOverviewCount (res: Response, expected: number) { |
26 | const overview: VideosOverview = res.body | |
27 | ||
28 | expect(overview.tags).to.have.lengthOf(expected) | |
29 | expect(overview.categories).to.have.lengthOf(expected) | |
30 | expect(overview.channels).to.have.lengthOf(expected) | |
31 | } | |
32 | ||
2d3741d6 C |
33 | before(async function () { |
34 | this.timeout(30000) | |
35 | ||
210feb6c | 36 | server = await flushAndRunServer(1) |
2d3741d6 C |
37 | |
38 | await setAccessTokensToServers([ server ]) | |
39 | }) | |
40 | ||
41 | it('Should send empty overview', async function () { | |
764a9657 | 42 | const res = await getVideosOverview(server.url, 1) |
2d3741d6 | 43 | |
52a350a1 | 44 | testOverviewCount(res, 0) |
2d3741d6 C |
45 | }) |
46 | ||
9a629c6e C |
47 | it('Should upload 5 videos in a specific category, tag and channel but not include them in overview', async function () { |
48 | this.timeout(15000) | |
49 | ||
764a9657 C |
50 | await wait(3000) |
51 | ||
52 | await uploadVideo(server.url, server.accessToken, { | |
53 | name: 'video 0', | |
54 | category: 3, | |
55 | tags: [ 'coucou1', 'coucou2' ] | |
56 | }) | |
2d3741d6 | 57 | |
764a9657 | 58 | const res = await getVideosOverview(server.url, 1) |
2d3741d6 | 59 | |
52a350a1 | 60 | testOverviewCount(res, 0) |
2d3741d6 C |
61 | }) |
62 | ||
63 | it('Should upload another video and include all videos in the overview', async function () { | |
764a9657 | 64 | this.timeout(15000) |
2d3741d6 | 65 | |
764a9657 C |
66 | for (let i = 1; i < 6; i++) { |
67 | await uploadVideo(server.url, server.accessToken, { | |
68 | name: 'video ' + i, | |
69 | category: 3, | |
70 | tags: [ 'coucou1', 'coucou2' ] | |
71 | }) | |
72 | } | |
2d3741d6 | 73 | |
764a9657 C |
74 | await wait(3000) |
75 | ||
76 | { | |
77 | const res = await getVideosOverview(server.url, 1) | |
78 | ||
52a350a1 | 79 | testOverviewCount(res, 1) |
764a9657 C |
80 | } |
81 | ||
82 | { | |
83 | const res = await getVideosOverview(server.url, 2) | |
84 | ||
85 | const overview: VideosOverview = res.body | |
86 | expect(overview.tags).to.have.lengthOf(1) | |
87 | expect(overview.categories).to.have.lengthOf(0) | |
88 | expect(overview.channels).to.have.lengthOf(0) | |
89 | } | |
2d3741d6 C |
90 | }) |
91 | ||
92 | it('Should have the correct overview', async function () { | |
764a9657 C |
93 | const res1 = await getVideosOverview(server.url, 1) |
94 | const res2 = await getVideosOverview(server.url, 2) | |
2d3741d6 | 95 | |
764a9657 C |
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 | ||
106 | for (const arr of tmp) { | |
107 | expect(arr).to.have.lengthOf(1) | |
2d3741d6 | 108 | |
764a9657 | 109 | const obj = arr[0] |
2d3741d6 | 110 | |
9a629c6e C |
111 | expect(obj.videos).to.have.lengthOf(6) |
112 | expect(obj.videos[0].name).to.equal('video 5') | |
113 | expect(obj.videos[1].name).to.equal('video 4') | |
114 | expect(obj.videos[2].name).to.equal('video 3') | |
115 | expect(obj.videos[3].name).to.equal('video 2') | |
116 | expect(obj.videos[4].name).to.equal('video 1') | |
117 | expect(obj.videos[5].name).to.equal('video 0') | |
2d3741d6 C |
118 | } |
119 | ||
764a9657 C |
120 | const tags = [ overview1.tags[0].tag, overview2.tags[0].tag ] |
121 | expect(tags.find(t => t === 'coucou1')).to.not.be.undefined | |
122 | expect(tags.find(t => t === 'coucou2')).to.not.be.undefined | |
2d3741d6 | 123 | |
764a9657 | 124 | expect(overview1.categories[0].category.id).to.equal(3) |
2d3741d6 | 125 | |
764a9657 | 126 | expect(overview1.channels[0].channel.name).to.equal('root_channel') |
2d3741d6 C |
127 | }) |
128 | ||
52a350a1 C |
129 | it('Should hide muted accounts', async function () { |
130 | const token = await generateUserAccessToken(server, 'choco') | |
131 | ||
132 | await addAccountToAccountBlocklist(server.url, token, 'root@' + server.host) | |
133 | ||
134 | { | |
135 | const res = await getVideosOverview(server.url, 1) | |
136 | ||
137 | testOverviewCount(res, 1) | |
138 | } | |
139 | ||
140 | { | |
141 | const res = await getVideosOverviewWithToken(server.url, 1, token) | |
142 | ||
143 | testOverviewCount(res, 0) | |
144 | } | |
145 | }) | |
146 | ||
7c3b7976 C |
147 | after(async function () { |
148 | await cleanupTests([ server ]) | |
2d3741d6 C |
149 | }) |
150 | }) |