diff options
Diffstat (limited to 'server/tests/utils')
-rw-r--r-- | server/tests/utils/miscs/miscs.ts | 23 | ||||
-rw-r--r-- | server/tests/utils/requests/requests.ts | 2 | ||||
-rw-r--r-- | server/tests/utils/server/config.ts | 41 | ||||
-rw-r--r-- | server/tests/utils/videos/videos.ts | 5 |
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 @@ | |||
1 | import * as WebTorrent from 'webtorrent' | 1 | import * as WebTorrent from 'webtorrent' |
2 | import { readFile, readdir } from 'fs' | ||
3 | 2 | ||
4 | let webtorrent = new WebTorrent() | 3 | let 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 | ||
10 | function 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 | |||
20 | function 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 |
31 | function dateIsValid (dateString: string, interval = 300000) { | 10 | function 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 | ||
50 | export { | 29 | export { |
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: { | |||
99 | function makePutBodyRequest (options: { | 99 | function 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 @@ | |||
1 | import * as request from 'supertest' | 1 | import * as request from 'supertest' |
2 | import { makeDeleteRequest, makeGetRequest, makePutBodyRequest } from '../' | ||
3 | import { CustomConfig } from '../../../../shared/models/config/custom-config.model' | ||
2 | 4 | ||
3 | function getConfig (url: string) { | 5 | function 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 | ||
15 | function 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 | |||
26 | function 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 | |||
38 | function 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 | ||
15 | export { | 51 | export { |
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' | |||
5 | import * as parseTorrent from 'parse-torrent' | 5 | import * as parseTorrent from 'parse-torrent' |
6 | import { extname, isAbsolute, join } from 'path' | 6 | import { extname, isAbsolute, join } from 'path' |
7 | import * as request from 'supertest' | 7 | import * as request from 'supertest' |
8 | import { getMyUserInformation, makeGetRequest, readFilePromise, ServerInfo } from '../' | 8 | import { getMyUserInformation, makeGetRequest, ServerInfo } from '../' |
9 | import { VideoPrivacy } from '../../../../shared/models/videos' | 9 | import { VideoPrivacy } from '../../../../shared/models/videos' |
10 | import { readFileBufferPromise } from '../../../helpers/core-utils' | ||
10 | import { VIDEO_CATEGORIES, VIDEO_LANGUAGES, VIDEO_LICENCES, VIDEO_PRIVACIES } from '../../../initializers' | 11 | import { VIDEO_CATEGORIES, VIDEO_LANGUAGES, VIDEO_LICENCES, VIDEO_PRIVACIES } from '../../../initializers' |
11 | import { dateIsValid, webtorrentAdd } from '../index' | 12 | import { 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 { |