]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blob - server/tests/plugins/video-constants.ts
shared/ typescript types dir server-commands
[github/Chocobozzz/PeerTube.git] / server / tests / plugins / video-constants.ts
1 /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
2
3 import 'mocha'
4 import * as chai from 'chai'
5 import {
6 cleanupTests,
7 createSingleServer,
8 makeGetRequest,
9 PeerTubeServer,
10 PluginsCommand,
11 setAccessTokensToServers
12 } from '@shared/server-commands'
13 import { HttpStatusCode, VideoPlaylistPrivacy } from '@shared/models'
14
15 const expect = chai.expect
16
17 describe('Test plugin altering video constants', function () {
18 let server: PeerTubeServer
19
20 before(async function () {
21 this.timeout(30000)
22
23 server = await createSingleServer(1)
24 await setAccessTokensToServers([ server ])
25
26 await server.plugins.install({ path: PluginsCommand.getPluginTestPath('-video-constants') })
27 })
28
29 it('Should have updated languages', async function () {
30 const languages = await server.videos.getLanguages()
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')
37 expect(languages['al_bhed3']).to.not.exist
38 })
39
40 it('Should have updated categories', async function () {
41 const categories = await server.videos.getCategories()
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 () {
51 const licences = await server.videos.getLicences()
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
60 it('Should have updated video privacies', async function () {
61 const privacies = await server.videos.getPrivacies()
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 () {
70 const playlistPrivacies = await server.playlists.getPrivacies()
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 () {
78 const attributes = { name: 'video', privacy: 2 }
79 await server.videos.upload({ attributes, expectedStatus: HttpStatusCode.BAD_REQUEST_400 })
80 })
81
82 it('Should not be able to create a video with this privacy', async function () {
83 const attributes = { displayName: 'video playlist', privacy: VideoPlaylistPrivacy.PRIVATE }
84 await server.playlists.create({ attributes, expectedStatus: HttpStatusCode.BAD_REQUEST_400 })
85 })
86
87 it('Should be able to upload a video with these values', async function () {
88 const attributes = { name: 'video', category: 42, licence: 42, language: 'al_bhed2' }
89 const { uuid } = await server.videos.upload({ attributes })
90
91 const video = await server.videos.get({ id: uuid })
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
97 it('Should uninstall the plugin and reset languages, categories, licences and privacies', async function () {
98 await server.plugins.uninstall({ npmName: 'peertube-plugin-test-video-constants' })
99
100 {
101 const languages = await server.videos.getLanguages()
102
103 expect(languages['en']).to.equal('English')
104 expect(languages['fr']).to.equal('French')
105
106 expect(languages['al_bhed']).to.not.exist
107 expect(languages['al_bhed2']).to.not.exist
108 expect(languages['al_bhed3']).to.not.exist
109 }
110
111 {
112 const categories = await server.videos.getCategories()
113
114 expect(categories[1]).to.equal('Music')
115 expect(categories[2]).to.equal('Films')
116
117 expect(categories[42]).to.not.exist
118 expect(categories[43]).to.not.exist
119 }
120
121 {
122 const licences = await server.videos.getLicences()
123
124 expect(licences[1]).to.equal('Attribution')
125 expect(licences[7]).to.equal('Public Domain Dedication')
126
127 expect(licences[42]).to.not.exist
128 expect(licences[43]).to.not.exist
129 }
130
131 {
132 const privacies = await server.videos.getPrivacies()
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 {
141 const playlistPrivacies = await server.playlists.getPrivacies()
142
143 expect(playlistPrivacies[1]).to.exist
144 expect(playlistPrivacies[2]).to.exist
145 expect(playlistPrivacies[3]).to.exist
146 }
147 })
148
149 it('Should be able to reset categories', async function () {
150 await server.plugins.install({ path: PluginsCommand.getPluginTestPath('-video-constants') })
151
152 {
153 const categories = await server.videos.getCategories()
154
155 expect(categories[1]).to.not.exist
156 expect(categories[2]).to.not.exist
157
158 expect(categories[42]).to.exist
159 expect(categories[43]).to.exist
160 }
161
162 await makeGetRequest({
163 url: server.url,
164 token: server.accessToken,
165 path: '/plugins/test-video-constants/router/reset-categories',
166 expectedStatus: HttpStatusCode.NO_CONTENT_204
167 })
168
169 {
170 const categories = await server.videos.getCategories()
171
172 expect(categories[1]).to.exist
173 expect(categories[2]).to.exist
174
175 expect(categories[42]).to.not.exist
176 expect(categories[43]).to.not.exist
177 }
178 })
179
180 after(async function () {
181 await cleanupTests([ server ])
182 })
183 })