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