]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - server/tests/api/check-params/config.ts
Update CHANGELOG.md
[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 },
51 user: {
bee0abff
FA
52 videoQuota: 5242881,
53 videoQuotaDaily: 318742
fd206f0b
C
54 },
55 transcoding: {
56 enabled: true,
14e2014a 57 allowAdditionalExtensions: true,
fd206f0b
C
58 threads: 1,
59 resolutions: {
60 '240p': false,
61 '360p': true,
62 '480p': true,
63 '720p': false,
64 '1080p': false
65 }
5d08a6a7
C
66 },
67 import: {
68 videos: {
69 http: {
70 enabled: false
a84b8fa5
C
71 },
72 torrent: {
73 enabled: false
5d08a6a7
C
74 }
75 }
fd206f0b
C
76 }
77 }
78
79 // ---------------------------------------------------------------
80
81 before(async function () {
e212f887 82 this.timeout(30000)
fd206f0b
C
83
84 await flushTests()
85 server = await runServer(1)
86
87 await setAccessTokensToServers([ server ])
88
89 const user = {
90 username: 'user1',
91 password: 'password'
92 }
93 await createUser(server.url, server.accessToken, user.username, user.password)
94 userAccessToken = await userLogin(server, user)
95 })
96
97 describe('When getting the configuration', function () {
98 it('Should fail without token', async function () {
99 await makeGetRequest({
100 url: server.url,
101 path,
102 statusCodeExpected: 401
103 })
104 })
105
106 it('Should fail if the user is not an administrator', async function () {
107 await makeGetRequest({
108 url: server.url,
109 path,
110 token: userAccessToken,
111 statusCodeExpected: 403
112 })
113 })
114 })
115
116 describe('When updating the configuration', function () {
117 it('Should fail without token', async function () {
118 await makePutBodyRequest({
119 url: server.url,
120 path,
121 fields: updateParams,
122 statusCodeExpected: 401
123 })
124 })
125
126 it('Should fail if the user is not an administrator', async function () {
127 await makePutBodyRequest({
128 url: server.url,
129 path,
130 fields: updateParams,
131 token: userAccessToken,
132 statusCodeExpected: 403
133 })
134 })
135
136 it('Should fail if it misses a key', async function () {
137 const newUpdateParams = omit(updateParams, 'admin.email')
138
139 await makePutBodyRequest({
140 url: server.url,
141 path,
0883b324
C
142 fields: newUpdateParams,
143 token: server.accessToken,
144 statusCodeExpected: 400
145 })
146 })
147
148 it('Should fail with a bad default NSFW policy', async function () {
149 const newUpdateParams = immutableAssign(updateParams, {
150 instance: {
151 defaultNSFWPolicy: 'hello'
152 }
153 })
154
155 await makePutBodyRequest({
156 url: server.url,
157 path,
fd206f0b
C
158 fields: newUpdateParams,
159 token: server.accessToken,
160 statusCodeExpected: 400
161 })
162 })
163
164 it('Should success with the correct parameters', async function () {
165 await makePutBodyRequest({
166 url: server.url,
167 path,
168 fields: updateParams,
169 token: server.accessToken,
170 statusCodeExpected: 200
171 })
172 })
173 })
174
175 describe('When deleting the configuration', function () {
176 it('Should fail without token', async function () {
177 await makeDeleteRequest({
178 url: server.url,
179 path,
180 statusCodeExpected: 401
181 })
182 })
183
184 it('Should fail if the user is not an administrator', async function () {
185 await makeDeleteRequest({
186 url: server.url,
187 path,
188 token: userAccessToken,
189 statusCodeExpected: 403
190 })
191 })
192 })
193
194 after(async function () {
195 killallServers([ server ])
196
197 // Keep the logs if the test failed
198 if (this['ok']) {
199 await flushTests()
200 }
201 })
202})