1 /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
3 import * as chai from 'chai'
5 import { cleanupTests, flushAndRunServer, ServerInfo } from '../../../shared/extra-utils/server/servers'
12 getVideoLicences, getVideoPlaylistPrivacies, getVideoPrivacies,
14 setAccessTokensToServers,
17 } from '../../../shared/extra-utils'
18 import { VideoDetails, VideoPlaylistPrivacy } from '../../../shared/models/videos'
19 import { HttpStatusCode } from '../../../shared/core-utils/miscs/http-error-codes'
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 ])
34 accessToken: server.accessToken,
35 path: getPluginTestPath('-video-constants')
39 it('Should have updated languages', async function () {
40 const res = await getVideoLanguages(server.url)
41 const languages = res.body
43 expect(languages['en']).to.not.exist
44 expect(languages['fr']).to.not.exist
46 expect(languages['al_bhed']).to.equal('Al Bhed')
47 expect(languages['al_bhed2']).to.equal('Al Bhed 2')
48 expect(languages['al_bhed3']).to.not.exist
51 it('Should have updated categories', async function () {
52 const res = await getVideoCategories(server.url)
53 const categories = res.body
55 expect(categories[1]).to.not.exist
56 expect(categories[2]).to.not.exist
58 expect(categories[42]).to.equal('Best category')
59 expect(categories[43]).to.equal('High best category')
62 it('Should have updated licences', async function () {
63 const res = await getVideoLicences(server.url)
64 const licences = res.body
66 expect(licences[1]).to.not.exist
67 expect(licences[7]).to.not.exist
69 expect(licences[42]).to.equal('Best licence')
70 expect(licences[43]).to.equal('High best licence')
73 it('Should have updated video privacies', async function () {
74 const res = await getVideoPrivacies(server.url)
75 const privacies = res.body
77 expect(privacies[1]).to.exist
78 expect(privacies[2]).to.not.exist
79 expect(privacies[3]).to.exist
80 expect(privacies[4]).to.exist
83 it('Should have updated playlist privacies', async function () {
84 const res = await getVideoPlaylistPrivacies(server.url)
85 const playlistPrivacies = res.body
87 expect(playlistPrivacies[1]).to.exist
88 expect(playlistPrivacies[2]).to.exist
89 expect(playlistPrivacies[3]).to.not.exist
92 it('Should not be able to create a video with this privacy', async function () {
93 const attrs = { name: 'video', privacy: 2 }
94 await uploadVideo(server.url, server.accessToken, attrs, HttpStatusCode.BAD_REQUEST_400)
97 it('Should not be able to create a video with this privacy', async function () {
98 const attrs = { displayName: 'video playlist', privacy: VideoPlaylistPrivacy.PRIVATE }
99 await createVideoPlaylist({
101 token: server.accessToken,
102 playlistAttrs: attrs,
103 expectedStatus: HttpStatusCode.BAD_REQUEST_400
107 it('Should be able to upload a video with these values', async function () {
108 const attrs = { name: 'video', category: 42, licence: 42, language: 'al_bhed2' }
109 const resUpload = await uploadVideo(server.url, server.accessToken, attrs)
111 const res = await getVideo(server.url, resUpload.body.video.uuid)
113 const video: VideoDetails = res.body
114 expect(video.language.label).to.equal('Al Bhed 2')
115 expect(video.licence.label).to.equal('Best licence')
116 expect(video.category.label).to.equal('Best category')
119 it('Should uninstall the plugin and reset languages, categories, licences and privacies', async function () {
120 await uninstallPlugin({ url: server.url, accessToken: server.accessToken, npmName: 'peertube-plugin-test-video-constants' })
123 const res = await getVideoLanguages(server.url)
124 const languages = res.body
126 expect(languages['en']).to.equal('English')
127 expect(languages['fr']).to.equal('French')
129 expect(languages['al_bhed']).to.not.exist
130 expect(languages['al_bhed2']).to.not.exist
131 expect(languages['al_bhed3']).to.not.exist
135 const res = await getVideoCategories(server.url)
136 const categories = res.body
138 expect(categories[1]).to.equal('Music')
139 expect(categories[2]).to.equal('Films')
141 expect(categories[42]).to.not.exist
142 expect(categories[43]).to.not.exist
146 const res = await getVideoLicences(server.url)
147 const licences = res.body
149 expect(licences[1]).to.equal('Attribution')
150 expect(licences[7]).to.equal('Public Domain Dedication')
152 expect(licences[42]).to.not.exist
153 expect(licences[43]).to.not.exist
157 const res = await getVideoPrivacies(server.url)
158 const privacies = res.body
160 expect(privacies[1]).to.exist
161 expect(privacies[2]).to.exist
162 expect(privacies[3]).to.exist
163 expect(privacies[4]).to.exist
167 const res = await getVideoPlaylistPrivacies(server.url)
168 const playlistPrivacies = res.body
170 expect(playlistPrivacies[1]).to.exist
171 expect(playlistPrivacies[2]).to.exist
172 expect(playlistPrivacies[3]).to.exist
176 after(async function () {
177 await cleanupTests([ server ])