1
0
Fork 0
peertube/server/tests/api/check-params/user-subscriptions.ts

299 lines
8.5 KiB
TypeScript
Raw Normal View History

2020-01-31 15:56:52 +00:00
/* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
import {
2019-04-24 13:10:37 +00:00
cleanupTests,
2021-07-16 07:47:51 +00:00
createSingleServer,
makeDeleteRequest,
makeGetRequest,
makePostBodyRequest,
2021-07-16 07:47:51 +00:00
PeerTubeServer,
2021-07-16 08:42:24 +00:00
setAccessTokensToServers,
waitJobs
} from '@shared/server-commands'
2021-07-16 08:42:24 +00:00
import { HttpStatusCode } from '@shared/models'
import { checkBadStartPagination, checkBadCountPagination, checkBadSortPagination } from '@server/tests/shared'
describe('Test user subscriptions API validators', function () {
const path = '/api/v1/users/me/subscriptions'
2021-07-16 07:47:51 +00:00
let server: PeerTubeServer
let userAccessToken = ''
// ---------------------------------------------------------------
before(async function () {
this.timeout(30000)
2021-07-16 07:47:51 +00:00
server = await createSingleServer(1)
await setAccessTokensToServers([ server ])
const user = {
username: 'user1',
password: 'my super password'
}
2021-07-16 07:04:35 +00:00
await server.users.create({ username: user.username, password: user.password })
userAccessToken = await server.login.getAccessToken(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,
2021-07-16 08:42:24 +00:00
expectedStatus: HttpStatusCode.UNAUTHORIZED_401
})
})
2018-08-21 08:34:18 +00:00
it('Should succeed with the correct parameters', async function () {
2018-08-17 13:45:42 +00:00
await makeGetRequest({
url: server.url,
path,
token: userAccessToken,
2021-07-16 08:42:24 +00:00
expectedStatus: HttpStatusCode.OK_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,
2021-07-16 08:42:24 +00:00
expectedStatus: HttpStatusCode.UNAUTHORIZED_401
})
})
2018-08-21 08:34:18 +00:00
it('Should succeed with the correct parameters', async function () {
2018-08-17 13:45:42 +00:00
await makeGetRequest({
url: server.url,
path,
token: userAccessToken,
2021-07-16 08:42:24 +00:00
expectedStatus: HttpStatusCode.OK_200
})
})
})
describe('When adding a subscription', function () {
it('Should fail with a non authenticated user', async function () {
await makePostBodyRequest({
url: server.url,
path,
2022-12-09 10:14:47 +00:00
fields: { uri: 'user1_channel@' + server.host },
2021-07-16 08:42:24 +00:00
expectedStatus: HttpStatusCode.UNAUTHORIZED_401
})
})
it('Should fail with bad URIs', async function () {
await makePostBodyRequest({
url: server.url,
path,
token: server.accessToken,
fields: { uri: 'root' },
2021-07-16 08:42:24 +00:00
expectedStatus: HttpStatusCode.BAD_REQUEST_400
})
await makePostBodyRequest({
url: server.url,
path,
token: server.accessToken,
fields: { uri: 'root@' },
2021-07-16 08:42:24 +00:00
expectedStatus: HttpStatusCode.BAD_REQUEST_400
})
await makePostBodyRequest({
url: server.url,
path,
token: server.accessToken,
fields: { uri: 'root@hello@' },
2021-07-16 08:42:24 +00:00
expectedStatus: HttpStatusCode.BAD_REQUEST_400
})
})
2018-08-21 08:34:18 +00:00
it('Should succeed with the correct parameters', async function () {
2018-11-16 10:18:13 +00:00
this.timeout(20000)
await makePostBodyRequest({
url: server.url,
path,
token: server.accessToken,
2022-12-09 10:14:47 +00:00
fields: { uri: 'user1_channel@' + server.host },
2021-07-16 08:42:24 +00:00
expectedStatus: HttpStatusCode.NO_CONTENT_204
})
2018-11-16 10:18:13 +00:00
await waitJobs([ server ])
})
})
2018-08-21 08:34:18 +00:00
describe('When getting a subscription', function () {
it('Should fail with a non authenticated user', async function () {
await makeGetRequest({
url: server.url,
2022-12-09 10:14:47 +00:00
path: path + '/user1_channel@' + server.host,
2021-07-16 08:42:24 +00:00
expectedStatus: HttpStatusCode.UNAUTHORIZED_401
2018-08-21 08:34:18 +00:00
})
})
it('Should fail with bad URIs', async function () {
await makeGetRequest({
url: server.url,
path: path + '/root',
token: server.accessToken,
2021-07-16 08:42:24 +00:00
expectedStatus: HttpStatusCode.BAD_REQUEST_400
2018-08-21 08:34:18 +00:00
})
await makeGetRequest({
url: server.url,
path: path + '/root@',
token: server.accessToken,
2021-07-16 08:42:24 +00:00
expectedStatus: HttpStatusCode.BAD_REQUEST_400
2018-08-21 08:34:18 +00:00
})
await makeGetRequest({
url: server.url,
path: path + '/root@hello@',
token: server.accessToken,
2021-07-16 08:42:24 +00:00
expectedStatus: HttpStatusCode.BAD_REQUEST_400
2018-08-21 08:34:18 +00:00
})
})
it('Should fail with an unknown subscription', async function () {
await makeGetRequest({
url: server.url,
2022-12-09 10:14:47 +00:00
path: path + '/root1@' + server.host,
2018-08-21 08:34:18 +00:00
token: server.accessToken,
2021-07-16 08:42:24 +00:00
expectedStatus: HttpStatusCode.NOT_FOUND_404
2018-08-21 08:34:18 +00:00
})
})
it('Should succeed with the correct parameters', async function () {
await makeGetRequest({
url: server.url,
2022-12-09 10:14:47 +00:00
path: path + '/user1_channel@' + server.host,
2018-08-21 08:34:18 +00:00
token: server.accessToken,
2021-07-16 08:42:24 +00:00
expectedStatus: HttpStatusCode.OK_200
2018-08-21 08:34:18 +00:00
})
})
})
2019-02-21 13:28:06 +00:00
describe('When checking if subscriptions exist', function () {
2018-08-23 15:58:39 +00:00
const existPath = path + '/exist'
it('Should fail with a non authenticated user', async function () {
await makeGetRequest({
url: server.url,
path: existPath,
2021-07-16 08:42:24 +00:00
expectedStatus: HttpStatusCode.UNAUTHORIZED_401
2018-08-23 15:58:39 +00:00
})
})
it('Should fail with bad URIs', async function () {
await makeGetRequest({
url: server.url,
path: existPath,
query: { uris: 'toto' },
token: server.accessToken,
2021-07-16 08:42:24 +00:00
expectedStatus: HttpStatusCode.BAD_REQUEST_400
2018-08-23 15:58:39 +00:00
})
await makeGetRequest({
url: server.url,
path: existPath,
query: { 'uris[]': 1 },
token: server.accessToken,
2021-07-16 08:42:24 +00:00
expectedStatus: HttpStatusCode.BAD_REQUEST_400
2018-08-23 15:58:39 +00:00
})
})
it('Should succeed with the correct parameters', async function () {
await makeGetRequest({
url: server.url,
path: existPath,
2022-12-09 10:14:47 +00:00
query: { 'uris[]': 'coucou@' + server.host },
2018-08-23 15:58:39 +00:00
token: server.accessToken,
2021-07-16 08:42:24 +00:00
expectedStatus: HttpStatusCode.OK_200
2018-08-23 15:58:39 +00:00
})
})
})
describe('When removing a subscription', function () {
it('Should fail with a non authenticated user', async function () {
await makeDeleteRequest({
url: server.url,
2022-12-09 10:14:47 +00:00
path: path + '/user1_channel@' + server.host,
2021-07-16 08:42:24 +00:00
expectedStatus: HttpStatusCode.UNAUTHORIZED_401
})
})
it('Should fail with bad URIs', async function () {
await makeDeleteRequest({
url: server.url,
path: path + '/root',
token: server.accessToken,
2021-07-16 08:42:24 +00:00
expectedStatus: HttpStatusCode.BAD_REQUEST_400
})
await makeDeleteRequest({
url: server.url,
path: path + '/root@',
token: server.accessToken,
2021-07-16 08:42:24 +00:00
expectedStatus: HttpStatusCode.BAD_REQUEST_400
})
await makeDeleteRequest({
url: server.url,
path: path + '/root@hello@',
token: server.accessToken,
2021-07-16 08:42:24 +00:00
expectedStatus: HttpStatusCode.BAD_REQUEST_400
})
})
it('Should fail with an unknown subscription', async function () {
await makeDeleteRequest({
url: server.url,
2022-12-09 10:14:47 +00:00
path: path + '/root1@' + server.host,
token: server.accessToken,
2021-07-16 08:42:24 +00:00
expectedStatus: HttpStatusCode.NOT_FOUND_404
})
})
2018-08-21 08:34:18 +00:00
it('Should succeed with the correct parameters', async function () {
await makeDeleteRequest({
url: server.url,
2022-12-09 10:14:47 +00:00
path: path + '/user1_channel@' + server.host,
token: server.accessToken,
2021-07-16 08:42:24 +00:00
expectedStatus: HttpStatusCode.NO_CONTENT_204
})
})
})
2019-04-24 13:10:37 +00:00
after(async function () {
await cleanupTests([ server ])
})
})