]>
Commit | Line | Data |
---|---|---|
792dbaf0 GS |
1 | /* tslint:disable:no-unused-expressions */ |
2 | ||
792dbaf0 | 3 | import * as chai from 'chai' |
792dbaf0 | 4 | import * as lodash from 'lodash' |
975e6e0e | 5 | import 'mocha' |
792dbaf0 | 6 | import { |
975e6e0e | 7 | addVideoToBlacklist, |
792dbaf0 | 8 | flushAndRunMultipleServers, |
975e6e0e C |
9 | flushTests, |
10 | getBlacklistedVideosList, | |
11 | getSortedBlacklistedVideosList, | |
792dbaf0 | 12 | getVideosList, |
975e6e0e | 13 | killallServers, |
792dbaf0 | 14 | removeVideoFromBlacklist, |
975e6e0e C |
15 | ServerInfo, |
16 | setAccessTokensToServers, | |
17 | uploadVideo, | |
18 | wait | |
792dbaf0 | 19 | } from '../utils' |
975e6e0e C |
20 | import { doubleFollow } from '../utils/follows' |
21 | ||
22 | const expect = chai.expect | |
23 | const orderBy = lodash.orderBy | |
792dbaf0 GS |
24 | |
25 | describe('Test video blacklist management', function () { | |
26 | let servers: ServerInfo[] = [] | |
27 | ||
975e6e0e | 28 | async function blacklistVideosOnServer (server: ServerInfo) { |
792dbaf0 GS |
29 | const res = await getVideosList(server.url) |
30 | ||
31 | const videos = res.body.data | |
32 | for (let video of videos) { | |
33 | await addVideoToBlacklist(server.url, server.accessToken, video.id) | |
34 | } | |
35 | } | |
36 | ||
37 | before(async function () { | |
572f8d3d | 38 | this.timeout(50000) |
792dbaf0 GS |
39 | |
40 | // Run servers | |
41 | servers = await flushAndRunMultipleServers(2) | |
42 | ||
43 | // Get the access tokens | |
44 | await setAccessTokensToServers(servers) | |
45 | ||
975e6e0e C |
46 | // Server 1 and server 2 follow each other |
47 | await doubleFollow(servers[0], servers[1]) | |
792dbaf0 | 48 | |
975e6e0e C |
49 | // Upload 2 videos on server 2 |
50 | await uploadVideo(servers[1].url, servers[1].accessToken, { name: 'My 1st video', description: 'A video on server 2' }) | |
51 | await uploadVideo(servers[1].url, servers[1].accessToken, { name: 'My 2nd video', description: 'A video on server 2' }) | |
792dbaf0 | 52 | |
572f8d3d C |
53 | // Wait videos propagation, server 2 has transcoding enabled |
54 | await wait(15000) | |
792dbaf0 | 55 | |
975e6e0e C |
56 | // Blacklist the two videos on server 1 |
57 | await blacklistVideosOnServer(servers[0]) | |
792dbaf0 GS |
58 | }) |
59 | ||
60 | describe('When listing blacklisted videos', function () { | |
61 | it('Should display all the blacklisted videos', async function () { | |
62 | const res = await getBlacklistedVideosList(servers[0].url, servers[0].accessToken) | |
63 | ||
64 | expect(res.body.total).to.equal(2) | |
65 | ||
66 | const videos = res.body.data | |
67 | expect(videos).to.be.an('array') | |
68 | expect(videos.length).to.equal(2) | |
69 | }) | |
70 | ||
71 | it('Should get the correct sort when sorting by descending id', async function () { | |
72 | const res = await getSortedBlacklistedVideosList(servers[0].url, servers[0].accessToken, '-id') | |
73 | expect(res.body.total).to.equal(2) | |
74 | ||
75 | const videos = res.body.data | |
76 | expect(videos).to.be.an('array') | |
77 | expect(videos.length).to.equal(2) | |
78 | ||
79 | const result = orderBy(res.body.data, [ 'id' ], [ 'desc' ]) | |
80 | ||
81 | expect(videos).to.deep.equal(result) | |
82 | }) | |
83 | ||
84 | it('Should get the correct sort when sorting by descending video name', async function () { | |
85 | const res = await getSortedBlacklistedVideosList(servers[0].url, servers[0].accessToken, '-name') | |
86 | expect(res.body.total).to.equal(2) | |
87 | ||
88 | const videos = res.body.data | |
89 | expect(videos).to.be.an('array') | |
90 | expect(videos.length).to.equal(2) | |
91 | ||
92 | const result = orderBy(res.body.data, [ 'name' ], [ 'desc' ]) | |
93 | ||
94 | expect(videos).to.deep.equal(result) | |
95 | }) | |
96 | ||
97 | it('Should get the correct sort when sorting by ascending creation date', async function () { | |
98 | const res = await getSortedBlacklistedVideosList(servers[0].url, servers[0].accessToken, 'createdAt') | |
99 | expect(res.body.total).to.equal(2) | |
100 | ||
101 | const videos = res.body.data | |
102 | expect(videos).to.be.an('array') | |
103 | expect(videos.length).to.equal(2) | |
104 | ||
105 | const result = orderBy(res.body.data, [ 'createdAt' ]) | |
106 | ||
107 | expect(videos).to.deep.equal(result) | |
108 | }) | |
109 | }) | |
110 | ||
111 | describe('When removing a blacklisted video', function () { | |
112 | let videoToRemove | |
113 | let blacklist = [] | |
114 | ||
975e6e0e | 115 | it('Should not have any video in videos list on server 1', async function () { |
792dbaf0 GS |
116 | const res = await getVideosList(servers[0].url) |
117 | expect(res.body.total).to.equal(0) | |
118 | expect(res.body.data).to.be.an('array') | |
119 | expect(res.body.data.length).to.equal(0) | |
120 | }) | |
121 | ||
975e6e0e | 122 | it('Should remove a video from the blacklist on server 1', async function () { |
792dbaf0 GS |
123 | // Get one video in the blacklist |
124 | const res = await getSortedBlacklistedVideosList(servers[0].url, servers[0].accessToken, '-name') | |
125 | videoToRemove = res.body.data[0] | |
126 | blacklist = res.body.data.slice(1) | |
127 | ||
128 | // Remove it | |
129 | await removeVideoFromBlacklist(servers[0].url, servers[0].accessToken, videoToRemove.videoId) | |
130 | }) | |
131 | ||
975e6e0e | 132 | it('Should have the ex-blacklisted video in videos list on server 1', async function () { |
792dbaf0 GS |
133 | const res = await getVideosList(servers[0].url) |
134 | expect(res.body.total).to.equal(1) | |
135 | ||
136 | const videos = res.body.data | |
137 | expect(videos).to.be.an('array') | |
138 | expect(videos.length).to.equal(1) | |
139 | ||
140 | expect(videos[0].name).to.equal(videoToRemove.name) | |
141 | expect(videos[0].id).to.equal(videoToRemove.videoId) | |
142 | }) | |
143 | ||
975e6e0e | 144 | it('Should not have the ex-blacklisted video in videos blacklist list on server 1', async function () { |
792dbaf0 GS |
145 | const res = await getSortedBlacklistedVideosList(servers[0].url, servers[0].accessToken, '-name') |
146 | expect(res.body.total).to.equal(1) | |
147 | ||
148 | const videos = res.body.data | |
149 | expect(videos).to.be.an('array') | |
150 | expect(videos.length).to.equal(1) | |
151 | expect(videos).to.deep.equal(blacklist) | |
152 | }) | |
153 | }) | |
154 | ||
155 | after(async function () { | |
156 | killallServers(servers) | |
157 | ||
158 | if (this['ok']) { | |
159 | await flushTests() | |
160 | } | |
161 | }) | |
162 | }) |