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('-three')
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')
50 it('Should have updated categories', async function () {
51 const res = await getVideoCategories(server.url)
52 const categories = res.body
54 expect(categories[1]).to.not.exist
55 expect(categories[2]).to.not.exist
57 expect(categories[42]).to.equal('Best category')
58 expect(categories[43]).to.equal('High best category')
61 it('Should have updated licences', async function () {
62 const res = await getVideoLicences(server.url)
63 const licences = res.body
65 expect(licences[1]).to.not.exist
66 expect(licences[7]).to.not.exist
68 expect(licences[42]).to.equal('Best licence')
69 expect(licences[43]).to.equal('High best licence')
72 it('Should have updated video privacies', async function () {
73 const res = await getVideoPrivacies(server.url)
74 const privacies = res.body
76 expect(privacies[1]).to.exist
77 expect(privacies[2]).to.not.exist
78 expect(privacies[3]).to.exist
79 expect(privacies[4]).to.exist
82 it('Should have updated playlist privacies', async function () {
83 const res = await getVideoPlaylistPrivacies(server.url)
84 const playlistPrivacies = res.body
86 expect(playlistPrivacies[1]).to.exist
87 expect(playlistPrivacies[2]).to.exist
88 expect(playlistPrivacies[3]).to.not.exist
91 it('Should not be able to create a video with this privacy', async function () {
92 const attrs = { name: 'video', privacy: 2 }
93 await uploadVideo(server.url, server.accessToken, attrs, HttpStatusCode.BAD_REQUEST_400)
96 it('Should not be able to create a video with this privacy', async function () {
97 const attrs = { displayName: 'video playlist', privacy: VideoPlaylistPrivacy.PRIVATE }
98 await createVideoPlaylist({
100 token: server.accessToken,
101 playlistAttrs: attrs,
102 expectedStatus: HttpStatusCode.BAD_REQUEST_400
106 it('Should be able to upload a video with these values', async function () {
107 const attrs = { name: 'video', category: 42, licence: 42, language: 'al_bhed2' }
108 const resUpload = await uploadVideo(server.url, server.accessToken, attrs)
110 const res = await getVideo(server.url, resUpload.body.video.uuid)
112 const video: VideoDetails = res.body
113 expect(video.language.label).to.equal('Al Bhed 2')
114 expect(video.licence.label).to.equal('Best licence')
115 expect(video.category.label).to.equal('Best category')
118 it('Should uninstall the plugin and reset languages, categories, licences and privacies', async function () {
119 await uninstallPlugin({ url: server.url, accessToken: server.accessToken, npmName: 'peertube-plugin-test-three' })
122 const res = await getVideoLanguages(server.url)
123 const languages = res.body
125 expect(languages['en']).to.equal('English')
126 expect(languages['fr']).to.equal('French')
128 expect(languages['al_bhed']).to.not.exist
129 expect(languages['al_bhed2']).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 ])