diff options
Diffstat (limited to 'server/tests')
-rw-r--r-- | server/tests/api/check-params/index.ts | 1 | ||||
-rw-r--r-- | server/tests/api/check-params/jobs.ts | 84 | ||||
-rw-r--r-- | server/tests/api/index-slow.ts | 1 | ||||
-rw-r--r-- | server/tests/api/jobs.ts | 64 | ||||
-rw-r--r-- | server/tests/utils/follows.ts | 2 | ||||
-rw-r--r-- | server/tests/utils/jobs.ts | 33 |
6 files changed, 184 insertions, 1 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 |
2 | import './follows' | 2 | import './follows' |
3 | import './jobs' | ||
3 | import './users' | 4 | import './users' |
4 | import './services' | 5 | import './services' |
5 | import './videos' | 6 | import './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 | |||
3 | import 'mocha' | ||
4 | import * as request from 'supertest' | ||
5 | |||
6 | import { createUser, flushTests, getUserAccessToken, killallServers, runServer, ServerInfo, setAccessTokensToServers } from '../../utils' | ||
7 | |||
8 | describe('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 @@ | |||
3 | import './video-transcoder' | 3 | import './video-transcoder' |
4 | import './multiple-servers' | 4 | import './multiple-servers' |
5 | import './follows' | 5 | import './follows' |
6 | import './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 | |||
3 | import * as chai from 'chai' | ||
4 | import 'mocha' | ||
5 | import { flushTests, killallServers, ServerInfo, setAccessTokensToServers, wait } from '../utils' | ||
6 | import { doubleFollow } from '../utils/follows' | ||
7 | import { getJobsList, getJobsListPaginationAndSort } from '../utils/jobs' | ||
8 | import { flushAndRunMultipleServers } from '../utils/servers' | ||
9 | import { uploadVideo } from '../utils/videos' | ||
10 | import { dateIsValid } from '../utils/miscs' | ||
11 | |||
12 | const expect = chai.expect | ||
13 | |||
14 | describe('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 | }) | ||
diff --git a/server/tests/utils/follows.ts b/server/tests/utils/follows.ts index b88776011..033c6a719 100644 --- a/server/tests/utils/follows.ts +++ b/server/tests/utils/follows.ts | |||
@@ -61,7 +61,7 @@ async function doubleFollow (server1: ServerInfo, server2: ServerInfo) { | |||
61 | ]) | 61 | ]) |
62 | 62 | ||
63 | // Wait request propagation | 63 | // Wait request propagation |
64 | await wait(20000) | 64 | await wait(10000) |
65 | 65 | ||
66 | return true | 66 | return true |
67 | } | 67 | } |
diff --git a/server/tests/utils/jobs.ts b/server/tests/utils/jobs.ts new file mode 100644 index 000000000..0a8c51575 --- /dev/null +++ b/server/tests/utils/jobs.ts | |||
@@ -0,0 +1,33 @@ | |||
1 | import * as request from 'supertest' | ||
2 | |||
3 | function getJobsList (url: string, accessToken: string) { | ||
4 | const path = '/api/v1/jobs' | ||
5 | |||
6 | return request(url) | ||
7 | .get(path) | ||
8 | .set('Accept', 'application/json') | ||
9 | .set('Authorization', 'Bearer ' + accessToken) | ||
10 | .expect(200) | ||
11 | .expect('Content-Type', /json/) | ||
12 | } | ||
13 | |||
14 | function getJobsListPaginationAndSort (url: string, accessToken: string, start: number, count: number, sort: string) { | ||
15 | const path = '/api/v1/jobs' | ||
16 | |||
17 | return request(url) | ||
18 | .get(path) | ||
19 | .query({ start }) | ||
20 | .query({ count }) | ||
21 | .query({ sort }) | ||
22 | .set('Accept', 'application/json') | ||
23 | .set('Authorization', 'Bearer ' + accessToken) | ||
24 | .expect(200) | ||
25 | .expect('Content-Type', /json/) | ||
26 | } | ||
27 | |||
28 | // --------------------------------------------------------------------------- | ||
29 | |||
30 | export { | ||
31 | getJobsList, | ||
32 | getJobsListPaginationAndSort | ||
33 | } | ||