search.ts 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  1. /* tslint:disable:no-unused-expression */
  2. import 'mocha'
  3. import { cleanupTests, flushAndRunServer, immutableAssign, makeGetRequest, ServerInfo } from '../../../../shared/extra-utils'
  4. import {
  5. checkBadCountPagination,
  6. checkBadSortPagination,
  7. checkBadStartPagination
  8. } from '../../../../shared/extra-utils/requests/check-api-params'
  9. describe('Test videos API validator', function () {
  10. let server: ServerInfo
  11. // ---------------------------------------------------------------
  12. before(async function () {
  13. this.timeout(30000)
  14. server = await flushAndRunServer(1)
  15. })
  16. describe('When searching videos', function () {
  17. const path = '/api/v1/search/videos/'
  18. const query = {
  19. search: 'coucou'
  20. }
  21. it('Should fail with a bad start pagination', async function () {
  22. await checkBadStartPagination(server.url, path, null, query)
  23. })
  24. it('Should fail with a bad count pagination', async function () {
  25. await checkBadCountPagination(server.url, path, null, query)
  26. })
  27. it('Should fail with an incorrect sort', async function () {
  28. await checkBadSortPagination(server.url, path, null, query)
  29. })
  30. it('Should success with the correct parameters', async function () {
  31. await makeGetRequest({ url: server.url, path, query, statusCodeExpected: 200 })
  32. })
  33. it('Should fail with an invalid category', async function () {
  34. const customQuery1 = immutableAssign(query, { categoryOneOf: [ 'aa', 'b' ] })
  35. await makeGetRequest({ url: server.url, path, query: customQuery1, statusCodeExpected: 400 })
  36. const customQuery2 = immutableAssign(query, { categoryOneOf: 'a' })
  37. await makeGetRequest({ url: server.url, path, query: customQuery2, statusCodeExpected: 400 })
  38. })
  39. it('Should succeed with a valid category', async function () {
  40. const customQuery1 = immutableAssign(query, { categoryOneOf: [ 1, 7 ] })
  41. await makeGetRequest({ url: server.url, path, query: customQuery1, statusCodeExpected: 200 })
  42. const customQuery2 = immutableAssign(query, { categoryOneOf: 1 })
  43. await makeGetRequest({ url: server.url, path, query: customQuery2, statusCodeExpected: 200 })
  44. })
  45. it('Should fail with an invalid licence', async function () {
  46. const customQuery1 = immutableAssign(query, { licenceOneOf: [ 'aa', 'b' ] })
  47. await makeGetRequest({ url: server.url, path, query: customQuery1, statusCodeExpected: 400 })
  48. const customQuery2 = immutableAssign(query, { licenceOneOf: 'a' })
  49. await makeGetRequest({ url: server.url, path, query: customQuery2, statusCodeExpected: 400 })
  50. })
  51. it('Should succeed with a valid licence', async function () {
  52. const customQuery1 = immutableAssign(query, { licenceOneOf: [ 1, 2 ] })
  53. await makeGetRequest({ url: server.url, path, query: customQuery1, statusCodeExpected: 200 })
  54. const customQuery2 = immutableAssign(query, { licenceOneOf: 1 })
  55. await makeGetRequest({ url: server.url, path, query: customQuery2, statusCodeExpected: 200 })
  56. })
  57. it('Should succeed with a valid language', async function () {
  58. const customQuery1 = immutableAssign(query, { languageOneOf: [ 'fr', 'en' ] })
  59. await makeGetRequest({ url: server.url, path, query: customQuery1, statusCodeExpected: 200 })
  60. const customQuery2 = immutableAssign(query, { languageOneOf: 'fr' })
  61. await makeGetRequest({ url: server.url, path, query: customQuery2, statusCodeExpected: 200 })
  62. })
  63. it('Should succeed with valid tags', async function () {
  64. const customQuery1 = immutableAssign(query, { tagsOneOf: [ 'tag1', 'tag2' ] })
  65. await makeGetRequest({ url: server.url, path, query: customQuery1, statusCodeExpected: 200 })
  66. const customQuery2 = immutableAssign(query, { tagsOneOf: 'tag1' })
  67. await makeGetRequest({ url: server.url, path, query: customQuery2, statusCodeExpected: 200 })
  68. const customQuery3 = immutableAssign(query, { tagsAllOf: [ 'tag1', 'tag2' ] })
  69. await makeGetRequest({ url: server.url, path, query: customQuery3, statusCodeExpected: 200 })
  70. const customQuery4 = immutableAssign(query, { tagsAllOf: 'tag1' })
  71. await makeGetRequest({ url: server.url, path, query: customQuery4, statusCodeExpected: 200 })
  72. })
  73. it('Should fail with invalid durations', async function () {
  74. const customQuery1 = immutableAssign(query, { durationMin: 'hello' })
  75. await makeGetRequest({ url: server.url, path, query: customQuery1, statusCodeExpected: 400 })
  76. const customQuery2 = immutableAssign(query, { durationMax: 'hello' })
  77. await makeGetRequest({ url: server.url, path, query: customQuery2, statusCodeExpected: 400 })
  78. })
  79. it('Should fail with invalid dates', async function () {
  80. const customQuery1 = immutableAssign(query, { startDate: 'hello' })
  81. await makeGetRequest({ url: server.url, path, query: customQuery1, statusCodeExpected: 400 })
  82. const customQuery2 = immutableAssign(query, { endDate: 'hello' })
  83. await makeGetRequest({ url: server.url, path, query: customQuery2, statusCodeExpected: 400 })
  84. const customQuery3 = immutableAssign(query, { originallyPublishedStartDate: 'hello' })
  85. await makeGetRequest({ url: server.url, path, query: customQuery3, statusCodeExpected: 400 })
  86. const customQuery4 = immutableAssign(query, { originallyPublishedEndDate: 'hello' })
  87. await makeGetRequest({ url: server.url, path, query: customQuery4, statusCodeExpected: 400 })
  88. })
  89. })
  90. describe('When searching video channels', function () {
  91. const path = '/api/v1/search/video-channels/'
  92. const query = {
  93. search: 'coucou'
  94. }
  95. it('Should fail with a bad start pagination', async function () {
  96. await checkBadStartPagination(server.url, path, null, query)
  97. })
  98. it('Should fail with a bad count pagination', async function () {
  99. await checkBadCountPagination(server.url, path, null, query)
  100. })
  101. it('Should fail with an incorrect sort', async function () {
  102. await checkBadSortPagination(server.url, path, null, query)
  103. })
  104. it('Should success with the correct parameters', async function () {
  105. await makeGetRequest({ url: server.url, path, query, statusCodeExpected: 200 })
  106. })
  107. })
  108. after(async function () {
  109. await cleanupTests([ server ])
  110. })
  111. })