2020-01-31 16:56:52 +01:00
|
|
|
/* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
|
2018-08-16 15:25:20 +02:00
|
|
|
|
|
|
|
import 'mocha'
|
|
|
|
|
|
|
|
import {
|
2019-04-24 15:10:37 +02:00
|
|
|
cleanupTests,
|
2018-08-16 15:25:20 +02:00
|
|
|
createUser,
|
2019-04-24 15:10:37 +02:00
|
|
|
flushAndRunServer,
|
2018-08-16 15:25:20 +02:00
|
|
|
makeDeleteRequest,
|
|
|
|
makeGetRequest,
|
|
|
|
makePostBodyRequest,
|
|
|
|
ServerInfo,
|
|
|
|
setAccessTokensToServers,
|
|
|
|
userLogin
|
2019-04-15 15:26:15 +02:00
|
|
|
} from '../../../../shared/extra-utils'
|
2018-11-18 17:25:52 +01:00
|
|
|
|
2018-10-29 17:48:31 +01:00
|
|
|
import {
|
|
|
|
checkBadCountPagination,
|
|
|
|
checkBadSortPagination,
|
|
|
|
checkBadStartPagination
|
2019-04-15 15:26:15 +02:00
|
|
|
} from '../../../../shared/extra-utils/requests/check-api-params'
|
|
|
|
import { waitJobs } from '../../../../shared/extra-utils/server/jobs'
|
2020-12-07 14:32:36 +01:00
|
|
|
import { HttpStatusCode } from '../../../../shared/core-utils/miscs/http-error-codes'
|
2018-08-16 15:25:20 +02:00
|
|
|
|
|
|
|
describe('Test user subscriptions API validators', function () {
|
|
|
|
const path = '/api/v1/users/me/subscriptions'
|
|
|
|
let server: ServerInfo
|
|
|
|
let userAccessToken = ''
|
|
|
|
|
|
|
|
// ---------------------------------------------------------------
|
|
|
|
|
|
|
|
before(async function () {
|
|
|
|
this.timeout(30000)
|
|
|
|
|
2019-04-24 10:53:40 +02:00
|
|
|
server = await flushAndRunServer(1)
|
2018-08-16 15:25:20 +02:00
|
|
|
|
|
|
|
await setAccessTokensToServers([ server ])
|
|
|
|
|
|
|
|
const user = {
|
|
|
|
username: 'user1',
|
|
|
|
password: 'my super password'
|
|
|
|
}
|
2019-04-15 10:49:46 +02:00
|
|
|
await createUser({ url: server.url, accessToken: server.accessToken, username: user.username, password: user.password })
|
2018-08-16 15:25:20 +02:00
|
|
|
userAccessToken = await userLogin(server, user)
|
|
|
|
})
|
|
|
|
|
|
|
|
describe('When listing my subscriptions', function () {
|
|
|
|
it('Should fail with a bad start pagination', async function () {
|
|
|
|
await checkBadStartPagination(server.url, path, server.accessToken)
|
|
|
|
})
|
|
|
|
|
|
|
|
it('Should fail with a bad count pagination', async function () {
|
|
|
|
await checkBadCountPagination(server.url, path, server.accessToken)
|
|
|
|
})
|
|
|
|
|
|
|
|
it('Should fail with an incorrect sort', async function () {
|
|
|
|
await checkBadSortPagination(server.url, path, server.accessToken)
|
|
|
|
})
|
|
|
|
|
|
|
|
it('Should fail with a non authenticated user', async function () {
|
|
|
|
await makeGetRequest({
|
|
|
|
url: server.url,
|
|
|
|
path,
|
2020-12-07 14:32:36 +01:00
|
|
|
statusCodeExpected: HttpStatusCode.UNAUTHORIZED_401
|
2018-08-16 15:25:20 +02:00
|
|
|
})
|
|
|
|
})
|
|
|
|
|
2018-08-21 10:34:18 +02:00
|
|
|
it('Should succeed with the correct parameters', async function () {
|
2018-08-17 15:45:42 +02:00
|
|
|
await makeGetRequest({
|
2018-08-16 15:25:20 +02:00
|
|
|
url: server.url,
|
|
|
|
path,
|
|
|
|
token: userAccessToken,
|
2020-12-07 14:32:36 +01:00
|
|
|
statusCodeExpected: HttpStatusCode.OK_200
|
2018-08-16 15:25:20 +02:00
|
|
|
})
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
describe('When listing my subscriptions videos', function () {
|
|
|
|
const path = '/api/v1/users/me/subscriptions/videos'
|
|
|
|
|
|
|
|
it('Should fail with a bad start pagination', async function () {
|
|
|
|
await checkBadStartPagination(server.url, path, server.accessToken)
|
|
|
|
})
|
|
|
|
|
|
|
|
it('Should fail with a bad count pagination', async function () {
|
|
|
|
await checkBadCountPagination(server.url, path, server.accessToken)
|
|
|
|
})
|
|
|
|
|
|
|
|
it('Should fail with an incorrect sort', async function () {
|
|
|
|
await checkBadSortPagination(server.url, path, server.accessToken)
|
|
|
|
})
|
|
|
|
|
|
|
|
it('Should fail with a non authenticated user', async function () {
|
|
|
|
await makeGetRequest({
|
|
|
|
url: server.url,
|
|
|
|
path,
|
2020-12-07 14:32:36 +01:00
|
|
|
statusCodeExpected: HttpStatusCode.UNAUTHORIZED_401
|
2018-08-16 15:25:20 +02:00
|
|
|
})
|
|
|
|
})
|
|
|
|
|
2018-08-21 10:34:18 +02:00
|
|
|
it('Should succeed with the correct parameters', async function () {
|
2018-08-17 15:45:42 +02:00
|
|
|
await makeGetRequest({
|
2018-08-16 15:25:20 +02:00
|
|
|
url: server.url,
|
|
|
|
path,
|
|
|
|
token: userAccessToken,
|
2020-12-07 14:32:36 +01:00
|
|
|
statusCodeExpected: HttpStatusCode.OK_200
|
2018-08-16 15:25:20 +02:00
|
|
|
})
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
describe('When adding a subscription', function () {
|
|
|
|
it('Should fail with a non authenticated user', async function () {
|
|
|
|
await makePostBodyRequest({
|
|
|
|
url: server.url,
|
|
|
|
path,
|
2019-04-24 15:10:37 +02:00
|
|
|
fields: { uri: 'user1_channel@localhost:' + server.port },
|
2020-12-07 14:32:36 +01:00
|
|
|
statusCodeExpected: HttpStatusCode.UNAUTHORIZED_401
|
2018-08-16 15:25:20 +02:00
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
it('Should fail with bad URIs', async function () {
|
|
|
|
await makePostBodyRequest({
|
|
|
|
url: server.url,
|
|
|
|
path,
|
|
|
|
token: server.accessToken,
|
|
|
|
fields: { uri: 'root' },
|
2020-12-07 14:32:36 +01:00
|
|
|
statusCodeExpected: HttpStatusCode.BAD_REQUEST_400
|
2018-08-16 15:25:20 +02:00
|
|
|
})
|
|
|
|
|
|
|
|
await makePostBodyRequest({
|
|
|
|
url: server.url,
|
|
|
|
path,
|
|
|
|
token: server.accessToken,
|
|
|
|
fields: { uri: 'root@' },
|
2020-12-07 14:32:36 +01:00
|
|
|
statusCodeExpected: HttpStatusCode.BAD_REQUEST_400
|
2018-08-16 15:25:20 +02:00
|
|
|
})
|
|
|
|
|
|
|
|
await makePostBodyRequest({
|
|
|
|
url: server.url,
|
|
|
|
path,
|
|
|
|
token: server.accessToken,
|
|
|
|
fields: { uri: 'root@hello@' },
|
2020-12-07 14:32:36 +01:00
|
|
|
statusCodeExpected: HttpStatusCode.BAD_REQUEST_400
|
2018-08-16 15:25:20 +02:00
|
|
|
})
|
|
|
|
})
|
|
|
|
|
2018-08-21 10:34:18 +02:00
|
|
|
it('Should succeed with the correct parameters', async function () {
|
2018-11-16 11:18:13 +01:00
|
|
|
this.timeout(20000)
|
|
|
|
|
2018-08-16 15:25:20 +02:00
|
|
|
await makePostBodyRequest({
|
|
|
|
url: server.url,
|
|
|
|
path,
|
|
|
|
token: server.accessToken,
|
2019-04-24 15:10:37 +02:00
|
|
|
fields: { uri: 'user1_channel@localhost:' + server.port },
|
2020-12-07 14:32:36 +01:00
|
|
|
statusCodeExpected: HttpStatusCode.NO_CONTENT_204
|
2018-08-16 15:25:20 +02:00
|
|
|
})
|
2018-11-16 11:18:13 +01:00
|
|
|
|
|
|
|
await waitJobs([ server ])
|
2018-08-16 15:25:20 +02:00
|
|
|
})
|
|
|
|
})
|
|
|
|
|
2018-08-21 10:34:18 +02:00
|
|
|
describe('When getting a subscription', function () {
|
|
|
|
it('Should fail with a non authenticated user', async function () {
|
|
|
|
await makeGetRequest({
|
|
|
|
url: server.url,
|
2019-04-24 15:10:37 +02:00
|
|
|
path: path + '/user1_channel@localhost:' + server.port,
|
2020-12-07 14:32:36 +01:00
|
|
|
statusCodeExpected: HttpStatusCode.UNAUTHORIZED_401
|
2018-08-21 10:34:18 +02:00
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
it('Should fail with bad URIs', async function () {
|
|
|
|
await makeGetRequest({
|
|
|
|
url: server.url,
|
|
|
|
path: path + '/root',
|
|
|
|
token: server.accessToken,
|
2020-12-07 14:32:36 +01:00
|
|
|
statusCodeExpected: HttpStatusCode.BAD_REQUEST_400
|
2018-08-21 10:34:18 +02:00
|
|
|
})
|
|
|
|
|
|
|
|
await makeGetRequest({
|
|
|
|
url: server.url,
|
|
|
|
path: path + '/root@',
|
|
|
|
token: server.accessToken,
|
2020-12-07 14:32:36 +01:00
|
|
|
statusCodeExpected: HttpStatusCode.BAD_REQUEST_400
|
2018-08-21 10:34:18 +02:00
|
|
|
})
|
|
|
|
|
|
|
|
await makeGetRequest({
|
|
|
|
url: server.url,
|
|
|
|
path: path + '/root@hello@',
|
|
|
|
token: server.accessToken,
|
2020-12-07 14:32:36 +01:00
|
|
|
statusCodeExpected: HttpStatusCode.BAD_REQUEST_400
|
2018-08-21 10:34:18 +02:00
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
it('Should fail with an unknown subscription', async function () {
|
|
|
|
await makeGetRequest({
|
|
|
|
url: server.url,
|
2019-04-24 15:10:37 +02:00
|
|
|
path: path + '/root1@localhost:' + server.port,
|
2018-08-21 10:34:18 +02:00
|
|
|
token: server.accessToken,
|
2020-12-07 14:32:36 +01:00
|
|
|
statusCodeExpected: HttpStatusCode.NOT_FOUND_404
|
2018-08-21 10:34:18 +02:00
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
it('Should succeed with the correct parameters', async function () {
|
|
|
|
await makeGetRequest({
|
|
|
|
url: server.url,
|
2019-04-24 15:10:37 +02:00
|
|
|
path: path + '/user1_channel@localhost:' + server.port,
|
2018-08-21 10:34:18 +02:00
|
|
|
token: server.accessToken,
|
2020-12-07 14:32:36 +01:00
|
|
|
statusCodeExpected: HttpStatusCode.OK_200
|
2018-08-21 10:34:18 +02:00
|
|
|
})
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
2019-02-21 14:28:06 +01:00
|
|
|
describe('When checking if subscriptions exist', function () {
|
2018-08-23 17:58:39 +02:00
|
|
|
const existPath = path + '/exist'
|
|
|
|
|
|
|
|
it('Should fail with a non authenticated user', async function () {
|
|
|
|
await makeGetRequest({
|
|
|
|
url: server.url,
|
|
|
|
path: existPath,
|
2020-12-07 14:32:36 +01:00
|
|
|
statusCodeExpected: HttpStatusCode.UNAUTHORIZED_401
|
2018-08-23 17:58:39 +02:00
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
it('Should fail with bad URIs', async function () {
|
|
|
|
await makeGetRequest({
|
|
|
|
url: server.url,
|
|
|
|
path: existPath,
|
|
|
|
query: { uris: 'toto' },
|
|
|
|
token: server.accessToken,
|
2020-12-07 14:32:36 +01:00
|
|
|
statusCodeExpected: HttpStatusCode.BAD_REQUEST_400
|
2018-08-23 17:58:39 +02:00
|
|
|
})
|
|
|
|
|
|
|
|
await makeGetRequest({
|
|
|
|
url: server.url,
|
|
|
|
path: existPath,
|
|
|
|
query: { 'uris[]': 1 },
|
|
|
|
token: server.accessToken,
|
2020-12-07 14:32:36 +01:00
|
|
|
statusCodeExpected: HttpStatusCode.BAD_REQUEST_400
|
2018-08-23 17:58:39 +02:00
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
it('Should succeed with the correct parameters', async function () {
|
|
|
|
await makeGetRequest({
|
|
|
|
url: server.url,
|
|
|
|
path: existPath,
|
2019-04-24 15:10:37 +02:00
|
|
|
query: { 'uris[]': 'coucou@localhost:' + server.port },
|
2018-08-23 17:58:39 +02:00
|
|
|
token: server.accessToken,
|
2020-12-07 14:32:36 +01:00
|
|
|
statusCodeExpected: HttpStatusCode.OK_200
|
2018-08-23 17:58:39 +02:00
|
|
|
})
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
2018-08-16 15:25:20 +02:00
|
|
|
describe('When removing a subscription', function () {
|
|
|
|
it('Should fail with a non authenticated user', async function () {
|
|
|
|
await makeDeleteRequest({
|
|
|
|
url: server.url,
|
2019-04-24 15:10:37 +02:00
|
|
|
path: path + '/user1_channel@localhost:' + server.port,
|
2020-12-07 14:32:36 +01:00
|
|
|
statusCodeExpected: HttpStatusCode.UNAUTHORIZED_401
|
2018-08-16 15:25:20 +02:00
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
it('Should fail with bad URIs', async function () {
|
|
|
|
await makeDeleteRequest({
|
|
|
|
url: server.url,
|
|
|
|
path: path + '/root',
|
|
|
|
token: server.accessToken,
|
2020-12-07 14:32:36 +01:00
|
|
|
statusCodeExpected: HttpStatusCode.BAD_REQUEST_400
|
2018-08-16 15:25:20 +02:00
|
|
|
})
|
|
|
|
|
|
|
|
await makeDeleteRequest({
|
|
|
|
url: server.url,
|
|
|
|
path: path + '/root@',
|
|
|
|
token: server.accessToken,
|
2020-12-07 14:32:36 +01:00
|
|
|
statusCodeExpected: HttpStatusCode.BAD_REQUEST_400
|
2018-08-16 15:25:20 +02:00
|
|
|
})
|
|
|
|
|
|
|
|
await makeDeleteRequest({
|
|
|
|
url: server.url,
|
|
|
|
path: path + '/root@hello@',
|
|
|
|
token: server.accessToken,
|
2020-12-07 14:32:36 +01:00
|
|
|
statusCodeExpected: HttpStatusCode.BAD_REQUEST_400
|
2018-08-16 15:25:20 +02:00
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
it('Should fail with an unknown subscription', async function () {
|
|
|
|
await makeDeleteRequest({
|
|
|
|
url: server.url,
|
2019-04-24 15:10:37 +02:00
|
|
|
path: path + '/root1@localhost:' + server.port,
|
2018-08-16 15:25:20 +02:00
|
|
|
token: server.accessToken,
|
2020-12-07 14:32:36 +01:00
|
|
|
statusCodeExpected: HttpStatusCode.NOT_FOUND_404
|
2018-08-16 15:25:20 +02:00
|
|
|
})
|
|
|
|
})
|
|
|
|
|
2018-08-21 10:34:18 +02:00
|
|
|
it('Should succeed with the correct parameters', async function () {
|
2018-08-16 15:25:20 +02:00
|
|
|
await makeDeleteRequest({
|
|
|
|
url: server.url,
|
2019-04-24 15:10:37 +02:00
|
|
|
path: path + '/user1_channel@localhost:' + server.port,
|
2018-08-16 15:25:20 +02:00
|
|
|
token: server.accessToken,
|
2020-12-07 14:32:36 +01:00
|
|
|
statusCodeExpected: HttpStatusCode.NO_CONTENT_204
|
2018-08-16 15:25:20 +02:00
|
|
|
})
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
2019-04-24 15:10:37 +02:00
|
|
|
after(async function () {
|
|
|
|
await cleanupTests([ server ])
|
2018-08-16 15:25:20 +02:00
|
|
|
})
|
|
|
|
})
|