]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blob - server/tests/api/server/jobs.ts
Merge branch 'release/2.1.0' into develop
[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 * as chai from 'chai'
4 import 'mocha'
5 import { cleanupTests, ServerInfo, setAccessTokensToServers } from '../../../../shared/extra-utils/index'
6 import { doubleFollow } from '../../../../shared/extra-utils/server/follows'
7 import { getJobsList, getJobsListPaginationAndSort, waitJobs } from '../../../../shared/extra-utils/server/jobs'
8 import { flushAndRunMultipleServers } from '../../../../shared/extra-utils/server/servers'
9 import { uploadVideo } from '../../../../shared/extra-utils/videos/videos'
10 import { dateIsValid } from '../../../../shared/extra-utils/miscs/miscs'
11 import { Job } from '../../../../shared/models/server'
12
13 const expect = chai.expect
14
15 describe('Test jobs', function () {
16 let servers: ServerInfo[]
17
18 before(async function () {
19 this.timeout(30000)
20
21 servers = await flushAndRunMultipleServers(2)
22
23 await setAccessTokensToServers(servers)
24
25 // Server 1 and server 2 follow each other
26 await doubleFollow(servers[0], servers[1])
27 })
28
29 it('Should create some jobs', async function () {
30 this.timeout(60000)
31
32 await uploadVideo(servers[1].url, servers[1].accessToken, { name: 'video1' })
33 await uploadVideo(servers[1].url, servers[1].accessToken, { name: 'video2' })
34
35 await waitJobs(servers)
36 })
37
38 it('Should list jobs', async function () {
39 const res = await getJobsList(servers[1].url, servers[1].accessToken, 'completed')
40 expect(res.body.total).to.be.above(2)
41 expect(res.body.data).to.have.length.above(2)
42 })
43
44 it('Should list jobs with sort, pagination and job type', async function () {
45 {
46 const res = await getJobsListPaginationAndSort({
47 url: servers[1].url,
48 accessToken: servers[1].accessToken,
49 state: 'completed',
50 start: 1,
51 count: 2,
52 sort: 'createdAt'
53 })
54 expect(res.body.total).to.be.above(2)
55 expect(res.body.data).to.have.lengthOf(2)
56
57 let job: Job = res.body.data[0]
58 // Skip repeat jobs
59 if (job.type === 'videos-views') job = res.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 res = await getJobsListPaginationAndSort({
70 url: servers[1].url,
71 accessToken: servers[1].accessToken,
72 state: 'completed',
73 start: 0,
74 count: 100,
75 sort: 'createdAt',
76 jobType: 'activitypub-http-broadcast'
77 })
78 expect(res.body.total).to.be.above(2)
79
80 for (const j of res.body.data as Job[]) {
81 expect(j.type).to.equal('activitypub-http-broadcast')
82 }
83 }
84 })
85
86 after(async function () {
87 await cleanupTests(servers)
88 })
89 })