X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=server%2Ftests%2Fapi%2Fcheck-params%2Fuser-subscriptions.ts;h=a13ed5aa3eab1edf9cc6b5ae4e0ee529b41814e6;hb=1bb4c9ab2e8b3b3022351b33a82a5e527fa5d4d7;hp=628a744760bb1f93e6f6dbccda6d240685aeb3bd;hpb=8a19bee1a1ee39f973bb37429e4f73c3f2873cdb;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 628a74476..a13ed5aa3 100644 --- a/server/tests/api/check-params/user-subscriptions.ts +++ b/server/tests/api/check-params/user-subscriptions.ts @@ -1,24 +1,22 @@ -/* tslint:disable:no-unused-expression */ +/* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */ import 'mocha' - import { - createUser, - flushTests, - killallServers, + cleanupTests, + createSingleServer, makeDeleteRequest, makeGetRequest, makePostBodyRequest, - runServer, - ServerInfo, + PeerTubeServer, setAccessTokensToServers, - userLogin -} from '../../utils' -import { checkBadCountPagination, checkBadSortPagination, checkBadStartPagination } from '../../utils/requests/check-api-params' + waitJobs +} from '@shared/server-commands' +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' - let server: ServerInfo + let server: PeerTubeServer let userAccessToken = '' // --------------------------------------------------------------- @@ -26,9 +24,7 @@ describe('Test user subscriptions API validators', function () { before(async function () { this.timeout(30000) - await flushTests() - - server = await runServer(1) + server = await createSingleServer(1) await setAccessTokensToServers([ server ]) @@ -36,8 +32,8 @@ describe('Test user subscriptions API validators', function () { username: 'user1', password: 'my super password' } - await createUser(server.url, server.accessToken, user.username, user.password) - userAccessToken = await userLogin(server, user) + await server.users.create({ username: user.username, password: user.password }) + userAccessToken = await server.login.getAccessToken(user) }) describe('When listing my subscriptions', function () { @@ -57,16 +53,16 @@ describe('Test user subscriptions API validators', function () { await makeGetRequest({ url: server.url, path, - statusCodeExpected: 401 + expectedStatus: HttpStatusCode.UNAUTHORIZED_401 }) }) - it('Should success with the correct parameters', async function () { + it('Should succeed with the correct parameters', async function () { await makeGetRequest({ url: server.url, path, token: userAccessToken, - statusCodeExpected: 200 + expectedStatus: HttpStatusCode.OK_200 }) }) }) @@ -90,16 +86,16 @@ describe('Test user subscriptions API validators', function () { await makeGetRequest({ url: server.url, path, - statusCodeExpected: 401 + expectedStatus: HttpStatusCode.UNAUTHORIZED_401 }) }) - it('Should success with the correct parameters', async function () { + it('Should succeed with the correct parameters', async function () { await makeGetRequest({ url: server.url, path, token: userAccessToken, - statusCodeExpected: 200 + expectedStatus: HttpStatusCode.OK_200 }) }) }) @@ -109,8 +105,8 @@ describe('Test user subscriptions API validators', function () { await makePostBodyRequest({ url: server.url, path, - fields: { uri: 'user1_channel@localhost:9001' }, - statusCodeExpected: 401 + fields: { uri: 'user1_channel@localhost:' + server.port }, + expectedStatus: HttpStatusCode.UNAUTHORIZED_401 }) }) @@ -120,7 +116,7 @@ describe('Test user subscriptions API validators', function () { path, token: server.accessToken, fields: { uri: 'root' }, - statusCodeExpected: 400 + expectedStatus: HttpStatusCode.BAD_REQUEST_400 }) await makePostBodyRequest({ @@ -128,7 +124,7 @@ describe('Test user subscriptions API validators', function () { path, token: server.accessToken, fields: { uri: 'root@' }, - statusCodeExpected: 400 + expectedStatus: HttpStatusCode.BAD_REQUEST_400 }) await makePostBodyRequest({ @@ -136,17 +132,112 @@ describe('Test user subscriptions API validators', function () { path, token: server.accessToken, fields: { uri: 'root@hello@' }, - statusCodeExpected: 400 + expectedStatus: 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: 'user1_channel@localhost:9001' }, - statusCodeExpected: 204 + fields: { uri: 'user1_channel@localhost:' + server.port }, + expectedStatus: 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, + expectedStatus: HttpStatusCode.UNAUTHORIZED_401 + }) + }) + + it('Should fail with bad URIs', async function () { + await makeGetRequest({ + url: server.url, + path: path + '/root', + token: server.accessToken, + expectedStatus: HttpStatusCode.BAD_REQUEST_400 + }) + + await makeGetRequest({ + url: server.url, + path: path + '/root@', + token: server.accessToken, + expectedStatus: HttpStatusCode.BAD_REQUEST_400 + }) + + await makeGetRequest({ + url: server.url, + path: path + '/root@hello@', + token: server.accessToken, + expectedStatus: 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, + expectedStatus: 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, + expectedStatus: 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, + expectedStatus: HttpStatusCode.UNAUTHORIZED_401 + }) + }) + + it('Should fail with bad URIs', async function () { + await makeGetRequest({ + url: server.url, + path: existPath, + query: { uris: 'toto' }, + token: server.accessToken, + expectedStatus: HttpStatusCode.BAD_REQUEST_400 + }) + + await makeGetRequest({ + url: server.url, + path: existPath, + query: { 'uris[]': 1 }, + token: server.accessToken, + expectedStatus: 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, + expectedStatus: HttpStatusCode.OK_200 }) }) }) @@ -155,8 +246,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 + '/user1_channel@localhost:9001', - statusCodeExpected: 401 + path: path + '/user1_channel@localhost:' + server.port, + expectedStatus: HttpStatusCode.UNAUTHORIZED_401 }) }) @@ -165,49 +256,44 @@ describe('Test user subscriptions API validators', function () { url: server.url, path: path + '/root', token: server.accessToken, - statusCodeExpected: 400 + expectedStatus: HttpStatusCode.BAD_REQUEST_400 }) await makeDeleteRequest({ url: server.url, path: path + '/root@', token: server.accessToken, - statusCodeExpected: 400 + expectedStatus: HttpStatusCode.BAD_REQUEST_400 }) await makeDeleteRequest({ url: server.url, path: path + '/root@hello@', token: server.accessToken, - statusCodeExpected: 400 + expectedStatus: 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 + expectedStatus: 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 + '/user1_channel@localhost:9001', + path: path + '/user1_channel@localhost:' + server.port, token: server.accessToken, - statusCodeExpected: 204 + expectedStatus: HttpStatusCode.NO_CONTENT_204 }) }) }) after(async function () { - killallServers([ server ]) - - // Keep the logs if the test failed - if (this['ok']) { - await flushTests() - } + await cleanupTests([ server ]) }) })