aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/tests
diff options
context:
space:
mode:
Diffstat (limited to 'server/tests')
-rw-r--r--server/tests/api/check-params/index.ts1
-rw-r--r--server/tests/api/check-params/logs.ts117
-rw-r--r--server/tests/api/server/index.ts1
-rw-r--r--server/tests/api/server/logs.ts92
4 files changed, 211 insertions, 0 deletions
diff --git a/server/tests/api/check-params/index.ts b/server/tests/api/check-params/index.ts
index ca51cd39a..bdac95025 100644
--- a/server/tests/api/check-params/index.ts
+++ b/server/tests/api/check-params/index.ts
@@ -4,6 +4,7 @@ import './config'
4import './contact-form' 4import './contact-form'
5import './follows' 5import './follows'
6import './jobs' 6import './jobs'
7import './logs'
7import './redundancy' 8import './redundancy'
8import './search' 9import './search'
9import './services' 10import './services'
diff --git a/server/tests/api/check-params/logs.ts b/server/tests/api/check-params/logs.ts
new file mode 100644
index 000000000..d6a40da61
--- /dev/null
+++ b/server/tests/api/check-params/logs.ts
@@ -0,0 +1,117 @@
1/* tslint:disable:no-unused-expression */
2
3import 'mocha'
4
5import {
6 createUser,
7 flushTests,
8 killallServers,
9 runServer,
10 ServerInfo,
11 setAccessTokensToServers,
12 userLogin
13} from '../../../../shared/utils'
14import { makeGetRequest } from '../../../../shared/utils/requests/requests'
15
16describe('Test logs API validators', function () {
17 const path = '/api/v1/server/logs'
18 let server: ServerInfo
19 let userAccessToken = ''
20
21 // ---------------------------------------------------------------
22
23 before(async function () {
24 this.timeout(120000)
25
26 await flushTests()
27
28 server = await runServer(1)
29
30 await setAccessTokensToServers([ server ])
31
32 const user = {
33 username: 'user1',
34 password: 'my super password'
35 }
36 await createUser(server.url, server.accessToken, user.username, user.password)
37 userAccessToken = await userLogin(server, user)
38 })
39
40 describe('When getting logs', function () {
41
42 it('Should fail with a non authenticated user', async function () {
43 await makeGetRequest({
44 url: server.url,
45 path,
46 statusCodeExpected: 401
47 })
48 })
49
50 it('Should fail with a non admin user', async function () {
51 await makeGetRequest({
52 url: server.url,
53 path,
54 token: userAccessToken,
55 statusCodeExpected: 403
56 })
57 })
58
59 it('Should fail with a missing startDate query', async function () {
60 await makeGetRequest({
61 url: server.url,
62 path,
63 token: server.accessToken,
64 statusCodeExpected: 400
65 })
66 })
67
68 it('Should fail with a bad startDate query', async function () {
69 await makeGetRequest({
70 url: server.url,
71 path,
72 token: server.accessToken,
73 query: { startDate: 'toto' },
74 statusCodeExpected: 400
75 })
76 })
77
78 it('Should fail with a bad endDate query', async function () {
79 await makeGetRequest({
80 url: server.url,
81 path,
82 token: server.accessToken,
83 query: { startDate: new Date().toISOString(), endDate: 'toto' },
84 statusCodeExpected: 400
85 })
86 })
87
88 it('Should fail with a bad level parameter', async function () {
89 await makeGetRequest({
90 url: server.url,
91 path,
92 token: server.accessToken,
93 query: { startDate: new Date().toISOString(), level: 'toto' },
94 statusCodeExpected: 400
95 })
96 })
97
98 it('Should succeed with the correct params', async function () {
99 await makeGetRequest({
100 url: server.url,
101 path,
102 token: server.accessToken,
103 query: { startDate: new Date().toISOString() },
104 statusCodeExpected: 200
105 })
106 })
107 })
108
109 after(async function () {
110 killallServers([ server ])
111
112 // Keep the logs if the test failed
113 if (this['ok']) {
114 await flushTests()
115 }
116 })
117})
diff --git a/server/tests/api/server/index.ts b/server/tests/api/server/index.ts
index 4e53074ab..94c15e0d0 100644
--- a/server/tests/api/server/index.ts
+++ b/server/tests/api/server/index.ts
@@ -6,6 +6,7 @@ import './follows'
6import './follows-moderation' 6import './follows-moderation'
7import './handle-down' 7import './handle-down'
8import './jobs' 8import './jobs'
9import './logs'
9import './reverse-proxy' 10import './reverse-proxy'
10import './stats' 11import './stats'
11import './tracker' 12import './tracker'
diff --git a/server/tests/api/server/logs.ts b/server/tests/api/server/logs.ts
new file mode 100644
index 000000000..05b0308de
--- /dev/null
+++ b/server/tests/api/server/logs.ts
@@ -0,0 +1,92 @@
1/* tslint:disable:no-unused-expression */
2
3import * as chai from 'chai'
4import 'mocha'
5import { flushTests, killallServers, runServer, ServerInfo, setAccessTokensToServers } from '../../../../shared/utils/index'
6import { waitJobs } from '../../../../shared/utils/server/jobs'
7import { uploadVideo } from '../../../../shared/utils/videos/videos'
8import { getLogs } from '../../../../shared/utils/logs/logs'
9
10const expect = chai.expect
11
12describe('Test logs', function () {
13 let server: ServerInfo
14
15 before(async function () {
16 this.timeout(30000)
17
18 await flushTests()
19
20 server = await runServer(1)
21 await setAccessTokensToServers([ server ])
22 })
23
24 it('Should get logs with a start date', async function () {
25 this.timeout(10000)
26
27 await uploadVideo(server.url, server.accessToken, { name: 'video 1' })
28 await waitJobs([ server ])
29
30 const now = new Date()
31
32 await uploadVideo(server.url, server.accessToken, { name: 'video 2' })
33 await waitJobs([ server ])
34
35 const res = await getLogs(server.url, server.accessToken, now)
36 const logsString = JSON.stringify(res.body)
37
38 expect(logsString.includes('video 1')).to.be.false
39 expect(logsString.includes('video 2')).to.be.true
40 })
41
42 it('Should get logs with an end date', async function () {
43 this.timeout(10000)
44
45 await uploadVideo(server.url, server.accessToken, { name: 'video 3' })
46 await waitJobs([ server ])
47
48 const now1 = new Date()
49
50 await uploadVideo(server.url, server.accessToken, { name: 'video 4' })
51 await waitJobs([ server ])
52
53 const now2 = new Date()
54
55 await uploadVideo(server.url, server.accessToken, { name: 'video 5' })
56 await waitJobs([ server ])
57
58 const res = await getLogs(server.url, server.accessToken, now1, now2)
59 const logsString = JSON.stringify(res.body)
60
61 expect(logsString.includes('video 3')).to.be.false
62 expect(logsString.includes('video 4')).to.be.true
63 expect(logsString.includes('video 5')).to.be.false
64 })
65
66 it('Should get filter by level', async function () {
67 this.timeout(10000)
68
69 const now = new Date()
70
71 await uploadVideo(server.url, server.accessToken, { name: 'video 6' })
72 await waitJobs([ server ])
73
74 {
75 const res = await getLogs(server.url, server.accessToken, now, undefined, 'info')
76 const logsString = JSON.stringify(res.body)
77
78 expect(logsString.includes('video 6')).to.be.true
79 }
80
81 {
82 const res = await getLogs(server.url, server.accessToken, now, undefined, 'warn')
83 const logsString = JSON.stringify(res.body)
84
85 expect(logsString.includes('video 6')).to.be.false
86 }
87 })
88
89 after(async function () {
90 killallServers([ server ])
91 })
92})