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