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'
16 setAccessTokensToServers,
18 } from '@shared/extra-utils'
19 import { VideoDetails, VideoPlaylistPrivacy } from '@shared/models'
21 const expect = chai.expect
23 describe('Test plugin altering video constants', function () {
24 let server: ServerInfo
26 before(async function () {
29 server = await flushAndRunServer(1)
30 await setAccessTokensToServers([ server ])
32 await server.pluginsCommand.install({ path: PluginsCommand.getPluginTestPath('-video-constants') })
35 it('Should have updated languages', async function () {
36 const res = await getVideoLanguages(server.url)
37 const languages = res.body
39 expect(languages['en']).to.not.exist
40 expect(languages['fr']).to.not.exist
42 expect(languages['al_bhed']).to.equal('Al Bhed')
43 expect(languages['al_bhed2']).to.equal('Al Bhed 2')
44 expect(languages['al_bhed3']).to.not.exist
47 it('Should have updated categories', async function () {
48 const res = await getVideoCategories(server.url)
49 const categories = res.body
51 expect(categories[1]).to.not.exist
52 expect(categories[2]).to.not.exist
54 expect(categories[42]).to.equal('Best category')
55 expect(categories[43]).to.equal('High best category')
58 it('Should have updated licences', async function () {
59 const res = await getVideoLicences(server.url)
60 const licences = res.body
62 expect(licences[1]).to.not.exist
63 expect(licences[7]).to.not.exist
65 expect(licences[42]).to.equal('Best licence')
66 expect(licences[43]).to.equal('High best licence')
69 it('Should have updated video privacies', async function () {
70 const res = await getVideoPrivacies(server.url)
71 const privacies = res.body
73 expect(privacies[1]).to.exist
74 expect(privacies[2]).to.not.exist
75 expect(privacies[3]).to.exist
76 expect(privacies[4]).to.exist
79 it('Should have updated playlist privacies', async function () {
80 const playlistPrivacies = await server.playlistsCommand.getPrivacies()
82 expect(playlistPrivacies[1]).to.exist
83 expect(playlistPrivacies[2]).to.exist
84 expect(playlistPrivacies[3]).to.not.exist
87 it('Should not be able to create a video with this privacy', async function () {
88 const attrs = { name: 'video', privacy: 2 }
89 await uploadVideo(server.url, server.accessToken, attrs, HttpStatusCode.BAD_REQUEST_400)
92 it('Should not be able to create a video with this privacy', async function () {
93 const attributes = { displayName: 'video playlist', privacy: VideoPlaylistPrivacy.PRIVATE }
94 await server.playlistsCommand.create({ attributes, expectedStatus: HttpStatusCode.BAD_REQUEST_400 })
97 it('Should be able to upload a video with these values', async function () {
98 const attrs = { name: 'video', category: 42, licence: 42, language: 'al_bhed2' }
99 const resUpload = await uploadVideo(server.url, server.accessToken, attrs)
101 const res = await getVideo(server.url, resUpload.body.video.uuid)
103 const video: VideoDetails = res.body
104 expect(video.language.label).to.equal('Al Bhed 2')
105 expect(video.licence.label).to.equal('Best licence')
106 expect(video.category.label).to.equal('Best category')
109 it('Should uninstall the plugin and reset languages, categories, licences and privacies', async function () {
110 await server.pluginsCommand.uninstall({ npmName: 'peertube-plugin-test-video-constants' })
113 const res = await getVideoLanguages(server.url)
114 const languages = res.body
116 expect(languages['en']).to.equal('English')
117 expect(languages['fr']).to.equal('French')
119 expect(languages['al_bhed']).to.not.exist
120 expect(languages['al_bhed2']).to.not.exist
121 expect(languages['al_bhed3']).to.not.exist
125 const res = await getVideoCategories(server.url)
126 const categories = res.body
128 expect(categories[1]).to.equal('Music')
129 expect(categories[2]).to.equal('Films')
131 expect(categories[42]).to.not.exist
132 expect(categories[43]).to.not.exist
136 const res = await getVideoLicences(server.url)
137 const licences = res.body
139 expect(licences[1]).to.equal('Attribution')
140 expect(licences[7]).to.equal('Public Domain Dedication')
142 expect(licences[42]).to.not.exist
143 expect(licences[43]).to.not.exist
147 const res = await getVideoPrivacies(server.url)
148 const privacies = res.body
150 expect(privacies[1]).to.exist
151 expect(privacies[2]).to.exist
152 expect(privacies[3]).to.exist
153 expect(privacies[4]).to.exist
157 const playlistPrivacies = await server.playlistsCommand.getPrivacies()
159 expect(playlistPrivacies[1]).to.exist
160 expect(playlistPrivacies[2]).to.exist
161 expect(playlistPrivacies[3]).to.exist
165 after(async function () {
166 await cleanupTests([ server ])