]>
Commit | Line | Data |
---|---|---|
590fb506 C |
1 | /* tslint:disable:no-unused-expression */ |
2 | ||
3 | import * as chai from 'chai' | |
4 | import 'mocha' | |
5 | import { VideoDetails, VideoPrivacy } from '../../../../shared/models/videos' | |
6 | import { | |
7 | doubleFollow, | |
8 | flushAndRunMultipleServers, | |
9 | getMyUserInformation, | |
10 | getMyVideos, | |
11 | getVideo, | |
12 | getVideosList, | |
13 | killallServers, | |
14 | ServerInfo, | |
15 | setAccessTokensToServers | |
16 | } from '../../utils' | |
17 | import { waitJobs } from '../../utils/server/jobs' | |
18 | import { getMyVideoImports, getYoutubeVideoUrl, importVideo } from '../../utils/videos/video-imports' | |
19 | ||
20 | const expect = chai.expect | |
21 | ||
22 | describe('Test video imports', function () { | |
23 | let servers: ServerInfo[] = [] | |
24 | let channelIdServer1: number | |
25 | let channelIdServer2: number | |
26 | ||
27 | async function checkVideoServer1 (url: string, id: number | string) { | |
28 | const res = await getVideo(url, id) | |
29 | const video: VideoDetails = res.body | |
30 | ||
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' ]) | |
38 | ||
39 | expect(video.files).to.have.lengthOf(1) | |
40 | } | |
41 | ||
42 | async function checkVideoServer2 (url: string, id: number | string) { | |
43 | const res = await getVideo(url, id) | |
44 | const video = res.body | |
45 | ||
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' ]) | |
53 | ||
54 | expect(video.files).to.have.lengthOf(1) | |
55 | } | |
56 | ||
57 | before(async function () { | |
58 | this.timeout(30000) | |
59 | ||
60 | // Run servers | |
61 | servers = await flushAndRunMultipleServers(2) | |
62 | ||
63 | await setAccessTokensToServers(servers) | |
64 | ||
65 | { | |
66 | const res = await getMyUserInformation(servers[0].url, servers[0].accessToken) | |
67 | channelIdServer1 = res.body.videoChannels[ 0 ].id | |
68 | } | |
69 | ||
70 | { | |
71 | const res = await getMyUserInformation(servers[1].url, servers[1].accessToken) | |
72 | channelIdServer2 = res.body.videoChannels[ 0 ].id | |
73 | } | |
74 | ||
75 | await doubleFollow(servers[0], servers[1]) | |
76 | }) | |
77 | ||
78 | it('Should import a video on server 1', async function () { | |
79 | this.timeout(60000) | |
80 | ||
81 | const attributes = { | |
82 | targetUrl: getYoutubeVideoUrl(), | |
83 | channelId: channelIdServer1, | |
84 | privacy: VideoPrivacy.PUBLIC | |
85 | } | |
86 | const res = await importVideo(servers[0].url, servers[0].accessToken, attributes) | |
87 | expect(res.body.video.name).to.equal('small video - youtube') | |
88 | }) | |
89 | ||
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) | |
92 | ||
93 | expect(res.body.total).to.equal(1) | |
94 | ||
95 | const videos = res.body.data | |
96 | expect(videos).to.have.lengthOf(1) | |
97 | expect(videos[0].name).to.equal('small video - youtube') | |
98 | }) | |
99 | ||
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) | |
102 | ||
103 | expect(res.body.total).to.equal(1) | |
104 | const videoImports = res.body.data | |
105 | expect(videoImports).to.have.lengthOf(1) | |
106 | ||
107 | expect(videoImports[0].targetUrl).to.equal(getYoutubeVideoUrl()) | |
108 | expect(videoImports[0].video.name).to.equal('small video - youtube') | |
109 | }) | |
110 | ||
111 | it('Should have the video listed on the two instances1', async function () { | |
112 | this.timeout(120000) | |
113 | ||
114 | await waitJobs(servers) | |
115 | ||
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) | |
120 | ||
121 | await checkVideoServer1(server.url, res.body.data[0].uuid) | |
122 | } | |
123 | }) | |
124 | ||
125 | it('Should import a video on server 2 with some fields', async function () { | |
126 | this.timeout(60000) | |
127 | ||
128 | const attributes = { | |
129 | targetUrl: getYoutubeVideoUrl(), | |
130 | channelId: channelIdServer1, | |
131 | privacy: VideoPrivacy.PUBLIC, | |
132 | category: 10, | |
133 | licence: 7, | |
134 | language: 'en', | |
135 | name: 'my super name', | |
136 | description: 'my super description', | |
137 | tags: [ 'supertag1', 'supertag2' ] | |
138 | } | |
139 | const res = await importVideo(servers[1].url, servers[1].accessToken, attributes) | |
140 | expect(res.body.video.name).to.equal('my super name') | |
141 | }) | |
142 | ||
143 | it('Should have the video listed on the two instances', async function () { | |
144 | this.timeout(120000) | |
145 | ||
146 | await waitJobs(servers) | |
147 | ||
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) | |
152 | ||
153 | await checkVideoServer2(server.url, res.body.data[0].uuid) | |
154 | await checkVideoServer1(server.url, res.body.data[1].uuid) | |
155 | } | |
156 | }) | |
157 | ||
158 | after(async function () { | |
159 | killallServers(servers) | |
160 | }) | |
161 | }) |