diff options
Diffstat (limited to 'server/tests/utils')
-rw-r--r-- | server/tests/utils/miscs/miscs.ts | 35 | ||||
-rw-r--r-- | server/tests/utils/requests/requests.ts | 4 | ||||
-rw-r--r-- | server/tests/utils/server/follows.ts | 6 | ||||
-rw-r--r-- | server/tests/utils/users/blocklist.ts | 198 | ||||
-rw-r--r-- | server/tests/utils/users/users.ts | 3 | ||||
-rw-r--r-- | server/tests/utils/videos/video-comments.ts | 14 | ||||
-rw-r--r-- | server/tests/utils/videos/video-history.ts | 14 |
7 files changed, 260 insertions, 14 deletions
diff --git a/server/tests/utils/miscs/miscs.ts b/server/tests/utils/miscs/miscs.ts index b2f80e9b1..589daa420 100644 --- a/server/tests/utils/miscs/miscs.ts +++ b/server/tests/utils/miscs/miscs.ts | |||
@@ -4,7 +4,8 @@ import * as chai from 'chai' | |||
4 | import { isAbsolute, join } from 'path' | 4 | import { isAbsolute, join } from 'path' |
5 | import * as request from 'supertest' | 5 | import * as request from 'supertest' |
6 | import * as WebTorrent from 'webtorrent' | 6 | import * as WebTorrent from 'webtorrent' |
7 | import { readFile } from 'fs-extra' | 7 | import { pathExists, readFile } from 'fs-extra' |
8 | import * as ffmpeg from 'fluent-ffmpeg' | ||
8 | 9 | ||
9 | const expect = chai.expect | 10 | const expect = chai.expect |
10 | let webtorrent = new WebTorrent() | 11 | let webtorrent = new WebTorrent() |
@@ -51,14 +52,41 @@ async function testImage (url: string, imageName: string, imagePath: string, ext | |||
51 | expect(data.length).to.be.below(maxLength) | 52 | expect(data.length).to.be.below(maxLength) |
52 | } | 53 | } |
53 | 54 | ||
54 | function buildAbsoluteFixturePath (path: string) { | 55 | function buildAbsoluteFixturePath (path: string, customTravisPath = false) { |
55 | if (isAbsolute(path)) { | 56 | if (isAbsolute(path)) { |
56 | return path | 57 | return path |
57 | } | 58 | } |
58 | 59 | ||
60 | if (customTravisPath && process.env.TRAVIS) return join(process.env.HOME, 'fixtures', path) | ||
61 | |||
59 | return join(__dirname, '..', '..', 'fixtures', path) | 62 | return join(__dirname, '..', '..', 'fixtures', path) |
60 | } | 63 | } |
61 | 64 | ||
65 | async function generateHighBitrateVideo () { | ||
66 | const tempFixturePath = buildAbsoluteFixturePath('video_high_bitrate_1080p.mp4', true) | ||
67 | |||
68 | const exists = await pathExists(tempFixturePath) | ||
69 | if (!exists) { | ||
70 | |||
71 | // Generate a random, high bitrate video on the fly, so we don't have to include | ||
72 | // a large file in the repo. The video needs to have a certain minimum length so | ||
73 | // that FFmpeg properly applies bitrate limits. | ||
74 | // https://stackoverflow.com/a/15795112 | ||
75 | return new Promise<string>(async (res, rej) => { | ||
76 | ffmpeg() | ||
77 | .outputOptions([ '-f rawvideo', '-video_size 1920x1080', '-i /dev/urandom' ]) | ||
78 | .outputOptions([ '-ac 2', '-f s16le', '-i /dev/urandom', '-t 10' ]) | ||
79 | .outputOptions([ '-maxrate 10M', '-bufsize 10M' ]) | ||
80 | .output(tempFixturePath) | ||
81 | .on('error', rej) | ||
82 | .on('end', () => res(tempFixturePath)) | ||
83 | .run() | ||
84 | }) | ||
85 | } | ||
86 | |||
87 | return tempFixturePath | ||
88 | } | ||
89 | |||
62 | // --------------------------------------------------------------------------- | 90 | // --------------------------------------------------------------------------- |
63 | 91 | ||
64 | export { | 92 | export { |
@@ -68,5 +96,6 @@ export { | |||
68 | immutableAssign, | 96 | immutableAssign, |
69 | testImage, | 97 | testImage, |
70 | buildAbsoluteFixturePath, | 98 | buildAbsoluteFixturePath, |
71 | root | 99 | root, |
100 | generateHighBitrateVideo | ||
72 | } | 101 | } |
diff --git a/server/tests/utils/requests/requests.ts b/server/tests/utils/requests/requests.ts index 27a529eda..5796540f7 100644 --- a/server/tests/utils/requests/requests.ts +++ b/server/tests/utils/requests/requests.ts | |||
@@ -37,9 +37,7 @@ function makeDeleteRequest (options: { | |||
37 | 37 | ||
38 | if (options.token) req.set('Authorization', 'Bearer ' + options.token) | 38 | if (options.token) req.set('Authorization', 'Bearer ' + options.token) |
39 | 39 | ||
40 | return req | 40 | return req.expect(options.statusCodeExpected) |
41 | .expect('Content-Type', /json/) | ||
42 | .expect(options.statusCodeExpected) | ||
43 | } | 41 | } |
44 | 42 | ||
45 | function makeUploadRequest (options: { | 43 | function makeUploadRequest (options: { |
diff --git a/server/tests/utils/server/follows.ts b/server/tests/utils/server/follows.ts index 8a65a958b..7741757a6 100644 --- a/server/tests/utils/server/follows.ts +++ b/server/tests/utils/server/follows.ts | |||
@@ -2,7 +2,7 @@ import * as request from 'supertest' | |||
2 | import { ServerInfo } from './servers' | 2 | import { ServerInfo } from './servers' |
3 | import { waitJobs } from './jobs' | 3 | import { waitJobs } from './jobs' |
4 | 4 | ||
5 | function getFollowersListPaginationAndSort (url: string, start: number, count: number, sort: string) { | 5 | function getFollowersListPaginationAndSort (url: string, start: number, count: number, sort: string, search?: string) { |
6 | const path = '/api/v1/server/followers' | 6 | const path = '/api/v1/server/followers' |
7 | 7 | ||
8 | return request(url) | 8 | return request(url) |
@@ -10,12 +10,13 @@ function getFollowersListPaginationAndSort (url: string, start: number, count: n | |||
10 | .query({ start }) | 10 | .query({ start }) |
11 | .query({ count }) | 11 | .query({ count }) |
12 | .query({ sort }) | 12 | .query({ sort }) |
13 | .query({ search }) | ||
13 | .set('Accept', 'application/json') | 14 | .set('Accept', 'application/json') |
14 | .expect(200) | 15 | .expect(200) |
15 | .expect('Content-Type', /json/) | 16 | .expect('Content-Type', /json/) |
16 | } | 17 | } |
17 | 18 | ||
18 | function getFollowingListPaginationAndSort (url: string, start: number, count: number, sort: string) { | 19 | function getFollowingListPaginationAndSort (url: string, start: number, count: number, sort: string, search?: string) { |
19 | const path = '/api/v1/server/following' | 20 | const path = '/api/v1/server/following' |
20 | 21 | ||
21 | return request(url) | 22 | return request(url) |
@@ -23,6 +24,7 @@ function getFollowingListPaginationAndSort (url: string, start: number, count: n | |||
23 | .query({ start }) | 24 | .query({ start }) |
24 | .query({ count }) | 25 | .query({ count }) |
25 | .query({ sort }) | 26 | .query({ sort }) |
27 | .query({ search }) | ||
26 | .set('Accept', 'application/json') | 28 | .set('Accept', 'application/json') |
27 | .expect(200) | 29 | .expect(200) |
28 | .expect('Content-Type', /json/) | 30 | .expect('Content-Type', /json/) |
diff --git a/server/tests/utils/users/blocklist.ts b/server/tests/utils/users/blocklist.ts new file mode 100644 index 000000000..35b537571 --- /dev/null +++ b/server/tests/utils/users/blocklist.ts | |||
@@ -0,0 +1,198 @@ | |||
1 | /* tslint:disable:no-unused-expression */ | ||
2 | |||
3 | import { makeDeleteRequest, makePostBodyRequest } from '../index' | ||
4 | import { makeGetRequest } from '../requests/requests' | ||
5 | |||
6 | function getAccountBlocklistByAccount ( | ||
7 | url: string, | ||
8 | token: string, | ||
9 | start: number, | ||
10 | count: number, | ||
11 | sort = '-createdAt', | ||
12 | statusCodeExpected = 200 | ||
13 | ) { | ||
14 | const path = '/api/v1/users/me/blocklist/accounts' | ||
15 | |||
16 | return makeGetRequest({ | ||
17 | url, | ||
18 | token, | ||
19 | query: { start, count, sort }, | ||
20 | path, | ||
21 | statusCodeExpected | ||
22 | }) | ||
23 | } | ||
24 | |||
25 | function addAccountToAccountBlocklist (url: string, token: string, accountToBlock: string, statusCodeExpected = 204) { | ||
26 | const path = '/api/v1/users/me/blocklist/accounts' | ||
27 | |||
28 | return makePostBodyRequest({ | ||
29 | url, | ||
30 | path, | ||
31 | token, | ||
32 | fields: { | ||
33 | accountName: accountToBlock | ||
34 | }, | ||
35 | statusCodeExpected | ||
36 | }) | ||
37 | } | ||
38 | |||
39 | function removeAccountFromAccountBlocklist (url: string, token: string, accountToUnblock: string, statusCodeExpected = 204) { | ||
40 | const path = '/api/v1/users/me/blocklist/accounts/' + accountToUnblock | ||
41 | |||
42 | return makeDeleteRequest({ | ||
43 | url, | ||
44 | path, | ||
45 | token, | ||
46 | statusCodeExpected | ||
47 | }) | ||
48 | } | ||
49 | |||
50 | function getServerBlocklistByAccount ( | ||
51 | url: string, | ||
52 | token: string, | ||
53 | start: number, | ||
54 | count: number, | ||
55 | sort = '-createdAt', | ||
56 | statusCodeExpected = 200 | ||
57 | ) { | ||
58 | const path = '/api/v1/users/me/blocklist/servers' | ||
59 | |||
60 | return makeGetRequest({ | ||
61 | url, | ||
62 | token, | ||
63 | query: { start, count, sort }, | ||
64 | path, | ||
65 | statusCodeExpected | ||
66 | }) | ||
67 | } | ||
68 | |||
69 | function addServerToAccountBlocklist (url: string, token: string, serverToBlock: string, statusCodeExpected = 204) { | ||
70 | const path = '/api/v1/users/me/blocklist/servers' | ||
71 | |||
72 | return makePostBodyRequest({ | ||
73 | url, | ||
74 | path, | ||
75 | token, | ||
76 | fields: { | ||
77 | host: serverToBlock | ||
78 | }, | ||
79 | statusCodeExpected | ||
80 | }) | ||
81 | } | ||
82 | |||
83 | function removeServerFromAccountBlocklist (url: string, token: string, serverToBlock: string, statusCodeExpected = 204) { | ||
84 | const path = '/api/v1/users/me/blocklist/servers/' + serverToBlock | ||
85 | |||
86 | return makeDeleteRequest({ | ||
87 | url, | ||
88 | path, | ||
89 | token, | ||
90 | statusCodeExpected | ||
91 | }) | ||
92 | } | ||
93 | |||
94 | function getAccountBlocklistByServer ( | ||
95 | url: string, | ||
96 | token: string, | ||
97 | start: number, | ||
98 | count: number, | ||
99 | sort = '-createdAt', | ||
100 | statusCodeExpected = 200 | ||
101 | ) { | ||
102 | const path = '/api/v1/server/blocklist/accounts' | ||
103 | |||
104 | return makeGetRequest({ | ||
105 | url, | ||
106 | token, | ||
107 | query: { start, count, sort }, | ||
108 | path, | ||
109 | statusCodeExpected | ||
110 | }) | ||
111 | } | ||
112 | |||
113 | function addAccountToServerBlocklist (url: string, token: string, accountToBlock: string, statusCodeExpected = 204) { | ||
114 | const path = '/api/v1/server/blocklist/accounts' | ||
115 | |||
116 | return makePostBodyRequest({ | ||
117 | url, | ||
118 | path, | ||
119 | token, | ||
120 | fields: { | ||
121 | accountName: accountToBlock | ||
122 | }, | ||
123 | statusCodeExpected | ||
124 | }) | ||
125 | } | ||
126 | |||
127 | function removeAccountFromServerBlocklist (url: string, token: string, accountToUnblock: string, statusCodeExpected = 204) { | ||
128 | const path = '/api/v1/server/blocklist/accounts/' + accountToUnblock | ||
129 | |||
130 | return makeDeleteRequest({ | ||
131 | url, | ||
132 | path, | ||
133 | token, | ||
134 | statusCodeExpected | ||
135 | }) | ||
136 | } | ||
137 | |||
138 | function getServerBlocklistByServer ( | ||
139 | url: string, | ||
140 | token: string, | ||
141 | start: number, | ||
142 | count: number, | ||
143 | sort = '-createdAt', | ||
144 | statusCodeExpected = 200 | ||
145 | ) { | ||
146 | const path = '/api/v1/server/blocklist/servers' | ||
147 | |||
148 | return makeGetRequest({ | ||
149 | url, | ||
150 | token, | ||
151 | query: { start, count, sort }, | ||
152 | path, | ||
153 | statusCodeExpected | ||
154 | }) | ||
155 | } | ||
156 | |||
157 | function addServerToServerBlocklist (url: string, token: string, serverToBlock: string, statusCodeExpected = 204) { | ||
158 | const path = '/api/v1/server/blocklist/servers' | ||
159 | |||
160 | return makePostBodyRequest({ | ||
161 | url, | ||
162 | path, | ||
163 | token, | ||
164 | fields: { | ||
165 | host: serverToBlock | ||
166 | }, | ||
167 | statusCodeExpected | ||
168 | }) | ||
169 | } | ||
170 | |||
171 | function removeServerFromServerBlocklist (url: string, token: string, serverToBlock: string, statusCodeExpected = 204) { | ||
172 | const path = '/api/v1/server/blocklist/servers/' + serverToBlock | ||
173 | |||
174 | return makeDeleteRequest({ | ||
175 | url, | ||
176 | path, | ||
177 | token, | ||
178 | statusCodeExpected | ||
179 | }) | ||
180 | } | ||
181 | |||
182 | // --------------------------------------------------------------------------- | ||
183 | |||
184 | export { | ||
185 | getAccountBlocklistByAccount, | ||
186 | addAccountToAccountBlocklist, | ||
187 | removeAccountFromAccountBlocklist, | ||
188 | getServerBlocklistByAccount, | ||
189 | addServerToAccountBlocklist, | ||
190 | removeServerFromAccountBlocklist, | ||
191 | |||
192 | getAccountBlocklistByServer, | ||
193 | addAccountToServerBlocklist, | ||
194 | removeAccountFromServerBlocklist, | ||
195 | getServerBlocklistByServer, | ||
196 | addServerToServerBlocklist, | ||
197 | removeServerFromServerBlocklist | ||
198 | } | ||
diff --git a/server/tests/utils/users/users.ts b/server/tests/utils/users/users.ts index 41d8ce265..d77233d62 100644 --- a/server/tests/utils/users/users.ts +++ b/server/tests/utils/users/users.ts | |||
@@ -112,7 +112,7 @@ function getUsersList (url: string, accessToken: string) { | |||
112 | .expect('Content-Type', /json/) | 112 | .expect('Content-Type', /json/) |
113 | } | 113 | } |
114 | 114 | ||
115 | function getUsersListPaginationAndSort (url: string, accessToken: string, start: number, count: number, sort: string) { | 115 | function getUsersListPaginationAndSort (url: string, accessToken: string, start: number, count: number, sort: string, search?: string) { |
116 | const path = '/api/v1/users' | 116 | const path = '/api/v1/users' |
117 | 117 | ||
118 | return request(url) | 118 | return request(url) |
@@ -120,6 +120,7 @@ function getUsersListPaginationAndSort (url: string, accessToken: string, start: | |||
120 | .query({ start }) | 120 | .query({ start }) |
121 | .query({ count }) | 121 | .query({ count }) |
122 | .query({ sort }) | 122 | .query({ sort }) |
123 | .query({ search }) | ||
123 | .set('Accept', 'application/json') | 124 | .set('Accept', 'application/json') |
124 | .set('Authorization', 'Bearer ' + accessToken) | 125 | .set('Authorization', 'Bearer ' + accessToken) |
125 | .expect(200) | 126 | .expect(200) |
diff --git a/server/tests/utils/videos/video-comments.ts b/server/tests/utils/videos/video-comments.ts index 1b9ee452e..7d4cae364 100644 --- a/server/tests/utils/videos/video-comments.ts +++ b/server/tests/utils/videos/video-comments.ts | |||
@@ -1,7 +1,7 @@ | |||
1 | import * as request from 'supertest' | 1 | import * as request from 'supertest' |
2 | import { makeDeleteRequest } from '../' | 2 | import { makeDeleteRequest } from '../' |
3 | 3 | ||
4 | function getVideoCommentThreads (url: string, videoId: number | string, start: number, count: number, sort?: string) { | 4 | function getVideoCommentThreads (url: string, videoId: number | string, start: number, count: number, sort?: string, token?: string) { |
5 | const path = '/api/v1/videos/' + videoId + '/comment-threads' | 5 | const path = '/api/v1/videos/' + videoId + '/comment-threads' |
6 | 6 | ||
7 | const req = request(url) | 7 | const req = request(url) |
@@ -10,20 +10,24 @@ function getVideoCommentThreads (url: string, videoId: number | string, start: n | |||
10 | .query({ count: count }) | 10 | .query({ count: count }) |
11 | 11 | ||
12 | if (sort) req.query({ sort }) | 12 | if (sort) req.query({ sort }) |
13 | if (token) req.set('Authorization', 'Bearer ' + token) | ||
13 | 14 | ||
14 | return req.set('Accept', 'application/json') | 15 | return req.set('Accept', 'application/json') |
15 | .expect(200) | 16 | .expect(200) |
16 | .expect('Content-Type', /json/) | 17 | .expect('Content-Type', /json/) |
17 | } | 18 | } |
18 | 19 | ||
19 | function getVideoThreadComments (url: string, videoId: number | string, threadId: number) { | 20 | function getVideoThreadComments (url: string, videoId: number | string, threadId: number, token?: string) { |
20 | const path = '/api/v1/videos/' + videoId + '/comment-threads/' + threadId | 21 | const path = '/api/v1/videos/' + videoId + '/comment-threads/' + threadId |
21 | 22 | ||
22 | return request(url) | 23 | const req = request(url) |
23 | .get(path) | 24 | .get(path) |
24 | .set('Accept', 'application/json') | 25 | .set('Accept', 'application/json') |
25 | .expect(200) | 26 | |
26 | .expect('Content-Type', /json/) | 27 | if (token) req.set('Authorization', 'Bearer ' + token) |
28 | |||
29 | return req.expect(200) | ||
30 | .expect('Content-Type', /json/) | ||
27 | } | 31 | } |
28 | 32 | ||
29 | function addVideoCommentThread (url: string, token: string, videoId: number | string, text: string, expectedStatus = 200) { | 33 | function addVideoCommentThread (url: string, token: string, videoId: number | string, text: string, expectedStatus = 200) { |
diff --git a/server/tests/utils/videos/video-history.ts b/server/tests/utils/videos/video-history.ts new file mode 100644 index 000000000..7635478f7 --- /dev/null +++ b/server/tests/utils/videos/video-history.ts | |||
@@ -0,0 +1,14 @@ | |||
1 | import { makePutBodyRequest } from '../requests/requests' | ||
2 | |||
3 | function userWatchVideo (url: string, token: string, videoId: number | string, currentTime: number) { | ||
4 | const path = '/api/v1/videos/' + videoId + '/watching' | ||
5 | const fields = { currentTime } | ||
6 | |||
7 | return makePutBodyRequest({ url, path, token, fields, statusCodeExpected: 204 }) | ||
8 | } | ||
9 | |||
10 | // --------------------------------------------------------------------------- | ||
11 | |||
12 | export { | ||
13 | userWatchVideo | ||
14 | } | ||