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