]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - server/tests/api/check-params/config.ts
Do not bundle two different videojs versions
[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
fd206f0b
C
10} from '../../utils'
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 },
fd206f0b
C
29 cache: {
30 previews: {
31 size: 2
32 }
33 },
34 signup: {
35 enabled: false,
36 limit: 5
37 },
38 admin: {
39 email: 'superadmin1@example.com'
40 },
41 user: {
42 videoQuota: 5242881
43 },
44 transcoding: {
45 enabled: true,
46 threads: 1,
47 resolutions: {
48 '240p': false,
49 '360p': true,
50 '480p': true,
51 '720p': false,
52 '1080p': false
53 }
54 }
55 }
56
57 // ---------------------------------------------------------------
58
59 before(async function () {
e212f887 60 this.timeout(30000)
fd206f0b
C
61
62 await flushTests()
63 server = await runServer(1)
64
65 await setAccessTokensToServers([ server ])
66
67 const user = {
68 username: 'user1',
69 password: 'password'
70 }
71 await createUser(server.url, server.accessToken, user.username, user.password)
72 userAccessToken = await userLogin(server, user)
73 })
74
75 describe('When getting the configuration', function () {
76 it('Should fail without token', async function () {
77 await makeGetRequest({
78 url: server.url,
79 path,
80 statusCodeExpected: 401
81 })
82 })
83
84 it('Should fail if the user is not an administrator', async function () {
85 await makeGetRequest({
86 url: server.url,
87 path,
88 token: userAccessToken,
89 statusCodeExpected: 403
90 })
91 })
92 })
93
94 describe('When updating the configuration', function () {
95 it('Should fail without token', async function () {
96 await makePutBodyRequest({
97 url: server.url,
98 path,
99 fields: updateParams,
100 statusCodeExpected: 401
101 })
102 })
103
104 it('Should fail if the user is not an administrator', async function () {
105 await makePutBodyRequest({
106 url: server.url,
107 path,
108 fields: updateParams,
109 token: userAccessToken,
110 statusCodeExpected: 403
111 })
112 })
113
114 it('Should fail if it misses a key', async function () {
115 const newUpdateParams = omit(updateParams, 'admin.email')
116
117 await makePutBodyRequest({
118 url: server.url,
119 path,
0883b324
C
120 fields: newUpdateParams,
121 token: server.accessToken,
122 statusCodeExpected: 400
123 })
124 })
125
126 it('Should fail with a bad default NSFW policy', async function () {
127 const newUpdateParams = immutableAssign(updateParams, {
128 instance: {
129 defaultNSFWPolicy: 'hello'
130 }
131 })
132
133 await makePutBodyRequest({
134 url: server.url,
135 path,
fd206f0b
C
136 fields: newUpdateParams,
137 token: server.accessToken,
138 statusCodeExpected: 400
139 })
140 })
141
142 it('Should success with the correct parameters', async function () {
143 await makePutBodyRequest({
144 url: server.url,
145 path,
146 fields: updateParams,
147 token: server.accessToken,
148 statusCodeExpected: 200
149 })
150 })
151 })
152
153 describe('When deleting the configuration', function () {
154 it('Should fail without token', async function () {
155 await makeDeleteRequest({
156 url: server.url,
157 path,
158 statusCodeExpected: 401
159 })
160 })
161
162 it('Should fail if the user is not an administrator', async function () {
163 await makeDeleteRequest({
164 url: server.url,
165 path,
166 token: userAccessToken,
167 statusCodeExpected: 403
168 })
169 })
170 })
171
172 after(async function () {
173 killallServers([ server ])
174
175 // Keep the logs if the test failed
176 if (this['ok']) {
177 await flushTests()
178 }
179 })
180})