aboutsummaryrefslogtreecommitdiffhomepage
path: root/shared/extra-utils/server/follows.ts
diff options
context:
space:
mode:
authorRigel Kent <sendmemail@rigelk.eu>2020-12-07 14:32:36 +0100
committerGitHub <noreply@github.com>2020-12-07 14:32:36 +0100
commit2d53be0267acc49cda46707b885096193a1f4e9c (patch)
tree887061a34bc67f40acbb96a6278f9544bf83caeb /shared/extra-utils/server/follows.ts
parentadc1f09c0dbd997f34028c1c82d1c118dc8ead80 (diff)
downloadPeerTube-2d53be0267acc49cda46707b885096193a1f4e9c.tar.gz
PeerTube-2d53be0267acc49cda46707b885096193a1f4e9c.tar.zst
PeerTube-2d53be0267acc49cda46707b885096193a1f4e9c.zip
replace numbers with typed http status codes (#3409)
Diffstat (limited to 'shared/extra-utils/server/follows.ts')
-rw-r--r--shared/extra-utils/server/follows.ts15
1 files changed, 8 insertions, 7 deletions
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'
3import { waitJobs } from './jobs' 3import { waitJobs } from './jobs'
4import { makePostBodyRequest } from '../requests/requests' 4import { makePostBodyRequest } from '../requests/requests'
5import { ActivityPubActorType, FollowState } from '@shared/models' 5import { ActivityPubActorType, FollowState } from '@shared/models'
6import { HttpStatusCode } from '../../../shared/core-utils/miscs/http-error-codes'
6 7
7function getFollowersListPaginationAndSort (options: { 8function 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
36function acceptFollower (url: string, token: string, follower: string, statusCodeExpected = 204) { 37function 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
47function rejectFollower (url: string, token: string, follower: string, statusCodeExpected = 204) { 48function 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
87function follow (follower: string, following: string[], accessToken: string, expectedStatus = 204) { 88function 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
99async function unfollow (url: string, accessToken: string, target: ServerInfo, expectedStatus = 204) { 100async 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
109function removeFollower (url: string, accessToken: string, follower: ServerInfo, expectedStatus = 204) { 110function 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)