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