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