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