]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - server/tests/api/videos/video-imports.ts
Redundancy and search tests in parallel too
[github/Chocobozzz/PeerTube.git] / server / tests / api / videos / video-imports.ts
CommitLineData
590fb506
C
1/* tslint:disable:no-unused-expression */
2
3import * as chai from 'chai'
4import 'mocha'
3e17515e 5import { VideoDetails, VideoImport, VideoPrivacy } from '../../../../shared/models/videos'
590fb506 6import {
7c3b7976 7 cleanupTests,
590fb506
C
8 doubleFollow,
9 flushAndRunMultipleServers,
10 getMyUserInformation,
11 getMyVideos,
12 getVideo,
13 getVideosList,
3e17515e 14 immutableAssign,
590fb506
C
15 killallServers,
16 ServerInfo,
17 setAccessTokensToServers
94565d52
C
18} from '../../../../shared/extra-utils'
19import { waitJobs } from '../../../../shared/extra-utils/server/jobs'
20import { getMagnetURI, getYoutubeVideoUrl, importVideo, getMyVideoImports } from '../../../../shared/extra-utils/videos/video-imports'
590fb506
C
21
22const expect = chai.expect
23
24describe('Test video imports', function () {
25 let servers: ServerInfo[] = []
26 let channelIdServer1: number
27 let channelIdServer2: number
28
3e17515e
C
29 async function checkVideosServer1 (url: string, idHttp: string, idMagnet: string, idTorrent: string) {
30 const resHttp = await getVideo(url, idHttp)
31 const videoHttp: VideoDetails = resHttp.body
32
33 expect(videoHttp.name).to.equal('small video - youtube')
6f2ae7a1 34 expect(videoHttp.category.label).to.equal('News & Politics')
3e17515e
C
35 expect(videoHttp.licence.label).to.equal('Attribution')
36 expect(videoHttp.language.label).to.equal('Unknown')
37 expect(videoHttp.nsfw).to.be.false
38 expect(videoHttp.description).to.equal('this is a super description')
39 expect(videoHttp.tags).to.deep.equal([ 'tag1', 'tag2' ])
40 expect(videoHttp.files).to.have.lengthOf(1)
17036be5
C
41
42 const originallyPublishedAt = new Date(videoHttp.originallyPublishedAt)
43 expect(originallyPublishedAt.getDate()).to.equal(14)
44 expect(originallyPublishedAt.getMonth()).to.equal(0)
45 expect(originallyPublishedAt.getFullYear()).to.equal(2019)
3e17515e
C
46
47 const resMagnet = await getVideo(url, idMagnet)
48 const videoMagnet: VideoDetails = resMagnet.body
49 const resTorrent = await getVideo(url, idTorrent)
50 const videoTorrent: VideoDetails = resTorrent.body
51
52 for (const video of [ videoMagnet, videoTorrent ]) {
53 expect(video.category.label).to.equal('Misc')
54 expect(video.licence.label).to.equal('Unknown')
55 expect(video.language.label).to.equal('Unknown')
56 expect(video.nsfw).to.be.false
57 expect(video.description).to.equal('this is a super torrent description')
58 expect(video.tags).to.deep.equal([ 'tag_torrent1', 'tag_torrent2' ])
59 expect(video.files).to.have.lengthOf(1)
60 }
590fb506 61
3e17515e
C
62 expect(videoTorrent.name).to.contain('你好 世界 720p.mp4')
63 expect(videoMagnet.name).to.contain('super peertube2 video')
590fb506
C
64 }
65
66 async function checkVideoServer2 (url: string, id: number | string) {
67 const res = await getVideo(url, id)
68 const video = res.body
69
70 expect(video.name).to.equal('my super name')
71 expect(video.category.label).to.equal('Entertainment')
72 expect(video.licence.label).to.equal('Public Domain Dedication')
73 expect(video.language.label).to.equal('English')
74 expect(video.nsfw).to.be.false
75 expect(video.description).to.equal('my super description')
76 expect(video.tags).to.deep.equal([ 'supertag1', 'supertag2' ])
77
78 expect(video.files).to.have.lengthOf(1)
79 }
80
81 before(async function () {
82 this.timeout(30000)
83
84 // Run servers
85 servers = await flushAndRunMultipleServers(2)
86
87 await setAccessTokensToServers(servers)
88
89 {
90 const res = await getMyUserInformation(servers[0].url, servers[0].accessToken)
91 channelIdServer1 = res.body.videoChannels[ 0 ].id
92 }
93
94 {
95 const res = await getMyUserInformation(servers[1].url, servers[1].accessToken)
96 channelIdServer2 = res.body.videoChannels[ 0 ].id
97 }
98
99 await doubleFollow(servers[0], servers[1])
100 })
101
3e17515e 102 it('Should import videos on server 1', async function () {
590fb506
C
103 this.timeout(60000)
104
3e17515e 105 const baseAttributes = {
590fb506
C
106 channelId: channelIdServer1,
107 privacy: VideoPrivacy.PUBLIC
108 }
3e17515e
C
109
110 {
111 const attributes = immutableAssign(baseAttributes, { targetUrl: getYoutubeVideoUrl() })
112 const res = await importVideo(servers[0].url, servers[0].accessToken, attributes)
113 expect(res.body.video.name).to.equal('small video - youtube')
114 }
115
116 {
117 const attributes = immutableAssign(baseAttributes, {
118 magnetUri: getMagnetURI(),
119 description: 'this is a super torrent description',
120 tags: [ 'tag_torrent1', 'tag_torrent2' ]
121 })
122 const res = await importVideo(servers[0].url, servers[0].accessToken, attributes)
123 expect(res.body.video.name).to.equal('super peertube2 video')
124 }
125
126 {
127 const attributes = immutableAssign(baseAttributes, {
128 torrentfile: 'video-720p.torrent',
129 description: 'this is a super torrent description',
130 tags: [ 'tag_torrent1', 'tag_torrent2' ]
131 })
132 const res = await importVideo(servers[0].url, servers[0].accessToken, attributes)
133 expect(res.body.video.name).to.equal('你好 世界 720p.mp4')
134 }
590fb506
C
135 })
136
3e17515e
C
137 it('Should list the videos to import in my videos on server 1', async function () {
138 const res = await getMyVideos(servers[0].url, servers[0].accessToken, 0, 5, 'createdAt')
590fb506 139
3e17515e 140 expect(res.body.total).to.equal(3)
590fb506
C
141
142 const videos = res.body.data
3e17515e 143 expect(videos).to.have.lengthOf(3)
590fb506 144 expect(videos[0].name).to.equal('small video - youtube')
3e17515e
C
145 expect(videos[1].name).to.equal('super peertube2 video')
146 expect(videos[2].name).to.equal('你好 世界 720p.mp4')
590fb506
C
147 })
148
3e17515e
C
149 it('Should list the videos to import in my imports on server 1', async function () {
150 const res = await getMyVideoImports(servers[0].url, servers[0].accessToken, '-createdAt')
151
152 expect(res.body.total).to.equal(3)
153 const videoImports: VideoImport[] = res.body.data
154 expect(videoImports).to.have.lengthOf(3)
155
156 expect(videoImports[2].targetUrl).to.equal(getYoutubeVideoUrl())
157 expect(videoImports[2].magnetUri).to.be.null
158 expect(videoImports[2].torrentName).to.be.null
159 expect(videoImports[2].video.name).to.equal('small video - youtube')
590fb506 160
3e17515e
C
161 expect(videoImports[1].targetUrl).to.be.null
162 expect(videoImports[1].magnetUri).to.equal(getMagnetURI())
163 expect(videoImports[1].torrentName).to.be.null
164 expect(videoImports[1].video.name).to.equal('super peertube2 video')
590fb506 165
3e17515e
C
166 expect(videoImports[0].targetUrl).to.be.null
167 expect(videoImports[0].magnetUri).to.be.null
168 expect(videoImports[0].torrentName).to.equal('video-720p.torrent')
169 expect(videoImports[0].video.name).to.equal('你好 世界 720p.mp4')
590fb506
C
170 })
171
3e17515e 172 it('Should have the video listed on the two instances', async function () {
590fb506
C
173 this.timeout(120000)
174
175 await waitJobs(servers)
176
177 for (const server of servers) {
178 const res = await getVideosList(server.url)
3e17515e
C
179 expect(res.body.total).to.equal(3)
180 expect(res.body.data).to.have.lengthOf(3)
590fb506 181
3e17515e
C
182 const [ videoHttp, videoMagnet, videoTorrent ] = res.body.data
183 await checkVideosServer1(server.url, videoHttp.uuid, videoMagnet.uuid, videoTorrent.uuid)
590fb506
C
184 }
185 })
186
187 it('Should import a video on server 2 with some fields', async function () {
188 this.timeout(60000)
189
190 const attributes = {
191 targetUrl: getYoutubeVideoUrl(),
3e17515e 192 channelId: channelIdServer2,
590fb506
C
193 privacy: VideoPrivacy.PUBLIC,
194 category: 10,
195 licence: 7,
196 language: 'en',
197 name: 'my super name',
198 description: 'my super description',
199 tags: [ 'supertag1', 'supertag2' ]
200 }
201 const res = await importVideo(servers[1].url, servers[1].accessToken, attributes)
202 expect(res.body.video.name).to.equal('my super name')
203 })
204
3e17515e 205 it('Should have the videos listed on the two instances', async function () {
590fb506
C
206 this.timeout(120000)
207
208 await waitJobs(servers)
209
210 for (const server of servers) {
211 const res = await getVideosList(server.url)
3e17515e
C
212 expect(res.body.total).to.equal(4)
213 expect(res.body.data).to.have.lengthOf(4)
590fb506
C
214
215 await checkVideoServer2(server.url, res.body.data[0].uuid)
3e17515e
C
216
217 const [ ,videoHttp, videoMagnet, videoTorrent ] = res.body.data
218 await checkVideosServer1(server.url, videoHttp.uuid, videoMagnet.uuid, videoTorrent.uuid)
219 }
220 })
221
222 it('Should import a video that will be transcoded', async function () {
223 this.timeout(120000)
224
225 const attributes = {
226 name: 'transcoded video',
227 magnetUri: getMagnetURI(),
228 channelId: channelIdServer2,
229 privacy: VideoPrivacy.PUBLIC
230 }
231 const res = await importVideo(servers[1].url, servers[1].accessToken, attributes)
232 const videoUUID = res.body.video.uuid
233
234 await waitJobs(servers)
235
236 for (const server of servers) {
237 const res = await getVideo(server.url, videoUUID)
238 const video: VideoDetails = res.body
239
240 expect(video.name).to.equal('transcoded video')
241 expect(video.files).to.have.lengthOf(4)
590fb506
C
242 }
243 })
244
7c3b7976
C
245 after(async function () {
246 await cleanupTests(servers)
590fb506
C
247 })
248})