]>
Commit | Line | Data |
---|---|---|
792dbaf0 GS |
1 | /* tslint:disable:no-unused-expression */ |
2 | ||
3 | import 'mocha' | |
792dbaf0 GS |
4 | |
5 | import { | |
26b7305a C |
6 | createUser, |
7 | flushTests, | |
e5e7f7fe | 8 | getBlacklistedVideosList, getVideo, getVideoWithToken, |
26b7305a C |
9 | killallServers, |
10 | makePostBodyRequest, | |
11 | makePutBodyRequest, | |
12 | removeVideoFromBlacklist, | |
13 | runServer, | |
14 | ServerInfo, | |
15 | setAccessTokensToServers, | |
16 | uploadVideo, | |
17 | userLogin | |
792dbaf0 | 18 | } from '../../utils' |
11ba2ab3 | 19 | import { checkBadCountPagination, checkBadSortPagination, checkBadStartPagination } from '../../utils/requests/check-api-params' |
e5e7f7fe C |
20 | import { VideoDetails } from '../../../../shared/models/videos' |
21 | import { expect } from 'chai' | |
792dbaf0 GS |
22 | |
23 | describe('Test video blacklist API validators', function () { | |
24 | let server: ServerInfo | |
26b7305a | 25 | let notBlacklistedVideoId: number |
e5e7f7fe C |
26 | let userAccessToken1 = '' |
27 | let userAccessToken2 = '' | |
792dbaf0 GS |
28 | |
29 | // --------------------------------------------------------------- | |
30 | ||
31 | before(async function () { | |
32 | this.timeout(120000) | |
33 | ||
34 | await flushTests() | |
35 | ||
36 | server = await runServer(1) | |
37 | ||
38 | await setAccessTokensToServers([ server ]) | |
39 | ||
e5e7f7fe C |
40 | { |
41 | const username = 'user1' | |
42 | const password = 'my super password' | |
43 | await createUser(server.url, server.accessToken, username, password) | |
44 | userAccessToken1 = await userLogin(server, { username, password }) | |
45 | } | |
792dbaf0 | 46 | |
26b7305a | 47 | { |
e5e7f7fe C |
48 | const username = 'user2' |
49 | const password = 'my super password' | |
50 | await createUser(server.url, server.accessToken, username, password) | |
51 | userAccessToken2 = await userLogin(server, { username, password }) | |
52 | } | |
53 | ||
54 | { | |
55 | const res = await uploadVideo(server.url, userAccessToken1, {}) | |
26b7305a C |
56 | server.video = res.body.video |
57 | } | |
58 | ||
59 | { | |
60 | const res = await uploadVideo(server.url, server.accessToken, {}) | |
61 | notBlacklistedVideoId = res.body.video.uuid | |
62 | } | |
792dbaf0 GS |
63 | }) |
64 | ||
65 | describe('When adding a video in blacklist', function () { | |
66 | const basePath = '/api/v1/videos/' | |
67 | ||
68 | it('Should fail with nothing', async function () { | |
69 | const path = basePath + server.video + '/blacklist' | |
70 | const fields = {} | |
71 | await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields }) | |
72 | }) | |
73 | ||
74 | it('Should fail with a wrong video', async function () { | |
75 | const wrongPath = '/api/v1/videos/blabla/blacklist' | |
76 | const fields = {} | |
77 | await makePostBodyRequest({ url: server.url, path: wrongPath, token: server.accessToken, fields }) | |
78 | }) | |
79 | ||
80 | it('Should fail with a non authenticated user', async function () { | |
792dbaf0 | 81 | const path = basePath + server.video + '/blacklist' |
11ba2ab3 | 82 | const fields = {} |
792dbaf0 GS |
83 | await makePostBodyRequest({ url: server.url, path, token: 'hello', fields, statusCodeExpected: 401 }) |
84 | }) | |
85 | ||
86 | it('Should fail with a non admin user', async function () { | |
792dbaf0 | 87 | const path = basePath + server.video + '/blacklist' |
11ba2ab3 | 88 | const fields = {} |
e5e7f7fe | 89 | await makePostBodyRequest({ url: server.url, path, token: userAccessToken2, fields, statusCodeExpected: 403 }) |
792dbaf0 GS |
90 | }) |
91 | ||
26b7305a C |
92 | it('Should fail with an invalid reason', async function () { |
93 | const path = basePath + server.video.uuid + '/blacklist' | |
94 | const fields = { reason: 'a'.repeat(305) } | |
95 | ||
96 | await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields }) | |
97 | }) | |
98 | ||
99 | it('Should succeed with the correct params', async function () { | |
100 | const path = basePath + server.video.uuid + '/blacklist' | |
101 | const fields = { } | |
102 | ||
103 | await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields, statusCodeExpected: 204 }) | |
104 | }) | |
105 | }) | |
106 | ||
107 | describe('When updating a video in blacklist', function () { | |
108 | const basePath = '/api/v1/videos/' | |
109 | ||
110 | it('Should fail with a wrong video', async function () { | |
111 | const wrongPath = '/api/v1/videos/blabla/blacklist' | |
112 | const fields = {} | |
113 | await makePutBodyRequest({ url: server.url, path: wrongPath, token: server.accessToken, fields }) | |
114 | }) | |
115 | ||
116 | it('Should fail with a video not blacklisted', async function () { | |
117 | const path = '/api/v1/videos/' + notBlacklistedVideoId + '/blacklist' | |
118 | const fields = {} | |
119 | await makePutBodyRequest({ url: server.url, path, token: server.accessToken, fields, statusCodeExpected: 404 }) | |
120 | }) | |
121 | ||
122 | it('Should fail with a non authenticated user', async function () { | |
123 | const path = basePath + server.video + '/blacklist' | |
124 | const fields = {} | |
125 | await makePutBodyRequest({ url: server.url, path, token: 'hello', fields, statusCodeExpected: 401 }) | |
126 | }) | |
127 | ||
128 | it('Should fail with a non admin user', async function () { | |
129 | const path = basePath + server.video + '/blacklist' | |
11ba2ab3 | 130 | const fields = {} |
e5e7f7fe | 131 | await makePutBodyRequest({ url: server.url, path, token: userAccessToken2, fields, statusCodeExpected: 403 }) |
26b7305a C |
132 | }) |
133 | ||
134 | it('Should fail with an invalid reason', async function () { | |
135 | const path = basePath + server.video.uuid + '/blacklist' | |
136 | const fields = { reason: 'a'.repeat(305) } | |
137 | ||
138 | await makePutBodyRequest({ url: server.url, path, token: server.accessToken, fields }) | |
139 | }) | |
140 | ||
141 | it('Should succeed with the correct params', async function () { | |
142 | const path = basePath + server.video.uuid + '/blacklist' | |
143 | const fields = { reason: 'hello' } | |
144 | ||
145 | await makePutBodyRequest({ url: server.url, path, token: server.accessToken, fields, statusCodeExpected: 204 }) | |
792dbaf0 GS |
146 | }) |
147 | }) | |
148 | ||
e5e7f7fe C |
149 | describe('When getting blacklisted video', function () { |
150 | ||
151 | it('Should fail with a non authenticated user', async function () { | |
152 | await getVideo(server.url, server.video.uuid, 401) | |
153 | }) | |
154 | ||
155 | it('Should fail with another user', async function () { | |
156 | await getVideoWithToken(server.url, userAccessToken2, server.video.uuid, 403) | |
157 | }) | |
158 | ||
159 | it('Should succeed with the owner authenticated user', async function () { | |
160 | const res = await getVideoWithToken(server.url, userAccessToken1, server.video.uuid, 200) | |
161 | const video: VideoDetails = res.body | |
162 | ||
163 | expect(video.blacklisted).to.be.true | |
164 | }) | |
165 | ||
166 | it('Should succeed with an admin', async function () { | |
167 | const res = await getVideoWithToken(server.url, server.accessToken, server.video.uuid, 200) | |
168 | const video: VideoDetails = res.body | |
169 | ||
170 | expect(video.blacklisted).to.be.true | |
171 | }) | |
172 | }) | |
173 | ||
792dbaf0 | 174 | describe('When removing a video in blacklist', function () { |
792dbaf0 | 175 | it('Should fail with a non authenticated user', async function () { |
26b7305a | 176 | await removeVideoFromBlacklist(server.url, 'fake token', server.video.uuid, 401) |
792dbaf0 GS |
177 | }) |
178 | ||
179 | it('Should fail with a non admin user', async function () { | |
e5e7f7fe | 180 | await removeVideoFromBlacklist(server.url, userAccessToken2, server.video.uuid, 403) |
792dbaf0 GS |
181 | }) |
182 | ||
183 | it('Should fail with an incorrect id', async function () { | |
11ba2ab3 | 184 | await removeVideoFromBlacklist(server.url, server.accessToken, 'hello', 400) |
792dbaf0 GS |
185 | }) |
186 | ||
187 | it('Should fail with a not blacklisted video', async function () { | |
188 | // The video was not added to the blacklist so it should fail | |
26b7305a C |
189 | await removeVideoFromBlacklist(server.url, server.accessToken, notBlacklistedVideoId, 404) |
190 | }) | |
191 | ||
192 | it('Should succeed with the correct params', async function () { | |
193 | await removeVideoFromBlacklist(server.url, server.accessToken, server.video.uuid, 204) | |
792dbaf0 GS |
194 | }) |
195 | }) | |
196 | ||
197 | describe('When listing videos in blacklist', function () { | |
35bf0c83 | 198 | const basePath = '/api/v1/videos/blacklist/' |
792dbaf0 GS |
199 | |
200 | it('Should fail with a non authenticated user', async function () { | |
11ba2ab3 | 201 | await getBlacklistedVideosList(server.url, 'fake token', 401) |
792dbaf0 GS |
202 | }) |
203 | ||
204 | it('Should fail with a non admin user', async function () { | |
e5e7f7fe | 205 | await getBlacklistedVideosList(server.url, userAccessToken2, 403) |
792dbaf0 GS |
206 | }) |
207 | ||
208 | it('Should fail with a bad start pagination', async function () { | |
11ba2ab3 | 209 | await checkBadStartPagination(server.url, basePath, server.accessToken) |
792dbaf0 GS |
210 | }) |
211 | ||
212 | it('Should fail with a bad count pagination', async function () { | |
11ba2ab3 | 213 | await checkBadCountPagination(server.url, basePath, server.accessToken) |
792dbaf0 GS |
214 | }) |
215 | ||
216 | it('Should fail with an incorrect sort', async function () { | |
11ba2ab3 | 217 | await checkBadSortPagination(server.url, basePath, server.accessToken) |
792dbaf0 GS |
218 | }) |
219 | }) | |
220 | ||
221 | after(async function () { | |
222 | killallServers([ server ]) | |
223 | ||
224 | // Keep the logs if the test failed | |
225 | if (this['ok']) { | |
226 | await flushTests() | |
227 | } | |
228 | }) | |
229 | }) |