aboutsummaryrefslogblamecommitdiffhomepage
path: root/server/tests/api/check-params/runners.ts
blob: 4da6fd91d1f1f23a1766690429c9c7a3a03edea0 (plain) (tree)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702





























































































































































































































































































































































































































































































































































































































































































































                                                                                                                                           
/* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
import { checkBadCountPagination, checkBadSortPagination, checkBadStartPagination } from '@server/tests/shared'
import { HttpStatusCode, RunnerJob, RunnerJobState, RunnerJobSuccessPayload, RunnerJobUpdatePayload, VideoPrivacy } from '@shared/models'
import {
  cleanupTests,
  createSingleServer,
  makePostBodyRequest,
  PeerTubeServer,
  sendRTMPStream,
  setAccessTokensToServers,
  setDefaultVideoChannel,
  stopFfmpeg,
  waitJobs
} from '@shared/server-commands'

const badUUID = '910ec12a-d9e6-458b-a274-0abb655f9464'

describe('Test managing runners', function () {
  let server: PeerTubeServer

  let userToken: string

  let registrationTokenId: number
  let registrationToken: string

  let runnerToken: string
  let runnerToken2: string

  let completedJobToken: string
  let completedJobUUID: string

  let cancelledJobUUID: string

  before(async function () {
    this.timeout(120000)

    const config = {
      rates_limit: {
        api: {
          max: 5000
        }
      }
    }

    server = await createSingleServer(1, config)
    await setAccessTokensToServers([ server ])
    await setDefaultVideoChannel([ server ])

    userToken = await server.users.generateUserAndToken('user1')

    const { data } = await server.runnerRegistrationTokens.list()
    registrationToken = data[0].registrationToken
    registrationTokenId = data[0].id

    await server.config.enableTranscoding(true, true)
    await server.config.enableRemoteTranscoding()
    runnerToken = await server.runners.autoRegisterRunner()
    runnerToken2 = await server.runners.autoRegisterRunner()

    {
      await server.videos.quickUpload({ name: 'video 1' })
      await server.videos.quickUpload({ name: 'video 2' })

      await waitJobs([ server ])

      {
        const job = await server.runnerJobs.autoProcessWebVideoJob(runnerToken)
        completedJobToken = job.jobToken
        completedJobUUID = job.uuid
      }

      {
        const { job } = await server.runnerJobs.autoAccept({ runnerToken })
        cancelledJobUUID = job.uuid
        await server.runnerJobs.cancelByAdmin({ jobUUID: cancelledJobUUID })
      }
    }
  })

  describe('Managing runner registration tokens', function () {

    describe('Common', function () {

      it('Should fail to generate, list or delete runner registration token without oauth token', async function () {
        const expectedStatus = HttpStatusCode.UNAUTHORIZED_401

        await server.runnerRegistrationTokens.generate({ token: null, expectedStatus })
        await server.runnerRegistrationTokens.list({ token: null, expectedStatus })
        await server.runnerRegistrationTokens.delete({ token: null, id: registrationTokenId, expectedStatus })
      })

      it('Should fail to generate, list or delete runner registration token without admin rights', async function () {
        const expectedStatus = HttpStatusCode.FORBIDDEN_403

        await server.runnerRegistrationTokens.generate({ token: userToken, expectedStatus })
        await server.runnerRegistrationTokens.list({ token: userToken, expectedStatus })
        await server.runnerRegistrationTokens.delete({ token: userToken, id: registrationTokenId, expectedStatus })
      })
    })

    describe('Delete', function () {

      it('Should fail to delete with a bad id', async function () {
        await server.runnerRegistrationTokens.delete({ id: 404, expectedStatus: HttpStatusCode.NOT_FOUND_404 })
      })
    })

    describe('List', function () {
      const path = '/api/v1/runners/registration-tokens'

      it('Should fail to list with a bad start pagination', async function () {
        await checkBadStartPagination(server.url, path, server.accessToken)
      })

      it('Should fail to list with a bad count pagination', async function () {
        await checkBadCountPagination(server.url, path, server.accessToken)
      })

      it('Should fail to list with an incorrect sort', async function () {
        await checkBadSortPagination(server.url, path, server.accessToken)
      })

      it('Should succeed to list with the correct params', async function () {
        await server.runnerRegistrationTokens.list({ start: 0, count: 5, sort: '-createdAt' })
      })
    })
  })

  describe('Managing runners', function () {
    let toDeleteId: number

    describe('Register', function () {
      const name = 'runner name'

      it('Should fail with a bad registration token', async function () {
        const expectedStatus = HttpStatusCode.BAD_REQUEST_400

        await server.runners.register({ name, registrationToken: 'a'.repeat(4000), expectedStatus })
        await server.runners.register({ name, registrationToken: null, expectedStatus })
      })

      it('Should fail with an unknown registration token', async function () {
        await server.runners.register({ name, registrationToken: 'aaa', expectedStatus: HttpStatusCode.NOT_FOUND_404 })
      })

      it('Should fail with a bad name', async function () {
        const expectedStatus = HttpStatusCode.BAD_REQUEST_400

        await server.runners.register({ name: '', registrationToken, expectedStatus })
        await server.runners.register({ name: 'a'.repeat(200), registrationToken, expectedStatus })
      })

      it('Should fail with an invalid description', async function () {
        const expectedStatus = HttpStatusCode.BAD_REQUEST_400

        await server.runners.register({ name, description: '', registrationToken, expectedStatus })
        await server.runners.register({ name, description: 'a'.repeat(5000), registrationToken, expectedStatus })
      })

      it('Should succeed with the correct params', async function () {
        const { id } = await server.runners.register({ name, description: 'super description', registrationToken })

        toDeleteId = id
      })
    })

    describe('Delete', function () {

      it('Should fail without oauth token', async function () {
        await server.runners.delete({ token: null, id: toDeleteId, expectedStatus: HttpStatusCode.UNAUTHORIZED_401 })
      })

      it('Should fail without admin rights', async function () {
        await server.runners.delete({ token: userToken, id: toDeleteId, expectedStatus: HttpStatusCode.FORBIDDEN_403 })
      })

      it('Should fail with a bad id', async function () {
        await server.runners.delete({ id: 'hi' as any, expectedStatus: HttpStatusCode.BAD_REQUEST_400 })
      })

      it('Should fail with an unknown id', async function () {
        await server.runners.delete({ id: 404, expectedStatus: HttpStatusCode.NOT_FOUND_404 })
      })

      it('Should succeed with the correct params', async function () {
        await server.runners.delete({ id: toDeleteId })
      })
    })

    describe('List', function () {
      const path = '/api/v1/runners'

      it('Should fail without oauth token', async function () {
        await server.runners.list({ token: null, expectedStatus: HttpStatusCode.UNAUTHORIZED_401 })
      })

      it('Should fail without admin rights', async function () {
        await server.runners.list({ token: userToken, expectedStatus: HttpStatusCode.FORBIDDEN_403 })
      })

      it('Should fail to list with a bad start pagination', async function () {
        await checkBadStartPagination(server.url, path, server.accessToken)
      })

      it('Should fail to list with a bad count pagination', async function () {
        await checkBadCountPagination(server.url, path, server.accessToken)
      })

      it('Should fail to list with an incorrect sort', async function () {
        await checkBadSortPagination(server.url, path, server.accessToken)
      })

      it('Should succeed to list with the correct params', async function () {
        await server.runners.list({ start: 0, count: 5, sort: '-createdAt' })
      })
    })

  })

  describe('Runner jobs by admin', function () {

    describe('Cancel', function () {
      let jobUUID: string

      before(async function () {
        this.timeout(60000)

        await server.videos.quickUpload({ name: 'video' })
        await waitJobs([ server ])

        const { availableJobs } = await server.runnerJobs.request({ runnerToken })
        jobUUID = availableJobs[0].uuid
      })

      it('Should fail without oauth token', async function () {
        await server.runnerJobs.cancelByAdmin({ token: null, jobUUID, expectedStatus: HttpStatusCode.UNAUTHORIZED_401 })
      })

      it('Should fail without admin rights', async function () {
        await server.runnerJobs.cancelByAdmin({ token: userToken, jobUUID, expectedStatus: HttpStatusCode.FORBIDDEN_403 })
      })

      it('Should fail with a bad job uuid', async function () {
        await server.runnerJobs.cancelByAdmin({ jobUUID: 'hello', expectedStatus: HttpStatusCode.BAD_REQUEST_400 })
      })

      it('Should fail with an unknown job uuid', async function () {
        const jobUUID = badUUID
        await server.runnerJobs.cancelByAdmin({ jobUUID, expectedStatus: HttpStatusCode.NOT_FOUND_404 })
      })

      it('Should succeed with the correct params', async function () {
        await server.runnerJobs.cancelByAdmin({ jobUUID })
      })
    })

    describe('List', function () {
      const path = '/api/v1/runners/jobs'

      it('Should fail without oauth token', async function () {
        await server.runnerJobs.list({ token: null, expectedStatus: HttpStatusCode.UNAUTHORIZED_401 })
      })

      it('Should fail without admin rights', async function () {
        await server.runnerJobs.list({ token: userToken, expectedStatus: HttpStatusCode.FORBIDDEN_403 })
      })

      it('Should fail to list with a bad start pagination', async function () {
        await checkBadStartPagination(server.url, path, server.accessToken)
      })

      it('Should fail to list with a bad count pagination', async function () {
        await checkBadCountPagination(server.url, path, server.accessToken)
      })

      it('Should fail to list with an incorrect sort', async function () {
        await checkBadSortPagination(server.url, path, server.accessToken)
      })

      it('Should succeed to list with the correct params', async function () {
        await server.runnerJobs.list({ start: 0, count: 5, sort: '-createdAt' })
      })
    })

  })

  describe('Runner jobs by runners', function () {
    let jobUUID: string
    let jobToken: string
    let videoUUID: string

    let jobUUID2: string
    let jobToken2: string

    let videoUUID2: string

    let pendingUUID: string

    let liveAcceptedJob: RunnerJob & { jobToken: string }

    async function fetchFiles (options: {
      jobUUID: string
      videoUUID: string
      runnerToken: string
      jobToken: string
      expectedStatus: HttpStatusCode
    }) {
      const { jobUUID, expectedStatus, videoUUID, runnerToken, jobToken } = options

      const basePath = '/api/v1/runners/jobs/' + jobUUID + '/files/videos/' + videoUUID
      const paths = [ `${basePath}/max-quality`, `${basePath}/previews/max-quality` ]

      for (const path of paths) {
        await makePostBodyRequest({ url: server.url, path, fields: { runnerToken, jobToken }, expectedStatus })
      }
    }

    before(async function () {
      this.timeout(120000)

      {
        await server.runnerJobs.cancelAllJobs({ state: RunnerJobState.PENDING })
      }

      {
        const { uuid } = await server.videos.quickUpload({ name: 'video' })
        videoUUID = uuid

        await waitJobs([ server ])

        const { job } = await server.runnerJobs.autoAccept({ runnerToken })
        jobUUID = job.uuid
        jobToken = job.jobToken
      }

      {
        const { uuid } = await server.videos.quickUpload({ name: 'video' })
        videoUUID2 = uuid

        await waitJobs([ server ])

        const { job } = await server.runnerJobs.autoAccept({ runnerToken: runnerToken2 })
        jobUUID2 = job.uuid
        jobToken2 = job.jobToken
      }

      {
        await server.videos.quickUpload({ name: 'video' })
        await waitJobs([ server ])

        const { availableJobs } = await server.runnerJobs.request({ runnerToken })
        pendingUUID = availableJobs[0].uuid
      }

      {
        await server.config.enableLive({
          allowReplay: false,
          resolutions: 'max',
          transcoding: true
        })

        const { live } = await server.live.quickCreate({ permanentLive: true, saveReplay: false, privacy: VideoPrivacy.PUBLIC })

        const ffmpegCommand = sendRTMPStream({ rtmpBaseUrl: live.rtmpUrl, streamKey: live.streamKey })
        await waitJobs([ server ])

        await server.runnerJobs.requestLiveJob(runnerToken)

        const { job } = await server.runnerJobs.autoAccept({ runnerToken, type: 'live-rtmp-hls-transcoding' })
        liveAcceptedJob = job

        await stopFfmpeg(ffmpegCommand)
      }
    })

    describe('Common runner tokens validations', function () {

      async function testEndpoints (options: {
        jobUUID: string
        runnerToken: string
        jobToken: string
        expectedStatus: HttpStatusCode
      }) {
        await fetchFiles({ ...options, videoUUID })

        await server.runnerJobs.abort({ ...options, reason: 'reason' })
        await server.runnerJobs.update({ ...options })
        await server.runnerJobs.error({ ...options, message: 'message' })
        await server.runnerJobs.success({ ...options, payload: { videoFile: 'video_short.mp4' } })
      }

      it('Should fail with an invalid job uuid', async function () {
        await testEndpoints({ jobUUID: 'a', runnerToken, jobToken, expectedStatus: HttpStatusCode.BAD_REQUEST_400 })
      })

      it('Should fail with an unknown job uuid', async function () {
        const jobUUID = badUUID
        await testEndpoints({ jobUUID, runnerToken, jobToken, expectedStatus: HttpStatusCode.NOT_FOUND_404 })
      })

      it('Should fail with an invalid runner token', async function () {
        await testEndpoints({ jobUUID, runnerToken: '', jobToken, expectedStatus: HttpStatusCode.BAD_REQUEST_400 })
      })

      it('Should fail with an unknown runner token', async function () {
        const runnerToken = badUUID
        await testEndpoints({ jobUUID, runnerToken, jobToken, expectedStatus: HttpStatusCode.NOT_FOUND_404 })
      })

      it('Should fail with an invalid job token job uuid', async function () {
        await testEndpoints({ jobUUID, runnerToken, jobToken: '', expectedStatus: HttpStatusCode.BAD_REQUEST_400 })
      })

      it('Should fail with an unknown job token job uuid', async function () {
        const jobToken = badUUID
        await testEndpoints({ jobUUID, runnerToken, jobToken, expectedStatus: HttpStatusCode.NOT_FOUND_404 })
      })

      it('Should fail with a runner token not associated to this job', async function () {
        await testEndpoints({ jobUUID, runnerToken: runnerToken2, jobToken, expectedStatus: HttpStatusCode.NOT_FOUND_404 })
      })

      it('Should fail with a job uuid not associated to the job token', async function () {
        await testEndpoints({ jobUUID: jobUUID2, runnerToken, jobToken, expectedStatus: HttpStatusCode.NOT_FOUND_404 })
        await testEndpoints({ jobUUID, runnerToken, jobToken: jobToken2, expectedStatus: HttpStatusCode.NOT_FOUND_404 })
      })
    })

    describe('Unregister', function () {

      it('Should fail without a runner token', async function () {
        await server.runners.unregister({ runnerToken: null, expectedStatus: HttpStatusCode.BAD_REQUEST_400 })
      })

      it('Should fail with a bad a runner token', async function () {
        await server.runners.unregister({ runnerToken: '', expectedStatus: HttpStatusCode.BAD_REQUEST_400 })
      })

      it('Should fail with an unknown runner token', async function () {
        await server.runners.unregister({ runnerToken: badUUID, expectedStatus: HttpStatusCode.NOT_FOUND_404 })
      })
    })

    describe('Request', function () {

      it('Should fail without a runner token', async function () {
        await server.runnerJobs.request({ runnerToken: null, expectedStatus: HttpStatusCode.BAD_REQUEST_400 })
      })

      it('Should fail with a bad a runner token', async function () {
        await server.runnerJobs.request({ runnerToken: '', expectedStatus: HttpStatusCode.BAD_REQUEST_400 })
      })

      it('Should fail with an unknown runner token', async function () {
        await server.runnerJobs.request({ runnerToken: badUUID, expectedStatus: HttpStatusCode.NOT_FOUND_404 })
      })
    })

    describe('Accept', function () {

      it('Should fail with a bad a job uuid', async function () {
        await server.runnerJobs.accept({ jobUUID: '', runnerToken, expectedStatus: HttpStatusCode.BAD_REQUEST_400 })
      })

      it('Should fail with an unknown job uuid', async function () {
        await server.runnerJobs.accept({ jobUUID: badUUID, runnerToken, expectedStatus: HttpStatusCode.NOT_FOUND_404 })
      })

      it('Should fail with a job not in pending state', async function () {
        await server.runnerJobs.accept({ jobUUID: completedJobUUID, runnerToken, expectedStatus: HttpStatusCode.BAD_REQUEST_400 })
        await server.runnerJobs.accept({ jobUUID: cancelledJobUUID, runnerToken, expectedStatus: HttpStatusCode.BAD_REQUEST_400 })
      })

      it('Should fail without a runner token', async function () {
        await server.runnerJobs.accept({ jobUUID: pendingUUID, runnerToken: null, expectedStatus: HttpStatusCode.BAD_REQUEST_400 })
      })

      it('Should fail with a bad a runner token', async function () {
        await server.runnerJobs.accept({ jobUUID: pendingUUID, runnerToken: '', expectedStatus: HttpStatusCode.BAD_REQUEST_400 })
      })

      it('Should fail with an unknown runner token', async function () {
        await server.runnerJobs.accept({ jobUUID: pendingUUID, runnerToken: badUUID, expectedStatus: HttpStatusCode.NOT_FOUND_404 })
      })
    })

    describe('Abort', function () {

      it('Should fail without a reason', async function () {
        await server.runnerJobs.abort({ jobUUID, jobToken, runnerToken, reason: null, expectedStatus: HttpStatusCode.BAD_REQUEST_400 })
      })

      it('Should fail with a bad reason', async function () {
        const reason = 'reason'.repeat(5000)
        await server.runnerJobs.abort({ jobUUID, jobToken, runnerToken, reason, expectedStatus: HttpStatusCode.BAD_REQUEST_400 })
      })

      it('Should fail with a job not in processing state', async function () {
        await server.runnerJobs.abort({
          jobUUID: completedJobUUID,
          jobToken: completedJobToken,
          runnerToken,
          reason: 'reason',
          expectedStatus: HttpStatusCode.BAD_REQUEST_400
        })
      })
    })

    describe('Update', function () {

      describe('Common', function () {

        it('Should fail with an invalid progress', async function () {
          await server.runnerJobs.update({ jobUUID, jobToken, runnerToken, progress: 101, expectedStatus: HttpStatusCode.BAD_REQUEST_400 })
        })

        it('Should fail with a job not in processing state', async function () {
          await server.runnerJobs.update({
            jobUUID: completedJobUUID,
            jobToken: completedJobToken,
            runnerToken,
            expectedStatus: HttpStatusCode.BAD_REQUEST_400
          })
        })
      })

      describe('Live RTMP to HLS', function () {
        const base: RunnerJobUpdatePayload = {
          masterPlaylistFile: 'live/master.m3u8',
          resolutionPlaylistFilename: '0.m3u8',
          resolutionPlaylistFile: 'live/1.m3u8',
          type: 'add-chunk',
          videoChunkFile: 'live/1-000069.ts',
          videoChunkFilename: '1-000068.ts'
        }

        function testUpdate (payload: RunnerJobUpdatePayload) {
          return server.runnerJobs.update({
            jobUUID: liveAcceptedJob.uuid,
            jobToken: liveAcceptedJob.jobToken,
            payload,
            runnerToken,
            expectedStatus: HttpStatusCode.BAD_REQUEST_400
          })
        }

        it('Should fail with an invalid resolutionPlaylistFilename', async function () {
          await testUpdate({ ...base, resolutionPlaylistFilename: undefined })
          await testUpdate({ ...base, resolutionPlaylistFilename: 'coucou/hello' })
          await testUpdate({ ...base, resolutionPlaylistFilename: 'hello' })
        })

        it('Should fail with an invalid videoChunkFilename', async function () {
          await testUpdate({ ...base, resolutionPlaylistFilename: undefined })
          await testUpdate({ ...base, resolutionPlaylistFilename: 'coucou/hello' })
          await testUpdate({ ...base, resolutionPlaylistFilename: 'hello' })
        })

        it('Should fail with an invalid type', async function () {
          await testUpdate({ ...base, type: undefined })
          await testUpdate({ ...base, type: 'toto' as any })
        })

        it('Should succeed with the correct params', async function () {
          await server.runnerJobs.update({
            jobUUID: liveAcceptedJob.uuid,
            jobToken: liveAcceptedJob.jobToken,
            payload: base,
            runnerToken
          })

          await server.runnerJobs.update({
            jobUUID: liveAcceptedJob.uuid,
            jobToken: liveAcceptedJob.jobToken,
            payload: { ...base, masterPlaylistFile: undefined },
            runnerToken
          })
        })
      })
    })

    describe('Error', function () {

      it('Should fail with a missing error message', async function () {
        await server.runnerJobs.error({ jobUUID, jobToken, runnerToken, message: null, expectedStatus: HttpStatusCode.BAD_REQUEST_400 })
      })

      it('Should fail with an invalid error messgae', async function () {
        const message = 'a'.repeat(6000)
        await server.runnerJobs.error({ jobUUID, jobToken, runnerToken, message, expectedStatus: HttpStatusCode.BAD_REQUEST_400 })
      })

      it('Should fail with a job not in processing state', async function () {
        await server.runnerJobs.error({
          jobUUID: completedJobUUID,
          jobToken: completedJobToken,
          message: 'my message',
          runnerToken,
          expectedStatus: HttpStatusCode.BAD_REQUEST_400
        })
      })
    })

    describe('Success', function () {
      let vodJobUUID: string
      let vodJobToken: string

      describe('Common', function () {

        it('Should fail with a job not in processing state', async function () {
          await server.runnerJobs.success({
            jobUUID: completedJobUUID,
            jobToken: completedJobToken,
            payload: { videoFile: 'video_short.mp4' },
            runnerToken,
            expectedStatus: HttpStatusCode.BAD_REQUEST_400
          })
        })
      })

      describe('VOD', function () {

        it('Should fail with an invalid vod web video payload', async function () {
          const { job } = await server.runnerJobs.autoAccept({ runnerToken, type: 'vod-web-video-transcoding' })

          await server.runnerJobs.success({
            jobUUID: job.uuid,
            jobToken: job.jobToken,
            payload: { hello: 'video_short.mp4' } as any,
            runnerToken,
            expectedStatus: HttpStatusCode.BAD_REQUEST_400
          })

          vodJobUUID = job.uuid
          vodJobToken = job.jobToken
        })

        it('Should fail with an invalid vod hls payload', async function () {
          // To create HLS jobs
          const payload: RunnerJobSuccessPayload = { videoFile: 'video_short.mp4' }
          await server.runnerJobs.success({ runnerToken, jobUUID: vodJobUUID, jobToken: vodJobToken, payload })

          await waitJobs([ server ])

          const { job } = await server.runnerJobs.autoAccept({ runnerToken, type: 'vod-hls-transcoding' })

          await server.runnerJobs.success({
            jobUUID: job.uuid,
            jobToken: job.jobToken,
            payload: { videoFile: 'video_short.mp4' } as any,
            runnerToken,
            expectedStatus: HttpStatusCode.BAD_REQUEST_400
          })
        })

        it('Should fail with an invalid vod audio merge payload', async function () {
          const attributes = { name: 'audio_with_preview', previewfile: 'preview.jpg', fixture: 'sample.ogg' }
          await server.videos.upload({ attributes, mode: 'legacy' })

          await waitJobs([ server ])

          const { job } = await server.runnerJobs.autoAccept({ runnerToken, type: 'vod-audio-merge-transcoding' })

          await server.runnerJobs.success({
            jobUUID: job.uuid,
            jobToken: job.jobToken,
            payload: { hello: 'video_short.mp4' } as any,
            runnerToken,
            expectedStatus: HttpStatusCode.BAD_REQUEST_400
          })
        })
      })
    })

    describe('Job files', function () {

      describe('Video files', function () {

        it('Should fail with an invalid video id', async function () {
          await fetchFiles({ videoUUID: 'a', jobUUID, runnerToken, jobToken, expectedStatus: HttpStatusCode.BAD_REQUEST_400 })
        })

        it('Should fail with an unknown video id', async function () {
          const videoUUID = '910ec12a-d9e6-458b-a274-0abb655f9464'
          await fetchFiles({ videoUUID, jobUUID, runnerToken, jobToken, expectedStatus: HttpStatusCode.NOT_FOUND_404 })
        })

        it('Should fail with a video id not associated to this job', async function () {
          await fetchFiles({ videoUUID: videoUUID2, jobUUID, runnerToken, jobToken, expectedStatus: HttpStatusCode.FORBIDDEN_403 })
        })

        it('Should succeed with the correct params', async function () {
          await fetchFiles({ videoUUID, jobUUID, runnerToken, jobToken, expectedStatus: HttpStatusCode.OK_200 })
        })
      })
    })
  })

  after(async function () {
    await cleanupTests([ server ])
  })
})