]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - server/tests/api/check-params/config.ts
Add ability to update another user video
[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'
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 = {
66b16caf
C
17 instance: {
18 name: 'PeerTube updated',
19 description: 'my super description',
20 terms: 'my super terms'
21 },
fd206f0b
C
22 cache: {
23 previews: {
24 size: 2
25 }
26 },
27 signup: {
28 enabled: false,
29 limit: 5
30 },
31 admin: {
32 email: 'superadmin1@example.com'
33 },
34 user: {
35 videoQuota: 5242881
36 },
37 transcoding: {
38 enabled: true,
39 threads: 1,
40 resolutions: {
41 '240p': false,
42 '360p': true,
43 '480p': true,
44 '720p': false,
45 '1080p': false
46 }
47 }
48 }
49
50 // ---------------------------------------------------------------
51
52 before(async function () {
e212f887 53 this.timeout(30000)
fd206f0b
C
54
55 await flushTests()
56 server = await runServer(1)
57
58 await setAccessTokensToServers([ server ])
59
60 const user = {
61 username: 'user1',
62 password: 'password'
63 }
64 await createUser(server.url, server.accessToken, user.username, user.password)
65 userAccessToken = await userLogin(server, user)
66 })
67
68 describe('When getting the configuration', function () {
69 it('Should fail without token', async function () {
70 await makeGetRequest({
71 url: server.url,
72 path,
73 statusCodeExpected: 401
74 })
75 })
76
77 it('Should fail if the user is not an administrator', async function () {
78 await makeGetRequest({
79 url: server.url,
80 path,
81 token: userAccessToken,
82 statusCodeExpected: 403
83 })
84 })
85 })
86
87 describe('When updating the configuration', function () {
88 it('Should fail without token', async function () {
89 await makePutBodyRequest({
90 url: server.url,
91 path,
92 fields: updateParams,
93 statusCodeExpected: 401
94 })
95 })
96
97 it('Should fail if the user is not an administrator', async function () {
98 await makePutBodyRequest({
99 url: server.url,
100 path,
101 fields: updateParams,
102 token: userAccessToken,
103 statusCodeExpected: 403
104 })
105 })
106
107 it('Should fail if it misses a key', async function () {
108 const newUpdateParams = omit(updateParams, 'admin.email')
109
110 await makePutBodyRequest({
111 url: server.url,
112 path,
113 fields: newUpdateParams,
114 token: server.accessToken,
115 statusCodeExpected: 400
116 })
117 })
118
119 it('Should success with the correct parameters', async function () {
120 await makePutBodyRequest({
121 url: server.url,
122 path,
123 fields: updateParams,
124 token: server.accessToken,
125 statusCodeExpected: 200
126 })
127 })
128 })
129
130 describe('When deleting the configuration', function () {
131 it('Should fail without token', async function () {
132 await makeDeleteRequest({
133 url: server.url,
134 path,
135 statusCodeExpected: 401
136 })
137 })
138
139 it('Should fail if the user is not an administrator', async function () {
140 await makeDeleteRequest({
141 url: server.url,
142 path,
143 token: userAccessToken,
144 statusCodeExpected: 403
145 })
146 })
147 })
148
149 after(async function () {
150 killallServers([ server ])
151
152 // Keep the logs if the test failed
153 if (this['ok']) {
154 await flushTests()
155 }
156 })
157})