From dc3d902234bb73fbc8cf9787e3036f2012526e6c Mon Sep 17 00:00:00 2001 From: lutangar Date: Tue, 29 Jun 2021 16:02:05 +0200 Subject: Introduce generic video constant manager for plugins Allow a plugin developer to get back constants values, and reset constants deletions or additions. --- .../peertube-plugin-test-video-constants/main.js | 58 ++++---- .../video-constant-registry-factory.test.ts | 155 +++++++++++++++++++++ server/tests/plugins/video-constants.ts | 37 ++++- 3 files changed, 219 insertions(+), 31 deletions(-) create mode 100644 server/tests/lib/plugins/video-constant-registry-factory.test.ts (limited to 'server/tests') diff --git a/server/tests/fixtures/peertube-plugin-test-video-constants/main.js b/server/tests/fixtures/peertube-plugin-test-video-constants/main.js index 3e650e0a1..f44704a44 100644 --- a/server/tests/fixtures/peertube-plugin-test-video-constants/main.js +++ b/server/tests/fixtures/peertube-plugin-test-video-constants/main.js @@ -1,46 +1,44 @@ async function register ({ - registerHook, - registerSetting, - settingsManager, - storageManager, videoCategoryManager, videoLicenceManager, videoLanguageManager, videoPrivacyManager, - playlistPrivacyManager + playlistPrivacyManager, + getRouter }) { - videoLanguageManager.addLanguage('al_bhed', 'Al Bhed') - videoLanguageManager.addLanguage('al_bhed2', 'Al Bhed 2') - videoLanguageManager.addLanguage('al_bhed3', 'Al Bhed 3') - videoLanguageManager.deleteLanguage('en') - videoLanguageManager.deleteLanguage('fr') - videoLanguageManager.deleteLanguage('al_bhed3') + videoLanguageManager.addConstant('al_bhed', 'Al Bhed') + videoLanguageManager.addConstant('al_bhed2', 'Al Bhed 2') + videoLanguageManager.addConstant('al_bhed3', 'Al Bhed 3') + videoLanguageManager.deleteConstant('en') + videoLanguageManager.deleteConstant('fr') + videoLanguageManager.deleteConstant('al_bhed3') - videoCategoryManager.addCategory(42, 'Best category') - videoCategoryManager.addCategory(43, 'High best category') - videoCategoryManager.deleteCategory(1) // Music - videoCategoryManager.deleteCategory(2) // Films + videoCategoryManager.addConstant(42, 'Best category') + videoCategoryManager.addConstant(43, 'High best category') + videoCategoryManager.deleteConstant(1) // Music + videoCategoryManager.deleteConstant(2) // Films - videoLicenceManager.addLicence(42, 'Best licence') - videoLicenceManager.addLicence(43, 'High best licence') - videoLicenceManager.deleteLicence(1) // Attribution - videoLicenceManager.deleteLicence(7) // Public domain + videoLicenceManager.addConstant(42, 'Best licence') + videoLicenceManager.addConstant(43, 'High best licence') + videoLicenceManager.deleteConstant(1) // Attribution + videoLicenceManager.deleteConstant(7) // Public domain - videoPrivacyManager.deletePrivacy(2) - playlistPrivacyManager.deletePlaylistPrivacy(3) -} + videoPrivacyManager.deleteConstant(2) + playlistPrivacyManager.deleteConstant(3) + + { + const router = getRouter() + router.get('/reset-categories', (req, res) => { + videoCategoryManager.resetConstants() -async function unregister () { - return + res.sendStatus(204) + }) + } } +async function unregister () {} + module.exports = { register, unregister } - -// ############################################################################ - -function addToCount (obj) { - return Object.assign({}, obj, { count: obj.count + 1 }) -} 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 @@ +/* eslint-disable @typescript-eslint/no-unused-expressions */ +import 'mocha' +import { expect } from 'chai' +import { VideoConstantManagerFactory } from '@server/lib/plugins/video-constant-manager-factory' +import { + VIDEO_CATEGORIES, + VIDEO_LANGUAGES, + VIDEO_LICENCES, + VIDEO_PLAYLIST_PRIVACIES, + VIDEO_PRIVACIES +} from '@server/initializers/constants' +import { + VideoPlaylistPrivacy, + VideoPrivacy +} from '@shared/models' + +describe('VideoConstantManagerFactory', function () { + const factory = new VideoConstantManagerFactory('peertube-plugin-constants') + + afterEach(() => { + factory.resetVideoConstants('peertube-plugin-constants') + }) + + describe('VideoCategoryManager', () => { + const videoCategoryManager = factory.createVideoConstantManager('category') + + it('Should be able to list all video category constants', () => { + const constants = videoCategoryManager.getConstants() + expect(constants).to.deep.equal(VIDEO_CATEGORIES) + }) + + it('Should be able to delete a video category constant', () => { + const successfullyDeleted = videoCategoryManager.deleteConstant(1) + expect(successfullyDeleted).to.be.true + expect(videoCategoryManager.getConstantValue(1)).to.be.undefined + }) + + it('Should be able to add a video category constant', () => { + const successfullyAdded = videoCategoryManager.addConstant(42, 'The meaning of life') + expect(successfullyAdded).to.be.true + expect(videoCategoryManager.getConstantValue(42)).to.equal('The meaning of life') + }) + + it('Should be able to reset video category constants', () => { + videoCategoryManager.deleteConstant(1) + videoCategoryManager.resetConstants() + expect(videoCategoryManager.getConstantValue(1)).not.be.undefined + }) + }) + + describe('VideoLicenceManager', () => { + const videoLicenceManager = factory.createVideoConstantManager('licence') + it('Should be able to list all video licence constants', () => { + const constants = videoLicenceManager.getConstants() + expect(constants).to.deep.equal(VIDEO_LICENCES) + }) + + it('Should be able to delete a video licence constant', () => { + const successfullyDeleted = videoLicenceManager.deleteConstant(1) + expect(successfullyDeleted).to.be.true + expect(videoLicenceManager.getConstantValue(1)).to.be.undefined + }) + + it('Should be able to add a video licence constant', () => { + const successfullyAdded = videoLicenceManager.addConstant(42, 'European Union Public Licence') + expect(successfullyAdded).to.be.true + expect(videoLicenceManager.getConstantValue(42)).to.equal('European Union Public Licence') + }) + + it('Should be able to reset video licence constants', () => { + videoLicenceManager.deleteConstant(1) + videoLicenceManager.resetConstants() + expect(videoLicenceManager.getConstantValue(1)).not.be.undefined + }) + }) + + describe('PlaylistPrivacyManager', () => { + const playlistPrivacyManager = factory.createVideoConstantManager('playlistPrivacy') + it('Should be able to list all video playlist privacy constants', () => { + const constants = playlistPrivacyManager.getConstants() + expect(constants).to.deep.equal(VIDEO_PLAYLIST_PRIVACIES) + }) + + it('Should be able to delete a video playlist privacy constant', () => { + const successfullyDeleted = playlistPrivacyManager.deleteConstant(1) + expect(successfullyDeleted).to.be.true + expect(playlistPrivacyManager.getConstantValue(1)).to.be.undefined + }) + + it('Should be able to add a video playlist privacy constant', () => { + const successfullyAdded = playlistPrivacyManager.addConstant(42, 'Friends only') + expect(successfullyAdded).to.be.true + expect(playlistPrivacyManager.getConstantValue(42)).to.equal('Friends only') + }) + + it('Should be able to reset video playlist privacy constants', () => { + playlistPrivacyManager.deleteConstant(1) + playlistPrivacyManager.resetConstants() + expect(playlistPrivacyManager.getConstantValue(1)).not.be.undefined + }) + }) + + describe('VideoPrivacyManager', () => { + const videoPrivacyManager = factory.createVideoConstantManager('privacy') + it('Should be able to list all video privacy constants', () => { + const constants = videoPrivacyManager.getConstants() + expect(constants).to.deep.equal(VIDEO_PRIVACIES) + }) + + it('Should be able to delete a video privacy constant', () => { + const successfullyDeleted = videoPrivacyManager.deleteConstant(1) + expect(successfullyDeleted).to.be.true + expect(videoPrivacyManager.getConstantValue(1)).to.be.undefined + }) + + it('Should be able to add a video privacy constant', () => { + const successfullyAdded = videoPrivacyManager.addConstant(42, 'Friends only') + expect(successfullyAdded).to.be.true + expect(videoPrivacyManager.getConstantValue(42)).to.equal('Friends only') + }) + + it('Should be able to reset video privacy constants', () => { + videoPrivacyManager.deleteConstant(1) + videoPrivacyManager.resetConstants() + expect(videoPrivacyManager.getConstantValue(1)).not.be.undefined + }) + }) + + describe('VideoLanguageManager', () => { + const videoLanguageManager = factory.createVideoConstantManager('language') + it('Should be able to list all video language constants', () => { + const constants = videoLanguageManager.getConstants() + expect(constants).to.deep.equal(VIDEO_LANGUAGES) + }) + + it('Should be able to add a video language constant', () => { + const successfullyAdded = videoLanguageManager.addConstant('fr', 'Fr occitan') + expect(successfullyAdded).to.be.true + expect(videoLanguageManager.getConstantValue('fr')).to.equal('Fr occitan') + }) + + it('Should be able to delete a video language constant', () => { + videoLanguageManager.addConstant('fr', 'Fr occitan') + const successfullyDeleted = videoLanguageManager.deleteConstant('fr') + expect(successfullyDeleted).to.be.true + expect(videoLanguageManager.getConstantValue('fr')).to.be.undefined + }) + + it('Should be able to reset video language constants', () => { + videoLanguageManager.addConstant('fr', 'Fr occitan') + videoLanguageManager.resetConstants() + expect(videoLanguageManager.getConstantValue('fr')).to.be.undefined + }) + }) +}) diff --git a/server/tests/plugins/video-constants.ts b/server/tests/plugins/video-constants.ts index eb014c596..7b1312f88 100644 --- a/server/tests/plugins/video-constants.ts +++ b/server/tests/plugins/video-constants.ts @@ -9,8 +9,11 @@ import { getVideo, getVideoCategories, getVideoLanguages, - getVideoLicences, getVideoPlaylistPrivacies, getVideoPrivacies, + getVideoLicences, + getVideoPlaylistPrivacies, + getVideoPrivacies, installPlugin, + makeGetRequest, setAccessTokensToServers, uninstallPlugin, uploadVideo @@ -173,6 +176,38 @@ describe('Test plugin altering video constants', function () { } }) + it('Should be able to reset categories', async function () { + await installPlugin({ + url: server.url, + accessToken: server.accessToken, + path: getPluginTestPath('-video-constants') + }) + + let { body: categories } = await getVideoCategories(server.url) + + expect(categories[1]).to.not.exist + expect(categories[2]).to.not.exist + + expect(categories[42]).to.exist + expect(categories[43]).to.exist + + await makeGetRequest({ + url: server.url, + token: server.accessToken, + path: '/plugins/test-video-constants/router/reset-categories', + statusCodeExpected: HttpStatusCode.NO_CONTENT_204 + }) + + const { body } = await getVideoCategories(server.url) + categories = body + + expect(categories[1]).to.exist + expect(categories[2]).to.exist + + expect(categories[42]).to.not.exist + expect(categories[43]).to.not.exist + }) + after(async function () { await cleanupTests([ server ]) }) -- cgit v1.2.3 From 2b9f672b58bc2c13c96ee79f522003979e4bfc02 Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Wed, 21 Jul 2021 15:44:28 +0200 Subject: Improve plugin constant tests --- .../peertube-plugin-test-video-constants/main.js | 12 +- server/tests/index.ts | 1 + server/tests/lib/index.ts | 1 + .../video-constant-registry-factory.test.ts | 155 --------------------- .../tests/lib/video-constant-registry-factory.ts | 155 +++++++++++++++++++++ 5 files changed, 164 insertions(+), 160 deletions(-) create mode 100644 server/tests/lib/index.ts delete mode 100644 server/tests/lib/plugins/video-constant-registry-factory.test.ts create mode 100644 server/tests/lib/video-constant-registry-factory.ts (limited to 'server/tests') diff --git a/server/tests/fixtures/peertube-plugin-test-video-constants/main.js b/server/tests/fixtures/peertube-plugin-test-video-constants/main.js index f44704a44..06527bd35 100644 --- a/server/tests/fixtures/peertube-plugin-test-video-constants/main.js +++ b/server/tests/fixtures/peertube-plugin-test-video-constants/main.js @@ -7,24 +7,26 @@ async function register ({ getRouter }) { videoLanguageManager.addConstant('al_bhed', 'Al Bhed') - videoLanguageManager.addConstant('al_bhed2', 'Al Bhed 2') + videoLanguageManager.addLanguage('al_bhed2', 'Al Bhed 2') videoLanguageManager.addConstant('al_bhed3', 'Al Bhed 3') videoLanguageManager.deleteConstant('en') - videoLanguageManager.deleteConstant('fr') + videoLanguageManager.deleteLanguage('fr') videoLanguageManager.deleteConstant('al_bhed3') - videoCategoryManager.addConstant(42, 'Best category') + videoCategoryManager.addCategory(42, 'Best category') videoCategoryManager.addConstant(43, 'High best category') videoCategoryManager.deleteConstant(1) // Music - videoCategoryManager.deleteConstant(2) // Films + videoCategoryManager.deleteCategory(2) // Films - videoLicenceManager.addConstant(42, 'Best licence') + videoLicenceManager.addLicence(42, 'Best licence') videoLicenceManager.addConstant(43, 'High best licence') videoLicenceManager.deleteConstant(1) // Attribution videoLicenceManager.deleteConstant(7) // Public domain videoPrivacyManager.deleteConstant(2) + videoPrivacyManager.deletePrivacy(2) playlistPrivacyManager.deleteConstant(3) + playlistPrivacyManager.deletePlaylistPrivacy(3) { const router = getRouter() diff --git a/server/tests/index.ts b/server/tests/index.ts index 3fbd0ebbd..1718ac424 100644 --- a/server/tests/index.ts +++ b/server/tests/index.ts @@ -6,3 +6,4 @@ import './cli/' import './api/' import './plugins/' import './helpers/' +import './lib/' 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/plugins/video-constant-registry-factory.test.ts b/server/tests/lib/plugins/video-constant-registry-factory.test.ts deleted file mode 100644 index e26b286e1..000000000 --- a/server/tests/lib/plugins/video-constant-registry-factory.test.ts +++ /dev/null @@ -1,155 +0,0 @@ -/* eslint-disable @typescript-eslint/no-unused-expressions */ -import 'mocha' -import { expect } from 'chai' -import { VideoConstantManagerFactory } from '@server/lib/plugins/video-constant-manager-factory' -import { - VIDEO_CATEGORIES, - VIDEO_LANGUAGES, - VIDEO_LICENCES, - VIDEO_PLAYLIST_PRIVACIES, - VIDEO_PRIVACIES -} from '@server/initializers/constants' -import { - VideoPlaylistPrivacy, - VideoPrivacy -} from '@shared/models' - -describe('VideoConstantManagerFactory', function () { - const factory = new VideoConstantManagerFactory('peertube-plugin-constants') - - afterEach(() => { - factory.resetVideoConstants('peertube-plugin-constants') - }) - - describe('VideoCategoryManager', () => { - const videoCategoryManager = factory.createVideoConstantManager('category') - - it('Should be able to list all video category constants', () => { - const constants = videoCategoryManager.getConstants() - expect(constants).to.deep.equal(VIDEO_CATEGORIES) - }) - - it('Should be able to delete a video category constant', () => { - const successfullyDeleted = videoCategoryManager.deleteConstant(1) - expect(successfullyDeleted).to.be.true - expect(videoCategoryManager.getConstantValue(1)).to.be.undefined - }) - - it('Should be able to add a video category constant', () => { - const successfullyAdded = videoCategoryManager.addConstant(42, 'The meaning of life') - expect(successfullyAdded).to.be.true - expect(videoCategoryManager.getConstantValue(42)).to.equal('The meaning of life') - }) - - it('Should be able to reset video category constants', () => { - videoCategoryManager.deleteConstant(1) - videoCategoryManager.resetConstants() - expect(videoCategoryManager.getConstantValue(1)).not.be.undefined - }) - }) - - describe('VideoLicenceManager', () => { - const videoLicenceManager = factory.createVideoConstantManager('licence') - it('Should be able to list all video licence constants', () => { - const constants = videoLicenceManager.getConstants() - expect(constants).to.deep.equal(VIDEO_LICENCES) - }) - - it('Should be able to delete a video licence constant', () => { - const successfullyDeleted = videoLicenceManager.deleteConstant(1) - expect(successfullyDeleted).to.be.true - expect(videoLicenceManager.getConstantValue(1)).to.be.undefined - }) - - it('Should be able to add a video licence constant', () => { - const successfullyAdded = videoLicenceManager.addConstant(42, 'European Union Public Licence') - expect(successfullyAdded).to.be.true - expect(videoLicenceManager.getConstantValue(42)).to.equal('European Union Public Licence') - }) - - it('Should be able to reset video licence constants', () => { - videoLicenceManager.deleteConstant(1) - videoLicenceManager.resetConstants() - expect(videoLicenceManager.getConstantValue(1)).not.be.undefined - }) - }) - - describe('PlaylistPrivacyManager', () => { - const playlistPrivacyManager = factory.createVideoConstantManager('playlistPrivacy') - it('Should be able to list all video playlist privacy constants', () => { - const constants = playlistPrivacyManager.getConstants() - expect(constants).to.deep.equal(VIDEO_PLAYLIST_PRIVACIES) - }) - - it('Should be able to delete a video playlist privacy constant', () => { - const successfullyDeleted = playlistPrivacyManager.deleteConstant(1) - expect(successfullyDeleted).to.be.true - expect(playlistPrivacyManager.getConstantValue(1)).to.be.undefined - }) - - it('Should be able to add a video playlist privacy constant', () => { - const successfullyAdded = playlistPrivacyManager.addConstant(42, 'Friends only') - expect(successfullyAdded).to.be.true - expect(playlistPrivacyManager.getConstantValue(42)).to.equal('Friends only') - }) - - it('Should be able to reset video playlist privacy constants', () => { - playlistPrivacyManager.deleteConstant(1) - playlistPrivacyManager.resetConstants() - expect(playlistPrivacyManager.getConstantValue(1)).not.be.undefined - }) - }) - - describe('VideoPrivacyManager', () => { - const videoPrivacyManager = factory.createVideoConstantManager('privacy') - it('Should be able to list all video privacy constants', () => { - const constants = videoPrivacyManager.getConstants() - expect(constants).to.deep.equal(VIDEO_PRIVACIES) - }) - - it('Should be able to delete a video privacy constant', () => { - const successfullyDeleted = videoPrivacyManager.deleteConstant(1) - expect(successfullyDeleted).to.be.true - expect(videoPrivacyManager.getConstantValue(1)).to.be.undefined - }) - - it('Should be able to add a video privacy constant', () => { - const successfullyAdded = videoPrivacyManager.addConstant(42, 'Friends only') - expect(successfullyAdded).to.be.true - expect(videoPrivacyManager.getConstantValue(42)).to.equal('Friends only') - }) - - it('Should be able to reset video privacy constants', () => { - videoPrivacyManager.deleteConstant(1) - videoPrivacyManager.resetConstants() - expect(videoPrivacyManager.getConstantValue(1)).not.be.undefined - }) - }) - - describe('VideoLanguageManager', () => { - const videoLanguageManager = factory.createVideoConstantManager('language') - it('Should be able to list all video language constants', () => { - const constants = videoLanguageManager.getConstants() - expect(constants).to.deep.equal(VIDEO_LANGUAGES) - }) - - it('Should be able to add a video language constant', () => { - const successfullyAdded = videoLanguageManager.addConstant('fr', 'Fr occitan') - expect(successfullyAdded).to.be.true - expect(videoLanguageManager.getConstantValue('fr')).to.equal('Fr occitan') - }) - - it('Should be able to delete a video language constant', () => { - videoLanguageManager.addConstant('fr', 'Fr occitan') - const successfullyDeleted = videoLanguageManager.deleteConstant('fr') - expect(successfullyDeleted).to.be.true - expect(videoLanguageManager.getConstantValue('fr')).to.be.undefined - }) - - it('Should be able to reset video language constants', () => { - videoLanguageManager.addConstant('fr', 'Fr occitan') - videoLanguageManager.resetConstants() - expect(videoLanguageManager.getConstantValue('fr')).to.be.undefined - }) - }) -}) 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 @@ +/* eslint-disable @typescript-eslint/no-unused-expressions */ +import 'mocha' +import { expect } from 'chai' +import { VideoConstantManagerFactory } from '@server/lib/plugins/video-constant-manager-factory' +import { + VIDEO_CATEGORIES, + VIDEO_LANGUAGES, + VIDEO_LICENCES, + VIDEO_PLAYLIST_PRIVACIES, + VIDEO_PRIVACIES +} from '@server/initializers/constants' +import { + VideoPlaylistPrivacy, + VideoPrivacy +} from '@shared/models' + +describe('VideoConstantManagerFactory', function () { + const factory = new VideoConstantManagerFactory('peertube-plugin-constants') + + afterEach(() => { + factory.resetVideoConstants('peertube-plugin-constants') + }) + + describe('VideoCategoryManager', () => { + const videoCategoryManager = factory.createVideoConstantManager('category') + + it('Should be able to list all video category constants', () => { + const constants = videoCategoryManager.getConstants() + expect(constants).to.deep.equal(VIDEO_CATEGORIES) + }) + + it('Should be able to delete a video category constant', () => { + const successfullyDeleted = videoCategoryManager.deleteConstant(1) + expect(successfullyDeleted).to.be.true + expect(videoCategoryManager.getConstantValue(1)).to.be.undefined + }) + + it('Should be able to add a video category constant', () => { + const successfullyAdded = videoCategoryManager.addConstant(42, 'The meaning of life') + expect(successfullyAdded).to.be.true + expect(videoCategoryManager.getConstantValue(42)).to.equal('The meaning of life') + }) + + it('Should be able to reset video category constants', () => { + videoCategoryManager.deleteConstant(1) + videoCategoryManager.resetConstants() + expect(videoCategoryManager.getConstantValue(1)).not.be.undefined + }) + }) + + describe('VideoLicenceManager', () => { + const videoLicenceManager = factory.createVideoConstantManager('licence') + it('Should be able to list all video licence constants', () => { + const constants = videoLicenceManager.getConstants() + expect(constants).to.deep.equal(VIDEO_LICENCES) + }) + + it('Should be able to delete a video licence constant', () => { + const successfullyDeleted = videoLicenceManager.deleteConstant(1) + expect(successfullyDeleted).to.be.true + expect(videoLicenceManager.getConstantValue(1)).to.be.undefined + }) + + it('Should be able to add a video licence constant', () => { + const successfullyAdded = videoLicenceManager.addConstant(42, 'European Union Public Licence') + expect(successfullyAdded).to.be.true + expect(videoLicenceManager.getConstantValue(42)).to.equal('European Union Public Licence') + }) + + it('Should be able to reset video licence constants', () => { + videoLicenceManager.deleteConstant(1) + videoLicenceManager.resetConstants() + expect(videoLicenceManager.getConstantValue(1)).not.be.undefined + }) + }) + + describe('PlaylistPrivacyManager', () => { + const playlistPrivacyManager = factory.createVideoConstantManager('playlistPrivacy') + it('Should be able to list all video playlist privacy constants', () => { + const constants = playlistPrivacyManager.getConstants() + expect(constants).to.deep.equal(VIDEO_PLAYLIST_PRIVACIES) + }) + + it('Should be able to delete a video playlist privacy constant', () => { + const successfullyDeleted = playlistPrivacyManager.deleteConstant(1) + expect(successfullyDeleted).to.be.true + expect(playlistPrivacyManager.getConstantValue(1)).to.be.undefined + }) + + it('Should be able to add a video playlist privacy constant', () => { + const successfullyAdded = playlistPrivacyManager.addConstant(42, 'Friends only') + expect(successfullyAdded).to.be.true + expect(playlistPrivacyManager.getConstantValue(42)).to.equal('Friends only') + }) + + it('Should be able to reset video playlist privacy constants', () => { + playlistPrivacyManager.deleteConstant(1) + playlistPrivacyManager.resetConstants() + expect(playlistPrivacyManager.getConstantValue(1)).not.be.undefined + }) + }) + + describe('VideoPrivacyManager', () => { + const videoPrivacyManager = factory.createVideoConstantManager('privacy') + it('Should be able to list all video privacy constants', () => { + const constants = videoPrivacyManager.getConstants() + expect(constants).to.deep.equal(VIDEO_PRIVACIES) + }) + + it('Should be able to delete a video privacy constant', () => { + const successfullyDeleted = videoPrivacyManager.deleteConstant(1) + expect(successfullyDeleted).to.be.true + expect(videoPrivacyManager.getConstantValue(1)).to.be.undefined + }) + + it('Should be able to add a video privacy constant', () => { + const successfullyAdded = videoPrivacyManager.addConstant(42, 'Friends only') + expect(successfullyAdded).to.be.true + expect(videoPrivacyManager.getConstantValue(42)).to.equal('Friends only') + }) + + it('Should be able to reset video privacy constants', () => { + videoPrivacyManager.deleteConstant(1) + videoPrivacyManager.resetConstants() + expect(videoPrivacyManager.getConstantValue(1)).not.be.undefined + }) + }) + + describe('VideoLanguageManager', () => { + const videoLanguageManager = factory.createVideoConstantManager('language') + it('Should be able to list all video language constants', () => { + const constants = videoLanguageManager.getConstants() + expect(constants).to.deep.equal(VIDEO_LANGUAGES) + }) + + it('Should be able to add a video language constant', () => { + const successfullyAdded = videoLanguageManager.addConstant('fr', 'Fr occitan') + expect(successfullyAdded).to.be.true + expect(videoLanguageManager.getConstantValue('fr')).to.equal('Fr occitan') + }) + + it('Should be able to delete a video language constant', () => { + videoLanguageManager.addConstant('fr', 'Fr occitan') + const successfullyDeleted = videoLanguageManager.deleteConstant('fr') + expect(successfullyDeleted).to.be.true + expect(videoLanguageManager.getConstantValue('fr')).to.be.undefined + }) + + it('Should be able to reset video language constants', () => { + videoLanguageManager.addConstant('fr', 'Fr occitan') + videoLanguageManager.resetConstants() + expect(videoLanguageManager.getConstantValue('fr')).to.be.undefined + }) + }) +}) -- cgit v1.2.3