1 /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
4 import * as chai from 'chai'
5 import { cleanupTests, createSingleServer, PeerTubeServer, PluginsCommand, setAccessTokensToServers } from '@shared/extra-utils'
6 import { HttpStatusCode, VideoPlaylistPrivacy } from '@shared/models'
8 const expect = chai.expect
10 describe('Test plugin altering video constants', function () {
11 let server: PeerTubeServer
13 before(async function () {
16 server = await createSingleServer(1)
17 await setAccessTokensToServers([ server ])
19 await server.plugins.install({ path: PluginsCommand.getPluginTestPath('-video-constants') })
22 it('Should have updated languages', async function () {
23 const languages = await server.videos.getLanguages()
25 expect(languages['en']).to.not.exist
26 expect(languages['fr']).to.not.exist
28 expect(languages['al_bhed']).to.equal('Al Bhed')
29 expect(languages['al_bhed2']).to.equal('Al Bhed 2')
30 expect(languages['al_bhed3']).to.not.exist
33 it('Should have updated categories', async function () {
34 const categories = await server.videos.getCategories()
36 expect(categories[1]).to.not.exist
37 expect(categories[2]).to.not.exist
39 expect(categories[42]).to.equal('Best category')
40 expect(categories[43]).to.equal('High best category')
43 it('Should have updated licences', async function () {
44 const licences = await server.videos.getLicences()
46 expect(licences[1]).to.not.exist
47 expect(licences[7]).to.not.exist
49 expect(licences[42]).to.equal('Best licence')
50 expect(licences[43]).to.equal('High best licence')
53 it('Should have updated video privacies', async function () {
54 const privacies = await server.videos.getPrivacies()
56 expect(privacies[1]).to.exist
57 expect(privacies[2]).to.not.exist
58 expect(privacies[3]).to.exist
59 expect(privacies[4]).to.exist
62 it('Should have updated playlist privacies', async function () {
63 const playlistPrivacies = await server.playlists.getPrivacies()
65 expect(playlistPrivacies[1]).to.exist
66 expect(playlistPrivacies[2]).to.exist
67 expect(playlistPrivacies[3]).to.not.exist
70 it('Should not be able to create a video with this privacy', async function () {
71 const attributes = { name: 'video', privacy: 2 }
72 await server.videos.upload({ attributes, expectedStatus: HttpStatusCode.BAD_REQUEST_400 })
75 it('Should not be able to create a video with this privacy', async function () {
76 const attributes = { displayName: 'video playlist', privacy: VideoPlaylistPrivacy.PRIVATE }
77 await server.playlists.create({ attributes, expectedStatus: HttpStatusCode.BAD_REQUEST_400 })
80 it('Should be able to upload a video with these values', async function () {
81 const attributes = { name: 'video', category: 42, licence: 42, language: 'al_bhed2' }
82 const { uuid } = await server.videos.upload({ attributes })
84 const video = await server.videos.get({ id: uuid })
85 expect(video.language.label).to.equal('Al Bhed 2')
86 expect(video.licence.label).to.equal('Best licence')
87 expect(video.category.label).to.equal('Best category')
90 it('Should uninstall the plugin and reset languages, categories, licences and privacies', async function () {
91 await server.plugins.uninstall({ npmName: 'peertube-plugin-test-video-constants' })
94 const languages = await server.videos.getLanguages()
96 expect(languages['en']).to.equal('English')
97 expect(languages['fr']).to.equal('French')
99 expect(languages['al_bhed']).to.not.exist
100 expect(languages['al_bhed2']).to.not.exist
101 expect(languages['al_bhed3']).to.not.exist
105 const categories = await server.videos.getCategories()
107 expect(categories[1]).to.equal('Music')
108 expect(categories[2]).to.equal('Films')
110 expect(categories[42]).to.not.exist
111 expect(categories[43]).to.not.exist
115 const licences = await server.videos.getLicences()
117 expect(licences[1]).to.equal('Attribution')
118 expect(licences[7]).to.equal('Public Domain Dedication')
120 expect(licences[42]).to.not.exist
121 expect(licences[43]).to.not.exist
125 const privacies = await server.videos.getPrivacies()
127 expect(privacies[1]).to.exist
128 expect(privacies[2]).to.exist
129 expect(privacies[3]).to.exist
130 expect(privacies[4]).to.exist
134 const playlistPrivacies = await server.playlists.getPrivacies()
136 expect(playlistPrivacies[1]).to.exist
137 expect(playlistPrivacies[2]).to.exist
138 expect(playlistPrivacies[3]).to.exist
142 after(async function () {
143 await cleanupTests([ server ])