1 /* tslint:disable:no-unused-expression */
3 import * as chai from 'chai'
5 import { VideoDetails, VideoImport, VideoPrivacy } from '../../../../shared/models/videos'
9 flushAndRunMultipleServers,
17 setAccessTokensToServers
18 } from '../../../../shared/extra-utils'
19 import { waitJobs } from '../../../../shared/extra-utils/server/jobs'
20 import { getMagnetURI, getYoutubeVideoUrl, importVideo, getMyVideoImports } from '../../../../shared/extra-utils/videos/video-imports'
22 const expect = chai.expect
24 describe('Test video imports', function () {
25 let servers: ServerInfo[] = []
26 let channelIdServer1: number
27 let channelIdServer2: number
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
33 expect(videoHttp.name).to.equal('small video - youtube')
34 expect(videoHttp.category.label).to.equal('News & Politics')
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)
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)
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
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)
62 expect(videoTorrent.name).to.contain('你好 世界 720p.mp4')
63 expect(videoMagnet.name).to.contain('super peertube2 video')
66 async function checkVideoServer2 (url: string, id: number | string) {
67 const res = await getVideo(url, id)
68 const video = res.body
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' ])
78 expect(video.files).to.have.lengthOf(1)
81 before(async function () {
85 servers = await flushAndRunMultipleServers(2)
87 await setAccessTokensToServers(servers)
90 const res = await getMyUserInformation(servers[0].url, servers[0].accessToken)
91 channelIdServer1 = res.body.videoChannels[ 0 ].id
95 const res = await getMyUserInformation(servers[1].url, servers[1].accessToken)
96 channelIdServer2 = res.body.videoChannels[ 0 ].id
99 await doubleFollow(servers[0], servers[1])
102 it('Should import videos on server 1', async function () {
105 const baseAttributes = {
106 channelId: channelIdServer1,
107 privacy: VideoPrivacy.PUBLIC
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')
117 const attributes = immutableAssign(baseAttributes, {
118 magnetUri: getMagnetURI(),
119 description: 'this is a super torrent description',
120 tags: [ 'tag_torrent1', 'tag_torrent2' ]
122 const res = await importVideo(servers[0].url, servers[0].accessToken, attributes)
123 expect(res.body.video.name).to.equal('super peertube2 video')
127 const attributes = immutableAssign(baseAttributes, {
128 torrentfile: 'video-720p.torrent',
129 description: 'this is a super torrent description',
130 tags: [ 'tag_torrent1', 'tag_torrent2' ]
132 const res = await importVideo(servers[0].url, servers[0].accessToken, attributes)
133 expect(res.body.video.name).to.equal('你好 世界 720p.mp4')
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')
140 expect(res.body.total).to.equal(3)
142 const videos = res.body.data
143 expect(videos).to.have.lengthOf(3)
144 expect(videos[0].name).to.equal('small video - youtube')
145 expect(videos[1].name).to.equal('super peertube2 video')
146 expect(videos[2].name).to.equal('你好 世界 720p.mp4')
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')
152 expect(res.body.total).to.equal(3)
153 const videoImports: VideoImport[] = res.body.data
154 expect(videoImports).to.have.lengthOf(3)
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')
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')
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')
172 it('Should have the video listed on the two instances', async function () {
175 await waitJobs(servers)
177 for (const server of servers) {
178 const res = await getVideosList(server.url)
179 expect(res.body.total).to.equal(3)
180 expect(res.body.data).to.have.lengthOf(3)
182 const [ videoHttp, videoMagnet, videoTorrent ] = res.body.data
183 await checkVideosServer1(server.url, videoHttp.uuid, videoMagnet.uuid, videoTorrent.uuid)
187 it('Should import a video on server 2 with some fields', async function () {
191 targetUrl: getYoutubeVideoUrl(),
192 channelId: channelIdServer2,
193 privacy: VideoPrivacy.PUBLIC,
197 name: 'my super name',
198 description: 'my super description',
199 tags: [ 'supertag1', 'supertag2' ]
201 const res = await importVideo(servers[1].url, servers[1].accessToken, attributes)
202 expect(res.body.video.name).to.equal('my super name')
205 it('Should have the videos listed on the two instances', async function () {
208 await waitJobs(servers)
210 for (const server of servers) {
211 const res = await getVideosList(server.url)
212 expect(res.body.total).to.equal(4)
213 expect(res.body.data).to.have.lengthOf(4)
215 await checkVideoServer2(server.url, res.body.data[0].uuid)
217 const [ ,videoHttp, videoMagnet, videoTorrent ] = res.body.data
218 await checkVideosServer1(server.url, videoHttp.uuid, videoMagnet.uuid, videoTorrent.uuid)
222 it('Should import a video that will be transcoded', async function () {
226 name: 'transcoded video',
227 magnetUri: getMagnetURI(),
228 channelId: channelIdServer2,
229 privacy: VideoPrivacy.PUBLIC
231 const res = await importVideo(servers[1].url, servers[1].accessToken, attributes)
232 const videoUUID = res.body.video.uuid
234 await waitJobs(servers)
236 for (const server of servers) {
237 const res = await getVideo(server.url, videoUUID)
238 const video: VideoDetails = res.body
240 expect(video.name).to.equal('transcoded video')
241 expect(video.files).to.have.lengthOf(4)
245 after(async function () {
246 await cleanupTests(servers)