]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - server/tests/plugins/video-constants.ts
Better 413 error handling in cli script
[github/Chocobozzz/PeerTube.git] / server / tests / plugins / video-constants.ts
CommitLineData
a1587156 1/* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
ee286591 2
ee286591 3import 'mocha'
ae2abfd3 4import * as chai from 'chai'
ee286591 5import {
a24bd1ed
C
6 cleanupTests,
7 createSingleServer,
dc3d9022 8 makeGetRequest,
a24bd1ed
C
9 PeerTubeServer,
10 PluginsCommand,
11 setAccessTokensToServers
bf54587a 12} from '@shared/server-commands'
4c7e60bc 13import { HttpStatusCode, VideoPlaylistPrivacy } from '@shared/models'
ee286591
C
14
15const expect = chai.expect
16
17describe('Test plugin altering video constants', function () {
254d3579 18 let server: PeerTubeServer
ee286591
C
19
20 before(async function () {
21 this.timeout(30000)
22
254d3579 23 server = await createSingleServer(1)
ee286591
C
24 await setAccessTokensToServers([ server ])
25
89d241a7 26 await server.plugins.install({ path: PluginsCommand.getPluginTestPath('-video-constants') })
ee286591
C
27 })
28
29 it('Should have updated languages', async function () {
89d241a7 30 const languages = await server.videos.getLanguages()
ee286591
C
31
32 expect(languages['en']).to.not.exist
33 expect(languages['fr']).to.not.exist
34
35 expect(languages['al_bhed']).to.equal('Al Bhed')
36 expect(languages['al_bhed2']).to.equal('Al Bhed 2')
799ece6a 37 expect(languages['al_bhed3']).to.not.exist
ee286591
C
38 })
39
40 it('Should have updated categories', async function () {
89d241a7 41 const categories = await server.videos.getCategories()
ee286591
C
42
43 expect(categories[1]).to.not.exist
44 expect(categories[2]).to.not.exist
45
46 expect(categories[42]).to.equal('Best category')
47 expect(categories[43]).to.equal('High best category')
48 })
49
50 it('Should have updated licences', async function () {
89d241a7 51 const licences = await server.videos.getLicences()
ee286591
C
52
53 expect(licences[1]).to.not.exist
54 expect(licences[7]).to.not.exist
55
56 expect(licences[42]).to.equal('Best licence')
57 expect(licences[43]).to.equal('High best licence')
58 })
59
b3af2601 60 it('Should have updated video privacies', async function () {
89d241a7 61 const privacies = await server.videos.getPrivacies()
b3af2601
C
62
63 expect(privacies[1]).to.exist
64 expect(privacies[2]).to.not.exist
65 expect(privacies[3]).to.exist
66 expect(privacies[4]).to.exist
67 })
68
69 it('Should have updated playlist privacies', async function () {
89d241a7 70 const playlistPrivacies = await server.playlists.getPrivacies()
b3af2601
C
71
72 expect(playlistPrivacies[1]).to.exist
73 expect(playlistPrivacies[2]).to.exist
74 expect(playlistPrivacies[3]).to.not.exist
75 })
76
77 it('Should not be able to create a video with this privacy', async function () {
d23dd9fb 78 const attributes = { name: 'video', privacy: 2 }
89d241a7 79 await server.videos.upload({ attributes, expectedStatus: HttpStatusCode.BAD_REQUEST_400 })
b3af2601
C
80 })
81
82 it('Should not be able to create a video with this privacy', async function () {
e6346d59 83 const attributes = { displayName: 'video playlist', privacy: VideoPlaylistPrivacy.PRIVATE }
89d241a7 84 await server.playlists.create({ attributes, expectedStatus: HttpStatusCode.BAD_REQUEST_400 })
b3af2601
C
85 })
86
ee286591 87 it('Should be able to upload a video with these values', async function () {
d23dd9fb 88 const attributes = { name: 'video', category: 42, licence: 42, language: 'al_bhed2' }
89d241a7 89 const { uuid } = await server.videos.upload({ attributes })
ee286591 90
89d241a7 91 const video = await server.videos.get({ id: uuid })
ee286591
C
92 expect(video.language.label).to.equal('Al Bhed 2')
93 expect(video.licence.label).to.equal('Best licence')
94 expect(video.category.label).to.equal('Best category')
95 })
96
b3af2601 97 it('Should uninstall the plugin and reset languages, categories, licences and privacies', async function () {
89d241a7 98 await server.plugins.uninstall({ npmName: 'peertube-plugin-test-video-constants' })
ee286591
C
99
100 {
89d241a7 101 const languages = await server.videos.getLanguages()
ee286591 102
a1587156
C
103 expect(languages['en']).to.equal('English')
104 expect(languages['fr']).to.equal('French')
ee286591 105
a1587156
C
106 expect(languages['al_bhed']).to.not.exist
107 expect(languages['al_bhed2']).to.not.exist
799ece6a 108 expect(languages['al_bhed3']).to.not.exist
ee286591
C
109 }
110
111 {
89d241a7 112 const categories = await server.videos.getCategories()
ee286591 113
a1587156
C
114 expect(categories[1]).to.equal('Music')
115 expect(categories[2]).to.equal('Films')
ee286591 116
a1587156
C
117 expect(categories[42]).to.not.exist
118 expect(categories[43]).to.not.exist
ee286591
C
119 }
120
121 {
89d241a7 122 const licences = await server.videos.getLicences()
ee286591 123
a1587156
C
124 expect(licences[1]).to.equal('Attribution')
125 expect(licences[7]).to.equal('Public Domain Dedication')
ee286591 126
a1587156
C
127 expect(licences[42]).to.not.exist
128 expect(licences[43]).to.not.exist
ee286591 129 }
b3af2601
C
130
131 {
89d241a7 132 const privacies = await server.videos.getPrivacies()
b3af2601
C
133
134 expect(privacies[1]).to.exist
135 expect(privacies[2]).to.exist
136 expect(privacies[3]).to.exist
137 expect(privacies[4]).to.exist
138 }
139
140 {
89d241a7 141 const playlistPrivacies = await server.playlists.getPrivacies()
b3af2601
C
142
143 expect(playlistPrivacies[1]).to.exist
144 expect(playlistPrivacies[2]).to.exist
145 expect(playlistPrivacies[3]).to.exist
146 }
ee286591
C
147 })
148
dc3d9022 149 it('Should be able to reset categories', async function () {
a24bd1ed 150 await server.plugins.install({ path: PluginsCommand.getPluginTestPath('-video-constants') })
dc3d9022 151
a24bd1ed
C
152 {
153 const categories = await server.videos.getCategories()
dc3d9022 154
a24bd1ed
C
155 expect(categories[1]).to.not.exist
156 expect(categories[2]).to.not.exist
dc3d9022 157
a24bd1ed
C
158 expect(categories[42]).to.exist
159 expect(categories[43]).to.exist
160 }
dc3d9022 161
162 await makeGetRequest({
163 url: server.url,
164 token: server.accessToken,
165 path: '/plugins/test-video-constants/router/reset-categories',
a24bd1ed 166 expectedStatus: HttpStatusCode.NO_CONTENT_204
dc3d9022 167 })
168
a24bd1ed
C
169 {
170 const categories = await server.videos.getCategories()
dc3d9022 171
a24bd1ed
C
172 expect(categories[1]).to.exist
173 expect(categories[2]).to.exist
dc3d9022 174
a24bd1ed
C
175 expect(categories[42]).to.not.exist
176 expect(categories[43]).to.not.exist
177 }
dc3d9022 178 })
179
ee286591
C
180 after(async function () {
181 await cleanupTests([ server ])
182 })
183})