X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=server%2Ftests%2Fapi%2Fcheck-params%2Fuser-subscriptions.ts;h=fa36c40780c7be91b9e0b663907107ab30a4d766;hb=97ecddae104f4013d261f0e9645e8b319ff0f1a6;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..fa36c4078 100644 --- a/server/tests/api/check-params/user-subscriptions.ts +++ b/server/tests/api/check-params/user-subscriptions.ts @@ -3,18 +3,23 @@ import 'mocha' import { + cleanupTests, createUser, - flushTests, - 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' describe('Test user subscriptions API validators', function () { const path = '/api/v1/users/me/subscriptions' @@ -26,9 +31,7 @@ describe('Test user subscriptions API validators', function () { before(async function () { this.timeout(30000) - await flushTests() - - server = await runServer(1) + server = await flushAndRunServer(1) await setAccessTokensToServers([ server ]) @@ -36,7 +39,7 @@ 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) }) @@ -61,7 +64,7 @@ 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 makeGetRequest({ url: server.url, path, @@ -94,7 +97,7 @@ 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 makeGetRequest({ url: server.url, path, @@ -109,7 +112,7 @@ describe('Test user subscriptions API validators', function () { await makePostBodyRequest({ url: server.url, path, - fields: { uri: 'user1_channel@localhost:9001' }, + fields: { uri: 'user1_channel@localhost:' + server.port }, statusCodeExpected: 401 }) }) @@ -140,14 +143,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: 'user1_channel@localhost:9001' }, + 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 + }) }) }) @@ -155,7 +253,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 + '/user1_channel@localhost:9001', + path: path + '/user1_channel@localhost:' + server.port, statusCodeExpected: 401 }) }) @@ -186,16 +284,16 @@ describe('Test user subscriptions API validators', function () { 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 }) }) - 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 }) @@ -203,11 +301,6 @@ describe('Test user subscriptions API validators', function () { }) after(async function () { - killallServers([ server ]) - - // Keep the logs if the test failed - if (this['ok']) { - await flushTests() - } + await cleanupTests([ server ]) }) })