]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - server/tests/api/check-params/config.ts
Merge branch 'feature/correctly-send-activities' into develop
[github/Chocobozzz/PeerTube.git] / server / tests / api / check-params / config.ts
CommitLineData
fd206f0b
C
1/* tslint:disable:no-unused-expression */
2
3import { omit } from 'lodash'
4import 'mocha'
09cababd 5import { CustomConfig } from '../../../../shared/models/server/custom-config.model'
fd206f0b
C
6
7import {
8 createUser, flushTests, killallServers, makeDeleteRequest, makeGetRequest, makePutBodyRequest, runServer, ServerInfo,
0883b324 9 setAccessTokensToServers, userLogin, immutableAssign
9639bd17 10} from '../../../../shared/utils'
fd206f0b
C
11
12describe('Test config API validators', function () {
13 const path = '/api/v1/config/custom'
14 let server: ServerInfo
15 let userAccessToken: string
16 const updateParams: CustomConfig = {
66b16caf
C
17 instance: {
18 name: 'PeerTube updated',
2e3a0215 19 shortDescription: 'my short description',
66b16caf 20 description: 'my super description',
00b5556c 21 terms: 'my super terms',
901637bb 22 defaultClientRoute: '/videos/recently-added',
0883b324 23 defaultNSFWPolicy: 'blur',
00b5556c
C
24 customizations: {
25 javascript: 'alert("coucou")',
26 css: 'body { background-color: red; }'
27 }
66b16caf 28 },
8be1afa1
C
29 services: {
30 twitter: {
31 username: '@MySuperUsername',
32 whitelisted: true
33 }
34 },
fd206f0b
C
35 cache: {
36 previews: {
37 size: 2
40e87e9e
C
38 },
39 captions: {
40 size: 3
fd206f0b
C
41 }
42 },
43 signup: {
44 enabled: false,
d9eaee39
JM
45 limit: 5,
46 requiresEmailVerification: false
fd206f0b
C
47 },
48 admin: {
49 email: 'superadmin1@example.com'
50 },
a4101923
C
51 contactForm: {
52 enabled: false
53 },
fd206f0b 54 user: {
bee0abff
FA
55 videoQuota: 5242881,
56 videoQuotaDaily: 318742
fd206f0b
C
57 },
58 transcoding: {
59 enabled: true,
14e2014a 60 allowAdditionalExtensions: true,
fd206f0b
C
61 threads: 1,
62 resolutions: {
63 '240p': false,
64 '360p': true,
65 '480p': true,
66 '720p': false,
67 '1080p': false
09209296
C
68 },
69 hls: {
70 enabled: false
fd206f0b 71 }
5d08a6a7
C
72 },
73 import: {
74 videos: {
75 http: {
76 enabled: false
a84b8fa5
C
77 },
78 torrent: {
79 enabled: false
5d08a6a7
C
80 }
81 }
fd206f0b
C
82 }
83 }
84
85 // ---------------------------------------------------------------
86
87 before(async function () {
e212f887 88 this.timeout(30000)
fd206f0b
C
89
90 await flushTests()
91 server = await runServer(1)
92
93 await setAccessTokensToServers([ server ])
94
95 const user = {
96 username: 'user1',
97 password: 'password'
98 }
99 await createUser(server.url, server.accessToken, user.username, user.password)
100 userAccessToken = await userLogin(server, user)
101 })
102
103 describe('When getting the configuration', function () {
104 it('Should fail without token', async function () {
105 await makeGetRequest({
106 url: server.url,
107 path,
108 statusCodeExpected: 401
109 })
110 })
111
112 it('Should fail if the user is not an administrator', async function () {
113 await makeGetRequest({
114 url: server.url,
115 path,
116 token: userAccessToken,
117 statusCodeExpected: 403
118 })
119 })
120 })
121
122 describe('When updating the configuration', function () {
123 it('Should fail without token', async function () {
124 await makePutBodyRequest({
125 url: server.url,
126 path,
127 fields: updateParams,
128 statusCodeExpected: 401
129 })
130 })
131
132 it('Should fail if the user is not an administrator', async function () {
133 await makePutBodyRequest({
134 url: server.url,
135 path,
136 fields: updateParams,
137 token: userAccessToken,
138 statusCodeExpected: 403
139 })
140 })
141
142 it('Should fail if it misses a key', async function () {
143 const newUpdateParams = omit(updateParams, 'admin.email')
144
145 await makePutBodyRequest({
146 url: server.url,
147 path,
0883b324
C
148 fields: newUpdateParams,
149 token: server.accessToken,
150 statusCodeExpected: 400
151 })
152 })
153
154 it('Should fail with a bad default NSFW policy', async function () {
155 const newUpdateParams = immutableAssign(updateParams, {
156 instance: {
157 defaultNSFWPolicy: 'hello'
158 }
159 })
160
161 await makePutBodyRequest({
162 url: server.url,
163 path,
fd206f0b
C
164 fields: newUpdateParams,
165 token: server.accessToken,
166 statusCodeExpected: 400
167 })
168 })
169
170 it('Should success with the correct parameters', async function () {
171 await makePutBodyRequest({
172 url: server.url,
173 path,
174 fields: updateParams,
175 token: server.accessToken,
176 statusCodeExpected: 200
177 })
178 })
179 })
180
181 describe('When deleting the configuration', function () {
182 it('Should fail without token', async function () {
183 await makeDeleteRequest({
184 url: server.url,
185 path,
186 statusCodeExpected: 401
187 })
188 })
189
190 it('Should fail if the user is not an administrator', async function () {
191 await makeDeleteRequest({
192 url: server.url,
193 path,
194 token: userAccessToken,
195 statusCodeExpected: 403
196 })
197 })
198 })
199
200 after(async function () {
201 killallServers([ server ])
202
203 // Keep the logs if the test failed
204 if (this['ok']) {
205 await flushTests()
206 }
207 })
208})