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