video.ts 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. import { VideoMetadata, PublishedBeforeJoystream, MediaType, License } from '../src'
  2. import { assert, expect } from 'chai'
  3. describe('Video Metadata', () => {
  4. it('Message', () => {
  5. const meta = new VideoMetadata()
  6. const title = 'Video Title'
  7. const description = 'Video Description'
  8. const duration = 100
  9. meta.setTitle(title)
  10. meta.setDescription(description)
  11. meta.setDuration(duration)
  12. meta.setMediaPixelHeight(1)
  13. meta.setMediaPixelWidth(2)
  14. meta.setMediaType(new MediaType())
  15. meta.setLanguage('en')
  16. meta.setLicense(new License())
  17. meta.setPublishedBeforeJoystream(new PublishedBeforeJoystream())
  18. meta.setHasMarketing(true)
  19. meta.setIsPublic(true)
  20. meta.setIsExplicit(false)
  21. meta.setVideo(0)
  22. meta.setThumbnailPhoto(1)
  23. meta.setCategory(101)
  24. assert.deepEqual(meta.toObject(), {
  25. title,
  26. description,
  27. duration,
  28. mediaPixelHeight: 1,
  29. mediaPixelWidth: 2,
  30. mediaType: {
  31. codecName: undefined,
  32. container: undefined,
  33. mimeMediaType: undefined,
  34. },
  35. language: 'en',
  36. license: {
  37. code: undefined,
  38. attribution: undefined,
  39. customText: undefined,
  40. },
  41. publishedBeforeJoystream: { isPublished: undefined, date: undefined },
  42. hasMarketing: true,
  43. isPublic: true,
  44. isExplicit: false,
  45. thumbnailPhoto: 1,
  46. video: 0,
  47. personsList: [],
  48. category: 101,
  49. })
  50. // sanity check - encoding / decoding works
  51. assert.deepEqual(VideoMetadata.deserializeBinary(meta.serializeBinary()), meta)
  52. })
  53. it('Message: PublishedBeforeJoystream', () => {
  54. const meta = new VideoMetadata()
  55. expect(meta.hasPublishedBeforeJoystream()).equals(false, 'PublishedBeforeJoystream field should NOT be set')
  56. const published = new PublishedBeforeJoystream()
  57. const isPublished = true
  58. const date = '1950-12-24'
  59. published.setIsPublished(isPublished)
  60. published.setDate(date)
  61. meta.setPublishedBeforeJoystream(published)
  62. // Field should now be set
  63. expect(meta.hasPublishedBeforeJoystream()).equals(true, 'PublishedBeforeJoystream field should be set')
  64. assert.deepEqual(published.toObject(), {
  65. isPublished,
  66. date,
  67. })
  68. })
  69. it('Message: License', () => {
  70. const license = new License()
  71. const code = 1000
  72. const attribution = 'Attribution Text'
  73. const customText = 'Custom License Details'
  74. license.setCode(code)
  75. license.setAttribution(attribution)
  76. license.setCustomText(customText)
  77. assert.deepEqual(license.toObject(), {
  78. code,
  79. attribution,
  80. customText,
  81. })
  82. })
  83. it('Message: MediaType', () => {
  84. const mediaType = new MediaType()
  85. const codecName = 'mpeg4'
  86. const container = 'avi'
  87. const mimeMediaType = 'videp/mp4'
  88. mediaType.setCodecName(codecName)
  89. mediaType.setContainer(container)
  90. mediaType.setMimeMediaType(mimeMediaType)
  91. assert.deepEqual(mediaType.toObject(), {
  92. codecName,
  93. container,
  94. mimeMediaType,
  95. })
  96. })
  97. })