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