PeerTube/server/tests/api/server/config.ts

234 lines
7.5 KiB
TypeScript
Raw Normal View History

2017-09-04 21:21:47 +02:00
/* tslint:disable:no-unused-expression */
import 'mocha'
import * as chai from 'chai'
2018-02-28 18:04:46 +01:00
import { About } from '../../../../shared/models/server/about.model'
import { CustomConfig } from '../../../../shared/models/server/custom-config.model'
2017-09-04 21:21:47 +02:00
import {
deleteCustomConfig,
getAbout,
killallServers,
reRunServer,
2017-09-04 21:21:47 +02:00
flushTests,
2018-07-23 11:28:27 +02:00
getConfig,
getCustomConfig,
registerUser,
2017-09-04 21:21:47 +02:00
runServer,
2018-07-23 11:28:27 +02:00
setAccessTokensToServers,
updateCustomConfig
} from '../../../../shared/utils'
2017-09-04 21:21:47 +02:00
2018-07-23 11:28:27 +02:00
const expect = chai.expect
2018-07-12 19:02:00 +02:00
function checkInitialConfig (data: CustomConfig) {
expect(data.instance.name).to.equal('PeerTube')
expect(data.instance.shortDescription).to.equal(
'PeerTube, a federated (ActivityPub) video streaming platform using P2P (BitTorrent) directly in the web browser ' +
'with WebTorrent and Angular.'
)
expect(data.instance.description).to.equal('Welcome to this PeerTube instance!')
expect(data.instance.terms).to.equal('No terms for now.')
expect(data.instance.defaultClientRoute).to.equal('/videos/trending')
expect(data.instance.defaultNSFWPolicy).to.equal('display')
expect(data.instance.customizations.css).to.be.empty
expect(data.instance.customizations.javascript).to.be.empty
expect(data.services.twitter.username).to.equal('@Chocobozzz')
expect(data.services.twitter.whitelisted).to.be.false
expect(data.cache.previews.size).to.equal(1)
expect(data.cache.captions.size).to.equal(1)
expect(data.signup.enabled).to.be.true
expect(data.signup.limit).to.equal(4)
expect(data.signup.requiresEmailVerification).to.be.false
2018-07-12 19:02:00 +02:00
expect(data.admin.email).to.equal('admin1@example.com')
expect(data.user.videoQuota).to.equal(5242880)
2018-08-28 11:32:03 +02:00
expect(data.user.videoQuotaDaily).to.equal(-1)
2018-07-12 19:02:00 +02:00
expect(data.transcoding.enabled).to.be.false
expect(data.transcoding.threads).to.equal(2)
expect(data.transcoding.resolutions['240p']).to.be.true
expect(data.transcoding.resolutions['360p']).to.be.true
expect(data.transcoding.resolutions['480p']).to.be.true
expect(data.transcoding.resolutions['720p']).to.be.true
expect(data.transcoding.resolutions['1080p']).to.be.true
2018-08-03 11:10:31 +02:00
expect(data.import.videos.http.enabled).to.be.true
2018-08-07 10:07:53 +02:00
expect(data.import.videos.torrent.enabled).to.be.true
2018-07-12 19:02:00 +02:00
}
function checkUpdatedConfig (data: CustomConfig) {
expect(data.instance.name).to.equal('PeerTube updated')
expect(data.instance.shortDescription).to.equal('my short description')
expect(data.instance.description).to.equal('my super description')
expect(data.instance.terms).to.equal('my super terms')
expect(data.instance.defaultClientRoute).to.equal('/videos/recently-added')
expect(data.instance.defaultNSFWPolicy).to.equal('blur')
expect(data.instance.customizations.javascript).to.equal('alert("coucou")')
expect(data.instance.customizations.css).to.equal('body { background-color: red; }')
expect(data.services.twitter.username).to.equal('@Kuja')
expect(data.services.twitter.whitelisted).to.be.true
expect(data.cache.previews.size).to.equal(2)
expect(data.cache.captions.size).to.equal(3)
expect(data.signup.enabled).to.be.false
expect(data.signup.limit).to.equal(5)
expect(data.signup.requiresEmailVerification).to.be.true
2018-07-12 19:02:00 +02:00
expect(data.admin.email).to.equal('superadmin1@example.com')
expect(data.user.videoQuota).to.equal(5242881)
expect(data.user.videoQuotaDaily).to.equal(318742)
2018-07-12 19:02:00 +02:00
expect(data.transcoding.enabled).to.be.true
expect(data.transcoding.threads).to.equal(1)
expect(data.transcoding.resolutions['240p']).to.be.false
expect(data.transcoding.resolutions['360p']).to.be.true
expect(data.transcoding.resolutions['480p']).to.be.true
expect(data.transcoding.resolutions['720p']).to.be.false
expect(data.transcoding.resolutions['1080p']).to.be.false
2018-08-03 11:10:31 +02:00
expect(data.import.videos.http.enabled).to.be.false
2018-08-07 10:07:53 +02:00
expect(data.import.videos.torrent.enabled).to.be.false
2018-07-12 19:02:00 +02:00
}
2017-09-04 21:21:47 +02:00
describe('Test config', function () {
let server = null
before(async function () {
2018-01-18 18:10:45 +01:00
this.timeout(30000)
2017-09-04 21:21:47 +02:00
await flushTests()
server = await runServer(1)
await setAccessTokensToServers([ server ])
2017-09-04 21:21:47 +02:00
})
it('Should have a correct config on a server with registration enabled', async function () {
const res = await getConfig(server.url)
const data = res.body
expect(data.signup.allowed).to.be.true
})
it('Should have a correct config on a server with registration enabled and a users limit', async function () {
2017-11-24 14:39:14 +01:00
this.timeout(5000)
2017-11-16 18:40:50 +01:00
await Promise.all([
registerUser(server.url, 'user1', 'super password'),
registerUser(server.url, 'user2', 'super password'),
registerUser(server.url, 'user3', 'super password')
])
2017-09-04 21:21:47 +02:00
const res = await getConfig(server.url)
const data = res.body
expect(data.signup.allowed).to.be.false
})
it('Should get the customized configuration', async function () {
const res = await getCustomConfig(server.url, server.accessToken)
const data = res.body as CustomConfig
2018-07-12 19:02:00 +02:00
checkInitialConfig(data)
})
it('Should update the customized configuration', async function () {
2018-07-12 19:02:00 +02:00
const newCustomConfig: CustomConfig = {
instance: {
name: 'PeerTube updated',
2018-03-15 14:31:08 +01:00
shortDescription: 'my short description',
description: 'my super description',
terms: 'my super terms',
2018-03-01 13:57:29 +01:00
defaultClientRoute: '/videos/recently-added',
defaultNSFWPolicy: 'blur' as 'blur',
customizations: {
javascript: 'alert("coucou")',
css: 'body { background-color: red; }'
}
},
services: {
twitter: {
username: '@Kuja',
whitelisted: true
}
},
cache: {
previews: {
size: 2
2018-07-12 19:02:00 +02:00
},
captions: {
size: 3
}
},
signup: {
enabled: false,
limit: 5,
requiresEmailVerification: true
},
admin: {
email: 'superadmin1@example.com'
},
user: {
videoQuota: 5242881,
videoQuotaDaily: 318742
},
transcoding: {
enabled: true,
threads: 1,
resolutions: {
'240p': false,
'360p': true,
'480p': true,
'720p': false,
'1080p': false
}
2018-08-03 11:10:31 +02:00
},
import: {
videos: {
http: {
enabled: false
2018-08-07 10:07:53 +02:00
},
torrent: {
enabled: false
2018-08-03 11:10:31 +02:00
}
}
}
}
await updateCustomConfig(server.url, server.accessToken, newCustomConfig)
const res = await getCustomConfig(server.url, server.accessToken)
const data = res.body
2018-07-12 19:02:00 +02:00
checkUpdatedConfig(data)
})
it('Should have the configuration updated after a restart', async function () {
2018-01-19 13:58:13 +01:00
this.timeout(10000)
killallServers([ server ])
await reRunServer(server)
const res = await getCustomConfig(server.url, server.accessToken)
const data = res.body
2018-07-12 19:02:00 +02:00
checkUpdatedConfig(data)
})
2018-01-31 17:47:36 +01:00
it('Should fetch the about information', async function () {
const res = await getAbout(server.url)
const data: About = res.body
expect(data.instance.name).to.equal('PeerTube updated')
2018-03-15 14:31:08 +01:00
expect(data.instance.shortDescription).to.equal('my short description')
2018-01-31 17:47:36 +01:00
expect(data.instance.description).to.equal('my super description')
expect(data.instance.terms).to.equal('my super terms')
})
it('Should remove the custom configuration', async function () {
2018-01-19 13:58:13 +01:00
this.timeout(10000)
await deleteCustomConfig(server.url, server.accessToken)
const res = await getCustomConfig(server.url, server.accessToken)
const data = res.body
2018-07-12 19:02:00 +02:00
checkInitialConfig(data)
})
2017-09-04 21:21:47 +02:00
after(async function () {
killallServers([ server ])
2017-09-04 21:21:47 +02:00
})
})