diff options
Diffstat (limited to 'shared/extra-utils')
-rw-r--r-- | shared/extra-utils/server/activitypub.ts | 3 | ||||
-rw-r--r-- | shared/extra-utils/server/redundancy.ts | 8 | ||||
-rw-r--r-- | shared/extra-utils/users/login.ts | 13 | ||||
-rw-r--r-- | shared/extra-utils/videos/video-history.ts | 8 | ||||
-rw-r--r-- | shared/extra-utils/videos/videos.ts | 4 |
5 files changed, 25 insertions, 11 deletions
diff --git a/shared/extra-utils/server/activitypub.ts b/shared/extra-utils/server/activitypub.ts index eccb198ca..cf967ed7d 100644 --- a/shared/extra-utils/server/activitypub.ts +++ b/shared/extra-utils/server/activitypub.ts | |||
@@ -1,6 +1,7 @@ | |||
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 makeActivityPubGetRequest (url: string, path: string, expectedStatus = 200) { | 4 | function makeActivityPubGetRequest (url: string, path: string, expectedStatus = HttpStatusCode.OK_200) { |
4 | return request(url) | 5 | return request(url) |
5 | .get(path) | 6 | .get(path) |
6 | .set('Accept', 'application/activity+json,text/html;q=0.9,\\*/\\*;q=0.8') | 7 | .set('Accept', 'application/activity+json,text/html;q=0.9,\\*/\\*;q=0.8') |
diff --git a/shared/extra-utils/server/redundancy.ts b/shared/extra-utils/server/redundancy.ts index 3aca4ebfd..b83815a37 100644 --- a/shared/extra-utils/server/redundancy.ts +++ b/shared/extra-utils/server/redundancy.ts | |||
@@ -2,7 +2,13 @@ import { makeDeleteRequest, makeGetRequest, makePostBodyRequest, makePutBodyRequ | |||
2 | import { VideoRedundanciesTarget } from '@shared/models' | 2 | import { VideoRedundanciesTarget } from '@shared/models' |
3 | import { HttpStatusCode } from '../../../shared/core-utils/miscs/http-error-codes' | 3 | import { HttpStatusCode } from '../../../shared/core-utils/miscs/http-error-codes' |
4 | 4 | ||
5 | function updateRedundancy (url: string, accessToken: string, host: string, redundancyAllowed: boolean, expectedStatus = 204) { | 5 | function updateRedundancy ( |
6 | url: string, | ||
7 | accessToken: string, | ||
8 | host: string, | ||
9 | redundancyAllowed: boolean, | ||
10 | expectedStatus = HttpStatusCode.NO_CONTENT_204 | ||
11 | ) { | ||
6 | const path = '/api/v1/server/redundancy/' + host | 12 | const path = '/api/v1/server/redundancy/' + host |
7 | 13 | ||
8 | return makePutBodyRequest({ | 14 | return makePutBodyRequest({ |
diff --git a/shared/extra-utils/users/login.ts b/shared/extra-utils/users/login.ts index 275bb0826..39e1a2747 100644 --- a/shared/extra-utils/users/login.ts +++ b/shared/extra-utils/users/login.ts | |||
@@ -2,12 +2,13 @@ import * as request from 'supertest' | |||
2 | 2 | ||
3 | import { ServerInfo } from '../server/servers' | 3 | import { ServerInfo } from '../server/servers' |
4 | import { getClient } from '../server/clients' | 4 | import { getClient } from '../server/clients' |
5 | import { HttpStatusCode } from '../../../shared/core-utils/miscs/http-error-codes' | ||
5 | 6 | ||
6 | type Client = { id: string, secret: string } | 7 | type Client = { id: string, secret: string } |
7 | type User = { username: string, password: string } | 8 | type User = { username: string, password: string } |
8 | type Server = { url: string, client: Client, user: User } | 9 | type Server = { url: string, client: Client, user: User } |
9 | 10 | ||
10 | function login (url: string, client: Client, user: User, expectedStatus = 200) { | 11 | function login (url: string, client: Client, user: User, expectedStatus = HttpStatusCode.OK_200) { |
11 | const path = '/api/v1/users/token' | 12 | const path = '/api/v1/users/token' |
12 | 13 | ||
13 | const body = { | 14 | const body = { |
@@ -27,7 +28,7 @@ function login (url: string, client: Client, user: User, expectedStatus = 200) { | |||
27 | .expect(expectedStatus) | 28 | .expect(expectedStatus) |
28 | } | 29 | } |
29 | 30 | ||
30 | function logout (url: string, token: string, expectedStatus = 200) { | 31 | function logout (url: string, token: string, expectedStatus = HttpStatusCode.OK_200) { |
31 | const path = '/api/v1/users/revoke-token' | 32 | const path = '/api/v1/users/revoke-token' |
32 | 33 | ||
33 | return request(url) | 34 | return request(url) |
@@ -38,12 +39,12 @@ function logout (url: string, token: string, expectedStatus = 200) { | |||
38 | } | 39 | } |
39 | 40 | ||
40 | async function serverLogin (server: Server) { | 41 | async function serverLogin (server: Server) { |
41 | const res = await login(server.url, server.client, server.user, 200) | 42 | const res = await login(server.url, server.client, server.user, HttpStatusCode.OK_200) |
42 | 43 | ||
43 | return res.body.access_token as string | 44 | return res.body.access_token as string |
44 | } | 45 | } |
45 | 46 | ||
46 | function refreshToken (server: ServerInfo, refreshToken: string, expectedStatus = 200) { | 47 | function refreshToken (server: ServerInfo, refreshToken: string, expectedStatus = HttpStatusCode.OK_200) { |
47 | const path = '/api/v1/users/token' | 48 | const path = '/api/v1/users/token' |
48 | 49 | ||
49 | const body = { | 50 | const body = { |
@@ -61,7 +62,7 @@ function refreshToken (server: ServerInfo, refreshToken: string, expectedStatus | |||
61 | .expect(expectedStatus) | 62 | .expect(expectedStatus) |
62 | } | 63 | } |
63 | 64 | ||
64 | async function userLogin (server: Server, user: User, expectedStatus = 200) { | 65 | async function userLogin (server: Server, user: User, expectedStatus = HttpStatusCode.OK_200) { |
65 | const res = await login(server.url, server.client, user, expectedStatus) | 66 | const res = await login(server.url, server.client, user, expectedStatus) |
66 | 67 | ||
67 | return res.body.access_token as string | 68 | return res.body.access_token as string |
@@ -95,7 +96,7 @@ function setAccessTokensToServers (servers: ServerInfo[]) { | |||
95 | return Promise.all(tasks) | 96 | return Promise.all(tasks) |
96 | } | 97 | } |
97 | 98 | ||
98 | function loginUsingExternalToken (server: Server, username: string, externalAuthToken: string, expectedStatus = 200) { | 99 | function loginUsingExternalToken (server: Server, username: string, externalAuthToken: string, expectedStatus = HttpStatusCode.OK_200) { |
99 | const path = '/api/v1/users/token' | 100 | const path = '/api/v1/users/token' |
100 | 101 | ||
101 | const body = { | 102 | const body = { |
diff --git a/shared/extra-utils/videos/video-history.ts b/shared/extra-utils/videos/video-history.ts index 2d751cf14..0dd3afb24 100644 --- a/shared/extra-utils/videos/video-history.ts +++ b/shared/extra-utils/videos/video-history.ts | |||
@@ -1,7 +1,13 @@ | |||
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 | import { HttpStatusCode } from '../../../shared/core-utils/miscs/http-error-codes' |
3 | 3 | ||
4 | function userWatchVideo (url: string, token: string, videoId: number | string, currentTime: number, statusCodeExpected = 204) { | 4 | function userWatchVideo ( |
5 | url: string, | ||
6 | token: string, | ||
7 | videoId: number | string, | ||
8 | currentTime: number, | ||
9 | statusCodeExpected = HttpStatusCode.NO_CONTENT_204 | ||
10 | ) { | ||
5 | const path = '/api/v1/videos/' + videoId + '/watching' | 11 | const path = '/api/v1/videos/' + videoId + '/watching' |
6 | const fields = { currentTime } | 12 | const fields = { currentTime } |
7 | 13 | ||
diff --git a/shared/extra-utils/videos/videos.ts b/shared/extra-utils/videos/videos.ts index a4b9d688e..a2438d712 100644 --- a/shared/extra-utils/videos/videos.ts +++ b/shared/extra-utils/videos/videos.ts | |||
@@ -155,7 +155,7 @@ function getVideosListWithToken (url: string, token: string, query: { nsfw?: boo | |||
155 | .set('Authorization', 'Bearer ' + token) | 155 | .set('Authorization', 'Bearer ' + token) |
156 | .query(immutableAssign(query, { sort: 'name' })) | 156 | .query(immutableAssign(query, { sort: 'name' })) |
157 | .set('Accept', 'application/json') | 157 | .set('Accept', 'application/json') |
158 | .expect(200) | 158 | .expect(HttpStatusCode.OK_200) |
159 | .expect('Content-Type', /json/) | 159 | .expect('Content-Type', /json/) |
160 | } | 160 | } |
161 | 161 | ||
@@ -166,7 +166,7 @@ function getLocalVideos (url: string) { | |||
166 | .get(path) | 166 | .get(path) |
167 | .query({ sort: 'name', filter: 'local' }) | 167 | .query({ sort: 'name', filter: 'local' }) |
168 | .set('Accept', 'application/json') | 168 | .set('Accept', 'application/json') |
169 | .expect(200) | 169 | .expect(HttpStatusCode.OK_200) |
170 | .expect('Content-Type', /json/) | 170 | .expect('Content-Type', /json/) |
171 | } | 171 | } |
172 | 172 | ||