From fd206f0b2d7e5c8e00e2817266d90ec54f79e1da Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Wed, 17 Jan 2018 10:32:03 +0100 Subject: Add ability to update some configuration keys --- server/tests/utils/miscs/miscs.ts | 23 ------------------ server/tests/utils/requests/requests.ts | 2 +- server/tests/utils/server/config.ts | 41 ++++++++++++++++++++++++++++++++- server/tests/utils/videos/videos.ts | 5 ++-- 4 files changed, 44 insertions(+), 27 deletions(-) (limited to 'server/tests/utils') 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 @@ import * as WebTorrent from 'webtorrent' -import { readFile, readdir } from 'fs' let webtorrent = new WebTorrent() @@ -7,26 +6,6 @@ function immutableAssign (target: T, source: U) { return Object.assign<{}, T, U>({}, target, source) } -function readFilePromise (path: string) { - return new Promise((res, rej) => { - readFile(path, (err, data) => { - if (err) return rej(err) - - return res(data) - }) - }) -} - -function readdirPromise (path: string) { - return new Promise((res, rej) => { - readdir(path, (err, files) => { - if (err) return rej(err) - - return res(files) - }) - }) -} - // Default interval -> 5 minutes function dateIsValid (dateString: string, interval = 300000) { const dateToCheck = new Date(dateString) @@ -48,8 +27,6 @@ function webtorrentAdd (torrent: string, refreshWebTorrent = false) { // --------------------------------------------------------------------------- export { - readFilePromise, - readdirPromise, dateIsValid, wait, 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: { function makePutBodyRequest (options: { url: string, path: string, - token: string, + token?: string, fields: { [ fieldName: string ]: any }, statusCodeExpected?: number }) { 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 @@ import * as request from 'supertest' +import { makeDeleteRequest, makeGetRequest, makePutBodyRequest } from '../' +import { CustomConfig } from '../../../../shared/models/config/custom-config.model' function getConfig (url: string) { const path = '/api/v1/config' @@ -10,8 +12,45 @@ function getConfig (url: string) { .expect('Content-Type', /json/) } +function getCustomConfig (url: string, token: string, statusCodeExpected = 200) { + const path = '/api/v1/config/custom' + + return makeGetRequest({ + url, + token, + path, + statusCodeExpected + }) +} + +function updateCustomConfig (url: string, token: string, newCustomConfig: CustomConfig, statusCodeExpected = 200) { + const path = '/api/v1/config/custom' + + return makePutBodyRequest({ + url, + token, + path, + fields: newCustomConfig, + statusCodeExpected + }) +} + +function deleteCustomConfig (url: string, token: string, statusCodeExpected = 200) { + const path = '/api/v1/config/custom' + + return makeDeleteRequest({ + url, + token, + path, + statusCodeExpected + }) +} + // --------------------------------------------------------------------------- export { - getConfig + getConfig, + getCustomConfig, + updateCustomConfig, + deleteCustomConfig } 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' import * as parseTorrent from 'parse-torrent' import { extname, isAbsolute, join } from 'path' import * as request from 'supertest' -import { getMyUserInformation, makeGetRequest, readFilePromise, ServerInfo } from '../' +import { getMyUserInformation, makeGetRequest, ServerInfo } from '../' import { VideoPrivacy } from '../../../../shared/models/videos' +import { readFileBufferPromise } from '../../../helpers/core-utils' import { VIDEO_CATEGORIES, VIDEO_LANGUAGES, VIDEO_LICENCES, VIDEO_PRIVACIES } from '../../../initializers' import { dateIsValid, webtorrentAdd } from '../index' @@ -210,7 +211,7 @@ async function testVideoImage (url: string, imageName: string, imagePath: string .get(imagePath) .expect(200) - const data = await readFilePromise(join(__dirname, '..', '..', 'api', 'fixtures', imageName + extension)) + const data = await readFileBufferPromise(join(__dirname, '..', '..', 'api', 'fixtures', imageName + extension)) return data.equals(res.body) } else { -- cgit v1.2.3