license-codes.ts 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. import {
  2. KnownLicenses,
  3. CUSTOM_LICENSE_CODE,
  4. getLicenseCodeByName,
  5. createKnownLicenseFromCode,
  6. createCustomKnownLicense,
  7. } from '../src/licenses'
  8. import { License } 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 TEXT = 'custom text'
  29. const license = createCustomKnownLicense(TEXT)
  30. assert.equal(license.code, CUSTOM_LICENSE_CODE)
  31. assert.equal(license.customText, TEXT)
  32. License.verify(license)
  33. })
  34. it('createKnownLicenseFromCode(): License can be created by name', () => {
  35. const NAME = 'CC_BY'
  36. const ATTRIBUTION = 'Attribution: Joystream'
  37. const licenseCode = getLicenseCodeByName(NAME) as number
  38. const license = createKnownLicenseFromCode(licenseCode, ATTRIBUTION)
  39. assert.isDefined(license.code)
  40. assert.equal(license.attribution, ATTRIBUTION)
  41. License.verify(license)
  42. })
  43. })