1 /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
4 import * as chai from 'chai'
5 import { FIXTURE_URLS } from '@server/tests/shared'
6 import { VideoDetails, VideoPrivacy } from '@shared/models'
7 import { cleanupTests, createSingleServer, PeerTubeServer, setAccessTokensToServers, setDefaultVideoChannel } from '@shared/server-commands'
9 const expect = chai.expect
11 describe('Test config defaults', function () {
12 let server: PeerTubeServer
15 before(async function () {
18 server = await createSingleServer(1)
19 await setAccessTokensToServers([ server ])
20 await setDefaultVideoChannel([ server ])
22 channelId = server.store.channel.id
25 describe('Default publish values', function () {
27 before(async function () {
28 const overrideConfig = {
31 comments_enabled: false,
32 download_enabled: false,
33 privacy: VideoPrivacy.INTERNAL,
40 await server.run(overrideConfig)
45 downloadEnabled: undefined,
46 commentsEnabled: undefined,
48 privacy: VideoPrivacy.PUBLIC // Privacy is mandatory for server
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)
57 before(async function () {
58 await server.config.disableTranscoding()
59 await server.config.enableImports()
60 await server.config.enableLive({ allowReplay: false, transcoding: false })
63 it('Should have the correct server configuration', async function () {
64 const config = await server.config.getConfig()
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)
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 })
76 const video = await server.videos.get({ id })
81 it('Should respect default values when importing a video using URL', async function () {
82 const { video: { id } } = await server.imports.importVideo({
86 targetUrl: FIXTURE_URLS.goodVideo
90 const video = await server.videos.get({ id })
94 it('Should respect default values when importing a video using magnet URI', async function () {
95 const { video: { id } } = await server.imports.importVideo({
99 magnetUri: FIXTURE_URLS.magnet
103 const video = await server.videos.get({ id })
107 it('Should respect default values when creating a live', async function () {
108 const { id } = await server.live.create({
115 const video = await server.videos.get({ id })
120 describe('Default P2P values', function () {
122 describe('Webapp default value', function () {
124 before(async function () {
125 const overrideConfig = {
136 await server.run(overrideConfig)
139 it('Should have appropriate P2P config', async function () {
140 const config = await server.config.getConfig()
142 expect(config.defaults.p2p.webapp.enabled).to.be.false
143 expect(config.defaults.p2p.embed.enabled).to.be.true
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')
150 const { p2pEnabled } = await server.users.getMyInfo({ token: userToken })
151 expect(p2pEnabled).to.be.false
154 it('Should register a user with this default setting', async function () {
155 await server.users.register({ username: 'user_p2p_2' })
157 const userToken = await server.login.getAccessToken('user_p2p_2')
159 const { p2pEnabled } = await server.users.getMyInfo({ token: userToken })
160 expect(p2pEnabled).to.be.false
164 describe('Embed default value', function () {
166 before(async function () {
167 const overrideConfig = {
181 await server.run(overrideConfig)
184 it('Should have appropriate P2P config', async function () {
185 const config = await server.config.getConfig()
187 expect(config.defaults.p2p.webapp.enabled).to.be.true
188 expect(config.defaults.p2p.embed.enabled).to.be.false
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')
195 const { p2pEnabled } = await server.users.getMyInfo({ token: userToken })
196 expect(p2pEnabled).to.be.true
199 it('Should register a user with this default setting', async function () {
200 await server.users.register({ username: 'user_p2p_4' })
202 const userToken = await server.login.getAccessToken('user_p2p_4')
204 const { p2pEnabled } = await server.users.getMyInfo({ token: userToken })
205 expect(p2pEnabled).to.be.true
210 after(async function () {
211 await cleanupTests([ server ])