video-captions.ts 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  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. const expect = chai.expect
  6. function createVideoCaption (args: {
  7. url: string,
  8. accessToken: string
  9. videoId: string | number
  10. language: string
  11. fixture: string,
  12. mimeType?: string,
  13. statusCodeExpected?: number
  14. }) {
  15. const path = '/api/v1/videos/' + args.videoId + '/captions/' + args.language
  16. const captionfile = buildAbsoluteFixturePath(args.fixture)
  17. const captionfileAttach = args.mimeType ? [ captionfile, { contentType: args.mimeType } ] : captionfile
  18. return makeUploadRequest({
  19. method: 'PUT',
  20. url: args.url,
  21. path,
  22. token: args.accessToken,
  23. fields: {},
  24. attaches: {
  25. captionfile: captionfileAttach
  26. },
  27. statusCodeExpected: args.statusCodeExpected || 204
  28. })
  29. }
  30. function listVideoCaptions (url: string, videoId: string | number) {
  31. const path = '/api/v1/videos/' + videoId + '/captions'
  32. return makeGetRequest({
  33. url,
  34. path,
  35. statusCodeExpected: 200
  36. })
  37. }
  38. function deleteVideoCaption (url: string, token: string, videoId: string | number, language: string) {
  39. const path = '/api/v1/videos/' + videoId + '/captions/' + language
  40. return makeDeleteRequest({
  41. url,
  42. token,
  43. path,
  44. statusCodeExpected: 204
  45. })
  46. }
  47. async function testCaptionFile (url: string, captionPath: string, containsString: string) {
  48. const res = await request(url)
  49. .get(captionPath)
  50. .expect(200)
  51. expect(res.text).to.contain(containsString)
  52. }
  53. // ---------------------------------------------------------------------------
  54. export {
  55. createVideoCaption,
  56. listVideoCaptions,
  57. testCaptionFile,
  58. deleteVideoCaption
  59. }