]>
Commit | Line | Data |
---|---|---|
a1587156 | 1 | /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */ |
5d08a6a7 | 2 | |
5d08a6a7 | 3 | import 'mocha' |
b488ba1e | 4 | import { omit } from 'lodash' |
5d08a6a7 | 5 | import { join } from 'path' |
5d08a6a7 | 6 | import { |
7c3b7976 | 7 | cleanupTests, |
5d08a6a7 | 8 | createUser, |
7c3b7976 | 9 | flushAndRunServer, |
5d08a6a7 C |
10 | getMyUserInformation, |
11 | immutableAssign, | |
5d08a6a7 C |
12 | makeGetRequest, |
13 | makePostBodyRequest, | |
14 | makeUploadRequest, | |
5d08a6a7 C |
15 | ServerInfo, |
16 | setAccessTokensToServers, | |
590fb506 | 17 | updateCustomSubConfig, |
5d08a6a7 | 18 | userLogin |
94565d52 | 19 | } from '../../../../shared/extra-utils' |
9639bd17 | 20 | import { |
21 | checkBadCountPagination, | |
22 | checkBadSortPagination, | |
23 | checkBadStartPagination | |
94565d52 | 24 | } from '../../../../shared/extra-utils/requests/check-api-params' |
b488ba1e C |
25 | import { getMagnetURI, getGoodVideoUrl } from '../../../../shared/extra-utils/videos/video-imports' |
26 | import { VideoPrivacy } from '../../../../shared/models/videos/video-privacy.enum' | |
5d08a6a7 C |
27 | |
28 | describe('Test video imports API validator', function () { | |
29 | const path = '/api/v1/videos/imports' | |
30 | let server: ServerInfo | |
31 | let userAccessToken = '' | |
5d08a6a7 | 32 | let channelId: number |
5d08a6a7 C |
33 | |
34 | // --------------------------------------------------------------- | |
35 | ||
36 | before(async function () { | |
37 | this.timeout(30000) | |
38 | ||
210feb6c | 39 | server = await flushAndRunServer(1) |
5d08a6a7 C |
40 | |
41 | await setAccessTokensToServers([ server ]) | |
42 | ||
43 | const username = 'user1' | |
44 | const password = 'my super password' | |
1eddc9a7 | 45 | await createUser({ url: server.url, accessToken: server.accessToken, username: username, password: password }) |
5d08a6a7 C |
46 | userAccessToken = await userLogin(server, { username, password }) |
47 | ||
48 | { | |
49 | const res = await getMyUserInformation(server.url, server.accessToken) | |
a1587156 | 50 | channelId = res.body.videoChannels[0].id |
5d08a6a7 C |
51 | } |
52 | }) | |
53 | ||
54 | describe('When listing my video imports', function () { | |
55 | const myPath = '/api/v1/users/me/videos/imports' | |
56 | ||
57 | it('Should fail with a bad start pagination', async function () { | |
58 | await checkBadStartPagination(server.url, myPath, server.accessToken) | |
59 | }) | |
60 | ||
61 | it('Should fail with a bad count pagination', async function () { | |
62 | await checkBadCountPagination(server.url, myPath, server.accessToken) | |
63 | }) | |
64 | ||
65 | it('Should fail with an incorrect sort', async function () { | |
66 | await checkBadSortPagination(server.url, myPath, server.accessToken) | |
67 | }) | |
68 | ||
69 | it('Should success with the correct parameters', async function () { | |
70 | await makeGetRequest({ url: server.url, path: myPath, statusCodeExpected: 200, token: server.accessToken }) | |
71 | }) | |
72 | }) | |
73 | ||
74 | describe('When adding a video import', function () { | |
75 | let baseCorrectParams | |
76 | ||
77 | before(function () { | |
78 | baseCorrectParams = { | |
b488ba1e | 79 | targetUrl: getGoodVideoUrl(), |
5d08a6a7 C |
80 | name: 'my super name', |
81 | category: 5, | |
82 | licence: 1, | |
83 | language: 'pt', | |
84 | nsfw: false, | |
85 | commentsEnabled: true, | |
7f2cfe3a | 86 | downloadEnabled: true, |
5d08a6a7 C |
87 | waitTranscoding: true, |
88 | description: 'my super description', | |
89 | support: 'my super support text', | |
90 | tags: [ 'tag1', 'tag2' ], | |
91 | privacy: VideoPrivacy.PUBLIC, | |
c8861d5d | 92 | channelId |
5d08a6a7 C |
93 | } |
94 | }) | |
95 | ||
96 | it('Should fail with nothing', async function () { | |
97 | const fields = {} | |
98 | await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields }) | |
99 | }) | |
100 | ||
590fb506 C |
101 | it('Should fail without a target url', async function () { |
102 | const fields = omit(baseCorrectParams, 'targetUrl') | |
103 | await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields, statusCodeExpected: 400 }) | |
104 | }) | |
105 | ||
106 | it('Should fail with a bad target url', async function () { | |
107 | const fields = immutableAssign(baseCorrectParams, { targetUrl: 'htt://hello' }) | |
108 | ||
109 | await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields }) | |
110 | }) | |
111 | ||
5d08a6a7 C |
112 | it('Should fail with a long name', async function () { |
113 | const fields = immutableAssign(baseCorrectParams, { name: 'super'.repeat(65) }) | |
114 | ||
115 | await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields }) | |
116 | }) | |
117 | ||
118 | it('Should fail with a bad category', async function () { | |
119 | const fields = immutableAssign(baseCorrectParams, { category: 125 }) | |
120 | ||
121 | await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields }) | |
122 | }) | |
123 | ||
124 | it('Should fail with a bad licence', async function () { | |
125 | const fields = immutableAssign(baseCorrectParams, { licence: 125 }) | |
126 | ||
127 | await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields }) | |
128 | }) | |
129 | ||
130 | it('Should fail with a bad language', async function () { | |
131 | const fields = immutableAssign(baseCorrectParams, { language: 'a'.repeat(15) }) | |
132 | ||
133 | await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields }) | |
134 | }) | |
135 | ||
136 | it('Should fail with a long description', async function () { | |
137 | const fields = immutableAssign(baseCorrectParams, { description: 'super'.repeat(2500) }) | |
138 | ||
139 | await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields }) | |
140 | }) | |
141 | ||
142 | it('Should fail with a long support text', async function () { | |
d23e6a1c | 143 | const fields = immutableAssign(baseCorrectParams, { support: 'super'.repeat(201) }) |
5d08a6a7 C |
144 | |
145 | await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields }) | |
146 | }) | |
147 | ||
148 | it('Should fail without a channel', async function () { | |
149 | const fields = omit(baseCorrectParams, 'channelId') | |
150 | ||
151 | await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields }) | |
152 | }) | |
153 | ||
154 | it('Should fail with a bad channel', async function () { | |
155 | const fields = immutableAssign(baseCorrectParams, { channelId: 545454 }) | |
156 | ||
157 | await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields }) | |
158 | }) | |
159 | ||
160 | it('Should fail with another user channel', async function () { | |
161 | const user = { | |
162 | username: 'fake', | |
163 | password: 'fake_password' | |
164 | } | |
1eddc9a7 | 165 | await createUser({ url: server.url, accessToken: server.accessToken, username: user.username, password: user.password }) |
5d08a6a7 C |
166 | |
167 | const accessTokenUser = await userLogin(server, user) | |
168 | const res = await getMyUserInformation(server.url, accessTokenUser) | |
169 | const customChannelId = res.body.videoChannels[0].id | |
170 | ||
171 | const fields = immutableAssign(baseCorrectParams, { channelId: customChannelId }) | |
172 | ||
173 | await makePostBodyRequest({ url: server.url, path, token: userAccessToken, fields }) | |
174 | }) | |
175 | ||
176 | it('Should fail with too many tags', async function () { | |
177 | const fields = immutableAssign(baseCorrectParams, { tags: [ 'tag1', 'tag2', 'tag3', 'tag4', 'tag5', 'tag6' ] }) | |
178 | ||
179 | await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields }) | |
180 | }) | |
181 | ||
182 | it('Should fail with a tag length too low', async function () { | |
183 | const fields = immutableAssign(baseCorrectParams, { tags: [ 'tag1', 't' ] }) | |
184 | ||
185 | await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields }) | |
186 | }) | |
187 | ||
188 | it('Should fail with a tag length too big', async function () { | |
189 | const fields = immutableAssign(baseCorrectParams, { tags: [ 'tag1', 'my_super_tag_too_long_long_long_long_long_long' ] }) | |
190 | ||
191 | await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields }) | |
192 | }) | |
193 | ||
194 | it('Should fail with an incorrect thumbnail file', async function () { | |
195 | const fields = baseCorrectParams | |
196 | const attaches = { | |
a1587156 | 197 | thumbnailfile: join(__dirname, '..', '..', 'fixtures', 'avatar.png') |
5d08a6a7 C |
198 | } |
199 | ||
200 | await makeUploadRequest({ url: server.url, path, token: server.accessToken, fields, attaches }) | |
201 | }) | |
202 | ||
203 | it('Should fail with a big thumbnail file', async function () { | |
204 | const fields = baseCorrectParams | |
205 | const attaches = { | |
a1587156 | 206 | thumbnailfile: join(__dirname, '..', '..', 'fixtures', 'avatar-big.png') |
5d08a6a7 C |
207 | } |
208 | ||
209 | await makeUploadRequest({ url: server.url, path, token: server.accessToken, fields, attaches }) | |
210 | }) | |
211 | ||
212 | it('Should fail with an incorrect preview file', async function () { | |
213 | const fields = baseCorrectParams | |
214 | const attaches = { | |
a1587156 | 215 | previewfile: join(__dirname, '..', '..', 'fixtures', 'avatar.png') |
5d08a6a7 C |
216 | } |
217 | ||
218 | await makeUploadRequest({ url: server.url, path, token: server.accessToken, fields, attaches }) | |
219 | }) | |
220 | ||
221 | it('Should fail with a big preview file', async function () { | |
222 | const fields = baseCorrectParams | |
223 | const attaches = { | |
a1587156 | 224 | previewfile: join(__dirname, '..', '..', 'fixtures', 'avatar-big.png') |
5d08a6a7 C |
225 | } |
226 | ||
227 | await makeUploadRequest({ url: server.url, path, token: server.accessToken, fields, attaches }) | |
228 | }) | |
229 | ||
187501f8 C |
230 | it('Should fail with an invalid torrent file', async function () { |
231 | const fields = omit(baseCorrectParams, 'targetUrl') | |
232 | const attaches = { | |
a1587156 | 233 | torrentfile: join(__dirname, '..', '..', 'fixtures', 'avatar-big.png') |
187501f8 C |
234 | } |
235 | ||
236 | await makeUploadRequest({ url: server.url, path, token: server.accessToken, fields, attaches }) | |
237 | }) | |
238 | ||
239 | it('Should fail with an invalid magnet URI', async function () { | |
240 | let fields = omit(baseCorrectParams, 'targetUrl') | |
241 | fields = immutableAssign(fields, { magnetUri: 'blabla' }) | |
242 | ||
243 | await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields }) | |
244 | }) | |
245 | ||
5d08a6a7 | 246 | it('Should succeed with the correct parameters', async function () { |
13b6dc1f | 247 | this.timeout(30000) |
5d08a6a7 | 248 | |
b488ba1e C |
249 | await makePostBodyRequest({ |
250 | url: server.url, | |
251 | path, | |
252 | token: server.accessToken, | |
253 | fields: baseCorrectParams, | |
254 | statusCodeExpected: 200 | |
255 | }) | |
5d08a6a7 C |
256 | }) |
257 | ||
187501f8 | 258 | it('Should forbid to import http videos', async function () { |
590fb506 C |
259 | await updateCustomSubConfig(server.url, server.accessToken, { |
260 | import: { | |
261 | videos: { | |
262 | http: { | |
263 | enabled: false | |
187501f8 C |
264 | }, |
265 | torrent: { | |
266 | enabled: true | |
590fb506 C |
267 | } |
268 | } | |
269 | } | |
270 | }) | |
271 | ||
272 | await makePostBodyRequest({ | |
273 | url: server.url, | |
274 | path, | |
275 | token: server.accessToken, | |
276 | fields: baseCorrectParams, | |
277 | statusCodeExpected: 409 | |
278 | }) | |
279 | }) | |
187501f8 C |
280 | |
281 | it('Should forbid to import torrent videos', async function () { | |
282 | await updateCustomSubConfig(server.url, server.accessToken, { | |
283 | import: { | |
284 | videos: { | |
285 | http: { | |
286 | enabled: true | |
287 | }, | |
288 | torrent: { | |
289 | enabled: false | |
290 | } | |
291 | } | |
292 | } | |
293 | }) | |
294 | ||
295 | let fields = omit(baseCorrectParams, 'targetUrl') | |
296 | fields = immutableAssign(fields, { magnetUri: getMagnetURI() }) | |
297 | ||
298 | await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields, statusCodeExpected: 409 }) | |
299 | ||
300 | fields = omit(fields, 'magnetUri') | |
301 | const attaches = { | |
a1587156 | 302 | torrentfile: join(__dirname, '..', '..', 'fixtures', 'video-720p.torrent') |
187501f8 C |
303 | } |
304 | ||
305 | await makeUploadRequest({ url: server.url, path, token: server.accessToken, fields, attaches, statusCodeExpected: 409 }) | |
306 | }) | |
5d08a6a7 C |
307 | }) |
308 | ||
7c3b7976 C |
309 | after(async function () { |
310 | await cleanupTests([ server ]) | |
5d08a6a7 C |
311 | }) |
312 | }) |