aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/tests/lib
diff options
context:
space:
mode:
authorChocobozzz <me@florianbigard.com>2021-07-21 15:45:42 +0200
committerChocobozzz <me@florianbigard.com>2021-07-21 15:45:42 +0200
commit5f26f13b3c16ac5ae0a3b0a7142d84a9528cf565 (patch)
tree64021f952b125ae3d152c07180804fd13adfeb48 /server/tests/lib
parent435990290a61ca6fdb679e6b076ef9157b89a6ce (diff)
parent2b9f672b58bc2c13c96ee79f522003979e4bfc02 (diff)
downloadPeerTube-5f26f13b3c16ac5ae0a3b0a7142d84a9528cf565.tar.gz
PeerTube-5f26f13b3c16ac5ae0a3b0a7142d84a9528cf565.tar.zst
PeerTube-5f26f13b3c16ac5ae0a3b0a7142d84a9528cf565.zip
Merge branch 'constant-registry' into develop
Diffstat (limited to 'server/tests/lib')
-rw-r--r--server/tests/lib/index.ts1
-rw-r--r--server/tests/lib/video-constant-registry-factory.ts155
2 files changed, 156 insertions, 0 deletions
diff --git a/server/tests/lib/index.ts b/server/tests/lib/index.ts
new file mode 100644
index 000000000..a40df35fd
--- /dev/null
+++ b/server/tests/lib/index.ts
@@ -0,0 +1 @@
export * from './video-constant-registry-factory'
diff --git a/server/tests/lib/video-constant-registry-factory.ts b/server/tests/lib/video-constant-registry-factory.ts
new file mode 100644
index 000000000..e26b286e1
--- /dev/null
+++ b/server/tests/lib/video-constant-registry-factory.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})