]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - server/tests/api/server/config-defaults.ts
shared/ typescript types dir server-commands
[github/Chocobozzz/PeerTube.git] / server / tests / api / server / config-defaults.ts
CommitLineData
3cf68b86
C
1/* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
2
3import 'mocha'
4import * as chai from 'chai'
854f533c
C
5import {
6 cleanupTests,
7 createSingleServer,
8 FIXTURE_URLS,
9 PeerTubeServer,
10 setAccessTokensToServers,
11 setDefaultVideoChannel
bf54587a 12} from '@shared/server-commands'
3cf68b86
C
13import { VideoDetails, VideoPrivacy } from '@shared/models'
14
15const expect = chai.expect
16
17describe('Test config defaults', function () {
18 let server: PeerTubeServer
19 let channelId: number
20
21 before(async function () {
22 this.timeout(30000)
23
a9bfa85d 24 server = await createSingleServer(1)
3cf68b86
C
25 await setAccessTokensToServers([ server ])
26 await setDefaultVideoChannel([ server ])
27
28 channelId = server.store.channel.id
29 })
30
31 describe('Default publish values', function () {
a9bfa85d
C
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
3cf68b86
C
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
a9bfa85d
C
126 describe('Default P2P values', function () {
127
b65de1be
C
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 }
a9bfa85d
C
138 }
139 }
a9bfa85d 140
b65de1be
C
141 await server.kill()
142 await server.run(overrideConfig)
143 })
a9bfa85d 144
b65de1be
C
145 it('Should have appropriate P2P config', async function () {
146 const config = await server.config.getConfig()
a9bfa85d 147
b65de1be
C
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 })
a9bfa85d 159
b65de1be
C
160 it('Should register a user with this default setting', async function () {
161 await server.users.register({ username: 'user_p2p_2' })
a9bfa85d 162
b65de1be
C
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 })
a9bfa85d
C
168 })
169
b65de1be
C
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()
a9bfa85d 192
b65de1be
C
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 })
a9bfa85d 204
b65de1be
C
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 })
a9bfa85d
C
213 })
214 })
215
3cf68b86
C
216 after(async function () {
217 await cleanupTests([ server ])
218 })
219})