]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blob - server/tests/api/server/jobs.ts
Use an object to represent a server
[github/Chocobozzz/PeerTube.git] / server / tests / api / server / jobs.ts
1 /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
2
3 import 'mocha'
4 import * as chai from 'chai'
5 import {
6 cleanupTests,
7 dateIsValid,
8 doubleFollow,
9 createMultipleServers,
10 PeerTubeServer,
11 setAccessTokensToServers,
12 waitJobs
13 } from '@shared/extra-utils'
14
15 const expect = chai.expect
16
17 describe('Test jobs', function () {
18 let servers: PeerTubeServer[]
19
20 before(async function () {
21 this.timeout(30000)
22
23 servers = await createMultipleServers(2)
24
25 await setAccessTokensToServers(servers)
26
27 // Server 1 and server 2 follow each other
28 await doubleFollow(servers[0], servers[1])
29 })
30
31 it('Should create some jobs', async function () {
32 this.timeout(120000)
33
34 await servers[1].videos.upload({ attributes: { name: 'video1' } })
35 await servers[1].videos.upload({ attributes: { name: 'video2' } })
36
37 await waitJobs(servers)
38 })
39
40 it('Should list jobs', async function () {
41 const body = await servers[1].jobs.getJobsList({ state: 'completed' })
42 expect(body.total).to.be.above(2)
43 expect(body.data).to.have.length.above(2)
44 })
45
46 it('Should list jobs with sort, pagination and job type', async function () {
47 {
48 const body = await servers[1].jobs.getJobsList({
49 state: 'completed',
50 start: 1,
51 count: 2,
52 sort: 'createdAt'
53 })
54 expect(body.total).to.be.above(2)
55 expect(body.data).to.have.lengthOf(2)
56
57 let job = body.data[0]
58 // Skip repeat jobs
59 if (job.type === 'videos-views') job = body.data[1]
60
61 expect(job.state).to.equal('completed')
62 expect(job.type.startsWith('activitypub-')).to.be.true
63 expect(dateIsValid(job.createdAt as string)).to.be.true
64 expect(dateIsValid(job.processedOn as string)).to.be.true
65 expect(dateIsValid(job.finishedOn as string)).to.be.true
66 }
67
68 {
69 const body = await servers[1].jobs.getJobsList({
70 state: 'completed',
71 start: 0,
72 count: 100,
73 sort: 'createdAt',
74 jobType: 'activitypub-http-broadcast'
75 })
76 expect(body.total).to.be.above(2)
77
78 for (const j of body.data) {
79 expect(j.type).to.equal('activitypub-http-broadcast')
80 }
81 }
82 })
83
84 it('Should list all jobs', async function () {
85 const body = await servers[1].jobs.getJobsList()
86 expect(body.total).to.be.above(2)
87
88 const jobs = body.data
89 expect(jobs).to.have.length.above(2)
90
91 // We know there are a least 1 delayed job (video views) and 1 completed job (broadcast)
92 expect(jobs.find(j => j.state === 'delayed')).to.not.be.undefined
93 expect(jobs.find(j => j.state === 'completed')).to.not.be.undefined
94 })
95
96 after(async function () {
97 await cleanupTests(servers)
98 })
99 })