]>
Commit | Line | Data |
---|---|---|
1 | /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */ | |
2 | ||
3 | import 'mocha' | |
4 | import * as chai from 'chai' | |
5 | import { cleanupTests, createMultipleServers, doubleFollow, PeerTubeServer, setAccessTokensToServers, waitJobs } from '@shared/extra-utils' | |
6 | import { VideoFile } from '@shared/models' | |
7 | ||
8 | const expect = chai.expect | |
9 | ||
10 | function assertVideoProperties (video: VideoFile, resolution: number, extname: string, size?: number) { | |
11 | expect(video).to.have.nested.property('resolution.id', resolution) | |
12 | expect(video).to.have.property('torrentUrl').that.includes(`-${resolution}.torrent`) | |
13 | expect(video).to.have.property('fileUrl').that.includes(`.${extname}`) | |
14 | expect(video).to.have.property('magnetUri').that.includes(`.${extname}`) | |
15 | expect(video).to.have.property('size').that.is.above(0) | |
16 | ||
17 | if (size) expect(video.size).to.equal(size) | |
18 | } | |
19 | ||
20 | describe('Test create import video jobs', function () { | |
21 | this.timeout(60000) | |
22 | ||
23 | let servers: PeerTubeServer[] = [] | |
24 | let video1UUID: string | |
25 | let video2UUID: string | |
26 | ||
27 | before(async function () { | |
28 | this.timeout(90000) | |
29 | ||
30 | // Run server 2 to have transcoding enabled | |
31 | servers = await createMultipleServers(2) | |
32 | await setAccessTokensToServers(servers) | |
33 | ||
34 | await doubleFollow(servers[0], servers[1]) | |
35 | ||
36 | // Upload two videos for our needs | |
37 | { | |
38 | const { uuid } = await servers[0].videos.upload({ attributes: { name: 'video1' } }) | |
39 | video1UUID = uuid | |
40 | } | |
41 | ||
42 | { | |
43 | const { uuid } = await servers[1].videos.upload({ attributes: { name: 'video2' } }) | |
44 | video2UUID = uuid | |
45 | } | |
46 | ||
47 | // Transcoding | |
48 | await waitJobs(servers) | |
49 | }) | |
50 | ||
51 | it('Should run a import job on video 1 with a lower resolution', async function () { | |
52 | const command = `npm run create-import-video-file-job -- -v ${video1UUID} -i server/tests/fixtures/video_short-480.webm` | |
53 | await servers[0].cli.execWithEnv(command) | |
54 | ||
55 | await waitJobs(servers) | |
56 | ||
57 | for (const server of servers) { | |
58 | const { data: videos } = await server.videos.list() | |
59 | expect(videos).to.have.lengthOf(2) | |
60 | ||
61 | const video = videos.find(({ uuid }) => uuid === video1UUID) | |
62 | const videoDetails = await server.videos.get({ id: video.uuid }) | |
63 | ||
64 | expect(videoDetails.files).to.have.lengthOf(2) | |
65 | const [ originalVideo, transcodedVideo ] = videoDetails.files | |
66 | assertVideoProperties(originalVideo, 720, 'webm', 218910) | |
67 | assertVideoProperties(transcodedVideo, 480, 'webm', 69217) | |
68 | } | |
69 | }) | |
70 | ||
71 | it('Should run a import job on video 2 with the same resolution and a different extension', async function () { | |
72 | const command = `npm run create-import-video-file-job -- -v ${video2UUID} -i server/tests/fixtures/video_short.ogv` | |
73 | await servers[1].cli.execWithEnv(command) | |
74 | ||
75 | await waitJobs(servers) | |
76 | ||
77 | for (const server of servers) { | |
78 | const { data: videos } = await server.videos.list() | |
79 | expect(videos).to.have.lengthOf(2) | |
80 | ||
81 | const video = videos.find(({ uuid }) => uuid === video2UUID) | |
82 | const videoDetails = await server.videos.get({ id: video.uuid }) | |
83 | ||
84 | expect(videoDetails.files).to.have.lengthOf(4) | |
85 | const [ originalVideo, transcodedVideo420, transcodedVideo320, transcodedVideo240 ] = videoDetails.files | |
86 | assertVideoProperties(originalVideo, 720, 'ogv', 140849) | |
87 | assertVideoProperties(transcodedVideo420, 480, 'mp4') | |
88 | assertVideoProperties(transcodedVideo320, 360, 'mp4') | |
89 | assertVideoProperties(transcodedVideo240, 240, 'mp4') | |
90 | } | |
91 | }) | |
92 | ||
93 | it('Should run a import job on video 2 with the same resolution and the same extension', async function () { | |
94 | const command = `npm run create-import-video-file-job -- -v ${video1UUID} -i server/tests/fixtures/video_short2.webm` | |
95 | await servers[0].cli.execWithEnv(command) | |
96 | ||
97 | await waitJobs(servers) | |
98 | ||
99 | for (const server of servers) { | |
100 | const { data: videos } = await server.videos.list() | |
101 | expect(videos).to.have.lengthOf(2) | |
102 | ||
103 | const video = videos.find(({ uuid }) => uuid === video1UUID) | |
104 | const videoDetails = await server.videos.get({ id: video.uuid }) | |
105 | ||
106 | expect(videoDetails.files).to.have.lengthOf(2) | |
107 | const [ video720, video480 ] = videoDetails.files | |
108 | assertVideoProperties(video720, 720, 'webm', 942961) | |
109 | assertVideoProperties(video480, 480, 'webm', 69217) | |
110 | } | |
111 | }) | |
112 | ||
113 | after(async function () { | |
114 | await cleanupTests(servers) | |
115 | }) | |
116 | }) |