-/* tslint:disable:no-unused-expression */
+/* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
import 'mocha'
import {
+ cleanupTests,
createUser,
doubleFollow,
flushAndRunMultipleServers,
- flushTests,
- killallServers,
makeDeleteRequest,
makeGetRequest,
makePostBodyRequest,
ServerInfo,
- setAccessTokensToServers, userLogin
-} from '../../../../shared/utils'
+ setAccessTokensToServers,
+ userLogin
+} from '../../../../shared/extra-utils'
import {
checkBadCountPagination,
checkBadSortPagination,
checkBadStartPagination
-} from '../../../../shared/utils/requests/check-api-params'
+} from '../../../../shared/extra-utils/requests/check-api-params'
describe('Test blocklist API validators', function () {
let servers: ServerInfo[]
before(async function () {
this.timeout(60000)
- await flushTests()
-
servers = await flushAndRunMultipleServers(2)
await setAccessTokensToServers(servers)
server = servers[0]
const user = { username: 'user1', password: 'password' }
- await createUser(server.url, server.accessToken, user.username, user.password)
+ await createUser({ url: server.url, accessToken: server.accessToken, username: user.username, password: user.password })
userAccessToken = await userLogin(server, user)
})
})
- it('Should fail with an unknown server', async function () {
+ it('Should succeed with an unknown server', async function () {
await makePostBodyRequest({
url: server.url,
token: server.accessToken,
path,
fields: { host: 'localhost:9003' },
- statusCodeExpected: 404
+ statusCodeExpected: 204
})
})
url: server.url,
token: server.accessToken,
path,
- fields: { host: 'localhost:9001' },
+ fields: { host: 'localhost:' + server.port },
statusCodeExpected: 409
})
})
url: server.url,
token: server.accessToken,
path,
- fields: { host: 'localhost:9002' },
+ fields: { host: 'localhost:' + servers[1].port },
statusCodeExpected: 204
})
})
it('Should fail with an unauthenticated user', async function () {
await makeDeleteRequest({
url: server.url,
- path: path + '/localhost:9002',
+ path: path + '/localhost:' + servers[1].port,
statusCodeExpected: 401
})
})
it('Should fail with an unknown server block', async function () {
await makeDeleteRequest({
url: server.url,
- path: path + '/localhost:9003',
+ path: path + '/localhost:9004',
token: server.accessToken,
statusCodeExpected: 404
})
it('Should succeed with the correct params', async function () {
await makeDeleteRequest({
url: server.url,
- path: path + '/localhost:9002',
+ path: path + '/localhost:' + servers[1].port,
token: server.accessToken,
statusCodeExpected: 204
})
await makePostBodyRequest({
url: server.url,
path,
- fields: { host: 'localhost:9002' },
+ fields: { host: 'localhost:' + servers[1].port },
statusCodeExpected: 401
})
})
url: server.url,
token: userAccessToken,
path,
- fields: { host: 'localhost:9002' },
+ fields: { host: 'localhost:' + servers[1].port },
statusCodeExpected: 403
})
})
- it('Should fail with an unknown server', async function () {
+ it('Should succeed with an unknown server', async function () {
await makePostBodyRequest({
url: server.url,
token: server.accessToken,
path,
fields: { host: 'localhost:9003' },
- statusCodeExpected: 404
+ statusCodeExpected: 204
})
})
url: server.url,
token: server.accessToken,
path,
- fields: { host: 'localhost:9001' },
+ fields: { host: 'localhost:' + server.port },
statusCodeExpected: 409
})
})
url: server.url,
token: server.accessToken,
path,
- fields: { host: 'localhost:9002' },
+ fields: { host: 'localhost:' + servers[1].port },
statusCodeExpected: 204
})
})
it('Should fail with an unauthenticated user', async function () {
await makeDeleteRequest({
url: server.url,
- path: path + '/localhost:9002',
+ path: path + '/localhost:' + servers[1].port,
statusCodeExpected: 401
})
})
it('Should fail with a user without the appropriate rights', async function () {
await makeDeleteRequest({
url: server.url,
- path: path + '/localhost:9002',
+ path: path + '/localhost:' + servers[1].port,
token: userAccessToken,
statusCodeExpected: 403
})
it('Should fail with an unknown server block', async function () {
await makeDeleteRequest({
url: server.url,
- path: path + '/localhost:9003',
+ path: path + '/localhost:9004',
token: server.accessToken,
statusCodeExpected: 404
})
it('Should succeed with the correct params', async function () {
await makeDeleteRequest({
url: server.url,
- path: path + '/localhost:9002',
+ path: path + '/localhost:' + servers[1].port,
token: server.accessToken,
statusCodeExpected: 204
})
})
after(async function () {
- killallServers(servers)
-
- // Keep the logs if the test failed
- if (this['ok']) {
- await flushTests()
- }
+ await cleanupTests(servers)
})
})