]>
Commit | Line | Data |
---|---|---|
a1587156 | 1 | /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */ |
ee286591 C |
2 | |
3 | import * as chai from 'chai' | |
4 | import 'mocha' | |
a1587156 | 5 | import { cleanupTests, flushAndRunServer, ServerInfo } from '../../../shared/extra-utils/server/servers' |
ee286591 | 6 | import { |
b3af2601 | 7 | createVideoPlaylist, |
ee286591 | 8 | getPluginTestPath, |
a1587156 C |
9 | getVideo, |
10 | getVideoCategories, | |
11 | getVideoLanguages, | |
dc3d9022 | 12 | getVideoLicences, |
13 | getVideoPlaylistPrivacies, | |
14 | getVideoPrivacies, | |
ee286591 | 15 | installPlugin, |
dc3d9022 | 16 | makeGetRequest, |
ee286591 | 17 | setAccessTokensToServers, |
a1587156 C |
18 | uninstallPlugin, |
19 | uploadVideo | |
ee286591 | 20 | } from '../../../shared/extra-utils' |
b3af2601 | 21 | import { VideoDetails, VideoPlaylistPrivacy } from '../../../shared/models/videos' |
f2eb23cd | 22 | import { HttpStatusCode } from '../../../shared/core-utils/miscs/http-error-codes' |
ee286591 C |
23 | |
24 | const expect = chai.expect | |
25 | ||
26 | describe('Test plugin altering video constants', function () { | |
27 | let server: ServerInfo | |
28 | ||
29 | before(async function () { | |
30 | this.timeout(30000) | |
31 | ||
32 | server = await flushAndRunServer(1) | |
33 | await setAccessTokensToServers([ server ]) | |
34 | ||
35 | await installPlugin({ | |
36 | url: server.url, | |
37 | accessToken: server.accessToken, | |
799ece6a | 38 | path: getPluginTestPath('-video-constants') |
ee286591 C |
39 | }) |
40 | }) | |
41 | ||
42 | it('Should have updated languages', async function () { | |
43 | const res = await getVideoLanguages(server.url) | |
44 | const languages = res.body | |
45 | ||
46 | expect(languages['en']).to.not.exist | |
47 | expect(languages['fr']).to.not.exist | |
48 | ||
49 | expect(languages['al_bhed']).to.equal('Al Bhed') | |
50 | expect(languages['al_bhed2']).to.equal('Al Bhed 2') | |
799ece6a | 51 | expect(languages['al_bhed3']).to.not.exist |
ee286591 C |
52 | }) |
53 | ||
54 | it('Should have updated categories', async function () { | |
55 | const res = await getVideoCategories(server.url) | |
56 | const categories = res.body | |
57 | ||
58 | expect(categories[1]).to.not.exist | |
59 | expect(categories[2]).to.not.exist | |
60 | ||
61 | expect(categories[42]).to.equal('Best category') | |
62 | expect(categories[43]).to.equal('High best category') | |
63 | }) | |
64 | ||
65 | it('Should have updated licences', async function () { | |
66 | const res = await getVideoLicences(server.url) | |
67 | const licences = res.body | |
68 | ||
69 | expect(licences[1]).to.not.exist | |
70 | expect(licences[7]).to.not.exist | |
71 | ||
72 | expect(licences[42]).to.equal('Best licence') | |
73 | expect(licences[43]).to.equal('High best licence') | |
74 | }) | |
75 | ||
b3af2601 C |
76 | it('Should have updated video privacies', async function () { |
77 | const res = await getVideoPrivacies(server.url) | |
78 | const privacies = res.body | |
79 | ||
80 | expect(privacies[1]).to.exist | |
81 | expect(privacies[2]).to.not.exist | |
82 | expect(privacies[3]).to.exist | |
83 | expect(privacies[4]).to.exist | |
84 | }) | |
85 | ||
86 | it('Should have updated playlist privacies', async function () { | |
87 | const res = await getVideoPlaylistPrivacies(server.url) | |
88 | const playlistPrivacies = res.body | |
89 | ||
90 | expect(playlistPrivacies[1]).to.exist | |
91 | expect(playlistPrivacies[2]).to.exist | |
92 | expect(playlistPrivacies[3]).to.not.exist | |
93 | }) | |
94 | ||
95 | it('Should not be able to create a video with this privacy', async function () { | |
96 | const attrs = { name: 'video', privacy: 2 } | |
f2eb23cd | 97 | await uploadVideo(server.url, server.accessToken, attrs, HttpStatusCode.BAD_REQUEST_400) |
b3af2601 C |
98 | }) |
99 | ||
100 | it('Should not be able to create a video with this privacy', async function () { | |
101 | const attrs = { displayName: 'video playlist', privacy: VideoPlaylistPrivacy.PRIVATE } | |
f2eb23cd RK |
102 | await createVideoPlaylist({ |
103 | url: server.url, | |
104 | token: server.accessToken, | |
105 | playlistAttrs: attrs, | |
106 | expectedStatus: HttpStatusCode.BAD_REQUEST_400 | |
107 | }) | |
b3af2601 C |
108 | }) |
109 | ||
ee286591 C |
110 | it('Should be able to upload a video with these values', async function () { |
111 | const attrs = { name: 'video', category: 42, licence: 42, language: 'al_bhed2' } | |
112 | const resUpload = await uploadVideo(server.url, server.accessToken, attrs) | |
113 | ||
114 | const res = await getVideo(server.url, resUpload.body.video.uuid) | |
115 | ||
116 | const video: VideoDetails = res.body | |
117 | expect(video.language.label).to.equal('Al Bhed 2') | |
118 | expect(video.licence.label).to.equal('Best licence') | |
119 | expect(video.category.label).to.equal('Best category') | |
120 | }) | |
121 | ||
b3af2601 | 122 | it('Should uninstall the plugin and reset languages, categories, licences and privacies', async function () { |
799ece6a | 123 | await uninstallPlugin({ url: server.url, accessToken: server.accessToken, npmName: 'peertube-plugin-test-video-constants' }) |
ee286591 C |
124 | |
125 | { | |
126 | const res = await getVideoLanguages(server.url) | |
127 | const languages = res.body | |
128 | ||
a1587156 C |
129 | expect(languages['en']).to.equal('English') |
130 | expect(languages['fr']).to.equal('French') | |
ee286591 | 131 | |
a1587156 C |
132 | expect(languages['al_bhed']).to.not.exist |
133 | expect(languages['al_bhed2']).to.not.exist | |
799ece6a | 134 | expect(languages['al_bhed3']).to.not.exist |
ee286591 C |
135 | } |
136 | ||
137 | { | |
138 | const res = await getVideoCategories(server.url) | |
139 | const categories = res.body | |
140 | ||
a1587156 C |
141 | expect(categories[1]).to.equal('Music') |
142 | expect(categories[2]).to.equal('Films') | |
ee286591 | 143 | |
a1587156 C |
144 | expect(categories[42]).to.not.exist |
145 | expect(categories[43]).to.not.exist | |
ee286591 C |
146 | } |
147 | ||
148 | { | |
149 | const res = await getVideoLicences(server.url) | |
150 | const licences = res.body | |
151 | ||
a1587156 C |
152 | expect(licences[1]).to.equal('Attribution') |
153 | expect(licences[7]).to.equal('Public Domain Dedication') | |
ee286591 | 154 | |
a1587156 C |
155 | expect(licences[42]).to.not.exist |
156 | expect(licences[43]).to.not.exist | |
ee286591 | 157 | } |
b3af2601 C |
158 | |
159 | { | |
160 | const res = await getVideoPrivacies(server.url) | |
161 | const privacies = res.body | |
162 | ||
163 | expect(privacies[1]).to.exist | |
164 | expect(privacies[2]).to.exist | |
165 | expect(privacies[3]).to.exist | |
166 | expect(privacies[4]).to.exist | |
167 | } | |
168 | ||
169 | { | |
170 | const res = await getVideoPlaylistPrivacies(server.url) | |
171 | const playlistPrivacies = res.body | |
172 | ||
173 | expect(playlistPrivacies[1]).to.exist | |
174 | expect(playlistPrivacies[2]).to.exist | |
175 | expect(playlistPrivacies[3]).to.exist | |
176 | } | |
ee286591 C |
177 | }) |
178 | ||
dc3d9022 | 179 | it('Should be able to reset categories', async function () { |
180 | await installPlugin({ | |
181 | url: server.url, | |
182 | accessToken: server.accessToken, | |
183 | path: getPluginTestPath('-video-constants') | |
184 | }) | |
185 | ||
186 | let { body: categories } = await getVideoCategories(server.url) | |
187 | ||
188 | expect(categories[1]).to.not.exist | |
189 | expect(categories[2]).to.not.exist | |
190 | ||
191 | expect(categories[42]).to.exist | |
192 | expect(categories[43]).to.exist | |
193 | ||
194 | await makeGetRequest({ | |
195 | url: server.url, | |
196 | token: server.accessToken, | |
197 | path: '/plugins/test-video-constants/router/reset-categories', | |
198 | statusCodeExpected: HttpStatusCode.NO_CONTENT_204 | |
199 | }) | |
200 | ||
201 | const { body } = await getVideoCategories(server.url) | |
202 | categories = body | |
203 | ||
204 | expect(categories[1]).to.exist | |
205 | expect(categories[2]).to.exist | |
206 | ||
207 | expect(categories[42]).to.not.exist | |
208 | expect(categories[43]).to.not.exist | |
209 | }) | |
210 | ||
ee286591 C |
211 | after(async function () { |
212 | await cleanupTests([ server ]) | |
213 | }) | |
214 | }) |