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