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