X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=server%2Ftests%2Fapi%2Fcheck-params%2Fuser-subscriptions.ts;h=04a3eb97c43cb7a80dac3d83e45e59c7d9402f33;hb=883993c81ecc2388d4a4b37b29b81b6de73d264f;hp=9f7d15b27aa65c5af8b79a9a95a159201f77cb31;hpb=06a05d5f4784a7cbb27aa1188385b5679845dad8;p=github%2FChocobozzz%2FPeerTube.git diff --git a/server/tests/api/check-params/user-subscriptions.ts b/server/tests/api/check-params/user-subscriptions.ts index 9f7d15b27..04a3eb97c 100644 --- a/server/tests/api/check-params/user-subscriptions.ts +++ b/server/tests/api/check-params/user-subscriptions.ts @@ -5,7 +5,6 @@ import 'mocha' import { createUser, flushTests, - getMyUserInformation, killallServers, makeDeleteRequest, makeGetRequest, @@ -14,14 +13,19 @@ import { ServerInfo, setAccessTokensToServers, userLogin -} from '../../utils' -import { checkBadCountPagination, checkBadSortPagination, checkBadStartPagination } from '../../utils/requests/check-api-params' +} from '../../../../shared/utils' + +import { + checkBadCountPagination, + checkBadSortPagination, + checkBadStartPagination +} from '../../../../shared/utils/requests/check-api-params' +import { waitJobs } from '../../../../shared/utils/server/jobs' describe('Test user subscriptions API validators', function () { const path = '/api/v1/users/me/subscriptions' let server: ServerInfo let userAccessToken = '' - let userChannelUUID: string // --------------------------------------------------------------- @@ -40,11 +44,6 @@ describe('Test user subscriptions API validators', function () { } await createUser(server.url, server.accessToken, user.username, user.password) userAccessToken = await userLogin(server, user) - - { - const res = await getMyUserInformation(server.url, server.accessToken) - userChannelUUID = res.body.videoChannels[ 0 ].uuid - } }) describe('When listing my subscriptions', function () { @@ -68,8 +67,8 @@ describe('Test user subscriptions API validators', function () { }) }) - it('Should success with the correct parameters', async function () { - await await makeGetRequest({ + it('Should succeed with the correct parameters', async function () { + await makeGetRequest({ url: server.url, path, token: userAccessToken, @@ -101,8 +100,8 @@ describe('Test user subscriptions API validators', function () { }) }) - it('Should success with the correct parameters', async function () { - await await makeGetRequest({ + it('Should succeed with the correct parameters', async function () { + await makeGetRequest({ url: server.url, path, token: userAccessToken, @@ -116,7 +115,7 @@ describe('Test user subscriptions API validators', function () { await makePostBodyRequest({ url: server.url, path, - fields: { uri: userChannelUUID + '@localhost:9001' }, + fields: { uri: 'user1_channel@localhost:9001' }, statusCodeExpected: 401 }) }) @@ -147,14 +146,109 @@ describe('Test user subscriptions API validators', function () { }) }) - it('Should success with the correct parameters', async function () { + it('Should succeed with the correct parameters', async function () { + this.timeout(20000) + await makePostBodyRequest({ url: server.url, path, token: server.accessToken, - fields: { uri: userChannelUUID + '@localhost:9001' }, + fields: { uri: 'user1_channel@localhost:9001' }, 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: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 + }) + }) + }) + + 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:9001' }, + token: server.accessToken, + statusCodeExpected: 200 + }) }) }) @@ -162,7 +256,7 @@ describe('Test user subscriptions API validators', function () { it('Should fail with a non authenticated user', async function () { await makeDeleteRequest({ url: server.url, - path: path + '/' + userChannelUUID + '@localhost:9001', + path: path + '/user1_channel@localhost:9001', statusCodeExpected: 401 }) }) @@ -199,10 +293,10 @@ describe('Test user subscriptions API validators', function () { }) }) - it('Should success with the correct parameters', async function () { + it('Should succeed with the correct parameters', async function () { await makeDeleteRequest({ url: server.url, - path: path + '/' + userChannelUUID + '@localhost:9001', + path: path + '/user1_channel@localhost:9001', token: server.accessToken, statusCodeExpected: 204 })