]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - server/tests/api/server/jobs.ts
fix missing title attribute on <iframe> tag suggested for embedding (#3901)
[github/Chocobozzz/PeerTube.git] / server / tests / api / server / jobs.ts
CommitLineData
a1587156 1/* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
5cd80545
C
2
3import * as chai from 'chai'
4import 'mocha'
a1587156 5import { cleanupTests, ServerInfo, setAccessTokensToServers } from '../../../../shared/extra-utils/index'
94565d52
C
6import { doubleFollow } from '../../../../shared/extra-utils/server/follows'
7import { getJobsList, getJobsListPaginationAndSort, waitJobs } from '../../../../shared/extra-utils/server/jobs'
8import { flushAndRunMultipleServers } from '../../../../shared/extra-utils/server/servers'
9import { uploadVideo } from '../../../../shared/extra-utils/videos/videos'
10import { dateIsValid } from '../../../../shared/extra-utils/miscs/miscs'
2284f202 11import { Job } from '../../../../shared/models/server'
5cd80545
C
12
13const expect = chai.expect
14
15describe('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 () {
b345a804 30 this.timeout(60000)
5cd80545
C
31
32 await uploadVideo(servers[1].url, servers[1].accessToken, { name: 'video1' })
33 await uploadVideo(servers[1].url, servers[1].accessToken, { name: 'video2' })
34
3cd0734f 35 await waitJobs(servers)
5cd80545
C
36 })
37
38 it('Should list jobs', async function () {
94831479 39 const res = await getJobsList(servers[1].url, servers[1].accessToken, 'completed')
5cd80545
C
40 expect(res.body.total).to.be.above(2)
41 expect(res.body.data).to.have.length.above(2)
42 })
43
1061c73f
C
44 it('Should list jobs with sort, pagination and job type', async function () {
45 {
46 const res = await getJobsListPaginationAndSort({
a1587156
C
47 url: servers[1].url,
48 accessToken: servers[1].accessToken,
1061c73f
C
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
a1587156 57 let job: Job = res.body.data[0]
1061c73f 58 // Skip repeat jobs
a1587156 59 if (job.type === 'videos-views') job = res.body.data[1]
1061c73f
C
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 }
5cd80545 67
1061c73f
C
68 {
69 const res = await getJobsListPaginationAndSort({
a1587156
C
70 url: servers[1].url,
71 accessToken: servers[1].accessToken,
1061c73f
C
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)
94a5ff8a 79
1061c73f
C
80 for (const j of res.body.data as Job[]) {
81 expect(j.type).to.equal('activitypub-http-broadcast')
82 }
83 }
5cd80545
C
84 })
85
402145b8
C
86 it('Should list all jobs', async function () {
87 const res = await getJobsList(servers[1].url, servers[1].accessToken)
88
89 const jobs = res.body.data as Job[]
90
91 expect(res.body.total).to.be.above(2)
92 expect(jobs).to.have.length.above(2)
93
94 // We know there are a least 1 delayed job (video views) and 1 completed job (broadcast)
95 expect(jobs.find(j => j.state === 'delayed')).to.not.be.undefined
96 expect(jobs.find(j => j.state === 'completed')).to.not.be.undefined
97 })
98
7c3b7976
C
99 after(async function () {
100 await cleanupTests(servers)
5cd80545
C
101 })
102})