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