aboutsummaryrefslogtreecommitdiffhomepage
path: root/packages/tests/src/plugins/video-constants.ts
diff options
context:
space:
mode:
Diffstat (limited to 'packages/tests/src/plugins/video-constants.ts')
-rw-r--r--packages/tests/src/plugins/video-constants.ts180
1 files changed, 180 insertions, 0 deletions
diff --git a/packages/tests/src/plugins/video-constants.ts b/packages/tests/src/plugins/video-constants.ts
new file mode 100644
index 000000000..b81240a64
--- /dev/null
+++ b/packages/tests/src/plugins/video-constants.ts
@@ -0,0 +1,180 @@
1/* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
2
3import { expect } from 'chai'
4import {
5 cleanupTests,
6 createSingleServer,
7 makeGetRequest,
8 PeerTubeServer,
9 PluginsCommand,
10 setAccessTokensToServers
11} from '@peertube/peertube-server-commands'
12import { HttpStatusCode, VideoPlaylistPrivacy, VideoPrivacy } from '@peertube/peertube-models'
13
14describe('Test plugin altering video constants', function () {
15 let server: PeerTubeServer
16
17 before(async function () {
18 this.timeout(30000)
19
20 server = await createSingleServer(1)
21 await setAccessTokensToServers([ server ])
22
23 await server.plugins.install({ path: PluginsCommand.getPluginTestPath('-video-constants') })
24 })
25
26 it('Should have updated languages', async function () {
27 const languages = await server.videos.getLanguages()
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')
34 expect(languages['al_bhed3']).to.not.exist
35 })
36
37 it('Should have updated categories', async function () {
38 const categories = await server.videos.getCategories()
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 () {
48 const licences = await server.videos.getLicences()
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
57 it('Should have updated video privacies', async function () {
58 const privacies = await server.videos.getPrivacies()
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 () {
67 const playlistPrivacies = await server.playlists.getPrivacies()
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 () {
75 const attributes = { name: 'video', privacy: VideoPrivacy.UNLISTED }
76 await server.videos.upload({ attributes, expectedStatus: HttpStatusCode.BAD_REQUEST_400 })
77 })
78
79 it('Should not be able to create a video with this privacy', async function () {
80 const attributes = { displayName: 'video playlist', privacy: VideoPlaylistPrivacy.PRIVATE }
81 await server.playlists.create({ attributes, expectedStatus: HttpStatusCode.BAD_REQUEST_400 })
82 })
83
84 it('Should be able to upload a video with these values', async function () {
85 const attributes = { name: 'video', category: 42, licence: 42, language: 'al_bhed2' }
86 const { uuid } = await server.videos.upload({ attributes })
87
88 const video = await server.videos.get({ id: uuid })
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
94 it('Should uninstall the plugin and reset languages, categories, licences and privacies', async function () {
95 await server.plugins.uninstall({ npmName: 'peertube-plugin-test-video-constants' })
96
97 {
98 const languages = await server.videos.getLanguages()
99
100 expect(languages['en']).to.equal('English')
101 expect(languages['fr']).to.equal('French')
102
103 expect(languages['al_bhed']).to.not.exist
104 expect(languages['al_bhed2']).to.not.exist
105 expect(languages['al_bhed3']).to.not.exist
106 }
107
108 {
109 const categories = await server.videos.getCategories()
110
111 expect(categories[1]).to.equal('Music')
112 expect(categories[2]).to.equal('Films')
113
114 expect(categories[42]).to.not.exist
115 expect(categories[43]).to.not.exist
116 }
117
118 {
119 const licences = await server.videos.getLicences()
120
121 expect(licences[1]).to.equal('Attribution')
122 expect(licences[7]).to.equal('Public Domain Dedication')
123
124 expect(licences[42]).to.not.exist
125 expect(licences[43]).to.not.exist
126 }
127
128 {
129 const privacies = await server.videos.getPrivacies()
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 {
138 const playlistPrivacies = await server.playlists.getPrivacies()
139
140 expect(playlistPrivacies[1]).to.exist
141 expect(playlistPrivacies[2]).to.exist
142 expect(playlistPrivacies[3]).to.exist
143 }
144 })
145
146 it('Should be able to reset categories', async function () {
147 await server.plugins.install({ path: PluginsCommand.getPluginTestPath('-video-constants') })
148
149 {
150 const categories = await server.videos.getCategories()
151
152 expect(categories[1]).to.not.exist
153 expect(categories[2]).to.not.exist
154
155 expect(categories[42]).to.exist
156 expect(categories[43]).to.exist
157 }
158
159 await makeGetRequest({
160 url: server.url,
161 token: server.accessToken,
162 path: '/plugins/test-video-constants/router/reset-categories',
163 expectedStatus: HttpStatusCode.NO_CONTENT_204
164 })
165
166 {
167 const categories = await server.videos.getCategories()
168
169 expect(categories[1]).to.exist
170 expect(categories[2]).to.exist
171
172 expect(categories[42]).to.not.exist
173 expect(categories[43]).to.not.exist
174 }
175 })
176
177 after(async function () {
178 await cleanupTests([ server ])
179 })
180})