1 /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
4 import * as chai from 'chai'
11 setAccessTokensToServers
12 } from '@shared/server-commands'
13 import { HttpStatusCode, VideoPlaylistPrivacy } from '@shared/models'
15 const expect = chai.expect
17 describe('Test plugin altering video constants', function () {
18 let server: PeerTubeServer
20 before(async function () {
23 server = await createSingleServer(1)
24 await setAccessTokensToServers([ server ])
26 await server.plugins.install({ path: PluginsCommand.getPluginTestPath('-video-constants') })
29 it('Should have updated languages', async function () {
30 const languages = await server.videos.getLanguages()
32 expect(languages['en']).to.not.exist
33 expect(languages['fr']).to.not.exist
35 expect(languages['al_bhed']).to.equal('Al Bhed')
36 expect(languages['al_bhed2']).to.equal('Al Bhed 2')
37 expect(languages['al_bhed3']).to.not.exist
40 it('Should have updated categories', async function () {
41 const categories = await server.videos.getCategories()
43 expect(categories[1]).to.not.exist
44 expect(categories[2]).to.not.exist
46 expect(categories[42]).to.equal('Best category')
47 expect(categories[43]).to.equal('High best category')
50 it('Should have updated licences', async function () {
51 const licences = await server.videos.getLicences()
53 expect(licences[1]).to.not.exist
54 expect(licences[7]).to.not.exist
56 expect(licences[42]).to.equal('Best licence')
57 expect(licences[43]).to.equal('High best licence')
60 it('Should have updated video privacies', async function () {
61 const privacies = await server.videos.getPrivacies()
63 expect(privacies[1]).to.exist
64 expect(privacies[2]).to.not.exist
65 expect(privacies[3]).to.exist
66 expect(privacies[4]).to.exist
69 it('Should have updated playlist privacies', async function () {
70 const playlistPrivacies = await server.playlists.getPrivacies()
72 expect(playlistPrivacies[1]).to.exist
73 expect(playlistPrivacies[2]).to.exist
74 expect(playlistPrivacies[3]).to.not.exist
77 it('Should not be able to create a video with this privacy', async function () {
78 const attributes = { name: 'video', privacy: 2 }
79 await server.videos.upload({ attributes, expectedStatus: HttpStatusCode.BAD_REQUEST_400 })
82 it('Should not be able to create a video with this privacy', async function () {
83 const attributes = { displayName: 'video playlist', privacy: VideoPlaylistPrivacy.PRIVATE }
84 await server.playlists.create({ attributes, expectedStatus: HttpStatusCode.BAD_REQUEST_400 })
87 it('Should be able to upload a video with these values', async function () {
88 const attributes = { name: 'video', category: 42, licence: 42, language: 'al_bhed2' }
89 const { uuid } = await server.videos.upload({ attributes })
91 const video = await server.videos.get({ id: uuid })
92 expect(video.language.label).to.equal('Al Bhed 2')
93 expect(video.licence.label).to.equal('Best licence')
94 expect(video.category.label).to.equal('Best category')
97 it('Should uninstall the plugin and reset languages, categories, licences and privacies', async function () {
98 await server.plugins.uninstall({ npmName: 'peertube-plugin-test-video-constants' })
101 const languages = await server.videos.getLanguages()
103 expect(languages['en']).to.equal('English')
104 expect(languages['fr']).to.equal('French')
106 expect(languages['al_bhed']).to.not.exist
107 expect(languages['al_bhed2']).to.not.exist
108 expect(languages['al_bhed3']).to.not.exist
112 const categories = await server.videos.getCategories()
114 expect(categories[1]).to.equal('Music')
115 expect(categories[2]).to.equal('Films')
117 expect(categories[42]).to.not.exist
118 expect(categories[43]).to.not.exist
122 const licences = await server.videos.getLicences()
124 expect(licences[1]).to.equal('Attribution')
125 expect(licences[7]).to.equal('Public Domain Dedication')
127 expect(licences[42]).to.not.exist
128 expect(licences[43]).to.not.exist
132 const privacies = await server.videos.getPrivacies()
134 expect(privacies[1]).to.exist
135 expect(privacies[2]).to.exist
136 expect(privacies[3]).to.exist
137 expect(privacies[4]).to.exist
141 const playlistPrivacies = await server.playlists.getPrivacies()
143 expect(playlistPrivacies[1]).to.exist
144 expect(playlistPrivacies[2]).to.exist
145 expect(playlistPrivacies[3]).to.exist
149 it('Should be able to reset categories', async function () {
150 await server.plugins.install({ path: PluginsCommand.getPluginTestPath('-video-constants') })
153 const categories = await server.videos.getCategories()
155 expect(categories[1]).to.not.exist
156 expect(categories[2]).to.not.exist
158 expect(categories[42]).to.exist
159 expect(categories[43]).to.exist
162 await makeGetRequest({
164 token: server.accessToken,
165 path: '/plugins/test-video-constants/router/reset-categories',
166 expectedStatus: HttpStatusCode.NO_CONTENT_204
170 const categories = await server.videos.getCategories()
172 expect(categories[1]).to.exist
173 expect(categories[2]).to.exist
175 expect(categories[42]).to.not.exist
176 expect(categories[43]).to.not.exist
180 after(async function () {
181 await cleanupTests([ server ])