video-constant-registry-factory.ts 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155
  1. /* eslint-disable @typescript-eslint/no-unused-expressions */
  2. import 'mocha'
  3. import { expect } from 'chai'
  4. import { VideoConstantManagerFactory } from '@server/lib/plugins/video-constant-manager-factory'
  5. import {
  6. VIDEO_CATEGORIES,
  7. VIDEO_LANGUAGES,
  8. VIDEO_LICENCES,
  9. VIDEO_PLAYLIST_PRIVACIES,
  10. VIDEO_PRIVACIES
  11. } from '@server/initializers/constants'
  12. import {
  13. VideoPlaylistPrivacy,
  14. VideoPrivacy
  15. } from '@shared/models'
  16. describe('VideoConstantManagerFactory', function () {
  17. const factory = new VideoConstantManagerFactory('peertube-plugin-constants')
  18. afterEach(() => {
  19. factory.resetVideoConstants('peertube-plugin-constants')
  20. })
  21. describe('VideoCategoryManager', () => {
  22. const videoCategoryManager = factory.createVideoConstantManager<number>('category')
  23. it('Should be able to list all video category constants', () => {
  24. const constants = videoCategoryManager.getConstants()
  25. expect(constants).to.deep.equal(VIDEO_CATEGORIES)
  26. })
  27. it('Should be able to delete a video category constant', () => {
  28. const successfullyDeleted = videoCategoryManager.deleteConstant(1)
  29. expect(successfullyDeleted).to.be.true
  30. expect(videoCategoryManager.getConstantValue(1)).to.be.undefined
  31. })
  32. it('Should be able to add a video category constant', () => {
  33. const successfullyAdded = videoCategoryManager.addConstant(42, 'The meaning of life')
  34. expect(successfullyAdded).to.be.true
  35. expect(videoCategoryManager.getConstantValue(42)).to.equal('The meaning of life')
  36. })
  37. it('Should be able to reset video category constants', () => {
  38. videoCategoryManager.deleteConstant(1)
  39. videoCategoryManager.resetConstants()
  40. expect(videoCategoryManager.getConstantValue(1)).not.be.undefined
  41. })
  42. })
  43. describe('VideoLicenceManager', () => {
  44. const videoLicenceManager = factory.createVideoConstantManager<number>('licence')
  45. it('Should be able to list all video licence constants', () => {
  46. const constants = videoLicenceManager.getConstants()
  47. expect(constants).to.deep.equal(VIDEO_LICENCES)
  48. })
  49. it('Should be able to delete a video licence constant', () => {
  50. const successfullyDeleted = videoLicenceManager.deleteConstant(1)
  51. expect(successfullyDeleted).to.be.true
  52. expect(videoLicenceManager.getConstantValue(1)).to.be.undefined
  53. })
  54. it('Should be able to add a video licence constant', () => {
  55. const successfullyAdded = videoLicenceManager.addConstant(42, 'European Union Public Licence')
  56. expect(successfullyAdded).to.be.true
  57. expect(videoLicenceManager.getConstantValue(42)).to.equal('European Union Public Licence')
  58. })
  59. it('Should be able to reset video licence constants', () => {
  60. videoLicenceManager.deleteConstant(1)
  61. videoLicenceManager.resetConstants()
  62. expect(videoLicenceManager.getConstantValue(1)).not.be.undefined
  63. })
  64. })
  65. describe('PlaylistPrivacyManager', () => {
  66. const playlistPrivacyManager = factory.createVideoConstantManager<VideoPlaylistPrivacy>('playlistPrivacy')
  67. it('Should be able to list all video playlist privacy constants', () => {
  68. const constants = playlistPrivacyManager.getConstants()
  69. expect(constants).to.deep.equal(VIDEO_PLAYLIST_PRIVACIES)
  70. })
  71. it('Should be able to delete a video playlist privacy constant', () => {
  72. const successfullyDeleted = playlistPrivacyManager.deleteConstant(1)
  73. expect(successfullyDeleted).to.be.true
  74. expect(playlistPrivacyManager.getConstantValue(1)).to.be.undefined
  75. })
  76. it('Should be able to add a video playlist privacy constant', () => {
  77. const successfullyAdded = playlistPrivacyManager.addConstant(42, 'Friends only')
  78. expect(successfullyAdded).to.be.true
  79. expect(playlistPrivacyManager.getConstantValue(42)).to.equal('Friends only')
  80. })
  81. it('Should be able to reset video playlist privacy constants', () => {
  82. playlistPrivacyManager.deleteConstant(1)
  83. playlistPrivacyManager.resetConstants()
  84. expect(playlistPrivacyManager.getConstantValue(1)).not.be.undefined
  85. })
  86. })
  87. describe('VideoPrivacyManager', () => {
  88. const videoPrivacyManager = factory.createVideoConstantManager<VideoPrivacy>('privacy')
  89. it('Should be able to list all video privacy constants', () => {
  90. const constants = videoPrivacyManager.getConstants()
  91. expect(constants).to.deep.equal(VIDEO_PRIVACIES)
  92. })
  93. it('Should be able to delete a video privacy constant', () => {
  94. const successfullyDeleted = videoPrivacyManager.deleteConstant(1)
  95. expect(successfullyDeleted).to.be.true
  96. expect(videoPrivacyManager.getConstantValue(1)).to.be.undefined
  97. })
  98. it('Should be able to add a video privacy constant', () => {
  99. const successfullyAdded = videoPrivacyManager.addConstant(42, 'Friends only')
  100. expect(successfullyAdded).to.be.true
  101. expect(videoPrivacyManager.getConstantValue(42)).to.equal('Friends only')
  102. })
  103. it('Should be able to reset video privacy constants', () => {
  104. videoPrivacyManager.deleteConstant(1)
  105. videoPrivacyManager.resetConstants()
  106. expect(videoPrivacyManager.getConstantValue(1)).not.be.undefined
  107. })
  108. })
  109. describe('VideoLanguageManager', () => {
  110. const videoLanguageManager = factory.createVideoConstantManager<string>('language')
  111. it('Should be able to list all video language constants', () => {
  112. const constants = videoLanguageManager.getConstants()
  113. expect(constants).to.deep.equal(VIDEO_LANGUAGES)
  114. })
  115. it('Should be able to add a video language constant', () => {
  116. const successfullyAdded = videoLanguageManager.addConstant('fr', 'Fr occitan')
  117. expect(successfullyAdded).to.be.true
  118. expect(videoLanguageManager.getConstantValue('fr')).to.equal('Fr occitan')
  119. })
  120. it('Should be able to delete a video language constant', () => {
  121. videoLanguageManager.addConstant('fr', 'Fr occitan')
  122. const successfullyDeleted = videoLanguageManager.deleteConstant('fr')
  123. expect(successfullyDeleted).to.be.true
  124. expect(videoLanguageManager.getConstantValue('fr')).to.be.undefined
  125. })
  126. it('Should be able to reset video language constants', () => {
  127. videoLanguageManager.addConstant('fr', 'Fr occitan')
  128. videoLanguageManager.resetConstants()
  129. expect(videoLanguageManager.getConstantValue('fr')).to.be.undefined
  130. })
  131. })
  132. })