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 fail to block ourselves', async function () {
89 await makePostBodyRequest({
91 token: server.accessToken,
93 fields: { accountName: 'root' },
94 statusCodeExpected: 409
98 it('Should succeed with the correct params', async function () {
99 await makePostBodyRequest({
101 token: server.accessToken,
103 fields: { accountName: 'user1' },
104 statusCodeExpected: 204
109 describe('When unblocking an account', function () {
110 it('Should fail with an unauthenticated user', async function () {
111 await makeDeleteRequest({
113 path: path + '/user1',
114 statusCodeExpected: 401
118 it('Should fail with an unknown account block', async function () {
119 await makeDeleteRequest({
121 path: path + '/user2',
122 token: server.accessToken,
123 statusCodeExpected: 404
127 it('Should succeed with the correct params', async function () {
128 await makeDeleteRequest({
130 path: path + '/user1',
131 token: server.accessToken,
132 statusCodeExpected: 204
138 describe('When managing user servers blocklist', function () {
139 const path = '/api/v1/users/me/blocklist/servers'
141 describe('When listing blocked servers', function () {
142 it('Should fail with an unauthenticated user', async function () {
143 await makeGetRequest({
146 statusCodeExpected: 401
150 it('Should fail with a bad start pagination', async function () {
151 await checkBadStartPagination(server.url, path, server.accessToken)
154 it('Should fail with a bad count pagination', async function () {
155 await checkBadCountPagination(server.url, path, server.accessToken)
158 it('Should fail with an incorrect sort', async function () {
159 await checkBadSortPagination(server.url, path, server.accessToken)
163 describe('When blocking a server', function () {
164 it('Should fail with an unauthenticated user', async function () {
165 await makePostBodyRequest({
168 fields: { host: 'localhost:9002' },
169 statusCodeExpected: 401
173 it('Should fail with an unknown server', async function () {
174 await makePostBodyRequest({
176 token: server.accessToken,
178 fields: { host: 'localhost:9003' },
179 statusCodeExpected: 404
183 it('Should fail with our own server', async function () {
184 await makePostBodyRequest({
186 token: server.accessToken,
188 fields: { host: 'localhost:9001' },
189 statusCodeExpected: 409
193 it('Should succeed with the correct params', async function () {
194 await makePostBodyRequest({
196 token: server.accessToken,
198 fields: { host: 'localhost:9002' },
199 statusCodeExpected: 204
204 describe('When unblocking a server', function () {
205 it('Should fail with an unauthenticated user', async function () {
206 await makeDeleteRequest({
208 path: path + '/localhost:9002',
209 statusCodeExpected: 401
213 it('Should fail with an unknown server block', async function () {
214 await makeDeleteRequest({
216 path: path + '/localhost:9003',
217 token: server.accessToken,
218 statusCodeExpected: 404
222 it('Should succeed with the correct params', async function () {
223 await makeDeleteRequest({
225 path: path + '/localhost:9002',
226 token: server.accessToken,
227 statusCodeExpected: 204
234 after(async function () {
235 killallServers(servers)
237 // Keep the logs if the test failed