video-captions.ts 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. import { makeDeleteRequest, makeGetRequest, makeUploadRequest } from '../requests/requests'
  2. import * as request from 'supertest'
  3. import * as chai from 'chai'
  4. import { buildAbsoluteFixturePath } from '../miscs/miscs'
  5. import { HttpStatusCode } from '../../../shared/core-utils/miscs/http-error-codes'
  6. const expect = chai.expect
  7. function createVideoCaption (args: {
  8. url: string
  9. accessToken: string
  10. videoId: string | number
  11. language: string
  12. fixture: string
  13. mimeType?: string
  14. statusCodeExpected?: number
  15. }) {
  16. const path = '/api/v1/videos/' + args.videoId + '/captions/' + args.language
  17. const captionfile = buildAbsoluteFixturePath(args.fixture)
  18. const captionfileAttach = args.mimeType ? [ captionfile, { contentType: args.mimeType } ] : captionfile
  19. return makeUploadRequest({
  20. method: 'PUT',
  21. url: args.url,
  22. path,
  23. token: args.accessToken,
  24. fields: {},
  25. attaches: {
  26. captionfile: captionfileAttach
  27. },
  28. statusCodeExpected: args.statusCodeExpected || HttpStatusCode.NO_CONTENT_204
  29. })
  30. }
  31. function listVideoCaptions (url: string, videoId: string | number) {
  32. const path = '/api/v1/videos/' + videoId + '/captions'
  33. return makeGetRequest({
  34. url,
  35. path,
  36. statusCodeExpected: HttpStatusCode.OK_200
  37. })
  38. }
  39. function deleteVideoCaption (url: string, token: string, videoId: string | number, language: string) {
  40. const path = '/api/v1/videos/' + videoId + '/captions/' + language
  41. return makeDeleteRequest({
  42. url,
  43. token,
  44. path,
  45. statusCodeExpected: HttpStatusCode.NO_CONTENT_204
  46. })
  47. }
  48. async function testCaptionFile (url: string, captionPath: string, containsString: string) {
  49. const res = await request(url)
  50. .get(captionPath)
  51. .expect(HttpStatusCode.OK_200)
  52. expect(res.text).to.contain(containsString)
  53. }
  54. // ---------------------------------------------------------------------------
  55. export {
  56. createVideoCaption,
  57. listVideoCaptions,
  58. testCaptionFile,
  59. deleteVideoCaption
  60. }