]>
Commit | Line | Data |
---|---|---|
a20399c9 C |
1 | /* tslint:disable:no-unused-expression */ |
2 | ||
3 | import { expect } from 'chai' | |
df0b219d | 4 | import { pathExists, readdir, readFile } from 'fs-extra' |
fdbda9e3 | 5 | import * as parseTorrent from 'parse-torrent' |
1d791a26 | 6 | import { extname, join } from 'path' |
c5d31dba | 7 | import * as request from 'supertest' |
ac81d1a0 C |
8 | import { |
9 | buildAbsoluteFixturePath, | |
62689b94 C |
10 | getMyUserInformation, |
11 | immutableAssign, | |
ac81d1a0 C |
12 | makeGetRequest, |
13 | makePutBodyRequest, | |
14 | makeUploadRequest, | |
15 | root, | |
16 | ServerInfo, | |
17 | testImage | |
18 | } from '../' | |
df0b219d | 19 | import * as validator from 'validator' |
d4681c00 | 20 | import { VideoDetails, VideoPrivacy } from '../../models/videos' |
8f0bc73d | 21 | import { VIDEO_CATEGORIES, VIDEO_LANGUAGES, loadLanguages, VIDEO_LICENCES, VIDEO_PRIVACIES } from '../../../server/initializers/constants' |
e2600d8b | 22 | import { dateIsValid, webtorrentAdd, buildServerDirectory } from '../miscs/miscs' |
0e1dc3e7 | 23 | |
8f0bc73d C |
24 | loadLanguages() |
25 | ||
0e1dc3e7 C |
26 | type VideoAttributes = { |
27 | name?: string | |
28 | category?: number | |
29 | licence?: number | |
9d3ef9fe | 30 | language?: string |
0e1dc3e7 | 31 | nsfw?: boolean |
47564bbe | 32 | commentsEnabled?: boolean |
7f2cfe3a | 33 | downloadEnabled?: boolean |
2186386c | 34 | waitTranscoding?: boolean |
0e1dc3e7 | 35 | description?: string |
7519127b | 36 | originallyPublishedAt?: string |
0e1dc3e7 | 37 | tags?: string[] |
5f04dd2f | 38 | channelId?: number |
11474c3c | 39 | privacy?: VideoPrivacy |
0e1dc3e7 | 40 | fixture?: string |
ac81d1a0 C |
41 | thumbnailfile?: string |
42 | previewfile?: string | |
2baea0c7 C |
43 | scheduleUpdate?: { |
44 | updateAt: string | |
45 | privacy?: VideoPrivacy | |
46 | } | |
0e1dc3e7 C |
47 | } |
48 | ||
49 | function getVideoCategories (url: string) { | |
50 | const path = '/api/v1/videos/categories' | |
51 | ||
eec63bbc C |
52 | return makeGetRequest({ |
53 | url, | |
59651eee C |
54 | path, |
55 | statusCodeExpected: 200 | |
eec63bbc | 56 | }) |
0e1dc3e7 C |
57 | } |
58 | ||
59 | function getVideoLicences (url: string) { | |
60 | const path = '/api/v1/videos/licences' | |
61 | ||
eec63bbc C |
62 | return makeGetRequest({ |
63 | url, | |
59651eee C |
64 | path, |
65 | statusCodeExpected: 200 | |
eec63bbc | 66 | }) |
0e1dc3e7 C |
67 | } |
68 | ||
69 | function getVideoLanguages (url: string) { | |
70 | const path = '/api/v1/videos/languages' | |
71 | ||
eec63bbc C |
72 | return makeGetRequest({ |
73 | url, | |
59651eee C |
74 | path, |
75 | statusCodeExpected: 200 | |
eec63bbc | 76 | }) |
0e1dc3e7 C |
77 | } |
78 | ||
11474c3c C |
79 | function getVideoPrivacies (url: string) { |
80 | const path = '/api/v1/videos/privacies' | |
81 | ||
eec63bbc C |
82 | return makeGetRequest({ |
83 | url, | |
59651eee C |
84 | path, |
85 | statusCodeExpected: 200 | |
eec63bbc | 86 | }) |
11474c3c C |
87 | } |
88 | ||
11474c3c | 89 | function getVideo (url: string, id: number | string, expectedStatus = 200) { |
0e1dc3e7 C |
90 | const path = '/api/v1/videos/' + id |
91 | ||
92 | return request(url) | |
93 | .get(path) | |
94 | .set('Accept', 'application/json') | |
11474c3c C |
95 | .expect(expectedStatus) |
96 | } | |
97 | ||
490b595a | 98 | function viewVideo (url: string, id: number | string, expectedStatus = 204, xForwardedFor?: string) { |
1f3e9fec C |
99 | const path = '/api/v1/videos/' + id + '/views' |
100 | ||
490b595a | 101 | const req = request(url) |
1f3e9fec C |
102 | .post(path) |
103 | .set('Accept', 'application/json') | |
490b595a C |
104 | |
105 | if (xForwardedFor) { | |
106 | req.set('X-Forwarded-For', xForwardedFor) | |
107 | } | |
108 | ||
109 | return req.expect(expectedStatus) | |
1f3e9fec C |
110 | } |
111 | ||
11474c3c C |
112 | function getVideoWithToken (url: string, token: string, id: number | string, expectedStatus = 200) { |
113 | const path = '/api/v1/videos/' + id | |
114 | ||
115 | return request(url) | |
116 | .get(path) | |
117 | .set('Authorization', 'Bearer ' + token) | |
118 | .set('Accept', 'application/json') | |
119 | .expect(expectedStatus) | |
0e1dc3e7 C |
120 | } |
121 | ||
9567011b C |
122 | function getVideoDescription (url: string, descriptionPath: string) { |
123 | return request(url) | |
124 | .get(descriptionPath) | |
125 | .set('Accept', 'application/json') | |
126 | .expect(200) | |
127 | .expect('Content-Type', /json/) | |
128 | } | |
129 | ||
0e1dc3e7 C |
130 | function getVideosList (url: string) { |
131 | const path = '/api/v1/videos' | |
132 | ||
133 | return request(url) | |
134 | .get(path) | |
135 | .query({ sort: 'name' }) | |
136 | .set('Accept', 'application/json') | |
137 | .expect(200) | |
138 | .expect('Content-Type', /json/) | |
139 | } | |
140 | ||
d525fc39 | 141 | function getVideosListWithToken (url: string, token: string, query: { nsfw?: boolean } = {}) { |
0883b324 C |
142 | const path = '/api/v1/videos' |
143 | ||
144 | return request(url) | |
145 | .get(path) | |
146 | .set('Authorization', 'Bearer ' + token) | |
d525fc39 | 147 | .query(immutableAssign(query, { sort: 'name' })) |
0883b324 C |
148 | .set('Accept', 'application/json') |
149 | .expect(200) | |
150 | .expect('Content-Type', /json/) | |
151 | } | |
152 | ||
066e94c5 C |
153 | function getLocalVideos (url: string) { |
154 | const path = '/api/v1/videos' | |
155 | ||
156 | return request(url) | |
157 | .get(path) | |
158 | .query({ sort: 'name', filter: 'local' }) | |
159 | .set('Accept', 'application/json') | |
160 | .expect(200) | |
161 | .expect('Content-Type', /json/) | |
162 | } | |
163 | ||
cca1e13b | 164 | function getMyVideos (url: string, accessToken: string, start: number, count: number, sort?: string, search?: string) { |
11474c3c C |
165 | const path = '/api/v1/users/me/videos' |
166 | ||
167 | const req = request(url) | |
168 | .get(path) | |
169 | .query({ start: start }) | |
170 | .query({ count: count }) | |
cca1e13b | 171 | .query({ search: search }) |
11474c3c C |
172 | |
173 | if (sort) req.query({ sort }) | |
174 | ||
175 | return req.set('Accept', 'application/json') | |
176 | .set('Authorization', 'Bearer ' + accessToken) | |
177 | .expect(200) | |
178 | .expect('Content-Type', /json/) | |
179 | } | |
180 | ||
d525fc39 C |
181 | function getAccountVideos ( |
182 | url: string, | |
183 | accessToken: string, | |
184 | accountName: string, | |
185 | start: number, | |
186 | count: number, | |
187 | sort?: string, | |
188 | query: { nsfw?: boolean } = {} | |
189 | ) { | |
ad9e39fb | 190 | const path = '/api/v1/accounts/' + accountName + '/videos' |
6b738c7a C |
191 | |
192 | return makeGetRequest({ | |
193 | url, | |
194 | path, | |
d525fc39 | 195 | query: immutableAssign(query, { |
6b738c7a C |
196 | start, |
197 | count, | |
198 | sort | |
d525fc39 | 199 | }), |
6b738c7a C |
200 | token: accessToken, |
201 | statusCodeExpected: 200 | |
202 | }) | |
203 | } | |
204 | ||
205 | function getVideoChannelVideos ( | |
206 | url: string, | |
207 | accessToken: string, | |
8a19bee1 | 208 | videoChannelName: string, |
6b738c7a C |
209 | start: number, |
210 | count: number, | |
d525fc39 C |
211 | sort?: string, |
212 | query: { nsfw?: boolean } = {} | |
6b738c7a | 213 | ) { |
8a19bee1 | 214 | const path = '/api/v1/video-channels/' + videoChannelName + '/videos' |
6b738c7a C |
215 | |
216 | return makeGetRequest({ | |
217 | url, | |
218 | path, | |
d525fc39 | 219 | query: immutableAssign(query, { |
6b738c7a C |
220 | start, |
221 | count, | |
222 | sort | |
d525fc39 | 223 | }), |
6b738c7a C |
224 | token: accessToken, |
225 | statusCodeExpected: 200 | |
226 | }) | |
227 | } | |
228 | ||
418d092a C |
229 | function getPlaylistVideos ( |
230 | url: string, | |
231 | accessToken: string, | |
232 | playlistId: number | string, | |
233 | start: number, | |
234 | count: number, | |
235 | query: { nsfw?: boolean } = {} | |
236 | ) { | |
237 | const path = '/api/v1/video-playlists/' + playlistId + '/videos' | |
238 | ||
239 | return makeGetRequest({ | |
240 | url, | |
241 | path, | |
242 | query: immutableAssign(query, { | |
243 | start, | |
244 | count | |
245 | }), | |
246 | token: accessToken, | |
247 | statusCodeExpected: 200 | |
248 | }) | |
249 | } | |
250 | ||
0e1dc3e7 C |
251 | function getVideosListPagination (url: string, start: number, count: number, sort?: string) { |
252 | const path = '/api/v1/videos' | |
253 | ||
254 | const req = request(url) | |
255 | .get(path) | |
256 | .query({ start: start }) | |
257 | .query({ count: count }) | |
258 | ||
259 | if (sort) req.query({ sort }) | |
260 | ||
261 | return req.set('Accept', 'application/json') | |
262 | .expect(200) | |
263 | .expect('Content-Type', /json/) | |
264 | } | |
265 | ||
266 | function getVideosListSort (url: string, sort: string) { | |
267 | const path = '/api/v1/videos' | |
268 | ||
269 | return request(url) | |
270 | .get(path) | |
271 | .query({ sort: sort }) | |
272 | .set('Accept', 'application/json') | |
273 | .expect(200) | |
274 | .expect('Content-Type', /json/) | |
275 | } | |
276 | ||
d525fc39 | 277 | function getVideosWithFilters (url: string, query: { tagsAllOf: string[], categoryOneOf: number[] | number }) { |
0e1dc3e7 C |
278 | const path = '/api/v1/videos' |
279 | ||
280 | return request(url) | |
57c36b27 | 281 | .get(path) |
d525fc39 | 282 | .query(query) |
f3aaa9a9 | 283 | .set('Accept', 'application/json') |
d525fc39 | 284 | .expect(200) |
f3aaa9a9 | 285 | .expect('Content-Type', /json/) |
0e1dc3e7 C |
286 | } |
287 | ||
d525fc39 | 288 | function removeVideo (url: string, token: string, id: number | string, expectedStatus = 204) { |
0883b324 | 289 | const path = '/api/v1/videos' |
0e1dc3e7 C |
290 | |
291 | return request(url) | |
d525fc39 | 292 | .delete(path + '/' + id) |
0e1dc3e7 | 293 | .set('Accept', 'application/json') |
d525fc39 C |
294 | .set('Authorization', 'Bearer ' + token) |
295 | .expect(expectedStatus) | |
0e1dc3e7 C |
296 | } |
297 | ||
25378bc8 C |
298 | async function checkVideoFilesWereRemoved ( |
299 | videoUUID: string, | |
300 | serverNumber: number, | |
09209296 C |
301 | directories = [ |
302 | 'redundancy', | |
303 | 'videos', | |
304 | 'thumbnails', | |
305 | 'torrents', | |
306 | 'previews', | |
307 | 'captions', | |
308 | join('playlists', 'hls'), | |
309 | join('redundancy', 'hls') | |
310 | ] | |
25378bc8 | 311 | ) { |
25378bc8 | 312 | for (const directory of directories) { |
e2600d8b | 313 | const directoryPath = buildServerDirectory(serverNumber, directory) |
f05a1c30 | 314 | |
df0b219d C |
315 | const directoryExists = await pathExists(directoryPath) |
316 | if (directoryExists === false) continue | |
f05a1c30 | 317 | |
62689b94 | 318 | const files = await readdir(directoryPath) |
f05a1c30 C |
319 | for (const file of files) { |
320 | expect(file).to.not.contain(videoUUID) | |
321 | } | |
322 | } | |
323 | } | |
324 | ||
e11f68a3 | 325 | async function uploadVideo (url: string, accessToken: string, videoAttributesArg: VideoAttributes, specialStatus = 200) { |
e95561cd | 326 | const path = '/api/v1/videos/upload' |
5f04dd2f C |
327 | let defaultChannelId = '1' |
328 | ||
329 | try { | |
330 | const res = await getMyUserInformation(url, accessToken) | |
331 | defaultChannelId = res.body.videoChannels[0].id | |
332 | } catch (e) { /* empty */ } | |
0e1dc3e7 | 333 | |
ac81d1a0 C |
334 | // Override default attributes |
335 | const attributes = Object.assign({ | |
0e1dc3e7 C |
336 | name: 'my super video', |
337 | category: 5, | |
338 | licence: 4, | |
9d3ef9fe | 339 | language: 'zh', |
5f04dd2f | 340 | channelId: defaultChannelId, |
0e1dc3e7 | 341 | nsfw: true, |
2186386c | 342 | waitTranscoding: false, |
0e1dc3e7 | 343 | description: 'my super description', |
2422c46b | 344 | support: 'my super support text', |
0e1dc3e7 | 345 | tags: [ 'tag' ], |
11474c3c | 346 | privacy: VideoPrivacy.PUBLIC, |
47564bbe | 347 | commentsEnabled: true, |
7f2cfe3a | 348 | downloadEnabled: true, |
0e1dc3e7 | 349 | fixture: 'video_short.webm' |
ac81d1a0 | 350 | }, videoAttributesArg) |
0e1dc3e7 C |
351 | |
352 | const req = request(url) | |
353 | .post(path) | |
354 | .set('Accept', 'application/json') | |
355 | .set('Authorization', 'Bearer ' + accessToken) | |
356 | .field('name', attributes.name) | |
0e1dc3e7 | 357 | .field('nsfw', JSON.stringify(attributes.nsfw)) |
47564bbe | 358 | .field('commentsEnabled', JSON.stringify(attributes.commentsEnabled)) |
7f2cfe3a | 359 | .field('downloadEnabled', JSON.stringify(attributes.downloadEnabled)) |
2186386c | 360 | .field('waitTranscoding', JSON.stringify(attributes.waitTranscoding)) |
11474c3c | 361 | .field('privacy', attributes.privacy.toString()) |
5f04dd2f | 362 | .field('channelId', attributes.channelId) |
0e1dc3e7 | 363 | |
fc8c024a C |
364 | if (attributes.support !== undefined) { |
365 | req.field('support', attributes.support) | |
366 | } | |
367 | ||
a87d467a C |
368 | if (attributes.description !== undefined) { |
369 | req.field('description', attributes.description) | |
370 | } | |
8df87ce7 C |
371 | if (attributes.language !== undefined) { |
372 | req.field('language', attributes.language.toString()) | |
373 | } | |
a7fea183 C |
374 | if (attributes.category !== undefined) { |
375 | req.field('category', attributes.category.toString()) | |
376 | } | |
377 | if (attributes.licence !== undefined) { | |
378 | req.field('licence', attributes.licence.toString()) | |
379 | } | |
8df87ce7 | 380 | |
970ceac0 C |
381 | const tags = attributes.tags || [] |
382 | for (let i = 0; i < tags.length; i++) { | |
2422c46b C |
383 | req.field('tags[' + i + ']', attributes.tags[i]) |
384 | } | |
385 | ||
ac81d1a0 C |
386 | if (attributes.thumbnailfile !== undefined) { |
387 | req.attach('thumbnailfile', buildAbsoluteFixturePath(attributes.thumbnailfile)) | |
388 | } | |
389 | if (attributes.previewfile !== undefined) { | |
390 | req.attach('previewfile', buildAbsoluteFixturePath(attributes.previewfile)) | |
0e1dc3e7 C |
391 | } |
392 | ||
2baea0c7 C |
393 | if (attributes.scheduleUpdate) { |
394 | req.field('scheduleUpdate[updateAt]', attributes.scheduleUpdate.updateAt) | |
395 | ||
396 | if (attributes.scheduleUpdate.privacy) { | |
397 | req.field('scheduleUpdate[privacy]', attributes.scheduleUpdate.privacy) | |
398 | } | |
399 | } | |
400 | ||
84929846 AM |
401 | if (attributes.originallyPublishedAt !== undefined) { |
402 | req.field('originallyPublishedAt', attributes.originallyPublishedAt) | |
403 | } | |
404 | ||
ac81d1a0 | 405 | return req.attach('videofile', buildAbsoluteFixturePath(attributes.fixture)) |
0e1dc3e7 C |
406 | .expect(specialStatus) |
407 | } | |
408 | ||
ac81d1a0 | 409 | function updateVideo (url: string, accessToken: string, id: number | string, attributes: VideoAttributes, statusCodeExpected = 204) { |
0e1dc3e7 C |
410 | const path = '/api/v1/videos/' + id |
411 | const body = {} | |
412 | ||
413 | if (attributes.name) body['name'] = attributes.name | |
414 | if (attributes.category) body['category'] = attributes.category | |
415 | if (attributes.licence) body['licence'] = attributes.licence | |
416 | if (attributes.language) body['language'] = attributes.language | |
47564bbe C |
417 | if (attributes.nsfw !== undefined) body['nsfw'] = JSON.stringify(attributes.nsfw) |
418 | if (attributes.commentsEnabled !== undefined) body['commentsEnabled'] = JSON.stringify(attributes.commentsEnabled) | |
7f2cfe3a | 419 | if (attributes.downloadEnabled !== undefined) body['downloadEnabled'] = JSON.stringify(attributes.downloadEnabled) |
7519127b | 420 | if (attributes.originallyPublishedAt !== undefined) body['originallyPublishedAt'] = attributes.originallyPublishedAt |
0e1dc3e7 C |
421 | if (attributes.description) body['description'] = attributes.description |
422 | if (attributes.tags) body['tags'] = attributes.tags | |
11474c3c | 423 | if (attributes.privacy) body['privacy'] = attributes.privacy |
0f320037 | 424 | if (attributes.channelId) body['channelId'] = attributes.channelId |
2baea0c7 | 425 | if (attributes.scheduleUpdate) body['scheduleUpdate'] = attributes.scheduleUpdate |
0e1dc3e7 | 426 | |
ac81d1a0 C |
427 | // Upload request |
428 | if (attributes.thumbnailfile || attributes.previewfile) { | |
429 | const attaches: any = {} | |
430 | if (attributes.thumbnailfile) attaches.thumbnailfile = attributes.thumbnailfile | |
431 | if (attributes.previewfile) attaches.previewfile = attributes.previewfile | |
432 | ||
433 | return makeUploadRequest({ | |
434 | url, | |
435 | method: 'PUT', | |
436 | path, | |
437 | token: accessToken, | |
438 | fields: body, | |
439 | attaches, | |
440 | statusCodeExpected | |
441 | }) | |
442 | } | |
443 | ||
444 | return makePutBodyRequest({ | |
445 | url, | |
446 | path, | |
447 | fields: body, | |
448 | token: accessToken, | |
449 | statusCodeExpected | |
450 | }) | |
0e1dc3e7 C |
451 | } |
452 | ||
453 | function rateVideo (url: string, accessToken: string, id: number, rating: string, specialStatus = 204) { | |
454 | const path = '/api/v1/videos/' + id + '/rate' | |
455 | ||
456 | return request(url) | |
457 | .put(path) | |
458 | .set('Accept', 'application/json') | |
459 | .set('Authorization', 'Bearer ' + accessToken) | |
460 | .send({ rating }) | |
461 | .expect(specialStatus) | |
462 | } | |
463 | ||
14d3270f | 464 | function parseTorrentVideo (server: ServerInfo, videoUUID: string, resolution: number) { |
fdbda9e3 | 465 | return new Promise<any>((res, rej) => { |
14d3270f | 466 | const torrentName = videoUUID + '-' + resolution + '.torrent' |
2a8c5d0a | 467 | const torrentPath = join(root(), 'test' + server.serverNumber, 'torrents', torrentName) |
fdbda9e3 C |
468 | readFile(torrentPath, (err, data) => { |
469 | if (err) return rej(err) | |
470 | ||
471 | return res(parseTorrent(data)) | |
472 | }) | |
473 | }) | |
474 | } | |
475 | ||
a20399c9 C |
476 | async function completeVideoCheck ( |
477 | url: string, | |
478 | video: any, | |
479 | attributes: { | |
480 | name: string | |
481 | category: number | |
482 | licence: number | |
9d3ef9fe | 483 | language: string |
a20399c9 | 484 | nsfw: boolean |
47564bbe | 485 | commentsEnabled: boolean |
7f2cfe3a | 486 | downloadEnabled: boolean |
a20399c9 | 487 | description: string |
53a61317 | 488 | publishedAt?: string |
2422c46b | 489 | support: string |
7519127b | 490 | originallyPublishedAt?: string, |
b64c950a C |
491 | account: { |
492 | name: string | |
493 | host: string | |
494 | } | |
f6eebcb3 C |
495 | isLocal: boolean |
496 | tags: string[] | |
497 | privacy: number | |
498 | likes?: number | |
499 | dislikes?: number | |
500 | duration: number | |
a20399c9 | 501 | channel: { |
f6eebcb3 C |
502 | displayName: string |
503 | name: string | |
b1f5b93e | 504 | description |
a20399c9 C |
505 | isLocal: boolean |
506 | } | |
f6eebcb3 | 507 | fixture: string |
a20399c9 C |
508 | files: { |
509 | resolution: number | |
510 | size: number | |
ac81d1a0 C |
511 | }[], |
512 | thumbnailfile?: string | |
513 | previewfile?: string | |
a20399c9 C |
514 | } |
515 | ) { | |
b1f5b93e C |
516 | if (!attributes.likes) attributes.likes = 0 |
517 | if (!attributes.dislikes) attributes.dislikes = 0 | |
518 | ||
a20399c9 | 519 | expect(video.name).to.equal(attributes.name) |
09700934 | 520 | expect(video.category.id).to.equal(attributes.category) |
9d3ef9fe | 521 | expect(video.category.label).to.equal(attributes.category !== null ? VIDEO_CATEGORIES[attributes.category] : 'Misc') |
09700934 | 522 | expect(video.licence.id).to.equal(attributes.licence) |
9d3ef9fe | 523 | expect(video.licence.label).to.equal(attributes.licence !== null ? VIDEO_LICENCES[attributes.licence] : 'Unknown') |
09700934 | 524 | expect(video.language.id).to.equal(attributes.language) |
9d3ef9fe | 525 | expect(video.language.label).to.equal(attributes.language !== null ? VIDEO_LANGUAGES[attributes.language] : 'Unknown') |
2243730c C |
526 | expect(video.privacy.id).to.deep.equal(attributes.privacy) |
527 | expect(video.privacy.label).to.deep.equal(VIDEO_PRIVACIES[attributes.privacy]) | |
a20399c9 C |
528 | expect(video.nsfw).to.equal(attributes.nsfw) |
529 | expect(video.description).to.equal(attributes.description) | |
03e12d7c | 530 | expect(video.account.id).to.be.a('number') |
b64c950a C |
531 | expect(video.account.host).to.equal(attributes.account.host) |
532 | expect(video.account.name).to.equal(attributes.account.name) | |
f6eebcb3 C |
533 | expect(video.channel.displayName).to.equal(attributes.channel.displayName) |
534 | expect(video.channel.name).to.equal(attributes.channel.name) | |
b1f5b93e C |
535 | expect(video.likes).to.equal(attributes.likes) |
536 | expect(video.dislikes).to.equal(attributes.dislikes) | |
a20399c9 | 537 | expect(video.isLocal).to.equal(attributes.isLocal) |
b1f5b93e | 538 | expect(video.duration).to.equal(attributes.duration) |
a20399c9 | 539 | expect(dateIsValid(video.createdAt)).to.be.true |
c49db162 | 540 | expect(dateIsValid(video.publishedAt)).to.be.true |
a20399c9 C |
541 | expect(dateIsValid(video.updatedAt)).to.be.true |
542 | ||
53a61317 | 543 | if (attributes.publishedAt) { |
53a61317 C |
544 | expect(video.publishedAt).to.equal(attributes.publishedAt) |
545 | } | |
546 | ||
7519127b C |
547 | if (attributes.originallyPublishedAt) { |
548 | expect(video.originallyPublishedAt).to.equal(attributes.originallyPublishedAt) | |
549 | } else { | |
550 | expect(video.originallyPublishedAt).to.be.null | |
551 | } | |
552 | ||
66b16caf | 553 | const res = await getVideo(url, video.uuid) |
0f320037 | 554 | const videoDetails: VideoDetails = res.body |
a20399c9 C |
555 | |
556 | expect(videoDetails.files).to.have.lengthOf(attributes.files.length) | |
557 | expect(videoDetails.tags).to.deep.equal(attributes.tags) | |
19a3b914 C |
558 | expect(videoDetails.account.name).to.equal(attributes.account.name) |
559 | expect(videoDetails.account.host).to.equal(attributes.account.host) | |
f6eebcb3 C |
560 | expect(video.channel.displayName).to.equal(attributes.channel.displayName) |
561 | expect(video.channel.name).to.equal(attributes.channel.name) | |
0f320037 | 562 | expect(videoDetails.channel.host).to.equal(attributes.account.host) |
a20399c9 | 563 | expect(videoDetails.channel.isLocal).to.equal(attributes.channel.isLocal) |
0f320037 C |
564 | expect(dateIsValid(videoDetails.channel.createdAt.toString())).to.be.true |
565 | expect(dateIsValid(videoDetails.channel.updatedAt.toString())).to.be.true | |
566 | expect(videoDetails.commentsEnabled).to.equal(attributes.commentsEnabled) | |
7f2cfe3a | 567 | expect(videoDetails.downloadEnabled).to.equal(attributes.downloadEnabled) |
a20399c9 C |
568 | |
569 | for (const attributeFile of attributes.files) { | |
5d00a3d7 | 570 | const file = videoDetails.files.find(f => f.resolution.id === attributeFile.resolution) |
a20399c9 C |
571 | expect(file).not.to.be.undefined |
572 | ||
b1f5b93e | 573 | let extension = extname(attributes.fixture) |
48f07b4a C |
574 | // Transcoding enabled: extension will always be .mp4 |
575 | if (attributes.files.length > 1) extension = '.mp4' | |
b1f5b93e | 576 | |
a20399c9 | 577 | expect(file.magnetUri).to.have.lengthOf.above(2) |
5d00a3d7 C |
578 | expect(file.torrentUrl).to.equal(`http://${attributes.account.host}/static/torrents/${videoDetails.uuid}-${file.resolution.id}.torrent`) |
579 | expect(file.fileUrl).to.equal(`http://${attributes.account.host}/static/webseed/${videoDetails.uuid}-${file.resolution.id}${extension}`) | |
09700934 C |
580 | expect(file.resolution.id).to.equal(attributeFile.resolution) |
581 | expect(file.resolution.label).to.equal(attributeFile.resolution + 'p') | |
b1f5b93e C |
582 | |
583 | const minSize = attributeFile.size - ((10 * attributeFile.size) / 100) | |
584 | const maxSize = attributeFile.size + ((10 * attributeFile.size) / 100) | |
4176e227 | 585 | expect(file.size, |
7160878c | 586 | 'File size for resolution ' + file.resolution.label + ' outside confidence interval (' + minSize + '> size <' + maxSize + ')') |
4176e227 | 587 | .to.be.above(minSize).and.below(maxSize) |
a20399c9 | 588 | |
ac81d1a0 | 589 | { |
7b0956ec | 590 | await testImage(url, attributes.thumbnailfile || attributes.fixture, videoDetails.thumbnailPath) |
ac81d1a0 C |
591 | } |
592 | ||
593 | if (attributes.previewfile) { | |
7b0956ec | 594 | await testImage(url, attributes.previewfile, videoDetails.previewPath) |
ac81d1a0 | 595 | } |
a20399c9 | 596 | |
d7a25329 | 597 | const torrent = await webtorrentAdd(file.magnetUri, true) |
a20399c9 C |
598 | expect(torrent.files).to.be.an('array') |
599 | expect(torrent.files.length).to.equal(1) | |
600 | expect(torrent.files[0].path).to.exist.and.to.not.equal('') | |
601 | } | |
602 | } | |
603 | ||
df0b219d C |
604 | async function videoUUIDToId (url: string, id: number | string) { |
605 | if (validator.isUUID('' + id) === false) return id | |
606 | ||
607 | const res = await getVideo(url, id) | |
608 | return res.body.id | |
609 | } | |
610 | ||
611 | async function uploadVideoAndGetId (options: { server: ServerInfo, videoName: string, nsfw?: boolean, token?: string }) { | |
612 | const videoAttrs: any = { name: options.videoName } | |
613 | if (options.nsfw) videoAttrs.nsfw = options.nsfw | |
614 | ||
df0b219d C |
615 | const res = await uploadVideo(options.server.url, options.token || options.server.accessToken, videoAttrs) |
616 | ||
617 | return { id: res.body.video.id, uuid: res.body.video.uuid } | |
618 | } | |
619 | ||
0e1dc3e7 C |
620 | // --------------------------------------------------------------------------- |
621 | ||
622 | export { | |
9567011b | 623 | getVideoDescription, |
0e1dc3e7 C |
624 | getVideoCategories, |
625 | getVideoLicences, | |
df0b219d | 626 | videoUUIDToId, |
11474c3c | 627 | getVideoPrivacies, |
0e1dc3e7 | 628 | getVideoLanguages, |
11474c3c | 629 | getMyVideos, |
6b738c7a C |
630 | getAccountVideos, |
631 | getVideoChannelVideos, | |
0e1dc3e7 | 632 | getVideo, |
11474c3c | 633 | getVideoWithToken, |
0e1dc3e7 C |
634 | getVideosList, |
635 | getVideosListPagination, | |
636 | getVideosListSort, | |
637 | removeVideo, | |
0883b324 | 638 | getVideosListWithToken, |
0e1dc3e7 | 639 | uploadVideo, |
d525fc39 | 640 | getVideosWithFilters, |
0e1dc3e7 | 641 | updateVideo, |
fdbda9e3 | 642 | rateVideo, |
1f3e9fec | 643 | viewVideo, |
a20399c9 | 644 | parseTorrentVideo, |
066e94c5 | 645 | getLocalVideos, |
f05a1c30 | 646 | completeVideoCheck, |
418d092a | 647 | checkVideoFilesWereRemoved, |
df0b219d C |
648 | getPlaylistVideos, |
649 | uploadVideoAndGetId | |
0e1dc3e7 | 650 | } |