]>
Commit | Line | Data |
---|---|---|
1 | /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */ | |
2 | ||
3 | import 'mocha' | |
4 | import * as chai from 'chai' | |
5 | import { | |
6 | cleanupTests, | |
7 | flushAndRunServer, | |
8 | generateUserAccessToken, | |
9 | ServerInfo, | |
10 | setAccessTokensToServers, | |
11 | uploadVideo, | |
12 | wait | |
13 | } from '@shared/extra-utils' | |
14 | import { VideosOverview } from '@shared/models' | |
15 | ||
16 | const expect = chai.expect | |
17 | ||
18 | describe('Test a videos overview', function () { | |
19 | let server: ServerInfo = null | |
20 | ||
21 | function testOverviewCount (overview: VideosOverview, expected: number) { | |
22 | expect(overview.tags).to.have.lengthOf(expected) | |
23 | expect(overview.categories).to.have.lengthOf(expected) | |
24 | expect(overview.channels).to.have.lengthOf(expected) | |
25 | } | |
26 | ||
27 | before(async function () { | |
28 | this.timeout(30000) | |
29 | ||
30 | server = await flushAndRunServer(1) | |
31 | ||
32 | await setAccessTokensToServers([ server ]) | |
33 | }) | |
34 | ||
35 | it('Should send empty overview', async function () { | |
36 | const body = await server.overviewsCommand.getVideos({ page: 1 }) | |
37 | ||
38 | testOverviewCount(body, 0) | |
39 | }) | |
40 | ||
41 | it('Should upload 5 videos in a specific category, tag and channel but not include them in overview', async function () { | |
42 | this.timeout(30000) | |
43 | ||
44 | await wait(3000) | |
45 | ||
46 | await uploadVideo(server.url, server.accessToken, { | |
47 | name: 'video 0', | |
48 | category: 3, | |
49 | tags: [ 'coucou1', 'coucou2' ] | |
50 | }) | |
51 | ||
52 | const body = await server.overviewsCommand.getVideos({ page: 1 }) | |
53 | ||
54 | testOverviewCount(body, 0) | |
55 | }) | |
56 | ||
57 | it('Should upload another video and include all videos in the overview', async function () { | |
58 | this.timeout(30000) | |
59 | ||
60 | { | |
61 | for (let i = 1; i < 6; i++) { | |
62 | await uploadVideo(server.url, server.accessToken, { | |
63 | name: 'video ' + i, | |
64 | category: 3, | |
65 | tags: [ 'coucou1', 'coucou2' ] | |
66 | }) | |
67 | } | |
68 | ||
69 | await wait(3000) | |
70 | } | |
71 | ||
72 | { | |
73 | const body = await server.overviewsCommand.getVideos({ page: 1 }) | |
74 | ||
75 | testOverviewCount(body, 1) | |
76 | } | |
77 | ||
78 | { | |
79 | const overview = await server.overviewsCommand.getVideos({ page: 2 }) | |
80 | ||
81 | expect(overview.tags).to.have.lengthOf(1) | |
82 | expect(overview.categories).to.have.lengthOf(0) | |
83 | expect(overview.channels).to.have.lengthOf(0) | |
84 | } | |
85 | }) | |
86 | ||
87 | it('Should have the correct overview', async function () { | |
88 | const overview1 = await server.overviewsCommand.getVideos({ page: 1 }) | |
89 | const overview2 = await server.overviewsCommand.getVideos({ page: 2 }) | |
90 | ||
91 | for (const arr of [ overview1.tags, overview1.categories, overview1.channels, overview2.tags ]) { | |
92 | expect(arr).to.have.lengthOf(1) | |
93 | ||
94 | const obj = arr[0] | |
95 | ||
96 | expect(obj.videos).to.have.lengthOf(6) | |
97 | expect(obj.videos[0].name).to.equal('video 5') | |
98 | expect(obj.videos[1].name).to.equal('video 4') | |
99 | expect(obj.videos[2].name).to.equal('video 3') | |
100 | expect(obj.videos[3].name).to.equal('video 2') | |
101 | expect(obj.videos[4].name).to.equal('video 1') | |
102 | expect(obj.videos[5].name).to.equal('video 0') | |
103 | } | |
104 | ||
105 | const tags = [ overview1.tags[0].tag, overview2.tags[0].tag ] | |
106 | expect(tags.find(t => t === 'coucou1')).to.not.be.undefined | |
107 | expect(tags.find(t => t === 'coucou2')).to.not.be.undefined | |
108 | ||
109 | expect(overview1.categories[0].category.id).to.equal(3) | |
110 | ||
111 | expect(overview1.channels[0].channel.name).to.equal('root_channel') | |
112 | }) | |
113 | ||
114 | it('Should hide muted accounts', async function () { | |
115 | const token = await generateUserAccessToken(server, 'choco') | |
116 | ||
117 | await server.blocklistCommand.addToMyBlocklist({ token, account: 'root@' + server.host }) | |
118 | ||
119 | { | |
120 | const body = await server.overviewsCommand.getVideos({ page: 1 }) | |
121 | ||
122 | testOverviewCount(body, 1) | |
123 | } | |
124 | ||
125 | { | |
126 | const body = await server.overviewsCommand.getVideos({ page: 1, token }) | |
127 | ||
128 | testOverviewCount(body, 0) | |
129 | } | |
130 | }) | |
131 | ||
132 | after(async function () { | |
133 | await cleanupTests([ server ]) | |
134 | }) | |
135 | }) |