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