1 /* tslint:disable:no-unused-expression */
3 import * as chai from 'chai'
5 import { VideoDetails, VideoPrivacy } from '../../../../shared/models/videos'
8 flushAndRunMultipleServers,
15 setAccessTokensToServers
17 import { waitJobs } from '../../utils/server/jobs'
18 import { getMyVideoImports, getYoutubeVideoUrl, importVideo } from '../../utils/videos/video-imports'
20 const expect = chai.expect
22 describe('Test video imports', function () {
23 let servers: ServerInfo[] = []
24 let channelIdServer1: number
25 let channelIdServer2: number
27 async function checkVideoServer1 (url: string, id: number | string) {
28 const res = await getVideo(url, id)
29 const video: VideoDetails = res.body
31 expect(video.name).to.equal('small video - youtube')
32 expect(video.category.label).to.equal('News')
33 expect(video.licence.label).to.equal('Attribution')
34 expect(video.language.label).to.equal('Unknown')
35 expect(video.nsfw).to.be.false
36 expect(video.description).to.equal('this is a super description')
37 expect(video.tags).to.deep.equal([ 'tag1', 'tag2' ])
39 expect(video.files).to.have.lengthOf(1)
42 async function checkVideoServer2 (url: string, id: number | string) {
43 const res = await getVideo(url, id)
44 const video = res.body
46 expect(video.name).to.equal('my super name')
47 expect(video.category.label).to.equal('Entertainment')
48 expect(video.licence.label).to.equal('Public Domain Dedication')
49 expect(video.language.label).to.equal('English')
50 expect(video.nsfw).to.be.false
51 expect(video.description).to.equal('my super description')
52 expect(video.tags).to.deep.equal([ 'supertag1', 'supertag2' ])
54 expect(video.files).to.have.lengthOf(1)
57 before(async function () {
61 servers = await flushAndRunMultipleServers(2)
63 await setAccessTokensToServers(servers)
66 const res = await getMyUserInformation(servers[0].url, servers[0].accessToken)
67 channelIdServer1 = res.body.videoChannels[ 0 ].id
71 const res = await getMyUserInformation(servers[1].url, servers[1].accessToken)
72 channelIdServer2 = res.body.videoChannels[ 0 ].id
75 await doubleFollow(servers[0], servers[1])
78 it('Should import a video on server 1', async function () {
82 targetUrl: getYoutubeVideoUrl(),
83 channelId: channelIdServer1,
84 privacy: VideoPrivacy.PUBLIC
86 const res = await importVideo(servers[0].url, servers[0].accessToken, attributes)
87 expect(res.body.video.name).to.equal('small video - youtube')
90 it('Should list the video to import in my videos on server 1', async function () {
91 const res = await getMyVideos(servers[0].url, servers[0].accessToken, 0, 5)
93 expect(res.body.total).to.equal(1)
95 const videos = res.body.data
96 expect(videos).to.have.lengthOf(1)
97 expect(videos[0].name).to.equal('small video - youtube')
100 it('Should list the video to import in my imports on server 1', async function () {
101 const res = await getMyVideoImports(servers[0].url, servers[0].accessToken)
103 expect(res.body.total).to.equal(1)
104 const videoImports = res.body.data
105 expect(videoImports).to.have.lengthOf(1)
107 expect(videoImports[0].targetUrl).to.equal(getYoutubeVideoUrl())
108 expect(videoImports[0].video.name).to.equal('small video - youtube')
111 it('Should have the video listed on the two instances1', async function () {
114 await waitJobs(servers)
116 for (const server of servers) {
117 const res = await getVideosList(server.url)
118 expect(res.body.total).to.equal(1)
119 expect(res.body.data).to.have.lengthOf(1)
121 await checkVideoServer1(server.url, res.body.data[0].uuid)
125 it('Should import a video on server 2 with some fields', async function () {
129 targetUrl: getYoutubeVideoUrl(),
130 channelId: channelIdServer1,
131 privacy: VideoPrivacy.PUBLIC,
135 name: 'my super name',
136 description: 'my super description',
137 tags: [ 'supertag1', 'supertag2' ]
139 const res = await importVideo(servers[1].url, servers[1].accessToken, attributes)
140 expect(res.body.video.name).to.equal('my super name')
143 it('Should have the video listed on the two instances', async function () {
146 await waitJobs(servers)
148 for (const server of servers) {
149 const res = await getVideosList(server.url)
150 expect(res.body.total).to.equal(2)
151 expect(res.body.data).to.have.lengthOf(2)
153 await checkVideoServer2(server.url, res.body.data[0].uuid)
154 await checkVideoServer1(server.url, res.body.data[1].uuid)
158 after(async function () {
159 killallServers(servers)