]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - server/tests/api/server/jobs.ts
Fix job tests
[github/Chocobozzz/PeerTube.git] / server / tests / api / server / jobs.ts
CommitLineData
5cd80545
C
1/* tslint:disable:no-unused-expression */
2
3import * as chai from 'chai'
4import 'mocha'
94831479 5import { killallServers, ServerInfo, setAccessTokensToServers } from '../../utils/index'
c5d31dba 6import { doubleFollow } from '../../utils/server/follows'
3cd0734f 7import { getJobsList, getJobsListPaginationAndSort, waitJobs } from '../../utils/server/jobs'
c5d31dba
C
8import { flushAndRunMultipleServers } from '../../utils/server/servers'
9import { uploadVideo } from '../../utils/videos/videos'
10import { dateIsValid } from '../../utils/miscs/miscs'
5cd80545
C
11
12const expect = chai.expect
13
14describe('Test jobs', function () {
15 let servers: ServerInfo[]
16
17 before(async function () {
18 this.timeout(30000)
19
20 servers = await flushAndRunMultipleServers(2)
21
22 await setAccessTokensToServers(servers)
23
24 // Server 1 and server 2 follow each other
25 await doubleFollow(servers[0], servers[1])
26 })
27
28 it('Should create some jobs', async function () {
29 this.timeout(30000)
30
31 await uploadVideo(servers[1].url, servers[1].accessToken, { name: 'video1' })
32 await uploadVideo(servers[1].url, servers[1].accessToken, { name: 'video2' })
33
3cd0734f 34 await waitJobs(servers)
5cd80545
C
35 })
36
37 it('Should list jobs', async function () {
94831479 38 const res = await getJobsList(servers[1].url, servers[1].accessToken, 'completed')
5cd80545
C
39 expect(res.body.total).to.be.above(2)
40 expect(res.body.data).to.have.length.above(2)
41 })
42
43 it('Should list jobs with sort and pagination', async function () {
94831479 44 const res = await getJobsListPaginationAndSort(servers[1].url, servers[1].accessToken, 'completed', 1, 1, 'createdAt')
5cd80545
C
45 expect(res.body.total).to.be.above(2)
46 expect(res.body.data).to.have.lengthOf(1)
47
48 const job = res.body.data[0]
94a5ff8a 49
94831479 50 expect(job.state).to.equal('completed')
04291e1b 51 expect(job.type).to.equal('activitypub-follow')
5cd80545 52 expect(dateIsValid(job.createdAt)).to.be.true
94831479
C
53 expect(dateIsValid(job.processedOn)).to.be.true
54 expect(dateIsValid(job.finishedOn)).to.be.true
5cd80545
C
55 })
56
57 after(async function () {
58 killallServers(servers)
5cd80545
C
59 })
60})