videos-history.ts 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  1. /* tslint:disable:no-unused-expression */
  2. import * as chai from 'chai'
  3. import 'mocha'
  4. import {
  5. checkBadCountPagination,
  6. checkBadStartPagination,
  7. cleanupTests,
  8. flushAndRunServer,
  9. makeGetRequest,
  10. makePostBodyRequest,
  11. makePutBodyRequest,
  12. ServerInfo,
  13. setAccessTokensToServers,
  14. uploadVideo
  15. } from '../../../../shared/extra-utils'
  16. const expect = chai.expect
  17. describe('Test videos history API validator', function () {
  18. let watchingPath: string
  19. let myHistoryPath = '/api/v1/users/me/history/videos'
  20. let myHistoryRemove = myHistoryPath + '/remove'
  21. let server: ServerInfo
  22. // ---------------------------------------------------------------
  23. before(async function () {
  24. this.timeout(30000)
  25. server = await flushAndRunServer(1)
  26. await setAccessTokensToServers([ server ])
  27. const res = await uploadVideo(server.url, server.accessToken, {})
  28. const videoUUID = res.body.video.uuid
  29. watchingPath = '/api/v1/videos/' + videoUUID + '/watching'
  30. })
  31. describe('When notifying a user is watching a video', function () {
  32. it('Should fail with an unauthenticated user', async function () {
  33. const fields = { currentTime: 5 }
  34. await makePutBodyRequest({ url: server.url, path: watchingPath, fields, statusCodeExpected: 401 })
  35. })
  36. it('Should fail with an incorrect video id', async function () {
  37. const fields = { currentTime: 5 }
  38. const path = '/api/v1/videos/blabla/watching'
  39. await makePutBodyRequest({ url: server.url, path, fields, token: server.accessToken, statusCodeExpected: 400 })
  40. })
  41. it('Should fail with an unknown video', async function () {
  42. const fields = { currentTime: 5 }
  43. const path = '/api/v1/videos/d91fff41-c24d-4508-8e13-3bd5902c3b02/watching'
  44. await makePutBodyRequest({ url: server.url, path, fields, token: server.accessToken, statusCodeExpected: 404 })
  45. })
  46. it('Should fail with a bad current time', async function () {
  47. const fields = { currentTime: 'hello' }
  48. await makePutBodyRequest({ url: server.url, path: watchingPath, fields, token: server.accessToken, statusCodeExpected: 400 })
  49. })
  50. it('Should succeed with the correct parameters', async function () {
  51. const fields = { currentTime: 5 }
  52. await makePutBodyRequest({ url: server.url, path: watchingPath, fields, token: server.accessToken, statusCodeExpected: 204 })
  53. })
  54. })
  55. describe('When listing user videos history', function () {
  56. it('Should fail with a bad start pagination', async function () {
  57. await checkBadStartPagination(server.url, myHistoryPath, server.accessToken)
  58. })
  59. it('Should fail with a bad count pagination', async function () {
  60. await checkBadCountPagination(server.url, myHistoryPath, server.accessToken)
  61. })
  62. it('Should fail with an unauthenticated user', async function () {
  63. await makeGetRequest({ url: server.url, path: myHistoryPath, statusCodeExpected: 401 })
  64. })
  65. it('Should succeed with the correct params', async function () {
  66. await makeGetRequest({ url: server.url, token: server.accessToken, path: myHistoryPath, statusCodeExpected: 200 })
  67. })
  68. })
  69. describe('When removing user videos history', function () {
  70. it('Should fail with an unauthenticated user', async function () {
  71. await makePostBodyRequest({ url: server.url, path: myHistoryPath + '/remove', statusCodeExpected: 401 })
  72. })
  73. it('Should fail with a bad beforeDate parameter', async function () {
  74. const body = { beforeDate: '15' }
  75. await makePostBodyRequest({
  76. url: server.url,
  77. token: server.accessToken,
  78. path: myHistoryRemove,
  79. fields: body,
  80. statusCodeExpected: 400
  81. })
  82. })
  83. it('Should succeed with a valid beforeDate param', async function () {
  84. const body = { beforeDate: new Date().toISOString() }
  85. await makePostBodyRequest({
  86. url: server.url,
  87. token: server.accessToken,
  88. path: myHistoryRemove,
  89. fields: body,
  90. statusCodeExpected: 204
  91. })
  92. })
  93. it('Should succeed without body', async function () {
  94. await makePostBodyRequest({
  95. url: server.url,
  96. token: server.accessToken,
  97. path: myHistoryRemove,
  98. statusCodeExpected: 204
  99. })
  100. })
  101. })
  102. after(async function () {
  103. await cleanupTests([ server ])
  104. })
  105. })