video.ts 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. import { VideoMetadata, MediaType } from '../src'
  2. import { assert, expect } from 'chai'
  3. import { isSet, encodeDecode, metaToObject } from '../src/utils'
  4. import Long from 'long'
  5. describe('Video Metadata', () => {
  6. it('Message', () => {
  7. const video = {
  8. title: 'Video Title',
  9. description: 'Video Description',
  10. duration: 100,
  11. mediaPixelHeight: 1,
  12. mediaPixelWidth: 2,
  13. mediaType: {},
  14. language: 'en',
  15. license: {},
  16. publishedBeforeJoystream: {},
  17. hasMarketing: true,
  18. isPublic: true,
  19. isExplicit: false,
  20. video: 0,
  21. thumbnailPhoto: 1,
  22. category: Long.fromNumber(101, true),
  23. }
  24. const videoMessage = new VideoMetadata(video)
  25. assert.deepEqual(metaToObject(VideoMetadata, videoMessage), { ...video, category: '101' })
  26. assert.deepEqual(encodeDecode(VideoMetadata, video), { ...video, category: '101' })
  27. })
  28. it('Message: PublishedBeforeJoystream', () => {
  29. const meta = new VideoMetadata()
  30. expect(isSet(metaToObject(VideoMetadata, meta).publishedBeforeJoystream)).equals(
  31. false,
  32. 'PublishedBeforeJoystream field should NOT be set'
  33. )
  34. const published = {
  35. isPublished: true,
  36. date: '1950-12-24',
  37. }
  38. meta.publishedBeforeJoystream = published
  39. // Field should now be set
  40. expect(isSet(metaToObject(VideoMetadata, meta).publishedBeforeJoystream)).equals(
  41. true,
  42. 'PublishedBeforeJoystream field should be set'
  43. )
  44. assert.deepEqual(metaToObject(VideoMetadata, meta).publishedBeforeJoystream, published)
  45. assert.deepEqual(encodeDecode(VideoMetadata, meta).publishedBeforeJoystream, meta.publishedBeforeJoystream)
  46. })
  47. it('Message: License', () => {
  48. const license = {
  49. code: 1000,
  50. attribution: 'Attribution Text',
  51. customText: 'Custom License Details',
  52. }
  53. const meta = new VideoMetadata({ license })
  54. assert.deepEqual(metaToObject(VideoMetadata, meta).license, license)
  55. assert.deepEqual(encodeDecode(VideoMetadata, meta).license, license)
  56. // Empty object check
  57. meta.license = {}
  58. assert.deepEqual(metaToObject(VideoMetadata, meta).license, {})
  59. assert.deepEqual(encodeDecode(VideoMetadata, meta).license, {})
  60. // Unset check
  61. meta.license = undefined
  62. assert.deepEqual(metaToObject(VideoMetadata, meta).license, undefined)
  63. assert.deepEqual(encodeDecode(VideoMetadata, meta).license, undefined)
  64. })
  65. it('Message: MediaType', () => {
  66. const mediaType = {
  67. codecName: 'mpeg4',
  68. container: 'avi',
  69. mimeMediaType: 'videp/mp4',
  70. }
  71. const mediaTypeMessage = new MediaType(mediaType)
  72. assert.deepEqual(metaToObject(MediaType, mediaTypeMessage), mediaType)
  73. assert.deepEqual(encodeDecode(MediaType, mediaType), mediaType)
  74. })
  75. })