license-codes.ts 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. import {
  2. KnownLicenses,
  3. CUSTOM_LICENSE_CODE,
  4. getLicenseCodeByName,
  5. createKnownLicenseFromCode,
  6. createCustomKnownLicense,
  7. } from '../src/licenses'
  8. import { VideoMetadata } from '../src/index'
  9. import { assert } from 'chai'
  10. describe('Known License Codes', () => {
  11. it('Excludes default value 0', () => {
  12. assert(!KnownLicenses.has(0))
  13. })
  14. it('Pre-defined Joystream license codes', () => {
  15. // Make sure we have correct known custom license
  16. assert(KnownLicenses.has(CUSTOM_LICENSE_CODE))
  17. assert.equal(KnownLicenses.get(CUSTOM_LICENSE_CODE)!.name, 'CUSTOM')
  18. assert(KnownLicenses.has(1001))
  19. assert(KnownLicenses.has(1002))
  20. assert(KnownLicenses.has(1003))
  21. assert(KnownLicenses.has(1004))
  22. assert(KnownLicenses.has(1005))
  23. assert(KnownLicenses.has(1006))
  24. assert(KnownLicenses.has(1007))
  25. assert(KnownLicenses.has(1008))
  26. })
  27. it('createCustomKnownLicense(): uses correct code', () => {
  28. const license = createCustomKnownLicense('custom text')
  29. assert.equal(license.getCode(), CUSTOM_LICENSE_CODE)
  30. })
  31. it('createKnownLicenseFromCode(): License can be created by name', () => {
  32. const licenseCode = getLicenseCodeByName('CC_BY') as number
  33. const license = createKnownLicenseFromCode(licenseCode as number, 'Attribution: Joystream')
  34. const videoMeta = new VideoMetadata()
  35. videoMeta.setLicense(license)
  36. })
  37. })