jobs.ts 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
  2. import 'mocha'
  3. import {
  4. cleanupTests,
  5. createUser,
  6. flushAndRunServer,
  7. ServerInfo,
  8. setAccessTokensToServers,
  9. userLogin
  10. } from '../../../../shared/extra-utils'
  11. import {
  12. checkBadCountPagination,
  13. checkBadSortPagination,
  14. checkBadStartPagination
  15. } from '../../../../shared/extra-utils/requests/check-api-params'
  16. import { makeGetRequest } from '../../../../shared/extra-utils/requests/requests'
  17. import { HttpStatusCode } from '../../../../shared/core-utils/miscs/http-error-codes'
  18. describe('Test jobs API validators', function () {
  19. const path = '/api/v1/jobs/failed'
  20. let server: ServerInfo
  21. let userAccessToken = ''
  22. // ---------------------------------------------------------------
  23. before(async function () {
  24. this.timeout(120000)
  25. server = await flushAndRunServer(1)
  26. await setAccessTokensToServers([ server ])
  27. const user = {
  28. username: 'user1',
  29. password: 'my super password'
  30. }
  31. await createUser({ url: server.url, accessToken: server.accessToken, username: user.username, password: user.password })
  32. userAccessToken = await userLogin(server, user)
  33. })
  34. describe('When listing jobs', function () {
  35. it('Should fail with a bad state', async function () {
  36. await makeGetRequest({
  37. url: server.url,
  38. token: server.accessToken,
  39. path: path + 'ade'
  40. })
  41. })
  42. it('Should fail with an incorrect job type', async function () {
  43. await makeGetRequest({
  44. url: server.url,
  45. token: server.accessToken,
  46. path,
  47. query: {
  48. jobType: 'toto'
  49. }
  50. })
  51. })
  52. it('Should fail with a bad start pagination', async function () {
  53. await checkBadStartPagination(server.url, path, server.accessToken)
  54. })
  55. it('Should fail with a bad count pagination', async function () {
  56. await checkBadCountPagination(server.url, path, server.accessToken)
  57. })
  58. it('Should fail with an incorrect sort', async function () {
  59. await checkBadSortPagination(server.url, path, server.accessToken)
  60. })
  61. it('Should fail with a non authenticated user', async function () {
  62. await makeGetRequest({
  63. url: server.url,
  64. path,
  65. statusCodeExpected: HttpStatusCode.UNAUTHORIZED_401
  66. })
  67. })
  68. it('Should fail with a non admin user', async function () {
  69. await makeGetRequest({
  70. url: server.url,
  71. path,
  72. token: userAccessToken,
  73. statusCodeExpected: HttpStatusCode.FORBIDDEN_403
  74. })
  75. })
  76. })
  77. after(async function () {
  78. await cleanupTests([ server ])
  79. })
  80. })