From 3cf68b869decf07ff7435fe1436d4f3134df1bf4 Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Tue, 14 Dec 2021 17:17:01 +0100 Subject: Ability for admins to set default upload values --- server/tests/api/server/config-defaults.ts | 116 +++++++++++++++++++++++++++++ server/tests/api/server/index.ts | 2 + 2 files changed, 118 insertions(+) create mode 100644 server/tests/api/server/config-defaults.ts (limited to 'server/tests') diff --git a/server/tests/api/server/config-defaults.ts b/server/tests/api/server/config-defaults.ts new file mode 100644 index 000000000..2433d3119 --- /dev/null +++ b/server/tests/api/server/config-defaults.ts @@ -0,0 +1,116 @@ +/* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */ + +import 'mocha' +import * as chai from 'chai' +import { cleanupTests, createSingleServer, FIXTURE_URLS, PeerTubeServer, setAccessTokensToServers, setDefaultVideoChannel } from '@shared/extra-utils' +import { VideoDetails, VideoPrivacy } from '@shared/models' + +const expect = chai.expect + +describe('Test config defaults', function () { + let server: PeerTubeServer + let channelId: number + + before(async function () { + this.timeout(30000) + + const overrideConfig = { + defaults: { + publish: { + comments_enabled: false, + download_enabled: false, + privacy: VideoPrivacy.INTERNAL, + licence: 4 + } + } + } + + server = await createSingleServer(1, overrideConfig) + await setAccessTokensToServers([ server ]) + await setDefaultVideoChannel([ server ]) + + channelId = server.store.channel.id + }) + + describe('Default publish values', function () { + const attributes = { + name: 'video', + downloadEnabled: undefined, + commentsEnabled: undefined, + licence: undefined, + privacy: VideoPrivacy.PUBLIC // Privacy is mandatory for server + } + + function checkVideo (video: VideoDetails) { + expect(video.downloadEnabled).to.be.false + expect(video.commentsEnabled).to.be.false + expect(video.licence.id).to.equal(4) + } + + before(async function () { + await server.config.disableTranscoding() + await server.config.enableImports() + await server.config.enableLive({ allowReplay: false, transcoding: false }) + }) + + it('Should have the correct server configuration', async function () { + const config = await server.config.getConfig() + + expect(config.defaults.publish.commentsEnabled).to.be.false + expect(config.defaults.publish.downloadEnabled).to.be.false + expect(config.defaults.publish.licence).to.equal(4) + expect(config.defaults.publish.privacy).to.equal(VideoPrivacy.INTERNAL) + }) + + it('Should respect default values when uploading a video', async function () { + for (const mode of [ 'legacy' as 'legacy', 'resumable' as 'resumable' ]) { + const { id } = await server.videos.upload({ attributes, mode }) + + const video = await server.videos.get({ id }) + checkVideo(video) + } + }) + + it('Should respect default values when importing a video using URL', async function () { + const { video: { id } } = await server.imports.importVideo({ + attributes: { + ...attributes, + channelId, + targetUrl: FIXTURE_URLS.goodVideo + } + }) + + const video = await server.videos.get({ id }) + checkVideo(video) + }) + + it('Should respect default values when importing a video using magnet URI', async function () { + const { video: { id } } = await server.imports.importVideo({ + attributes: { + ...attributes, + channelId, + magnetUri: FIXTURE_URLS.magnet + } + }) + + const video = await server.videos.get({ id }) + checkVideo(video) + }) + + it('Should respect default values when creating a live', async function () { + const { id } = await server.live.create({ + fields: { + ...attributes, + channelId + } + }) + + const video = await server.videos.get({ id }) + checkVideo(video) + }) + }) + + after(async function () { + await cleanupTests([ server ]) + }) +}) diff --git a/server/tests/api/server/index.ts b/server/tests/api/server/index.ts index 8136fc3c6..45be107ce 100644 --- a/server/tests/api/server/index.ts +++ b/server/tests/api/server/index.ts @@ -1,4 +1,6 @@ import './auto-follows' +import './bulk' +import './config-defaults' import './config' import './contact-form' import './email' -- cgit v1.2.3