aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/tests/api/check-params/logs.ts
diff options
context:
space:
mode:
Diffstat (limited to 'server/tests/api/check-params/logs.ts')
-rw-r--r--server/tests/api/check-params/logs.ts117
1 files changed, 117 insertions, 0 deletions
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})