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