1 /* tslint:disable:no-unused-expression */
3 import * as chai from 'chai'
5 import { VideoDetails, VideoImport, VideoPrivacy } from '../../../../shared/models/videos'
8 flushAndRunMultipleServers,
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'
21 const expect = chai.expect
23 describe('Test video imports', function () {
24 let servers: ServerInfo[] = []
25 let channelIdServer1: number
26 let channelIdServer2: number
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
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)
41 const originallyPublishedAt = new Date(videoHttp.originallyPublishedAt)
42 expect(originallyPublishedAt.getDate()).to.equal(14)
43 expect(originallyPublishedAt.getMonth()).to.equal(0)
44 expect(originallyPublishedAt.getFullYear()).to.equal(2019)
46 const resMagnet = await getVideo(url, idMagnet)
47 const videoMagnet: VideoDetails = resMagnet.body
48 const resTorrent = await getVideo(url, idTorrent)
49 const videoTorrent: VideoDetails = resTorrent.body
51 for (const video of [ videoMagnet, videoTorrent ]) {
52 expect(video.category.label).to.equal('Misc')
53 expect(video.licence.label).to.equal('Unknown')
54 expect(video.language.label).to.equal('Unknown')
55 expect(video.nsfw).to.be.false
56 expect(video.description).to.equal('this is a super torrent description')
57 expect(video.tags).to.deep.equal([ 'tag_torrent1', 'tag_torrent2' ])
58 expect(video.files).to.have.lengthOf(1)
61 expect(videoTorrent.name).to.contain('你好 世界 720p.mp4')
62 expect(videoMagnet.name).to.contain('super peertube2 video')
65 async function checkVideoServer2 (url: string, id: number | string) {
66 const res = await getVideo(url, id)
67 const video = res.body
69 expect(video.name).to.equal('my super name')
70 expect(video.category.label).to.equal('Entertainment')
71 expect(video.licence.label).to.equal('Public Domain Dedication')
72 expect(video.language.label).to.equal('English')
73 expect(video.nsfw).to.be.false
74 expect(video.description).to.equal('my super description')
75 expect(video.tags).to.deep.equal([ 'supertag1', 'supertag2' ])
77 expect(video.files).to.have.lengthOf(1)
80 before(async function () {
84 servers = await flushAndRunMultipleServers(2)
86 await setAccessTokensToServers(servers)
89 const res = await getMyUserInformation(servers[0].url, servers[0].accessToken)
90 channelIdServer1 = res.body.videoChannels[ 0 ].id
94 const res = await getMyUserInformation(servers[1].url, servers[1].accessToken)
95 channelIdServer2 = res.body.videoChannels[ 0 ].id
98 await doubleFollow(servers[0], servers[1])
101 it('Should import videos on server 1', async function () {
104 const baseAttributes = {
105 channelId: channelIdServer1,
106 privacy: VideoPrivacy.PUBLIC
110 const attributes = immutableAssign(baseAttributes, { targetUrl: getYoutubeVideoUrl() })
111 const res = await importVideo(servers[0].url, servers[0].accessToken, attributes)
112 expect(res.body.video.name).to.equal('small video - youtube')
116 const attributes = immutableAssign(baseAttributes, {
117 magnetUri: getMagnetURI(),
118 description: 'this is a super torrent description',
119 tags: [ 'tag_torrent1', 'tag_torrent2' ]
121 const res = await importVideo(servers[0].url, servers[0].accessToken, attributes)
122 expect(res.body.video.name).to.equal('super peertube2 video')
126 const attributes = immutableAssign(baseAttributes, {
127 torrentfile: 'video-720p.torrent',
128 description: 'this is a super torrent description',
129 tags: [ 'tag_torrent1', 'tag_torrent2' ]
131 const res = await importVideo(servers[0].url, servers[0].accessToken, attributes)
132 expect(res.body.video.name).to.equal('你好 世界 720p.mp4')
136 it('Should list the videos to import in my videos on server 1', async function () {
137 const res = await getMyVideos(servers[0].url, servers[0].accessToken, 0, 5, 'createdAt')
139 expect(res.body.total).to.equal(3)
141 const videos = res.body.data
142 expect(videos).to.have.lengthOf(3)
143 expect(videos[0].name).to.equal('small video - youtube')
144 expect(videos[1].name).to.equal('super peertube2 video')
145 expect(videos[2].name).to.equal('你好 世界 720p.mp4')
148 it('Should list the videos to import in my imports on server 1', async function () {
149 const res = await getMyVideoImports(servers[0].url, servers[0].accessToken, '-createdAt')
151 expect(res.body.total).to.equal(3)
152 const videoImports: VideoImport[] = res.body.data
153 expect(videoImports).to.have.lengthOf(3)
155 expect(videoImports[2].targetUrl).to.equal(getYoutubeVideoUrl())
156 expect(videoImports[2].magnetUri).to.be.null
157 expect(videoImports[2].torrentName).to.be.null
158 expect(videoImports[2].video.name).to.equal('small video - youtube')
160 expect(videoImports[1].targetUrl).to.be.null
161 expect(videoImports[1].magnetUri).to.equal(getMagnetURI())
162 expect(videoImports[1].torrentName).to.be.null
163 expect(videoImports[1].video.name).to.equal('super peertube2 video')
165 expect(videoImports[0].targetUrl).to.be.null
166 expect(videoImports[0].magnetUri).to.be.null
167 expect(videoImports[0].torrentName).to.equal('video-720p.torrent')
168 expect(videoImports[0].video.name).to.equal('你好 世界 720p.mp4')
171 it('Should have the video listed on the two instances', async function () {
174 await waitJobs(servers)
176 for (const server of servers) {
177 const res = await getVideosList(server.url)
178 expect(res.body.total).to.equal(3)
179 expect(res.body.data).to.have.lengthOf(3)
181 const [ videoHttp, videoMagnet, videoTorrent ] = res.body.data
182 await checkVideosServer1(server.url, videoHttp.uuid, videoMagnet.uuid, videoTorrent.uuid)
186 it('Should import a video on server 2 with some fields', async function () {
190 targetUrl: getYoutubeVideoUrl(),
191 channelId: channelIdServer2,
192 privacy: VideoPrivacy.PUBLIC,
196 name: 'my super name',
197 description: 'my super description',
198 tags: [ 'supertag1', 'supertag2' ]
200 const res = await importVideo(servers[1].url, servers[1].accessToken, attributes)
201 expect(res.body.video.name).to.equal('my super name')
204 it('Should have the videos listed on the two instances', async function () {
207 await waitJobs(servers)
209 for (const server of servers) {
210 const res = await getVideosList(server.url)
211 expect(res.body.total).to.equal(4)
212 expect(res.body.data).to.have.lengthOf(4)
214 await checkVideoServer2(server.url, res.body.data[0].uuid)
216 const [ ,videoHttp, videoMagnet, videoTorrent ] = res.body.data
217 await checkVideosServer1(server.url, videoHttp.uuid, videoMagnet.uuid, videoTorrent.uuid)
221 it('Should import a video that will be transcoded', async function () {
225 name: 'transcoded video',
226 magnetUri: getMagnetURI(),
227 channelId: channelIdServer2,
228 privacy: VideoPrivacy.PUBLIC
230 const res = await importVideo(servers[1].url, servers[1].accessToken, attributes)
231 const videoUUID = res.body.video.uuid
233 await waitJobs(servers)
235 for (const server of servers) {
236 const res = await getVideo(server.url, videoUUID)
237 const video: VideoDetails = res.body
239 expect(video.name).to.equal('transcoded video')
240 expect(video.files).to.have.lengthOf(4)
244 after(async function () {
245 killallServers(servers)