From 8ef9457fdee7812b1a8cc3b3bdeff94130819003 Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Tue, 6 Jul 2021 10:36:54 +0200 Subject: Correctly export misc files --- server/tests/api/check-params/contact-form.ts | 5 ++--- server/tests/api/check-params/users.ts | 2 +- 2 files changed, 3 insertions(+), 4 deletions(-) (limited to 'server/tests/api/check-params') diff --git a/server/tests/api/check-params/contact-form.ts b/server/tests/api/check-params/contact-form.ts index c7f9c1b47..274562cbb 100644 --- a/server/tests/api/check-params/contact-form.ts +++ b/server/tests/api/check-params/contact-form.ts @@ -1,11 +1,10 @@ /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */ import 'mocha' - +import { HttpStatusCode } from '../../../../shared/core-utils/miscs/http-error-codes' import { cleanupTests, flushAndRunServer, immutableAssign, killallServers, reRunServer, ServerInfo } from '../../../../shared/extra-utils' +import { MockSmtpServer } from '../../../../shared/extra-utils/mock-servers/mock-email' import { sendContactForm } from '../../../../shared/extra-utils/server/contact-form' -import { MockSmtpServer } from '../../../../shared/extra-utils/miscs/email' -import { HttpStatusCode } from '../../../../shared/core-utils/miscs/http-error-codes' describe('Test contact form API validators', function () { let server: ServerInfo diff --git a/server/tests/api/check-params/users.ts b/server/tests/api/check-params/users.ts index 70a872ce5..da0f55bf8 100644 --- a/server/tests/api/check-params/users.ts +++ b/server/tests/api/check-params/users.ts @@ -32,7 +32,7 @@ import { uploadVideo, userLogin } from '../../../../shared/extra-utils' -import { MockSmtpServer } from '../../../../shared/extra-utils/miscs/email' +import { MockSmtpServer } from '../../../../shared/extra-utils/mock-servers/mock-email' import { checkBadCountPagination, checkBadSortPagination, -- cgit v1.2.3 From 0c1a77e9ccf915184c431145a8b326d4ce271b46 Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Tue, 6 Jul 2021 12:01:59 +0200 Subject: Introduce abuse command --- server/tests/api/check-params/abuses.ts | 146 +++++++++++++++----------------- 1 file changed, 67 insertions(+), 79 deletions(-) (limited to 'server/tests/api/check-params') diff --git a/server/tests/api/check-params/abuses.ts b/server/tests/api/check-params/abuses.ts index 2054776cc..e158e50dc 100644 --- a/server/tests/api/check-params/abuses.ts +++ b/server/tests/api/check-params/abuses.ts @@ -1,46 +1,40 @@ /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */ import 'mocha' -import { AbuseCreate, AbuseState } from '@shared/models' +import { HttpStatusCode } from '@shared/core-utils' import { - addAbuseMessage, + AbusesCommand, + checkBadCountPagination, + checkBadSortPagination, + checkBadStartPagination, cleanupTests, createUser, - deleteAbuse, - deleteAbuseMessage, doubleFollow, flushAndRunServer, generateUserAccessToken, - getAdminAbusesList, getVideoIdFromUUID, - listAbuseMessages, makeGetRequest, makePostBodyRequest, - reportAbuse, ServerInfo, setAccessTokensToServers, - updateAbuse, uploadVideo, userLogin, waitJobs -} from '../../../../shared/extra-utils' -import { - checkBadCountPagination, - checkBadSortPagination, - checkBadStartPagination -} from '../../../../shared/extra-utils/requests/check-api-params' -import { HttpStatusCode } from '../../../../shared/core-utils/miscs/http-error-codes' +} from '@shared/extra-utils' +import { AbuseCreate, AbuseState } from '@shared/models' describe('Test abuses API validators', function () { const basePath = '/api/v1/abuses/' let server: ServerInfo - let userAccessToken = '' - let userAccessToken2 = '' + let userToken = '' + let userToken2 = '' let abuseId: number let messageId: number + let command: AbusesCommand + // --------------------------------------------------------------- before(async function () { @@ -53,14 +47,14 @@ describe('Test abuses API validators', function () { const username = 'user1' const password = 'my super password' await createUser({ url: server.url, accessToken: server.accessToken, username: username, password: password }) - userAccessToken = await userLogin(server, { username, password }) + userToken = await userLogin(server, { username, password }) - { - userAccessToken2 = await generateUserAccessToken(server, 'user_2') - } + userToken2 = await generateUserAccessToken(server, 'user_2') const res = await uploadVideo(server.url, server.accessToken, {}) server.video = res.body.video + + command = server.abusesCommand }) describe('When listing abuses for admins', function () { @@ -90,7 +84,7 @@ describe('Test abuses API validators', function () { await makeGetRequest({ url: server.url, path, - token: userAccessToken, + token: userToken, statusCodeExpected: HttpStatusCode.FORBIDDEN_403 }) }) @@ -134,15 +128,15 @@ describe('Test abuses API validators', function () { const path = '/api/v1/users/me/abuses' it('Should fail with a bad start pagination', async function () { - await checkBadStartPagination(server.url, path, userAccessToken) + await checkBadStartPagination(server.url, path, userToken) }) it('Should fail with a bad count pagination', async function () { - await checkBadCountPagination(server.url, path, userAccessToken) + await checkBadCountPagination(server.url, path, userToken) }) it('Should fail with an incorrect sort', async function () { - await checkBadSortPagination(server.url, path, userAccessToken) + await checkBadSortPagination(server.url, path, userToken) }) it('Should fail with a non authenticated user', async function () { @@ -154,12 +148,12 @@ describe('Test abuses API validators', function () { }) it('Should fail with a bad id filter', async function () { - await makeGetRequest({ url: server.url, path, token: userAccessToken, query: { id: 'toto' } }) + await makeGetRequest({ url: server.url, path, token: userToken, query: { id: 'toto' } }) }) it('Should fail with a bad state filter', async function () { - await makeGetRequest({ url: server.url, path, token: userAccessToken, query: { state: 'toto' } }) - await makeGetRequest({ url: server.url, path, token: userAccessToken, query: { state: 0 } }) + await makeGetRequest({ url: server.url, path, token: userToken, query: { state: 'toto' } }) + await makeGetRequest({ url: server.url, path, token: userToken, query: { state: 0 } }) }) it('Should succeed with the correct params', async function () { @@ -168,7 +162,7 @@ describe('Test abuses API validators', function () { state: 2 } - await makeGetRequest({ url: server.url, path, token: userAccessToken, query, statusCodeExpected: HttpStatusCode.OK_200 }) + await makeGetRequest({ url: server.url, path, token: userToken, query, statusCodeExpected: HttpStatusCode.OK_200 }) }) }) @@ -177,12 +171,12 @@ describe('Test abuses API validators', function () { it('Should fail with nothing', async function () { const fields = {} - await makePostBodyRequest({ url: server.url, path, token: userAccessToken, fields }) + await makePostBodyRequest({ url: server.url, path, token: userToken, fields }) }) it('Should fail with a wrong video', async function () { const fields = { video: { id: 'blabla' }, reason: 'my super reason' } - await makePostBodyRequest({ url: server.url, path: path, token: userAccessToken, fields }) + await makePostBodyRequest({ url: server.url, path: path, token: userToken, fields }) }) it('Should fail with an unknown video', async function () { @@ -190,7 +184,7 @@ describe('Test abuses API validators', function () { await makePostBodyRequest({ url: server.url, path, - token: userAccessToken, + token: userToken, fields, statusCodeExpected: HttpStatusCode.NOT_FOUND_404 }) @@ -198,7 +192,7 @@ describe('Test abuses API validators', function () { it('Should fail with a wrong comment', async function () { const fields = { comment: { id: 'blabla' }, reason: 'my super reason' } - await makePostBodyRequest({ url: server.url, path: path, token: userAccessToken, fields }) + await makePostBodyRequest({ url: server.url, path: path, token: userToken, fields }) }) it('Should fail with an unknown comment', async function () { @@ -206,7 +200,7 @@ describe('Test abuses API validators', function () { await makePostBodyRequest({ url: server.url, path, - token: userAccessToken, + token: userToken, fields, statusCodeExpected: HttpStatusCode.NOT_FOUND_404 }) @@ -214,7 +208,7 @@ describe('Test abuses API validators', function () { it('Should fail with a wrong account', async function () { const fields = { account: { id: 'blabla' }, reason: 'my super reason' } - await makePostBodyRequest({ url: server.url, path: path, token: userAccessToken, fields }) + await makePostBodyRequest({ url: server.url, path: path, token: userToken, fields }) }) it('Should fail with an unknown account', async function () { @@ -222,7 +216,7 @@ describe('Test abuses API validators', function () { await makePostBodyRequest({ url: server.url, path, - token: userAccessToken, + token: userToken, fields, statusCodeExpected: HttpStatusCode.NOT_FOUND_404 }) @@ -233,7 +227,7 @@ describe('Test abuses API validators', function () { await makePostBodyRequest({ url: server.url, path, - token: userAccessToken, + token: userToken, fields, statusCodeExpected: HttpStatusCode.BAD_REQUEST_400 }) @@ -248,13 +242,13 @@ describe('Test abuses API validators', function () { it('Should fail with a reason too short', async function () { const fields = { video: { id: server.video.id }, reason: 'h' } - await makePostBodyRequest({ url: server.url, path, token: userAccessToken, fields }) + await makePostBodyRequest({ url: server.url, path, token: userToken, fields }) }) it('Should fail with a too big reason', async function () { const fields = { video: { id: server.video.id }, reason: 'super'.repeat(605) } - await makePostBodyRequest({ url: server.url, path, token: userAccessToken, fields }) + await makePostBodyRequest({ url: server.url, path, token: userToken, fields }) }) it('Should succeed with the correct parameters (basic)', async function () { @@ -263,7 +257,7 @@ describe('Test abuses API validators', function () { const res = await makePostBodyRequest({ url: server.url, path, - token: userAccessToken, + token: userToken, fields, statusCodeExpected: HttpStatusCode.OK_200 }) @@ -273,19 +267,19 @@ describe('Test abuses API validators', function () { it('Should fail with a wrong predefined reason', async function () { const fields = { video: { id: server.video.id }, reason: 'my super reason', predefinedReasons: [ 'wrongPredefinedReason' ] } - await makePostBodyRequest({ url: server.url, path, token: userAccessToken, fields }) + await makePostBodyRequest({ url: server.url, path, token: userToken, fields }) }) it('Should fail with negative timestamps', async function () { const fields = { video: { id: server.video.id, startAt: -1 }, reason: 'my super reason' } - await makePostBodyRequest({ url: server.url, path, token: userAccessToken, fields }) + await makePostBodyRequest({ url: server.url, path, token: userToken, fields }) }) it('Should fail mith misordered startAt/endAt', async function () { const fields = { video: { id: server.video.id, startAt: 5, endAt: 1 }, reason: 'my super reason' } - await makePostBodyRequest({ url: server.url, path, token: userAccessToken, fields }) + await makePostBodyRequest({ url: server.url, path, token: userToken, fields }) }) it('Should succeed with the corret parameters (advanced)', async function () { @@ -299,37 +293,37 @@ describe('Test abuses API validators', function () { predefinedReasons: [ 'serverRules' ] } - await makePostBodyRequest({ url: server.url, path, token: userAccessToken, fields, statusCodeExpected: HttpStatusCode.OK_200 }) + await makePostBodyRequest({ url: server.url, path, token: userToken, fields, statusCodeExpected: HttpStatusCode.OK_200 }) }) }) describe('When updating an abuse', function () { it('Should fail with a non authenticated user', async function () { - await updateAbuse(server.url, 'blabla', abuseId, {}, HttpStatusCode.UNAUTHORIZED_401) + await command.update({ token: 'blabla', abuseId, body: {}, expectedStatus: HttpStatusCode.UNAUTHORIZED_401 }) }) it('Should fail with a non admin user', async function () { - await updateAbuse(server.url, userAccessToken, abuseId, {}, HttpStatusCode.FORBIDDEN_403) + await command.update({ token: userToken, abuseId, body: {}, expectedStatus: HttpStatusCode.FORBIDDEN_403 }) }) it('Should fail with a bad abuse id', async function () { - await updateAbuse(server.url, server.accessToken, 45, {}, HttpStatusCode.NOT_FOUND_404) + await command.update({ abuseId: 45, body: {}, expectedStatus: HttpStatusCode.NOT_FOUND_404 }) }) it('Should fail with a bad state', async function () { const body = { state: 5 } - await updateAbuse(server.url, server.accessToken, abuseId, body, HttpStatusCode.BAD_REQUEST_400) + await command.update({ abuseId, body, expectedStatus: HttpStatusCode.BAD_REQUEST_400 }) }) it('Should fail with a bad moderation comment', async function () { const body = { moderationComment: 'b'.repeat(3001) } - await updateAbuse(server.url, server.accessToken, abuseId, body, HttpStatusCode.BAD_REQUEST_400) + await command.update({ abuseId, body, expectedStatus: HttpStatusCode.BAD_REQUEST_400 }) }) it('Should succeed with the correct params', async function () { const body = { state: AbuseState.ACCEPTED } - await updateAbuse(server.url, server.accessToken, abuseId, body) + await command.update({ abuseId, body }) }) }) @@ -337,23 +331,23 @@ describe('Test abuses API validators', function () { const message = 'my super message' it('Should fail with an invalid abuse id', async function () { - await addAbuseMessage(server.url, userAccessToken2, 888, message, HttpStatusCode.NOT_FOUND_404) + await command.addMessage({ token: userToken2, abuseId: 888, message, expectedStatus: HttpStatusCode.NOT_FOUND_404 }) }) it('Should fail with a non authenticated user', async function () { - await addAbuseMessage(server.url, 'fake_token', abuseId, message, HttpStatusCode.UNAUTHORIZED_401) + await command.addMessage({ token: 'fake_token', abuseId, message, expectedStatus: HttpStatusCode.UNAUTHORIZED_401 }) }) it('Should fail with an invalid logged in user', async function () { - await addAbuseMessage(server.url, userAccessToken2, abuseId, message, HttpStatusCode.FORBIDDEN_403) + await command.addMessage({ token: userToken2, abuseId, message, expectedStatus: HttpStatusCode.FORBIDDEN_403 }) }) it('Should fail with an invalid message', async function () { - await addAbuseMessage(server.url, userAccessToken, abuseId, 'a'.repeat(5000), HttpStatusCode.BAD_REQUEST_400) + await command.addMessage({ token: userToken, abuseId, message: 'a'.repeat(5000), expectedStatus: HttpStatusCode.BAD_REQUEST_400 }) }) it('Should suceed with the correct params', async function () { - const res = await addAbuseMessage(server.url, userAccessToken, abuseId, message) + const res = await command.addMessage({ token: userToken, abuseId, message }) messageId = res.body.abuseMessage.id }) }) @@ -361,61 +355,60 @@ describe('Test abuses API validators', function () { describe('When listing abuse messages', function () { it('Should fail with an invalid abuse id', async function () { - await listAbuseMessages(server.url, userAccessToken, 888, HttpStatusCode.NOT_FOUND_404) + await command.listMessages({ token: userToken, abuseId: 888, expectedStatus: HttpStatusCode.NOT_FOUND_404 }) }) it('Should fail with a non authenticated user', async function () { - await listAbuseMessages(server.url, 'fake_token', abuseId, HttpStatusCode.UNAUTHORIZED_401) + await command.listMessages({ token: 'fake_token', abuseId, expectedStatus: HttpStatusCode.UNAUTHORIZED_401 }) }) it('Should fail with an invalid logged in user', async function () { - await listAbuseMessages(server.url, userAccessToken2, abuseId, HttpStatusCode.FORBIDDEN_403) + await command.listMessages({ token: userToken2, abuseId, expectedStatus: HttpStatusCode.FORBIDDEN_403 }) }) it('Should succeed with the correct params', async function () { - await listAbuseMessages(server.url, userAccessToken, abuseId) + await command.listMessages({ token: userToken, abuseId }) }) }) describe('When deleting an abuse message', function () { - it('Should fail with an invalid abuse id', async function () { - await deleteAbuseMessage(server.url, userAccessToken, 888, messageId, HttpStatusCode.NOT_FOUND_404) + await command.deleteMessage({ token: userToken, abuseId: 888, messageId, expectedStatus: HttpStatusCode.NOT_FOUND_404 }) }) it('Should fail with an invalid message id', async function () { - await deleteAbuseMessage(server.url, userAccessToken, abuseId, 888, HttpStatusCode.NOT_FOUND_404) + await command.deleteMessage({ token: userToken, abuseId, messageId: 888, expectedStatus: HttpStatusCode.NOT_FOUND_404 }) }) it('Should fail with a non authenticated user', async function () { - await deleteAbuseMessage(server.url, 'fake_token', abuseId, messageId, HttpStatusCode.UNAUTHORIZED_401) + await command.deleteMessage({ token: 'fake_token', abuseId, messageId, expectedStatus: HttpStatusCode.UNAUTHORIZED_401 }) }) it('Should fail with an invalid logged in user', async function () { - await deleteAbuseMessage(server.url, userAccessToken2, abuseId, messageId, HttpStatusCode.FORBIDDEN_403) + await command.deleteMessage({ token: userToken2, abuseId, messageId, expectedStatus: HttpStatusCode.FORBIDDEN_403 }) }) it('Should succeed with the correct params', async function () { - await deleteAbuseMessage(server.url, userAccessToken, abuseId, messageId) + await command.deleteMessage({ token: userToken, abuseId, messageId }) }) }) describe('When deleting a video abuse', function () { it('Should fail with a non authenticated user', async function () { - await deleteAbuse(server.url, 'blabla', abuseId, HttpStatusCode.UNAUTHORIZED_401) + await command.delete({ token: 'blabla', abuseId, expectedStatus: HttpStatusCode.UNAUTHORIZED_401 }) }) it('Should fail with a non admin user', async function () { - await deleteAbuse(server.url, userAccessToken, abuseId, HttpStatusCode.FORBIDDEN_403) + await command.delete({ token: userToken, abuseId, expectedStatus: HttpStatusCode.FORBIDDEN_403 }) }) it('Should fail with a bad abuse id', async function () { - await deleteAbuse(server.url, server.accessToken, 45, HttpStatusCode.NOT_FOUND_404) + await command.delete({ abuseId: 45, expectedStatus: HttpStatusCode.NOT_FOUND_404 }) }) it('Should succeed with the correct params', async function () { - await deleteAbuse(server.url, server.accessToken, abuseId) + await command.delete({ abuseId }) }) }) @@ -432,25 +425,20 @@ describe('Test abuses API validators', function () { await doubleFollow(anotherServer, server) const server2VideoId = await getVideoIdFromUUID(anotherServer.url, server.video.uuid) - await reportAbuse({ - url: anotherServer.url, - token: anotherServer.accessToken, - reason: 'remote server', - videoId: server2VideoId - }) + await anotherServer.abusesCommand.report({ reason: 'remote server', videoId: server2VideoId }) await waitJobs([ server, anotherServer ]) - const res = await getAdminAbusesList({ url: server.url, token: server.accessToken, sort: '-createdAt' }) - remoteAbuseId = res.body.data[0].id + const body = await command.getAdminList({ sort: '-createdAt' }) + remoteAbuseId = body.data[0].id }) it('Should fail when listing abuse messages of a remote abuse', async function () { - await listAbuseMessages(server.url, server.accessToken, remoteAbuseId, HttpStatusCode.BAD_REQUEST_400) + await command.listMessages({ abuseId: remoteAbuseId, expectedStatus: HttpStatusCode.BAD_REQUEST_400 }) }) it('Should fail when creating abuse message of a remote abuse', async function () { - await addAbuseMessage(server.url, server.accessToken, remoteAbuseId, 'message', HttpStatusCode.BAD_REQUEST_400) + await command.addMessage({ abuseId: remoteAbuseId, message: 'message', expectedStatus: HttpStatusCode.BAD_REQUEST_400 }) }) after(async function () { -- cgit v1.2.3 From 23a3a8827cb8b862f5cc7ee2819f39918303beca Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Tue, 6 Jul 2021 14:30:20 +0200 Subject: Introduce overviews command --- server/tests/api/check-params/videos-overviews.ts | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) (limited to 'server/tests/api/check-params') diff --git a/server/tests/api/check-params/videos-overviews.ts b/server/tests/api/check-params/videos-overviews.ts index 69d7fc471..44a936c9f 100644 --- a/server/tests/api/check-params/videos-overviews.ts +++ b/server/tests/api/check-params/videos-overviews.ts @@ -1,8 +1,7 @@ /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */ import 'mocha' -import { cleanupTests, flushAndRunServer, ServerInfo } from '../../../../shared/extra-utils' -import { getVideosOverview } from '@shared/extra-utils/overviews/overviews' +import { cleanupTests, flushAndRunServer, ServerInfo } from '@shared/extra-utils' describe('Test videos overview', function () { let server: ServerInfo @@ -18,12 +17,12 @@ describe('Test videos overview', function () { describe('When getting videos overview', function () { it('Should fail with a bad pagination', async function () { - await getVideosOverview(server.url, 0, 400) - await getVideosOverview(server.url, 100, 400) + await server.overviewsCommand.getVideos({ page: 0, expectedStatus: 400 }) + await server.overviewsCommand.getVideos({ page: 100, expectedStatus: 400 }) }) it('Should succeed with a good pagination', async function () { - await getVideosOverview(server.url, 1) + await server.overviewsCommand.getVideos({ page: 1 }) }) }) -- cgit v1.2.3 From a9c58393d36d221197b48884a1960e6126ab31d7 Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Tue, 6 Jul 2021 15:53:25 +0200 Subject: Introduce contact form command --- server/tests/api/check-params/contact-form.ts | 69 +++++++-------------------- 1 file changed, 17 insertions(+), 52 deletions(-) (limited to 'server/tests/api/check-params') diff --git a/server/tests/api/check-params/contact-form.ts b/server/tests/api/check-params/contact-form.ts index 274562cbb..fb30766d9 100644 --- a/server/tests/api/check-params/contact-form.ts +++ b/server/tests/api/check-params/contact-form.ts @@ -1,10 +1,9 @@ /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */ import 'mocha' -import { HttpStatusCode } from '../../../../shared/core-utils/miscs/http-error-codes' -import { cleanupTests, flushAndRunServer, immutableAssign, killallServers, reRunServer, ServerInfo } from '../../../../shared/extra-utils' -import { MockSmtpServer } from '../../../../shared/extra-utils/mock-servers/mock-email' -import { sendContactForm } from '../../../../shared/extra-utils/server/contact-form' +import { HttpStatusCode } from '@shared/core-utils' +import { cleanupTests, flushAndRunServer, killallServers, MockSmtpServer, reRunServer, ServerInfo } from '@shared/extra-utils' +import { ContactFormCommand } from '@shared/extra-utils/server' describe('Test contact form API validators', function () { let server: ServerInfo @@ -16,6 +15,7 @@ describe('Test contact form API validators', function () { body: 'Hello, how are you?' } let emailPort: number + let command: ContactFormCommand // --------------------------------------------------------------- @@ -26,10 +26,11 @@ describe('Test contact form API validators', function () { // Email is disabled server = await flushAndRunServer(1) + command = server.contactFormCommand }) it('Should not accept a contact form if emails are disabled', async function () { - await sendContactForm(immutableAssign(defaultBody, { url: server.url, expectedStatus: HttpStatusCode.CONFLICT_409 })) + await command.send({ ...defaultBody, expectedStatus: HttpStatusCode.CONFLICT_409 }) }) it('Should not accept a contact form if it is disabled in the configuration', async function () { @@ -39,7 +40,7 @@ describe('Test contact form API validators', function () { // Contact form is disabled await reRunServer(server, { smtp: { hostname: 'localhost', port: emailPort }, contact_form: { enabled: false } }) - await sendContactForm(immutableAssign(defaultBody, { url: server.url, expectedStatus: HttpStatusCode.CONFLICT_409 })) + await command.send({ ...defaultBody, expectedStatus: HttpStatusCode.CONFLICT_409 }) }) it('Should not accept a contact form if from email is invalid', async function () { @@ -50,61 +51,25 @@ describe('Test contact form API validators', function () { // Email & contact form enabled await reRunServer(server, { smtp: { hostname: 'localhost', port: emailPort } }) - await sendContactForm(immutableAssign(defaultBody, { - url: server.url, - expectedStatus: HttpStatusCode.BAD_REQUEST_400, - fromEmail: 'badEmail' - })) - await sendContactForm(immutableAssign(defaultBody, { - url: server.url, - expectedStatus: HttpStatusCode.BAD_REQUEST_400, - fromEmail: 'badEmail@' - })) - await sendContactForm(immutableAssign(defaultBody, { - url: server.url, - expectedStatus: HttpStatusCode.BAD_REQUEST_400, - fromEmail: undefined - })) + await command.send({ ...defaultBody, fromEmail: 'badEmail', expectedStatus: HttpStatusCode.BAD_REQUEST_400 }) + await command.send({ ...defaultBody, fromEmail: 'badEmail@', expectedStatus: HttpStatusCode.BAD_REQUEST_400 }) + await command.send({ ...defaultBody, fromEmail: undefined, expectedStatus: HttpStatusCode.BAD_REQUEST_400 }) }) it('Should not accept a contact form if from name is invalid', async function () { - await sendContactForm(immutableAssign(defaultBody, { - url: server.url, - expectedStatus: HttpStatusCode.BAD_REQUEST_400, - fromName: 'name'.repeat(100) - })) - await sendContactForm(immutableAssign(defaultBody, { - url: server.url, - expectedStatus: HttpStatusCode.BAD_REQUEST_400, - fromName: '' - })) - await sendContactForm(immutableAssign(defaultBody, { - url: server.url, - expectedStatus: HttpStatusCode.BAD_REQUEST_400, - fromName: undefined - })) + await command.send({ ...defaultBody, fromName: 'name'.repeat(100), expectedStatus: HttpStatusCode.BAD_REQUEST_400 }) + await command.send({ ...defaultBody, fromName: '', expectedStatus: HttpStatusCode.BAD_REQUEST_400 }) + await command.send({ ...defaultBody, fromName: undefined, expectedStatus: HttpStatusCode.BAD_REQUEST_400 }) }) it('Should not accept a contact form if body is invalid', async function () { - await sendContactForm(immutableAssign(defaultBody, { - url: server.url, - expectedStatus: HttpStatusCode.BAD_REQUEST_400, - body: 'body'.repeat(5000) - })) - await sendContactForm(immutableAssign(defaultBody, { - url: server.url, - expectedStatus: HttpStatusCode.BAD_REQUEST_400, - body: 'a' - })) - await sendContactForm(immutableAssign(defaultBody, { - url: server.url, - expectedStatus: HttpStatusCode.BAD_REQUEST_400, - body: undefined - })) + await command.send({ ...defaultBody, body: 'body'.repeat(5000), expectedStatus: HttpStatusCode.BAD_REQUEST_400 }) + await command.send({ ...defaultBody, body: 'a', expectedStatus: HttpStatusCode.BAD_REQUEST_400 }) + await command.send({ ...defaultBody, body: undefined, expectedStatus: HttpStatusCode.BAD_REQUEST_400 }) }) it('Should accept a contact form with the correct parameters', async function () { - await sendContactForm(immutableAssign(defaultBody, { url: server.url })) + await command.send({ ...defaultBody }) }) after(async function () { -- cgit v1.2.3 From ae2abfd3aed3e75d39a316b49b914d187faa7475 Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Wed, 7 Jul 2021 10:33:49 +0200 Subject: Introduce plugins command --- server/tests/api/check-params/plugins.ts | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) (limited to 'server/tests/api/check-params') diff --git a/server/tests/api/check-params/plugins.ts b/server/tests/api/check-params/plugins.ts index a833fe6ff..d372221d0 100644 --- a/server/tests/api/check-params/plugins.ts +++ b/server/tests/api/check-params/plugins.ts @@ -10,7 +10,6 @@ import { createUser, flushAndRunServer, immutableAssign, - installPlugin, makeGetRequest, makePostBodyRequest, makePutBodyRequest, @@ -50,13 +49,13 @@ describe('Test server plugins API validators', function () { userAccessToken = await userLogin(server, user) { - const res = await installPlugin({ url: server.url, accessToken: server.accessToken, npmName: npmPlugin }) + const res = await server.pluginsCommand.install({ npmName: npmPlugin }) const plugin = res.body as PeerTubePlugin npmVersion = plugin.version } { - const res = await installPlugin({ url: server.url, accessToken: server.accessToken, npmName: themePlugin }) + const res = await server.pluginsCommand.install({ npmName: themePlugin }) const plugin = res.body as PeerTubePlugin themeVersion = plugin.version } -- cgit v1.2.3 From 65e6e2602c0d5521f3a6740f7469bb92830ecb53 Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Wed, 7 Jul 2021 11:51:09 +0200 Subject: Introduce config command --- server/tests/api/check-params/live.ts | 75 +++++++++++++++----------- server/tests/api/check-params/search.ts | 25 +++++---- server/tests/api/check-params/video-imports.ts | 53 +++++++++--------- 3 files changed, 83 insertions(+), 70 deletions(-) (limited to 'server/tests/api/check-params') diff --git a/server/tests/api/check-params/live.ts b/server/tests/api/check-params/live.ts index 933d8abf2..7a623c169 100644 --- a/server/tests/api/check-params/live.ts +++ b/server/tests/api/check-params/live.ts @@ -19,7 +19,6 @@ import { ServerInfo, setAccessTokensToServers, stopFfmpeg, - updateCustomSubConfig, updateLive, uploadVideoAndGetId, userLogin, @@ -43,12 +42,14 @@ describe('Test video lives API validator', function () { await setAccessTokensToServers([ server ]) - await updateCustomSubConfig(server.url, server.accessToken, { - live: { - enabled: true, - maxInstanceLives: 20, - maxUserLives: 20, - allowReplay: true + await server.configCommand.updateCustomSubConfig({ + newConfig: { + live: { + enabled: true, + maxInstanceLives: 20, + maxUserLives: 20, + allowReplay: true + } } }) @@ -234,9 +235,11 @@ describe('Test video lives API validator', function () { }) it('Should forbid if live is disabled', async function () { - await updateCustomSubConfig(server.url, server.accessToken, { - live: { - enabled: false + await server.configCommand.updateCustomSubConfig({ + newConfig: { + live: { + enabled: false + } } }) @@ -252,10 +255,12 @@ describe('Test video lives API validator', function () { it('Should forbid to save replay if not enabled by the admin', async function () { const fields = immutableAssign(baseCorrectParams, { saveReplay: true }) - await updateCustomSubConfig(server.url, server.accessToken, { - live: { - enabled: true, - allowReplay: false + await server.configCommand.updateCustomSubConfig({ + newConfig: { + live: { + enabled: true, + allowReplay: false + } } }) @@ -271,10 +276,12 @@ describe('Test video lives API validator', function () { it('Should allow to save replay if enabled by the admin', async function () { const fields = immutableAssign(baseCorrectParams, { saveReplay: true }) - await updateCustomSubConfig(server.url, server.accessToken, { - live: { - enabled: true, - allowReplay: true + await server.configCommand.updateCustomSubConfig({ + newConfig: { + live: { + enabled: true, + allowReplay: true + } } }) @@ -288,10 +295,12 @@ describe('Test video lives API validator', function () { }) it('Should not allow live if max instance lives is reached', async function () { - await updateCustomSubConfig(server.url, server.accessToken, { - live: { - enabled: true, - maxInstanceLives: 1 + await server.configCommand.updateCustomSubConfig({ + newConfig: { + live: { + enabled: true, + maxInstanceLives: 1 + } } }) @@ -305,11 +314,13 @@ describe('Test video lives API validator', function () { }) it('Should not allow live if max user lives is reached', async function () { - await updateCustomSubConfig(server.url, server.accessToken, { - live: { - enabled: true, - maxInstanceLives: 20, - maxUserLives: 1 + await server.configCommand.updateCustomSubConfig({ + newConfig: { + live: { + enabled: true, + maxInstanceLives: 20, + maxUserLives: 1 + } } }) @@ -393,10 +404,12 @@ describe('Test video lives API validator', function () { }) it('Should fail to update replay status if replay is not allowed on the instance', async function () { - await updateCustomSubConfig(server.url, server.accessToken, { - live: { - enabled: true, - allowReplay: false + await server.configCommand.updateCustomSubConfig({ + newConfig: { + live: { + enabled: true, + allowReplay: false + } } }) diff --git a/server/tests/api/check-params/search.ts b/server/tests/api/check-params/search.ts index 20ad46cff..4a2fc1197 100644 --- a/server/tests/api/check-params/search.ts +++ b/server/tests/api/check-params/search.ts @@ -1,28 +1,27 @@ /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */ import 'mocha' +import { HttpStatusCode } from '@shared/core-utils' import { + checkBadCountPagination, + checkBadSortPagination, + checkBadStartPagination, cleanupTests, flushAndRunServer, immutableAssign, makeGetRequest, ServerInfo, - updateCustomSubConfig, setAccessTokensToServers -} from '../../../../shared/extra-utils' -import { - checkBadCountPagination, - checkBadSortPagination, - checkBadStartPagination -} from '../../../../shared/extra-utils/requests/check-api-params' -import { HttpStatusCode } from '../../../../shared/core-utils/miscs/http-error-codes' +} from '@shared/extra-utils' function updateSearchIndex (server: ServerInfo, enabled: boolean, disableLocalSearch = false) { - return updateCustomSubConfig(server.url, server.accessToken, { - search: { - searchIndex: { - enabled, - disableLocalSearch + return server.configCommand.updateCustomSubConfig({ + newConfig: { + search: { + searchIndex: { + enabled, + disableLocalSearch + } } } }) diff --git a/server/tests/api/check-params/video-imports.ts b/server/tests/api/check-params/video-imports.ts index a27b624d0..dae3860ef 100644 --- a/server/tests/api/check-params/video-imports.ts +++ b/server/tests/api/check-params/video-imports.ts @@ -2,9 +2,12 @@ import 'mocha' import { omit } from 'lodash' -import { HttpStatusCode } from '../../../../shared/core-utils/miscs/http-error-codes' +import { HttpStatusCode } from '@shared/core-utils' import { buildAbsoluteFixturePath, + checkBadCountPagination, + checkBadSortPagination, + checkBadStartPagination, cleanupTests, createUser, flushAndRunServer, @@ -15,16 +18,10 @@ import { makeUploadRequest, ServerInfo, setAccessTokensToServers, - updateCustomSubConfig, userLogin -} from '../../../../shared/extra-utils' -import { - checkBadCountPagination, - checkBadSortPagination, - checkBadStartPagination -} from '../../../../shared/extra-utils/requests/check-api-params' -import { getGoodVideoUrl, getMagnetURI } from '../../../../shared/extra-utils/videos/video-imports' -import { VideoPrivacy } from '../../../../shared/models/videos/video-privacy.enum' +} from '@shared/extra-utils' +import { getGoodVideoUrl, getMagnetURI } from '@shared/extra-utils/videos/video-imports' +import { VideoPrivacy } from '@shared/models' describe('Test video imports API validator', function () { const path = '/api/v1/videos/imports' @@ -263,14 +260,16 @@ describe('Test video imports API validator', function () { }) it('Should forbid to import http videos', async function () { - await updateCustomSubConfig(server.url, server.accessToken, { - import: { - videos: { - http: { - enabled: false - }, - torrent: { - enabled: true + await server.configCommand.updateCustomSubConfig({ + newConfig: { + import: { + videos: { + http: { + enabled: false + }, + torrent: { + enabled: true + } } } } @@ -286,14 +285,16 @@ describe('Test video imports API validator', function () { }) it('Should forbid to import torrent videos', async function () { - await updateCustomSubConfig(server.url, server.accessToken, { - import: { - videos: { - http: { - enabled: true - }, - torrent: { - enabled: false + await server.configCommand.updateCustomSubConfig({ + newConfig: { + import: { + videos: { + http: { + enabled: true + }, + torrent: { + enabled: false + } } } } -- cgit v1.2.3 From 9fff08cf83f34339df7ed4ac770e1dee536adf9d Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Wed, 7 Jul 2021 13:38:26 +0200 Subject: Introduce accounts command --- server/tests/api/check-params/accounts.ts | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) (limited to 'server/tests/api/check-params') diff --git a/server/tests/api/check-params/accounts.ts b/server/tests/api/check-params/accounts.ts index d1712cff6..45d440c47 100644 --- a/server/tests/api/check-params/accounts.ts +++ b/server/tests/api/check-params/accounts.ts @@ -1,15 +1,15 @@ /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */ import 'mocha' - -import { cleanupTests, flushAndRunServer, ServerInfo } from '../../../../shared/extra-utils' +import { HttpStatusCode } from '@shared/core-utils' import { checkBadCountPagination, checkBadSortPagination, - checkBadStartPagination -} from '../../../../shared/extra-utils/requests/check-api-params' -import { getAccount } from '../../../../shared/extra-utils/users/accounts' -import { HttpStatusCode } from '../../../../shared/core-utils/miscs/http-error-codes' + checkBadStartPagination, + cleanupTests, + flushAndRunServer, + ServerInfo +} from '@shared/extra-utils' describe('Test accounts API validators', function () { const path = '/api/v1/accounts/' @@ -38,8 +38,9 @@ describe('Test accounts API validators', function () { }) describe('When getting an account', function () { + it('Should return 404 with a non existing name', async function () { - await getAccount(server.url, 'arfaze', HttpStatusCode.NOT_FOUND_404) + await server.accountsCommand.get({ accountName: 'arfaze', expectedStatus: HttpStatusCode.NOT_FOUND_404 }) }) }) -- cgit v1.2.3 From 4f2199144e428c16460750305f737b890c1ac322 Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Thu, 8 Jul 2021 10:18:40 +0200 Subject: Introduce live command --- server/tests/api/check-params/live.ts | 72 +++++++++++++++++------------------ 1 file changed, 36 insertions(+), 36 deletions(-) (limited to 'server/tests/api/check-params') diff --git a/server/tests/api/check-params/live.ts b/server/tests/api/check-params/live.ts index 7a623c169..56116848f 100644 --- a/server/tests/api/check-params/live.ts +++ b/server/tests/api/check-params/live.ts @@ -2,27 +2,24 @@ import 'mocha' import { omit } from 'lodash' -import { LiveVideo, VideoCreateResult, VideoPrivacy } from '@shared/models' +import { VideoCreateResult, VideoPrivacy } from '@shared/models' import { HttpStatusCode } from '../../../../shared/core-utils/miscs/http-error-codes' import { buildAbsoluteFixturePath, cleanupTests, createUser, flushAndRunServer, - getLive, getMyUserInformation, immutableAssign, + LiveCommand, makePostBodyRequest, makeUploadRequest, - runAndTestFfmpegStreamError, sendRTMPStream, ServerInfo, setAccessTokensToServers, stopFfmpeg, - updateLive, uploadVideoAndGetId, - userLogin, - waitUntilLivePublished + userLogin } from '../../../../shared/extra-utils' describe('Test video lives API validator', function () { @@ -32,6 +29,7 @@ describe('Test video lives API validator', function () { let channelId: number let video: VideoCreateResult let videoIdNotLive: number + let command: LiveCommand // --------------------------------------------------------------- @@ -66,6 +64,8 @@ describe('Test video lives API validator', function () { { videoIdNotLive = (await uploadVideoAndGetId({ server, videoName: 'not live' })).id } + + command = server.liveCommand }) describe('When creating a live', function () { @@ -337,70 +337,72 @@ describe('Test video lives API validator', function () { describe('When getting live information', function () { it('Should fail without access token', async function () { - await getLive(server.url, '', video.id, HttpStatusCode.UNAUTHORIZED_401) + await command.getLive({ token: '', videoId: video.id, expectedStatus: HttpStatusCode.UNAUTHORIZED_401 }) }) it('Should fail with a bad access token', async function () { - await getLive(server.url, 'toto', video.id, HttpStatusCode.UNAUTHORIZED_401) + await command.getLive({ token: 'toto', videoId: video.id, expectedStatus: HttpStatusCode.UNAUTHORIZED_401 }) }) it('Should fail with access token of another user', async function () { - await getLive(server.url, userAccessToken, video.id, HttpStatusCode.FORBIDDEN_403) + await command.getLive({ token: userAccessToken, videoId: video.id, expectedStatus: HttpStatusCode.FORBIDDEN_403 }) }) it('Should fail with a bad video id', async function () { - await getLive(server.url, server.accessToken, 'toto', HttpStatusCode.BAD_REQUEST_400) + await command.getLive({ videoId: 'toto', expectedStatus: HttpStatusCode.BAD_REQUEST_400 }) }) it('Should fail with an unknown video id', async function () { - await getLive(server.url, server.accessToken, 454555, HttpStatusCode.NOT_FOUND_404) + await command.getLive({ videoId: 454555, expectedStatus: HttpStatusCode.NOT_FOUND_404 }) }) it('Should fail with a non live video', async function () { - await getLive(server.url, server.accessToken, videoIdNotLive, HttpStatusCode.NOT_FOUND_404) + await command.getLive({ videoId: videoIdNotLive, expectedStatus: HttpStatusCode.NOT_FOUND_404 }) }) it('Should succeed with the correct params', async function () { - await getLive(server.url, server.accessToken, video.id) - await getLive(server.url, server.accessToken, video.shortUUID) + await command.getLive({ videoId: video.id }) + await command.getLive({ videoId: video.uuid }) + await command.getLive({ videoId: video.shortUUID }) }) }) describe('When updating live information', async function () { it('Should fail without access token', async function () { - await updateLive(server.url, '', video.id, {}, HttpStatusCode.UNAUTHORIZED_401) + await command.updateLive({ token: '', videoId: video.id, fields: {}, expectedStatus: HttpStatusCode.UNAUTHORIZED_401 }) }) it('Should fail with a bad access token', async function () { - await updateLive(server.url, 'toto', video.id, {}, HttpStatusCode.UNAUTHORIZED_401) + await command.updateLive({ token: 'toto', videoId: video.id, fields: {}, expectedStatus: HttpStatusCode.UNAUTHORIZED_401 }) }) it('Should fail with access token of another user', async function () { - await updateLive(server.url, userAccessToken, video.id, {}, HttpStatusCode.FORBIDDEN_403) + await command.updateLive({ token: userAccessToken, videoId: video.id, fields: {}, expectedStatus: HttpStatusCode.FORBIDDEN_403 }) }) it('Should fail with a bad video id', async function () { - await updateLive(server.url, server.accessToken, 'toto', {}, HttpStatusCode.BAD_REQUEST_400) + await command.updateLive({ videoId: 'toto', fields: {}, expectedStatus: HttpStatusCode.BAD_REQUEST_400 }) }) it('Should fail with an unknown video id', async function () { - await updateLive(server.url, server.accessToken, 454555, {}, HttpStatusCode.NOT_FOUND_404) + await command.updateLive({ videoId: 454555, fields: {}, expectedStatus: HttpStatusCode.NOT_FOUND_404 }) }) it('Should fail with a non live video', async function () { - await updateLive(server.url, server.accessToken, videoIdNotLive, {}, HttpStatusCode.NOT_FOUND_404) + await command.updateLive({ videoId: videoIdNotLive, fields: {}, expectedStatus: HttpStatusCode.NOT_FOUND_404 }) }) it('Should fail with save replay and permanent live set to true', async function () { const fields = { saveReplay: true, permanentLive: true } - await updateLive(server.url, server.accessToken, video.id, fields, HttpStatusCode.BAD_REQUEST_400) + await command.updateLive({ videoId: video.id, fields, expectedStatus: HttpStatusCode.BAD_REQUEST_400 }) }) it('Should succeed with the correct params', async function () { - await updateLive(server.url, server.accessToken, video.id, { saveReplay: false }) - await updateLive(server.url, server.accessToken, video.shortUUID, { saveReplay: false }) + await command.updateLive({ videoId: video.id, fields: { saveReplay: false } }) + await command.updateLive({ videoId: video.uuid, fields: { saveReplay: false } }) + await command.updateLive({ videoId: video.shortUUID, fields: { saveReplay: false } }) }) it('Should fail to update replay status if replay is not allowed on the instance', async function () { @@ -413,36 +415,34 @@ describe('Test video lives API validator', function () { } }) - await updateLive(server.url, server.accessToken, video.id, { saveReplay: true }, HttpStatusCode.FORBIDDEN_403) + await command.updateLive({ videoId: video.id, fields: { saveReplay: true }, expectedStatus: HttpStatusCode.FORBIDDEN_403 }) }) it('Should fail to update a live if it has already started', async function () { this.timeout(40000) - const resLive = await getLive(server.url, server.accessToken, video.id) - const live: LiveVideo = resLive.body + const live = await command.getLive({ videoId: video.id }) - const command = sendRTMPStream(live.rtmpUrl, live.streamKey) + const ffmpegCommand = sendRTMPStream(live.rtmpUrl, live.streamKey) - await waitUntilLivePublished(server.url, server.accessToken, video.id) - await updateLive(server.url, server.accessToken, video.id, {}, HttpStatusCode.BAD_REQUEST_400) + await command.waitUntilLivePublished({ videoId: video.id }) + await command.updateLive({ videoId: video.id, fields: {}, expectedStatus: HttpStatusCode.BAD_REQUEST_400 }) - await stopFfmpeg(command) + await stopFfmpeg(ffmpegCommand) }) it('Should fail to stream twice in the save live', async function () { this.timeout(40000) - const resLive = await getLive(server.url, server.accessToken, video.id) - const live: LiveVideo = resLive.body + const live = await command.getLive({ videoId: video.id }) - const command = sendRTMPStream(live.rtmpUrl, live.streamKey) + const ffmpegCommand = sendRTMPStream(live.rtmpUrl, live.streamKey) - await waitUntilLivePublished(server.url, server.accessToken, video.id) + await command.waitUntilLivePublished({ videoId: video.id }) - await runAndTestFfmpegStreamError(server.url, server.accessToken, video.id, true) + await command.runAndTestFfmpegStreamError({ videoId: video.id, shouldHaveError: true }) - await stopFfmpeg(command) + await stopFfmpeg(ffmpegCommand) }) }) -- cgit v1.2.3 From 04aed76711909507e74905bde3a7fa024d3585c9 Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Thu, 8 Jul 2021 10:25:50 +0200 Subject: Shorter live methods --- server/tests/api/check-params/live.ts | 52 +++++++++++++++++------------------ 1 file changed, 26 insertions(+), 26 deletions(-) (limited to 'server/tests/api/check-params') diff --git a/server/tests/api/check-params/live.ts b/server/tests/api/check-params/live.ts index 56116848f..d851d258d 100644 --- a/server/tests/api/check-params/live.ts +++ b/server/tests/api/check-params/live.ts @@ -337,72 +337,72 @@ describe('Test video lives API validator', function () { describe('When getting live information', function () { it('Should fail without access token', async function () { - await command.getLive({ token: '', videoId: video.id, expectedStatus: HttpStatusCode.UNAUTHORIZED_401 }) + await command.get({ token: '', videoId: video.id, expectedStatus: HttpStatusCode.UNAUTHORIZED_401 }) }) it('Should fail with a bad access token', async function () { - await command.getLive({ token: 'toto', videoId: video.id, expectedStatus: HttpStatusCode.UNAUTHORIZED_401 }) + await command.get({ token: 'toto', videoId: video.id, expectedStatus: HttpStatusCode.UNAUTHORIZED_401 }) }) it('Should fail with access token of another user', async function () { - await command.getLive({ token: userAccessToken, videoId: video.id, expectedStatus: HttpStatusCode.FORBIDDEN_403 }) + await command.get({ token: userAccessToken, videoId: video.id, expectedStatus: HttpStatusCode.FORBIDDEN_403 }) }) it('Should fail with a bad video id', async function () { - await command.getLive({ videoId: 'toto', expectedStatus: HttpStatusCode.BAD_REQUEST_400 }) + await command.get({ videoId: 'toto', expectedStatus: HttpStatusCode.BAD_REQUEST_400 }) }) it('Should fail with an unknown video id', async function () { - await command.getLive({ videoId: 454555, expectedStatus: HttpStatusCode.NOT_FOUND_404 }) + await command.get({ videoId: 454555, expectedStatus: HttpStatusCode.NOT_FOUND_404 }) }) it('Should fail with a non live video', async function () { - await command.getLive({ videoId: videoIdNotLive, expectedStatus: HttpStatusCode.NOT_FOUND_404 }) + await command.get({ videoId: videoIdNotLive, expectedStatus: HttpStatusCode.NOT_FOUND_404 }) }) it('Should succeed with the correct params', async function () { - await command.getLive({ videoId: video.id }) - await command.getLive({ videoId: video.uuid }) - await command.getLive({ videoId: video.shortUUID }) + await command.get({ videoId: video.id }) + await command.get({ videoId: video.uuid }) + await command.get({ videoId: video.shortUUID }) }) }) describe('When updating live information', async function () { it('Should fail without access token', async function () { - await command.updateLive({ token: '', videoId: video.id, fields: {}, expectedStatus: HttpStatusCode.UNAUTHORIZED_401 }) + await command.update({ token: '', videoId: video.id, fields: {}, expectedStatus: HttpStatusCode.UNAUTHORIZED_401 }) }) it('Should fail with a bad access token', async function () { - await command.updateLive({ token: 'toto', videoId: video.id, fields: {}, expectedStatus: HttpStatusCode.UNAUTHORIZED_401 }) + await command.update({ token: 'toto', videoId: video.id, fields: {}, expectedStatus: HttpStatusCode.UNAUTHORIZED_401 }) }) it('Should fail with access token of another user', async function () { - await command.updateLive({ token: userAccessToken, videoId: video.id, fields: {}, expectedStatus: HttpStatusCode.FORBIDDEN_403 }) + await command.update({ token: userAccessToken, videoId: video.id, fields: {}, expectedStatus: HttpStatusCode.FORBIDDEN_403 }) }) it('Should fail with a bad video id', async function () { - await command.updateLive({ videoId: 'toto', fields: {}, expectedStatus: HttpStatusCode.BAD_REQUEST_400 }) + await command.update({ videoId: 'toto', fields: {}, expectedStatus: HttpStatusCode.BAD_REQUEST_400 }) }) it('Should fail with an unknown video id', async function () { - await command.updateLive({ videoId: 454555, fields: {}, expectedStatus: HttpStatusCode.NOT_FOUND_404 }) + await command.update({ videoId: 454555, fields: {}, expectedStatus: HttpStatusCode.NOT_FOUND_404 }) }) it('Should fail with a non live video', async function () { - await command.updateLive({ videoId: videoIdNotLive, fields: {}, expectedStatus: HttpStatusCode.NOT_FOUND_404 }) + await command.update({ videoId: videoIdNotLive, fields: {}, expectedStatus: HttpStatusCode.NOT_FOUND_404 }) }) it('Should fail with save replay and permanent live set to true', async function () { const fields = { saveReplay: true, permanentLive: true } - await command.updateLive({ videoId: video.id, fields, expectedStatus: HttpStatusCode.BAD_REQUEST_400 }) + await command.update({ videoId: video.id, fields, expectedStatus: HttpStatusCode.BAD_REQUEST_400 }) }) it('Should succeed with the correct params', async function () { - await command.updateLive({ videoId: video.id, fields: { saveReplay: false } }) - await command.updateLive({ videoId: video.uuid, fields: { saveReplay: false } }) - await command.updateLive({ videoId: video.shortUUID, fields: { saveReplay: false } }) + await command.update({ videoId: video.id, fields: { saveReplay: false } }) + await command.update({ videoId: video.uuid, fields: { saveReplay: false } }) + await command.update({ videoId: video.shortUUID, fields: { saveReplay: false } }) }) it('Should fail to update replay status if replay is not allowed on the instance', async function () { @@ -415,18 +415,18 @@ describe('Test video lives API validator', function () { } }) - await command.updateLive({ videoId: video.id, fields: { saveReplay: true }, expectedStatus: HttpStatusCode.FORBIDDEN_403 }) + await command.update({ videoId: video.id, fields: { saveReplay: true }, expectedStatus: HttpStatusCode.FORBIDDEN_403 }) }) it('Should fail to update a live if it has already started', async function () { this.timeout(40000) - const live = await command.getLive({ videoId: video.id }) + const live = await command.get({ videoId: video.id }) const ffmpegCommand = sendRTMPStream(live.rtmpUrl, live.streamKey) - await command.waitUntilLivePublished({ videoId: video.id }) - await command.updateLive({ videoId: video.id, fields: {}, expectedStatus: HttpStatusCode.BAD_REQUEST_400 }) + await command.waitUntilPublished({ videoId: video.id }) + await command.update({ videoId: video.id, fields: {}, expectedStatus: HttpStatusCode.BAD_REQUEST_400 }) await stopFfmpeg(ffmpegCommand) }) @@ -434,13 +434,13 @@ describe('Test video lives API validator', function () { it('Should fail to stream twice in the save live', async function () { this.timeout(40000) - const live = await command.getLive({ videoId: video.id }) + const live = await command.get({ videoId: video.id }) const ffmpegCommand = sendRTMPStream(live.rtmpUrl, live.streamKey) - await command.waitUntilLivePublished({ videoId: video.id }) + await command.waitUntilPublished({ videoId: video.id }) - await command.runAndTestFfmpegStreamError({ videoId: video.id, shouldHaveError: true }) + await command.runAndTestStreamError({ videoId: video.id, shouldHaveError: true }) await stopFfmpeg(ffmpegCommand) }) -- cgit v1.2.3 From e3d15a6a9aed97a004d9dac1b7a6499d794e080a Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Thu, 8 Jul 2021 11:17:55 +0200 Subject: Introduce blacklist command --- server/tests/api/check-params/video-blacklist.ts | 47 +++++++++++------------- 1 file changed, 21 insertions(+), 26 deletions(-) (limited to 'server/tests/api/check-params') diff --git a/server/tests/api/check-params/video-blacklist.ts b/server/tests/api/check-params/video-blacklist.ts index ce7f5fa17..98cf2e11a 100644 --- a/server/tests/api/check-params/video-blacklist.ts +++ b/server/tests/api/check-params/video-blacklist.ts @@ -1,32 +1,28 @@ /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */ import 'mocha' - +import { expect } from 'chai' +import { HttpStatusCode } from '@shared/core-utils' import { + BlacklistCommand, + checkBadCountPagination, + checkBadSortPagination, + checkBadStartPagination, cleanupTests, createUser, doubleFollow, flushAndRunMultipleServers, - getBlacklistedVideosList, getVideo, getVideoWithToken, makePostBodyRequest, makePutBodyRequest, - removeVideoFromBlacklist, ServerInfo, setAccessTokensToServers, uploadVideo, userLogin, waitJobs -} from '../../../../shared/extra-utils' -import { - checkBadCountPagination, - checkBadSortPagination, - checkBadStartPagination -} from '../../../../shared/extra-utils/requests/check-api-params' -import { VideoBlacklistType, VideoDetails } from '../../../../shared/models/videos' -import { expect } from 'chai' -import { HttpStatusCode } from '../../../../shared/core-utils/miscs/http-error-codes' +} from '@shared/extra-utils' +import { VideoBlacklistType, VideoDetails } from '@shared/models' describe('Test video blacklist API validators', function () { let servers: ServerInfo[] @@ -34,6 +30,7 @@ describe('Test video blacklist API validators', function () { let remoteVideoUUID: string let userAccessToken1 = '' let userAccessToken2 = '' + let command: BlacklistCommand // --------------------------------------------------------------- @@ -75,6 +72,8 @@ describe('Test video blacklist API validators', function () { } await waitJobs(servers) + + command = servers[0].blacklistCommand }) describe('When adding a video in blacklist', function () { @@ -234,25 +233,26 @@ describe('Test video blacklist API validators', function () { }) describe('When removing a video in blacklist', function () { + it('Should fail with a non authenticated user', async function () { - await removeVideoFromBlacklist(servers[0].url, 'fake token', servers[0].video.uuid, HttpStatusCode.UNAUTHORIZED_401) + await command.remove({ token: 'fake token', videoId: servers[0].video.uuid, expectedStatus: HttpStatusCode.UNAUTHORIZED_401 }) }) it('Should fail with a non admin user', async function () { - await removeVideoFromBlacklist(servers[0].url, userAccessToken2, servers[0].video.uuid, HttpStatusCode.FORBIDDEN_403) + await command.remove({ token: userAccessToken2, videoId: servers[0].video.uuid, expectedStatus: HttpStatusCode.FORBIDDEN_403 }) }) it('Should fail with an incorrect id', async function () { - await removeVideoFromBlacklist(servers[0].url, servers[0].accessToken, 'hello', HttpStatusCode.BAD_REQUEST_400) + await command.remove({ videoId: 'hello', expectedStatus: HttpStatusCode.BAD_REQUEST_400 }) }) it('Should fail with a not blacklisted video', async function () { // The video was not added to the blacklist so it should fail - await removeVideoFromBlacklist(servers[0].url, servers[0].accessToken, notBlacklistedVideoId, HttpStatusCode.NOT_FOUND_404) + await command.remove({ videoId: notBlacklistedVideoId, expectedStatus: HttpStatusCode.NOT_FOUND_404 }) }) it('Should succeed with the correct params', async function () { - await removeVideoFromBlacklist(servers[0].url, servers[0].accessToken, servers[0].video.uuid, HttpStatusCode.NO_CONTENT_204) + await command.remove({ videoId: servers[0].video.uuid, expectedStatus: HttpStatusCode.NO_CONTENT_204 }) }) }) @@ -260,11 +260,11 @@ describe('Test video blacklist API validators', function () { const basePath = '/api/v1/videos/blacklist/' it('Should fail with a non authenticated user', async function () { - await getBlacklistedVideosList({ url: servers[0].url, token: 'fake token', specialStatus: HttpStatusCode.UNAUTHORIZED_401 }) + await servers[0].blacklistCommand.list({ token: 'fake token', expectedStatus: HttpStatusCode.UNAUTHORIZED_401 }) }) it('Should fail with a non admin user', async function () { - await getBlacklistedVideosList({ url: servers[0].url, token: userAccessToken2, specialStatus: HttpStatusCode.FORBIDDEN_403 }) + await servers[0].blacklistCommand.list({ token: userAccessToken2, expectedStatus: HttpStatusCode.FORBIDDEN_403 }) }) it('Should fail with a bad start pagination', async function () { @@ -280,16 +280,11 @@ describe('Test video blacklist API validators', function () { }) it('Should fail with an invalid type', async function () { - await getBlacklistedVideosList({ - url: servers[0].url, - token: servers[0].accessToken, - type: 0, - specialStatus: HttpStatusCode.BAD_REQUEST_400 - }) + await servers[0].blacklistCommand.list({ type: 0, expectedStatus: HttpStatusCode.BAD_REQUEST_400 }) }) it('Should succeed with the correct parameters', async function () { - await getBlacklistedVideosList({ url: servers[0].url, token: servers[0].accessToken, type: VideoBlacklistType.MANUAL }) + await servers[0].blacklistCommand.list({ type: VideoBlacklistType.MANUAL }) }) }) -- cgit v1.2.3 From a2470c9f4bfc7f49f4b94de935bacdd53fd54f29 Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Thu, 8 Jul 2021 11:49:38 +0200 Subject: Introduce captions command --- server/tests/api/check-params/video-captions.ts | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) (limited to 'server/tests/api/check-params') diff --git a/server/tests/api/check-params/video-captions.ts b/server/tests/api/check-params/video-captions.ts index c0595c04d..baab0f276 100644 --- a/server/tests/api/check-params/video-captions.ts +++ b/server/tests/api/check-params/video-captions.ts @@ -1,8 +1,7 @@ /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */ import 'mocha' -import { VideoCreateResult } from '@shared/models' -import { HttpStatusCode } from '../../../../shared/core-utils/miscs/http-error-codes' +import { HttpStatusCode } from '@shared/core-utils' import { buildAbsoluteFixturePath, cleanupTests, @@ -15,8 +14,8 @@ import { setAccessTokensToServers, uploadVideo, userLogin -} from '../../../../shared/extra-utils' -import { createVideoCaption } from '../../../../shared/extra-utils/videos/video-captions' +} from '@shared/extra-utils' +import { VideoCreateResult } from '@shared/models' describe('Test video captions API validator', function () { const path = '/api/v1/videos/' @@ -159,9 +158,7 @@ describe('Test video captions API validator', function () { // }) it('Should succeed with a valid captionfile extension and octet-stream mime type', async function () { - await createVideoCaption({ - url: server.url, - accessToken: server.accessToken, + await server.captionsCommand.createVideoCaption({ language: 'zh', videoId: video.uuid, fixture: 'subtitle-good.srt', -- cgit v1.2.3 From e6346d59e63135cf012ed18c102d3b0179ef565f Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Thu, 8 Jul 2021 15:54:39 +0200 Subject: Introduce playlist command --- server/tests/api/check-params/services.ts | 18 +- server/tests/api/check-params/video-playlists.ts | 347 ++++++++++++----------- 2 files changed, 191 insertions(+), 174 deletions(-) (limited to 'server/tests/api/check-params') diff --git a/server/tests/api/check-params/services.ts b/server/tests/api/check-params/services.ts index 514e3da70..595fab70d 100644 --- a/server/tests/api/check-params/services.ts +++ b/server/tests/api/check-params/services.ts @@ -1,19 +1,17 @@ /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */ import 'mocha' - +import { VideoPlaylistPrivacy } from '@shared/models' +import { HttpStatusCode } from '../../../../shared/core-utils/miscs/http-error-codes' import { cleanupTests, flushAndRunServer, makeGetRequest, ServerInfo, setAccessTokensToServers, - uploadVideo, - createVideoPlaylist, - setDefaultVideoChannel + setDefaultVideoChannel, + uploadVideo } from '../../../../shared/extra-utils' -import { VideoPlaylistPrivacy } from '@shared/models' -import { HttpStatusCode } from '../../../../shared/core-utils/miscs/http-error-codes' describe('Test services API validators', function () { let server: ServerInfo @@ -34,17 +32,15 @@ describe('Test services API validators', function () { } { - const res = await createVideoPlaylist({ - url: server.url, - token: server.accessToken, - playlistAttrs: { + const created = await server.playlistsCommand.create({ + attributes: { displayName: 'super playlist', privacy: VideoPlaylistPrivacy.PUBLIC, videoChannelId: server.videoChannel.id } }) - playlistUUID = res.body.videoPlaylist.uuid + playlistUUID = created.uuid } }) diff --git a/server/tests/api/check-params/video-playlists.ts b/server/tests/api/check-params/video-playlists.ts index 18253d11a..1c507a047 100644 --- a/server/tests/api/check-params/video-playlists.ts +++ b/server/tests/api/check-params/video-playlists.ts @@ -1,29 +1,29 @@ /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */ import 'mocha' -import { VideoPlaylistCreateResult, VideoPlaylistPrivacy, VideoPlaylistType } from '@shared/models' +import { + VideoPlaylistCreate, + VideoPlaylistCreateResult, + VideoPlaylistElementCreate, + VideoPlaylistElementUpdate, + VideoPlaylistPrivacy, + VideoPlaylistReorder, + VideoPlaylistType +} from '@shared/models' import { HttpStatusCode } from '../../../../shared/core-utils/miscs/http-error-codes' import { - addVideoInPlaylist, checkBadCountPagination, checkBadSortPagination, checkBadStartPagination, cleanupTests, - createVideoPlaylist, - deleteVideoPlaylist, flushAndRunServer, generateUserAccessToken, - getAccountPlaylistsListWithToken, - getVideoPlaylist, immutableAssign, makeGetRequest, - removeVideoFromPlaylist, - reorderVideosPlaylist, + PlaylistsCommand, ServerInfo, setAccessTokensToServers, setDefaultVideoChannel, - updateVideoPlaylist, - updateVideoPlaylistElement, uploadVideoAndGetId } from '../../../../shared/extra-utils' @@ -36,7 +36,9 @@ describe('Test video playlists API validator', function () { let watchLaterPlaylistId: number let videoId: number - let playlistElementId: number + let elementId: number + + let command: PlaylistsCommand // --------------------------------------------------------------- @@ -51,34 +53,37 @@ describe('Test video playlists API validator', function () { userAccessToken = await generateUserAccessToken(server, 'user1') videoId = (await uploadVideoAndGetId({ server, videoName: 'video 1' })).id + command = server.playlistsCommand + { - const res = await getAccountPlaylistsListWithToken(server.url, server.accessToken, 'root', 0, 5, VideoPlaylistType.WATCH_LATER) - watchLaterPlaylistId = res.body.data[0].id + const { data } = await command.listByAccount({ + token: server.accessToken, + handle: 'root', + start: 0, + count: 5, + playlistType: VideoPlaylistType.WATCH_LATER + }) + watchLaterPlaylistId = data[0].id } { - const res = await createVideoPlaylist({ - url: server.url, - token: server.accessToken, - playlistAttrs: { + playlist = await command.create({ + attributes: { displayName: 'super playlist', privacy: VideoPlaylistPrivacy.PUBLIC, videoChannelId: server.videoChannel.id } }) - playlist = res.body.videoPlaylist } { - const res = await createVideoPlaylist({ - url: server.url, - token: server.accessToken, - playlistAttrs: { + const created = await command.create({ + attributes: { displayName: 'private', privacy: VideoPlaylistPrivacy.PRIVATE } }) - privatePlaylistUUID = res.body.videoPlaylist.uuid + privatePlaylistUUID = created.uuid } }) @@ -163,47 +168,50 @@ describe('Test video playlists API validator', function () { describe('When getting a video playlist', function () { it('Should fail with a bad id or uuid', async function () { - await getVideoPlaylist(server.url, 'toto', HttpStatusCode.BAD_REQUEST_400) + await command.get({ playlistId: 'toto', expectedStatus: HttpStatusCode.BAD_REQUEST_400 }) }) it('Should fail with an unknown playlist', async function () { - await getVideoPlaylist(server.url, 42, HttpStatusCode.NOT_FOUND_404) + await command.get({ playlistId: 42, expectedStatus: HttpStatusCode.NOT_FOUND_404 }) }) it('Should fail to get an unlisted playlist with the number id', async function () { - const res = await createVideoPlaylist({ - url: server.url, - token: server.accessToken, - playlistAttrs: { + const playlist = await command.create({ + attributes: { displayName: 'super playlist', videoChannelId: server.videoChannel.id, privacy: VideoPlaylistPrivacy.UNLISTED } }) - const playlist = res.body.videoPlaylist - await getVideoPlaylist(server.url, playlist.id, HttpStatusCode.NOT_FOUND_404) - await getVideoPlaylist(server.url, playlist.uuid, HttpStatusCode.OK_200) + await command.get({ playlistId: playlist.id, expectedStatus: HttpStatusCode.NOT_FOUND_404 }) + await command.get({ playlistId: playlist.uuid, expectedStatus: HttpStatusCode.OK_200 }) }) it('Should succeed with the correct params', async function () { - await getVideoPlaylist(server.url, playlist.uuid, HttpStatusCode.OK_200) + await command.get({ playlistId: playlist.uuid, expectedStatus: HttpStatusCode.OK_200 }) }) }) describe('When creating/updating a video playlist', function () { - const getBase = (playlistAttrs: any = {}, wrapper: any = {}) => { - return Object.assign({ - expectedStatus: HttpStatusCode.BAD_REQUEST_400, - url: server.url, - token: server.accessToken, - playlistAttrs: Object.assign({ + const getBase = ( + attributes?: Partial, + wrapper?: Partial[0]> + ) => { + return { + attributes: { displayName: 'display name', privacy: VideoPlaylistPrivacy.UNLISTED, thumbnailfile: 'thumbnail.jpg', - videoChannelId: server.videoChannel.id - }, playlistAttrs) - }, wrapper) + videoChannelId: server.videoChannel.id, + + ...attributes + }, + + expectedStatus: HttpStatusCode.BAD_REQUEST_400, + + ...wrapper + } } const getUpdate = (params: any, playlistId: number | string) => { return immutableAssign(params, { playlistId: playlistId }) @@ -212,86 +220,86 @@ describe('Test video playlists API validator', function () { it('Should fail with an unauthenticated user', async function () { const params = getBase({}, { token: null, expectedStatus: HttpStatusCode.UNAUTHORIZED_401 }) - await createVideoPlaylist(params) - await updateVideoPlaylist(getUpdate(params, playlist.shortUUID)) + await command.create(params) + await command.update(getUpdate(params, playlist.shortUUID)) }) it('Should fail without displayName', async function () { const params = getBase({ displayName: undefined }) - await createVideoPlaylist(params) + await command.create(params) }) it('Should fail with an incorrect display name', async function () { const params = getBase({ displayName: 's'.repeat(300) }) - await createVideoPlaylist(params) - await updateVideoPlaylist(getUpdate(params, playlist.shortUUID)) + await command.create(params) + await command.update(getUpdate(params, playlist.shortUUID)) }) it('Should fail with an incorrect description', async function () { const params = getBase({ description: 't' }) - await createVideoPlaylist(params) - await updateVideoPlaylist(getUpdate(params, playlist.shortUUID)) + await command.create(params) + await command.update(getUpdate(params, playlist.shortUUID)) }) it('Should fail with an incorrect privacy', async function () { const params = getBase({ privacy: 45 }) - await createVideoPlaylist(params) - await updateVideoPlaylist(getUpdate(params, playlist.shortUUID)) + await command.create(params) + await command.update(getUpdate(params, playlist.shortUUID)) }) it('Should fail with an unknown video channel id', async function () { const params = getBase({ videoChannelId: 42 }, { expectedStatus: HttpStatusCode.NOT_FOUND_404 }) - await createVideoPlaylist(params) - await updateVideoPlaylist(getUpdate(params, playlist.shortUUID)) + await command.create(params) + await command.update(getUpdate(params, playlist.shortUUID)) }) it('Should fail with an incorrect thumbnail file', async function () { const params = getBase({ thumbnailfile: 'video_short.mp4' }) - await createVideoPlaylist(params) - await updateVideoPlaylist(getUpdate(params, playlist.shortUUID)) + await command.create(params) + await command.update(getUpdate(params, playlist.shortUUID)) }) it('Should fail with a thumbnail file too big', async function () { const params = getBase({ thumbnailfile: 'preview-big.png' }) - await createVideoPlaylist(params) - await updateVideoPlaylist(getUpdate(params, playlist.shortUUID)) + await command.create(params) + await command.update(getUpdate(params, playlist.shortUUID)) }) it('Should fail to set "public" a playlist not assigned to a channel', async function () { const params = getBase({ privacy: VideoPlaylistPrivacy.PUBLIC, videoChannelId: undefined }) - const params2 = getBase({ privacy: VideoPlaylistPrivacy.PUBLIC, videoChannelId: 'null' }) - const params3 = getBase({ privacy: undefined, videoChannelId: 'null' }) + const params2 = getBase({ privacy: VideoPlaylistPrivacy.PUBLIC, videoChannelId: 'null' as any }) + const params3 = getBase({ privacy: undefined, videoChannelId: 'null' as any }) - await createVideoPlaylist(params) - await createVideoPlaylist(params2) - await updateVideoPlaylist(getUpdate(params, privatePlaylistUUID)) - await updateVideoPlaylist(getUpdate(params2, playlist.shortUUID)) - await updateVideoPlaylist(getUpdate(params3, playlist.shortUUID)) + await command.create(params) + await command.create(params2) + await command.update(getUpdate(params, privatePlaylistUUID)) + await command.update(getUpdate(params2, playlist.shortUUID)) + await command.update(getUpdate(params3, playlist.shortUUID)) }) it('Should fail with an unknown playlist to update', async function () { - await updateVideoPlaylist(getUpdate( + await command.update(getUpdate( getBase({}, { expectedStatus: HttpStatusCode.NOT_FOUND_404 }), 42 )) }) it('Should fail to update a playlist of another user', async function () { - await updateVideoPlaylist(getUpdate( + await command.update(getUpdate( getBase({}, { token: userAccessToken, expectedStatus: HttpStatusCode.FORBIDDEN_403 }), playlist.shortUUID )) }) it('Should fail to update the watch later playlist', async function () { - await updateVideoPlaylist(getUpdate( + await command.update(getUpdate( getBase({}, { expectedStatus: HttpStatusCode.BAD_REQUEST_400 }), watchLaterPlaylistId )) @@ -300,146 +308,158 @@ describe('Test video playlists API validator', function () { it('Should succeed with the correct params', async function () { { const params = getBase({}, { expectedStatus: HttpStatusCode.OK_200 }) - await createVideoPlaylist(params) + await command.create(params) } { const params = getBase({}, { expectedStatus: HttpStatusCode.NO_CONTENT_204 }) - await updateVideoPlaylist(getUpdate(params, playlist.shortUUID)) + await command.update(getUpdate(params, playlist.shortUUID)) } }) }) describe('When adding an element in a playlist', function () { - const getBase = (elementAttrs: any = {}, wrapper: any = {}) => { - return Object.assign({ - expectedStatus: HttpStatusCode.BAD_REQUEST_400, - url: server.url, - token: server.accessToken, - playlistId: playlist.id, - elementAttrs: Object.assign({ + const getBase = ( + attributes?: Partial, + wrapper?: Partial[0]> + ) => { + return { + attributes: { videoId, startTimestamp: 2, - stopTimestamp: 3 - }, elementAttrs) - }, wrapper) + stopTimestamp: 3, + + ...attributes + }, + + expectedStatus: HttpStatusCode.BAD_REQUEST_400, + playlistId: playlist.id, + + ...wrapper + } } it('Should fail with an unauthenticated user', async function () { const params = getBase({}, { token: null, expectedStatus: HttpStatusCode.UNAUTHORIZED_401 }) - await addVideoInPlaylist(params) + await command.addElement(params) }) it('Should fail with the playlist of another user', async function () { const params = getBase({}, { token: userAccessToken, expectedStatus: HttpStatusCode.FORBIDDEN_403 }) - await addVideoInPlaylist(params) + await command.addElement(params) }) it('Should fail with an unknown or incorrect playlist id', async function () { { const params = getBase({}, { playlistId: 'toto' }) - await addVideoInPlaylist(params) + await command.addElement(params) } { const params = getBase({}, { playlistId: 42, expectedStatus: HttpStatusCode.NOT_FOUND_404 }) - await addVideoInPlaylist(params) + await command.addElement(params) } }) it('Should fail with an unknown or incorrect video id', async function () { const params = getBase({ videoId: 42 }, { expectedStatus: HttpStatusCode.NOT_FOUND_404 }) - await addVideoInPlaylist(params) + await command.addElement(params) }) it('Should fail with a bad start/stop timestamp', async function () { { const params = getBase({ startTimestamp: -42 }) - await addVideoInPlaylist(params) + await command.addElement(params) } { const params = getBase({ stopTimestamp: 'toto' as any }) - await addVideoInPlaylist(params) + await command.addElement(params) } }) it('Succeed with the correct params', async function () { const params = getBase({}, { expectedStatus: HttpStatusCode.OK_200 }) - const res = await addVideoInPlaylist(params) - playlistElementId = res.body.videoPlaylistElement.id + const created = await command.addElement(params) + elementId = created.id }) }) describe('When updating an element in a playlist', function () { - const getBase = (elementAttrs: any = {}, wrapper: any = {}) => { - return Object.assign({ - url: server.url, - token: server.accessToken, - elementAttrs: Object.assign({ + const getBase = ( + attributes?: Partial, + wrapper?: Partial[0]> + ) => { + return { + attributes: { startTimestamp: 1, - stopTimestamp: 2 - }, elementAttrs), - playlistElementId, + stopTimestamp: 2, + + ...attributes + }, + + elementId, playlistId: playlist.id, - expectedStatus: HttpStatusCode.BAD_REQUEST_400 - }, wrapper) + expectedStatus: HttpStatusCode.BAD_REQUEST_400, + + ...wrapper + } } it('Should fail with an unauthenticated user', async function () { const params = getBase({}, { token: null, expectedStatus: HttpStatusCode.UNAUTHORIZED_401 }) - await updateVideoPlaylistElement(params) + await command.updateElement(params) }) it('Should fail with the playlist of another user', async function () { const params = getBase({}, { token: userAccessToken, expectedStatus: HttpStatusCode.FORBIDDEN_403 }) - await updateVideoPlaylistElement(params) + await command.updateElement(params) }) it('Should fail with an unknown or incorrect playlist id', async function () { { const params = getBase({}, { playlistId: 'toto' }) - await updateVideoPlaylistElement(params) + await command.updateElement(params) } { const params = getBase({}, { playlistId: 42, expectedStatus: HttpStatusCode.NOT_FOUND_404 }) - await updateVideoPlaylistElement(params) + await command.updateElement(params) } }) it('Should fail with an unknown or incorrect playlistElement id', async function () { { - const params = getBase({}, { playlistElementId: 'toto' }) - await updateVideoPlaylistElement(params) + const params = getBase({}, { elementId: 'toto' }) + await command.updateElement(params) } { - const params = getBase({}, { playlistElementId: 42, expectedStatus: HttpStatusCode.NOT_FOUND_404 }) - await updateVideoPlaylistElement(params) + const params = getBase({}, { elementId: 42, expectedStatus: HttpStatusCode.NOT_FOUND_404 }) + await command.updateElement(params) } }) it('Should fail with a bad start/stop timestamp', async function () { { const params = getBase({ startTimestamp: 'toto' as any }) - await updateVideoPlaylistElement(params) + await command.updateElement(params) } { const params = getBase({ stopTimestamp: -42 }) - await updateVideoPlaylistElement(params) + await command.updateElement(params) } }) it('Should fail with an unknown element', async function () { - const params = getBase({}, { playlistElementId: 888, expectedStatus: HttpStatusCode.NOT_FOUND_404 }) - await updateVideoPlaylistElement(params) + const params = getBase({}, { elementId: 888, expectedStatus: HttpStatusCode.NOT_FOUND_404 }) + await command.updateElement(params) }) it('Succeed with the correct params', async function () { const params = getBase({}, { expectedStatus: HttpStatusCode.NO_CONTENT_204 }) - await updateVideoPlaylistElement(params) + await command.updateElement(params) }) }) @@ -447,18 +467,24 @@ describe('Test video playlists API validator', function () { let videoId3: number let videoId4: number - const getBase = (elementAttrs: any = {}, wrapper: any = {}) => { - return Object.assign({ - url: server.url, - token: server.accessToken, - playlistId: playlist.shortUUID, - elementAttrs: Object.assign({ + const getBase = ( + attributes?: Partial, + wrapper?: Partial[0]> + ) => { + return { + attributes: { startPosition: 1, insertAfterPosition: 2, - reorderLength: 3 - }, elementAttrs), - expectedStatus: HttpStatusCode.BAD_REQUEST_400 - }, wrapper) + reorderLength: 3, + + ...attributes + }, + + playlistId: playlist.shortUUID, + expectedStatus: HttpStatusCode.BAD_REQUEST_400, + + ...wrapper + } } before(async function () { @@ -466,91 +492,86 @@ describe('Test video playlists API validator', function () { videoId4 = (await uploadVideoAndGetId({ server, videoName: 'video 4' })).id for (const id of [ videoId3, videoId4 ]) { - await addVideoInPlaylist({ - url: server.url, - token: server.accessToken, - playlistId: playlist.shortUUID, - elementAttrs: { videoId: id } - }) + await command.addElement({ playlistId: playlist.shortUUID, attributes: { videoId: id } }) } }) it('Should fail with an unauthenticated user', async function () { const params = getBase({}, { token: null, expectedStatus: HttpStatusCode.UNAUTHORIZED_401 }) - await reorderVideosPlaylist(params) + await command.reorderElements(params) }) it('Should fail with the playlist of another user', async function () { const params = getBase({}, { token: userAccessToken, expectedStatus: HttpStatusCode.FORBIDDEN_403 }) - await reorderVideosPlaylist(params) + await command.reorderElements(params) }) it('Should fail with an invalid playlist', async function () { { const params = getBase({}, { playlistId: 'toto' }) - await reorderVideosPlaylist(params) + await command.reorderElements(params) } { const params = getBase({}, { playlistId: 42, expectedStatus: HttpStatusCode.NOT_FOUND_404 }) - await reorderVideosPlaylist(params) + await command.reorderElements(params) } }) it('Should fail with an invalid start position', async function () { { const params = getBase({ startPosition: -1 }) - await reorderVideosPlaylist(params) + await command.reorderElements(params) } { const params = getBase({ startPosition: 'toto' as any }) - await reorderVideosPlaylist(params) + await command.reorderElements(params) } { const params = getBase({ startPosition: 42 }) - await reorderVideosPlaylist(params) + await command.reorderElements(params) } }) it('Should fail with an invalid insert after position', async function () { { const params = getBase({ insertAfterPosition: 'toto' as any }) - await reorderVideosPlaylist(params) + await command.reorderElements(params) } { const params = getBase({ insertAfterPosition: -2 }) - await reorderVideosPlaylist(params) + await command.reorderElements(params) } { const params = getBase({ insertAfterPosition: 42 }) - await reorderVideosPlaylist(params) + await command.reorderElements(params) } }) it('Should fail with an invalid reorder length', async function () { { const params = getBase({ reorderLength: 'toto' as any }) - await reorderVideosPlaylist(params) + await command.reorderElements(params) } { const params = getBase({ reorderLength: -2 }) - await reorderVideosPlaylist(params) + await command.reorderElements(params) } { const params = getBase({ reorderLength: 42 }) - await reorderVideosPlaylist(params) + await command.reorderElements(params) } }) it('Succeed with the correct params', async function () { const params = getBase({}, { expectedStatus: HttpStatusCode.NO_CONTENT_204 }) - await reorderVideosPlaylist(params) + await command.reorderElements(params) }) }) @@ -601,76 +622,76 @@ describe('Test video playlists API validator', function () { }) describe('When deleting an element in a playlist', function () { - const getBase = (wrapper: any = {}) => { - return Object.assign({ - url: server.url, - token: server.accessToken, - playlistElementId, + const getBase = (wrapper: Partial[0]>) => { + return { + elementId, playlistId: playlist.uuid, - expectedStatus: HttpStatusCode.BAD_REQUEST_400 - }, wrapper) + expectedStatus: HttpStatusCode.BAD_REQUEST_400, + + ...wrapper + } } it('Should fail with an unauthenticated user', async function () { const params = getBase({ token: null, expectedStatus: HttpStatusCode.UNAUTHORIZED_401 }) - await removeVideoFromPlaylist(params) + await command.removeElement(params) }) it('Should fail with the playlist of another user', async function () { const params = getBase({ token: userAccessToken, expectedStatus: HttpStatusCode.FORBIDDEN_403 }) - await removeVideoFromPlaylist(params) + await command.removeElement(params) }) it('Should fail with an unknown or incorrect playlist id', async function () { { const params = getBase({ playlistId: 'toto' }) - await removeVideoFromPlaylist(params) + await command.removeElement(params) } { const params = getBase({ playlistId: 42, expectedStatus: HttpStatusCode.NOT_FOUND_404 }) - await removeVideoFromPlaylist(params) + await command.removeElement(params) } }) it('Should fail with an unknown or incorrect video id', async function () { { - const params = getBase({ playlistElementId: 'toto' }) - await removeVideoFromPlaylist(params) + const params = getBase({ elementId: 'toto' as any }) + await command.removeElement(params) } { - const params = getBase({ playlistElementId: 42, expectedStatus: HttpStatusCode.NOT_FOUND_404 }) - await removeVideoFromPlaylist(params) + const params = getBase({ elementId: 42, expectedStatus: HttpStatusCode.NOT_FOUND_404 }) + await command.removeElement(params) } }) it('Should fail with an unknown element', async function () { - const params = getBase({ playlistElementId: 888, expectedStatus: HttpStatusCode.NOT_FOUND_404 }) - await removeVideoFromPlaylist(params) + const params = getBase({ elementId: 888, expectedStatus: HttpStatusCode.NOT_FOUND_404 }) + await command.removeElement(params) }) it('Succeed with the correct params', async function () { const params = getBase({ expectedStatus: HttpStatusCode.NO_CONTENT_204 }) - await removeVideoFromPlaylist(params) + await command.removeElement(params) }) }) describe('When deleting a playlist', function () { it('Should fail with an unknown playlist', async function () { - await deleteVideoPlaylist(server.url, server.accessToken, 42, HttpStatusCode.NOT_FOUND_404) + await command.delete({ playlistId: 42, expectedStatus: HttpStatusCode.NOT_FOUND_404 }) }) it('Should fail with a playlist of another user', async function () { - await deleteVideoPlaylist(server.url, userAccessToken, playlist.uuid, HttpStatusCode.FORBIDDEN_403) + await command.delete({ token: userAccessToken, playlistId: playlist.uuid, expectedStatus: HttpStatusCode.FORBIDDEN_403 }) }) it('Should fail with the watch later playlist', async function () { - await deleteVideoPlaylist(server.url, server.accessToken, watchLaterPlaylistId, HttpStatusCode.BAD_REQUEST_400) + await command.delete({ playlistId: watchLaterPlaylistId, expectedStatus: HttpStatusCode.BAD_REQUEST_400 }) }) it('Should succeed with the correct params', async function () { - await deleteVideoPlaylist(server.url, server.accessToken, playlist.uuid) + await command.delete({ playlistId: playlist.uuid }) }) }) -- cgit v1.2.3 From 6910f20f114b5bd020258a3a9a3f2117819a60c2 Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Thu, 8 Jul 2021 16:49:51 +0200 Subject: Introduce import command --- server/tests/api/check-params/upload-quota.ts | 16 +++++++--------- server/tests/api/check-params/video-imports.ts | 6 +++--- 2 files changed, 10 insertions(+), 12 deletions(-) (limited to 'server/tests/api/check-params') diff --git a/server/tests/api/check-params/upload-quota.ts b/server/tests/api/check-params/upload-quota.ts index d0fbec415..c444663b8 100644 --- a/server/tests/api/check-params/upload-quota.ts +++ b/server/tests/api/check-params/upload-quota.ts @@ -3,13 +3,12 @@ import 'mocha' import { expect } from 'chai' import { HttpStatusCode, randomInt } from '@shared/core-utils' -import { getGoodVideoUrl, getMagnetURI, getMyVideoImports, importVideo } from '@shared/extra-utils/videos/video-imports' -import { MyUser, VideoImport, VideoImportState, VideoPrivacy } from '@shared/models' +import { MyUser, VideoImportState, VideoPrivacy } from '@shared/models' import { cleanupTests, flushAndRunServer, getMyUserInformation, - immutableAssign, + ImportsCommand, registerUser, ServerInfo, setAccessTokensToServers, @@ -83,16 +82,15 @@ describe('Test upload quota', function () { channelId: server.videoChannel.id, privacy: VideoPrivacy.PUBLIC } - await importVideo(server.url, server.accessToken, immutableAssign(baseAttributes, { targetUrl: getGoodVideoUrl() })) - await importVideo(server.url, server.accessToken, immutableAssign(baseAttributes, { magnetUri: getMagnetURI() })) - await importVideo(server.url, server.accessToken, immutableAssign(baseAttributes, { torrentfile: 'video-720p.torrent' as any })) + await server.importsCommand.importVideo({ attributes: { ...baseAttributes, targetUrl: ImportsCommand.getGoodVideoUrl() } }) + await server.importsCommand.importVideo({ attributes: { ...baseAttributes, magnetUri: ImportsCommand.getMagnetURI() } }) + await server.importsCommand.importVideo({ attributes: { ...baseAttributes, torrentfile: 'video-720p.torrent' as any } }) await waitJobs([ server ]) - const res = await getMyVideoImports(server.url, server.accessToken) + const { total, data: videoImports } = await server.importsCommand.getMyVideoImports() + expect(total).to.equal(3) - expect(res.body.total).to.equal(3) - const videoImports: VideoImport[] = res.body.data expect(videoImports).to.have.lengthOf(3) for (const videoImport of videoImports) { diff --git a/server/tests/api/check-params/video-imports.ts b/server/tests/api/check-params/video-imports.ts index dae3860ef..ea473191e 100644 --- a/server/tests/api/check-params/video-imports.ts +++ b/server/tests/api/check-params/video-imports.ts @@ -13,6 +13,7 @@ import { flushAndRunServer, getMyUserInformation, immutableAssign, + ImportsCommand, makeGetRequest, makePostBodyRequest, makeUploadRequest, @@ -20,7 +21,6 @@ import { setAccessTokensToServers, userLogin } from '@shared/extra-utils' -import { getGoodVideoUrl, getMagnetURI } from '@shared/extra-utils/videos/video-imports' import { VideoPrivacy } from '@shared/models' describe('Test video imports API validator', function () { @@ -74,7 +74,7 @@ describe('Test video imports API validator', function () { before(function () { baseCorrectParams = { - targetUrl: getGoodVideoUrl(), + targetUrl: ImportsCommand.getGoodVideoUrl(), name: 'my super name', category: 5, licence: 1, @@ -301,7 +301,7 @@ describe('Test video imports API validator', function () { }) let fields = omit(baseCorrectParams, 'targetUrl') - fields = immutableAssign(fields, { magnetUri: getMagnetURI() }) + fields = immutableAssign(fields, { magnetUri: ImportsCommand.getMagnetURI() }) await makePostBodyRequest({ url: server.url, -- cgit v1.2.3 From a54618880c394ad7571f3f3222dc96ec2dd10d9a Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Fri, 9 Jul 2021 11:21:30 +0200 Subject: Introduce channels command --- server/tests/api/check-params/users.ts | 5 ++--- server/tests/api/check-params/video-channels.ts | 18 ++++++++++-------- 2 files changed, 12 insertions(+), 11 deletions(-) (limited to 'server/tests/api/check-params') diff --git a/server/tests/api/check-params/users.ts b/server/tests/api/check-params/users.ts index da0f55bf8..88fc8e8b1 100644 --- a/server/tests/api/check-params/users.ts +++ b/server/tests/api/check-params/users.ts @@ -5,7 +5,6 @@ import { omit } from 'lodash' import { User, UserRole, VideoCreateResult } from '../../../../shared' import { HttpStatusCode } from '../../../../shared/core-utils/miscs/http-error-codes' import { - addVideoChannel, blockUser, buildAbsoluteFixturePath, cleanupTests, @@ -1041,8 +1040,8 @@ describe('Test users API validators', function () { }) it('Should fail with an existing channel', async function () { - const videoChannelAttributesArg = { name: 'existing_channel', displayName: 'hello', description: 'super description' } - await addVideoChannel(server.url, server.accessToken, videoChannelAttributesArg) + const attributes = { name: 'existing_channel', displayName: 'hello', description: 'super description' } + await server.channelsCommand.create({ attributes }) const fields = immutableAssign(baseCorrectParams, { channel: { name: 'existing_channel', displayName: 'toto' } }) diff --git a/server/tests/api/check-params/video-channels.ts b/server/tests/api/check-params/video-channels.ts index 5c02afd31..d29346dc3 100644 --- a/server/tests/api/check-params/video-channels.ts +++ b/server/tests/api/check-params/video-channels.ts @@ -6,11 +6,10 @@ import { omit } from 'lodash' import { HttpStatusCode } from '../../../../shared/core-utils/miscs/http-error-codes' import { buildAbsoluteFixturePath, + ChannelsCommand, cleanupTests, createUser, - deleteVideoChannel, flushAndRunServer, - getAccountVideoChannelsList, immutableAssign, makeGetRequest, makePostBodyRequest, @@ -33,6 +32,7 @@ describe('Test video channels API validator', function () { const videoChannelPath = '/api/v1/video-channels' let server: ServerInfo let accessTokenUser: string + let command: ChannelsCommand // --------------------------------------------------------------- @@ -52,6 +52,8 @@ describe('Test video channels API validator', function () { await createUser({ url: server.url, accessToken: server.accessToken, username: user.username, password: user.password }) accessTokenUser = await userLogin(server, user) } + + command = server.channelsCommand }) describe('When listing a video channels', function () { @@ -84,7 +86,7 @@ describe('Test video channels API validator', function () { }) it('Should fail with a unknown account', async function () { - await getAccountVideoChannelsList({ url: server.url, accountName: 'unknown', specialStatus: HttpStatusCode.NOT_FOUND_404 }) + await server.channelsCommand.listByAccount({ accountName: 'unknown', expectedStatus: HttpStatusCode.NOT_FOUND_404 }) }) it('Should succeed with the correct parameters', async function () { @@ -327,23 +329,23 @@ describe('Test video channels API validator', function () { describe('When deleting a video channel', function () { it('Should fail with a non authenticated user', async function () { - await deleteVideoChannel(server.url, 'coucou', 'super_channel', HttpStatusCode.UNAUTHORIZED_401) + await command.delete({ token: 'coucou', channelName: 'super_channel', expectedStatus: HttpStatusCode.UNAUTHORIZED_401 }) }) it('Should fail with another authenticated user', async function () { - await deleteVideoChannel(server.url, accessTokenUser, 'super_channel', HttpStatusCode.FORBIDDEN_403) + await command.delete({ token: accessTokenUser, channelName: 'super_channel', expectedStatus: HttpStatusCode.FORBIDDEN_403 }) }) it('Should fail with an unknown video channel id', async function () { - await deleteVideoChannel(server.url, server.accessToken, 'super_channel2', HttpStatusCode.NOT_FOUND_404) + await command.delete({ channelName: 'super_channel2', expectedStatus: HttpStatusCode.NOT_FOUND_404 }) }) it('Should succeed with the correct parameters', async function () { - await deleteVideoChannel(server.url, server.accessToken, 'super_channel') + await command.delete({ channelName: 'super_channel' }) }) it('Should fail to delete the last user video channel', async function () { - await deleteVideoChannel(server.url, server.accessToken, 'root_channel', HttpStatusCode.CONFLICT_409) + await command.delete({ channelName: 'root_channel', expectedStatus: HttpStatusCode.CONFLICT_409 }) }) }) -- cgit v1.2.3 From 12edc1495a36b2199f1bf1ba37f50c7b694be382 Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Fri, 9 Jul 2021 14:15:11 +0200 Subject: Introduce comments command --- server/tests/api/check-params/video-comments.ts | 27 +++++++++++-------------- 1 file changed, 12 insertions(+), 15 deletions(-) (limited to 'server/tests/api/check-params') diff --git a/server/tests/api/check-params/video-comments.ts b/server/tests/api/check-params/video-comments.ts index a38420851..ff94645cb 100644 --- a/server/tests/api/check-params/video-comments.ts +++ b/server/tests/api/check-params/video-comments.ts @@ -2,9 +2,11 @@ import 'mocha' import * as chai from 'chai' -import { VideoCreateResult } from '@shared/models' -import { HttpStatusCode } from '../../../../shared/core-utils/miscs/http-error-codes' +import { HttpStatusCode } from '@shared/core-utils' import { + checkBadCountPagination, + checkBadSortPagination, + checkBadStartPagination, cleanupTests, createUser, flushAndRunServer, @@ -15,13 +17,8 @@ import { setAccessTokensToServers, uploadVideo, userLogin -} from '../../../../shared/extra-utils' -import { - checkBadCountPagination, - checkBadSortPagination, - checkBadStartPagination -} from '../../../../shared/extra-utils/requests/check-api-params' -import { addVideoCommentThread } from '../../../../shared/extra-utils/videos/video-comments' +} from '@shared/extra-utils' +import { VideoCreateResult } from '@shared/models' const expect = chai.expect @@ -50,8 +47,8 @@ describe('Test video comments API validator', function () { } { - const res = await addVideoCommentThread(server.url, server.accessToken, video.uuid, 'coucou') - commentId = res.body.comment.id + const created = await server.commentsCommand.createThread({ videoId: video.uuid, text: 'coucou' }) + commentId = created.id pathComment = '/api/v1/videos/' + video.uuid + '/comments/' + commentId } @@ -281,8 +278,8 @@ describe('Test video comments API validator', function () { let commentToDelete: number { - const res = await addVideoCommentThread(server.url, userAccessToken, video.uuid, 'hello') - commentToDelete = res.body.comment.id + const created = await server.commentsCommand.createThread({ videoId: video.uuid, text: 'hello' }) + commentToDelete = created.id } const path = '/api/v1/videos/' + video.uuid + '/comments/' + commentToDelete @@ -301,8 +298,8 @@ describe('Test video comments API validator', function () { } { - const res = await addVideoCommentThread(server.url, server.accessToken, anotherVideoUUID, 'hello') - commentToDelete = res.body.comment.id + const created = await server.commentsCommand.createThread({ videoId: anotherVideoUUID, text: 'hello' }) + commentToDelete = created.id } const path = '/api/v1/videos/' + anotherVideoUUID + '/comments/' + commentToDelete -- cgit v1.2.3 From 9293139fde7091e9badcafa9b570b83cea9a10ad Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Fri, 9 Jul 2021 15:37:43 +0200 Subject: Introduce sql command --- server/tests/api/check-params/contact-form.ts | 4 ++-- server/tests/api/check-params/users.ts | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) (limited to 'server/tests/api/check-params') diff --git a/server/tests/api/check-params/contact-form.ts b/server/tests/api/check-params/contact-form.ts index fb30766d9..5539266b8 100644 --- a/server/tests/api/check-params/contact-form.ts +++ b/server/tests/api/check-params/contact-form.ts @@ -36,7 +36,7 @@ describe('Test contact form API validators', function () { it('Should not accept a contact form if it is disabled in the configuration', async function () { this.timeout(10000) - killallServers([ server ]) + await killallServers([ server ]) // Contact form is disabled await reRunServer(server, { smtp: { hostname: 'localhost', port: emailPort }, contact_form: { enabled: false } }) @@ -46,7 +46,7 @@ describe('Test contact form API validators', function () { it('Should not accept a contact form if from email is invalid', async function () { this.timeout(10000) - killallServers([ server ]) + await killallServers([ server ]) // Email & contact form enabled await reRunServer(server, { smtp: { hostname: 'localhost', port: emailPort } }) diff --git a/server/tests/api/check-params/users.ts b/server/tests/api/check-params/users.ts index 88fc8e8b1..bffe29bce 100644 --- a/server/tests/api/check-params/users.ts +++ b/server/tests/api/check-params/users.ts @@ -237,7 +237,7 @@ describe('Test users API validators', function () { it('Should succeed with no password on a server with smtp enabled', async function () { this.timeout(20000) - killallServers([ server ]) + await killallServers([ server ]) const config = immutableAssign(overrideConfig, { smtp: { -- cgit v1.2.3 From dd0ebb715123dfa126a82d4e4fe3a04064ae77b8 Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Fri, 9 Jul 2021 16:23:01 +0200 Subject: Introduce notifications command --- server/tests/api/check-params/contact-form.ts | 2 +- server/tests/api/check-params/video-comments.ts | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) (limited to 'server/tests/api/check-params') diff --git a/server/tests/api/check-params/contact-form.ts b/server/tests/api/check-params/contact-form.ts index 5539266b8..4eed1661a 100644 --- a/server/tests/api/check-params/contact-form.ts +++ b/server/tests/api/check-params/contact-form.ts @@ -69,7 +69,7 @@ describe('Test contact form API validators', function () { }) it('Should accept a contact form with the correct parameters', async function () { - await command.send({ ...defaultBody }) + await command.send(defaultBody) }) after(async function () { diff --git a/server/tests/api/check-params/video-comments.ts b/server/tests/api/check-params/video-comments.ts index ff94645cb..0f8c81392 100644 --- a/server/tests/api/check-params/video-comments.ts +++ b/server/tests/api/check-params/video-comments.ts @@ -278,7 +278,7 @@ describe('Test video comments API validator', function () { let commentToDelete: number { - const created = await server.commentsCommand.createThread({ videoId: video.uuid, text: 'hello' }) + const created = await server.commentsCommand.createThread({ videoId: video.uuid, token: userAccessToken, text: 'hello' }) commentToDelete = created.id } -- cgit v1.2.3 From 6c5065a011b099618681a37bd77eaa7bd3db752e Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Tue, 13 Jul 2021 09:43:59 +0200 Subject: Introduce server commands --- server/tests/api/check-params/config.ts | 28 ++++---- server/tests/api/check-params/live.ts | 29 ++++---- server/tests/api/check-params/plugins.ts | 7 +- server/tests/api/check-params/search.ts | 55 ++++++++-------- .../tests/api/check-params/user-notifications.ts | 20 +++--- server/tests/api/check-params/users.ts | 77 +++++++++++----------- server/tests/api/check-params/video-channels.ts | 31 ++++----- server/tests/api/check-params/video-imports.ts | 29 ++++---- server/tests/api/check-params/video-playlists.ts | 5 +- server/tests/api/check-params/videos.ts | 75 +++++++++++---------- 10 files changed, 178 insertions(+), 178 deletions(-) (limited to 'server/tests/api/check-params') diff --git a/server/tests/api/check-params/config.ts b/server/tests/api/check-params/config.ts index 9549070ef..291de93ea 100644 --- a/server/tests/api/check-params/config.ts +++ b/server/tests/api/check-params/config.ts @@ -1,22 +1,20 @@ /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */ -import { omit } from 'lodash' import 'mocha' -import { CustomConfig } from '../../../../shared/models/server/custom-config.model' - +import { omit } from 'lodash' +import { HttpStatusCode } from '@shared/core-utils' import { cleanupTests, createUser, flushAndRunServer, - immutableAssign, makeDeleteRequest, makeGetRequest, makePutBodyRequest, ServerInfo, setAccessTokensToServers, userLogin -} from '../../../../shared/extra-utils' -import { HttpStatusCode } from '../../../../shared/core-utils/miscs/http-error-codes' +} from '@shared/extra-utils' +import { CustomConfig } from '@shared/models' describe('Test config API validators', function () { const path = '/api/v1/config/custom' @@ -265,11 +263,13 @@ describe('Test config API validators', function () { }) it('Should fail with a bad default NSFW policy', async function () { - const newUpdateParams = immutableAssign(updateParams, { + const newUpdateParams = { + ...updateParams, + instance: { defaultNSFWPolicy: 'hello' } - }) + } await makePutBodyRequest({ url: server.url, @@ -282,13 +282,15 @@ describe('Test config API validators', function () { it('Should fail if email disabled and signup requires email verification', async function () { // opposite scenario - success when enable enabled - covered via tests/api/users/user-verification.ts - const newUpdateParams = immutableAssign(updateParams, { + const newUpdateParams = { + ...updateParams, + signup: { enabled: true, limit: 5, requiresEmailVerification: true } - }) + } await makePutBodyRequest({ url: server.url, @@ -300,7 +302,9 @@ describe('Test config API validators', function () { }) it('Should fail with a disabled webtorrent & hls transcoding', async function () { - const newUpdateParams = immutableAssign(updateParams, { + const newUpdateParams = { + ...updateParams, + transcoding: { hls: { enabled: false @@ -309,7 +313,7 @@ describe('Test config API validators', function () { enabled: false } } - }) + } await makePutBodyRequest({ url: server.url, diff --git a/server/tests/api/check-params/live.ts b/server/tests/api/check-params/live.ts index d851d258d..394967285 100644 --- a/server/tests/api/check-params/live.ts +++ b/server/tests/api/check-params/live.ts @@ -10,7 +10,6 @@ import { createUser, flushAndRunServer, getMyUserInformation, - immutableAssign, LiveCommand, makePostBodyRequest, makeUploadRequest, @@ -97,37 +96,37 @@ describe('Test video lives API validator', function () { }) it('Should fail with a long name', async function () { - const fields = immutableAssign(baseCorrectParams, { name: 'super'.repeat(65) }) + const fields = { ...baseCorrectParams, name: 'super'.repeat(65) } await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields }) }) it('Should fail with a bad category', async function () { - const fields = immutableAssign(baseCorrectParams, { category: 125 }) + const fields = { ...baseCorrectParams, category: 125 } await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields }) }) it('Should fail with a bad licence', async function () { - const fields = immutableAssign(baseCorrectParams, { licence: 125 }) + const fields = { ...baseCorrectParams, licence: 125 } await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields }) }) it('Should fail with a bad language', async function () { - const fields = immutableAssign(baseCorrectParams, { language: 'a'.repeat(15) }) + const fields = { ...baseCorrectParams, language: 'a'.repeat(15) } await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields }) }) it('Should fail with a long description', async function () { - const fields = immutableAssign(baseCorrectParams, { description: 'super'.repeat(2500) }) + const fields = { ...baseCorrectParams, description: 'super'.repeat(2500) } await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields }) }) it('Should fail with a long support text', async function () { - const fields = immutableAssign(baseCorrectParams, { support: 'super'.repeat(201) }) + const fields = { ...baseCorrectParams, support: 'super'.repeat(201) } await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields }) }) @@ -139,7 +138,7 @@ describe('Test video lives API validator', function () { }) it('Should fail with a bad channel', async function () { - const fields = immutableAssign(baseCorrectParams, { channelId: 545454 }) + const fields = { ...baseCorrectParams, channelId: 545454 } await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields }) }) @@ -155,25 +154,25 @@ describe('Test video lives API validator', function () { const res = await getMyUserInformation(server.url, accessTokenUser) const customChannelId = res.body.videoChannels[0].id - const fields = immutableAssign(baseCorrectParams, { channelId: customChannelId }) + const fields = { ...baseCorrectParams, channelId: customChannelId } await makePostBodyRequest({ url: server.url, path, token: userAccessToken, fields }) }) it('Should fail with too many tags', async function () { - const fields = immutableAssign(baseCorrectParams, { tags: [ 'tag1', 'tag2', 'tag3', 'tag4', 'tag5', 'tag6' ] }) + const fields = { ...baseCorrectParams, tags: [ 'tag1', 'tag2', 'tag3', 'tag4', 'tag5', 'tag6' ] } await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields }) }) it('Should fail with a tag length too low', async function () { - const fields = immutableAssign(baseCorrectParams, { tags: [ 'tag1', 't' ] }) + const fields = { ...baseCorrectParams, tags: [ 'tag1', 't' ] } await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields }) }) it('Should fail with a tag length too big', async function () { - const fields = immutableAssign(baseCorrectParams, { tags: [ 'tag1', 'my_super_tag_too_long_long_long_long_long_long' ] }) + const fields = { ...baseCorrectParams, tags: [ 'tag1', 'my_super_tag_too_long_long_long_long_long_long' ] } await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields }) }) @@ -215,7 +214,7 @@ describe('Test video lives API validator', function () { }) it('Should fail with save replay and permanent live set to true', async function () { - const fields = immutableAssign(baseCorrectParams, { saveReplay: true, permanentLive: true }) + const fields = { ...baseCorrectParams, saveReplay: true, permanentLive: true } await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields }) }) @@ -253,7 +252,7 @@ describe('Test video lives API validator', function () { }) it('Should forbid to save replay if not enabled by the admin', async function () { - const fields = immutableAssign(baseCorrectParams, { saveReplay: true }) + const fields = { ...baseCorrectParams, saveReplay: true } await server.configCommand.updateCustomSubConfig({ newConfig: { @@ -274,7 +273,7 @@ describe('Test video lives API validator', function () { }) it('Should allow to save replay if enabled by the admin', async function () { - const fields = immutableAssign(baseCorrectParams, { saveReplay: true }) + const fields = { ...baseCorrectParams, saveReplay: true } await server.configCommand.updateCustomSubConfig({ newConfig: { diff --git a/server/tests/api/check-params/plugins.ts b/server/tests/api/check-params/plugins.ts index d372221d0..8509b8ac5 100644 --- a/server/tests/api/check-params/plugins.ts +++ b/server/tests/api/check-params/plugins.ts @@ -9,7 +9,6 @@ import { cleanupTests, createUser, flushAndRunServer, - immutableAssign, makeGetRequest, makePostBodyRequest, makePutBodyRequest, @@ -200,7 +199,7 @@ describe('Test server plugins API validators', function () { }) it('Should fail with an invalid plugin type', async function () { - const query = immutableAssign(baseQuery, { pluginType: 5 }) + const query = { ...baseQuery, pluginType: 5 } await makeGetRequest({ url: server.url, @@ -211,7 +210,7 @@ describe('Test server plugins API validators', function () { }) it('Should fail with an invalid current peertube engine', async function () { - const query = immutableAssign(baseQuery, { currentPeerTubeEngine: '1.0' }) + const query = { ...baseQuery, currentPeerTubeEngine: '1.0' } await makeGetRequest({ url: server.url, @@ -271,7 +270,7 @@ describe('Test server plugins API validators', function () { }) it('Should fail with an invalid plugin type', async function () { - const query = immutableAssign(baseQuery, { pluginType: 5 }) + const query = { ...baseQuery, pluginType: 5 } await makeGetRequest({ url: server.url, diff --git a/server/tests/api/check-params/search.ts b/server/tests/api/check-params/search.ts index 4a2fc1197..7973c112f 100644 --- a/server/tests/api/check-params/search.ts +++ b/server/tests/api/check-params/search.ts @@ -8,7 +8,6 @@ import { checkBadStartPagination, cleanupTests, flushAndRunServer, - immutableAssign, makeGetRequest, ServerInfo, setAccessTokensToServers @@ -63,78 +62,78 @@ describe('Test videos API validator', function () { }) it('Should fail with an invalid category', async function () { - const customQuery1 = immutableAssign(query, { categoryOneOf: [ 'aa', 'b' ] }) + const customQuery1 = { ...query, categoryOneOf: [ 'aa', 'b' ] } await makeGetRequest({ url: server.url, path, query: customQuery1, statusCodeExpected: HttpStatusCode.BAD_REQUEST_400 }) - const customQuery2 = immutableAssign(query, { categoryOneOf: 'a' }) + const customQuery2 = { ...query, categoryOneOf: 'a' } await makeGetRequest({ url: server.url, path, query: customQuery2, statusCodeExpected: HttpStatusCode.BAD_REQUEST_400 }) }) it('Should succeed with a valid category', async function () { - const customQuery1 = immutableAssign(query, { categoryOneOf: [ 1, 7 ] }) + const customQuery1 = { ...query, categoryOneOf: [ 1, 7 ] } await makeGetRequest({ url: server.url, path, query: customQuery1, statusCodeExpected: HttpStatusCode.OK_200 }) - const customQuery2 = immutableAssign(query, { categoryOneOf: 1 }) + const customQuery2 = { ...query, categoryOneOf: 1 } await makeGetRequest({ url: server.url, path, query: customQuery2, statusCodeExpected: HttpStatusCode.OK_200 }) }) it('Should fail with an invalid licence', async function () { - const customQuery1 = immutableAssign(query, { licenceOneOf: [ 'aa', 'b' ] }) + const customQuery1 = { ...query, licenceOneOf: [ 'aa', 'b' ] } await makeGetRequest({ url: server.url, path, query: customQuery1, statusCodeExpected: HttpStatusCode.BAD_REQUEST_400 }) - const customQuery2 = immutableAssign(query, { licenceOneOf: 'a' }) + const customQuery2 = { ...query, licenceOneOf: 'a' } await makeGetRequest({ url: server.url, path, query: customQuery2, statusCodeExpected: HttpStatusCode.BAD_REQUEST_400 }) }) it('Should succeed with a valid licence', async function () { - const customQuery1 = immutableAssign(query, { licenceOneOf: [ 1, 2 ] }) + const customQuery1 = { ...query, licenceOneOf: [ 1, 2 ] } await makeGetRequest({ url: server.url, path, query: customQuery1, statusCodeExpected: HttpStatusCode.OK_200 }) - const customQuery2 = immutableAssign(query, { licenceOneOf: 1 }) + const customQuery2 = { ...query, licenceOneOf: 1 } await makeGetRequest({ url: server.url, path, query: customQuery2, statusCodeExpected: HttpStatusCode.OK_200 }) }) it('Should succeed with a valid language', async function () { - const customQuery1 = immutableAssign(query, { languageOneOf: [ 'fr', 'en' ] }) + const customQuery1 = { ...query, languageOneOf: [ 'fr', 'en' ] } await makeGetRequest({ url: server.url, path, query: customQuery1, statusCodeExpected: HttpStatusCode.OK_200 }) - const customQuery2 = immutableAssign(query, { languageOneOf: 'fr' }) + const customQuery2 = { ...query, languageOneOf: 'fr' } await makeGetRequest({ url: server.url, path, query: customQuery2, statusCodeExpected: HttpStatusCode.OK_200 }) }) it('Should succeed with valid tags', async function () { - const customQuery1 = immutableAssign(query, { tagsOneOf: [ 'tag1', 'tag2' ] }) + const customQuery1 = { ...query, tagsOneOf: [ 'tag1', 'tag2' ] } await makeGetRequest({ url: server.url, path, query: customQuery1, statusCodeExpected: HttpStatusCode.OK_200 }) - const customQuery2 = immutableAssign(query, { tagsOneOf: 'tag1' }) + const customQuery2 = { ...query, tagsOneOf: 'tag1' } await makeGetRequest({ url: server.url, path, query: customQuery2, statusCodeExpected: HttpStatusCode.OK_200 }) - const customQuery3 = immutableAssign(query, { tagsAllOf: [ 'tag1', 'tag2' ] }) + const customQuery3 = { ...query, tagsAllOf: [ 'tag1', 'tag2' ] } await makeGetRequest({ url: server.url, path, query: customQuery3, statusCodeExpected: HttpStatusCode.OK_200 }) - const customQuery4 = immutableAssign(query, { tagsAllOf: 'tag1' }) + const customQuery4 = { ...query, tagsAllOf: 'tag1' } await makeGetRequest({ url: server.url, path, query: customQuery4, statusCodeExpected: HttpStatusCode.OK_200 }) }) it('Should fail with invalid durations', async function () { - const customQuery1 = immutableAssign(query, { durationMin: 'hello' }) + const customQuery1 = { ...query, durationMin: 'hello' } await makeGetRequest({ url: server.url, path, query: customQuery1, statusCodeExpected: HttpStatusCode.BAD_REQUEST_400 }) - const customQuery2 = immutableAssign(query, { durationMax: 'hello' }) + const customQuery2 = { ...query, durationMax: 'hello' } await makeGetRequest({ url: server.url, path, query: customQuery2, statusCodeExpected: HttpStatusCode.BAD_REQUEST_400 }) }) it('Should fail with invalid dates', async function () { - const customQuery1 = immutableAssign(query, { startDate: 'hello' }) + const customQuery1 = { ...query, startDate: 'hello' } await makeGetRequest({ url: server.url, path, query: customQuery1, statusCodeExpected: HttpStatusCode.BAD_REQUEST_400 }) - const customQuery2 = immutableAssign(query, { endDate: 'hello' }) + const customQuery2 = { ...query, endDate: 'hello' } await makeGetRequest({ url: server.url, path, query: customQuery2, statusCodeExpected: HttpStatusCode.BAD_REQUEST_400 }) - const customQuery3 = immutableAssign(query, { originallyPublishedStartDate: 'hello' }) + const customQuery3 = { ...query, originallyPublishedStartDate: 'hello' } await makeGetRequest({ url: server.url, path, query: customQuery3, statusCodeExpected: HttpStatusCode.BAD_REQUEST_400 }) - const customQuery4 = immutableAssign(query, { originallyPublishedEndDate: 'hello' }) + const customQuery4 = { ...query, originallyPublishedEndDate: 'hello' } await makeGetRequest({ url: server.url, path, query: customQuery4, statusCodeExpected: HttpStatusCode.BAD_REQUEST_400 }) }) }) @@ -201,41 +200,41 @@ describe('Test videos API validator', function () { for (const path of paths) { { - const customQuery = immutableAssign(query, { searchTarget: 'hello' }) + const customQuery = { ...query, searchTarget: 'hello' } await makeGetRequest({ url: server.url, path, query: customQuery, statusCodeExpected: HttpStatusCode.BAD_REQUEST_400 }) } { - const customQuery = immutableAssign(query, { searchTarget: undefined }) + const customQuery = { ...query, searchTarget: undefined } await makeGetRequest({ url: server.url, path, query: customQuery, statusCodeExpected: HttpStatusCode.OK_200 }) } { - const customQuery = immutableAssign(query, { searchTarget: 'local' }) + const customQuery = { ...query, searchTarget: 'local' } await makeGetRequest({ url: server.url, path, query: customQuery, statusCodeExpected: HttpStatusCode.OK_200 }) } { - const customQuery = immutableAssign(query, { searchTarget: 'search-index' }) + const customQuery = { ...query, searchTarget: 'search-index' } await makeGetRequest({ url: server.url, path, query: customQuery, statusCodeExpected: HttpStatusCode.BAD_REQUEST_400 }) } await updateSearchIndex(server, true, true) { - const customQuery = immutableAssign(query, { searchTarget: 'local' }) + const customQuery = { ...query, searchTarget: 'local' } await makeGetRequest({ url: server.url, path, query: customQuery, statusCodeExpected: HttpStatusCode.BAD_REQUEST_400 }) } { - const customQuery = immutableAssign(query, { searchTarget: 'search-index' }) + const customQuery = { ...query, searchTarget: 'search-index' } await makeGetRequest({ url: server.url, path, query: customQuery, statusCodeExpected: HttpStatusCode.OK_200 }) } await updateSearchIndex(server, true, false) { - const customQuery = immutableAssign(query, { searchTarget: 'local' }) + const customQuery = { ...query, searchTarget: 'local' } await makeGetRequest({ url: server.url, path, query: customQuery, statusCodeExpected: HttpStatusCode.OK_200 }) } diff --git a/server/tests/api/check-params/user-notifications.ts b/server/tests/api/check-params/user-notifications.ts index 26d4423f9..913eca366 100644 --- a/server/tests/api/check-params/user-notifications.ts +++ b/server/tests/api/check-params/user-notifications.ts @@ -2,25 +2,21 @@ import 'mocha' import { io } from 'socket.io-client' - +import { HttpStatusCode } from '@shared/core-utils' import { + checkBadCountPagination, + checkBadSortPagination, + checkBadStartPagination, cleanupTests, flushAndRunServer, - immutableAssign, makeGetRequest, makePostBodyRequest, makePutBodyRequest, ServerInfo, setAccessTokensToServers, wait -} from '../../../../shared/extra-utils' -import { - checkBadCountPagination, - checkBadSortPagination, - checkBadStartPagination -} from '../../../../shared/extra-utils/requests/check-api-params' -import { UserNotificationSetting, UserNotificationSettingValue } from '../../../../shared/models/users' -import { HttpStatusCode } from '../../../../shared/core-utils/miscs/http-error-codes' +} from '@shared/extra-utils' +import { UserNotificationSetting, UserNotificationSettingValue } from '@shared/models' describe('Test user notifications API validators', function () { let server: ServerInfo @@ -193,7 +189,7 @@ describe('Test user notifications API validators', function () { it('Should fail with incorrect field values', async function () { { - const fields = immutableAssign(correctFields, { newCommentOnMyVideo: 15 }) + const fields = { ...correctFields, newCommentOnMyVideo: 15 } await makePutBodyRequest({ url: server.url, @@ -205,7 +201,7 @@ describe('Test user notifications API validators', function () { } { - const fields = immutableAssign(correctFields, { newCommentOnMyVideo: 'toto' }) + const fields = { ...correctFields, newCommentOnMyVideo: 'toto' } await makePutBodyRequest({ url: server.url, diff --git a/server/tests/api/check-params/users.ts b/server/tests/api/check-params/users.ts index bffe29bce..fda7e9640 100644 --- a/server/tests/api/check-params/users.ts +++ b/server/tests/api/check-params/users.ts @@ -15,7 +15,6 @@ import { getMyUserVideoRating, getUserScopedTokens, getUsersList, - immutableAssign, killallServers, makeGetRequest, makePostBodyRequest, @@ -181,25 +180,25 @@ describe('Test users API validators', function () { } it('Should fail with a too small username', async function () { - const fields = immutableAssign(baseCorrectParams, { username: '' }) + const fields = { ...baseCorrectParams, username: '' } await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields }) }) it('Should fail with a too long username', async function () { - const fields = immutableAssign(baseCorrectParams, { username: 'super'.repeat(50) }) + const fields = { ...baseCorrectParams, username: 'super'.repeat(50) } await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields }) }) it('Should fail with a not lowercase username', async function () { - const fields = immutableAssign(baseCorrectParams, { username: 'Toto' }) + const fields = { ...baseCorrectParams, username: 'Toto' } await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields }) }) it('Should fail with an incorrect username', async function () { - const fields = immutableAssign(baseCorrectParams, { username: 'my username' }) + const fields = { ...baseCorrectParams, username: 'my username' } await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields }) }) @@ -211,25 +210,25 @@ describe('Test users API validators', function () { }) it('Should fail with an invalid email', async function () { - const fields = immutableAssign(baseCorrectParams, { email: 'test_example.com' }) + const fields = { ...baseCorrectParams, email: 'test_example.com' } await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields }) }) it('Should fail with a too small password', async function () { - const fields = immutableAssign(baseCorrectParams, { password: 'bla' }) + const fields = { ...baseCorrectParams, password: 'bla' } await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields }) }) it('Should fail with a too long password', async function () { - const fields = immutableAssign(baseCorrectParams, { password: 'super'.repeat(61) }) + const fields = { ...baseCorrectParams, password: 'super'.repeat(61) } await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields }) }) it('Should fail with empty password and no smtp configured', async function () { - const fields = immutableAssign(baseCorrectParams, { password: '' }) + const fields = { ...baseCorrectParams, password: '' } await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields }) }) @@ -239,19 +238,23 @@ describe('Test users API validators', function () { await killallServers([ server ]) - const config = immutableAssign(overrideConfig, { + const config = { + ...overrideConfig, + smtp: { hostname: 'localhost', port: emailPort } - }) + } await reRunServer(server, config) - const fields = immutableAssign(baseCorrectParams, { + const fields = { + ...baseCorrectParams, + password: '', username: 'create_password', email: 'create_password@example.com' - }) + } await makePostBodyRequest({ url: server.url, @@ -263,7 +266,7 @@ describe('Test users API validators', function () { }) it('Should fail with invalid admin flags', async function () { - const fields = immutableAssign(baseCorrectParams, { adminFlags: 'toto' }) + const fields = { ...baseCorrectParams, adminFlags: 'toto' } await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields }) }) @@ -279,7 +282,7 @@ describe('Test users API validators', function () { }) it('Should fail if we add a user with the same username', async function () { - const fields = immutableAssign(baseCorrectParams, { username: 'user1' }) + const fields = { ...baseCorrectParams, username: 'user1' } await makePostBodyRequest({ url: server.url, @@ -291,7 +294,7 @@ describe('Test users API validators', function () { }) it('Should fail if we add a user with the same email', async function () { - const fields = immutableAssign(baseCorrectParams, { email: 'user1@example.com' }) + const fields = { ...baseCorrectParams, email: 'user1@example.com' } await makePostBodyRequest({ url: server.url, @@ -315,13 +318,13 @@ describe('Test users API validators', function () { }) it('Should fail with an invalid videoQuota', async function () { - const fields = immutableAssign(baseCorrectParams, { videoQuota: -5 }) + const fields = { ...baseCorrectParams, videoQuota: -5 } await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields }) }) it('Should fail with an invalid videoQuotaDaily', async function () { - const fields = immutableAssign(baseCorrectParams, { videoQuotaDaily: -7 }) + const fields = { ...baseCorrectParams, videoQuotaDaily: -7 } await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields }) }) @@ -333,13 +336,13 @@ describe('Test users API validators', function () { }) it('Should fail with an invalid user role', async function () { - const fields = immutableAssign(baseCorrectParams, { role: 88989 }) + const fields = { ...baseCorrectParams, role: 88989 } await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields }) }) it('Should fail with a "peertube" username', async function () { - const fields = immutableAssign(baseCorrectParams, { username: 'peertube' }) + const fields = { ...baseCorrectParams, username: 'peertube' } await makePostBodyRequest({ url: server.url, @@ -352,7 +355,7 @@ describe('Test users API validators', function () { it('Should fail to create a moderator or an admin with a moderator', async function () { for (const role of [ UserRole.MODERATOR, UserRole.ADMINISTRATOR ]) { - const fields = immutableAssign(baseCorrectParams, { role }) + const fields = { ...baseCorrectParams, role } await makePostBodyRequest({ url: server.url, @@ -365,7 +368,7 @@ describe('Test users API validators', function () { }) it('Should succeed to create a user with a moderator', async function () { - const fields = immutableAssign(baseCorrectParams, { username: 'a4656', email: 'a4656@example.com', role: UserRole.USER }) + const fields = { ...baseCorrectParams, username: 'a4656', email: 'a4656@example.com', role: UserRole.USER } await makePostBodyRequest({ url: server.url, @@ -937,19 +940,19 @@ describe('Test users API validators', function () { } it('Should fail with a too small username', async function () { - const fields = immutableAssign(baseCorrectParams, { username: '' }) + const fields = { ...baseCorrectParams, username: '' } await makePostBodyRequest({ url: server.url, path: registrationPath, token: server.accessToken, fields }) }) it('Should fail with a too long username', async function () { - const fields = immutableAssign(baseCorrectParams, { username: 'super'.repeat(50) }) + const fields = { ...baseCorrectParams, username: 'super'.repeat(50) } await makePostBodyRequest({ url: server.url, path: registrationPath, token: server.accessToken, fields }) }) it('Should fail with an incorrect username', async function () { - const fields = immutableAssign(baseCorrectParams, { username: 'my username' }) + const fields = { ...baseCorrectParams, username: 'my username' } await makePostBodyRequest({ url: server.url, path: registrationPath, token: server.accessToken, fields }) }) @@ -961,25 +964,25 @@ describe('Test users API validators', function () { }) it('Should fail with an invalid email', async function () { - const fields = immutableAssign(baseCorrectParams, { email: 'test_example.com' }) + const fields = { ...baseCorrectParams, email: 'test_example.com' } await makePostBodyRequest({ url: server.url, path: registrationPath, token: server.accessToken, fields }) }) it('Should fail with a too small password', async function () { - const fields = immutableAssign(baseCorrectParams, { password: 'bla' }) + const fields = { ...baseCorrectParams, password: 'bla' } await makePostBodyRequest({ url: server.url, path: registrationPath, token: server.accessToken, fields }) }) it('Should fail with a too long password', async function () { - const fields = immutableAssign(baseCorrectParams, { password: 'super'.repeat(61) }) + const fields = { ...baseCorrectParams, password: 'super'.repeat(61) } await makePostBodyRequest({ url: server.url, path: registrationPath, token: server.accessToken, fields }) }) it('Should fail if we register a user with the same username', async function () { - const fields = immutableAssign(baseCorrectParams, { username: 'root' }) + const fields = { ...baseCorrectParams, username: 'root' } await makePostBodyRequest({ url: server.url, @@ -991,7 +994,7 @@ describe('Test users API validators', function () { }) it('Should fail with a "peertube" username', async function () { - const fields = immutableAssign(baseCorrectParams, { username: 'peertube' }) + const fields = { ...baseCorrectParams, username: 'peertube' } await makePostBodyRequest({ url: server.url, @@ -1003,7 +1006,7 @@ describe('Test users API validators', function () { }) it('Should fail if we register a user with the same email', async function () { - const fields = immutableAssign(baseCorrectParams, { email: 'admin' + server.internalServerNumber + '@example.com' }) + const fields = { ...baseCorrectParams, email: 'admin' + server.internalServerNumber + '@example.com' } await makePostBodyRequest({ url: server.url, @@ -1015,26 +1018,26 @@ describe('Test users API validators', function () { }) it('Should fail with a bad display name', async function () { - const fields = immutableAssign(baseCorrectParams, { displayName: 'a'.repeat(150) }) + const fields = { ...baseCorrectParams, displayName: 'a'.repeat(150) } await makePostBodyRequest({ url: server.url, path: registrationPath, token: server.accessToken, fields }) }) it('Should fail with a bad channel name', async function () { - const fields = immutableAssign(baseCorrectParams, { channel: { name: '[]azf', displayName: 'toto' } }) + const fields = { ...baseCorrectParams, channel: { name: '[]azf', displayName: 'toto' } } await makePostBodyRequest({ url: server.url, path: registrationPath, token: server.accessToken, fields }) }) it('Should fail with a bad channel display name', async function () { - const fields = immutableAssign(baseCorrectParams, { channel: { name: 'toto', displayName: '' } }) + const fields = { ...baseCorrectParams, channel: { name: 'toto', displayName: '' } } await makePostBodyRequest({ url: server.url, path: registrationPath, token: server.accessToken, fields }) }) it('Should fail with a channel name that is the same as username', async function () { const source = { username: 'super_user', channel: { name: 'super_user', displayName: 'display name' } } - const fields = immutableAssign(baseCorrectParams, source) + const fields = { ...baseCorrectParams, ...source } await makePostBodyRequest({ url: server.url, path: registrationPath, token: server.accessToken, fields }) }) @@ -1043,7 +1046,7 @@ describe('Test users API validators', function () { const attributes = { name: 'existing_channel', displayName: 'hello', description: 'super description' } await server.channelsCommand.create({ attributes }) - const fields = immutableAssign(baseCorrectParams, { channel: { name: 'existing_channel', displayName: 'toto' } }) + const fields = { ...baseCorrectParams, channel: { name: 'existing_channel', displayName: 'toto' } } await makePostBodyRequest({ url: server.url, @@ -1055,7 +1058,7 @@ describe('Test users API validators', function () { }) it('Should succeed with the correct params', async function () { - const fields = immutableAssign(baseCorrectParams, { channel: { name: 'super_channel', displayName: 'toto' } }) + const fields = { ...baseCorrectParams, channel: { name: 'super_channel', displayName: 'toto' } } await makePostBodyRequest({ url: server.url, diff --git a/server/tests/api/check-params/video-channels.ts b/server/tests/api/check-params/video-channels.ts index d29346dc3..3b72d3796 100644 --- a/server/tests/api/check-params/video-channels.ts +++ b/server/tests/api/check-params/video-channels.ts @@ -3,14 +3,16 @@ import 'mocha' import * as chai from 'chai' import { omit } from 'lodash' -import { HttpStatusCode } from '../../../../shared/core-utils/miscs/http-error-codes' +import { HttpStatusCode } from '@shared/core-utils' import { buildAbsoluteFixturePath, ChannelsCommand, + checkBadCountPagination, + checkBadSortPagination, + checkBadStartPagination, cleanupTests, createUser, flushAndRunServer, - immutableAssign, makeGetRequest, makePostBodyRequest, makePutBodyRequest, @@ -18,13 +20,8 @@ import { ServerInfo, setAccessTokensToServers, userLogin -} from '../../../../shared/extra-utils' -import { - checkBadCountPagination, - checkBadSortPagination, - checkBadStartPagination -} from '../../../../shared/extra-utils/requests/check-api-params' -import { VideoChannelUpdate } from '../../../../shared/models/videos' +} from '@shared/extra-utils' +import { VideoChannelUpdate } from '@shared/models' const expect = chai.expect @@ -127,7 +124,7 @@ describe('Test video channels API validator', function () { }) it('Should fail with a bad name', async function () { - const fields = immutableAssign(baseCorrectParams, { name: 'super name' }) + const fields = { ...baseCorrectParams, name: 'super name' } await makePostBodyRequest({ url: server.url, path: videoChannelPath, token: server.accessToken, fields }) }) @@ -137,17 +134,17 @@ describe('Test video channels API validator', function () { }) it('Should fail with a long name', async function () { - const fields = immutableAssign(baseCorrectParams, { displayName: 'super'.repeat(25) }) + const fields = { ...baseCorrectParams, displayName: 'super'.repeat(25) } await makePostBodyRequest({ url: server.url, path: videoChannelPath, token: server.accessToken, fields }) }) it('Should fail with a long description', async function () { - const fields = immutableAssign(baseCorrectParams, { description: 'super'.repeat(201) }) + const fields = { ...baseCorrectParams, description: 'super'.repeat(201) } await makePostBodyRequest({ url: server.url, path: videoChannelPath, token: server.accessToken, fields }) }) it('Should fail with a long support text', async function () { - const fields = immutableAssign(baseCorrectParams, { support: 'super'.repeat(201) }) + const fields = { ...baseCorrectParams, support: 'super'.repeat(201) } await makePostBodyRequest({ url: server.url, path: videoChannelPath, token: server.accessToken, fields }) }) @@ -206,22 +203,22 @@ describe('Test video channels API validator', function () { }) it('Should fail with a long name', async function () { - const fields = immutableAssign(baseCorrectParams, { displayName: 'super'.repeat(25) }) + const fields = { ...baseCorrectParams, displayName: 'super'.repeat(25) } await makePutBodyRequest({ url: server.url, path, token: server.accessToken, fields }) }) it('Should fail with a long description', async function () { - const fields = immutableAssign(baseCorrectParams, { description: 'super'.repeat(201) }) + const fields = { ...baseCorrectParams, description: 'super'.repeat(201) } await makePutBodyRequest({ url: server.url, path, token: server.accessToken, fields }) }) it('Should fail with a long support text', async function () { - const fields = immutableAssign(baseCorrectParams, { support: 'super'.repeat(201) }) + const fields = { ...baseCorrectParams, support: 'super'.repeat(201) } await makePutBodyRequest({ url: server.url, path, token: server.accessToken, fields }) }) it('Should fail with a bad bulkVideosSupportUpdate field', async function () { - const fields = immutableAssign(baseCorrectParams, { bulkVideosSupportUpdate: 'super' }) + const fields = { ...baseCorrectParams, bulkVideosSupportUpdate: 'super' } await makePutBodyRequest({ url: server.url, path, token: server.accessToken, fields }) }) diff --git a/server/tests/api/check-params/video-imports.ts b/server/tests/api/check-params/video-imports.ts index ea473191e..2cc124cc1 100644 --- a/server/tests/api/check-params/video-imports.ts +++ b/server/tests/api/check-params/video-imports.ts @@ -12,7 +12,6 @@ import { createUser, flushAndRunServer, getMyUserInformation, - immutableAssign, ImportsCommand, makeGetRequest, makePostBodyRequest, @@ -108,43 +107,43 @@ describe('Test video imports API validator', function () { }) it('Should fail with a bad target url', async function () { - const fields = immutableAssign(baseCorrectParams, { targetUrl: 'htt://hello' }) + const fields = { ...baseCorrectParams, targetUrl: 'htt://hello' } await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields }) }) it('Should fail with a long name', async function () { - const fields = immutableAssign(baseCorrectParams, { name: 'super'.repeat(65) }) + const fields = { ...baseCorrectParams, name: 'super'.repeat(65) } await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields }) }) it('Should fail with a bad category', async function () { - const fields = immutableAssign(baseCorrectParams, { category: 125 }) + const fields = { ...baseCorrectParams, category: 125 } await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields }) }) it('Should fail with a bad licence', async function () { - const fields = immutableAssign(baseCorrectParams, { licence: 125 }) + const fields = { ...baseCorrectParams, licence: 125 } await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields }) }) it('Should fail with a bad language', async function () { - const fields = immutableAssign(baseCorrectParams, { language: 'a'.repeat(15) }) + const fields = { ...baseCorrectParams, language: 'a'.repeat(15) } await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields }) }) it('Should fail with a long description', async function () { - const fields = immutableAssign(baseCorrectParams, { description: 'super'.repeat(2500) }) + const fields = { ...baseCorrectParams, description: 'super'.repeat(2500) } await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields }) }) it('Should fail with a long support text', async function () { - const fields = immutableAssign(baseCorrectParams, { support: 'super'.repeat(201) }) + const fields = { ...baseCorrectParams, support: 'super'.repeat(201) } await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields }) }) @@ -156,7 +155,7 @@ describe('Test video imports API validator', function () { }) it('Should fail with a bad channel', async function () { - const fields = immutableAssign(baseCorrectParams, { channelId: 545454 }) + const fields = { ...baseCorrectParams, channelId: 545454 } await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields }) }) @@ -172,25 +171,25 @@ describe('Test video imports API validator', function () { const res = await getMyUserInformation(server.url, accessTokenUser) const customChannelId = res.body.videoChannels[0].id - const fields = immutableAssign(baseCorrectParams, { channelId: customChannelId }) + const fields = { ...baseCorrectParams, channelId: customChannelId } await makePostBodyRequest({ url: server.url, path, token: userAccessToken, fields }) }) it('Should fail with too many tags', async function () { - const fields = immutableAssign(baseCorrectParams, { tags: [ 'tag1', 'tag2', 'tag3', 'tag4', 'tag5', 'tag6' ] }) + const fields = { ...baseCorrectParams, tags: [ 'tag1', 'tag2', 'tag3', 'tag4', 'tag5', 'tag6' ] } await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields }) }) it('Should fail with a tag length too low', async function () { - const fields = immutableAssign(baseCorrectParams, { tags: [ 'tag1', 't' ] }) + const fields = { ...baseCorrectParams, tags: [ 'tag1', 't' ] } await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields }) }) it('Should fail with a tag length too big', async function () { - const fields = immutableAssign(baseCorrectParams, { tags: [ 'tag1', 'my_super_tag_too_long_long_long_long_long_long' ] }) + const fields = { ...baseCorrectParams, tags: [ 'tag1', 'my_super_tag_too_long_long_long_long_long_long' ] } await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields }) }) @@ -242,7 +241,7 @@ describe('Test video imports API validator', function () { it('Should fail with an invalid magnet URI', async function () { let fields = omit(baseCorrectParams, 'targetUrl') - fields = immutableAssign(fields, { magnetUri: 'blabla' }) + fields = { ...fields, magnetUri: 'blabla' } await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields }) }) @@ -301,7 +300,7 @@ describe('Test video imports API validator', function () { }) let fields = omit(baseCorrectParams, 'targetUrl') - fields = immutableAssign(fields, { magnetUri: ImportsCommand.getMagnetURI() }) + fields = { ...fields, magnetUri: ImportsCommand.getMagnetURI() } await makePostBodyRequest({ url: server.url, diff --git a/server/tests/api/check-params/video-playlists.ts b/server/tests/api/check-params/video-playlists.ts index 1c507a047..3799e73b6 100644 --- a/server/tests/api/check-params/video-playlists.ts +++ b/server/tests/api/check-params/video-playlists.ts @@ -1,6 +1,7 @@ /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */ import 'mocha' +import { HttpStatusCode } from '@shared/core-utils' import { VideoPlaylistCreate, VideoPlaylistCreateResult, @@ -10,7 +11,6 @@ import { VideoPlaylistReorder, VideoPlaylistType } from '@shared/models' -import { HttpStatusCode } from '../../../../shared/core-utils/miscs/http-error-codes' import { checkBadCountPagination, checkBadSortPagination, @@ -18,7 +18,6 @@ import { cleanupTests, flushAndRunServer, generateUserAccessToken, - immutableAssign, makeGetRequest, PlaylistsCommand, ServerInfo, @@ -214,7 +213,7 @@ describe('Test video playlists API validator', function () { } } const getUpdate = (params: any, playlistId: number | string) => { - return immutableAssign(params, { playlistId: playlistId }) + return { ...params, playlistId: playlistId } } it('Should fail with an unauthenticated user', async function () { diff --git a/server/tests/api/check-params/videos.ts b/server/tests/api/check-params/videos.ts index 4d7a9a23b..6549063b1 100644 --- a/server/tests/api/check-params/videos.ts +++ b/server/tests/api/check-params/videos.ts @@ -15,7 +15,6 @@ import { getMyUserInformation, getVideo, getVideosList, - immutableAssign, makeDeleteRequest, makeGetRequest, makePutBodyRequest, @@ -225,42 +224,42 @@ describe('Test videos API validator', function () { }) it('Should fail with a long name', async function () { - const fields = immutableAssign(baseCorrectParams, { name: 'super'.repeat(65) }) + const fields = { ...baseCorrectParams, name: 'super'.repeat(65) } const attaches = baseCorrectAttaches await checkUploadVideoParam(server.url, server.accessToken, { ...fields, ...attaches }, HttpStatusCode.BAD_REQUEST_400, mode) }) it('Should fail with a bad category', async function () { - const fields = immutableAssign(baseCorrectParams, { category: 125 }) + const fields = { ...baseCorrectParams, category: 125 } const attaches = baseCorrectAttaches await checkUploadVideoParam(server.url, server.accessToken, { ...fields, ...attaches }, HttpStatusCode.BAD_REQUEST_400, mode) }) it('Should fail with a bad licence', async function () { - const fields = immutableAssign(baseCorrectParams, { licence: 125 }) + const fields = { ...baseCorrectParams, licence: 125 } const attaches = baseCorrectAttaches await checkUploadVideoParam(server.url, server.accessToken, { ...fields, ...attaches }, HttpStatusCode.BAD_REQUEST_400, mode) }) it('Should fail with a bad language', async function () { - const fields = immutableAssign(baseCorrectParams, { language: 'a'.repeat(15) }) + const fields = { ...baseCorrectParams, language: 'a'.repeat(15) } const attaches = baseCorrectAttaches await checkUploadVideoParam(server.url, server.accessToken, { ...fields, ...attaches }, HttpStatusCode.BAD_REQUEST_400, mode) }) it('Should fail with a long description', async function () { - const fields = immutableAssign(baseCorrectParams, { description: 'super'.repeat(2500) }) + const fields = { ...baseCorrectParams, description: 'super'.repeat(2500) } const attaches = baseCorrectAttaches await checkUploadVideoParam(server.url, server.accessToken, { ...fields, ...attaches }, HttpStatusCode.BAD_REQUEST_400, mode) }) it('Should fail with a long support text', async function () { - const fields = immutableAssign(baseCorrectParams, { support: 'super'.repeat(201) }) + const fields = { ...baseCorrectParams, support: 'super'.repeat(201) } const attaches = baseCorrectAttaches await checkUploadVideoParam(server.url, server.accessToken, { ...fields, ...attaches }, HttpStatusCode.BAD_REQUEST_400, mode) @@ -274,7 +273,7 @@ describe('Test videos API validator', function () { }) it('Should fail with a bad channel', async function () { - const fields = immutableAssign(baseCorrectParams, { channelId: 545454 }) + const fields = { ...baseCorrectParams, channelId: 545454 } const attaches = baseCorrectAttaches await checkUploadVideoParam(server.url, server.accessToken, { ...fields, ...attaches }, HttpStatusCode.BAD_REQUEST_400, mode) @@ -291,54 +290,56 @@ describe('Test videos API validator', function () { const res = await getMyUserInformation(server.url, accessTokenUser) const customChannelId = res.body.videoChannels[0].id - const fields = immutableAssign(baseCorrectParams, { channelId: customChannelId }) + const fields = { ...baseCorrectParams, channelId: customChannelId } const attaches = baseCorrectAttaches await checkUploadVideoParam(server.url, userAccessToken, { ...fields, ...attaches }, HttpStatusCode.BAD_REQUEST_400, mode) }) it('Should fail with too many tags', async function () { - const fields = immutableAssign(baseCorrectParams, { tags: [ 'tag1', 'tag2', 'tag3', 'tag4', 'tag5', 'tag6' ] }) + const fields = { ...baseCorrectParams, tags: [ 'tag1', 'tag2', 'tag3', 'tag4', 'tag5', 'tag6' ] } const attaches = baseCorrectAttaches await checkUploadVideoParam(server.url, server.accessToken, { ...fields, ...attaches }, HttpStatusCode.BAD_REQUEST_400, mode) }) it('Should fail with a tag length too low', async function () { - const fields = immutableAssign(baseCorrectParams, { tags: [ 'tag1', 't' ] }) + const fields = { ...baseCorrectParams, tags: [ 'tag1', 't' ] } const attaches = baseCorrectAttaches await checkUploadVideoParam(server.url, server.accessToken, { ...fields, ...attaches }, HttpStatusCode.BAD_REQUEST_400, mode) }) it('Should fail with a tag length too big', async function () { - const fields = immutableAssign(baseCorrectParams, { tags: [ 'tag1', 'my_super_tag_too_long_long_long_long_long_long' ] }) + const fields = { ...baseCorrectParams, tags: [ 'tag1', 'my_super_tag_too_long_long_long_long_long_long' ] } const attaches = baseCorrectAttaches await checkUploadVideoParam(server.url, server.accessToken, { ...fields, ...attaches }, HttpStatusCode.BAD_REQUEST_400, mode) }) it('Should fail with a bad schedule update (miss updateAt)', async function () { - const fields = immutableAssign(baseCorrectParams, { scheduleUpdate: { privacy: VideoPrivacy.PUBLIC } }) + const fields = { ...baseCorrectParams, scheduleUpdate: { privacy: VideoPrivacy.PUBLIC } } const attaches = baseCorrectAttaches await checkUploadVideoParam(server.url, server.accessToken, { ...fields, ...attaches }, HttpStatusCode.BAD_REQUEST_400, mode) }) it('Should fail with a bad schedule update (wrong updateAt)', async function () { - const fields = immutableAssign(baseCorrectParams, { + const fields = { + ...baseCorrectParams, + scheduleUpdate: { privacy: VideoPrivacy.PUBLIC, updateAt: 'toto' } - }) + } const attaches = baseCorrectAttaches await checkUploadVideoParam(server.url, server.accessToken, { ...fields, ...attaches }, HttpStatusCode.BAD_REQUEST_400, mode) }) it('Should fail with a bad originally published at attribute', async function () { - const fields = immutableAssign(baseCorrectParams, { originallyPublishedAt: 'toto' }) + const fields = { ...baseCorrectParams, originallyPublishedAt: 'toto' } const attaches = baseCorrectAttaches await checkUploadVideoParam(server.url, server.accessToken, { ...fields, ...attaches }, HttpStatusCode.BAD_REQUEST_400, mode) @@ -413,7 +414,7 @@ describe('Test videos API validator', function () { }) it('Should report the appropriate error', async function () { - const fields = immutableAssign(baseCorrectParams, { language: 'a'.repeat(15) }) + const fields = { ...baseCorrectParams, language: 'a'.repeat(15) } const attaches = baseCorrectAttaches const attributes = { ...fields, ...attaches } @@ -448,17 +449,21 @@ describe('Test videos API validator', function () { } { - const attaches = immutableAssign(baseCorrectAttaches, { + const attaches = { + ...baseCorrectAttaches, + videofile: join(root(), 'server', 'tests', 'fixtures', 'video_short.mp4') - }) + } await checkUploadVideoParam(server.url, server.accessToken, { ...fields, ...attaches }, HttpStatusCode.OK_200, mode) } { - const attaches = immutableAssign(baseCorrectAttaches, { + const attaches = { + ...baseCorrectAttaches, + videofile: join(root(), 'server', 'tests', 'fixtures', 'video_short.ogv') - }) + } await checkUploadVideoParam(server.url, server.accessToken, { ...fields, ...attaches }, HttpStatusCode.OK_200, mode) } @@ -516,79 +521,79 @@ describe('Test videos API validator', function () { }) it('Should fail with a long name', async function () { - const fields = immutableAssign(baseCorrectParams, { name: 'super'.repeat(65) }) + const fields = { ...baseCorrectParams, name: 'super'.repeat(65) } await makePutBodyRequest({ url: server.url, path: path + video.shortUUID, token: server.accessToken, fields }) }) it('Should fail with a bad category', async function () { - const fields = immutableAssign(baseCorrectParams, { category: 125 }) + const fields = { ...baseCorrectParams, category: 125 } await makePutBodyRequest({ url: server.url, path: path + video.shortUUID, token: server.accessToken, fields }) }) it('Should fail with a bad licence', async function () { - const fields = immutableAssign(baseCorrectParams, { licence: 125 }) + const fields = { ...baseCorrectParams, licence: 125 } await makePutBodyRequest({ url: server.url, path: path + video.shortUUID, token: server.accessToken, fields }) }) it('Should fail with a bad language', async function () { - const fields = immutableAssign(baseCorrectParams, { language: 'a'.repeat(15) }) + const fields = { ...baseCorrectParams, language: 'a'.repeat(15) } await makePutBodyRequest({ url: server.url, path: path + video.shortUUID, token: server.accessToken, fields }) }) it('Should fail with a long description', async function () { - const fields = immutableAssign(baseCorrectParams, { description: 'super'.repeat(2500) }) + const fields = { ...baseCorrectParams, description: 'super'.repeat(2500) } await makePutBodyRequest({ url: server.url, path: path + video.shortUUID, token: server.accessToken, fields }) }) it('Should fail with a long support text', async function () { - const fields = immutableAssign(baseCorrectParams, { support: 'super'.repeat(201) }) + const fields = { ...baseCorrectParams, support: 'super'.repeat(201) } await makePutBodyRequest({ url: server.url, path: path + video.shortUUID, token: server.accessToken, fields }) }) it('Should fail with a bad channel', async function () { - const fields = immutableAssign(baseCorrectParams, { channelId: 545454 }) + const fields = { ...baseCorrectParams, channelId: 545454 } await makePutBodyRequest({ url: server.url, path: path + video.shortUUID, token: server.accessToken, fields }) }) it('Should fail with too many tags', async function () { - const fields = immutableAssign(baseCorrectParams, { tags: [ 'tag1', 'tag2', 'tag3', 'tag4', 'tag5', 'tag6' ] }) + const fields = { ...baseCorrectParams, tags: [ 'tag1', 'tag2', 'tag3', 'tag4', 'tag5', 'tag6' ] } await makePutBodyRequest({ url: server.url, path: path + video.shortUUID, token: server.accessToken, fields }) }) it('Should fail with a tag length too low', async function () { - const fields = immutableAssign(baseCorrectParams, { tags: [ 'tag1', 't' ] }) + const fields = { ...baseCorrectParams, tags: [ 'tag1', 't' ] } await makePutBodyRequest({ url: server.url, path: path + video.shortUUID, token: server.accessToken, fields }) }) it('Should fail with a tag length too big', async function () { - const fields = immutableAssign(baseCorrectParams, { tags: [ 'tag1', 'my_super_tag_too_long_long_long_long_long_long' ] }) + const fields = { ...baseCorrectParams, tags: [ 'tag1', 'my_super_tag_too_long_long_long_long_long_long' ] } await makePutBodyRequest({ url: server.url, path: path + video.shortUUID, token: server.accessToken, fields }) }) it('Should fail with a bad schedule update (miss updateAt)', async function () { - const fields = immutableAssign(baseCorrectParams, { scheduleUpdate: { privacy: VideoPrivacy.PUBLIC } }) + const fields = { ...baseCorrectParams, scheduleUpdate: { privacy: VideoPrivacy.PUBLIC } } await makePutBodyRequest({ url: server.url, path: path + video.shortUUID, token: server.accessToken, fields }) }) it('Should fail with a bad schedule update (wrong updateAt)', async function () { - const fields = immutableAssign(baseCorrectParams, { scheduleUpdate: { updateAt: 'toto', privacy: VideoPrivacy.PUBLIC } }) + const fields = { ...baseCorrectParams, scheduleUpdate: { updateAt: 'toto', privacy: VideoPrivacy.PUBLIC } } await makePutBodyRequest({ url: server.url, path: path + video.shortUUID, token: server.accessToken, fields }) }) it('Should fail with a bad originally published at param', async function () { - const fields = immutableAssign(baseCorrectParams, { originallyPublishedAt: 'toto' }) + const fields = { ...baseCorrectParams, originallyPublishedAt: 'toto' } await makePutBodyRequest({ url: server.url, path: path + video.shortUUID, token: server.accessToken, fields }) }) @@ -672,7 +677,7 @@ describe('Test videos API validator', function () { it('Should fail with a video of another server') it('Shoud report the appropriate error', async function () { - const fields = immutableAssign(baseCorrectParams, { licence: 125 }) + const fields = { ...baseCorrectParams, licence: 125 } const res = await makePutBodyRequest({ url: server.url, path: path + video.shortUUID, token: server.accessToken, fields }) const error = res.body as PeerTubeProblemDocument -- cgit v1.2.3 From 41d1d075011174e73dccb74006181a92a618d7b4 Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Tue, 13 Jul 2021 11:05:15 +0200 Subject: Introduce login command --- server/tests/api/check-params/abuses.ts | 3 +-- server/tests/api/check-params/blocklist.ts | 5 ++--- server/tests/api/check-params/bulk.ts | 5 ++--- server/tests/api/check-params/config.ts | 5 ++--- server/tests/api/check-params/custom-pages.ts | 5 ++--- server/tests/api/check-params/debug.ts | 5 ++--- server/tests/api/check-params/follows.ts | 5 ++--- server/tests/api/check-params/jobs.ts | 5 ++--- server/tests/api/check-params/live.ts | 7 +++---- server/tests/api/check-params/logs.ts | 5 ++--- server/tests/api/check-params/plugins.ts | 5 ++--- server/tests/api/check-params/redundancy.ts | 3 +-- server/tests/api/check-params/upload-quota.ts | 5 ++--- server/tests/api/check-params/user-subscriptions.ts | 5 ++--- server/tests/api/check-params/users.ts | 9 ++++----- server/tests/api/check-params/video-blacklist.ts | 5 ++--- server/tests/api/check-params/video-captions.ts | 5 ++--- server/tests/api/check-params/video-channels.ts | 5 ++--- server/tests/api/check-params/video-comments.ts | 7 +++---- server/tests/api/check-params/video-imports.ts | 7 +++---- server/tests/api/check-params/videos-filter.ts | 7 +++---- server/tests/api/check-params/videos.ts | 7 +++---- 22 files changed, 49 insertions(+), 71 deletions(-) (limited to 'server/tests/api/check-params') diff --git a/server/tests/api/check-params/abuses.ts b/server/tests/api/check-params/abuses.ts index e158e50dc..14949d301 100644 --- a/server/tests/api/check-params/abuses.ts +++ b/server/tests/api/check-params/abuses.ts @@ -18,7 +18,6 @@ import { ServerInfo, setAccessTokensToServers, uploadVideo, - userLogin, waitJobs } from '@shared/extra-utils' import { AbuseCreate, AbuseState } from '@shared/models' @@ -47,7 +46,7 @@ describe('Test abuses API validators', function () { const username = 'user1' const password = 'my super password' await createUser({ url: server.url, accessToken: server.accessToken, username: username, password: password }) - userToken = await userLogin(server, { username, password }) + userToken = await server.loginCommand.getAccessToken({ username, password }) userToken2 = await generateUserAccessToken(server, 'user_2') diff --git a/server/tests/api/check-params/blocklist.ts b/server/tests/api/check-params/blocklist.ts index 5ed8810ce..11a79387f 100644 --- a/server/tests/api/check-params/blocklist.ts +++ b/server/tests/api/check-params/blocklist.ts @@ -11,8 +11,7 @@ import { makeGetRequest, makePostBodyRequest, ServerInfo, - setAccessTokensToServers, - userLogin + setAccessTokensToServers } from '../../../../shared/extra-utils' import { checkBadCountPagination, @@ -37,7 +36,7 @@ describe('Test blocklist API validators', function () { const user = { username: 'user1', password: 'password' } await createUser({ url: server.url, accessToken: server.accessToken, username: user.username, password: user.password }) - userAccessToken = await userLogin(server, user) + userAccessToken = await server.loginCommand.getAccessToken(user) await doubleFollow(servers[0], servers[1]) }) diff --git a/server/tests/api/check-params/bulk.ts b/server/tests/api/check-params/bulk.ts index 07b920ba7..85520b3bd 100644 --- a/server/tests/api/check-params/bulk.ts +++ b/server/tests/api/check-params/bulk.ts @@ -6,8 +6,7 @@ import { createUser, flushAndRunServer, ServerInfo, - setAccessTokensToServers, - userLogin + setAccessTokensToServers } from '../../../../shared/extra-utils' import { makePostBodyRequest } from '../../../../shared/extra-utils/requests/requests' import { HttpStatusCode } from '../../../../shared/core-utils/miscs/http-error-codes' @@ -27,7 +26,7 @@ describe('Test bulk API validators', function () { const user = { username: 'user1', password: 'password' } await createUser({ url: server.url, accessToken: server.accessToken, username: user.username, password: user.password }) - userAccessToken = await userLogin(server, user) + userAccessToken = await server.loginCommand.getAccessToken(user) }) describe('When removing comments of', function () { diff --git a/server/tests/api/check-params/config.ts b/server/tests/api/check-params/config.ts index 291de93ea..e93523e4b 100644 --- a/server/tests/api/check-params/config.ts +++ b/server/tests/api/check-params/config.ts @@ -11,8 +11,7 @@ import { makeGetRequest, makePutBodyRequest, ServerInfo, - setAccessTokensToServers, - userLogin + setAccessTokensToServers } from '@shared/extra-utils' import { CustomConfig } from '@shared/models' @@ -208,7 +207,7 @@ describe('Test config API validators', function () { password: 'password' } await createUser({ url: server.url, accessToken: server.accessToken, username: user.username, password: user.password }) - userAccessToken = await userLogin(server, user) + userAccessToken = await server.loginCommand.getAccessToken(user) }) describe('When getting the configuration', function () { diff --git a/server/tests/api/check-params/custom-pages.ts b/server/tests/api/check-params/custom-pages.ts index 74ca3384c..c1dd258aa 100644 --- a/server/tests/api/check-params/custom-pages.ts +++ b/server/tests/api/check-params/custom-pages.ts @@ -7,8 +7,7 @@ import { createUser, flushAndRunServer, ServerInfo, - setAccessTokensToServers, - userLogin + setAccessTokensToServers } from '../../../../shared/extra-utils' import { makeGetRequest, makePutBodyRequest } from '../../../../shared/extra-utils/requests/requests' @@ -29,7 +28,7 @@ describe('Test custom pages validators', function () { const user = { username: 'user1', password: 'password' } await createUser({ url: server.url, accessToken: server.accessToken, username: user.username, password: user.password }) - userAccessToken = await userLogin(server, user) + userAccessToken = await server.loginCommand.getAccessToken(user) }) describe('When updating instance homepage', function () { diff --git a/server/tests/api/check-params/debug.ts b/server/tests/api/check-params/debug.ts index 37bf0f99b..dc033a441 100644 --- a/server/tests/api/check-params/debug.ts +++ b/server/tests/api/check-params/debug.ts @@ -7,8 +7,7 @@ import { createUser, flushAndRunServer, ServerInfo, - setAccessTokensToServers, - userLogin + setAccessTokensToServers } from '../../../../shared/extra-utils' import { makeGetRequest } from '../../../../shared/extra-utils/requests/requests' import { HttpStatusCode } from '../../../../shared/core-utils/miscs/http-error-codes' @@ -32,7 +31,7 @@ describe('Test debug API validators', function () { password: 'my super password' } await createUser({ url: server.url, accessToken: server.accessToken, username: user.username, password: user.password }) - userAccessToken = await userLogin(server, user) + userAccessToken = await server.loginCommand.getAccessToken(user) }) describe('When getting debug endpoint', function () { diff --git a/server/tests/api/check-params/follows.ts b/server/tests/api/check-params/follows.ts index c03dd5c9c..8cf5b130e 100644 --- a/server/tests/api/check-params/follows.ts +++ b/server/tests/api/check-params/follows.ts @@ -9,8 +9,7 @@ import { makeDeleteRequest, makeGetRequest, makePostBodyRequest, ServerInfo, - setAccessTokensToServers, - userLogin + setAccessTokensToServers } from '../../../../shared/extra-utils' import { checkBadCountPagination, @@ -42,7 +41,7 @@ describe('Test server follows API validators', function () { } await createUser({ url: server.url, accessToken: server.accessToken, username: user.username, password: user.password }) - userAccessToken = await userLogin(server, user) + userAccessToken = await server.loginCommand.getAccessToken(user) }) describe('When adding follows', function () { diff --git a/server/tests/api/check-params/jobs.ts b/server/tests/api/check-params/jobs.ts index 3c1d2049b..cbe6a28b8 100644 --- a/server/tests/api/check-params/jobs.ts +++ b/server/tests/api/check-params/jobs.ts @@ -7,8 +7,7 @@ import { createUser, flushAndRunServer, ServerInfo, - setAccessTokensToServers, - userLogin + setAccessTokensToServers } from '../../../../shared/extra-utils' import { checkBadCountPagination, @@ -37,7 +36,7 @@ describe('Test jobs API validators', function () { password: 'my super password' } await createUser({ url: server.url, accessToken: server.accessToken, username: user.username, password: user.password }) - userAccessToken = await userLogin(server, user) + userAccessToken = await server.loginCommand.getAccessToken(user) }) describe('When listing jobs', function () { diff --git a/server/tests/api/check-params/live.ts b/server/tests/api/check-params/live.ts index 394967285..045f3a1b1 100644 --- a/server/tests/api/check-params/live.ts +++ b/server/tests/api/check-params/live.ts @@ -17,8 +17,7 @@ import { ServerInfo, setAccessTokensToServers, stopFfmpeg, - uploadVideoAndGetId, - userLogin + uploadVideoAndGetId } from '../../../../shared/extra-utils' describe('Test video lives API validator', function () { @@ -53,7 +52,7 @@ describe('Test video lives API validator', function () { const username = 'user1' const password = 'my super password' await createUser({ url: server.url, accessToken: server.accessToken, username: username, password: password }) - userAccessToken = await userLogin(server, { username, password }) + userAccessToken = await server.loginCommand.getAccessToken({ username, password }) { const res = await getMyUserInformation(server.url, server.accessToken) @@ -150,7 +149,7 @@ describe('Test video lives API validator', function () { } await createUser({ url: server.url, accessToken: server.accessToken, username: user.username, password: user.password }) - const accessTokenUser = await userLogin(server, user) + const accessTokenUser = await server.loginCommand.getAccessToken(user) const res = await getMyUserInformation(server.url, accessTokenUser) const customChannelId = res.body.videoChannels[0].id diff --git a/server/tests/api/check-params/logs.ts b/server/tests/api/check-params/logs.ts index dac1e6b98..83ecfec93 100644 --- a/server/tests/api/check-params/logs.ts +++ b/server/tests/api/check-params/logs.ts @@ -7,8 +7,7 @@ import { createUser, flushAndRunServer, ServerInfo, - setAccessTokensToServers, - userLogin + setAccessTokensToServers } from '../../../../shared/extra-utils' import { makeGetRequest } from '../../../../shared/extra-utils/requests/requests' import { HttpStatusCode } from '../../../../shared/core-utils/miscs/http-error-codes' @@ -32,7 +31,7 @@ describe('Test logs API validators', function () { password: 'my super password' } await createUser({ url: server.url, accessToken: server.accessToken, username: user.username, password: user.password }) - userAccessToken = await userLogin(server, user) + userAccessToken = await server.loginCommand.getAccessToken(user) }) describe('When getting logs', function () { diff --git a/server/tests/api/check-params/plugins.ts b/server/tests/api/check-params/plugins.ts index 8509b8ac5..130cf6869 100644 --- a/server/tests/api/check-params/plugins.ts +++ b/server/tests/api/check-params/plugins.ts @@ -13,8 +13,7 @@ import { makePostBodyRequest, makePutBodyRequest, ServerInfo, - setAccessTokensToServers, - userLogin + setAccessTokensToServers } from '@shared/extra-utils' import { PeerTubePlugin, PluginType } from '@shared/models' @@ -45,7 +44,7 @@ describe('Test server plugins API validators', function () { } await createUser({ url: server.url, accessToken: server.accessToken, username: user.username, password: user.password }) - userAccessToken = await userLogin(server, user) + userAccessToken = await server.loginCommand.getAccessToken(user) { const res = await server.pluginsCommand.install({ npmName: npmPlugin }) diff --git a/server/tests/api/check-params/redundancy.ts b/server/tests/api/check-params/redundancy.ts index dac6938de..2e10e378a 100644 --- a/server/tests/api/check-params/redundancy.ts +++ b/server/tests/api/check-params/redundancy.ts @@ -19,7 +19,6 @@ import { ServerInfo, setAccessTokensToServers, uploadVideoAndGetId, - userLogin, waitJobs } from '../../../../shared/extra-utils' @@ -45,7 +44,7 @@ describe('Test server redundancy API validators', function () { } await createUser({ url: servers[0].url, accessToken: servers[0].accessToken, username: user.username, password: user.password }) - userAccessToken = await userLogin(servers[0], user) + userAccessToken = await servers[0].loginCommand.getAccessToken(user) videoIdLocal = (await uploadVideoAndGetId({ server: servers[0], videoName: 'video' })).id diff --git a/server/tests/api/check-params/upload-quota.ts b/server/tests/api/check-params/upload-quota.ts index c444663b8..3dc6cf2b4 100644 --- a/server/tests/api/check-params/upload-quota.ts +++ b/server/tests/api/check-params/upload-quota.ts @@ -15,7 +15,6 @@ import { setDefaultVideoChannel, updateUser, uploadVideo, - userLogin, waitJobs } from '../../../../shared/extra-utils' @@ -50,7 +49,7 @@ describe('Test upload quota', function () { const user = { username: 'registered' + randomInt(1, 1500), password: 'password' } await registerUser(server.url, user.username, user.password) - const userAccessToken = await userLogin(server, user) + const userAccessToken = await server.loginCommand.getAccessToken(user) const videoAttributes = { fixture: 'video_short2.webm' } for (let i = 0; i < 5; i++) { @@ -65,7 +64,7 @@ describe('Test upload quota', function () { const user = { username: 'registered' + randomInt(1, 1500), password: 'password' } await registerUser(server.url, user.username, user.password) - const userAccessToken = await userLogin(server, user) + const userAccessToken = await server.loginCommand.getAccessToken(user) const videoAttributes = { fixture: 'video_short2.webm' } for (let i = 0; i < 5; i++) { diff --git a/server/tests/api/check-params/user-subscriptions.ts b/server/tests/api/check-params/user-subscriptions.ts index 538201647..64e2703b9 100644 --- a/server/tests/api/check-params/user-subscriptions.ts +++ b/server/tests/api/check-params/user-subscriptions.ts @@ -10,8 +10,7 @@ import { makeGetRequest, makePostBodyRequest, ServerInfo, - setAccessTokensToServers, - userLogin + setAccessTokensToServers } from '../../../../shared/extra-utils' import { @@ -41,7 +40,7 @@ describe('Test user subscriptions API validators', function () { password: 'my super password' } await createUser({ url: server.url, accessToken: server.accessToken, username: user.username, password: user.password }) - userAccessToken = await userLogin(server, user) + userAccessToken = await server.loginCommand.getAccessToken(user) }) describe('When listing my subscriptions', function () { diff --git a/server/tests/api/check-params/users.ts b/server/tests/api/check-params/users.ts index fda7e9640..54baeebe1 100644 --- a/server/tests/api/check-params/users.ts +++ b/server/tests/api/check-params/users.ts @@ -27,8 +27,7 @@ import { ServerInfo, setAccessTokensToServers, unblockUser, - uploadVideo, - userLogin + uploadVideo } from '../../../../shared/extra-utils' import { MockSmtpServer } from '../../../../shared/extra-utils/mock-servers/mock-email' import { @@ -87,7 +86,7 @@ describe('Test users API validators', function () { password: user.password, videoQuota: videoQuota }) - userAccessToken = await userLogin(server, user) + userAccessToken = await server.loginCommand.getAccessToken(user) } { @@ -104,7 +103,7 @@ describe('Test users API validators', function () { role: UserRole.MODERATOR }) - moderatorAccessToken = await userLogin(server, moderator) + moderatorAccessToken = await server.loginCommand.getAccessToken(moderator) } { @@ -394,7 +393,7 @@ describe('Test users API validators', function () { username: 'user1', password: 'my super password' } - userAccessToken = await userLogin(server, user) + userAccessToken = await server.loginCommand.getAccessToken(user) const fields = { username: 'user3', diff --git a/server/tests/api/check-params/video-blacklist.ts b/server/tests/api/check-params/video-blacklist.ts index 98cf2e11a..c33bc196d 100644 --- a/server/tests/api/check-params/video-blacklist.ts +++ b/server/tests/api/check-params/video-blacklist.ts @@ -19,7 +19,6 @@ import { ServerInfo, setAccessTokensToServers, uploadVideo, - userLogin, waitJobs } from '@shared/extra-utils' import { VideoBlacklistType, VideoDetails } from '@shared/models' @@ -46,14 +45,14 @@ describe('Test video blacklist API validators', function () { const username = 'user1' const password = 'my super password' await createUser({ url: servers[0].url, accessToken: servers[0].accessToken, username: username, password: password }) - userAccessToken1 = await userLogin(servers[0], { username, password }) + userAccessToken1 = await servers[0].loginCommand.getAccessToken({ username, password }) } { const username = 'user2' const password = 'my super password' await createUser({ url: servers[0].url, accessToken: servers[0].accessToken, username: username, password: password }) - userAccessToken2 = await userLogin(servers[0], { username, password }) + userAccessToken2 = await servers[0].loginCommand.getAccessToken({ username, password }) } { diff --git a/server/tests/api/check-params/video-captions.ts b/server/tests/api/check-params/video-captions.ts index baab0f276..f2fd61b91 100644 --- a/server/tests/api/check-params/video-captions.ts +++ b/server/tests/api/check-params/video-captions.ts @@ -12,8 +12,7 @@ import { makeUploadRequest, ServerInfo, setAccessTokensToServers, - uploadVideo, - userLogin + uploadVideo } from '@shared/extra-utils' import { VideoCreateResult } from '@shared/models' @@ -44,7 +43,7 @@ describe('Test video captions API validator', function () { password: 'my super password' } await createUser({ url: server.url, accessToken: server.accessToken, username: user.username, password: user.password }) - userAccessToken = await userLogin(server, user) + userAccessToken = await server.loginCommand.getAccessToken(user) } }) diff --git a/server/tests/api/check-params/video-channels.ts b/server/tests/api/check-params/video-channels.ts index 3b72d3796..5361f6917 100644 --- a/server/tests/api/check-params/video-channels.ts +++ b/server/tests/api/check-params/video-channels.ts @@ -18,8 +18,7 @@ import { makePutBodyRequest, makeUploadRequest, ServerInfo, - setAccessTokensToServers, - userLogin + setAccessTokensToServers } from '@shared/extra-utils' import { VideoChannelUpdate } from '@shared/models' @@ -47,7 +46,7 @@ describe('Test video channels API validator', function () { { await createUser({ url: server.url, accessToken: server.accessToken, username: user.username, password: user.password }) - accessTokenUser = await userLogin(server, user) + accessTokenUser = await server.loginCommand.getAccessToken(user) } command = server.channelsCommand diff --git a/server/tests/api/check-params/video-comments.ts b/server/tests/api/check-params/video-comments.ts index 0f8c81392..c21aebaae 100644 --- a/server/tests/api/check-params/video-comments.ts +++ b/server/tests/api/check-params/video-comments.ts @@ -15,8 +15,7 @@ import { makePostBodyRequest, ServerInfo, setAccessTokensToServers, - uploadVideo, - userLogin + uploadVideo } from '@shared/extra-utils' import { VideoCreateResult } from '@shared/models' @@ -55,13 +54,13 @@ describe('Test video comments API validator', function () { { 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) + userAccessToken = await server.loginCommand.getAccessToken(user) } { const user = { username: 'user2', password: 'my super password' } await createUser({ url: server.url, accessToken: server.accessToken, username: user.username, password: user.password }) - userAccessToken2 = await userLogin(server, user) + userAccessToken2 = await server.loginCommand.getAccessToken(user) } }) diff --git a/server/tests/api/check-params/video-imports.ts b/server/tests/api/check-params/video-imports.ts index 2cc124cc1..51260affa 100644 --- a/server/tests/api/check-params/video-imports.ts +++ b/server/tests/api/check-params/video-imports.ts @@ -17,8 +17,7 @@ import { makePostBodyRequest, makeUploadRequest, ServerInfo, - setAccessTokensToServers, - userLogin + setAccessTokensToServers } from '@shared/extra-utils' import { VideoPrivacy } from '@shared/models' @@ -40,7 +39,7 @@ describe('Test video imports API validator', function () { const username = 'user1' const password = 'my super password' await createUser({ url: server.url, accessToken: server.accessToken, username: username, password: password }) - userAccessToken = await userLogin(server, { username, password }) + userAccessToken = await server.loginCommand.getAccessToken({ username, password }) { const res = await getMyUserInformation(server.url, server.accessToken) @@ -167,7 +166,7 @@ describe('Test video imports API validator', function () { } await createUser({ url: server.url, accessToken: server.accessToken, username: user.username, password: user.password }) - const accessTokenUser = await userLogin(server, user) + const accessTokenUser = await server.loginCommand.getAccessToken(user) const res = await getMyUserInformation(server.url, accessTokenUser) const customChannelId = res.body.videoChannels[0].id diff --git a/server/tests/api/check-params/videos-filter.ts b/server/tests/api/check-params/videos-filter.ts index 4d54a4fd0..095b94656 100644 --- a/server/tests/api/check-params/videos-filter.ts +++ b/server/tests/api/check-params/videos-filter.ts @@ -8,8 +8,7 @@ import { makeGetRequest, ServerInfo, setAccessTokensToServers, - setDefaultVideoChannel, - userLogin + setDefaultVideoChannel } from '../../../../shared/extra-utils' import { UserRole } from '../../../../shared/models/users' import { HttpStatusCode } from '../../../../shared/core-utils/miscs/http-error-codes' @@ -52,7 +51,7 @@ describe('Test video filters validators', function () { 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) + userAccessToken = await server.loginCommand.getAccessToken(user) const moderator = { username: 'moderator', password: 'my super password' } await createUser( @@ -66,7 +65,7 @@ describe('Test video filters validators', function () { role: UserRole.MODERATOR } ) - moderatorAccessToken = await userLogin(server, moderator) + moderatorAccessToken = await server.loginCommand.getAccessToken(moderator) }) describe('When setting a video filter', function () { diff --git a/server/tests/api/check-params/videos.ts b/server/tests/api/check-params/videos.ts index 6549063b1..8e11232bd 100644 --- a/server/tests/api/check-params/videos.ts +++ b/server/tests/api/check-params/videos.ts @@ -22,8 +22,7 @@ import { removeVideo, root, ServerInfo, - setAccessTokensToServers, - userLogin + setAccessTokensToServers } from '../../../../shared/extra-utils' import { checkBadCountPagination, @@ -55,7 +54,7 @@ describe('Test videos API validator', function () { const username = 'user1' const password = 'my super password' await createUser({ url: server.url, accessToken: server.accessToken, username: username, password: password }) - userAccessToken = await userLogin(server, { username, password }) + userAccessToken = await server.loginCommand.getAccessToken({ username, password }) { const res = await getMyUserInformation(server.url, server.accessToken) @@ -286,7 +285,7 @@ describe('Test videos API validator', function () { } await createUser({ url: server.url, accessToken: server.accessToken, username: user.username, password: user.password }) - const accessTokenUser = await userLogin(server, user) + const accessTokenUser = await server.loginCommand.getAccessToken(user) const res = await getMyUserInformation(server.url, accessTokenUser) const customChannelId = res.body.videoChannels[0].id -- cgit v1.2.3 From 7926c5f9b3ffcabb1ffb0dcfa5e48b8e0b88fbc0 Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Tue, 13 Jul 2021 14:23:01 +0200 Subject: Introduce user command --- server/tests/api/check-params/abuses.ts | 6 +- server/tests/api/check-params/blocklist.ts | 3 +- server/tests/api/check-params/bulk.ts | 3 +- server/tests/api/check-params/config.ts | 3 +- server/tests/api/check-params/custom-pages.ts | 3 +- server/tests/api/check-params/debug.ts | 3 +- server/tests/api/check-params/follows.ts | 3 +- server/tests/api/check-params/jobs.ts | 3 +- server/tests/api/check-params/live.ts | 20 +- server/tests/api/check-params/logs.ts | 3 +- server/tests/api/check-params/plugins.ts | 3 +- server/tests/api/check-params/redundancy.ts | 3 +- server/tests/api/check-params/upload-quota.ts | 35 +-- .../tests/api/check-params/user-subscriptions.ts | 3 +- server/tests/api/check-params/users.ts | 243 +++++++++------------ server/tests/api/check-params/video-blacklist.ts | 5 +- server/tests/api/check-params/video-captions.ts | 3 +- server/tests/api/check-params/video-channels.ts | 3 +- server/tests/api/check-params/video-comments.ts | 5 +- server/tests/api/check-params/video-imports.ts | 14 +- server/tests/api/check-params/video-playlists.ts | 3 +- server/tests/api/check-params/videos-filter.ts | 16 +- server/tests/api/check-params/videos.ts | 18 +- 23 files changed, 163 insertions(+), 241 deletions(-) (limited to 'server/tests/api/check-params') diff --git a/server/tests/api/check-params/abuses.ts b/server/tests/api/check-params/abuses.ts index 14949d301..4cd10a6fd 100644 --- a/server/tests/api/check-params/abuses.ts +++ b/server/tests/api/check-params/abuses.ts @@ -8,10 +8,8 @@ import { checkBadSortPagination, checkBadStartPagination, cleanupTests, - createUser, doubleFollow, flushAndRunServer, - generateUserAccessToken, getVideoIdFromUUID, makeGetRequest, makePostBodyRequest, @@ -45,10 +43,10 @@ describe('Test abuses API validators', function () { const username = 'user1' const password = 'my super password' - await createUser({ url: server.url, accessToken: server.accessToken, username: username, password: password }) + await server.usersCommand.create({ username: username, password: password }) userToken = await server.loginCommand.getAccessToken({ username, password }) - userToken2 = await generateUserAccessToken(server, 'user_2') + userToken2 = await server.usersCommand.generateUserAndToken('user_2') const res = await uploadVideo(server.url, server.accessToken, {}) server.video = res.body.video diff --git a/server/tests/api/check-params/blocklist.ts b/server/tests/api/check-params/blocklist.ts index 11a79387f..18238bb04 100644 --- a/server/tests/api/check-params/blocklist.ts +++ b/server/tests/api/check-params/blocklist.ts @@ -4,7 +4,6 @@ import 'mocha' import { cleanupTests, - createUser, doubleFollow, flushAndRunMultipleServers, makeDeleteRequest, @@ -34,7 +33,7 @@ describe('Test blocklist API validators', function () { server = servers[0] const user = { username: 'user1', password: 'password' } - await createUser({ url: server.url, accessToken: server.accessToken, username: user.username, password: user.password }) + await server.usersCommand.create({ username: user.username, password: user.password }) userAccessToken = await server.loginCommand.getAccessToken(user) diff --git a/server/tests/api/check-params/bulk.ts b/server/tests/api/check-params/bulk.ts index 85520b3bd..3f80c79a8 100644 --- a/server/tests/api/check-params/bulk.ts +++ b/server/tests/api/check-params/bulk.ts @@ -3,7 +3,6 @@ import 'mocha' import { cleanupTests, - createUser, flushAndRunServer, ServerInfo, setAccessTokensToServers @@ -24,7 +23,7 @@ describe('Test bulk API validators', function () { await setAccessTokensToServers([ server ]) const user = { username: 'user1', password: 'password' } - await createUser({ url: server.url, accessToken: server.accessToken, username: user.username, password: user.password }) + await server.usersCommand.create({ username: user.username, password: user.password }) userAccessToken = await server.loginCommand.getAccessToken(user) }) diff --git a/server/tests/api/check-params/config.ts b/server/tests/api/check-params/config.ts index e93523e4b..c204d9415 100644 --- a/server/tests/api/check-params/config.ts +++ b/server/tests/api/check-params/config.ts @@ -5,7 +5,6 @@ import { omit } from 'lodash' import { HttpStatusCode } from '@shared/core-utils' import { cleanupTests, - createUser, flushAndRunServer, makeDeleteRequest, makeGetRequest, @@ -206,7 +205,7 @@ describe('Test config API validators', function () { username: 'user1', password: 'password' } - await createUser({ url: server.url, accessToken: server.accessToken, username: user.username, password: user.password }) + await server.usersCommand.create({ username: user.username, password: user.password }) userAccessToken = await server.loginCommand.getAccessToken(user) }) diff --git a/server/tests/api/check-params/custom-pages.ts b/server/tests/api/check-params/custom-pages.ts index c1dd258aa..58b0b8600 100644 --- a/server/tests/api/check-params/custom-pages.ts +++ b/server/tests/api/check-params/custom-pages.ts @@ -4,7 +4,6 @@ import 'mocha' import { HttpStatusCode } from '../../../../shared/core-utils/miscs/http-error-codes' import { cleanupTests, - createUser, flushAndRunServer, ServerInfo, setAccessTokensToServers @@ -26,7 +25,7 @@ describe('Test custom pages validators', function () { await setAccessTokensToServers([ server ]) const user = { username: 'user1', password: 'password' } - await createUser({ url: server.url, accessToken: server.accessToken, username: user.username, password: user.password }) + await server.usersCommand.create({ username: user.username, password: user.password }) userAccessToken = await server.loginCommand.getAccessToken(user) }) diff --git a/server/tests/api/check-params/debug.ts b/server/tests/api/check-params/debug.ts index dc033a441..2a7485cf3 100644 --- a/server/tests/api/check-params/debug.ts +++ b/server/tests/api/check-params/debug.ts @@ -4,7 +4,6 @@ import 'mocha' import { cleanupTests, - createUser, flushAndRunServer, ServerInfo, setAccessTokensToServers @@ -30,7 +29,7 @@ describe('Test debug API validators', function () { username: 'user1', password: 'my super password' } - await createUser({ url: server.url, accessToken: server.accessToken, username: user.username, password: user.password }) + await server.usersCommand.create({ username: user.username, password: user.password }) userAccessToken = await server.loginCommand.getAccessToken(user) }) diff --git a/server/tests/api/check-params/follows.ts b/server/tests/api/check-params/follows.ts index 8cf5b130e..24e483448 100644 --- a/server/tests/api/check-params/follows.ts +++ b/server/tests/api/check-params/follows.ts @@ -4,7 +4,6 @@ import 'mocha' import { cleanupTests, - createUser, flushAndRunServer, makeDeleteRequest, makeGetRequest, makePostBodyRequest, @@ -40,7 +39,7 @@ describe('Test server follows API validators', function () { password: 'password' } - await createUser({ url: server.url, accessToken: server.accessToken, username: user.username, password: user.password }) + await server.usersCommand.create({ username: user.username, password: user.password }) userAccessToken = await server.loginCommand.getAccessToken(user) }) diff --git a/server/tests/api/check-params/jobs.ts b/server/tests/api/check-params/jobs.ts index cbe6a28b8..29439bebf 100644 --- a/server/tests/api/check-params/jobs.ts +++ b/server/tests/api/check-params/jobs.ts @@ -4,7 +4,6 @@ import 'mocha' import { cleanupTests, - createUser, flushAndRunServer, ServerInfo, setAccessTokensToServers @@ -35,7 +34,7 @@ describe('Test jobs API validators', function () { username: 'user1', password: 'my super password' } - await createUser({ url: server.url, accessToken: server.accessToken, username: user.username, password: user.password }) + await server.usersCommand.create({ username: user.username, password: user.password }) userAccessToken = await server.loginCommand.getAccessToken(user) }) diff --git a/server/tests/api/check-params/live.ts b/server/tests/api/check-params/live.ts index 045f3a1b1..78863fd50 100644 --- a/server/tests/api/check-params/live.ts +++ b/server/tests/api/check-params/live.ts @@ -2,14 +2,11 @@ import 'mocha' import { omit } from 'lodash' -import { VideoCreateResult, VideoPrivacy } from '@shared/models' -import { HttpStatusCode } from '../../../../shared/core-utils/miscs/http-error-codes' +import { HttpStatusCode } from '@shared/core-utils' import { buildAbsoluteFixturePath, cleanupTests, - createUser, flushAndRunServer, - getMyUserInformation, LiveCommand, makePostBodyRequest, makeUploadRequest, @@ -18,7 +15,8 @@ import { setAccessTokensToServers, stopFfmpeg, uploadVideoAndGetId -} from '../../../../shared/extra-utils' +} from '@shared/extra-utils' +import { VideoCreateResult, VideoPrivacy } from '@shared/models' describe('Test video lives API validator', function () { const path = '/api/v1/videos/live' @@ -51,12 +49,12 @@ describe('Test video lives API validator', function () { const username = 'user1' const password = 'my super password' - await createUser({ url: server.url, accessToken: server.accessToken, username: username, password: password }) + await server.usersCommand.create({ username: username, password: password }) userAccessToken = await server.loginCommand.getAccessToken({ username, password }) { - const res = await getMyUserInformation(server.url, server.accessToken) - channelId = res.body.videoChannels[0].id + const { videoChannels } = await server.usersCommand.getMyInfo() + channelId = videoChannels[0].id } { @@ -147,11 +145,11 @@ describe('Test video lives API validator', function () { username: 'fake', password: 'fake_password' } - await createUser({ url: server.url, accessToken: server.accessToken, username: user.username, password: user.password }) + await server.usersCommand.create({ username: user.username, password: user.password }) const accessTokenUser = await server.loginCommand.getAccessToken(user) - const res = await getMyUserInformation(server.url, accessTokenUser) - const customChannelId = res.body.videoChannels[0].id + const { videoChannels } = await server.usersCommand.getMyInfo({ token: accessTokenUser }) + const customChannelId = videoChannels[0].id const fields = { ...baseCorrectParams, channelId: customChannelId } diff --git a/server/tests/api/check-params/logs.ts b/server/tests/api/check-params/logs.ts index 83ecfec93..69eaad69f 100644 --- a/server/tests/api/check-params/logs.ts +++ b/server/tests/api/check-params/logs.ts @@ -4,7 +4,6 @@ import 'mocha' import { cleanupTests, - createUser, flushAndRunServer, ServerInfo, setAccessTokensToServers @@ -30,7 +29,7 @@ describe('Test logs API validators', function () { username: 'user1', password: 'my super password' } - await createUser({ url: server.url, accessToken: server.accessToken, username: user.username, password: user.password }) + await server.usersCommand.create({ username: user.username, password: user.password }) userAccessToken = await server.loginCommand.getAccessToken(user) }) diff --git a/server/tests/api/check-params/plugins.ts b/server/tests/api/check-params/plugins.ts index 130cf6869..08fb2397f 100644 --- a/server/tests/api/check-params/plugins.ts +++ b/server/tests/api/check-params/plugins.ts @@ -7,7 +7,6 @@ import { checkBadSortPagination, checkBadStartPagination, cleanupTests, - createUser, flushAndRunServer, makeGetRequest, makePostBodyRequest, @@ -43,7 +42,7 @@ describe('Test server plugins API validators', function () { password: 'password' } - await createUser({ url: server.url, accessToken: server.accessToken, username: user.username, password: user.password }) + await server.usersCommand.create({ username: user.username, password: user.password }) userAccessToken = await server.loginCommand.getAccessToken(user) { diff --git a/server/tests/api/check-params/redundancy.ts b/server/tests/api/check-params/redundancy.ts index 2e10e378a..d93022c32 100644 --- a/server/tests/api/check-params/redundancy.ts +++ b/server/tests/api/check-params/redundancy.ts @@ -8,7 +8,6 @@ import { checkBadSortPagination, checkBadStartPagination, cleanupTests, - createUser, doubleFollow, flushAndRunMultipleServers, getVideo, @@ -43,7 +42,7 @@ describe('Test server redundancy API validators', function () { password: 'password' } - await createUser({ url: servers[0].url, accessToken: servers[0].accessToken, username: user.username, password: user.password }) + await servers[0].usersCommand.create({ username: user.username, password: user.password }) userAccessToken = await servers[0].loginCommand.getAccessToken(user) videoIdLocal = (await uploadVideoAndGetId({ server: servers[0], videoName: 'video' })).id diff --git a/server/tests/api/check-params/upload-quota.ts b/server/tests/api/check-params/upload-quota.ts index 3dc6cf2b4..d94dec624 100644 --- a/server/tests/api/check-params/upload-quota.ts +++ b/server/tests/api/check-params/upload-quota.ts @@ -3,17 +3,14 @@ import 'mocha' import { expect } from 'chai' import { HttpStatusCode, randomInt } from '@shared/core-utils' -import { MyUser, VideoImportState, VideoPrivacy } from '@shared/models' +import { VideoImportState, VideoPrivacy } from '@shared/models' import { cleanupTests, flushAndRunServer, - getMyUserInformation, ImportsCommand, - registerUser, ServerInfo, setAccessTokensToServers, setDefaultVideoChannel, - updateUser, uploadVideo, waitJobs } from '../../../../shared/extra-utils' @@ -31,15 +28,10 @@ describe('Test upload quota', function () { await setAccessTokensToServers([ server ]) await setDefaultVideoChannel([ server ]) - const res = await getMyUserInformation(server.url, server.accessToken) - rootId = (res.body as MyUser).id + const user = await server.usersCommand.getMyInfo() + rootId = user.id - await updateUser({ - url: server.url, - userId: rootId, - accessToken: server.accessToken, - videoQuota: 42 - }) + await server.usersCommand.update({ userId: rootId, videoQuota: 42 }) }) describe('When having a video quota', function () { @@ -48,7 +40,7 @@ describe('Test upload quota', function () { this.timeout(30000) const user = { username: 'registered' + randomInt(1, 1500), password: 'password' } - await registerUser(server.url, user.username, user.password) + await server.usersCommand.register(user) const userAccessToken = await server.loginCommand.getAccessToken(user) const videoAttributes = { fixture: 'video_short2.webm' } @@ -63,7 +55,7 @@ describe('Test upload quota', function () { this.timeout(30000) const user = { username: 'registered' + randomInt(1, 1500), password: 'password' } - await registerUser(server.url, user.username, user.password) + await server.usersCommand.register(user) const userAccessToken = await server.loginCommand.getAccessToken(user) const videoAttributes = { fixture: 'video_short2.webm' } @@ -103,12 +95,7 @@ describe('Test upload quota', function () { describe('When having a daily video quota', function () { it('Should fail with a user having too many videos daily', async function () { - await updateUser({ - url: server.url, - userId: rootId, - accessToken: server.accessToken, - videoQuotaDaily: 42 - }) + await server.usersCommand.update({ userId: rootId, videoQuotaDaily: 42 }) await uploadVideo(server.url, server.accessToken, {}, HttpStatusCode.PAYLOAD_TOO_LARGE_413, 'legacy') await uploadVideo(server.url, server.accessToken, {}, HttpStatusCode.PAYLOAD_TOO_LARGE_413, 'resumable') @@ -117,10 +104,8 @@ describe('Test upload quota', function () { describe('When having an absolute and daily video quota', function () { it('Should fail if exceeding total quota', async function () { - await updateUser({ - url: server.url, + await server.usersCommand.update({ userId: rootId, - accessToken: server.accessToken, videoQuota: 42, videoQuotaDaily: 1024 * 1024 * 1024 }) @@ -130,10 +115,8 @@ describe('Test upload quota', function () { }) it('Should fail if exceeding daily quota', async function () { - await updateUser({ - url: server.url, + await server.usersCommand.update({ userId: rootId, - accessToken: server.accessToken, videoQuota: 1024 * 1024 * 1024, videoQuotaDaily: 42 }) diff --git a/server/tests/api/check-params/user-subscriptions.ts b/server/tests/api/check-params/user-subscriptions.ts index 64e2703b9..8ce201d61 100644 --- a/server/tests/api/check-params/user-subscriptions.ts +++ b/server/tests/api/check-params/user-subscriptions.ts @@ -4,7 +4,6 @@ import 'mocha' import { cleanupTests, - createUser, flushAndRunServer, makeDeleteRequest, makeGetRequest, @@ -39,7 +38,7 @@ describe('Test user subscriptions API validators', function () { username: 'user1', password: 'my super password' } - await createUser({ url: server.url, accessToken: server.accessToken, username: user.username, password: user.password }) + await server.usersCommand.create({ username: user.username, password: user.password }) userAccessToken = await server.loginCommand.getAccessToken(user) }) diff --git a/server/tests/api/check-params/users.ts b/server/tests/api/check-params/users.ts index 54baeebe1..801131918 100644 --- a/server/tests/api/check-params/users.ts +++ b/server/tests/api/check-params/users.ts @@ -2,32 +2,22 @@ import 'mocha' import { omit } from 'lodash' -import { User, UserRole, VideoCreateResult } from '../../../../shared' +import { UserRole, VideoCreateResult } from '../../../../shared' import { HttpStatusCode } from '../../../../shared/core-utils/miscs/http-error-codes' import { - blockUser, buildAbsoluteFixturePath, cleanupTests, - createUser, - deleteMe, flushAndRunServer, - getMyUserInformation, - getMyUserVideoRating, - getUserScopedTokens, - getUsersList, killallServers, makeGetRequest, makePostBodyRequest, makePutBodyRequest, makeUploadRequest, - registerUser, - removeUser, - renewUserScopedTokens, reRunServer, ServerInfo, setAccessTokensToServers, - unblockUser, - uploadVideo + uploadVideo, + UsersCommand } from '../../../../shared/extra-utils' import { MockSmtpServer } from '../../../../shared/extra-utils/mock-servers/mock-email' import { @@ -45,8 +35,8 @@ describe('Test users API validators', function () { let video: VideoCreateResult let server: ServerInfo let serverWithRegistrationDisabled: ServerInfo - let userAccessToken = '' - let moderatorAccessToken = '' + let userToken = '' + let moderatorToken = '' let emailPort: number let overrideConfig: Object @@ -73,52 +63,20 @@ describe('Test users API validators', function () { } { - const user = { - username: 'user1', - password: 'my super password' - } - - const videoQuota = 42000000 - await createUser({ - url: server.url, - accessToken: server.accessToken, - username: user.username, - password: user.password, - videoQuota: videoQuota - }) - userAccessToken = await server.loginCommand.getAccessToken(user) + const user = { username: 'user1' } + await server.usersCommand.create({ ...user }) + userToken = await server.loginCommand.getAccessToken(user) } { - const moderator = { - username: 'moderator1', - password: 'super password' - } - - await createUser({ - url: server.url, - accessToken: server.accessToken, - username: moderator.username, - password: moderator.password, - role: UserRole.MODERATOR - }) - - moderatorAccessToken = await server.loginCommand.getAccessToken(moderator) + const moderator = { username: 'moderator1' } + await server.usersCommand.create({ ...moderator, role: UserRole.MODERATOR }) + moderatorToken = await server.loginCommand.getAccessToken(moderator) } { - const moderator = { - username: 'moderator2', - password: 'super password' - } - - await createUser({ - url: server.url, - accessToken: server.accessToken, - username: moderator.username, - password: moderator.password, - role: UserRole.MODERATOR - }) + const moderator = { username: 'moderator2' } + await server.usersCommand.create({ ...moderator, role: UserRole.MODERATOR }) } { @@ -127,12 +85,10 @@ describe('Test users API validators', function () { } { - const res = await getUsersList(server.url, server.accessToken) - const users: User[] = res.body.data - - userId = users.find(u => u.username === 'user1').id - rootId = users.find(u => u.username === 'root').id - moderatorId = users.find(u => u.username === 'moderator2').id + const { data } = await server.usersCommand.list() + userId = data.find(u => u.username === 'user1').id + rootId = data.find(u => u.username === 'root').id + moderatorId = data.find(u => u.username === 'moderator2').id } }) @@ -161,7 +117,7 @@ describe('Test users API validators', function () { await makeGetRequest({ url: server.url, path, - token: userAccessToken, + token: userToken, statusCodeExpected: HttpStatusCode.FORBIDDEN_403 }) }) @@ -359,7 +315,7 @@ describe('Test users API validators', function () { await makePostBodyRequest({ url: server.url, path, - token: moderatorAccessToken, + token: moderatorToken, fields, statusCodeExpected: HttpStatusCode.FORBIDDEN_403 }) @@ -372,7 +328,7 @@ describe('Test users API validators', function () { await makePostBodyRequest({ url: server.url, path, - token: moderatorAccessToken, + token: moderatorToken, fields, statusCodeExpected: HttpStatusCode.OK_200 }) @@ -389,11 +345,8 @@ describe('Test users API validators', function () { }) it('Should fail with a non admin user', async function () { - const user = { - username: 'user1', - password: 'my super password' - } - userAccessToken = await server.loginCommand.getAccessToken(user) + const user = { username: 'user1' } + userToken = await server.loginCommand.getAccessToken(user) const fields = { username: 'user3', @@ -401,11 +354,12 @@ describe('Test users API validators', function () { password: 'my super password', videoQuota: 42000000 } - await makePostBodyRequest({ url: server.url, path, token: userAccessToken, fields, statusCodeExpected: HttpStatusCode.FORBIDDEN_403 }) + await makePostBodyRequest({ url: server.url, path, token: userToken, fields, statusCodeExpected: HttpStatusCode.FORBIDDEN_403 }) }) }) describe('When updating my account', function () { + it('Should fail with an invalid email attribute', async function () { const fields = { email: 'blabla' @@ -416,29 +370,29 @@ describe('Test users API validators', function () { it('Should fail with a too small password', async function () { const fields = { - currentPassword: 'my super password', + currentPassword: 'password', password: 'bla' } - await makePutBodyRequest({ url: server.url, path: path + 'me', token: userAccessToken, fields }) + await makePutBodyRequest({ url: server.url, path: path + 'me', token: userToken, fields }) }) it('Should fail with a too long password', async function () { const fields = { - currentPassword: 'my super password', + currentPassword: 'password', password: 'super'.repeat(61) } - await makePutBodyRequest({ url: server.url, path: path + 'me', token: userAccessToken, fields }) + await makePutBodyRequest({ url: server.url, path: path + 'me', token: userToken, fields }) }) it('Should fail without the current password', async function () { const fields = { - currentPassword: 'my super password', + currentPassword: 'password', password: 'super'.repeat(61) } - await makePutBodyRequest({ url: server.url, path: path + 'me', token: userAccessToken, fields }) + await makePutBodyRequest({ url: server.url, path: path + 'me', token: userToken, fields }) }) it('Should fail with an invalid current password', async function () { @@ -450,7 +404,7 @@ describe('Test users API validators', function () { await makePutBodyRequest({ url: server.url, path: path + 'me', - token: userAccessToken, + token: userToken, fields, statusCodeExpected: HttpStatusCode.UNAUTHORIZED_401 }) @@ -461,7 +415,7 @@ describe('Test users API validators', function () { nsfwPolicy: 'hello' } - await makePutBodyRequest({ url: server.url, path: path + 'me', token: userAccessToken, fields }) + await makePutBodyRequest({ url: server.url, path: path + 'me', token: userToken, fields }) }) it('Should fail with an invalid autoPlayVideo attribute', async function () { @@ -469,7 +423,7 @@ describe('Test users API validators', function () { autoPlayVideo: -1 } - await makePutBodyRequest({ url: server.url, path: path + 'me', token: userAccessToken, fields }) + await makePutBodyRequest({ url: server.url, path: path + 'me', token: userToken, fields }) }) it('Should fail with an invalid autoPlayNextVideo attribute', async function () { @@ -477,7 +431,7 @@ describe('Test users API validators', function () { autoPlayNextVideo: -1 } - await makePutBodyRequest({ url: server.url, path: path + 'me', token: userAccessToken, fields }) + await makePutBodyRequest({ url: server.url, path: path + 'me', token: userToken, fields }) }) it('Should fail with an invalid videosHistoryEnabled attribute', async function () { @@ -485,12 +439,12 @@ describe('Test users API validators', function () { videosHistoryEnabled: -1 } - await makePutBodyRequest({ url: server.url, path: path + 'me', token: userAccessToken, fields }) + await makePutBodyRequest({ url: server.url, path: path + 'me', token: userToken, fields }) }) it('Should fail with an non authenticated user', async function () { const fields = { - currentPassword: 'my super password', + currentPassword: 'password', password: 'my super password' } @@ -508,7 +462,7 @@ describe('Test users API validators', function () { description: 'super'.repeat(201) } - await makePutBodyRequest({ url: server.url, path: path + 'me', token: userAccessToken, fields }) + await makePutBodyRequest({ url: server.url, path: path + 'me', token: userToken, fields }) }) it('Should fail with an invalid videoLanguages attribute', async function () { @@ -517,7 +471,7 @@ describe('Test users API validators', function () { videoLanguages: 'toto' } - await makePutBodyRequest({ url: server.url, path: path + 'me', token: userAccessToken, fields }) + await makePutBodyRequest({ url: server.url, path: path + 'me', token: userToken, fields }) } { @@ -530,18 +484,18 @@ describe('Test users API validators', function () { videoLanguages: languages } - await makePutBodyRequest({ url: server.url, path: path + 'me', token: userAccessToken, fields }) + await makePutBodyRequest({ url: server.url, path: path + 'me', token: userToken, fields }) } }) it('Should fail with an invalid theme', async function () { const fields = { theme: 'invalid' } - await makePutBodyRequest({ url: server.url, path: path + 'me', token: userAccessToken, fields }) + await makePutBodyRequest({ url: server.url, path: path + 'me', token: userToken, fields }) }) it('Should fail with an unknown theme', async function () { const fields = { theme: 'peertube-theme-unknown' } - await makePutBodyRequest({ url: server.url, path: path + 'me', token: userAccessToken, fields }) + await makePutBodyRequest({ url: server.url, path: path + 'me', token: userToken, fields }) }) it('Should fail with an invalid noInstanceConfigWarningModal attribute', async function () { @@ -549,7 +503,7 @@ describe('Test users API validators', function () { noInstanceConfigWarningModal: -1 } - await makePutBodyRequest({ url: server.url, path: path + 'me', token: userAccessToken, fields }) + await makePutBodyRequest({ url: server.url, path: path + 'me', token: userToken, fields }) }) it('Should fail with an invalid noWelcomeModal attribute', async function () { @@ -557,12 +511,12 @@ describe('Test users API validators', function () { noWelcomeModal: -1 } - await makePutBodyRequest({ url: server.url, path: path + 'me', token: userAccessToken, fields }) + await makePutBodyRequest({ url: server.url, path: path + 'me', token: userToken, fields }) }) it('Should succeed to change password with the correct params', async function () { const fields = { - currentPassword: 'my super password', + currentPassword: 'password', password: 'my super password', nsfwPolicy: 'blur', autoPlayVideo: false, @@ -575,7 +529,7 @@ describe('Test users API validators', function () { await makePutBodyRequest({ url: server.url, path: path + 'me', - token: userAccessToken, + token: userToken, fields, statusCodeExpected: HttpStatusCode.NO_CONTENT_204 }) @@ -590,7 +544,7 @@ describe('Test users API validators', function () { await makePutBodyRequest({ url: server.url, path: path + 'me', - token: userAccessToken, + token: userToken, fields, statusCodeExpected: HttpStatusCode.NO_CONTENT_204 }) @@ -647,28 +601,28 @@ describe('Test users API validators', function () { describe('When managing my scoped tokens', function () { it('Should fail to get my scoped tokens with an non authenticated user', async function () { - await getUserScopedTokens(server.url, null, HttpStatusCode.UNAUTHORIZED_401) + await server.usersCommand.getMyScopedTokens({ token: null, expectedStatus: HttpStatusCode.UNAUTHORIZED_401 }) }) it('Should fail to get my scoped tokens with a bad token', async function () { - await getUserScopedTokens(server.url, 'bad', HttpStatusCode.UNAUTHORIZED_401) + await server.usersCommand.getMyScopedTokens({ token: 'bad', expectedStatus: HttpStatusCode.UNAUTHORIZED_401 }) }) it('Should succeed to get my scoped tokens', async function () { - await getUserScopedTokens(server.url, server.accessToken) + await server.usersCommand.getMyScopedTokens() }) it('Should fail to renew my scoped tokens with an non authenticated user', async function () { - await renewUserScopedTokens(server.url, null, HttpStatusCode.UNAUTHORIZED_401) + await server.usersCommand.renewMyScopedTokens({ token: null, expectedStatus: HttpStatusCode.UNAUTHORIZED_401 }) }) it('Should fail to renew my scoped tokens with a bad token', async function () { - await renewUserScopedTokens(server.url, 'bad', HttpStatusCode.UNAUTHORIZED_401) + await server.usersCommand.renewMyScopedTokens({ token: 'bad', expectedStatus: HttpStatusCode.UNAUTHORIZED_401 }) }) it('Should succeed to renew my scoped tokens', async function () { - await renewUserScopedTokens(server.url, server.accessToken) + await server.usersCommand.renewMyScopedTokens() }) }) @@ -684,7 +638,7 @@ describe('Test users API validators', function () { }) it('Should fail with a non admin user', async function () { - await makeGetRequest({ url: server.url, path, token: userAccessToken, statusCodeExpected: HttpStatusCode.FORBIDDEN_403 }) + await makeGetRequest({ url: server.url, path, token: userToken, statusCodeExpected: HttpStatusCode.FORBIDDEN_403 }) }) it('Should succeed with the correct params', async function () { @@ -728,7 +682,7 @@ describe('Test users API validators', function () { it('Should fail with a too small password', async function () { const fields = { - currentPassword: 'my super password', + currentPassword: 'password', password: 'bla' } @@ -737,7 +691,7 @@ describe('Test users API validators', function () { it('Should fail with a too long password', async function () { const fields = { - currentPassword: 'my super password', + currentPassword: 'password', password: 'super'.repeat(61) } @@ -780,7 +734,7 @@ describe('Test users API validators', function () { await makePutBodyRequest({ url: server.url, path: path + moderatorId, - token: moderatorAccessToken, + token: moderatorToken, fields, statusCodeExpected: HttpStatusCode.FORBIDDEN_403 }) @@ -794,7 +748,7 @@ describe('Test users API validators', function () { await makePutBodyRequest({ url: server.url, path: path + userId, - token: moderatorAccessToken, + token: moderatorToken, fields, statusCodeExpected: HttpStatusCode.NO_CONTENT_204 }) @@ -820,31 +774,37 @@ describe('Test users API validators', function () { describe('When getting my information', function () { it('Should fail with a non authenticated user', async function () { - await getMyUserInformation(server.url, 'fake_token', HttpStatusCode.UNAUTHORIZED_401) + await server.usersCommand.getMyInfo({ token: 'fake_token', expectedStatus: HttpStatusCode.UNAUTHORIZED_401 }) }) it('Should success with the correct parameters', async function () { - await getMyUserInformation(server.url, userAccessToken) + await server.usersCommand.getMyInfo({ token: userToken }) }) }) describe('When getting my video rating', function () { + let command: UsersCommand + + before(function () { + command = server.usersCommand + }) + it('Should fail with a non authenticated user', async function () { - await getMyUserVideoRating(server.url, 'fake_token', video.id, HttpStatusCode.UNAUTHORIZED_401) + await command.getMyRating({ token: 'fake_token', videoId: video.id, expectedStatus: HttpStatusCode.UNAUTHORIZED_401 }) }) it('Should fail with an incorrect video uuid', async function () { - await getMyUserVideoRating(server.url, server.accessToken, 'blabla', HttpStatusCode.BAD_REQUEST_400) + await command.getMyRating({ videoId: 'blabla', expectedStatus: HttpStatusCode.BAD_REQUEST_400 }) }) it('Should fail with an unknown video', async function () { - await getMyUserVideoRating(server.url, server.accessToken, '4da6fde3-88f7-4d16-b119-108df5630b06', HttpStatusCode.NOT_FOUND_404) + await command.getMyRating({ videoId: '4da6fde3-88f7-4d16-b119-108df5630b06', expectedStatus: HttpStatusCode.NOT_FOUND_404 }) }) it('Should succeed with the correct parameters', async function () { - await getMyUserVideoRating(server.url, server.accessToken, video.id) - await getMyUserVideoRating(server.url, server.accessToken, video.uuid) - await getMyUserVideoRating(server.url, server.accessToken, video.shortUUID) + await command.getMyRating({ videoId: video.id }) + await command.getMyRating({ videoId: video.uuid }) + await command.getMyRating({ videoId: video.shortUUID }) }) }) @@ -852,15 +812,15 @@ describe('Test users API validators', function () { const path = '/api/v1/accounts/user1/ratings' it('Should fail with a bad start pagination', async function () { - await checkBadStartPagination(server.url, path, userAccessToken) + await checkBadStartPagination(server.url, path, userToken) }) it('Should fail with a bad count pagination', async function () { - await checkBadCountPagination(server.url, path, userAccessToken) + await checkBadCountPagination(server.url, path, userToken) }) it('Should fail with an incorrect sort', async function () { - await checkBadSortPagination(server.url, path, userAccessToken) + await checkBadSortPagination(server.url, path, userToken) }) it('Should fail with a unauthenticated user', async function () { @@ -875,57 +835,70 @@ describe('Test users API validators', function () { await makeGetRequest({ url: server.url, path, - token: userAccessToken, + token: userToken, query: { rating: 'toto ' }, statusCodeExpected: HttpStatusCode.BAD_REQUEST_400 }) }) it('Should succeed with the correct params', async function () { - await makeGetRequest({ url: server.url, path, token: userAccessToken, statusCodeExpected: HttpStatusCode.OK_200 }) + await makeGetRequest({ url: server.url, path, token: userToken, statusCodeExpected: HttpStatusCode.OK_200 }) }) }) describe('When blocking/unblocking/removing user', function () { + it('Should fail with an incorrect id', async function () { - await removeUser(server.url, 'blabla', server.accessToken, HttpStatusCode.BAD_REQUEST_400) - await blockUser(server.url, 'blabla', server.accessToken, HttpStatusCode.BAD_REQUEST_400) - await unblockUser(server.url, 'blabla', server.accessToken, HttpStatusCode.BAD_REQUEST_400) + const options = { userId: 'blabla' as any, expectedStatus: HttpStatusCode.BAD_REQUEST_400 } + + await server.usersCommand.remove(options) + await server.usersCommand.banUser({ userId: 'blabla' as any, expectedStatus: HttpStatusCode.BAD_REQUEST_400 }) + await server.usersCommand.unbanUser({ userId: 'blabla' as any, expectedStatus: HttpStatusCode.BAD_REQUEST_400 }) }) it('Should fail with the root user', async function () { - await removeUser(server.url, rootId, server.accessToken, HttpStatusCode.BAD_REQUEST_400) - await blockUser(server.url, rootId, server.accessToken, HttpStatusCode.BAD_REQUEST_400) - await unblockUser(server.url, rootId, server.accessToken, HttpStatusCode.BAD_REQUEST_400) + const options = { userId: rootId, expectedStatus: HttpStatusCode.BAD_REQUEST_400 } + + await server.usersCommand.remove(options) + await server.usersCommand.banUser(options) + await server.usersCommand.unbanUser(options) }) it('Should return 404 with a non existing id', async function () { - await removeUser(server.url, 4545454, server.accessToken, HttpStatusCode.NOT_FOUND_404) - await blockUser(server.url, 4545454, server.accessToken, HttpStatusCode.NOT_FOUND_404) - await unblockUser(server.url, 4545454, server.accessToken, HttpStatusCode.NOT_FOUND_404) + const options = { userId: 4545454, expectedStatus: HttpStatusCode.NOT_FOUND_404 } + + await server.usersCommand.remove(options) + await server.usersCommand.banUser(options) + await server.usersCommand.unbanUser(options) }) it('Should fail with a non admin user', async function () { - await removeUser(server.url, userId, userAccessToken, HttpStatusCode.FORBIDDEN_403) - await blockUser(server.url, userId, userAccessToken, HttpStatusCode.FORBIDDEN_403) - await unblockUser(server.url, userId, userAccessToken, HttpStatusCode.FORBIDDEN_403) + const options = { userId, token: userToken, expectedStatus: HttpStatusCode.FORBIDDEN_403 } + + await server.usersCommand.remove(options) + await server.usersCommand.banUser(options) + await server.usersCommand.unbanUser(options) }) it('Should fail on a moderator with a moderator', async function () { - await removeUser(server.url, moderatorId, moderatorAccessToken, HttpStatusCode.FORBIDDEN_403) - await blockUser(server.url, moderatorId, moderatorAccessToken, HttpStatusCode.FORBIDDEN_403) - await unblockUser(server.url, moderatorId, moderatorAccessToken, HttpStatusCode.FORBIDDEN_403) + const options = { userId: moderatorId, token: moderatorToken, expectedStatus: HttpStatusCode.FORBIDDEN_403 } + + await server.usersCommand.remove(options) + await server.usersCommand.banUser(options) + await server.usersCommand.unbanUser(options) }) it('Should succeed on a user with a moderator', async function () { - await blockUser(server.url, userId, moderatorAccessToken) - await unblockUser(server.url, userId, moderatorAccessToken) + const options = { userId, token: moderatorToken } + + await server.usersCommand.banUser(options) + await server.usersCommand.unbanUser(options) }) }) describe('When deleting our account', function () { it('Should fail with with the root account', async function () { - await deleteMe(server.url, server.accessToken, HttpStatusCode.BAD_REQUEST_400) + await server.usersCommand.deleteMe({ expectedStatus: HttpStatusCode.BAD_REQUEST_400 }) }) }) @@ -1087,7 +1060,7 @@ describe('Test users API validators', function () { describe('When registering multiple users on a server with users limit', function () { it('Should fail when after 3 registrations', async function () { - await registerUser(server.url, 'user42', 'super password', HttpStatusCode.FORBIDDEN_403) + await server.usersCommand.register({ username: 'user42', expectedStatus: HttpStatusCode.FORBIDDEN_403 }) }) }) diff --git a/server/tests/api/check-params/video-blacklist.ts b/server/tests/api/check-params/video-blacklist.ts index c33bc196d..5097f8069 100644 --- a/server/tests/api/check-params/video-blacklist.ts +++ b/server/tests/api/check-params/video-blacklist.ts @@ -9,7 +9,6 @@ import { checkBadSortPagination, checkBadStartPagination, cleanupTests, - createUser, doubleFollow, flushAndRunMultipleServers, getVideo, @@ -44,14 +43,14 @@ describe('Test video blacklist API validators', function () { { const username = 'user1' const password = 'my super password' - await createUser({ url: servers[0].url, accessToken: servers[0].accessToken, username: username, password: password }) + await servers[0].usersCommand.create({ username: username, password: password }) userAccessToken1 = await servers[0].loginCommand.getAccessToken({ username, password }) } { const username = 'user2' const password = 'my super password' - await createUser({ url: servers[0].url, accessToken: servers[0].accessToken, username: username, password: password }) + await servers[0].usersCommand.create({ username: username, password: password }) userAccessToken2 = await servers[0].loginCommand.getAccessToken({ username, password }) } diff --git a/server/tests/api/check-params/video-captions.ts b/server/tests/api/check-params/video-captions.ts index f2fd61b91..631ef4dac 100644 --- a/server/tests/api/check-params/video-captions.ts +++ b/server/tests/api/check-params/video-captions.ts @@ -5,7 +5,6 @@ import { HttpStatusCode } from '@shared/core-utils' import { buildAbsoluteFixturePath, cleanupTests, - createUser, flushAndRunServer, makeDeleteRequest, makeGetRequest, @@ -42,7 +41,7 @@ describe('Test video captions API validator', function () { username: 'user1', password: 'my super password' } - await createUser({ url: server.url, accessToken: server.accessToken, username: user.username, password: user.password }) + await server.usersCommand.create({ username: user.username, password: user.password }) userAccessToken = await server.loginCommand.getAccessToken(user) } }) diff --git a/server/tests/api/check-params/video-channels.ts b/server/tests/api/check-params/video-channels.ts index 5361f6917..2b4c17ea1 100644 --- a/server/tests/api/check-params/video-channels.ts +++ b/server/tests/api/check-params/video-channels.ts @@ -11,7 +11,6 @@ import { checkBadSortPagination, checkBadStartPagination, cleanupTests, - createUser, flushAndRunServer, makeGetRequest, makePostBodyRequest, @@ -45,7 +44,7 @@ describe('Test video channels API validator', function () { } { - await createUser({ url: server.url, accessToken: server.accessToken, username: user.username, password: user.password }) + await server.usersCommand.create({ username: user.username, password: user.password }) accessTokenUser = await server.loginCommand.getAccessToken(user) } diff --git a/server/tests/api/check-params/video-comments.ts b/server/tests/api/check-params/video-comments.ts index c21aebaae..b7656a176 100644 --- a/server/tests/api/check-params/video-comments.ts +++ b/server/tests/api/check-params/video-comments.ts @@ -8,7 +8,6 @@ import { checkBadSortPagination, checkBadStartPagination, cleanupTests, - createUser, flushAndRunServer, makeDeleteRequest, makeGetRequest, @@ -53,13 +52,13 @@ describe('Test video comments API validator', function () { { const user = { username: 'user1', password: 'my super password' } - await createUser({ url: server.url, accessToken: server.accessToken, username: user.username, password: user.password }) + await server.usersCommand.create({ username: user.username, password: user.password }) userAccessToken = await server.loginCommand.getAccessToken(user) } { const user = { username: 'user2', password: 'my super password' } - await createUser({ url: server.url, accessToken: server.accessToken, username: user.username, password: user.password }) + await server.usersCommand.create({ username: user.username, password: user.password }) userAccessToken2 = await server.loginCommand.getAccessToken(user) } }) diff --git a/server/tests/api/check-params/video-imports.ts b/server/tests/api/check-params/video-imports.ts index 51260affa..d09e473de 100644 --- a/server/tests/api/check-params/video-imports.ts +++ b/server/tests/api/check-params/video-imports.ts @@ -9,9 +9,7 @@ import { checkBadSortPagination, checkBadStartPagination, cleanupTests, - createUser, flushAndRunServer, - getMyUserInformation, ImportsCommand, makeGetRequest, makePostBodyRequest, @@ -38,12 +36,12 @@ describe('Test video imports API validator', function () { const username = 'user1' const password = 'my super password' - await createUser({ url: server.url, accessToken: server.accessToken, username: username, password: password }) + await server.usersCommand.create({ username: username, password: password }) userAccessToken = await server.loginCommand.getAccessToken({ username, password }) { - const res = await getMyUserInformation(server.url, server.accessToken) - channelId = res.body.videoChannels[0].id + const { videoChannels } = await server.usersCommand.getMyInfo() + channelId = videoChannels[0].id } }) @@ -164,11 +162,11 @@ describe('Test video imports API validator', function () { username: 'fake', password: 'fake_password' } - await createUser({ url: server.url, accessToken: server.accessToken, username: user.username, password: user.password }) + await server.usersCommand.create({ username: user.username, password: user.password }) const accessTokenUser = await server.loginCommand.getAccessToken(user) - const res = await getMyUserInformation(server.url, accessTokenUser) - const customChannelId = res.body.videoChannels[0].id + const { videoChannels } = await server.usersCommand.getMyInfo({ token: accessTokenUser }) + const customChannelId = videoChannels[0].id const fields = { ...baseCorrectParams, channelId: customChannelId } diff --git a/server/tests/api/check-params/video-playlists.ts b/server/tests/api/check-params/video-playlists.ts index 3799e73b6..46c09bb11 100644 --- a/server/tests/api/check-params/video-playlists.ts +++ b/server/tests/api/check-params/video-playlists.ts @@ -17,7 +17,6 @@ import { checkBadStartPagination, cleanupTests, flushAndRunServer, - generateUserAccessToken, makeGetRequest, PlaylistsCommand, ServerInfo, @@ -49,7 +48,7 @@ describe('Test video playlists API validator', function () { await setAccessTokensToServers([ server ]) await setDefaultVideoChannel([ server ]) - userAccessToken = await generateUserAccessToken(server, 'user1') + userAccessToken = await server.usersCommand.generateUserAndToken('user1') videoId = (await uploadVideoAndGetId({ server, videoName: 'video 1' })).id command = server.playlistsCommand diff --git a/server/tests/api/check-params/videos-filter.ts b/server/tests/api/check-params/videos-filter.ts index 095b94656..d7bf081d4 100644 --- a/server/tests/api/check-params/videos-filter.ts +++ b/server/tests/api/check-params/videos-filter.ts @@ -3,7 +3,6 @@ import 'mocha' import { cleanupTests, - createUser, flushAndRunServer, makeGetRequest, ServerInfo, @@ -50,21 +49,12 @@ describe('Test video filters validators', function () { await setDefaultVideoChannel([ server ]) const user = { username: 'user1', password: 'my super password' } - await createUser({ url: server.url, accessToken: server.accessToken, username: user.username, password: user.password }) + await server.usersCommand.create({ username: user.username, password: user.password }) userAccessToken = await server.loginCommand.getAccessToken(user) const moderator = { username: 'moderator', password: 'my super password' } - await createUser( - { - url: server.url, - accessToken: server.accessToken, - username: moderator.username, - password: moderator.password, - videoQuota: undefined, - videoQuotaDaily: undefined, - role: UserRole.MODERATOR - } - ) + await server.usersCommand.create({ username: moderator.username, password: moderator.password, role: UserRole.MODERATOR }) + moderatorAccessToken = await server.loginCommand.getAccessToken(moderator) }) diff --git a/server/tests/api/check-params/videos.ts b/server/tests/api/check-params/videos.ts index 8e11232bd..855b09f39 100644 --- a/server/tests/api/check-params/videos.ts +++ b/server/tests/api/check-params/videos.ts @@ -10,9 +10,7 @@ import { HttpStatusCode } from '../../../../shared/core-utils/miscs/http-error-c import { checkUploadVideoParam, cleanupTests, - createUser, flushAndRunServer, - getMyUserInformation, getVideo, getVideosList, makeDeleteRequest, @@ -53,14 +51,14 @@ describe('Test videos API validator', function () { const username = 'user1' const password = 'my super password' - await createUser({ url: server.url, accessToken: server.accessToken, username: username, password: password }) + await server.usersCommand.create({ username: username, password: password }) userAccessToken = await server.loginCommand.getAccessToken({ username, password }) { - const res = await getMyUserInformation(server.url, server.accessToken) - channelId = res.body.videoChannels[0].id - channelName = res.body.videoChannels[0].name - accountName = res.body.account.name + '@' + res.body.account.host + const body = await server.usersCommand.getMyInfo() + channelId = body.videoChannels[0].id + channelName = body.videoChannels[0].name + accountName = body.account.name + '@' + body.account.host } }) @@ -283,11 +281,11 @@ describe('Test videos API validator', function () { username: 'fake' + randomInt(0, 1500), password: 'fake_password' } - await createUser({ url: server.url, accessToken: server.accessToken, username: user.username, password: user.password }) + await server.usersCommand.create({ username: user.username, password: user.password }) const accessTokenUser = await server.loginCommand.getAccessToken(user) - const res = await getMyUserInformation(server.url, accessTokenUser) - const customChannelId = res.body.videoChannels[0].id + const { videoChannels } = await server.usersCommand.getMyInfo({ token: accessTokenUser }) + const customChannelId = videoChannels[0].id const fields = { ...baseCorrectParams, channelId: customChannelId } const attaches = baseCorrectAttaches -- cgit v1.2.3 From d23dd9fbfc4d26026352c10f81d2795ceaf2908a Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Thu, 15 Jul 2021 10:02:54 +0200 Subject: Introduce videos command --- server/tests/api/check-params/abuses.ts | 13 +-- server/tests/api/check-params/live.ts | 5 +- server/tests/api/check-params/redundancy.ts | 9 +- server/tests/api/check-params/services.ts | 14 ++- server/tests/api/check-params/upload-quota.ts | 37 ++++---- server/tests/api/check-params/users.ts | 21 ++--- server/tests/api/check-params/video-blacklist.ts | 34 ++++--- server/tests/api/check-params/video-captions.ts | 8 +- server/tests/api/check-params/video-comments.ts | 13 ++- server/tests/api/check-params/video-playlists.ts | 29 +++--- server/tests/api/check-params/videos-history.ts | 13 ++- server/tests/api/check-params/videos.ts | 109 +++++++++++------------ 12 files changed, 133 insertions(+), 172 deletions(-) (limited to 'server/tests/api/check-params') diff --git a/server/tests/api/check-params/abuses.ts b/server/tests/api/check-params/abuses.ts index 4cd10a6fd..199cc5599 100644 --- a/server/tests/api/check-params/abuses.ts +++ b/server/tests/api/check-params/abuses.ts @@ -10,12 +10,10 @@ import { cleanupTests, doubleFollow, flushAndRunServer, - getVideoIdFromUUID, makeGetRequest, makePostBodyRequest, ServerInfo, setAccessTokensToServers, - uploadVideo, waitJobs } from '@shared/extra-utils' import { AbuseCreate, AbuseState } from '@shared/models' @@ -41,15 +39,10 @@ describe('Test abuses API validators', function () { await setAccessTokensToServers([ server ]) - const username = 'user1' - const password = 'my super password' - await server.usersCommand.create({ username: username, password: password }) - userToken = await server.loginCommand.getAccessToken({ username, password }) - + userToken = await server.usersCommand.generateUserAndToken('user_1') userToken2 = await server.usersCommand.generateUserAndToken('user_2') - const res = await uploadVideo(server.url, server.accessToken, {}) - server.video = res.body.video + server.video = await server.videosCommand.upload() command = server.abusesCommand }) @@ -421,7 +414,7 @@ describe('Test abuses API validators', function () { await doubleFollow(anotherServer, server) - const server2VideoId = await getVideoIdFromUUID(anotherServer.url, server.video.uuid) + const server2VideoId = await anotherServer.videosCommand.getId({ uuid: server.video.uuid }) await anotherServer.abusesCommand.report({ reason: 'remote server', videoId: server2VideoId }) await waitJobs([ server, anotherServer ]) diff --git a/server/tests/api/check-params/live.ts b/server/tests/api/check-params/live.ts index 78863fd50..4b54fc31c 100644 --- a/server/tests/api/check-params/live.ts +++ b/server/tests/api/check-params/live.ts @@ -13,8 +13,7 @@ import { sendRTMPStream, ServerInfo, setAccessTokensToServers, - stopFfmpeg, - uploadVideoAndGetId + stopFfmpeg } from '@shared/extra-utils' import { VideoCreateResult, VideoPrivacy } from '@shared/models' @@ -58,7 +57,7 @@ describe('Test video lives API validator', function () { } { - videoIdNotLive = (await uploadVideoAndGetId({ server, videoName: 'not live' })).id + videoIdNotLive = (await server.videosCommand.quickUpload({ name: 'not live' })).id } command = server.liveCommand diff --git a/server/tests/api/check-params/redundancy.ts b/server/tests/api/check-params/redundancy.ts index d93022c32..b1692b986 100644 --- a/server/tests/api/check-params/redundancy.ts +++ b/server/tests/api/check-params/redundancy.ts @@ -10,14 +10,12 @@ import { cleanupTests, doubleFollow, flushAndRunMultipleServers, - getVideo, makeDeleteRequest, makeGetRequest, makePostBodyRequest, makePutBodyRequest, ServerInfo, setAccessTokensToServers, - uploadVideoAndGetId, waitJobs } from '../../../../shared/extra-utils' @@ -45,14 +43,13 @@ describe('Test server redundancy API validators', function () { await servers[0].usersCommand.create({ username: user.username, password: user.password }) userAccessToken = await servers[0].loginCommand.getAccessToken(user) - videoIdLocal = (await uploadVideoAndGetId({ server: servers[0], videoName: 'video' })).id + videoIdLocal = (await servers[0].videosCommand.quickUpload({ name: 'video' })).id - const remoteUUID = (await uploadVideoAndGetId({ server: servers[1], videoName: 'video' })).uuid + const remoteUUID = (await servers[1].videosCommand.quickUpload({ name: 'video' })).uuid await waitJobs(servers) - const resVideo = await getVideo(servers[0].url, remoteUUID) - videoRemote = resVideo.body + videoRemote = await servers[0].videosCommand.get({ id: remoteUUID }) }) describe('When listing redundancies', function () { diff --git a/server/tests/api/check-params/services.ts b/server/tests/api/check-params/services.ts index 595fab70d..f86712b4e 100644 --- a/server/tests/api/check-params/services.ts +++ b/server/tests/api/check-params/services.ts @@ -1,17 +1,16 @@ /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */ import 'mocha' -import { VideoPlaylistPrivacy } from '@shared/models' -import { HttpStatusCode } from '../../../../shared/core-utils/miscs/http-error-codes' +import { HttpStatusCode } from '@shared/core-utils' import { cleanupTests, flushAndRunServer, makeGetRequest, ServerInfo, setAccessTokensToServers, - setDefaultVideoChannel, - uploadVideo -} from '../../../../shared/extra-utils' + setDefaultVideoChannel +} from '@shared/extra-utils' +import { VideoPlaylistPrivacy } from '@shared/models' describe('Test services API validators', function () { let server: ServerInfo @@ -26,10 +25,7 @@ describe('Test services API validators', function () { await setAccessTokensToServers([ server ]) await setDefaultVideoChannel([ server ]) - { - const res = await uploadVideo(server.url, server.accessToken, { name: 'my super name' }) - server.video = res.body.video - } + server.video = await server.videosCommand.upload({ attributes: { name: 'my super name' } }) { const created = await server.playlistsCommand.create({ diff --git a/server/tests/api/check-params/upload-quota.ts b/server/tests/api/check-params/upload-quota.ts index d94dec624..164c581e3 100644 --- a/server/tests/api/check-params/upload-quota.ts +++ b/server/tests/api/check-params/upload-quota.ts @@ -3,7 +3,6 @@ import 'mocha' import { expect } from 'chai' import { HttpStatusCode, randomInt } from '@shared/core-utils' -import { VideoImportState, VideoPrivacy } from '@shared/models' import { cleanupTests, flushAndRunServer, @@ -11,13 +10,15 @@ import { ServerInfo, setAccessTokensToServers, setDefaultVideoChannel, - uploadVideo, + VideosCommand, waitJobs -} from '../../../../shared/extra-utils' +} from '@shared/extra-utils' +import { VideoImportState, VideoPrivacy } from '@shared/models' describe('Test upload quota', function () { let server: ServerInfo let rootId: number + let command: VideosCommand // --------------------------------------------------------------- @@ -32,6 +33,8 @@ describe('Test upload quota', function () { rootId = user.id await server.usersCommand.update({ userId: rootId, videoQuota: 42 }) + + command = server.videosCommand }) describe('When having a video quota', function () { @@ -41,14 +44,14 @@ describe('Test upload quota', function () { const user = { username: 'registered' + randomInt(1, 1500), password: 'password' } await server.usersCommand.register(user) - const userAccessToken = await server.loginCommand.getAccessToken(user) + const userToken = await server.loginCommand.getAccessToken(user) - const videoAttributes = { fixture: 'video_short2.webm' } + const attributes = { fixture: 'video_short2.webm' } for (let i = 0; i < 5; i++) { - await uploadVideo(server.url, userAccessToken, videoAttributes) + await command.upload({ token: userToken, attributes }) } - await uploadVideo(server.url, userAccessToken, videoAttributes, HttpStatusCode.PAYLOAD_TOO_LARGE_413, 'legacy') + await command.upload({ token: userToken, attributes, expectedStatus: HttpStatusCode.PAYLOAD_TOO_LARGE_413, mode: 'legacy' }) }) it('Should fail with a registered user having too many videos with resumable upload', async function () { @@ -56,14 +59,14 @@ describe('Test upload quota', function () { const user = { username: 'registered' + randomInt(1, 1500), password: 'password' } await server.usersCommand.register(user) - const userAccessToken = await server.loginCommand.getAccessToken(user) + const userToken = await server.loginCommand.getAccessToken(user) - const videoAttributes = { fixture: 'video_short2.webm' } + const attributes = { fixture: 'video_short2.webm' } for (let i = 0; i < 5; i++) { - await uploadVideo(server.url, userAccessToken, videoAttributes) + await command.upload({ token: userToken, attributes }) } - await uploadVideo(server.url, userAccessToken, videoAttributes, HttpStatusCode.PAYLOAD_TOO_LARGE_413, 'resumable') + await command.upload({ token: userToken, attributes, expectedStatus: HttpStatusCode.PAYLOAD_TOO_LARGE_413, mode: 'resumable' }) }) it('Should fail to import with HTTP/Torrent/magnet', async function () { @@ -97,8 +100,8 @@ describe('Test upload quota', function () { it('Should fail with a user having too many videos daily', async function () { await server.usersCommand.update({ userId: rootId, videoQuotaDaily: 42 }) - await uploadVideo(server.url, server.accessToken, {}, HttpStatusCode.PAYLOAD_TOO_LARGE_413, 'legacy') - await uploadVideo(server.url, server.accessToken, {}, HttpStatusCode.PAYLOAD_TOO_LARGE_413, 'resumable') + await command.upload({ expectedStatus: HttpStatusCode.PAYLOAD_TOO_LARGE_413, mode: 'legacy' }) + await command.upload({ expectedStatus: HttpStatusCode.PAYLOAD_TOO_LARGE_413, mode: 'resumable' }) }) }) @@ -110,8 +113,8 @@ describe('Test upload quota', function () { videoQuotaDaily: 1024 * 1024 * 1024 }) - await uploadVideo(server.url, server.accessToken, {}, HttpStatusCode.PAYLOAD_TOO_LARGE_413, 'legacy') - await uploadVideo(server.url, server.accessToken, {}, HttpStatusCode.PAYLOAD_TOO_LARGE_413, 'resumable') + await command.upload({ expectedStatus: HttpStatusCode.PAYLOAD_TOO_LARGE_413, mode: 'legacy' }) + await command.upload({ expectedStatus: HttpStatusCode.PAYLOAD_TOO_LARGE_413, mode: 'resumable' }) }) it('Should fail if exceeding daily quota', async function () { @@ -121,8 +124,8 @@ describe('Test upload quota', function () { videoQuotaDaily: 42 }) - await uploadVideo(server.url, server.accessToken, {}, HttpStatusCode.PAYLOAD_TOO_LARGE_413, 'legacy') - await uploadVideo(server.url, server.accessToken, {}, HttpStatusCode.PAYLOAD_TOO_LARGE_413, 'resumable') + await command.upload({ expectedStatus: HttpStatusCode.PAYLOAD_TOO_LARGE_413, mode: 'legacy' }) + await command.upload({ expectedStatus: HttpStatusCode.PAYLOAD_TOO_LARGE_413, mode: 'resumable' }) }) }) diff --git a/server/tests/api/check-params/users.ts b/server/tests/api/check-params/users.ts index 801131918..33c48a009 100644 --- a/server/tests/api/check-params/users.ts +++ b/server/tests/api/check-params/users.ts @@ -2,10 +2,12 @@ import 'mocha' import { omit } from 'lodash' -import { UserRole, VideoCreateResult } from '../../../../shared' -import { HttpStatusCode } from '../../../../shared/core-utils/miscs/http-error-codes' +import { HttpStatusCode } from '@shared/core-utils' import { buildAbsoluteFixturePath, + checkBadCountPagination, + checkBadSortPagination, + checkBadStartPagination, cleanupTests, flushAndRunServer, killallServers, @@ -13,19 +15,13 @@ import { makePostBodyRequest, makePutBodyRequest, makeUploadRequest, + MockSmtpServer, reRunServer, ServerInfo, setAccessTokensToServers, - uploadVideo, UsersCommand -} from '../../../../shared/extra-utils' -import { MockSmtpServer } from '../../../../shared/extra-utils/mock-servers/mock-email' -import { - checkBadCountPagination, - checkBadSortPagination, - checkBadStartPagination -} from '../../../../shared/extra-utils/requests/check-api-params' -import { UserAdminFlag } from '../../../../shared/models/users/user-flag.model' +} from '@shared/extra-utils' +import { UserAdminFlag, UserRole, VideoCreateResult } from '@shared/models' describe('Test users API validators', function () { const path = '/api/v1/users/' @@ -80,8 +76,7 @@ describe('Test users API validators', function () { } { - const res = await uploadVideo(server.url, server.accessToken, {}) - video = res.body.video + video = await server.videosCommand.upload() } { diff --git a/server/tests/api/check-params/video-blacklist.ts b/server/tests/api/check-params/video-blacklist.ts index 5097f8069..0fda31b29 100644 --- a/server/tests/api/check-params/video-blacklist.ts +++ b/server/tests/api/check-params/video-blacklist.ts @@ -11,20 +11,17 @@ import { cleanupTests, doubleFollow, flushAndRunMultipleServers, - getVideo, - getVideoWithToken, makePostBodyRequest, makePutBodyRequest, ServerInfo, setAccessTokensToServers, - uploadVideo, waitJobs } from '@shared/extra-utils' -import { VideoBlacklistType, VideoDetails } from '@shared/models' +import { VideoBlacklistType } from '@shared/models' describe('Test video blacklist API validators', function () { let servers: ServerInfo[] - let notBlacklistedVideoId: number + let notBlacklistedVideoId: string let remoteVideoUUID: string let userAccessToken1 = '' let userAccessToken2 = '' @@ -55,18 +52,17 @@ describe('Test video blacklist API validators', function () { } { - const res = await uploadVideo(servers[0].url, userAccessToken1, {}) - servers[0].video = res.body.video + servers[0].video = await servers[0].videosCommand.upload({ token: userAccessToken1 }) } { - const res = await uploadVideo(servers[0].url, servers[0].accessToken, {}) - notBlacklistedVideoId = res.body.video.uuid + const { uuid } = await servers[0].videosCommand.upload() + notBlacklistedVideoId = uuid } { - const res = await uploadVideo(servers[1].url, servers[1].accessToken, {}) - remoteVideoUUID = res.body.video.uuid + const { uuid } = await servers[1].videosCommand.upload() + remoteVideoUUID = uuid } await waitJobs(servers) @@ -204,17 +200,19 @@ describe('Test video blacklist API validators', function () { describe('When getting blacklisted video', function () { it('Should fail with a non authenticated user', async function () { - await getVideo(servers[0].url, servers[0].video.uuid, HttpStatusCode.UNAUTHORIZED_401) + await servers[0].videosCommand.get({ id: servers[0].video.uuid, expectedStatus: HttpStatusCode.UNAUTHORIZED_401 }) }) it('Should fail with another user', async function () { - await getVideoWithToken(servers[0].url, userAccessToken2, servers[0].video.uuid, HttpStatusCode.FORBIDDEN_403) + await servers[0].videosCommand.getWithToken({ + token: userAccessToken2, + id: servers[0].video.uuid, + expectedStatus: HttpStatusCode.FORBIDDEN_403 + }) }) it('Should succeed with the owner authenticated user', async function () { - const res = await getVideoWithToken(servers[0].url, userAccessToken1, servers[0].video.uuid, HttpStatusCode.OK_200) - const video: VideoDetails = res.body - + const video = await servers[0].videosCommand.getWithToken({ token: userAccessToken1, id: servers[0].video.uuid }) expect(video.blacklisted).to.be.true }) @@ -222,9 +220,7 @@ describe('Test video blacklist API validators', function () { const video = servers[0].video for (const id of [ video.id, video.uuid, video.shortUUID ]) { - const res = await getVideoWithToken(servers[0].url, servers[0].accessToken, id, HttpStatusCode.OK_200) - const video: VideoDetails = res.body - + const video = await servers[0].videosCommand.getWithToken({ id, expectedStatus: HttpStatusCode.OK_200 }) expect(video.blacklisted).to.be.true } }) diff --git a/server/tests/api/check-params/video-captions.ts b/server/tests/api/check-params/video-captions.ts index 631ef4dac..f3941b3fa 100644 --- a/server/tests/api/check-params/video-captions.ts +++ b/server/tests/api/check-params/video-captions.ts @@ -10,8 +10,7 @@ import { makeGetRequest, makeUploadRequest, ServerInfo, - setAccessTokensToServers, - uploadVideo + setAccessTokensToServers } from '@shared/extra-utils' import { VideoCreateResult } from '@shared/models' @@ -31,10 +30,7 @@ describe('Test video captions API validator', function () { await setAccessTokensToServers([ server ]) - { - const res = await uploadVideo(server.url, server.accessToken, {}) - video = res.body.video - } + video = await server.videosCommand.upload() { const user = { diff --git a/server/tests/api/check-params/video-comments.ts b/server/tests/api/check-params/video-comments.ts index b7656a176..bdf7f91ee 100644 --- a/server/tests/api/check-params/video-comments.ts +++ b/server/tests/api/check-params/video-comments.ts @@ -13,8 +13,7 @@ import { makeGetRequest, makePostBodyRequest, ServerInfo, - setAccessTokensToServers, - uploadVideo + setAccessTokensToServers } from '@shared/extra-utils' import { VideoCreateResult } from '@shared/models' @@ -39,8 +38,7 @@ describe('Test video comments API validator', function () { await setAccessTokensToServers([ server ]) { - const res = await uploadVideo(server.url, server.accessToken, {}) - video = res.body.video + const video = await server.videosCommand.upload({ attributes: {} }) pathThread = '/api/v1/videos/' + video.uuid + '/comment-threads' } @@ -291,8 +289,8 @@ describe('Test video comments API validator', function () { let anotherVideoUUID: string { - const res = await uploadVideo(server.url, userAccessToken, { name: 'video' }) - anotherVideoUUID = res.body.video.uuid + const { uuid } = await server.videosCommand.upload({ token: userAccessToken, attributes: { name: 'video' } }) + anotherVideoUUID = uuid } { @@ -318,8 +316,7 @@ describe('Test video comments API validator', function () { describe('When a video has comments disabled', function () { before(async function () { - const res = await uploadVideo(server.url, server.accessToken, { commentsEnabled: false }) - video = res.body.video + video = await server.videosCommand.upload({ attributes: { commentsEnabled: false } }) pathThread = '/api/v1/videos/' + video.uuid + '/comment-threads' }) diff --git a/server/tests/api/check-params/video-playlists.ts b/server/tests/api/check-params/video-playlists.ts index 46c09bb11..ebd7e2413 100644 --- a/server/tests/api/check-params/video-playlists.ts +++ b/server/tests/api/check-params/video-playlists.ts @@ -2,15 +2,6 @@ import 'mocha' import { HttpStatusCode } from '@shared/core-utils' -import { - VideoPlaylistCreate, - VideoPlaylistCreateResult, - VideoPlaylistElementCreate, - VideoPlaylistElementUpdate, - VideoPlaylistPrivacy, - VideoPlaylistReorder, - VideoPlaylistType -} from '@shared/models' import { checkBadCountPagination, checkBadSortPagination, @@ -21,9 +12,17 @@ import { PlaylistsCommand, ServerInfo, setAccessTokensToServers, - setDefaultVideoChannel, - uploadVideoAndGetId -} from '../../../../shared/extra-utils' + setDefaultVideoChannel +} from '@shared/extra-utils' +import { + VideoPlaylistCreate, + VideoPlaylistCreateResult, + VideoPlaylistElementCreate, + VideoPlaylistElementUpdate, + VideoPlaylistPrivacy, + VideoPlaylistReorder, + VideoPlaylistType +} from '@shared/models' describe('Test video playlists API validator', function () { let server: ServerInfo @@ -49,7 +48,7 @@ describe('Test video playlists API validator', function () { await setDefaultVideoChannel([ server ]) userAccessToken = await server.usersCommand.generateUserAndToken('user1') - videoId = (await uploadVideoAndGetId({ server, videoName: 'video 1' })).id + videoId = (await server.videosCommand.quickUpload({ name: 'video 1' })).id command = server.playlistsCommand @@ -486,8 +485,8 @@ describe('Test video playlists API validator', function () { } before(async function () { - videoId3 = (await uploadVideoAndGetId({ server, videoName: 'video 3' })).id - videoId4 = (await uploadVideoAndGetId({ server, videoName: 'video 4' })).id + videoId3 = (await server.videosCommand.quickUpload({ name: 'video 3' })).id + videoId4 = (await server.videosCommand.quickUpload({ name: 'video 4' })).id for (const id of [ videoId3, videoId4 ]) { await command.addElement({ playlistId: playlist.shortUUID, attributes: { videoId: id } }) diff --git a/server/tests/api/check-params/videos-history.ts b/server/tests/api/check-params/videos-history.ts index 0e91fe0a8..1da922a17 100644 --- a/server/tests/api/check-params/videos-history.ts +++ b/server/tests/api/check-params/videos-history.ts @@ -1,6 +1,7 @@ /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */ import 'mocha' +import { HttpStatusCode } from '@shared/core-utils' import { checkBadCountPagination, checkBadStartPagination, @@ -10,10 +11,8 @@ import { makePostBodyRequest, makePutBodyRequest, ServerInfo, - setAccessTokensToServers, - uploadVideo -} from '../../../../shared/extra-utils' -import { HttpStatusCode } from '../../../../shared/core-utils/miscs/http-error-codes' + setAccessTokensToServers +} from '@shared/extra-utils' describe('Test videos history API validator', function () { const myHistoryPath = '/api/v1/users/me/history/videos' @@ -30,10 +29,8 @@ describe('Test videos history API validator', function () { await setAccessTokensToServers([ server ]) - const res = await uploadVideo(server.url, server.accessToken, {}) - const videoUUID = res.body.video.uuid - - watchingPath = '/api/v1/videos/' + videoUUID + '/watching' + const { uuid } = await server.videosCommand.upload() + watchingPath = '/api/v1/videos/' + uuid + '/watching' }) describe('When notifying a user is watching a video', function () { diff --git a/server/tests/api/check-params/videos.ts b/server/tests/api/check-params/videos.ts index 855b09f39..8f9f33b8c 100644 --- a/server/tests/api/check-params/videos.ts +++ b/server/tests/api/check-params/videos.ts @@ -4,30 +4,23 @@ import 'mocha' import * as chai from 'chai' import { omit } from 'lodash' import { join } from 'path' -import { randomInt } from '@shared/core-utils' -import { PeerTubeProblemDocument, VideoCreateResult } from '@shared/models' -import { HttpStatusCode } from '../../../../shared/core-utils/miscs/http-error-codes' +import { HttpStatusCode, randomInt } from '@shared/core-utils' import { + checkBadCountPagination, + checkBadSortPagination, + checkBadStartPagination, checkUploadVideoParam, cleanupTests, flushAndRunServer, - getVideo, - getVideosList, makeDeleteRequest, makeGetRequest, makePutBodyRequest, makeUploadRequest, - removeVideo, root, ServerInfo, setAccessTokensToServers -} from '../../../../shared/extra-utils' -import { - checkBadCountPagination, - checkBadSortPagination, - checkBadStartPagination -} from '../../../../shared/extra-utils/requests/check-api-params' -import { VideoPrivacy } from '../../../../shared/models/videos/video-privacy.enum' +} from '@shared/extra-utils' +import { PeerTubeProblemDocument, VideoCreateResult, VideoPrivacy } from '@shared/models' const expect = chai.expect @@ -210,70 +203,70 @@ describe('Test videos API validator', function () { it('Should fail with nothing', async function () { const fields = {} const attaches = {} - await checkUploadVideoParam(server.url, server.accessToken, { ...fields, ...attaches }, HttpStatusCode.BAD_REQUEST_400, mode) + await checkUploadVideoParam(server, server.accessToken, { ...fields, ...attaches }, HttpStatusCode.BAD_REQUEST_400, mode) }) it('Should fail without name', async function () { const fields = omit(baseCorrectParams, 'name') const attaches = baseCorrectAttaches - await checkUploadVideoParam(server.url, server.accessToken, { ...fields, ...attaches }, HttpStatusCode.BAD_REQUEST_400, mode) + await checkUploadVideoParam(server, server.accessToken, { ...fields, ...attaches }, HttpStatusCode.BAD_REQUEST_400, mode) }) it('Should fail with a long name', async function () { const fields = { ...baseCorrectParams, name: 'super'.repeat(65) } const attaches = baseCorrectAttaches - await checkUploadVideoParam(server.url, server.accessToken, { ...fields, ...attaches }, HttpStatusCode.BAD_REQUEST_400, mode) + await checkUploadVideoParam(server, server.accessToken, { ...fields, ...attaches }, HttpStatusCode.BAD_REQUEST_400, mode) }) it('Should fail with a bad category', async function () { const fields = { ...baseCorrectParams, category: 125 } const attaches = baseCorrectAttaches - await checkUploadVideoParam(server.url, server.accessToken, { ...fields, ...attaches }, HttpStatusCode.BAD_REQUEST_400, mode) + await checkUploadVideoParam(server, server.accessToken, { ...fields, ...attaches }, HttpStatusCode.BAD_REQUEST_400, mode) }) it('Should fail with a bad licence', async function () { const fields = { ...baseCorrectParams, licence: 125 } const attaches = baseCorrectAttaches - await checkUploadVideoParam(server.url, server.accessToken, { ...fields, ...attaches }, HttpStatusCode.BAD_REQUEST_400, mode) + await checkUploadVideoParam(server, server.accessToken, { ...fields, ...attaches }, HttpStatusCode.BAD_REQUEST_400, mode) }) it('Should fail with a bad language', async function () { const fields = { ...baseCorrectParams, language: 'a'.repeat(15) } const attaches = baseCorrectAttaches - await checkUploadVideoParam(server.url, server.accessToken, { ...fields, ...attaches }, HttpStatusCode.BAD_REQUEST_400, mode) + await checkUploadVideoParam(server, server.accessToken, { ...fields, ...attaches }, HttpStatusCode.BAD_REQUEST_400, mode) }) it('Should fail with a long description', async function () { const fields = { ...baseCorrectParams, description: 'super'.repeat(2500) } const attaches = baseCorrectAttaches - await checkUploadVideoParam(server.url, server.accessToken, { ...fields, ...attaches }, HttpStatusCode.BAD_REQUEST_400, mode) + await checkUploadVideoParam(server, server.accessToken, { ...fields, ...attaches }, HttpStatusCode.BAD_REQUEST_400, mode) }) it('Should fail with a long support text', async function () { const fields = { ...baseCorrectParams, support: 'super'.repeat(201) } const attaches = baseCorrectAttaches - await checkUploadVideoParam(server.url, server.accessToken, { ...fields, ...attaches }, HttpStatusCode.BAD_REQUEST_400, mode) + await checkUploadVideoParam(server, server.accessToken, { ...fields, ...attaches }, HttpStatusCode.BAD_REQUEST_400, mode) }) it('Should fail without a channel', async function () { const fields = omit(baseCorrectParams, 'channelId') const attaches = baseCorrectAttaches - await checkUploadVideoParam(server.url, server.accessToken, { ...fields, ...attaches }, HttpStatusCode.BAD_REQUEST_400, mode) + await checkUploadVideoParam(server, server.accessToken, { ...fields, ...attaches }, HttpStatusCode.BAD_REQUEST_400, mode) }) it('Should fail with a bad channel', async function () { const fields = { ...baseCorrectParams, channelId: 545454 } const attaches = baseCorrectAttaches - await checkUploadVideoParam(server.url, server.accessToken, { ...fields, ...attaches }, HttpStatusCode.BAD_REQUEST_400, mode) + await checkUploadVideoParam(server, server.accessToken, { ...fields, ...attaches }, HttpStatusCode.BAD_REQUEST_400, mode) }) it('Should fail with another user channel', async function () { @@ -290,35 +283,35 @@ describe('Test videos API validator', function () { const fields = { ...baseCorrectParams, channelId: customChannelId } const attaches = baseCorrectAttaches - await checkUploadVideoParam(server.url, userAccessToken, { ...fields, ...attaches }, HttpStatusCode.BAD_REQUEST_400, mode) + await checkUploadVideoParam(server, userAccessToken, { ...fields, ...attaches }, HttpStatusCode.BAD_REQUEST_400, mode) }) it('Should fail with too many tags', async function () { const fields = { ...baseCorrectParams, tags: [ 'tag1', 'tag2', 'tag3', 'tag4', 'tag5', 'tag6' ] } const attaches = baseCorrectAttaches - await checkUploadVideoParam(server.url, server.accessToken, { ...fields, ...attaches }, HttpStatusCode.BAD_REQUEST_400, mode) + await checkUploadVideoParam(server, server.accessToken, { ...fields, ...attaches }, HttpStatusCode.BAD_REQUEST_400, mode) }) it('Should fail with a tag length too low', async function () { const fields = { ...baseCorrectParams, tags: [ 'tag1', 't' ] } const attaches = baseCorrectAttaches - await checkUploadVideoParam(server.url, server.accessToken, { ...fields, ...attaches }, HttpStatusCode.BAD_REQUEST_400, mode) + await checkUploadVideoParam(server, server.accessToken, { ...fields, ...attaches }, HttpStatusCode.BAD_REQUEST_400, mode) }) it('Should fail with a tag length too big', async function () { const fields = { ...baseCorrectParams, tags: [ 'tag1', 'my_super_tag_too_long_long_long_long_long_long' ] } const attaches = baseCorrectAttaches - await checkUploadVideoParam(server.url, server.accessToken, { ...fields, ...attaches }, HttpStatusCode.BAD_REQUEST_400, mode) + await checkUploadVideoParam(server, server.accessToken, { ...fields, ...attaches }, HttpStatusCode.BAD_REQUEST_400, mode) }) it('Should fail with a bad schedule update (miss updateAt)', async function () { const fields = { ...baseCorrectParams, scheduleUpdate: { privacy: VideoPrivacy.PUBLIC } } const attaches = baseCorrectAttaches - await checkUploadVideoParam(server.url, server.accessToken, { ...fields, ...attaches }, HttpStatusCode.BAD_REQUEST_400, mode) + await checkUploadVideoParam(server, server.accessToken, { ...fields, ...attaches }, HttpStatusCode.BAD_REQUEST_400, mode) }) it('Should fail with a bad schedule update (wrong updateAt)', async function () { @@ -332,20 +325,20 @@ describe('Test videos API validator', function () { } const attaches = baseCorrectAttaches - await checkUploadVideoParam(server.url, server.accessToken, { ...fields, ...attaches }, HttpStatusCode.BAD_REQUEST_400, mode) + await checkUploadVideoParam(server, server.accessToken, { ...fields, ...attaches }, HttpStatusCode.BAD_REQUEST_400, mode) }) it('Should fail with a bad originally published at attribute', async function () { const fields = { ...baseCorrectParams, originallyPublishedAt: 'toto' } const attaches = baseCorrectAttaches - await checkUploadVideoParam(server.url, server.accessToken, { ...fields, ...attaches }, HttpStatusCode.BAD_REQUEST_400, mode) + await checkUploadVideoParam(server, server.accessToken, { ...fields, ...attaches }, HttpStatusCode.BAD_REQUEST_400, mode) }) it('Should fail without an input file', async function () { const fields = baseCorrectParams const attaches = {} - await checkUploadVideoParam(server.url, server.accessToken, { ...fields, ...attaches }, HttpStatusCode.BAD_REQUEST_400, mode) + await checkUploadVideoParam(server, server.accessToken, { ...fields, ...attaches }, HttpStatusCode.BAD_REQUEST_400, mode) }) it('Should fail with an incorrect input file', async function () { @@ -353,7 +346,7 @@ describe('Test videos API validator', function () { let attaches = { fixture: join(root(), 'server', 'tests', 'fixtures', 'video_short_fake.webm') } await checkUploadVideoParam( - server.url, + server, server.accessToken, { ...fields, ...attaches }, HttpStatusCode.UNPROCESSABLE_ENTITY_422, @@ -362,7 +355,7 @@ describe('Test videos API validator', function () { attaches = { fixture: join(root(), 'server', 'tests', 'fixtures', 'video_short.mkv') } await checkUploadVideoParam( - server.url, + server, server.accessToken, { ...fields, ...attaches }, HttpStatusCode.UNSUPPORTED_MEDIA_TYPE_415, @@ -377,7 +370,7 @@ describe('Test videos API validator', function () { fixture: join(root(), 'server', 'tests', 'fixtures', 'video_short.mp4') } - await checkUploadVideoParam(server.url, server.accessToken, { ...fields, ...attaches }, HttpStatusCode.BAD_REQUEST_400, mode) + await checkUploadVideoParam(server, server.accessToken, { ...fields, ...attaches }, HttpStatusCode.BAD_REQUEST_400, mode) }) it('Should fail with a big thumbnail file', async function () { @@ -387,7 +380,7 @@ describe('Test videos API validator', function () { fixture: join(root(), 'server', 'tests', 'fixtures', 'video_short.mp4') } - await checkUploadVideoParam(server.url, server.accessToken, { ...fields, ...attaches }, HttpStatusCode.BAD_REQUEST_400, mode) + await checkUploadVideoParam(server, server.accessToken, { ...fields, ...attaches }, HttpStatusCode.BAD_REQUEST_400, mode) }) it('Should fail with an incorrect preview file', async function () { @@ -397,7 +390,7 @@ describe('Test videos API validator', function () { fixture: join(root(), 'server', 'tests', 'fixtures', 'video_short.mp4') } - await checkUploadVideoParam(server.url, server.accessToken, { ...fields, ...attaches }, HttpStatusCode.BAD_REQUEST_400, mode) + await checkUploadVideoParam(server, server.accessToken, { ...fields, ...attaches }, HttpStatusCode.BAD_REQUEST_400, mode) }) it('Should fail with a big preview file', async function () { @@ -407,7 +400,7 @@ describe('Test videos API validator', function () { fixture: join(root(), 'server', 'tests', 'fixtures', 'video_short.mp4') } - await checkUploadVideoParam(server.url, server.accessToken, { ...fields, ...attaches }, HttpStatusCode.BAD_REQUEST_400, mode) + await checkUploadVideoParam(server, server.accessToken, { ...fields, ...attaches }, HttpStatusCode.BAD_REQUEST_400, mode) }) it('Should report the appropriate error', async function () { @@ -415,9 +408,9 @@ describe('Test videos API validator', function () { const attaches = baseCorrectAttaches const attributes = { ...fields, ...attaches } - const res = await checkUploadVideoParam(server.url, server.accessToken, attributes, HttpStatusCode.BAD_REQUEST_400, mode) + const body = await checkUploadVideoParam(server, server.accessToken, attributes, HttpStatusCode.BAD_REQUEST_400, mode) - const error = res.body as PeerTubeProblemDocument + const error = body as unknown as PeerTubeProblemDocument if (mode === 'legacy') { expect(error.docs).to.equal('https://docs.joinpeertube.org/api-rest-reference.html#operation/uploadLegacy') @@ -442,7 +435,7 @@ describe('Test videos API validator', function () { { const attaches = baseCorrectAttaches - await checkUploadVideoParam(server.url, server.accessToken, { ...fields, ...attaches }, HttpStatusCode.OK_200, mode) + await checkUploadVideoParam(server, server.accessToken, { ...fields, ...attaches }, HttpStatusCode.OK_200, mode) } { @@ -452,7 +445,7 @@ describe('Test videos API validator', function () { videofile: join(root(), 'server', 'tests', 'fixtures', 'video_short.mp4') } - await checkUploadVideoParam(server.url, server.accessToken, { ...fields, ...attaches }, HttpStatusCode.OK_200, mode) + await checkUploadVideoParam(server, server.accessToken, { ...fields, ...attaches }, HttpStatusCode.OK_200, mode) } { @@ -462,7 +455,7 @@ describe('Test videos API validator', function () { videofile: join(root(), 'server', 'tests', 'fixtures', 'video_short.ogv') } - await checkUploadVideoParam(server.url, server.accessToken, { ...fields, ...attaches }, HttpStatusCode.OK_200, mode) + await checkUploadVideoParam(server, server.accessToken, { ...fields, ...attaches }, HttpStatusCode.OK_200, mode) } }) } @@ -491,8 +484,8 @@ describe('Test videos API validator', function () { } before(async function () { - const res = await getVideosList(server.url) - video = res.body.data[0] + const { data } = await server.videosCommand.list() + video = data[0] }) it('Should fail with nothing', async function () { @@ -717,16 +710,16 @@ describe('Test videos API validator', function () { }) it('Should fail without a correct uuid', async function () { - await getVideo(server.url, 'coucou', HttpStatusCode.BAD_REQUEST_400) + await server.videosCommand.get({ id: 'coucou', expectedStatus: HttpStatusCode.BAD_REQUEST_400 }) }) it('Should return 404 with an incorrect video', async function () { - await getVideo(server.url, '4da6fde3-88f7-4d16-b119-108df5630b06', HttpStatusCode.NOT_FOUND_404) + await server.videosCommand.get({ id: '4da6fde3-88f7-4d16-b119-108df5630b06', expectedStatus: HttpStatusCode.NOT_FOUND_404 }) }) it('Shoud report the appropriate error', async function () { - const res = await getVideo(server.url, 'hi', HttpStatusCode.BAD_REQUEST_400) - const error = res.body as PeerTubeProblemDocument + const body = await server.videosCommand.get({ id: 'hi', expectedStatus: HttpStatusCode.BAD_REQUEST_400 }) + const error = body as unknown as PeerTubeProblemDocument expect(error.docs).to.equal('https://docs.joinpeertube.org/api-rest-reference.html#operation/getVideo') @@ -741,16 +734,16 @@ describe('Test videos API validator', function () { }) it('Should succeed with the correct parameters', async function () { - await getVideo(server.url, video.shortUUID) + await server.videosCommand.get({ id: video.shortUUID }) }) }) describe('When rating a video', function () { - let videoId + let videoId: number before(async function () { - const res = await getVideosList(server.url) - videoId = res.body.data[0].id + const { data } = await server.videosCommand.list() + videoId = data[0].id }) it('Should fail without a valid uuid', async function () { @@ -804,22 +797,22 @@ describe('Test videos API validator', function () { }) it('Should fail without a correct uuid', async function () { - await removeVideo(server.url, server.accessToken, 'hello', HttpStatusCode.BAD_REQUEST_400) + await server.videosCommand.remove({ id: 'hello', expectedStatus: HttpStatusCode.BAD_REQUEST_400 }) }) it('Should fail with a video which does not exist', async function () { - await removeVideo(server.url, server.accessToken, '4da6fde3-88f7-4d16-b119-108df5630b06', HttpStatusCode.NOT_FOUND_404) + await server.videosCommand.remove({ id: '4da6fde3-88f7-4d16-b119-108df5630b06', expectedStatus: HttpStatusCode.NOT_FOUND_404 }) }) it('Should fail with a video of another user without the appropriate right', async function () { - await removeVideo(server.url, userAccessToken, video.uuid, HttpStatusCode.FORBIDDEN_403) + await server.videosCommand.remove({ token: userAccessToken, id: video.uuid, expectedStatus: HttpStatusCode.FORBIDDEN_403 }) }) it('Should fail with a video of another server') it('Shoud report the appropriate error', async function () { - const res = await removeVideo(server.url, server.accessToken, 'hello', HttpStatusCode.BAD_REQUEST_400) - const error = res.body as PeerTubeProblemDocument + const body = await server.videosCommand.remove({ id: 'hello', expectedStatus: HttpStatusCode.BAD_REQUEST_400 }) + const error = body as unknown as PeerTubeProblemDocument expect(error.docs).to.equal('https://docs.joinpeertube.org/api-rest-reference.html#operation/delVideo') @@ -834,7 +827,7 @@ describe('Test videos API validator', function () { }) it('Should succeed with the correct parameters', async function () { - await removeVideo(server.url, server.accessToken, video.uuid) + await server.videosCommand.remove({ id: video.uuid }) }) }) -- cgit v1.2.3 From 89d241a79c262b9775c233b73cff080043ebb5e6 Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Fri, 16 Jul 2021 09:04:35 +0200 Subject: Shorter server command names --- server/tests/api/check-params/abuses.ts | 28 ++++---- server/tests/api/check-params/accounts.ts | 2 +- server/tests/api/check-params/blocklist.ts | 4 +- server/tests/api/check-params/bulk.ts | 4 +- server/tests/api/check-params/config.ts | 4 +- server/tests/api/check-params/contact-form.ts | 2 +- server/tests/api/check-params/custom-pages.ts | 4 +- server/tests/api/check-params/debug.ts | 4 +- server/tests/api/check-params/follows.ts | 4 +- server/tests/api/check-params/jobs.ts | 4 +- server/tests/api/check-params/live.ts | 30 ++++----- server/tests/api/check-params/logs.ts | 4 +- server/tests/api/check-params/plugins.ts | 8 +-- server/tests/api/check-params/redundancy.ts | 10 +-- server/tests/api/check-params/search.ts | 2 +- server/tests/api/check-params/services.ts | 20 +++--- server/tests/api/check-params/upload-quota.ts | 30 ++++----- .../tests/api/check-params/user-subscriptions.ts | 4 +- server/tests/api/check-params/users.ts | 74 +++++++++++----------- server/tests/api/check-params/video-blacklist.ts | 60 +++++++++--------- server/tests/api/check-params/video-captions.ts | 8 +-- server/tests/api/check-params/video-channels.ts | 8 +-- server/tests/api/check-params/video-comments.ts | 20 +++--- server/tests/api/check-params/video-imports.ts | 16 ++--- server/tests/api/check-params/video-playlists.ts | 16 ++--- server/tests/api/check-params/videos-filter.ts | 8 +-- server/tests/api/check-params/videos-history.ts | 2 +- server/tests/api/check-params/videos-overviews.ts | 6 +- server/tests/api/check-params/videos.ts | 34 +++++----- 29 files changed, 210 insertions(+), 210 deletions(-) (limited to 'server/tests/api/check-params') diff --git a/server/tests/api/check-params/abuses.ts b/server/tests/api/check-params/abuses.ts index 199cc5599..7a6790ba8 100644 --- a/server/tests/api/check-params/abuses.ts +++ b/server/tests/api/check-params/abuses.ts @@ -39,12 +39,12 @@ describe('Test abuses API validators', function () { await setAccessTokensToServers([ server ]) - userToken = await server.usersCommand.generateUserAndToken('user_1') - userToken2 = await server.usersCommand.generateUserAndToken('user_2') + userToken = await server.users.generateUserAndToken('user_1') + userToken2 = await server.users.generateUserAndToken('user_2') - server.video = await server.videosCommand.upload() + server.store.video = await server.videos.upload() - command = server.abusesCommand + command = server.abuses }) describe('When listing abuses for admins', function () { @@ -224,25 +224,25 @@ describe('Test abuses API validators', function () { }) it('Should fail with a non authenticated user', async function () { - const fields = { video: { id: server.video.id }, reason: 'my super reason' } + const fields = { video: { id: server.store.video.id }, reason: 'my super reason' } await makePostBodyRequest({ url: server.url, path, token: 'hello', fields, statusCodeExpected: HttpStatusCode.UNAUTHORIZED_401 }) }) it('Should fail with a reason too short', async function () { - const fields = { video: { id: server.video.id }, reason: 'h' } + const fields = { video: { id: server.store.video.id }, reason: 'h' } await makePostBodyRequest({ url: server.url, path, token: userToken, fields }) }) it('Should fail with a too big reason', async function () { - const fields = { video: { id: server.video.id }, reason: 'super'.repeat(605) } + const fields = { video: { id: server.store.video.id }, reason: 'super'.repeat(605) } await makePostBodyRequest({ url: server.url, path, token: userToken, fields }) }) it('Should succeed with the correct parameters (basic)', async function () { - const fields: AbuseCreate = { video: { id: server.video.shortUUID }, reason: 'my super reason' } + const fields: AbuseCreate = { video: { id: server.store.video.shortUUID }, reason: 'my super reason' } const res = await makePostBodyRequest({ url: server.url, @@ -255,19 +255,19 @@ describe('Test abuses API validators', function () { }) it('Should fail with a wrong predefined reason', async function () { - const fields = { video: { id: server.video.id }, reason: 'my super reason', predefinedReasons: [ 'wrongPredefinedReason' ] } + const fields = { video: { id: server.store.video.id }, reason: 'my super reason', predefinedReasons: [ 'wrongPredefinedReason' ] } await makePostBodyRequest({ url: server.url, path, token: userToken, fields }) }) it('Should fail with negative timestamps', async function () { - const fields = { video: { id: server.video.id, startAt: -1 }, reason: 'my super reason' } + const fields = { video: { id: server.store.video.id, startAt: -1 }, reason: 'my super reason' } await makePostBodyRequest({ url: server.url, path, token: userToken, fields }) }) it('Should fail mith misordered startAt/endAt', async function () { - const fields = { video: { id: server.video.id, startAt: 5, endAt: 1 }, reason: 'my super reason' } + const fields = { video: { id: server.store.video.id, startAt: 5, endAt: 1 }, reason: 'my super reason' } await makePostBodyRequest({ url: server.url, path, token: userToken, fields }) }) @@ -275,7 +275,7 @@ describe('Test abuses API validators', function () { it('Should succeed with the corret parameters (advanced)', async function () { const fields: AbuseCreate = { video: { - id: server.video.id, + id: server.store.video.id, startAt: 1, endAt: 5 }, @@ -414,8 +414,8 @@ describe('Test abuses API validators', function () { await doubleFollow(anotherServer, server) - const server2VideoId = await anotherServer.videosCommand.getId({ uuid: server.video.uuid }) - await anotherServer.abusesCommand.report({ reason: 'remote server', videoId: server2VideoId }) + const server2VideoId = await anotherServer.videos.getId({ uuid: server.store.video.uuid }) + await anotherServer.abuses.report({ reason: 'remote server', videoId: server2VideoId }) await waitJobs([ server, anotherServer ]) diff --git a/server/tests/api/check-params/accounts.ts b/server/tests/api/check-params/accounts.ts index 45d440c47..223322626 100644 --- a/server/tests/api/check-params/accounts.ts +++ b/server/tests/api/check-params/accounts.ts @@ -40,7 +40,7 @@ describe('Test accounts API validators', function () { describe('When getting an account', function () { it('Should return 404 with a non existing name', async function () { - await server.accountsCommand.get({ accountName: 'arfaze', expectedStatus: HttpStatusCode.NOT_FOUND_404 }) + await server.accounts.get({ accountName: 'arfaze', expectedStatus: HttpStatusCode.NOT_FOUND_404 }) }) }) diff --git a/server/tests/api/check-params/blocklist.ts b/server/tests/api/check-params/blocklist.ts index 18238bb04..14e45e503 100644 --- a/server/tests/api/check-params/blocklist.ts +++ b/server/tests/api/check-params/blocklist.ts @@ -33,9 +33,9 @@ describe('Test blocklist API validators', function () { server = servers[0] const user = { username: 'user1', password: 'password' } - await server.usersCommand.create({ username: user.username, password: user.password }) + await server.users.create({ username: user.username, password: user.password }) - userAccessToken = await server.loginCommand.getAccessToken(user) + userAccessToken = await server.login.getAccessToken(user) await doubleFollow(servers[0], servers[1]) }) diff --git a/server/tests/api/check-params/bulk.ts b/server/tests/api/check-params/bulk.ts index 3f80c79a8..69ff7dd96 100644 --- a/server/tests/api/check-params/bulk.ts +++ b/server/tests/api/check-params/bulk.ts @@ -23,9 +23,9 @@ describe('Test bulk API validators', function () { await setAccessTokensToServers([ server ]) const user = { username: 'user1', password: 'password' } - await server.usersCommand.create({ username: user.username, password: user.password }) + await server.users.create({ username: user.username, password: user.password }) - userAccessToken = await server.loginCommand.getAccessToken(user) + userAccessToken = await server.login.getAccessToken(user) }) describe('When removing comments of', function () { diff --git a/server/tests/api/check-params/config.ts b/server/tests/api/check-params/config.ts index c204d9415..6fd26864e 100644 --- a/server/tests/api/check-params/config.ts +++ b/server/tests/api/check-params/config.ts @@ -205,8 +205,8 @@ describe('Test config API validators', function () { username: 'user1', password: 'password' } - await server.usersCommand.create({ username: user.username, password: user.password }) - userAccessToken = await server.loginCommand.getAccessToken(user) + await server.users.create({ username: user.username, password: user.password }) + userAccessToken = await server.login.getAccessToken(user) }) describe('When getting the configuration', function () { diff --git a/server/tests/api/check-params/contact-form.ts b/server/tests/api/check-params/contact-form.ts index 4eed1661a..d2541777f 100644 --- a/server/tests/api/check-params/contact-form.ts +++ b/server/tests/api/check-params/contact-form.ts @@ -26,7 +26,7 @@ describe('Test contact form API validators', function () { // Email is disabled server = await flushAndRunServer(1) - command = server.contactFormCommand + command = server.contactForm }) it('Should not accept a contact form if emails are disabled', async function () { diff --git a/server/tests/api/check-params/custom-pages.ts b/server/tests/api/check-params/custom-pages.ts index 58b0b8600..3d84fb3e6 100644 --- a/server/tests/api/check-params/custom-pages.ts +++ b/server/tests/api/check-params/custom-pages.ts @@ -25,9 +25,9 @@ describe('Test custom pages validators', function () { await setAccessTokensToServers([ server ]) const user = { username: 'user1', password: 'password' } - await server.usersCommand.create({ username: user.username, password: user.password }) + await server.users.create({ username: user.username, password: user.password }) - userAccessToken = await server.loginCommand.getAccessToken(user) + userAccessToken = await server.login.getAccessToken(user) }) describe('When updating instance homepage', function () { diff --git a/server/tests/api/check-params/debug.ts b/server/tests/api/check-params/debug.ts index 2a7485cf3..609f9566e 100644 --- a/server/tests/api/check-params/debug.ts +++ b/server/tests/api/check-params/debug.ts @@ -29,8 +29,8 @@ describe('Test debug API validators', function () { username: 'user1', password: 'my super password' } - await server.usersCommand.create({ username: user.username, password: user.password }) - userAccessToken = await server.loginCommand.getAccessToken(user) + await server.users.create({ username: user.username, password: user.password }) + userAccessToken = await server.login.getAccessToken(user) }) describe('When getting debug endpoint', function () { diff --git a/server/tests/api/check-params/follows.ts b/server/tests/api/check-params/follows.ts index 24e483448..fae3712ce 100644 --- a/server/tests/api/check-params/follows.ts +++ b/server/tests/api/check-params/follows.ts @@ -39,8 +39,8 @@ describe('Test server follows API validators', function () { password: 'password' } - await server.usersCommand.create({ username: user.username, password: user.password }) - userAccessToken = await server.loginCommand.getAccessToken(user) + await server.users.create({ username: user.username, password: user.password }) + userAccessToken = await server.login.getAccessToken(user) }) describe('When adding follows', function () { diff --git a/server/tests/api/check-params/jobs.ts b/server/tests/api/check-params/jobs.ts index 29439bebf..3786e8612 100644 --- a/server/tests/api/check-params/jobs.ts +++ b/server/tests/api/check-params/jobs.ts @@ -34,8 +34,8 @@ describe('Test jobs API validators', function () { username: 'user1', password: 'my super password' } - await server.usersCommand.create({ username: user.username, password: user.password }) - userAccessToken = await server.loginCommand.getAccessToken(user) + await server.users.create({ username: user.username, password: user.password }) + userAccessToken = await server.login.getAccessToken(user) }) describe('When listing jobs', function () { diff --git a/server/tests/api/check-params/live.ts b/server/tests/api/check-params/live.ts index 4b54fc31c..20f27dd1d 100644 --- a/server/tests/api/check-params/live.ts +++ b/server/tests/api/check-params/live.ts @@ -35,7 +35,7 @@ describe('Test video lives API validator', function () { await setAccessTokensToServers([ server ]) - await server.configCommand.updateCustomSubConfig({ + await server.config.updateCustomSubConfig({ newConfig: { live: { enabled: true, @@ -48,19 +48,19 @@ describe('Test video lives API validator', function () { const username = 'user1' const password = 'my super password' - await server.usersCommand.create({ username: username, password: password }) - userAccessToken = await server.loginCommand.getAccessToken({ username, password }) + await server.users.create({ username: username, password: password }) + userAccessToken = await server.login.getAccessToken({ username, password }) { - const { videoChannels } = await server.usersCommand.getMyInfo() + const { videoChannels } = await server.users.getMyInfo() channelId = videoChannels[0].id } { - videoIdNotLive = (await server.videosCommand.quickUpload({ name: 'not live' })).id + videoIdNotLive = (await server.videos.quickUpload({ name: 'not live' })).id } - command = server.liveCommand + command = server.live }) describe('When creating a live', function () { @@ -144,10 +144,10 @@ describe('Test video lives API validator', function () { username: 'fake', password: 'fake_password' } - await server.usersCommand.create({ username: user.username, password: user.password }) + await server.users.create({ username: user.username, password: user.password }) - const accessTokenUser = await server.loginCommand.getAccessToken(user) - const { videoChannels } = await server.usersCommand.getMyInfo({ token: accessTokenUser }) + const accessTokenUser = await server.login.getAccessToken(user) + const { videoChannels } = await server.users.getMyInfo({ token: accessTokenUser }) const customChannelId = videoChannels[0].id const fields = { ...baseCorrectParams, channelId: customChannelId } @@ -230,7 +230,7 @@ describe('Test video lives API validator', function () { }) it('Should forbid if live is disabled', async function () { - await server.configCommand.updateCustomSubConfig({ + await server.config.updateCustomSubConfig({ newConfig: { live: { enabled: false @@ -250,7 +250,7 @@ describe('Test video lives API validator', function () { it('Should forbid to save replay if not enabled by the admin', async function () { const fields = { ...baseCorrectParams, saveReplay: true } - await server.configCommand.updateCustomSubConfig({ + await server.config.updateCustomSubConfig({ newConfig: { live: { enabled: true, @@ -271,7 +271,7 @@ describe('Test video lives API validator', function () { it('Should allow to save replay if enabled by the admin', async function () { const fields = { ...baseCorrectParams, saveReplay: true } - await server.configCommand.updateCustomSubConfig({ + await server.config.updateCustomSubConfig({ newConfig: { live: { enabled: true, @@ -290,7 +290,7 @@ describe('Test video lives API validator', function () { }) it('Should not allow live if max instance lives is reached', async function () { - await server.configCommand.updateCustomSubConfig({ + await server.config.updateCustomSubConfig({ newConfig: { live: { enabled: true, @@ -309,7 +309,7 @@ describe('Test video lives API validator', function () { }) it('Should not allow live if max user lives is reached', async function () { - await server.configCommand.updateCustomSubConfig({ + await server.config.updateCustomSubConfig({ newConfig: { live: { enabled: true, @@ -401,7 +401,7 @@ describe('Test video lives API validator', function () { }) it('Should fail to update replay status if replay is not allowed on the instance', async function () { - await server.configCommand.updateCustomSubConfig({ + await server.config.updateCustomSubConfig({ newConfig: { live: { enabled: true, diff --git a/server/tests/api/check-params/logs.ts b/server/tests/api/check-params/logs.ts index 69eaad69f..cf8f77959 100644 --- a/server/tests/api/check-params/logs.ts +++ b/server/tests/api/check-params/logs.ts @@ -29,8 +29,8 @@ describe('Test logs API validators', function () { username: 'user1', password: 'my super password' } - await server.usersCommand.create({ username: user.username, password: user.password }) - userAccessToken = await server.loginCommand.getAccessToken(user) + await server.users.create({ username: user.username, password: user.password }) + userAccessToken = await server.login.getAccessToken(user) }) describe('When getting logs', function () { diff --git a/server/tests/api/check-params/plugins.ts b/server/tests/api/check-params/plugins.ts index 08fb2397f..d4b72c0f4 100644 --- a/server/tests/api/check-params/plugins.ts +++ b/server/tests/api/check-params/plugins.ts @@ -42,17 +42,17 @@ describe('Test server plugins API validators', function () { password: 'password' } - await server.usersCommand.create({ username: user.username, password: user.password }) - userAccessToken = await server.loginCommand.getAccessToken(user) + await server.users.create({ username: user.username, password: user.password }) + userAccessToken = await server.login.getAccessToken(user) { - const res = await server.pluginsCommand.install({ npmName: npmPlugin }) + const res = await server.plugins.install({ npmName: npmPlugin }) const plugin = res.body as PeerTubePlugin npmVersion = plugin.version } { - const res = await server.pluginsCommand.install({ npmName: themePlugin }) + const res = await server.plugins.install({ npmName: themePlugin }) const plugin = res.body as PeerTubePlugin themeVersion = plugin.version } diff --git a/server/tests/api/check-params/redundancy.ts b/server/tests/api/check-params/redundancy.ts index b1692b986..fca92fde4 100644 --- a/server/tests/api/check-params/redundancy.ts +++ b/server/tests/api/check-params/redundancy.ts @@ -40,16 +40,16 @@ describe('Test server redundancy API validators', function () { password: 'password' } - await servers[0].usersCommand.create({ username: user.username, password: user.password }) - userAccessToken = await servers[0].loginCommand.getAccessToken(user) + await servers[0].users.create({ username: user.username, password: user.password }) + userAccessToken = await servers[0].login.getAccessToken(user) - videoIdLocal = (await servers[0].videosCommand.quickUpload({ name: 'video' })).id + videoIdLocal = (await servers[0].videos.quickUpload({ name: 'video' })).id - const remoteUUID = (await servers[1].videosCommand.quickUpload({ name: 'video' })).uuid + const remoteUUID = (await servers[1].videos.quickUpload({ name: 'video' })).uuid await waitJobs(servers) - videoRemote = await servers[0].videosCommand.get({ id: remoteUUID }) + videoRemote = await servers[0].videos.get({ id: remoteUUID }) }) describe('When listing redundancies', function () { diff --git a/server/tests/api/check-params/search.ts b/server/tests/api/check-params/search.ts index 7973c112f..1acfa0922 100644 --- a/server/tests/api/check-params/search.ts +++ b/server/tests/api/check-params/search.ts @@ -14,7 +14,7 @@ import { } from '@shared/extra-utils' function updateSearchIndex (server: ServerInfo, enabled: boolean, disableLocalSearch = false) { - return server.configCommand.updateCustomSubConfig({ + return server.config.updateCustomSubConfig({ newConfig: { search: { searchIndex: { diff --git a/server/tests/api/check-params/services.ts b/server/tests/api/check-params/services.ts index f86712b4e..83435c24a 100644 --- a/server/tests/api/check-params/services.ts +++ b/server/tests/api/check-params/services.ts @@ -25,14 +25,14 @@ describe('Test services API validators', function () { await setAccessTokensToServers([ server ]) await setDefaultVideoChannel([ server ]) - server.video = await server.videosCommand.upload({ attributes: { name: 'my super name' } }) + server.store.video = await server.videos.upload({ attributes: { name: 'my super name' } }) { - const created = await server.playlistsCommand.create({ + const created = await server.playlists.create({ attributes: { displayName: 'super playlist', privacy: VideoPlaylistPrivacy.PUBLIC, - videoChannelId: server.videoChannel.id + videoChannelId: server.store.channel.id } }) @@ -48,7 +48,7 @@ describe('Test services API validators', function () { }) it('Should fail with an invalid host', async function () { - const embedUrl = 'http://hello.com/videos/watch/' + server.video.uuid + const embedUrl = 'http://hello.com/videos/watch/' + server.store.video.uuid await checkParamEmbed(server, embedUrl) }) @@ -63,37 +63,37 @@ describe('Test services API validators', function () { }) it('Should fail with an invalid path', async function () { - const embedUrl = `http://localhost:${server.port}/videos/watchs/${server.video.uuid}` + const embedUrl = `http://localhost:${server.port}/videos/watchs/${server.store.video.uuid}` await checkParamEmbed(server, embedUrl) }) it('Should fail with an invalid max height', async function () { - const embedUrl = `http://localhost:${server.port}/videos/watch/${server.video.uuid}` + const embedUrl = `http://localhost:${server.port}/videos/watch/${server.store.video.uuid}` await checkParamEmbed(server, embedUrl, HttpStatusCode.BAD_REQUEST_400, { maxheight: 'hello' }) }) it('Should fail with an invalid max width', async function () { - const embedUrl = `http://localhost:${server.port}/videos/watch/${server.video.uuid}` + const embedUrl = `http://localhost:${server.port}/videos/watch/${server.store.video.uuid}` await checkParamEmbed(server, embedUrl, HttpStatusCode.BAD_REQUEST_400, { maxwidth: 'hello' }) }) it('Should fail with an invalid format', async function () { - const embedUrl = `http://localhost:${server.port}/videos/watch/${server.video.uuid}` + const embedUrl = `http://localhost:${server.port}/videos/watch/${server.store.video.uuid}` await checkParamEmbed(server, embedUrl, HttpStatusCode.BAD_REQUEST_400, { format: 'blabla' }) }) it('Should fail with a non supported format', async function () { - const embedUrl = `http://localhost:${server.port}/videos/watch/${server.video.uuid}` + const embedUrl = `http://localhost:${server.port}/videos/watch/${server.store.video.uuid}` await checkParamEmbed(server, embedUrl, HttpStatusCode.NOT_IMPLEMENTED_501, { format: 'xml' }) }) it('Should succeed with the correct params with a video', async function () { - const embedUrl = `http://localhost:${server.port}/videos/watch/${server.video.uuid}` + const embedUrl = `http://localhost:${server.port}/videos/watch/${server.store.video.uuid}` const query = { format: 'json', maxheight: 400, diff --git a/server/tests/api/check-params/upload-quota.ts b/server/tests/api/check-params/upload-quota.ts index 164c581e3..4ca544790 100644 --- a/server/tests/api/check-params/upload-quota.ts +++ b/server/tests/api/check-params/upload-quota.ts @@ -29,12 +29,12 @@ describe('Test upload quota', function () { await setAccessTokensToServers([ server ]) await setDefaultVideoChannel([ server ]) - const user = await server.usersCommand.getMyInfo() + const user = await server.users.getMyInfo() rootId = user.id - await server.usersCommand.update({ userId: rootId, videoQuota: 42 }) + await server.users.update({ userId: rootId, videoQuota: 42 }) - command = server.videosCommand + command = server.videos }) describe('When having a video quota', function () { @@ -43,8 +43,8 @@ describe('Test upload quota', function () { this.timeout(30000) const user = { username: 'registered' + randomInt(1, 1500), password: 'password' } - await server.usersCommand.register(user) - const userToken = await server.loginCommand.getAccessToken(user) + await server.users.register(user) + const userToken = await server.login.getAccessToken(user) const attributes = { fixture: 'video_short2.webm' } for (let i = 0; i < 5; i++) { @@ -58,8 +58,8 @@ describe('Test upload quota', function () { this.timeout(30000) const user = { username: 'registered' + randomInt(1, 1500), password: 'password' } - await server.usersCommand.register(user) - const userToken = await server.loginCommand.getAccessToken(user) + await server.users.register(user) + const userToken = await server.login.getAccessToken(user) const attributes = { fixture: 'video_short2.webm' } for (let i = 0; i < 5; i++) { @@ -73,16 +73,16 @@ describe('Test upload quota', function () { this.timeout(120000) const baseAttributes = { - channelId: server.videoChannel.id, + channelId: server.store.channel.id, privacy: VideoPrivacy.PUBLIC } - await server.importsCommand.importVideo({ attributes: { ...baseAttributes, targetUrl: ImportsCommand.getGoodVideoUrl() } }) - await server.importsCommand.importVideo({ attributes: { ...baseAttributes, magnetUri: ImportsCommand.getMagnetURI() } }) - await server.importsCommand.importVideo({ attributes: { ...baseAttributes, torrentfile: 'video-720p.torrent' as any } }) + await server.imports.importVideo({ attributes: { ...baseAttributes, targetUrl: ImportsCommand.getGoodVideoUrl() } }) + await server.imports.importVideo({ attributes: { ...baseAttributes, magnetUri: ImportsCommand.getMagnetURI() } }) + await server.imports.importVideo({ attributes: { ...baseAttributes, torrentfile: 'video-720p.torrent' as any } }) await waitJobs([ server ]) - const { total, data: videoImports } = await server.importsCommand.getMyVideoImports() + const { total, data: videoImports } = await server.imports.getMyVideoImports() expect(total).to.equal(3) expect(videoImports).to.have.lengthOf(3) @@ -98,7 +98,7 @@ describe('Test upload quota', function () { describe('When having a daily video quota', function () { it('Should fail with a user having too many videos daily', async function () { - await server.usersCommand.update({ userId: rootId, videoQuotaDaily: 42 }) + await server.users.update({ userId: rootId, videoQuotaDaily: 42 }) await command.upload({ expectedStatus: HttpStatusCode.PAYLOAD_TOO_LARGE_413, mode: 'legacy' }) await command.upload({ expectedStatus: HttpStatusCode.PAYLOAD_TOO_LARGE_413, mode: 'resumable' }) @@ -107,7 +107,7 @@ describe('Test upload quota', function () { describe('When having an absolute and daily video quota', function () { it('Should fail if exceeding total quota', async function () { - await server.usersCommand.update({ + await server.users.update({ userId: rootId, videoQuota: 42, videoQuotaDaily: 1024 * 1024 * 1024 @@ -118,7 +118,7 @@ describe('Test upload quota', function () { }) it('Should fail if exceeding daily quota', async function () { - await server.usersCommand.update({ + await server.users.update({ userId: rootId, videoQuota: 1024 * 1024 * 1024, videoQuotaDaily: 42 diff --git a/server/tests/api/check-params/user-subscriptions.ts b/server/tests/api/check-params/user-subscriptions.ts index 8ce201d61..885ad68e4 100644 --- a/server/tests/api/check-params/user-subscriptions.ts +++ b/server/tests/api/check-params/user-subscriptions.ts @@ -38,8 +38,8 @@ describe('Test user subscriptions API validators', function () { username: 'user1', password: 'my super password' } - await server.usersCommand.create({ username: user.username, password: user.password }) - userAccessToken = await server.loginCommand.getAccessToken(user) + await server.users.create({ username: user.username, password: user.password }) + userAccessToken = await server.login.getAccessToken(user) }) describe('When listing my subscriptions', function () { diff --git a/server/tests/api/check-params/users.ts b/server/tests/api/check-params/users.ts index 33c48a009..bce3f0774 100644 --- a/server/tests/api/check-params/users.ts +++ b/server/tests/api/check-params/users.ts @@ -60,27 +60,27 @@ describe('Test users API validators', function () { { const user = { username: 'user1' } - await server.usersCommand.create({ ...user }) - userToken = await server.loginCommand.getAccessToken(user) + await server.users.create({ ...user }) + userToken = await server.login.getAccessToken(user) } { const moderator = { username: 'moderator1' } - await server.usersCommand.create({ ...moderator, role: UserRole.MODERATOR }) - moderatorToken = await server.loginCommand.getAccessToken(moderator) + await server.users.create({ ...moderator, role: UserRole.MODERATOR }) + moderatorToken = await server.login.getAccessToken(moderator) } { const moderator = { username: 'moderator2' } - await server.usersCommand.create({ ...moderator, role: UserRole.MODERATOR }) + await server.users.create({ ...moderator, role: UserRole.MODERATOR }) } { - video = await server.videosCommand.upload() + video = await server.videos.upload() } { - const { data } = await server.usersCommand.list() + const { data } = await server.users.list() userId = data.find(u => u.username === 'user1').id rootId = data.find(u => u.username === 'root').id moderatorId = data.find(u => u.username === 'moderator2').id @@ -341,7 +341,7 @@ describe('Test users API validators', function () { it('Should fail with a non admin user', async function () { const user = { username: 'user1' } - userToken = await server.loginCommand.getAccessToken(user) + userToken = await server.login.getAccessToken(user) const fields = { username: 'user3', @@ -596,28 +596,28 @@ describe('Test users API validators', function () { describe('When managing my scoped tokens', function () { it('Should fail to get my scoped tokens with an non authenticated user', async function () { - await server.usersCommand.getMyScopedTokens({ token: null, expectedStatus: HttpStatusCode.UNAUTHORIZED_401 }) + await server.users.getMyScopedTokens({ token: null, expectedStatus: HttpStatusCode.UNAUTHORIZED_401 }) }) it('Should fail to get my scoped tokens with a bad token', async function () { - await server.usersCommand.getMyScopedTokens({ token: 'bad', expectedStatus: HttpStatusCode.UNAUTHORIZED_401 }) + await server.users.getMyScopedTokens({ token: 'bad', expectedStatus: HttpStatusCode.UNAUTHORIZED_401 }) }) it('Should succeed to get my scoped tokens', async function () { - await server.usersCommand.getMyScopedTokens() + await server.users.getMyScopedTokens() }) it('Should fail to renew my scoped tokens with an non authenticated user', async function () { - await server.usersCommand.renewMyScopedTokens({ token: null, expectedStatus: HttpStatusCode.UNAUTHORIZED_401 }) + await server.users.renewMyScopedTokens({ token: null, expectedStatus: HttpStatusCode.UNAUTHORIZED_401 }) }) it('Should fail to renew my scoped tokens with a bad token', async function () { - await server.usersCommand.renewMyScopedTokens({ token: 'bad', expectedStatus: HttpStatusCode.UNAUTHORIZED_401 }) + await server.users.renewMyScopedTokens({ token: 'bad', expectedStatus: HttpStatusCode.UNAUTHORIZED_401 }) }) it('Should succeed to renew my scoped tokens', async function () { - await server.usersCommand.renewMyScopedTokens() + await server.users.renewMyScopedTokens() }) }) @@ -769,11 +769,11 @@ describe('Test users API validators', function () { describe('When getting my information', function () { it('Should fail with a non authenticated user', async function () { - await server.usersCommand.getMyInfo({ token: 'fake_token', expectedStatus: HttpStatusCode.UNAUTHORIZED_401 }) + await server.users.getMyInfo({ token: 'fake_token', expectedStatus: HttpStatusCode.UNAUTHORIZED_401 }) }) it('Should success with the correct parameters', async function () { - await server.usersCommand.getMyInfo({ token: userToken }) + await server.users.getMyInfo({ token: userToken }) }) }) @@ -781,7 +781,7 @@ describe('Test users API validators', function () { let command: UsersCommand before(function () { - command = server.usersCommand + command = server.users }) it('Should fail with a non authenticated user', async function () { @@ -846,54 +846,54 @@ describe('Test users API validators', function () { it('Should fail with an incorrect id', async function () { const options = { userId: 'blabla' as any, expectedStatus: HttpStatusCode.BAD_REQUEST_400 } - await server.usersCommand.remove(options) - await server.usersCommand.banUser({ userId: 'blabla' as any, expectedStatus: HttpStatusCode.BAD_REQUEST_400 }) - await server.usersCommand.unbanUser({ userId: 'blabla' as any, expectedStatus: HttpStatusCode.BAD_REQUEST_400 }) + await server.users.remove(options) + await server.users.banUser({ userId: 'blabla' as any, expectedStatus: HttpStatusCode.BAD_REQUEST_400 }) + await server.users.unbanUser({ userId: 'blabla' as any, expectedStatus: HttpStatusCode.BAD_REQUEST_400 }) }) it('Should fail with the root user', async function () { const options = { userId: rootId, expectedStatus: HttpStatusCode.BAD_REQUEST_400 } - await server.usersCommand.remove(options) - await server.usersCommand.banUser(options) - await server.usersCommand.unbanUser(options) + await server.users.remove(options) + await server.users.banUser(options) + await server.users.unbanUser(options) }) it('Should return 404 with a non existing id', async function () { const options = { userId: 4545454, expectedStatus: HttpStatusCode.NOT_FOUND_404 } - await server.usersCommand.remove(options) - await server.usersCommand.banUser(options) - await server.usersCommand.unbanUser(options) + await server.users.remove(options) + await server.users.banUser(options) + await server.users.unbanUser(options) }) it('Should fail with a non admin user', async function () { const options = { userId, token: userToken, expectedStatus: HttpStatusCode.FORBIDDEN_403 } - await server.usersCommand.remove(options) - await server.usersCommand.banUser(options) - await server.usersCommand.unbanUser(options) + await server.users.remove(options) + await server.users.banUser(options) + await server.users.unbanUser(options) }) it('Should fail on a moderator with a moderator', async function () { const options = { userId: moderatorId, token: moderatorToken, expectedStatus: HttpStatusCode.FORBIDDEN_403 } - await server.usersCommand.remove(options) - await server.usersCommand.banUser(options) - await server.usersCommand.unbanUser(options) + await server.users.remove(options) + await server.users.banUser(options) + await server.users.unbanUser(options) }) it('Should succeed on a user with a moderator', async function () { const options = { userId, token: moderatorToken } - await server.usersCommand.banUser(options) - await server.usersCommand.unbanUser(options) + await server.users.banUser(options) + await server.users.unbanUser(options) }) }) describe('When deleting our account', function () { it('Should fail with with the root account', async function () { - await server.usersCommand.deleteMe({ expectedStatus: HttpStatusCode.BAD_REQUEST_400 }) + await server.users.deleteMe({ expectedStatus: HttpStatusCode.BAD_REQUEST_400 }) }) }) @@ -1011,7 +1011,7 @@ describe('Test users API validators', function () { it('Should fail with an existing channel', async function () { const attributes = { name: 'existing_channel', displayName: 'hello', description: 'super description' } - await server.channelsCommand.create({ attributes }) + await server.channels.create({ attributes }) const fields = { ...baseCorrectParams, channel: { name: 'existing_channel', displayName: 'toto' } } @@ -1055,7 +1055,7 @@ describe('Test users API validators', function () { describe('When registering multiple users on a server with users limit', function () { it('Should fail when after 3 registrations', async function () { - await server.usersCommand.register({ username: 'user42', expectedStatus: HttpStatusCode.FORBIDDEN_403 }) + await server.users.register({ username: 'user42', expectedStatus: HttpStatusCode.FORBIDDEN_403 }) }) }) diff --git a/server/tests/api/check-params/video-blacklist.ts b/server/tests/api/check-params/video-blacklist.ts index 0fda31b29..51609b982 100644 --- a/server/tests/api/check-params/video-blacklist.ts +++ b/server/tests/api/check-params/video-blacklist.ts @@ -40,41 +40,41 @@ describe('Test video blacklist API validators', function () { { const username = 'user1' const password = 'my super password' - await servers[0].usersCommand.create({ username: username, password: password }) - userAccessToken1 = await servers[0].loginCommand.getAccessToken({ username, password }) + await servers[0].users.create({ username: username, password: password }) + userAccessToken1 = await servers[0].login.getAccessToken({ username, password }) } { const username = 'user2' const password = 'my super password' - await servers[0].usersCommand.create({ username: username, password: password }) - userAccessToken2 = await servers[0].loginCommand.getAccessToken({ username, password }) + await servers[0].users.create({ username: username, password: password }) + userAccessToken2 = await servers[0].login.getAccessToken({ username, password }) } { - servers[0].video = await servers[0].videosCommand.upload({ token: userAccessToken1 }) + servers[0].store.video = await servers[0].videos.upload({ token: userAccessToken1 }) } { - const { uuid } = await servers[0].videosCommand.upload() + const { uuid } = await servers[0].videos.upload() notBlacklistedVideoId = uuid } { - const { uuid } = await servers[1].videosCommand.upload() + const { uuid } = await servers[1].videos.upload() remoteVideoUUID = uuid } await waitJobs(servers) - command = servers[0].blacklistCommand + command = servers[0].blacklist }) describe('When adding a video in blacklist', function () { const basePath = '/api/v1/videos/' it('Should fail with nothing', async function () { - const path = basePath + servers[0].video + '/blacklist' + const path = basePath + servers[0].store.video + '/blacklist' const fields = {} await makePostBodyRequest({ url: servers[0].url, path, token: servers[0].accessToken, fields }) }) @@ -86,13 +86,13 @@ describe('Test video blacklist API validators', function () { }) it('Should fail with a non authenticated user', async function () { - const path = basePath + servers[0].video + '/blacklist' + const path = basePath + servers[0].store.video + '/blacklist' const fields = {} await makePostBodyRequest({ url: servers[0].url, path, token: 'hello', fields, statusCodeExpected: HttpStatusCode.UNAUTHORIZED_401 }) }) it('Should fail with a non admin user', async function () { - const path = basePath + servers[0].video + '/blacklist' + const path = basePath + servers[0].store.video + '/blacklist' const fields = {} await makePostBodyRequest({ url: servers[0].url, @@ -104,7 +104,7 @@ describe('Test video blacklist API validators', function () { }) it('Should fail with an invalid reason', async function () { - const path = basePath + servers[0].video.uuid + '/blacklist' + const path = basePath + servers[0].store.video.uuid + '/blacklist' const fields = { reason: 'a'.repeat(305) } await makePostBodyRequest({ url: servers[0].url, path, token: servers[0].accessToken, fields }) @@ -124,7 +124,7 @@ describe('Test video blacklist API validators', function () { }) it('Should succeed with the correct params', async function () { - const path = basePath + servers[0].video.uuid + '/blacklist' + const path = basePath + servers[0].store.video.uuid + '/blacklist' const fields = {} await makePostBodyRequest({ @@ -159,13 +159,13 @@ describe('Test video blacklist API validators', function () { }) it('Should fail with a non authenticated user', async function () { - const path = basePath + servers[0].video + '/blacklist' + const path = basePath + servers[0].store.video + '/blacklist' const fields = {} await makePutBodyRequest({ url: servers[0].url, path, token: 'hello', fields, statusCodeExpected: HttpStatusCode.UNAUTHORIZED_401 }) }) it('Should fail with a non admin user', async function () { - const path = basePath + servers[0].video + '/blacklist' + const path = basePath + servers[0].store.video + '/blacklist' const fields = {} await makePutBodyRequest({ url: servers[0].url, @@ -177,14 +177,14 @@ describe('Test video blacklist API validators', function () { }) it('Should fail with an invalid reason', async function () { - const path = basePath + servers[0].video.uuid + '/blacklist' + const path = basePath + servers[0].store.video.uuid + '/blacklist' const fields = { reason: 'a'.repeat(305) } await makePutBodyRequest({ url: servers[0].url, path, token: servers[0].accessToken, fields }) }) it('Should succeed with the correct params', async function () { - const path = basePath + servers[0].video.shortUUID + '/blacklist' + const path = basePath + servers[0].store.video.shortUUID + '/blacklist' const fields = { reason: 'hello' } await makePutBodyRequest({ @@ -200,27 +200,27 @@ describe('Test video blacklist API validators', function () { describe('When getting blacklisted video', function () { it('Should fail with a non authenticated user', async function () { - await servers[0].videosCommand.get({ id: servers[0].video.uuid, expectedStatus: HttpStatusCode.UNAUTHORIZED_401 }) + await servers[0].videos.get({ id: servers[0].store.video.uuid, expectedStatus: HttpStatusCode.UNAUTHORIZED_401 }) }) it('Should fail with another user', async function () { - await servers[0].videosCommand.getWithToken({ + await servers[0].videos.getWithToken({ token: userAccessToken2, - id: servers[0].video.uuid, + id: servers[0].store.video.uuid, expectedStatus: HttpStatusCode.FORBIDDEN_403 }) }) it('Should succeed with the owner authenticated user', async function () { - const video = await servers[0].videosCommand.getWithToken({ token: userAccessToken1, id: servers[0].video.uuid }) + const video = await servers[0].videos.getWithToken({ token: userAccessToken1, id: servers[0].store.video.uuid }) expect(video.blacklisted).to.be.true }) it('Should succeed with an admin', async function () { - const video = servers[0].video + const video = servers[0].store.video for (const id of [ video.id, video.uuid, video.shortUUID ]) { - const video = await servers[0].videosCommand.getWithToken({ id, expectedStatus: HttpStatusCode.OK_200 }) + const video = await servers[0].videos.getWithToken({ id, expectedStatus: HttpStatusCode.OK_200 }) expect(video.blacklisted).to.be.true } }) @@ -229,11 +229,11 @@ describe('Test video blacklist API validators', function () { describe('When removing a video in blacklist', function () { it('Should fail with a non authenticated user', async function () { - await command.remove({ token: 'fake token', videoId: servers[0].video.uuid, expectedStatus: HttpStatusCode.UNAUTHORIZED_401 }) + await command.remove({ token: 'fake token', videoId: servers[0].store.video.uuid, expectedStatus: HttpStatusCode.UNAUTHORIZED_401 }) }) it('Should fail with a non admin user', async function () { - await command.remove({ token: userAccessToken2, videoId: servers[0].video.uuid, expectedStatus: HttpStatusCode.FORBIDDEN_403 }) + await command.remove({ token: userAccessToken2, videoId: servers[0].store.video.uuid, expectedStatus: HttpStatusCode.FORBIDDEN_403 }) }) it('Should fail with an incorrect id', async function () { @@ -246,7 +246,7 @@ describe('Test video blacklist API validators', function () { }) it('Should succeed with the correct params', async function () { - await command.remove({ videoId: servers[0].video.uuid, expectedStatus: HttpStatusCode.NO_CONTENT_204 }) + await command.remove({ videoId: servers[0].store.video.uuid, expectedStatus: HttpStatusCode.NO_CONTENT_204 }) }) }) @@ -254,11 +254,11 @@ describe('Test video blacklist API validators', function () { const basePath = '/api/v1/videos/blacklist/' it('Should fail with a non authenticated user', async function () { - await servers[0].blacklistCommand.list({ token: 'fake token', expectedStatus: HttpStatusCode.UNAUTHORIZED_401 }) + await servers[0].blacklist.list({ token: 'fake token', expectedStatus: HttpStatusCode.UNAUTHORIZED_401 }) }) it('Should fail with a non admin user', async function () { - await servers[0].blacklistCommand.list({ token: userAccessToken2, expectedStatus: HttpStatusCode.FORBIDDEN_403 }) + await servers[0].blacklist.list({ token: userAccessToken2, expectedStatus: HttpStatusCode.FORBIDDEN_403 }) }) it('Should fail with a bad start pagination', async function () { @@ -274,11 +274,11 @@ describe('Test video blacklist API validators', function () { }) it('Should fail with an invalid type', async function () { - await servers[0].blacklistCommand.list({ type: 0, expectedStatus: HttpStatusCode.BAD_REQUEST_400 }) + await servers[0].blacklist.list({ type: 0, expectedStatus: HttpStatusCode.BAD_REQUEST_400 }) }) it('Should succeed with the correct parameters', async function () { - await servers[0].blacklistCommand.list({ type: VideoBlacklistType.MANUAL }) + await servers[0].blacklist.list({ type: VideoBlacklistType.MANUAL }) }) }) diff --git a/server/tests/api/check-params/video-captions.ts b/server/tests/api/check-params/video-captions.ts index f3941b3fa..913f894b9 100644 --- a/server/tests/api/check-params/video-captions.ts +++ b/server/tests/api/check-params/video-captions.ts @@ -30,15 +30,15 @@ describe('Test video captions API validator', function () { await setAccessTokensToServers([ server ]) - video = await server.videosCommand.upload() + video = await server.videos.upload() { const user = { username: 'user1', password: 'my super password' } - await server.usersCommand.create({ username: user.username, password: user.password }) - userAccessToken = await server.loginCommand.getAccessToken(user) + await server.users.create({ username: user.username, password: user.password }) + userAccessToken = await server.login.getAccessToken(user) } }) @@ -152,7 +152,7 @@ describe('Test video captions API validator', function () { // }) it('Should succeed with a valid captionfile extension and octet-stream mime type', async function () { - await server.captionsCommand.createVideoCaption({ + await server.captions.createVideoCaption({ language: 'zh', videoId: video.uuid, fixture: 'subtitle-good.srt', diff --git a/server/tests/api/check-params/video-channels.ts b/server/tests/api/check-params/video-channels.ts index 2b4c17ea1..8e6e32f20 100644 --- a/server/tests/api/check-params/video-channels.ts +++ b/server/tests/api/check-params/video-channels.ts @@ -44,11 +44,11 @@ describe('Test video channels API validator', function () { } { - await server.usersCommand.create({ username: user.username, password: user.password }) - accessTokenUser = await server.loginCommand.getAccessToken(user) + await server.users.create({ username: user.username, password: user.password }) + accessTokenUser = await server.login.getAccessToken(user) } - command = server.channelsCommand + command = server.channels }) describe('When listing a video channels', function () { @@ -81,7 +81,7 @@ describe('Test video channels API validator', function () { }) it('Should fail with a unknown account', async function () { - await server.channelsCommand.listByAccount({ accountName: 'unknown', expectedStatus: HttpStatusCode.NOT_FOUND_404 }) + await server.channels.listByAccount({ accountName: 'unknown', expectedStatus: HttpStatusCode.NOT_FOUND_404 }) }) it('Should succeed with the correct parameters', async function () { diff --git a/server/tests/api/check-params/video-comments.ts b/server/tests/api/check-params/video-comments.ts index bdf7f91ee..44af9d7e3 100644 --- a/server/tests/api/check-params/video-comments.ts +++ b/server/tests/api/check-params/video-comments.ts @@ -38,26 +38,26 @@ describe('Test video comments API validator', function () { await setAccessTokensToServers([ server ]) { - const video = await server.videosCommand.upload({ attributes: {} }) + const video = await server.videos.upload({ attributes: {} }) pathThread = '/api/v1/videos/' + video.uuid + '/comment-threads' } { - const created = await server.commentsCommand.createThread({ videoId: video.uuid, text: 'coucou' }) + const created = await server.comments.createThread({ videoId: video.uuid, text: 'coucou' }) commentId = created.id pathComment = '/api/v1/videos/' + video.uuid + '/comments/' + commentId } { const user = { username: 'user1', password: 'my super password' } - await server.usersCommand.create({ username: user.username, password: user.password }) - userAccessToken = await server.loginCommand.getAccessToken(user) + await server.users.create({ username: user.username, password: user.password }) + userAccessToken = await server.login.getAccessToken(user) } { const user = { username: 'user2', password: 'my super password' } - await server.usersCommand.create({ username: user.username, password: user.password }) - userAccessToken2 = await server.loginCommand.getAccessToken(user) + await server.users.create({ username: user.username, password: user.password }) + userAccessToken2 = await server.login.getAccessToken(user) } }) @@ -274,7 +274,7 @@ describe('Test video comments API validator', function () { let commentToDelete: number { - const created = await server.commentsCommand.createThread({ videoId: video.uuid, token: userAccessToken, text: 'hello' }) + const created = await server.comments.createThread({ videoId: video.uuid, token: userAccessToken, text: 'hello' }) commentToDelete = created.id } @@ -289,12 +289,12 @@ describe('Test video comments API validator', function () { let anotherVideoUUID: string { - const { uuid } = await server.videosCommand.upload({ token: userAccessToken, attributes: { name: 'video' } }) + const { uuid } = await server.videos.upload({ token: userAccessToken, attributes: { name: 'video' } }) anotherVideoUUID = uuid } { - const created = await server.commentsCommand.createThread({ videoId: anotherVideoUUID, text: 'hello' }) + const created = await server.comments.createThread({ videoId: anotherVideoUUID, text: 'hello' }) commentToDelete = created.id } @@ -316,7 +316,7 @@ describe('Test video comments API validator', function () { describe('When a video has comments disabled', function () { before(async function () { - video = await server.videosCommand.upload({ attributes: { commentsEnabled: false } }) + video = await server.videos.upload({ attributes: { commentsEnabled: false } }) pathThread = '/api/v1/videos/' + video.uuid + '/comment-threads' }) diff --git a/server/tests/api/check-params/video-imports.ts b/server/tests/api/check-params/video-imports.ts index d09e473de..1a6b6075f 100644 --- a/server/tests/api/check-params/video-imports.ts +++ b/server/tests/api/check-params/video-imports.ts @@ -36,11 +36,11 @@ describe('Test video imports API validator', function () { const username = 'user1' const password = 'my super password' - await server.usersCommand.create({ username: username, password: password }) - userAccessToken = await server.loginCommand.getAccessToken({ username, password }) + await server.users.create({ username: username, password: password }) + userAccessToken = await server.login.getAccessToken({ username, password }) { - const { videoChannels } = await server.usersCommand.getMyInfo() + const { videoChannels } = await server.users.getMyInfo() channelId = videoChannels[0].id } }) @@ -162,10 +162,10 @@ describe('Test video imports API validator', function () { username: 'fake', password: 'fake_password' } - await server.usersCommand.create({ username: user.username, password: user.password }) + await server.users.create({ username: user.username, password: user.password }) - const accessTokenUser = await server.loginCommand.getAccessToken(user) - const { videoChannels } = await server.usersCommand.getMyInfo({ token: accessTokenUser }) + const accessTokenUser = await server.login.getAccessToken(user) + const { videoChannels } = await server.users.getMyInfo({ token: accessTokenUser }) const customChannelId = videoChannels[0].id const fields = { ...baseCorrectParams, channelId: customChannelId } @@ -256,7 +256,7 @@ describe('Test video imports API validator', function () { }) it('Should forbid to import http videos', async function () { - await server.configCommand.updateCustomSubConfig({ + await server.config.updateCustomSubConfig({ newConfig: { import: { videos: { @@ -281,7 +281,7 @@ describe('Test video imports API validator', function () { }) it('Should forbid to import torrent videos', async function () { - await server.configCommand.updateCustomSubConfig({ + await server.config.updateCustomSubConfig({ newConfig: { import: { videos: { diff --git a/server/tests/api/check-params/video-playlists.ts b/server/tests/api/check-params/video-playlists.ts index ebd7e2413..e0e42ebb0 100644 --- a/server/tests/api/check-params/video-playlists.ts +++ b/server/tests/api/check-params/video-playlists.ts @@ -47,10 +47,10 @@ describe('Test video playlists API validator', function () { await setAccessTokensToServers([ server ]) await setDefaultVideoChannel([ server ]) - userAccessToken = await server.usersCommand.generateUserAndToken('user1') - videoId = (await server.videosCommand.quickUpload({ name: 'video 1' })).id + userAccessToken = await server.users.generateUserAndToken('user1') + videoId = (await server.videos.quickUpload({ name: 'video 1' })).id - command = server.playlistsCommand + command = server.playlists { const { data } = await command.listByAccount({ @@ -68,7 +68,7 @@ describe('Test video playlists API validator', function () { attributes: { displayName: 'super playlist', privacy: VideoPlaylistPrivacy.PUBLIC, - videoChannelId: server.videoChannel.id + videoChannelId: server.store.channel.id } }) } @@ -176,7 +176,7 @@ describe('Test video playlists API validator', function () { const playlist = await command.create({ attributes: { displayName: 'super playlist', - videoChannelId: server.videoChannel.id, + videoChannelId: server.store.channel.id, privacy: VideoPlaylistPrivacy.UNLISTED } }) @@ -200,7 +200,7 @@ describe('Test video playlists API validator', function () { displayName: 'display name', privacy: VideoPlaylistPrivacy.UNLISTED, thumbnailfile: 'thumbnail.jpg', - videoChannelId: server.videoChannel.id, + videoChannelId: server.store.channel.id, ...attributes }, @@ -485,8 +485,8 @@ describe('Test video playlists API validator', function () { } before(async function () { - videoId3 = (await server.videosCommand.quickUpload({ name: 'video 3' })).id - videoId4 = (await server.videosCommand.quickUpload({ name: 'video 4' })).id + videoId3 = (await server.videos.quickUpload({ name: 'video 3' })).id + videoId4 = (await server.videos.quickUpload({ name: 'video 4' })).id for (const id of [ videoId3, videoId4 ]) { await command.addElement({ playlistId: playlist.shortUUID, attributes: { videoId: id } }) diff --git a/server/tests/api/check-params/videos-filter.ts b/server/tests/api/check-params/videos-filter.ts index d7bf081d4..cbfdef1db 100644 --- a/server/tests/api/check-params/videos-filter.ts +++ b/server/tests/api/check-params/videos-filter.ts @@ -49,13 +49,13 @@ describe('Test video filters validators', function () { await setDefaultVideoChannel([ server ]) const user = { username: 'user1', password: 'my super password' } - await server.usersCommand.create({ username: user.username, password: user.password }) - userAccessToken = await server.loginCommand.getAccessToken(user) + await server.users.create({ username: user.username, password: user.password }) + userAccessToken = await server.login.getAccessToken(user) const moderator = { username: 'moderator', password: 'my super password' } - await server.usersCommand.create({ username: moderator.username, password: moderator.password, role: UserRole.MODERATOR }) + await server.users.create({ username: moderator.username, password: moderator.password, role: UserRole.MODERATOR }) - moderatorAccessToken = await server.loginCommand.getAccessToken(moderator) + moderatorAccessToken = await server.login.getAccessToken(moderator) }) describe('When setting a video filter', function () { diff --git a/server/tests/api/check-params/videos-history.ts b/server/tests/api/check-params/videos-history.ts index 1da922a17..549c9fa1f 100644 --- a/server/tests/api/check-params/videos-history.ts +++ b/server/tests/api/check-params/videos-history.ts @@ -29,7 +29,7 @@ describe('Test videos history API validator', function () { await setAccessTokensToServers([ server ]) - const { uuid } = await server.videosCommand.upload() + const { uuid } = await server.videos.upload() watchingPath = '/api/v1/videos/' + uuid + '/watching' }) diff --git a/server/tests/api/check-params/videos-overviews.ts b/server/tests/api/check-params/videos-overviews.ts index 44a936c9f..3597c81d3 100644 --- a/server/tests/api/check-params/videos-overviews.ts +++ b/server/tests/api/check-params/videos-overviews.ts @@ -17,12 +17,12 @@ describe('Test videos overview', function () { describe('When getting videos overview', function () { it('Should fail with a bad pagination', async function () { - await server.overviewsCommand.getVideos({ page: 0, expectedStatus: 400 }) - await server.overviewsCommand.getVideos({ page: 100, expectedStatus: 400 }) + await server.overviews.getVideos({ page: 0, expectedStatus: 400 }) + await server.overviews.getVideos({ page: 100, expectedStatus: 400 }) }) it('Should succeed with a good pagination', async function () { - await server.overviewsCommand.getVideos({ page: 1 }) + await server.overviews.getVideos({ page: 1 }) }) }) diff --git a/server/tests/api/check-params/videos.ts b/server/tests/api/check-params/videos.ts index 8f9f33b8c..69bdae7cf 100644 --- a/server/tests/api/check-params/videos.ts +++ b/server/tests/api/check-params/videos.ts @@ -44,11 +44,11 @@ describe('Test videos API validator', function () { const username = 'user1' const password = 'my super password' - await server.usersCommand.create({ username: username, password: password }) - userAccessToken = await server.loginCommand.getAccessToken({ username, password }) + await server.users.create({ username: username, password: password }) + userAccessToken = await server.login.getAccessToken({ username, password }) { - const body = await server.usersCommand.getMyInfo() + const body = await server.users.getMyInfo() channelId = body.videoChannels[0].id channelName = body.videoChannels[0].name accountName = body.account.name + '@' + body.account.host @@ -274,10 +274,10 @@ describe('Test videos API validator', function () { username: 'fake' + randomInt(0, 1500), password: 'fake_password' } - await server.usersCommand.create({ username: user.username, password: user.password }) + await server.users.create({ username: user.username, password: user.password }) - const accessTokenUser = await server.loginCommand.getAccessToken(user) - const { videoChannels } = await server.usersCommand.getMyInfo({ token: accessTokenUser }) + const accessTokenUser = await server.login.getAccessToken(user) + const { videoChannels } = await server.users.getMyInfo({ token: accessTokenUser }) const customChannelId = videoChannels[0].id const fields = { ...baseCorrectParams, channelId: customChannelId } @@ -484,7 +484,7 @@ describe('Test videos API validator', function () { } before(async function () { - const { data } = await server.videosCommand.list() + const { data } = await server.videos.list() video = data[0] }) @@ -710,15 +710,15 @@ describe('Test videos API validator', function () { }) it('Should fail without a correct uuid', async function () { - await server.videosCommand.get({ id: 'coucou', expectedStatus: HttpStatusCode.BAD_REQUEST_400 }) + await server.videos.get({ id: 'coucou', expectedStatus: HttpStatusCode.BAD_REQUEST_400 }) }) it('Should return 404 with an incorrect video', async function () { - await server.videosCommand.get({ id: '4da6fde3-88f7-4d16-b119-108df5630b06', expectedStatus: HttpStatusCode.NOT_FOUND_404 }) + await server.videos.get({ id: '4da6fde3-88f7-4d16-b119-108df5630b06', expectedStatus: HttpStatusCode.NOT_FOUND_404 }) }) it('Shoud report the appropriate error', async function () { - const body = await server.videosCommand.get({ id: 'hi', expectedStatus: HttpStatusCode.BAD_REQUEST_400 }) + const body = await server.videos.get({ id: 'hi', expectedStatus: HttpStatusCode.BAD_REQUEST_400 }) const error = body as unknown as PeerTubeProblemDocument expect(error.docs).to.equal('https://docs.joinpeertube.org/api-rest-reference.html#operation/getVideo') @@ -734,7 +734,7 @@ describe('Test videos API validator', function () { }) it('Should succeed with the correct parameters', async function () { - await server.videosCommand.get({ id: video.shortUUID }) + await server.videos.get({ id: video.shortUUID }) }) }) @@ -742,7 +742,7 @@ describe('Test videos API validator', function () { let videoId: number before(async function () { - const { data } = await server.videosCommand.list() + const { data } = await server.videos.list() videoId = data[0].id }) @@ -797,21 +797,21 @@ describe('Test videos API validator', function () { }) it('Should fail without a correct uuid', async function () { - await server.videosCommand.remove({ id: 'hello', expectedStatus: HttpStatusCode.BAD_REQUEST_400 }) + await server.videos.remove({ id: 'hello', expectedStatus: HttpStatusCode.BAD_REQUEST_400 }) }) it('Should fail with a video which does not exist', async function () { - await server.videosCommand.remove({ id: '4da6fde3-88f7-4d16-b119-108df5630b06', expectedStatus: HttpStatusCode.NOT_FOUND_404 }) + await server.videos.remove({ id: '4da6fde3-88f7-4d16-b119-108df5630b06', expectedStatus: HttpStatusCode.NOT_FOUND_404 }) }) it('Should fail with a video of another user without the appropriate right', async function () { - await server.videosCommand.remove({ token: userAccessToken, id: video.uuid, expectedStatus: HttpStatusCode.FORBIDDEN_403 }) + await server.videos.remove({ token: userAccessToken, id: video.uuid, expectedStatus: HttpStatusCode.FORBIDDEN_403 }) }) it('Should fail with a video of another server') it('Shoud report the appropriate error', async function () { - const body = await server.videosCommand.remove({ id: 'hello', expectedStatus: HttpStatusCode.BAD_REQUEST_400 }) + const body = await server.videos.remove({ id: 'hello', expectedStatus: HttpStatusCode.BAD_REQUEST_400 }) const error = body as unknown as PeerTubeProblemDocument expect(error.docs).to.equal('https://docs.joinpeertube.org/api-rest-reference.html#operation/delVideo') @@ -827,7 +827,7 @@ describe('Test videos API validator', function () { }) it('Should succeed with the correct parameters', async function () { - await server.videosCommand.remove({ id: video.uuid }) + await server.videos.remove({ id: video.uuid }) }) }) -- cgit v1.2.3 From 254d3579f5338f5fd775c17d15cdfc37078bcfb4 Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Fri, 16 Jul 2021 09:47:51 +0200 Subject: Use an object to represent a server --- server/tests/api/check-params/abuses.ts | 12 ++++++------ server/tests/api/check-params/accounts.ts | 8 ++++---- server/tests/api/check-params/blocklist.ts | 10 +++++----- server/tests/api/check-params/bulk.ts | 8 ++++---- server/tests/api/check-params/config.ts | 8 ++++---- server/tests/api/check-params/contact-form.ts | 10 +++++----- server/tests/api/check-params/custom-pages.ts | 8 ++++---- server/tests/api/check-params/debug.ts | 8 ++++---- server/tests/api/check-params/follows.ts | 8 ++++---- server/tests/api/check-params/jobs.ts | 8 ++++---- server/tests/api/check-params/live.ts | 8 ++++---- server/tests/api/check-params/logs.ts | 8 ++++---- server/tests/api/check-params/plugins.ts | 8 ++++---- server/tests/api/check-params/redundancy.ts | 8 ++++---- server/tests/api/check-params/search.ts | 10 +++++----- server/tests/api/check-params/services.ts | 10 +++++----- server/tests/api/check-params/upload-quota.ts | 8 ++++---- server/tests/api/check-params/user-notifications.ts | 8 ++++---- server/tests/api/check-params/user-subscriptions.ts | 8 ++++---- server/tests/api/check-params/users.ts | 15 +++++++-------- server/tests/api/check-params/video-blacklist.ts | 8 ++++---- server/tests/api/check-params/video-captions.ts | 8 ++++---- server/tests/api/check-params/video-channels.ts | 8 ++++---- server/tests/api/check-params/video-comments.ts | 8 ++++---- server/tests/api/check-params/video-imports.ts | 8 ++++---- server/tests/api/check-params/video-playlists.ts | 8 ++++---- server/tests/api/check-params/videos-filter.ts | 10 +++++----- server/tests/api/check-params/videos-history.ts | 8 ++++---- server/tests/api/check-params/videos-overviews.ts | 6 +++--- server/tests/api/check-params/videos.ts | 8 ++++---- 30 files changed, 129 insertions(+), 130 deletions(-) (limited to 'server/tests/api/check-params') diff --git a/server/tests/api/check-params/abuses.ts b/server/tests/api/check-params/abuses.ts index 7a6790ba8..62811f932 100644 --- a/server/tests/api/check-params/abuses.ts +++ b/server/tests/api/check-params/abuses.ts @@ -9,10 +9,10 @@ import { checkBadStartPagination, cleanupTests, doubleFollow, - flushAndRunServer, + createSingleServer, makeGetRequest, makePostBodyRequest, - ServerInfo, + PeerTubeServer, setAccessTokensToServers, waitJobs } from '@shared/extra-utils' @@ -21,7 +21,7 @@ import { AbuseCreate, AbuseState } from '@shared/models' describe('Test abuses API validators', function () { const basePath = '/api/v1/abuses/' - let server: ServerInfo + let server: PeerTubeServer let userToken = '' let userToken2 = '' @@ -35,7 +35,7 @@ describe('Test abuses API validators', function () { before(async function () { this.timeout(30000) - server = await flushAndRunServer(1) + server = await createSingleServer(1) await setAccessTokensToServers([ server ]) @@ -404,12 +404,12 @@ describe('Test abuses API validators', function () { describe('When trying to manage messages of a remote abuse', function () { let remoteAbuseId: number - let anotherServer: ServerInfo + let anotherServer: PeerTubeServer before(async function () { this.timeout(50000) - anotherServer = await flushAndRunServer(2) + anotherServer = await createSingleServer(2) await setAccessTokensToServers([ anotherServer ]) await doubleFollow(anotherServer, server) diff --git a/server/tests/api/check-params/accounts.ts b/server/tests/api/check-params/accounts.ts index 223322626..e866593db 100644 --- a/server/tests/api/check-params/accounts.ts +++ b/server/tests/api/check-params/accounts.ts @@ -7,20 +7,20 @@ import { checkBadSortPagination, checkBadStartPagination, cleanupTests, - flushAndRunServer, - ServerInfo + createSingleServer, + PeerTubeServer } from '@shared/extra-utils' describe('Test accounts API validators', function () { const path = '/api/v1/accounts/' - let server: ServerInfo + let server: PeerTubeServer // --------------------------------------------------------------- before(async function () { this.timeout(30000) - server = await flushAndRunServer(1) + server = await createSingleServer(1) }) describe('When listing accounts', function () { diff --git a/server/tests/api/check-params/blocklist.ts b/server/tests/api/check-params/blocklist.ts index 14e45e503..b2a1cc4e2 100644 --- a/server/tests/api/check-params/blocklist.ts +++ b/server/tests/api/check-params/blocklist.ts @@ -5,11 +5,11 @@ import 'mocha' import { cleanupTests, doubleFollow, - flushAndRunMultipleServers, + createMultipleServers, makeDeleteRequest, makeGetRequest, makePostBodyRequest, - ServerInfo, + PeerTubeServer, setAccessTokensToServers } from '../../../../shared/extra-utils' import { @@ -20,14 +20,14 @@ import { import { HttpStatusCode } from '../../../../shared/core-utils/miscs/http-error-codes' describe('Test blocklist API validators', function () { - let servers: ServerInfo[] - let server: ServerInfo + let servers: PeerTubeServer[] + let server: PeerTubeServer let userAccessToken: string before(async function () { this.timeout(60000) - servers = await flushAndRunMultipleServers(2) + servers = await createMultipleServers(2) await setAccessTokensToServers(servers) server = servers[0] diff --git a/server/tests/api/check-params/bulk.ts b/server/tests/api/check-params/bulk.ts index 69ff7dd96..a660c3d80 100644 --- a/server/tests/api/check-params/bulk.ts +++ b/server/tests/api/check-params/bulk.ts @@ -3,15 +3,15 @@ import 'mocha' import { cleanupTests, - flushAndRunServer, - ServerInfo, + createSingleServer, + PeerTubeServer, setAccessTokensToServers } from '../../../../shared/extra-utils' import { makePostBodyRequest } from '../../../../shared/extra-utils/requests/requests' import { HttpStatusCode } from '../../../../shared/core-utils/miscs/http-error-codes' describe('Test bulk API validators', function () { - let server: ServerInfo + let server: PeerTubeServer let userAccessToken: string // --------------------------------------------------------------- @@ -19,7 +19,7 @@ describe('Test bulk API validators', function () { before(async function () { this.timeout(120000) - server = await flushAndRunServer(1) + server = await createSingleServer(1) await setAccessTokensToServers([ server ]) const user = { username: 'user1', password: 'password' } diff --git a/server/tests/api/check-params/config.ts b/server/tests/api/check-params/config.ts index 6fd26864e..1756d58ee 100644 --- a/server/tests/api/check-params/config.ts +++ b/server/tests/api/check-params/config.ts @@ -5,18 +5,18 @@ import { omit } from 'lodash' import { HttpStatusCode } from '@shared/core-utils' import { cleanupTests, - flushAndRunServer, + createSingleServer, makeDeleteRequest, makeGetRequest, makePutBodyRequest, - ServerInfo, + PeerTubeServer, setAccessTokensToServers } from '@shared/extra-utils' import { CustomConfig } from '@shared/models' describe('Test config API validators', function () { const path = '/api/v1/config/custom' - let server: ServerInfo + let server: PeerTubeServer let userAccessToken: string const updateParams: CustomConfig = { instance: { @@ -197,7 +197,7 @@ describe('Test config API validators', function () { before(async function () { this.timeout(30000) - server = await flushAndRunServer(1) + server = await createSingleServer(1) await setAccessTokensToServers([ server ]) diff --git a/server/tests/api/check-params/contact-form.ts b/server/tests/api/check-params/contact-form.ts index d2541777f..8c2b2a84b 100644 --- a/server/tests/api/check-params/contact-form.ts +++ b/server/tests/api/check-params/contact-form.ts @@ -2,11 +2,11 @@ import 'mocha' import { HttpStatusCode } from '@shared/core-utils' -import { cleanupTests, flushAndRunServer, killallServers, MockSmtpServer, reRunServer, ServerInfo } from '@shared/extra-utils' +import { cleanupTests, createSingleServer, killallServers, MockSmtpServer, PeerTubeServer } from '@shared/extra-utils' import { ContactFormCommand } from '@shared/extra-utils/server' describe('Test contact form API validators', function () { - let server: ServerInfo + let server: PeerTubeServer const emails: object[] = [] const defaultBody = { fromName: 'super name', @@ -25,7 +25,7 @@ describe('Test contact form API validators', function () { emailPort = await MockSmtpServer.Instance.collectEmails(emails) // Email is disabled - server = await flushAndRunServer(1) + server = await createSingleServer(1) command = server.contactForm }) @@ -39,7 +39,7 @@ describe('Test contact form API validators', function () { await killallServers([ server ]) // Contact form is disabled - await reRunServer(server, { smtp: { hostname: 'localhost', port: emailPort }, contact_form: { enabled: false } }) + await server.run({ smtp: { hostname: 'localhost', port: emailPort }, contact_form: { enabled: false } }) await command.send({ ...defaultBody, expectedStatus: HttpStatusCode.CONFLICT_409 }) }) @@ -49,7 +49,7 @@ describe('Test contact form API validators', function () { await killallServers([ server ]) // Email & contact form enabled - await reRunServer(server, { smtp: { hostname: 'localhost', port: emailPort } }) + await server.run({ smtp: { hostname: 'localhost', port: emailPort } }) await command.send({ ...defaultBody, fromEmail: 'badEmail', expectedStatus: HttpStatusCode.BAD_REQUEST_400 }) await command.send({ ...defaultBody, fromEmail: 'badEmail@', expectedStatus: HttpStatusCode.BAD_REQUEST_400 }) diff --git a/server/tests/api/check-params/custom-pages.ts b/server/tests/api/check-params/custom-pages.ts index 3d84fb3e6..043505e32 100644 --- a/server/tests/api/check-params/custom-pages.ts +++ b/server/tests/api/check-params/custom-pages.ts @@ -4,8 +4,8 @@ import 'mocha' import { HttpStatusCode } from '../../../../shared/core-utils/miscs/http-error-codes' import { cleanupTests, - flushAndRunServer, - ServerInfo, + createSingleServer, + PeerTubeServer, setAccessTokensToServers } from '../../../../shared/extra-utils' import { makeGetRequest, makePutBodyRequest } from '../../../../shared/extra-utils/requests/requests' @@ -13,7 +13,7 @@ import { makeGetRequest, makePutBodyRequest } from '../../../../shared/extra-uti describe('Test custom pages validators', function () { const path = '/api/v1/custom-pages/homepage/instance' - let server: ServerInfo + let server: PeerTubeServer let userAccessToken: string // --------------------------------------------------------------- @@ -21,7 +21,7 @@ describe('Test custom pages validators', function () { before(async function () { this.timeout(120000) - server = await flushAndRunServer(1) + server = await createSingleServer(1) await setAccessTokensToServers([ server ]) const user = { username: 'user1', password: 'password' } diff --git a/server/tests/api/check-params/debug.ts b/server/tests/api/check-params/debug.ts index 609f9566e..9c13e9daf 100644 --- a/server/tests/api/check-params/debug.ts +++ b/server/tests/api/check-params/debug.ts @@ -4,8 +4,8 @@ import 'mocha' import { cleanupTests, - flushAndRunServer, - ServerInfo, + createSingleServer, + PeerTubeServer, setAccessTokensToServers } from '../../../../shared/extra-utils' import { makeGetRequest } from '../../../../shared/extra-utils/requests/requests' @@ -13,7 +13,7 @@ import { HttpStatusCode } from '../../../../shared/core-utils/miscs/http-error-c describe('Test debug API validators', function () { const path = '/api/v1/server/debug' - let server: ServerInfo + let server: PeerTubeServer let userAccessToken = '' // --------------------------------------------------------------- @@ -21,7 +21,7 @@ describe('Test debug API validators', function () { before(async function () { this.timeout(120000) - server = await flushAndRunServer(1) + server = await createSingleServer(1) await setAccessTokensToServers([ server ]) diff --git a/server/tests/api/check-params/follows.ts b/server/tests/api/check-params/follows.ts index fae3712ce..0fd2b4925 100644 --- a/server/tests/api/check-params/follows.ts +++ b/server/tests/api/check-params/follows.ts @@ -4,10 +4,10 @@ import 'mocha' import { cleanupTests, - flushAndRunServer, + createSingleServer, makeDeleteRequest, makeGetRequest, makePostBodyRequest, - ServerInfo, + PeerTubeServer, setAccessTokensToServers } from '../../../../shared/extra-utils' import { @@ -18,14 +18,14 @@ import { import { HttpStatusCode } from '../../../../shared/core-utils/miscs/http-error-codes' describe('Test server follows API validators', function () { - let server: ServerInfo + let server: PeerTubeServer // --------------------------------------------------------------- before(async function () { this.timeout(30000) - server = await flushAndRunServer(1) + server = await createSingleServer(1) await setAccessTokensToServers([ server ]) }) diff --git a/server/tests/api/check-params/jobs.ts b/server/tests/api/check-params/jobs.ts index 3786e8612..a370ec2d3 100644 --- a/server/tests/api/check-params/jobs.ts +++ b/server/tests/api/check-params/jobs.ts @@ -4,8 +4,8 @@ import 'mocha' import { cleanupTests, - flushAndRunServer, - ServerInfo, + createSingleServer, + PeerTubeServer, setAccessTokensToServers } from '../../../../shared/extra-utils' import { @@ -18,7 +18,7 @@ import { HttpStatusCode } from '../../../../shared/core-utils/miscs/http-error-c describe('Test jobs API validators', function () { const path = '/api/v1/jobs/failed' - let server: ServerInfo + let server: PeerTubeServer let userAccessToken = '' // --------------------------------------------------------------- @@ -26,7 +26,7 @@ describe('Test jobs API validators', function () { before(async function () { this.timeout(120000) - server = await flushAndRunServer(1) + server = await createSingleServer(1) await setAccessTokensToServers([ server ]) diff --git a/server/tests/api/check-params/live.ts b/server/tests/api/check-params/live.ts index 20f27dd1d..eb5cdd1d8 100644 --- a/server/tests/api/check-params/live.ts +++ b/server/tests/api/check-params/live.ts @@ -6,12 +6,12 @@ import { HttpStatusCode } from '@shared/core-utils' import { buildAbsoluteFixturePath, cleanupTests, - flushAndRunServer, + createSingleServer, LiveCommand, makePostBodyRequest, makeUploadRequest, sendRTMPStream, - ServerInfo, + PeerTubeServer, setAccessTokensToServers, stopFfmpeg } from '@shared/extra-utils' @@ -19,7 +19,7 @@ import { VideoCreateResult, VideoPrivacy } from '@shared/models' describe('Test video lives API validator', function () { const path = '/api/v1/videos/live' - let server: ServerInfo + let server: PeerTubeServer let userAccessToken = '' let channelId: number let video: VideoCreateResult @@ -31,7 +31,7 @@ describe('Test video lives API validator', function () { before(async function () { this.timeout(30000) - server = await flushAndRunServer(1) + server = await createSingleServer(1) await setAccessTokensToServers([ server ]) diff --git a/server/tests/api/check-params/logs.ts b/server/tests/api/check-params/logs.ts index cf8f77959..2eb074007 100644 --- a/server/tests/api/check-params/logs.ts +++ b/server/tests/api/check-params/logs.ts @@ -4,8 +4,8 @@ import 'mocha' import { cleanupTests, - flushAndRunServer, - ServerInfo, + createSingleServer, + PeerTubeServer, setAccessTokensToServers } from '../../../../shared/extra-utils' import { makeGetRequest } from '../../../../shared/extra-utils/requests/requests' @@ -13,7 +13,7 @@ import { HttpStatusCode } from '../../../../shared/core-utils/miscs/http-error-c describe('Test logs API validators', function () { const path = '/api/v1/server/logs' - let server: ServerInfo + let server: PeerTubeServer let userAccessToken = '' // --------------------------------------------------------------- @@ -21,7 +21,7 @@ describe('Test logs API validators', function () { before(async function () { this.timeout(120000) - server = await flushAndRunServer(1) + server = await createSingleServer(1) await setAccessTokensToServers([ server ]) diff --git a/server/tests/api/check-params/plugins.ts b/server/tests/api/check-params/plugins.ts index d4b72c0f4..2b471ee7d 100644 --- a/server/tests/api/check-params/plugins.ts +++ b/server/tests/api/check-params/plugins.ts @@ -7,17 +7,17 @@ import { checkBadSortPagination, checkBadStartPagination, cleanupTests, - flushAndRunServer, + createSingleServer, makeGetRequest, makePostBodyRequest, makePutBodyRequest, - ServerInfo, + PeerTubeServer, setAccessTokensToServers } from '@shared/extra-utils' import { PeerTubePlugin, PluginType } from '@shared/models' describe('Test server plugins API validators', function () { - let server: ServerInfo + let server: PeerTubeServer let userAccessToken = null const npmPlugin = 'peertube-plugin-hello-world' @@ -33,7 +33,7 @@ describe('Test server plugins API validators', function () { before(async function () { this.timeout(30000) - server = await flushAndRunServer(1) + server = await createSingleServer(1) await setAccessTokensToServers([ server ]) diff --git a/server/tests/api/check-params/redundancy.ts b/server/tests/api/check-params/redundancy.ts index fca92fde4..18b98a0f9 100644 --- a/server/tests/api/check-params/redundancy.ts +++ b/server/tests/api/check-params/redundancy.ts @@ -9,18 +9,18 @@ import { checkBadStartPagination, cleanupTests, doubleFollow, - flushAndRunMultipleServers, + createMultipleServers, makeDeleteRequest, makeGetRequest, makePostBodyRequest, makePutBodyRequest, - ServerInfo, + PeerTubeServer, setAccessTokensToServers, waitJobs } from '../../../../shared/extra-utils' describe('Test server redundancy API validators', function () { - let servers: ServerInfo[] + let servers: PeerTubeServer[] let userAccessToken = null let videoIdLocal: number let videoRemote: VideoCreateResult @@ -30,7 +30,7 @@ describe('Test server redundancy API validators', function () { before(async function () { this.timeout(80000) - servers = await flushAndRunMultipleServers(2) + servers = await createMultipleServers(2) await setAccessTokensToServers(servers) await doubleFollow(servers[0], servers[1]) diff --git a/server/tests/api/check-params/search.ts b/server/tests/api/check-params/search.ts index 1acfa0922..43cd81af9 100644 --- a/server/tests/api/check-params/search.ts +++ b/server/tests/api/check-params/search.ts @@ -7,13 +7,13 @@ import { checkBadSortPagination, checkBadStartPagination, cleanupTests, - flushAndRunServer, + createSingleServer, makeGetRequest, - ServerInfo, + PeerTubeServer, setAccessTokensToServers } from '@shared/extra-utils' -function updateSearchIndex (server: ServerInfo, enabled: boolean, disableLocalSearch = false) { +function updateSearchIndex (server: PeerTubeServer, enabled: boolean, disableLocalSearch = false) { return server.config.updateCustomSubConfig({ newConfig: { search: { @@ -27,14 +27,14 @@ function updateSearchIndex (server: ServerInfo, enabled: boolean, disableLocalSe } describe('Test videos API validator', function () { - let server: ServerInfo + let server: PeerTubeServer // --------------------------------------------------------------- before(async function () { this.timeout(30000) - server = await flushAndRunServer(1) + server = await createSingleServer(1) await setAccessTokensToServers([ server ]) }) diff --git a/server/tests/api/check-params/services.ts b/server/tests/api/check-params/services.ts index 83435c24a..c623240b7 100644 --- a/server/tests/api/check-params/services.ts +++ b/server/tests/api/check-params/services.ts @@ -4,16 +4,16 @@ import 'mocha' import { HttpStatusCode } from '@shared/core-utils' import { cleanupTests, - flushAndRunServer, + createSingleServer, makeGetRequest, - ServerInfo, + PeerTubeServer, setAccessTokensToServers, setDefaultVideoChannel } from '@shared/extra-utils' import { VideoPlaylistPrivacy } from '@shared/models' describe('Test services API validators', function () { - let server: ServerInfo + let server: PeerTubeServer let playlistUUID: string // --------------------------------------------------------------- @@ -21,7 +21,7 @@ describe('Test services API validators', function () { before(async function () { this.timeout(60000) - server = await flushAndRunServer(1) + server = await createSingleServer(1) await setAccessTokensToServers([ server ]) await setDefaultVideoChannel([ server ]) @@ -120,7 +120,7 @@ describe('Test services API validators', function () { }) }) -function checkParamEmbed (server: ServerInfo, embedUrl: string, statusCodeExpected = HttpStatusCode.BAD_REQUEST_400, query = {}) { +function checkParamEmbed (server: PeerTubeServer, embedUrl: string, statusCodeExpected = HttpStatusCode.BAD_REQUEST_400, query = {}) { const path = '/services/oembed' return makeGetRequest({ diff --git a/server/tests/api/check-params/upload-quota.ts b/server/tests/api/check-params/upload-quota.ts index 4ca544790..2c73e6a19 100644 --- a/server/tests/api/check-params/upload-quota.ts +++ b/server/tests/api/check-params/upload-quota.ts @@ -5,9 +5,9 @@ import { expect } from 'chai' import { HttpStatusCode, randomInt } from '@shared/core-utils' import { cleanupTests, - flushAndRunServer, + createSingleServer, ImportsCommand, - ServerInfo, + PeerTubeServer, setAccessTokensToServers, setDefaultVideoChannel, VideosCommand, @@ -16,7 +16,7 @@ import { import { VideoImportState, VideoPrivacy } from '@shared/models' describe('Test upload quota', function () { - let server: ServerInfo + let server: PeerTubeServer let rootId: number let command: VideosCommand @@ -25,7 +25,7 @@ describe('Test upload quota', function () { before(async function () { this.timeout(30000) - server = await flushAndRunServer(1) + server = await createSingleServer(1) await setAccessTokensToServers([ server ]) await setDefaultVideoChannel([ server ]) diff --git a/server/tests/api/check-params/user-notifications.ts b/server/tests/api/check-params/user-notifications.ts index 913eca366..038c444b3 100644 --- a/server/tests/api/check-params/user-notifications.ts +++ b/server/tests/api/check-params/user-notifications.ts @@ -8,25 +8,25 @@ import { checkBadSortPagination, checkBadStartPagination, cleanupTests, - flushAndRunServer, + createSingleServer, makeGetRequest, makePostBodyRequest, makePutBodyRequest, - ServerInfo, + PeerTubeServer, setAccessTokensToServers, wait } from '@shared/extra-utils' import { UserNotificationSetting, UserNotificationSettingValue } from '@shared/models' describe('Test user notifications API validators', function () { - let server: ServerInfo + let server: PeerTubeServer // --------------------------------------------------------------- before(async function () { this.timeout(30000) - server = await flushAndRunServer(1) + server = await createSingleServer(1) await setAccessTokensToServers([ server ]) }) diff --git a/server/tests/api/check-params/user-subscriptions.ts b/server/tests/api/check-params/user-subscriptions.ts index 885ad68e4..22cf130c2 100644 --- a/server/tests/api/check-params/user-subscriptions.ts +++ b/server/tests/api/check-params/user-subscriptions.ts @@ -4,11 +4,11 @@ import 'mocha' import { cleanupTests, - flushAndRunServer, + createSingleServer, makeDeleteRequest, makeGetRequest, makePostBodyRequest, - ServerInfo, + PeerTubeServer, setAccessTokensToServers } from '../../../../shared/extra-utils' @@ -22,7 +22,7 @@ import { HttpStatusCode } from '../../../../shared/core-utils/miscs/http-error-c describe('Test user subscriptions API validators', function () { const path = '/api/v1/users/me/subscriptions' - let server: ServerInfo + let server: PeerTubeServer let userAccessToken = '' // --------------------------------------------------------------- @@ -30,7 +30,7 @@ describe('Test user subscriptions API validators', function () { before(async function () { this.timeout(30000) - server = await flushAndRunServer(1) + server = await createSingleServer(1) await setAccessTokensToServers([ server ]) diff --git a/server/tests/api/check-params/users.ts b/server/tests/api/check-params/users.ts index bce3f0774..c2c98f429 100644 --- a/server/tests/api/check-params/users.ts +++ b/server/tests/api/check-params/users.ts @@ -9,15 +9,14 @@ import { checkBadSortPagination, checkBadStartPagination, cleanupTests, - flushAndRunServer, + createSingleServer, killallServers, makeGetRequest, makePostBodyRequest, makePutBodyRequest, makeUploadRequest, MockSmtpServer, - reRunServer, - ServerInfo, + PeerTubeServer, setAccessTokensToServers, UsersCommand } from '@shared/extra-utils' @@ -29,8 +28,8 @@ describe('Test users API validators', function () { let rootId: number let moderatorId: number let video: VideoCreateResult - let server: ServerInfo - let serverWithRegistrationDisabled: ServerInfo + let server: PeerTubeServer + let serverWithRegistrationDisabled: PeerTubeServer let userToken = '' let moderatorToken = '' let emailPort: number @@ -48,8 +47,8 @@ describe('Test users API validators', function () { { const res = await Promise.all([ - flushAndRunServer(1, overrideConfig), - flushAndRunServer(2) + createSingleServer(1, overrideConfig), + createSingleServer(2) ]) server = res[0] @@ -196,7 +195,7 @@ describe('Test users API validators', function () { port: emailPort } } - await reRunServer(server, config) + await server.run(config) const fields = { ...baseCorrectParams, diff --git a/server/tests/api/check-params/video-blacklist.ts b/server/tests/api/check-params/video-blacklist.ts index 51609b982..b5d0e0778 100644 --- a/server/tests/api/check-params/video-blacklist.ts +++ b/server/tests/api/check-params/video-blacklist.ts @@ -10,17 +10,17 @@ import { checkBadStartPagination, cleanupTests, doubleFollow, - flushAndRunMultipleServers, + createMultipleServers, makePostBodyRequest, makePutBodyRequest, - ServerInfo, + PeerTubeServer, setAccessTokensToServers, waitJobs } from '@shared/extra-utils' import { VideoBlacklistType } from '@shared/models' describe('Test video blacklist API validators', function () { - let servers: ServerInfo[] + let servers: PeerTubeServer[] let notBlacklistedVideoId: string let remoteVideoUUID: string let userAccessToken1 = '' @@ -32,7 +32,7 @@ describe('Test video blacklist API validators', function () { before(async function () { this.timeout(120000) - servers = await flushAndRunMultipleServers(2) + servers = await createMultipleServers(2) await setAccessTokensToServers(servers) await doubleFollow(servers[0], servers[1]) diff --git a/server/tests/api/check-params/video-captions.ts b/server/tests/api/check-params/video-captions.ts index 913f894b9..26aab79e7 100644 --- a/server/tests/api/check-params/video-captions.ts +++ b/server/tests/api/check-params/video-captions.ts @@ -5,11 +5,11 @@ import { HttpStatusCode } from '@shared/core-utils' import { buildAbsoluteFixturePath, cleanupTests, - flushAndRunServer, + createSingleServer, makeDeleteRequest, makeGetRequest, makeUploadRequest, - ServerInfo, + PeerTubeServer, setAccessTokensToServers } from '@shared/extra-utils' import { VideoCreateResult } from '@shared/models' @@ -17,7 +17,7 @@ import { VideoCreateResult } from '@shared/models' describe('Test video captions API validator', function () { const path = '/api/v1/videos/' - let server: ServerInfo + let server: PeerTubeServer let userAccessToken: string let video: VideoCreateResult @@ -26,7 +26,7 @@ describe('Test video captions API validator', function () { before(async function () { this.timeout(30000) - server = await flushAndRunServer(1) + server = await createSingleServer(1) await setAccessTokensToServers([ server ]) diff --git a/server/tests/api/check-params/video-channels.ts b/server/tests/api/check-params/video-channels.ts index 8e6e32f20..62b8fa4f6 100644 --- a/server/tests/api/check-params/video-channels.ts +++ b/server/tests/api/check-params/video-channels.ts @@ -11,12 +11,12 @@ import { checkBadSortPagination, checkBadStartPagination, cleanupTests, - flushAndRunServer, + createSingleServer, makeGetRequest, makePostBodyRequest, makePutBodyRequest, makeUploadRequest, - ServerInfo, + PeerTubeServer, setAccessTokensToServers } from '@shared/extra-utils' import { VideoChannelUpdate } from '@shared/models' @@ -25,7 +25,7 @@ const expect = chai.expect describe('Test video channels API validator', function () { const videoChannelPath = '/api/v1/video-channels' - let server: ServerInfo + let server: PeerTubeServer let accessTokenUser: string let command: ChannelsCommand @@ -34,7 +34,7 @@ describe('Test video channels API validator', function () { before(async function () { this.timeout(30000) - server = await flushAndRunServer(1) + server = await createSingleServer(1) await setAccessTokensToServers([ server ]) diff --git a/server/tests/api/check-params/video-comments.ts b/server/tests/api/check-params/video-comments.ts index 44af9d7e3..ea5340b40 100644 --- a/server/tests/api/check-params/video-comments.ts +++ b/server/tests/api/check-params/video-comments.ts @@ -8,11 +8,11 @@ import { checkBadSortPagination, checkBadStartPagination, cleanupTests, - flushAndRunServer, + createSingleServer, makeDeleteRequest, makeGetRequest, makePostBodyRequest, - ServerInfo, + PeerTubeServer, setAccessTokensToServers } from '@shared/extra-utils' import { VideoCreateResult } from '@shared/models' @@ -22,7 +22,7 @@ const expect = chai.expect describe('Test video comments API validator', function () { let pathThread: string let pathComment: string - let server: ServerInfo + let server: PeerTubeServer let video: VideoCreateResult let userAccessToken: string let userAccessToken2: string @@ -33,7 +33,7 @@ describe('Test video comments API validator', function () { before(async function () { this.timeout(30000) - server = await flushAndRunServer(1) + server = await createSingleServer(1) await setAccessTokensToServers([ server ]) diff --git a/server/tests/api/check-params/video-imports.ts b/server/tests/api/check-params/video-imports.ts index 1a6b6075f..627f0c7ad 100644 --- a/server/tests/api/check-params/video-imports.ts +++ b/server/tests/api/check-params/video-imports.ts @@ -9,19 +9,19 @@ import { checkBadSortPagination, checkBadStartPagination, cleanupTests, - flushAndRunServer, + createSingleServer, ImportsCommand, makeGetRequest, makePostBodyRequest, makeUploadRequest, - ServerInfo, + PeerTubeServer, setAccessTokensToServers } from '@shared/extra-utils' import { VideoPrivacy } from '@shared/models' describe('Test video imports API validator', function () { const path = '/api/v1/videos/imports' - let server: ServerInfo + let server: PeerTubeServer let userAccessToken = '' let channelId: number @@ -30,7 +30,7 @@ describe('Test video imports API validator', function () { before(async function () { this.timeout(30000) - server = await flushAndRunServer(1) + server = await createSingleServer(1) await setAccessTokensToServers([ server ]) diff --git a/server/tests/api/check-params/video-playlists.ts b/server/tests/api/check-params/video-playlists.ts index e0e42ebb0..9d054b176 100644 --- a/server/tests/api/check-params/video-playlists.ts +++ b/server/tests/api/check-params/video-playlists.ts @@ -7,10 +7,10 @@ import { checkBadSortPagination, checkBadStartPagination, cleanupTests, - flushAndRunServer, + createSingleServer, makeGetRequest, PlaylistsCommand, - ServerInfo, + PeerTubeServer, setAccessTokensToServers, setDefaultVideoChannel } from '@shared/extra-utils' @@ -25,7 +25,7 @@ import { } from '@shared/models' describe('Test video playlists API validator', function () { - let server: ServerInfo + let server: PeerTubeServer let userAccessToken: string let playlist: VideoPlaylistCreateResult @@ -42,7 +42,7 @@ describe('Test video playlists API validator', function () { before(async function () { this.timeout(30000) - server = await flushAndRunServer(1) + server = await createSingleServer(1) await setAccessTokensToServers([ server ]) await setDefaultVideoChannel([ server ]) diff --git a/server/tests/api/check-params/videos-filter.ts b/server/tests/api/check-params/videos-filter.ts index cbfdef1db..e4e799cc7 100644 --- a/server/tests/api/check-params/videos-filter.ts +++ b/server/tests/api/check-params/videos-filter.ts @@ -3,16 +3,16 @@ import 'mocha' import { cleanupTests, - flushAndRunServer, + createSingleServer, makeGetRequest, - ServerInfo, + PeerTubeServer, setAccessTokensToServers, setDefaultVideoChannel } from '../../../../shared/extra-utils' import { UserRole } from '../../../../shared/models/users' import { HttpStatusCode } from '../../../../shared/core-utils/miscs/http-error-codes' -async function testEndpoints (server: ServerInfo, token: string, filter: string, statusCodeExpected: HttpStatusCode) { +async function testEndpoints (server: PeerTubeServer, token: string, filter: string, statusCodeExpected: HttpStatusCode) { const paths = [ '/api/v1/video-channels/root_channel/videos', '/api/v1/accounts/root/videos', @@ -34,7 +34,7 @@ async function testEndpoints (server: ServerInfo, token: string, filter: string, } describe('Test video filters validators', function () { - let server: ServerInfo + let server: PeerTubeServer let userAccessToken: string let moderatorAccessToken: string @@ -43,7 +43,7 @@ describe('Test video filters validators', function () { before(async function () { this.timeout(30000) - server = await flushAndRunServer(1) + server = await createSingleServer(1) await setAccessTokensToServers([ server ]) await setDefaultVideoChannel([ server ]) diff --git a/server/tests/api/check-params/videos-history.ts b/server/tests/api/check-params/videos-history.ts index 549c9fa1f..3c1f479e4 100644 --- a/server/tests/api/check-params/videos-history.ts +++ b/server/tests/api/check-params/videos-history.ts @@ -6,11 +6,11 @@ import { checkBadCountPagination, checkBadStartPagination, cleanupTests, - flushAndRunServer, + createSingleServer, makeGetRequest, makePostBodyRequest, makePutBodyRequest, - ServerInfo, + PeerTubeServer, setAccessTokensToServers } from '@shared/extra-utils' @@ -18,14 +18,14 @@ describe('Test videos history API validator', function () { const myHistoryPath = '/api/v1/users/me/history/videos' const myHistoryRemove = myHistoryPath + '/remove' let watchingPath: string - let server: ServerInfo + let server: PeerTubeServer // --------------------------------------------------------------- before(async function () { this.timeout(30000) - server = await flushAndRunServer(1) + server = await createSingleServer(1) await setAccessTokensToServers([ server ]) diff --git a/server/tests/api/check-params/videos-overviews.ts b/server/tests/api/check-params/videos-overviews.ts index 3597c81d3..c2139d74b 100644 --- a/server/tests/api/check-params/videos-overviews.ts +++ b/server/tests/api/check-params/videos-overviews.ts @@ -1,17 +1,17 @@ /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */ import 'mocha' -import { cleanupTests, flushAndRunServer, ServerInfo } from '@shared/extra-utils' +import { cleanupTests, createSingleServer, PeerTubeServer } from '@shared/extra-utils' describe('Test videos overview', function () { - let server: ServerInfo + let server: PeerTubeServer // --------------------------------------------------------------- before(async function () { this.timeout(30000) - server = await flushAndRunServer(1) + server = await createSingleServer(1) }) describe('When getting videos overview', function () { diff --git a/server/tests/api/check-params/videos.ts b/server/tests/api/check-params/videos.ts index 69bdae7cf..c60de2640 100644 --- a/server/tests/api/check-params/videos.ts +++ b/server/tests/api/check-params/videos.ts @@ -11,13 +11,13 @@ import { checkBadStartPagination, checkUploadVideoParam, cleanupTests, - flushAndRunServer, + createSingleServer, makeDeleteRequest, makeGetRequest, makePutBodyRequest, makeUploadRequest, root, - ServerInfo, + PeerTubeServer, setAccessTokensToServers } from '@shared/extra-utils' import { PeerTubeProblemDocument, VideoCreateResult, VideoPrivacy } from '@shared/models' @@ -26,7 +26,7 @@ const expect = chai.expect describe('Test videos API validator', function () { const path = '/api/v1/videos/' - let server: ServerInfo + let server: PeerTubeServer let userAccessToken = '' let accountName: string let channelId: number @@ -38,7 +38,7 @@ describe('Test videos API validator', function () { before(async function () { this.timeout(30000) - server = await flushAndRunServer(1) + server = await createSingleServer(1) await setAccessTokensToServers([ server ]) -- cgit v1.2.3 From 59bbcced37005dd511daca9bd58ae2998cb931b1 Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Fri, 16 Jul 2021 10:19:16 +0200 Subject: Centralize test URLs --- server/tests/api/check-params/upload-quota.ts | 6 +++--- server/tests/api/check-params/video-imports.ts | 6 +++--- 2 files changed, 6 insertions(+), 6 deletions(-) (limited to 'server/tests/api/check-params') diff --git a/server/tests/api/check-params/upload-quota.ts b/server/tests/api/check-params/upload-quota.ts index 2c73e6a19..bd8dce975 100644 --- a/server/tests/api/check-params/upload-quota.ts +++ b/server/tests/api/check-params/upload-quota.ts @@ -6,7 +6,7 @@ import { HttpStatusCode, randomInt } from '@shared/core-utils' import { cleanupTests, createSingleServer, - ImportsCommand, + FIXTURE_URLS, PeerTubeServer, setAccessTokensToServers, setDefaultVideoChannel, @@ -76,8 +76,8 @@ describe('Test upload quota', function () { channelId: server.store.channel.id, privacy: VideoPrivacy.PUBLIC } - await server.imports.importVideo({ attributes: { ...baseAttributes, targetUrl: ImportsCommand.getGoodVideoUrl() } }) - await server.imports.importVideo({ attributes: { ...baseAttributes, magnetUri: ImportsCommand.getMagnetURI() } }) + await server.imports.importVideo({ attributes: { ...baseAttributes, targetUrl: FIXTURE_URLS.goodVideo } }) + await server.imports.importVideo({ attributes: { ...baseAttributes, magnetUri: FIXTURE_URLS.magnet } }) await server.imports.importVideo({ attributes: { ...baseAttributes, torrentfile: 'video-720p.torrent' as any } }) await waitJobs([ server ]) diff --git a/server/tests/api/check-params/video-imports.ts b/server/tests/api/check-params/video-imports.ts index 627f0c7ad..0209275ac 100644 --- a/server/tests/api/check-params/video-imports.ts +++ b/server/tests/api/check-params/video-imports.ts @@ -10,7 +10,7 @@ import { checkBadStartPagination, cleanupTests, createSingleServer, - ImportsCommand, + FIXTURE_URLS, makeGetRequest, makePostBodyRequest, makeUploadRequest, @@ -70,7 +70,7 @@ describe('Test video imports API validator', function () { before(function () { baseCorrectParams = { - targetUrl: ImportsCommand.getGoodVideoUrl(), + targetUrl: FIXTURE_URLS.goodVideo, name: 'my super name', category: 5, licence: 1, @@ -297,7 +297,7 @@ describe('Test video imports API validator', function () { }) let fields = omit(baseCorrectParams, 'targetUrl') - fields = { ...fields, magnetUri: ImportsCommand.getMagnetURI() } + fields = { ...fields, magnetUri: FIXTURE_URLS.magnet } await makePostBodyRequest({ url: server.url, -- cgit v1.2.3 From 08642a765ea514a00f159db898edf14c376fbe6c Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Fri, 16 Jul 2021 10:20:44 +0200 Subject: Fix server run --- server/tests/api/check-params/video-comments.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'server/tests/api/check-params') diff --git a/server/tests/api/check-params/video-comments.ts b/server/tests/api/check-params/video-comments.ts index ea5340b40..92c29da0e 100644 --- a/server/tests/api/check-params/video-comments.ts +++ b/server/tests/api/check-params/video-comments.ts @@ -38,7 +38,7 @@ describe('Test video comments API validator', function () { await setAccessTokensToServers([ server ]) { - const video = await server.videos.upload({ attributes: {} }) + video = await server.videos.upload({ attributes: {} }) pathThread = '/api/v1/videos/' + video.uuid + '/comment-threads' } -- cgit v1.2.3 From c0e8b12e7fd554ba4d2ceb0c4900804c6a4c63ea Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Fri, 16 Jul 2021 10:42:24 +0200 Subject: Refactor requests --- server/tests/api/check-params/abuses.ts | 26 +++---- server/tests/api/check-params/accounts.ts | 2 +- server/tests/api/check-params/blocklist.ts | 91 +++++++++++----------- server/tests/api/check-params/bulk.ts | 20 ++--- server/tests/api/check-params/config.ts | 24 +++--- server/tests/api/check-params/contact-form.ts | 2 +- server/tests/api/check-params/custom-pages.ts | 15 ++-- server/tests/api/check-params/debug.ts | 17 ++-- server/tests/api/check-params/follows.ts | 64 ++++++++------- server/tests/api/check-params/jobs.ts | 19 ++--- server/tests/api/check-params/live.ts | 14 ++-- server/tests/api/check-params/logs.ts | 25 +++--- server/tests/api/check-params/plugins.ts | 66 ++++++++-------- server/tests/api/check-params/redundancy.ts | 39 +++++----- server/tests/api/check-params/search.ts | 62 +++++++-------- server/tests/api/check-params/services.ts | 6 +- server/tests/api/check-params/upload-quota.ts | 4 +- .../tests/api/check-params/user-notifications.ts | 32 ++++---- .../tests/api/check-params/user-subscriptions.ts | 68 ++++++++-------- server/tests/api/check-params/users.ts | 74 +++++++++--------- server/tests/api/check-params/video-blacklist.ts | 18 ++--- server/tests/api/check-params/video-captions.ts | 30 +++---- server/tests/api/check-params/video-channels.ts | 26 +++---- server/tests/api/check-params/video-comments.ts | 52 ++++++------- server/tests/api/check-params/video-imports.ts | 14 ++-- server/tests/api/check-params/video-playlists.ts | 18 ++--- server/tests/api/check-params/videos-filter.ts | 14 ++-- server/tests/api/check-params/videos-history.ts | 24 +++--- server/tests/api/check-params/videos.ts | 36 ++++----- 29 files changed, 435 insertions(+), 467 deletions(-) (limited to 'server/tests/api/check-params') diff --git a/server/tests/api/check-params/abuses.ts b/server/tests/api/check-params/abuses.ts index 62811f932..87d93195c 100644 --- a/server/tests/api/check-params/abuses.ts +++ b/server/tests/api/check-params/abuses.ts @@ -1,7 +1,7 @@ /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */ import 'mocha' -import { HttpStatusCode } from '@shared/core-utils' +import { HttpStatusCode } from '@shared/models' import { AbusesCommand, checkBadCountPagination, @@ -66,7 +66,7 @@ describe('Test abuses API validators', function () { await makeGetRequest({ url: server.url, path, - statusCodeExpected: HttpStatusCode.UNAUTHORIZED_401 + expectedStatus: HttpStatusCode.UNAUTHORIZED_401 }) }) @@ -75,7 +75,7 @@ describe('Test abuses API validators', function () { url: server.url, path, token: userToken, - statusCodeExpected: HttpStatusCode.FORBIDDEN_403 + expectedStatus: HttpStatusCode.FORBIDDEN_403 }) }) @@ -110,7 +110,7 @@ describe('Test abuses API validators', function () { videoIs: 'deleted' } - await makeGetRequest({ url: server.url, path, token: server.accessToken, query, statusCodeExpected: HttpStatusCode.OK_200 }) + await makeGetRequest({ url: server.url, path, token: server.accessToken, query, expectedStatus: HttpStatusCode.OK_200 }) }) }) @@ -133,7 +133,7 @@ describe('Test abuses API validators', function () { await makeGetRequest({ url: server.url, path, - statusCodeExpected: HttpStatusCode.UNAUTHORIZED_401 + expectedStatus: HttpStatusCode.UNAUTHORIZED_401 }) }) @@ -152,7 +152,7 @@ describe('Test abuses API validators', function () { state: 2 } - await makeGetRequest({ url: server.url, path, token: userToken, query, statusCodeExpected: HttpStatusCode.OK_200 }) + await makeGetRequest({ url: server.url, path, token: userToken, query, expectedStatus: HttpStatusCode.OK_200 }) }) }) @@ -176,7 +176,7 @@ describe('Test abuses API validators', function () { path, token: userToken, fields, - statusCodeExpected: HttpStatusCode.NOT_FOUND_404 + expectedStatus: HttpStatusCode.NOT_FOUND_404 }) }) @@ -192,7 +192,7 @@ describe('Test abuses API validators', function () { path, token: userToken, fields, - statusCodeExpected: HttpStatusCode.NOT_FOUND_404 + expectedStatus: HttpStatusCode.NOT_FOUND_404 }) }) @@ -208,7 +208,7 @@ describe('Test abuses API validators', function () { path, token: userToken, fields, - statusCodeExpected: HttpStatusCode.NOT_FOUND_404 + expectedStatus: HttpStatusCode.NOT_FOUND_404 }) }) @@ -219,14 +219,14 @@ describe('Test abuses API validators', function () { path, token: userToken, fields, - statusCodeExpected: HttpStatusCode.BAD_REQUEST_400 + expectedStatus: HttpStatusCode.BAD_REQUEST_400 }) }) it('Should fail with a non authenticated user', async function () { const fields = { video: { id: server.store.video.id }, reason: 'my super reason' } - await makePostBodyRequest({ url: server.url, path, token: 'hello', fields, statusCodeExpected: HttpStatusCode.UNAUTHORIZED_401 }) + await makePostBodyRequest({ url: server.url, path, token: 'hello', fields, expectedStatus: HttpStatusCode.UNAUTHORIZED_401 }) }) it('Should fail with a reason too short', async function () { @@ -249,7 +249,7 @@ describe('Test abuses API validators', function () { path, token: userToken, fields, - statusCodeExpected: HttpStatusCode.OK_200 + expectedStatus: HttpStatusCode.OK_200 }) abuseId = res.body.abuse.id }) @@ -283,7 +283,7 @@ describe('Test abuses API validators', function () { predefinedReasons: [ 'serverRules' ] } - await makePostBodyRequest({ url: server.url, path, token: userToken, fields, statusCodeExpected: HttpStatusCode.OK_200 }) + await makePostBodyRequest({ url: server.url, path, token: userToken, fields, expectedStatus: HttpStatusCode.OK_200 }) }) }) diff --git a/server/tests/api/check-params/accounts.ts b/server/tests/api/check-params/accounts.ts index e866593db..0cae485d9 100644 --- a/server/tests/api/check-params/accounts.ts +++ b/server/tests/api/check-params/accounts.ts @@ -1,7 +1,7 @@ /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */ import 'mocha' -import { HttpStatusCode } from '@shared/core-utils' +import { HttpStatusCode } from '@shared/models' import { checkBadCountPagination, checkBadSortPagination, diff --git a/server/tests/api/check-params/blocklist.ts b/server/tests/api/check-params/blocklist.ts index b2a1cc4e2..7d5fae5cf 100644 --- a/server/tests/api/check-params/blocklist.ts +++ b/server/tests/api/check-params/blocklist.ts @@ -1,23 +1,20 @@ /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */ import 'mocha' - import { + checkBadCountPagination, + checkBadSortPagination, + checkBadStartPagination, cleanupTests, - doubleFollow, createMultipleServers, + doubleFollow, makeDeleteRequest, makeGetRequest, makePostBodyRequest, PeerTubeServer, setAccessTokensToServers -} from '../../../../shared/extra-utils' -import { - checkBadCountPagination, - checkBadSortPagination, - checkBadStartPagination -} from '../../../../shared/extra-utils/requests/check-api-params' -import { HttpStatusCode } from '../../../../shared/core-utils/miscs/http-error-codes' +} from '@shared/extra-utils' +import { HttpStatusCode } from '@shared/models' describe('Test blocklist API validators', function () { let servers: PeerTubeServer[] @@ -52,7 +49,7 @@ describe('Test blocklist API validators', function () { await makeGetRequest({ url: server.url, path, - statusCodeExpected: HttpStatusCode.UNAUTHORIZED_401 + expectedStatus: HttpStatusCode.UNAUTHORIZED_401 }) }) @@ -75,7 +72,7 @@ describe('Test blocklist API validators', function () { url: server.url, path, fields: { accountName: 'user1' }, - statusCodeExpected: HttpStatusCode.UNAUTHORIZED_401 + expectedStatus: HttpStatusCode.UNAUTHORIZED_401 }) }) @@ -85,7 +82,7 @@ describe('Test blocklist API validators', function () { token: server.accessToken, path, fields: { accountName: 'user2' }, - statusCodeExpected: HttpStatusCode.NOT_FOUND_404 + expectedStatus: HttpStatusCode.NOT_FOUND_404 }) }) @@ -95,7 +92,7 @@ describe('Test blocklist API validators', function () { token: server.accessToken, path, fields: { accountName: 'root' }, - statusCodeExpected: HttpStatusCode.CONFLICT_409 + expectedStatus: HttpStatusCode.CONFLICT_409 }) }) @@ -105,7 +102,7 @@ describe('Test blocklist API validators', function () { token: server.accessToken, path, fields: { accountName: 'user1' }, - statusCodeExpected: HttpStatusCode.NO_CONTENT_204 + expectedStatus: HttpStatusCode.NO_CONTENT_204 }) }) }) @@ -115,7 +112,7 @@ describe('Test blocklist API validators', function () { await makeDeleteRequest({ url: server.url, path: path + '/user1', - statusCodeExpected: HttpStatusCode.UNAUTHORIZED_401 + expectedStatus: HttpStatusCode.UNAUTHORIZED_401 }) }) @@ -124,7 +121,7 @@ describe('Test blocklist API validators', function () { url: server.url, path: path + '/user2', token: server.accessToken, - statusCodeExpected: HttpStatusCode.NOT_FOUND_404 + expectedStatus: HttpStatusCode.NOT_FOUND_404 }) }) @@ -133,7 +130,7 @@ describe('Test blocklist API validators', function () { url: server.url, path: path + '/user1', token: server.accessToken, - statusCodeExpected: HttpStatusCode.NO_CONTENT_204 + expectedStatus: HttpStatusCode.NO_CONTENT_204 }) }) }) @@ -147,7 +144,7 @@ describe('Test blocklist API validators', function () { await makeGetRequest({ url: server.url, path, - statusCodeExpected: HttpStatusCode.UNAUTHORIZED_401 + expectedStatus: HttpStatusCode.UNAUTHORIZED_401 }) }) @@ -170,7 +167,7 @@ describe('Test blocklist API validators', function () { url: server.url, path, fields: { host: 'localhost:9002' }, - statusCodeExpected: HttpStatusCode.UNAUTHORIZED_401 + expectedStatus: HttpStatusCode.UNAUTHORIZED_401 }) }) @@ -180,7 +177,7 @@ describe('Test blocklist API validators', function () { token: server.accessToken, path, fields: { host: 'localhost:9003' }, - statusCodeExpected: HttpStatusCode.NO_CONTENT_204 + expectedStatus: HttpStatusCode.NO_CONTENT_204 }) }) @@ -190,7 +187,7 @@ describe('Test blocklist API validators', function () { token: server.accessToken, path, fields: { host: 'localhost:' + server.port }, - statusCodeExpected: HttpStatusCode.CONFLICT_409 + expectedStatus: HttpStatusCode.CONFLICT_409 }) }) @@ -200,7 +197,7 @@ describe('Test blocklist API validators', function () { token: server.accessToken, path, fields: { host: 'localhost:' + servers[1].port }, - statusCodeExpected: HttpStatusCode.NO_CONTENT_204 + expectedStatus: HttpStatusCode.NO_CONTENT_204 }) }) }) @@ -210,7 +207,7 @@ describe('Test blocklist API validators', function () { await makeDeleteRequest({ url: server.url, path: path + '/localhost:' + servers[1].port, - statusCodeExpected: HttpStatusCode.UNAUTHORIZED_401 + expectedStatus: HttpStatusCode.UNAUTHORIZED_401 }) }) @@ -219,7 +216,7 @@ describe('Test blocklist API validators', function () { url: server.url, path: path + '/localhost:9004', token: server.accessToken, - statusCodeExpected: HttpStatusCode.NOT_FOUND_404 + expectedStatus: HttpStatusCode.NOT_FOUND_404 }) }) @@ -228,7 +225,7 @@ describe('Test blocklist API validators', function () { url: server.url, path: path + '/localhost:' + servers[1].port, token: server.accessToken, - statusCodeExpected: HttpStatusCode.NO_CONTENT_204 + expectedStatus: HttpStatusCode.NO_CONTENT_204 }) }) }) @@ -245,7 +242,7 @@ describe('Test blocklist API validators', function () { await makeGetRequest({ url: server.url, path, - statusCodeExpected: HttpStatusCode.UNAUTHORIZED_401 + expectedStatus: HttpStatusCode.UNAUTHORIZED_401 }) }) @@ -254,7 +251,7 @@ describe('Test blocklist API validators', function () { url: server.url, token: userAccessToken, path, - statusCodeExpected: HttpStatusCode.FORBIDDEN_403 + expectedStatus: HttpStatusCode.FORBIDDEN_403 }) }) @@ -277,7 +274,7 @@ describe('Test blocklist API validators', function () { url: server.url, path, fields: { accountName: 'user1' }, - statusCodeExpected: HttpStatusCode.UNAUTHORIZED_401 + expectedStatus: HttpStatusCode.UNAUTHORIZED_401 }) }) @@ -287,7 +284,7 @@ describe('Test blocklist API validators', function () { token: userAccessToken, path, fields: { accountName: 'user1' }, - statusCodeExpected: HttpStatusCode.FORBIDDEN_403 + expectedStatus: HttpStatusCode.FORBIDDEN_403 }) }) @@ -297,7 +294,7 @@ describe('Test blocklist API validators', function () { token: server.accessToken, path, fields: { accountName: 'user2' }, - statusCodeExpected: HttpStatusCode.NOT_FOUND_404 + expectedStatus: HttpStatusCode.NOT_FOUND_404 }) }) @@ -307,7 +304,7 @@ describe('Test blocklist API validators', function () { token: server.accessToken, path, fields: { accountName: 'root' }, - statusCodeExpected: HttpStatusCode.CONFLICT_409 + expectedStatus: HttpStatusCode.CONFLICT_409 }) }) @@ -317,7 +314,7 @@ describe('Test blocklist API validators', function () { token: server.accessToken, path, fields: { accountName: 'user1' }, - statusCodeExpected: HttpStatusCode.NO_CONTENT_204 + expectedStatus: HttpStatusCode.NO_CONTENT_204 }) }) }) @@ -327,7 +324,7 @@ describe('Test blocklist API validators', function () { await makeDeleteRequest({ url: server.url, path: path + '/user1', - statusCodeExpected: HttpStatusCode.UNAUTHORIZED_401 + expectedStatus: HttpStatusCode.UNAUTHORIZED_401 }) }) @@ -336,7 +333,7 @@ describe('Test blocklist API validators', function () { url: server.url, path: path + '/user1', token: userAccessToken, - statusCodeExpected: HttpStatusCode.FORBIDDEN_403 + expectedStatus: HttpStatusCode.FORBIDDEN_403 }) }) @@ -345,7 +342,7 @@ describe('Test blocklist API validators', function () { url: server.url, path: path + '/user2', token: server.accessToken, - statusCodeExpected: HttpStatusCode.NOT_FOUND_404 + expectedStatus: HttpStatusCode.NOT_FOUND_404 }) }) @@ -354,7 +351,7 @@ describe('Test blocklist API validators', function () { url: server.url, path: path + '/user1', token: server.accessToken, - statusCodeExpected: HttpStatusCode.NO_CONTENT_204 + expectedStatus: HttpStatusCode.NO_CONTENT_204 }) }) }) @@ -368,7 +365,7 @@ describe('Test blocklist API validators', function () { await makeGetRequest({ url: server.url, path, - statusCodeExpected: HttpStatusCode.UNAUTHORIZED_401 + expectedStatus: HttpStatusCode.UNAUTHORIZED_401 }) }) @@ -377,7 +374,7 @@ describe('Test blocklist API validators', function () { url: server.url, token: userAccessToken, path, - statusCodeExpected: HttpStatusCode.FORBIDDEN_403 + expectedStatus: HttpStatusCode.FORBIDDEN_403 }) }) @@ -400,7 +397,7 @@ describe('Test blocklist API validators', function () { url: server.url, path, fields: { host: 'localhost:' + servers[1].port }, - statusCodeExpected: HttpStatusCode.UNAUTHORIZED_401 + expectedStatus: HttpStatusCode.UNAUTHORIZED_401 }) }) @@ -410,7 +407,7 @@ describe('Test blocklist API validators', function () { token: userAccessToken, path, fields: { host: 'localhost:' + servers[1].port }, - statusCodeExpected: HttpStatusCode.FORBIDDEN_403 + expectedStatus: HttpStatusCode.FORBIDDEN_403 }) }) @@ -420,7 +417,7 @@ describe('Test blocklist API validators', function () { token: server.accessToken, path, fields: { host: 'localhost:9003' }, - statusCodeExpected: HttpStatusCode.NO_CONTENT_204 + expectedStatus: HttpStatusCode.NO_CONTENT_204 }) }) @@ -430,7 +427,7 @@ describe('Test blocklist API validators', function () { token: server.accessToken, path, fields: { host: 'localhost:' + server.port }, - statusCodeExpected: HttpStatusCode.CONFLICT_409 + expectedStatus: HttpStatusCode.CONFLICT_409 }) }) @@ -440,7 +437,7 @@ describe('Test blocklist API validators', function () { token: server.accessToken, path, fields: { host: 'localhost:' + servers[1].port }, - statusCodeExpected: HttpStatusCode.NO_CONTENT_204 + expectedStatus: HttpStatusCode.NO_CONTENT_204 }) }) }) @@ -450,7 +447,7 @@ describe('Test blocklist API validators', function () { await makeDeleteRequest({ url: server.url, path: path + '/localhost:' + servers[1].port, - statusCodeExpected: HttpStatusCode.UNAUTHORIZED_401 + expectedStatus: HttpStatusCode.UNAUTHORIZED_401 }) }) @@ -459,7 +456,7 @@ describe('Test blocklist API validators', function () { url: server.url, path: path + '/localhost:' + servers[1].port, token: userAccessToken, - statusCodeExpected: HttpStatusCode.FORBIDDEN_403 + expectedStatus: HttpStatusCode.FORBIDDEN_403 }) }) @@ -468,7 +465,7 @@ describe('Test blocklist API validators', function () { url: server.url, path: path + '/localhost:9004', token: server.accessToken, - statusCodeExpected: HttpStatusCode.NOT_FOUND_404 + expectedStatus: HttpStatusCode.NOT_FOUND_404 }) }) @@ -477,7 +474,7 @@ describe('Test blocklist API validators', function () { url: server.url, path: path + '/localhost:' + servers[1].port, token: server.accessToken, - statusCodeExpected: HttpStatusCode.NO_CONTENT_204 + expectedStatus: HttpStatusCode.NO_CONTENT_204 }) }) }) diff --git a/server/tests/api/check-params/bulk.ts b/server/tests/api/check-params/bulk.ts index a660c3d80..bc9d7784d 100644 --- a/server/tests/api/check-params/bulk.ts +++ b/server/tests/api/check-params/bulk.ts @@ -1,14 +1,8 @@ /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */ import 'mocha' -import { - cleanupTests, - createSingleServer, - PeerTubeServer, - setAccessTokensToServers -} from '../../../../shared/extra-utils' -import { makePostBodyRequest } from '../../../../shared/extra-utils/requests/requests' -import { HttpStatusCode } from '../../../../shared/core-utils/miscs/http-error-codes' +import { cleanupTests, createSingleServer, makePostBodyRequest, PeerTubeServer, setAccessTokensToServers } from '@shared/extra-utils' +import { HttpStatusCode } from '@shared/models' describe('Test bulk API validators', function () { let server: PeerTubeServer @@ -36,7 +30,7 @@ describe('Test bulk API validators', function () { url: server.url, path, fields: { accountName: 'user1', scope: 'my-videos' }, - statusCodeExpected: HttpStatusCode.UNAUTHORIZED_401 + expectedStatus: HttpStatusCode.UNAUTHORIZED_401 }) }) @@ -46,7 +40,7 @@ describe('Test bulk API validators', function () { token: server.accessToken, path, fields: { accountName: 'user2', scope: 'my-videos' }, - statusCodeExpected: HttpStatusCode.NOT_FOUND_404 + expectedStatus: HttpStatusCode.NOT_FOUND_404 }) }) @@ -56,7 +50,7 @@ describe('Test bulk API validators', function () { token: server.accessToken, path, fields: { accountName: 'user1', scope: 'my-videoss' }, - statusCodeExpected: HttpStatusCode.BAD_REQUEST_400 + expectedStatus: HttpStatusCode.BAD_REQUEST_400 }) }) @@ -66,7 +60,7 @@ describe('Test bulk API validators', function () { token: userAccessToken, path, fields: { accountName: 'user1', scope: 'instance' }, - statusCodeExpected: HttpStatusCode.FORBIDDEN_403 + expectedStatus: HttpStatusCode.FORBIDDEN_403 }) }) @@ -76,7 +70,7 @@ describe('Test bulk API validators', function () { token: server.accessToken, path, fields: { accountName: 'user1', scope: 'instance' }, - statusCodeExpected: HttpStatusCode.NO_CONTENT_204 + expectedStatus: HttpStatusCode.NO_CONTENT_204 }) }) }) diff --git a/server/tests/api/check-params/config.ts b/server/tests/api/check-params/config.ts index 1756d58ee..c3438917e 100644 --- a/server/tests/api/check-params/config.ts +++ b/server/tests/api/check-params/config.ts @@ -2,7 +2,7 @@ import 'mocha' import { omit } from 'lodash' -import { HttpStatusCode } from '@shared/core-utils' +import { HttpStatusCode } from '@shared/models' import { cleanupTests, createSingleServer, @@ -214,7 +214,7 @@ describe('Test config API validators', function () { await makeGetRequest({ url: server.url, path, - statusCodeExpected: HttpStatusCode.UNAUTHORIZED_401 + expectedStatus: HttpStatusCode.UNAUTHORIZED_401 }) }) @@ -223,7 +223,7 @@ describe('Test config API validators', function () { url: server.url, path, token: userAccessToken, - statusCodeExpected: HttpStatusCode.FORBIDDEN_403 + expectedStatus: HttpStatusCode.FORBIDDEN_403 }) }) }) @@ -234,7 +234,7 @@ describe('Test config API validators', function () { url: server.url, path, fields: updateParams, - statusCodeExpected: HttpStatusCode.UNAUTHORIZED_401 + expectedStatus: HttpStatusCode.UNAUTHORIZED_401 }) }) @@ -244,7 +244,7 @@ describe('Test config API validators', function () { path, fields: updateParams, token: userAccessToken, - statusCodeExpected: HttpStatusCode.FORBIDDEN_403 + expectedStatus: HttpStatusCode.FORBIDDEN_403 }) }) @@ -256,7 +256,7 @@ describe('Test config API validators', function () { path, fields: newUpdateParams, token: server.accessToken, - statusCodeExpected: HttpStatusCode.BAD_REQUEST_400 + expectedStatus: HttpStatusCode.BAD_REQUEST_400 }) }) @@ -274,7 +274,7 @@ describe('Test config API validators', function () { path, fields: newUpdateParams, token: server.accessToken, - statusCodeExpected: HttpStatusCode.BAD_REQUEST_400 + expectedStatus: HttpStatusCode.BAD_REQUEST_400 }) }) @@ -295,7 +295,7 @@ describe('Test config API validators', function () { path, fields: newUpdateParams, token: server.accessToken, - statusCodeExpected: HttpStatusCode.BAD_REQUEST_400 + expectedStatus: HttpStatusCode.BAD_REQUEST_400 }) }) @@ -318,7 +318,7 @@ describe('Test config API validators', function () { path, fields: newUpdateParams, token: server.accessToken, - statusCodeExpected: HttpStatusCode.BAD_REQUEST_400 + expectedStatus: HttpStatusCode.BAD_REQUEST_400 }) }) @@ -328,7 +328,7 @@ describe('Test config API validators', function () { path, fields: updateParams, token: server.accessToken, - statusCodeExpected: HttpStatusCode.OK_200 + expectedStatus: HttpStatusCode.OK_200 }) }) }) @@ -338,7 +338,7 @@ describe('Test config API validators', function () { await makeDeleteRequest({ url: server.url, path, - statusCodeExpected: HttpStatusCode.UNAUTHORIZED_401 + expectedStatus: HttpStatusCode.UNAUTHORIZED_401 }) }) @@ -347,7 +347,7 @@ describe('Test config API validators', function () { url: server.url, path, token: userAccessToken, - statusCodeExpected: HttpStatusCode.FORBIDDEN_403 + expectedStatus: HttpStatusCode.FORBIDDEN_403 }) }) }) diff --git a/server/tests/api/check-params/contact-form.ts b/server/tests/api/check-params/contact-form.ts index 8c2b2a84b..8e755c69b 100644 --- a/server/tests/api/check-params/contact-form.ts +++ b/server/tests/api/check-params/contact-form.ts @@ -1,7 +1,7 @@ /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */ import 'mocha' -import { HttpStatusCode } from '@shared/core-utils' +import { HttpStatusCode } from '@shared/models' import { cleanupTests, createSingleServer, killallServers, MockSmtpServer, PeerTubeServer } from '@shared/extra-utils' import { ContactFormCommand } from '@shared/extra-utils/server' diff --git a/server/tests/api/check-params/custom-pages.ts b/server/tests/api/check-params/custom-pages.ts index 043505e32..9fbbea315 100644 --- a/server/tests/api/check-params/custom-pages.ts +++ b/server/tests/api/check-params/custom-pages.ts @@ -1,14 +1,15 @@ /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */ import 'mocha' -import { HttpStatusCode } from '../../../../shared/core-utils/miscs/http-error-codes' import { cleanupTests, createSingleServer, + makeGetRequest, + makePutBodyRequest, PeerTubeServer, setAccessTokensToServers -} from '../../../../shared/extra-utils' -import { makeGetRequest, makePutBodyRequest } from '../../../../shared/extra-utils/requests/requests' +} from '@shared/extra-utils' +import { HttpStatusCode } from '@shared/models' describe('Test custom pages validators', function () { const path = '/api/v1/custom-pages/homepage/instance' @@ -37,7 +38,7 @@ describe('Test custom pages validators', function () { url: server.url, path, fields: { content: 'super content' }, - statusCodeExpected: HttpStatusCode.UNAUTHORIZED_401 + expectedStatus: HttpStatusCode.UNAUTHORIZED_401 }) }) @@ -47,7 +48,7 @@ describe('Test custom pages validators', function () { path, token: userAccessToken, fields: { content: 'super content' }, - statusCodeExpected: HttpStatusCode.FORBIDDEN_403 + expectedStatus: HttpStatusCode.FORBIDDEN_403 }) }) @@ -57,7 +58,7 @@ describe('Test custom pages validators', function () { path, token: server.accessToken, fields: { content: 'super content' }, - statusCodeExpected: HttpStatusCode.NO_CONTENT_204 + expectedStatus: HttpStatusCode.NO_CONTENT_204 }) }) }) @@ -68,7 +69,7 @@ describe('Test custom pages validators', function () { await makeGetRequest({ url: server.url, path, - statusCodeExpected: HttpStatusCode.OK_200 + expectedStatus: HttpStatusCode.OK_200 }) }) }) diff --git a/server/tests/api/check-params/debug.ts b/server/tests/api/check-params/debug.ts index 9c13e9daf..a55786359 100644 --- a/server/tests/api/check-params/debug.ts +++ b/server/tests/api/check-params/debug.ts @@ -1,15 +1,8 @@ /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */ import 'mocha' - -import { - cleanupTests, - createSingleServer, - PeerTubeServer, - setAccessTokensToServers -} from '../../../../shared/extra-utils' -import { makeGetRequest } from '../../../../shared/extra-utils/requests/requests' -import { HttpStatusCode } from '../../../../shared/core-utils/miscs/http-error-codes' +import { cleanupTests, createSingleServer, makeGetRequest, PeerTubeServer, setAccessTokensToServers } from '@shared/extra-utils' +import { HttpStatusCode } from '@shared/models' describe('Test debug API validators', function () { const path = '/api/v1/server/debug' @@ -39,7 +32,7 @@ describe('Test debug API validators', function () { await makeGetRequest({ url: server.url, path, - statusCodeExpected: HttpStatusCode.UNAUTHORIZED_401 + expectedStatus: HttpStatusCode.UNAUTHORIZED_401 }) }) @@ -48,7 +41,7 @@ describe('Test debug API validators', function () { url: server.url, path, token: userAccessToken, - statusCodeExpected: HttpStatusCode.FORBIDDEN_403 + expectedStatus: HttpStatusCode.FORBIDDEN_403 }) }) @@ -58,7 +51,7 @@ describe('Test debug API validators', function () { path, token: server.accessToken, query: { startDate: new Date().toISOString() }, - statusCodeExpected: HttpStatusCode.OK_200 + expectedStatus: HttpStatusCode.OK_200 }) }) }) diff --git a/server/tests/api/check-params/follows.ts b/server/tests/api/check-params/follows.ts index 0fd2b4925..dfe3f226d 100644 --- a/server/tests/api/check-params/follows.ts +++ b/server/tests/api/check-params/follows.ts @@ -1,21 +1,19 @@ /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */ import 'mocha' - import { + checkBadCountPagination, + checkBadSortPagination, + checkBadStartPagination, cleanupTests, createSingleServer, - makeDeleteRequest, makeGetRequest, + makeDeleteRequest, + makeGetRequest, makePostBodyRequest, PeerTubeServer, setAccessTokensToServers -} from '../../../../shared/extra-utils' -import { - checkBadCountPagination, - checkBadSortPagination, - checkBadStartPagination -} from '../../../../shared/extra-utils/requests/check-api-params' -import { HttpStatusCode } from '../../../../shared/core-utils/miscs/http-error-codes' +} from '@shared/extra-utils' +import { HttpStatusCode } from '@shared/models' describe('Test server follows API validators', function () { let server: PeerTubeServer @@ -51,7 +49,7 @@ describe('Test server follows API validators', function () { url: server.url, path, token: server.accessToken, - statusCodeExpected: HttpStatusCode.BAD_REQUEST_400 + expectedStatus: HttpStatusCode.BAD_REQUEST_400 }) }) @@ -61,7 +59,7 @@ describe('Test server follows API validators', function () { path, token: server.accessToken, fields: { hosts: 'localhost:9002' }, - statusCodeExpected: HttpStatusCode.BAD_REQUEST_400 + expectedStatus: HttpStatusCode.BAD_REQUEST_400 }) }) @@ -71,7 +69,7 @@ describe('Test server follows API validators', function () { path, fields: { hosts: [ 'localhost:9002', 'localhost:coucou' ] }, token: server.accessToken, - statusCodeExpected: HttpStatusCode.BAD_REQUEST_400 + expectedStatus: HttpStatusCode.BAD_REQUEST_400 }) }) @@ -81,7 +79,7 @@ describe('Test server follows API validators', function () { path, fields: { hosts: [ 'localhost:9002', 'http://localhost:9003' ] }, token: server.accessToken, - statusCodeExpected: HttpStatusCode.BAD_REQUEST_400 + expectedStatus: HttpStatusCode.BAD_REQUEST_400 }) }) @@ -91,7 +89,7 @@ describe('Test server follows API validators', function () { path, fields: { urls: [ 'localhost:9002', 'localhost:9002' ] }, token: server.accessToken, - statusCodeExpected: HttpStatusCode.BAD_REQUEST_400 + expectedStatus: HttpStatusCode.BAD_REQUEST_400 }) }) @@ -101,7 +99,7 @@ describe('Test server follows API validators', function () { path, fields: { hosts: [ 'localhost:9002' ] }, token: 'fake_token', - statusCodeExpected: HttpStatusCode.UNAUTHORIZED_401 + expectedStatus: HttpStatusCode.UNAUTHORIZED_401 }) }) @@ -111,7 +109,7 @@ describe('Test server follows API validators', function () { path, fields: { hosts: [ 'localhost:9002' ] }, token: userAccessToken, - statusCodeExpected: HttpStatusCode.FORBIDDEN_403 + expectedStatus: HttpStatusCode.FORBIDDEN_403 }) }) }) @@ -155,7 +153,7 @@ describe('Test server follows API validators', function () { await makeGetRequest({ url: server.url, path, - statusCodeExpected: HttpStatusCode.OK_200, + expectedStatus: HttpStatusCode.OK_200, query: { state: 'accepted', actorType: 'Application' @@ -204,7 +202,7 @@ describe('Test server follows API validators', function () { await makeGetRequest({ url: server.url, path, - statusCodeExpected: HttpStatusCode.OK_200, + expectedStatus: HttpStatusCode.OK_200, query: { state: 'accepted' } @@ -220,7 +218,7 @@ describe('Test server follows API validators', function () { url: server.url, path: path + '/toto@localhost:9002', token: 'fake_token', - statusCodeExpected: HttpStatusCode.UNAUTHORIZED_401 + expectedStatus: HttpStatusCode.UNAUTHORIZED_401 }) }) @@ -229,7 +227,7 @@ describe('Test server follows API validators', function () { url: server.url, path: path + '/toto@localhost:9002', token: userAccessToken, - statusCodeExpected: HttpStatusCode.FORBIDDEN_403 + expectedStatus: HttpStatusCode.FORBIDDEN_403 }) }) @@ -238,7 +236,7 @@ describe('Test server follows API validators', function () { url: server.url, path: path + '/toto', token: server.accessToken, - statusCodeExpected: HttpStatusCode.BAD_REQUEST_400 + expectedStatus: HttpStatusCode.BAD_REQUEST_400 }) }) @@ -247,7 +245,7 @@ describe('Test server follows API validators', function () { url: server.url, path: path + '/toto@localhost:9003', token: server.accessToken, - statusCodeExpected: HttpStatusCode.NOT_FOUND_404 + expectedStatus: HttpStatusCode.NOT_FOUND_404 }) }) }) @@ -260,7 +258,7 @@ describe('Test server follows API validators', function () { url: server.url, path: path + '/toto@localhost:9002/accept', token: 'fake_token', - statusCodeExpected: HttpStatusCode.UNAUTHORIZED_401 + expectedStatus: HttpStatusCode.UNAUTHORIZED_401 }) }) @@ -269,7 +267,7 @@ describe('Test server follows API validators', function () { url: server.url, path: path + '/toto@localhost:9002/accept', token: userAccessToken, - statusCodeExpected: HttpStatusCode.FORBIDDEN_403 + expectedStatus: HttpStatusCode.FORBIDDEN_403 }) }) @@ -278,7 +276,7 @@ describe('Test server follows API validators', function () { url: server.url, path: path + '/toto/accept', token: server.accessToken, - statusCodeExpected: HttpStatusCode.BAD_REQUEST_400 + expectedStatus: HttpStatusCode.BAD_REQUEST_400 }) }) @@ -287,7 +285,7 @@ describe('Test server follows API validators', function () { url: server.url, path: path + '/toto@localhost:9003/accept', token: server.accessToken, - statusCodeExpected: HttpStatusCode.NOT_FOUND_404 + expectedStatus: HttpStatusCode.NOT_FOUND_404 }) }) }) @@ -300,7 +298,7 @@ describe('Test server follows API validators', function () { url: server.url, path: path + '/toto@localhost:9002/reject', token: 'fake_token', - statusCodeExpected: HttpStatusCode.UNAUTHORIZED_401 + expectedStatus: HttpStatusCode.UNAUTHORIZED_401 }) }) @@ -309,7 +307,7 @@ describe('Test server follows API validators', function () { url: server.url, path: path + '/toto@localhost:9002/reject', token: userAccessToken, - statusCodeExpected: HttpStatusCode.FORBIDDEN_403 + expectedStatus: HttpStatusCode.FORBIDDEN_403 }) }) @@ -318,7 +316,7 @@ describe('Test server follows API validators', function () { url: server.url, path: path + '/toto/reject', token: server.accessToken, - statusCodeExpected: HttpStatusCode.BAD_REQUEST_400 + expectedStatus: HttpStatusCode.BAD_REQUEST_400 }) }) @@ -327,7 +325,7 @@ describe('Test server follows API validators', function () { url: server.url, path: path + '/toto@localhost:9003/reject', token: server.accessToken, - statusCodeExpected: HttpStatusCode.NOT_FOUND_404 + expectedStatus: HttpStatusCode.NOT_FOUND_404 }) }) }) @@ -340,7 +338,7 @@ describe('Test server follows API validators', function () { url: server.url, path: path + '/localhost:9002', token: 'fake_token', - statusCodeExpected: HttpStatusCode.UNAUTHORIZED_401 + expectedStatus: HttpStatusCode.UNAUTHORIZED_401 }) }) @@ -349,7 +347,7 @@ describe('Test server follows API validators', function () { url: server.url, path: path + '/localhost:9002', token: userAccessToken, - statusCodeExpected: HttpStatusCode.FORBIDDEN_403 + expectedStatus: HttpStatusCode.FORBIDDEN_403 }) }) @@ -358,7 +356,7 @@ describe('Test server follows API validators', function () { url: server.url, path: path + '/example.com', token: server.accessToken, - statusCodeExpected: HttpStatusCode.NOT_FOUND_404 + expectedStatus: HttpStatusCode.NOT_FOUND_404 }) }) }) diff --git a/server/tests/api/check-params/jobs.ts b/server/tests/api/check-params/jobs.ts index a370ec2d3..23d95d8e4 100644 --- a/server/tests/api/check-params/jobs.ts +++ b/server/tests/api/check-params/jobs.ts @@ -1,20 +1,17 @@ /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */ import 'mocha' - import { + checkBadCountPagination, + checkBadSortPagination, + checkBadStartPagination, cleanupTests, createSingleServer, + makeGetRequest, PeerTubeServer, setAccessTokensToServers -} from '../../../../shared/extra-utils' -import { - checkBadCountPagination, - checkBadSortPagination, - checkBadStartPagination -} from '../../../../shared/extra-utils/requests/check-api-params' -import { makeGetRequest } from '../../../../shared/extra-utils/requests/requests' -import { HttpStatusCode } from '../../../../shared/core-utils/miscs/http-error-codes' +} from '@shared/extra-utils' +import { HttpStatusCode } from '@shared/models' describe('Test jobs API validators', function () { const path = '/api/v1/jobs/failed' @@ -75,7 +72,7 @@ describe('Test jobs API validators', function () { await makeGetRequest({ url: server.url, path, - statusCodeExpected: HttpStatusCode.UNAUTHORIZED_401 + expectedStatus: HttpStatusCode.UNAUTHORIZED_401 }) }) @@ -84,7 +81,7 @@ describe('Test jobs API validators', function () { url: server.url, path, token: userAccessToken, - statusCodeExpected: HttpStatusCode.FORBIDDEN_403 + expectedStatus: HttpStatusCode.FORBIDDEN_403 }) }) diff --git a/server/tests/api/check-params/live.ts b/server/tests/api/check-params/live.ts index eb5cdd1d8..0ef86a538 100644 --- a/server/tests/api/check-params/live.ts +++ b/server/tests/api/check-params/live.ts @@ -2,7 +2,7 @@ import 'mocha' import { omit } from 'lodash' -import { HttpStatusCode } from '@shared/core-utils' +import { HttpStatusCode } from '@shared/models' import { buildAbsoluteFixturePath, cleanupTests, @@ -223,7 +223,7 @@ describe('Test video lives API validator', function () { path, token: server.accessToken, fields: baseCorrectParams, - statusCodeExpected: HttpStatusCode.OK_200 + expectedStatus: HttpStatusCode.OK_200 }) video = res.body.video @@ -243,7 +243,7 @@ describe('Test video lives API validator', function () { path, token: server.accessToken, fields: baseCorrectParams, - statusCodeExpected: HttpStatusCode.FORBIDDEN_403 + expectedStatus: HttpStatusCode.FORBIDDEN_403 }) }) @@ -264,7 +264,7 @@ describe('Test video lives API validator', function () { path, token: server.accessToken, fields, - statusCodeExpected: HttpStatusCode.FORBIDDEN_403 + expectedStatus: HttpStatusCode.FORBIDDEN_403 }) }) @@ -285,7 +285,7 @@ describe('Test video lives API validator', function () { path, token: server.accessToken, fields, - statusCodeExpected: HttpStatusCode.OK_200 + expectedStatus: HttpStatusCode.OK_200 }) }) @@ -304,7 +304,7 @@ describe('Test video lives API validator', function () { path, token: server.accessToken, fields: baseCorrectParams, - statusCodeExpected: HttpStatusCode.FORBIDDEN_403 + expectedStatus: HttpStatusCode.FORBIDDEN_403 }) }) @@ -324,7 +324,7 @@ describe('Test video lives API validator', function () { path, token: server.accessToken, fields: baseCorrectParams, - statusCodeExpected: HttpStatusCode.FORBIDDEN_403 + expectedStatus: HttpStatusCode.FORBIDDEN_403 }) }) }) diff --git a/server/tests/api/check-params/logs.ts b/server/tests/api/check-params/logs.ts index 2eb074007..05372257a 100644 --- a/server/tests/api/check-params/logs.ts +++ b/server/tests/api/check-params/logs.ts @@ -1,15 +1,8 @@ /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */ import 'mocha' - -import { - cleanupTests, - createSingleServer, - PeerTubeServer, - setAccessTokensToServers -} from '../../../../shared/extra-utils' -import { makeGetRequest } from '../../../../shared/extra-utils/requests/requests' -import { HttpStatusCode } from '../../../../shared/core-utils/miscs/http-error-codes' +import { cleanupTests, createSingleServer, makeGetRequest, PeerTubeServer, setAccessTokensToServers } from '@shared/extra-utils' +import { HttpStatusCode } from '@shared/models' describe('Test logs API validators', function () { const path = '/api/v1/server/logs' @@ -39,7 +32,7 @@ describe('Test logs API validators', function () { await makeGetRequest({ url: server.url, path, - statusCodeExpected: HttpStatusCode.UNAUTHORIZED_401 + expectedStatus: HttpStatusCode.UNAUTHORIZED_401 }) }) @@ -48,7 +41,7 @@ describe('Test logs API validators', function () { url: server.url, path, token: userAccessToken, - statusCodeExpected: HttpStatusCode.FORBIDDEN_403 + expectedStatus: HttpStatusCode.FORBIDDEN_403 }) }) @@ -57,7 +50,7 @@ describe('Test logs API validators', function () { url: server.url, path, token: server.accessToken, - statusCodeExpected: HttpStatusCode.BAD_REQUEST_400 + expectedStatus: HttpStatusCode.BAD_REQUEST_400 }) }) @@ -67,7 +60,7 @@ describe('Test logs API validators', function () { path, token: server.accessToken, query: { startDate: 'toto' }, - statusCodeExpected: HttpStatusCode.BAD_REQUEST_400 + expectedStatus: HttpStatusCode.BAD_REQUEST_400 }) }) @@ -77,7 +70,7 @@ describe('Test logs API validators', function () { path, token: server.accessToken, query: { startDate: new Date().toISOString(), endDate: 'toto' }, - statusCodeExpected: HttpStatusCode.BAD_REQUEST_400 + expectedStatus: HttpStatusCode.BAD_REQUEST_400 }) }) @@ -87,7 +80,7 @@ describe('Test logs API validators', function () { path, token: server.accessToken, query: { startDate: new Date().toISOString(), level: 'toto' }, - statusCodeExpected: HttpStatusCode.BAD_REQUEST_400 + expectedStatus: HttpStatusCode.BAD_REQUEST_400 }) }) @@ -97,7 +90,7 @@ describe('Test logs API validators', function () { path, token: server.accessToken, query: { startDate: new Date().toISOString() }, - statusCodeExpected: HttpStatusCode.OK_200 + expectedStatus: HttpStatusCode.OK_200 }) }) }) diff --git a/server/tests/api/check-params/plugins.ts b/server/tests/api/check-params/plugins.ts index 2b471ee7d..d3dda7fce 100644 --- a/server/tests/api/check-params/plugins.ts +++ b/server/tests/api/check-params/plugins.ts @@ -1,7 +1,7 @@ /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */ import 'mocha' -import { HttpStatusCode } from '@shared/core-utils' +import { HttpStatusCode } from '@shared/models' import { checkBadCountPagination, checkBadSortPagination, @@ -70,7 +70,7 @@ describe('Test server plugins API validators', function () { ] for (const p of paths) { - await makeGetRequest({ url: server.url, path: p, statusCodeExpected: HttpStatusCode.NOT_FOUND_404 }) + await makeGetRequest({ url: server.url, path: p, expectedStatus: HttpStatusCode.NOT_FOUND_404 }) } }) @@ -78,7 +78,7 @@ describe('Test server plugins API validators', function () { await makeGetRequest({ url: server.url, path: '/themes/' + pluginName + '/' + npmVersion + '/static/images/chocobo.png', - statusCodeExpected: HttpStatusCode.NOT_FOUND_404 + expectedStatus: HttpStatusCode.NOT_FOUND_404 }) }) @@ -93,7 +93,7 @@ describe('Test server plugins API validators', function () { ] for (const p of paths) { - await makeGetRequest({ url: server.url, path: p, statusCodeExpected: HttpStatusCode.BAD_REQUEST_400 }) + await makeGetRequest({ url: server.url, path: p, expectedStatus: HttpStatusCode.BAD_REQUEST_400 }) } }) @@ -107,14 +107,14 @@ describe('Test server plugins API validators', function () { ] for (const p of paths) { - await makeGetRequest({ url: server.url, path: p, statusCodeExpected: HttpStatusCode.BAD_REQUEST_400 }) + await makeGetRequest({ url: server.url, path: p, expectedStatus: HttpStatusCode.BAD_REQUEST_400 }) } }) it('Should fail with an unknown auth name', async function () { const path = '/plugins/' + pluginName + '/' + npmVersion + '/auth/bad-auth' - await makeGetRequest({ url: server.url, path, statusCodeExpected: HttpStatusCode.NOT_FOUND_404 }) + await makeGetRequest({ url: server.url, path, expectedStatus: HttpStatusCode.NOT_FOUND_404 }) }) it('Should fail with an unknown static file', async function () { @@ -126,7 +126,7 @@ describe('Test server plugins API validators', function () { ] for (const p of paths) { - await makeGetRequest({ url: server.url, path: p, statusCodeExpected: HttpStatusCode.NOT_FOUND_404 }) + await makeGetRequest({ url: server.url, path: p, expectedStatus: HttpStatusCode.NOT_FOUND_404 }) } }) @@ -134,7 +134,7 @@ describe('Test server plugins API validators', function () { await makeGetRequest({ url: server.url, path: '/themes/' + themeName + '/' + themeVersion + '/css/assets/fake.css', - statusCodeExpected: HttpStatusCode.NOT_FOUND_404 + expectedStatus: HttpStatusCode.NOT_FOUND_404 }) }) @@ -148,11 +148,11 @@ describe('Test server plugins API validators', function () { ] for (const p of paths) { - await makeGetRequest({ url: server.url, path: p, statusCodeExpected: HttpStatusCode.OK_200 }) + await makeGetRequest({ url: server.url, path: p, expectedStatus: HttpStatusCode.OK_200 }) } const authPath = '/plugins/' + pluginName + '/' + npmVersion + '/auth/fake-auth' - await makeGetRequest({ url: server.url, path: authPath, statusCodeExpected: HttpStatusCode.FOUND_302 }) + await makeGetRequest({ url: server.url, path: authPath, expectedStatus: HttpStatusCode.FOUND_302 }) }) }) @@ -170,7 +170,7 @@ describe('Test server plugins API validators', function () { path, token: 'fake_token', query: baseQuery, - statusCodeExpected: HttpStatusCode.UNAUTHORIZED_401 + expectedStatus: HttpStatusCode.UNAUTHORIZED_401 }) }) @@ -180,7 +180,7 @@ describe('Test server plugins API validators', function () { path, token: userAccessToken, query: baseQuery, - statusCodeExpected: HttpStatusCode.FORBIDDEN_403 + expectedStatus: HttpStatusCode.FORBIDDEN_403 }) }) @@ -224,7 +224,7 @@ describe('Test server plugins API validators', function () { path, token: server.accessToken, query: baseQuery, - statusCodeExpected: HttpStatusCode.OK_200 + expectedStatus: HttpStatusCode.OK_200 }) }) }) @@ -241,7 +241,7 @@ describe('Test server plugins API validators', function () { path, token: 'fake_token', query: baseQuery, - statusCodeExpected: HttpStatusCode.UNAUTHORIZED_401 + expectedStatus: HttpStatusCode.UNAUTHORIZED_401 }) }) @@ -251,7 +251,7 @@ describe('Test server plugins API validators', function () { path, token: userAccessToken, query: baseQuery, - statusCodeExpected: HttpStatusCode.FORBIDDEN_403 + expectedStatus: HttpStatusCode.FORBIDDEN_403 }) }) @@ -284,7 +284,7 @@ describe('Test server plugins API validators', function () { path, token: server.accessToken, query: baseQuery, - statusCodeExpected: HttpStatusCode.OK_200 + expectedStatus: HttpStatusCode.OK_200 }) }) }) @@ -298,7 +298,7 @@ describe('Test server plugins API validators', function () { url: server.url, path: path + suffix, token: 'fake_token', - statusCodeExpected: HttpStatusCode.UNAUTHORIZED_401 + expectedStatus: HttpStatusCode.UNAUTHORIZED_401 }) } }) @@ -309,7 +309,7 @@ describe('Test server plugins API validators', function () { url: server.url, path: path + suffix, token: userAccessToken, - statusCodeExpected: HttpStatusCode.FORBIDDEN_403 + expectedStatus: HttpStatusCode.FORBIDDEN_403 }) } }) @@ -320,7 +320,7 @@ describe('Test server plugins API validators', function () { url: server.url, path: path + suffix, token: server.accessToken, - statusCodeExpected: HttpStatusCode.BAD_REQUEST_400 + expectedStatus: HttpStatusCode.BAD_REQUEST_400 }) } @@ -329,7 +329,7 @@ describe('Test server plugins API validators', function () { url: server.url, path: path + suffix, token: server.accessToken, - statusCodeExpected: HttpStatusCode.BAD_REQUEST_400 + expectedStatus: HttpStatusCode.BAD_REQUEST_400 }) } }) @@ -340,7 +340,7 @@ describe('Test server plugins API validators', function () { url: server.url, path: path + suffix, token: server.accessToken, - statusCodeExpected: HttpStatusCode.NOT_FOUND_404 + expectedStatus: HttpStatusCode.NOT_FOUND_404 }) } }) @@ -351,7 +351,7 @@ describe('Test server plugins API validators', function () { url: server.url, path: path + suffix, token: server.accessToken, - statusCodeExpected: HttpStatusCode.OK_200 + expectedStatus: HttpStatusCode.OK_200 }) } }) @@ -367,7 +367,7 @@ describe('Test server plugins API validators', function () { path: path + npmPlugin + '/settings', fields: { settings }, token: 'fake_token', - statusCodeExpected: HttpStatusCode.UNAUTHORIZED_401 + expectedStatus: HttpStatusCode.UNAUTHORIZED_401 }) }) @@ -377,7 +377,7 @@ describe('Test server plugins API validators', function () { path: path + npmPlugin + '/settings', fields: { settings }, token: userAccessToken, - statusCodeExpected: HttpStatusCode.FORBIDDEN_403 + expectedStatus: HttpStatusCode.FORBIDDEN_403 }) }) @@ -387,7 +387,7 @@ describe('Test server plugins API validators', function () { path: path + 'toto/settings', fields: { settings }, token: server.accessToken, - statusCodeExpected: HttpStatusCode.BAD_REQUEST_400 + expectedStatus: HttpStatusCode.BAD_REQUEST_400 }) await makePutBodyRequest({ @@ -395,7 +395,7 @@ describe('Test server plugins API validators', function () { path: path + 'peertube-plugin-TOTO/settings', fields: { settings }, token: server.accessToken, - statusCodeExpected: HttpStatusCode.BAD_REQUEST_400 + expectedStatus: HttpStatusCode.BAD_REQUEST_400 }) }) @@ -405,7 +405,7 @@ describe('Test server plugins API validators', function () { path: path + 'peertube-plugin-toto/settings', fields: { settings }, token: server.accessToken, - statusCodeExpected: HttpStatusCode.NOT_FOUND_404 + expectedStatus: HttpStatusCode.NOT_FOUND_404 }) }) @@ -415,7 +415,7 @@ describe('Test server plugins API validators', function () { path: path + npmPlugin + '/settings', fields: { settings }, token: server.accessToken, - statusCodeExpected: HttpStatusCode.NO_CONTENT_204 + expectedStatus: HttpStatusCode.NO_CONTENT_204 }) }) }) @@ -430,7 +430,7 @@ describe('Test server plugins API validators', function () { path: path + suffix, fields: { npmName: npmPlugin }, token: 'fake_token', - statusCodeExpected: HttpStatusCode.UNAUTHORIZED_401 + expectedStatus: HttpStatusCode.UNAUTHORIZED_401 }) } }) @@ -442,7 +442,7 @@ describe('Test server plugins API validators', function () { path: path + suffix, fields: { npmName: npmPlugin }, token: userAccessToken, - statusCodeExpected: HttpStatusCode.FORBIDDEN_403 + expectedStatus: HttpStatusCode.FORBIDDEN_403 }) } }) @@ -454,7 +454,7 @@ describe('Test server plugins API validators', function () { path: path + suffix, fields: { npmName: 'toto' }, token: server.accessToken, - statusCodeExpected: HttpStatusCode.BAD_REQUEST_400 + expectedStatus: HttpStatusCode.BAD_REQUEST_400 }) } @@ -464,7 +464,7 @@ describe('Test server plugins API validators', function () { path: path + suffix, fields: { npmName: 'peertube-plugin-TOTO' }, token: server.accessToken, - statusCodeExpected: HttpStatusCode.BAD_REQUEST_400 + expectedStatus: HttpStatusCode.BAD_REQUEST_400 }) } }) @@ -484,7 +484,7 @@ describe('Test server plugins API validators', function () { path: path + obj.suffix, fields: { npmName: npmPlugin }, token: server.accessToken, - statusCodeExpected: obj.status + expectedStatus: obj.status }) } }) diff --git a/server/tests/api/check-params/redundancy.ts b/server/tests/api/check-params/redundancy.ts index 18b98a0f9..d9f905549 100644 --- a/server/tests/api/check-params/redundancy.ts +++ b/server/tests/api/check-params/redundancy.ts @@ -1,15 +1,13 @@ /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */ import 'mocha' -import { VideoCreateResult } from '@shared/models' -import { HttpStatusCode } from '../../../../shared/core-utils/miscs/http-error-codes' import { checkBadCountPagination, checkBadSortPagination, checkBadStartPagination, cleanupTests, - doubleFollow, createMultipleServers, + doubleFollow, makeDeleteRequest, makeGetRequest, makePostBodyRequest, @@ -17,7 +15,8 @@ import { PeerTubeServer, setAccessTokensToServers, waitJobs -} from '../../../../shared/extra-utils' +} from '@shared/extra-utils' +import { HttpStatusCode, VideoCreateResult } from '@shared/models' describe('Test server redundancy API validators', function () { let servers: PeerTubeServer[] @@ -64,11 +63,11 @@ describe('Test server redundancy API validators', function () { }) it('Should fail with an invalid token', async function () { - await makeGetRequest({ url, path, token: 'fake_token', statusCodeExpected: HttpStatusCode.UNAUTHORIZED_401 }) + await makeGetRequest({ url, path, token: 'fake_token', expectedStatus: HttpStatusCode.UNAUTHORIZED_401 }) }) it('Should fail if the user is not an administrator', async function () { - await makeGetRequest({ url, path, token: userAccessToken, statusCodeExpected: HttpStatusCode.FORBIDDEN_403 }) + await makeGetRequest({ url, path, token: userAccessToken, expectedStatus: HttpStatusCode.FORBIDDEN_403 }) }) it('Should fail with a bad start pagination', async function () { @@ -92,7 +91,7 @@ describe('Test server redundancy API validators', function () { }) it('Should succeed with the correct params', async function () { - await makeGetRequest({ url, path, token, query: { target: 'my-videos' }, statusCodeExpected: HttpStatusCode.OK_200 }) + await makeGetRequest({ url, path, token, query: { target: 'my-videos' }, expectedStatus: HttpStatusCode.OK_200 }) }) }) @@ -108,11 +107,11 @@ describe('Test server redundancy API validators', function () { }) it('Should fail with an invalid token', async function () { - await makePostBodyRequest({ url, path, token: 'fake_token', statusCodeExpected: HttpStatusCode.UNAUTHORIZED_401 }) + await makePostBodyRequest({ url, path, token: 'fake_token', expectedStatus: HttpStatusCode.UNAUTHORIZED_401 }) }) it('Should fail if the user is not an administrator', async function () { - await makePostBodyRequest({ url, path, token: userAccessToken, statusCodeExpected: HttpStatusCode.FORBIDDEN_403 }) + await makePostBodyRequest({ url, path, token: userAccessToken, expectedStatus: HttpStatusCode.FORBIDDEN_403 }) }) it('Should fail without a video id', async function () { @@ -124,7 +123,7 @@ describe('Test server redundancy API validators', function () { }) it('Should fail with a not found video id', async function () { - await makePostBodyRequest({ url, path, token, fields: { videoId: 6565 }, statusCodeExpected: HttpStatusCode.NOT_FOUND_404 }) + await makePostBodyRequest({ url, path, token, fields: { videoId: 6565 }, expectedStatus: HttpStatusCode.NOT_FOUND_404 }) }) it('Should fail with a local a video id', async function () { @@ -137,7 +136,7 @@ describe('Test server redundancy API validators', function () { path, token, fields: { videoId: videoRemote.shortUUID }, - statusCodeExpected: HttpStatusCode.NO_CONTENT_204 + expectedStatus: HttpStatusCode.NO_CONTENT_204 }) }) @@ -151,7 +150,7 @@ describe('Test server redundancy API validators', function () { path, token, fields: { videoId: videoRemote.uuid }, - statusCodeExpected: HttpStatusCode.CONFLICT_409 + expectedStatus: HttpStatusCode.CONFLICT_409 }) }) }) @@ -168,11 +167,11 @@ describe('Test server redundancy API validators', function () { }) it('Should fail with an invalid token', async function () { - await makeDeleteRequest({ url, path: path + '1', token: 'fake_token', statusCodeExpected: HttpStatusCode.UNAUTHORIZED_401 }) + await makeDeleteRequest({ url, path: path + '1', token: 'fake_token', expectedStatus: HttpStatusCode.UNAUTHORIZED_401 }) }) it('Should fail if the user is not an administrator', async function () { - await makeDeleteRequest({ url, path: path + '1', token: userAccessToken, statusCodeExpected: HttpStatusCode.FORBIDDEN_403 }) + await makeDeleteRequest({ url, path: path + '1', token: userAccessToken, expectedStatus: HttpStatusCode.FORBIDDEN_403 }) }) it('Should fail with an incorrect video id', async function () { @@ -180,7 +179,7 @@ describe('Test server redundancy API validators', function () { }) it('Should fail with a not found video redundancy', async function () { - await makeDeleteRequest({ url, path: path + '454545', token, statusCodeExpected: HttpStatusCode.NOT_FOUND_404 }) + await makeDeleteRequest({ url, path: path + '454545', token, expectedStatus: HttpStatusCode.NOT_FOUND_404 }) }) }) @@ -193,7 +192,7 @@ describe('Test server redundancy API validators', function () { path: path + '/localhost:' + servers[1].port, fields: { redundancyAllowed: true }, token: 'fake_token', - statusCodeExpected: HttpStatusCode.UNAUTHORIZED_401 + expectedStatus: HttpStatusCode.UNAUTHORIZED_401 }) }) @@ -203,7 +202,7 @@ describe('Test server redundancy API validators', function () { path: path + '/localhost:' + servers[1].port, fields: { redundancyAllowed: true }, token: userAccessToken, - statusCodeExpected: HttpStatusCode.FORBIDDEN_403 + expectedStatus: HttpStatusCode.FORBIDDEN_403 }) }) @@ -213,7 +212,7 @@ describe('Test server redundancy API validators', function () { path: path + '/example.com', fields: { redundancyAllowed: true }, token: servers[0].accessToken, - statusCodeExpected: HttpStatusCode.NOT_FOUND_404 + expectedStatus: HttpStatusCode.NOT_FOUND_404 }) }) @@ -223,7 +222,7 @@ describe('Test server redundancy API validators', function () { path: path + '/localhost:' + servers[1].port, fields: { blabla: true }, token: servers[0].accessToken, - statusCodeExpected: HttpStatusCode.BAD_REQUEST_400 + expectedStatus: HttpStatusCode.BAD_REQUEST_400 }) }) @@ -233,7 +232,7 @@ describe('Test server redundancy API validators', function () { path: path + '/localhost:' + servers[1].port, fields: { redundancyAllowed: true }, token: servers[0].accessToken, - statusCodeExpected: HttpStatusCode.NO_CONTENT_204 + expectedStatus: HttpStatusCode.NO_CONTENT_204 }) }) }) diff --git a/server/tests/api/check-params/search.ts b/server/tests/api/check-params/search.ts index 43cd81af9..b49169e38 100644 --- a/server/tests/api/check-params/search.ts +++ b/server/tests/api/check-params/search.ts @@ -1,7 +1,7 @@ /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */ import 'mocha' -import { HttpStatusCode } from '@shared/core-utils' +import { HttpStatusCode } from '@shared/models' import { checkBadCountPagination, checkBadSortPagination, @@ -58,83 +58,83 @@ describe('Test videos API validator', function () { }) it('Should success with the correct parameters', async function () { - await makeGetRequest({ url: server.url, path, query, statusCodeExpected: HttpStatusCode.OK_200 }) + await makeGetRequest({ url: server.url, path, query, expectedStatus: HttpStatusCode.OK_200 }) }) it('Should fail with an invalid category', async function () { const customQuery1 = { ...query, categoryOneOf: [ 'aa', 'b' ] } - await makeGetRequest({ url: server.url, path, query: customQuery1, statusCodeExpected: HttpStatusCode.BAD_REQUEST_400 }) + await makeGetRequest({ url: server.url, path, query: customQuery1, expectedStatus: HttpStatusCode.BAD_REQUEST_400 }) const customQuery2 = { ...query, categoryOneOf: 'a' } - await makeGetRequest({ url: server.url, path, query: customQuery2, statusCodeExpected: HttpStatusCode.BAD_REQUEST_400 }) + await makeGetRequest({ url: server.url, path, query: customQuery2, expectedStatus: HttpStatusCode.BAD_REQUEST_400 }) }) it('Should succeed with a valid category', async function () { const customQuery1 = { ...query, categoryOneOf: [ 1, 7 ] } - await makeGetRequest({ url: server.url, path, query: customQuery1, statusCodeExpected: HttpStatusCode.OK_200 }) + await makeGetRequest({ url: server.url, path, query: customQuery1, expectedStatus: HttpStatusCode.OK_200 }) const customQuery2 = { ...query, categoryOneOf: 1 } - await makeGetRequest({ url: server.url, path, query: customQuery2, statusCodeExpected: HttpStatusCode.OK_200 }) + await makeGetRequest({ url: server.url, path, query: customQuery2, expectedStatus: HttpStatusCode.OK_200 }) }) it('Should fail with an invalid licence', async function () { const customQuery1 = { ...query, licenceOneOf: [ 'aa', 'b' ] } - await makeGetRequest({ url: server.url, path, query: customQuery1, statusCodeExpected: HttpStatusCode.BAD_REQUEST_400 }) + await makeGetRequest({ url: server.url, path, query: customQuery1, expectedStatus: HttpStatusCode.BAD_REQUEST_400 }) const customQuery2 = { ...query, licenceOneOf: 'a' } - await makeGetRequest({ url: server.url, path, query: customQuery2, statusCodeExpected: HttpStatusCode.BAD_REQUEST_400 }) + await makeGetRequest({ url: server.url, path, query: customQuery2, expectedStatus: HttpStatusCode.BAD_REQUEST_400 }) }) it('Should succeed with a valid licence', async function () { const customQuery1 = { ...query, licenceOneOf: [ 1, 2 ] } - await makeGetRequest({ url: server.url, path, query: customQuery1, statusCodeExpected: HttpStatusCode.OK_200 }) + await makeGetRequest({ url: server.url, path, query: customQuery1, expectedStatus: HttpStatusCode.OK_200 }) const customQuery2 = { ...query, licenceOneOf: 1 } - await makeGetRequest({ url: server.url, path, query: customQuery2, statusCodeExpected: HttpStatusCode.OK_200 }) + await makeGetRequest({ url: server.url, path, query: customQuery2, expectedStatus: HttpStatusCode.OK_200 }) }) it('Should succeed with a valid language', async function () { const customQuery1 = { ...query, languageOneOf: [ 'fr', 'en' ] } - await makeGetRequest({ url: server.url, path, query: customQuery1, statusCodeExpected: HttpStatusCode.OK_200 }) + await makeGetRequest({ url: server.url, path, query: customQuery1, expectedStatus: HttpStatusCode.OK_200 }) const customQuery2 = { ...query, languageOneOf: 'fr' } - await makeGetRequest({ url: server.url, path, query: customQuery2, statusCodeExpected: HttpStatusCode.OK_200 }) + await makeGetRequest({ url: server.url, path, query: customQuery2, expectedStatus: HttpStatusCode.OK_200 }) }) it('Should succeed with valid tags', async function () { const customQuery1 = { ...query, tagsOneOf: [ 'tag1', 'tag2' ] } - await makeGetRequest({ url: server.url, path, query: customQuery1, statusCodeExpected: HttpStatusCode.OK_200 }) + await makeGetRequest({ url: server.url, path, query: customQuery1, expectedStatus: HttpStatusCode.OK_200 }) const customQuery2 = { ...query, tagsOneOf: 'tag1' } - await makeGetRequest({ url: server.url, path, query: customQuery2, statusCodeExpected: HttpStatusCode.OK_200 }) + await makeGetRequest({ url: server.url, path, query: customQuery2, expectedStatus: HttpStatusCode.OK_200 }) const customQuery3 = { ...query, tagsAllOf: [ 'tag1', 'tag2' ] } - await makeGetRequest({ url: server.url, path, query: customQuery3, statusCodeExpected: HttpStatusCode.OK_200 }) + await makeGetRequest({ url: server.url, path, query: customQuery3, expectedStatus: HttpStatusCode.OK_200 }) const customQuery4 = { ...query, tagsAllOf: 'tag1' } - await makeGetRequest({ url: server.url, path, query: customQuery4, statusCodeExpected: HttpStatusCode.OK_200 }) + await makeGetRequest({ url: server.url, path, query: customQuery4, expectedStatus: HttpStatusCode.OK_200 }) }) it('Should fail with invalid durations', async function () { const customQuery1 = { ...query, durationMin: 'hello' } - await makeGetRequest({ url: server.url, path, query: customQuery1, statusCodeExpected: HttpStatusCode.BAD_REQUEST_400 }) + await makeGetRequest({ url: server.url, path, query: customQuery1, expectedStatus: HttpStatusCode.BAD_REQUEST_400 }) const customQuery2 = { ...query, durationMax: 'hello' } - await makeGetRequest({ url: server.url, path, query: customQuery2, statusCodeExpected: HttpStatusCode.BAD_REQUEST_400 }) + await makeGetRequest({ url: server.url, path, query: customQuery2, expectedStatus: HttpStatusCode.BAD_REQUEST_400 }) }) it('Should fail with invalid dates', async function () { const customQuery1 = { ...query, startDate: 'hello' } - await makeGetRequest({ url: server.url, path, query: customQuery1, statusCodeExpected: HttpStatusCode.BAD_REQUEST_400 }) + await makeGetRequest({ url: server.url, path, query: customQuery1, expectedStatus: HttpStatusCode.BAD_REQUEST_400 }) const customQuery2 = { ...query, endDate: 'hello' } - await makeGetRequest({ url: server.url, path, query: customQuery2, statusCodeExpected: HttpStatusCode.BAD_REQUEST_400 }) + await makeGetRequest({ url: server.url, path, query: customQuery2, expectedStatus: HttpStatusCode.BAD_REQUEST_400 }) const customQuery3 = { ...query, originallyPublishedStartDate: 'hello' } - await makeGetRequest({ url: server.url, path, query: customQuery3, statusCodeExpected: HttpStatusCode.BAD_REQUEST_400 }) + await makeGetRequest({ url: server.url, path, query: customQuery3, expectedStatus: HttpStatusCode.BAD_REQUEST_400 }) const customQuery4 = { ...query, originallyPublishedEndDate: 'hello' } - await makeGetRequest({ url: server.url, path, query: customQuery4, statusCodeExpected: HttpStatusCode.BAD_REQUEST_400 }) + await makeGetRequest({ url: server.url, path, query: customQuery4, expectedStatus: HttpStatusCode.BAD_REQUEST_400 }) }) }) @@ -158,7 +158,7 @@ describe('Test videos API validator', function () { }) it('Should success with the correct parameters', async function () { - await makeGetRequest({ url: server.url, path, query, statusCodeExpected: HttpStatusCode.OK_200 }) + await makeGetRequest({ url: server.url, path, query, expectedStatus: HttpStatusCode.OK_200 }) }) }) @@ -182,7 +182,7 @@ describe('Test videos API validator', function () { }) it('Should success with the correct parameters', async function () { - await makeGetRequest({ url: server.url, path, query, statusCodeExpected: HttpStatusCode.OK_200 }) + await makeGetRequest({ url: server.url, path, query, expectedStatus: HttpStatusCode.OK_200 }) }) }) @@ -201,41 +201,41 @@ describe('Test videos API validator', function () { for (const path of paths) { { const customQuery = { ...query, searchTarget: 'hello' } - await makeGetRequest({ url: server.url, path, query: customQuery, statusCodeExpected: HttpStatusCode.BAD_REQUEST_400 }) + await makeGetRequest({ url: server.url, path, query: customQuery, expectedStatus: HttpStatusCode.BAD_REQUEST_400 }) } { const customQuery = { ...query, searchTarget: undefined } - await makeGetRequest({ url: server.url, path, query: customQuery, statusCodeExpected: HttpStatusCode.OK_200 }) + await makeGetRequest({ url: server.url, path, query: customQuery, expectedStatus: HttpStatusCode.OK_200 }) } { const customQuery = { ...query, searchTarget: 'local' } - await makeGetRequest({ url: server.url, path, query: customQuery, statusCodeExpected: HttpStatusCode.OK_200 }) + await makeGetRequest({ url: server.url, path, query: customQuery, expectedStatus: HttpStatusCode.OK_200 }) } { const customQuery = { ...query, searchTarget: 'search-index' } - await makeGetRequest({ url: server.url, path, query: customQuery, statusCodeExpected: HttpStatusCode.BAD_REQUEST_400 }) + await makeGetRequest({ url: server.url, path, query: customQuery, expectedStatus: HttpStatusCode.BAD_REQUEST_400 }) } await updateSearchIndex(server, true, true) { const customQuery = { ...query, searchTarget: 'local' } - await makeGetRequest({ url: server.url, path, query: customQuery, statusCodeExpected: HttpStatusCode.BAD_REQUEST_400 }) + await makeGetRequest({ url: server.url, path, query: customQuery, expectedStatus: HttpStatusCode.BAD_REQUEST_400 }) } { const customQuery = { ...query, searchTarget: 'search-index' } - await makeGetRequest({ url: server.url, path, query: customQuery, statusCodeExpected: HttpStatusCode.OK_200 }) + await makeGetRequest({ url: server.url, path, query: customQuery, expectedStatus: HttpStatusCode.OK_200 }) } await updateSearchIndex(server, true, false) { const customQuery = { ...query, searchTarget: 'local' } - await makeGetRequest({ url: server.url, path, query: customQuery, statusCodeExpected: HttpStatusCode.OK_200 }) + await makeGetRequest({ url: server.url, path, query: customQuery, expectedStatus: HttpStatusCode.OK_200 }) } await updateSearchIndex(server, false, false) diff --git a/server/tests/api/check-params/services.ts b/server/tests/api/check-params/services.ts index c623240b7..973b25598 100644 --- a/server/tests/api/check-params/services.ts +++ b/server/tests/api/check-params/services.ts @@ -1,7 +1,7 @@ /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */ import 'mocha' -import { HttpStatusCode } from '@shared/core-utils' +import { HttpStatusCode } from '@shared/models' import { cleanupTests, createSingleServer, @@ -120,13 +120,13 @@ describe('Test services API validators', function () { }) }) -function checkParamEmbed (server: PeerTubeServer, embedUrl: string, statusCodeExpected = HttpStatusCode.BAD_REQUEST_400, query = {}) { +function checkParamEmbed (server: PeerTubeServer, embedUrl: string, expectedStatus = HttpStatusCode.BAD_REQUEST_400, query = {}) { const path = '/services/oembed' return makeGetRequest({ url: server.url, path, query: Object.assign(query, { url: embedUrl }), - statusCodeExpected + expectedStatus }) } diff --git a/server/tests/api/check-params/upload-quota.ts b/server/tests/api/check-params/upload-quota.ts index bd8dce975..322e93d0d 100644 --- a/server/tests/api/check-params/upload-quota.ts +++ b/server/tests/api/check-params/upload-quota.ts @@ -2,7 +2,7 @@ import 'mocha' import { expect } from 'chai' -import { HttpStatusCode, randomInt } from '@shared/core-utils' +import { randomInt } from '@shared/core-utils' import { cleanupTests, createSingleServer, @@ -13,7 +13,7 @@ import { VideosCommand, waitJobs } from '@shared/extra-utils' -import { VideoImportState, VideoPrivacy } from '@shared/models' +import { HttpStatusCode, VideoImportState, VideoPrivacy } from '@shared/models' describe('Test upload quota', function () { let server: PeerTubeServer diff --git a/server/tests/api/check-params/user-notifications.ts b/server/tests/api/check-params/user-notifications.ts index 038c444b3..3b709ee5a 100644 --- a/server/tests/api/check-params/user-notifications.ts +++ b/server/tests/api/check-params/user-notifications.ts @@ -2,7 +2,7 @@ import 'mocha' import { io } from 'socket.io-client' -import { HttpStatusCode } from '@shared/core-utils' +import { HttpStatusCode } from '@shared/models' import { checkBadCountPagination, checkBadSortPagination, @@ -54,7 +54,7 @@ describe('Test user notifications API validators', function () { unread: 'toto' }, token: server.accessToken, - statusCodeExpected: HttpStatusCode.OK_200 + expectedStatus: HttpStatusCode.OK_200 }) }) @@ -62,7 +62,7 @@ describe('Test user notifications API validators', function () { await makeGetRequest({ url: server.url, path, - statusCodeExpected: HttpStatusCode.UNAUTHORIZED_401 + expectedStatus: HttpStatusCode.UNAUTHORIZED_401 }) }) @@ -71,7 +71,7 @@ describe('Test user notifications API validators', function () { url: server.url, path, token: server.accessToken, - statusCodeExpected: HttpStatusCode.OK_200 + expectedStatus: HttpStatusCode.OK_200 }) }) }) @@ -87,7 +87,7 @@ describe('Test user notifications API validators', function () { ids: [ 'hello' ] }, token: server.accessToken, - statusCodeExpected: HttpStatusCode.BAD_REQUEST_400 + expectedStatus: HttpStatusCode.BAD_REQUEST_400 }) await makePostBodyRequest({ @@ -97,7 +97,7 @@ describe('Test user notifications API validators', function () { ids: [ ] }, token: server.accessToken, - statusCodeExpected: HttpStatusCode.BAD_REQUEST_400 + expectedStatus: HttpStatusCode.BAD_REQUEST_400 }) await makePostBodyRequest({ @@ -107,7 +107,7 @@ describe('Test user notifications API validators', function () { ids: 5 }, token: server.accessToken, - statusCodeExpected: HttpStatusCode.BAD_REQUEST_400 + expectedStatus: HttpStatusCode.BAD_REQUEST_400 }) }) @@ -118,7 +118,7 @@ describe('Test user notifications API validators', function () { fields: { ids: [ 5 ] }, - statusCodeExpected: HttpStatusCode.UNAUTHORIZED_401 + expectedStatus: HttpStatusCode.UNAUTHORIZED_401 }) }) @@ -130,7 +130,7 @@ describe('Test user notifications API validators', function () { ids: [ 5 ] }, token: server.accessToken, - statusCodeExpected: HttpStatusCode.NO_CONTENT_204 + expectedStatus: HttpStatusCode.NO_CONTENT_204 }) }) }) @@ -142,7 +142,7 @@ describe('Test user notifications API validators', function () { await makePostBodyRequest({ url: server.url, path, - statusCodeExpected: HttpStatusCode.UNAUTHORIZED_401 + expectedStatus: HttpStatusCode.UNAUTHORIZED_401 }) }) @@ -151,7 +151,7 @@ describe('Test user notifications API validators', function () { url: server.url, path, token: server.accessToken, - statusCodeExpected: HttpStatusCode.NO_CONTENT_204 + expectedStatus: HttpStatusCode.NO_CONTENT_204 }) }) }) @@ -183,7 +183,7 @@ describe('Test user notifications API validators', function () { path, token: server.accessToken, fields: { newVideoFromSubscription: UserNotificationSettingValue.WEB }, - statusCodeExpected: HttpStatusCode.BAD_REQUEST_400 + expectedStatus: HttpStatusCode.BAD_REQUEST_400 }) }) @@ -196,7 +196,7 @@ describe('Test user notifications API validators', function () { path, token: server.accessToken, fields, - statusCodeExpected: HttpStatusCode.BAD_REQUEST_400 + expectedStatus: HttpStatusCode.BAD_REQUEST_400 }) } @@ -208,7 +208,7 @@ describe('Test user notifications API validators', function () { path, fields, token: server.accessToken, - statusCodeExpected: HttpStatusCode.BAD_REQUEST_400 + expectedStatus: HttpStatusCode.BAD_REQUEST_400 }) } }) @@ -218,7 +218,7 @@ describe('Test user notifications API validators', function () { url: server.url, path, fields: correctFields, - statusCodeExpected: HttpStatusCode.UNAUTHORIZED_401 + expectedStatus: HttpStatusCode.UNAUTHORIZED_401 }) }) @@ -228,7 +228,7 @@ describe('Test user notifications API validators', function () { path, token: server.accessToken, fields: correctFields, - statusCodeExpected: HttpStatusCode.NO_CONTENT_204 + expectedStatus: HttpStatusCode.NO_CONTENT_204 }) }) }) diff --git a/server/tests/api/check-params/user-subscriptions.ts b/server/tests/api/check-params/user-subscriptions.ts index 22cf130c2..624069c80 100644 --- a/server/tests/api/check-params/user-subscriptions.ts +++ b/server/tests/api/check-params/user-subscriptions.ts @@ -1,24 +1,20 @@ /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */ import 'mocha' - import { + checkBadCountPagination, + checkBadSortPagination, + checkBadStartPagination, cleanupTests, createSingleServer, makeDeleteRequest, makeGetRequest, makePostBodyRequest, PeerTubeServer, - setAccessTokensToServers -} 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' + setAccessTokensToServers, + waitJobs +} from '@shared/extra-utils' +import { HttpStatusCode } from '@shared/models' describe('Test user subscriptions API validators', function () { const path = '/api/v1/users/me/subscriptions' @@ -59,7 +55,7 @@ describe('Test user subscriptions API validators', function () { await makeGetRequest({ url: server.url, path, - statusCodeExpected: HttpStatusCode.UNAUTHORIZED_401 + expectedStatus: HttpStatusCode.UNAUTHORIZED_401 }) }) @@ -68,7 +64,7 @@ describe('Test user subscriptions API validators', function () { url: server.url, path, token: userAccessToken, - statusCodeExpected: HttpStatusCode.OK_200 + expectedStatus: HttpStatusCode.OK_200 }) }) }) @@ -92,7 +88,7 @@ describe('Test user subscriptions API validators', function () { await makeGetRequest({ url: server.url, path, - statusCodeExpected: HttpStatusCode.UNAUTHORIZED_401 + expectedStatus: HttpStatusCode.UNAUTHORIZED_401 }) }) @@ -101,7 +97,7 @@ describe('Test user subscriptions API validators', function () { url: server.url, path, token: userAccessToken, - statusCodeExpected: HttpStatusCode.OK_200 + expectedStatus: HttpStatusCode.OK_200 }) }) }) @@ -112,7 +108,7 @@ describe('Test user subscriptions API validators', function () { url: server.url, path, fields: { uri: 'user1_channel@localhost:' + server.port }, - statusCodeExpected: HttpStatusCode.UNAUTHORIZED_401 + expectedStatus: HttpStatusCode.UNAUTHORIZED_401 }) }) @@ -122,7 +118,7 @@ describe('Test user subscriptions API validators', function () { path, token: server.accessToken, fields: { uri: 'root' }, - statusCodeExpected: HttpStatusCode.BAD_REQUEST_400 + expectedStatus: HttpStatusCode.BAD_REQUEST_400 }) await makePostBodyRequest({ @@ -130,7 +126,7 @@ describe('Test user subscriptions API validators', function () { path, token: server.accessToken, fields: { uri: 'root@' }, - statusCodeExpected: HttpStatusCode.BAD_REQUEST_400 + expectedStatus: HttpStatusCode.BAD_REQUEST_400 }) await makePostBodyRequest({ @@ -138,7 +134,7 @@ describe('Test user subscriptions API validators', function () { path, token: server.accessToken, fields: { uri: 'root@hello@' }, - statusCodeExpected: HttpStatusCode.BAD_REQUEST_400 + expectedStatus: HttpStatusCode.BAD_REQUEST_400 }) }) @@ -150,7 +146,7 @@ describe('Test user subscriptions API validators', function () { path, token: server.accessToken, fields: { uri: 'user1_channel@localhost:' + server.port }, - statusCodeExpected: HttpStatusCode.NO_CONTENT_204 + expectedStatus: HttpStatusCode.NO_CONTENT_204 }) await waitJobs([ server ]) @@ -162,7 +158,7 @@ describe('Test user subscriptions API validators', function () { await makeGetRequest({ url: server.url, path: path + '/user1_channel@localhost:' + server.port, - statusCodeExpected: HttpStatusCode.UNAUTHORIZED_401 + expectedStatus: HttpStatusCode.UNAUTHORIZED_401 }) }) @@ -171,21 +167,21 @@ describe('Test user subscriptions API validators', function () { url: server.url, path: path + '/root', token: server.accessToken, - statusCodeExpected: HttpStatusCode.BAD_REQUEST_400 + expectedStatus: HttpStatusCode.BAD_REQUEST_400 }) await makeGetRequest({ url: server.url, path: path + '/root@', token: server.accessToken, - statusCodeExpected: HttpStatusCode.BAD_REQUEST_400 + expectedStatus: HttpStatusCode.BAD_REQUEST_400 }) await makeGetRequest({ url: server.url, path: path + '/root@hello@', token: server.accessToken, - statusCodeExpected: HttpStatusCode.BAD_REQUEST_400 + expectedStatus: HttpStatusCode.BAD_REQUEST_400 }) }) @@ -194,7 +190,7 @@ describe('Test user subscriptions API validators', function () { url: server.url, path: path + '/root1@localhost:' + server.port, token: server.accessToken, - statusCodeExpected: HttpStatusCode.NOT_FOUND_404 + expectedStatus: HttpStatusCode.NOT_FOUND_404 }) }) @@ -203,7 +199,7 @@ describe('Test user subscriptions API validators', function () { url: server.url, path: path + '/user1_channel@localhost:' + server.port, token: server.accessToken, - statusCodeExpected: HttpStatusCode.OK_200 + expectedStatus: HttpStatusCode.OK_200 }) }) }) @@ -215,7 +211,7 @@ describe('Test user subscriptions API validators', function () { await makeGetRequest({ url: server.url, path: existPath, - statusCodeExpected: HttpStatusCode.UNAUTHORIZED_401 + expectedStatus: HttpStatusCode.UNAUTHORIZED_401 }) }) @@ -225,7 +221,7 @@ describe('Test user subscriptions API validators', function () { path: existPath, query: { uris: 'toto' }, token: server.accessToken, - statusCodeExpected: HttpStatusCode.BAD_REQUEST_400 + expectedStatus: HttpStatusCode.BAD_REQUEST_400 }) await makeGetRequest({ @@ -233,7 +229,7 @@ describe('Test user subscriptions API validators', function () { path: existPath, query: { 'uris[]': 1 }, token: server.accessToken, - statusCodeExpected: HttpStatusCode.BAD_REQUEST_400 + expectedStatus: HttpStatusCode.BAD_REQUEST_400 }) }) @@ -243,7 +239,7 @@ describe('Test user subscriptions API validators', function () { path: existPath, query: { 'uris[]': 'coucou@localhost:' + server.port }, token: server.accessToken, - statusCodeExpected: HttpStatusCode.OK_200 + expectedStatus: HttpStatusCode.OK_200 }) }) }) @@ -253,7 +249,7 @@ describe('Test user subscriptions API validators', function () { await makeDeleteRequest({ url: server.url, path: path + '/user1_channel@localhost:' + server.port, - statusCodeExpected: HttpStatusCode.UNAUTHORIZED_401 + expectedStatus: HttpStatusCode.UNAUTHORIZED_401 }) }) @@ -262,21 +258,21 @@ describe('Test user subscriptions API validators', function () { url: server.url, path: path + '/root', token: server.accessToken, - statusCodeExpected: HttpStatusCode.BAD_REQUEST_400 + expectedStatus: HttpStatusCode.BAD_REQUEST_400 }) await makeDeleteRequest({ url: server.url, path: path + '/root@', token: server.accessToken, - statusCodeExpected: HttpStatusCode.BAD_REQUEST_400 + expectedStatus: HttpStatusCode.BAD_REQUEST_400 }) await makeDeleteRequest({ url: server.url, path: path + '/root@hello@', token: server.accessToken, - statusCodeExpected: HttpStatusCode.BAD_REQUEST_400 + expectedStatus: HttpStatusCode.BAD_REQUEST_400 }) }) @@ -285,7 +281,7 @@ describe('Test user subscriptions API validators', function () { url: server.url, path: path + '/root1@localhost:' + server.port, token: server.accessToken, - statusCodeExpected: HttpStatusCode.NOT_FOUND_404 + expectedStatus: HttpStatusCode.NOT_FOUND_404 }) }) @@ -294,7 +290,7 @@ describe('Test user subscriptions API validators', function () { url: server.url, path: path + '/user1_channel@localhost:' + server.port, token: server.accessToken, - statusCodeExpected: HttpStatusCode.NO_CONTENT_204 + expectedStatus: HttpStatusCode.NO_CONTENT_204 }) }) }) diff --git a/server/tests/api/check-params/users.ts b/server/tests/api/check-params/users.ts index c2c98f429..34fe309f9 100644 --- a/server/tests/api/check-params/users.ts +++ b/server/tests/api/check-params/users.ts @@ -2,7 +2,7 @@ import 'mocha' import { omit } from 'lodash' -import { HttpStatusCode } from '@shared/core-utils' +import { HttpStatusCode } from '@shared/models' import { buildAbsoluteFixturePath, checkBadCountPagination, @@ -103,7 +103,7 @@ describe('Test users API validators', function () { await makeGetRequest({ url: server.url, path, - statusCodeExpected: HttpStatusCode.UNAUTHORIZED_401 + expectedStatus: HttpStatusCode.UNAUTHORIZED_401 }) }) @@ -112,7 +112,7 @@ describe('Test users API validators', function () { url: server.url, path, token: userToken, - statusCodeExpected: HttpStatusCode.FORBIDDEN_403 + expectedStatus: HttpStatusCode.FORBIDDEN_403 }) }) }) @@ -210,7 +210,7 @@ describe('Test users API validators', function () { path: path, token: server.accessToken, fields, - statusCodeExpected: HttpStatusCode.OK_200 + expectedStatus: HttpStatusCode.OK_200 }) }) @@ -226,7 +226,7 @@ describe('Test users API validators', function () { path, token: 'super token', fields: baseCorrectParams, - statusCodeExpected: HttpStatusCode.UNAUTHORIZED_401 + expectedStatus: HttpStatusCode.UNAUTHORIZED_401 }) }) @@ -238,7 +238,7 @@ describe('Test users API validators', function () { path, token: server.accessToken, fields, - statusCodeExpected: HttpStatusCode.CONFLICT_409 + expectedStatus: HttpStatusCode.CONFLICT_409 }) }) @@ -250,7 +250,7 @@ describe('Test users API validators', function () { path, token: server.accessToken, fields, - statusCodeExpected: HttpStatusCode.CONFLICT_409 + expectedStatus: HttpStatusCode.CONFLICT_409 }) }) @@ -298,7 +298,7 @@ describe('Test users API validators', function () { path, token: server.accessToken, fields, - statusCodeExpected: HttpStatusCode.CONFLICT_409 + expectedStatus: HttpStatusCode.CONFLICT_409 }) }) @@ -311,7 +311,7 @@ describe('Test users API validators', function () { path, token: moderatorToken, fields, - statusCodeExpected: HttpStatusCode.FORBIDDEN_403 + expectedStatus: HttpStatusCode.FORBIDDEN_403 }) } }) @@ -324,7 +324,7 @@ describe('Test users API validators', function () { path, token: moderatorToken, fields, - statusCodeExpected: HttpStatusCode.OK_200 + expectedStatus: HttpStatusCode.OK_200 }) }) @@ -334,7 +334,7 @@ describe('Test users API validators', function () { path, token: server.accessToken, fields: baseCorrectParams, - statusCodeExpected: HttpStatusCode.OK_200 + expectedStatus: HttpStatusCode.OK_200 }) }) @@ -348,7 +348,7 @@ describe('Test users API validators', function () { password: 'my super password', videoQuota: 42000000 } - await makePostBodyRequest({ url: server.url, path, token: userToken, fields, statusCodeExpected: HttpStatusCode.FORBIDDEN_403 }) + await makePostBodyRequest({ url: server.url, path, token: userToken, fields, expectedStatus: HttpStatusCode.FORBIDDEN_403 }) }) }) @@ -400,7 +400,7 @@ describe('Test users API validators', function () { path: path + 'me', token: userToken, fields, - statusCodeExpected: HttpStatusCode.UNAUTHORIZED_401 + expectedStatus: HttpStatusCode.UNAUTHORIZED_401 }) }) @@ -447,7 +447,7 @@ describe('Test users API validators', function () { path: path + 'me', token: 'super token', fields, - statusCodeExpected: HttpStatusCode.UNAUTHORIZED_401 + expectedStatus: HttpStatusCode.UNAUTHORIZED_401 }) }) @@ -525,7 +525,7 @@ describe('Test users API validators', function () { path: path + 'me', token: userToken, fields, - statusCodeExpected: HttpStatusCode.NO_CONTENT_204 + expectedStatus: HttpStatusCode.NO_CONTENT_204 }) }) @@ -540,7 +540,7 @@ describe('Test users API validators', function () { path: path + 'me', token: userToken, fields, - statusCodeExpected: HttpStatusCode.NO_CONTENT_204 + expectedStatus: HttpStatusCode.NO_CONTENT_204 }) }) }) @@ -572,7 +572,7 @@ describe('Test users API validators', function () { path: path + '/me/avatar/pick', fields, attaches, - statusCodeExpected: HttpStatusCode.UNAUTHORIZED_401 + expectedStatus: HttpStatusCode.UNAUTHORIZED_401 }) }) @@ -587,7 +587,7 @@ describe('Test users API validators', function () { token: server.accessToken, fields, attaches, - statusCodeExpected: HttpStatusCode.OK_200 + expectedStatus: HttpStatusCode.OK_200 }) }) }) @@ -627,16 +627,16 @@ describe('Test users API validators', function () { url: server.url, path: path + userId, token: 'super token', - statusCodeExpected: HttpStatusCode.UNAUTHORIZED_401 + expectedStatus: HttpStatusCode.UNAUTHORIZED_401 }) }) it('Should fail with a non admin user', async function () { - await makeGetRequest({ url: server.url, path, token: userToken, statusCodeExpected: HttpStatusCode.FORBIDDEN_403 }) + await makeGetRequest({ url: server.url, path, token: userToken, expectedStatus: HttpStatusCode.FORBIDDEN_403 }) }) it('Should succeed with the correct params', async function () { - await makeGetRequest({ url: server.url, path: path + userId, token: server.accessToken, statusCodeExpected: HttpStatusCode.OK_200 }) + await makeGetRequest({ url: server.url, path: path + userId, token: server.accessToken, expectedStatus: HttpStatusCode.OK_200 }) }) }) @@ -702,7 +702,7 @@ describe('Test users API validators', function () { path: path + userId, token: 'super token', fields, - statusCodeExpected: HttpStatusCode.UNAUTHORIZED_401 + expectedStatus: HttpStatusCode.UNAUTHORIZED_401 }) }) @@ -730,7 +730,7 @@ describe('Test users API validators', function () { path: path + moderatorId, token: moderatorToken, fields, - statusCodeExpected: HttpStatusCode.FORBIDDEN_403 + expectedStatus: HttpStatusCode.FORBIDDEN_403 }) }) @@ -744,7 +744,7 @@ describe('Test users API validators', function () { path: path + userId, token: moderatorToken, fields, - statusCodeExpected: HttpStatusCode.NO_CONTENT_204 + expectedStatus: HttpStatusCode.NO_CONTENT_204 }) }) @@ -761,7 +761,7 @@ describe('Test users API validators', function () { path: path + userId, token: server.accessToken, fields, - statusCodeExpected: HttpStatusCode.NO_CONTENT_204 + expectedStatus: HttpStatusCode.NO_CONTENT_204 }) }) }) @@ -818,11 +818,11 @@ describe('Test users API validators', function () { }) it('Should fail with a unauthenticated user', async function () { - await makeGetRequest({ url: server.url, path, statusCodeExpected: HttpStatusCode.UNAUTHORIZED_401 }) + await makeGetRequest({ url: server.url, path, expectedStatus: HttpStatusCode.UNAUTHORIZED_401 }) }) it('Should fail with a another user', async function () { - await makeGetRequest({ url: server.url, path, token: server.accessToken, statusCodeExpected: HttpStatusCode.FORBIDDEN_403 }) + await makeGetRequest({ url: server.url, path, token: server.accessToken, expectedStatus: HttpStatusCode.FORBIDDEN_403 }) }) it('Should fail with a bad type', async function () { @@ -831,12 +831,12 @@ describe('Test users API validators', function () { path, token: userToken, query: { rating: 'toto ' }, - statusCodeExpected: HttpStatusCode.BAD_REQUEST_400 + expectedStatus: HttpStatusCode.BAD_REQUEST_400 }) }) it('Should succeed with the correct params', async function () { - await makeGetRequest({ url: server.url, path, token: userToken, statusCodeExpected: HttpStatusCode.OK_200 }) + await makeGetRequest({ url: server.url, path, token: userToken, expectedStatus: HttpStatusCode.OK_200 }) }) }) @@ -955,7 +955,7 @@ describe('Test users API validators', function () { path: registrationPath, token: server.accessToken, fields, - statusCodeExpected: HttpStatusCode.CONFLICT_409 + expectedStatus: HttpStatusCode.CONFLICT_409 }) }) @@ -967,7 +967,7 @@ describe('Test users API validators', function () { path: registrationPath, token: server.accessToken, fields, - statusCodeExpected: HttpStatusCode.CONFLICT_409 + expectedStatus: HttpStatusCode.CONFLICT_409 }) }) @@ -979,7 +979,7 @@ describe('Test users API validators', function () { path: registrationPath, token: server.accessToken, fields, - statusCodeExpected: HttpStatusCode.CONFLICT_409 + expectedStatus: HttpStatusCode.CONFLICT_409 }) }) @@ -1019,7 +1019,7 @@ describe('Test users API validators', function () { path: registrationPath, token: server.accessToken, fields, - statusCodeExpected: HttpStatusCode.CONFLICT_409 + expectedStatus: HttpStatusCode.CONFLICT_409 }) }) @@ -1031,7 +1031,7 @@ describe('Test users API validators', function () { path: registrationPath, token: server.accessToken, fields: fields, - statusCodeExpected: HttpStatusCode.NO_CONTENT_204 + expectedStatus: HttpStatusCode.NO_CONTENT_204 }) }) @@ -1047,7 +1047,7 @@ describe('Test users API validators', function () { path: registrationPath, token: serverWithRegistrationDisabled.accessToken, fields, - statusCodeExpected: HttpStatusCode.FORBIDDEN_403 + expectedStatus: HttpStatusCode.FORBIDDEN_403 }) }) }) @@ -1081,7 +1081,7 @@ describe('Test users API validators', function () { path, token: server.accessToken, fields, - statusCodeExpected: HttpStatusCode.NO_CONTENT_204 + expectedStatus: HttpStatusCode.NO_CONTENT_204 }) }) }) @@ -1109,7 +1109,7 @@ describe('Test users API validators', function () { path, token: server.accessToken, fields, - statusCodeExpected: HttpStatusCode.NO_CONTENT_204 + expectedStatus: HttpStatusCode.NO_CONTENT_204 }) }) }) diff --git a/server/tests/api/check-params/video-blacklist.ts b/server/tests/api/check-params/video-blacklist.ts index b5d0e0778..2072df4b6 100644 --- a/server/tests/api/check-params/video-blacklist.ts +++ b/server/tests/api/check-params/video-blacklist.ts @@ -2,7 +2,7 @@ import 'mocha' import { expect } from 'chai' -import { HttpStatusCode } from '@shared/core-utils' +import { HttpStatusCode } from '@shared/models' import { BlacklistCommand, checkBadCountPagination, @@ -88,7 +88,7 @@ describe('Test video blacklist API validators', function () { it('Should fail with a non authenticated user', async function () { const path = basePath + servers[0].store.video + '/blacklist' const fields = {} - await makePostBodyRequest({ url: servers[0].url, path, token: 'hello', fields, statusCodeExpected: HttpStatusCode.UNAUTHORIZED_401 }) + await makePostBodyRequest({ url: servers[0].url, path, token: 'hello', fields, expectedStatus: HttpStatusCode.UNAUTHORIZED_401 }) }) it('Should fail with a non admin user', async function () { @@ -99,7 +99,7 @@ describe('Test video blacklist API validators', function () { path, token: userAccessToken2, fields, - statusCodeExpected: HttpStatusCode.FORBIDDEN_403 + expectedStatus: HttpStatusCode.FORBIDDEN_403 }) }) @@ -119,7 +119,7 @@ describe('Test video blacklist API validators', function () { path, token: servers[0].accessToken, fields, - statusCodeExpected: HttpStatusCode.CONFLICT_409 + expectedStatus: HttpStatusCode.CONFLICT_409 }) }) @@ -132,7 +132,7 @@ describe('Test video blacklist API validators', function () { path, token: servers[0].accessToken, fields, - statusCodeExpected: HttpStatusCode.NO_CONTENT_204 + expectedStatus: HttpStatusCode.NO_CONTENT_204 }) }) }) @@ -154,14 +154,14 @@ describe('Test video blacklist API validators', function () { path, token: servers[0].accessToken, fields, - statusCodeExpected: HttpStatusCode.NOT_FOUND_404 + expectedStatus: HttpStatusCode.NOT_FOUND_404 }) }) it('Should fail with a non authenticated user', async function () { const path = basePath + servers[0].store.video + '/blacklist' const fields = {} - await makePutBodyRequest({ url: servers[0].url, path, token: 'hello', fields, statusCodeExpected: HttpStatusCode.UNAUTHORIZED_401 }) + await makePutBodyRequest({ url: servers[0].url, path, token: 'hello', fields, expectedStatus: HttpStatusCode.UNAUTHORIZED_401 }) }) it('Should fail with a non admin user', async function () { @@ -172,7 +172,7 @@ describe('Test video blacklist API validators', function () { path, token: userAccessToken2, fields, - statusCodeExpected: HttpStatusCode.FORBIDDEN_403 + expectedStatus: HttpStatusCode.FORBIDDEN_403 }) }) @@ -192,7 +192,7 @@ describe('Test video blacklist API validators', function () { path, token: servers[0].accessToken, fields, - statusCodeExpected: HttpStatusCode.NO_CONTENT_204 + expectedStatus: HttpStatusCode.NO_CONTENT_204 }) }) }) diff --git a/server/tests/api/check-params/video-captions.ts b/server/tests/api/check-params/video-captions.ts index 26aab79e7..1b3d1aa95 100644 --- a/server/tests/api/check-params/video-captions.ts +++ b/server/tests/api/check-params/video-captions.ts @@ -1,7 +1,7 @@ /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */ import 'mocha' -import { HttpStatusCode } from '@shared/core-utils' +import { HttpStatusCode } from '@shared/models' import { buildAbsoluteFixturePath, cleanupTests, @@ -67,7 +67,7 @@ describe('Test video captions API validator', function () { token: server.accessToken, fields, attaches, - statusCodeExpected: 404 + expectedStatus: 404 }) }) @@ -103,7 +103,7 @@ describe('Test video captions API validator', function () { path: captionPath, fields, attaches, - statusCodeExpected: HttpStatusCode.UNAUTHORIZED_401 + expectedStatus: HttpStatusCode.UNAUTHORIZED_401 }) }) @@ -116,7 +116,7 @@ describe('Test video captions API validator', function () { token: 'blabla', fields, attaches, - statusCodeExpected: HttpStatusCode.UNAUTHORIZED_401 + expectedStatus: HttpStatusCode.UNAUTHORIZED_401 }) }) @@ -134,7 +134,7 @@ describe('Test video captions API validator', function () { // token: server.accessToken, // fields, // attaches, - // statusCodeExpected: HttpStatusCode.BAD_REQUEST_400 + // expectedStatus: HttpStatusCode.BAD_REQUEST_400 // }) // }) @@ -147,7 +147,7 @@ describe('Test video captions API validator', function () { // videoId: video.uuid, // fixture: 'subtitle-bad.txt', // mimeType: 'application/octet-stream', - // statusCodeExpected: HttpStatusCode.BAD_REQUEST_400 + // expectedStatus: HttpStatusCode.BAD_REQUEST_400 // }) // }) @@ -174,7 +174,7 @@ describe('Test video captions API validator', function () { // token: server.accessToken, // fields, // attaches, - // statusCodeExpected: HttpStatusCode.INTERNAL_SERVER_ERROR_500 + // expectedStatus: HttpStatusCode.INTERNAL_SERVER_ERROR_500 // }) // }) @@ -187,7 +187,7 @@ describe('Test video captions API validator', function () { token: server.accessToken, fields, attaches, - statusCodeExpected: HttpStatusCode.NO_CONTENT_204 + expectedStatus: HttpStatusCode.NO_CONTENT_204 }) }) }) @@ -201,12 +201,12 @@ describe('Test video captions API validator', function () { await makeGetRequest({ url: server.url, path: path + '4da6fde3-88f7-4d16-b119-108df5630b06/captions', - statusCodeExpected: HttpStatusCode.NOT_FOUND_404 + expectedStatus: HttpStatusCode.NOT_FOUND_404 }) }) it('Should success with the correct parameters', async function () { - await makeGetRequest({ url: server.url, path: path + video.shortUUID + '/captions', statusCodeExpected: HttpStatusCode.OK_200 }) + await makeGetRequest({ url: server.url, path: path + video.shortUUID + '/captions', expectedStatus: HttpStatusCode.OK_200 }) }) }) @@ -224,7 +224,7 @@ describe('Test video captions API validator', function () { url: server.url, path: path + '4da6fde3-88f7-4d16-b119-108df5630b06/captions/fr', token: server.accessToken, - statusCodeExpected: HttpStatusCode.NOT_FOUND_404 + expectedStatus: HttpStatusCode.NOT_FOUND_404 }) }) @@ -248,12 +248,12 @@ describe('Test video captions API validator', function () { it('Should fail without access token', async function () { const captionPath = path + video.shortUUID + '/captions/fr' - await makeDeleteRequest({ url: server.url, path: captionPath, statusCodeExpected: HttpStatusCode.UNAUTHORIZED_401 }) + await makeDeleteRequest({ url: server.url, path: captionPath, expectedStatus: HttpStatusCode.UNAUTHORIZED_401 }) }) it('Should fail with a bad access token', async function () { const captionPath = path + video.shortUUID + '/captions/fr' - await makeDeleteRequest({ url: server.url, path: captionPath, token: 'coucou', statusCodeExpected: HttpStatusCode.UNAUTHORIZED_401 }) + await makeDeleteRequest({ url: server.url, path: captionPath, token: 'coucou', expectedStatus: HttpStatusCode.UNAUTHORIZED_401 }) }) it('Should fail with another user', async function () { @@ -262,7 +262,7 @@ describe('Test video captions API validator', function () { url: server.url, path: captionPath, token: userAccessToken, - statusCodeExpected: HttpStatusCode.FORBIDDEN_403 + expectedStatus: HttpStatusCode.FORBIDDEN_403 }) }) @@ -272,7 +272,7 @@ describe('Test video captions API validator', function () { url: server.url, path: captionPath, token: server.accessToken, - statusCodeExpected: HttpStatusCode.NO_CONTENT_204 + expectedStatus: HttpStatusCode.NO_CONTENT_204 }) }) }) diff --git a/server/tests/api/check-params/video-channels.ts b/server/tests/api/check-params/video-channels.ts index 62b8fa4f6..bbe42e43d 100644 --- a/server/tests/api/check-params/video-channels.ts +++ b/server/tests/api/check-params/video-channels.ts @@ -3,7 +3,7 @@ import 'mocha' import * as chai from 'chai' import { omit } from 'lodash' -import { HttpStatusCode } from '@shared/core-utils' +import { HttpStatusCode } from '@shared/models' import { buildAbsoluteFixturePath, ChannelsCommand, @@ -88,7 +88,7 @@ describe('Test video channels API validator', function () { await makeGetRequest({ url: server.url, path: accountChannelPath, - statusCodeExpected: HttpStatusCode.OK_200 + expectedStatus: HttpStatusCode.OK_200 }) }) }) @@ -107,7 +107,7 @@ describe('Test video channels API validator', function () { path: videoChannelPath, token: 'none', fields: baseCorrectParams, - statusCodeExpected: HttpStatusCode.UNAUTHORIZED_401 + expectedStatus: HttpStatusCode.UNAUTHORIZED_401 }) }) @@ -152,7 +152,7 @@ describe('Test video channels API validator', function () { path: videoChannelPath, token: server.accessToken, fields: baseCorrectParams, - statusCodeExpected: HttpStatusCode.OK_200 + expectedStatus: HttpStatusCode.OK_200 }) }) @@ -162,7 +162,7 @@ describe('Test video channels API validator', function () { path: videoChannelPath, token: server.accessToken, fields: baseCorrectParams, - statusCodeExpected: HttpStatusCode.CONFLICT_409 + expectedStatus: HttpStatusCode.CONFLICT_409 }) }) }) @@ -186,7 +186,7 @@ describe('Test video channels API validator', function () { path, token: 'hi', fields: baseCorrectParams, - statusCodeExpected: HttpStatusCode.UNAUTHORIZED_401 + expectedStatus: HttpStatusCode.UNAUTHORIZED_401 }) }) @@ -196,7 +196,7 @@ describe('Test video channels API validator', function () { path, token: accessTokenUser, fields: baseCorrectParams, - statusCodeExpected: HttpStatusCode.FORBIDDEN_403 + expectedStatus: HttpStatusCode.FORBIDDEN_403 }) }) @@ -226,7 +226,7 @@ describe('Test video channels API validator', function () { path, token: server.accessToken, fields: baseCorrectParams, - statusCodeExpected: HttpStatusCode.NO_CONTENT_204 + expectedStatus: HttpStatusCode.NO_CONTENT_204 }) }) }) @@ -271,7 +271,7 @@ describe('Test video channels API validator', function () { path: `${path}/${type}/pick`, fields, attaches, - statusCodeExpected: HttpStatusCode.UNAUTHORIZED_401 + expectedStatus: HttpStatusCode.UNAUTHORIZED_401 }) } }) @@ -288,7 +288,7 @@ describe('Test video channels API validator', function () { token: server.accessToken, fields, attaches, - statusCodeExpected: HttpStatusCode.OK_200 + expectedStatus: HttpStatusCode.OK_200 }) } }) @@ -299,7 +299,7 @@ describe('Test video channels API validator', function () { const res = await makeGetRequest({ url: server.url, path: videoChannelPath, - statusCodeExpected: HttpStatusCode.OK_200 + expectedStatus: HttpStatusCode.OK_200 }) expect(res.body.data).to.be.an('array') @@ -309,7 +309,7 @@ describe('Test video channels API validator', function () { await makeGetRequest({ url: server.url, path: videoChannelPath + '/super_channel2', - statusCodeExpected: HttpStatusCode.NOT_FOUND_404 + expectedStatus: HttpStatusCode.NOT_FOUND_404 }) }) @@ -317,7 +317,7 @@ describe('Test video channels API validator', function () { await makeGetRequest({ url: server.url, path: videoChannelPath + '/super_channel', - statusCodeExpected: HttpStatusCode.OK_200 + expectedStatus: HttpStatusCode.OK_200 }) }) }) diff --git a/server/tests/api/check-params/video-comments.ts b/server/tests/api/check-params/video-comments.ts index 92c29da0e..bfd9e0172 100644 --- a/server/tests/api/check-params/video-comments.ts +++ b/server/tests/api/check-params/video-comments.ts @@ -2,7 +2,7 @@ import 'mocha' import * as chai from 'chai' -import { HttpStatusCode } from '@shared/core-utils' +import { HttpStatusCode } from '@shared/models' import { checkBadCountPagination, checkBadSortPagination, @@ -78,7 +78,7 @@ describe('Test video comments API validator', function () { await makeGetRequest({ url: server.url, path: '/api/v1/videos/ba708d62-e3d7-45d9-9d73-41b9097cc02d/comment-threads', - statusCodeExpected: HttpStatusCode.NOT_FOUND_404 + expectedStatus: HttpStatusCode.NOT_FOUND_404 }) }) }) @@ -88,7 +88,7 @@ describe('Test video comments API validator', function () { await makeGetRequest({ url: server.url, path: '/api/v1/videos/ba708d62-e3d7-45d9-9d73-41b9097cc02d/comment-threads/' + commentId, - statusCodeExpected: HttpStatusCode.NOT_FOUND_404 + expectedStatus: HttpStatusCode.NOT_FOUND_404 }) }) @@ -96,7 +96,7 @@ describe('Test video comments API validator', function () { await makeGetRequest({ url: server.url, path: '/api/v1/videos/' + video.shortUUID + '/comment-threads/156', - statusCodeExpected: HttpStatusCode.NOT_FOUND_404 + expectedStatus: HttpStatusCode.NOT_FOUND_404 }) }) @@ -104,7 +104,7 @@ describe('Test video comments API validator', function () { await makeGetRequest({ url: server.url, path: '/api/v1/videos/' + video.shortUUID + '/comment-threads/' + commentId, - statusCodeExpected: HttpStatusCode.OK_200 + expectedStatus: HttpStatusCode.OK_200 }) }) }) @@ -120,7 +120,7 @@ describe('Test video comments API validator', function () { path: pathThread, token: 'none', fields, - statusCodeExpected: HttpStatusCode.UNAUTHORIZED_401 + expectedStatus: HttpStatusCode.UNAUTHORIZED_401 }) }) @@ -153,7 +153,7 @@ describe('Test video comments API validator', function () { path, token: server.accessToken, fields, - statusCodeExpected: HttpStatusCode.NOT_FOUND_404 + expectedStatus: HttpStatusCode.NOT_FOUND_404 }) }) @@ -166,7 +166,7 @@ describe('Test video comments API validator', function () { path: pathThread, token: server.accessToken, fields, - statusCodeExpected: HttpStatusCode.OK_200 + expectedStatus: HttpStatusCode.OK_200 }) }) }) @@ -181,7 +181,7 @@ describe('Test video comments API validator', function () { path: pathComment, token: 'none', fields, - statusCodeExpected: HttpStatusCode.UNAUTHORIZED_401 + expectedStatus: HttpStatusCode.UNAUTHORIZED_401 }) }) @@ -214,7 +214,7 @@ describe('Test video comments API validator', function () { path, token: server.accessToken, fields, - statusCodeExpected: HttpStatusCode.NOT_FOUND_404 + expectedStatus: HttpStatusCode.NOT_FOUND_404 }) }) @@ -228,7 +228,7 @@ describe('Test video comments API validator', function () { path, token: server.accessToken, fields, - statusCodeExpected: HttpStatusCode.NOT_FOUND_404 + expectedStatus: HttpStatusCode.NOT_FOUND_404 }) }) @@ -241,14 +241,14 @@ describe('Test video comments API validator', function () { path: pathComment, token: server.accessToken, fields, - statusCodeExpected: HttpStatusCode.OK_200 + expectedStatus: HttpStatusCode.OK_200 }) }) }) describe('When removing video comments', function () { it('Should fail with a non authenticated user', async function () { - await makeDeleteRequest({ url: server.url, path: pathComment, token: 'none', statusCodeExpected: HttpStatusCode.UNAUTHORIZED_401 }) + await makeDeleteRequest({ url: server.url, path: pathComment, token: 'none', expectedStatus: HttpStatusCode.UNAUTHORIZED_401 }) }) it('Should fail with another user', async function () { @@ -256,18 +256,18 @@ describe('Test video comments API validator', function () { url: server.url, path: pathComment, token: userAccessToken, - statusCodeExpected: HttpStatusCode.FORBIDDEN_403 + expectedStatus: HttpStatusCode.FORBIDDEN_403 }) }) it('Should fail with an incorrect video', async function () { const path = '/api/v1/videos/ba708d62-e3d7-45d9-9d73-41b9097cc02d/comments/' + commentId - await makeDeleteRequest({ url: server.url, path, token: server.accessToken, statusCodeExpected: HttpStatusCode.NOT_FOUND_404 }) + await makeDeleteRequest({ url: server.url, path, token: server.accessToken, expectedStatus: HttpStatusCode.NOT_FOUND_404 }) }) it('Should fail with an incorrect comment', async function () { const path = '/api/v1/videos/' + video.uuid + '/comments/124' - await makeDeleteRequest({ url: server.url, path, token: server.accessToken, statusCodeExpected: HttpStatusCode.NOT_FOUND_404 }) + await makeDeleteRequest({ url: server.url, path, token: server.accessToken, expectedStatus: HttpStatusCode.NOT_FOUND_404 }) }) it('Should succeed with the same user', async function () { @@ -280,8 +280,8 @@ describe('Test video comments API validator', function () { const path = '/api/v1/videos/' + video.uuid + '/comments/' + commentToDelete - await makeDeleteRequest({ url: server.url, path, token: userAccessToken2, statusCodeExpected: HttpStatusCode.FORBIDDEN_403 }) - await makeDeleteRequest({ url: server.url, path, token: userAccessToken, statusCodeExpected: HttpStatusCode.NO_CONTENT_204 }) + await makeDeleteRequest({ url: server.url, path, token: userAccessToken2, expectedStatus: HttpStatusCode.FORBIDDEN_403 }) + await makeDeleteRequest({ url: server.url, path, token: userAccessToken, expectedStatus: HttpStatusCode.NO_CONTENT_204 }) }) it('Should succeed with the owner of the video', async function () { @@ -300,8 +300,8 @@ describe('Test video comments API validator', function () { const path = '/api/v1/videos/' + anotherVideoUUID + '/comments/' + commentToDelete - await makeDeleteRequest({ url: server.url, path, token: userAccessToken2, statusCodeExpected: HttpStatusCode.FORBIDDEN_403 }) - await makeDeleteRequest({ url: server.url, path, token: userAccessToken, statusCodeExpected: HttpStatusCode.NO_CONTENT_204 }) + await makeDeleteRequest({ url: server.url, path, token: userAccessToken2, expectedStatus: HttpStatusCode.FORBIDDEN_403 }) + await makeDeleteRequest({ url: server.url, path, token: userAccessToken, expectedStatus: HttpStatusCode.NO_CONTENT_204 }) }) it('Should succeed with the correct parameters', async function () { @@ -309,7 +309,7 @@ describe('Test video comments API validator', function () { url: server.url, path: pathComment, token: server.accessToken, - statusCodeExpected: HttpStatusCode.NO_CONTENT_204 + expectedStatus: HttpStatusCode.NO_CONTENT_204 }) }) }) @@ -324,7 +324,7 @@ describe('Test video comments API validator', function () { const res = await makeGetRequest({ url: server.url, path: pathThread, - statusCodeExpected: HttpStatusCode.OK_200 + expectedStatus: HttpStatusCode.OK_200 }) expect(res.body.total).to.equal(0) expect(res.body.data).to.have.lengthOf(0) @@ -341,7 +341,7 @@ describe('Test video comments API validator', function () { path: pathThread, token: server.accessToken, fields, - statusCodeExpected: HttpStatusCode.CONFLICT_409 + expectedStatus: HttpStatusCode.CONFLICT_409 }) }) @@ -367,7 +367,7 @@ describe('Test video comments API validator', function () { await makeGetRequest({ url: server.url, path, - statusCodeExpected: HttpStatusCode.UNAUTHORIZED_401 + expectedStatus: HttpStatusCode.UNAUTHORIZED_401 }) }) @@ -376,7 +376,7 @@ describe('Test video comments API validator', function () { url: server.url, path, token: userAccessToken, - statusCodeExpected: HttpStatusCode.FORBIDDEN_403 + expectedStatus: HttpStatusCode.FORBIDDEN_403 }) }) @@ -391,7 +391,7 @@ describe('Test video comments API validator', function () { searchAccount: 'toto', searchVideo: 'toto' }, - statusCodeExpected: HttpStatusCode.OK_200 + expectedStatus: HttpStatusCode.OK_200 }) }) }) diff --git a/server/tests/api/check-params/video-imports.ts b/server/tests/api/check-params/video-imports.ts index 0209275ac..957556c9b 100644 --- a/server/tests/api/check-params/video-imports.ts +++ b/server/tests/api/check-params/video-imports.ts @@ -2,7 +2,7 @@ import 'mocha' import { omit } from 'lodash' -import { HttpStatusCode } from '@shared/core-utils' +import { HttpStatusCode } from '@shared/models' import { buildAbsoluteFixturePath, checkBadCountPagination, @@ -61,7 +61,7 @@ describe('Test video imports API validator', function () { }) it('Should success with the correct parameters', async function () { - await makeGetRequest({ url: server.url, path: myPath, statusCodeExpected: HttpStatusCode.OK_200, token: server.accessToken }) + await makeGetRequest({ url: server.url, path: myPath, expectedStatus: HttpStatusCode.OK_200, token: server.accessToken }) }) }) @@ -99,7 +99,7 @@ describe('Test video imports API validator', function () { path, token: server.accessToken, fields, - statusCodeExpected: HttpStatusCode.BAD_REQUEST_400 + expectedStatus: HttpStatusCode.BAD_REQUEST_400 }) }) @@ -251,7 +251,7 @@ describe('Test video imports API validator', function () { path, token: server.accessToken, fields: baseCorrectParams, - statusCodeExpected: HttpStatusCode.OK_200 + expectedStatus: HttpStatusCode.OK_200 }) }) @@ -276,7 +276,7 @@ describe('Test video imports API validator', function () { path, token: server.accessToken, fields: baseCorrectParams, - statusCodeExpected: HttpStatusCode.CONFLICT_409 + expectedStatus: HttpStatusCode.CONFLICT_409 }) }) @@ -304,7 +304,7 @@ describe('Test video imports API validator', function () { path, token: server.accessToken, fields, - statusCodeExpected: HttpStatusCode.CONFLICT_409 + expectedStatus: HttpStatusCode.CONFLICT_409 }) fields = omit(fields, 'magnetUri') @@ -318,7 +318,7 @@ describe('Test video imports API validator', function () { token: server.accessToken, fields, attaches, - statusCodeExpected: HttpStatusCode.CONFLICT_409 + expectedStatus: HttpStatusCode.CONFLICT_409 }) }) }) diff --git a/server/tests/api/check-params/video-playlists.ts b/server/tests/api/check-params/video-playlists.ts index 9d054b176..7dcb4935a 100644 --- a/server/tests/api/check-params/video-playlists.ts +++ b/server/tests/api/check-params/video-playlists.ts @@ -1,7 +1,7 @@ /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */ import 'mocha' -import { HttpStatusCode } from '@shared/core-utils' +import { HttpStatusCode } from '@shared/models' import { checkBadCountPagination, checkBadSortPagination, @@ -119,7 +119,7 @@ describe('Test video playlists API validator', function () { await makeGetRequest({ url: server.url, path: accountPath, - statusCodeExpected: HttpStatusCode.NOT_FOUND_404, + expectedStatus: HttpStatusCode.NOT_FOUND_404, token: server.accessToken }) }) @@ -130,18 +130,18 @@ describe('Test video playlists API validator', function () { await makeGetRequest({ url: server.url, path: accountPath, - statusCodeExpected: HttpStatusCode.NOT_FOUND_404, + expectedStatus: HttpStatusCode.NOT_FOUND_404, token: server.accessToken }) }) it('Should success with the correct parameters', async function () { - await makeGetRequest({ url: server.url, path: globalPath, statusCodeExpected: HttpStatusCode.OK_200, token: server.accessToken }) - await makeGetRequest({ url: server.url, path: accountPath, statusCodeExpected: HttpStatusCode.OK_200, token: server.accessToken }) + await makeGetRequest({ url: server.url, path: globalPath, expectedStatus: HttpStatusCode.OK_200, token: server.accessToken }) + await makeGetRequest({ url: server.url, path: accountPath, expectedStatus: HttpStatusCode.OK_200, token: server.accessToken }) await makeGetRequest({ url: server.url, path: videoChannelPath, - statusCodeExpected: HttpStatusCode.OK_200, + expectedStatus: HttpStatusCode.OK_200, token: server.accessToken }) }) @@ -159,7 +159,7 @@ describe('Test video playlists API validator', function () { }) it('Should success with the correct parameters', async function () { - await makeGetRequest({ url: server.url, path: path + playlist.shortUUID + '/videos', statusCodeExpected: HttpStatusCode.OK_200 }) + await makeGetRequest({ url: server.url, path: path + playlist.shortUUID + '/videos', expectedStatus: HttpStatusCode.OK_200 }) }) }) @@ -580,7 +580,7 @@ describe('Test video playlists API validator', function () { url: server.url, path, query: { videoIds: [ 1, 2 ] }, - statusCodeExpected: HttpStatusCode.UNAUTHORIZED_401 + expectedStatus: HttpStatusCode.UNAUTHORIZED_401 }) }) @@ -613,7 +613,7 @@ describe('Test video playlists API validator', function () { token: server.accessToken, path, query: { videoIds: [ 1, 2 ] }, - statusCodeExpected: HttpStatusCode.OK_200 + expectedStatus: HttpStatusCode.OK_200 }) }) }) diff --git a/server/tests/api/check-params/videos-filter.ts b/server/tests/api/check-params/videos-filter.ts index e4e799cc7..c2c69904f 100644 --- a/server/tests/api/check-params/videos-filter.ts +++ b/server/tests/api/check-params/videos-filter.ts @@ -1,6 +1,7 @@ /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */ import 'mocha' +import { HttpStatusCode } from '@shared/models' import { cleanupTests, createSingleServer, @@ -8,11 +9,10 @@ import { PeerTubeServer, setAccessTokensToServers, setDefaultVideoChannel -} from '../../../../shared/extra-utils' -import { UserRole } from '../../../../shared/models/users' -import { HttpStatusCode } from '../../../../shared/core-utils/miscs/http-error-codes' +} from '@shared/extra-utils' +import { UserRole } from '@shared/models' -async function testEndpoints (server: PeerTubeServer, token: string, filter: string, statusCodeExpected: HttpStatusCode) { +async function testEndpoints (server: PeerTubeServer, token: string, filter: string, expectedStatus: HttpStatusCode) { const paths = [ '/api/v1/video-channels/root_channel/videos', '/api/v1/accounts/root/videos', @@ -28,7 +28,7 @@ async function testEndpoints (server: PeerTubeServer, token: string, filter: str query: { filter }, - statusCodeExpected + expectedStatus }) } } @@ -89,7 +89,7 @@ describe('Test video filters validators', function () { await makeGetRequest({ url: server.url, path: '/feeds/videos.json', - statusCodeExpected: HttpStatusCode.UNAUTHORIZED_401, + expectedStatus: HttpStatusCode.UNAUTHORIZED_401, query: { filter } @@ -101,7 +101,7 @@ describe('Test video filters validators', function () { await makeGetRequest({ url: server.url, path: '/feeds/videos.json', - statusCodeExpected: HttpStatusCode.OK_200, + expectedStatus: HttpStatusCode.OK_200, query: { filter: 'local' } diff --git a/server/tests/api/check-params/videos-history.ts b/server/tests/api/check-params/videos-history.ts index 3c1f479e4..7283a4d28 100644 --- a/server/tests/api/check-params/videos-history.ts +++ b/server/tests/api/check-params/videos-history.ts @@ -1,7 +1,7 @@ /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */ import 'mocha' -import { HttpStatusCode } from '@shared/core-utils' +import { HttpStatusCode } from '@shared/models' import { checkBadCountPagination, checkBadStartPagination, @@ -37,7 +37,7 @@ describe('Test videos history API validator', function () { it('Should fail with an unauthenticated user', async function () { const fields = { currentTime: 5 } - await makePutBodyRequest({ url: server.url, path: watchingPath, fields, statusCodeExpected: HttpStatusCode.UNAUTHORIZED_401 }) + await makePutBodyRequest({ url: server.url, path: watchingPath, fields, expectedStatus: HttpStatusCode.UNAUTHORIZED_401 }) }) it('Should fail with an incorrect video id', async function () { @@ -48,7 +48,7 @@ describe('Test videos history API validator', function () { path, fields, token: server.accessToken, - statusCodeExpected: HttpStatusCode.BAD_REQUEST_400 + expectedStatus: HttpStatusCode.BAD_REQUEST_400 }) }) @@ -61,7 +61,7 @@ describe('Test videos history API validator', function () { path, fields, token: server.accessToken, - statusCodeExpected: HttpStatusCode.NOT_FOUND_404 + expectedStatus: HttpStatusCode.NOT_FOUND_404 }) }) @@ -72,7 +72,7 @@ describe('Test videos history API validator', function () { path: watchingPath, fields, token: server.accessToken, - statusCodeExpected: HttpStatusCode.BAD_REQUEST_400 + expectedStatus: HttpStatusCode.BAD_REQUEST_400 }) }) @@ -84,7 +84,7 @@ describe('Test videos history API validator', function () { path: watchingPath, fields, token: server.accessToken, - statusCodeExpected: HttpStatusCode.NO_CONTENT_204 + expectedStatus: HttpStatusCode.NO_CONTENT_204 }) }) }) @@ -99,17 +99,17 @@ describe('Test videos history API validator', function () { }) it('Should fail with an unauthenticated user', async function () { - await makeGetRequest({ url: server.url, path: myHistoryPath, statusCodeExpected: HttpStatusCode.UNAUTHORIZED_401 }) + await makeGetRequest({ url: server.url, path: myHistoryPath, expectedStatus: HttpStatusCode.UNAUTHORIZED_401 }) }) it('Should succeed with the correct params', async function () { - await makeGetRequest({ url: server.url, token: server.accessToken, path: myHistoryPath, statusCodeExpected: HttpStatusCode.OK_200 }) + await makeGetRequest({ url: server.url, token: server.accessToken, path: myHistoryPath, expectedStatus: HttpStatusCode.OK_200 }) }) }) describe('When removing user videos history', function () { it('Should fail with an unauthenticated user', async function () { - await makePostBodyRequest({ url: server.url, path: myHistoryPath + '/remove', statusCodeExpected: HttpStatusCode.UNAUTHORIZED_401 }) + await makePostBodyRequest({ url: server.url, path: myHistoryPath + '/remove', expectedStatus: HttpStatusCode.UNAUTHORIZED_401 }) }) it('Should fail with a bad beforeDate parameter', async function () { @@ -119,7 +119,7 @@ describe('Test videos history API validator', function () { token: server.accessToken, path: myHistoryRemove, fields: body, - statusCodeExpected: HttpStatusCode.BAD_REQUEST_400 + expectedStatus: HttpStatusCode.BAD_REQUEST_400 }) }) @@ -130,7 +130,7 @@ describe('Test videos history API validator', function () { token: server.accessToken, path: myHistoryRemove, fields: body, - statusCodeExpected: HttpStatusCode.NO_CONTENT_204 + expectedStatus: HttpStatusCode.NO_CONTENT_204 }) }) @@ -139,7 +139,7 @@ describe('Test videos history API validator', function () { url: server.url, token: server.accessToken, path: myHistoryRemove, - statusCodeExpected: HttpStatusCode.NO_CONTENT_204 + expectedStatus: HttpStatusCode.NO_CONTENT_204 }) }) }) diff --git a/server/tests/api/check-params/videos.ts b/server/tests/api/check-params/videos.ts index c60de2640..e11ca0c82 100644 --- a/server/tests/api/check-params/videos.ts +++ b/server/tests/api/check-params/videos.ts @@ -4,7 +4,7 @@ import 'mocha' import * as chai from 'chai' import { omit } from 'lodash' import { join } from 'path' -import { HttpStatusCode, randomInt } from '@shared/core-utils' +import { randomInt } from '@shared/core-utils' import { checkBadCountPagination, checkBadSortPagination, @@ -16,11 +16,11 @@ import { makeGetRequest, makePutBodyRequest, makeUploadRequest, - root, PeerTubeServer, + root, setAccessTokensToServers } from '@shared/extra-utils' -import { PeerTubeProblemDocument, VideoCreateResult, VideoPrivacy } from '@shared/models' +import { HttpStatusCode, PeerTubeProblemDocument, VideoCreateResult, VideoPrivacy } from '@shared/models' const expect = chai.expect @@ -69,11 +69,11 @@ describe('Test videos API validator', function () { }) it('Should fail with a bad skipVideos query', async function () { - await makeGetRequest({ url: server.url, path, statusCodeExpected: HttpStatusCode.OK_200, query: { skipCount: 'toto' } }) + await makeGetRequest({ url: server.url, path, expectedStatus: HttpStatusCode.OK_200, query: { skipCount: 'toto' } }) }) it('Should success with the correct parameters', async function () { - await makeGetRequest({ url: server.url, path, statusCodeExpected: HttpStatusCode.OK_200, query: { skipCount: false } }) + await makeGetRequest({ url: server.url, path, expectedStatus: HttpStatusCode.OK_200, query: { skipCount: false } }) }) }) @@ -83,7 +83,7 @@ describe('Test videos API validator', function () { await makeGetRequest({ url: server.url, path: join(path, 'search'), - statusCodeExpected: HttpStatusCode.BAD_REQUEST_400 + expectedStatus: HttpStatusCode.BAD_REQUEST_400 }) }) @@ -100,7 +100,7 @@ describe('Test videos API validator', function () { }) it('Should success with the correct parameters', async function () { - await makeGetRequest({ url: server.url, path, statusCodeExpected: HttpStatusCode.OK_200 }) + await makeGetRequest({ url: server.url, path, expectedStatus: HttpStatusCode.OK_200 }) }) }) @@ -120,7 +120,7 @@ describe('Test videos API validator', function () { }) it('Should success with the correct parameters', async function () { - await makeGetRequest({ url: server.url, token: server.accessToken, path, statusCodeExpected: HttpStatusCode.OK_200 }) + await makeGetRequest({ url: server.url, token: server.accessToken, path, expectedStatus: HttpStatusCode.OK_200 }) }) }) @@ -144,7 +144,7 @@ describe('Test videos API validator', function () { }) it('Should success with the correct parameters', async function () { - await makeGetRequest({ url: server.url, path, statusCodeExpected: HttpStatusCode.OK_200 }) + await makeGetRequest({ url: server.url, path, expectedStatus: HttpStatusCode.OK_200 }) }) }) @@ -168,7 +168,7 @@ describe('Test videos API validator', function () { }) it('Should success with the correct parameters', async function () { - await makeGetRequest({ url: server.url, path, statusCodeExpected: HttpStatusCode.OK_200 }) + await makeGetRequest({ url: server.url, path, expectedStatus: HttpStatusCode.OK_200 }) }) }) @@ -506,7 +506,7 @@ describe('Test videos API validator', function () { path: path + '4da6fde3-88f7-4d16-b119-108df5630b06', token: server.accessToken, fields, - statusCodeExpected: HttpStatusCode.NOT_FOUND_404 + expectedStatus: HttpStatusCode.NOT_FOUND_404 }) }) @@ -660,7 +660,7 @@ describe('Test videos API validator', function () { path: path + video.shortUUID, token: userAccessToken, fields, - statusCodeExpected: HttpStatusCode.FORBIDDEN_403 + expectedStatus: HttpStatusCode.FORBIDDEN_403 }) }) @@ -692,7 +692,7 @@ describe('Test videos API validator', function () { path: path + video.shortUUID, token: server.accessToken, fields, - statusCodeExpected: HttpStatusCode.NO_CONTENT_204 + expectedStatus: HttpStatusCode.NO_CONTENT_204 }) }) }) @@ -702,7 +702,7 @@ describe('Test videos API validator', function () { const res = await makeGetRequest({ url: server.url, path, - statusCodeExpected: HttpStatusCode.OK_200 + expectedStatus: HttpStatusCode.OK_200 }) expect(res.body.data).to.be.an('array') @@ -762,7 +762,7 @@ describe('Test videos API validator', function () { path: path + '4da6fde3-88f7-4d16-b119-108df5630b06/rate', token: server.accessToken, fields, - statusCodeExpected: HttpStatusCode.NOT_FOUND_404 + expectedStatus: HttpStatusCode.NOT_FOUND_404 }) }) @@ -782,7 +782,7 @@ describe('Test videos API validator', function () { path: path + videoId + '/rate', token: server.accessToken, fields, - statusCodeExpected: HttpStatusCode.NO_CONTENT_204 + expectedStatus: HttpStatusCode.NO_CONTENT_204 }) }) }) @@ -792,7 +792,7 @@ describe('Test videos API validator', function () { await makeDeleteRequest({ url: server.url, path, - statusCodeExpected: HttpStatusCode.BAD_REQUEST_400 + expectedStatus: HttpStatusCode.BAD_REQUEST_400 }) }) @@ -812,7 +812,7 @@ describe('Test videos API validator', function () { it('Shoud report the appropriate error', async function () { const body = await server.videos.remove({ id: 'hello', expectedStatus: HttpStatusCode.BAD_REQUEST_400 }) - const error = body as unknown as PeerTubeProblemDocument + const error = body as PeerTubeProblemDocument expect(error.docs).to.equal('https://docs.joinpeertube.org/api-rest-reference.html#operation/delVideo') -- cgit v1.2.3 From 4c7e60bc17ee5830399bac4aa273356903421b4c Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Fri, 16 Jul 2021 14:27:30 +0200 Subject: Reorganize imports --- server/tests/api/check-params/abuses.ts | 5 ++--- server/tests/api/check-params/accounts.ts | 2 +- server/tests/api/check-params/config.ts | 3 +-- server/tests/api/check-params/contact-form.ts | 2 +- server/tests/api/check-params/live.ts | 5 ++--- server/tests/api/check-params/plugins.ts | 3 +-- server/tests/api/check-params/search.ts | 2 +- server/tests/api/check-params/services.ts | 3 +-- server/tests/api/check-params/user-notifications.ts | 3 +-- server/tests/api/check-params/users.ts | 3 +-- server/tests/api/check-params/video-blacklist.ts | 5 ++--- server/tests/api/check-params/video-captions.ts | 3 +-- server/tests/api/check-params/video-channels.ts | 3 +-- server/tests/api/check-params/video-comments.ts | 3 +-- server/tests/api/check-params/video-imports.ts | 3 +-- server/tests/api/check-params/video-playlists.ts | 4 ++-- server/tests/api/check-params/videos-filter.ts | 3 +-- server/tests/api/check-params/videos-history.ts | 2 +- 18 files changed, 22 insertions(+), 35 deletions(-) (limited to 'server/tests/api/check-params') diff --git a/server/tests/api/check-params/abuses.ts b/server/tests/api/check-params/abuses.ts index 87d93195c..72f2cbd8f 100644 --- a/server/tests/api/check-params/abuses.ts +++ b/server/tests/api/check-params/abuses.ts @@ -1,22 +1,21 @@ /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */ import 'mocha' -import { HttpStatusCode } from '@shared/models' import { AbusesCommand, checkBadCountPagination, checkBadSortPagination, checkBadStartPagination, cleanupTests, - doubleFollow, createSingleServer, + doubleFollow, makeGetRequest, makePostBodyRequest, PeerTubeServer, setAccessTokensToServers, waitJobs } from '@shared/extra-utils' -import { AbuseCreate, AbuseState } from '@shared/models' +import { AbuseCreate, AbuseState, HttpStatusCode } from '@shared/models' describe('Test abuses API validators', function () { const basePath = '/api/v1/abuses/' diff --git a/server/tests/api/check-params/accounts.ts b/server/tests/api/check-params/accounts.ts index 0cae485d9..141d869b7 100644 --- a/server/tests/api/check-params/accounts.ts +++ b/server/tests/api/check-params/accounts.ts @@ -1,7 +1,6 @@ /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */ import 'mocha' -import { HttpStatusCode } from '@shared/models' import { checkBadCountPagination, checkBadSortPagination, @@ -10,6 +9,7 @@ import { createSingleServer, PeerTubeServer } from '@shared/extra-utils' +import { HttpStatusCode } from '@shared/models' describe('Test accounts API validators', function () { const path = '/api/v1/accounts/' diff --git a/server/tests/api/check-params/config.ts b/server/tests/api/check-params/config.ts index c3438917e..87cb2287e 100644 --- a/server/tests/api/check-params/config.ts +++ b/server/tests/api/check-params/config.ts @@ -2,7 +2,6 @@ import 'mocha' import { omit } from 'lodash' -import { HttpStatusCode } from '@shared/models' import { cleanupTests, createSingleServer, @@ -12,7 +11,7 @@ import { PeerTubeServer, setAccessTokensToServers } from '@shared/extra-utils' -import { CustomConfig } from '@shared/models' +import { CustomConfig, HttpStatusCode } from '@shared/models' describe('Test config API validators', function () { const path = '/api/v1/config/custom' diff --git a/server/tests/api/check-params/contact-form.ts b/server/tests/api/check-params/contact-form.ts index 8e755c69b..1df9993da 100644 --- a/server/tests/api/check-params/contact-form.ts +++ b/server/tests/api/check-params/contact-form.ts @@ -1,9 +1,9 @@ /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */ import 'mocha' -import { HttpStatusCode } from '@shared/models' import { cleanupTests, createSingleServer, killallServers, MockSmtpServer, PeerTubeServer } from '@shared/extra-utils' import { ContactFormCommand } from '@shared/extra-utils/server' +import { HttpStatusCode } from '@shared/models' describe('Test contact form API validators', function () { let server: PeerTubeServer diff --git a/server/tests/api/check-params/live.ts b/server/tests/api/check-params/live.ts index 0ef86a538..700b4724d 100644 --- a/server/tests/api/check-params/live.ts +++ b/server/tests/api/check-params/live.ts @@ -2,7 +2,6 @@ import 'mocha' import { omit } from 'lodash' -import { HttpStatusCode } from '@shared/models' import { buildAbsoluteFixturePath, cleanupTests, @@ -10,12 +9,12 @@ import { LiveCommand, makePostBodyRequest, makeUploadRequest, - sendRTMPStream, PeerTubeServer, + sendRTMPStream, setAccessTokensToServers, stopFfmpeg } from '@shared/extra-utils' -import { VideoCreateResult, VideoPrivacy } from '@shared/models' +import { HttpStatusCode, VideoCreateResult, VideoPrivacy } from '@shared/models' describe('Test video lives API validator', function () { const path = '/api/v1/videos/live' diff --git a/server/tests/api/check-params/plugins.ts b/server/tests/api/check-params/plugins.ts index d3dda7fce..33f84ecbc 100644 --- a/server/tests/api/check-params/plugins.ts +++ b/server/tests/api/check-params/plugins.ts @@ -1,7 +1,6 @@ /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */ import 'mocha' -import { HttpStatusCode } from '@shared/models' import { checkBadCountPagination, checkBadSortPagination, @@ -14,7 +13,7 @@ import { PeerTubeServer, setAccessTokensToServers } from '@shared/extra-utils' -import { PeerTubePlugin, PluginType } from '@shared/models' +import { HttpStatusCode, PeerTubePlugin, PluginType } from '@shared/models' describe('Test server plugins API validators', function () { let server: PeerTubeServer diff --git a/server/tests/api/check-params/search.ts b/server/tests/api/check-params/search.ts index b49169e38..a3da54e1f 100644 --- a/server/tests/api/check-params/search.ts +++ b/server/tests/api/check-params/search.ts @@ -1,7 +1,6 @@ /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */ import 'mocha' -import { HttpStatusCode } from '@shared/models' import { checkBadCountPagination, checkBadSortPagination, @@ -12,6 +11,7 @@ import { PeerTubeServer, setAccessTokensToServers } from '@shared/extra-utils' +import { HttpStatusCode } from '@shared/models' function updateSearchIndex (server: PeerTubeServer, enabled: boolean, disableLocalSearch = false) { return server.config.updateCustomSubConfig({ diff --git a/server/tests/api/check-params/services.ts b/server/tests/api/check-params/services.ts index 973b25598..4c4a5cade 100644 --- a/server/tests/api/check-params/services.ts +++ b/server/tests/api/check-params/services.ts @@ -1,7 +1,6 @@ /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */ import 'mocha' -import { HttpStatusCode } from '@shared/models' import { cleanupTests, createSingleServer, @@ -10,7 +9,7 @@ import { setAccessTokensToServers, setDefaultVideoChannel } from '@shared/extra-utils' -import { VideoPlaylistPrivacy } from '@shared/models' +import { HttpStatusCode, VideoPlaylistPrivacy } from '@shared/models' describe('Test services API validators', function () { let server: PeerTubeServer diff --git a/server/tests/api/check-params/user-notifications.ts b/server/tests/api/check-params/user-notifications.ts index 3b709ee5a..17edf5aa1 100644 --- a/server/tests/api/check-params/user-notifications.ts +++ b/server/tests/api/check-params/user-notifications.ts @@ -2,7 +2,6 @@ import 'mocha' import { io } from 'socket.io-client' -import { HttpStatusCode } from '@shared/models' import { checkBadCountPagination, checkBadSortPagination, @@ -16,7 +15,7 @@ import { setAccessTokensToServers, wait } from '@shared/extra-utils' -import { UserNotificationSetting, UserNotificationSettingValue } from '@shared/models' +import { HttpStatusCode, UserNotificationSetting, UserNotificationSettingValue } from '@shared/models' describe('Test user notifications API validators', function () { let server: PeerTubeServer diff --git a/server/tests/api/check-params/users.ts b/server/tests/api/check-params/users.ts index 34fe309f9..9d8f933db 100644 --- a/server/tests/api/check-params/users.ts +++ b/server/tests/api/check-params/users.ts @@ -2,7 +2,6 @@ import 'mocha' import { omit } from 'lodash' -import { HttpStatusCode } from '@shared/models' import { buildAbsoluteFixturePath, checkBadCountPagination, @@ -20,7 +19,7 @@ import { setAccessTokensToServers, UsersCommand } from '@shared/extra-utils' -import { UserAdminFlag, UserRole, VideoCreateResult } from '@shared/models' +import { HttpStatusCode, UserAdminFlag, UserRole, VideoCreateResult } from '@shared/models' describe('Test users API validators', function () { const path = '/api/v1/users/' diff --git a/server/tests/api/check-params/video-blacklist.ts b/server/tests/api/check-params/video-blacklist.ts index 2072df4b6..d28c6a952 100644 --- a/server/tests/api/check-params/video-blacklist.ts +++ b/server/tests/api/check-params/video-blacklist.ts @@ -2,22 +2,21 @@ import 'mocha' import { expect } from 'chai' -import { HttpStatusCode } from '@shared/models' import { BlacklistCommand, checkBadCountPagination, checkBadSortPagination, checkBadStartPagination, cleanupTests, - doubleFollow, createMultipleServers, + doubleFollow, makePostBodyRequest, makePutBodyRequest, PeerTubeServer, setAccessTokensToServers, waitJobs } from '@shared/extra-utils' -import { VideoBlacklistType } from '@shared/models' +import { HttpStatusCode, VideoBlacklistType } from '@shared/models' describe('Test video blacklist API validators', function () { let servers: PeerTubeServer[] diff --git a/server/tests/api/check-params/video-captions.ts b/server/tests/api/check-params/video-captions.ts index 1b3d1aa95..5aaeb27fe 100644 --- a/server/tests/api/check-params/video-captions.ts +++ b/server/tests/api/check-params/video-captions.ts @@ -1,7 +1,6 @@ /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */ import 'mocha' -import { HttpStatusCode } from '@shared/models' import { buildAbsoluteFixturePath, cleanupTests, @@ -12,7 +11,7 @@ import { PeerTubeServer, setAccessTokensToServers } from '@shared/extra-utils' -import { VideoCreateResult } from '@shared/models' +import { HttpStatusCode, VideoCreateResult } from '@shared/models' describe('Test video captions API validator', function () { const path = '/api/v1/videos/' diff --git a/server/tests/api/check-params/video-channels.ts b/server/tests/api/check-params/video-channels.ts index bbe42e43d..2e63916d4 100644 --- a/server/tests/api/check-params/video-channels.ts +++ b/server/tests/api/check-params/video-channels.ts @@ -3,7 +3,6 @@ import 'mocha' import * as chai from 'chai' import { omit } from 'lodash' -import { HttpStatusCode } from '@shared/models' import { buildAbsoluteFixturePath, ChannelsCommand, @@ -19,7 +18,7 @@ import { PeerTubeServer, setAccessTokensToServers } from '@shared/extra-utils' -import { VideoChannelUpdate } from '@shared/models' +import { HttpStatusCode, VideoChannelUpdate } from '@shared/models' const expect = chai.expect diff --git a/server/tests/api/check-params/video-comments.ts b/server/tests/api/check-params/video-comments.ts index bfd9e0172..2d9ee1e0d 100644 --- a/server/tests/api/check-params/video-comments.ts +++ b/server/tests/api/check-params/video-comments.ts @@ -2,7 +2,6 @@ import 'mocha' import * as chai from 'chai' -import { HttpStatusCode } from '@shared/models' import { checkBadCountPagination, checkBadSortPagination, @@ -15,7 +14,7 @@ import { PeerTubeServer, setAccessTokensToServers } from '@shared/extra-utils' -import { VideoCreateResult } from '@shared/models' +import { HttpStatusCode, VideoCreateResult } from '@shared/models' const expect = chai.expect diff --git a/server/tests/api/check-params/video-imports.ts b/server/tests/api/check-params/video-imports.ts index 957556c9b..d6d745488 100644 --- a/server/tests/api/check-params/video-imports.ts +++ b/server/tests/api/check-params/video-imports.ts @@ -2,7 +2,6 @@ import 'mocha' import { omit } from 'lodash' -import { HttpStatusCode } from '@shared/models' import { buildAbsoluteFixturePath, checkBadCountPagination, @@ -17,7 +16,7 @@ import { PeerTubeServer, setAccessTokensToServers } from '@shared/extra-utils' -import { VideoPrivacy } from '@shared/models' +import { HttpStatusCode, VideoPrivacy } from '@shared/models' describe('Test video imports API validator', function () { const path = '/api/v1/videos/imports' diff --git a/server/tests/api/check-params/video-playlists.ts b/server/tests/api/check-params/video-playlists.ts index 7dcb4935a..e4d541b48 100644 --- a/server/tests/api/check-params/video-playlists.ts +++ b/server/tests/api/check-params/video-playlists.ts @@ -1,7 +1,6 @@ /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */ import 'mocha' -import { HttpStatusCode } from '@shared/models' import { checkBadCountPagination, checkBadSortPagination, @@ -9,12 +8,13 @@ import { cleanupTests, createSingleServer, makeGetRequest, - PlaylistsCommand, PeerTubeServer, + PlaylistsCommand, setAccessTokensToServers, setDefaultVideoChannel } from '@shared/extra-utils' import { + HttpStatusCode, VideoPlaylistCreate, VideoPlaylistCreateResult, VideoPlaylistElementCreate, diff --git a/server/tests/api/check-params/videos-filter.ts b/server/tests/api/check-params/videos-filter.ts index c2c69904f..d08570bbe 100644 --- a/server/tests/api/check-params/videos-filter.ts +++ b/server/tests/api/check-params/videos-filter.ts @@ -1,7 +1,6 @@ /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */ import 'mocha' -import { HttpStatusCode } from '@shared/models' import { cleanupTests, createSingleServer, @@ -10,7 +9,7 @@ import { setAccessTokensToServers, setDefaultVideoChannel } from '@shared/extra-utils' -import { UserRole } from '@shared/models' +import { HttpStatusCode, UserRole } from '@shared/models' async function testEndpoints (server: PeerTubeServer, token: string, filter: string, expectedStatus: HttpStatusCode) { const paths = [ diff --git a/server/tests/api/check-params/videos-history.ts b/server/tests/api/check-params/videos-history.ts index 7283a4d28..c3c309ed2 100644 --- a/server/tests/api/check-params/videos-history.ts +++ b/server/tests/api/check-params/videos-history.ts @@ -1,7 +1,6 @@ /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */ import 'mocha' -import { HttpStatusCode } from '@shared/models' import { checkBadCountPagination, checkBadStartPagination, @@ -13,6 +12,7 @@ import { PeerTubeServer, setAccessTokensToServers } from '@shared/extra-utils' +import { HttpStatusCode } from '@shared/models' describe('Test videos history API validator', function () { const myHistoryPath = '/api/v1/users/me/history/videos' -- cgit v1.2.3 From 4d029ef8ec3d5274eeaa3ee6d808eb7035e7faef Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Tue, 20 Jul 2021 14:15:15 +0200 Subject: Add ability for instances to follow any actor --- server/tests/api/check-params/follows.ts | 36 ++++++++++++++++++-------------- 1 file changed, 20 insertions(+), 16 deletions(-) (limited to 'server/tests/api/check-params') diff --git a/server/tests/api/check-params/follows.ts b/server/tests/api/check-params/follows.ts index dfe3f226d..2bc9f6b96 100644 --- a/server/tests/api/check-params/follows.ts +++ b/server/tests/api/check-params/follows.ts @@ -32,19 +32,13 @@ describe('Test server follows API validators', function () { let userAccessToken = null before(async function () { - const user = { - username: 'user1', - password: 'password' - } - - await server.users.create({ username: user.username, password: user.password }) - userAccessToken = await server.login.getAccessToken(user) + userAccessToken = await server.users.generateUserAndToken('user1') }) describe('When adding follows', function () { const path = '/api/v1/server/following' - it('Should fail without hosts', async function () { + it('Should fail with nothing', async function () { await makePostBodyRequest({ url: server.url, path, @@ -53,41 +47,51 @@ describe('Test server follows API validators', function () { }) }) - it('Should fail if hosts is not an array', async function () { + it('Should fail if hosts is not composed by hosts', async function () { await makePostBodyRequest({ url: server.url, path, + fields: { hosts: [ 'localhost:9002', 'localhost:coucou' ] }, token: server.accessToken, - fields: { hosts: 'localhost:9002' }, expectedStatus: HttpStatusCode.BAD_REQUEST_400 }) }) - it('Should fail if the array is not composed by hosts', async function () { + it('Should fail if hosts is composed with http schemes', async function () { await makePostBodyRequest({ url: server.url, path, - fields: { hosts: [ 'localhost:9002', 'localhost:coucou' ] }, + fields: { hosts: [ 'localhost:9002', 'http://localhost:9003' ] }, token: server.accessToken, expectedStatus: HttpStatusCode.BAD_REQUEST_400 }) }) - it('Should fail if the array is composed with http schemes', async function () { + it('Should fail if hosts are not unique', async function () { await makePostBodyRequest({ url: server.url, path, - fields: { hosts: [ 'localhost:9002', 'http://localhost:9003' ] }, + fields: { urls: [ 'localhost:9002', 'localhost:9002' ] }, token: server.accessToken, expectedStatus: HttpStatusCode.BAD_REQUEST_400 }) }) - it('Should fail if hosts are not unique', async function () { + it('Should fail if handles is not composed by handles', async function () { await makePostBodyRequest({ url: server.url, path, - fields: { urls: [ 'localhost:9002', 'localhost:9002' ] }, + fields: { handles: [ 'hello@example.com', 'localhost:9001' ] }, + token: server.accessToken, + expectedStatus: HttpStatusCode.BAD_REQUEST_400 + }) + }) + + it('Should fail if handles are not unique', async function () { + await makePostBodyRequest({ + url: server.url, + path, + fields: { urls: [ 'hello@example.com', 'hello@example.com' ] }, token: server.accessToken, expectedStatus: HttpStatusCode.BAD_REQUEST_400 }) -- cgit v1.2.3 From c63830f15403ac4e750829f27d8bbbdc9a59282c Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Wed, 21 Jul 2021 13:58:35 +0200 Subject: Rename captions commands --- server/tests/api/check-params/video-captions.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'server/tests/api/check-params') diff --git a/server/tests/api/check-params/video-captions.ts b/server/tests/api/check-params/video-captions.ts index 5aaeb27fe..90f429314 100644 --- a/server/tests/api/check-params/video-captions.ts +++ b/server/tests/api/check-params/video-captions.ts @@ -151,7 +151,7 @@ describe('Test video captions API validator', function () { // }) it('Should succeed with a valid captionfile extension and octet-stream mime type', async function () { - await server.captions.createVideoCaption({ + await server.captions.add({ language: 'zh', videoId: video.uuid, fixture: 'subtitle-good.srt', -- cgit v1.2.3