aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/tests/plugins
diff options
context:
space:
mode:
Diffstat (limited to 'server/tests/plugins')
-rw-r--r--server/tests/plugins/action-hooks.ts17
-rw-r--r--server/tests/plugins/filter-hooks.ts94
-rw-r--r--server/tests/plugins/plugin-helpers.ts57
-rw-r--r--server/tests/plugins/plugin-transcoding.ts23
-rw-r--r--server/tests/plugins/video-constants.ts52
5 files changed, 93 insertions, 150 deletions
diff --git a/server/tests/plugins/action-hooks.ts b/server/tests/plugins/action-hooks.ts
index b156f6b60..9e12c8aa7 100644
--- a/server/tests/plugins/action-hooks.ts
+++ b/server/tests/plugins/action-hooks.ts
@@ -9,10 +9,7 @@ import {
9 reRunServer, 9 reRunServer,
10 ServerInfo, 10 ServerInfo,
11 setAccessTokensToServers, 11 setAccessTokensToServers,
12 setDefaultVideoChannel, 12 setDefaultVideoChannel
13 updateVideo,
14 uploadVideo,
15 viewVideo
16} from '@shared/extra-utils' 13} from '@shared/extra-utils'
17import { ServerHookName, VideoPlaylistPrivacy, VideoPrivacy } from '@shared/models' 14import { ServerHookName, VideoPlaylistPrivacy, VideoPrivacy } from '@shared/models'
18 15
@@ -52,20 +49,20 @@ describe('Test plugin action hooks', function () {
52 describe('Videos hooks', function () { 49 describe('Videos hooks', function () {
53 50
54 it('Should run action:api.video.uploaded', async function () { 51 it('Should run action:api.video.uploaded', async function () {
55 const res = await uploadVideo(servers[0].url, servers[0].accessToken, { name: 'video' }) 52 const { uuid } = await servers[0].videosCommand.upload({ attributes: { name: 'video' } })
56 videoUUID = res.body.video.uuid 53 videoUUID = uuid
57 54
58 await checkHook('action:api.video.uploaded') 55 await checkHook('action:api.video.uploaded')
59 }) 56 })
60 57
61 it('Should run action:api.video.updated', async function () { 58 it('Should run action:api.video.updated', async function () {
62 await updateVideo(servers[0].url, servers[0].accessToken, videoUUID, { name: 'video updated' }) 59 await servers[0].videosCommand.update({ id: videoUUID, attributes: { name: 'video updated' } })
63 60
64 await checkHook('action:api.video.updated') 61 await checkHook('action:api.video.updated')
65 }) 62 })
66 63
67 it('Should run action:api.video.viewed', async function () { 64 it('Should run action:api.video.viewed', async function () {
68 await viewVideo(servers[0].url, videoUUID) 65 await servers[0].videosCommand.view({ id: videoUUID })
69 66
70 await checkHook('action:api.video.viewed') 67 await checkHook('action:api.video.viewed')
71 }) 68 })
@@ -170,8 +167,8 @@ describe('Test plugin action hooks', function () {
170 } 167 }
171 168
172 { 169 {
173 const res = await uploadVideo(servers[0].url, servers[0].accessToken, { name: 'my super name' }) 170 const { id } = await servers[0].videosCommand.upload({ attributes: { name: 'my super name' } })
174 videoId = res.body.video.id 171 videoId = id
175 } 172 }
176 }) 173 })
177 174
diff --git a/server/tests/plugins/filter-hooks.ts b/server/tests/plugins/filter-hooks.ts
index c82025f6a..e82aa3bfb 100644
--- a/server/tests/plugins/filter-hooks.ts
+++ b/server/tests/plugins/filter-hooks.ts
@@ -7,22 +7,12 @@ import {
7 cleanupTests, 7 cleanupTests,
8 doubleFollow, 8 doubleFollow,
9 flushAndRunMultipleServers, 9 flushAndRunMultipleServers,
10 getAccountVideos,
11 getMyVideos,
12 getVideo,
13 getVideoChannelVideos,
14 getVideosList,
15 getVideosListPagination,
16 getVideoWithToken,
17 ImportsCommand, 10 ImportsCommand,
18 makeRawRequest, 11 makeRawRequest,
19 PluginsCommand, 12 PluginsCommand,
20 ServerInfo, 13 ServerInfo,
21 setAccessTokensToServers, 14 setAccessTokensToServers,
22 setDefaultVideoChannel, 15 setDefaultVideoChannel,
23 updateVideo,
24 uploadVideo,
25 uploadVideoAndGetId,
26 waitJobs 16 waitJobs
27} from '@shared/extra-utils' 17} from '@shared/extra-utils'
28import { VideoDetails, VideoImportState, VideoPlaylist, VideoPlaylistPrivacy, VideoPrivacy } from '@shared/models' 18import { VideoDetails, VideoImportState, VideoPlaylist, VideoPlaylistPrivacy, VideoPrivacy } from '@shared/models'
@@ -46,11 +36,11 @@ describe('Test plugin filter hooks', function () {
46 await servers[0].pluginsCommand.install({ path: PluginsCommand.getPluginTestPath('-filter-translations') }) 36 await servers[0].pluginsCommand.install({ path: PluginsCommand.getPluginTestPath('-filter-translations') })
47 37
48 for (let i = 0; i < 10; i++) { 38 for (let i = 0; i < 10; i++) {
49 await uploadVideo(servers[0].url, servers[0].accessToken, { name: 'default video ' + i }) 39 await servers[0].videosCommand.upload({ attributes: { name: 'default video ' + i } })
50 } 40 }
51 41
52 const res = await getVideosList(servers[0].url) 42 const { data } = await servers[0].videosCommand.list()
53 videoUUID = res.body.data[0].uuid 43 videoUUID = data[0].uuid
54 44
55 await servers[0].configCommand.updateCustomSubConfig({ 45 await servers[0].configCommand.updateCustomSubConfig({
56 newConfig: { 46 newConfig: {
@@ -67,69 +57,68 @@ describe('Test plugin filter hooks', function () {
67 }) 57 })
68 58
69 it('Should run filter:api.videos.list.params', async function () { 59 it('Should run filter:api.videos.list.params', async function () {
70 const res = await getVideosListPagination(servers[0].url, 0, 2) 60 const { data } = await servers[0].videosCommand.list({ start: 0, count: 2 })
71 61
72 // 2 plugins do +1 to the count parameter 62 // 2 plugins do +1 to the count parameter
73 expect(res.body.data).to.have.lengthOf(4) 63 expect(data).to.have.lengthOf(4)
74 }) 64 })
75 65
76 it('Should run filter:api.videos.list.result', async function () { 66 it('Should run filter:api.videos.list.result', async function () {
77 const res = await getVideosListPagination(servers[0].url, 0, 0) 67 const { total } = await servers[0].videosCommand.list({ start: 0, count: 0 })
78 68
79 // Plugin do +1 to the total result 69 // Plugin do +1 to the total result
80 expect(res.body.total).to.equal(11) 70 expect(total).to.equal(11)
81 }) 71 })
82 72
83 it('Should run filter:api.accounts.videos.list.params', async function () { 73 it('Should run filter:api.accounts.videos.list.params', async function () {
84 const res = await getAccountVideos(servers[0].url, servers[0].accessToken, 'root', 0, 2) 74 const { data } = await servers[0].videosCommand.listByAccount({ accountName: 'root', start: 0, count: 2 })
85 75
86 // 1 plugin do +1 to the count parameter 76 // 1 plugin do +1 to the count parameter
87 expect(res.body.data).to.have.lengthOf(3) 77 expect(data).to.have.lengthOf(3)
88 }) 78 })
89 79
90 it('Should run filter:api.accounts.videos.list.result', async function () { 80 it('Should run filter:api.accounts.videos.list.result', async function () {
91 const res = await getAccountVideos(servers[0].url, servers[0].accessToken, 'root', 0, 2) 81 const { total } = await servers[0].videosCommand.listByAccount({ accountName: 'root', start: 0, count: 2 })
92 82
93 // Plugin do +2 to the total result 83 // Plugin do +2 to the total result
94 expect(res.body.total).to.equal(12) 84 expect(total).to.equal(12)
95 }) 85 })
96 86
97 it('Should run filter:api.video-channels.videos.list.params', async function () { 87 it('Should run filter:api.video-channels.videos.list.params', async function () {
98 const res = await getVideoChannelVideos(servers[0].url, servers[0].accessToken, 'root_channel', 0, 2) 88 const { data } = await servers[0].videosCommand.listByChannel({ videoChannelName: 'root_channel', start: 0, count: 2 })
99 89
100 // 1 plugin do +3 to the count parameter 90 // 1 plugin do +3 to the count parameter
101 expect(res.body.data).to.have.lengthOf(5) 91 expect(data).to.have.lengthOf(5)
102 }) 92 })
103 93
104 it('Should run filter:api.video-channels.videos.list.result', async function () { 94 it('Should run filter:api.video-channels.videos.list.result', async function () {
105 const res = await getVideoChannelVideos(servers[0].url, servers[0].accessToken, 'root_channel', 0, 2) 95 const { total } = await servers[0].videosCommand.listByChannel({ videoChannelName: 'root_channel', start: 0, count: 2 })
106 96
107 // Plugin do +3 to the total result 97 // Plugin do +3 to the total result
108 expect(res.body.total).to.equal(13) 98 expect(total).to.equal(13)
109 }) 99 })
110 100
111 it('Should run filter:api.user.me.videos.list.params', async function () { 101 it('Should run filter:api.user.me.videos.list.params', async function () {
112 const res = await getMyVideos(servers[0].url, servers[0].accessToken, 0, 2) 102 const { data } = await servers[0].videosCommand.listMyVideos({ start: 0, count: 2 })
113 103
114 // 1 plugin do +4 to the count parameter 104 // 1 plugin do +4 to the count parameter
115 expect(res.body.data).to.have.lengthOf(6) 105 expect(data).to.have.lengthOf(6)
116 }) 106 })
117 107
118 it('Should run filter:api.user.me.videos.list.result', async function () { 108 it('Should run filter:api.user.me.videos.list.result', async function () {
119 const res = await getMyVideos(servers[0].url, servers[0].accessToken, 0, 2) 109 const { total } = await servers[0].videosCommand.listMyVideos({ start: 0, count: 2 })
120 110
121 // Plugin do +4 to the total result 111 // Plugin do +4 to the total result
122 expect(res.body.total).to.equal(14) 112 expect(total).to.equal(14)
123 }) 113 })
124 114
125 it('Should run filter:api.video.get.result', async function () { 115 it('Should run filter:api.video.get.result', async function () {
126 const res = await getVideo(servers[0].url, videoUUID) 116 const video = await servers[0].videosCommand.get({ id: videoUUID })
127 117 expect(video.name).to.contain('<3')
128 expect(res.body.name).to.contain('<3')
129 }) 118 })
130 119
131 it('Should run filter:api.video.upload.accept.result', async function () { 120 it('Should run filter:api.video.upload.accept.result', async function () {
132 await uploadVideo(servers[0].url, servers[0].accessToken, { name: 'video with bad word' }, HttpStatusCode.FORBIDDEN_403) 121 await servers[0].videosCommand.upload({ attributes: { name: 'video with bad word' }, expectedStatus: HttpStatusCode.FORBIDDEN_403 })
133 }) 122 })
134 123
135 it('Should run filter:api.live-video.create.accept.result', async function () { 124 it('Should run filter:api.live-video.create.accept.result', async function () {
@@ -270,14 +259,13 @@ describe('Test plugin filter hooks', function () {
270 describe('Should run filter:video.auto-blacklist.result', function () { 259 describe('Should run filter:video.auto-blacklist.result', function () {
271 260
272 async function checkIsBlacklisted (id: number | string, value: boolean) { 261 async function checkIsBlacklisted (id: number | string, value: boolean) {
273 const res = await getVideoWithToken(servers[0].url, servers[0].accessToken, id) 262 const video = await servers[0].videosCommand.getWithToken({ id })
274 const video: VideoDetails = res.body
275 expect(video.blacklisted).to.equal(value) 263 expect(video.blacklisted).to.equal(value)
276 } 264 }
277 265
278 it('Should blacklist on upload', async function () { 266 it('Should blacklist on upload', async function () {
279 const res = await uploadVideo(servers[0].url, servers[0].accessToken, { name: 'video please blacklist me' }) 267 const { uuid } = await servers[0].videosCommand.upload({ attributes: { name: 'video please blacklist me' } })
280 await checkIsBlacklisted(res.body.video.uuid, true) 268 await checkIsBlacklisted(uuid, true)
281 }) 269 })
282 270
283 it('Should blacklist on import', async function () { 271 it('Should blacklist on import', async function () {
@@ -293,36 +281,34 @@ describe('Test plugin filter hooks', function () {
293 }) 281 })
294 282
295 it('Should blacklist on update', async function () { 283 it('Should blacklist on update', async function () {
296 const res = await uploadVideo(servers[0].url, servers[0].accessToken, { name: 'video' }) 284 const { uuid } = await servers[0].videosCommand.upload({ attributes: { name: 'video' } })
297 const videoId = res.body.video.uuid 285 await checkIsBlacklisted(uuid, false)
298 await checkIsBlacklisted(videoId, false)
299 286
300 await updateVideo(servers[0].url, servers[0].accessToken, videoId, { name: 'please blacklist me' }) 287 await servers[0].videosCommand.update({ id: uuid, attributes: { name: 'please blacklist me' } })
301 await checkIsBlacklisted(videoId, true) 288 await checkIsBlacklisted(uuid, true)
302 }) 289 })
303 290
304 it('Should blacklist on remote upload', async function () { 291 it('Should blacklist on remote upload', async function () {
305 this.timeout(120000) 292 this.timeout(120000)
306 293
307 const res = await uploadVideo(servers[1].url, servers[1].accessToken, { name: 'remote please blacklist me' }) 294 const { uuid } = await servers[1].videosCommand.upload({ attributes: { name: 'remote please blacklist me' } })
308 await waitJobs(servers) 295 await waitJobs(servers)
309 296
310 await checkIsBlacklisted(res.body.video.uuid, true) 297 await checkIsBlacklisted(uuid, true)
311 }) 298 })
312 299
313 it('Should blacklist on remote update', async function () { 300 it('Should blacklist on remote update', async function () {
314 this.timeout(120000) 301 this.timeout(120000)
315 302
316 const res = await uploadVideo(servers[1].url, servers[1].accessToken, { name: 'video' }) 303 const { uuid } = await servers[1].videosCommand.upload({ attributes: { name: 'video' } })
317 await waitJobs(servers) 304 await waitJobs(servers)
318 305
319 const videoId = res.body.video.uuid 306 await checkIsBlacklisted(uuid, false)
320 await checkIsBlacklisted(videoId, false)
321 307
322 await updateVideo(servers[1].url, servers[1].accessToken, videoId, { name: 'please blacklist me' }) 308 await servers[1].videosCommand.update({ id: uuid, attributes: { name: 'please blacklist me' } })
323 await waitJobs(servers) 309 await waitJobs(servers)
324 310
325 await checkIsBlacklisted(videoId, true) 311 await checkIsBlacklisted(uuid, true)
326 }) 312 })
327 }) 313 })
328 314
@@ -370,15 +356,14 @@ describe('Test plugin filter hooks', function () {
370 const uuids: string[] = [] 356 const uuids: string[] = []
371 357
372 for (const name of [ 'bad torrent', 'bad file', 'bad playlist file' ]) { 358 for (const name of [ 'bad torrent', 'bad file', 'bad playlist file' ]) {
373 const uuid = (await uploadVideoAndGetId({ server: servers[0], videoName: name })).uuid 359 const uuid = (await servers[0].videosCommand.quickUpload({ name: name })).uuid
374 uuids.push(uuid) 360 uuids.push(uuid)
375 } 361 }
376 362
377 await waitJobs(servers) 363 await waitJobs(servers)
378 364
379 for (const uuid of uuids) { 365 for (const uuid of uuids) {
380 const res = await getVideo(servers[0].url, uuid) 366 downloadVideos.push(await servers[0].videosCommand.get({ id: uuid }))
381 downloadVideos.push(res.body)
382 } 367 }
383 }) 368 })
384 369
@@ -428,9 +413,8 @@ describe('Test plugin filter hooks', function () {
428 413
429 for (const name of [ 'bad embed', 'good embed' ]) { 414 for (const name of [ 'bad embed', 'good embed' ]) {
430 { 415 {
431 const uuid = (await uploadVideoAndGetId({ server: servers[0], videoName: name })).uuid 416 const uuid = (await servers[0].videosCommand.quickUpload({ name: name })).uuid
432 const res = await getVideo(servers[0].url, uuid) 417 embedVideos.push(await servers[0].videosCommand.get({ id: uuid }))
433 embedVideos.push(res.body)
434 } 418 }
435 419
436 { 420 {
diff --git a/server/tests/plugins/plugin-helpers.ts b/server/tests/plugins/plugin-helpers.ts
index cbb6887eb..509aba13d 100644
--- a/server/tests/plugins/plugin-helpers.ts
+++ b/server/tests/plugins/plugin-helpers.ts
@@ -8,15 +8,11 @@ import {
8 cleanupTests, 8 cleanupTests,
9 doubleFollow, 9 doubleFollow,
10 flushAndRunMultipleServers, 10 flushAndRunMultipleServers,
11 getVideo,
12 getVideosList,
13 makeGetRequest, 11 makeGetRequest,
14 makePostBodyRequest, 12 makePostBodyRequest,
15 PluginsCommand, 13 PluginsCommand,
16 ServerInfo, 14 ServerInfo,
17 setAccessTokensToServers, 15 setAccessTokensToServers,
18 uploadVideoAndGetId,
19 viewVideo,
20 waitJobs 16 waitJobs
21} from '@shared/extra-utils' 17} from '@shared/extra-utils'
22 18
@@ -144,59 +140,54 @@ describe('Test plugin helpers', function () {
144 this.timeout(60000) 140 this.timeout(60000)
145 141
146 { 142 {
147 const res = await uploadVideoAndGetId({ server: servers[0], videoName: 'video server 1' }) 143 const res = await await servers[0].videosCommand.quickUpload({ name: 'video server 1' })
148 videoUUIDServer1 = res.uuid 144 videoUUIDServer1 = res.uuid
149 } 145 }
150 146
151 { 147 {
152 await uploadVideoAndGetId({ server: servers[1], videoName: 'video server 2' }) 148 await await servers[1].videosCommand.quickUpload({ name: 'video server 2' })
153 } 149 }
154 150
155 await waitJobs(servers) 151 await waitJobs(servers)
156 152
157 const res = await getVideosList(servers[0].url) 153 const { data } = await servers[0].videosCommand.list()
158 const videos = res.body.data
159 154
160 expect(videos).to.have.lengthOf(2) 155 expect(data).to.have.lengthOf(2)
161 }) 156 })
162 157
163 it('Should mute server 2', async function () { 158 it('Should mute server 2', async function () {
164 this.timeout(10000) 159 this.timeout(10000)
165 await postCommand(servers[0], 'blockServer', { hostToBlock: `localhost:${servers[1].port}` }) 160 await postCommand(servers[0], 'blockServer', { hostToBlock: `localhost:${servers[1].port}` })
166 161
167 const res = await getVideosList(servers[0].url) 162 const { data } = await servers[0].videosCommand.list()
168 const videos = res.body.data
169 163
170 expect(videos).to.have.lengthOf(1) 164 expect(data).to.have.lengthOf(1)
171 expect(videos[0].name).to.equal('video server 1') 165 expect(data[0].name).to.equal('video server 1')
172 }) 166 })
173 167
174 it('Should unmute server 2', async function () { 168 it('Should unmute server 2', async function () {
175 await postCommand(servers[0], 'unblockServer', { hostToUnblock: `localhost:${servers[1].port}` }) 169 await postCommand(servers[0], 'unblockServer', { hostToUnblock: `localhost:${servers[1].port}` })
176 170
177 const res = await getVideosList(servers[0].url) 171 const { data } = await servers[0].videosCommand.list()
178 const videos = res.body.data
179 172
180 expect(videos).to.have.lengthOf(2) 173 expect(data).to.have.lengthOf(2)
181 }) 174 })
182 175
183 it('Should mute account of server 2', async function () { 176 it('Should mute account of server 2', async function () {
184 await postCommand(servers[0], 'blockAccount', { handleToBlock: `root@localhost:${servers[1].port}` }) 177 await postCommand(servers[0], 'blockAccount', { handleToBlock: `root@localhost:${servers[1].port}` })
185 178
186 const res = await getVideosList(servers[0].url) 179 const { data } = await servers[0].videosCommand.list()
187 const videos = res.body.data
188 180
189 expect(videos).to.have.lengthOf(1) 181 expect(data).to.have.lengthOf(1)
190 expect(videos[0].name).to.equal('video server 1') 182 expect(data[0].name).to.equal('video server 1')
191 }) 183 })
192 184
193 it('Should unmute account of server 2', async function () { 185 it('Should unmute account of server 2', async function () {
194 await postCommand(servers[0], 'unblockAccount', { handleToUnblock: `root@localhost:${servers[1].port}` }) 186 await postCommand(servers[0], 'unblockAccount', { handleToUnblock: `root@localhost:${servers[1].port}` })
195 187
196 const res = await getVideosList(servers[0].url) 188 const { data } = await servers[0].videosCommand.list()
197 const videos = res.body.data
198 189
199 expect(videos).to.have.lengthOf(2) 190 expect(data).to.have.lengthOf(2)
200 }) 191 })
201 192
202 it('Should blacklist video', async function () { 193 it('Should blacklist video', async function () {
@@ -207,11 +198,10 @@ describe('Test plugin helpers', function () {
207 await waitJobs(servers) 198 await waitJobs(servers)
208 199
209 for (const server of servers) { 200 for (const server of servers) {
210 const res = await getVideosList(server.url) 201 const { data } = await server.videosCommand.list()
211 const videos = res.body.data
212 202
213 expect(videos).to.have.lengthOf(1) 203 expect(data).to.have.lengthOf(1)
214 expect(videos[0].name).to.equal('video server 2') 204 expect(data[0].name).to.equal('video server 2')
215 } 205 }
216 }) 206 })
217 207
@@ -223,10 +213,9 @@ describe('Test plugin helpers', function () {
223 await waitJobs(servers) 213 await waitJobs(servers)
224 214
225 for (const server of servers) { 215 for (const server of servers) {
226 const res = await getVideosList(server.url) 216 const { data } = await server.videosCommand.list()
227 const videos = res.body.data
228 217
229 expect(videos).to.have.lengthOf(2) 218 expect(data).to.have.lengthOf(2)
230 } 219 }
231 }) 220 })
232 }) 221 })
@@ -235,7 +224,7 @@ describe('Test plugin helpers', function () {
235 let videoUUID: string 224 let videoUUID: string
236 225
237 before(async () => { 226 before(async () => {
238 const res = await uploadVideoAndGetId({ server: servers[0], videoName: 'video1' }) 227 const res = await await servers[0].videosCommand.quickUpload({ name: 'video1' })
239 videoUUID = res.uuid 228 videoUUID = res.uuid
240 }) 229 })
241 230
@@ -243,15 +232,15 @@ describe('Test plugin helpers', function () {
243 this.timeout(40000) 232 this.timeout(40000)
244 233
245 // Should not throw -> video exists 234 // Should not throw -> video exists
246 await getVideo(servers[0].url, videoUUID) 235 await servers[0].videosCommand.get({ id: videoUUID })
247 // Should delete the video 236 // Should delete the video
248 await viewVideo(servers[0].url, videoUUID) 237 await servers[0].videosCommand.view({ id: videoUUID })
249 238
250 await servers[0].serversCommand.waitUntilLog('Video deleted by plugin four.') 239 await servers[0].serversCommand.waitUntilLog('Video deleted by plugin four.')
251 240
252 try { 241 try {
253 // Should throw because the video should have been deleted 242 // Should throw because the video should have been deleted
254 await getVideo(servers[0].url, videoUUID) 243 await servers[0].videosCommand.get({ id: videoUUID })
255 throw new Error('Video exists') 244 throw new Error('Video exists')
256 } catch (err) { 245 } catch (err) {
257 if (err.message.includes('exists')) throw err 246 if (err.message.includes('exists')) throw err
diff --git a/server/tests/plugins/plugin-transcoding.ts b/server/tests/plugins/plugin-transcoding.ts
index 4839e8792..a3613293a 100644
--- a/server/tests/plugins/plugin-transcoding.ts
+++ b/server/tests/plugins/plugin-transcoding.ts
@@ -7,16 +7,14 @@ import { getAudioStream, getVideoFileFPS, getVideoStreamFromFile } from '@server
7import { 7import {
8 cleanupTests, 8 cleanupTests,
9 flushAndRunServer, 9 flushAndRunServer,
10 getVideo,
11 PluginsCommand, 10 PluginsCommand,
12 ServerInfo, 11 ServerInfo,
13 setAccessTokensToServers, 12 setAccessTokensToServers,
14 setDefaultVideoChannel, 13 setDefaultVideoChannel,
15 testFfmpegStreamError, 14 testFfmpegStreamError,
16 uploadVideoAndGetId,
17 waitJobs 15 waitJobs
18} from '@shared/extra-utils' 16} from '@shared/extra-utils'
19import { VideoDetails, VideoPrivacy } from '@shared/models' 17import { VideoPrivacy } from '@shared/models'
20 18
21async function createLiveWrapper (server: ServerInfo) { 19async function createLiveWrapper (server: ServerInfo) {
22 const liveAttributes = { 20 const liveAttributes = {
@@ -81,8 +79,7 @@ describe('Test transcoding plugins', function () {
81 describe('When using a plugin adding profiles to existing encoders', function () { 79 describe('When using a plugin adding profiles to existing encoders', function () {
82 80
83 async function checkVideoFPS (uuid: string, type: 'above' | 'below', fps: number) { 81 async function checkVideoFPS (uuid: string, type: 'above' | 'below', fps: number) {
84 const res = await getVideo(server.url, uuid) 82 const video = await server.videosCommand.get({ id: uuid })
85 const video = res.body as VideoDetails
86 const files = video.files.concat(...video.streamingPlaylists.map(p => p.files)) 83 const files = video.files.concat(...video.streamingPlaylists.map(p => p.files))
87 84
88 for (const file of files) { 85 for (const file of files) {
@@ -119,7 +116,7 @@ describe('Test transcoding plugins', function () {
119 it('Should not use the plugin profile if not chosen by the admin', async function () { 116 it('Should not use the plugin profile if not chosen by the admin', async function () {
120 this.timeout(240000) 117 this.timeout(240000)
121 118
122 const videoUUID = (await uploadVideoAndGetId({ server, videoName: 'video' })).uuid 119 const videoUUID = (await server.videosCommand.quickUpload({ name: 'video' })).uuid
123 await waitJobs([ server ]) 120 await waitJobs([ server ])
124 121
125 await checkVideoFPS(videoUUID, 'above', 20) 122 await checkVideoFPS(videoUUID, 'above', 20)
@@ -130,7 +127,7 @@ describe('Test transcoding plugins', function () {
130 127
131 await updateConf(server, 'low-vod', 'default') 128 await updateConf(server, 'low-vod', 'default')
132 129
133 const videoUUID = (await uploadVideoAndGetId({ server, videoName: 'video' })).uuid 130 const videoUUID = (await server.videosCommand.quickUpload({ name: 'video' })).uuid
134 await waitJobs([ server ]) 131 await waitJobs([ server ])
135 132
136 await checkVideoFPS(videoUUID, 'below', 12) 133 await checkVideoFPS(videoUUID, 'below', 12)
@@ -141,7 +138,7 @@ describe('Test transcoding plugins', function () {
141 138
142 await updateConf(server, 'input-options-vod', 'default') 139 await updateConf(server, 'input-options-vod', 'default')
143 140
144 const videoUUID = (await uploadVideoAndGetId({ server, videoName: 'video' })).uuid 141 const videoUUID = (await server.videosCommand.quickUpload({ name: 'video' })).uuid
145 await waitJobs([ server ]) 142 await waitJobs([ server ])
146 143
147 await checkVideoFPS(videoUUID, 'below', 6) 144 await checkVideoFPS(videoUUID, 'below', 6)
@@ -152,13 +149,11 @@ describe('Test transcoding plugins', function () {
152 149
153 await updateConf(server, 'bad-scale-vod', 'default') 150 await updateConf(server, 'bad-scale-vod', 'default')
154 151
155 const videoUUID = (await uploadVideoAndGetId({ server, videoName: 'video' })).uuid 152 const videoUUID = (await server.videosCommand.quickUpload({ name: 'video' })).uuid
156 await waitJobs([ server ]) 153 await waitJobs([ server ])
157 154
158 // Transcoding failed 155 // Transcoding failed
159 const res = await getVideo(server.url, videoUUID) 156 const video = await server.videosCommand.get({ id: videoUUID })
160 const video: VideoDetails = res.body
161
162 expect(video.files).to.have.lengthOf(1) 157 expect(video.files).to.have.lengthOf(1)
163 expect(video.streamingPlaylists).to.have.lengthOf(0) 158 expect(video.streamingPlaylists).to.have.lengthOf(0)
164 }) 159 })
@@ -224,7 +219,7 @@ describe('Test transcoding plugins', function () {
224 expect(config.transcoding.availableProfiles).to.deep.equal([ 'default' ]) 219 expect(config.transcoding.availableProfiles).to.deep.equal([ 'default' ])
225 expect(config.live.transcoding.availableProfiles).to.deep.equal([ 'default' ]) 220 expect(config.live.transcoding.availableProfiles).to.deep.equal([ 'default' ])
226 221
227 const videoUUID = (await uploadVideoAndGetId({ server, videoName: 'video' })).uuid 222 const videoUUID = (await server.videosCommand.quickUpload({ name: 'video' })).uuid
228 await waitJobs([ server ]) 223 await waitJobs([ server ])
229 224
230 await checkVideoFPS(videoUUID, 'above', 20) 225 await checkVideoFPS(videoUUID, 'above', 20)
@@ -243,7 +238,7 @@ describe('Test transcoding plugins', function () {
243 it('Should use the new vod encoders', async function () { 238 it('Should use the new vod encoders', async function () {
244 this.timeout(240000) 239 this.timeout(240000)
245 240
246 const videoUUID = (await uploadVideoAndGetId({ server, videoName: 'video', fixture: 'video_short_240p.mp4' })).uuid 241 const videoUUID = (await server.videosCommand.quickUpload({ name: 'video', fixture: 'video_short_240p.mp4' })).uuid
247 await waitJobs([ server ]) 242 await waitJobs([ server ])
248 243
249 const path = server.serversCommand.buildDirectory(join('videos', videoUUID + '-240.mp4')) 244 const path = server.serversCommand.buildDirectory(join('videos', videoUUID + '-240.mp4'))
diff --git a/server/tests/plugins/video-constants.ts b/server/tests/plugins/video-constants.ts
index 4a05af042..641e37fbb 100644
--- a/server/tests/plugins/video-constants.ts
+++ b/server/tests/plugins/video-constants.ts
@@ -3,20 +3,8 @@
3import 'mocha' 3import 'mocha'
4import * as chai from 'chai' 4import * as chai from 'chai'
5import { HttpStatusCode } from '@shared/core-utils' 5import { HttpStatusCode } from '@shared/core-utils'
6import { 6import { cleanupTests, flushAndRunServer, PluginsCommand, ServerInfo, setAccessTokensToServers } from '@shared/extra-utils'
7 cleanupTests, 7import { VideoPlaylistPrivacy } from '@shared/models'
8 flushAndRunServer,
9 getVideo,
10 getVideoCategories,
11 getVideoLanguages,
12 getVideoLicences,
13 getVideoPrivacies,
14 PluginsCommand,
15 ServerInfo,
16 setAccessTokensToServers,
17 uploadVideo
18} from '@shared/extra-utils'
19import { VideoDetails, VideoPlaylistPrivacy } from '@shared/models'
20 8
21const expect = chai.expect 9const expect = chai.expect
22 10
@@ -33,8 +21,7 @@ describe('Test plugin altering video constants', function () {
33 }) 21 })
34 22
35 it('Should have updated languages', async function () { 23 it('Should have updated languages', async function () {
36 const res = await getVideoLanguages(server.url) 24 const languages = await server.videosCommand.getLanguages()
37 const languages = res.body
38 25
39 expect(languages['en']).to.not.exist 26 expect(languages['en']).to.not.exist
40 expect(languages['fr']).to.not.exist 27 expect(languages['fr']).to.not.exist
@@ -45,8 +32,7 @@ describe('Test plugin altering video constants', function () {
45 }) 32 })
46 33
47 it('Should have updated categories', async function () { 34 it('Should have updated categories', async function () {
48 const res = await getVideoCategories(server.url) 35 const categories = await server.videosCommand.getCategories()
49 const categories = res.body
50 36
51 expect(categories[1]).to.not.exist 37 expect(categories[1]).to.not.exist
52 expect(categories[2]).to.not.exist 38 expect(categories[2]).to.not.exist
@@ -56,8 +42,7 @@ describe('Test plugin altering video constants', function () {
56 }) 42 })
57 43
58 it('Should have updated licences', async function () { 44 it('Should have updated licences', async function () {
59 const res = await getVideoLicences(server.url) 45 const licences = await server.videosCommand.getLicences()
60 const licences = res.body
61 46
62 expect(licences[1]).to.not.exist 47 expect(licences[1]).to.not.exist
63 expect(licences[7]).to.not.exist 48 expect(licences[7]).to.not.exist
@@ -67,8 +52,7 @@ describe('Test plugin altering video constants', function () {
67 }) 52 })
68 53
69 it('Should have updated video privacies', async function () { 54 it('Should have updated video privacies', async function () {
70 const res = await getVideoPrivacies(server.url) 55 const privacies = await server.videosCommand.getPrivacies()
71 const privacies = res.body
72 56
73 expect(privacies[1]).to.exist 57 expect(privacies[1]).to.exist
74 expect(privacies[2]).to.not.exist 58 expect(privacies[2]).to.not.exist
@@ -85,8 +69,8 @@ describe('Test plugin altering video constants', function () {
85 }) 69 })
86 70
87 it('Should not be able to create a video with this privacy', async function () { 71 it('Should not be able to create a video with this privacy', async function () {
88 const attrs = { name: 'video', privacy: 2 } 72 const attributes = { name: 'video', privacy: 2 }
89 await uploadVideo(server.url, server.accessToken, attrs, HttpStatusCode.BAD_REQUEST_400) 73 await server.videosCommand.upload({ attributes, expectedStatus: HttpStatusCode.BAD_REQUEST_400 })
90 }) 74 })
91 75
92 it('Should not be able to create a video with this privacy', async function () { 76 it('Should not be able to create a video with this privacy', async function () {
@@ -95,12 +79,10 @@ describe('Test plugin altering video constants', function () {
95 }) 79 })
96 80
97 it('Should be able to upload a video with these values', async function () { 81 it('Should be able to upload a video with these values', async function () {
98 const attrs = { name: 'video', category: 42, licence: 42, language: 'al_bhed2' } 82 const attributes = { name: 'video', category: 42, licence: 42, language: 'al_bhed2' }
99 const resUpload = await uploadVideo(server.url, server.accessToken, attrs) 83 const { uuid } = await server.videosCommand.upload({ attributes })
100 84
101 const res = await getVideo(server.url, resUpload.body.video.uuid) 85 const video = await server.videosCommand.get({ id: uuid })
102
103 const video: VideoDetails = res.body
104 expect(video.language.label).to.equal('Al Bhed 2') 86 expect(video.language.label).to.equal('Al Bhed 2')
105 expect(video.licence.label).to.equal('Best licence') 87 expect(video.licence.label).to.equal('Best licence')
106 expect(video.category.label).to.equal('Best category') 88 expect(video.category.label).to.equal('Best category')
@@ -110,8 +92,7 @@ describe('Test plugin altering video constants', function () {
110 await server.pluginsCommand.uninstall({ npmName: 'peertube-plugin-test-video-constants' }) 92 await server.pluginsCommand.uninstall({ npmName: 'peertube-plugin-test-video-constants' })
111 93
112 { 94 {
113 const res = await getVideoLanguages(server.url) 95 const languages = await server.videosCommand.getLanguages()
114 const languages = res.body
115 96
116 expect(languages['en']).to.equal('English') 97 expect(languages['en']).to.equal('English')
117 expect(languages['fr']).to.equal('French') 98 expect(languages['fr']).to.equal('French')
@@ -122,8 +103,7 @@ describe('Test plugin altering video constants', function () {
122 } 103 }
123 104
124 { 105 {
125 const res = await getVideoCategories(server.url) 106 const categories = await server.videosCommand.getCategories()
126 const categories = res.body
127 107
128 expect(categories[1]).to.equal('Music') 108 expect(categories[1]).to.equal('Music')
129 expect(categories[2]).to.equal('Films') 109 expect(categories[2]).to.equal('Films')
@@ -133,8 +113,7 @@ describe('Test plugin altering video constants', function () {
133 } 113 }
134 114
135 { 115 {
136 const res = await getVideoLicences(server.url) 116 const licences = await server.videosCommand.getLicences()
137 const licences = res.body
138 117
139 expect(licences[1]).to.equal('Attribution') 118 expect(licences[1]).to.equal('Attribution')
140 expect(licences[7]).to.equal('Public Domain Dedication') 119 expect(licences[7]).to.equal('Public Domain Dedication')
@@ -144,8 +123,7 @@ describe('Test plugin altering video constants', function () {
144 } 123 }
145 124
146 { 125 {
147 const res = await getVideoPrivacies(server.url) 126 const privacies = await server.videosCommand.getPrivacies()
148 const privacies = res.body
149 127
150 expect(privacies[1]).to.exist 128 expect(privacies[1]).to.exist
151 expect(privacies[2]).to.exist 129 expect(privacies[2]).to.exist