1 /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
3 import { expect } from 'chai'
10 setAccessTokensToServers
11 } from '@shared/server-commands'
12 import { HttpStatusCode, VideoPlaylistPrivacy } from '@shared/models'
14 describe('Test plugin altering video constants', function () {
15 let server: PeerTubeServer
17 before(async function () {
20 server = await createSingleServer(1)
21 await setAccessTokensToServers([ server ])
23 await server.plugins.install({ path: PluginsCommand.getPluginTestPath('-video-constants') })
26 it('Should have updated languages', async function () {
27 const languages = await server.videos.getLanguages()
29 expect(languages['en']).to.not.exist
30 expect(languages['fr']).to.not.exist
32 expect(languages['al_bhed']).to.equal('Al Bhed')
33 expect(languages['al_bhed2']).to.equal('Al Bhed 2')
34 expect(languages['al_bhed3']).to.not.exist
37 it('Should have updated categories', async function () {
38 const categories = await server.videos.getCategories()
40 expect(categories[1]).to.not.exist
41 expect(categories[2]).to.not.exist
43 expect(categories[42]).to.equal('Best category')
44 expect(categories[43]).to.equal('High best category')
47 it('Should have updated licences', async function () {
48 const licences = await server.videos.getLicences()
50 expect(licences[1]).to.not.exist
51 expect(licences[7]).to.not.exist
53 expect(licences[42]).to.equal('Best licence')
54 expect(licences[43]).to.equal('High best licence')
57 it('Should have updated video privacies', async function () {
58 const privacies = await server.videos.getPrivacies()
60 expect(privacies[1]).to.exist
61 expect(privacies[2]).to.not.exist
62 expect(privacies[3]).to.exist
63 expect(privacies[4]).to.exist
66 it('Should have updated playlist privacies', async function () {
67 const playlistPrivacies = await server.playlists.getPrivacies()
69 expect(playlistPrivacies[1]).to.exist
70 expect(playlistPrivacies[2]).to.exist
71 expect(playlistPrivacies[3]).to.not.exist
74 it('Should not be able to create a video with this privacy', async function () {
75 const attributes = { name: 'video', privacy: 2 }
76 await server.videos.upload({ attributes, expectedStatus: HttpStatusCode.BAD_REQUEST_400 })
79 it('Should not be able to create a video with this privacy', async function () {
80 const attributes = { displayName: 'video playlist', privacy: VideoPlaylistPrivacy.PRIVATE }
81 await server.playlists.create({ attributes, expectedStatus: HttpStatusCode.BAD_REQUEST_400 })
84 it('Should be able to upload a video with these values', async function () {
85 const attributes = { name: 'video', category: 42, licence: 42, language: 'al_bhed2' }
86 const { uuid } = await server.videos.upload({ attributes })
88 const video = await server.videos.get({ id: uuid })
89 expect(video.language.label).to.equal('Al Bhed 2')
90 expect(video.licence.label).to.equal('Best licence')
91 expect(video.category.label).to.equal('Best category')
94 it('Should uninstall the plugin and reset languages, categories, licences and privacies', async function () {
95 await server.plugins.uninstall({ npmName: 'peertube-plugin-test-video-constants' })
98 const languages = await server.videos.getLanguages()
100 expect(languages['en']).to.equal('English')
101 expect(languages['fr']).to.equal('French')
103 expect(languages['al_bhed']).to.not.exist
104 expect(languages['al_bhed2']).to.not.exist
105 expect(languages['al_bhed3']).to.not.exist
109 const categories = await server.videos.getCategories()
111 expect(categories[1]).to.equal('Music')
112 expect(categories[2]).to.equal('Films')
114 expect(categories[42]).to.not.exist
115 expect(categories[43]).to.not.exist
119 const licences = await server.videos.getLicences()
121 expect(licences[1]).to.equal('Attribution')
122 expect(licences[7]).to.equal('Public Domain Dedication')
124 expect(licences[42]).to.not.exist
125 expect(licences[43]).to.not.exist
129 const privacies = await server.videos.getPrivacies()
131 expect(privacies[1]).to.exist
132 expect(privacies[2]).to.exist
133 expect(privacies[3]).to.exist
134 expect(privacies[4]).to.exist
138 const playlistPrivacies = await server.playlists.getPrivacies()
140 expect(playlistPrivacies[1]).to.exist
141 expect(playlistPrivacies[2]).to.exist
142 expect(playlistPrivacies[3]).to.exist
146 it('Should be able to reset categories', async function () {
147 await server.plugins.install({ path: PluginsCommand.getPluginTestPath('-video-constants') })
150 const categories = await server.videos.getCategories()
152 expect(categories[1]).to.not.exist
153 expect(categories[2]).to.not.exist
155 expect(categories[42]).to.exist
156 expect(categories[43]).to.exist
159 await makeGetRequest({
161 token: server.accessToken,
162 path: '/plugins/test-video-constants/router/reset-categories',
163 expectedStatus: HttpStatusCode.NO_CONTENT_204
167 const categories = await server.videos.getCategories()
169 expect(categories[1]).to.exist
170 expect(categories[2]).to.exist
172 expect(categories[42]).to.not.exist
173 expect(categories[43]).to.not.exist
177 after(async function () {
178 await cleanupTests([ server ])