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