1 /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
10 setAccessTokensToServers
11 } from '../../../../shared/extra-utils'
12 import { makeGetRequest } from '../../../../shared/extra-utils/requests/requests'
13 import { HttpStatusCode } from '../../../../shared/core-utils/miscs/http-error-codes'
15 describe('Test logs API validators', function () {
16 const path = '/api/v1/server/logs'
17 let server: ServerInfo
18 let userAccessToken = ''
20 // ---------------------------------------------------------------
22 before(async function () {
25 server = await flushAndRunServer(1)
27 await setAccessTokensToServers([ server ])
31 password: 'my super password'
33 await createUser({ url: server.url, accessToken: server.accessToken, username: user.username, password: user.password })
34 userAccessToken = await server.loginCommand.getAccessToken(user)
37 describe('When getting logs', function () {
39 it('Should fail with a non authenticated user', async function () {
40 await makeGetRequest({
43 statusCodeExpected: HttpStatusCode.UNAUTHORIZED_401
47 it('Should fail with a non admin user', async function () {
48 await makeGetRequest({
51 token: userAccessToken,
52 statusCodeExpected: HttpStatusCode.FORBIDDEN_403
56 it('Should fail with a missing startDate query', async function () {
57 await makeGetRequest({
60 token: server.accessToken,
61 statusCodeExpected: HttpStatusCode.BAD_REQUEST_400
65 it('Should fail with a bad startDate query', async function () {
66 await makeGetRequest({
69 token: server.accessToken,
70 query: { startDate: 'toto' },
71 statusCodeExpected: HttpStatusCode.BAD_REQUEST_400
75 it('Should fail with a bad endDate query', async function () {
76 await makeGetRequest({
79 token: server.accessToken,
80 query: { startDate: new Date().toISOString(), endDate: 'toto' },
81 statusCodeExpected: HttpStatusCode.BAD_REQUEST_400
85 it('Should fail with a bad level parameter', async function () {
86 await makeGetRequest({
89 token: server.accessToken,
90 query: { startDate: new Date().toISOString(), level: 'toto' },
91 statusCodeExpected: HttpStatusCode.BAD_REQUEST_400
95 it('Should succeed with the correct params', async function () {
96 await makeGetRequest({
99 token: server.accessToken,
100 query: { startDate: new Date().toISOString() },
101 statusCodeExpected: HttpStatusCode.OK_200
106 after(async function () {
107 await cleanupTests([ server ])