aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/tests/api
diff options
context:
space:
mode:
Diffstat (limited to 'server/tests/api')
-rw-r--r--server/tests/api/check-params/index.ts1
-rw-r--r--server/tests/api/check-params/jobs.ts84
-rw-r--r--server/tests/api/index-slow.ts1
-rw-r--r--server/tests/api/jobs.ts64
4 files changed, 150 insertions, 0 deletions
diff --git a/server/tests/api/check-params/index.ts b/server/tests/api/check-params/index.ts
index 287480808..b22bf054a 100644
--- a/server/tests/api/check-params/index.ts
+++ b/server/tests/api/check-params/index.ts
@@ -1,5 +1,6 @@
1// Order of the tests we want to execute 1// Order of the tests we want to execute
2import './follows' 2import './follows'
3import './jobs'
3import './users' 4import './users'
4import './services' 5import './services'
5import './videos' 6import './videos'
diff --git a/server/tests/api/check-params/jobs.ts b/server/tests/api/check-params/jobs.ts
new file mode 100644
index 000000000..7a0dd6e8c
--- /dev/null
+++ b/server/tests/api/check-params/jobs.ts
@@ -0,0 +1,84 @@
1/* tslint:disable:no-unused-expression */
2
3import 'mocha'
4import * as request from 'supertest'
5
6import { createUser, flushTests, getUserAccessToken, killallServers, runServer, ServerInfo, setAccessTokensToServers } from '../../utils'
7
8describe('Test jobs API validators', function () {
9 const path = '/api/v1/jobs/'
10 let server: ServerInfo
11 let userAccessToken = ''
12
13 // ---------------------------------------------------------------
14
15 before(async function () {
16 this.timeout(120000)
17
18 await flushTests()
19
20 server = await runServer(1)
21
22 await setAccessTokensToServers([ server ])
23
24 const user = {
25 username: 'user1',
26 password: 'my super password'
27 }
28 await createUser(server.url, server.accessToken, user.username, user.password)
29 userAccessToken = await getUserAccessToken(server, user)
30 })
31
32 describe('When listing jobs', function () {
33 it('Should fail with a bad start pagination', async function () {
34 await request(server.url)
35 .get(path)
36 .query({ start: 'hello' })
37 .set('Accept', 'application/json')
38 .set('Authorization', 'Bearer ' + server.accessToken)
39 .expect(400)
40 })
41
42 it('Should fail with a bad count pagination', async function () {
43 await request(server.url)
44 .get(path)
45 .query({ count: 'hello' })
46 .set('Accept', 'application/json')
47 .set('Authorization', 'Bearer ' + server.accessToken)
48 .expect(400)
49 })
50
51 it('Should fail with an incorrect sort', async function () {
52 await request(server.url)
53 .get(path)
54 .query({ sort: 'hello' })
55 .set('Accept', 'application/json')
56 .set('Authorization', 'Bearer ' + server.accessToken)
57 .expect(400)
58 })
59
60 it('Should fail with a non authenticated user', async function () {
61 await request(server.url)
62 .get(path)
63 .set('Accept', 'application/json')
64 .expect(401)
65 })
66
67 it('Should fail with a non admin user', async function () {
68 await request(server.url)
69 .get(path)
70 .set('Accept', 'application/json')
71 .set('Authorization', 'Bearer ' + userAccessToken)
72 .expect(403)
73 })
74 })
75
76 after(async function () {
77 killallServers([ server ])
78
79 // Keep the logs if the test failed
80 if (this['ok']) {
81 await flushTests()
82 }
83 })
84})
diff --git a/server/tests/api/index-slow.ts b/server/tests/api/index-slow.ts
index 2448147d8..4cd5b09a2 100644
--- a/server/tests/api/index-slow.ts
+++ b/server/tests/api/index-slow.ts
@@ -3,3 +3,4 @@
3import './video-transcoder' 3import './video-transcoder'
4import './multiple-servers' 4import './multiple-servers'
5import './follows' 5import './follows'
6import './jobs'
diff --git a/server/tests/api/jobs.ts b/server/tests/api/jobs.ts
new file mode 100644
index 000000000..4d9b61392
--- /dev/null
+++ b/server/tests/api/jobs.ts
@@ -0,0 +1,64 @@
1/* tslint:disable:no-unused-expression */
2
3import * as chai from 'chai'
4import 'mocha'
5import { flushTests, killallServers, ServerInfo, setAccessTokensToServers, wait } from '../utils'
6import { doubleFollow } from '../utils/follows'
7import { getJobsList, getJobsListPaginationAndSort } from '../utils/jobs'
8import { flushAndRunMultipleServers } from '../utils/servers'
9import { uploadVideo } from '../utils/videos'
10import { dateIsValid } from '../utils/miscs'
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
34 await wait(15000)
35 })
36
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)
41 })
42
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)
47
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
54 })
55
56 after(async function () {
57 killallServers(servers)
58
59 // Keep the logs if the test failed
60 if (this['ok']) {
61 await flushTests()
62 }
63 })
64})