1 /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
4 import * as chai from 'chai'
5 import { HttpStatusCode } from '@shared/core-utils'
14 getVideoPlaylistPrivacies,
18 setAccessTokensToServers,
20 } from '@shared/extra-utils'
21 import { VideoDetails, VideoPlaylistPrivacy } from '@shared/models'
23 const expect = chai.expect
25 describe('Test plugin altering video constants', function () {
26 let server: ServerInfo
28 before(async function () {
31 server = await flushAndRunServer(1)
32 await setAccessTokensToServers([ server ])
34 await server.pluginsCommand.install({ path: PluginsCommand.getPluginTestPath('-video-constants') })
37 it('Should have updated languages', async function () {
38 const res = await getVideoLanguages(server.url)
39 const languages = res.body
41 expect(languages['en']).to.not.exist
42 expect(languages['fr']).to.not.exist
44 expect(languages['al_bhed']).to.equal('Al Bhed')
45 expect(languages['al_bhed2']).to.equal('Al Bhed 2')
46 expect(languages['al_bhed3']).to.not.exist
49 it('Should have updated categories', async function () {
50 const res = await getVideoCategories(server.url)
51 const categories = res.body
53 expect(categories[1]).to.not.exist
54 expect(categories[2]).to.not.exist
56 expect(categories[42]).to.equal('Best category')
57 expect(categories[43]).to.equal('High best category')
60 it('Should have updated licences', async function () {
61 const res = await getVideoLicences(server.url)
62 const licences = res.body
64 expect(licences[1]).to.not.exist
65 expect(licences[7]).to.not.exist
67 expect(licences[42]).to.equal('Best licence')
68 expect(licences[43]).to.equal('High best licence')
71 it('Should have updated video privacies', async function () {
72 const res = await getVideoPrivacies(server.url)
73 const privacies = res.body
75 expect(privacies[1]).to.exist
76 expect(privacies[2]).to.not.exist
77 expect(privacies[3]).to.exist
78 expect(privacies[4]).to.exist
81 it('Should have updated playlist privacies', async function () {
82 const res = await getVideoPlaylistPrivacies(server.url)
83 const playlistPrivacies = res.body
85 expect(playlistPrivacies[1]).to.exist
86 expect(playlistPrivacies[2]).to.exist
87 expect(playlistPrivacies[3]).to.not.exist
90 it('Should not be able to create a video with this privacy', async function () {
91 const attrs = { name: 'video', privacy: 2 }
92 await uploadVideo(server.url, server.accessToken, attrs, HttpStatusCode.BAD_REQUEST_400)
95 it('Should not be able to create a video with this privacy', async function () {
96 const attrs = { displayName: 'video playlist', privacy: VideoPlaylistPrivacy.PRIVATE }
97 await createVideoPlaylist({
99 token: server.accessToken,
100 playlistAttrs: attrs,
101 expectedStatus: HttpStatusCode.BAD_REQUEST_400
105 it('Should be able to upload a video with these values', async function () {
106 const attrs = { name: 'video', category: 42, licence: 42, language: 'al_bhed2' }
107 const resUpload = await uploadVideo(server.url, server.accessToken, attrs)
109 const res = await getVideo(server.url, resUpload.body.video.uuid)
111 const video: VideoDetails = res.body
112 expect(video.language.label).to.equal('Al Bhed 2')
113 expect(video.licence.label).to.equal('Best licence')
114 expect(video.category.label).to.equal('Best category')
117 it('Should uninstall the plugin and reset languages, categories, licences and privacies', async function () {
118 await server.pluginsCommand.uninstall({ npmName: 'peertube-plugin-test-video-constants' })
121 const res = await getVideoLanguages(server.url)
122 const languages = res.body
124 expect(languages['en']).to.equal('English')
125 expect(languages['fr']).to.equal('French')
127 expect(languages['al_bhed']).to.not.exist
128 expect(languages['al_bhed2']).to.not.exist
129 expect(languages['al_bhed3']).to.not.exist
133 const res = await getVideoCategories(server.url)
134 const categories = res.body
136 expect(categories[1]).to.equal('Music')
137 expect(categories[2]).to.equal('Films')
139 expect(categories[42]).to.not.exist
140 expect(categories[43]).to.not.exist
144 const res = await getVideoLicences(server.url)
145 const licences = res.body
147 expect(licences[1]).to.equal('Attribution')
148 expect(licences[7]).to.equal('Public Domain Dedication')
150 expect(licences[42]).to.not.exist
151 expect(licences[43]).to.not.exist
155 const res = await getVideoPrivacies(server.url)
156 const privacies = res.body
158 expect(privacies[1]).to.exist
159 expect(privacies[2]).to.exist
160 expect(privacies[3]).to.exist
161 expect(privacies[4]).to.exist
165 const res = await getVideoPlaylistPrivacies(server.url)
166 const playlistPrivacies = res.body
168 expect(playlistPrivacies[1]).to.exist
169 expect(playlistPrivacies[2]).to.exist
170 expect(playlistPrivacies[3]).to.exist
174 after(async function () {
175 await cleanupTests([ server ])