X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=server%2Ftests%2Fapi%2Fcheck-params%2Fuser-subscriptions.ts;h=538201647417a259e3df5194e908442133c6a792;hb=a54618880c394ad7571f3f3222dc96ec2dd10d9a;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..538201647 100644 --- a/server/tests/api/check-params/user-subscriptions.ts +++ b/server/tests/api/check-params/user-subscriptions.ts @@ -1,36 +1,38 @@ -/* tslint:disable:no-unused-expression */ +/* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */ import 'mocha' import { + cleanupTests, createUser, - flushTests, - getMyUserInformation, - killallServers, + flushAndRunServer, makeDeleteRequest, makeGetRequest, makePostBodyRequest, - runServer, ServerInfo, setAccessTokensToServers, userLogin -} from '../../utils' -import { checkBadCountPagination, checkBadSortPagination, checkBadStartPagination } from '../../utils/requests/check-api-params' +} from '../../../../shared/extra-utils' + +import { + checkBadCountPagination, + checkBadSortPagination, + checkBadStartPagination +} from '../../../../shared/extra-utils/requests/check-api-params' +import { waitJobs } from '../../../../shared/extra-utils/server/jobs' +import { HttpStatusCode } from '../../../../shared/core-utils/miscs/http-error-codes' describe('Test user subscriptions API validators', function () { const path = '/api/v1/users/me/subscriptions' let server: ServerInfo let userAccessToken = '' - let userChannelUUID: string // --------------------------------------------------------------- before(async function () { this.timeout(30000) - await flushTests() - - server = await runServer(1) + server = await flushAndRunServer(1) await setAccessTokensToServers([ server ]) @@ -38,13 +40,8 @@ describe('Test user subscriptions API validators', function () { username: 'user1', password: 'my super password' } - await createUser(server.url, server.accessToken, user.username, user.password) + await createUser({ url: server.url, accessToken: server.accessToken, username: user.username, password: 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 () { @@ -64,16 +61,16 @@ describe('Test user subscriptions API validators', function () { await makeGetRequest({ url: server.url, path, - statusCodeExpected: 401 + statusCodeExpected: HttpStatusCode.UNAUTHORIZED_401 }) }) - 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, - statusCodeExpected: 200 + statusCodeExpected: HttpStatusCode.OK_200 }) }) }) @@ -97,16 +94,16 @@ describe('Test user subscriptions API validators', function () { await makeGetRequest({ url: server.url, path, - statusCodeExpected: 401 + statusCodeExpected: HttpStatusCode.UNAUTHORIZED_401 }) }) - 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, - statusCodeExpected: 200 + statusCodeExpected: HttpStatusCode.OK_200 }) }) }) @@ -116,8 +113,8 @@ describe('Test user subscriptions API validators', function () { await makePostBodyRequest({ url: server.url, path, - fields: { uri: userChannelUUID + '@localhost:9001' }, - statusCodeExpected: 401 + fields: { uri: 'user1_channel@localhost:' + server.port }, + statusCodeExpected: HttpStatusCode.UNAUTHORIZED_401 }) }) @@ -127,7 +124,7 @@ describe('Test user subscriptions API validators', function () { path, token: server.accessToken, fields: { uri: 'root' }, - statusCodeExpected: 400 + statusCodeExpected: HttpStatusCode.BAD_REQUEST_400 }) await makePostBodyRequest({ @@ -135,7 +132,7 @@ describe('Test user subscriptions API validators', function () { path, token: server.accessToken, fields: { uri: 'root@' }, - statusCodeExpected: 400 + statusCodeExpected: HttpStatusCode.BAD_REQUEST_400 }) await makePostBodyRequest({ @@ -143,17 +140,112 @@ describe('Test user subscriptions API validators', function () { path, token: server.accessToken, fields: { uri: 'root@hello@' }, - statusCodeExpected: 400 + statusCodeExpected: HttpStatusCode.BAD_REQUEST_400 }) }) - 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' }, - statusCodeExpected: 204 + fields: { uri: 'user1_channel@localhost:' + server.port }, + statusCodeExpected: HttpStatusCode.NO_CONTENT_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: HttpStatusCode.UNAUTHORIZED_401 + }) + }) + + it('Should fail with bad URIs', async function () { + await makeGetRequest({ + url: server.url, + path: path + '/root', + token: server.accessToken, + statusCodeExpected: HttpStatusCode.BAD_REQUEST_400 + }) + + await makeGetRequest({ + url: server.url, + path: path + '/root@', + token: server.accessToken, + statusCodeExpected: HttpStatusCode.BAD_REQUEST_400 + }) + + await makeGetRequest({ + url: server.url, + path: path + '/root@hello@', + token: server.accessToken, + statusCodeExpected: HttpStatusCode.BAD_REQUEST_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: HttpStatusCode.NOT_FOUND_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: HttpStatusCode.OK_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: HttpStatusCode.UNAUTHORIZED_401 + }) + }) + + it('Should fail with bad URIs', async function () { + await makeGetRequest({ + url: server.url, + path: existPath, + query: { uris: 'toto' }, + token: server.accessToken, + statusCodeExpected: HttpStatusCode.BAD_REQUEST_400 + }) + + await makeGetRequest({ + url: server.url, + path: existPath, + query: { 'uris[]': 1 }, + token: server.accessToken, + statusCodeExpected: HttpStatusCode.BAD_REQUEST_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: HttpStatusCode.OK_200 }) }) }) @@ -162,8 +254,8 @@ 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', - statusCodeExpected: 401 + path: path + '/user1_channel@localhost:' + server.port, + statusCodeExpected: HttpStatusCode.UNAUTHORIZED_401 }) }) @@ -172,49 +264,44 @@ describe('Test user subscriptions API validators', function () { url: server.url, path: path + '/root', token: server.accessToken, - statusCodeExpected: 400 + statusCodeExpected: HttpStatusCode.BAD_REQUEST_400 }) await makeDeleteRequest({ url: server.url, path: path + '/root@', token: server.accessToken, - statusCodeExpected: 400 + statusCodeExpected: HttpStatusCode.BAD_REQUEST_400 }) await makeDeleteRequest({ url: server.url, path: path + '/root@hello@', token: server.accessToken, - statusCodeExpected: 400 + statusCodeExpected: HttpStatusCode.BAD_REQUEST_400 }) }) it('Should fail with an unknown subscription', async function () { await makeDeleteRequest({ url: server.url, - path: path + '/root1@localhost:9001', + path: path + '/root1@localhost:' + server.port, token: server.accessToken, - statusCodeExpected: 404 + statusCodeExpected: HttpStatusCode.NOT_FOUND_404 }) }) - 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:' + server.port, token: server.accessToken, - statusCodeExpected: 204 + statusCodeExpected: HttpStatusCode.NO_CONTENT_204 }) }) }) after(async function () { - killallServers([ server ]) - - // Keep the logs if the test failed - if (this['ok']) { - await flushTests() - } + await cleanupTests([ server ]) }) })