1 /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
3 import { expect } from 'chai'
4 import { FIXTURE_URLS } from '@server/tests/shared'
5 import { VideoDetails, VideoPrivacy } from '@shared/models'
6 import { cleanupTests, createSingleServer, PeerTubeServer, setAccessTokensToServers, setDefaultVideoChannel } from '@shared/server-commands'
8 describe('Test config defaults', function () {
9 let server: PeerTubeServer
12 before(async function () {
15 server = await createSingleServer(1)
16 await setAccessTokensToServers([ server ])
17 await setDefaultVideoChannel([ server ])
19 channelId = server.store.channel.id
22 describe('Default publish values', function () {
24 before(async function () {
25 const overrideConfig = {
28 comments_enabled: false,
29 download_enabled: false,
30 privacy: VideoPrivacy.INTERNAL,
37 await server.run(overrideConfig)
42 downloadEnabled: undefined,
43 commentsEnabled: undefined,
45 privacy: VideoPrivacy.PUBLIC // Privacy is mandatory for server
48 function checkVideo (video: VideoDetails) {
49 expect(video.downloadEnabled).to.be.false
50 expect(video.commentsEnabled).to.be.false
51 expect(video.licence.id).to.equal(4)
54 before(async function () {
55 await server.config.disableTranscoding()
56 await server.config.enableImports()
57 await server.config.enableLive({ allowReplay: false, transcoding: false })
60 it('Should have the correct server configuration', async function () {
61 const config = await server.config.getConfig()
63 expect(config.defaults.publish.commentsEnabled).to.be.false
64 expect(config.defaults.publish.downloadEnabled).to.be.false
65 expect(config.defaults.publish.licence).to.equal(4)
66 expect(config.defaults.publish.privacy).to.equal(VideoPrivacy.INTERNAL)
69 it('Should respect default values when uploading a video', async function () {
70 for (const mode of [ 'legacy' as 'legacy', 'resumable' as 'resumable' ]) {
71 const { id } = await server.videos.upload({ attributes, mode })
73 const video = await server.videos.get({ id })
78 it('Should respect default values when importing a video using URL', async function () {
79 const { video: { id } } = await server.imports.importVideo({
83 targetUrl: FIXTURE_URLS.goodVideo
87 const video = await server.videos.get({ id })
91 it('Should respect default values when importing a video using magnet URI', async function () {
92 const { video: { id } } = await server.imports.importVideo({
96 magnetUri: FIXTURE_URLS.magnet
100 const video = await server.videos.get({ id })
104 it('Should respect default values when creating a live', async function () {
105 const { id } = await server.live.create({
112 const video = await server.videos.get({ id })
117 describe('Default P2P values', function () {
119 describe('Webapp default value', function () {
121 before(async function () {
122 const overrideConfig = {
133 await server.run(overrideConfig)
136 it('Should have appropriate P2P config', async function () {
137 const config = await server.config.getConfig()
139 expect(config.defaults.p2p.webapp.enabled).to.be.false
140 expect(config.defaults.p2p.embed.enabled).to.be.true
143 it('Should create a user with this default setting', async function () {
144 await server.users.create({ username: 'user_p2p_1' })
145 const userToken = await server.login.getAccessToken('user_p2p_1')
147 const { p2pEnabled } = await server.users.getMyInfo({ token: userToken })
148 expect(p2pEnabled).to.be.false
151 it('Should register a user with this default setting', async function () {
152 await server.registrations.register({ username: 'user_p2p_2' })
154 const userToken = await server.login.getAccessToken('user_p2p_2')
156 const { p2pEnabled } = await server.users.getMyInfo({ token: userToken })
157 expect(p2pEnabled).to.be.false
161 describe('Embed default value', function () {
163 before(async function () {
164 const overrideConfig = {
178 await server.run(overrideConfig)
181 it('Should have appropriate P2P config', async function () {
182 const config = await server.config.getConfig()
184 expect(config.defaults.p2p.webapp.enabled).to.be.true
185 expect(config.defaults.p2p.embed.enabled).to.be.false
188 it('Should create a user with this default setting', async function () {
189 await server.users.create({ username: 'user_p2p_3' })
190 const userToken = await server.login.getAccessToken('user_p2p_3')
192 const { p2pEnabled } = await server.users.getMyInfo({ token: userToken })
193 expect(p2pEnabled).to.be.true
196 it('Should register a user with this default setting', async function () {
197 await server.registrations.register({ username: 'user_p2p_4' })
199 const userToken = await server.login.getAccessToken('user_p2p_4')
201 const { p2pEnabled } = await server.users.getMyInfo({ token: userToken })
202 expect(p2pEnabled).to.be.true
207 after(async function () {
208 await cleanupTests([ server ])