1 /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
10 setAccessTokensToServers,
12 } from '../../../../shared/extra-utils'
13 import { makeGetRequest } from '../../../../shared/extra-utils/requests/requests'
14 import { HttpStatusCode } from '../../../../shared/core-utils/miscs/http-error-codes'
16 describe('Test logs API validators', function () {
17 const path = '/api/v1/server/logs'
18 let server: ServerInfo
19 let userAccessToken = ''
21 // ---------------------------------------------------------------
23 before(async function () {
26 server = await flushAndRunServer(1)
28 await setAccessTokensToServers([ server ])
32 password: 'my super password'
34 await createUser({ url: server.url, accessToken: server.accessToken, username: user.username, password: user.password })
35 userAccessToken = await userLogin(server, user)
38 describe('When getting logs', function () {
40 it('Should fail with a non authenticated user', async function () {
41 await makeGetRequest({
44 statusCodeExpected: HttpStatusCode.UNAUTHORIZED_401
48 it('Should fail with a non admin user', async function () {
49 await makeGetRequest({
52 token: userAccessToken,
53 statusCodeExpected: HttpStatusCode.FORBIDDEN_403
57 it('Should fail with a missing startDate query', async function () {
58 await makeGetRequest({
61 token: server.accessToken,
62 statusCodeExpected: HttpStatusCode.BAD_REQUEST_400
66 it('Should fail with a bad startDate query', async function () {
67 await makeGetRequest({
70 token: server.accessToken,
71 query: { startDate: 'toto' },
72 statusCodeExpected: HttpStatusCode.BAD_REQUEST_400
76 it('Should fail with a bad endDate query', async function () {
77 await makeGetRequest({
80 token: server.accessToken,
81 query: { startDate: new Date().toISOString(), endDate: 'toto' },
82 statusCodeExpected: HttpStatusCode.BAD_REQUEST_400
86 it('Should fail with a bad level parameter', async function () {
87 await makeGetRequest({
90 token: server.accessToken,
91 query: { startDate: new Date().toISOString(), level: 'toto' },
92 statusCodeExpected: HttpStatusCode.BAD_REQUEST_400
96 it('Should succeed with the correct params', async function () {
97 await makeGetRequest({
100 token: server.accessToken,
101 query: { startDate: new Date().toISOString() },
102 statusCodeExpected: HttpStatusCode.OK_200
107 after(async function () {
108 await cleanupTests([ server ])