aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/tests/utils
diff options
context:
space:
mode:
authorChocobozzz <me@florianbigard.com>2018-01-17 10:32:03 +0100
committerChocobozzz <me@florianbigard.com>2018-01-17 10:41:27 +0100
commitfd206f0b2d7e5c8e00e2817266d90ec54f79e1da (patch)
tree86b096cf2abd7eb49b892de1c9be855f45a41a9c /server/tests/utils
parent9581cabc596acb18c0ad86bcf3a07c2b45e8e47e (diff)
downloadPeerTube-fd206f0b2d7e5c8e00e2817266d90ec54f79e1da.tar.gz
PeerTube-fd206f0b2d7e5c8e00e2817266d90ec54f79e1da.tar.zst
PeerTube-fd206f0b2d7e5c8e00e2817266d90ec54f79e1da.zip
Add ability to update some configuration keys
Diffstat (limited to 'server/tests/utils')
-rw-r--r--server/tests/utils/miscs/miscs.ts23
-rw-r--r--server/tests/utils/requests/requests.ts2
-rw-r--r--server/tests/utils/server/config.ts41
-rw-r--r--server/tests/utils/videos/videos.ts5
4 files changed, 44 insertions, 27 deletions
diff --git a/server/tests/utils/miscs/miscs.ts b/server/tests/utils/miscs/miscs.ts
index 2c51d1f0a..2aac37791 100644
--- a/server/tests/utils/miscs/miscs.ts
+++ b/server/tests/utils/miscs/miscs.ts
@@ -1,5 +1,4 @@
1import * as WebTorrent from 'webtorrent' 1import * as WebTorrent from 'webtorrent'
2import { readFile, readdir } from 'fs'
3 2
4let webtorrent = new WebTorrent() 3let webtorrent = new WebTorrent()
5 4
@@ -7,26 +6,6 @@ function immutableAssign <T, U> (target: T, source: U) {
7 return Object.assign<{}, T, U>({}, target, source) 6 return Object.assign<{}, T, U>({}, target, source)
8} 7}
9 8
10function readFilePromise (path: string) {
11 return new Promise<Buffer>((res, rej) => {
12 readFile(path, (err, data) => {
13 if (err) return rej(err)
14
15 return res(data)
16 })
17 })
18}
19
20function readdirPromise (path: string) {
21 return new Promise<string[]>((res, rej) => {
22 readdir(path, (err, files) => {
23 if (err) return rej(err)
24
25 return res(files)
26 })
27 })
28}
29
30 // Default interval -> 5 minutes 9 // Default interval -> 5 minutes
31function dateIsValid (dateString: string, interval = 300000) { 10function dateIsValid (dateString: string, interval = 300000) {
32 const dateToCheck = new Date(dateString) 11 const dateToCheck = new Date(dateString)
@@ -48,8 +27,6 @@ function webtorrentAdd (torrent: string, refreshWebTorrent = false) {
48// --------------------------------------------------------------------------- 27// ---------------------------------------------------------------------------
49 28
50export { 29export {
51 readFilePromise,
52 readdirPromise,
53 dateIsValid, 30 dateIsValid,
54 wait, 31 wait,
55 webtorrentAdd, 32 webtorrentAdd,
diff --git a/server/tests/utils/requests/requests.ts b/server/tests/utils/requests/requests.ts
index eb02cf9e6..840072430 100644
--- a/server/tests/utils/requests/requests.ts
+++ b/server/tests/utils/requests/requests.ts
@@ -99,7 +99,7 @@ function makePostBodyRequest (options: {
99function makePutBodyRequest (options: { 99function makePutBodyRequest (options: {
100 url: string, 100 url: string,
101 path: string, 101 path: string,
102 token: string, 102 token?: string,
103 fields: { [ fieldName: string ]: any }, 103 fields: { [ fieldName: string ]: any },
104 statusCodeExpected?: number 104 statusCodeExpected?: number
105}) { 105}) {
diff --git a/server/tests/utils/server/config.ts b/server/tests/utils/server/config.ts
index d09c19c60..b6905757a 100644
--- a/server/tests/utils/server/config.ts
+++ b/server/tests/utils/server/config.ts
@@ -1,4 +1,6 @@
1import * as request from 'supertest' 1import * as request from 'supertest'
2import { makeDeleteRequest, makeGetRequest, makePutBodyRequest } from '../'
3import { CustomConfig } from '../../../../shared/models/config/custom-config.model'
2 4
3function getConfig (url: string) { 5function getConfig (url: string) {
4 const path = '/api/v1/config' 6 const path = '/api/v1/config'
@@ -10,8 +12,45 @@ function getConfig (url: string) {
10 .expect('Content-Type', /json/) 12 .expect('Content-Type', /json/)
11} 13}
12 14
15function getCustomConfig (url: string, token: string, statusCodeExpected = 200) {
16 const path = '/api/v1/config/custom'
17
18 return makeGetRequest({
19 url,
20 token,
21 path,
22 statusCodeExpected
23 })
24}
25
26function updateCustomConfig (url: string, token: string, newCustomConfig: CustomConfig, statusCodeExpected = 200) {
27 const path = '/api/v1/config/custom'
28
29 return makePutBodyRequest({
30 url,
31 token,
32 path,
33 fields: newCustomConfig,
34 statusCodeExpected
35 })
36}
37
38function deleteCustomConfig (url: string, token: string, statusCodeExpected = 200) {
39 const path = '/api/v1/config/custom'
40
41 return makeDeleteRequest({
42 url,
43 token,
44 path,
45 statusCodeExpected
46 })
47}
48
13// --------------------------------------------------------------------------- 49// ---------------------------------------------------------------------------
14 50
15export { 51export {
16 getConfig 52 getConfig,
53 getCustomConfig,
54 updateCustomConfig,
55 deleteCustomConfig
17} 56}
diff --git a/server/tests/utils/videos/videos.ts b/server/tests/utils/videos/videos.ts
index dc1327215..095d4e29d 100644
--- a/server/tests/utils/videos/videos.ts
+++ b/server/tests/utils/videos/videos.ts
@@ -5,8 +5,9 @@ import { readFile } from 'fs'
5import * as parseTorrent from 'parse-torrent' 5import * as parseTorrent from 'parse-torrent'
6import { extname, isAbsolute, join } from 'path' 6import { extname, isAbsolute, join } from 'path'
7import * as request from 'supertest' 7import * as request from 'supertest'
8import { getMyUserInformation, makeGetRequest, readFilePromise, ServerInfo } from '../' 8import { getMyUserInformation, makeGetRequest, ServerInfo } from '../'
9import { VideoPrivacy } from '../../../../shared/models/videos' 9import { VideoPrivacy } from '../../../../shared/models/videos'
10import { readFileBufferPromise } from '../../../helpers/core-utils'
10import { VIDEO_CATEGORIES, VIDEO_LANGUAGES, VIDEO_LICENCES, VIDEO_PRIVACIES } from '../../../initializers' 11import { VIDEO_CATEGORIES, VIDEO_LANGUAGES, VIDEO_LICENCES, VIDEO_PRIVACIES } from '../../../initializers'
11import { dateIsValid, webtorrentAdd } from '../index' 12import { dateIsValid, webtorrentAdd } from '../index'
12 13
@@ -210,7 +211,7 @@ async function testVideoImage (url: string, imageName: string, imagePath: string
210 .get(imagePath) 211 .get(imagePath)
211 .expect(200) 212 .expect(200)
212 213
213 const data = await readFilePromise(join(__dirname, '..', '..', 'api', 'fixtures', imageName + extension)) 214 const data = await readFileBufferPromise(join(__dirname, '..', '..', 'api', 'fixtures', imageName + extension))
214 215
215 return data.equals(res.body) 216 return data.equals(res.body)
216 } else { 217 } else {