aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/tests/api/server/config-defaults.ts
diff options
context:
space:
mode:
Diffstat (limited to 'server/tests/api/server/config-defaults.ts')
-rw-r--r--server/tests/api/server/config-defaults.ts213
1 files changed, 213 insertions, 0 deletions
diff --git a/server/tests/api/server/config-defaults.ts b/server/tests/api/server/config-defaults.ts
new file mode 100644
index 000000000..3ff09bf7e
--- /dev/null
+++ b/server/tests/api/server/config-defaults.ts
@@ -0,0 +1,213 @@
1/* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
2
3import 'mocha'
4import * as chai from 'chai'
5import { FIXTURE_URLS } from '@server/tests/shared'
6import { VideoDetails, VideoPrivacy } from '@shared/models'
7import { cleanupTests, createSingleServer, PeerTubeServer, setAccessTokensToServers, setDefaultVideoChannel } from '@shared/server-commands'
8
9const expect = chai.expect
10
11describe('Test config defaults', function () {
12 let server: PeerTubeServer
13 let channelId: number
14
15 before(async function () {
16 this.timeout(30000)
17
18 server = await createSingleServer(1)
19 await setAccessTokensToServers([ server ])
20 await setDefaultVideoChannel([ server ])
21
22 channelId = server.store.channel.id
23 })
24
25 describe('Default publish values', function () {
26
27 before(async function () {
28 const overrideConfig = {
29 defaults: {
30 publish: {
31 comments_enabled: false,
32 download_enabled: false,
33 privacy: VideoPrivacy.INTERNAL,
34 licence: 4
35 }
36 }
37 }
38
39 await server.kill()
40 await server.run(overrideConfig)
41 })
42
43 const attributes = {
44 name: 'video',
45 downloadEnabled: undefined,
46 commentsEnabled: undefined,
47 licence: undefined,
48 privacy: VideoPrivacy.PUBLIC // Privacy is mandatory for server
49 }
50
51 function checkVideo (video: VideoDetails) {
52 expect(video.downloadEnabled).to.be.false
53 expect(video.commentsEnabled).to.be.false
54 expect(video.licence.id).to.equal(4)
55 }
56
57 before(async function () {
58 await server.config.disableTranscoding()
59 await server.config.enableImports()
60 await server.config.enableLive({ allowReplay: false, transcoding: false })
61 })
62
63 it('Should have the correct server configuration', async function () {
64 const config = await server.config.getConfig()
65
66 expect(config.defaults.publish.commentsEnabled).to.be.false
67 expect(config.defaults.publish.downloadEnabled).to.be.false
68 expect(config.defaults.publish.licence).to.equal(4)
69 expect(config.defaults.publish.privacy).to.equal(VideoPrivacy.INTERNAL)
70 })
71
72 it('Should respect default values when uploading a video', async function () {
73 for (const mode of [ 'legacy' as 'legacy', 'resumable' as 'resumable' ]) {
74 const { id } = await server.videos.upload({ attributes, mode })
75
76 const video = await server.videos.get({ id })
77 checkVideo(video)
78 }
79 })
80
81 it('Should respect default values when importing a video using URL', async function () {
82 const { video: { id } } = await server.imports.importVideo({
83 attributes: {
84 ...attributes,
85 channelId,
86 targetUrl: FIXTURE_URLS.goodVideo
87 }
88 })
89
90 const video = await server.videos.get({ id })
91 checkVideo(video)
92 })
93
94 it('Should respect default values when importing a video using magnet URI', async function () {
95 const { video: { id } } = await server.imports.importVideo({
96 attributes: {
97 ...attributes,
98 channelId,
99 magnetUri: FIXTURE_URLS.magnet
100 }
101 })
102
103 const video = await server.videos.get({ id })
104 checkVideo(video)
105 })
106
107 it('Should respect default values when creating a live', async function () {
108 const { id } = await server.live.create({
109 fields: {
110 ...attributes,
111 channelId
112 }
113 })
114
115 const video = await server.videos.get({ id })
116 checkVideo(video)
117 })
118 })
119
120 describe('Default P2P values', function () {
121
122 describe('Webapp default value', function () {
123
124 before(async function () {
125 const overrideConfig = {
126 defaults: {
127 p2p: {
128 webapp: {
129 enabled: false
130 }
131 }
132 }
133 }
134
135 await server.kill()
136 await server.run(overrideConfig)
137 })
138
139 it('Should have appropriate P2P config', async function () {
140 const config = await server.config.getConfig()
141
142 expect(config.defaults.p2p.webapp.enabled).to.be.false
143 expect(config.defaults.p2p.embed.enabled).to.be.true
144 })
145
146 it('Should create a user with this default setting', async function () {
147 await server.users.create({ username: 'user_p2p_1' })
148 const userToken = await server.login.getAccessToken('user_p2p_1')
149
150 const { p2pEnabled } = await server.users.getMyInfo({ token: userToken })
151 expect(p2pEnabled).to.be.false
152 })
153
154 it('Should register a user with this default setting', async function () {
155 await server.users.register({ username: 'user_p2p_2' })
156
157 const userToken = await server.login.getAccessToken('user_p2p_2')
158
159 const { p2pEnabled } = await server.users.getMyInfo({ token: userToken })
160 expect(p2pEnabled).to.be.false
161 })
162 })
163
164 describe('Embed default value', function () {
165
166 before(async function () {
167 const overrideConfig = {
168 defaults: {
169 p2p: {
170 embed: {
171 enabled: false
172 }
173 }
174 },
175 signup: {
176 limit: 15
177 }
178 }
179
180 await server.kill()
181 await server.run(overrideConfig)
182 })
183
184 it('Should have appropriate P2P config', async function () {
185 const config = await server.config.getConfig()
186
187 expect(config.defaults.p2p.webapp.enabled).to.be.true
188 expect(config.defaults.p2p.embed.enabled).to.be.false
189 })
190
191 it('Should create a user with this default setting', async function () {
192 await server.users.create({ username: 'user_p2p_3' })
193 const userToken = await server.login.getAccessToken('user_p2p_3')
194
195 const { p2pEnabled } = await server.users.getMyInfo({ token: userToken })
196 expect(p2pEnabled).to.be.true
197 })
198
199 it('Should register a user with this default setting', async function () {
200 await server.users.register({ username: 'user_p2p_4' })
201
202 const userToken = await server.login.getAccessToken('user_p2p_4')
203
204 const { p2pEnabled } = await server.users.getMyInfo({ token: userToken })
205 expect(p2pEnabled).to.be.true
206 })
207 })
208 })
209
210 after(async function () {
211 await cleanupTests([ server ])
212 })
213})