123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306 |
- /* tslint:disable:no-unused-expression */
- import 'mocha'
- import {
- cleanupTests,
- createUser,
- flushAndRunServer,
- makeDeleteRequest,
- makeGetRequest,
- makePostBodyRequest,
- ServerInfo,
- setAccessTokensToServers,
- userLogin
- } from '../../../../shared/extra-utils'
- import {
- checkBadCountPagination,
- checkBadSortPagination,
- checkBadStartPagination
- } from '../../../../shared/extra-utils/requests/check-api-params'
- import { waitJobs } from '../../../../shared/extra-utils/server/jobs'
- 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)
- server = await flushAndRunServer(1)
- await setAccessTokensToServers([ server ])
- const user = {
- username: 'user1',
- password: 'my super password'
- }
- await createUser({ url: server.url, accessToken: server.accessToken, username: user.username, password: user.password })
- 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
- })
- })
- it('Should succeed with the correct parameters', async function () {
- await makeGetRequest({
- 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
- })
- })
- it('Should succeed with the correct parameters', async function () {
- await makeGetRequest({
- 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,
- fields: { uri: 'user1_channel@localhost:' + server.port },
- 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
- })
- })
- it('Should succeed with the correct parameters', async function () {
- this.timeout(20000)
- await makePostBodyRequest({
- url: server.url,
- path,
- token: server.accessToken,
- fields: { uri: 'user1_channel@localhost:' + server.port },
- statusCodeExpected: 204
- })
- await waitJobs([ server ])
- })
- })
- 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:' + server.port,
- 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:' + server.port,
- token: server.accessToken,
- statusCodeExpected: 404
- })
- })
- it('Should succeed with the correct parameters', async function () {
- await makeGetRequest({
- url: server.url,
- path: path + '/user1_channel@localhost:' + server.port,
- token: server.accessToken,
- statusCodeExpected: 200
- })
- })
- })
- describe('When checking if subscriptions exist', function () {
- 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:' + server.port },
- token: server.accessToken,
- statusCodeExpected: 200
- })
- })
- })
- describe('When removing a subscription', function () {
- it('Should fail with a non authenticated user', async function () {
- await makeDeleteRequest({
- url: server.url,
- path: path + '/user1_channel@localhost:' + server.port,
- 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:' + server.port,
- token: server.accessToken,
- statusCodeExpected: 404
- })
- })
- it('Should succeed with the correct parameters', async function () {
- await makeDeleteRequest({
- url: server.url,
- path: path + '/user1_channel@localhost:' + server.port,
- token: server.accessToken,
- statusCodeExpected: 204
- })
- })
- })
- after(async function () {
- await cleanupTests([ server ])
- })
- })
|