From 7ad9b9846c44d198a736183fb186c2039f5236b5 Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Fri, 12 Oct 2018 15:26:04 +0200 Subject: Add ability for users to block an account/instance on server side --- server/tests/utils/requests/requests.ts | 4 +- server/tests/utils/users/blocklist.ts | 103 ++++++++++++++++++++++++++++ server/tests/utils/videos/video-comments.ts | 14 ++-- 3 files changed, 113 insertions(+), 8 deletions(-) create mode 100644 server/tests/utils/users/blocklist.ts (limited to 'server/tests/utils') diff --git a/server/tests/utils/requests/requests.ts b/server/tests/utils/requests/requests.ts index 27a529eda..5796540f7 100644 --- a/server/tests/utils/requests/requests.ts +++ b/server/tests/utils/requests/requests.ts @@ -37,9 +37,7 @@ function makeDeleteRequest (options: { if (options.token) req.set('Authorization', 'Bearer ' + options.token) - return req - .expect('Content-Type', /json/) - .expect(options.statusCodeExpected) + return req.expect(options.statusCodeExpected) } function makeUploadRequest (options: { diff --git a/server/tests/utils/users/blocklist.ts b/server/tests/utils/users/blocklist.ts new file mode 100644 index 000000000..47b315480 --- /dev/null +++ b/server/tests/utils/users/blocklist.ts @@ -0,0 +1,103 @@ +/* tslint:disable:no-unused-expression */ + +import { makeDeleteRequest, makePostBodyRequest } from '../index' +import { makeGetRequest } from '../requests/requests' + +function getAccountBlocklistByAccount ( + url: string, + token: string, + start: number, + count: number, + sort = '-createdAt', + statusCodeExpected = 200 +) { + const path = '/api/v1/users/me/blocklist/accounts' + + return makeGetRequest({ + url, + token, + query: { start, count, sort }, + path, + statusCodeExpected + }) +} + +function addAccountToAccountBlocklist (url: string, token: string, accountToBlock: string, statusCodeExpected = 204) { + const path = '/api/v1/users/me/blocklist/accounts' + + return makePostBodyRequest({ + url, + path, + token, + fields: { + accountName: accountToBlock + }, + statusCodeExpected + }) +} + +function removeAccountFromAccountBlocklist (url: string, token: string, accountToUnblock: string, statusCodeExpected = 204) { + const path = '/api/v1/users/me/blocklist/accounts/' + accountToUnblock + + return makeDeleteRequest({ + url, + path, + token, + statusCodeExpected + }) +} + +function getServerBlocklistByAccount ( + url: string, + token: string, + start: number, + count: number, + sort = '-createdAt', + statusCodeExpected = 200 +) { + const path = '/api/v1/users/me/blocklist/servers' + + return makeGetRequest({ + url, + token, + query: { start, count, sort }, + path, + statusCodeExpected + }) +} + +function addServerToAccountBlocklist (url: string, token: string, serverToBlock: string, statusCodeExpected = 204) { + const path = '/api/v1/users/me/blocklist/servers' + + return makePostBodyRequest({ + url, + path, + token, + fields: { + host: serverToBlock + }, + statusCodeExpected + }) +} + +function removeServerFromAccountBlocklist (url: string, token: string, serverToBlock: string, statusCodeExpected = 204) { + const path = '/api/v1/users/me/blocklist/servers/' + serverToBlock + + return makeDeleteRequest({ + url, + path, + token, + statusCodeExpected + }) +} + +// --------------------------------------------------------------------------- + +export { + getAccountBlocklistByAccount, + addAccountToAccountBlocklist, + removeAccountFromAccountBlocklist, + getServerBlocklistByAccount, + addServerToAccountBlocklist, + removeServerFromAccountBlocklist +} diff --git a/server/tests/utils/videos/video-comments.ts b/server/tests/utils/videos/video-comments.ts index 1b9ee452e..7d4cae364 100644 --- a/server/tests/utils/videos/video-comments.ts +++ b/server/tests/utils/videos/video-comments.ts @@ -1,7 +1,7 @@ import * as request from 'supertest' import { makeDeleteRequest } from '../' -function getVideoCommentThreads (url: string, videoId: number | string, start: number, count: number, sort?: string) { +function getVideoCommentThreads (url: string, videoId: number | string, start: number, count: number, sort?: string, token?: string) { const path = '/api/v1/videos/' + videoId + '/comment-threads' const req = request(url) @@ -10,20 +10,24 @@ function getVideoCommentThreads (url: string, videoId: number | string, start: n .query({ count: count }) if (sort) req.query({ sort }) + if (token) req.set('Authorization', 'Bearer ' + token) return req.set('Accept', 'application/json') .expect(200) .expect('Content-Type', /json/) } -function getVideoThreadComments (url: string, videoId: number | string, threadId: number) { +function getVideoThreadComments (url: string, videoId: number | string, threadId: number, token?: string) { const path = '/api/v1/videos/' + videoId + '/comment-threads/' + threadId - return request(url) + const req = request(url) .get(path) .set('Accept', 'application/json') - .expect(200) - .expect('Content-Type', /json/) + + if (token) req.set('Authorization', 'Bearer ' + token) + + return req.expect(200) + .expect('Content-Type', /json/) } function addVideoCommentThread (url: string, token: string, videoId: number | string, text: string, expectedStatus = 200) { -- cgit v1.2.3