1 /* tslint:disable:no-unused-expression */
8 flushAndRunMultipleServers,
15 setAccessTokensToServers
17 import { checkBadCountPagination, checkBadSortPagination, checkBadStartPagination } from '../../utils/requests/check-api-params'
19 describe('Test blocklist API validators', function () {
20 let servers: ServerInfo[]
21 let server: ServerInfo
23 before(async function () {
28 servers = await flushAndRunMultipleServers(2)
29 await setAccessTokensToServers(servers)
33 const user = { username: 'user1', password: 'password' }
34 await createUser(server.url, server.accessToken, user.username, user.password)
36 await doubleFollow(servers[0], servers[1])
39 // ---------------------------------------------------------------
41 describe('When managing user blocklist', function () {
42 const path = '/api/v1/users/me/blocklist/accounts'
44 describe('When managing user accounts blocklist', function () {
46 describe('When listing blocked accounts', function () {
47 it('Should fail with an unauthenticated user', async function () {
48 await makeGetRequest({
51 statusCodeExpected: 401
55 it('Should fail with a bad start pagination', async function () {
56 await checkBadStartPagination(server.url, path, server.accessToken)
59 it('Should fail with a bad count pagination', async function () {
60 await checkBadCountPagination(server.url, path, server.accessToken)
63 it('Should fail with an incorrect sort', async function () {
64 await checkBadSortPagination(server.url, path, server.accessToken)
68 describe('When blocking an account', function () {
69 it('Should fail with an unauthenticated user', async function () {
70 await makePostBodyRequest({
73 fields: { accountName: 'user1' },
74 statusCodeExpected: 401
78 it('Should fail with an unknown account', async function () {
79 await makePostBodyRequest({
81 token: server.accessToken,
83 fields: { accountName: 'user2' },
84 statusCodeExpected: 404
88 it('Should succeed with the correct params', async function () {
89 await makePostBodyRequest({
91 token: server.accessToken,
93 fields: { accountName: 'user1' },
94 statusCodeExpected: 204
99 describe('When unblocking an account', function () {
100 it('Should fail with an unauthenticated user', async function () {
101 await makeDeleteRequest({
103 path: path + '/user1',
104 statusCodeExpected: 401
108 it('Should fail with an unknown account block', async function () {
109 await makeDeleteRequest({
111 path: path + '/user2',
112 token: server.accessToken,
113 statusCodeExpected: 404
117 it('Should succeed with the correct params', async function () {
118 await makeDeleteRequest({
120 path: path + '/user1',
121 token: server.accessToken,
122 statusCodeExpected: 204
128 describe('When managing user servers blocklist', function () {
129 const path = '/api/v1/users/me/blocklist/servers'
131 describe('When listing blocked servers', function () {
132 it('Should fail with an unauthenticated user', async function () {
133 await makeGetRequest({
136 statusCodeExpected: 401
140 it('Should fail with a bad start pagination', async function () {
141 await checkBadStartPagination(server.url, path, server.accessToken)
144 it('Should fail with a bad count pagination', async function () {
145 await checkBadCountPagination(server.url, path, server.accessToken)
148 it('Should fail with an incorrect sort', async function () {
149 await checkBadSortPagination(server.url, path, server.accessToken)
153 describe('When blocking a server', function () {
154 it('Should fail with an unauthenticated user', async function () {
155 await makePostBodyRequest({
158 fields: { host: 'localhost:9002' },
159 statusCodeExpected: 401
163 it('Should fail with an unknown server', async function () {
164 await makePostBodyRequest({
166 token: server.accessToken,
168 fields: { host: 'localhost:9003' },
169 statusCodeExpected: 404
173 it('Should succeed with the correct params', async function () {
174 await makePostBodyRequest({
176 token: server.accessToken,
178 fields: { host: 'localhost:9002' },
179 statusCodeExpected: 204
184 describe('When unblocking a server', function () {
185 it('Should fail with an unauthenticated user', async function () {
186 await makeDeleteRequest({
188 path: path + '/localhost:9002',
189 statusCodeExpected: 401
193 it('Should fail with an unknown server block', async function () {
194 await makeDeleteRequest({
196 path: path + '/localhost:9003',
197 token: server.accessToken,
198 statusCodeExpected: 404
202 it('Should succeed with the correct params', async function () {
203 await makeDeleteRequest({
205 path: path + '/localhost:9002',
206 token: server.accessToken,
207 statusCodeExpected: 204
214 after(async function () {
215 killallServers(servers)
217 // Keep the logs if the test failed