diff options
author | Rigel Kent <sendmemail@rigelk.eu> | 2020-12-07 14:32:36 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-12-07 14:32:36 +0100 |
commit | 2d53be0267acc49cda46707b885096193a1f4e9c (patch) | |
tree | 887061a34bc67f40acbb96a6278f9544bf83caeb /shared/extra-utils | |
parent | adc1f09c0dbd997f34028c1c82d1c118dc8ead80 (diff) | |
download | PeerTube-2d53be0267acc49cda46707b885096193a1f4e9c.tar.gz PeerTube-2d53be0267acc49cda46707b885096193a1f4e9c.tar.zst PeerTube-2d53be0267acc49cda46707b885096193a1f4e9c.zip |
replace numbers with typed http status codes (#3409)
Diffstat (limited to 'shared/extra-utils')
35 files changed, 379 insertions, 206 deletions
diff --git a/shared/extra-utils/bulk/bulk.ts b/shared/extra-utils/bulk/bulk.ts index d6798ceb7..b6f437b8b 100644 --- a/shared/extra-utils/bulk/bulk.ts +++ b/shared/extra-utils/bulk/bulk.ts | |||
@@ -1,5 +1,6 @@ | |||
1 | import { BulkRemoveCommentsOfBody } from "@shared/models/bulk/bulk-remove-comments-of-body.model" | 1 | import { BulkRemoveCommentsOfBody } from "@shared/models/bulk/bulk-remove-comments-of-body.model" |
2 | import { makePostBodyRequest } from "../requests/requests" | 2 | import { makePostBodyRequest } from "../requests/requests" |
3 | import { HttpStatusCode } from '../../../shared/core-utils/miscs/http-error-codes' | ||
3 | 4 | ||
4 | function bulkRemoveCommentsOf (options: { | 5 | function bulkRemoveCommentsOf (options: { |
5 | url: string | 6 | url: string |
@@ -15,7 +16,7 @@ function bulkRemoveCommentsOf (options: { | |||
15 | path, | 16 | path, |
16 | token, | 17 | token, |
17 | fields: attributes, | 18 | fields: attributes, |
18 | statusCodeExpected: expectedStatus || 204 | 19 | statusCodeExpected: expectedStatus || HttpStatusCode.NO_CONTENT_204 |
19 | }) | 20 | }) |
20 | } | 21 | } |
21 | 22 | ||
diff --git a/shared/extra-utils/feeds/feeds.ts b/shared/extra-utils/feeds/feeds.ts index 957d4499c..ce0a98c6d 100644 --- a/shared/extra-utils/feeds/feeds.ts +++ b/shared/extra-utils/feeds/feeds.ts | |||
@@ -1,4 +1,5 @@ | |||
1 | import * as request from 'supertest' | 1 | import * as request from 'supertest' |
2 | import { HttpStatusCode } from '../../../shared/core-utils/miscs/http-error-codes' | ||
2 | 3 | ||
3 | type FeedType = 'videos' | 'video-comments' | 'subscriptions' | 4 | type FeedType = 'videos' | 'video-comments' | 'subscriptions' |
4 | 5 | ||
@@ -9,11 +10,11 @@ function getXMLfeed (url: string, feed: FeedType, format?: string) { | |||
9 | .get(path) | 10 | .get(path) |
10 | .query((format) ? { format: format } : {}) | 11 | .query((format) ? { format: format } : {}) |
11 | .set('Accept', 'application/xml') | 12 | .set('Accept', 'application/xml') |
12 | .expect(200) | 13 | .expect(HttpStatusCode.OK_200) |
13 | .expect('Content-Type', /xml/) | 14 | .expect('Content-Type', /xml/) |
14 | } | 15 | } |
15 | 16 | ||
16 | function getJSONfeed (url: string, feed: FeedType, query: any = {}, statusCodeExpected = 200) { | 17 | function getJSONfeed (url: string, feed: FeedType, query: any = {}, statusCodeExpected = HttpStatusCode.OK_200) { |
17 | const path = '/feeds/' + feed + '.json' | 18 | const path = '/feeds/' + feed + '.json' |
18 | 19 | ||
19 | return request(url) | 20 | return request(url) |
diff --git a/shared/extra-utils/logs/logs.ts b/shared/extra-utils/logs/logs.ts index c494c1f1e..8d741276c 100644 --- a/shared/extra-utils/logs/logs.ts +++ b/shared/extra-utils/logs/logs.ts | |||
@@ -1,5 +1,6 @@ | |||
1 | import { makeGetRequest } from '../requests/requests' | 1 | import { makeGetRequest } from '../requests/requests' |
2 | import { LogLevel } from '../../models/server/log-level.type' | 2 | import { LogLevel } from '../../models/server/log-level.type' |
3 | import { HttpStatusCode } from '../../../shared/core-utils/miscs/http-error-codes' | ||
3 | 4 | ||
4 | function getLogs (url: string, accessToken: string, startDate: Date, endDate?: Date, level?: LogLevel) { | 5 | function getLogs (url: string, accessToken: string, startDate: Date, endDate?: Date, level?: LogLevel) { |
5 | const path = '/api/v1/server/logs' | 6 | const path = '/api/v1/server/logs' |
@@ -9,7 +10,7 @@ function getLogs (url: string, accessToken: string, startDate: Date, endDate?: D | |||
9 | path, | 10 | path, |
10 | token: accessToken, | 11 | token: accessToken, |
11 | query: { startDate, endDate, level }, | 12 | query: { startDate, endDate, level }, |
12 | statusCodeExpected: 200 | 13 | statusCodeExpected: HttpStatusCode.OK_200 |
13 | }) | 14 | }) |
14 | } | 15 | } |
15 | 16 | ||
@@ -21,7 +22,7 @@ function getAuditLogs (url: string, accessToken: string, startDate: Date, endDat | |||
21 | path, | 22 | path, |
22 | token: accessToken, | 23 | token: accessToken, |
23 | query: { startDate, endDate }, | 24 | query: { startDate, endDate }, |
24 | statusCodeExpected: 200 | 25 | statusCodeExpected: HttpStatusCode.OK_200 |
25 | }) | 26 | }) |
26 | } | 27 | } |
27 | 28 | ||
diff --git a/shared/extra-utils/miscs/miscs.ts b/shared/extra-utils/miscs/miscs.ts index aea9563cf..764b74bda 100644 --- a/shared/extra-utils/miscs/miscs.ts +++ b/shared/extra-utils/miscs/miscs.ts | |||
@@ -6,6 +6,7 @@ import { ensureDir, pathExists, readFile, stat } from 'fs-extra' | |||
6 | import { basename, dirname, isAbsolute, join, resolve } from 'path' | 6 | import { basename, dirname, isAbsolute, join, resolve } from 'path' |
7 | import * as request from 'supertest' | 7 | import * as request from 'supertest' |
8 | import * as WebTorrent from 'webtorrent' | 8 | import * as WebTorrent from 'webtorrent' |
9 | import { HttpStatusCode } from '../../../shared/core-utils/miscs/http-error-codes' | ||
9 | 10 | ||
10 | const expect = chai.expect | 11 | const expect = chai.expect |
11 | let webtorrent: WebTorrent.Instance | 12 | let webtorrent: WebTorrent.Instance |
@@ -51,7 +52,7 @@ function buildServerDirectory (server: { internalServerNumber: number }, directo | |||
51 | async function testImage (url: string, imageName: string, imagePath: string, extension = '.jpg') { | 52 | async function testImage (url: string, imageName: string, imagePath: string, extension = '.jpg') { |
52 | const res = await request(url) | 53 | const res = await request(url) |
53 | .get(imagePath) | 54 | .get(imagePath) |
54 | .expect(200) | 55 | .expect(HttpStatusCode.OK_200) |
55 | 56 | ||
56 | const body = res.body | 57 | const body = res.body |
57 | 58 | ||
diff --git a/shared/extra-utils/moderation/abuses.ts b/shared/extra-utils/moderation/abuses.ts index 7db75cebb..cb6ca46ef 100644 --- a/shared/extra-utils/moderation/abuses.ts +++ b/shared/extra-utils/moderation/abuses.ts | |||
@@ -1,6 +1,6 @@ | |||
1 | |||
2 | import { AbuseFilter, AbusePredefinedReasonsString, AbuseState, AbuseUpdate, AbuseVideoIs } from '@shared/models' | 1 | import { AbuseFilter, AbusePredefinedReasonsString, AbuseState, AbuseUpdate, AbuseVideoIs } from '@shared/models' |
3 | import { makeDeleteRequest, makeGetRequest, makePostBodyRequest, makePutBodyRequest } from '../requests/requests' | 2 | import { makeDeleteRequest, makeGetRequest, makePostBodyRequest, makePutBodyRequest } from '../requests/requests' |
3 | import { HttpStatusCode } from '../../../shared/core-utils/miscs/http-error-codes' | ||
4 | 4 | ||
5 | function reportAbuse (options: { | 5 | function reportAbuse (options: { |
6 | url: string | 6 | url: string |
@@ -50,7 +50,7 @@ function reportAbuse (options: { | |||
50 | token: options.token, | 50 | token: options.token, |
51 | 51 | ||
52 | fields: body, | 52 | fields: body, |
53 | statusCodeExpected: options.statusCodeExpected || 200 | 53 | statusCodeExpected: options.statusCodeExpected || HttpStatusCode.OK_200 |
54 | }) | 54 | }) |
55 | } | 55 | } |
56 | 56 | ||
@@ -113,7 +113,7 @@ function getAdminAbusesList (options: { | |||
113 | path, | 113 | path, |
114 | token, | 114 | token, |
115 | query, | 115 | query, |
116 | statusCodeExpected: 200 | 116 | statusCodeExpected: HttpStatusCode.OK_200 |
117 | }) | 117 | }) |
118 | } | 118 | } |
119 | 119 | ||
@@ -155,7 +155,7 @@ function getUserAbusesList (options: { | |||
155 | path, | 155 | path, |
156 | token, | 156 | token, |
157 | query, | 157 | query, |
158 | statusCodeExpected: 200 | 158 | statusCodeExpected: HttpStatusCode.OK_200 |
159 | }) | 159 | }) |
160 | } | 160 | } |
161 | 161 | ||
@@ -164,7 +164,7 @@ function updateAbuse ( | |||
164 | token: string, | 164 | token: string, |
165 | abuseId: number, | 165 | abuseId: number, |
166 | body: AbuseUpdate, | 166 | body: AbuseUpdate, |
167 | statusCodeExpected = 204 | 167 | statusCodeExpected = HttpStatusCode.NO_CONTENT_204 |
168 | ) { | 168 | ) { |
169 | const path = '/api/v1/abuses/' + abuseId | 169 | const path = '/api/v1/abuses/' + abuseId |
170 | 170 | ||
@@ -177,7 +177,7 @@ function updateAbuse ( | |||
177 | }) | 177 | }) |
178 | } | 178 | } |
179 | 179 | ||
180 | function deleteAbuse (url: string, token: string, abuseId: number, statusCodeExpected = 204) { | 180 | function deleteAbuse (url: string, token: string, abuseId: number, statusCodeExpected = HttpStatusCode.NO_CONTENT_204) { |
181 | const path = '/api/v1/abuses/' + abuseId | 181 | const path = '/api/v1/abuses/' + abuseId |
182 | 182 | ||
183 | return makeDeleteRequest({ | 183 | return makeDeleteRequest({ |
@@ -188,7 +188,7 @@ function deleteAbuse (url: string, token: string, abuseId: number, statusCodeExp | |||
188 | }) | 188 | }) |
189 | } | 189 | } |
190 | 190 | ||
191 | function listAbuseMessages (url: string, token: string, abuseId: number, statusCodeExpected = 200) { | 191 | function listAbuseMessages (url: string, token: string, abuseId: number, statusCodeExpected = HttpStatusCode.OK_200) { |
192 | const path = '/api/v1/abuses/' + abuseId + '/messages' | 192 | const path = '/api/v1/abuses/' + abuseId + '/messages' |
193 | 193 | ||
194 | return makeGetRequest({ | 194 | return makeGetRequest({ |
@@ -199,7 +199,13 @@ function listAbuseMessages (url: string, token: string, abuseId: number, statusC | |||
199 | }) | 199 | }) |
200 | } | 200 | } |
201 | 201 | ||
202 | function deleteAbuseMessage (url: string, token: string, abuseId: number, messageId: number, statusCodeExpected = 204) { | 202 | function deleteAbuseMessage ( |
203 | url: string, | ||
204 | token: string, | ||
205 | abuseId: number, | ||
206 | messageId: number, | ||
207 | statusCodeExpected = HttpStatusCode.NO_CONTENT_204 | ||
208 | ) { | ||
203 | const path = '/api/v1/abuses/' + abuseId + '/messages/' + messageId | 209 | const path = '/api/v1/abuses/' + abuseId + '/messages/' + messageId |
204 | 210 | ||
205 | return makeDeleteRequest({ | 211 | return makeDeleteRequest({ |
@@ -210,7 +216,7 @@ function deleteAbuseMessage (url: string, token: string, abuseId: number, messag | |||
210 | }) | 216 | }) |
211 | } | 217 | } |
212 | 218 | ||
213 | function addAbuseMessage (url: string, token: string, abuseId: number, message: string, statusCodeExpected = 200) { | 219 | function addAbuseMessage (url: string, token: string, abuseId: number, message: string, statusCodeExpected = HttpStatusCode.OK_200) { |
214 | const path = '/api/v1/abuses/' + abuseId + '/messages' | 220 | const path = '/api/v1/abuses/' + abuseId + '/messages' |
215 | 221 | ||
216 | return makePostBodyRequest({ | 222 | return makePostBodyRequest({ |
diff --git a/shared/extra-utils/overviews/overviews.ts b/shared/extra-utils/overviews/overviews.ts index ae4d31aa3..5e1a13e5e 100644 --- a/shared/extra-utils/overviews/overviews.ts +++ b/shared/extra-utils/overviews/overviews.ts | |||
@@ -1,6 +1,7 @@ | |||
1 | import { makeGetRequest } from '../requests/requests' | 1 | import { makeGetRequest } from '../requests/requests' |
2 | import { HttpStatusCode } from '../../../shared/core-utils/miscs/http-error-codes' | ||
2 | 3 | ||
3 | function getVideosOverview (url: string, page: number, statusCodeExpected = 200) { | 4 | function getVideosOverview (url: string, page: number, statusCodeExpected = HttpStatusCode.OK_200) { |
4 | const path = '/api/v1/overviews/videos' | 5 | const path = '/api/v1/overviews/videos' |
5 | 6 | ||
6 | const query = { page } | 7 | const query = { page } |
@@ -13,7 +14,7 @@ function getVideosOverview (url: string, page: number, statusCodeExpected = 200) | |||
13 | }) | 14 | }) |
14 | } | 15 | } |
15 | 16 | ||
16 | function getVideosOverviewWithToken (url: string, page: number, token: string, statusCodeExpected = 200) { | 17 | function getVideosOverviewWithToken (url: string, page: number, token: string, statusCodeExpected = HttpStatusCode.OK_200) { |
17 | const path = '/api/v1/overviews/videos' | 18 | const path = '/api/v1/overviews/videos' |
18 | 19 | ||
19 | const query = { page } | 20 | const query = { page } |
diff --git a/shared/extra-utils/requests/check-api-params.ts b/shared/extra-utils/requests/check-api-params.ts index c34c7c216..7f5ff775c 100644 --- a/shared/extra-utils/requests/check-api-params.ts +++ b/shared/extra-utils/requests/check-api-params.ts | |||
@@ -1,5 +1,6 @@ | |||
1 | import { makeGetRequest } from './requests' | 1 | import { makeGetRequest } from './requests' |
2 | import { immutableAssign } from '../miscs/miscs' | 2 | import { immutableAssign } from '../miscs/miscs' |
3 | import { HttpStatusCode } from '../../../shared/core-utils/miscs/http-error-codes' | ||
3 | 4 | ||
4 | function checkBadStartPagination (url: string, path: string, token?: string, query = {}) { | 5 | function checkBadStartPagination (url: string, path: string, token?: string, query = {}) { |
5 | return makeGetRequest({ | 6 | return makeGetRequest({ |
@@ -7,7 +8,7 @@ function checkBadStartPagination (url: string, path: string, token?: string, que | |||
7 | path, | 8 | path, |
8 | token, | 9 | token, |
9 | query: immutableAssign(query, { start: 'hello' }), | 10 | query: immutableAssign(query, { start: 'hello' }), |
10 | statusCodeExpected: 400 | 11 | statusCodeExpected: HttpStatusCode.BAD_REQUEST_400 |
11 | }) | 12 | }) |
12 | } | 13 | } |
13 | 14 | ||
@@ -17,7 +18,7 @@ async function checkBadCountPagination (url: string, path: string, token?: strin | |||
17 | path, | 18 | path, |
18 | token, | 19 | token, |
19 | query: immutableAssign(query, { count: 'hello' }), | 20 | query: immutableAssign(query, { count: 'hello' }), |
20 | statusCodeExpected: 400 | 21 | statusCodeExpected: HttpStatusCode.BAD_REQUEST_400 |
21 | }) | 22 | }) |
22 | 23 | ||
23 | await makeGetRequest({ | 24 | await makeGetRequest({ |
@@ -25,7 +26,7 @@ async function checkBadCountPagination (url: string, path: string, token?: strin | |||
25 | path, | 26 | path, |
26 | token, | 27 | token, |
27 | query: immutableAssign(query, { count: 2000 }), | 28 | query: immutableAssign(query, { count: 2000 }), |
28 | statusCodeExpected: 400 | 29 | statusCodeExpected: HttpStatusCode.BAD_REQUEST_400 |
29 | }) | 30 | }) |
30 | } | 31 | } |
31 | 32 | ||
@@ -35,7 +36,7 @@ function checkBadSortPagination (url: string, path: string, token?: string, quer | |||
35 | path, | 36 | path, |
36 | token, | 37 | token, |
37 | query: immutableAssign(query, { sort: 'hello' }), | 38 | query: immutableAssign(query, { sort: 'hello' }), |
38 | statusCodeExpected: 400 | 39 | statusCodeExpected: HttpStatusCode.BAD_REQUEST_400 |
39 | }) | 40 | }) |
40 | } | 41 | } |
41 | 42 | ||
diff --git a/shared/extra-utils/requests/requests.ts b/shared/extra-utils/requests/requests.ts index 6b00871e0..3e773ee03 100644 --- a/shared/extra-utils/requests/requests.ts +++ b/shared/extra-utils/requests/requests.ts | |||
@@ -5,12 +5,13 @@ import { buildAbsoluteFixturePath, root } from '../miscs/miscs' | |||
5 | import { isAbsolute, join } from 'path' | 5 | import { isAbsolute, join } from 'path' |
6 | import { URL } from 'url' | 6 | import { URL } from 'url' |
7 | import { decode } from 'querystring' | 7 | import { decode } from 'querystring' |
8 | import { HttpStatusCode } from '../../../shared/core-utils/miscs/http-error-codes' | ||
8 | 9 | ||
9 | function get4KFileUrl () { | 10 | function get4KFileUrl () { |
10 | return 'https://download.cpy.re/peertube/4k_file.txt' | 11 | return 'https://download.cpy.re/peertube/4k_file.txt' |
11 | } | 12 | } |
12 | 13 | ||
13 | function makeRawRequest (url: string, statusCodeExpected?: number, range?: string) { | 14 | function makeRawRequest (url: string, statusCodeExpected?: HttpStatusCode, range?: string) { |
14 | const { host, protocol, pathname } = new URL(url) | 15 | const { host, protocol, pathname } = new URL(url) |
15 | 16 | ||
16 | return makeGetRequest({ url: `${protocol}//${host}`, path: pathname, statusCodeExpected, range }) | 17 | return makeGetRequest({ url: `${protocol}//${host}`, path: pathname, statusCodeExpected, range }) |
@@ -21,12 +22,12 @@ function makeGetRequest (options: { | |||
21 | path?: string | 22 | path?: string |
22 | query?: any | 23 | query?: any |
23 | token?: string | 24 | token?: string |
24 | statusCodeExpected?: number | 25 | statusCodeExpected?: HttpStatusCode |
25 | contentType?: string | 26 | contentType?: string |
26 | range?: string | 27 | range?: string |
27 | redirects?: number | 28 | redirects?: number |
28 | }) { | 29 | }) { |
29 | if (!options.statusCodeExpected) options.statusCodeExpected = 400 | 30 | if (!options.statusCodeExpected) options.statusCodeExpected = HttpStatusCode.BAD_REQUEST_400 |
30 | if (options.contentType === undefined) options.contentType = 'application/json' | 31 | if (options.contentType === undefined) options.contentType = 'application/json' |
31 | 32 | ||
32 | const req = request(options.url).get(options.path) | 33 | const req = request(options.url).get(options.path) |
@@ -44,9 +45,9 @@ function makeDeleteRequest (options: { | |||
44 | url: string | 45 | url: string |
45 | path: string | 46 | path: string |
46 | token?: string | 47 | token?: string |
47 | statusCodeExpected?: number | 48 | statusCodeExpected?: HttpStatusCode |
48 | }) { | 49 | }) { |
49 | if (!options.statusCodeExpected) options.statusCodeExpected = 400 | 50 | if (!options.statusCodeExpected) options.statusCodeExpected = HttpStatusCode.BAD_REQUEST_400 |
50 | 51 | ||
51 | const req = request(options.url) | 52 | const req = request(options.url) |
52 | .delete(options.path) | 53 | .delete(options.path) |
@@ -64,9 +65,9 @@ function makeUploadRequest (options: { | |||
64 | token?: string | 65 | token?: string |
65 | fields: { [ fieldName: string ]: any } | 66 | fields: { [ fieldName: string ]: any } |
66 | attaches?: { [ attachName: string ]: any | any[] } | 67 | attaches?: { [ attachName: string ]: any | any[] } |
67 | statusCodeExpected?: number | 68 | statusCodeExpected?: HttpStatusCode |
68 | }) { | 69 | }) { |
69 | if (!options.statusCodeExpected) options.statusCodeExpected = 400 | 70 | if (!options.statusCodeExpected) options.statusCodeExpected = HttpStatusCode.BAD_REQUEST_400 |
70 | 71 | ||
71 | let req: request.Test | 72 | let req: request.Test |
72 | if (options.method === 'PUT') { | 73 | if (options.method === 'PUT') { |
@@ -110,10 +111,10 @@ function makePostBodyRequest (options: { | |||
110 | path: string | 111 | path: string |
111 | token?: string | 112 | token?: string |
112 | fields?: { [ fieldName: string ]: any } | 113 | fields?: { [ fieldName: string ]: any } |
113 | statusCodeExpected?: number | 114 | statusCodeExpected?: HttpStatusCode |
114 | }) { | 115 | }) { |
115 | if (!options.fields) options.fields = {} | 116 | if (!options.fields) options.fields = {} |
116 | if (!options.statusCodeExpected) options.statusCodeExpected = 400 | 117 | if (!options.statusCodeExpected) options.statusCodeExpected = HttpStatusCode.BAD_REQUEST_400 |
117 | 118 | ||
118 | const req = request(options.url) | 119 | const req = request(options.url) |
119 | .post(options.path) | 120 | .post(options.path) |
@@ -130,9 +131,9 @@ function makePutBodyRequest (options: { | |||
130 | path: string | 131 | path: string |
131 | token?: string | 132 | token?: string |
132 | fields: { [ fieldName: string ]: any } | 133 | fields: { [ fieldName: string ]: any } |
133 | statusCodeExpected?: number | 134 | statusCodeExpected?: HttpStatusCode |
134 | }) { | 135 | }) { |
135 | if (!options.statusCodeExpected) options.statusCodeExpected = 400 | 136 | if (!options.statusCodeExpected) options.statusCodeExpected = HttpStatusCode.BAD_REQUEST_400 |
136 | 137 | ||
137 | const req = request(options.url) | 138 | const req = request(options.url) |
138 | .put(options.path) | 139 | .put(options.path) |
@@ -148,7 +149,7 @@ function makeHTMLRequest (url: string, path: string) { | |||
148 | return request(url) | 149 | return request(url) |
149 | .get(path) | 150 | .get(path) |
150 | .set('Accept', 'text/html') | 151 | .set('Accept', 'text/html') |
151 | .expect(200) | 152 | .expect(HttpStatusCode.OK_200) |
152 | } | 153 | } |
153 | 154 | ||
154 | function updateAvatarRequest (options: { | 155 | function updateAvatarRequest (options: { |
@@ -170,7 +171,7 @@ function updateAvatarRequest (options: { | |||
170 | token: options.accessToken, | 171 | token: options.accessToken, |
171 | fields: {}, | 172 | fields: {}, |
172 | attaches: { avatarfile: filePath }, | 173 | attaches: { avatarfile: filePath }, |
173 | statusCodeExpected: 200 | 174 | statusCodeExpected: HttpStatusCode.OK_200 |
174 | }) | 175 | }) |
175 | } | 176 | } |
176 | 177 | ||
diff --git a/shared/extra-utils/search/video-channels.ts b/shared/extra-utils/search/video-channels.ts index d16210530..8e0f42578 100644 --- a/shared/extra-utils/search/video-channels.ts +++ b/shared/extra-utils/search/video-channels.ts | |||
@@ -1,7 +1,8 @@ | |||
1 | import { VideoChannelsSearchQuery } from '@shared/models' | 1 | import { VideoChannelsSearchQuery } from '@shared/models' |
2 | import { makeGetRequest } from '../requests/requests' | 2 | import { makeGetRequest } from '../requests/requests' |
3 | import { HttpStatusCode } from '../../../shared/core-utils/miscs/http-error-codes' | ||
3 | 4 | ||
4 | function searchVideoChannel (url: string, search: string, token?: string, statusCodeExpected = 200) { | 5 | function searchVideoChannel (url: string, search: string, token?: string, statusCodeExpected = HttpStatusCode.OK_200) { |
5 | const path = '/api/v1/search/video-channels' | 6 | const path = '/api/v1/search/video-channels' |
6 | 7 | ||
7 | return makeGetRequest({ | 8 | return makeGetRequest({ |
@@ -23,7 +24,7 @@ function advancedVideoChannelSearch (url: string, search: VideoChannelsSearchQue | |||
23 | url, | 24 | url, |
24 | path, | 25 | path, |
25 | query: search, | 26 | query: search, |
26 | statusCodeExpected: 200 | 27 | statusCodeExpected: HttpStatusCode.OK_200 |
27 | }) | 28 | }) |
28 | } | 29 | } |
29 | 30 | ||
diff --git a/shared/extra-utils/search/videos.ts b/shared/extra-utils/search/videos.ts index 4c52ea11c..ac65357e3 100644 --- a/shared/extra-utils/search/videos.ts +++ b/shared/extra-utils/search/videos.ts | |||
@@ -3,6 +3,7 @@ | |||
3 | import * as request from 'supertest' | 3 | import * as request from 'supertest' |
4 | import { VideosSearchQuery } from '../../models/search' | 4 | import { VideosSearchQuery } from '../../models/search' |
5 | import { immutableAssign } from '../miscs/miscs' | 5 | import { immutableAssign } from '../miscs/miscs' |
6 | import { HttpStatusCode } from '../../../shared/core-utils/miscs/http-error-codes' | ||
6 | 7 | ||
7 | function searchVideo (url: string, search: string) { | 8 | function searchVideo (url: string, search: string) { |
8 | const path = '/api/v1/search/videos' | 9 | const path = '/api/v1/search/videos' |
@@ -13,7 +14,7 @@ function searchVideo (url: string, search: string) { | |||
13 | .query(query) | 14 | .query(query) |
14 | .set('Accept', 'application/json') | 15 | .set('Accept', 'application/json') |
15 | 16 | ||
16 | return req.expect(200) | 17 | return req.expect(HttpStatusCode.OK_200) |
17 | .expect('Content-Type', /json/) | 18 | .expect('Content-Type', /json/) |
18 | } | 19 | } |
19 | 20 | ||
@@ -25,7 +26,7 @@ function searchVideoWithToken (url: string, search: string, token: string, query | |||
25 | .query(immutableAssign(query, { sort: '-publishedAt', search })) | 26 | .query(immutableAssign(query, { sort: '-publishedAt', search })) |
26 | .set('Accept', 'application/json') | 27 | .set('Accept', 'application/json') |
27 | 28 | ||
28 | return req.expect(200) | 29 | return req.expect(HttpStatusCode.OK_200) |
29 | .expect('Content-Type', /json/) | 30 | .expect('Content-Type', /json/) |
30 | } | 31 | } |
31 | 32 | ||
@@ -38,7 +39,7 @@ function searchVideoWithSort (url: string, search: string, sort: string) { | |||
38 | .get(path) | 39 | .get(path) |
39 | .query(query) | 40 | .query(query) |
40 | .set('Accept', 'application/json') | 41 | .set('Accept', 'application/json') |
41 | .expect(200) | 42 | .expect(HttpStatusCode.OK_200) |
42 | .expect('Content-Type', /json/) | 43 | .expect('Content-Type', /json/) |
43 | } | 44 | } |
44 | 45 | ||
@@ -49,7 +50,7 @@ function advancedVideosSearch (url: string, options: VideosSearchQuery) { | |||
49 | .get(path) | 50 | .get(path) |
50 | .query(options) | 51 | .query(options) |
51 | .set('Accept', 'application/json') | 52 | .set('Accept', 'application/json') |
52 | .expect(200) | 53 | .expect(HttpStatusCode.OK_200) |
53 | .expect('Content-Type', /json/) | 54 | .expect('Content-Type', /json/) |
54 | } | 55 | } |
55 | 56 | ||
diff --git a/shared/extra-utils/server/clients.ts b/shared/extra-utils/server/clients.ts index dc631e823..894fe4911 100644 --- a/shared/extra-utils/server/clients.ts +++ b/shared/extra-utils/server/clients.ts | |||
@@ -1,5 +1,6 @@ | |||
1 | import * as request from 'supertest' | 1 | import * as request from 'supertest' |
2 | import { URL } from 'url' | 2 | import { URL } from 'url' |
3 | import { HttpStatusCode } from '../../../shared/core-utils/miscs/http-error-codes' | ||
3 | 4 | ||
4 | function getClient (url: string) { | 5 | function getClient (url: string) { |
5 | const path = '/api/v1/oauth-clients/local' | 6 | const path = '/api/v1/oauth-clients/local' |
@@ -8,7 +9,7 @@ function getClient (url: string) { | |||
8 | .get(path) | 9 | .get(path) |
9 | .set('Host', new URL(url).host) | 10 | .set('Host', new URL(url).host) |
10 | .set('Accept', 'application/json') | 11 | .set('Accept', 'application/json') |
11 | .expect(200) | 12 | .expect(HttpStatusCode.OK_200) |
12 | .expect('Content-Type', /json/) | 13 | .expect('Content-Type', /json/) |
13 | } | 14 | } |
14 | 15 | ||
diff --git a/shared/extra-utils/server/config.ts b/shared/extra-utils/server/config.ts index 7c1ad0a75..3b6afe9ff 100644 --- a/shared/extra-utils/server/config.ts +++ b/shared/extra-utils/server/config.ts | |||
@@ -1,6 +1,6 @@ | |||
1 | import { makeDeleteRequest, makeGetRequest, makePutBodyRequest } from '../requests/requests' | 1 | import { makeDeleteRequest, makeGetRequest, makePutBodyRequest } from '../requests/requests' |
2 | import { CustomConfig } from '../../models/server/custom-config.model' | 2 | import { CustomConfig } from '../../models/server/custom-config.model' |
3 | import { DeepPartial } from '@shared/core-utils' | 3 | import { DeepPartial, HttpStatusCode } from '@shared/core-utils' |
4 | import { merge } from 'lodash' | 4 | import { merge } from 'lodash' |
5 | 5 | ||
6 | function getConfig (url: string) { | 6 | function getConfig (url: string) { |
@@ -9,7 +9,7 @@ function getConfig (url: string) { | |||
9 | return makeGetRequest({ | 9 | return makeGetRequest({ |
10 | url, | 10 | url, |
11 | path, | 11 | path, |
12 | statusCodeExpected: 200 | 12 | statusCodeExpected: HttpStatusCode.OK_200 |
13 | }) | 13 | }) |
14 | } | 14 | } |
15 | 15 | ||
@@ -19,11 +19,11 @@ function getAbout (url: string) { | |||
19 | return makeGetRequest({ | 19 | return makeGetRequest({ |
20 | url, | 20 | url, |
21 | path, | 21 | path, |
22 | statusCodeExpected: 200 | 22 | statusCodeExpected: HttpStatusCode.OK_200 |
23 | }) | 23 | }) |
24 | } | 24 | } |
25 | 25 | ||
26 | function getCustomConfig (url: string, token: string, statusCodeExpected = 200) { | 26 | function getCustomConfig (url: string, token: string, statusCodeExpected = HttpStatusCode.OK_200) { |
27 | const path = '/api/v1/config/custom' | 27 | const path = '/api/v1/config/custom' |
28 | 28 | ||
29 | return makeGetRequest({ | 29 | return makeGetRequest({ |
@@ -34,7 +34,7 @@ function getCustomConfig (url: string, token: string, statusCodeExpected = 200) | |||
34 | }) | 34 | }) |
35 | } | 35 | } |
36 | 36 | ||
37 | function updateCustomConfig (url: string, token: string, newCustomConfig: CustomConfig, statusCodeExpected = 200) { | 37 | function updateCustomConfig (url: string, token: string, newCustomConfig: CustomConfig, statusCodeExpected = HttpStatusCode.OK_200) { |
38 | const path = '/api/v1/config/custom' | 38 | const path = '/api/v1/config/custom' |
39 | 39 | ||
40 | return makePutBodyRequest({ | 40 | return makePutBodyRequest({ |
@@ -204,7 +204,7 @@ function updateCustomSubConfig (url: string, token: string, newConfig: DeepParti | |||
204 | return updateCustomConfig(url, token, updateParams) | 204 | return updateCustomConfig(url, token, updateParams) |
205 | } | 205 | } |
206 | 206 | ||
207 | function deleteCustomConfig (url: string, token: string, statusCodeExpected = 200) { | 207 | function deleteCustomConfig (url: string, token: string, statusCodeExpected = HttpStatusCode.OK_200) { |
208 | const path = '/api/v1/config/custom' | 208 | const path = '/api/v1/config/custom' |
209 | 209 | ||
210 | return makeDeleteRequest({ | 210 | return makeDeleteRequest({ |
diff --git a/shared/extra-utils/server/contact-form.ts b/shared/extra-utils/server/contact-form.ts index d50f83241..6c9232cc6 100644 --- a/shared/extra-utils/server/contact-form.ts +++ b/shared/extra-utils/server/contact-form.ts | |||
@@ -1,5 +1,6 @@ | |||
1 | import * as request from 'supertest' | 1 | import * as request from 'supertest' |
2 | import { ContactForm } from '../../models/server' | 2 | import { ContactForm } from '../../models/server' |
3 | import { HttpStatusCode } from '../../../shared/core-utils/miscs/http-error-codes' | ||
3 | 4 | ||
4 | function sendContactForm (options: { | 5 | function sendContactForm (options: { |
5 | url: string | 6 | url: string |
@@ -20,7 +21,7 @@ function sendContactForm (options: { | |||
20 | return request(options.url) | 21 | return request(options.url) |
21 | .post(path) | 22 | .post(path) |
22 | .send(body) | 23 | .send(body) |
23 | .expect(options.expectedStatus || 204) | 24 | .expect(options.expectedStatus || HttpStatusCode.NO_CONTENT_204) |
24 | } | 25 | } |
25 | 26 | ||
26 | // --------------------------------------------------------------------------- | 27 | // --------------------------------------------------------------------------- |
diff --git a/shared/extra-utils/server/follows.ts b/shared/extra-utils/server/follows.ts index 006d59199..6aae4a31d 100644 --- a/shared/extra-utils/server/follows.ts +++ b/shared/extra-utils/server/follows.ts | |||
@@ -3,6 +3,7 @@ import { ServerInfo } from './servers' | |||
3 | import { waitJobs } from './jobs' | 3 | import { waitJobs } from './jobs' |
4 | import { makePostBodyRequest } from '../requests/requests' | 4 | import { makePostBodyRequest } from '../requests/requests' |
5 | import { ActivityPubActorType, FollowState } from '@shared/models' | 5 | import { ActivityPubActorType, FollowState } from '@shared/models' |
6 | import { HttpStatusCode } from '../../../shared/core-utils/miscs/http-error-codes' | ||
6 | 7 | ||
7 | function getFollowersListPaginationAndSort (options: { | 8 | function getFollowersListPaginationAndSort (options: { |
8 | url: string | 9 | url: string |
@@ -29,11 +30,11 @@ function getFollowersListPaginationAndSort (options: { | |||
29 | .get(path) | 30 | .get(path) |
30 | .query(query) | 31 | .query(query) |
31 | .set('Accept', 'application/json') | 32 | .set('Accept', 'application/json') |
32 | .expect(200) | 33 | .expect(HttpStatusCode.OK_200) |
33 | .expect('Content-Type', /json/) | 34 | .expect('Content-Type', /json/) |
34 | } | 35 | } |
35 | 36 | ||
36 | function acceptFollower (url: string, token: string, follower: string, statusCodeExpected = 204) { | 37 | function acceptFollower (url: string, token: string, follower: string, statusCodeExpected = HttpStatusCode.NO_CONTENT_204) { |
37 | const path = '/api/v1/server/followers/' + follower + '/accept' | 38 | const path = '/api/v1/server/followers/' + follower + '/accept' |
38 | 39 | ||
39 | return makePostBodyRequest({ | 40 | return makePostBodyRequest({ |
@@ -44,7 +45,7 @@ function acceptFollower (url: string, token: string, follower: string, statusCod | |||
44 | }) | 45 | }) |
45 | } | 46 | } |
46 | 47 | ||
47 | function rejectFollower (url: string, token: string, follower: string, statusCodeExpected = 204) { | 48 | function rejectFollower (url: string, token: string, follower: string, statusCodeExpected = HttpStatusCode.NO_CONTENT_204) { |
48 | const path = '/api/v1/server/followers/' + follower + '/reject' | 49 | const path = '/api/v1/server/followers/' + follower + '/reject' |
49 | 50 | ||
50 | return makePostBodyRequest({ | 51 | return makePostBodyRequest({ |
@@ -80,11 +81,11 @@ function getFollowingListPaginationAndSort (options: { | |||
80 | .get(path) | 81 | .get(path) |
81 | .query(query) | 82 | .query(query) |
82 | .set('Accept', 'application/json') | 83 | .set('Accept', 'application/json') |
83 | .expect(200) | 84 | .expect(HttpStatusCode.OK_200) |
84 | .expect('Content-Type', /json/) | 85 | .expect('Content-Type', /json/) |
85 | } | 86 | } |
86 | 87 | ||
87 | function follow (follower: string, following: string[], accessToken: string, expectedStatus = 204) { | 88 | function follow (follower: string, following: string[], accessToken: string, expectedStatus = HttpStatusCode.NO_CONTENT_204) { |
88 | const path = '/api/v1/server/following' | 89 | const path = '/api/v1/server/following' |
89 | 90 | ||
90 | const followingHosts = following.map(f => f.replace(/^http:\/\//, '')) | 91 | const followingHosts = following.map(f => f.replace(/^http:\/\//, '')) |
@@ -96,7 +97,7 @@ function follow (follower: string, following: string[], accessToken: string, exp | |||
96 | .expect(expectedStatus) | 97 | .expect(expectedStatus) |
97 | } | 98 | } |
98 | 99 | ||
99 | async function unfollow (url: string, accessToken: string, target: ServerInfo, expectedStatus = 204) { | 100 | async function unfollow (url: string, accessToken: string, target: ServerInfo, expectedStatus = HttpStatusCode.NO_CONTENT_204) { |
100 | const path = '/api/v1/server/following/' + target.host | 101 | const path = '/api/v1/server/following/' + target.host |
101 | 102 | ||
102 | return request(url) | 103 | return request(url) |
@@ -106,7 +107,7 @@ async function unfollow (url: string, accessToken: string, target: ServerInfo, e | |||
106 | .expect(expectedStatus) | 107 | .expect(expectedStatus) |
107 | } | 108 | } |
108 | 109 | ||
109 | function removeFollower (url: string, accessToken: string, follower: ServerInfo, expectedStatus = 204) { | 110 | function removeFollower (url: string, accessToken: string, follower: ServerInfo, expectedStatus = HttpStatusCode.NO_CONTENT_204) { |
110 | const path = '/api/v1/server/followers/peertube@' + follower.host | 111 | const path = '/api/v1/server/followers/peertube@' + follower.host |
111 | 112 | ||
112 | return request(url) | 113 | return request(url) |
diff --git a/shared/extra-utils/server/jobs.ts b/shared/extra-utils/server/jobs.ts index d984b3d1e..cac00e9ab 100644 --- a/shared/extra-utils/server/jobs.ts +++ b/shared/extra-utils/server/jobs.ts | |||
@@ -3,6 +3,7 @@ import { Job, JobState, JobType } from '../../models' | |||
3 | import { wait } from '../miscs/miscs' | 3 | import { wait } from '../miscs/miscs' |
4 | import { ServerInfo } from './servers' | 4 | import { ServerInfo } from './servers' |
5 | import { makeGetRequest } from '../../../shared/extra-utils' | 5 | import { makeGetRequest } from '../../../shared/extra-utils' |
6 | import { HttpStatusCode } from '../../../shared/core-utils/miscs/http-error-codes' | ||
6 | 7 | ||
7 | function getJobsList (url: string, accessToken: string, state: JobState) { | 8 | function getJobsList (url: string, accessToken: string, state: JobState) { |
8 | const path = '/api/v1/jobs/' + state | 9 | const path = '/api/v1/jobs/' + state |
@@ -11,7 +12,7 @@ function getJobsList (url: string, accessToken: string, state: JobState) { | |||
11 | .get(path) | 12 | .get(path) |
12 | .set('Accept', 'application/json') | 13 | .set('Accept', 'application/json') |
13 | .set('Authorization', 'Bearer ' + accessToken) | 14 | .set('Authorization', 'Bearer ' + accessToken) |
14 | .expect(200) | 15 | .expect(HttpStatusCode.OK_200) |
15 | .expect('Content-Type', /json/) | 16 | .expect('Content-Type', /json/) |
16 | } | 17 | } |
17 | 18 | ||
@@ -38,7 +39,7 @@ function getJobsListPaginationAndSort (options: { | |||
38 | url, | 39 | url, |
39 | path, | 40 | path, |
40 | token: accessToken, | 41 | token: accessToken, |
41 | statusCodeExpected: 200, | 42 | statusCodeExpected: HttpStatusCode.OK_200, |
42 | query | 43 | query |
43 | }) | 44 | }) |
44 | } | 45 | } |
diff --git a/shared/extra-utils/server/plugins.ts b/shared/extra-utils/server/plugins.ts index 83db2f6b8..864954ee7 100644 --- a/shared/extra-utils/server/plugins.ts +++ b/shared/extra-utils/server/plugins.ts | |||
@@ -9,6 +9,7 @@ import { PluginType } from '../../models/plugins/plugin.type' | |||
9 | import { buildServerDirectory, root } from '../miscs/miscs' | 9 | import { buildServerDirectory, root } from '../miscs/miscs' |
10 | import { makeGetRequest, makePostBodyRequest, makePutBodyRequest } from '../requests/requests' | 10 | import { makeGetRequest, makePostBodyRequest, makePutBodyRequest } from '../requests/requests' |
11 | import { ServerInfo } from './servers' | 11 | import { ServerInfo } from './servers' |
12 | import { HttpStatusCode } from '../../../shared/core-utils/miscs/http-error-codes' | ||
12 | 13 | ||
13 | function listPlugins (parameters: { | 14 | function listPlugins (parameters: { |
14 | url: string | 15 | url: string |
@@ -18,9 +19,9 @@ function listPlugins (parameters: { | |||
18 | sort?: string | 19 | sort?: string |
19 | pluginType?: PluginType | 20 | pluginType?: PluginType |
20 | uninstalled?: boolean | 21 | uninstalled?: boolean |
21 | expectedStatus?: number | 22 | expectedStatus?: HttpStatusCode |
22 | }) { | 23 | }) { |
23 | const { url, accessToken, start, count, sort, pluginType, uninstalled, expectedStatus = 200 } = parameters | 24 | const { url, accessToken, start, count, sort, pluginType, uninstalled, expectedStatus = HttpStatusCode.OK_200 } = parameters |
24 | const path = '/api/v1/plugins' | 25 | const path = '/api/v1/plugins' |
25 | 26 | ||
26 | return makeGetRequest({ | 27 | return makeGetRequest({ |
@@ -47,9 +48,19 @@ function listAvailablePlugins (parameters: { | |||
47 | pluginType?: PluginType | 48 | pluginType?: PluginType |
48 | currentPeerTubeEngine?: string | 49 | currentPeerTubeEngine?: string |
49 | search?: string | 50 | search?: string |
50 | expectedStatus?: number | 51 | expectedStatus?: HttpStatusCode |
51 | }) { | 52 | }) { |
52 | const { url, accessToken, start, count, sort, pluginType, search, currentPeerTubeEngine, expectedStatus = 200 } = parameters | 53 | const { |
54 | url, | ||
55 | accessToken, | ||
56 | start, | ||
57 | count, | ||
58 | sort, | ||
59 | pluginType, | ||
60 | search, | ||
61 | currentPeerTubeEngine, | ||
62 | expectedStatus = HttpStatusCode.OK_200 | ||
63 | } = parameters | ||
53 | const path = '/api/v1/plugins/available' | 64 | const path = '/api/v1/plugins/available' |
54 | 65 | ||
55 | const query: PeertubePluginIndexList = { | 66 | const query: PeertubePluginIndexList = { |
@@ -74,9 +85,9 @@ function getPlugin (parameters: { | |||
74 | url: string | 85 | url: string |
75 | accessToken: string | 86 | accessToken: string |
76 | npmName: string | 87 | npmName: string |
77 | expectedStatus?: number | 88 | expectedStatus?: HttpStatusCode |
78 | }) { | 89 | }) { |
79 | const { url, accessToken, npmName, expectedStatus = 200 } = parameters | 90 | const { url, accessToken, npmName, expectedStatus = HttpStatusCode.OK_200 } = parameters |
80 | const path = '/api/v1/plugins/' + npmName | 91 | const path = '/api/v1/plugins/' + npmName |
81 | 92 | ||
82 | return makeGetRequest({ | 93 | return makeGetRequest({ |
@@ -92,9 +103,9 @@ function updatePluginSettings (parameters: { | |||
92 | accessToken: string | 103 | accessToken: string |
93 | npmName: string | 104 | npmName: string |
94 | settings: any | 105 | settings: any |
95 | expectedStatus?: number | 106 | expectedStatus?: HttpStatusCode |
96 | }) { | 107 | }) { |
97 | const { url, accessToken, npmName, settings, expectedStatus = 204 } = parameters | 108 | const { url, accessToken, npmName, settings, expectedStatus = HttpStatusCode.NO_CONTENT_204 } = parameters |
98 | const path = '/api/v1/plugins/' + npmName + '/settings' | 109 | const path = '/api/v1/plugins/' + npmName + '/settings' |
99 | 110 | ||
100 | return makePutBodyRequest({ | 111 | return makePutBodyRequest({ |
@@ -110,9 +121,9 @@ function getPluginRegisteredSettings (parameters: { | |||
110 | url: string | 121 | url: string |
111 | accessToken: string | 122 | accessToken: string |
112 | npmName: string | 123 | npmName: string |
113 | expectedStatus?: number | 124 | expectedStatus?: HttpStatusCode |
114 | }) { | 125 | }) { |
115 | const { url, accessToken, npmName, expectedStatus = 200 } = parameters | 126 | const { url, accessToken, npmName, expectedStatus = HttpStatusCode.OK_200 } = parameters |
116 | const path = '/api/v1/plugins/' + npmName + '/registered-settings' | 127 | const path = '/api/v1/plugins/' + npmName + '/registered-settings' |
117 | 128 | ||
118 | return makeGetRequest({ | 129 | return makeGetRequest({ |
@@ -141,9 +152,9 @@ async function testHelloWorldRegisteredSettings (server: ServerInfo) { | |||
141 | function getPublicSettings (parameters: { | 152 | function getPublicSettings (parameters: { |
142 | url: string | 153 | url: string |
143 | npmName: string | 154 | npmName: string |
144 | expectedStatus?: number | 155 | expectedStatus?: HttpStatusCode |
145 | }) { | 156 | }) { |
146 | const { url, npmName, expectedStatus = 200 } = parameters | 157 | const { url, npmName, expectedStatus = HttpStatusCode.OK_200 } = parameters |
147 | const path = '/api/v1/plugins/' + npmName + '/public-settings' | 158 | const path = '/api/v1/plugins/' + npmName + '/public-settings' |
148 | 159 | ||
149 | return makeGetRequest({ | 160 | return makeGetRequest({ |
@@ -156,9 +167,9 @@ function getPublicSettings (parameters: { | |||
156 | function getPluginTranslations (parameters: { | 167 | function getPluginTranslations (parameters: { |
157 | url: string | 168 | url: string |
158 | locale: string | 169 | locale: string |
159 | expectedStatus?: number | 170 | expectedStatus?: HttpStatusCode |
160 | }) { | 171 | }) { |
161 | const { url, locale, expectedStatus = 200 } = parameters | 172 | const { url, locale, expectedStatus = HttpStatusCode.OK_200 } = parameters |
162 | const path = '/plugins/translations/' + locale + '.json' | 173 | const path = '/plugins/translations/' + locale + '.json' |
163 | 174 | ||
164 | return makeGetRequest({ | 175 | return makeGetRequest({ |
@@ -173,9 +184,9 @@ function installPlugin (parameters: { | |||
173 | accessToken: string | 184 | accessToken: string |
174 | path?: string | 185 | path?: string |
175 | npmName?: string | 186 | npmName?: string |
176 | expectedStatus?: number | 187 | expectedStatus?: HttpStatusCode |
177 | }) { | 188 | }) { |
178 | const { url, accessToken, npmName, path, expectedStatus = 200 } = parameters | 189 | const { url, accessToken, npmName, path, expectedStatus = HttpStatusCode.OK_200 } = parameters |
179 | const apiPath = '/api/v1/plugins/install' | 190 | const apiPath = '/api/v1/plugins/install' |
180 | 191 | ||
181 | return makePostBodyRequest({ | 192 | return makePostBodyRequest({ |
@@ -192,9 +203,9 @@ function updatePlugin (parameters: { | |||
192 | accessToken: string | 203 | accessToken: string |
193 | path?: string | 204 | path?: string |
194 | npmName?: string | 205 | npmName?: string |
195 | expectedStatus?: number | 206 | expectedStatus?: HttpStatusCode |
196 | }) { | 207 | }) { |
197 | const { url, accessToken, npmName, path, expectedStatus = 200 } = parameters | 208 | const { url, accessToken, npmName, path, expectedStatus = HttpStatusCode.OK_200 } = parameters |
198 | const apiPath = '/api/v1/plugins/update' | 209 | const apiPath = '/api/v1/plugins/update' |
199 | 210 | ||
200 | return makePostBodyRequest({ | 211 | return makePostBodyRequest({ |
@@ -210,9 +221,9 @@ function uninstallPlugin (parameters: { | |||
210 | url: string | 221 | url: string |
211 | accessToken: string | 222 | accessToken: string |
212 | npmName: string | 223 | npmName: string |
213 | expectedStatus?: number | 224 | expectedStatus?: HttpStatusCode |
214 | }) { | 225 | }) { |
215 | const { url, accessToken, npmName, expectedStatus = 204 } = parameters | 226 | const { url, accessToken, npmName, expectedStatus = HttpStatusCode.NO_CONTENT_204 } = parameters |
216 | const apiPath = '/api/v1/plugins/uninstall' | 227 | const apiPath = '/api/v1/plugins/uninstall' |
217 | 228 | ||
218 | return makePostBodyRequest({ | 229 | return makePostBodyRequest({ |
@@ -230,7 +241,7 @@ function getPluginsCSS (url: string) { | |||
230 | return makeGetRequest({ | 241 | return makeGetRequest({ |
231 | url, | 242 | url, |
232 | path, | 243 | path, |
233 | statusCodeExpected: 200 | 244 | statusCodeExpected: HttpStatusCode.OK_200 |
234 | }) | 245 | }) |
235 | } | 246 | } |
236 | 247 | ||
@@ -260,7 +271,7 @@ function getExternalAuth (options: { | |||
260 | npmVersion: string | 271 | npmVersion: string |
261 | authName: string | 272 | authName: string |
262 | query?: any | 273 | query?: any |
263 | statusCodeExpected?: number | 274 | statusCodeExpected?: HttpStatusCode |
264 | }) { | 275 | }) { |
265 | const { url, npmName, npmVersion, authName, statusCodeExpected, query } = options | 276 | const { url, npmName, npmVersion, authName, statusCodeExpected, query } = options |
266 | 277 | ||
@@ -270,7 +281,7 @@ function getExternalAuth (options: { | |||
270 | url, | 281 | url, |
271 | path, | 282 | path, |
272 | query, | 283 | query, |
273 | statusCodeExpected: statusCodeExpected || 200, | 284 | statusCodeExpected: statusCodeExpected || HttpStatusCode.OK_200, |
274 | redirects: 0 | 285 | redirects: 0 |
275 | }) | 286 | }) |
276 | } | 287 | } |
diff --git a/shared/extra-utils/server/redundancy.ts b/shared/extra-utils/server/redundancy.ts index 08467e4c0..3aca4ebfd 100644 --- a/shared/extra-utils/server/redundancy.ts +++ b/shared/extra-utils/server/redundancy.ts | |||
@@ -1,5 +1,6 @@ | |||
1 | import { makeDeleteRequest, makeGetRequest, makePostBodyRequest, makePutBodyRequest } from '../requests/requests' | 1 | import { makeDeleteRequest, makeGetRequest, makePostBodyRequest, makePutBodyRequest } from '../requests/requests' |
2 | import { VideoRedundanciesTarget } from '@shared/models' | 2 | import { VideoRedundanciesTarget } from '@shared/models' |
3 | import { HttpStatusCode } from '../../../shared/core-utils/miscs/http-error-codes' | ||
3 | 4 | ||
4 | function updateRedundancy (url: string, accessToken: string, host: string, redundancyAllowed: boolean, expectedStatus = 204) { | 5 | function updateRedundancy (url: string, accessToken: string, host: string, redundancyAllowed: boolean, expectedStatus = 204) { |
5 | const path = '/api/v1/server/redundancy/' + host | 6 | const path = '/api/v1/server/redundancy/' + host |
@@ -20,7 +21,7 @@ function listVideoRedundancies (options: { | |||
20 | start?: number | 21 | start?: number |
21 | count?: number | 22 | count?: number |
22 | sort?: string | 23 | sort?: string |
23 | statusCodeExpected?: number | 24 | statusCodeExpected?: HttpStatusCode |
24 | }) { | 25 | }) { |
25 | const path = '/api/v1/server/redundancy/videos' | 26 | const path = '/api/v1/server/redundancy/videos' |
26 | 27 | ||
@@ -36,7 +37,7 @@ function listVideoRedundancies (options: { | |||
36 | sort: sort ?? 'name', | 37 | sort: sort ?? 'name', |
37 | target | 38 | target |
38 | }, | 39 | }, |
39 | statusCodeExpected: statusCodeExpected || 200 | 40 | statusCodeExpected: statusCodeExpected || HttpStatusCode.OK_200 |
40 | }) | 41 | }) |
41 | } | 42 | } |
42 | 43 | ||
@@ -53,7 +54,7 @@ function addVideoRedundancy (options: { | |||
53 | token: accessToken, | 54 | token: accessToken, |
54 | path, | 55 | path, |
55 | fields: { videoId }, | 56 | fields: { videoId }, |
56 | statusCodeExpected: 204 | 57 | statusCodeExpected: HttpStatusCode.NO_CONTENT_204 |
57 | }) | 58 | }) |
58 | } | 59 | } |
59 | 60 | ||
@@ -69,7 +70,7 @@ function removeVideoRedundancy (options: { | |||
69 | url, | 70 | url, |
70 | token: accessToken, | 71 | token: accessToken, |
71 | path, | 72 | path, |
72 | statusCodeExpected: 204 | 73 | statusCodeExpected: HttpStatusCode.NO_CONTENT_204 |
73 | }) | 74 | }) |
74 | } | 75 | } |
75 | 76 | ||
diff --git a/shared/extra-utils/server/stats.ts b/shared/extra-utils/server/stats.ts index 6f079ad18..b9dae24e2 100644 --- a/shared/extra-utils/server/stats.ts +++ b/shared/extra-utils/server/stats.ts | |||
@@ -1,4 +1,5 @@ | |||
1 | import { makeGetRequest } from '../requests/requests' | 1 | import { makeGetRequest } from '../requests/requests' |
2 | import { HttpStatusCode } from '../../../shared/core-utils/miscs/http-error-codes' | ||
2 | 3 | ||
3 | function getStats (url: string, useCache = false) { | 4 | function getStats (url: string, useCache = false) { |
4 | const path = '/api/v1/server/stats' | 5 | const path = '/api/v1/server/stats' |
@@ -11,7 +12,7 @@ function getStats (url: string, useCache = false) { | |||
11 | url, | 12 | url, |
12 | path, | 13 | path, |
13 | query, | 14 | query, |
14 | statusCodeExpected: 200 | 15 | statusCodeExpected: HttpStatusCode.OK_200 |
15 | }) | 16 | }) |
16 | } | 17 | } |
17 | 18 | ||
diff --git a/shared/extra-utils/users/accounts.ts b/shared/extra-utils/users/accounts.ts index f87706f6a..4ea7f1402 100644 --- a/shared/extra-utils/users/accounts.ts +++ b/shared/extra-utils/users/accounts.ts | |||
@@ -8,8 +8,9 @@ import { Account } from '../../models/actors' | |||
8 | import { root } from '../miscs/miscs' | 8 | import { root } from '../miscs/miscs' |
9 | import { makeGetRequest } from '../requests/requests' | 9 | import { makeGetRequest } from '../requests/requests' |
10 | import { VideoRateType } from '../../models/videos' | 10 | import { VideoRateType } from '../../models/videos' |
11 | import { HttpStatusCode } from '../../../shared/core-utils/miscs/http-error-codes' | ||
11 | 12 | ||
12 | function getAccountsList (url: string, sort = '-createdAt', statusCodeExpected = 200) { | 13 | function getAccountsList (url: string, sort = '-createdAt', statusCodeExpected = HttpStatusCode.OK_200) { |
13 | const path = '/api/v1/accounts' | 14 | const path = '/api/v1/accounts' |
14 | 15 | ||
15 | return makeGetRequest({ | 16 | return makeGetRequest({ |
@@ -20,7 +21,7 @@ function getAccountsList (url: string, sort = '-createdAt', statusCodeExpected = | |||
20 | }) | 21 | }) |
21 | } | 22 | } |
22 | 23 | ||
23 | function getAccount (url: string, accountName: string, statusCodeExpected = 200) { | 24 | function getAccount (url: string, accountName: string, statusCodeExpected = HttpStatusCode.OK_200) { |
24 | const path = '/api/v1/accounts/' + accountName | 25 | const path = '/api/v1/accounts/' + accountName |
25 | 26 | ||
26 | return makeGetRequest({ | 27 | return makeGetRequest({ |
@@ -55,7 +56,13 @@ async function checkActorFilesWereRemoved (filename: string, serverNumber: numbe | |||
55 | } | 56 | } |
56 | } | 57 | } |
57 | 58 | ||
58 | function getAccountRatings (url: string, accountName: string, accessToken: string, rating?: VideoRateType, statusCodeExpected = 200) { | 59 | function getAccountRatings ( |
60 | url: string, | ||
61 | accountName: string, | ||
62 | accessToken: string, | ||
63 | rating?: VideoRateType, | ||
64 | statusCodeExpected = HttpStatusCode.OK_200 | ||
65 | ) { | ||
59 | const path = '/api/v1/accounts/' + accountName + '/ratings' | 66 | const path = '/api/v1/accounts/' + accountName + '/ratings' |
60 | 67 | ||
61 | const query = rating ? { rating } : {} | 68 | const query = rating ? { rating } : {} |
diff --git a/shared/extra-utils/users/blocklist.ts b/shared/extra-utils/users/blocklist.ts index 39e720b42..bdf7ee58a 100644 --- a/shared/extra-utils/users/blocklist.ts +++ b/shared/extra-utils/users/blocklist.ts | |||
@@ -1,6 +1,7 @@ | |||
1 | /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */ | 1 | /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */ |
2 | 2 | ||
3 | import { makeGetRequest, makeDeleteRequest, makePostBodyRequest } from '../requests/requests' | 3 | import { makeGetRequest, makeDeleteRequest, makePostBodyRequest } from '../requests/requests' |
4 | import { HttpStatusCode } from '../../../shared/core-utils/miscs/http-error-codes' | ||
4 | 5 | ||
5 | function getAccountBlocklistByAccount ( | 6 | function getAccountBlocklistByAccount ( |
6 | url: string, | 7 | url: string, |
@@ -8,7 +9,7 @@ function getAccountBlocklistByAccount ( | |||
8 | start: number, | 9 | start: number, |
9 | count: number, | 10 | count: number, |
10 | sort = '-createdAt', | 11 | sort = '-createdAt', |
11 | statusCodeExpected = 200 | 12 | statusCodeExpected = HttpStatusCode.OK_200 |
12 | ) { | 13 | ) { |
13 | const path = '/api/v1/users/me/blocklist/accounts' | 14 | const path = '/api/v1/users/me/blocklist/accounts' |
14 | 15 | ||
@@ -21,7 +22,12 @@ function getAccountBlocklistByAccount ( | |||
21 | }) | 22 | }) |
22 | } | 23 | } |
23 | 24 | ||
24 | function addAccountToAccountBlocklist (url: string, token: string, accountToBlock: string, statusCodeExpected = 204) { | 25 | function addAccountToAccountBlocklist ( |
26 | url: string, | ||
27 | token: string, | ||
28 | accountToBlock: string, | ||
29 | statusCodeExpected = HttpStatusCode.NO_CONTENT_204 | ||
30 | ) { | ||
25 | const path = '/api/v1/users/me/blocklist/accounts' | 31 | const path = '/api/v1/users/me/blocklist/accounts' |
26 | 32 | ||
27 | return makePostBodyRequest({ | 33 | return makePostBodyRequest({ |
@@ -35,7 +41,12 @@ function addAccountToAccountBlocklist (url: string, token: string, accountToBloc | |||
35 | }) | 41 | }) |
36 | } | 42 | } |
37 | 43 | ||
38 | function removeAccountFromAccountBlocklist (url: string, token: string, accountToUnblock: string, statusCodeExpected = 204) { | 44 | function removeAccountFromAccountBlocklist ( |
45 | url: string, | ||
46 | token: string, | ||
47 | accountToUnblock: string, | ||
48 | statusCodeExpected = HttpStatusCode.NO_CONTENT_204 | ||
49 | ) { | ||
39 | const path = '/api/v1/users/me/blocklist/accounts/' + accountToUnblock | 50 | const path = '/api/v1/users/me/blocklist/accounts/' + accountToUnblock |
40 | 51 | ||
41 | return makeDeleteRequest({ | 52 | return makeDeleteRequest({ |
@@ -52,7 +63,7 @@ function getServerBlocklistByAccount ( | |||
52 | start: number, | 63 | start: number, |
53 | count: number, | 64 | count: number, |
54 | sort = '-createdAt', | 65 | sort = '-createdAt', |
55 | statusCodeExpected = 200 | 66 | statusCodeExpected = HttpStatusCode.OK_200 |
56 | ) { | 67 | ) { |
57 | const path = '/api/v1/users/me/blocklist/servers' | 68 | const path = '/api/v1/users/me/blocklist/servers' |
58 | 69 | ||
@@ -65,7 +76,12 @@ function getServerBlocklistByAccount ( | |||
65 | }) | 76 | }) |
66 | } | 77 | } |
67 | 78 | ||
68 | function addServerToAccountBlocklist (url: string, token: string, serverToBlock: string, statusCodeExpected = 204) { | 79 | function addServerToAccountBlocklist ( |
80 | url: string, | ||
81 | token: string, | ||
82 | serverToBlock: string, | ||
83 | statusCodeExpected = HttpStatusCode.NO_CONTENT_204 | ||
84 | ) { | ||
69 | const path = '/api/v1/users/me/blocklist/servers' | 85 | const path = '/api/v1/users/me/blocklist/servers' |
70 | 86 | ||
71 | return makePostBodyRequest({ | 87 | return makePostBodyRequest({ |
@@ -79,7 +95,12 @@ function addServerToAccountBlocklist (url: string, token: string, serverToBlock: | |||
79 | }) | 95 | }) |
80 | } | 96 | } |
81 | 97 | ||
82 | function removeServerFromAccountBlocklist (url: string, token: string, serverToBlock: string, statusCodeExpected = 204) { | 98 | function removeServerFromAccountBlocklist ( |
99 | url: string, | ||
100 | token: string, | ||
101 | serverToBlock: string, | ||
102 | statusCodeExpected = HttpStatusCode.NO_CONTENT_204 | ||
103 | ) { | ||
83 | const path = '/api/v1/users/me/blocklist/servers/' + serverToBlock | 104 | const path = '/api/v1/users/me/blocklist/servers/' + serverToBlock |
84 | 105 | ||
85 | return makeDeleteRequest({ | 106 | return makeDeleteRequest({ |
@@ -96,7 +117,7 @@ function getAccountBlocklistByServer ( | |||
96 | start: number, | 117 | start: number, |
97 | count: number, | 118 | count: number, |
98 | sort = '-createdAt', | 119 | sort = '-createdAt', |
99 | statusCodeExpected = 200 | 120 | statusCodeExpected = HttpStatusCode.OK_200 |
100 | ) { | 121 | ) { |
101 | const path = '/api/v1/server/blocklist/accounts' | 122 | const path = '/api/v1/server/blocklist/accounts' |
102 | 123 | ||
@@ -109,7 +130,12 @@ function getAccountBlocklistByServer ( | |||
109 | }) | 130 | }) |
110 | } | 131 | } |
111 | 132 | ||
112 | function addAccountToServerBlocklist (url: string, token: string, accountToBlock: string, statusCodeExpected = 204) { | 133 | function addAccountToServerBlocklist ( |
134 | url: string, | ||
135 | token: string, | ||
136 | accountToBlock: string, | ||
137 | statusCodeExpected = HttpStatusCode.NO_CONTENT_204 | ||
138 | ) { | ||
113 | const path = '/api/v1/server/blocklist/accounts' | 139 | const path = '/api/v1/server/blocklist/accounts' |
114 | 140 | ||
115 | return makePostBodyRequest({ | 141 | return makePostBodyRequest({ |
@@ -123,7 +149,12 @@ function addAccountToServerBlocklist (url: string, token: string, accountToBlock | |||
123 | }) | 149 | }) |
124 | } | 150 | } |
125 | 151 | ||
126 | function removeAccountFromServerBlocklist (url: string, token: string, accountToUnblock: string, statusCodeExpected = 204) { | 152 | function removeAccountFromServerBlocklist ( |
153 | url: string, | ||
154 | token: string, | ||
155 | accountToUnblock: string, | ||
156 | statusCodeExpected = HttpStatusCode.NO_CONTENT_204 | ||
157 | ) { | ||
127 | const path = '/api/v1/server/blocklist/accounts/' + accountToUnblock | 158 | const path = '/api/v1/server/blocklist/accounts/' + accountToUnblock |
128 | 159 | ||
129 | return makeDeleteRequest({ | 160 | return makeDeleteRequest({ |
@@ -140,7 +171,7 @@ function getServerBlocklistByServer ( | |||
140 | start: number, | 171 | start: number, |
141 | count: number, | 172 | count: number, |
142 | sort = '-createdAt', | 173 | sort = '-createdAt', |
143 | statusCodeExpected = 200 | 174 | statusCodeExpected = HttpStatusCode.OK_200 |
144 | ) { | 175 | ) { |
145 | const path = '/api/v1/server/blocklist/servers' | 176 | const path = '/api/v1/server/blocklist/servers' |
146 | 177 | ||
@@ -153,7 +184,12 @@ function getServerBlocklistByServer ( | |||
153 | }) | 184 | }) |
154 | } | 185 | } |
155 | 186 | ||
156 | function addServerToServerBlocklist (url: string, token: string, serverToBlock: string, statusCodeExpected = 204) { | 187 | function addServerToServerBlocklist ( |
188 | url: string, | ||
189 | token: string, | ||
190 | serverToBlock: string, | ||
191 | statusCodeExpected = HttpStatusCode.NO_CONTENT_204 | ||
192 | ) { | ||
157 | const path = '/api/v1/server/blocklist/servers' | 193 | const path = '/api/v1/server/blocklist/servers' |
158 | 194 | ||
159 | return makePostBodyRequest({ | 195 | return makePostBodyRequest({ |
@@ -167,7 +203,12 @@ function addServerToServerBlocklist (url: string, token: string, serverToBlock: | |||
167 | }) | 203 | }) |
168 | } | 204 | } |
169 | 205 | ||
170 | function removeServerFromServerBlocklist (url: string, token: string, serverToBlock: string, statusCodeExpected = 204) { | 206 | function removeServerFromServerBlocklist ( |
207 | url: string, | ||
208 | token: string, | ||
209 | serverToBlock: string, | ||
210 | statusCodeExpected = HttpStatusCode.NO_CONTENT_204 | ||
211 | ) { | ||
171 | const path = '/api/v1/server/blocklist/servers/' + serverToBlock | 212 | const path = '/api/v1/server/blocklist/servers/' + serverToBlock |
172 | 213 | ||
173 | return makeDeleteRequest({ | 214 | return makeDeleteRequest({ |
diff --git a/shared/extra-utils/users/user-notifications.ts b/shared/extra-utils/users/user-notifications.ts index 98d222e1d..467a3d959 100644 --- a/shared/extra-utils/users/user-notifications.ts +++ b/shared/extra-utils/users/user-notifications.ts | |||
@@ -11,8 +11,14 @@ import { flushAndRunMultipleServers, ServerInfo } from '../server/servers' | |||
11 | import { getUserNotificationSocket } from '../socket/socket-io' | 11 | import { getUserNotificationSocket } from '../socket/socket-io' |
12 | import { setAccessTokensToServers, userLogin } from './login' | 12 | import { setAccessTokensToServers, userLogin } from './login' |
13 | import { createUser, getMyUserInformation } from './users' | 13 | import { createUser, getMyUserInformation } from './users' |
14 | import { HttpStatusCode } from '../../../shared/core-utils/miscs/http-error-codes' | ||
14 | 15 | ||
15 | function updateMyNotificationSettings (url: string, token: string, settings: UserNotificationSetting, statusCodeExpected = 204) { | 16 | function updateMyNotificationSettings ( |
17 | url: string, | ||
18 | token: string, | ||
19 | settings: UserNotificationSetting, | ||
20 | statusCodeExpected = HttpStatusCode.NO_CONTENT_204 | ||
21 | ) { | ||
16 | const path = '/api/v1/users/me/notification-settings' | 22 | const path = '/api/v1/users/me/notification-settings' |
17 | 23 | ||
18 | return makePutBodyRequest({ | 24 | return makePutBodyRequest({ |
@@ -31,7 +37,7 @@ async function getUserNotifications ( | |||
31 | count: number, | 37 | count: number, |
32 | unread?: boolean, | 38 | unread?: boolean, |
33 | sort = '-createdAt', | 39 | sort = '-createdAt', |
34 | statusCodeExpected = 200 | 40 | statusCodeExpected = HttpStatusCode.OK_200 |
35 | ) { | 41 | ) { |
36 | const path = '/api/v1/users/me/notifications' | 42 | const path = '/api/v1/users/me/notifications' |
37 | 43 | ||
@@ -49,7 +55,7 @@ async function getUserNotifications ( | |||
49 | }) | 55 | }) |
50 | } | 56 | } |
51 | 57 | ||
52 | function markAsReadNotifications (url: string, token: string, ids: number[], statusCodeExpected = 204) { | 58 | function markAsReadNotifications (url: string, token: string, ids: number[], statusCodeExpected = HttpStatusCode.NO_CONTENT_204) { |
53 | const path = '/api/v1/users/me/notifications/read' | 59 | const path = '/api/v1/users/me/notifications/read' |
54 | 60 | ||
55 | return makePostBodyRequest({ | 61 | return makePostBodyRequest({ |
@@ -61,7 +67,7 @@ function markAsReadNotifications (url: string, token: string, ids: number[], sta | |||
61 | }) | 67 | }) |
62 | } | 68 | } |
63 | 69 | ||
64 | function markAsReadAllNotifications (url: string, token: string, statusCodeExpected = 204) { | 70 | function markAsReadAllNotifications (url: string, token: string, statusCodeExpected = HttpStatusCode.NO_CONTENT_204) { |
65 | const path = '/api/v1/users/me/notifications/read-all' | 71 | const path = '/api/v1/users/me/notifications/read-all' |
66 | 72 | ||
67 | return makePostBodyRequest({ | 73 | return makePostBodyRequest({ |
diff --git a/shared/extra-utils/users/user-subscriptions.ts b/shared/extra-utils/users/user-subscriptions.ts index 6d402c073..edc7a3562 100644 --- a/shared/extra-utils/users/user-subscriptions.ts +++ b/shared/extra-utils/users/user-subscriptions.ts | |||
@@ -1,6 +1,7 @@ | |||
1 | import { makeDeleteRequest, makeGetRequest, makePostBodyRequest } from '../requests/requests' | 1 | import { makeDeleteRequest, makeGetRequest, makePostBodyRequest } from '../requests/requests' |
2 | import { HttpStatusCode } from '../../../shared/core-utils/miscs/http-error-codes' | ||
2 | 3 | ||
3 | function addUserSubscription (url: string, token: string, targetUri: string, statusCodeExpected = 204) { | 4 | function addUserSubscription (url: string, token: string, targetUri: string, statusCodeExpected = HttpStatusCode.NO_CONTENT_204) { |
4 | const path = '/api/v1/users/me/subscriptions' | 5 | const path = '/api/v1/users/me/subscriptions' |
5 | 6 | ||
6 | return makePostBodyRequest({ | 7 | return makePostBodyRequest({ |
@@ -19,7 +20,7 @@ function listUserSubscriptions (parameters: { | |||
19 | search?: string | 20 | search?: string |
20 | statusCodeExpected?: number | 21 | statusCodeExpected?: number |
21 | }) { | 22 | }) { |
22 | const { url, token, sort = '-createdAt', search, statusCodeExpected = 200 } = parameters | 23 | const { url, token, sort = '-createdAt', search, statusCodeExpected = HttpStatusCode.OK_200 } = parameters |
23 | const path = '/api/v1/users/me/subscriptions' | 24 | const path = '/api/v1/users/me/subscriptions' |
24 | 25 | ||
25 | return makeGetRequest({ | 26 | return makeGetRequest({ |
@@ -34,7 +35,7 @@ function listUserSubscriptions (parameters: { | |||
34 | }) | 35 | }) |
35 | } | 36 | } |
36 | 37 | ||
37 | function listUserSubscriptionVideos (url: string, token: string, sort = '-createdAt', statusCodeExpected = 200) { | 38 | function listUserSubscriptionVideos (url: string, token: string, sort = '-createdAt', statusCodeExpected = HttpStatusCode.OK_200) { |
38 | const path = '/api/v1/users/me/subscriptions/videos' | 39 | const path = '/api/v1/users/me/subscriptions/videos' |
39 | 40 | ||
40 | return makeGetRequest({ | 41 | return makeGetRequest({ |
@@ -46,7 +47,7 @@ function listUserSubscriptionVideos (url: string, token: string, sort = '-create | |||
46 | }) | 47 | }) |
47 | } | 48 | } |
48 | 49 | ||
49 | function getUserSubscription (url: string, token: string, uri: string, statusCodeExpected = 200) { | 50 | function getUserSubscription (url: string, token: string, uri: string, statusCodeExpected = HttpStatusCode.OK_200) { |
50 | const path = '/api/v1/users/me/subscriptions/' + uri | 51 | const path = '/api/v1/users/me/subscriptions/' + uri |
51 | 52 | ||
52 | return makeGetRequest({ | 53 | return makeGetRequest({ |
@@ -57,7 +58,7 @@ function getUserSubscription (url: string, token: string, uri: string, statusCod | |||
57 | }) | 58 | }) |
58 | } | 59 | } |
59 | 60 | ||
60 | function removeUserSubscription (url: string, token: string, uri: string, statusCodeExpected = 204) { | 61 | function removeUserSubscription (url: string, token: string, uri: string, statusCodeExpected = HttpStatusCode.NO_CONTENT_204) { |
61 | const path = '/api/v1/users/me/subscriptions/' + uri | 62 | const path = '/api/v1/users/me/subscriptions/' + uri |
62 | 63 | ||
63 | return makeDeleteRequest({ | 64 | return makeDeleteRequest({ |
@@ -68,7 +69,7 @@ function removeUserSubscription (url: string, token: string, uri: string, status | |||
68 | }) | 69 | }) |
69 | } | 70 | } |
70 | 71 | ||
71 | function areSubscriptionsExist (url: string, token: string, uris: string[], statusCodeExpected = 200) { | 72 | function areSubscriptionsExist (url: string, token: string, uris: string[], statusCodeExpected = HttpStatusCode.OK_200) { |
72 | const path = '/api/v1/users/me/subscriptions/exist' | 73 | const path = '/api/v1/users/me/subscriptions/exist' |
73 | 74 | ||
74 | return makeGetRequest({ | 75 | return makeGetRequest({ |
diff --git a/shared/extra-utils/users/users.ts b/shared/extra-utils/users/users.ts index ebb8bc257..c683dcdd1 100644 --- a/shared/extra-utils/users/users.ts +++ b/shared/extra-utils/users/users.ts | |||
@@ -7,6 +7,7 @@ import { UserRole } from '../../models/users/user-role' | |||
7 | import { makeGetRequest, makePostBodyRequest, makePutBodyRequest, updateAvatarRequest } from '../requests/requests' | 7 | import { makeGetRequest, makePostBodyRequest, makePutBodyRequest, updateAvatarRequest } from '../requests/requests' |
8 | import { ServerInfo } from '../server/servers' | 8 | import { ServerInfo } from '../server/servers' |
9 | import { userLogin } from './login' | 9 | import { userLogin } from './login' |
10 | import { HttpStatusCode } from '../../../shared/core-utils/miscs/http-error-codes' | ||
10 | 11 | ||
11 | type CreateUserArgs = { | 12 | type CreateUserArgs = { |
12 | url: string | 13 | url: string |
@@ -29,7 +30,7 @@ function createUser (parameters: CreateUserArgs) { | |||
29 | videoQuota = 1000000, | 30 | videoQuota = 1000000, |
30 | videoQuotaDaily = -1, | 31 | videoQuotaDaily = -1, |
31 | role = UserRole.USER, | 32 | role = UserRole.USER, |
32 | specialStatus = 200 | 33 | specialStatus = HttpStatusCode.OK_200 |
33 | } = parameters | 34 | } = parameters |
34 | 35 | ||
35 | const path = '/api/v1/users' | 36 | const path = '/api/v1/users' |
@@ -58,7 +59,7 @@ async function generateUserAccessToken (server: ServerInfo, username: string) { | |||
58 | return userLogin(server, { username, password }) | 59 | return userLogin(server, { username, password }) |
59 | } | 60 | } |
60 | 61 | ||
61 | function registerUser (url: string, username: string, password: string, specialStatus = 204) { | 62 | function registerUser (url: string, username: string, password: string, specialStatus = HttpStatusCode.NO_CONTENT_204) { |
62 | const path = '/api/v1/users/register' | 63 | const path = '/api/v1/users/register' |
63 | const body = { | 64 | const body = { |
64 | username, | 65 | username, |
@@ -94,11 +95,11 @@ function registerUserWithChannel (options: { | |||
94 | url: options.url, | 95 | url: options.url, |
95 | path, | 96 | path, |
96 | fields: body, | 97 | fields: body, |
97 | statusCodeExpected: 204 | 98 | statusCodeExpected: HttpStatusCode.NO_CONTENT_204 |
98 | }) | 99 | }) |
99 | } | 100 | } |
100 | 101 | ||
101 | function getMyUserInformation (url: string, accessToken: string, specialStatus = 200) { | 102 | function getMyUserInformation (url: string, accessToken: string, specialStatus = HttpStatusCode.OK_200) { |
102 | const path = '/api/v1/users/me' | 103 | const path = '/api/v1/users/me' |
103 | 104 | ||
104 | return request(url) | 105 | return request(url) |
@@ -109,7 +110,7 @@ function getMyUserInformation (url: string, accessToken: string, specialStatus = | |||
109 | .expect('Content-Type', /json/) | 110 | .expect('Content-Type', /json/) |
110 | } | 111 | } |
111 | 112 | ||
112 | function getUserScopedTokens (url: string, token: string, statusCodeExpected = 200) { | 113 | function getUserScopedTokens (url: string, token: string, statusCodeExpected = HttpStatusCode.OK_200) { |
113 | const path = '/api/v1/users/scoped-tokens' | 114 | const path = '/api/v1/users/scoped-tokens' |
114 | 115 | ||
115 | return makeGetRequest({ | 116 | return makeGetRequest({ |
@@ -120,7 +121,7 @@ function getUserScopedTokens (url: string, token: string, statusCodeExpected = 2 | |||
120 | }) | 121 | }) |
121 | } | 122 | } |
122 | 123 | ||
123 | function renewUserScopedTokens (url: string, token: string, statusCodeExpected = 200) { | 124 | function renewUserScopedTokens (url: string, token: string, statusCodeExpected = HttpStatusCode.OK_200) { |
124 | const path = '/api/v1/users/scoped-tokens' | 125 | const path = '/api/v1/users/scoped-tokens' |
125 | 126 | ||
126 | return makePostBodyRequest({ | 127 | return makePostBodyRequest({ |
@@ -131,7 +132,7 @@ function renewUserScopedTokens (url: string, token: string, statusCodeExpected = | |||
131 | }) | 132 | }) |
132 | } | 133 | } |
133 | 134 | ||
134 | function deleteMe (url: string, accessToken: string, specialStatus = 204) { | 135 | function deleteMe (url: string, accessToken: string, specialStatus = HttpStatusCode.NO_CONTENT_204) { |
135 | const path = '/api/v1/users/me' | 136 | const path = '/api/v1/users/me' |
136 | 137 | ||
137 | return request(url) | 138 | return request(url) |
@@ -141,7 +142,7 @@ function deleteMe (url: string, accessToken: string, specialStatus = 204) { | |||
141 | .expect(specialStatus) | 142 | .expect(specialStatus) |
142 | } | 143 | } |
143 | 144 | ||
144 | function getMyUserVideoQuotaUsed (url: string, accessToken: string, specialStatus = 200) { | 145 | function getMyUserVideoQuotaUsed (url: string, accessToken: string, specialStatus = HttpStatusCode.OK_200) { |
145 | const path = '/api/v1/users/me/video-quota-used' | 146 | const path = '/api/v1/users/me/video-quota-used' |
146 | 147 | ||
147 | return request(url) | 148 | return request(url) |
@@ -160,11 +161,11 @@ function getUserInformation (url: string, accessToken: string, userId: number, w | |||
160 | .query({ withStats }) | 161 | .query({ withStats }) |
161 | .set('Accept', 'application/json') | 162 | .set('Accept', 'application/json') |
162 | .set('Authorization', 'Bearer ' + accessToken) | 163 | .set('Authorization', 'Bearer ' + accessToken) |
163 | .expect(200) | 164 | .expect(HttpStatusCode.OK_200) |
164 | .expect('Content-Type', /json/) | 165 | .expect('Content-Type', /json/) |
165 | } | 166 | } |
166 | 167 | ||
167 | function getMyUserVideoRating (url: string, accessToken: string, videoId: number | string, specialStatus = 200) { | 168 | function getMyUserVideoRating (url: string, accessToken: string, videoId: number | string, specialStatus = HttpStatusCode.OK_200) { |
168 | const path = '/api/v1/users/me/videos/' + videoId + '/rating' | 169 | const path = '/api/v1/users/me/videos/' + videoId + '/rating' |
169 | 170 | ||
170 | return request(url) | 171 | return request(url) |
@@ -182,7 +183,7 @@ function getUsersList (url: string, accessToken: string) { | |||
182 | .get(path) | 183 | .get(path) |
183 | .set('Accept', 'application/json') | 184 | .set('Accept', 'application/json') |
184 | .set('Authorization', 'Bearer ' + accessToken) | 185 | .set('Authorization', 'Bearer ' + accessToken) |
185 | .expect(200) | 186 | .expect(HttpStatusCode.OK_200) |
186 | .expect('Content-Type', /json/) | 187 | .expect('Content-Type', /json/) |
187 | } | 188 | } |
188 | 189 | ||
@@ -210,11 +211,11 @@ function getUsersListPaginationAndSort ( | |||
210 | .query(query) | 211 | .query(query) |
211 | .set('Accept', 'application/json') | 212 | .set('Accept', 'application/json') |
212 | .set('Authorization', 'Bearer ' + accessToken) | 213 | .set('Authorization', 'Bearer ' + accessToken) |
213 | .expect(200) | 214 | .expect(HttpStatusCode.OK_200) |
214 | .expect('Content-Type', /json/) | 215 | .expect('Content-Type', /json/) |
215 | } | 216 | } |
216 | 217 | ||
217 | function removeUser (url: string, userId: number | string, accessToken: string, expectedStatus = 204) { | 218 | function removeUser (url: string, userId: number | string, accessToken: string, expectedStatus = HttpStatusCode.NO_CONTENT_204) { |
218 | const path = '/api/v1/users' | 219 | const path = '/api/v1/users' |
219 | 220 | ||
220 | return request(url) | 221 | return request(url) |
@@ -224,7 +225,13 @@ function removeUser (url: string, userId: number | string, accessToken: string, | |||
224 | .expect(expectedStatus) | 225 | .expect(expectedStatus) |
225 | } | 226 | } |
226 | 227 | ||
227 | function blockUser (url: string, userId: number | string, accessToken: string, expectedStatus = 204, reason?: string) { | 228 | function blockUser ( |
229 | url: string, | ||
230 | userId: number | string, | ||
231 | accessToken: string, | ||
232 | expectedStatus = HttpStatusCode.NO_CONTENT_204, | ||
233 | reason?: string | ||
234 | ) { | ||
228 | const path = '/api/v1/users' | 235 | const path = '/api/v1/users' |
229 | let body: any | 236 | let body: any |
230 | if (reason) body = { reason } | 237 | if (reason) body = { reason } |
@@ -237,7 +244,7 @@ function blockUser (url: string, userId: number | string, accessToken: string, e | |||
237 | .expect(expectedStatus) | 244 | .expect(expectedStatus) |
238 | } | 245 | } |
239 | 246 | ||
240 | function unblockUser (url: string, userId: number | string, accessToken: string, expectedStatus = 204) { | 247 | function unblockUser (url: string, userId: number | string, accessToken: string, expectedStatus = HttpStatusCode.NO_CONTENT_204) { |
241 | const path = '/api/v1/users' | 248 | const path = '/api/v1/users' |
242 | 249 | ||
243 | return request(url) | 250 | return request(url) |
@@ -247,7 +254,7 @@ function unblockUser (url: string, userId: number | string, accessToken: string, | |||
247 | .expect(expectedStatus) | 254 | .expect(expectedStatus) |
248 | } | 255 | } |
249 | 256 | ||
250 | function updateMyUser (options: { url: string, accessToken: string, statusCodeExpected?: number } & UserUpdateMe) { | 257 | function updateMyUser (options: { url: string, accessToken: string, statusCodeExpected?: HttpStatusCode } & UserUpdateMe) { |
251 | const path = '/api/v1/users/me' | 258 | const path = '/api/v1/users/me' |
252 | 259 | ||
253 | const toSend: UserUpdateMe = omit(options, 'url', 'accessToken') | 260 | const toSend: UserUpdateMe = omit(options, 'url', 'accessToken') |
@@ -257,7 +264,7 @@ function updateMyUser (options: { url: string, accessToken: string, statusCodeEx | |||
257 | path, | 264 | path, |
258 | token: options.accessToken, | 265 | token: options.accessToken, |
259 | fields: toSend, | 266 | fields: toSend, |
260 | statusCodeExpected: options.statusCodeExpected || 204 | 267 | statusCodeExpected: options.statusCodeExpected || HttpStatusCode.NO_CONTENT_204 |
261 | }) | 268 | }) |
262 | } | 269 | } |
263 | 270 | ||
@@ -299,7 +306,7 @@ function updateUser (options: { | |||
299 | path, | 306 | path, |
300 | token: options.accessToken, | 307 | token: options.accessToken, |
301 | fields: toSend, | 308 | fields: toSend, |
302 | statusCodeExpected: 204 | 309 | statusCodeExpected: HttpStatusCode.NO_CONTENT_204 |
303 | }) | 310 | }) |
304 | } | 311 | } |
305 | 312 | ||
@@ -310,11 +317,17 @@ function askResetPassword (url: string, email: string) { | |||
310 | url, | 317 | url, |
311 | path, | 318 | path, |
312 | fields: { email }, | 319 | fields: { email }, |
313 | statusCodeExpected: 204 | 320 | statusCodeExpected: HttpStatusCode.NO_CONTENT_204 |
314 | }) | 321 | }) |
315 | } | 322 | } |
316 | 323 | ||
317 | function resetPassword (url: string, userId: number, verificationString: string, password: string, statusCodeExpected = 204) { | 324 | function resetPassword ( |
325 | url: string, | ||
326 | userId: number, | ||
327 | verificationString: string, | ||
328 | password: string, | ||
329 | statusCodeExpected = HttpStatusCode.NO_CONTENT_204 | ||
330 | ) { | ||
318 | const path = '/api/v1/users/' + userId + '/reset-password' | 331 | const path = '/api/v1/users/' + userId + '/reset-password' |
319 | 332 | ||
320 | return makePostBodyRequest({ | 333 | return makePostBodyRequest({ |
@@ -332,11 +345,17 @@ function askSendVerifyEmail (url: string, email: string) { | |||
332 | url, | 345 | url, |
333 | path, | 346 | path, |
334 | fields: { email }, | 347 | fields: { email }, |
335 | statusCodeExpected: 204 | 348 | statusCodeExpected: HttpStatusCode.NO_CONTENT_204 |
336 | }) | 349 | }) |
337 | } | 350 | } |
338 | 351 | ||
339 | function verifyEmail (url: string, userId: number, verificationString: string, isPendingEmail = false, statusCodeExpected = 204) { | 352 | function verifyEmail ( |
353 | url: string, | ||
354 | userId: number, | ||
355 | verificationString: string, | ||
356 | isPendingEmail = false, | ||
357 | statusCodeExpected = HttpStatusCode.NO_CONTENT_204 | ||
358 | ) { | ||
340 | const path = '/api/v1/users/' + userId + '/verify-email' | 359 | const path = '/api/v1/users/' + userId + '/verify-email' |
341 | 360 | ||
342 | return makePostBodyRequest({ | 361 | return makePostBodyRequest({ |
diff --git a/shared/extra-utils/videos/live.ts b/shared/extra-utils/videos/live.ts index 522beb8bc..4aa66622b 100644 --- a/shared/extra-utils/videos/live.ts +++ b/shared/extra-utils/videos/live.ts | |||
@@ -10,8 +10,9 @@ import { buildAbsoluteFixturePath, buildServerDirectory, wait } from '../miscs/m | |||
10 | import { makeGetRequest, makePutBodyRequest, makeUploadRequest } from '../requests/requests' | 10 | import { makeGetRequest, makePutBodyRequest, makeUploadRequest } from '../requests/requests' |
11 | import { ServerInfo } from '../server/servers' | 11 | import { ServerInfo } from '../server/servers' |
12 | import { getVideoWithToken } from './videos' | 12 | import { getVideoWithToken } from './videos' |
13 | import { HttpStatusCode } from '../../../shared/core-utils/miscs/http-error-codes' | ||
13 | 14 | ||
14 | function getLive (url: string, token: string, videoId: number | string, statusCodeExpected = 200) { | 15 | function getLive (url: string, token: string, videoId: number | string, statusCodeExpected = HttpStatusCode.OK_200) { |
15 | const path = '/api/v1/videos/live' | 16 | const path = '/api/v1/videos/live' |
16 | 17 | ||
17 | return makeGetRequest({ | 18 | return makeGetRequest({ |
@@ -22,7 +23,13 @@ function getLive (url: string, token: string, videoId: number | string, statusCo | |||
22 | }) | 23 | }) |
23 | } | 24 | } |
24 | 25 | ||
25 | function updateLive (url: string, token: string, videoId: number | string, fields: LiveVideoUpdate, statusCodeExpected = 204) { | 26 | function updateLive ( |
27 | url: string, | ||
28 | token: string, | ||
29 | videoId: number | string, | ||
30 | fields: LiveVideoUpdate, | ||
31 | statusCodeExpected = HttpStatusCode.NO_CONTENT_204 | ||
32 | ) { | ||
26 | const path = '/api/v1/videos/live' | 33 | const path = '/api/v1/videos/live' |
27 | 34 | ||
28 | return makePutBodyRequest({ | 35 | return makePutBodyRequest({ |
@@ -34,7 +41,7 @@ function updateLive (url: string, token: string, videoId: number | string, field | |||
34 | }) | 41 | }) |
35 | } | 42 | } |
36 | 43 | ||
37 | function createLive (url: string, token: string, fields: LiveVideoCreate, statusCodeExpected = 200) { | 44 | function createLive (url: string, token: string, fields: LiveVideoCreate, statusCodeExpected = HttpStatusCode.OK_200) { |
38 | const path = '/api/v1/videos/live' | 45 | const path = '/api/v1/videos/live' |
39 | 46 | ||
40 | const attaches: any = {} | 47 | const attaches: any = {} |
diff --git a/shared/extra-utils/videos/services.ts b/shared/extra-utils/videos/services.ts index 1a53dd4cf..e13a788bd 100644 --- a/shared/extra-utils/videos/services.ts +++ b/shared/extra-utils/videos/services.ts | |||
@@ -1,4 +1,5 @@ | |||
1 | import * as request from 'supertest' | 1 | import * as request from 'supertest' |
2 | import { HttpStatusCode } from '../../../shared/core-utils/miscs/http-error-codes' | ||
2 | 3 | ||
3 | function getOEmbed (url: string, oembedUrl: string, format?: string, maxHeight?: number, maxWidth?: number) { | 4 | function getOEmbed (url: string, oembedUrl: string, format?: string, maxHeight?: number, maxWidth?: number) { |
4 | const path = '/services/oembed' | 5 | const path = '/services/oembed' |
@@ -13,7 +14,7 @@ function getOEmbed (url: string, oembedUrl: string, format?: string, maxHeight?: | |||
13 | .get(path) | 14 | .get(path) |
14 | .query(query) | 15 | .query(query) |
15 | .set('Accept', 'application/json') | 16 | .set('Accept', 'application/json') |
16 | .expect(200) | 17 | .expect(HttpStatusCode.OK_200) |
17 | } | 18 | } |
18 | 19 | ||
19 | // --------------------------------------------------------------------------- | 20 | // --------------------------------------------------------------------------- |
diff --git a/shared/extra-utils/videos/video-blacklist.ts b/shared/extra-utils/videos/video-blacklist.ts index ba139ef95..aa1548537 100644 --- a/shared/extra-utils/videos/video-blacklist.ts +++ b/shared/extra-utils/videos/video-blacklist.ts | |||
@@ -1,6 +1,7 @@ | |||
1 | import * as request from 'supertest' | 1 | import * as request from 'supertest' |
2 | import { VideoBlacklistType } from '../../models/videos' | 2 | import { VideoBlacklistType } from '../../models/videos' |
3 | import { makeGetRequest } from '..' | 3 | import { makeGetRequest } from '..' |
4 | import { HttpStatusCode } from '../../../shared/core-utils/miscs/http-error-codes' | ||
4 | 5 | ||
5 | function addVideoToBlacklist ( | 6 | function addVideoToBlacklist ( |
6 | url: string, | 7 | url: string, |
@@ -8,7 +9,7 @@ function addVideoToBlacklist ( | |||
8 | videoId: number | string, | 9 | videoId: number | string, |
9 | reason?: string, | 10 | reason?: string, |
10 | unfederate?: boolean, | 11 | unfederate?: boolean, |
11 | specialStatus = 204 | 12 | specialStatus = HttpStatusCode.NO_CONTENT_204 |
12 | ) { | 13 | ) { |
13 | const path = '/api/v1/videos/' + videoId + '/blacklist' | 14 | const path = '/api/v1/videos/' + videoId + '/blacklist' |
14 | 15 | ||
@@ -20,7 +21,13 @@ function addVideoToBlacklist ( | |||
20 | .expect(specialStatus) | 21 | .expect(specialStatus) |
21 | } | 22 | } |
22 | 23 | ||
23 | function updateVideoBlacklist (url: string, token: string, videoId: number, reason?: string, specialStatus = 204) { | 24 | function updateVideoBlacklist ( |
25 | url: string, | ||
26 | token: string, | ||
27 | videoId: number, | ||
28 | reason?: string, | ||
29 | specialStatus = HttpStatusCode.NO_CONTENT_204 | ||
30 | ) { | ||
24 | const path = '/api/v1/videos/' + videoId + '/blacklist' | 31 | const path = '/api/v1/videos/' + videoId + '/blacklist' |
25 | 32 | ||
26 | return request(url) | 33 | return request(url) |
@@ -31,7 +38,7 @@ function updateVideoBlacklist (url: string, token: string, videoId: number, reas | |||
31 | .expect(specialStatus) | 38 | .expect(specialStatus) |
32 | } | 39 | } |
33 | 40 | ||
34 | function removeVideoFromBlacklist (url: string, token: string, videoId: number | string, specialStatus = 204) { | 41 | function removeVideoFromBlacklist (url: string, token: string, videoId: number | string, specialStatus = HttpStatusCode.NO_CONTENT_204) { |
35 | const path = '/api/v1/videos/' + videoId + '/blacklist' | 42 | const path = '/api/v1/videos/' + videoId + '/blacklist' |
36 | 43 | ||
37 | return request(url) | 44 | return request(url) |
@@ -46,9 +53,9 @@ function getBlacklistedVideosList (parameters: { | |||
46 | token: string | 53 | token: string |
47 | sort?: string | 54 | sort?: string |
48 | type?: VideoBlacklistType | 55 | type?: VideoBlacklistType |
49 | specialStatus?: number | 56 | specialStatus?: HttpStatusCode |
50 | }) { | 57 | }) { |
51 | const { url, token, sort, type, specialStatus = 200 } = parameters | 58 | const { url, token, sort, type, specialStatus = HttpStatusCode.OK_200 } = parameters |
52 | const path = '/api/v1/videos/blacklist/' | 59 | const path = '/api/v1/videos/blacklist/' |
53 | 60 | ||
54 | const query = { sort, type } | 61 | const query = { sort, type } |
diff --git a/shared/extra-utils/videos/video-captions.ts b/shared/extra-utils/videos/video-captions.ts index 5bd533bba..62eec7b90 100644 --- a/shared/extra-utils/videos/video-captions.ts +++ b/shared/extra-utils/videos/video-captions.ts | |||
@@ -2,6 +2,7 @@ import { makeDeleteRequest, makeGetRequest, makeUploadRequest } from '../request | |||
2 | import * as request from 'supertest' | 2 | import * as request from 'supertest' |
3 | import * as chai from 'chai' | 3 | import * as chai from 'chai' |
4 | import { buildAbsoluteFixturePath } from '../miscs/miscs' | 4 | import { buildAbsoluteFixturePath } from '../miscs/miscs' |
5 | import { HttpStatusCode } from '../../../shared/core-utils/miscs/http-error-codes' | ||
5 | 6 | ||
6 | const expect = chai.expect | 7 | const expect = chai.expect |
7 | 8 | ||
@@ -28,7 +29,7 @@ function createVideoCaption (args: { | |||
28 | attaches: { | 29 | attaches: { |
29 | captionfile: captionfileAttach | 30 | captionfile: captionfileAttach |
30 | }, | 31 | }, |
31 | statusCodeExpected: args.statusCodeExpected || 204 | 32 | statusCodeExpected: args.statusCodeExpected || HttpStatusCode.NO_CONTENT_204 |
32 | }) | 33 | }) |
33 | } | 34 | } |
34 | 35 | ||
@@ -38,7 +39,7 @@ function listVideoCaptions (url: string, videoId: string | number) { | |||
38 | return makeGetRequest({ | 39 | return makeGetRequest({ |
39 | url, | 40 | url, |
40 | path, | 41 | path, |
41 | statusCodeExpected: 200 | 42 | statusCodeExpected: HttpStatusCode.OK_200 |
42 | }) | 43 | }) |
43 | } | 44 | } |
44 | 45 | ||
@@ -49,14 +50,14 @@ function deleteVideoCaption (url: string, token: string, videoId: string | numbe | |||
49 | url, | 50 | url, |
50 | token, | 51 | token, |
51 | path, | 52 | path, |
52 | statusCodeExpected: 204 | 53 | statusCodeExpected: HttpStatusCode.NO_CONTENT_204 |
53 | }) | 54 | }) |
54 | } | 55 | } |
55 | 56 | ||
56 | async function testCaptionFile (url: string, captionPath: string, containsString: string) { | 57 | async function testCaptionFile (url: string, captionPath: string, containsString: string) { |
57 | const res = await request(url) | 58 | const res = await request(url) |
58 | .get(captionPath) | 59 | .get(captionPath) |
59 | .expect(200) | 60 | .expect(HttpStatusCode.OK_200) |
60 | 61 | ||
61 | expect(res.text).to.contain(containsString) | 62 | expect(res.text).to.contain(containsString) |
62 | } | 63 | } |
diff --git a/shared/extra-utils/videos/video-change-ownership.ts b/shared/extra-utils/videos/video-change-ownership.ts index 371d02000..ef82a7636 100644 --- a/shared/extra-utils/videos/video-change-ownership.ts +++ b/shared/extra-utils/videos/video-change-ownership.ts | |||
@@ -1,6 +1,13 @@ | |||
1 | import * as request from 'supertest' | 1 | import * as request from 'supertest' |
2 | import { HttpStatusCode } from '../../../shared/core-utils/miscs/http-error-codes' | ||
2 | 3 | ||
3 | function changeVideoOwnership (url: string, token: string, videoId: number | string, username, expectedStatus = 204) { | 4 | function changeVideoOwnership ( |
5 | url: string, | ||
6 | token: string, | ||
7 | videoId: number | string, | ||
8 | username, | ||
9 | expectedStatus = HttpStatusCode.NO_CONTENT_204 | ||
10 | ) { | ||
4 | const path = '/api/v1/videos/' + videoId + '/give-ownership' | 11 | const path = '/api/v1/videos/' + videoId + '/give-ownership' |
5 | 12 | ||
6 | return request(url) | 13 | return request(url) |
@@ -19,11 +26,17 @@ function getVideoChangeOwnershipList (url: string, token: string) { | |||
19 | .query({ sort: '-createdAt' }) | 26 | .query({ sort: '-createdAt' }) |
20 | .set('Accept', 'application/json') | 27 | .set('Accept', 'application/json') |
21 | .set('Authorization', 'Bearer ' + token) | 28 | .set('Authorization', 'Bearer ' + token) |
22 | .expect(200) | 29 | .expect(HttpStatusCode.OK_200) |
23 | .expect('Content-Type', /json/) | 30 | .expect('Content-Type', /json/) |
24 | } | 31 | } |
25 | 32 | ||
26 | function acceptChangeOwnership (url: string, token: string, ownershipId: string, channelId: number, expectedStatus = 204) { | 33 | function acceptChangeOwnership ( |
34 | url: string, | ||
35 | token: string, | ||
36 | ownershipId: string, | ||
37 | channelId: number, | ||
38 | expectedStatus = HttpStatusCode.NO_CONTENT_204 | ||
39 | ) { | ||
27 | const path = '/api/v1/videos/ownership/' + ownershipId + '/accept' | 40 | const path = '/api/v1/videos/ownership/' + ownershipId + '/accept' |
28 | 41 | ||
29 | return request(url) | 42 | return request(url) |
@@ -34,7 +47,12 @@ function acceptChangeOwnership (url: string, token: string, ownershipId: string, | |||
34 | .expect(expectedStatus) | 47 | .expect(expectedStatus) |
35 | } | 48 | } |
36 | 49 | ||
37 | function refuseChangeOwnership (url: string, token: string, ownershipId: string, expectedStatus = 204) { | 50 | function refuseChangeOwnership ( |
51 | url: string, | ||
52 | token: string, | ||
53 | ownershipId: string, | ||
54 | expectedStatus = HttpStatusCode.NO_CONTENT_204 | ||
55 | ) { | ||
38 | const path = '/api/v1/videos/ownership/' + ownershipId + '/refuse' | 56 | const path = '/api/v1/videos/ownership/' + ownershipId + '/refuse' |
39 | 57 | ||
40 | return request(url) | 58 | return request(url) |
diff --git a/shared/extra-utils/videos/video-channels.ts b/shared/extra-utils/videos/video-channels.ts index 97b68178f..3ff445c2a 100644 --- a/shared/extra-utils/videos/video-channels.ts +++ b/shared/extra-utils/videos/video-channels.ts | |||
@@ -7,6 +7,7 @@ import { makeGetRequest, updateAvatarRequest } from '../requests/requests' | |||
7 | import { ServerInfo } from '../server/servers' | 7 | import { ServerInfo } from '../server/servers' |
8 | import { User } from '../../models/users/user.model' | 8 | import { User } from '../../models/users/user.model' |
9 | import { getMyUserInformation } from '../users/users' | 9 | import { getMyUserInformation } from '../users/users' |
10 | import { HttpStatusCode } from '../../../shared/core-utils/miscs/http-error-codes' | ||
10 | 11 | ||
11 | function getVideoChannelsList (url: string, start: number, count: number, sort?: string, withStats?: boolean) { | 12 | function getVideoChannelsList (url: string, start: number, count: number, sort?: string, withStats?: boolean) { |
12 | const path = '/api/v1/video-channels' | 13 | const path = '/api/v1/video-channels' |
@@ -20,7 +21,7 @@ function getVideoChannelsList (url: string, start: number, count: number, sort?: | |||
20 | if (withStats) req.query({ withStats }) | 21 | if (withStats) req.query({ withStats }) |
21 | 22 | ||
22 | return req.set('Accept', 'application/json') | 23 | return req.set('Accept', 'application/json') |
23 | .expect(200) | 24 | .expect(HttpStatusCode.OK_200) |
24 | .expect('Content-Type', /json/) | 25 | .expect('Content-Type', /json/) |
25 | } | 26 | } |
26 | 27 | ||
@@ -30,11 +31,20 @@ function getAccountVideoChannelsList (parameters: { | |||
30 | start?: number | 31 | start?: number |
31 | count?: number | 32 | count?: number |
32 | sort?: string | 33 | sort?: string |
33 | specialStatus?: number | 34 | specialStatus?: HttpStatusCode |
34 | withStats?: boolean | 35 | withStats?: boolean |
35 | search?: string | 36 | search?: string |
36 | }) { | 37 | }) { |
37 | const { url, accountName, start, count, sort = 'createdAt', specialStatus = 200, withStats = false, search } = parameters | 38 | const { |
39 | url, | ||
40 | accountName, | ||
41 | start, | ||
42 | count, | ||
43 | sort = 'createdAt', | ||
44 | specialStatus = HttpStatusCode.OK_200, | ||
45 | withStats = false, | ||
46 | search | ||
47 | } = parameters | ||
38 | 48 | ||
39 | const path = '/api/v1/accounts/' + accountName + '/video-channels' | 49 | const path = '/api/v1/accounts/' + accountName + '/video-channels' |
40 | 50 | ||
@@ -56,7 +66,7 @@ function addVideoChannel ( | |||
56 | url: string, | 66 | url: string, |
57 | token: string, | 67 | token: string, |
58 | videoChannelAttributesArg: VideoChannelCreate, | 68 | videoChannelAttributesArg: VideoChannelCreate, |
59 | expectedStatus = 200 | 69 | expectedStatus = HttpStatusCode.OK_200 |
60 | ) { | 70 | ) { |
61 | const path = '/api/v1/video-channels/' | 71 | const path = '/api/v1/video-channels/' |
62 | 72 | ||
@@ -81,7 +91,7 @@ function updateVideoChannel ( | |||
81 | token: string, | 91 | token: string, |
82 | channelName: string, | 92 | channelName: string, |
83 | attributes: VideoChannelUpdate, | 93 | attributes: VideoChannelUpdate, |
84 | expectedStatus = 204 | 94 | expectedStatus = HttpStatusCode.NO_CONTENT_204 |
85 | ) { | 95 | ) { |
86 | const body: any = {} | 96 | const body: any = {} |
87 | const path = '/api/v1/video-channels/' + channelName | 97 | const path = '/api/v1/video-channels/' + channelName |
@@ -99,7 +109,7 @@ function updateVideoChannel ( | |||
99 | .expect(expectedStatus) | 109 | .expect(expectedStatus) |
100 | } | 110 | } |
101 | 111 | ||
102 | function deleteVideoChannel (url: string, token: string, channelName: string, expectedStatus = 204) { | 112 | function deleteVideoChannel (url: string, token: string, channelName: string, expectedStatus = HttpStatusCode.NO_CONTENT_204) { |
103 | const path = '/api/v1/video-channels/' + channelName | 113 | const path = '/api/v1/video-channels/' + channelName |
104 | 114 | ||
105 | return request(url) | 115 | return request(url) |
@@ -115,7 +125,7 @@ function getVideoChannel (url: string, channelName: string) { | |||
115 | return request(url) | 125 | return request(url) |
116 | .get(path) | 126 | .get(path) |
117 | .set('Accept', 'application/json') | 127 | .set('Accept', 'application/json') |
118 | .expect(200) | 128 | .expect(HttpStatusCode.OK_200) |
119 | .expect('Content-Type', /json/) | 129 | .expect('Content-Type', /json/) |
120 | } | 130 | } |
121 | 131 | ||
diff --git a/shared/extra-utils/videos/video-comments.ts b/shared/extra-utils/videos/video-comments.ts index 0b0df81dc..71b9f875a 100644 --- a/shared/extra-utils/videos/video-comments.ts +++ b/shared/extra-utils/videos/video-comments.ts | |||
@@ -2,6 +2,7 @@ | |||
2 | 2 | ||
3 | import * as request from 'supertest' | 3 | import * as request from 'supertest' |
4 | import { makeDeleteRequest, makeGetRequest } from '../requests/requests' | 4 | import { makeDeleteRequest, makeGetRequest } from '../requests/requests' |
5 | import { HttpStatusCode } from '../../../shared/core-utils/miscs/http-error-codes' | ||
5 | 6 | ||
6 | function getAdminVideoComments (options: { | 7 | function getAdminVideoComments (options: { |
7 | url: string | 8 | url: string |
@@ -33,7 +34,7 @@ function getAdminVideoComments (options: { | |||
33 | path, | 34 | path, |
34 | token, | 35 | token, |
35 | query, | 36 | query, |
36 | statusCodeExpected: 200 | 37 | statusCodeExpected: HttpStatusCode.OK_200 |
37 | }) | 38 | }) |
38 | } | 39 | } |
39 | 40 | ||
@@ -49,7 +50,7 @@ function getVideoCommentThreads (url: string, videoId: number | string, start: n | |||
49 | if (token) req.set('Authorization', 'Bearer ' + token) | 50 | if (token) req.set('Authorization', 'Bearer ' + token) |
50 | 51 | ||
51 | return req.set('Accept', 'application/json') | 52 | return req.set('Accept', 'application/json') |
52 | .expect(200) | 53 | .expect(HttpStatusCode.OK_200) |
53 | .expect('Content-Type', /json/) | 54 | .expect('Content-Type', /json/) |
54 | } | 55 | } |
55 | 56 | ||
@@ -62,11 +63,17 @@ function getVideoThreadComments (url: string, videoId: number | string, threadId | |||
62 | 63 | ||
63 | if (token) req.set('Authorization', 'Bearer ' + token) | 64 | if (token) req.set('Authorization', 'Bearer ' + token) |
64 | 65 | ||
65 | return req.expect(200) | 66 | return req.expect(HttpStatusCode.OK_200) |
66 | .expect('Content-Type', /json/) | 67 | .expect('Content-Type', /json/) |
67 | } | 68 | } |
68 | 69 | ||
69 | function addVideoCommentThread (url: string, token: string, videoId: number | string, text: string, expectedStatus = 200) { | 70 | function addVideoCommentThread ( |
71 | url: string, | ||
72 | token: string, | ||
73 | videoId: number | string, | ||
74 | text: string, | ||
75 | expectedStatus = HttpStatusCode.OK_200 | ||
76 | ) { | ||
70 | const path = '/api/v1/videos/' + videoId + '/comment-threads' | 77 | const path = '/api/v1/videos/' + videoId + '/comment-threads' |
71 | 78 | ||
72 | return request(url) | 79 | return request(url) |
@@ -83,7 +90,7 @@ function addVideoCommentReply ( | |||
83 | videoId: number | string, | 90 | videoId: number | string, |
84 | inReplyToCommentId: number, | 91 | inReplyToCommentId: number, |
85 | text: string, | 92 | text: string, |
86 | expectedStatus = 200 | 93 | expectedStatus = HttpStatusCode.OK_200 |
87 | ) { | 94 | ) { |
88 | const path = '/api/v1/videos/' + videoId + '/comments/' + inReplyToCommentId | 95 | const path = '/api/v1/videos/' + videoId + '/comments/' + inReplyToCommentId |
89 | 96 | ||
@@ -106,7 +113,7 @@ function deleteVideoComment ( | |||
106 | token: string, | 113 | token: string, |
107 | videoId: number | string, | 114 | videoId: number | string, |
108 | commentId: number, | 115 | commentId: number, |
109 | statusCodeExpected = 204 | 116 | statusCodeExpected = HttpStatusCode.NO_CONTENT_204 |
110 | ) { | 117 | ) { |
111 | const path = '/api/v1/videos/' + videoId + '/comments/' + commentId | 118 | const path = '/api/v1/videos/' + videoId + '/comments/' + commentId |
112 | 119 | ||
diff --git a/shared/extra-utils/videos/video-history.ts b/shared/extra-utils/videos/video-history.ts index dc7095b4d..2d751cf14 100644 --- a/shared/extra-utils/videos/video-history.ts +++ b/shared/extra-utils/videos/video-history.ts | |||
@@ -1,4 +1,5 @@ | |||
1 | import { makeGetRequest, makePostBodyRequest, makePutBodyRequest } from '../requests/requests' | 1 | import { makeGetRequest, makePostBodyRequest, makePutBodyRequest } from '../requests/requests' |
2 | import { HttpStatusCode } from '../../../shared/core-utils/miscs/http-error-codes' | ||
2 | 3 | ||
3 | function userWatchVideo (url: string, token: string, videoId: number | string, currentTime: number, statusCodeExpected = 204) { | 4 | function userWatchVideo (url: string, token: string, videoId: number | string, currentTime: number, statusCodeExpected = 204) { |
4 | const path = '/api/v1/videos/' + videoId + '/watching' | 5 | const path = '/api/v1/videos/' + videoId + '/watching' |
@@ -14,7 +15,7 @@ function listMyVideosHistory (url: string, token: string) { | |||
14 | url, | 15 | url, |
15 | path, | 16 | path, |
16 | token, | 17 | token, |
17 | statusCodeExpected: 200 | 18 | statusCodeExpected: HttpStatusCode.OK_200 |
18 | }) | 19 | }) |
19 | } | 20 | } |
20 | 21 | ||
@@ -26,7 +27,7 @@ function removeMyVideosHistory (url: string, token: string, beforeDate?: string) | |||
26 | path, | 27 | path, |
27 | token, | 28 | token, |
28 | fields: beforeDate ? { beforeDate } : {}, | 29 | fields: beforeDate ? { beforeDate } : {}, |
29 | statusCodeExpected: 204 | 30 | statusCodeExpected: HttpStatusCode.NO_CONTENT_204 |
30 | }) | 31 | }) |
31 | } | 32 | } |
32 | 33 | ||
diff --git a/shared/extra-utils/videos/video-imports.ts b/shared/extra-utils/videos/video-imports.ts index 6249e8a94..52e0075fb 100644 --- a/shared/extra-utils/videos/video-imports.ts +++ b/shared/extra-utils/videos/video-imports.ts | |||
@@ -1,6 +1,7 @@ | |||
1 | 1 | ||
2 | import { VideoImportCreate } from '../../models/videos' | 2 | import { VideoImportCreate } from '../../models/videos' |
3 | import { makeGetRequest, makeUploadRequest } from '../requests/requests' | 3 | import { makeGetRequest, makeUploadRequest } from '../requests/requests' |
4 | import { HttpStatusCode } from '../../../shared/core-utils/miscs/http-error-codes' | ||
4 | 5 | ||
5 | function getYoutubeVideoUrl () { | 6 | function getYoutubeVideoUrl () { |
6 | return 'http://www.youtube.com/watch?v=msX3jv1XdvM' | 7 | return 'http://www.youtube.com/watch?v=msX3jv1XdvM' |
@@ -19,7 +20,12 @@ function getGoodVideoUrl () { | |||
19 | return 'https://download.cpy.re/peertube/good_video.mp4' | 20 | return 'https://download.cpy.re/peertube/good_video.mp4' |
20 | } | 21 | } |
21 | 22 | ||
22 | function importVideo (url: string, token: string, attributes: VideoImportCreate & { torrentfile?: string }, statusCodeExpected = 200) { | 23 | function importVideo ( |
24 | url: string, | ||
25 | token: string, | ||
26 | attributes: VideoImportCreate & { torrentfile?: string }, | ||
27 | statusCodeExpected = HttpStatusCode.OK_200 | ||
28 | ) { | ||
23 | const path = '/api/v1/videos/imports' | 29 | const path = '/api/v1/videos/imports' |
24 | 30 | ||
25 | let attaches: any = {} | 31 | let attaches: any = {} |
@@ -46,7 +52,7 @@ function getMyVideoImports (url: string, token: string, sort?: string) { | |||
46 | query, | 52 | query, |
47 | path, | 53 | path, |
48 | token, | 54 | token, |
49 | statusCodeExpected: 200 | 55 | statusCodeExpected: HttpStatusCode.OK_200 |
50 | }) | 56 | }) |
51 | } | 57 | } |
52 | 58 | ||
diff --git a/shared/extra-utils/videos/video-playlists.ts b/shared/extra-utils/videos/video-playlists.ts index 5bcc02570..c6f799e5d 100644 --- a/shared/extra-utils/videos/video-playlists.ts +++ b/shared/extra-utils/videos/video-playlists.ts | |||
@@ -10,6 +10,7 @@ import { root } from '..' | |||
10 | import { readdir } from 'fs-extra' | 10 | import { readdir } from 'fs-extra' |
11 | import { expect } from 'chai' | 11 | import { expect } from 'chai' |
12 | import { VideoPlaylistType } from '../../models/videos/playlist/video-playlist-type.model' | 12 | import { VideoPlaylistType } from '../../models/videos/playlist/video-playlist-type.model' |
13 | import { HttpStatusCode } from '../../../shared/core-utils/miscs/http-error-codes' | ||
13 | 14 | ||
14 | function getVideoPlaylistsList (url: string, start: number, count: number, sort?: string) { | 15 | function getVideoPlaylistsList (url: string, start: number, count: number, sort?: string) { |
15 | const path = '/api/v1/video-playlists' | 16 | const path = '/api/v1/video-playlists' |
@@ -24,7 +25,7 @@ function getVideoPlaylistsList (url: string, start: number, count: number, sort? | |||
24 | url, | 25 | url, |
25 | path, | 26 | path, |
26 | query, | 27 | query, |
27 | statusCodeExpected: 200 | 28 | statusCodeExpected: HttpStatusCode.OK_200 |
28 | }) | 29 | }) |
29 | } | 30 | } |
30 | 31 | ||
@@ -41,7 +42,7 @@ function getVideoChannelPlaylistsList (url: string, videoChannelName: string, st | |||
41 | url, | 42 | url, |
42 | path, | 43 | path, |
43 | query, | 44 | query, |
44 | statusCodeExpected: 200 | 45 | statusCodeExpected: HttpStatusCode.OK_200 |
45 | }) | 46 | }) |
46 | } | 47 | } |
47 | 48 | ||
@@ -59,7 +60,7 @@ function getAccountPlaylistsList (url: string, accountName: string, start: numbe | |||
59 | url, | 60 | url, |
60 | path, | 61 | path, |
61 | query, | 62 | query, |
62 | statusCodeExpected: 200 | 63 | statusCodeExpected: HttpStatusCode.OK_200 |
63 | }) | 64 | }) |
64 | } | 65 | } |
65 | 66 | ||
@@ -86,11 +87,11 @@ function getAccountPlaylistsListWithToken ( | |||
86 | token, | 87 | token, |
87 | path, | 88 | path, |
88 | query, | 89 | query, |
89 | statusCodeExpected: 200 | 90 | statusCodeExpected: HttpStatusCode.OK_200 |
90 | }) | 91 | }) |
91 | } | 92 | } |
92 | 93 | ||
93 | function getVideoPlaylist (url: string, playlistId: number | string, statusCodeExpected = 200) { | 94 | function getVideoPlaylist (url: string, playlistId: number | string, statusCodeExpected = HttpStatusCode.OK_200) { |
94 | const path = '/api/v1/video-playlists/' + playlistId | 95 | const path = '/api/v1/video-playlists/' + playlistId |
95 | 96 | ||
96 | return makeGetRequest({ | 97 | return makeGetRequest({ |
@@ -100,7 +101,7 @@ function getVideoPlaylist (url: string, playlistId: number | string, statusCodeE | |||
100 | }) | 101 | }) |
101 | } | 102 | } |
102 | 103 | ||
103 | function getVideoPlaylistWithToken (url: string, token: string, playlistId: number | string, statusCodeExpected = 200) { | 104 | function getVideoPlaylistWithToken (url: string, token: string, playlistId: number | string, statusCodeExpected = HttpStatusCode.OK_200) { |
104 | const path = '/api/v1/video-playlists/' + playlistId | 105 | const path = '/api/v1/video-playlists/' + playlistId |
105 | 106 | ||
106 | return makeGetRequest({ | 107 | return makeGetRequest({ |
@@ -111,7 +112,7 @@ function getVideoPlaylistWithToken (url: string, token: string, playlistId: numb | |||
111 | }) | 112 | }) |
112 | } | 113 | } |
113 | 114 | ||
114 | function deleteVideoPlaylist (url: string, token: string, playlistId: number | string, statusCodeExpected = 204) { | 115 | function deleteVideoPlaylist (url: string, token: string, playlistId: number | string, statusCodeExpected = HttpStatusCode.NO_CONTENT_204) { |
115 | const path = '/api/v1/video-playlists/' + playlistId | 116 | const path = '/api/v1/video-playlists/' + playlistId |
116 | 117 | ||
117 | return makeDeleteRequest({ | 118 | return makeDeleteRequest({ |
@@ -143,7 +144,7 @@ function createVideoPlaylist (options: { | |||
143 | token: options.token, | 144 | token: options.token, |
144 | fields, | 145 | fields, |
145 | attaches, | 146 | attaches, |
146 | statusCodeExpected: options.expectedStatus || 200 | 147 | statusCodeExpected: options.expectedStatus || HttpStatusCode.OK_200 |
147 | }) | 148 | }) |
148 | } | 149 | } |
149 | 150 | ||
@@ -169,7 +170,7 @@ function updateVideoPlaylist (options: { | |||
169 | token: options.token, | 170 | token: options.token, |
170 | fields, | 171 | fields, |
171 | attaches, | 172 | attaches, |
172 | statusCodeExpected: options.expectedStatus || 204 | 173 | statusCodeExpected: options.expectedStatus || HttpStatusCode.NO_CONTENT_204 |
173 | }) | 174 | }) |
174 | } | 175 | } |
175 | 176 | ||
@@ -189,7 +190,7 @@ async function addVideoInPlaylist (options: { | |||
189 | path, | 190 | path, |
190 | token: options.token, | 191 | token: options.token, |
191 | fields: options.elementAttrs, | 192 | fields: options.elementAttrs, |
192 | statusCodeExpected: options.expectedStatus || 200 | 193 | statusCodeExpected: options.expectedStatus || HttpStatusCode.OK_200 |
193 | }) | 194 | }) |
194 | } | 195 | } |
195 | 196 | ||
@@ -208,7 +209,7 @@ function updateVideoPlaylistElement (options: { | |||
208 | path, | 209 | path, |
209 | token: options.token, | 210 | token: options.token, |
210 | fields: options.elementAttrs, | 211 | fields: options.elementAttrs, |
211 | statusCodeExpected: options.expectedStatus || 204 | 212 | statusCodeExpected: options.expectedStatus || HttpStatusCode.NO_CONTENT_204 |
212 | }) | 213 | }) |
213 | } | 214 | } |
214 | 215 | ||
@@ -225,7 +226,7 @@ function removeVideoFromPlaylist (options: { | |||
225 | url: options.url, | 226 | url: options.url, |
226 | path, | 227 | path, |
227 | token: options.token, | 228 | token: options.token, |
228 | statusCodeExpected: options.expectedStatus || 204 | 229 | statusCodeExpected: options.expectedStatus || HttpStatusCode.NO_CONTENT_204 |
229 | }) | 230 | }) |
230 | } | 231 | } |
231 | 232 | ||
@@ -247,7 +248,7 @@ function reorderVideosPlaylist (options: { | |||
247 | path, | 248 | path, |
248 | token: options.token, | 249 | token: options.token, |
249 | fields: options.elementAttrs, | 250 | fields: options.elementAttrs, |
250 | statusCodeExpected: options.expectedStatus || 204 | 251 | statusCodeExpected: options.expectedStatus || HttpStatusCode.NO_CONTENT_204 |
251 | }) | 252 | }) |
252 | } | 253 | } |
253 | 254 | ||
@@ -274,7 +275,7 @@ function getVideoPlaylistPrivacies (url: string) { | |||
274 | return makeGetRequest({ | 275 | return makeGetRequest({ |
275 | url, | 276 | url, |
276 | path, | 277 | path, |
277 | statusCodeExpected: 200 | 278 | statusCodeExpected: HttpStatusCode.OK_200 |
278 | }) | 279 | }) |
279 | } | 280 | } |
280 | 281 | ||
@@ -286,7 +287,7 @@ function doVideosExistInMyPlaylist (url: string, token: string, videoIds: number | |||
286 | token, | 287 | token, |
287 | path, | 288 | path, |
288 | query: { videoIds }, | 289 | query: { videoIds }, |
289 | statusCodeExpected: 200 | 290 | statusCodeExpected: HttpStatusCode.OK_200 |
290 | }) | 291 | }) |
291 | } | 292 | } |
292 | 293 | ||
diff --git a/shared/extra-utils/videos/video-streaming-playlists.ts b/shared/extra-utils/videos/video-streaming-playlists.ts index b386e77c3..99c2e1880 100644 --- a/shared/extra-utils/videos/video-streaming-playlists.ts +++ b/shared/extra-utils/videos/video-streaming-playlists.ts | |||
@@ -2,16 +2,17 @@ import { makeRawRequest } from '../requests/requests' | |||
2 | import { sha256 } from '../../../server/helpers/core-utils' | 2 | import { sha256 } from '../../../server/helpers/core-utils' |
3 | import { VideoStreamingPlaylist } from '../../models/videos/video-streaming-playlist.model' | 3 | import { VideoStreamingPlaylist } from '../../models/videos/video-streaming-playlist.model' |
4 | import { expect } from 'chai' | 4 | import { expect } from 'chai' |
5 | import { HttpStatusCode } from '../../../shared/core-utils/miscs/http-error-codes' | ||
5 | 6 | ||
6 | function getPlaylist (url: string, statusCodeExpected = 200) { | 7 | function getPlaylist (url: string, statusCodeExpected = HttpStatusCode.OK_200) { |
7 | return makeRawRequest(url, statusCodeExpected) | 8 | return makeRawRequest(url, statusCodeExpected) |
8 | } | 9 | } |
9 | 10 | ||
10 | function getSegment (url: string, statusCodeExpected = 200, range?: string) { | 11 | function getSegment (url: string, statusCodeExpected = HttpStatusCode.OK_200, range?: string) { |
11 | return makeRawRequest(url, statusCodeExpected, range) | 12 | return makeRawRequest(url, statusCodeExpected, range) |
12 | } | 13 | } |
13 | 14 | ||
14 | function getSegmentSha256 (url: string, statusCodeExpected = 200) { | 15 | function getSegmentSha256 (url: string, statusCodeExpected = HttpStatusCode.OK_200) { |
15 | return makeRawRequest(url, statusCodeExpected) | 16 | return makeRawRequest(url, statusCodeExpected) |
16 | } | 17 | } |
17 | 18 | ||
@@ -33,7 +34,7 @@ async function checkSegmentHash ( | |||
33 | const offset = parseInt(matches[2], 10) | 34 | const offset = parseInt(matches[2], 10) |
34 | const range = `${offset}-${offset + length - 1}` | 35 | const range = `${offset}-${offset + length - 1}` |
35 | 36 | ||
36 | const res2 = await getSegment(`${baseUrlSegment}/${videoUUID}/${videoName}`, 206, `bytes=${range}`) | 37 | const res2 = await getSegment(`${baseUrlSegment}/${videoUUID}/${videoName}`, HttpStatusCode.PARTIAL_CONTENT_206, `bytes=${range}`) |
37 | 38 | ||
38 | const resSha = await getSegmentSha256(hlsPlaylist.segmentsSha256Url) | 39 | const resSha = await getSegmentSha256(hlsPlaylist.segmentsSha256Url) |
39 | 40 | ||
diff --git a/shared/extra-utils/videos/videos.ts b/shared/extra-utils/videos/videos.ts index 2b8c55acb..a4b9d688e 100644 --- a/shared/extra-utils/videos/videos.ts +++ b/shared/extra-utils/videos/videos.ts | |||
@@ -1,5 +1,6 @@ | |||
1 | /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/no-floating-promises */ | 1 | /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/no-floating-promises */ |
2 | 2 | ||
3 | import { HttpStatusCode } from '@shared/core-utils' | ||
3 | import { expect } from 'chai' | 4 | import { expect } from 'chai' |
4 | import { pathExists, readdir, readFile } from 'fs-extra' | 5 | import { pathExists, readdir, readFile } from 'fs-extra' |
5 | import * as parseTorrent from 'parse-torrent' | 6 | import * as parseTorrent from 'parse-torrent' |
@@ -46,7 +47,7 @@ function getVideoCategories (url: string) { | |||
46 | return makeGetRequest({ | 47 | return makeGetRequest({ |
47 | url, | 48 | url, |
48 | path, | 49 | path, |
49 | statusCodeExpected: 200 | 50 | statusCodeExpected: HttpStatusCode.OK_200 |
50 | }) | 51 | }) |
51 | } | 52 | } |
52 | 53 | ||
@@ -56,7 +57,7 @@ function getVideoLicences (url: string) { | |||
56 | return makeGetRequest({ | 57 | return makeGetRequest({ |
57 | url, | 58 | url, |
58 | path, | 59 | path, |
59 | statusCodeExpected: 200 | 60 | statusCodeExpected: HttpStatusCode.OK_200 |
60 | }) | 61 | }) |
61 | } | 62 | } |
62 | 63 | ||
@@ -66,7 +67,7 @@ function getVideoLanguages (url: string) { | |||
66 | return makeGetRequest({ | 67 | return makeGetRequest({ |
67 | url, | 68 | url, |
68 | path, | 69 | path, |
69 | statusCodeExpected: 200 | 70 | statusCodeExpected: HttpStatusCode.OK_200 |
70 | }) | 71 | }) |
71 | } | 72 | } |
72 | 73 | ||
@@ -76,11 +77,11 @@ function getVideoPrivacies (url: string) { | |||
76 | return makeGetRequest({ | 77 | return makeGetRequest({ |
77 | url, | 78 | url, |
78 | path, | 79 | path, |
79 | statusCodeExpected: 200 | 80 | statusCodeExpected: HttpStatusCode.OK_200 |
80 | }) | 81 | }) |
81 | } | 82 | } |
82 | 83 | ||
83 | function getVideo (url: string, id: number | string, expectedStatus = 200) { | 84 | function getVideo (url: string, id: number | string, expectedStatus = HttpStatusCode.OK_200) { |
84 | const path = '/api/v1/videos/' + id | 85 | const path = '/api/v1/videos/' + id |
85 | 86 | ||
86 | return request(url) | 87 | return request(url) |
@@ -99,11 +100,11 @@ function getVideoFileMetadataUrl (url: string) { | |||
99 | return request(url) | 100 | return request(url) |
100 | .get('/') | 101 | .get('/') |
101 | .set('Accept', 'application/json') | 102 | .set('Accept', 'application/json') |
102 | .expect(200) | 103 | .expect(HttpStatusCode.OK_200) |
103 | .expect('Content-Type', /json/) | 104 | .expect('Content-Type', /json/) |
104 | } | 105 | } |
105 | 106 | ||
106 | function viewVideo (url: string, id: number | string, expectedStatus = 204, xForwardedFor?: string) { | 107 | function viewVideo (url: string, id: number | string, expectedStatus = HttpStatusCode.NO_CONTENT_204, xForwardedFor?: string) { |
107 | const path = '/api/v1/videos/' + id + '/views' | 108 | const path = '/api/v1/videos/' + id + '/views' |
108 | 109 | ||
109 | const req = request(url) | 110 | const req = request(url) |
@@ -117,7 +118,7 @@ function viewVideo (url: string, id: number | string, expectedStatus = 204, xFor | |||
117 | return req.expect(expectedStatus) | 118 | return req.expect(expectedStatus) |
118 | } | 119 | } |
119 | 120 | ||
120 | function getVideoWithToken (url: string, token: string, id: number | string, expectedStatus = 200) { | 121 | function getVideoWithToken (url: string, token: string, id: number | string, expectedStatus = HttpStatusCode.OK_200) { |
121 | const path = '/api/v1/videos/' + id | 122 | const path = '/api/v1/videos/' + id |
122 | 123 | ||
123 | return request(url) | 124 | return request(url) |
@@ -131,7 +132,7 @@ function getVideoDescription (url: string, descriptionPath: string) { | |||
131 | return request(url) | 132 | return request(url) |
132 | .get(descriptionPath) | 133 | .get(descriptionPath) |
133 | .set('Accept', 'application/json') | 134 | .set('Accept', 'application/json') |
134 | .expect(200) | 135 | .expect(HttpStatusCode.OK_200) |
135 | .expect('Content-Type', /json/) | 136 | .expect('Content-Type', /json/) |
136 | } | 137 | } |
137 | 138 | ||
@@ -142,7 +143,7 @@ function getVideosList (url: string) { | |||
142 | .get(path) | 143 | .get(path) |
143 | .query({ sort: 'name' }) | 144 | .query({ sort: 'name' }) |
144 | .set('Accept', 'application/json') | 145 | .set('Accept', 'application/json') |
145 | .expect(200) | 146 | .expect(HttpStatusCode.OK_200) |
146 | .expect('Content-Type', /json/) | 147 | .expect('Content-Type', /json/) |
147 | } | 148 | } |
148 | 149 | ||
@@ -182,7 +183,7 @@ function getMyVideos (url: string, accessToken: string, start: number, count: nu | |||
182 | 183 | ||
183 | return req.set('Accept', 'application/json') | 184 | return req.set('Accept', 'application/json') |
184 | .set('Authorization', 'Bearer ' + accessToken) | 185 | .set('Authorization', 'Bearer ' + accessToken) |
185 | .expect(200) | 186 | .expect(HttpStatusCode.OK_200) |
186 | .expect('Content-Type', /json/) | 187 | .expect('Content-Type', /json/) |
187 | } | 188 | } |
188 | 189 | ||
@@ -206,7 +207,7 @@ function getAccountVideos ( | |||
206 | sort | 207 | sort |
207 | }), | 208 | }), |
208 | token: accessToken, | 209 | token: accessToken, |
209 | statusCodeExpected: 200 | 210 | statusCodeExpected: HttpStatusCode.OK_200 |
210 | }) | 211 | }) |
211 | } | 212 | } |
212 | 213 | ||
@@ -230,7 +231,7 @@ function getVideoChannelVideos ( | |||
230 | sort | 231 | sort |
231 | }), | 232 | }), |
232 | token: accessToken, | 233 | token: accessToken, |
233 | statusCodeExpected: 200 | 234 | statusCodeExpected: HttpStatusCode.OK_200 |
234 | }) | 235 | }) |
235 | } | 236 | } |
236 | 237 | ||
@@ -252,7 +253,7 @@ function getPlaylistVideos ( | |||
252 | count | 253 | count |
253 | }), | 254 | }), |
254 | token: accessToken, | 255 | token: accessToken, |
255 | statusCodeExpected: 200 | 256 | statusCodeExpected: HttpStatusCode.OK_200 |
256 | }) | 257 | }) |
257 | } | 258 | } |
258 | 259 | ||
@@ -268,7 +269,7 @@ function getVideosListPagination (url: string, start: number, count: number, sor | |||
268 | if (skipCount) req.query({ skipCount }) | 269 | if (skipCount) req.query({ skipCount }) |
269 | 270 | ||
270 | return req.set('Accept', 'application/json') | 271 | return req.set('Accept', 'application/json') |
271 | .expect(200) | 272 | .expect(HttpStatusCode.OK_200) |
272 | .expect('Content-Type', /json/) | 273 | .expect('Content-Type', /json/) |
273 | } | 274 | } |
274 | 275 | ||
@@ -279,7 +280,7 @@ function getVideosListSort (url: string, sort: string) { | |||
279 | .get(path) | 280 | .get(path) |
280 | .query({ sort: sort }) | 281 | .query({ sort: sort }) |
281 | .set('Accept', 'application/json') | 282 | .set('Accept', 'application/json') |
282 | .expect(200) | 283 | .expect(HttpStatusCode.OK_200) |
283 | .expect('Content-Type', /json/) | 284 | .expect('Content-Type', /json/) |
284 | } | 285 | } |
285 | 286 | ||
@@ -290,11 +291,11 @@ function getVideosWithFilters (url: string, query: { tagsAllOf: string[], catego | |||
290 | .get(path) | 291 | .get(path) |
291 | .query(query) | 292 | .query(query) |
292 | .set('Accept', 'application/json') | 293 | .set('Accept', 'application/json') |
293 | .expect(200) | 294 | .expect(HttpStatusCode.OK_200) |
294 | .expect('Content-Type', /json/) | 295 | .expect('Content-Type', /json/) |
295 | } | 296 | } |
296 | 297 | ||
297 | function removeVideo (url: string, token: string, id: number | string, expectedStatus = 204) { | 298 | function removeVideo (url: string, token: string, id: number | string, expectedStatus = HttpStatusCode.NO_CONTENT_204) { |
298 | const path = '/api/v1/videos' | 299 | const path = '/api/v1/videos' |
299 | 300 | ||
300 | return request(url) | 301 | return request(url) |
@@ -339,7 +340,7 @@ async function checkVideoFilesWereRemoved ( | |||
339 | } | 340 | } |
340 | } | 341 | } |
341 | 342 | ||
342 | async function uploadVideo (url: string, accessToken: string, videoAttributesArg: VideoAttributes, specialStatus = 200) { | 343 | async function uploadVideo (url: string, accessToken: string, videoAttributesArg: VideoAttributes, specialStatus = HttpStatusCode.OK_200) { |
343 | const path = '/api/v1/videos/upload' | 344 | const path = '/api/v1/videos/upload' |
344 | let defaultChannelId = '1' | 345 | let defaultChannelId = '1' |
345 | 346 | ||
@@ -423,7 +424,13 @@ async function uploadVideo (url: string, accessToken: string, videoAttributesArg | |||
423 | .expect(specialStatus) | 424 | .expect(specialStatus) |
424 | } | 425 | } |
425 | 426 | ||
426 | function updateVideo (url: string, accessToken: string, id: number | string, attributes: VideoAttributes, statusCodeExpected = 204) { | 427 | function updateVideo ( |
428 | url: string, | ||
429 | accessToken: string, | ||
430 | id: number | string, | ||
431 | attributes: VideoAttributes, | ||
432 | statusCodeExpected = HttpStatusCode.NO_CONTENT_204 | ||
433 | ) { | ||
427 | const path = '/api/v1/videos/' + id | 434 | const path = '/api/v1/videos/' + id |
428 | const body = {} | 435 | const body = {} |
429 | 436 | ||
@@ -467,7 +474,7 @@ function updateVideo (url: string, accessToken: string, id: number | string, att | |||
467 | }) | 474 | }) |
468 | } | 475 | } |
469 | 476 | ||
470 | function rateVideo (url: string, accessToken: string, id: number, rating: string, specialStatus = 204) { | 477 | function rateVideo (url: string, accessToken: string, id: number, rating: string, specialStatus = HttpStatusCode.NO_CONTENT_204) { |
471 | const path = '/api/v1/videos/' + id + '/rate' | 478 | const path = '/api/v1/videos/' + id + '/rate' |
472 | 479 | ||
473 | return request(url) | 480 | return request(url) |