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