2018-08-16 08:25:20 -05:00
|
|
|
/* tslint:disable:no-unused-expression */
|
|
|
|
|
|
|
|
import 'mocha'
|
|
|
|
|
|
|
|
import {
|
|
|
|
createUser,
|
|
|
|
flushTests,
|
|
|
|
killallServers,
|
|
|
|
makeDeleteRequest,
|
|
|
|
makeGetRequest,
|
|
|
|
makePostBodyRequest,
|
|
|
|
runServer,
|
|
|
|
ServerInfo,
|
|
|
|
setAccessTokensToServers,
|
|
|
|
userLogin
|
2018-10-29 11:48:31 -05:00
|
|
|
} from '../../../../shared/utils'
|
2018-11-18 10:25:52 -06:00
|
|
|
|
2018-10-29 11:48:31 -05:00
|
|
|
import {
|
|
|
|
checkBadCountPagination,
|
|
|
|
checkBadSortPagination,
|
|
|
|
checkBadStartPagination
|
|
|
|
} from '../../../../shared/utils/requests/check-api-params'
|
2018-11-18 10:25:52 -06:00
|
|
|
import { waitJobs } from '../../../../shared/utils/server/jobs'
|
2018-08-16 08:25:20 -05: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)
|
|
|
|
|
|
|
|
await flushTests()
|
|
|
|
|
|
|
|
server = await runServer(1)
|
|
|
|
|
|
|
|
await setAccessTokensToServers([ server ])
|
|
|
|
|
|
|
|
const user = {
|
|
|
|
username: 'user1',
|
|
|
|
password: 'my super password'
|
|
|
|
}
|
2019-04-15 03:49:46 -05:00
|
|
|
await createUser({ url: server.url, accessToken: server.accessToken, username: user.username, password: user.password })
|
2018-08-16 08:25:20 -05: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,
|
|
|
|
statusCodeExpected: 401
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
2018-08-21 03:34:18 -05:00
|
|
|
it('Should succeed with the correct parameters', async function () {
|
2018-08-17 08:45:42 -05:00
|
|
|
await makeGetRequest({
|
2018-08-16 08:25:20 -05:00
|
|
|
url: server.url,
|
|
|
|
path,
|
|
|
|
token: userAccessToken,
|
|
|
|
statusCodeExpected: 200
|
|
|
|
})
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
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,
|
|
|
|
statusCodeExpected: 401
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
2018-08-21 03:34:18 -05:00
|
|
|
it('Should succeed with the correct parameters', async function () {
|
2018-08-17 08:45:42 -05:00
|
|
|
await makeGetRequest({
|
2018-08-16 08:25:20 -05:00
|
|
|
url: server.url,
|
|
|
|
path,
|
|
|
|
token: userAccessToken,
|
|
|
|
statusCodeExpected: 200
|
|
|
|
})
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
describe('When adding a subscription', function () {
|
|
|
|
it('Should fail with a non authenticated user', async function () {
|
|
|
|
await makePostBodyRequest({
|
|
|
|
url: server.url,
|
|
|
|
path,
|
2018-08-17 08:45:42 -05:00
|
|
|
fields: { uri: 'user1_channel@localhost:9001' },
|
2018-08-16 08:25:20 -05:00
|
|
|
statusCodeExpected: 401
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
it('Should fail with bad URIs', async function () {
|
|
|
|
await makePostBodyRequest({
|
|
|
|
url: server.url,
|
|
|
|
path,
|
|
|
|
token: server.accessToken,
|
|
|
|
fields: { uri: 'root' },
|
|
|
|
statusCodeExpected: 400
|
|
|
|
})
|
|
|
|
|
|
|
|
await makePostBodyRequest({
|
|
|
|
url: server.url,
|
|
|
|
path,
|
|
|
|
token: server.accessToken,
|
|
|
|
fields: { uri: 'root@' },
|
|
|
|
statusCodeExpected: 400
|
|
|
|
})
|
|
|
|
|
|
|
|
await makePostBodyRequest({
|
|
|
|
url: server.url,
|
|
|
|
path,
|
|
|
|
token: server.accessToken,
|
|
|
|
fields: { uri: 'root@hello@' },
|
|
|
|
statusCodeExpected: 400
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
2018-08-21 03:34:18 -05:00
|
|
|
it('Should succeed with the correct parameters', async function () {
|
2018-11-16 04:18:13 -06:00
|
|
|
this.timeout(20000)
|
|
|
|
|
2018-08-16 08:25:20 -05:00
|
|
|
await makePostBodyRequest({
|
|
|
|
url: server.url,
|
|
|
|
path,
|
|
|
|
token: server.accessToken,
|
2018-08-17 08:45:42 -05:00
|
|
|
fields: { uri: 'user1_channel@localhost:9001' },
|
2018-08-16 08:25:20 -05:00
|
|
|
statusCodeExpected: 204
|
|
|
|
})
|
2018-11-16 04:18:13 -06:00
|
|
|
|
|
|
|
await waitJobs([ server ])
|
2018-08-16 08:25:20 -05:00
|
|
|
})
|
|
|
|
})
|
|
|
|
|
2018-08-21 03:34:18 -05:00
|
|
|
describe('When getting a subscription', function () {
|
|
|
|
it('Should fail with a non authenticated user', async function () {
|
|
|
|
await makeGetRequest({
|
|
|
|
url: server.url,
|
|
|
|
path: path + '/user1_channel@localhost:9001',
|
|
|
|
statusCodeExpected: 401
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
it('Should fail with bad URIs', async function () {
|
|
|
|
await makeGetRequest({
|
|
|
|
url: server.url,
|
|
|
|
path: path + '/root',
|
|
|
|
token: server.accessToken,
|
|
|
|
statusCodeExpected: 400
|
|
|
|
})
|
|
|
|
|
|
|
|
await makeGetRequest({
|
|
|
|
url: server.url,
|
|
|
|
path: path + '/root@',
|
|
|
|
token: server.accessToken,
|
|
|
|
statusCodeExpected: 400
|
|
|
|
})
|
|
|
|
|
|
|
|
await makeGetRequest({
|
|
|
|
url: server.url,
|
|
|
|
path: path + '/root@hello@',
|
|
|
|
token: server.accessToken,
|
|
|
|
statusCodeExpected: 400
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
it('Should fail with an unknown subscription', async function () {
|
|
|
|
await makeGetRequest({
|
|
|
|
url: server.url,
|
|
|
|
path: path + '/root1@localhost:9001',
|
|
|
|
token: server.accessToken,
|
|
|
|
statusCodeExpected: 404
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
it('Should succeed with the correct parameters', async function () {
|
|
|
|
await makeGetRequest({
|
|
|
|
url: server.url,
|
|
|
|
path: path + '/user1_channel@localhost:9001',
|
|
|
|
token: server.accessToken,
|
|
|
|
statusCodeExpected: 200
|
|
|
|
})
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
2019-02-21 07:28:06 -06:00
|
|
|
describe('When checking if subscriptions exist', function () {
|
2018-08-23 10:58:39 -05:00
|
|
|
const existPath = path + '/exist'
|
|
|
|
|
|
|
|
it('Should fail with a non authenticated user', async function () {
|
|
|
|
await makeGetRequest({
|
|
|
|
url: server.url,
|
|
|
|
path: existPath,
|
|
|
|
statusCodeExpected: 401
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
it('Should fail with bad URIs', async function () {
|
|
|
|
await makeGetRequest({
|
|
|
|
url: server.url,
|
|
|
|
path: existPath,
|
|
|
|
query: { uris: 'toto' },
|
|
|
|
token: server.accessToken,
|
|
|
|
statusCodeExpected: 400
|
|
|
|
})
|
|
|
|
|
|
|
|
await makeGetRequest({
|
|
|
|
url: server.url,
|
|
|
|
path: existPath,
|
|
|
|
query: { 'uris[]': 1 },
|
|
|
|
token: server.accessToken,
|
|
|
|
statusCodeExpected: 400
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
it('Should succeed with the correct parameters', async function () {
|
|
|
|
await makeGetRequest({
|
|
|
|
url: server.url,
|
|
|
|
path: existPath,
|
|
|
|
query: { 'uris[]': 'coucou@localhost:9001' },
|
|
|
|
token: server.accessToken,
|
|
|
|
statusCodeExpected: 200
|
|
|
|
})
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
2018-08-16 08:25:20 -05:00
|
|
|
describe('When removing a subscription', function () {
|
|
|
|
it('Should fail with a non authenticated user', async function () {
|
|
|
|
await makeDeleteRequest({
|
|
|
|
url: server.url,
|
2018-08-17 08:45:42 -05:00
|
|
|
path: path + '/user1_channel@localhost:9001',
|
2018-08-16 08:25:20 -05:00
|
|
|
statusCodeExpected: 401
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
it('Should fail with bad URIs', async function () {
|
|
|
|
await makeDeleteRequest({
|
|
|
|
url: server.url,
|
|
|
|
path: path + '/root',
|
|
|
|
token: server.accessToken,
|
|
|
|
statusCodeExpected: 400
|
|
|
|
})
|
|
|
|
|
|
|
|
await makeDeleteRequest({
|
|
|
|
url: server.url,
|
|
|
|
path: path + '/root@',
|
|
|
|
token: server.accessToken,
|
|
|
|
statusCodeExpected: 400
|
|
|
|
})
|
|
|
|
|
|
|
|
await makeDeleteRequest({
|
|
|
|
url: server.url,
|
|
|
|
path: path + '/root@hello@',
|
|
|
|
token: server.accessToken,
|
|
|
|
statusCodeExpected: 400
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
it('Should fail with an unknown subscription', async function () {
|
|
|
|
await makeDeleteRequest({
|
|
|
|
url: server.url,
|
|
|
|
path: path + '/root1@localhost:9001',
|
|
|
|
token: server.accessToken,
|
|
|
|
statusCodeExpected: 404
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
2018-08-21 03:34:18 -05:00
|
|
|
it('Should succeed with the correct parameters', async function () {
|
2018-08-16 08:25:20 -05:00
|
|
|
await makeDeleteRequest({
|
|
|
|
url: server.url,
|
2018-08-17 08:45:42 -05:00
|
|
|
path: path + '/user1_channel@localhost:9001',
|
2018-08-16 08:25:20 -05:00
|
|
|
token: server.accessToken,
|
|
|
|
statusCodeExpected: 204
|
|
|
|
})
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
after(async function () {
|
|
|
|
killallServers([ server ])
|
|
|
|
|
|
|
|
// Keep the logs if the test failed
|
|
|
|
if (this['ok']) {
|
|
|
|
await flushTests()
|
|
|
|
}
|
|
|
|
})
|
|
|
|
})
|