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