]>
Commit | Line | Data |
---|---|---|
590fb506 C |
1 | /* tslint:disable:no-unused-expression */ |
2 | ||
3 | import * as chai from 'chai' | |
4 | import 'mocha' | |
3e17515e | 5 | import { VideoDetails, VideoImport, VideoPrivacy } from '../../../../shared/models/videos' |
590fb506 C |
6 | import { |
7 | doubleFollow, | |
8 | flushAndRunMultipleServers, | |
9 | getMyUserInformation, | |
10 | getMyVideos, | |
11 | getVideo, | |
12 | getVideosList, | |
3e17515e | 13 | immutableAssign, |
590fb506 C |
14 | killallServers, |
15 | ServerInfo, | |
16 | setAccessTokensToServers | |
9639bd17 | 17 | } from '../../../../shared/utils' |
18 | import { waitJobs } from '../../../../shared/utils/server/jobs' | |
19 | import { getMagnetURI, getYoutubeVideoUrl, importVideo, getMyVideoImports } from '../../../../shared/utils/videos/video-imports' | |
590fb506 C |
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 | ||
3e17515e C |
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') | |
6f2ae7a1 | 33 | expect(videoHttp.category.label).to.equal('News & Politics') |
3e17515e C |
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) | |
17036be5 C |
40 | |
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) | |
3e17515e C |
45 | |
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 | |
50 | ||
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) | |
59 | } | |
590fb506 | 60 | |
3e17515e C |
61 | expect(videoTorrent.name).to.contain('你好 世界 720p.mp4') |
62 | expect(videoMagnet.name).to.contain('super peertube2 video') | |
590fb506 C |
63 | } |
64 | ||
65 | async function checkVideoServer2 (url: string, id: number | string) { | |
66 | const res = await getVideo(url, id) | |
67 | const video = res.body | |
68 | ||
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' ]) | |
76 | ||
77 | expect(video.files).to.have.lengthOf(1) | |
78 | } | |
79 | ||
80 | before(async function () { | |
81 | this.timeout(30000) | |
82 | ||
83 | // Run servers | |
84 | servers = await flushAndRunMultipleServers(2) | |
85 | ||
86 | await setAccessTokensToServers(servers) | |
87 | ||
88 | { | |
89 | const res = await getMyUserInformation(servers[0].url, servers[0].accessToken) | |
90 | channelIdServer1 = res.body.videoChannels[ 0 ].id | |
91 | } | |
92 | ||
93 | { | |
94 | const res = await getMyUserInformation(servers[1].url, servers[1].accessToken) | |
95 | channelIdServer2 = res.body.videoChannels[ 0 ].id | |
96 | } | |
97 | ||
98 | await doubleFollow(servers[0], servers[1]) | |
99 | }) | |
100 | ||
3e17515e | 101 | it('Should import videos on server 1', async function () { |
590fb506 C |
102 | this.timeout(60000) |
103 | ||
3e17515e | 104 | const baseAttributes = { |
590fb506 C |
105 | channelId: channelIdServer1, |
106 | privacy: VideoPrivacy.PUBLIC | |
107 | } | |
3e17515e C |
108 | |
109 | { | |
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') | |
113 | } | |
114 | ||
115 | { | |
116 | const attributes = immutableAssign(baseAttributes, { | |
117 | magnetUri: getMagnetURI(), | |
118 | description: 'this is a super torrent description', | |
119 | tags: [ 'tag_torrent1', 'tag_torrent2' ] | |
120 | }) | |
121 | const res = await importVideo(servers[0].url, servers[0].accessToken, attributes) | |
122 | expect(res.body.video.name).to.equal('super peertube2 video') | |
123 | } | |
124 | ||
125 | { | |
126 | const attributes = immutableAssign(baseAttributes, { | |
127 | torrentfile: 'video-720p.torrent', | |
128 | description: 'this is a super torrent description', | |
129 | tags: [ 'tag_torrent1', 'tag_torrent2' ] | |
130 | }) | |
131 | const res = await importVideo(servers[0].url, servers[0].accessToken, attributes) | |
132 | expect(res.body.video.name).to.equal('你好 世界 720p.mp4') | |
133 | } | |
590fb506 C |
134 | }) |
135 | ||
3e17515e C |
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') | |
590fb506 | 138 | |
3e17515e | 139 | expect(res.body.total).to.equal(3) |
590fb506 C |
140 | |
141 | const videos = res.body.data | |
3e17515e | 142 | expect(videos).to.have.lengthOf(3) |
590fb506 | 143 | expect(videos[0].name).to.equal('small video - youtube') |
3e17515e C |
144 | expect(videos[1].name).to.equal('super peertube2 video') |
145 | expect(videos[2].name).to.equal('你好 世界 720p.mp4') | |
590fb506 C |
146 | }) |
147 | ||
3e17515e C |
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') | |
150 | ||
151 | expect(res.body.total).to.equal(3) | |
152 | const videoImports: VideoImport[] = res.body.data | |
153 | expect(videoImports).to.have.lengthOf(3) | |
154 | ||
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') | |
590fb506 | 159 | |
3e17515e C |
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') | |
590fb506 | 164 | |
3e17515e C |
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') | |
590fb506 C |
169 | }) |
170 | ||
3e17515e | 171 | it('Should have the video listed on the two instances', async function () { |
590fb506 C |
172 | this.timeout(120000) |
173 | ||
174 | await waitJobs(servers) | |
175 | ||
176 | for (const server of servers) { | |
177 | const res = await getVideosList(server.url) | |
3e17515e C |
178 | expect(res.body.total).to.equal(3) |
179 | expect(res.body.data).to.have.lengthOf(3) | |
590fb506 | 180 | |
3e17515e C |
181 | const [ videoHttp, videoMagnet, videoTorrent ] = res.body.data |
182 | await checkVideosServer1(server.url, videoHttp.uuid, videoMagnet.uuid, videoTorrent.uuid) | |
590fb506 C |
183 | } |
184 | }) | |
185 | ||
186 | it('Should import a video on server 2 with some fields', async function () { | |
187 | this.timeout(60000) | |
188 | ||
189 | const attributes = { | |
190 | targetUrl: getYoutubeVideoUrl(), | |
3e17515e | 191 | channelId: channelIdServer2, |
590fb506 C |
192 | privacy: VideoPrivacy.PUBLIC, |
193 | category: 10, | |
194 | licence: 7, | |
195 | language: 'en', | |
196 | name: 'my super name', | |
197 | description: 'my super description', | |
198 | tags: [ 'supertag1', 'supertag2' ] | |
199 | } | |
200 | const res = await importVideo(servers[1].url, servers[1].accessToken, attributes) | |
201 | expect(res.body.video.name).to.equal('my super name') | |
202 | }) | |
203 | ||
3e17515e | 204 | it('Should have the videos listed on the two instances', async function () { |
590fb506 C |
205 | this.timeout(120000) |
206 | ||
207 | await waitJobs(servers) | |
208 | ||
209 | for (const server of servers) { | |
210 | const res = await getVideosList(server.url) | |
3e17515e C |
211 | expect(res.body.total).to.equal(4) |
212 | expect(res.body.data).to.have.lengthOf(4) | |
590fb506 C |
213 | |
214 | await checkVideoServer2(server.url, res.body.data[0].uuid) | |
3e17515e C |
215 | |
216 | const [ ,videoHttp, videoMagnet, videoTorrent ] = res.body.data | |
217 | await checkVideosServer1(server.url, videoHttp.uuid, videoMagnet.uuid, videoTorrent.uuid) | |
218 | } | |
219 | }) | |
220 | ||
221 | it('Should import a video that will be transcoded', async function () { | |
222 | this.timeout(120000) | |
223 | ||
224 | const attributes = { | |
225 | name: 'transcoded video', | |
226 | magnetUri: getMagnetURI(), | |
227 | channelId: channelIdServer2, | |
228 | privacy: VideoPrivacy.PUBLIC | |
229 | } | |
230 | const res = await importVideo(servers[1].url, servers[1].accessToken, attributes) | |
231 | const videoUUID = res.body.video.uuid | |
232 | ||
233 | await waitJobs(servers) | |
234 | ||
235 | for (const server of servers) { | |
236 | const res = await getVideo(server.url, videoUUID) | |
237 | const video: VideoDetails = res.body | |
238 | ||
239 | expect(video.name).to.equal('transcoded video') | |
240 | expect(video.files).to.have.lengthOf(4) | |
590fb506 C |
241 | } |
242 | }) | |
243 | ||
244 | after(async function () { | |
245 | killallServers(servers) | |
246 | }) | |
247 | }) |