aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/tests/api/check-params/config.ts
diff options
context:
space:
mode:
authorChocobozzz <me@florianbigard.com>2018-01-17 10:32:03 +0100
committerChocobozzz <me@florianbigard.com>2018-01-17 10:41:27 +0100
commitfd206f0b2d7e5c8e00e2817266d90ec54f79e1da (patch)
tree86b096cf2abd7eb49b892de1c9be855f45a41a9c /server/tests/api/check-params/config.ts
parent9581cabc596acb18c0ad86bcf3a07c2b45e8e47e (diff)
downloadPeerTube-fd206f0b2d7e5c8e00e2817266d90ec54f79e1da.tar.gz
PeerTube-fd206f0b2d7e5c8e00e2817266d90ec54f79e1da.tar.zst
PeerTube-fd206f0b2d7e5c8e00e2817266d90ec54f79e1da.zip
Add ability to update some configuration keys
Diffstat (limited to 'server/tests/api/check-params/config.ts')
-rw-r--r--server/tests/api/check-params/config.ts152
1 files changed, 152 insertions, 0 deletions
diff --git a/server/tests/api/check-params/config.ts b/server/tests/api/check-params/config.ts
new file mode 100644
index 000000000..59a0c3049
--- /dev/null
+++ b/server/tests/api/check-params/config.ts
@@ -0,0 +1,152 @@
1/* tslint:disable:no-unused-expression */
2
3import { omit } from 'lodash'
4import 'mocha'
5import { CustomConfig } from '../../../../shared/models/config/custom-config.model'
6
7import {
8 createUser, flushTests, killallServers, makeDeleteRequest, makeGetRequest, makePutBodyRequest, runServer, ServerInfo,
9 setAccessTokensToServers, userLogin
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 = {
17 cache: {
18 previews: {
19 size: 2
20 }
21 },
22 signup: {
23 enabled: false,
24 limit: 5
25 },
26 admin: {
27 email: 'superadmin1@example.com'
28 },
29 user: {
30 videoQuota: 5242881
31 },
32 transcoding: {
33 enabled: true,
34 threads: 1,
35 resolutions: {
36 '240p': false,
37 '360p': true,
38 '480p': true,
39 '720p': false,
40 '1080p': false
41 }
42 }
43 }
44
45 // ---------------------------------------------------------------
46
47 before(async function () {
48 this.timeout(20000)
49
50 await flushTests()
51 server = await runServer(1)
52
53 await setAccessTokensToServers([ server ])
54
55 const user = {
56 username: 'user1',
57 password: 'password'
58 }
59 await createUser(server.url, server.accessToken, user.username, user.password)
60 userAccessToken = await userLogin(server, user)
61 })
62
63 describe('When getting the configuration', function () {
64 it('Should fail without token', async function () {
65 await makeGetRequest({
66 url: server.url,
67 path,
68 statusCodeExpected: 401
69 })
70 })
71
72 it('Should fail if the user is not an administrator', async function () {
73 await makeGetRequest({
74 url: server.url,
75 path,
76 token: userAccessToken,
77 statusCodeExpected: 403
78 })
79 })
80 })
81
82 describe('When updating the configuration', function () {
83 it('Should fail without token', async function () {
84 await makePutBodyRequest({
85 url: server.url,
86 path,
87 fields: updateParams,
88 statusCodeExpected: 401
89 })
90 })
91
92 it('Should fail if the user is not an administrator', async function () {
93 await makePutBodyRequest({
94 url: server.url,
95 path,
96 fields: updateParams,
97 token: userAccessToken,
98 statusCodeExpected: 403
99 })
100 })
101
102 it('Should fail if it misses a key', async function () {
103 const newUpdateParams = omit(updateParams, 'admin.email')
104
105 await makePutBodyRequest({
106 url: server.url,
107 path,
108 fields: newUpdateParams,
109 token: server.accessToken,
110 statusCodeExpected: 400
111 })
112 })
113
114 it('Should success with the correct parameters', async function () {
115 await makePutBodyRequest({
116 url: server.url,
117 path,
118 fields: updateParams,
119 token: server.accessToken,
120 statusCodeExpected: 200
121 })
122 })
123 })
124
125 describe('When deleting the configuration', function () {
126 it('Should fail without token', async function () {
127 await makeDeleteRequest({
128 url: server.url,
129 path,
130 statusCodeExpected: 401
131 })
132 })
133
134 it('Should fail if the user is not an administrator', async function () {
135 await makeDeleteRequest({
136 url: server.url,
137 path,
138 token: userAccessToken,
139 statusCodeExpected: 403
140 })
141 })
142 })
143
144 after(async function () {
145 killallServers([ server ])
146
147 // Keep the logs if the test failed
148 if (this['ok']) {
149 await flushTests()
150 }
151 })
152})