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