1 /* tslint:disable:no-unused-expression */
3 import * as chai from 'chai'
5 import { flushTests, killallServers, ServerInfo, setAccessTokensToServers, wait } from '../utils'
6 import { doubleFollow } from '../utils/follows'
7 import { getJobsList, getJobsListPaginationAndSort } from '../utils/jobs'
8 import { flushAndRunMultipleServers } from '../utils/servers'
9 import { uploadVideo } from '../utils/videos'
10 import { dateIsValid } from '../utils/miscs'
12 const expect = chai.expect
14 describe('Test jobs', function () {
15 let servers: ServerInfo[]
17 before(async function () {
20 servers = await flushAndRunMultipleServers(2)
22 await setAccessTokensToServers(servers)
24 // Server 1 and server 2 follow each other
25 await doubleFollow(servers[0], servers[1])
28 it('Should create some jobs', async function () {
31 await uploadVideo(servers[1].url, servers[1].accessToken, { name: 'video1' })
32 await uploadVideo(servers[1].url, servers[1].accessToken, { name: 'video2' })
37 it('Should list jobs', async function () {
38 const res = await getJobsList(servers[1].url, servers[1].accessToken)
39 expect(res.body.total).to.be.above(2)
40 expect(res.body.data).to.have.length.above(2)
43 it('Should list jobs with sort and pagination', async function () {
44 const res = await getJobsListPaginationAndSort(servers[1].url, servers[1].accessToken, 4, 1, 'createdAt')
45 expect(res.body.total).to.be.above(2)
46 expect(res.body.data).to.have.lengthOf(1)
48 const job = res.body.data[0]
49 expect(job.state).to.equal('success')
50 expect(job.category).to.equal('transcoding')
51 expect(job.handlerName).to.have.length.above(3)
52 expect(dateIsValid(job.createdAt)).to.be.true
53 expect(dateIsValid(job.updatedAt)).to.be.true
56 after(async function () {
57 killallServers(servers)
59 // Keep the logs if the test failed