From a6a79eae0d8564099b6957e76d7a18528d9ef124 Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Mon, 5 Jul 2021 14:57:03 +0200 Subject: Introduce bulk command --- server/tests/api/server/bulk.ts | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) (limited to 'server/tests/api') diff --git a/server/tests/api/server/bulk.ts b/server/tests/api/server/bulk.ts index 80fa7fce6..ca98a2eb2 100644 --- a/server/tests/api/server/bulk.ts +++ b/server/tests/api/server/bulk.ts @@ -6,7 +6,7 @@ import { Video, VideoComment } from '@shared/models' import { addVideoCommentReply, addVideoCommentThread, - bulkRemoveCommentsOf, + BulkCommand, cleanupTests, createUser, doubleFollow, @@ -30,6 +30,8 @@ describe('Test bulk actions', function () { let user2AccessToken: string let user3AccessToken: string + let bulkCommand: BulkCommand + before(async function () { this.timeout(30000) @@ -60,6 +62,8 @@ describe('Test bulk actions', function () { } await doubleFollow(servers[0], servers[1]) + + bulkCommand = new BulkCommand(servers[0]) }) describe('Bulk remove comments', function () { @@ -133,8 +137,7 @@ describe('Test bulk actions', function () { it('Should delete comments of an account on my videos', async function () { this.timeout(60000) - await bulkRemoveCommentsOf({ - url: servers[0].url, + await bulkCommand.removeCommentsOf({ token: user1AccessToken, attributes: { accountName: 'user2', @@ -164,9 +167,7 @@ describe('Test bulk actions', function () { it('Should delete comments of an account on the instance', async function () { this.timeout(60000) - await bulkRemoveCommentsOf({ - url: servers[0].url, - token: servers[0].accessToken, + await bulkCommand.removeCommentsOf({ attributes: { accountName: 'user3@localhost:' + servers[1].port, scope: 'instance' -- cgit v1.2.3 From e8bd7ce7ccafe3e064b03978e9b512c1a4cc99e6 Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Tue, 6 Jul 2021 09:55:05 +0200 Subject: Introduce CustomPage command --- server/tests/api/server/homepage.ts | 25 ++++++++++++------------- 1 file changed, 12 insertions(+), 13 deletions(-) (limited to 'server/tests/api') diff --git a/server/tests/api/server/homepage.ts b/server/tests/api/server/homepage.ts index e8ba89ca6..4a3ec0479 100644 --- a/server/tests/api/server/homepage.ts +++ b/server/tests/api/server/homepage.ts @@ -3,17 +3,16 @@ import 'mocha' import * as chai from 'chai' import { HttpStatusCode } from '@shared/core-utils' -import { CustomPage, ServerConfig } from '@shared/models' +import { ServerConfig } from '@shared/models' import { cleanupTests, + CustomPagesCommand, flushAndRunServer, getConfig, - getInstanceHomepage, killallServers, reRunServer, ServerInfo, - setAccessTokensToServers, - updateInstanceHomepage + setAccessTokensToServers } from '../../../../shared/extra-utils/index' const expect = chai.expect @@ -27,26 +26,28 @@ async function getHomepageState (server: ServerInfo) { describe('Test instance homepage actions', function () { let server: ServerInfo + let command: CustomPagesCommand before(async function () { this.timeout(30000) server = await flushAndRunServer(1) await setAccessTokensToServers([ server ]) + + command = server.customPageCommand }) it('Should not have a homepage', async function () { const state = await getHomepageState(server) expect(state).to.be.false - await getInstanceHomepage(server.url, HttpStatusCode.NOT_FOUND_404) + await command.getInstanceHomepage({ expectedStatus: HttpStatusCode.NOT_FOUND_404 }) }) it('Should set a homepage', async function () { - await updateInstanceHomepage(server.url, server.accessToken, '') + await command.updateInstanceHomepage({ content: '' }) - const res = await getInstanceHomepage(server.url) - const page: CustomPage = res.body + const page = await command.getInstanceHomepage() expect(page.content).to.equal('') const state = await getHomepageState(server) @@ -60,8 +61,7 @@ describe('Test instance homepage actions', function () { await reRunServer(server) - const res = await getInstanceHomepage(server.url) - const page: CustomPage = res.body + const page = await command.getInstanceHomepage() expect(page.content).to.equal('') const state = await getHomepageState(server) @@ -69,10 +69,9 @@ describe('Test instance homepage actions', function () { }) it('Should empty the homepage', async function () { - await updateInstanceHomepage(server.url, server.accessToken, '') + await command.updateInstanceHomepage({ content: '' }) - const res = await getInstanceHomepage(server.url) - const page: CustomPage = res.body + const page = await command.getInstanceHomepage() expect(page.content).to.be.empty const state = await getHomepageState(server) -- cgit v1.2.3 From a92ddacb38a4a17e117ca9ed41680a03580fb81d Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Tue, 6 Jul 2021 10:34:29 +0200 Subject: Introduce logs command --- server/tests/api/server/logs.ts | 49 ++++++++++++++++++++++------------------- 1 file changed, 26 insertions(+), 23 deletions(-) (limited to 'server/tests/api') diff --git a/server/tests/api/server/logs.ts b/server/tests/api/server/logs.ts index bc398ea73..ab83a329f 100644 --- a/server/tests/api/server/logs.ts +++ b/server/tests/api/server/logs.ts @@ -6,25 +6,28 @@ import { cleanupTests, flushAndRunServer, killallServers, + LogsCommand, makePingRequest, reRunServer, ServerInfo, - setAccessTokensToServers -} from '../../../../shared/extra-utils/index' -import { getAuditLogs, getLogs } from '../../../../shared/extra-utils/logs/logs' -import { waitJobs } from '../../../../shared/extra-utils/server/jobs' -import { uploadVideo } from '../../../../shared/extra-utils/videos/videos' + setAccessTokensToServers, + uploadVideo, + waitJobs +} from '@shared/extra-utils' const expect = chai.expect describe('Test logs', function () { let server: ServerInfo + let logsCommand: LogsCommand before(async function () { this.timeout(30000) server = await flushAndRunServer(1) await setAccessTokensToServers([ server ]) + + logsCommand = server.logsCommand }) describe('With the standard log file', function () { @@ -40,8 +43,8 @@ describe('Test logs', function () { await uploadVideo(server.url, server.accessToken, { name: 'video 2' }) await waitJobs([ server ]) - const res = await getLogs(server.url, server.accessToken, now) - const logsString = JSON.stringify(res.body) + const body = await logsCommand.getLogs({ startDate: now }) + const logsString = JSON.stringify(body) expect(logsString.includes('video 1')).to.be.false expect(logsString.includes('video 2')).to.be.true @@ -63,8 +66,8 @@ describe('Test logs', function () { await uploadVideo(server.url, server.accessToken, { name: 'video 5' }) await waitJobs([ server ]) - const res = await getLogs(server.url, server.accessToken, now1, now2) - const logsString = JSON.stringify(res.body) + const body = await logsCommand.getLogs({ startDate: now1, endDate: now2 }) + const logsString = JSON.stringify(body) expect(logsString.includes('video 3')).to.be.false expect(logsString.includes('video 4')).to.be.true @@ -80,15 +83,15 @@ describe('Test logs', function () { await waitJobs([ server ]) { - const res = await getLogs(server.url, server.accessToken, now, undefined, 'info') - const logsString = JSON.stringify(res.body) + const body = await logsCommand.getLogs({ startDate: now, level: 'info' }) + const logsString = JSON.stringify(body) expect(logsString.includes('video 6')).to.be.true } { - const res = await getLogs(server.url, server.accessToken, now, undefined, 'warn') - const logsString = JSON.stringify(res.body) + const body = await logsCommand.getLogs({ startDate: now, level: 'warn' }) + const logsString = JSON.stringify(body) expect(logsString.includes('video 6')).to.be.false } @@ -101,8 +104,8 @@ describe('Test logs', function () { await makePingRequest(server) - const res = await getLogs(server.url, server.accessToken, now, undefined, 'info') - const logsString = JSON.stringify(res.body) + const body = await logsCommand.getLogs({ startDate: now, level: 'info' }) + const logsString = JSON.stringify(body) expect(logsString.includes('/api/v1/ping')).to.be.true }) @@ -118,8 +121,8 @@ describe('Test logs', function () { await makePingRequest(server) - const res = await getLogs(server.url, server.accessToken, now, undefined, 'info') - const logsString = JSON.stringify(res.body) + const body = await logsCommand.getLogs({ startDate: now, level: 'info' }) + const logsString = JSON.stringify(body) expect(logsString.includes('/api/v1/ping')).to.be.false }) @@ -137,15 +140,15 @@ describe('Test logs', function () { await uploadVideo(server.url, server.accessToken, { name: 'video 8' }) await waitJobs([ server ]) - const res = await getAuditLogs(server.url, server.accessToken, now) - const logsString = JSON.stringify(res.body) + const body = await logsCommand.getAuditLogs({ startDate: now }) + const logsString = JSON.stringify(body) expect(logsString.includes('video 7')).to.be.false expect(logsString.includes('video 8')).to.be.true - expect(res.body).to.have.lengthOf(1) + expect(body).to.have.lengthOf(1) - const item = res.body[0] + const item = body[0] const message = JSON.parse(item.message) expect(message.domain).to.equal('videos') @@ -168,8 +171,8 @@ describe('Test logs', function () { await uploadVideo(server.url, server.accessToken, { name: 'video 11' }) await waitJobs([ server ]) - const res = await getAuditLogs(server.url, server.accessToken, now1, now2) - const logsString = JSON.stringify(res.body) + const body = await logsCommand.getAuditLogs({ startDate: now1, endDate: now2 }) + const logsString = JSON.stringify(body) expect(logsString.includes('video 9')).to.be.false expect(logsString.includes('video 10')).to.be.true -- cgit v1.2.3 From c8fc9b47188b33cfc33184b1ee7e680a093244f1 Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Tue, 6 Jul 2021 10:35:35 +0200 Subject: Rename mock server files --- server/tests/api/notifications/admin-notifications.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'server/tests/api') diff --git a/server/tests/api/notifications/admin-notifications.ts b/server/tests/api/notifications/admin-notifications.ts index cfe0bd2bb..170aa4532 100644 --- a/server/tests/api/notifications/admin-notifications.ts +++ b/server/tests/api/notifications/admin-notifications.ts @@ -2,7 +2,7 @@ import 'mocha' import { expect } from 'chai' -import { MockJoinPeerTubeVersions } from '@shared/extra-utils/mock-servers/joinpeertube-versions' +import { MockJoinPeerTubeVersions } from '@shared/extra-utils' import { PluginType } from '@shared/models' import { cleanupTests, installPlugin, setPluginLatestVersion, setPluginVersion, wait } from '../../../../shared/extra-utils' import { ServerInfo } from '../../../../shared/extra-utils/index' -- cgit v1.2.3 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 +- server/tests/api/notifications/admin-notifications.ts | 2 +- server/tests/api/notifications/moderation-notifications.ts | 2 +- server/tests/api/notifications/notifications-api.ts | 2 +- server/tests/api/notifications/user-notifications.ts | 2 +- server/tests/api/server/contact-form.ts | 8 ++++---- server/tests/api/server/email.ts | 4 ++-- server/tests/api/users/users-verification.ts | 8 ++++---- 9 files changed, 17 insertions(+), 18 deletions(-) (limited to 'server/tests/api') 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, diff --git a/server/tests/api/notifications/admin-notifications.ts b/server/tests/api/notifications/admin-notifications.ts index 170aa4532..91681c9d6 100644 --- a/server/tests/api/notifications/admin-notifications.ts +++ b/server/tests/api/notifications/admin-notifications.ts @@ -6,7 +6,7 @@ import { MockJoinPeerTubeVersions } from '@shared/extra-utils' import { PluginType } from '@shared/models' import { cleanupTests, installPlugin, setPluginLatestVersion, setPluginVersion, wait } from '../../../../shared/extra-utils' import { ServerInfo } from '../../../../shared/extra-utils/index' -import { MockSmtpServer } from '../../../../shared/extra-utils/miscs/email' +import { MockSmtpServer } from '../../../../shared/extra-utils/mock-servers/mock-email' import { CheckerBaseParams, checkNewPeerTubeVersion, diff --git a/server/tests/api/notifications/moderation-notifications.ts b/server/tests/api/notifications/moderation-notifications.ts index 3425480ae..a7671696f 100644 --- a/server/tests/api/notifications/moderation-notifications.ts +++ b/server/tests/api/notifications/moderation-notifications.ts @@ -27,7 +27,7 @@ import { wait } from '../../../../shared/extra-utils' import { ServerInfo, uploadVideo } from '../../../../shared/extra-utils/index' -import { MockSmtpServer } from '../../../../shared/extra-utils/miscs/email' +import { MockSmtpServer } from '../../../../shared/extra-utils/mock-servers/mock-email' import { waitJobs } from '../../../../shared/extra-utils/server/jobs' import { checkAbuseStateChange, diff --git a/server/tests/api/notifications/notifications-api.ts b/server/tests/api/notifications/notifications-api.ts index b81995449..19f9dbbab 100644 --- a/server/tests/api/notifications/notifications-api.ts +++ b/server/tests/api/notifications/notifications-api.ts @@ -5,7 +5,7 @@ import * as chai from 'chai' import { addUserSubscription } from '@shared/extra-utils/users/user-subscriptions' import { cleanupTests, getMyUserInformation, immutableAssign, uploadRandomVideo, waitJobs } from '../../../../shared/extra-utils' import { ServerInfo } from '../../../../shared/extra-utils/index' -import { MockSmtpServer } from '../../../../shared/extra-utils/miscs/email' +import { MockSmtpServer } from '../../../../shared/extra-utils/mock-servers/mock-email' import { CheckerBaseParams, checkNewVideoFromSubscription, diff --git a/server/tests/api/notifications/user-notifications.ts b/server/tests/api/notifications/user-notifications.ts index e981c1718..ace7e48c7 100644 --- a/server/tests/api/notifications/user-notifications.ts +++ b/server/tests/api/notifications/user-notifications.ts @@ -12,7 +12,7 @@ import { wait } from '../../../../shared/extra-utils' import { ServerInfo } from '../../../../shared/extra-utils/index' -import { MockSmtpServer } from '../../../../shared/extra-utils/miscs/email' +import { MockSmtpServer } from '../../../../shared/extra-utils/mock-servers/mock-email' import { waitJobs } from '../../../../shared/extra-utils/server/jobs' import { CheckerBaseParams, diff --git a/server/tests/api/server/contact-form.ts b/server/tests/api/server/contact-form.ts index 8851ad55e..71205723d 100644 --- a/server/tests/api/server/contact-form.ts +++ b/server/tests/api/server/contact-form.ts @@ -1,12 +1,12 @@ /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */ -import * as chai from 'chai' import 'mocha' +import * as chai from 'chai' +import { HttpStatusCode } from '../../../../shared/core-utils/miscs/http-error-codes' import { cleanupTests, flushAndRunServer, ServerInfo, setAccessTokensToServers, wait } from '../../../../shared/extra-utils' -import { MockSmtpServer } from '../../../../shared/extra-utils/miscs/email' -import { waitJobs } from '../../../../shared/extra-utils/server/jobs' +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/miscs/http-error-codes' +import { waitJobs } from '../../../../shared/extra-utils/server/jobs' const expect = chai.expect diff --git a/server/tests/api/server/email.ts b/server/tests/api/server/email.ts index 92768d9df..41071692a 100644 --- a/server/tests/api/server/email.ts +++ b/server/tests/api/server/email.ts @@ -2,6 +2,7 @@ import 'mocha' import * as chai from 'chai' +import { HttpStatusCode } from '../../../../shared/core-utils/miscs/http-error-codes' import { addVideoToBlacklist, askResetPassword, @@ -20,9 +21,8 @@ import { userLogin, verifyEmail } from '../../../../shared/extra-utils' -import { MockSmtpServer } from '../../../../shared/extra-utils/miscs/email' +import { MockSmtpServer } from '../../../../shared/extra-utils/mock-servers/mock-email' import { waitJobs } from '../../../../shared/extra-utils/server/jobs' -import { HttpStatusCode } from '../../../../shared/core-utils/miscs/http-error-codes' const expect = chai.expect diff --git a/server/tests/api/users/users-verification.ts b/server/tests/api/users/users-verification.ts index e0f2f2112..265cd6050 100644 --- a/server/tests/api/users/users-verification.ts +++ b/server/tests/api/users/users-verification.ts @@ -1,7 +1,8 @@ /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */ -import * as chai from 'chai' import 'mocha' +import * as chai from 'chai' +import { HttpStatusCode } from '../../../../shared/core-utils/miscs/http-error-codes' import { cleanupTests, flushAndRunServer, @@ -15,11 +16,10 @@ import { userLogin, verifyEmail } from '../../../../shared/extra-utils' -import { setAccessTokensToServers } from '../../../../shared/extra-utils/users/login' -import { MockSmtpServer } from '../../../../shared/extra-utils/miscs/email' +import { MockSmtpServer } from '../../../../shared/extra-utils/mock-servers/mock-email' import { waitJobs } from '../../../../shared/extra-utils/server/jobs' +import { setAccessTokensToServers } from '../../../../shared/extra-utils/users/login' import { User } from '../../../../shared/models/users' -import { HttpStatusCode } from '../../../../shared/core-utils/miscs/http-error-codes' const expect = chai.expect -- 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 +++-- server/tests/api/moderation/abuses.ts | 631 ++++++++++----------- .../api/notifications/moderation-notifications.ts | 88 ++- server/tests/api/server/email.ts | 3 +- server/tests/api/users/users.ts | 28 +- 5 files changed, 415 insertions(+), 481 deletions(-) (limited to 'server/tests/api') 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 () { diff --git a/server/tests/api/moderation/abuses.ts b/server/tests/api/moderation/abuses.ts index fb765e7e3..a9f5332ce 100644 --- a/server/tests/api/moderation/abuses.ts +++ b/server/tests/api/moderation/abuses.ts @@ -3,51 +3,32 @@ import 'mocha' import * as chai from 'chai' import { - AbuseFilter, - AbuseMessage, - AbusePredefinedReasonsString, - AbuseState, - Account, - AdminAbuse, - UserAbuse, - VideoComment -} from '@shared/models' -import { - addAbuseMessage, + AbusesCommand, + addAccountToServerBlocklist, + addServerToServerBlocklist, addVideoCommentThread, cleanupTests, createUser, - deleteAbuse, - deleteAbuseMessage, deleteVideoComment, + doubleFollow, flushAndRunMultipleServers, generateUserAccessToken, getAccount, - getAdminAbusesList, - getUserAbusesList, getVideoCommentThreads, getVideoIdFromUUID, getVideosList, - immutableAssign, - listAbuseMessages, + removeAccountFromServerBlocklist, + removeServerFromServerBlocklist, removeUser, removeVideo, - reportAbuse, ServerInfo, setAccessTokensToServers, - updateAbuse, uploadVideo, uploadVideoAndGetId, - userLogin -} from '../../../../shared/extra-utils/index' -import { doubleFollow } from '../../../../shared/extra-utils/server/follows' -import { waitJobs } from '../../../../shared/extra-utils/server/jobs' -import { - addAccountToServerBlocklist, - addServerToServerBlocklist, - removeAccountFromServerBlocklist, - removeServerFromServerBlocklist -} from '../../../../shared/extra-utils/users/blocklist' + userLogin, + waitJobs +} from '@shared/extra-utils' +import { AbuseMessage, AbusePredefinedReasonsString, AbuseState, Account, AdminAbuse, UserAbuse, VideoComment } from '@shared/models' const expect = chai.expect @@ -55,6 +36,7 @@ describe('Test abuses', function () { let servers: ServerInfo[] = [] let abuseServer1: AdminAbuse let abuseServer2: AdminAbuse + let commands: AbusesCommand[] before(async function () { this.timeout(50000) @@ -67,6 +49,8 @@ describe('Test abuses', function () { // Server 1 and server 2 follow each other await doubleFollow(servers[0], servers[1]) + + commands = servers.map(s => s.abusesCommand) }) describe('Video abuses', function () { @@ -100,54 +84,58 @@ describe('Test abuses', function () { }) it('Should not have abuses', async function () { - const res = await getAdminAbusesList({ url: servers[0].url, token: servers[0].accessToken }) + const body = await commands[0].getAdminList() - expect(res.body.total).to.equal(0) - expect(res.body.data).to.be.an('array') - expect(res.body.data.length).to.equal(0) + expect(body.total).to.equal(0) + expect(body.data).to.be.an('array') + expect(body.data.length).to.equal(0) }) it('Should report abuse on a local video', async function () { this.timeout(15000) const reason = 'my super bad reason' - await reportAbuse({ url: servers[0].url, token: servers[0].accessToken, videoId: servers[0].video.id, reason }) + await commands[0].report({ videoId: servers[0].video.id, reason }) // We wait requests propagation, even if the server 1 is not supposed to make a request to server 2 await waitJobs(servers) }) it('Should have 1 video abuses on server 1 and 0 on server 2', async function () { - const res1 = await getAdminAbusesList({ url: servers[0].url, token: servers[0].accessToken }) + { + const body = await commands[0].getAdminList() - expect(res1.body.total).to.equal(1) - expect(res1.body.data).to.be.an('array') - expect(res1.body.data.length).to.equal(1) + expect(body.total).to.equal(1) + expect(body.data).to.be.an('array') + expect(body.data.length).to.equal(1) - const abuse: AdminAbuse = res1.body.data[0] - expect(abuse.reason).to.equal('my super bad reason') + const abuse = body.data[0] + expect(abuse.reason).to.equal('my super bad reason') - expect(abuse.reporterAccount.name).to.equal('root') - expect(abuse.reporterAccount.host).to.equal(servers[0].host) + expect(abuse.reporterAccount.name).to.equal('root') + expect(abuse.reporterAccount.host).to.equal(servers[0].host) - expect(abuse.video.id).to.equal(servers[0].video.id) - expect(abuse.video.channel).to.exist + expect(abuse.video.id).to.equal(servers[0].video.id) + expect(abuse.video.channel).to.exist - expect(abuse.comment).to.be.null + expect(abuse.comment).to.be.null - expect(abuse.flaggedAccount.name).to.equal('root') - expect(abuse.flaggedAccount.host).to.equal(servers[0].host) + expect(abuse.flaggedAccount.name).to.equal('root') + expect(abuse.flaggedAccount.host).to.equal(servers[0].host) - expect(abuse.video.countReports).to.equal(1) - expect(abuse.video.nthReport).to.equal(1) + expect(abuse.video.countReports).to.equal(1) + expect(abuse.video.nthReport).to.equal(1) - expect(abuse.countReportsForReporter).to.equal(1) - expect(abuse.countReportsForReportee).to.equal(1) + expect(abuse.countReportsForReporter).to.equal(1) + expect(abuse.countReportsForReportee).to.equal(1) + } - const res2 = await getAdminAbusesList({ url: servers[1].url, token: servers[1].accessToken }) - expect(res2.body.total).to.equal(0) - expect(res2.body.data).to.be.an('array') - expect(res2.body.data.length).to.equal(0) + { + const body = await commands[1].getAdminList() + expect(body.total).to.equal(0) + expect(body.data).to.be.an('array') + expect(body.data.length).to.equal(0) + } }) it('Should report abuse on a remote video', async function () { @@ -155,68 +143,72 @@ describe('Test abuses', function () { const reason = 'my super bad reason 2' const videoId = await getVideoIdFromUUID(servers[0].url, servers[1].video.uuid) - await reportAbuse({ url: servers[0].url, token: servers[0].accessToken, videoId, reason }) + await commands[0].report({ videoId, reason }) // We wait requests propagation await waitJobs(servers) }) it('Should have 2 video abuses on server 1 and 1 on server 2', async function () { - const res1 = await getAdminAbusesList({ url: servers[0].url, token: servers[0].accessToken }) + { + const body = await commands[0].getAdminList() - expect(res1.body.total).to.equal(2) - expect(res1.body.data.length).to.equal(2) + expect(body.total).to.equal(2) + expect(body.data.length).to.equal(2) - const abuse1: AdminAbuse = res1.body.data[0] - expect(abuse1.reason).to.equal('my super bad reason') - expect(abuse1.reporterAccount.name).to.equal('root') - expect(abuse1.reporterAccount.host).to.equal(servers[0].host) + const abuse1 = body.data[0] + expect(abuse1.reason).to.equal('my super bad reason') + expect(abuse1.reporterAccount.name).to.equal('root') + expect(abuse1.reporterAccount.host).to.equal(servers[0].host) - expect(abuse1.video.id).to.equal(servers[0].video.id) - expect(abuse1.video.countReports).to.equal(1) - expect(abuse1.video.nthReport).to.equal(1) + expect(abuse1.video.id).to.equal(servers[0].video.id) + expect(abuse1.video.countReports).to.equal(1) + expect(abuse1.video.nthReport).to.equal(1) - expect(abuse1.comment).to.be.null + expect(abuse1.comment).to.be.null - expect(abuse1.flaggedAccount.name).to.equal('root') - expect(abuse1.flaggedAccount.host).to.equal(servers[0].host) + expect(abuse1.flaggedAccount.name).to.equal('root') + expect(abuse1.flaggedAccount.host).to.equal(servers[0].host) - expect(abuse1.state.id).to.equal(AbuseState.PENDING) - expect(abuse1.state.label).to.equal('Pending') - expect(abuse1.moderationComment).to.be.null + expect(abuse1.state.id).to.equal(AbuseState.PENDING) + expect(abuse1.state.label).to.equal('Pending') + expect(abuse1.moderationComment).to.be.null - const abuse2: AdminAbuse = res1.body.data[1] - expect(abuse2.reason).to.equal('my super bad reason 2') + const abuse2 = body.data[1] + expect(abuse2.reason).to.equal('my super bad reason 2') - expect(abuse2.reporterAccount.name).to.equal('root') - expect(abuse2.reporterAccount.host).to.equal(servers[0].host) + expect(abuse2.reporterAccount.name).to.equal('root') + expect(abuse2.reporterAccount.host).to.equal(servers[0].host) - expect(abuse2.video.id).to.equal(servers[1].video.id) + expect(abuse2.video.id).to.equal(servers[1].video.id) - expect(abuse2.comment).to.be.null + expect(abuse2.comment).to.be.null - expect(abuse2.flaggedAccount.name).to.equal('root') - expect(abuse2.flaggedAccount.host).to.equal(servers[1].host) + expect(abuse2.flaggedAccount.name).to.equal('root') + expect(abuse2.flaggedAccount.host).to.equal(servers[1].host) - expect(abuse2.state.id).to.equal(AbuseState.PENDING) - expect(abuse2.state.label).to.equal('Pending') - expect(abuse2.moderationComment).to.be.null + expect(abuse2.state.id).to.equal(AbuseState.PENDING) + expect(abuse2.state.label).to.equal('Pending') + expect(abuse2.moderationComment).to.be.null + } - const res2 = await getAdminAbusesList({ url: servers[1].url, token: servers[1].accessToken }) - expect(res2.body.total).to.equal(1) - expect(res2.body.data.length).to.equal(1) + { + const body = await commands[1].getAdminList() + expect(body.total).to.equal(1) + expect(body.data.length).to.equal(1) - abuseServer2 = res2.body.data[0] - expect(abuseServer2.reason).to.equal('my super bad reason 2') - expect(abuseServer2.reporterAccount.name).to.equal('root') - expect(abuseServer2.reporterAccount.host).to.equal(servers[0].host) + abuseServer2 = body.data[0] + expect(abuseServer2.reason).to.equal('my super bad reason 2') + expect(abuseServer2.reporterAccount.name).to.equal('root') + expect(abuseServer2.reporterAccount.host).to.equal(servers[0].host) - expect(abuse2.flaggedAccount.name).to.equal('root') - expect(abuse2.flaggedAccount.host).to.equal(servers[1].host) + expect(abuseServer2.flaggedAccount.name).to.equal('root') + expect(abuseServer2.flaggedAccount.host).to.equal(servers[1].host) - expect(abuseServer2.state.id).to.equal(AbuseState.PENDING) - expect(abuseServer2.state.label).to.equal('Pending') - expect(abuseServer2.moderationComment).to.be.null + expect(abuseServer2.state.id).to.equal(AbuseState.PENDING) + expect(abuseServer2.state.label).to.equal('Pending') + expect(abuseServer2.moderationComment).to.be.null + } }) it('Should hide video abuses from blocked accounts', async function () { @@ -224,11 +216,11 @@ describe('Test abuses', function () { { const videoId = await getVideoIdFromUUID(servers[1].url, servers[0].video.uuid) - await reportAbuse({ url: servers[1].url, token: servers[1].accessToken, videoId, reason: 'will mute this' }) + await commands[1].report({ videoId, reason: 'will mute this' }) await waitJobs(servers) - const res = await getAdminAbusesList({ url: servers[0].url, token: servers[0].accessToken }) - expect(res.body.total).to.equal(3) + const body = await commands[0].getAdminList() + expect(body.total).to.equal(3) } const accountToBlock = 'root@' + servers[1].host @@ -236,18 +228,18 @@ describe('Test abuses', function () { { await addAccountToServerBlocklist(servers[0].url, servers[0].accessToken, accountToBlock) - const res = await getAdminAbusesList({ url: servers[0].url, token: servers[0].accessToken }) - expect(res.body.total).to.equal(2) + const body = await commands[0].getAdminList() + expect(body.total).to.equal(2) - const abuse = res.body.data.find(a => a.reason === 'will mute this') + const abuse = body.data.find(a => a.reason === 'will mute this') expect(abuse).to.be.undefined } { await removeAccountFromServerBlocklist(servers[0].url, servers[0].accessToken, accountToBlock) - const res = await getAdminAbusesList({ url: servers[0].url, token: servers[0].accessToken }) - expect(res.body.total).to.equal(3) + const body = await commands[0].getAdminList() + expect(body.total).to.equal(3) } }) @@ -257,18 +249,18 @@ describe('Test abuses', function () { { await addServerToServerBlocklist(servers[0].url, servers[0].accessToken, servers[1].host) - const res = await getAdminAbusesList({ url: servers[0].url, token: servers[0].accessToken }) - expect(res.body.total).to.equal(2) + const body = await commands[0].getAdminList() + expect(body.total).to.equal(2) - const abuse = res.body.data.find(a => a.reason === 'will mute this') + const abuse = body.data.find(a => a.reason === 'will mute this') expect(abuse).to.be.undefined } { await removeServerFromServerBlocklist(servers[0].url, servers[0].accessToken, serverToBlock) - const res = await getAdminAbusesList({ url: servers[0].url, token: servers[0].accessToken }) - expect(res.body.total).to.equal(3) + const body = await commands[0].getAdminList() + expect(body.total).to.equal(3) } }) @@ -279,11 +271,11 @@ describe('Test abuses', function () { await waitJobs(servers) - const res = await getAdminAbusesList({ url: servers[1].url, token: servers[1].accessToken }) - expect(res.body.total).to.equal(2, "wrong number of videos returned") - expect(res.body.data).to.have.lengthOf(2, "wrong number of videos returned") + const body = await commands[1].getAdminList() + expect(body.total).to.equal(2, "wrong number of videos returned") + expect(body.data).to.have.lengthOf(2, "wrong number of videos returned") - const abuse: AdminAbuse = res.body.data[0] + const abuse = body.data[0] expect(abuse.id).to.equal(abuseServer2.id, "wrong origin server id for first video") expect(abuse.video.id).to.equal(abuseServer2.video.id, "wrong video id") expect(abuse.video.channel).to.exist @@ -303,24 +295,21 @@ describe('Test abuses', function () { name: 'my second super name for server 1', description: 'my second super description for server 1' } - await uploadVideo(servers[0].url, userAccessToken, video3Attributes) - - const res1 = await getVideosList(servers[0].url) - const videos = res1.body.data - const video3 = videos.find(video => video.name === 'my second super name for server 1') + const resUpload = await uploadVideo(servers[0].url, userAccessToken, video3Attributes) + const video3Id = resUpload.body.video.id // resume with the test const reason3 = 'my super bad reason 3' - await reportAbuse({ url: servers[0].url, token: servers[0].accessToken, videoId: video3.id, reason: reason3 }) + await commands[0].report({ videoId: video3Id, reason: reason3 }) const reason4 = 'my super bad reason 4' - await reportAbuse({ url: servers[0].url, token: userAccessToken, videoId: servers[0].video.id, reason: reason4 }) + await commands[0].report({ token: userAccessToken, videoId: servers[0].video.id, reason: reason4 }) { - const res2 = await getAdminAbusesList({ url: servers[0].url, token: servers[0].accessToken }) - const abuses = res2.body.data as AdminAbuse[] + const body = await commands[0].getAdminList() + const abuses = body.data - const abuseVideo3 = res2.body.data.find(a => a.video.id === video3.id) + const abuseVideo3 = body.data.find(a => a.video.id === video3Id) expect(abuseVideo3).to.not.be.undefined expect(abuseVideo3.video.countReports).to.equal(1, "wrong reports count for video 3") expect(abuseVideo3.video.nthReport).to.equal(1, "wrong report position in report list for video 3") @@ -337,20 +326,18 @@ describe('Test abuses', function () { const reason5 = 'my super bad reason 5' const predefinedReasons5: AbusePredefinedReasonsString[] = [ 'violentOrRepulsive', 'captions' ] - const createdAbuse = (await reportAbuse({ - url: servers[0].url, - token: servers[0].accessToken, + const createRes = await commands[0].report({ videoId: servers[0].video.id, reason: reason5, predefinedReasons: predefinedReasons5, startAt: 1, endAt: 5 - })).body.abuse + }) - const res = await getAdminAbusesList({ url: servers[0].url, token: servers[0].accessToken }) + const body = await commands[0].getAdminList() { - const abuse = (res.body.data as AdminAbuse[]).find(a => a.id === createdAbuse.id) + const abuse = body.data.find(a => a.id === createRes.abuse.id) expect(abuse.reason).to.equals(reason5) expect(abuse.predefinedReasons).to.deep.equals(predefinedReasons5, "predefined reasons do not match the one reported") expect(abuse.video.startAt).to.equal(1, "starting timestamp doesn't match the one reported") @@ -361,37 +348,30 @@ describe('Test abuses', function () { it('Should delete the video abuse', async function () { this.timeout(10000) - await deleteAbuse(servers[1].url, servers[1].accessToken, abuseServer2.id) + await commands[1].delete({ abuseId: abuseServer2.id }) await waitJobs(servers) { - const res = await getAdminAbusesList({ url: servers[1].url, token: servers[1].accessToken }) - expect(res.body.total).to.equal(1) - expect(res.body.data.length).to.equal(1) - expect(res.body.data[0].id).to.not.equal(abuseServer2.id) + const body = await commands[1].getAdminList() + expect(body.total).to.equal(1) + expect(body.data.length).to.equal(1) + expect(body.data[0].id).to.not.equal(abuseServer2.id) } { - const res = await getAdminAbusesList({ url: servers[0].url, token: servers[0].accessToken }) - expect(res.body.total).to.equal(6) + const body = await commands[0].getAdminList() + expect(body.total).to.equal(6) } }) it('Should list and filter video abuses', async function () { this.timeout(10000) - async function list (query: Omit[0], 'url' | 'token'>) { - const options = { - url: servers[0].url, - token: servers[0].accessToken - } - - Object.assign(options, query) + async function list (query: Parameters[0]) { + const body = await commands[0].getAdminList(query) - const res = await getAdminAbusesList(options) - - return res.body.data as AdminAbuse[] + return body.data } expect(await list({ id: 56 })).to.have.lengthOf(0) @@ -452,7 +432,7 @@ describe('Test abuses', function () { const comment = await getComment(servers[0].url, servers[0].video.id) const reason = 'it is a bad comment' - await reportAbuse({ url: servers[0].url, token: servers[0].accessToken, commentId: comment.id, reason }) + await commands[0].report({ commentId: comment.id, reason }) await waitJobs(servers) }) @@ -460,12 +440,12 @@ describe('Test abuses', function () { it('Should have 1 comment abuse on server 1 and 0 on server 2', async function () { { const comment = await getComment(servers[0].url, servers[0].video.id) - const res = await getAdminAbusesList({ url: servers[0].url, token: servers[0].accessToken, filter: 'comment' }) + const body = await commands[0].getAdminList({ filter: 'comment' }) - expect(res.body.total).to.equal(1) - expect(res.body.data).to.have.lengthOf(1) + expect(body.total).to.equal(1) + expect(body.data).to.have.lengthOf(1) - const abuse: AdminAbuse = res.body.data[0] + const abuse = body.data[0] expect(abuse.reason).to.equal('it is a bad comment') expect(abuse.reporterAccount.name).to.equal('root') @@ -485,9 +465,9 @@ describe('Test abuses', function () { } { - const res = await getAdminAbusesList({ url: servers[1].url, token: servers[1].accessToken, filter: 'comment' }) - expect(res.body.total).to.equal(0) - expect(res.body.data.length).to.equal(0) + const body = await commands[1].getAdminList({ filter: 'comment' }) + expect(body.total).to.equal(0) + expect(body.data.length).to.equal(0) } }) @@ -497,7 +477,7 @@ describe('Test abuses', function () { const comment = await getComment(servers[0].url, servers[1].video.uuid) const reason = 'it is a really bad comment' - await reportAbuse({ url: servers[0].url, token: servers[0].accessToken, commentId: comment.id, reason }) + await commands[0].report({ commentId: comment.id, reason }) await waitJobs(servers) }) @@ -505,54 +485,58 @@ describe('Test abuses', function () { it('Should have 2 comment abuses on server 1 and 1 on server 2', async function () { const commentServer2 = await getComment(servers[0].url, servers[1].video.id) - const res1 = await getAdminAbusesList({ url: servers[0].url, token: servers[0].accessToken, filter: 'comment' }) - expect(res1.body.total).to.equal(2) - expect(res1.body.data.length).to.equal(2) + { + const body = await commands[0].getAdminList({ filter: 'comment' }) + expect(body.total).to.equal(2) + expect(body.data.length).to.equal(2) - const abuse: AdminAbuse = res1.body.data[0] - expect(abuse.reason).to.equal('it is a bad comment') - expect(abuse.countReportsForReporter).to.equal(6) - expect(abuse.countReportsForReportee).to.equal(5) + const abuse = body.data[0] + expect(abuse.reason).to.equal('it is a bad comment') + expect(abuse.countReportsForReporter).to.equal(6) + expect(abuse.countReportsForReportee).to.equal(5) - const abuse2: AdminAbuse = res1.body.data[1] + const abuse2 = body.data[1] - expect(abuse2.reason).to.equal('it is a really bad comment') + expect(abuse2.reason).to.equal('it is a really bad comment') - expect(abuse2.reporterAccount.name).to.equal('root') - expect(abuse2.reporterAccount.host).to.equal(servers[0].host) + expect(abuse2.reporterAccount.name).to.equal('root') + expect(abuse2.reporterAccount.host).to.equal(servers[0].host) - expect(abuse2.video).to.be.null + expect(abuse2.video).to.be.null - expect(abuse2.comment.deleted).to.be.false - expect(abuse2.comment.id).to.equal(commentServer2.id) - expect(abuse2.comment.text).to.equal(commentServer2.text) - expect(abuse2.comment.video.name).to.equal('server 2') - expect(abuse2.comment.video.uuid).to.equal(servers[1].video.uuid) + expect(abuse2.comment.deleted).to.be.false + expect(abuse2.comment.id).to.equal(commentServer2.id) + expect(abuse2.comment.text).to.equal(commentServer2.text) + expect(abuse2.comment.video.name).to.equal('server 2') + expect(abuse2.comment.video.uuid).to.equal(servers[1].video.uuid) - expect(abuse2.state.id).to.equal(AbuseState.PENDING) - expect(abuse2.state.label).to.equal('Pending') + expect(abuse2.state.id).to.equal(AbuseState.PENDING) + expect(abuse2.state.label).to.equal('Pending') - expect(abuse2.moderationComment).to.be.null + expect(abuse2.moderationComment).to.be.null - expect(abuse2.countReportsForReporter).to.equal(6) - expect(abuse2.countReportsForReportee).to.equal(2) + expect(abuse2.countReportsForReporter).to.equal(6) + expect(abuse2.countReportsForReportee).to.equal(2) + } - const res2 = await getAdminAbusesList({ url: servers[1].url, token: servers[1].accessToken, filter: 'comment' }) - expect(res2.body.total).to.equal(1) - expect(res2.body.data.length).to.equal(1) + { + const body = await commands[1].getAdminList({ filter: 'comment' }) + expect(body.total).to.equal(1) + expect(body.data.length).to.equal(1) - abuseServer2 = res2.body.data[0] - expect(abuseServer2.reason).to.equal('it is a really bad comment') - expect(abuseServer2.reporterAccount.name).to.equal('root') - expect(abuseServer2.reporterAccount.host).to.equal(servers[0].host) + abuseServer2 = body.data[0] + expect(abuseServer2.reason).to.equal('it is a really bad comment') + expect(abuseServer2.reporterAccount.name).to.equal('root') + expect(abuseServer2.reporterAccount.host).to.equal(servers[0].host) - expect(abuseServer2.state.id).to.equal(AbuseState.PENDING) - expect(abuseServer2.state.label).to.equal('Pending') + expect(abuseServer2.state.id).to.equal(AbuseState.PENDING) + expect(abuseServer2.state.label).to.equal('Pending') - expect(abuseServer2.moderationComment).to.be.null + expect(abuseServer2.moderationComment).to.be.null - expect(abuseServer2.countReportsForReporter).to.equal(1) - expect(abuseServer2.countReportsForReportee).to.equal(1) + expect(abuseServer2.countReportsForReporter).to.equal(1) + expect(abuseServer2.countReportsForReportee).to.equal(1) + } }) it('Should keep the comment abuse when deleting the comment', async function () { @@ -564,11 +548,11 @@ describe('Test abuses', function () { await waitJobs(servers) - const res = await getAdminAbusesList({ url: servers[0].url, token: servers[0].accessToken, filter: 'comment' }) - expect(res.body.total).to.equal(2) - expect(res.body.data).to.have.lengthOf(2) + const body = await commands[0].getAdminList({ filter: 'comment' }) + expect(body.total).to.equal(2) + expect(body.data).to.have.lengthOf(2) - const abuse = (res.body.data as AdminAbuse[]).find(a => a.comment?.id === commentServer2.id) + const abuse = body.data.find(a => a.comment?.id === commentServer2.id) expect(abuse).to.not.be.undefined expect(abuse.comment.text).to.be.empty @@ -579,53 +563,43 @@ describe('Test abuses', function () { it('Should delete the comment abuse', async function () { this.timeout(10000) - await deleteAbuse(servers[1].url, servers[1].accessToken, abuseServer2.id) + await commands[1].delete({ abuseId: abuseServer2.id }) await waitJobs(servers) { - const res = await getAdminAbusesList({ url: servers[1].url, token: servers[1].accessToken, filter: 'comment' }) - expect(res.body.total).to.equal(0) - expect(res.body.data.length).to.equal(0) + const body = await commands[1].getAdminList({ filter: 'comment' }) + expect(body.total).to.equal(0) + expect(body.data.length).to.equal(0) } { - const res = await getAdminAbusesList({ url: servers[0].url, token: servers[0].accessToken, filter: 'comment' }) - expect(res.body.total).to.equal(2) + const body = await commands[0].getAdminList({ filter: 'comment' }) + expect(body.total).to.equal(2) } }) it('Should list and filter video abuses', async function () { { - const res = await getAdminAbusesList({ - url: servers[0].url, - token: servers[0].accessToken, - filter: 'comment', - searchReportee: 'foo' - }) - expect(res.body.total).to.equal(0) + const body = await commands[0].getAdminList({ filter: 'comment', searchReportee: 'foo' }) + expect(body.total).to.equal(0) } { - const res = await getAdminAbusesList({ - url: servers[0].url, - token: servers[0].accessToken, - filter: 'comment', - searchReportee: 'ot' - }) - expect(res.body.total).to.equal(2) + const body = await commands[0].getAdminList({ filter: 'comment', searchReportee: 'ot' }) + expect(body.total).to.equal(2) } { - const baseParams = { url: servers[0].url, token: servers[0].accessToken, filter: 'comment' as AbuseFilter, start: 1, count: 1 } - - const res1 = await getAdminAbusesList(immutableAssign(baseParams, { sort: 'createdAt' })) - expect(res1.body.data).to.have.lengthOf(1) - expect(res1.body.data[0].comment.text).to.be.empty + const body = await commands[0].getAdminList({ filter: 'comment', start: 1, count: 1, sort: 'createdAt' }) + expect(body.data).to.have.lengthOf(1) + expect(body.data[0].comment.text).to.be.empty + } - const res2 = await getAdminAbusesList(immutableAssign(baseParams, { sort: '-createdAt' })) - expect(res2.body.data).to.have.lengthOf(1) - expect(res2.body.data[0].comment.text).to.equal('comment server 1') + { + const body = await commands[0].getAdminList({ filter: 'comment', start: 1, count: 1, sort: '-createdAt' }) + expect(body.data).to.have.lengthOf(1) + expect(body.data[0].comment.text).to.equal('comment server 1') } }) }) @@ -655,19 +629,19 @@ describe('Test abuses', function () { const account = await getAccountFromServer(servers[0].url, 'user_1', servers[0]) const reason = 'it is a bad account' - await reportAbuse({ url: servers[0].url, token: servers[0].accessToken, accountId: account.id, reason }) + await commands[0].report({ accountId: account.id, reason }) await waitJobs(servers) }) it('Should have 1 account abuse on server 1 and 0 on server 2', async function () { { - const res = await getAdminAbusesList({ url: servers[0].url, token: servers[0].accessToken, filter: 'account' }) + const body = await commands[0].getAdminList({ filter: 'account' }) - expect(res.body.total).to.equal(1) - expect(res.body.data).to.have.lengthOf(1) + expect(body.total).to.equal(1) + expect(body.data).to.have.lengthOf(1) - const abuse: AdminAbuse = res.body.data[0] + const abuse = body.data[0] expect(abuse.reason).to.equal('it is a bad account') expect(abuse.reporterAccount.name).to.equal('root') @@ -681,9 +655,9 @@ describe('Test abuses', function () { } { - const res = await getAdminAbusesList({ url: servers[1].url, token: servers[1].accessToken, filter: 'comment' }) - expect(res.body.total).to.equal(0) - expect(res.body.data.length).to.equal(0) + const body = await commands[1].getAdminList({ filter: 'comment' }) + expect(body.total).to.equal(0) + expect(body.data.length).to.equal(0) } }) @@ -693,48 +667,52 @@ describe('Test abuses', function () { const account = await getAccountFromServer(servers[0].url, 'user_2', servers[1]) const reason = 'it is a really bad account' - await reportAbuse({ url: servers[0].url, token: servers[0].accessToken, accountId: account.id, reason }) + await commands[0].report({ accountId: account.id, reason }) await waitJobs(servers) }) it('Should have 2 comment abuses on server 1 and 1 on server 2', async function () { - const res1 = await getAdminAbusesList({ url: servers[0].url, token: servers[0].accessToken, filter: 'account' }) - expect(res1.body.total).to.equal(2) - expect(res1.body.data.length).to.equal(2) + { + const body = await commands[0].getAdminList({ filter: 'account' }) + expect(body.total).to.equal(2) + expect(body.data.length).to.equal(2) - const abuse: AdminAbuse = res1.body.data[0] - expect(abuse.reason).to.equal('it is a bad account') + const abuse: AdminAbuse = body.data[0] + expect(abuse.reason).to.equal('it is a bad account') - const abuse2: AdminAbuse = res1.body.data[1] - expect(abuse2.reason).to.equal('it is a really bad account') + const abuse2: AdminAbuse = body.data[1] + expect(abuse2.reason).to.equal('it is a really bad account') - expect(abuse2.reporterAccount.name).to.equal('root') - expect(abuse2.reporterAccount.host).to.equal(servers[0].host) + expect(abuse2.reporterAccount.name).to.equal('root') + expect(abuse2.reporterAccount.host).to.equal(servers[0].host) - expect(abuse2.video).to.be.null - expect(abuse2.comment).to.be.null + expect(abuse2.video).to.be.null + expect(abuse2.comment).to.be.null - expect(abuse2.state.id).to.equal(AbuseState.PENDING) - expect(abuse2.state.label).to.equal('Pending') + expect(abuse2.state.id).to.equal(AbuseState.PENDING) + expect(abuse2.state.label).to.equal('Pending') - expect(abuse2.moderationComment).to.be.null + expect(abuse2.moderationComment).to.be.null + } - const res2 = await getAdminAbusesList({ url: servers[1].url, token: servers[1].accessToken, filter: 'account' }) - expect(res2.body.total).to.equal(1) - expect(res2.body.data.length).to.equal(1) + { + const body = await commands[1].getAdminList({ filter: 'account' }) + expect(body.total).to.equal(1) + expect(body.data.length).to.equal(1) - abuseServer2 = res2.body.data[0] + abuseServer2 = body.data[0] - expect(abuseServer2.reason).to.equal('it is a really bad account') + expect(abuseServer2.reason).to.equal('it is a really bad account') - expect(abuseServer2.reporterAccount.name).to.equal('root') - expect(abuseServer2.reporterAccount.host).to.equal(servers[0].host) + expect(abuseServer2.reporterAccount.name).to.equal('root') + expect(abuseServer2.reporterAccount.host).to.equal(servers[0].host) - expect(abuseServer2.state.id).to.equal(AbuseState.PENDING) - expect(abuseServer2.state.label).to.equal('Pending') + expect(abuseServer2.state.id).to.equal(AbuseState.PENDING) + expect(abuseServer2.state.label).to.equal('Pending') - expect(abuseServer2.moderationComment).to.be.null + expect(abuseServer2.moderationComment).to.be.null + } }) it('Should keep the account abuse when deleting the account', async function () { @@ -745,32 +723,32 @@ describe('Test abuses', function () { await waitJobs(servers) - const res = await getAdminAbusesList({ url: servers[0].url, token: servers[0].accessToken, filter: 'account' }) - expect(res.body.total).to.equal(2) - expect(res.body.data).to.have.lengthOf(2) + const body = await commands[0].getAdminList({ filter: 'account' }) + expect(body.total).to.equal(2) + expect(body.data).to.have.lengthOf(2) - const abuse = (res.body.data as AdminAbuse[]).find(a => a.reason === 'it is a really bad account') + const abuse = body.data.find(a => a.reason === 'it is a really bad account') expect(abuse).to.not.be.undefined }) it('Should delete the account abuse', async function () { this.timeout(10000) - await deleteAbuse(servers[1].url, servers[1].accessToken, abuseServer2.id) + await commands[1].delete({ abuseId: abuseServer2.id }) await waitJobs(servers) { - const res = await getAdminAbusesList({ url: servers[1].url, token: servers[1].accessToken, filter: 'account' }) - expect(res.body.total).to.equal(0) - expect(res.body.data.length).to.equal(0) + const body = await commands[1].getAdminList({ filter: 'account' }) + expect(body.total).to.equal(0) + expect(body.data.length).to.equal(0) } { - const res = await getAdminAbusesList({ url: servers[0].url, token: servers[0].accessToken, filter: 'account' }) - expect(res.body.total).to.equal(2) + const body = await commands[0].getAdminList({ filter: 'account' }) + expect(body.total).to.equal(2) - abuseServer1 = res.body.data[0] + abuseServer1 = body.data[0] } }) }) @@ -778,20 +756,18 @@ describe('Test abuses', function () { describe('Common actions on abuses', function () { it('Should update the state of an abuse', async function () { - const body = { state: AbuseState.REJECTED } - await updateAbuse(servers[0].url, servers[0].accessToken, abuseServer1.id, body) + await commands[0].update({ abuseId: abuseServer1.id, body: { state: AbuseState.REJECTED } }) - const res = await getAdminAbusesList({ url: servers[0].url, token: servers[0].accessToken, id: abuseServer1.id }) - expect(res.body.data[0].state.id).to.equal(AbuseState.REJECTED) + const body = await commands[0].getAdminList({ id: abuseServer1.id }) + expect(body.data[0].state.id).to.equal(AbuseState.REJECTED) }) it('Should add a moderation comment', async function () { - const body = { state: AbuseState.ACCEPTED, moderationComment: 'It is valid' } - await updateAbuse(servers[0].url, servers[0].accessToken, abuseServer1.id, body) + await commands[0].update({ abuseId: abuseServer1.id, body: { state: AbuseState.ACCEPTED, moderationComment: 'Valid' } }) - const res = await getAdminAbusesList({ url: servers[0].url, token: servers[0].accessToken, id: abuseServer1.id }) - expect(res.body.data[0].state.id).to.equal(AbuseState.ACCEPTED) - expect(res.body.data[0].moderationComment).to.equal('It is valid') + const body = await commands[0].getAdminList({ id: abuseServer1.id }) + expect(body.data[0].state.id).to.equal(AbuseState.ACCEPTED) + expect(body.data[0].moderationComment).to.equal('Valid') }) }) @@ -802,18 +778,18 @@ describe('Test abuses', function () { before(async function () { userAccessToken = await generateUserAccessToken(servers[0], 'user_42') - await reportAbuse({ url: servers[0].url, token: userAccessToken, videoId: servers[0].video.id, reason: 'user reason 1' }) + await commands[0].report({ token: userAccessToken, videoId: servers[0].video.id, reason: 'user reason 1' }) const videoId = await getVideoIdFromUUID(servers[0].url, servers[1].video.uuid) - await reportAbuse({ url: servers[0].url, token: userAccessToken, videoId, reason: 'user reason 2' }) + await commands[0].report({ token: userAccessToken, videoId, reason: 'user reason 2' }) }) it('Should correctly list my abuses', async function () { { - const res = await getUserAbusesList({ url: servers[0].url, token: userAccessToken, start: 0, count: 5, sort: 'createdAt' }) - expect(res.body.total).to.equal(2) + const body = await commands[0].getUserList({ token: userAccessToken, start: 0, count: 5, sort: 'createdAt' }) + expect(body.total).to.equal(2) - const abuses: UserAbuse[] = res.body.data + const abuses = body.data expect(abuses[0].reason).to.equal('user reason 1') expect(abuses[1].reason).to.equal('user reason 2') @@ -821,95 +797,77 @@ describe('Test abuses', function () { } { - const res = await getUserAbusesList({ url: servers[0].url, token: userAccessToken, start: 1, count: 1, sort: 'createdAt' }) - expect(res.body.total).to.equal(2) + const body = await commands[0].getUserList({ token: userAccessToken, start: 1, count: 1, sort: 'createdAt' }) + expect(body.total).to.equal(2) - const abuses: UserAbuse[] = res.body.data + const abuses: UserAbuse[] = body.data expect(abuses[0].reason).to.equal('user reason 2') } { - const res = await getUserAbusesList({ url: servers[0].url, token: userAccessToken, start: 1, count: 1, sort: '-createdAt' }) - expect(res.body.total).to.equal(2) + const body = await commands[0].getUserList({ token: userAccessToken, start: 1, count: 1, sort: '-createdAt' }) + expect(body.total).to.equal(2) - const abuses: UserAbuse[] = res.body.data + const abuses: UserAbuse[] = body.data expect(abuses[0].reason).to.equal('user reason 1') } }) it('Should correctly filter my abuses by id', async function () { - const res = await getUserAbusesList({ url: servers[0].url, token: userAccessToken, id: abuseId1 }) - - expect(res.body.total).to.equal(1) + const body = await commands[0].getUserList({ token: userAccessToken, id: abuseId1 }) + expect(body.total).to.equal(1) - const abuses: UserAbuse[] = res.body.data + const abuses: UserAbuse[] = body.data expect(abuses[0].reason).to.equal('user reason 1') }) it('Should correctly filter my abuses by search', async function () { - const res = await getUserAbusesList({ - url: servers[0].url, - token: userAccessToken, - search: 'server 2' - }) - - expect(res.body.total).to.equal(1) + const body = await commands[0].getUserList({ token: userAccessToken, search: 'server 2' }) + expect(body.total).to.equal(1) - const abuses: UserAbuse[] = res.body.data + const abuses: UserAbuse[] = body.data expect(abuses[0].reason).to.equal('user reason 2') }) it('Should correctly filter my abuses by state', async function () { - const body = { state: AbuseState.REJECTED } - await updateAbuse(servers[0].url, servers[0].accessToken, abuseId1, body) - - const res = await getUserAbusesList({ - url: servers[0].url, - token: userAccessToken, - state: AbuseState.REJECTED - }) + await commands[0].update({ abuseId: abuseId1, body: { state: AbuseState.REJECTED } }) - expect(res.body.total).to.equal(1) + const body = await commands[0].getUserList({ token: userAccessToken, state: AbuseState.REJECTED }) + expect(body.total).to.equal(1) - const abuses: UserAbuse[] = res.body.data + const abuses: UserAbuse[] = body.data expect(abuses[0].reason).to.equal('user reason 1') }) }) describe('Abuse messages', async function () { let abuseId: number - let userAccessToken: string + let userToken: string let abuseMessageUserId: number let abuseMessageModerationId: number before(async function () { - userAccessToken = await generateUserAccessToken(servers[0], 'user_43') - - const res = await reportAbuse({ - url: servers[0].url, - token: userAccessToken, - videoId: servers[0].video.id, - reason: 'user 43 reason 1' - }) + userToken = await generateUserAccessToken(servers[0], 'user_43') - abuseId = res.body.abuse.id + const body = await commands[0].report({ token: userToken, videoId: servers[0].video.id, reason: 'user 43 reason 1' }) + abuseId = body.abuse.id }) it('Should create some messages on the abuse', async function () { - await addAbuseMessage(servers[0].url, userAccessToken, abuseId, 'message 1') - await addAbuseMessage(servers[0].url, servers[0].accessToken, abuseId, 'message 2') - await addAbuseMessage(servers[0].url, servers[0].accessToken, abuseId, 'message 3') - await addAbuseMessage(servers[0].url, userAccessToken, abuseId, 'message 4') + await commands[0].addMessage({ token: userToken, abuseId, message: 'message 1' }) + await commands[0].addMessage({ abuseId, message: 'message 2' }) + await commands[0].addMessage({ abuseId, message: 'message 3' }) + await commands[0].addMessage({ token: userToken, abuseId, message: 'message 4' }) }) it('Should have the correct messages count when listing abuses', async function () { const results = await Promise.all([ - getAdminAbusesList({ url: servers[0].url, token: servers[0].accessToken, start: 0, count: 50 }), - getUserAbusesList({ url: servers[0].url, token: userAccessToken, start: 0, count: 50 }) + commands[0].getAdminList({ start: 0, count: 50 }), + commands[0].getUserList({ token: userToken, start: 0, count: 50 }) ]) - for (const res of results) { - const abuses: AdminAbuse[] = res.body.data + for (const body of results) { + const abuses = body.data const abuse = abuses.find(a => a.id === abuseId) expect(abuse.countMessages).to.equal(4) } @@ -917,14 +875,14 @@ describe('Test abuses', function () { it('Should correctly list messages of this abuse', async function () { const results = await Promise.all([ - listAbuseMessages(servers[0].url, servers[0].accessToken, abuseId), - listAbuseMessages(servers[0].url, userAccessToken, abuseId) + commands[0].listMessages({ abuseId }), + commands[0].listMessages({ token: userToken, abuseId }) ]) - for (const res of results) { - expect(res.body.total).to.equal(4) + for (const body of results) { + expect(body.total).to.equal(4) - const abuseMessages: AbuseMessage[] = res.body.data + const abuseMessages: AbuseMessage[] = body.data expect(abuseMessages[0].message).to.equal('message 1') expect(abuseMessages[0].byModerator).to.be.false @@ -948,19 +906,18 @@ describe('Test abuses', function () { }) it('Should delete messages', async function () { - await deleteAbuseMessage(servers[0].url, servers[0].accessToken, abuseId, abuseMessageModerationId) - await deleteAbuseMessage(servers[0].url, userAccessToken, abuseId, abuseMessageUserId) + await commands[0].deleteMessage({ abuseId, messageId: abuseMessageModerationId }) + await commands[0].deleteMessage({ token: userToken, abuseId, messageId: abuseMessageUserId }) const results = await Promise.all([ - listAbuseMessages(servers[0].url, servers[0].accessToken, abuseId), - listAbuseMessages(servers[0].url, userAccessToken, abuseId) + commands[0].listMessages({ abuseId }), + commands[0].listMessages({ token: userToken, abuseId }) ]) - for (const res of results) { - expect(res.body.total).to.equal(2) - - const abuseMessages: AbuseMessage[] = res.body.data + for (const body of results) { + expect(body.total).to.equal(2) + const abuseMessages: AbuseMessage[] = body.data expect(abuseMessages[0].message).to.equal('message 2') expect(abuseMessages[1].message).to.equal('message 4') } diff --git a/server/tests/api/notifications/moderation-notifications.ts b/server/tests/api/notifications/moderation-notifications.ts index a7671696f..f77719c68 100644 --- a/server/tests/api/notifications/moderation-notifications.ts +++ b/server/tests/api/notifications/moderation-notifications.ts @@ -2,11 +2,23 @@ import 'mocha' import { buildUUID } from '@server/helpers/uuid' -import { AbuseState } from '@shared/models' import { - addAbuseMessage, + addUserSubscription, addVideoCommentThread, addVideoToBlacklist, + checkAbuseStateChange, + checkAutoInstanceFollowing, + CheckerBaseParams, + checkNewAbuseMessage, + checkNewAccountAbuseForModerators, + checkNewBlacklistOnMyVideo, + checkNewCommentAbuseForModerators, + checkNewInstanceFollower, + checkNewVideoAbuseForModerators, + checkNewVideoFromSubscription, + checkUserRegistered, + checkVideoAutoBlacklistForModerators, + checkVideoIsPublished, cleanupTests, createUser, follow, @@ -17,38 +29,20 @@ import { getVideoIdFromUUID, immutableAssign, MockInstancesIndex, + MockSmtpServer, + prepareNotificationsTest, registerUser, + removeUserSubscription, removeVideoFromBlacklist, - reportAbuse, + ServerInfo, unfollow, - updateAbuse, updateCustomConfig, updateCustomSubConfig, - wait -} from '../../../../shared/extra-utils' -import { ServerInfo, uploadVideo } from '../../../../shared/extra-utils/index' -import { MockSmtpServer } from '../../../../shared/extra-utils/mock-servers/mock-email' -import { waitJobs } from '../../../../shared/extra-utils/server/jobs' -import { - checkAbuseStateChange, - checkAutoInstanceFollowing, - CheckerBaseParams, - checkNewAbuseMessage, - checkNewAccountAbuseForModerators, - checkNewBlacklistOnMyVideo, - checkNewCommentAbuseForModerators, - checkNewInstanceFollower, - checkNewVideoAbuseForModerators, - checkNewVideoFromSubscription, - checkUserRegistered, - checkVideoAutoBlacklistForModerators, - checkVideoIsPublished, - prepareNotificationsTest -} from '../../../../shared/extra-utils/users/user-notifications' -import { addUserSubscription, removeUserSubscription } from '../../../../shared/extra-utils/users/user-subscriptions' -import { CustomConfig } from '../../../../shared/models/server' -import { UserNotification } from '../../../../shared/models/users' -import { VideoPrivacy } from '../../../../shared/models/videos' + uploadVideo, + wait, + waitJobs +} from '@shared/extra-utils' +import { AbuseState, CustomConfig, UserNotification, VideoPrivacy } from '@shared/models' describe('Test moderation notifications', function () { let servers: ServerInfo[] = [] @@ -89,7 +83,7 @@ describe('Test moderation notifications', function () { const resVideo = await uploadVideo(servers[0].url, userAccessToken, { name }) const video = resVideo.body.video - await reportAbuse({ url: servers[0].url, token: servers[0].accessToken, videoId: video.id, reason: 'super reason' }) + await servers[0].abusesCommand.report({ videoId: video.id, reason: 'super reason' }) await waitJobs(servers) await checkNewVideoAbuseForModerators(baseParams, video.uuid, name, 'presence') @@ -105,7 +99,7 @@ describe('Test moderation notifications', function () { await waitJobs(servers) const videoId = await getVideoIdFromUUID(servers[1].url, video.uuid) - await reportAbuse({ url: servers[1].url, token: servers[1].accessToken, videoId, reason: 'super reason' }) + await servers[1].abusesCommand.report({ videoId, reason: 'super reason' }) await waitJobs(servers) await checkNewVideoAbuseForModerators(baseParams, video.uuid, name, 'presence') @@ -122,7 +116,7 @@ describe('Test moderation notifications', function () { await waitJobs(servers) - await reportAbuse({ url: servers[0].url, token: servers[0].accessToken, commentId: comment.id, reason: 'super reason' }) + await servers[0].abusesCommand.report({ commentId: comment.id, reason: 'super reason' }) await waitJobs(servers) await checkNewCommentAbuseForModerators(baseParams, video.uuid, name, 'presence') @@ -140,7 +134,7 @@ describe('Test moderation notifications', function () { const resComments = await getVideoCommentThreads(servers[1].url, video.uuid, 0, 5) const commentId = resComments.body.data[0].id - await reportAbuse({ url: servers[1].url, token: servers[1].accessToken, commentId, reason: 'super reason' }) + await servers[1].abusesCommand.report({ commentId, reason: 'super reason' }) await waitJobs(servers) await checkNewCommentAbuseForModerators(baseParams, video.uuid, name, 'presence') @@ -153,7 +147,7 @@ describe('Test moderation notifications', function () { const resUser = await createUser({ url: servers[0].url, accessToken: servers[0].accessToken, username, password: 'donald' }) const accountId = resUser.body.user.account.id - await reportAbuse({ url: servers[0].url, token: servers[0].accessToken, accountId, reason: 'super reason' }) + await servers[0].abusesCommand.report({ accountId, reason: 'super reason' }) await waitJobs(servers) await checkNewAccountAbuseForModerators(baseParams, username, 'presence') @@ -169,7 +163,7 @@ describe('Test moderation notifications', function () { await waitJobs(servers) const resAccount = await getAccount(servers[1].url, username + '@' + servers[0].host) - await reportAbuse({ url: servers[1].url, token: servers[1].accessToken, accountId: resAccount.body.id, reason: 'super reason' }) + await servers[1].abusesCommand.report({ accountId: resAccount.body.id, reason: 'super reason' }) await waitJobs(servers) await checkNewAccountAbuseForModerators(baseParams, username, 'presence') @@ -192,14 +186,14 @@ describe('Test moderation notifications', function () { const resVideo = await uploadVideo(servers[0].url, userAccessToken, { name }) const video = resVideo.body.video - const res = await reportAbuse({ url: servers[0].url, token: userAccessToken, videoId: video.id, reason: 'super reason' }) - abuseId = res.body.abuse.id + const body = await servers[0].abusesCommand.report({ token: userAccessToken, videoId: video.id, reason: 'super reason' }) + abuseId = body.abuse.id }) it('Should send a notification to reporter if the abuse has been accepted', async function () { this.timeout(10000) - await updateAbuse(servers[0].url, servers[0].accessToken, abuseId, { state: AbuseState.ACCEPTED }) + await servers[0].abusesCommand.update({ abuseId, body: { state: AbuseState.ACCEPTED } }) await waitJobs(servers) await checkAbuseStateChange(baseParams, abuseId, AbuseState.ACCEPTED, 'presence') @@ -208,7 +202,7 @@ describe('Test moderation notifications', function () { it('Should send a notification to reporter if the abuse has been rejected', async function () { this.timeout(10000) - await updateAbuse(servers[0].url, servers[0].accessToken, abuseId, { state: AbuseState.REJECTED }) + await servers[0].abusesCommand.update({ abuseId, body: { state: AbuseState.REJECTED } }) await waitJobs(servers) await checkAbuseStateChange(baseParams, abuseId, AbuseState.REJECTED, 'presence') @@ -241,13 +235,13 @@ describe('Test moderation notifications', function () { const video = resVideo.body.video { - const res = await reportAbuse({ url: servers[0].url, token: userAccessToken, videoId: video.id, reason: 'super reason' }) - abuseId = res.body.abuse.id + const body = await servers[0].abusesCommand.report({ token: userAccessToken, videoId: video.id, reason: 'super reason' }) + abuseId = body.abuse.id } { - const res = await reportAbuse({ url: servers[0].url, token: userAccessToken, videoId: video.id, reason: 'super reason 2' }) - abuseId2 = res.body.abuse.id + const body = await servers[0].abusesCommand.report({ token: userAccessToken, videoId: video.id, reason: 'super reason 2' }) + abuseId2 = body.abuse.id } }) @@ -255,7 +249,7 @@ describe('Test moderation notifications', function () { this.timeout(10000) const message = 'my super message to users' - await addAbuseMessage(servers[0].url, servers[0].accessToken, abuseId, message) + await servers[0].abusesCommand.addMessage({ abuseId, message }) await waitJobs(servers) await checkNewAbuseMessage(baseParamsUser, abuseId, message, 'user_1@example.com', 'presence') @@ -265,7 +259,7 @@ describe('Test moderation notifications', function () { this.timeout(10000) const message = 'my super message that should not be sent to the admin' - await addAbuseMessage(servers[0].url, servers[0].accessToken, abuseId, message) + await servers[0].abusesCommand.addMessage({ abuseId, message }) await waitJobs(servers) await checkNewAbuseMessage(baseParamsAdmin, abuseId, message, 'admin' + servers[0].internalServerNumber + '@example.com', 'absence') @@ -275,7 +269,7 @@ describe('Test moderation notifications', function () { this.timeout(10000) const message = 'my super message to moderators' - await addAbuseMessage(servers[0].url, userAccessToken, abuseId2, message) + await servers[0].abusesCommand.addMessage({ token: userAccessToken, abuseId: abuseId2, message }) await waitJobs(servers) await checkNewAbuseMessage(baseParamsAdmin, abuseId2, message, 'admin' + servers[0].internalServerNumber + '@example.com', 'presence') @@ -285,7 +279,7 @@ describe('Test moderation notifications', function () { this.timeout(10000) const message = 'my super message that should not be sent to reporter' - await addAbuseMessage(servers[0].url, userAccessToken, abuseId2, message) + await servers[0].abusesCommand.addMessage({ token: userAccessToken, abuseId: abuseId2, message }) await waitJobs(servers) await checkNewAbuseMessage(baseParamsUser, abuseId2, message, 'user_1@example.com', 'absence') diff --git a/server/tests/api/server/email.ts b/server/tests/api/server/email.ts index 41071692a..85844ae9d 100644 --- a/server/tests/api/server/email.ts +++ b/server/tests/api/server/email.ts @@ -12,7 +12,6 @@ import { createUser, flushAndRunServer, removeVideoFromBlacklist, - reportAbuse, resetPassword, ServerInfo, setAccessTokensToServers, @@ -190,7 +189,7 @@ describe('Test emails', function () { this.timeout(10000) const reason = 'my super bad reason' - await reportAbuse({ url: server.url, token: server.accessToken, videoId, reason }) + await server.abusesCommand.report({ videoId, reason }) await waitJobs(server) expect(emails).to.have.lengthOf(3) diff --git a/server/tests/api/users/users.ts b/server/tests/api/users/users.ts index 87ba775f6..6bfc7cfe5 100644 --- a/server/tests/api/users/users.ts +++ b/server/tests/api/users/users.ts @@ -2,9 +2,7 @@ import 'mocha' import * as chai from 'chai' -import { AbuseState, AbuseUpdate, MyUser, User, UserRole, Video, VideoPlaylistType } from '@shared/models' -import { CustomConfig, OAuth2ErrorCode } from '@shared/models/server' -import { HttpStatusCode } from '../../../../shared/core-utils/miscs/http-error-codes' +import { HttpStatusCode } from '@shared/core-utils' import { addVideoCommentThread, blockUser, @@ -13,13 +11,14 @@ import { createUser, deleteMe, flushAndRunServer, + follow, getAccountRatings, - getAdminAbusesList, getBlacklistedVideosList, getCustomConfig, getMyUserInformation, getMyUserVideoQuotaUsed, getMyUserVideoRating, + getMyVideos, getUserInformation, getUsersList, getUsersListPaginationAndSort, @@ -28,18 +27,19 @@ import { installPlugin, killallServers, login, + logout, makePutBodyRequest, rateVideo, + refreshToken, registerUserWithChannel, removeUser, removeVideo, - reportAbuse, reRunServer, ServerInfo, + setAccessTokensToServers, setTokenField, testImage, unblockUser, - updateAbuse, updateCustomSubConfig, updateMyAvatar, updateMyUser, @@ -47,11 +47,8 @@ import { uploadVideo, userLogin, waitJobs -} from '../../../../shared/extra-utils' -import { follow } from '../../../../shared/extra-utils/server/follows' -import { logout, refreshToken, setAccessTokensToServers } from '../../../../shared/extra-utils/users/login' -import { getMyVideos } from '../../../../shared/extra-utils/videos/videos' -import { UserAdminFlag } from '../../../../shared/models/users/user-flag.model' +} from '@shared/extra-utils' +import { AbuseState, CustomConfig, MyUser, OAuth2ErrorCode, User, UserAdminFlag, UserRole, Video, VideoPlaylistType } from '@shared/models' const expect = chai.expect @@ -1002,10 +999,10 @@ describe('Test users', function () { it('Should report correct abuses counts', async function () { const reason = 'my super bad reason' - await reportAbuse({ url: server.url, token: user17AccessToken, videoId, reason }) + await server.abusesCommand.report({ token: user17AccessToken, videoId, reason }) - const res1 = await getAdminAbusesList({ url: server.url, token: server.accessToken }) - const abuseId = res1.body.data[0].id + const body1 = await server.abusesCommand.getAdminList() + const abuseId = body1.data[0].id const res2 = await getUserInformation(server.url, server.accessToken, user17Id, true) const user2: User = res2.body @@ -1013,8 +1010,7 @@ describe('Test users', function () { expect(user2.abusesCount).to.equal(1) // number of incriminations expect(user2.abusesCreatedCount).to.equal(1) // number of reports created - const body: AbuseUpdate = { state: AbuseState.ACCEPTED } - await updateAbuse(server.url, server.accessToken, abuseId, body) + await server.abusesCommand.update({ abuseId, body: { state: AbuseState.ACCEPTED } }) const res3 = await getUserInformation(server.url, server.accessToken, user17Id, true) const user3: User = res3.body -- 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 ++- server/tests/api/videos/video-nsfw.ts | 35 ++++++----- server/tests/api/videos/videos-overview.ts | 71 +++++++++-------------- 3 files changed, 52 insertions(+), 63 deletions(-) (limited to 'server/tests/api') 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 }) }) }) diff --git a/server/tests/api/videos/video-nsfw.ts b/server/tests/api/videos/video-nsfw.ts index b16b484b9..6c98c9f12 100644 --- a/server/tests/api/videos/video-nsfw.ts +++ b/server/tests/api/videos/video-nsfw.ts @@ -1,34 +1,33 @@ /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */ -import * as chai from 'chai' import 'mocha' -import { cleanupTests, getVideosList, ServerInfo, setAccessTokensToServers, uploadVideo } from '../../../../shared/extra-utils/index' -import { userLogin } from '../../../../shared/extra-utils/users/login' -import { createUser } from '../../../../shared/extra-utils/users/users' -import { getMyVideos } from '../../../../shared/extra-utils/videos/videos' +import * as chai from 'chai' import { + cleanupTests, + createUser, flushAndRunServer, getAccountVideos, getConfig, getCustomConfig, getMyUserInformation, + getMyVideos, getVideoChannelVideos, + getVideosList, getVideosListWithToken, searchVideo, searchVideoWithToken, + ServerInfo, + setAccessTokensToServers, updateCustomConfig, - updateMyUser -} from '../../../../shared/extra-utils' -import { ServerConfig, VideosOverview } from '../../../../shared/models' -import { CustomConfig } from '../../../../shared/models/server/custom-config.model' -import { User } from '../../../../shared/models/users' -import { getVideosOverview, getVideosOverviewWithToken } from '@shared/extra-utils/overviews/overviews' + updateMyUser, + uploadVideo, + userLogin +} from '@shared/extra-utils' +import { CustomConfig, ServerConfig, User, VideosOverview } from '@shared/models' const expect = chai.expect -function createOverviewRes (res: any) { - const overview = res.body as VideosOverview - +function createOverviewRes (overview: VideosOverview) { const videos = overview.categories[0].videos return { body: { data: videos, total: videos.length } } } @@ -57,7 +56,9 @@ describe('Test video NSFW policy', function () { // Overviews do not support video filters if (!hasQuery) { - promises.push(getVideosOverviewWithToken(server.url, 1, token).then(res => createOverviewRes(res))) + const p = server.overviewsCommand.getVideos({ page: 1, token }) + .then(res => createOverviewRes(res)) + promises.push(p) } return Promise.all(promises) @@ -72,7 +73,9 @@ describe('Test video NSFW policy', function () { // Overviews do not support video filters if (!hasQuery) { - promises.push(getVideosOverview(server.url, 1).then(res => createOverviewRes(res))) + const p = server.overviewsCommand.getVideos({ page: 1 }) + .then(res => createOverviewRes(res)) + promises.push(p) } return Promise.all(promises) diff --git a/server/tests/api/videos/videos-overview.ts b/server/tests/api/videos/videos-overview.ts index c266a1dc5..c8e3df4bd 100644 --- a/server/tests/api/videos/videos-overview.ts +++ b/server/tests/api/videos/videos-overview.ts @@ -2,8 +2,9 @@ import 'mocha' import * as chai from 'chai' - +import { Response } from 'superagent' import { + addAccountToAccountBlocklist, cleanupTests, flushAndRunServer, generateUserAccessToken, @@ -11,20 +12,15 @@ import { setAccessTokensToServers, uploadVideo, wait -} from '../../../../shared/extra-utils' -import { getVideosOverview, getVideosOverviewWithToken } from '../../../../shared/extra-utils/overviews/overviews' -import { VideosOverview } from '../../../../shared/models/overviews' -import { addAccountToAccountBlocklist } from '@shared/extra-utils/users/blocklist' -import { Response } from 'superagent' +} from '@shared/extra-utils' +import { VideosOverview } from '@shared/models' const expect = chai.expect describe('Test a videos overview', function () { let server: ServerInfo = null - function testOverviewCount (res: Response, expected: number) { - const overview: VideosOverview = res.body - + function testOverviewCount (overview: VideosOverview, expected: number) { expect(overview.tags).to.have.lengthOf(expected) expect(overview.categories).to.have.lengthOf(expected) expect(overview.channels).to.have.lengthOf(expected) @@ -39,9 +35,9 @@ describe('Test a videos overview', function () { }) it('Should send empty overview', async function () { - const res = await getVideosOverview(server.url, 1) + const body = await server.overviewsCommand.getVideos({ page: 1 }) - testOverviewCount(res, 0) + testOverviewCount(body, 0) }) it('Should upload 5 videos in a specific category, tag and channel but not include them in overview', async function () { @@ -55,34 +51,35 @@ describe('Test a videos overview', function () { tags: [ 'coucou1', 'coucou2' ] }) - const res = await getVideosOverview(server.url, 1) + const body = await server.overviewsCommand.getVideos({ page: 1 }) - testOverviewCount(res, 0) + testOverviewCount(body, 0) }) it('Should upload another video and include all videos in the overview', async function () { this.timeout(30000) - for (let i = 1; i < 6; i++) { - await uploadVideo(server.url, server.accessToken, { - name: 'video ' + i, - category: 3, - tags: [ 'coucou1', 'coucou2' ] - }) + { + for (let i = 1; i < 6; i++) { + await uploadVideo(server.url, server.accessToken, { + name: 'video ' + i, + category: 3, + tags: [ 'coucou1', 'coucou2' ] + }) + } + + await wait(3000) } - await wait(3000) - { - const res = await getVideosOverview(server.url, 1) + const body = await server.overviewsCommand.getVideos({ page: 1 }) - testOverviewCount(res, 1) + testOverviewCount(body, 1) } { - const res = await getVideosOverview(server.url, 2) + const overview = await server.overviewsCommand.getVideos({ page: 2 }) - const overview: VideosOverview = res.body expect(overview.tags).to.have.lengthOf(1) expect(overview.categories).to.have.lengthOf(0) expect(overview.channels).to.have.lengthOf(0) @@ -90,20 +87,10 @@ describe('Test a videos overview', function () { }) it('Should have the correct overview', async function () { - const res1 = await getVideosOverview(server.url, 1) - const res2 = await getVideosOverview(server.url, 2) - - const overview1: VideosOverview = res1.body - const overview2: VideosOverview = res2.body - - const tmp = [ - overview1.tags, - overview1.categories, - overview1.channels, - overview2.tags - ] + const overview1 = await server.overviewsCommand.getVideos({ page: 1 }) + const overview2 = await server.overviewsCommand.getVideos({ page: 2 }) - for (const arr of tmp) { + for (const arr of [ overview1.tags, overview1.categories, overview1.channels, overview2.tags ]) { expect(arr).to.have.lengthOf(1) const obj = arr[0] @@ -132,15 +119,15 @@ describe('Test a videos overview', function () { await addAccountToAccountBlocklist(server.url, token, 'root@' + server.host) { - const res = await getVideosOverview(server.url, 1) + const body = await server.overviewsCommand.getVideos({ page: 1 }) - testOverviewCount(res, 1) + testOverviewCount(body, 1) } { - const res = await getVideosOverviewWithToken(server.url, 1, token) + const body = await server.overviewsCommand.getVideos({ page: 1, token }) - testOverviewCount(res, 0) + testOverviewCount(body, 0) } }) -- cgit v1.2.3 From af971e06c620bd46a5aa64c8833364e7022b5e3d Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Tue, 6 Jul 2021 15:22:51 +0200 Subject: Introduce search command --- server/tests/api/moderation/video-blacklist.ts | 31 ++- .../search/search-activitypub-video-channels.ts | 83 ++++---- .../search/search-activitypub-video-playlists.ts | 84 ++++---- .../tests/api/search/search-activitypub-videos.ts | 81 ++++---- server/tests/api/search/search-channels.ts | 29 +-- server/tests/api/search/search-index.ts | 129 +++++++------ server/tests/api/search/search-playlists.ts | 36 ++-- server/tests/api/search/search-videos.ts | 211 ++++++++++++--------- server/tests/api/videos/video-nsfw.ts | 14 +- server/tests/api/videos/videos-history.ts | 15 +- 10 files changed, 372 insertions(+), 341 deletions(-) (limited to 'server/tests/api') diff --git a/server/tests/api/moderation/video-blacklist.ts b/server/tests/api/moderation/video-blacklist.ts index 52cac20d9..4a4930c98 100644 --- a/server/tests/api/moderation/video-blacklist.ts +++ b/server/tests/api/moderation/video-blacklist.ts @@ -7,6 +7,7 @@ import { addVideoToBlacklist, cleanupTests, createUser, + doubleFollow, flushAndRunMultipleServers, getBlacklistedVideosList, getMyUserInformation, @@ -15,20 +16,16 @@ import { killallServers, removeVideoFromBlacklist, reRunServer, - searchVideo, ServerInfo, setAccessTokensToServers, updateVideo, updateVideoBlacklist, uploadVideo, - userLogin -} from '../../../../shared/extra-utils/index' -import { doubleFollow } from '../../../../shared/extra-utils/server/follows' -import { waitJobs } from '../../../../shared/extra-utils/server/jobs' -import { getGoodVideoUrl, getMagnetURI, importVideo } from '../../../../shared/extra-utils/videos/video-imports' -import { User, UserRole } from '../../../../shared/models/users' -import { UserAdminFlag } from '../../../../shared/models/users/user-flag.model' -import { VideoBlacklist, VideoBlacklistType } from '../../../../shared/models/videos' + userLogin, + waitJobs +} from '@shared/extra-utils' +import { getGoodVideoUrl, getMagnetURI, importVideo } from '@shared/extra-utils/videos/video-imports' +import { User, UserAdminFlag, UserRole, VideoBlacklist, VideoBlacklistType } from '@shared/models' const expect = chai.expect @@ -80,11 +77,11 @@ describe('Test video blacklist', function () { } { - const res = await searchVideo(servers[0].url, 'name') + const body = await servers[0].searchCommand.searchVideos({ search: 'name' }) - expect(res.body.total).to.equal(0) - expect(res.body.data).to.be.an('array') - expect(res.body.data.length).to.equal(0) + expect(body.total).to.equal(0) + expect(body.data).to.be.an('array') + expect(body.data.length).to.equal(0) } }) @@ -98,11 +95,11 @@ describe('Test video blacklist', function () { } { - const res = await searchVideo(servers[1].url, 'video') + const body = await servers[1].searchCommand.searchVideos({ search: 'name' }) - expect(res.body.total).to.equal(2) - expect(res.body.data).to.be.an('array') - expect(res.body.data.length).to.equal(2) + expect(body.total).to.equal(2) + expect(body.data).to.be.an('array') + expect(body.data.length).to.equal(2) } }) }) diff --git a/server/tests/api/search/search-activitypub-video-channels.ts b/server/tests/api/search/search-activitypub-video-channels.ts index e83eb7171..cf5158b66 100644 --- a/server/tests/api/search/search-activitypub-video-channels.ts +++ b/server/tests/api/search/search-activitypub-video-channels.ts @@ -1,7 +1,7 @@ /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */ -import * as chai from 'chai' import 'mocha' +import * as chai from 'chai' import { addVideoChannel, cleanupTests, @@ -10,6 +10,7 @@ import { flushAndRunMultipleServers, getVideoChannelsList, getVideoChannelVideos, + SearchCommand, ServerInfo, setAccessTokensToServers, updateMyUser, @@ -17,11 +18,10 @@ import { updateVideoChannel, uploadVideo, userLogin, - wait -} from '../../../../shared/extra-utils' -import { waitJobs } from '../../../../shared/extra-utils/server/jobs' -import { VideoChannel } from '../../../../shared/models/videos' -import { searchVideoChannel } from '../../../../shared/extra-utils/search/video-channels' + wait, + waitJobs +} from '@shared/extra-utils' +import { VideoChannel } from '@shared/models' const expect = chai.expect @@ -30,6 +30,7 @@ describe('Test ActivityPub video channels search', function () { let userServer2Token: string let videoServer2UUID: string let channelIdServer2: number + let command: SearchCommand before(async function () { this.timeout(120000) @@ -64,6 +65,8 @@ describe('Test ActivityPub video channels search', function () { } await waitJobs(servers) + + command = servers[0].searchCommand }) it('Should not find a remote video channel', async function () { @@ -71,21 +74,21 @@ describe('Test ActivityPub video channels search', function () { { const search = 'http://localhost:' + servers[1].port + '/video-channels/channel1_server3' - const res = await searchVideoChannel(servers[0].url, search, servers[0].accessToken) + const body = await command.searchChannels({ search, token: servers[0].accessToken }) - expect(res.body.total).to.equal(0) - expect(res.body.data).to.be.an('array') - expect(res.body.data).to.have.lengthOf(0) + expect(body.total).to.equal(0) + expect(body.data).to.be.an('array') + expect(body.data).to.have.lengthOf(0) } { // Without token const search = 'http://localhost:' + servers[1].port + '/video-channels/channel1_server2' - const res = await searchVideoChannel(servers[0].url, search) + const body = await command.searchChannels({ search }) - expect(res.body.total).to.equal(0) - expect(res.body.data).to.be.an('array') - expect(res.body.data).to.have.lengthOf(0) + expect(body.total).to.equal(0) + expect(body.data).to.be.an('array') + expect(body.data).to.have.lengthOf(0) } }) @@ -96,13 +99,13 @@ describe('Test ActivityPub video channels search', function () { ] for (const search of searches) { - const res = await searchVideoChannel(servers[0].url, search) + const body = await command.searchChannels({ search }) - expect(res.body.total).to.equal(1) - expect(res.body.data).to.be.an('array') - expect(res.body.data).to.have.lengthOf(1) - expect(res.body.data[0].name).to.equal('channel1_server1') - expect(res.body.data[0].displayName).to.equal('Channel 1 server 1') + expect(body.total).to.equal(1) + expect(body.data).to.be.an('array') + expect(body.data).to.have.lengthOf(1) + expect(body.data[0].name).to.equal('channel1_server1') + expect(body.data[0].displayName).to.equal('Channel 1 server 1') } }) @@ -110,13 +113,13 @@ describe('Test ActivityPub video channels search', function () { const search = 'http://localhost:' + servers[0].port + '/c/channel1_server1' for (const token of [ undefined, servers[0].accessToken ]) { - const res = await searchVideoChannel(servers[0].url, search, token) + const body = await command.searchChannels({ search, token }) - expect(res.body.total).to.equal(1) - expect(res.body.data).to.be.an('array') - expect(res.body.data).to.have.lengthOf(1) - expect(res.body.data[0].name).to.equal('channel1_server1') - expect(res.body.data[0].displayName).to.equal('Channel 1 server 1') + expect(body.total).to.equal(1) + expect(body.data).to.be.an('array') + expect(body.data).to.have.lengthOf(1) + expect(body.data[0].name).to.equal('channel1_server1') + expect(body.data[0].displayName).to.equal('Channel 1 server 1') } }) @@ -129,13 +132,13 @@ describe('Test ActivityPub video channels search', function () { ] for (const search of searches) { - const res = await searchVideoChannel(servers[0].url, search, servers[0].accessToken) + const body = await command.searchChannels({ search, token: servers[0].accessToken }) - expect(res.body.total).to.equal(1) - expect(res.body.data).to.be.an('array') - expect(res.body.data).to.have.lengthOf(1) - expect(res.body.data[0].name).to.equal('channel1_server2') - expect(res.body.data[0].displayName).to.equal('Channel 1 server 2') + expect(body.total).to.equal(1) + expect(body.data).to.be.an('array') + expect(body.data).to.have.lengthOf(1) + expect(body.data[0].name).to.equal('channel1_server2') + expect(body.data[0].displayName).to.equal('Channel 1 server 2') } }) @@ -176,11 +179,11 @@ describe('Test ActivityPub video channels search', function () { await wait(10000) const search = 'http://localhost:' + servers[1].port + '/video-channels/channel1_server2' - const res = await searchVideoChannel(servers[0].url, search, servers[0].accessToken) - expect(res.body.total).to.equal(1) - expect(res.body.data).to.have.lengthOf(1) + const body = await command.searchChannels({ search, token: servers[0].accessToken }) + expect(body.total).to.equal(1) + expect(body.data).to.have.lengthOf(1) - const videoChannel: VideoChannel = res.body.data[0] + const videoChannel: VideoChannel = body.data[0] expect(videoChannel.displayName).to.equal('channel updated') // We don't return the owner account for now @@ -199,7 +202,7 @@ describe('Test ActivityPub video channels search', function () { await wait(10000) const search = 'http://localhost:' + servers[1].port + '/video-channels/channel1_server2' - await searchVideoChannel(servers[0].url, search, servers[0].accessToken) + await command.searchChannels({ search, token: servers[0].accessToken }) await waitJobs(servers) @@ -221,9 +224,9 @@ describe('Test ActivityPub video channels search', function () { await wait(10000) const search = 'http://localhost:' + servers[1].port + '/video-channels/channel1_server2' - const res = await searchVideoChannel(servers[0].url, search, servers[0].accessToken) - expect(res.body.total).to.equal(0) - expect(res.body.data).to.have.lengthOf(0) + const body = await command.searchChannels({ search, token: servers[0].accessToken }) + expect(body.total).to.equal(0) + expect(body.data).to.have.lengthOf(0) }) after(async function () { diff --git a/server/tests/api/search/search-activitypub-video-playlists.ts b/server/tests/api/search/search-activitypub-video-playlists.ts index 4c08e9548..1df18173a 100644 --- a/server/tests/api/search/search-activitypub-video-playlists.ts +++ b/server/tests/api/search/search-activitypub-video-playlists.ts @@ -9,15 +9,15 @@ import { deleteVideoPlaylist, flushAndRunMultipleServers, getVideoPlaylistsList, - searchVideoPlaylists, + SearchCommand, ServerInfo, setAccessTokensToServers, setDefaultVideoChannel, uploadVideoAndGetId, - wait -} from '../../../../shared/extra-utils' -import { waitJobs } from '../../../../shared/extra-utils/server/jobs' -import { VideoPlaylist, VideoPlaylistPrivacy } from '../../../../shared/models/videos' + wait, + waitJobs +} from '@shared/extra-utils' +import { VideoPlaylistPrivacy } from '@shared/models' const expect = chai.expect @@ -27,6 +27,8 @@ describe('Test ActivityPub playlists search', function () { let playlistServer2UUID: string let video2Server2: string + let command: SearchCommand + before(async function () { this.timeout(120000) @@ -78,38 +80,40 @@ describe('Test ActivityPub playlists search', function () { } await waitJobs(servers) + + command = servers[0].searchCommand }) it('Should not find a remote playlist', async function () { { const search = 'http://localhost:' + servers[1].port + '/video-playlists/43' - const res = await searchVideoPlaylists(servers[0].url, search, servers[0].accessToken) + const body = await command.searchPlaylists({ search, token: servers[0].accessToken }) - expect(res.body.total).to.equal(0) - expect(res.body.data).to.be.an('array') - expect(res.body.data).to.have.lengthOf(0) + expect(body.total).to.equal(0) + expect(body.data).to.be.an('array') + expect(body.data).to.have.lengthOf(0) } { // Without token const search = 'http://localhost:' + servers[1].port + '/video-playlists/' + playlistServer2UUID - const res = await searchVideoPlaylists(servers[0].url, search) + const body = await command.searchPlaylists({ search }) - expect(res.body.total).to.equal(0) - expect(res.body.data).to.be.an('array') - expect(res.body.data).to.have.lengthOf(0) + expect(body.total).to.equal(0) + expect(body.data).to.be.an('array') + expect(body.data).to.have.lengthOf(0) } }) it('Should search a local playlist', async function () { const search = 'http://localhost:' + servers[0].port + '/video-playlists/' + playlistServer1UUID - const res = await searchVideoPlaylists(servers[0].url, search) + const body = await command.searchPlaylists({ search }) - expect(res.body.total).to.equal(1) - expect(res.body.data).to.be.an('array') - expect(res.body.data).to.have.lengthOf(1) - expect(res.body.data[0].displayName).to.equal('playlist 1 on server 1') - expect(res.body.data[0].videosLength).to.equal(2) + expect(body.total).to.equal(1) + expect(body.data).to.be.an('array') + expect(body.data).to.have.lengthOf(1) + expect(body.data[0].displayName).to.equal('playlist 1 on server 1') + expect(body.data[0].videosLength).to.equal(2) }) it('Should search a local playlist with an alternative URL', async function () { @@ -120,13 +124,13 @@ describe('Test ActivityPub playlists search', function () { for (const search of searches) { for (const token of [ undefined, servers[0].accessToken ]) { - const res = await searchVideoPlaylists(servers[0].url, search, token) + const body = await command.searchPlaylists({ search, token }) - expect(res.body.total).to.equal(1) - expect(res.body.data).to.be.an('array') - expect(res.body.data).to.have.lengthOf(1) - expect(res.body.data[0].displayName).to.equal('playlist 1 on server 1') - expect(res.body.data[0].videosLength).to.equal(2) + expect(body.total).to.equal(1) + expect(body.data).to.be.an('array') + expect(body.data).to.have.lengthOf(1) + expect(body.data[0].displayName).to.equal('playlist 1 on server 1') + expect(body.data[0].videosLength).to.equal(2) } } }) @@ -139,13 +143,13 @@ describe('Test ActivityPub playlists search', function () { ] for (const search of searches) { - const res = await searchVideoPlaylists(servers[0].url, search, servers[0].accessToken) + const body = await command.searchPlaylists({ search, token: servers[0].accessToken }) - expect(res.body.total).to.equal(1) - expect(res.body.data).to.be.an('array') - expect(res.body.data).to.have.lengthOf(1) - expect(res.body.data[0].displayName).to.equal('playlist 1 on server 2') - expect(res.body.data[0].videosLength).to.equal(1) + expect(body.total).to.equal(1) + expect(body.data).to.be.an('array') + expect(body.data).to.have.lengthOf(1) + expect(body.data[0].displayName).to.equal('playlist 1 on server 2') + expect(body.data[0].videosLength).to.equal(1) } }) @@ -172,16 +176,16 @@ describe('Test ActivityPub playlists search', function () { // Will run refresh async const search = 'http://localhost:' + servers[1].port + '/video-playlists/' + playlistServer2UUID - await searchVideoPlaylists(servers[0].url, search, servers[0].accessToken) + await command.searchPlaylists({ search, token: servers[0].accessToken }) // Wait refresh await wait(5000) - const res = await searchVideoPlaylists(servers[0].url, search, servers[0].accessToken) - expect(res.body.total).to.equal(1) - expect(res.body.data).to.have.lengthOf(1) + const body = await command.searchPlaylists({ search, token: servers[0].accessToken }) + expect(body.total).to.equal(1) + expect(body.data).to.have.lengthOf(1) - const playlist: VideoPlaylist = res.body.data[0] + const playlist = body.data[0] expect(playlist.videosLength).to.equal(2) }) @@ -196,14 +200,14 @@ describe('Test ActivityPub playlists search', function () { // Will run refresh async const search = 'http://localhost:' + servers[1].port + '/video-playlists/' + playlistServer2UUID - await searchVideoPlaylists(servers[0].url, search, servers[0].accessToken) + await command.searchPlaylists({ search, token: servers[0].accessToken }) // Wait refresh await wait(5000) - const res = await searchVideoPlaylists(servers[0].url, search, servers[0].accessToken) - expect(res.body.total).to.equal(0) - expect(res.body.data).to.have.lengthOf(0) + const body = await command.searchPlaylists({ search, token: servers[0].accessToken }) + expect(body.total).to.equal(0) + expect(body.data).to.have.lengthOf(0) }) after(async function () { diff --git a/server/tests/api/search/search-activitypub-videos.ts b/server/tests/api/search/search-activitypub-videos.ts index e9b4978da..1a5130ce9 100644 --- a/server/tests/api/search/search-activitypub-videos.ts +++ b/server/tests/api/search/search-activitypub-videos.ts @@ -1,15 +1,14 @@ /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */ -import * as chai from 'chai' import 'mocha' +import * as chai from 'chai' import { addVideoChannel, cleanupTests, flushAndRunMultipleServers, getVideosList, removeVideo, - searchVideo, - searchVideoWithToken, + SearchCommand, ServerInfo, setAccessTokensToServers, updateVideo, @@ -17,7 +16,7 @@ import { wait } from '../../../../shared/extra-utils' import { waitJobs } from '../../../../shared/extra-utils/server/jobs' -import { Video, VideoPrivacy } from '../../../../shared/models/videos' +import { VideoPrivacy } from '../../../../shared/models/videos' const expect = chai.expect @@ -26,6 +25,8 @@ describe('Test ActivityPub videos search', function () { let videoServer1UUID: string let videoServer2UUID: string + let command: SearchCommand + before(async function () { this.timeout(120000) @@ -44,49 +45,51 @@ describe('Test ActivityPub videos search', function () { } await waitJobs(servers) + + command = servers[0].searchCommand }) it('Should not find a remote video', async function () { { const search = 'http://localhost:' + servers[1].port + '/videos/watch/43' - const res = await searchVideoWithToken(servers[0].url, search, servers[0].accessToken) + const body = await command.searchVideos({ search, token: servers[0].accessToken }) - expect(res.body.total).to.equal(0) - expect(res.body.data).to.be.an('array') - expect(res.body.data).to.have.lengthOf(0) + expect(body.total).to.equal(0) + expect(body.data).to.be.an('array') + expect(body.data).to.have.lengthOf(0) } { // Without token const search = 'http://localhost:' + servers[1].port + '/videos/watch/' + videoServer2UUID - const res = await searchVideo(servers[0].url, search) + const body = await command.searchVideos({ search }) - expect(res.body.total).to.equal(0) - expect(res.body.data).to.be.an('array') - expect(res.body.data).to.have.lengthOf(0) + expect(body.total).to.equal(0) + expect(body.data).to.be.an('array') + expect(body.data).to.have.lengthOf(0) } }) it('Should search a local video', async function () { const search = 'http://localhost:' + servers[0].port + '/videos/watch/' + videoServer1UUID - const res = await searchVideo(servers[0].url, search) + const body = await command.searchVideos({ search }) - expect(res.body.total).to.equal(1) - expect(res.body.data).to.be.an('array') - expect(res.body.data).to.have.lengthOf(1) - expect(res.body.data[0].name).to.equal('video 1 on server 1') + expect(body.total).to.equal(1) + expect(body.data).to.be.an('array') + expect(body.data).to.have.lengthOf(1) + expect(body.data[0].name).to.equal('video 1 on server 1') }) it('Should search a local video with an alternative URL', async function () { const search = 'http://localhost:' + servers[0].port + '/w/' + videoServer1UUID - const res1 = await searchVideo(servers[0].url, search) - const res2 = await searchVideoWithToken(servers[0].url, search, servers[0].accessToken) - - for (const res of [ res1, res2 ]) { - expect(res.body.total).to.equal(1) - expect(res.body.data).to.be.an('array') - expect(res.body.data).to.have.lengthOf(1) - expect(res.body.data[0].name).to.equal('video 1 on server 1') + const body1 = await command.searchVideos({ search }) + const body2 = await command.searchVideos({ search, token: servers[0].accessToken }) + + for (const body of [ body1, body2 ]) { + expect(body.total).to.equal(1) + expect(body.data).to.be.an('array') + expect(body.data).to.have.lengthOf(1) + expect(body.data[0].name).to.equal('video 1 on server 1') } }) @@ -97,12 +100,12 @@ describe('Test ActivityPub videos search', function () { ] for (const search of searches) { - const res = await searchVideoWithToken(servers[0].url, search, servers[0].accessToken) + const body = await command.searchVideos({ search, token: servers[0].accessToken }) - expect(res.body.total).to.equal(1) - expect(res.body.data).to.be.an('array') - expect(res.body.data).to.have.lengthOf(1) - expect(res.body.data[0].name).to.equal('video 1 on server 2') + expect(body.total).to.equal(1) + expect(body.data).to.be.an('array') + expect(body.data).to.have.lengthOf(1) + expect(body.data[0].name).to.equal('video 1 on server 2') } }) @@ -137,16 +140,16 @@ describe('Test ActivityPub videos search', function () { // Will run refresh async const search = 'http://localhost:' + servers[1].port + '/videos/watch/' + videoServer2UUID - await searchVideoWithToken(servers[0].url, search, servers[0].accessToken) + await command.searchVideos({ search, token: servers[0].accessToken }) // Wait refresh await wait(5000) - const res = await searchVideoWithToken(servers[0].url, search, servers[0].accessToken) - expect(res.body.total).to.equal(1) - expect(res.body.data).to.have.lengthOf(1) + const body = await command.searchVideos({ search, token: servers[0].accessToken }) + expect(body.total).to.equal(1) + expect(body.data).to.have.lengthOf(1) - const video: Video = res.body.data[0] + const video = body.data[0] expect(video.name).to.equal('updated') expect(video.channel.name).to.equal('super_channel') expect(video.privacy.id).to.equal(VideoPrivacy.UNLISTED) @@ -163,14 +166,14 @@ describe('Test ActivityPub videos search', function () { // Will run refresh async const search = 'http://localhost:' + servers[1].port + '/videos/watch/' + videoServer2UUID - await searchVideoWithToken(servers[0].url, search, servers[0].accessToken) + await command.searchVideos({ search, token: servers[0].accessToken }) // Wait refresh await wait(5000) - const res = await searchVideoWithToken(servers[0].url, search, servers[0].accessToken) - expect(res.body.total).to.equal(0) - expect(res.body.data).to.have.lengthOf(0) + const body = await command.searchVideos({ search, token: servers[0].accessToken }) + expect(body.total).to.equal(0) + expect(body.data).to.have.lengthOf(0) }) after(async function () { diff --git a/server/tests/api/search/search-channels.ts b/server/tests/api/search/search-channels.ts index daca2aebe..307bc063d 100644 --- a/server/tests/api/search/search-channels.ts +++ b/server/tests/api/search/search-channels.ts @@ -2,21 +2,22 @@ import 'mocha' import * as chai from 'chai' -import { searchVideoChannel, advancedVideoChannelSearch } from '@shared/extra-utils/search/video-channels' import { addVideoChannel, cleanupTests, createUser, flushAndRunServer, + SearchCommand, ServerInfo, setAccessTokensToServers -} from '../../../../shared/extra-utils' +} from '@shared/extra-utils' import { VideoChannel } from '@shared/models' const expect = chai.expect describe('Test channels search', function () { let server: ServerInfo = null + let command: SearchCommand before(async function () { this.timeout(30000) @@ -33,13 +34,15 @@ describe('Test channels search', function () { } await addVideoChannel(server.url, server.accessToken, channel) } + + command = server.searchCommand }) it('Should make a simple search and not have results', async function () { - const res = await searchVideoChannel(server.url, 'abc') + const body = await command.searchChannels({ search: 'abc' }) - expect(res.body.total).to.equal(0) - expect(res.body.data).to.have.lengthOf(0) + expect(body.total).to.equal(0) + expect(body.data).to.have.lengthOf(0) }) it('Should make a search and have results', async function () { @@ -49,11 +52,11 @@ describe('Test channels search', function () { start: 0, count: 1 } - const res = await advancedVideoChannelSearch(server.url, search) - expect(res.body.total).to.equal(1) - expect(res.body.data).to.have.lengthOf(1) + const body = await command.advancedChannelSearch({ search }) + expect(body.total).to.equal(1) + expect(body.data).to.have.lengthOf(1) - const channel: VideoChannel = res.body.data[0] + const channel: VideoChannel = body.data[0] expect(channel.name).to.equal('squall_channel') expect(channel.displayName).to.equal('Squall channel') } @@ -65,11 +68,9 @@ describe('Test channels search', function () { count: 1 } - const res = await advancedVideoChannelSearch(server.url, search) - - expect(res.body.total).to.equal(1) - - expect(res.body.data).to.have.lengthOf(0) + const body = await command.advancedChannelSearch({ search }) + expect(body.total).to.equal(1) + expect(body.data).to.have.lengthOf(0) } }) diff --git a/server/tests/api/search/search-index.ts b/server/tests/api/search/search-index.ts index 00f79232a..b2c0857a7 100644 --- a/server/tests/api/search/search-index.ts +++ b/server/tests/api/search/search-index.ts @@ -2,28 +2,26 @@ import 'mocha' import * as chai from 'chai' -import { advancedVideoChannelSearch, searchVideoChannel } from '@shared/extra-utils/search/video-channels' -import { Video, VideoChannel, VideoPlaylist, VideoPlaylistPrivacy, VideoPlaylistType, VideosSearchQuery } from '@shared/models' import { - advancedVideoPlaylistSearch, - advancedVideosSearch, cleanupTests, flushAndRunServer, immutableAssign, - searchVideo, - searchVideoPlaylists, + SearchCommand, ServerInfo, setAccessTokensToServers, updateCustomSubConfig, uploadVideo -} from '../../../../shared/extra-utils' +} from '@shared/extra-utils' +import { VideoPlaylistPrivacy, VideoPlaylistType, VideosSearchQuery } from '@shared/models' const expect = chai.expect describe('Test videos search', function () { - let server: ServerInfo = null const localVideoName = 'local video' + new Date().toISOString() + let server: ServerInfo = null + let command: SearchCommand + before(async function () { this.timeout(30000) @@ -32,6 +30,8 @@ describe('Test videos search', function () { await setAccessTokensToServers([ server ]) await uploadVideo(server.url, server.accessToken, { name: localVideoName }) + + command = server.searchCommand }) describe('Default search', async function () { @@ -49,18 +49,18 @@ describe('Test videos search', function () { } }) - const res = await searchVideo(server.url, 'local video') + const body = await command.searchVideos({ search: 'local video' }) - expect(res.body.total).to.equal(1) - expect(res.body.data[0].name).to.equal(localVideoName) + expect(body.total).to.equal(1) + expect(body.data[0].name).to.equal(localVideoName) }) it('Should make a local channels search by default', async function () { - const res = await searchVideoChannel(server.url, 'root') + const body = await command.searchChannels({ search: 'root' }) - expect(res.body.total).to.equal(1) - expect(res.body.data[0].name).to.equal('root_channel') - expect(res.body.data[0].host).to.equal('localhost:' + server.port) + expect(body.total).to.equal(1) + expect(body.data[0].name).to.equal('root_channel') + expect(body.data[0].host).to.equal('localhost:' + server.port) }) it('Should make an index videos search by default', async function () { @@ -74,13 +74,13 @@ describe('Test videos search', function () { } }) - const res = await searchVideo(server.url, 'local video') - expect(res.body.total).to.be.greaterThan(2) + const body = await command.searchVideos({ search: 'local video' }) + expect(body.total).to.be.greaterThan(2) }) it('Should make an index channels search by default', async function () { - const res = await searchVideoChannel(server.url, 'root') - expect(res.body.total).to.be.greaterThan(2) + const body = await command.searchChannels({ search: 'root' }) + expect(body.total).to.be.greaterThan(2) }) it('Should make an index videos search if local search is disabled', async function () { @@ -94,46 +94,46 @@ describe('Test videos search', function () { } }) - const res = await searchVideo(server.url, 'local video') - expect(res.body.total).to.be.greaterThan(2) + const body = await command.searchVideos({ search: 'local video' }) + expect(body.total).to.be.greaterThan(2) }) it('Should make an index channels search if local search is disabled', async function () { - const res = await searchVideoChannel(server.url, 'root') - expect(res.body.total).to.be.greaterThan(2) + const body = await command.searchChannels({ search: 'root' }) + expect(body.total).to.be.greaterThan(2) }) }) describe('Videos search', async function () { it('Should make a simple search and not have results', async function () { - const res = await searchVideo(server.url, 'djidane'.repeat(50)) + const body = await command.searchVideos({ search: 'djidane'.repeat(50) }) - expect(res.body.total).to.equal(0) - expect(res.body.data).to.have.lengthOf(0) + expect(body.total).to.equal(0) + expect(body.data).to.have.lengthOf(0) }) it('Should make a simple search and have results', async function () { - const res = await searchVideo(server.url, 'What is PeerTube') + const body = await command.searchVideos({ search: 'What is PeerTube' }) - expect(res.body.total).to.be.greaterThan(1) + expect(body.total).to.be.greaterThan(1) }) it('Should make a complex search', async function () { async function check (search: VideosSearchQuery, exists = true) { - const res = await advancedVideosSearch(server.url, search) + const body = await command.advancedVideoSearch({ search }) if (exists === false) { - expect(res.body.total).to.equal(0) - expect(res.body.data).to.have.lengthOf(0) + expect(body.total).to.equal(0) + expect(body.data).to.have.lengthOf(0) return } - expect(res.body.total).to.equal(1) - expect(res.body.data).to.have.lengthOf(1) + expect(body.total).to.equal(1) + expect(body.data).to.have.lengthOf(1) - const video: Video = res.body.data[0] + const video = body.data[0] expect(video.name).to.equal('What is PeerTube?') expect(video.category.label).to.equal('Science & Technology') @@ -206,10 +206,10 @@ describe('Test videos search', function () { count: 5 } - const res = await advancedVideosSearch(server.url, search) + const body = await command.advancedVideoSearch({ search }) - expect(res.body.total).to.be.greaterThan(5) - expect(res.body.data).to.have.lengthOf(5) + expect(body.total).to.be.greaterThan(5) + expect(body.data).to.have.lengthOf(5) }) it('Should use the nsfw instance policy as default', async function () { @@ -218,10 +218,10 @@ describe('Test videos search', function () { { await updateCustomSubConfig(server.url, server.accessToken, { instance: { defaultNSFWPolicy: 'display' } }) - const res = await searchVideo(server.url, 'NSFW search index', '-match') - const video = res.body.data[0] as Video + const body = await command.searchVideos({ search: 'NSFW search index', sort: '-match' }) + expect(body.data).to.have.length.greaterThan(0) - expect(res.body.data).to.have.length.greaterThan(0) + const video = body.data[0] expect(video.nsfw).to.be.true nsfwUUID = video.uuid @@ -230,13 +230,12 @@ describe('Test videos search', function () { { await updateCustomSubConfig(server.url, server.accessToken, { instance: { defaultNSFWPolicy: 'do_not_list' } }) - const res = await searchVideo(server.url, 'NSFW search index', '-match') + const body = await command.searchVideos({ search: 'NSFW search index', sort: '-match' }) try { - expect(res.body.data).to.have.lengthOf(0) - } catch (err) { - // - const video = res.body.data[0] as Video + expect(body.data).to.have.lengthOf(0) + } catch { + const video = body.data[0] expect(video.uuid).not.equal(nsfwUUID) } @@ -247,19 +246,19 @@ describe('Test videos search', function () { describe('Channels search', async function () { it('Should make a simple search and not have results', async function () { - const res = await searchVideoChannel(server.url, 'a'.repeat(500)) + const body = await command.searchChannels({ search: 'a'.repeat(500) }) - expect(res.body.total).to.equal(0) - expect(res.body.data).to.have.lengthOf(0) + expect(body.total).to.equal(0) + expect(body.data).to.have.lengthOf(0) }) it('Should make a search and have results', async function () { - const res = await advancedVideoChannelSearch(server.url, { search: 'Framasoft', sort: 'createdAt' }) + const body = await command.advancedChannelSearch({ search: { search: 'Framasoft', sort: 'createdAt' } }) - expect(res.body.total).to.be.greaterThan(0) - expect(res.body.data).to.have.length.greaterThan(0) + expect(body.total).to.be.greaterThan(0) + expect(body.data).to.have.length.greaterThan(0) - const videoChannel: VideoChannel = res.body.data[0] + const videoChannel = body.data[0] expect(videoChannel.url).to.equal('https://framatube.org/video-channels/bf54d359-cfad-4935-9d45-9d6be93f63e8') expect(videoChannel.host).to.equal('framatube.org') expect(videoChannel.avatar).to.exist @@ -272,29 +271,29 @@ describe('Test videos search', function () { }) it('Should have a correct pagination', async function () { - const res = await advancedVideoChannelSearch(server.url, { search: 'root', start: 0, count: 2 }) + const body = await command.advancedChannelSearch({ search: { search: 'root', start: 0, count: 2 } }) - expect(res.body.total).to.be.greaterThan(2) - expect(res.body.data).to.have.lengthOf(2) + expect(body.total).to.be.greaterThan(2) + expect(body.data).to.have.lengthOf(2) }) }) describe('Playlists search', async function () { it('Should make a simple search and not have results', async function () { - const res = await searchVideoPlaylists(server.url, 'a'.repeat(500)) + const body = await command.searchPlaylists({ search: 'a'.repeat(500) }) - expect(res.body.total).to.equal(0) - expect(res.body.data).to.have.lengthOf(0) + expect(body.total).to.equal(0) + expect(body.data).to.have.lengthOf(0) }) it('Should make a search and have results', async function () { - const res = await advancedVideoPlaylistSearch(server.url, { search: 'E2E playlist', sort: '-match' }) + const body = await command.advancedPlaylistSearch({ search: { search: 'E2E playlist', sort: '-match' } }) - expect(res.body.total).to.be.greaterThan(0) - expect(res.body.data).to.have.length.greaterThan(0) + expect(body.total).to.be.greaterThan(0) + expect(body.data).to.have.length.greaterThan(0) - const videoPlaylist: VideoPlaylist = res.body.data[0] + const videoPlaylist = body.data[0] expect(videoPlaylist.url).to.equal('https://peertube2.cpy.re/videos/watch/playlist/73804a40-da9a-40c2-b1eb-2c6d9eec8f0a') expect(videoPlaylist.thumbnailUrl).to.exist @@ -322,10 +321,10 @@ describe('Test videos search', function () { }) it('Should have a correct pagination', async function () { - const res = await advancedVideoChannelSearch(server.url, { search: 'root', start: 0, count: 2 }) + const body = await command.advancedChannelSearch({ search: { search: 'root', start: 0, count: 2 } }) - expect(res.body.total).to.be.greaterThan(2) - expect(res.body.data).to.have.lengthOf(2) + expect(body.total).to.be.greaterThan(2) + expect(body.data).to.have.lengthOf(2) }) }) diff --git a/server/tests/api/search/search-playlists.ts b/server/tests/api/search/search-playlists.ts index ab17d55e9..1862ecd31 100644 --- a/server/tests/api/search/search-playlists.ts +++ b/server/tests/api/search/search-playlists.ts @@ -2,14 +2,13 @@ import 'mocha' import * as chai from 'chai' -import { VideoPlaylist, VideoPlaylistPrivacy } from '@shared/models' +import { VideoPlaylistPrivacy } from '@shared/models' import { addVideoInPlaylist, - advancedVideoPlaylistSearch, cleanupTests, createVideoPlaylist, flushAndRunServer, - searchVideoPlaylists, + SearchCommand, ServerInfo, setAccessTokensToServers, setDefaultVideoChannel, @@ -20,6 +19,7 @@ const expect = chai.expect describe('Test playlists search', function () { let server: ServerInfo = null + let command: SearchCommand before(async function () { this.timeout(30000) @@ -71,13 +71,15 @@ describe('Test playlists search', function () { } await createVideoPlaylist({ url: server.url, token: server.accessToken, playlistAttrs: attributes }) } + + command = server.searchCommand }) it('Should make a simple search and not have results', async function () { - const res = await searchVideoPlaylists(server.url, 'abc') + const body = await command.searchPlaylists({ search: 'abc' }) - expect(res.body.total).to.equal(0) - expect(res.body.data).to.have.lengthOf(0) + expect(body.total).to.equal(0) + expect(body.data).to.have.lengthOf(0) }) it('Should make a search and have results', async function () { @@ -87,11 +89,11 @@ describe('Test playlists search', function () { start: 0, count: 1 } - const res = await advancedVideoPlaylistSearch(server.url, search) - expect(res.body.total).to.equal(1) - expect(res.body.data).to.have.lengthOf(1) + const body = await command.advancedPlaylistSearch({ search }) + expect(body.total).to.equal(1) + expect(body.data).to.have.lengthOf(1) - const playlist: VideoPlaylist = res.body.data[0] + const playlist = body.data[0] expect(playlist.displayName).to.equal('Dr. Kenzo Tenma hospital videos') expect(playlist.url).to.equal(server.url + '/video-playlists/' + playlist.uuid) } @@ -102,11 +104,11 @@ describe('Test playlists search', function () { start: 0, count: 1 } - const res = await advancedVideoPlaylistSearch(server.url, search) - expect(res.body.total).to.equal(1) - expect(res.body.data).to.have.lengthOf(1) + const body = await command.advancedPlaylistSearch({ search }) + expect(body.total).to.equal(1) + expect(body.data).to.have.lengthOf(1) - const playlist: VideoPlaylist = res.body.data[0] + const playlist = body.data[0] expect(playlist.displayName).to.equal('Johan & Anna Libert musics') } }) @@ -117,9 +119,9 @@ describe('Test playlists search', function () { start: 0, count: 1 } - const res = await advancedVideoPlaylistSearch(server.url, search) - expect(res.body.total).to.equal(0) - expect(res.body.data).to.have.lengthOf(0) + const body = await command.advancedPlaylistSearch({ search }) + expect(body.total).to.equal(0) + expect(body.data).to.have.lengthOf(0) }) after(async function () { diff --git a/server/tests/api/search/search-videos.ts b/server/tests/api/search/search-videos.ts index 5b8907961..f0482c7e0 100644 --- a/server/tests/api/search/search-videos.ts +++ b/server/tests/api/search/search-videos.ts @@ -4,12 +4,11 @@ import 'mocha' import * as chai from 'chai' import { VideoPrivacy } from '@shared/models' import { - advancedVideosSearch, cleanupTests, createLive, flushAndRunServer, immutableAssign, - searchVideo, + SearchCommand, sendRTMPStreamInVideo, ServerInfo, setAccessTokensToServers, @@ -29,6 +28,8 @@ describe('Test videos search', function () { let startDate: string let videoUUID: string + let command: SearchCommand + before(async function () { this.timeout(60000) @@ -144,21 +145,23 @@ describe('Test videos search', function () { await uploadVideo(server.url, server.accessToken, attributes1) await uploadVideo(server.url, server.accessToken, immutableAssign(attributes1, { category: 2 })) } + + command = server.searchCommand }) it('Should make a simple search and not have results', async function () { - const res = await searchVideo(server.url, 'abc') + const body = await command.searchVideos({ search: 'abc' }) - expect(res.body.total).to.equal(0) - expect(res.body.data).to.have.lengthOf(0) + expect(body.total).to.equal(0) + expect(body.data).to.have.lengthOf(0) }) it('Should make a simple search and have results', async function () { - const res = await searchVideo(server.url, '4444 5555 duplicate') + const body = await command.searchVideos({ search: '4444 5555 duplicate' }) - expect(res.body.total).to.equal(2) + expect(body.total).to.equal(2) - const videos = res.body.data + const videos = body.data expect(videos).to.have.lengthOf(2) // bestmatch @@ -167,15 +170,15 @@ describe('Test videos search', function () { }) it('Should make a search on tags too, and have results', async function () { - const query = { + const search = { search: 'aaaa', categoryOneOf: [ 1 ] } - const res = await advancedVideosSearch(server.url, query) + const body = await command.advancedVideoSearch({ search }) - expect(res.body.total).to.equal(2) + expect(body.total).to.equal(2) - const videos = res.body.data + const videos = body.data expect(videos).to.have.lengthOf(2) // bestmatch @@ -184,14 +187,14 @@ describe('Test videos search', function () { }) it('Should filter on tags without a search', async function () { - const query = { + const search = { tagsAllOf: [ 'bbbb' ] } - const res = await advancedVideosSearch(server.url, query) + const body = await command.advancedVideoSearch({ search }) - expect(res.body.total).to.equal(2) + expect(body.total).to.equal(2) - const videos = res.body.data + const videos = body.data expect(videos).to.have.lengthOf(2) expect(videos[0].name).to.equal('9999') @@ -199,14 +202,14 @@ describe('Test videos search', function () { }) it('Should filter on category without a search', async function () { - const query = { + const search = { categoryOneOf: [ 3 ] } - const res = await advancedVideosSearch(server.url, query) + const body = await command.advancedVideoSearch({ search: search }) - expect(res.body.total).to.equal(1) + expect(body.total).to.equal(1) - const videos = res.body.data + const videos = body.data expect(videos).to.have.lengthOf(1) expect(videos[0].name).to.equal('6666 7777 8888') @@ -218,11 +221,16 @@ describe('Test videos search', function () { categoryOneOf: [ 1 ], tagsOneOf: [ 'aAaa', 'ffff' ] } - const res1 = await advancedVideosSearch(server.url, query) - expect(res1.body.total).to.equal(2) - const res2 = await advancedVideosSearch(server.url, immutableAssign(query, { tagsOneOf: [ 'blabla' ] })) - expect(res2.body.total).to.equal(0) + { + const body = await command.advancedVideoSearch({ search: query }) + expect(body.total).to.equal(2) + } + + { + const body = await command.advancedVideoSearch({ search: { ...query, tagsOneOf: [ 'blabla' ] } }) + expect(body.total).to.equal(0) + } }) it('Should search by tags (all of)', async function () { @@ -231,14 +239,21 @@ describe('Test videos search', function () { categoryOneOf: [ 1 ], tagsAllOf: [ 'CCcc' ] } - const res1 = await advancedVideosSearch(server.url, query) - expect(res1.body.total).to.equal(2) - const res2 = await advancedVideosSearch(server.url, immutableAssign(query, { tagsAllOf: [ 'blAbla' ] })) - expect(res2.body.total).to.equal(0) + { + const body = await command.advancedVideoSearch({ search: query }) + expect(body.total).to.equal(2) + } - const res3 = await advancedVideosSearch(server.url, immutableAssign(query, { tagsAllOf: [ 'bbbb', 'CCCC' ] })) - expect(res3.body.total).to.equal(1) + { + const body = await command.advancedVideoSearch({ search: { ...query, tagsAllOf: [ 'blAbla' ] } }) + expect(body.total).to.equal(0) + } + + { + const body = await command.advancedVideoSearch({ search: { ...query, tagsAllOf: [ 'bbbb', 'CCCC' ] } }) + expect(body.total).to.equal(1) + } }) it('Should search by category', async function () { @@ -246,12 +261,17 @@ describe('Test videos search', function () { search: '6666', categoryOneOf: [ 3 ] } - const res1 = await advancedVideosSearch(server.url, query) - expect(res1.body.total).to.equal(1) - expect(res1.body.data[0].name).to.equal('6666 7777 8888') - const res2 = await advancedVideosSearch(server.url, immutableAssign(query, { categoryOneOf: [ 2 ] })) - expect(res2.body.total).to.equal(0) + { + const body = await command.advancedVideoSearch({ search: query }) + expect(body.total).to.equal(1) + expect(body.data[0].name).to.equal('6666 7777 8888') + } + + { + const body = await command.advancedVideoSearch({ search: { ...query, categoryOneOf: [ 2 ] } }) + expect(body.total).to.equal(0) + } }) it('Should search by licence', async function () { @@ -259,13 +279,18 @@ describe('Test videos search', function () { search: '4444 5555', licenceOneOf: [ 2 ] } - const res1 = await advancedVideosSearch(server.url, query) - expect(res1.body.total).to.equal(2) - expect(res1.body.data[0].name).to.equal('3333 4444 5555') - expect(res1.body.data[1].name).to.equal('3333 4444 5555 duplicate') - const res2 = await advancedVideosSearch(server.url, immutableAssign(query, { licenceOneOf: [ 3 ] })) - expect(res2.body.total).to.equal(0) + { + const body = await command.advancedVideoSearch({ search: query }) + expect(body.total).to.equal(2) + expect(body.data[0].name).to.equal('3333 4444 5555') + expect(body.data[1].name).to.equal('3333 4444 5555 duplicate') + } + + { + const body = await command.advancedVideoSearch({ search: { ...query, licenceOneOf: [ 3 ] } }) + expect(body.total).to.equal(0) + } }) it('Should search by languages', async function () { @@ -275,23 +300,23 @@ describe('Test videos search', function () { } { - const res = await advancedVideosSearch(server.url, query) - expect(res.body.total).to.equal(2) - expect(res.body.data[0].name).to.equal('1111 2222 3333 - 3') - expect(res.body.data[1].name).to.equal('1111 2222 3333 - 4') + const body = await command.advancedVideoSearch({ search: query }) + expect(body.total).to.equal(2) + expect(body.data[0].name).to.equal('1111 2222 3333 - 3') + expect(body.data[1].name).to.equal('1111 2222 3333 - 4') } { - const res = await advancedVideosSearch(server.url, immutableAssign(query, { languageOneOf: [ 'pl', 'en', '_unknown' ] })) - expect(res.body.total).to.equal(3) - expect(res.body.data[0].name).to.equal('1111 2222 3333 - 3') - expect(res.body.data[1].name).to.equal('1111 2222 3333 - 4') - expect(res.body.data[2].name).to.equal('1111 2222 3333 - 5') + const body = await command.advancedVideoSearch({ search: { ...query, languageOneOf: [ 'pl', 'en', '_unknown' ] } }) + expect(body.total).to.equal(3) + expect(body.data[0].name).to.equal('1111 2222 3333 - 3') + expect(body.data[1].name).to.equal('1111 2222 3333 - 4') + expect(body.data[2].name).to.equal('1111 2222 3333 - 5') } { - const res = await advancedVideosSearch(server.url, immutableAssign(query, { languageOneOf: [ 'eo' ] })) - expect(res.body.total).to.equal(0) + const body = await command.advancedVideoSearch({ search: { ...query, languageOneOf: [ 'eo' ] } }) + expect(body.total).to.equal(0) } }) @@ -301,10 +326,10 @@ describe('Test videos search', function () { startDate } - const res = await advancedVideosSearch(server.url, query) - expect(res.body.total).to.equal(4) + const body = await command.advancedVideoSearch({ search: query }) + expect(body.total).to.equal(4) - const videos = res.body.data + const videos = body.data expect(videos[0].name).to.equal('1111 2222 3333 - 5') expect(videos[1].name).to.equal('1111 2222 3333 - 6') expect(videos[2].name).to.equal('1111 2222 3333 - 7') @@ -320,10 +345,10 @@ describe('Test videos search', function () { licenceOneOf: [ 1, 4 ] } - const res = await advancedVideosSearch(server.url, query) - expect(res.body.total).to.equal(4) + const body = await command.advancedVideoSearch({ search: query }) + expect(body.total).to.equal(4) - const videos = res.body.data + const videos = body.data expect(videos[0].name).to.equal('1111 2222 3333') expect(videos[1].name).to.equal('1111 2222 3333 - 6') expect(videos[2].name).to.equal('1111 2222 3333 - 7') @@ -340,10 +365,10 @@ describe('Test videos search', function () { sort: '-name' } - const res = await advancedVideosSearch(server.url, query) - expect(res.body.total).to.equal(4) + const body = await command.advancedVideoSearch({ search: query }) + expect(body.total).to.equal(4) - const videos = res.body.data + const videos = body.data expect(videos[0].name).to.equal('1111 2222 3333 - 8') expect(videos[1].name).to.equal('1111 2222 3333 - 7') expect(videos[2].name).to.equal('1111 2222 3333 - 6') @@ -362,10 +387,10 @@ describe('Test videos search', function () { count: 1 } - const res = await advancedVideosSearch(server.url, query) - expect(res.body.total).to.equal(4) + const body = await command.advancedVideoSearch({ search: query }) + expect(body.total).to.equal(4) - const videos = res.body.data + const videos = body.data expect(videos[0].name).to.equal('1111 2222 3333 - 8') }) @@ -381,10 +406,10 @@ describe('Test videos search', function () { count: 1 } - const res = await advancedVideosSearch(server.url, query) - expect(res.body.total).to.equal(4) + const body = await command.advancedVideoSearch({ search: query }) + expect(body.total).to.equal(4) - const videos = res.body.data + const videos = body.data expect(videos[0].name).to.equal('1111 2222 3333') }) @@ -399,32 +424,32 @@ describe('Test videos search', function () { { const query = immutableAssign(baseQuery, { originallyPublishedStartDate: '2019-02-11T09:58:08.286Z' }) - const res = await advancedVideosSearch(server.url, query) + const body = await command.advancedVideoSearch({ search: query }) - expect(res.body.total).to.equal(1) - expect(res.body.data[0].name).to.equal('1111 2222 3333 - 7') + expect(body.total).to.equal(1) + expect(body.data[0].name).to.equal('1111 2222 3333 - 7') } { const query = immutableAssign(baseQuery, { originallyPublishedEndDate: '2019-03-11T09:58:08.286Z' }) - const res = await advancedVideosSearch(server.url, query) + const body = await command.advancedVideoSearch({ search: query }) - expect(res.body.total).to.equal(1) - expect(res.body.data[0].name).to.equal('1111 2222 3333 - 7') + expect(body.total).to.equal(1) + expect(body.data[0].name).to.equal('1111 2222 3333 - 7') } { const query = immutableAssign(baseQuery, { originallyPublishedEndDate: '2019-01-11T09:58:08.286Z' }) - const res = await advancedVideosSearch(server.url, query) + const body = await command.advancedVideoSearch({ search: query }) - expect(res.body.total).to.equal(0) + expect(body.total).to.equal(0) } { const query = immutableAssign(baseQuery, { originallyPublishedStartDate: '2019-03-11T09:58:08.286Z' }) - const res = await advancedVideosSearch(server.url, query) + const body = await command.advancedVideoSearch({ search: query }) - expect(res.body.total).to.equal(0) + expect(body.total).to.equal(0) } { @@ -432,9 +457,9 @@ describe('Test videos search', function () { originallyPublishedStartDate: '2019-01-11T09:58:08.286Z', originallyPublishedEndDate: '2019-01-10T09:58:08.286Z' }) - const res = await advancedVideosSearch(server.url, query) + const body = await command.advancedVideoSearch({ search: query }) - expect(res.body.total).to.equal(0) + expect(body.total).to.equal(0) } { @@ -442,19 +467,19 @@ describe('Test videos search', function () { originallyPublishedStartDate: '2019-01-11T09:58:08.286Z', originallyPublishedEndDate: '2019-04-11T09:58:08.286Z' }) - const res = await advancedVideosSearch(server.url, query) + const body = await command.advancedVideoSearch({ search: query }) - expect(res.body.total).to.equal(1) - expect(res.body.data[0].name).to.equal('1111 2222 3333 - 7') + expect(body.total).to.equal(1) + expect(body.data[0].name).to.equal('1111 2222 3333 - 7') } }) it('Should search by UUID', async function () { const search = videoUUID - const res = await advancedVideosSearch(server.url, { search }) + const body = await command.advancedVideoSearch({ search: { search } }) - expect(res.body.total).to.equal(1) - expect(res.body.data[0].name).to.equal('1111 2222 3333 - 3') + expect(body.total).to.equal(1) + expect(body.data[0].name).to.equal('1111 2222 3333 - 3') }) it('Should search by live', async function () { @@ -471,10 +496,10 @@ describe('Test videos search', function () { } { - const res = await advancedVideosSearch(server.url, { isLive: true }) + const body = await command.advancedVideoSearch({ search: { isLive: true } }) - expect(res.body.total).to.equal(0) - expect(res.body.data).to.have.lengthOf(0) + expect(body.total).to.equal(0) + expect(body.data).to.have.lengthOf(0) } { @@ -482,15 +507,15 @@ describe('Test videos search', function () { const resLive = await createLive(server.url, server.accessToken, liveOptions) const liveVideoId = resLive.body.video.uuid - const command = await sendRTMPStreamInVideo(server.url, server.accessToken, liveVideoId) + const ffmpegCommand = await sendRTMPStreamInVideo(server.url, server.accessToken, liveVideoId) await waitUntilLivePublished(server.url, server.accessToken, liveVideoId) - const res = await advancedVideosSearch(server.url, { isLive: true }) + const body = await command.advancedVideoSearch({ search: { isLive: true } }) - expect(res.body.total).to.equal(1) - expect(res.body.data[0].name).to.equal('live') + expect(body.total).to.equal(1) + expect(body.data[0].name).to.equal('live') - await stopFfmpeg(command) + await stopFfmpeg(ffmpegCommand) } }) diff --git a/server/tests/api/videos/video-nsfw.ts b/server/tests/api/videos/video-nsfw.ts index 6c98c9f12..24a4c6152 100644 --- a/server/tests/api/videos/video-nsfw.ts +++ b/server/tests/api/videos/video-nsfw.ts @@ -14,8 +14,6 @@ import { getVideoChannelVideos, getVideosList, getVideosListWithToken, - searchVideo, - searchVideoWithToken, ServerInfo, setAccessTokensToServers, updateCustomConfig, @@ -23,7 +21,7 @@ import { uploadVideo, userLogin } from '@shared/extra-utils' -import { CustomConfig, ServerConfig, User, VideosOverview } from '@shared/models' +import { BooleanBothQuery, CustomConfig, ServerConfig, User, VideosOverview } from '@shared/models' const expect = chai.expect @@ -37,7 +35,7 @@ describe('Test video NSFW policy', function () { let userAccessToken: string let customConfig: CustomConfig - function getVideosFunctions (token?: string, query = {}) { + function getVideosFunctions (token?: string, query: { nsfw?: BooleanBothQuery } = {}) { return getMyUserInformation(server.url, server.accessToken) .then(res => { const user: User = res.body @@ -49,7 +47,7 @@ describe('Test video NSFW policy', function () { if (token) { promises = [ getVideosListWithToken(server.url, token, query), - searchVideoWithToken(server.url, 'n', token, query), + server.searchCommand.advancedVideoSearch({ token, search: { search: 'n', ...query } }), getAccountVideos(server.url, token, accountName, 0, 5, undefined, query), getVideoChannelVideos(server.url, token, videoChannelName, 0, 5, undefined, query) ] @@ -66,7 +64,7 @@ describe('Test video NSFW policy', function () { promises = [ getVideosList(server.url), - searchVideo(server.url, 'n'), + server.searchCommand.searchVideos({ search: 'n' }), getAccountVideos(server.url, undefined, accountName, 0, 5), getVideoChannelVideos(server.url, undefined, videoChannelName, 0, 5) ] @@ -230,7 +228,7 @@ describe('Test video NSFW policy', function () { }) it('Should display NSFW videos when the nsfw param === true', async function () { - for (const res of await getVideosFunctions(server.accessToken, { nsfw: true })) { + for (const res of await getVideosFunctions(server.accessToken, { nsfw: 'true' })) { expect(res.body.total).to.equal(1) const videos = res.body.data @@ -240,7 +238,7 @@ describe('Test video NSFW policy', function () { }) it('Should hide NSFW videos when the nsfw param === true', async function () { - for (const res of await getVideosFunctions(server.accessToken, { nsfw: false })) { + for (const res of await getVideosFunctions(server.accessToken, { nsfw: 'false' })) { expect(res.body.total).to.equal(1) const videos = res.body.data diff --git a/server/tests/api/videos/videos-history.ts b/server/tests/api/videos/videos-history.ts index b25cff879..209b93014 100644 --- a/server/tests/api/videos/videos-history.ts +++ b/server/tests/api/videos/videos-history.ts @@ -1,7 +1,8 @@ /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */ -import * as chai from 'chai' import 'mocha' +import * as chai from 'chai' +import { HttpStatusCode } from '@shared/core-utils' import { cleanupTests, createUser, @@ -10,17 +11,15 @@ import { getVideoWithToken, killallServers, reRunServer, - searchVideoWithToken, ServerInfo, setAccessTokensToServers, updateMyUser, uploadVideo, userLogin, wait -} from '../../../../shared/extra-utils' -import { Video, VideoDetails } from '../../../../shared/models/videos' -import { listMyVideosHistory, removeMyVideosHistory, userWatchVideo } from '../../../../shared/extra-utils/videos/video-history' -import { HttpStatusCode } from '../../../../shared/core-utils/miscs/http-error-codes' +} from '@shared/extra-utils' +import { listMyVideosHistory, removeMyVideosHistory, userWatchVideo } from '@shared/extra-utils/videos/video-history' +import { Video, VideoDetails } from '@shared/models' const expect = chai.expect @@ -89,8 +88,8 @@ describe('Test videos history', function () { } { - const res = await searchVideoWithToken(server.url, 'video', server.accessToken) - videosOfVideos.push(res.body.data) + const body = await server.searchCommand.searchVideos({ token: server.accessToken, search: 'video' }) + videosOfVideos.push(body.data) } for (const videos of videosOfVideos) { -- cgit v1.2.3 From 2d1ad5b96063d1e430ca99128a15e2e56cb614e0 Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Tue, 6 Jul 2021 15:33:39 +0200 Subject: Move AP request in requests file --- server/tests/api/notifications/moderation-notifications.ts | 2 +- server/tests/api/search/search-activitypub-videos.ts | 2 +- server/tests/api/videos/videos-overview.ts | 1 - 3 files changed, 2 insertions(+), 3 deletions(-) (limited to 'server/tests/api') diff --git a/server/tests/api/notifications/moderation-notifications.ts b/server/tests/api/notifications/moderation-notifications.ts index f77719c68..c4f63200a 100644 --- a/server/tests/api/notifications/moderation-notifications.ts +++ b/server/tests/api/notifications/moderation-notifications.ts @@ -235,7 +235,7 @@ describe('Test moderation notifications', function () { const video = resVideo.body.video { - const body = await servers[0].abusesCommand.report({ token: userAccessToken, videoId: video.id, reason: 'super reason' }) + const body = await servers[0].abusesCommand.report({ token: userAccessToken, videoId: video.id, reason: 'super reason' }) abuseId = body.abuse.id } diff --git a/server/tests/api/search/search-activitypub-videos.ts b/server/tests/api/search/search-activitypub-videos.ts index 1a5130ce9..7c6455258 100644 --- a/server/tests/api/search/search-activitypub-videos.ts +++ b/server/tests/api/search/search-activitypub-videos.ts @@ -72,7 +72,7 @@ describe('Test ActivityPub videos search', function () { it('Should search a local video', async function () { const search = 'http://localhost:' + servers[0].port + '/videos/watch/' + videoServer1UUID - const body = await command.searchVideos({ search }) + const body = await command.searchVideos({ search }) expect(body.total).to.equal(1) expect(body.data).to.be.an('array') diff --git a/server/tests/api/videos/videos-overview.ts b/server/tests/api/videos/videos-overview.ts index c8e3df4bd..b3ab9e070 100644 --- a/server/tests/api/videos/videos-overview.ts +++ b/server/tests/api/videos/videos-overview.ts @@ -2,7 +2,6 @@ import 'mocha' import * as chai from 'chai' -import { Response } from 'superagent' import { addAccountToAccountBlocklist, cleanupTests, -- 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 +++++++-------------------- server/tests/api/server/contact-form.ts | 23 ++++----- 2 files changed, 27 insertions(+), 65 deletions(-) (limited to 'server/tests/api') 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 () { diff --git a/server/tests/api/server/contact-form.ts b/server/tests/api/server/contact-form.ts index 71205723d..79c4c6748 100644 --- a/server/tests/api/server/contact-form.ts +++ b/server/tests/api/server/contact-form.ts @@ -2,17 +2,16 @@ import 'mocha' import * as chai from 'chai' -import { HttpStatusCode } from '../../../../shared/core-utils/miscs/http-error-codes' -import { cleanupTests, flushAndRunServer, ServerInfo, setAccessTokensToServers, wait } from '../../../../shared/extra-utils' -import { MockSmtpServer } from '../../../../shared/extra-utils/mock-servers/mock-email' -import { sendContactForm } from '../../../../shared/extra-utils/server/contact-form' -import { waitJobs } from '../../../../shared/extra-utils/server/jobs' +import { HttpStatusCode } from '@shared/core-utils' +import { cleanupTests, flushAndRunServer, MockSmtpServer, ServerInfo, setAccessTokensToServers, wait, waitJobs } from '@shared/extra-utils' +import { ContactFormCommand } from '@shared/extra-utils/server' const expect = chai.expect describe('Test contact form', function () { let server: ServerInfo const emails: object[] = [] + let command: ContactFormCommand before(async function () { this.timeout(30000) @@ -27,13 +26,14 @@ describe('Test contact form', function () { } server = await flushAndRunServer(1, overrideConfig) await setAccessTokensToServers([ server ]) + + command = server.contactFormCommand }) it('Should send a contact form', async function () { this.timeout(10000) - await sendContactForm({ - url: server.url, + await command.send({ fromEmail: 'toto@example.com', body: 'my super message', subject: 'my subject', @@ -58,16 +58,14 @@ describe('Test contact form', function () { await wait(1000) - await sendContactForm({ - url: server.url, + await command.send({ fromEmail: 'toto@example.com', body: 'my super message', subject: 'my subject', fromName: 'Super toto' }) - await sendContactForm({ - url: server.url, + await command.send({ fromEmail: 'toto@example.com', body: 'my super message', fromName: 'Super toto', @@ -79,8 +77,7 @@ describe('Test contact form', function () { it('Should be able to send another contact form after a while', async function () { await wait(1000) - await sendContactForm({ - url: server.url, + await command.send({ fromEmail: 'toto@example.com', fromName: 'Super toto', subject: 'my subject', -- cgit v1.2.3 From 883a9019085ff9013079d6b1539b86f2f519175a Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Tue, 6 Jul 2021 16:02:11 +0200 Subject: Introduce debug command --- server/tests/api/videos/resumable-upload.ts | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) (limited to 'server/tests/api') diff --git a/server/tests/api/videos/resumable-upload.ts b/server/tests/api/videos/resumable-upload.ts index 4fc3317df..6c01c7e78 100644 --- a/server/tests/api/videos/resumable-upload.ts +++ b/server/tests/api/videos/resumable-upload.ts @@ -12,7 +12,6 @@ import { flushAndRunServer, getMyUserInformation, prepareResumableUpload, - sendDebugCommand, sendResumableChunks, ServerInfo, setAccessTokensToServers, @@ -138,13 +137,13 @@ describe('Test resumable upload', function () { }) it('Should not delete recent uploads', async function () { - await sendDebugCommand(server.url, server.accessToken, { command: 'remove-dandling-resumable-uploads' }) + await server.debugCommand.sendCommand({ body: { command: 'remove-dandling-resumable-uploads' } }) expect(await countResumableUploads()).to.equal(2) }) it('Should delete old uploads', async function () { - await sendDebugCommand(server.url, server.accessToken, { command: 'remove-dandling-resumable-uploads' }) + await server.debugCommand.sendCommand({ body: { command: 'remove-dandling-resumable-uploads' } }) expect(await countResumableUploads()).to.equal(0) }) -- cgit v1.2.3 From c3d29f694bf8c910f917be655626d0f80871124f Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Wed, 7 Jul 2021 09:16:40 +0200 Subject: Introduce follows command --- server/tests/api/moderation/blocklist.ts | 10 +- .../api/notifications/moderation-notifications.ts | 16 +-- .../tests/api/redundancy/redundancy-constraints.ts | 5 +- server/tests/api/redundancy/redundancy.ts | 24 ++-- server/tests/api/server/auto-follows.ts | 48 +++---- server/tests/api/server/follow-constraints.ts | 15 +-- server/tests/api/server/follows-moderation.ts | 92 ++++++------- server/tests/api/server/follows.ts | 144 ++++++++++----------- server/tests/api/server/handle-down.ts | 50 ++++--- server/tests/api/server/jobs.ts | 4 +- server/tests/api/server/stats.ts | 22 ++-- server/tests/api/users/user-subscriptions.ts | 33 +++-- server/tests/api/users/users.ts | 8 +- server/tests/api/videos/video-description.ts | 2 +- server/tests/api/videos/video-playlists.ts | 41 +++--- 15 files changed, 233 insertions(+), 281 deletions(-) (limited to 'server/tests/api') diff --git a/server/tests/api/moderation/blocklist.ts b/server/tests/api/moderation/blocklist.ts index 793abbcb4..9ca6324c2 100644 --- a/server/tests/api/moderation/blocklist.ts +++ b/server/tests/api/moderation/blocklist.ts @@ -15,7 +15,6 @@ import { doubleFollow, findCommentId, flushAndRunMultipleServers, - follow, getAccountBlocklistByAccount, getAccountBlocklistByServer, getServerBlocklistByAccount, @@ -31,7 +30,6 @@ import { removeServerFromServerBlocklist, ServerInfo, setAccessTokensToServers, - unfollow, uploadVideo, userLogin, waitJobs @@ -742,9 +740,9 @@ describe('Test blocklist', function () { { const now = new Date() - await unfollow(servers[1].url, servers[1].accessToken, servers[0]) + await servers[1].followsCommand.unfollow({ target: servers[0] }) await waitJobs(servers) - await follow(servers[1].url, [ servers[0].host ], servers[1].accessToken) + await servers[1].followsCommand.follow({ targets: [ servers[0].host ] }) await waitJobs(servers) @@ -807,9 +805,9 @@ describe('Test blocklist', function () { { const now = new Date() - await unfollow(servers[1].url, servers[1].accessToken, servers[0]) + await servers[1].followsCommand.unfollow({ target: servers[0] }) await waitJobs(servers) - await follow(servers[1].url, [ servers[0].host ], servers[1].accessToken) + await servers[1].followsCommand.follow({ targets: [ servers[0].host ] }) await waitJobs(servers) diff --git a/server/tests/api/notifications/moderation-notifications.ts b/server/tests/api/notifications/moderation-notifications.ts index c4f63200a..9a93ce401 100644 --- a/server/tests/api/notifications/moderation-notifications.ts +++ b/server/tests/api/notifications/moderation-notifications.ts @@ -21,7 +21,6 @@ import { checkVideoIsPublished, cleanupTests, createUser, - follow, generateUserAccessToken, getAccount, getCustomConfig, @@ -35,7 +34,6 @@ import { removeUserSubscription, removeVideoFromBlacklist, ServerInfo, - unfollow, updateCustomConfig, updateCustomSubConfig, uploadVideo, @@ -386,7 +384,7 @@ describe('Test moderation notifications', function () { it('Should send a notification only to admin when there is a new instance follower', async function () { this.timeout(20000) - await follow(servers[2].url, [ servers[0].url ], servers[2].accessToken) + await servers[2].followsCommand.follow({ targets: [ servers[0].url ] }) await waitJobs(servers) @@ -399,7 +397,7 @@ describe('Test moderation notifications', function () { it('Should send a notification on auto follow back', async function () { this.timeout(40000) - await unfollow(servers[2].url, servers[2].accessToken, servers[0]) + await servers[2].followsCommand.unfollow({ target: servers[0] }) await waitJobs(servers) const config = { @@ -411,7 +409,7 @@ describe('Test moderation notifications', function () { } await updateCustomSubConfig(servers[0].url, servers[0].accessToken, config) - await follow(servers[2].url, [ servers[0].url ], servers[2].accessToken) + await servers[2].followsCommand.follow({ targets: [ servers[0].url ] }) await waitJobs(servers) @@ -424,13 +422,13 @@ describe('Test moderation notifications', function () { config.followings.instance.autoFollowBack.enabled = false await updateCustomSubConfig(servers[0].url, servers[0].accessToken, config) - await unfollow(servers[0].url, servers[0].accessToken, servers[2]) - await unfollow(servers[2].url, servers[2].accessToken, servers[0]) + await servers[0].followsCommand.unfollow({ target: servers[2] }) + await servers[2].followsCommand.unfollow({ target: servers[0] }) }) it('Should send a notification on auto instances index follow', async function () { this.timeout(30000) - await unfollow(servers[0].url, servers[0].accessToken, servers[1]) + await servers[0].followsCommand.unfollow({ target: servers[1] }) await updateCustomSubConfig(servers[0].url, servers[0].accessToken, config) @@ -443,7 +441,7 @@ describe('Test moderation notifications', function () { config.followings.instance.autoFollowIndex.enabled = false await updateCustomSubConfig(servers[0].url, servers[0].accessToken, config) - await unfollow(servers[0].url, servers[0].accessToken, servers[1]) + await servers[0].followsCommand.unfollow({ target: servers[1] }) }) }) diff --git a/server/tests/api/redundancy/redundancy-constraints.ts b/server/tests/api/redundancy/redundancy-constraints.ts index 1cb1603bc..602f4bc1b 100644 --- a/server/tests/api/redundancy/redundancy-constraints.ts +++ b/server/tests/api/redundancy/redundancy-constraints.ts @@ -7,7 +7,6 @@ import { VideoPrivacy } from '@shared/models' import { cleanupTests, flushAndRunServer, - follow, killallServers, reRunServer, ServerInfo, @@ -98,7 +97,7 @@ describe('Test redundancy constraints', function () { await waitJobs(servers) // Server 1 and server 2 follow each other - await follow(remoteServer.url, [ localServer.url ], remoteServer.accessToken) + await remoteServer.followsCommand.follow({ targets: [ localServer.url ] }) await waitJobs(servers) await updateRedundancy(remoteServer.url, remoteServer.accessToken, localServer.host, true) @@ -184,7 +183,7 @@ describe('Test redundancy constraints', function () { it('Should have redundancy on server 1 and on server 2 with followings filter now server 2 follows server 1', async function () { this.timeout(120000) - await follow(localServer.url, [ remoteServer.url ], localServer.accessToken) + await localServer.followsCommand.follow({ targets: [ remoteServer.url ] }) await waitJobs(servers) await uploadWrapper('video 4 server 2') diff --git a/server/tests/api/redundancy/redundancy.ts b/server/tests/api/redundancy/redundancy.ts index 0e0a73b9d..dfe8099ed 100644 --- a/server/tests/api/redundancy/redundancy.ts +++ b/server/tests/api/redundancy/redundancy.ts @@ -12,7 +12,6 @@ import { cleanupTests, doubleFollow, flushAndRunMultipleServers, - getFollowingListPaginationAndSort, getVideo, getVideoWithToken, immutableAssign, @@ -23,7 +22,6 @@ import { root, ServerInfo, setAccessTokensToServers, - unfollow, updateVideo, uploadVideo, viewVideo, @@ -38,7 +36,6 @@ import { updateRedundancy } from '../../../../shared/extra-utils/server/redundancy' import { getStats } from '../../../../shared/extra-utils/server/stats' -import { ActorFollow } from '../../../../shared/models/actors' import { VideoRedundancy, VideoRedundancyStrategy, VideoRedundancyStrategyWithManual } from '../../../../shared/models/redundancy' import { ServerStats } from '../../../../shared/models/server/server-stats.model' import { VideoDetails, VideoPrivacy } from '../../../../shared/models/videos' @@ -272,13 +269,19 @@ async function checkStatsWithoutRedundancy (strategy: VideoRedundancyStrategyWit expect(stat.totalVideos).to.equal(0) } +async function findServerFollows () { + const body = await servers[0].followsCommand.getFollowings({ start: 0, count: 5, sort: '-createdAt' }) + const follows = body.data + const server2 = follows.find(f => f.following.host === `localhost:${servers[1].port}`) + const server3 = follows.find(f => f.following.host === `localhost:${servers[2].port}`) + + return { server2, server3 } +} + async function enableRedundancyOnServer1 () { await updateRedundancy(servers[0].url, servers[0].accessToken, servers[1].host, true) - const res = await getFollowingListPaginationAndSort({ url: servers[0].url, start: 0, count: 5, sort: '-createdAt' }) - const follows: ActorFollow[] = res.body.data - const server2 = follows.find(f => f.following.host === `localhost:${servers[1].port}`) - const server3 = follows.find(f => f.following.host === `localhost:${servers[2].port}`) + const { server2, server3 } = await findServerFollows() expect(server3).to.not.be.undefined expect(server3.following.hostRedundancyAllowed).to.be.false @@ -290,10 +293,7 @@ async function enableRedundancyOnServer1 () { async function disableRedundancyOnServer1 () { await updateRedundancy(servers[0].url, servers[0].accessToken, servers[1].host, false) - const res = await getFollowingListPaginationAndSort({ url: servers[0].url, start: 0, count: 5, sort: '-createdAt' }) - const follows: ActorFollow[] = res.body.data - const server2 = follows.find(f => f.following.host === `localhost:${servers[1].port}`) - const server3 = follows.find(f => f.following.host === `localhost:${servers[2].port}`) + const { server2, server3 } = await findServerFollows() expect(server3).to.not.be.undefined expect(server3.following.hostRedundancyAllowed).to.be.false @@ -388,7 +388,7 @@ describe('Test videos redundancy', function () { it('Should unfollow on server 1 and remove duplicated videos', async function () { this.timeout(80000) - await unfollow(servers[0].url, servers[0].accessToken, servers[1]) + await servers[0].followsCommand.unfollow({ target: servers[1] }) await waitJobs(servers) await wait(5000) diff --git a/server/tests/api/server/auto-follows.ts b/server/tests/api/server/auto-follows.ts index 1519b263f..02389b1e9 100644 --- a/server/tests/api/server/auto-follows.ts +++ b/server/tests/api/server/auto-follows.ts @@ -3,64 +3,46 @@ import 'mocha' import * as chai from 'chai' import { - acceptFollower, cleanupTests, flushAndRunMultipleServers, MockInstancesIndex, ServerInfo, setAccessTokensToServers, - unfollow, updateCustomSubConfig, - wait -} from '../../../../shared/extra-utils/index' -import { follow, getFollowersListPaginationAndSort, getFollowingListPaginationAndSort } from '../../../../shared/extra-utils/server/follows' -import { waitJobs } from '../../../../shared/extra-utils/server/jobs' -import { ActorFollow } from '../../../../shared/models/actors' + wait, + waitJobs +} from '@shared/extra-utils' const expect = chai.expect async function checkFollow (follower: ServerInfo, following: ServerInfo, exists: boolean) { { - const res = await getFollowersListPaginationAndSort({ url: following.url, start: 0, count: 5, sort: '-createdAt' }) - const follows = res.body.data as ActorFollow[] + const body = await following.followsCommand.getFollowers({ start: 0, count: 5, sort: '-createdAt' }) + const follow = body.data.find(f => f.follower.host === follower.host && f.state === 'accepted') - const follow = follows.find(f => { - return f.follower.host === follower.host && f.state === 'accepted' - }) - - if (exists === true) { - expect(follow).to.exist - } else { - expect(follow).to.be.undefined - } + if (exists === true) expect(follow).to.exist + else expect(follow).to.be.undefined } { - const res = await getFollowingListPaginationAndSort({ url: follower.url, start: 0, count: 5, sort: '-createdAt' }) - const follows = res.body.data as ActorFollow[] - - const follow = follows.find(f => { - return f.following.host === following.host && f.state === 'accepted' - }) + const body = await follower.followsCommand.getFollowings({ start: 0, count: 5, sort: '-createdAt' }) + const follow = body.data.find(f => f.following.host === following.host && f.state === 'accepted') - if (exists === true) { - expect(follow).to.exist - } else { - expect(follow).to.be.undefined - } + if (exists === true) expect(follow).to.exist + else expect(follow).to.be.undefined } } async function server1Follows2 (servers: ServerInfo[]) { - await follow(servers[0].url, [ servers[1].host ], servers[0].accessToken) + await servers[0].followsCommand.follow({ targets: [ servers[1].host ] }) await waitJobs(servers) } async function resetFollows (servers: ServerInfo[]) { try { - await unfollow(servers[0].url, servers[0].accessToken, servers[1]) - await unfollow(servers[1].url, servers[1].accessToken, servers[0]) + await servers[0].followsCommand.unfollow({ target: servers[1] }) + await servers[1].followsCommand.unfollow({ target: servers[0] }) } catch { /* empty */ } @@ -137,7 +119,7 @@ describe('Test auto follows', function () { await checkFollow(servers[0], servers[1], false) await checkFollow(servers[1], servers[0], false) - await acceptFollower(servers[1].url, servers[1].accessToken, 'peertube@' + servers[0].host) + await servers[1].followsCommand.acceptFollower({ follower: 'peertube@' + servers[0].host }) await waitJobs(servers) await checkFollow(servers[0], servers[1], true) diff --git a/server/tests/api/server/follow-constraints.ts b/server/tests/api/server/follow-constraints.ts index 3f2f71f46..0f1c6264d 100644 --- a/server/tests/api/server/follow-constraints.ts +++ b/server/tests/api/server/follow-constraints.ts @@ -1,9 +1,12 @@ /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */ -import * as chai from 'chai' import 'mocha' +import * as chai from 'chai' +import { HttpStatusCode } from '@shared/core-utils' +import { PeerTubeProblemDocument, ServerErrorCode } from '@shared/models' import { cleanupTests, + createUser, doubleFollow, flushAndRunMultipleServers, getAccountVideos, @@ -12,13 +15,9 @@ import { getVideoWithToken, ServerInfo, setAccessTokensToServers, - uploadVideo + uploadVideo, + userLogin } from '../../../../shared/extra-utils' -import { unfollow } from '../../../../shared/extra-utils/server/follows' -import { userLogin } from '../../../../shared/extra-utils/users/login' -import { createUser } from '../../../../shared/extra-utils/users/users' -import { HttpStatusCode } from '../../../../shared/core-utils/miscs/http-error-codes' -import { PeerTubeProblemDocument, ServerErrorCode } from '@shared/models' const expect = chai.expect @@ -144,7 +143,7 @@ describe('Test follow constraints', function () { before(async function () { this.timeout(30000) - await unfollow(servers[0].url, servers[0].accessToken, servers[1]) + await servers[0].followsCommand.unfollow({ target: servers[1] }) }) describe('With an unlogged user', function () { diff --git a/server/tests/api/server/follows-moderation.ts b/server/tests/api/server/follows-moderation.ts index 73c212a32..4853b647d 100644 --- a/server/tests/api/server/follows-moderation.ts +++ b/server/tests/api/server/follows-moderation.ts @@ -1,43 +1,30 @@ /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */ -import * as chai from 'chai' import 'mocha' +import * as chai from 'chai' import { - acceptFollower, cleanupTests, flushAndRunMultipleServers, + FollowsCommand, ServerInfo, setAccessTokensToServers, - updateCustomSubConfig -} from '../../../../shared/extra-utils/index' -import { - follow, - getFollowersListPaginationAndSort, - getFollowingListPaginationAndSort, - rejectFollower, - removeFollower -} from '../../../../shared/extra-utils/server/follows' -import { waitJobs } from '../../../../shared/extra-utils/server/jobs' -import { ActorFollow } from '../../../../shared/models/actors' + updateCustomSubConfig, + waitJobs +} from '@shared/extra-utils' const expect = chai.expect async function checkServer1And2HasFollowers (servers: ServerInfo[], state = 'accepted') { - { - const res = await getFollowingListPaginationAndSort({ url: servers[0].url, start: 0, count: 5, sort: 'createdAt' }) - expect(res.body.total).to.equal(1) + const fns = [ + servers[0].followsCommand.getFollowings.bind(servers[0].followsCommand), + servers[1].followsCommand.getFollowers.bind(servers[1].followsCommand) + ] - const follow = res.body.data[0] as ActorFollow - expect(follow.state).to.equal(state) - expect(follow.follower.url).to.equal('http://localhost:' + servers[0].port + '/accounts/peertube') - expect(follow.following.url).to.equal('http://localhost:' + servers[1].port + '/accounts/peertube') - } - - { - const res = await getFollowersListPaginationAndSort({ url: servers[1].url, start: 0, count: 5, sort: 'createdAt' }) - expect(res.body.total).to.equal(1) + for (const fn of fns) { + const body = await fn({ start: 0, count: 5, sort: 'createdAt' }) + expect(body.total).to.equal(1) - const follow = res.body.data[0] as ActorFollow + const follow = body.data[0] expect(follow.state).to.equal(state) expect(follow.follower.url).to.equal('http://localhost:' + servers[0].port + '/accounts/peertube') expect(follow.following.url).to.equal('http://localhost:' + servers[1].port + '/accounts/peertube') @@ -45,19 +32,20 @@ async function checkServer1And2HasFollowers (servers: ServerInfo[], state = 'acc } async function checkNoFollowers (servers: ServerInfo[]) { - { - const res = await getFollowingListPaginationAndSort({ url: servers[0].url, start: 0, count: 5, sort: 'createdAt' }) - expect(res.body.total).to.equal(0) - } - - { - const res = await getFollowersListPaginationAndSort({ url: servers[1].url, start: 0, count: 5, sort: 'createdAt' }) - expect(res.body.total).to.equal(0) + const fns = [ + servers[0].followsCommand.getFollowings.bind(servers[0].followsCommand), + servers[1].followsCommand.getFollowers.bind(servers[1].followsCommand) + ] + + for (const fn of fns) { + const body = await fn({ start: 0, count: 5, sort: 'createdAt' }) + expect(body.total).to.equal(0) } } describe('Test follows moderation', function () { let servers: ServerInfo[] = [] + let commands: FollowsCommand[] before(async function () { this.timeout(30000) @@ -66,12 +54,14 @@ describe('Test follows moderation', function () { // Get the access tokens await setAccessTokensToServers(servers) + + commands = servers.map(s => s.followsCommand) }) it('Should have server 1 following server 2', async function () { this.timeout(30000) - await follow(servers[0].url, [ servers[1].url ], servers[0].accessToken) + await commands[0].follow({ targets: [ servers[1].url ] }) await waitJobs(servers) }) @@ -83,7 +73,7 @@ describe('Test follows moderation', function () { it('Should remove follower on server 2', async function () { this.timeout(10000) - await removeFollower(servers[1].url, servers[1].accessToken, servers[0]) + await commands[1].removeFollower({ follower: servers[0] }) await waitJobs(servers) }) @@ -106,7 +96,7 @@ describe('Test follows moderation', function () { await updateCustomSubConfig(servers[1].url, servers[1].accessToken, subConfig) - await follow(servers[0].url, [ servers[1].url ], servers[0].accessToken) + await commands[0].follow({ targets: [ servers[1].url ] }) await waitJobs(servers) await checkNoFollowers(servers) @@ -126,7 +116,7 @@ describe('Test follows moderation', function () { await updateCustomSubConfig(servers[1].url, servers[1].accessToken, subConfig) - await follow(servers[0].url, [ servers[1].url ], servers[0].accessToken) + await commands[0].follow({ targets: [ servers[1].url ] }) await waitJobs(servers) await checkServer1And2HasFollowers(servers) @@ -135,7 +125,7 @@ describe('Test follows moderation', function () { it('Should manually approve followers', async function () { this.timeout(20000) - await removeFollower(servers[1].url, servers[1].accessToken, servers[0]) + await commands[1].removeFollower({ follower: servers[0] }) await waitJobs(servers) const subConfig = { @@ -150,7 +140,7 @@ describe('Test follows moderation', function () { await updateCustomSubConfig(servers[1].url, servers[1].accessToken, subConfig) await updateCustomSubConfig(servers[2].url, servers[2].accessToken, subConfig) - await follow(servers[0].url, [ servers[1].url ], servers[0].accessToken) + await commands[0].follow({ targets: [ servers[1].url ] }) await waitJobs(servers) await checkServer1And2HasFollowers(servers, 'pending') @@ -159,7 +149,7 @@ describe('Test follows moderation', function () { it('Should accept a follower', async function () { this.timeout(10000) - await acceptFollower(servers[1].url, servers[1].accessToken, 'peertube@localhost:' + servers[0].port) + await commands[1].acceptFollower({ follower: 'peertube@localhost:' + servers[0].port }) await waitJobs(servers) await checkServer1And2HasFollowers(servers) @@ -168,32 +158,32 @@ describe('Test follows moderation', function () { it('Should reject another follower', async function () { this.timeout(20000) - await follow(servers[0].url, [ servers[2].url ], servers[0].accessToken) + await commands[0].follow({ targets: [ servers[2].url ] }) await waitJobs(servers) { - const res = await getFollowingListPaginationAndSort({ url: servers[0].url, start: 0, count: 5, sort: 'createdAt' }) - expect(res.body.total).to.equal(2) + const body = await commands[0].getFollowings({ start: 0, count: 5, sort: 'createdAt' }) + expect(body.total).to.equal(2) } { - const res = await getFollowersListPaginationAndSort({ url: servers[1].url, start: 0, count: 5, sort: 'createdAt' }) - expect(res.body.total).to.equal(1) + const body = await commands[1].getFollowers({ start: 0, count: 5, sort: 'createdAt' }) + expect(body.total).to.equal(1) } { - const res = await getFollowersListPaginationAndSort({ url: servers[2].url, start: 0, count: 5, sort: 'createdAt' }) - expect(res.body.total).to.equal(1) + const body = await commands[2].getFollowers({ start: 0, count: 5, sort: 'createdAt' }) + expect(body.total).to.equal(1) } - await rejectFollower(servers[2].url, servers[2].accessToken, 'peertube@localhost:' + servers[0].port) + await commands[2].rejectFollower({ follower: 'peertube@localhost:' + servers[0].port }) await waitJobs(servers) await checkServer1And2HasFollowers(servers) { - const res = await getFollowersListPaginationAndSort({ url: servers[2].url, start: 0, count: 5, sort: 'createdAt' }) - expect(res.body.total).to.equal(0) + const body = await commands[2].getFollowers({ start: 0, count: 5, sort: 'createdAt' }) + expect(body.total).to.equal(0) } }) diff --git a/server/tests/api/server/follows.ts b/server/tests/api/server/follows.ts index 9e5aa00c7..c8fcca02c 100644 --- a/server/tests/api/server/follows.ts +++ b/server/tests/api/server/follows.ts @@ -13,9 +13,7 @@ import { deleteVideoComment, expectAccountFollows, flushAndRunMultipleServers, - follow, - getFollowersListPaginationAndSort, - getFollowingListPaginationAndSort, + FollowsCommand, getVideoCommentThreads, getVideosList, getVideoThreadComments, @@ -24,7 +22,6 @@ import { ServerInfo, setAccessTokensToServers, testCaptionFile, - unfollow, uploadVideo, userLogin, waitJobs @@ -35,11 +32,13 @@ const expect = chai.expect describe('Test follows', function () { let servers: ServerInfo[] = [] + let followsCommands: FollowsCommand[] before(async function () { this.timeout(30000) servers = await flushAndRunMultipleServers(3) + followsCommands = servers.map(s => s.followsCommand) // Get the access tokens await setAccessTokensToServers(servers) @@ -47,10 +46,10 @@ describe('Test follows', function () { it('Should not have followers', async function () { for (const server of servers) { - const res = await getFollowersListPaginationAndSort({ url: server.url, start: 0, count: 5, sort: 'createdAt' }) - const follows = res.body.data + const body = await server.followsCommand.getFollowers({ start: 0, count: 5, sort: 'createdAt' }) + expect(body.total).to.equal(0) - expect(res.body.total).to.equal(0) + const follows = body.data expect(follows).to.be.an('array') expect(follows.length).to.equal(0) } @@ -58,10 +57,10 @@ describe('Test follows', function () { it('Should not have following', async function () { for (const server of servers) { - const res = await getFollowingListPaginationAndSort({ url: server.url, start: 0, count: 5, sort: 'createdAt' }) - const follows = res.body.data + const body = await server.followsCommand.getFollowings({ start: 0, count: 5, sort: 'createdAt' }) + expect(body.total).to.equal(0) - expect(res.body.total).to.equal(0) + const follows = body.data expect(follows).to.be.an('array') expect(follows.length).to.equal(0) } @@ -70,21 +69,21 @@ describe('Test follows', function () { it('Should have server 1 following server 2 and 3', async function () { this.timeout(30000) - await follow(servers[0].url, [ servers[1].url, servers[2].url ], servers[0].accessToken) + await followsCommands[0].follow({ targets: [ servers[1].url, servers[2].url ] }) await waitJobs(servers) }) it('Should have 2 followings on server 1', async function () { - let res = await getFollowingListPaginationAndSort({ url: servers[0].url, start: 0, count: 1, sort: 'createdAt' }) - let follows = res.body.data + const body = await followsCommands[0].getFollowings({ start: 0, count: 1, sort: 'createdAt' }) + expect(body.total).to.equal(2) - expect(res.body.total).to.equal(2) + let follows = body.data expect(follows).to.be.an('array') expect(follows.length).to.equal(1) - res = await getFollowingListPaginationAndSort({ url: servers[0].url, start: 1, count: 1, sort: 'createdAt' }) - follows = follows.concat(res.body.data) + const body2 = await followsCommands[0].getFollowings({ start: 1, count: 1, sort: 'createdAt' }) + follows = follows.concat(body2.data) const server2Follow = follows.find(f => f.following.host === 'localhost:' + servers[1].port) const server3Follow = follows.find(f => f.following.host === 'localhost:' + servers[2].port) @@ -99,35 +98,33 @@ describe('Test follows', function () { const sort = 'createdAt' const start = 0 const count = 1 - const url = servers[0].url { const search = ':' + servers[1].port { - const res = await getFollowingListPaginationAndSort({ url, start, count, sort, search }) - const follows = res.body.data + const body = await followsCommands[0].getFollowings({ start, count, sort, search }) + expect(body.total).to.equal(1) - expect(res.body.total).to.equal(1) + const follows = body.data expect(follows.length).to.equal(1) expect(follows[0].following.host).to.equal('localhost:' + servers[1].port) } { - const res = await getFollowingListPaginationAndSort({ url, start, count, sort, search, state: 'accepted' }) - expect(res.body.total).to.equal(1) - expect(res.body.data).to.have.lengthOf(1) + const body = await followsCommands[0].getFollowings({ start, count, sort, search, state: 'accepted' }) + expect(body.total).to.equal(1) + expect(body.data).to.have.lengthOf(1) } { - const res = await getFollowingListPaginationAndSort({ url, start, count, sort, search, state: 'accepted', actorType: 'Person' }) - expect(res.body.total).to.equal(0) - expect(res.body.data).to.have.lengthOf(0) + const body = await followsCommands[0].getFollowings({ start, count, sort, search, state: 'accepted', actorType: 'Person' }) + expect(body.total).to.equal(0) + expect(body.data).to.have.lengthOf(0) } { - const res = await getFollowingListPaginationAndSort({ - url, + const body = await followsCommands[0].getFollowings({ start, count, sort, @@ -135,32 +132,31 @@ describe('Test follows', function () { state: 'accepted', actorType: 'Application' }) - expect(res.body.total).to.equal(1) - expect(res.body.data).to.have.lengthOf(1) + expect(body.total).to.equal(1) + expect(body.data).to.have.lengthOf(1) } { - const res = await getFollowingListPaginationAndSort({ url, start, count, sort, search, state: 'pending' }) - expect(res.body.total).to.equal(0) - expect(res.body.data).to.have.lengthOf(0) + const body = await followsCommands[0].getFollowings({ start, count, sort, search, state: 'pending' }) + expect(body.total).to.equal(0) + expect(body.data).to.have.lengthOf(0) } } { - const res = await getFollowingListPaginationAndSort({ url, start, count, sort, search: 'bla' }) - const follows = res.body.data + const body = await followsCommands[0].getFollowings({ start, count, sort, search: 'bla' }) + expect(body.total).to.equal(0) - expect(res.body.total).to.equal(0) - expect(follows.length).to.equal(0) + expect(body.data.length).to.equal(0) } }) it('Should have 0 followings on server 2 and 3', async function () { for (const server of [ servers[1], servers[2] ]) { - const res = await getFollowingListPaginationAndSort({ url: server.url, start: 0, count: 5, sort: 'createdAt' }) - const follows = res.body.data + const body = await server.followsCommand.getFollowings({ start: 0, count: 5, sort: 'createdAt' }) + expect(body.total).to.equal(0) - expect(res.body.total).to.equal(0) + const follows = body.data expect(follows).to.be.an('array') expect(follows.length).to.equal(0) } @@ -168,10 +164,10 @@ describe('Test follows', function () { it('Should have 1 followers on server 2 and 3', async function () { for (const server of [ servers[1], servers[2] ]) { - const res = await getFollowersListPaginationAndSort({ url: server.url, start: 0, count: 1, sort: 'createdAt' }) + const body = await server.followsCommand.getFollowers({ start: 0, count: 1, sort: 'createdAt' }) + expect(body.total).to.equal(1) - const follows = res.body.data - expect(res.body.total).to.equal(1) + const follows = body.data expect(follows).to.be.an('array') expect(follows.length).to.equal(1) expect(follows[0].follower.host).to.equal('localhost:' + servers[0].port) @@ -179,7 +175,6 @@ describe('Test follows', function () { }) it('Should search/filter followers on server 2', async function () { - const url = servers[2].url const start = 0 const count = 5 const sort = 'createdAt' @@ -188,29 +183,28 @@ describe('Test follows', function () { const search = servers[0].port + '' { - const res = await getFollowersListPaginationAndSort({ url, start, count, sort, search }) - const follows = res.body.data + const body = await followsCommands[2].getFollowers({ start, count, sort, search }) + expect(body.total).to.equal(1) - expect(res.body.total).to.equal(1) + const follows = body.data expect(follows.length).to.equal(1) expect(follows[0].following.host).to.equal('localhost:' + servers[2].port) } { - const res = await getFollowersListPaginationAndSort({ url, start, count, sort, search, state: 'accepted' }) - expect(res.body.total).to.equal(1) - expect(res.body.data).to.have.lengthOf(1) + const body = await followsCommands[2].getFollowers({ start, count, sort, search, state: 'accepted' }) + expect(body.total).to.equal(1) + expect(body.data).to.have.lengthOf(1) } { - const res = await getFollowersListPaginationAndSort({ url, start, count, sort, search, state: 'accepted', actorType: 'Person' }) - expect(res.body.total).to.equal(0) - expect(res.body.data).to.have.lengthOf(0) + const body = await followsCommands[2].getFollowers({ start, count, sort, search, state: 'accepted', actorType: 'Person' }) + expect(body.total).to.equal(0) + expect(body.data).to.have.lengthOf(0) } { - const res = await getFollowersListPaginationAndSort({ - url, + const body = await followsCommands[2].getFollowers({ start, count, sort, @@ -218,31 +212,31 @@ describe('Test follows', function () { state: 'accepted', actorType: 'Application' }) - expect(res.body.total).to.equal(1) - expect(res.body.data).to.have.lengthOf(1) + expect(body.total).to.equal(1) + expect(body.data).to.have.lengthOf(1) } { - const res = await getFollowersListPaginationAndSort({ url, start, count, sort, search, state: 'pending' }) - expect(res.body.total).to.equal(0) - expect(res.body.data).to.have.lengthOf(0) + const body = await followsCommands[2].getFollowers({ start, count, sort, search, state: 'pending' }) + expect(body.total).to.equal(0) + expect(body.data).to.have.lengthOf(0) } } { - const res = await getFollowersListPaginationAndSort({ url, start, count, sort, search: 'bla' }) - const follows = res.body.data + const body = await followsCommands[2].getFollowers({ start, count, sort, search: 'bla' }) + expect(body.total).to.equal(0) - expect(res.body.total).to.equal(0) + const follows = body.data expect(follows.length).to.equal(0) } }) it('Should have 0 followers on server 1', async function () { - const res = await getFollowersListPaginationAndSort({ url: servers[0].url, start: 0, count: 5, sort: 'createdAt' }) - const follows = res.body.data + const body = await followsCommands[0].getFollowers({ start: 0, count: 5, sort: 'createdAt' }) + expect(body.total).to.equal(0) - expect(res.body.total).to.equal(0) + const follows = body.data expect(follows).to.be.an('array') expect(follows.length).to.equal(0) }) @@ -263,16 +257,16 @@ describe('Test follows', function () { it('Should unfollow server 3 on server 1', async function () { this.timeout(5000) - await unfollow(servers[0].url, servers[0].accessToken, servers[2]) + await followsCommands[0].unfollow({ target: servers[2] }) await waitJobs(servers) }) it('Should not follow server 3 on server 1 anymore', async function () { - const res = await getFollowingListPaginationAndSort({ url: servers[0].url, start: 0, count: 2, sort: 'createdAt' }) - const follows = res.body.data + const body = await followsCommands[0].getFollowings({ start: 0, count: 2, sort: 'createdAt' }) + expect(body.total).to.equal(1) - expect(res.body.total).to.equal(1) + const follows = body.data expect(follows).to.be.an('array') expect(follows.length).to.equal(1) @@ -280,10 +274,10 @@ describe('Test follows', function () { }) it('Should not have server 1 as follower on server 3 anymore', async function () { - const res = await getFollowersListPaginationAndSort({ url: servers[2].url, start: 0, count: 1, sort: 'createdAt' }) + const body = await followsCommands[2].getFollowers({ start: 0, count: 1, sort: 'createdAt' }) + expect(body.total).to.equal(0) - const follows = res.body.data - expect(res.body.total).to.equal(0) + const follows = body.data expect(follows).to.be.an('array') expect(follows.length).to.equal(0) }) @@ -404,7 +398,7 @@ describe('Test follows', function () { await waitJobs(servers) // Server 1 follows server 3 - await follow(servers[0].url, [ servers[2].url ], servers[0].accessToken) + await followsCommands[0].follow({ targets: [ servers[2].url ] }) await waitJobs(servers) }) @@ -563,7 +557,7 @@ describe('Test follows', function () { it('Should unfollow server 3 on server 1 and does not list server 3 videos', async function () { this.timeout(5000) - await unfollow(servers[0].url, servers[0].accessToken, servers[2]) + await followsCommands[0].unfollow({ target: servers[2] }) await waitJobs(servers) diff --git a/server/tests/api/server/handle-down.ts b/server/tests/api/server/handle-down.ts index d57d72f5e..eff4451e5 100644 --- a/server/tests/api/server/handle-down.ts +++ b/server/tests/api/server/handle-down.ts @@ -1,39 +1,33 @@ /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */ -import * as chai from 'chai' import 'mocha' -import { JobState, Video } from '../../../../shared/models' -import { VideoPrivacy } from '../../../../shared/models/videos' -import { VideoCommentThreadTree } from '../../../../shared/models/videos/comment/video-comment.model' - +import * as chai from 'chai' +import { HttpStatusCode } from '@shared/core-utils' import { + addVideoCommentReply, + addVideoCommentThread, cleanupTests, closeAllSequelize, completeVideoCheck, flushAndRunMultipleServers, + getJobsListPaginationAndSort, getVideo, + getVideoCommentThreads, getVideosList, + getVideoThreadComments, immutableAssign, killallServers, reRunServer, ServerInfo, setAccessTokensToServers, setActorFollowScores, - unfollow, updateVideo, uploadVideo, uploadVideoAndGetId, - wait -} from '../../../../shared/extra-utils' -import { follow, getFollowersListPaginationAndSort } from '../../../../shared/extra-utils/server/follows' -import { getJobsListPaginationAndSort, waitJobs } from '../../../../shared/extra-utils/server/jobs' -import { - addVideoCommentReply, - addVideoCommentThread, - getVideoCommentThreads, - getVideoThreadComments -} from '../../../../shared/extra-utils/videos/video-comments' -import { HttpStatusCode } from '../../../../shared/core-utils/miscs/http-error-codes' + wait, + waitJobs +} from '@shared/extra-utils' +import { JobState, Video, VideoCommentThreadTree, VideoPrivacy } from '@shared/models' const expect = chai.expect @@ -118,8 +112,8 @@ describe('Test handle downs', function () { this.timeout(240000) // Server 2 and 3 follow server 1 - await follow(servers[1].url, [ servers[0].url ], servers[1].accessToken) - await follow(servers[2].url, [ servers[0].url ], servers[2].accessToken) + await servers[1].followsCommand.follow({ targets: [ servers[0].url ] }) + await servers[2].followsCommand.follow({ targets: [ servers[0].url ] }) await waitJobs(servers) @@ -177,10 +171,10 @@ describe('Test handle downs', function () { await wait(11000) // Only server 3 is still a follower of server 1 - const res = await getFollowersListPaginationAndSort({ url: servers[0].url, start: 0, count: 2, sort: 'createdAt' }) - expect(res.body.data).to.be.an('array') - expect(res.body.data).to.have.lengthOf(1) - expect(res.body.data[0].follower.host).to.equal('localhost:' + servers[2].port) + const body = await servers[0].followsCommand.getFollowers({ start: 0, count: 2, sort: 'createdAt' }) + expect(body.data).to.be.an('array') + expect(body.data).to.have.lengthOf(1) + expect(body.data[0].follower.host).to.equal('localhost:' + servers[2].port) }) it('Should not have pending/processing jobs anymore', async function () { @@ -205,16 +199,16 @@ describe('Test handle downs', function () { await reRunServer(servers[1]) await reRunServer(servers[2]) - await unfollow(servers[1].url, servers[1].accessToken, servers[0]) + await servers[1].followsCommand.unfollow({ target: servers[0] }) await waitJobs(servers) - await follow(servers[1].url, [ servers[0].url ], servers[1].accessToken) + await servers[1].followsCommand.follow({ targets: [ servers[0].url ] }) await waitJobs(servers) - const res = await getFollowersListPaginationAndSort({ url: servers[0].url, start: 0, count: 2, sort: 'createdAt' }) - expect(res.body.data).to.be.an('array') - expect(res.body.data).to.have.lengthOf(2) + const body = await servers[0].followsCommand.getFollowers({ start: 0, count: 2, sort: 'createdAt' }) + expect(body.data).to.be.an('array') + expect(body.data).to.have.lengthOf(2) }) it('Should send an update to server 3, and automatically fetch the video', async function () { diff --git a/server/tests/api/server/jobs.ts b/server/tests/api/server/jobs.ts index d0e222997..6576dd7af 100644 --- a/server/tests/api/server/jobs.ts +++ b/server/tests/api/server/jobs.ts @@ -1,13 +1,13 @@ /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */ -import * as chai from 'chai' import 'mocha' +import * as chai from 'chai' import { cleanupTests, ServerInfo, setAccessTokensToServers } from '../../../../shared/extra-utils/index' +import { dateIsValid } from '../../../../shared/extra-utils/miscs/miscs' import { doubleFollow } from '../../../../shared/extra-utils/server/follows' import { getJobsList, getJobsListPaginationAndSort, waitJobs } from '../../../../shared/extra-utils/server/jobs' import { flushAndRunMultipleServers } from '../../../../shared/extra-utils/server/servers' import { uploadVideo } from '../../../../shared/extra-utils/videos/videos' -import { dateIsValid } from '../../../../shared/extra-utils/miscs/miscs' import { Job } from '../../../../shared/models/server' const expect = chai.expect diff --git a/server/tests/api/server/stats.ts b/server/tests/api/server/stats.ts index 304181a6d..f609ea725 100644 --- a/server/tests/api/server/stats.ts +++ b/server/tests/api/server/stats.ts @@ -4,27 +4,23 @@ import 'mocha' import * as chai from 'chai' import { addVideoChannel, + addVideoCommentThread, cleanupTests, createUser, createVideoPlaylist, doubleFollow, flushAndRunMultipleServers, - follow, ServerInfo, - unfollow, + setAccessTokensToServers, updateCustomSubConfig, uploadVideo, userLogin, viewVideo, - wait -} from '../../../../shared/extra-utils' -import { setAccessTokensToServers } from '../../../../shared/extra-utils/index' -import { waitJobs } from '../../../../shared/extra-utils/server/jobs' -import { getStats } from '../../../../shared/extra-utils/server/stats' -import { addVideoCommentThread } from '../../../../shared/extra-utils/videos/video-comments' -import { ServerStats } from '../../../../shared/models/server/server-stats.model' -import { VideoPlaylistPrivacy } from '../../../../shared/models/videos/playlist/video-playlist-privacy.model' -import { ActivityType } from '@shared/models' + wait, + waitJobs +} from '@shared/extra-utils' +import { getStats } from '@shared/extra-utils/server/stats' +import { ActivityType, ServerStats, VideoPlaylistPrivacy } from '@shared/models' const expect = chai.expect @@ -57,7 +53,7 @@ describe('Test stats (excluding redundancy)', function () { // Wait the video views repeatable job await wait(8000) - await follow(servers[2].url, [ servers[0].url ], servers[2].accessToken) + await servers[2].followsCommand.follow({ targets: [ servers[0].url ] }) await waitJobs(servers) }) @@ -111,7 +107,7 @@ describe('Test stats (excluding redundancy)', function () { it('Should have the correct total videos stats after an unfollow', async function () { this.timeout(15000) - await unfollow(servers[2].url, servers[2].accessToken, servers[0]) + await servers[2].followsCommand.unfollow({ target: servers[0] }) await waitJobs(servers) const res = await getStats(servers[2].url) diff --git a/server/tests/api/users/user-subscriptions.ts b/server/tests/api/users/user-subscriptions.ts index 60676a37b..7e365d797 100644 --- a/server/tests/api/users/user-subscriptions.ts +++ b/server/tests/api/users/user-subscriptions.ts @@ -1,30 +1,27 @@ /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */ -import * as chai from 'chai' import 'mocha' +import * as chai from 'chai' import { + addUserSubscription, + areSubscriptionsExist, cleanupTests, createUser, doubleFollow, flushAndRunMultipleServers, - follow, - getVideosList, - unfollow, - updateVideo, - userLogin -} from '../../../../shared/extra-utils' -import { ServerInfo, uploadVideo } from '../../../../shared/extra-utils/index' -import { setAccessTokensToServers } from '../../../../shared/extra-utils/users/login' -import { Video, VideoChannel } from '../../../../shared/models/videos' -import { waitJobs } from '../../../../shared/extra-utils/server/jobs' -import { - addUserSubscription, - areSubscriptionsExist, getUserSubscription, + getVideosList, listUserSubscriptions, listUserSubscriptionVideos, - removeUserSubscription -} from '../../../../shared/extra-utils/users/user-subscriptions' + removeUserSubscription, + ServerInfo, + setAccessTokensToServers, + updateVideo, + uploadVideo, + userLogin, + waitJobs +} from '@shared/extra-utils' +import { Video, VideoChannel } from '@shared/models' const expect = chai.expect @@ -250,7 +247,7 @@ describe('Test users subscriptions', function () { it('Should have server 1 follow server 3 and display server 3 videos', async function () { this.timeout(60000) - await follow(servers[0].url, [ servers[2].url ], servers[0].accessToken) + await servers[0].followsCommand.follow({ targets: [ servers[2].url ] }) await waitJobs(servers) @@ -268,7 +265,7 @@ describe('Test users subscriptions', function () { it('Should remove follow server 1 -> server 3 and hide server 3 videos', async function () { this.timeout(60000) - await unfollow(servers[0].url, servers[0].accessToken, servers[2]) + await servers[0].followsCommand.unfollow({ target: servers[2] }) await waitJobs(servers) diff --git a/server/tests/api/users/users.ts b/server/tests/api/users/users.ts index 6bfc7cfe5..92927ea97 100644 --- a/server/tests/api/users/users.ts +++ b/server/tests/api/users/users.ts @@ -11,7 +11,6 @@ import { createUser, deleteMe, flushAndRunServer, - follow, getAccountRatings, getBlacklistedVideosList, getCustomConfig, @@ -138,7 +137,12 @@ describe('Test users', function () { it('Should not be able to follow', async function () { accessToken = 'my_super_token' - await follow(server.url, [ 'http://example.com' ], accessToken, HttpStatusCode.UNAUTHORIZED_401) + + await server.followsCommand.follow({ + targets: [ 'http://example.com' ], + token: accessToken, + expectedStatus: HttpStatusCode.UNAUTHORIZED_401 + }) }) it('Should not be able to unfollow') diff --git a/server/tests/api/videos/video-description.ts b/server/tests/api/videos/video-description.ts index b8e98e45f..e1c9afe79 100644 --- a/server/tests/api/videos/video-description.ts +++ b/server/tests/api/videos/video-description.ts @@ -1,7 +1,7 @@ /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */ -import * as chai from 'chai' import 'mocha' +import * as chai from 'chai' import { cleanupTests, flushAndRunMultipleServers, diff --git a/server/tests/api/videos/video-playlists.ts b/server/tests/api/videos/video-playlists.ts index da8de054b..28f68dcfe 100644 --- a/server/tests/api/videos/video-playlists.ts +++ b/server/tests/api/videos/video-playlists.ts @@ -2,8 +2,12 @@ import 'mocha' import * as chai from 'chai' -import { HttpStatusCode } from '../../../../shared/core-utils/miscs/http-error-codes' +import { HttpStatusCode } from '@shared/core-utils' import { + addAccountToAccountBlocklist, + addAccountToServerBlocklist, + addServerToAccountBlocklist, + addServerToServerBlocklist, addVideoChannel, addVideoInPlaylist, addVideoToBlacklist, @@ -27,6 +31,10 @@ import { getVideoPlaylistPrivacies, getVideoPlaylistsList, getVideoPlaylistWithToken, + removeAccountFromAccountBlocklist, + removeAccountFromServerBlocklist, + removeServerFromAccountBlocklist, + removeServerFromServerBlocklist, removeUser, removeVideoFromBlacklist, removeVideoFromPlaylist, @@ -35,7 +43,6 @@ import { setAccessTokensToServers, setDefaultVideoChannel, testImage, - unfollow, updateVideo, updateVideoPlaylist, updateVideoPlaylistElement, @@ -44,24 +51,18 @@ import { userLogin, wait, waitJobs -} from '../../../../shared/extra-utils' +} from '@shared/extra-utils' import { - addAccountToAccountBlocklist, - addAccountToServerBlocklist, - addServerToAccountBlocklist, - addServerToServerBlocklist, - removeAccountFromAccountBlocklist, - removeAccountFromServerBlocklist, - removeServerFromAccountBlocklist, - removeServerFromServerBlocklist -} from '../../../../shared/extra-utils/users/blocklist' -import { User } from '../../../../shared/models/users' -import { VideoPlaylistCreateResult, VideoPrivacy } from '../../../../shared/models/videos' -import { VideoExistInPlaylist } from '../../../../shared/models/videos/playlist/video-exist-in-playlist.model' -import { VideoPlaylistElement, VideoPlaylistElementType } from '../../../../shared/models/videos/playlist/video-playlist-element.model' -import { VideoPlaylistPrivacy } from '../../../../shared/models/videos/playlist/video-playlist-privacy.model' -import { VideoPlaylistType } from '../../../../shared/models/videos/playlist/video-playlist-type.model' -import { VideoPlaylist } from '../../../../shared/models/videos/playlist/video-playlist.model' + User, + VideoExistInPlaylist, + VideoPlaylist, + VideoPlaylistCreateResult, + VideoPlaylistElement, + VideoPlaylistElementType, + VideoPlaylistPrivacy, + VideoPlaylistType, + VideoPrivacy +} from '@shared/models' const expect = chai.expect @@ -1171,7 +1172,7 @@ describe('Test video playlists', function () { expect(finder(res.body.data)).to.not.be.undefined } - await unfollow(servers[2].url, servers[2].accessToken, servers[0]) + await servers[2].followsCommand.unfollow({ target: servers[0] }) { const res = await getVideoPlaylistsList(servers[2].url, 0, 5) -- cgit v1.2.3 From 9c6327f803aaf4200672f1fc40b2f43786daca47 Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Wed, 7 Jul 2021 09:34:56 +0200 Subject: Introduce jobs command --- server/tests/api/server/handle-down.ts | 7 ++-- server/tests/api/server/jobs.ts | 50 ++++++++++++++--------------- server/tests/api/videos/video-transcoder.ts | 8 ++--- 3 files changed, 28 insertions(+), 37 deletions(-) (limited to 'server/tests/api') diff --git a/server/tests/api/server/handle-down.ts b/server/tests/api/server/handle-down.ts index eff4451e5..c6202fdaa 100644 --- a/server/tests/api/server/handle-down.ts +++ b/server/tests/api/server/handle-down.ts @@ -10,7 +10,6 @@ import { closeAllSequelize, completeVideoCheck, flushAndRunMultipleServers, - getJobsListPaginationAndSort, getVideo, getVideoCommentThreads, getVideosList, @@ -181,15 +180,13 @@ describe('Test handle downs', function () { const states: JobState[] = [ 'waiting', 'active' ] for (const state of states) { - const res = await getJobsListPaginationAndSort({ - url: servers[0].url, - accessToken: servers[0].accessToken, + const body = await servers[0].jobsCommand.getJobsList({ state: state, start: 0, count: 50, sort: '-createdAt' }) - expect(res.body.data).to.have.length(0) + expect(body.data).to.have.length(0) } }) diff --git a/server/tests/api/server/jobs.ts b/server/tests/api/server/jobs.ts index 6576dd7af..c0b9facff 100644 --- a/server/tests/api/server/jobs.ts +++ b/server/tests/api/server/jobs.ts @@ -2,13 +2,16 @@ import 'mocha' import * as chai from 'chai' -import { cleanupTests, ServerInfo, setAccessTokensToServers } from '../../../../shared/extra-utils/index' -import { dateIsValid } from '../../../../shared/extra-utils/miscs/miscs' -import { doubleFollow } from '../../../../shared/extra-utils/server/follows' -import { getJobsList, getJobsListPaginationAndSort, waitJobs } from '../../../../shared/extra-utils/server/jobs' -import { flushAndRunMultipleServers } from '../../../../shared/extra-utils/server/servers' -import { uploadVideo } from '../../../../shared/extra-utils/videos/videos' -import { Job } from '../../../../shared/models/server' +import { + cleanupTests, + dateIsValid, + doubleFollow, + flushAndRunMultipleServers, + ServerInfo, + setAccessTokensToServers, + uploadVideo, + waitJobs +} from '@shared/extra-utils' const expect = chai.expect @@ -36,27 +39,25 @@ describe('Test jobs', function () { }) it('Should list jobs', async function () { - const res = await getJobsList(servers[1].url, servers[1].accessToken, 'completed') - expect(res.body.total).to.be.above(2) - expect(res.body.data).to.have.length.above(2) + const body = await servers[1].jobsCommand.getJobsList({ state: 'completed' }) + expect(body.total).to.be.above(2) + expect(body.data).to.have.length.above(2) }) it('Should list jobs with sort, pagination and job type', async function () { { - const res = await getJobsListPaginationAndSort({ - url: servers[1].url, - accessToken: servers[1].accessToken, + const body = await servers[1].jobsCommand.getJobsList({ state: 'completed', start: 1, count: 2, sort: 'createdAt' }) - expect(res.body.total).to.be.above(2) - expect(res.body.data).to.have.lengthOf(2) + expect(body.total).to.be.above(2) + expect(body.data).to.have.lengthOf(2) - let job: Job = res.body.data[0] + let job = body.data[0] // Skip repeat jobs - if (job.type === 'videos-views') job = res.body.data[1] + if (job.type === 'videos-views') job = body.data[1] expect(job.state).to.equal('completed') expect(job.type.startsWith('activitypub-')).to.be.true @@ -66,29 +67,26 @@ describe('Test jobs', function () { } { - const res = await getJobsListPaginationAndSort({ - url: servers[1].url, - accessToken: servers[1].accessToken, + const body = await servers[1].jobsCommand.getJobsList({ state: 'completed', start: 0, count: 100, sort: 'createdAt', jobType: 'activitypub-http-broadcast' }) - expect(res.body.total).to.be.above(2) + expect(body.total).to.be.above(2) - for (const j of res.body.data as Job[]) { + for (const j of body.data) { expect(j.type).to.equal('activitypub-http-broadcast') } } }) it('Should list all jobs', async function () { - const res = await getJobsList(servers[1].url, servers[1].accessToken) + const body = await servers[1].jobsCommand.getJobsList() + expect(body.total).to.be.above(2) - const jobs = res.body.data as Job[] - - expect(res.body.total).to.be.above(2) + const jobs = body.data expect(jobs).to.have.length.above(2) // We know there are a least 1 delayed job (video views) and 1 completed job (broadcast) diff --git a/server/tests/api/videos/video-transcoder.ts b/server/tests/api/videos/video-transcoder.ts index ea5ffd239..c95053a29 100644 --- a/server/tests/api/videos/video-transcoder.ts +++ b/server/tests/api/videos/video-transcoder.ts @@ -16,7 +16,6 @@ import { flushAndRunMultipleServers, generateHighBitrateVideo, generateVideoWithFramerate, - getJobsListPaginationAndSort, getMyVideos, getServerFileSize, getVideo, @@ -709,17 +708,14 @@ describe('Test video transcoding', function () { describe('Transcoding job queue', function () { it('Should have the appropriate priorities for transcoding jobs', async function () { - const res = await getJobsListPaginationAndSort({ - url: servers[1].url, - accessToken: servers[1].accessToken, + const body = await servers[1].jobsCommand.getJobsList({ start: 0, count: 100, sort: '-createdAt', jobType: 'video-transcoding' }) - const jobs = res.body.data as Job[] - + const jobs = body.data const transcodingJobs = jobs.filter(j => j.data.videoUUID === video4k) expect(transcodingJobs).to.have.lengthOf(14) -- 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 +- .../tests/api/notifications/admin-notifications.ts | 31 ++-- server/tests/api/server/plugins.ts | 188 ++++++--------------- server/tests/api/users/users.ts | 3 +- 4 files changed, 64 insertions(+), 163 deletions(-) (limited to 'server/tests/api') 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 } diff --git a/server/tests/api/notifications/admin-notifications.ts b/server/tests/api/notifications/admin-notifications.ts index 91681c9d6..da9767b74 100644 --- a/server/tests/api/notifications/admin-notifications.ts +++ b/server/tests/api/notifications/admin-notifications.ts @@ -2,18 +2,20 @@ import 'mocha' import { expect } from 'chai' -import { MockJoinPeerTubeVersions } from '@shared/extra-utils' -import { PluginType } from '@shared/models' -import { cleanupTests, installPlugin, setPluginLatestVersion, setPluginVersion, wait } from '../../../../shared/extra-utils' -import { ServerInfo } from '../../../../shared/extra-utils/index' -import { MockSmtpServer } from '../../../../shared/extra-utils/mock-servers/mock-email' import { CheckerBaseParams, checkNewPeerTubeVersion, checkNewPluginVersion, - prepareNotificationsTest -} from '../../../../shared/extra-utils/users/user-notifications' -import { UserNotification, UserNotificationType } from '../../../../shared/models/users' + cleanupTests, + MockJoinPeerTubeVersions, + MockSmtpServer, + prepareNotificationsTest, + ServerInfo, + setPluginLatestVersion, + setPluginVersion, + wait +} from '@shared/extra-utils' +import { PluginType, UserNotification, UserNotificationType } from '@shared/models' describe('Test admin notifications', function () { let server: ServerInfo @@ -58,17 +60,8 @@ describe('Test admin notifications', function () { token: server.accessToken } - await installPlugin({ - url: server.url, - accessToken: server.accessToken, - npmName: 'peertube-plugin-hello-world' - }) - - await installPlugin({ - url: server.url, - accessToken: server.accessToken, - npmName: 'peertube-theme-background-red' - }) + await server.pluginsCommand.install({ npmName: 'peertube-plugin-hello-world' }) + await server.pluginsCommand.install({ npmName: 'peertube-theme-background-red' }) }) describe('Latest PeerTube version notification', function () { diff --git a/server/tests/api/server/plugins.ts b/server/tests/api/server/plugins.ts index 6b61c7c33..1536997d5 100644 --- a/server/tests/api/server/plugins.ts +++ b/server/tests/api/server/plugins.ts @@ -9,34 +9,25 @@ import { flushAndRunServer, getConfig, getMyUserInformation, - getPlugin, - getPluginPackageJSON, - getPluginTestPath, - getPublicSettings, - installPlugin, killallServers, - listAvailablePlugins, - listPlugins, + PluginsCommand, reRunServer, ServerInfo, setAccessTokensToServers, setPluginVersion, testHelloWorldRegisteredSettings, - uninstallPlugin, updateCustomSubConfig, updateMyUser, - updatePlugin, - updatePluginPackageJSON, - updatePluginSettings, wait, waitUntilLog } from '@shared/extra-utils' -import { PeerTubePlugin, PeerTubePluginIndex, PluginPackageJson, PluginType, PublicServerSetting, ServerConfig, User } from '@shared/models' +import { PluginType, ServerConfig, User } from '@shared/models' const expect = chai.expect describe('Test plugins', function () { let server: ServerInfo = null + let command: PluginsCommand before(async function () { this.timeout(30000) @@ -54,60 +45,51 @@ describe('Test plugins', function () { this.timeout(30000) { - const res = await listAvailablePlugins({ - url: server.url, - accessToken: server.accessToken, + const body = await command.listAvailable({ count: 1, start: 0, pluginType: PluginType.THEME, search: 'background-red' }) - expect(res.body.total).to.be.at.least(1) - expect(res.body.data).to.have.lengthOf(1) + expect(body.total).to.be.at.least(1) + expect(body.data).to.have.lengthOf(1) } { - const res1 = await listAvailablePlugins({ - url: server.url, - accessToken: server.accessToken, + const body1 = await command.listAvailable({ count: 2, start: 0, sort: 'npmName' }) - const data1: PeerTubePluginIndex[] = res1.body.data + expect(body1.total).to.be.at.least(2) - expect(res1.body.total).to.be.at.least(2) + const data1 = body1.data expect(data1).to.have.lengthOf(2) - const res2 = await listAvailablePlugins({ - url: server.url, - accessToken: server.accessToken, + const body2 = await command.listAvailable({ count: 2, start: 0, sort: '-npmName' }) - const data2: PeerTubePluginIndex[] = res2.body.data + expect(body2.total).to.be.at.least(2) - expect(res2.body.total).to.be.at.least(2) + const data2 = body2.data expect(data2).to.have.lengthOf(2) expect(data1[0].npmName).to.not.equal(data2[0].npmName) } { - const res = await listAvailablePlugins({ - url: server.url, - accessToken: server.accessToken, + const body = await command.listAvailable({ count: 10, start: 0, pluginType: PluginType.THEME, search: 'background-red', currentPeerTubeEngine: '1.0.0' }) - const data: PeerTubePluginIndex[] = res.body.data - const p = data.find(p => p.npmName === 'peertube-theme-background-red') + const p = body.data.find(p => p.npmName === 'peertube-theme-background-red') expect(p).to.be.undefined } }) @@ -115,17 +97,8 @@ describe('Test plugins', function () { it('Should install a plugin and a theme', async function () { this.timeout(30000) - await installPlugin({ - url: server.url, - accessToken: server.accessToken, - npmName: 'peertube-plugin-hello-world' - }) - - await installPlugin({ - url: server.url, - accessToken: server.accessToken, - npmName: 'peertube-theme-background-red' - }) + await command.install({ npmName: 'peertube-plugin-hello-world' }) + await command.install({ npmName: 'peertube-theme-background-red' }) }) it('Should have the plugin loaded in the configuration', async function () { @@ -161,45 +134,38 @@ describe('Test plugins', function () { it('Should list plugins and themes', async function () { { - const res = await listPlugins({ - url: server.url, - accessToken: server.accessToken, + const body = await command.list({ count: 1, start: 0, pluginType: PluginType.THEME }) - const data: PeerTubePlugin[] = res.body.data + expect(body.total).to.be.at.least(1) - expect(res.body.total).to.be.at.least(1) + const data = body.data expect(data).to.have.lengthOf(1) expect(data[0].name).to.equal('background-red') } { - const res = await listPlugins({ - url: server.url, - accessToken: server.accessToken, + const body = await command.list({ count: 2, start: 0, sort: 'name' }) - const data: PeerTubePlugin[] = res.body.data + const data = body expect(data[0].name).to.equal('background-red') expect(data[1].name).to.equal('hello-world') } { - const res = await listPlugins({ - url: server.url, - accessToken: server.accessToken, + const body = await command.list({ count: 2, start: 1, sort: 'name' }) - const data: PeerTubePlugin[] = res.body.data - expect(data[0].name).to.equal('hello-world') + expect(body.data[0].name).to.equal('hello-world') } }) @@ -208,9 +174,8 @@ describe('Test plugins', function () { }) it('Should get public settings', async function () { - const res = await getPublicSettings({ url: server.url, npmName: 'peertube-plugin-hello-world' }) - - const publicSettings = (res.body as PublicServerSetting).publicSettings + const body = await command.getPublicSettings({ npmName: 'peertube-plugin-hello-world' }) + const publicSettings = body.publicSettings expect(Object.keys(publicSettings)).to.have.lengthOf(1) expect(Object.keys(publicSettings)).to.deep.equal([ 'user-name' ]) @@ -222,9 +187,7 @@ describe('Test plugins', function () { 'admin-name': 'Cid' } - await updatePluginSettings({ - url: server.url, - accessToken: server.accessToken, + await command.updateSettings({ npmName: 'peertube-plugin-hello-world', settings }) @@ -238,13 +201,7 @@ describe('Test plugins', function () { it('Should get a plugin and a theme', async function () { { - const res = await getPlugin({ - url: server.url, - accessToken: server.accessToken, - npmName: 'peertube-plugin-hello-world' - }) - - const plugin: PeerTubePlugin = res.body + const plugin = await command.get({ npmName: 'peertube-plugin-hello-world' }) expect(plugin.type).to.equal(PluginType.PLUGIN) expect(plugin.name).to.equal('hello-world') @@ -262,13 +219,7 @@ describe('Test plugins', function () { } { - const res = await getPlugin({ - url: server.url, - accessToken: server.accessToken, - npmName: 'peertube-theme-background-red' - }) - - const plugin: PeerTubePlugin = res.body + const plugin = await command.get({ npmName: 'peertube-theme-background-red' }) expect(plugin.type).to.equal(PluginType.THEME) expect(plugin.name).to.equal('background-red') @@ -295,92 +246,59 @@ describe('Test plugins', function () { await setPluginVersion(server.internalServerNumber, 'hello-world', '0.0.1') // Fake update package.json - const packageJSON: PluginPackageJson = await getPluginPackageJSON(server, 'peertube-plugin-hello-world') + const packageJSON = await command.getPackageJSON('peertube-plugin-hello-world') const oldVersion = packageJSON.version packageJSON.version = '0.0.1' - await updatePluginPackageJSON(server, 'peertube-plugin-hello-world', packageJSON) + await command.updatePackageJSON('peertube-plugin-hello-world', packageJSON) // Restart the server to take into account this change killallServers([ server ]) await reRunServer(server) { - const res = await listPlugins({ - url: server.url, - accessToken: server.accessToken, - pluginType: PluginType.PLUGIN - }) - - const plugin: PeerTubePlugin = res.body.data[0] + const body = await command.list({ pluginType: PluginType.PLUGIN }) + const plugin = body.data[0] expect(plugin.version).to.equal('0.0.1') expect(plugin.latestVersion).to.exist expect(plugin.latestVersion).to.not.equal('0.0.1') } { - await updatePlugin({ - url: server.url, - accessToken: server.accessToken, - npmName: 'peertube-plugin-hello-world' - }) - - const res = await listPlugins({ - url: server.url, - accessToken: server.accessToken, - pluginType: PluginType.PLUGIN - }) + await command.update({ npmName: 'peertube-plugin-hello-world' }) - const plugin: PeerTubePlugin = res.body.data[0] + const body = await command.list({ pluginType: PluginType.PLUGIN }) + const plugin = body.data[0] expect(plugin.version).to.equal(oldVersion) - const updatedPackageJSON: PluginPackageJson = await getPluginPackageJSON(server, 'peertube-plugin-hello-world') + const updatedPackageJSON = await command.getPackageJSON('peertube-plugin-hello-world') expect(updatedPackageJSON.version).to.equal(oldVersion) } }) it('Should uninstall the plugin', async function () { - await uninstallPlugin({ - url: server.url, - accessToken: server.accessToken, - npmName: 'peertube-plugin-hello-world' - }) - - const res = await listPlugins({ - url: server.url, - accessToken: server.accessToken, - pluginType: PluginType.PLUGIN - }) + await command.uninstall({ npmName: 'peertube-plugin-hello-world' }) - expect(res.body.total).to.equal(0) - expect(res.body.data).to.have.lengthOf(0) + const body = await command.list({ pluginType: PluginType.PLUGIN }) + expect(body.total).to.equal(0) + expect(body.data).to.have.lengthOf(0) }) it('Should list uninstalled plugins', async function () { - const res = await listPlugins({ - url: server.url, - accessToken: server.accessToken, - pluginType: PluginType.PLUGIN, - uninstalled: true - }) + const body = await command.list({ pluginType: PluginType.PLUGIN, uninstalled: true }) + expect(body.total).to.equal(1) + expect(body.data).to.have.lengthOf(1) - expect(res.body.total).to.equal(1) - expect(res.body.data).to.have.lengthOf(1) - - const plugin: PeerTubePlugin = res.body.data[0] + const plugin = body.data[0] expect(plugin.name).to.equal('hello-world') expect(plugin.enabled).to.be.false expect(plugin.uninstalled).to.be.true }) it('Should uninstall the theme', async function () { - await uninstallPlugin({ - url: server.url, - accessToken: server.accessToken, - npmName: 'peertube-theme-background-red' - }) + await command.uninstall({ npmName: 'peertube-theme-background-red' }) }) it('Should have updated the configuration', async function () { @@ -406,21 +324,13 @@ describe('Test plugins', function () { this.timeout(60000) async function check () { - const res = await listPlugins({ - url: server.url, - accessToken: server.accessToken, - pluginType: PluginType.PLUGIN - }) - - const plugins: PeerTubePlugin[] = res.body.data - + const body = await command.list({ pluginType: PluginType.PLUGIN }) + const plugins = body.data expect(plugins.find(p => p.name === 'test-broken')).to.not.exist } - await installPlugin({ - url: server.url, - accessToken: server.accessToken, - path: getPluginTestPath('-broken'), + await command.install({ + path: PluginsCommand.getPluginTestPath('-broken'), expectedStatus: HttpStatusCode.BAD_REQUEST_400 }) diff --git a/server/tests/api/users/users.ts b/server/tests/api/users/users.ts index 92927ea97..ba4183e08 100644 --- a/server/tests/api/users/users.ts +++ b/server/tests/api/users/users.ts @@ -23,7 +23,6 @@ import { getUsersListPaginationAndSort, getVideoChannel, getVideosList, - installPlugin, killallServers, login, logout, @@ -75,7 +74,7 @@ describe('Test users', function () { await setAccessTokensToServers([ server ]) - await installPlugin({ url: server.url, accessToken: server.accessToken, npmName: 'peertube-theme-background-red' }) + await server.pluginsCommand.install({ npmName: 'peertube-theme-background-red' }) }) describe('OAuth client', function () { -- cgit v1.2.3 From dab047092b51b453f175069573d8865fb17acdfc Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Wed, 7 Jul 2021 10:56:45 +0200 Subject: Introduce redundancy command --- server/tests/api/redundancy/manage-redundancy.ts | 165 +++++++-------------- .../tests/api/redundancy/redundancy-constraints.ts | 28 ++-- server/tests/api/redundancy/redundancy.ts | 49 +++--- 3 files changed, 84 insertions(+), 158 deletions(-) (limited to 'server/tests/api') diff --git a/server/tests/api/redundancy/manage-redundancy.ts b/server/tests/api/redundancy/manage-redundancy.ts index 4253124c8..363e4cbfe 100644 --- a/server/tests/api/redundancy/manage-redundancy.ts +++ b/server/tests/api/redundancy/manage-redundancy.ts @@ -1,21 +1,21 @@ /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */ -import * as chai from 'chai' import 'mocha' +import * as chai from 'chai' import { cleanupTests, doubleFollow, flushAndRunMultipleServers, getLocalIdByUUID, + RedundancyCommand, ServerInfo, setAccessTokensToServers, uploadVideo, uploadVideoAndGetId, + waitJobs, waitUntilLog -} from '../../../../shared/extra-utils' -import { waitJobs } from '../../../../shared/extra-utils/server/jobs' -import { addVideoRedundancy, listVideoRedundancies, removeVideoRedundancy, updateRedundancy } from '@shared/extra-utils/server/redundancy' -import { VideoPrivacy, VideoRedundanciesTarget, VideoRedundancy } from '@shared/models' +} from '@shared/extra-utils' +import { VideoPrivacy, VideoRedundanciesTarget } from '@shared/models' const expect = chai.expect @@ -27,6 +27,8 @@ describe('Test manage videos redundancy', function () { let video2Server2UUID: string let redundanciesToRemove: number[] = [] + let commands: RedundancyCommand[] + before(async function () { this.timeout(120000) @@ -55,6 +57,8 @@ describe('Test manage videos redundancy', function () { // Get the access tokens await setAccessTokensToServers(servers) + commands = servers.map(s => s.redundancyCommand) + { const res = await uploadVideo(servers[1].url, servers[1].accessToken, { name: 'video 1 server 2' }) video1Server2UUID = res.body.video.uuid @@ -69,21 +73,17 @@ describe('Test manage videos redundancy', function () { // Server 1 and server 2 follow each other await doubleFollow(servers[0], servers[1]) - await updateRedundancy(servers[0].url, servers[0].accessToken, servers[1].host, true) + await commands[0].updateRedundancy({ host: servers[1].host, redundancyAllowed: true }) await waitJobs(servers) }) it('Should not have redundancies on server 3', async function () { for (const target of targets) { - const res = await listVideoRedundancies({ - url: servers[2].url, - accessToken: servers[2].accessToken, - target - }) + const body = await commands[2].listVideos({ target }) - expect(res.body.total).to.equal(0) - expect(res.body.data).to.have.lengthOf(0) + expect(body.total).to.equal(0) + expect(body.data).to.have.lengthOf(0) } }) @@ -94,28 +94,19 @@ describe('Test manage videos redundancy', function () { await waitUntilLog(servers[0], 'Duplicated ', 10) await waitJobs(servers) - const res = await listVideoRedundancies({ - url: servers[1].url, - accessToken: servers[1].accessToken, - target: 'remote-videos' - }) + const body = await commands[1].listVideos({ target: 'remote-videos' }) - expect(res.body.total).to.equal(0) - expect(res.body.data).to.have.lengthOf(0) + expect(body.total).to.equal(0) + expect(body.data).to.have.lengthOf(0) }) it('Should have "my-videos" redundancies on server 2', async function () { this.timeout(120000) - const res = await listVideoRedundancies({ - url: servers[1].url, - accessToken: servers[1].accessToken, - target: 'my-videos' - }) - - expect(res.body.total).to.equal(2) + const body = await commands[1].listVideos({ target: 'my-videos' }) + expect(body.total).to.equal(2) - const videos = res.body.data as VideoRedundancy[] + const videos = body.data expect(videos).to.have.lengthOf(2) const videos1 = videos.find(v => v.uuid === video1Server2UUID) @@ -139,28 +130,19 @@ describe('Test manage videos redundancy', function () { }) it('Should not have "my-videos" redundancies on server 1', async function () { - const res = await listVideoRedundancies({ - url: servers[0].url, - accessToken: servers[0].accessToken, - target: 'my-videos' - }) + const body = await commands[0].listVideos({ target: 'my-videos' }) - expect(res.body.total).to.equal(0) - expect(res.body.data).to.have.lengthOf(0) + expect(body.total).to.equal(0) + expect(body.data).to.have.lengthOf(0) }) it('Should have "remote-videos" redundancies on server 1', async function () { this.timeout(120000) - const res = await listVideoRedundancies({ - url: servers[0].url, - accessToken: servers[0].accessToken, - target: 'remote-videos' - }) + const body = await commands[0].listVideos({ target: 'remote-videos' }) + expect(body.total).to.equal(2) - expect(res.body.total).to.equal(2) - - const videos = res.body.data as VideoRedundancy[] + const videos = body.data expect(videos).to.have.lengthOf(2) const videos1 = videos.find(v => v.uuid === video1Server2UUID) @@ -185,47 +167,40 @@ describe('Test manage videos redundancy', function () { it('Should correctly paginate and sort results', async function () { { - const res = await listVideoRedundancies({ - url: servers[0].url, - accessToken: servers[0].accessToken, + const body = await commands[0].listVideos({ target: 'remote-videos', sort: 'name', start: 0, count: 2 }) - const videos = res.body.data + const videos = body.data expect(videos[0].name).to.equal('video 1 server 2') expect(videos[1].name).to.equal('video 2 server 2') } { - const res = await listVideoRedundancies({ - url: servers[0].url, - accessToken: servers[0].accessToken, + const body = await commands[0].listVideos({ target: 'remote-videos', sort: '-name', start: 0, count: 2 }) - const videos = res.body.data + const videos = body.data expect(videos[0].name).to.equal('video 2 server 2') expect(videos[1].name).to.equal('video 1 server 2') } { - const res = await listVideoRedundancies({ - url: servers[0].url, - accessToken: servers[0].accessToken, + const body = await commands[0].listVideos({ target: 'remote-videos', sort: '-name', start: 1, count: 1 }) - const videos = res.body.data - expect(videos[0].name).to.equal('video 1 server 2') + expect(body.data[0].name).to.equal('video 1 server 2') } }) @@ -236,30 +211,23 @@ describe('Test manage videos redundancy', function () { await waitJobs(servers) const videoId = await getLocalIdByUUID(servers[0].url, uuid) - await addVideoRedundancy({ - url: servers[0].url, - accessToken: servers[0].accessToken, - videoId - }) + await commands[0].addVideo({ videoId }) await waitJobs(servers) await waitUntilLog(servers[0], 'Duplicated ', 15) await waitJobs(servers) { - const res = await listVideoRedundancies({ - url: servers[0].url, - accessToken: servers[0].accessToken, + const body = await commands[0].listVideos({ target: 'remote-videos', sort: '-name', start: 0, count: 5 }) - const videos = res.body.data - expect(videos[0].name).to.equal('video 3 server 2') + const video = body.data[0] - const video = videos[0] + expect(video.name).to.equal('video 3 server 2') expect(video.redundancies.files).to.have.lengthOf(4) expect(video.redundancies.streamingPlaylists).to.have.lengthOf(1) @@ -276,19 +244,15 @@ describe('Test manage videos redundancy', function () { } } - const res = await listVideoRedundancies({ - url: servers[1].url, - accessToken: servers[1].accessToken, + const body = await commands[1].listVideos({ target: 'my-videos', sort: '-name', start: 0, count: 5 }) - const videos = res.body.data - expect(videos[0].name).to.equal('video 3 server 2') - - const video = videos[0] + const video = body.data[0] + expect(video.name).to.equal('video 3 server 2') expect(video.redundancies.files).to.have.lengthOf(4) expect(video.redundancies.streamingPlaylists).to.have.lengthOf(1) @@ -307,64 +271,47 @@ describe('Test manage videos redundancy', function () { this.timeout(120000) for (const redundancyId of redundanciesToRemove) { - await removeVideoRedundancy({ - url: servers[0].url, - accessToken: servers[0].accessToken, - redundancyId - }) + await commands[0].removeVideo({ redundancyId }) } { - const res = await listVideoRedundancies({ - url: servers[0].url, - accessToken: servers[0].accessToken, + const body = await commands[0].listVideos({ target: 'remote-videos', sort: '-name', start: 0, count: 5 }) - const videos = res.body.data - expect(videos).to.have.lengthOf(2) + const videos = body.data - expect(videos[0].name).to.equal('video 2 server 2') + expect(videos).to.have.lengthOf(2) - redundanciesToRemove = [] const video = videos[0] + expect(video.name).to.equal('video 2 server 2') expect(video.redundancies.files).to.have.lengthOf(4) expect(video.redundancies.streamingPlaylists).to.have.lengthOf(1) const redundancies = video.redundancies.files.concat(video.redundancies.streamingPlaylists) - for (const r of redundancies) { - redundanciesToRemove.push(r.id) - } + redundanciesToRemove = redundancies.map(r => r.id) } }) it('Should remove another (auto) redundancy', async function () { - { - for (const redundancyId of redundanciesToRemove) { - await removeVideoRedundancy({ - url: servers[0].url, - accessToken: servers[0].accessToken, - redundancyId - }) - } + for (const redundancyId of redundanciesToRemove) { + await commands[0].removeVideo({ redundancyId }) + } - const res = await listVideoRedundancies({ - url: servers[0].url, - accessToken: servers[0].accessToken, - target: 'remote-videos', - sort: '-name', - start: 0, - count: 5 - }) + const body = await commands[0].listVideos({ + target: 'remote-videos', + sort: '-name', + start: 0, + count: 5 + }) - const videos = res.body.data - expect(videos[0].name).to.equal('video 1 server 2') - expect(videos).to.have.lengthOf(1) - } + const videos = body.data + expect(videos).to.have.lengthOf(1) + expect(videos[0].name).to.equal('video 1 server 2') }) after(async function () { diff --git a/server/tests/api/redundancy/redundancy-constraints.ts b/server/tests/api/redundancy/redundancy-constraints.ts index 602f4bc1b..a666976b3 100644 --- a/server/tests/api/redundancy/redundancy-constraints.ts +++ b/server/tests/api/redundancy/redundancy-constraints.ts @@ -1,9 +1,6 @@ /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */ import 'mocha' -import * as chai from 'chai' -import { listVideoRedundancies, updateRedundancy } from '@shared/extra-utils/server/redundancy' -import { VideoPrivacy } from '@shared/models' import { cleanupTests, flushAndRunServer, @@ -13,9 +10,10 @@ import { setAccessTokensToServers, updateVideo, uploadVideo, + waitJobs, waitUntilLog -} from '../../../../shared/extra-utils' -import { waitJobs } from '../../../../shared/extra-utils/server/jobs' +} from '@shared/extra-utils' +import { VideoPrivacy } from '@shared/models' const expect = chai.expect @@ -50,23 +48,15 @@ describe('Test redundancy constraints', function () { } async function getTotalRedundanciesLocalServer () { - const res = await listVideoRedundancies({ - url: localServer.url, - accessToken: localServer.accessToken, - target: 'my-videos' - }) + const body = await localServer.redundancyCommand.listVideos({ target: 'my-videos' }) - return res.body.total + return body.total } async function getTotalRedundanciesRemoteServer () { - const res = await listVideoRedundancies({ - url: remoteServer.url, - accessToken: remoteServer.accessToken, - target: 'remote-videos' - }) + const body = await remoteServer.redundancyCommand.listVideos({ target: 'remote-videos' }) - return res.body.total + return body.total } before(async function () { @@ -99,7 +89,7 @@ describe('Test redundancy constraints', function () { // Server 1 and server 2 follow each other await remoteServer.followsCommand.follow({ targets: [ localServer.url ] }) await waitJobs(servers) - await updateRedundancy(remoteServer.url, remoteServer.accessToken, localServer.host, true) + await remoteServer.redundancyCommand.updateRedundancy({ host: localServer.host, redundancyAllowed: true }) await waitJobs(servers) }) @@ -161,7 +151,7 @@ describe('Test redundancy constraints', function () { } } } - await killallServers([ localServer ]) + killallServers([ localServer ]) await reRunServer(localServer, config) await uploadWrapper('video 3 server 2') diff --git a/server/tests/api/redundancy/redundancy.ts b/server/tests/api/redundancy/redundancy.ts index dfe8099ed..5b970473c 100644 --- a/server/tests/api/redundancy/redundancy.ts +++ b/server/tests/api/redundancy/redundancy.ts @@ -5,7 +5,8 @@ import * as chai from 'chai' import { readdir } from 'fs-extra' import * as magnetUtil from 'magnet-uri' import { join } from 'path' -import { HttpStatusCode } from '../../../../shared/core-utils/miscs/http-error-codes' +import { removeVideoRedundancy } from '@server/lib/redundancy' +import { HttpStatusCode } from '@shared/core-utils' import { checkSegmentHash, checkVideoFilesWereRemoved, @@ -26,19 +27,18 @@ import { uploadVideo, viewVideo, wait, + waitJobs, waitUntilLog -} from '../../../../shared/extra-utils' -import { waitJobs } from '../../../../shared/extra-utils/server/jobs' +} from '@shared/extra-utils' +import { getStats } from '@shared/extra-utils/server/stats' import { - addVideoRedundancy, - listVideoRedundancies, - removeVideoRedundancy, - updateRedundancy -} from '../../../../shared/extra-utils/server/redundancy' -import { getStats } from '../../../../shared/extra-utils/server/stats' -import { VideoRedundancy, VideoRedundancyStrategy, VideoRedundancyStrategyWithManual } from '../../../../shared/models/redundancy' -import { ServerStats } from '../../../../shared/models/server/server-stats.model' -import { VideoDetails, VideoPrivacy } from '../../../../shared/models/videos' + ServerStats, + VideoDetails, + VideoPrivacy, + VideoRedundancy, + VideoRedundancyStrategy, + VideoRedundancyStrategyWithManual +} from '@shared/models' const expect = chai.expect @@ -279,7 +279,7 @@ async function findServerFollows () { } async function enableRedundancyOnServer1 () { - await updateRedundancy(servers[0].url, servers[0].accessToken, servers[1].host, true) + await servers[0].redundancyCommand.updateRedundancy({ host: servers[1].host, redundancyAllowed: true }) const { server2, server3 } = await findServerFollows() @@ -291,7 +291,7 @@ async function enableRedundancyOnServer1 () { } async function disableRedundancyOnServer1 () { - await updateRedundancy(servers[0].url, servers[0].accessToken, servers[1].host, false) + await servers[0].redundancyCommand.updateRedundancy({ host: servers[1].host, redundancyAllowed: false }) const { server2, server3 } = await findServerFollows() @@ -551,11 +551,7 @@ describe('Test videos redundancy', function () { }) it('Should create a redundancy on first video', async function () { - await addVideoRedundancy({ - url: servers[0].url, - accessToken: servers[0].accessToken, - videoId: video1Server2Id - }) + await servers[0].redundancyCommand.addVideo({ videoId: video1Server2Id }) }) it('Should have 2 webseeds on the first video', async function () { @@ -573,22 +569,15 @@ describe('Test videos redundancy', function () { it('Should manually remove redundancies on server 1 and remove duplicated videos', async function () { this.timeout(80000) - const res = await listVideoRedundancies({ - url: servers[0].url, - accessToken: servers[0].accessToken, - target: 'remote-videos' - }) + const body = await servers[0].redundancyCommand.listVideos({ target: 'remote-videos' }) - const videos = res.body.data as VideoRedundancy[] + const videos = body.data expect(videos).to.have.lengthOf(1) const video = videos[0] + for (const r of video.redundancies.files.concat(video.redundancies.streamingPlaylists)) { - await removeVideoRedundancy({ - url: servers[0].url, - accessToken: servers[0].accessToken, - redundancyId: r.id - }) + await servers[0].redundancyCommand.removeVideo({ redundancyId: r.id }) } await waitJobs(servers) -- cgit v1.2.3 From bc8090411ddaa8d742ce4de3c83f9dba7bc18e2a Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Wed, 7 Jul 2021 11:07:12 +0200 Subject: Introduce stats command --- server/tests/api/redundancy/redundancy.ts | 15 +------- server/tests/api/server/stats.ts | 63 ++++++++++++------------------- 2 files changed, 27 insertions(+), 51 deletions(-) (limited to 'server/tests/api') diff --git a/server/tests/api/redundancy/redundancy.ts b/server/tests/api/redundancy/redundancy.ts index 5b970473c..e4ea99de6 100644 --- a/server/tests/api/redundancy/redundancy.ts +++ b/server/tests/api/redundancy/redundancy.ts @@ -5,7 +5,6 @@ import * as chai from 'chai' import { readdir } from 'fs-extra' import * as magnetUtil from 'magnet-uri' import { join } from 'path' -import { removeVideoRedundancy } from '@server/lib/redundancy' import { HttpStatusCode } from '@shared/core-utils' import { checkSegmentHash, @@ -30,15 +29,7 @@ import { waitJobs, waitUntilLog } from '@shared/extra-utils' -import { getStats } from '@shared/extra-utils/server/stats' -import { - ServerStats, - VideoDetails, - VideoPrivacy, - VideoRedundancy, - VideoRedundancyStrategy, - VideoRedundancyStrategyWithManual -} from '@shared/models' +import { VideoDetails, VideoPrivacy, VideoRedundancyStrategy, VideoRedundancyStrategyWithManual } from '@shared/models' const expect = chai.expect @@ -241,9 +232,7 @@ async function checkStatsGlobal (strategy: VideoRedundancyStrategyWithManual) { statsLength = 2 } - const res = await getStats(servers[0].url) - const data: ServerStats = res.body - + const data = await servers[0].statsCommand.get() expect(data.videosRedundancy).to.have.lengthOf(statsLength) const stat = data.videosRedundancy[0] diff --git a/server/tests/api/server/stats.ts b/server/tests/api/server/stats.ts index f609ea725..36114a297 100644 --- a/server/tests/api/server/stats.ts +++ b/server/tests/api/server/stats.ts @@ -19,8 +19,7 @@ import { wait, waitJobs } from '@shared/extra-utils' -import { getStats } from '@shared/extra-utils/server/stats' -import { ActivityType, ServerStats, VideoPlaylistPrivacy } from '@shared/models' +import { ActivityType, VideoPlaylistPrivacy } from '@shared/models' const expect = chai.expect @@ -58,8 +57,7 @@ describe('Test stats (excluding redundancy)', function () { }) it('Should have the correct stats on instance 1', async function () { - const res = await getStats(servers[0].url) - const data: ServerStats = res.body + const data = await servers[0].statsCommand.get() expect(data.totalLocalVideoComments).to.equal(1) expect(data.totalLocalVideos).to.equal(1) @@ -74,8 +72,7 @@ describe('Test stats (excluding redundancy)', function () { }) it('Should have the correct stats on instance 2', async function () { - const res = await getStats(servers[1].url) - const data: ServerStats = res.body + const data = await servers[1].statsCommand.get() expect(data.totalLocalVideoComments).to.equal(0) expect(data.totalLocalVideos).to.equal(0) @@ -90,8 +87,7 @@ describe('Test stats (excluding redundancy)', function () { }) it('Should have the correct stats on instance 3', async function () { - const res = await getStats(servers[2].url) - const data: ServerStats = res.body + const data = await servers[2].statsCommand.get() expect(data.totalLocalVideoComments).to.equal(0) expect(data.totalLocalVideos).to.equal(0) @@ -110,8 +106,7 @@ describe('Test stats (excluding redundancy)', function () { await servers[2].followsCommand.unfollow({ target: servers[0] }) await waitJobs(servers) - const res = await getStats(servers[2].url) - const data: ServerStats = res.body + const data = await servers[2].statsCommand.get() expect(data.totalVideos).to.equal(0) }) @@ -120,8 +115,8 @@ describe('Test stats (excluding redundancy)', function () { const server = servers[0] { - const res = await getStats(server.url) - const data: ServerStats = res.body + const data = await server.statsCommand.get() + expect(data.totalDailyActiveUsers).to.equal(1) expect(data.totalWeeklyActiveUsers).to.equal(1) expect(data.totalMonthlyActiveUsers).to.equal(1) @@ -130,8 +125,8 @@ describe('Test stats (excluding redundancy)', function () { { await userLogin(server, user) - const res = await getStats(server.url) - const data: ServerStats = res.body + const data = await server.statsCommand.get() + expect(data.totalDailyActiveUsers).to.equal(2) expect(data.totalWeeklyActiveUsers).to.equal(2) expect(data.totalMonthlyActiveUsers).to.equal(2) @@ -142,8 +137,8 @@ describe('Test stats (excluding redundancy)', function () { const server = servers[0] { - const res = await getStats(server.url) - const data: ServerStats = res.body + const data = await server.statsCommand.get() + expect(data.totalLocalDailyActiveVideoChannels).to.equal(1) expect(data.totalLocalWeeklyActiveVideoChannels).to.equal(1) expect(data.totalLocalMonthlyActiveVideoChannels).to.equal(1) @@ -157,8 +152,8 @@ describe('Test stats (excluding redundancy)', function () { const resChannel = await addVideoChannel(server.url, server.accessToken, channelAttributes) channelId = resChannel.body.videoChannel.id - const res = await getStats(server.url) - const data: ServerStats = res.body + const data = await server.statsCommand.get() + expect(data.totalLocalDailyActiveVideoChannels).to.equal(1) expect(data.totalLocalWeeklyActiveVideoChannels).to.equal(1) expect(data.totalLocalMonthlyActiveVideoChannels).to.equal(1) @@ -167,8 +162,8 @@ describe('Test stats (excluding redundancy)', function () { { await uploadVideo(server.url, server.accessToken, { fixture: 'video_short.webm', channelId }) - const res = await getStats(server.url) - const data: ServerStats = res.body + const data = await server.statsCommand.get() + expect(data.totalLocalDailyActiveVideoChannels).to.equal(2) expect(data.totalLocalWeeklyActiveVideoChannels).to.equal(2) expect(data.totalLocalMonthlyActiveVideoChannels).to.equal(2) @@ -179,9 +174,8 @@ describe('Test stats (excluding redundancy)', function () { const server = servers[0] { - const resStats = await getStats(server.url) - const dataStats: ServerStats = resStats.body - expect(dataStats.totalLocalPlaylists).to.equal(0) + const data = await server.statsCommand.get() + expect(data.totalLocalPlaylists).to.equal(0) } { @@ -195,9 +189,8 @@ describe('Test stats (excluding redundancy)', function () { } }) - const resStats = await getStats(server.url) - const dataStats: ServerStats = resStats.body - expect(dataStats.totalLocalPlaylists).to.equal(1) + const data = await server.statsCommand.get() + expect(data.totalLocalPlaylists).to.equal(1) } }) @@ -231,14 +224,12 @@ describe('Test stats (excluding redundancy)', function () { await waitJobs(servers) { - const res = await getStats(servers[1].url) - const data: ServerStats = res.body + const data = await servers[1].statsCommand.get() expect(data.totalLocalVideoFilesSize).to.equal(0) } { - const res = await getStats(servers[0].url) - const data: ServerStats = res.body + const data = await servers[0].statsCommand.get() expect(data.totalLocalVideoFilesSize).to.be.greaterThan(500000) expect(data.totalLocalVideoFilesSize).to.be.lessThan(600000) } @@ -253,8 +244,7 @@ describe('Test stats (excluding redundancy)', function () { } }) - const res1 = await getStats(servers[1].url) - const first = res1.body as ServerStats + const first = await servers[1].statsCommand.get() for (let i = 0; i < 10; i++) { await uploadVideo(servers[0].url, servers[0].accessToken, { name: 'video' }) @@ -264,10 +254,9 @@ describe('Test stats (excluding redundancy)', function () { await wait(6000) - const res2 = await getStats(servers[1].url) - const second: ServerStats = res2.body - + const second = await servers[1].statsCommand.get() expect(second.totalActivityPubMessagesProcessed).to.be.greaterThan(first.totalActivityPubMessagesProcessed) + const apTypes: ActivityType[] = [ 'Create', 'Update', 'Delete', 'Follow', 'Accept', 'Announce', 'Undo', 'Like', 'Reject', 'View', 'Dislike', 'Flag' ] @@ -287,9 +276,7 @@ describe('Test stats (excluding redundancy)', function () { await wait(6000) - const res3 = await getStats(servers[1].url) - const third: ServerStats = res3.body - + const third = await servers[1].statsCommand.get() expect(third.totalActivityPubMessagesWaiting).to.equal(0) expect(third.activityPubMessagesProcessedPerSecond).to.be.lessThan(second.activityPubMessagesProcessedPerSecond) }) -- 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 ++++++------- server/tests/api/live/live-constraints.ts | 33 +++++---- server/tests/api/live/live-permanent.ts | 35 +++++---- server/tests/api/live/live-save-replay.ts | 21 +++--- server/tests/api/live/live-socket-messages.ts | 15 ++-- server/tests/api/live/live-views.ts | 15 ++-- server/tests/api/live/live.ts | 43 ++++++----- .../api/notifications/moderation-notifications.ts | 20 +++-- server/tests/api/search/search-index.ts | 55 ++++++++------ server/tests/api/search/search-videos.ts | 5 +- server/tests/api/server/auto-follows.ts | 9 +-- server/tests/api/server/config.ts | 48 ++++-------- server/tests/api/server/follows-moderation.ts | 9 +-- server/tests/api/server/homepage.ts | 5 +- server/tests/api/server/plugins.ts | 21 +++--- server/tests/api/server/stats.ts | 47 ++++++------ server/tests/api/users/users-verification.ts | 37 ++++++---- server/tests/api/users/users.ts | 9 +-- server/tests/api/videos/video-change-ownership.ts | 15 ++-- server/tests/api/videos/video-hls.ts | 41 ++++++----- server/tests/api/videos/video-imports.ts | 5 +- server/tests/api/videos/video-nsfw.ts | 25 ++----- server/tests/api/videos/video-transcoder.ts | 86 +++++++++++----------- 25 files changed, 381 insertions(+), 371 deletions(-) (limited to 'server/tests/api') 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 + } } } } diff --git a/server/tests/api/live/live-constraints.ts b/server/tests/api/live/live-constraints.ts index cc635de33..c64d10dcd 100644 --- a/server/tests/api/live/live-constraints.ts +++ b/server/tests/api/live/live-constraints.ts @@ -6,17 +6,16 @@ import { VideoDetails, VideoPrivacy } from '@shared/models' import { checkLiveCleanup, cleanupTests, + ConfigCommand, createLive, doubleFollow, flushAndRunMultipleServers, generateUser, - getCustomConfigResolutions, getVideo, runAndTestFfmpegStreamError, ServerInfo, setAccessTokensToServers, setDefaultVideoChannel, - updateCustomSubConfig, updateUser, wait, waitJobs, @@ -80,12 +79,14 @@ describe('Test live constraints', function () { await setAccessTokensToServers(servers) await setDefaultVideoChannel(servers) - await updateCustomSubConfig(servers[0].url, servers[0].accessToken, { - live: { - enabled: true, - allowReplay: true, - transcoding: { - enabled: false + await servers[0].configCommand.updateCustomSubConfig({ + newConfig: { + live: { + enabled: true, + allowReplay: true, + transcoding: { + enabled: false + } } } }) @@ -157,14 +158,16 @@ describe('Test live constraints', function () { it('Should have max duration limit', async function () { this.timeout(60000) - await updateCustomSubConfig(servers[0].url, servers[0].accessToken, { - live: { - enabled: true, - allowReplay: true, - maxDuration: 1, - transcoding: { + await servers[0].configCommand.updateCustomSubConfig({ + newConfig: { + live: { enabled: true, - resolutions: getCustomConfigResolutions(true) + allowReplay: true, + maxDuration: 1, + transcoding: { + enabled: true, + resolutions: ConfigCommand.getCustomConfigResolutions(true) + } } } }) diff --git a/server/tests/api/live/live-permanent.ts b/server/tests/api/live/live-permanent.ts index 71b7d28a8..b9e37c834 100644 --- a/server/tests/api/live/live-permanent.ts +++ b/server/tests/api/live/live-permanent.ts @@ -5,10 +5,10 @@ import * as chai from 'chai' import { LiveVideoCreate, VideoDetails, VideoPrivacy, VideoState } from '@shared/models' import { cleanupTests, + ConfigCommand, createLive, doubleFollow, flushAndRunMultipleServers, - getCustomConfigResolutions, getLive, getPlaylistsCount, getVideo, @@ -17,7 +17,6 @@ import { setAccessTokensToServers, setDefaultVideoChannel, stopFfmpeg, - updateCustomSubConfig, updateLive, wait, waitJobs, @@ -63,14 +62,16 @@ describe('Permanent live', function () { // Server 1 and server 2 follow each other await doubleFollow(servers[0], servers[1]) - await updateCustomSubConfig(servers[0].url, servers[0].accessToken, { - live: { - enabled: true, - allowReplay: true, - maxDuration: -1, - transcoding: { + await servers[0].configCommand.updateCustomSubConfig({ + newConfig: { + live: { enabled: true, - resolutions: getCustomConfigResolutions(true) + allowReplay: true, + maxDuration: -1, + transcoding: { + enabled: true, + resolutions: ConfigCommand.getCustomConfigResolutions(true) + } } } }) @@ -145,14 +146,16 @@ describe('Permanent live', function () { it('Should be able to stream again in the permanent live', async function () { this.timeout(20000) - await updateCustomSubConfig(servers[0].url, servers[0].accessToken, { - live: { - enabled: true, - allowReplay: true, - maxDuration: -1, - transcoding: { + await servers[0].configCommand.updateCustomSubConfig({ + newConfig: { + live: { enabled: true, - resolutions: getCustomConfigResolutions(false) + allowReplay: true, + maxDuration: -1, + transcoding: { + enabled: true, + resolutions: ConfigCommand.getCustomConfigResolutions(false) + } } } }) diff --git a/server/tests/api/live/live-save-replay.ts b/server/tests/api/live/live-save-replay.ts index 3d4736c8f..e74bc3e8d 100644 --- a/server/tests/api/live/live-save-replay.ts +++ b/server/tests/api/live/live-save-replay.ts @@ -9,10 +9,10 @@ import { addVideoToBlacklist, checkLiveCleanup, cleanupTests, + ConfigCommand, createLive, doubleFollow, flushAndRunMultipleServers, - getCustomConfigResolutions, getVideo, getVideosList, removeVideo, @@ -22,7 +22,6 @@ import { setDefaultVideoChannel, stopFfmpeg, testFfmpegStreamError, - updateCustomSubConfig, updateVideo, wait, waitJobs, @@ -102,14 +101,16 @@ describe('Save replay setting', function () { // Server 1 and server 2 follow each other await doubleFollow(servers[0], servers[1]) - await updateCustomSubConfig(servers[0].url, servers[0].accessToken, { - live: { - enabled: true, - allowReplay: true, - maxDuration: -1, - transcoding: { - enabled: false, - resolutions: getCustomConfigResolutions(true) + await servers[0].configCommand.updateCustomSubConfig({ + newConfig: { + live: { + enabled: true, + allowReplay: true, + maxDuration: -1, + transcoding: { + enabled: false, + resolutions: ConfigCommand.getCustomConfigResolutions(true) + } } } }) diff --git a/server/tests/api/live/live-socket-messages.ts b/server/tests/api/live/live-socket-messages.ts index e00909ade..0159d5199 100644 --- a/server/tests/api/live/live-socket-messages.ts +++ b/server/tests/api/live/live-socket-messages.ts @@ -15,7 +15,6 @@ import { setAccessTokensToServers, setDefaultVideoChannel, stopFfmpeg, - updateCustomSubConfig, viewVideo, wait, waitJobs, @@ -37,12 +36,14 @@ describe('Test live', function () { await setAccessTokensToServers(servers) await setDefaultVideoChannel(servers) - await updateCustomSubConfig(servers[0].url, servers[0].accessToken, { - live: { - enabled: true, - allowReplay: true, - transcoding: { - enabled: false + await servers[0].configCommand.updateCustomSubConfig({ + newConfig: { + live: { + enabled: true, + allowReplay: true, + transcoding: { + enabled: false + } } } }) diff --git a/server/tests/api/live/live-views.ts b/server/tests/api/live/live-views.ts index a44d21ffa..ca571c962 100644 --- a/server/tests/api/live/live-views.ts +++ b/server/tests/api/live/live-views.ts @@ -15,7 +15,6 @@ import { setAccessTokensToServers, setDefaultVideoChannel, stopFfmpeg, - updateCustomSubConfig, viewVideo, wait, waitJobs, @@ -36,12 +35,14 @@ describe('Test live', function () { await setAccessTokensToServers(servers) await setDefaultVideoChannel(servers) - await updateCustomSubConfig(servers[0].url, servers[0].accessToken, { - live: { - enabled: true, - allowReplay: true, - transcoding: { - enabled: false + await servers[0].configCommand.updateCustomSubConfig({ + newConfig: { + live: { + enabled: true, + allowReplay: true, + transcoding: { + enabled: false + } } } }) diff --git a/server/tests/api/live/live.ts b/server/tests/api/live/live.ts index 50397924e..2c3102994 100644 --- a/server/tests/api/live/live.ts +++ b/server/tests/api/live/live.ts @@ -34,7 +34,6 @@ import { stopFfmpeg, testFfmpegStreamError, testImage, - updateCustomSubConfig, updateLive, uploadVideoAndGetId, wait, @@ -59,12 +58,14 @@ describe('Test live', function () { await setAccessTokensToServers(servers) await setDefaultVideoChannel(servers) - await updateCustomSubConfig(servers[0].url, servers[0].accessToken, { - live: { - enabled: true, - allowReplay: true, - transcoding: { - enabled: false + await servers[0].configCommand.updateCustomSubConfig({ + newConfig: { + live: { + enabled: true, + allowReplay: true, + transcoding: { + enabled: false + } } } }) @@ -422,20 +423,22 @@ describe('Test live', function () { } function updateConf (resolutions: number[]) { - return updateCustomSubConfig(servers[0].url, servers[0].accessToken, { - live: { - enabled: true, - allowReplay: true, - maxDuration: -1, - transcoding: { + return servers[0].configCommand.updateCustomSubConfig({ + newConfig: { + live: { enabled: true, - resolutions: { - '240p': resolutions.includes(240), - '360p': resolutions.includes(360), - '480p': resolutions.includes(480), - '720p': resolutions.includes(720), - '1080p': resolutions.includes(1080), - '2160p': resolutions.includes(2160) + allowReplay: true, + maxDuration: -1, + transcoding: { + enabled: true, + resolutions: { + '240p': resolutions.includes(240), + '360p': resolutions.includes(360), + '480p': resolutions.includes(480), + '720p': resolutions.includes(720), + '1080p': resolutions.includes(1080), + '2160p': resolutions.includes(2160) + } } } } diff --git a/server/tests/api/notifications/moderation-notifications.ts b/server/tests/api/notifications/moderation-notifications.ts index 9a93ce401..3e66e7517 100644 --- a/server/tests/api/notifications/moderation-notifications.ts +++ b/server/tests/api/notifications/moderation-notifications.ts @@ -23,7 +23,6 @@ import { createUser, generateUserAccessToken, getAccount, - getCustomConfig, getVideoCommentThreads, getVideoIdFromUUID, immutableAssign, @@ -34,8 +33,6 @@ import { removeUserSubscription, removeVideoFromBlacklist, ServerInfo, - updateCustomConfig, - updateCustomSubConfig, uploadVideo, wait, waitJobs @@ -407,7 +404,7 @@ describe('Test moderation notifications', function () { } } } - await updateCustomSubConfig(servers[0].url, servers[0].accessToken, config) + await servers[0].configCommand.updateCustomSubConfig({ newConfig: config }) await servers[2].followsCommand.follow({ targets: [ servers[0].url ] }) @@ -421,7 +418,7 @@ describe('Test moderation notifications', function () { await checkAutoInstanceFollowing(immutableAssign(baseParams, userOverride), followerHost, followingHost, 'absence') config.followings.instance.autoFollowBack.enabled = false - await updateCustomSubConfig(servers[0].url, servers[0].accessToken, config) + await servers[0].configCommand.updateCustomSubConfig({ newConfig: config }) await servers[0].followsCommand.unfollow({ target: servers[2] }) await servers[2].followsCommand.unfollow({ target: servers[0] }) }) @@ -430,7 +427,7 @@ describe('Test moderation notifications', function () { this.timeout(30000) await servers[0].followsCommand.unfollow({ target: servers[1] }) - await updateCustomSubConfig(servers[0].url, servers[0].accessToken, config) + await servers[0].configCommand.updateCustomSubConfig({ newConfig: config }) await wait(5000) await waitJobs(servers) @@ -440,7 +437,7 @@ describe('Test moderation notifications', function () { await checkAutoInstanceFollowing(baseParams, followerHost, followingHost, 'presence') config.followings.instance.autoFollowIndex.enabled = false - await updateCustomSubConfig(servers[0].url, servers[0].accessToken, config) + await servers[0].configCommand.updateCustomSubConfig({ newConfig: config }) await servers[0].followsCommand.unfollow({ target: servers[1] }) }) }) @@ -476,8 +473,8 @@ describe('Test moderation notifications', function () { token: userAccessToken } - const resCustomConfig = await getCustomConfig(servers[0].url, servers[0].accessToken) - currentCustomConfig = resCustomConfig.body + currentCustomConfig = await servers[0].configCommand.getCustomConfig() + const autoBlacklistTestsCustomConfig = immutableAssign(currentCustomConfig, { autoBlacklist: { videos: { @@ -487,9 +484,10 @@ describe('Test moderation notifications', function () { } } }) + // enable transcoding otherwise own publish notification after transcoding not expected autoBlacklistTestsCustomConfig.transcoding.enabled = true - await updateCustomConfig(servers[0].url, servers[0].accessToken, autoBlacklistTestsCustomConfig) + await servers[0].configCommand.updateCustomConfig({ newCustomConfig: autoBlacklistTestsCustomConfig }) await addUserSubscription(servers[0].url, servers[0].accessToken, 'user_1_channel@localhost:' + servers[0].port) await addUserSubscription(servers[1].url, servers[1].accessToken, 'user_1_channel@localhost:' + servers[0].port) @@ -612,7 +610,7 @@ describe('Test moderation notifications', function () { }) after(async () => { - await updateCustomConfig(servers[0].url, servers[0].accessToken, currentCustomConfig) + await servers[0].configCommand.updateCustomConfig({ newCustomConfig: currentCustomConfig }) await removeUserSubscription(servers[0].url, servers[0].accessToken, 'user_1_channel@localhost:' + servers[0].port) await removeUserSubscription(servers[1].url, servers[1].accessToken, 'user_1_channel@localhost:' + servers[0].port) diff --git a/server/tests/api/search/search-index.ts b/server/tests/api/search/search-index.ts index b2c0857a7..e4c5f5796 100644 --- a/server/tests/api/search/search-index.ts +++ b/server/tests/api/search/search-index.ts @@ -9,7 +9,6 @@ import { SearchCommand, ServerInfo, setAccessTokensToServers, - updateCustomSubConfig, uploadVideo } from '@shared/extra-utils' import { VideoPlaylistPrivacy, VideoPlaylistType, VideosSearchQuery } from '@shared/models' @@ -39,12 +38,14 @@ describe('Test videos search', function () { it('Should make a local videos search by default', async function () { this.timeout(10000) - await updateCustomSubConfig(server.url, server.accessToken, { - search: { - searchIndex: { - enabled: true, - isDefaultSearch: false, - disableLocalSearch: false + await server.configCommand.updateCustomSubConfig({ + newConfig: { + search: { + searchIndex: { + enabled: true, + isDefaultSearch: false, + disableLocalSearch: false + } } } }) @@ -64,12 +65,14 @@ describe('Test videos search', function () { }) it('Should make an index videos search by default', async function () { - await updateCustomSubConfig(server.url, server.accessToken, { - search: { - searchIndex: { - enabled: true, - isDefaultSearch: true, - disableLocalSearch: false + await server.configCommand.updateCustomSubConfig({ + newConfig: { + search: { + searchIndex: { + enabled: true, + isDefaultSearch: true, + disableLocalSearch: false + } } } }) @@ -84,12 +87,14 @@ describe('Test videos search', function () { }) it('Should make an index videos search if local search is disabled', async function () { - await updateCustomSubConfig(server.url, server.accessToken, { - search: { - searchIndex: { - enabled: true, - isDefaultSearch: false, - disableLocalSearch: true + await server.configCommand.updateCustomSubConfig({ + newConfig: { + search: { + searchIndex: { + enabled: true, + isDefaultSearch: false, + disableLocalSearch: true + } } } }) @@ -216,7 +221,11 @@ describe('Test videos search', function () { let nsfwUUID: string { - await updateCustomSubConfig(server.url, server.accessToken, { instance: { defaultNSFWPolicy: 'display' } }) + await server.configCommand.updateCustomSubConfig({ + newConfig: { + instance: { defaultNSFWPolicy: 'display' } + } + }) const body = await command.searchVideos({ search: 'NSFW search index', sort: '-match' }) expect(body.data).to.have.length.greaterThan(0) @@ -228,7 +237,11 @@ describe('Test videos search', function () { } { - await updateCustomSubConfig(server.url, server.accessToken, { instance: { defaultNSFWPolicy: 'do_not_list' } }) + await server.configCommand.updateCustomSubConfig({ + newConfig: { + instance: { defaultNSFWPolicy: 'do_not_list' } + } + }) const body = await command.searchVideos({ search: 'NSFW search index', sort: '-match' }) diff --git a/server/tests/api/search/search-videos.ts b/server/tests/api/search/search-videos.ts index f0482c7e0..7dc89c447 100644 --- a/server/tests/api/search/search-videos.ts +++ b/server/tests/api/search/search-videos.ts @@ -14,7 +14,6 @@ import { setAccessTokensToServers, setDefaultVideoChannel, stopFfmpeg, - updateCustomSubConfig, uploadVideo, wait, waitUntilLivePublished @@ -486,13 +485,13 @@ describe('Test videos search', function () { this.timeout(30000) { - const options = { + const newConfig = { search: { searchIndex: { enabled: false } }, live: { enabled: true } } - await updateCustomSubConfig(server.url, server.accessToken, options) + await server.configCommand.updateCustomSubConfig({ newConfig }) } { diff --git a/server/tests/api/server/auto-follows.ts b/server/tests/api/server/auto-follows.ts index 02389b1e9..34c4f6882 100644 --- a/server/tests/api/server/auto-follows.ts +++ b/server/tests/api/server/auto-follows.ts @@ -8,7 +8,6 @@ import { MockInstancesIndex, ServerInfo, setAccessTokensToServers, - updateCustomSubConfig, wait, waitJobs } from '@shared/extra-utils' @@ -87,7 +86,7 @@ describe('Test auto follows', function () { } } } - await updateCustomSubConfig(servers[1].url, servers[1].accessToken, config) + await servers[1].configCommand.updateCustomSubConfig({ newConfig: config }) await server1Follows2(servers) @@ -112,7 +111,7 @@ describe('Test auto follows', function () { } } } - await updateCustomSubConfig(servers[1].url, servers[1].accessToken, config) + await servers[1].configCommand.updateCustomSubConfig({ newConfig: config }) await server1Follows2(servers) @@ -129,7 +128,7 @@ describe('Test auto follows', function () { config.followings.instance.autoFollowBack.enabled = false config.followers.instance.manualApproval = false - await updateCustomSubConfig(servers[1].url, servers[1].accessToken, config) + await servers[1].configCommand.updateCustomSubConfig({ newConfig: config }) }) }) @@ -166,7 +165,7 @@ describe('Test auto follows', function () { } } } - await updateCustomSubConfig(servers[0].url, servers[0].accessToken, config) + await servers[0].configCommand.updateCustomSubConfig({ newConfig: config }) await wait(5000) await waitJobs(servers) diff --git a/server/tests/api/server/config.ts b/server/tests/api/server/config.ts index 19bf9582c..037628c9d 100644 --- a/server/tests/api/server/config.ts +++ b/server/tests/api/server/config.ts @@ -2,15 +2,10 @@ import 'mocha' import * as chai from 'chai' -import { About } from '../../../../shared/models/server/about.model' -import { CustomConfig } from '../../../../shared/models/server/custom-config.model' +import { HttpStatusCode } from '@shared/core-utils' import { cleanupTests, - deleteCustomConfig, flushAndRunServer, - getAbout, - getConfig, - getCustomConfig, killallServers, makeGetRequest, parallelTests, @@ -18,11 +13,9 @@ import { reRunServer, ServerInfo, setAccessTokensToServers, - updateCustomConfig, uploadVideo -} from '../../../../shared/extra-utils' -import { ServerConfig } from '../../../../shared/models' -import { HttpStatusCode } from '../../../../shared/core-utils/miscs/http-error-codes' +} from '@shared/extra-utils' +import { CustomConfig } from '@shared/models' const expect = chai.expect @@ -213,7 +206,7 @@ function checkUpdatedConfig (data: CustomConfig) { } describe('Test config', function () { - let server = null + let server: ServerInfo = null before(async function () { this.timeout(30000) @@ -223,8 +216,7 @@ describe('Test config', function () { }) it('Should have a correct config on a server with registration enabled', async function () { - const res = await getConfig(server.url) - const data: ServerConfig = res.body + const data = await server.configCommand.getConfig() expect(data.signup.allowed).to.be.true }) @@ -238,15 +230,13 @@ describe('Test config', function () { registerUser(server.url, 'user3', 'super password') ]) - const res = await getConfig(server.url) - const data: ServerConfig = res.body + const data = await server.configCommand.getConfig() expect(data.signup.allowed).to.be.false }) it('Should have the correct video allowed extensions', async function () { - const res = await getConfig(server.url) - const data: ServerConfig = res.body + const data = await server.configCommand.getConfig() expect(data.video.file.extensions).to.have.lengthOf(3) expect(data.video.file.extensions).to.contain('.mp4') @@ -260,8 +250,7 @@ describe('Test config', function () { }) it('Should get the customized configuration', async function () { - const res = await getCustomConfig(server.url, server.accessToken) - const data = res.body as CustomConfig + const data = await server.configCommand.getCustomConfig() checkInitialConfig(server, data) }) @@ -438,19 +427,16 @@ describe('Test config', function () { } } } - await updateCustomConfig(server.url, server.accessToken, newCustomConfig) - - const res = await getCustomConfig(server.url, server.accessToken) - const data = res.body + await server.configCommand.updateCustomConfig({ newCustomConfig }) + const data = await server.configCommand.getCustomConfig() checkUpdatedConfig(data) }) it('Should have the correct updated video allowed extensions', async function () { this.timeout(10000) - const res = await getConfig(server.url) - const data: ServerConfig = res.body + const data = await server.configCommand.getConfig() expect(data.video.file.extensions).to.have.length.above(4) expect(data.video.file.extensions).to.contain('.mp4') @@ -474,15 +460,13 @@ describe('Test config', function () { await reRunServer(server) - const res = await getCustomConfig(server.url, server.accessToken) - const data = res.body + const data = await server.configCommand.getCustomConfig() checkUpdatedConfig(data) }) it('Should fetch the about information', async function () { - const res = await getAbout(server.url) - const data: About = res.body + const data = await server.configCommand.getAbout() expect(data.instance.name).to.equal('PeerTube updated') expect(data.instance.shortDescription).to.equal('my short description') @@ -504,11 +488,9 @@ describe('Test config', function () { it('Should remove the custom configuration', async function () { this.timeout(10000) - await deleteCustomConfig(server.url, server.accessToken) - - const res = await getCustomConfig(server.url, server.accessToken) - const data = res.body + await server.configCommand.deleteCustomConfig() + const data = await server.configCommand.getCustomConfig() checkInitialConfig(server, data) }) diff --git a/server/tests/api/server/follows-moderation.ts b/server/tests/api/server/follows-moderation.ts index 4853b647d..6d6eca9a8 100644 --- a/server/tests/api/server/follows-moderation.ts +++ b/server/tests/api/server/follows-moderation.ts @@ -8,7 +8,6 @@ import { FollowsCommand, ServerInfo, setAccessTokensToServers, - updateCustomSubConfig, waitJobs } from '@shared/extra-utils' @@ -94,7 +93,7 @@ describe('Test follows moderation', function () { } } - await updateCustomSubConfig(servers[1].url, servers[1].accessToken, subConfig) + await servers[1].configCommand.updateCustomSubConfig({ newConfig: subConfig }) await commands[0].follow({ targets: [ servers[1].url ] }) await waitJobs(servers) @@ -114,7 +113,7 @@ describe('Test follows moderation', function () { } } - await updateCustomSubConfig(servers[1].url, servers[1].accessToken, subConfig) + await servers[1].configCommand.updateCustomSubConfig({ newConfig: subConfig }) await commands[0].follow({ targets: [ servers[1].url ] }) await waitJobs(servers) @@ -137,8 +136,8 @@ describe('Test follows moderation', function () { } } - await updateCustomSubConfig(servers[1].url, servers[1].accessToken, subConfig) - await updateCustomSubConfig(servers[2].url, servers[2].accessToken, subConfig) + await servers[1].configCommand.updateCustomSubConfig({ newConfig: subConfig }) + await servers[2].configCommand.updateCustomSubConfig({ newConfig: subConfig }) await commands[0].follow({ targets: [ servers[1].url ] }) await waitJobs(servers) diff --git a/server/tests/api/server/homepage.ts b/server/tests/api/server/homepage.ts index 4a3ec0479..c08067f3c 100644 --- a/server/tests/api/server/homepage.ts +++ b/server/tests/api/server/homepage.ts @@ -3,12 +3,10 @@ import 'mocha' import * as chai from 'chai' import { HttpStatusCode } from '@shared/core-utils' -import { ServerConfig } from '@shared/models' import { cleanupTests, CustomPagesCommand, flushAndRunServer, - getConfig, killallServers, reRunServer, ServerInfo, @@ -18,9 +16,8 @@ import { const expect = chai.expect async function getHomepageState (server: ServerInfo) { - const res = await getConfig(server.url) + const config = await server.configCommand.getConfig() - const config = res.body as ServerConfig return config.homepage.enabled } diff --git a/server/tests/api/server/plugins.ts b/server/tests/api/server/plugins.ts index 1536997d5..528bbbe58 100644 --- a/server/tests/api/server/plugins.ts +++ b/server/tests/api/server/plugins.ts @@ -7,7 +7,6 @@ import { cleanupTests, closeAllSequelize, flushAndRunServer, - getConfig, getMyUserInformation, killallServers, PluginsCommand, @@ -16,12 +15,11 @@ import { setAccessTokensToServers, setPluginVersion, testHelloWorldRegisteredSettings, - updateCustomSubConfig, updateMyUser, wait, waitUntilLog } from '@shared/extra-utils' -import { PluginType, ServerConfig, User } from '@shared/models' +import { PluginType, User } from '@shared/models' const expect = chai.expect @@ -102,8 +100,7 @@ describe('Test plugins', function () { }) it('Should have the plugin loaded in the configuration', async function () { - const res = await getConfig(server.url) - const config: ServerConfig = res.body + const config = await server.configCommand.getConfig() const theme = config.theme.registered.find(r => r.name === 'background-red') expect(theme).to.not.be.undefined @@ -113,11 +110,13 @@ describe('Test plugins', function () { }) it('Should update the default theme in the configuration', async function () { - await updateCustomSubConfig(server.url, server.accessToken, { theme: { default: 'background-red' } }) - - const res = await getConfig(server.url) - const config: ServerConfig = res.body + await server.configCommand.updateCustomSubConfig({ + newConfig: { + theme: { default: 'background-red' } + } + }) + const config = await server.configCommand.getConfig() expect(config.theme.default).to.equal('background-red') }) @@ -302,9 +301,7 @@ describe('Test plugins', function () { }) it('Should have updated the configuration', async function () { - // get /config (default theme + registered themes + registered plugins) - const res = await getConfig(server.url) - const config: ServerConfig = res.body + const config = await server.configCommand.getConfig() expect(config.theme.default).to.equal('default') diff --git a/server/tests/api/server/stats.ts b/server/tests/api/server/stats.ts index 36114a297..f01188d67 100644 --- a/server/tests/api/server/stats.ts +++ b/server/tests/api/server/stats.ts @@ -12,7 +12,6 @@ import { flushAndRunMultipleServers, ServerInfo, setAccessTokensToServers, - updateCustomSubConfig, uploadVideo, userLogin, viewVideo, @@ -197,24 +196,26 @@ describe('Test stats (excluding redundancy)', function () { it('Should correctly count video file sizes if transcoding is enabled', async function () { this.timeout(60000) - await updateCustomSubConfig(servers[0].url, servers[0].accessToken, { - transcoding: { - enabled: true, - webtorrent: { - enabled: true - }, - hls: { - enabled: true - }, - resolutions: { - '0p': false, - '240p': false, - '360p': false, - '480p': false, - '720p': false, - '1080p': false, - '1440p': false, - '2160p': false + await servers[0].configCommand.updateCustomSubConfig({ + newConfig: { + transcoding: { + enabled: true, + webtorrent: { + enabled: true + }, + hls: { + enabled: true + }, + resolutions: { + '0p': false, + '240p': false, + '360p': false, + '480p': false, + '720p': false, + '1080p': false, + '1440p': false, + '2160p': false + } } } }) @@ -238,9 +239,11 @@ describe('Test stats (excluding redundancy)', function () { it('Should have the correct AP stats', async function () { this.timeout(60000) - await updateCustomSubConfig(servers[0].url, servers[0].accessToken, { - transcoding: { - enabled: false + await servers[0].configCommand.updateCustomSubConfig({ + newConfig: { + transcoding: { + enabled: false + } } }) diff --git a/server/tests/api/users/users-verification.ts b/server/tests/api/users/users-verification.ts index 265cd6050..23f81d804 100644 --- a/server/tests/api/users/users-verification.ts +++ b/server/tests/api/users/users-verification.ts @@ -11,7 +11,6 @@ import { login, registerUser, ServerInfo, - updateCustomSubConfig, updateMyUser, userLogin, verifyEmail @@ -58,11 +57,13 @@ describe('Test users account verification', function () { it('Should register user and send verification email if verification required', async function () { this.timeout(30000) - await updateCustomSubConfig(server.url, server.accessToken, { - signup: { - enabled: true, - requiresEmailVerification: true, - limit: 10 + await server.configCommand.updateCustomSubConfig({ + newConfig: { + signup: { + enabled: true, + requiresEmailVerification: true, + limit: 10 + } } }) @@ -148,11 +149,13 @@ describe('Test users account verification', function () { it('Should register user not requiring email verification if setting not enabled', async function () { this.timeout(5000) - await updateCustomSubConfig(server.url, server.accessToken, { - signup: { - enabled: true, - requiresEmailVerification: false, - limit: 10 + await server.configCommand.updateCustomSubConfig({ + newConfig: { + signup: { + enabled: true, + requiresEmailVerification: false, + limit: 10 + } } }) @@ -168,11 +171,13 @@ describe('Test users account verification', function () { }) it('Should allow login for user with unverified email when setting later enabled', async function () { - await updateCustomSubConfig(server.url, server.accessToken, { - signup: { - enabled: true, - requiresEmailVerification: true, - limit: 10 + await server.configCommand.updateCustomSubConfig({ + newConfig: { + signup: { + enabled: true, + requiresEmailVerification: true, + limit: 10 + } } }) diff --git a/server/tests/api/users/users.ts b/server/tests/api/users/users.ts index ba4183e08..33bcc8701 100644 --- a/server/tests/api/users/users.ts +++ b/server/tests/api/users/users.ts @@ -13,7 +13,6 @@ import { flushAndRunServer, getAccountRatings, getBlacklistedVideosList, - getCustomConfig, getMyUserInformation, getMyUserVideoQuotaUsed, getMyUserVideoRating, @@ -38,7 +37,6 @@ import { setTokenField, testImage, unblockUser, - updateCustomSubConfig, updateMyAvatar, updateMyUser, updateUser, @@ -46,7 +44,7 @@ import { userLogin, waitJobs } from '@shared/extra-utils' -import { AbuseState, CustomConfig, MyUser, OAuth2ErrorCode, User, UserAdminFlag, UserRole, Video, VideoPlaylistType } from '@shared/models' +import { AbuseState, MyUser, OAuth2ErrorCode, User, UserAdminFlag, UserRole, Video, VideoPlaylistType } from '@shared/models' const expect = chai.expect @@ -418,12 +416,11 @@ describe('Test users', function () { this.timeout(60000) { - const res = await getCustomConfig(server.url, server.accessToken) - const config = res.body as CustomConfig + const config = await server.configCommand.getCustomConfig() config.transcoding.webtorrent.enabled = false config.transcoding.hls.enabled = true config.transcoding.enabled = true - await updateCustomSubConfig(server.url, server.accessToken, config) + await server.configCommand.updateCustomSubConfig({ newConfig: config }) } { diff --git a/server/tests/api/videos/video-change-ownership.ts b/server/tests/api/videos/video-change-ownership.ts index a3384851b..89dba14b1 100644 --- a/server/tests/api/videos/video-change-ownership.ts +++ b/server/tests/api/videos/video-change-ownership.ts @@ -20,7 +20,6 @@ import { ServerInfo, setAccessTokensToServers, setDefaultVideoChannel, - updateCustomSubConfig, uploadVideo, userLogin } from '../../../../shared/extra-utils' @@ -58,12 +57,14 @@ describe('Test video change ownership - nominal', function () { await setAccessTokensToServers(servers) await setDefaultVideoChannel(servers) - await updateCustomSubConfig(servers[0].url, servers[0].accessToken, { - transcoding: { - enabled: false - }, - live: { - enabled: true + await servers[0].configCommand.updateCustomSubConfig({ + newConfig: { + transcoding: { + enabled: false + }, + live: { + enabled: true + } } }) diff --git a/server/tests/api/videos/video-hls.ts b/server/tests/api/videos/video-hls.ts index 03ac3f321..3821cfed0 100644 --- a/server/tests/api/videos/video-hls.ts +++ b/server/tests/api/videos/video-hls.ts @@ -3,6 +3,7 @@ import 'mocha' import * as chai from 'chai' import { join } from 'path' +import { HttpStatusCode } from '../../../../shared/core-utils/miscs/http-error-codes' import { checkDirectoryIsEmpty, checkResolutionsInMasterPlaylist, @@ -17,7 +18,6 @@ import { removeVideo, ServerInfo, setAccessTokensToServers, - updateCustomSubConfig, updateVideo, uploadVideo, waitJobs, @@ -26,7 +26,6 @@ import { import { VideoDetails } from '../../../../shared/models/videos' import { VideoStreamingPlaylistType } from '../../../../shared/models/videos/video-streaming-playlist.type' import { DEFAULT_AUDIO_RESOLUTION } from '../../../initializers/constants' -import { HttpStatusCode } from '../../../../shared/core-utils/miscs/http-error-codes' const expect = chai.expect @@ -192,24 +191,26 @@ describe('Test HLS videos', function () { describe('With only HLS enabled', function () { before(async function () { - await updateCustomSubConfig(servers[0].url, servers[0].accessToken, { - transcoding: { - enabled: true, - allowAudioFiles: true, - resolutions: { - '240p': true, - '360p': true, - '480p': true, - '720p': true, - '1080p': true, - '1440p': true, - '2160p': true - }, - hls: { - enabled: true - }, - webtorrent: { - enabled: false + await servers[0].configCommand.updateCustomSubConfig({ + newConfig: { + transcoding: { + enabled: true, + allowAudioFiles: true, + resolutions: { + '240p': true, + '360p': true, + '480p': true, + '720p': true, + '1080p': true, + '1440p': true, + '2160p': true + }, + hls: { + enabled: true + }, + webtorrent: { + enabled: false + } } } }) diff --git a/server/tests/api/videos/video-imports.ts b/server/tests/api/videos/video-imports.ts index 80834ca86..a4a9132b4 100644 --- a/server/tests/api/videos/video-imports.ts +++ b/server/tests/api/videos/video-imports.ts @@ -14,8 +14,7 @@ import { listVideoCaptions, ServerInfo, setAccessTokensToServers, - testCaptionFile, - updateCustomSubConfig + testCaptionFile } from '../../../../shared/extra-utils' import { areHttpImportTestsDisabled, testImage } from '../../../../shared/extra-utils/miscs/miscs' import { waitJobs } from '../../../../shared/extra-utils/server/jobs' @@ -333,7 +332,7 @@ Ajouter un sous-titre est vraiment facile`) } } } - await updateCustomSubConfig(servers[0].url, servers[0].accessToken, config) + await servers[0].configCommand.updateCustomSubConfig({ newConfig: config }) const attributes = { name: 'hdr video', diff --git a/server/tests/api/videos/video-nsfw.ts b/server/tests/api/videos/video-nsfw.ts index 24a4c6152..65813517d 100644 --- a/server/tests/api/videos/video-nsfw.ts +++ b/server/tests/api/videos/video-nsfw.ts @@ -7,8 +7,6 @@ import { createUser, flushAndRunServer, getAccountVideos, - getConfig, - getCustomConfig, getMyUserInformation, getMyVideos, getVideoChannelVideos, @@ -16,12 +14,11 @@ import { getVideosListWithToken, ServerInfo, setAccessTokensToServers, - updateCustomConfig, updateMyUser, uploadVideo, userLogin } from '@shared/extra-utils' -import { BooleanBothQuery, CustomConfig, ServerConfig, User, VideosOverview } from '@shared/models' +import { BooleanBothQuery, CustomConfig, User, VideosOverview } from '@shared/models' const expect = chai.expect @@ -97,16 +94,12 @@ describe('Test video NSFW policy', function () { await uploadVideo(server.url, server.accessToken, attributes) } - { - const res = await getCustomConfig(server.url, server.accessToken) - customConfig = res.body - } + customConfig = await server.configCommand.getCustomConfig() }) describe('Instance default NSFW policy', function () { it('Should display NSFW videos with display default NSFW policy', async function () { - const resConfig = await getConfig(server.url) - const serverConfig: ServerConfig = resConfig.body + const serverConfig = await server.configCommand.getConfig() expect(serverConfig.instance.defaultNSFWPolicy).to.equal('display') for (const res of await getVideosFunctions()) { @@ -121,10 +114,9 @@ describe('Test video NSFW policy', function () { it('Should not display NSFW videos with do_not_list default NSFW policy', async function () { customConfig.instance.defaultNSFWPolicy = 'do_not_list' - await updateCustomConfig(server.url, server.accessToken, customConfig) + await server.configCommand.updateCustomConfig({ newCustomConfig: customConfig }) - const resConfig = await getConfig(server.url) - const serverConfig: ServerConfig = resConfig.body + const serverConfig = await server.configCommand.getConfig() expect(serverConfig.instance.defaultNSFWPolicy).to.equal('do_not_list') for (const res of await getVideosFunctions()) { @@ -138,10 +130,9 @@ describe('Test video NSFW policy', function () { it('Should display NSFW videos with blur default NSFW policy', async function () { customConfig.instance.defaultNSFWPolicy = 'blur' - await updateCustomConfig(server.url, server.accessToken, customConfig) + await server.configCommand.updateCustomConfig({ newCustomConfig: customConfig }) - const resConfig = await getConfig(server.url) - const serverConfig: ServerConfig = resConfig.body + const serverConfig = await server.configCommand.getConfig() expect(serverConfig.instance.defaultNSFWPolicy).to.equal('blur') for (const res of await getVideosFunctions()) { @@ -172,7 +163,7 @@ describe('Test video NSFW policy', function () { it('Should display NSFW videos with blur user NSFW policy', async function () { customConfig.instance.defaultNSFWPolicy = 'do_not_list' - await updateCustomConfig(server.url, server.accessToken, customConfig) + await server.configCommand.updateCustomConfig({ newCustomConfig: customConfig }) for (const res of await getVideosFunctions(userAccessToken)) { expect(res.body.total).to.equal(2) diff --git a/server/tests/api/videos/video-transcoder.ts b/server/tests/api/videos/video-transcoder.ts index c95053a29..e74fb5bef 100644 --- a/server/tests/api/videos/video-transcoder.ts +++ b/server/tests/api/videos/video-transcoder.ts @@ -5,7 +5,6 @@ import * as chai from 'chai' import { FfprobeData } from 'fluent-ffmpeg' import { omit } from 'lodash' import { join } from 'path' -import { Job } from '@shared/models' import { VIDEO_TRANSCODING_FPS } from '../../../../server/initializers/constants' import { HttpStatusCode } from '../../../../shared/core-utils/miscs/http-error-codes' import { @@ -24,7 +23,6 @@ import { makeGetRequest, ServerInfo, setAccessTokensToServers, - updateCustomSubConfig, uploadVideo, uploadVideoAndGetId, waitJobs, @@ -43,22 +41,24 @@ import { const expect = chai.expect function updateConfigForTranscoding (server: ServerInfo) { - return updateCustomSubConfig(server.url, server.accessToken, { - transcoding: { - enabled: true, - allowAdditionalExtensions: true, - allowAudioFiles: true, - hls: { enabled: true }, - webtorrent: { enabled: true }, - resolutions: { - '0p': false, - '240p': true, - '360p': true, - '480p': true, - '720p': true, - '1080p': true, - '1440p': true, - '2160p': true + return server.configCommand.updateCustomSubConfig({ + newConfig: { + transcoding: { + enabled: true, + allowAdditionalExtensions: true, + allowAudioFiles: true, + hls: { enabled: true }, + webtorrent: { enabled: true }, + resolutions: { + '0p': false, + '240p': true, + '360p': true, + '480p': true, + '720p': true, + '1080p': true, + '1440p': true, + '2160p': true + } } } }) @@ -363,19 +363,21 @@ describe('Test video transcoding', function () { function runSuite (mode: 'legacy' | 'resumable') { before(async function () { - await updateCustomSubConfig(servers[1].url, servers[1].accessToken, { - transcoding: { - hls: { enabled: true }, - webtorrent: { enabled: true }, - resolutions: { - '0p': false, - '240p': false, - '360p': false, - '480p': false, - '720p': false, - '1080p': false, - '1440p': false, - '2160p': false + await servers[1].configCommand.updateCustomSubConfig({ + newConfig: { + transcoding: { + hls: { enabled: true }, + webtorrent: { enabled: true }, + resolutions: { + '0p': false, + '240p': false, + '360p': false, + '480p': false, + '720p': false, + '1080p': false, + '1440p': false, + '2160p': false + } } } }) @@ -434,14 +436,16 @@ describe('Test video transcoding', function () { it('Should upload an audio file and create an audio version only', async function () { this.timeout(60_000) - await updateCustomSubConfig(servers[1].url, servers[1].accessToken, { - transcoding: { - hls: { enabled: true }, - webtorrent: { enabled: true }, - resolutions: { - '0p': true, - '240p': false, - '360p': false + await servers[1].configCommand.updateCustomSubConfig({ + newConfig: { + transcoding: { + hls: { enabled: true }, + webtorrent: { enabled: true }, + resolutions: { + '0p': true, + '240p': false, + '360p': false + } } } }) @@ -601,7 +605,7 @@ describe('Test video transcoding', function () { it('Should not transcode to an higher bitrate than the original file', async function () { this.timeout(160_000) - const config = { + const newConfig = { transcoding: { enabled: true, resolutions: { @@ -617,7 +621,7 @@ describe('Test video transcoding', function () { hls: { enabled: true } } } - await updateCustomSubConfig(servers[1].url, servers[1].accessToken, config) + await servers[1].configCommand.updateCustomSubConfig({ newConfig }) const videoAttributes = { name: 'low bitrate', -- cgit v1.2.3 From 87e2635a50ac2decb1c330e55c2ff7b6d07a85de Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Wed, 7 Jul 2021 11:55:16 +0200 Subject: Introduce socket io command --- server/tests/api/live/live-socket-messages.ts | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) (limited to 'server/tests/api') diff --git a/server/tests/api/live/live-socket-messages.ts b/server/tests/api/live/live-socket-messages.ts index 0159d5199..20fec16a9 100644 --- a/server/tests/api/live/live-socket-messages.ts +++ b/server/tests/api/live/live-socket-messages.ts @@ -2,7 +2,6 @@ import 'mocha' import * as chai from 'chai' -import { getLiveNotificationSocket } from '@shared/extra-utils/socket/socket-io' import { VideoPrivacy, VideoState } from '@shared/models' import { cleanupTests, @@ -77,7 +76,7 @@ describe('Test live', function () { { const videoId = await getVideoIdFromUUID(servers[0].url, liveVideoUUID) - const localSocket = getLiveNotificationSocket(servers[0].url) + const localSocket = servers[0].socketIOCommand.getLiveNotificationSocket() localSocket.on('state-change', data => localStateChanges.push(data.state)) localSocket.emit('subscribe', { videoId }) } @@ -85,7 +84,7 @@ describe('Test live', function () { { const videoId = await getVideoIdFromUUID(servers[1].url, liveVideoUUID) - const remoteSocket = getLiveNotificationSocket(servers[1].url) + const remoteSocket = servers[1].socketIOCommand.getLiveNotificationSocket() remoteSocket.on('state-change', data => remoteStateChanges.push(data.state)) remoteSocket.emit('subscribe', { videoId }) } @@ -125,7 +124,7 @@ describe('Test live', function () { { const videoId = await getVideoIdFromUUID(servers[0].url, liveVideoUUID) - const localSocket = getLiveNotificationSocket(servers[0].url) + const localSocket = servers[0].socketIOCommand.getLiveNotificationSocket() localSocket.on('views-change', data => { localLastVideoViews = data.views }) localSocket.emit('subscribe', { videoId }) } @@ -133,7 +132,7 @@ describe('Test live', function () { { const videoId = await getVideoIdFromUUID(servers[1].url, liveVideoUUID) - const remoteSocket = getLiveNotificationSocket(servers[1].url) + const remoteSocket = servers[1].socketIOCommand.getLiveNotificationSocket() remoteSocket.on('views-change', data => { remoteLastVideoViews = data.views }) remoteSocket.emit('subscribe', { videoId }) } @@ -169,7 +168,7 @@ describe('Test live', function () { const videoId = await getVideoIdFromUUID(servers[0].url, liveVideoUUID) - const socket = getLiveNotificationSocket(servers[0].url) + const socket = servers[0].socketIOCommand.getLiveNotificationSocket() socket.on('state-change', data => stateChanges.push(data.state)) socket.emit('subscribe', { videoId }) -- 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/activitypub/refresher.ts | 20 ++++++----- server/tests/api/check-params/accounts.ts | 15 ++++---- server/tests/api/moderation/abuses.ts | 13 +++---- .../api/notifications/moderation-notifications.ts | 5 ++- server/tests/api/server/follows.ts | 40 +++++++++++----------- server/tests/api/users/users-multiple-servers.ts | 37 ++++++++++---------- server/tests/api/users/users.ts | 20 +++++------ 7 files changed, 73 insertions(+), 77 deletions(-) (limited to 'server/tests/api') diff --git a/server/tests/api/activitypub/refresher.ts b/server/tests/api/activitypub/refresher.ts index c717f1a30..0d5452ea4 100644 --- a/server/tests/api/activitypub/refresher.ts +++ b/server/tests/api/activitypub/refresher.ts @@ -1,8 +1,10 @@ /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */ import 'mocha' +import { HttpStatusCode } from '@shared/core-utils' import { - cleanupTests, closeAllSequelize, + cleanupTests, + closeAllSequelize, createVideoPlaylist, doubleFollow, flushAndRunMultipleServers, @@ -21,10 +23,8 @@ import { uploadVideoAndGetId, wait, waitJobs -} from '../../../../shared/extra-utils' -import { getAccount } from '../../../../shared/extra-utils/users/accounts' -import { VideoPlaylistPrivacy } from '../../../../shared/models/videos' -import { HttpStatusCode } from '../../../../shared/core-utils/miscs/http-error-codes' +} from '@shared/extra-utils' +import { VideoPlaylistPrivacy } from '@shared/models' describe('Test AP refresher', function () { let servers: ServerInfo[] = [] @@ -116,19 +116,21 @@ describe('Test AP refresher', function () { it('Should remove a deleted actor', async function () { this.timeout(60000) + const command = servers[0].accountsCommand + await wait(10000) // Change actor name so the remote server returns a 404 const to = 'http://localhost:' + servers[1].port + '/accounts/user2' await setActorField(servers[1].internalServerNumber, to, 'preferredUsername', 'toto') - await getAccount(servers[0].url, 'user1@localhost:' + servers[1].port) - await getAccount(servers[0].url, 'user2@localhost:' + servers[1].port) + await command.get({ accountName: 'user1@localhost:' + servers[1].port }) + await command.get({ accountName: 'user2@localhost:' + servers[1].port }) await waitJobs(servers) - await getAccount(servers[0].url, 'user1@localhost:' + servers[1].port, HttpStatusCode.OK_200) - await getAccount(servers[0].url, 'user2@localhost:' + servers[1].port, HttpStatusCode.NOT_FOUND_404) + await command.get({ accountName: 'user1@localhost:' + servers[1].port, expectedStatus: HttpStatusCode.OK_200 }) + await command.get({ accountName: 'user2@localhost:' + servers[1].port, expectedStatus: HttpStatusCode.NOT_FOUND_404 }) }) }) 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 }) }) }) diff --git a/server/tests/api/moderation/abuses.ts b/server/tests/api/moderation/abuses.ts index a9f5332ce..124833cf6 100644 --- a/server/tests/api/moderation/abuses.ts +++ b/server/tests/api/moderation/abuses.ts @@ -13,7 +13,6 @@ import { doubleFollow, flushAndRunMultipleServers, generateUserAccessToken, - getAccount, getVideoCommentThreads, getVideoIdFromUUID, getVideosList, @@ -606,10 +605,8 @@ describe('Test abuses', function () { describe('Account abuses', function () { - async function getAccountFromServer (url: string, name: string, server: ServerInfo) { - const res = await getAccount(url, name + '@' + server.host) - - return res.body as Account + function getAccountFromServer (server: ServerInfo, targetName: string, targetServer: ServerInfo) { + return server.accountsCommand.get({ accountName: targetName + '@' + targetServer.host }) } before(async function () { @@ -626,7 +623,7 @@ describe('Test abuses', function () { it('Should report abuse on an account', async function () { this.timeout(15000) - const account = await getAccountFromServer(servers[0].url, 'user_1', servers[0]) + const account = await getAccountFromServer(servers[0], 'user_1', servers[0]) const reason = 'it is a bad account' await commands[0].report({ accountId: account.id, reason }) @@ -664,7 +661,7 @@ describe('Test abuses', function () { it('Should report abuse on a remote account', async function () { this.timeout(10000) - const account = await getAccountFromServer(servers[0].url, 'user_2', servers[1]) + const account = await getAccountFromServer(servers[0], 'user_2', servers[1]) const reason = 'it is a really bad account' await commands[0].report({ accountId: account.id, reason }) @@ -718,7 +715,7 @@ describe('Test abuses', function () { it('Should keep the account abuse when deleting the account', async function () { this.timeout(10000) - const account = await getAccountFromServer(servers[1].url, 'user_2', servers[1]) + const account = await getAccountFromServer(servers[1], 'user_2', servers[1]) await removeUser(servers[1].url, account.userId, servers[1].accessToken) await waitJobs(servers) diff --git a/server/tests/api/notifications/moderation-notifications.ts b/server/tests/api/notifications/moderation-notifications.ts index 3e66e7517..e90640ad6 100644 --- a/server/tests/api/notifications/moderation-notifications.ts +++ b/server/tests/api/notifications/moderation-notifications.ts @@ -22,7 +22,6 @@ import { cleanupTests, createUser, generateUserAccessToken, - getAccount, getVideoCommentThreads, getVideoIdFromUUID, immutableAssign, @@ -157,8 +156,8 @@ describe('Test moderation notifications', function () { await waitJobs(servers) - const resAccount = await getAccount(servers[1].url, username + '@' + servers[0].host) - await servers[1].abusesCommand.report({ accountId: resAccount.body.id, reason: 'super reason' }) + const account = await servers[1].accountsCommand.get({ accountName: username + '@' + servers[0].host }) + await servers[1].abusesCommand.report({ accountId: account.id, reason: 'super reason' }) await waitJobs(servers) await checkNewAccountAbuseForModerators(baseParams, username, 'presence') diff --git a/server/tests/api/server/follows.ts b/server/tests/api/server/follows.ts index c8fcca02c..466932d63 100644 --- a/server/tests/api/server/follows.ts +++ b/server/tests/api/server/follows.ts @@ -242,16 +242,16 @@ describe('Test follows', function () { }) it('Should have the correct follows counts', async function () { - await expectAccountFollows(servers[0].url, 'peertube@localhost:' + servers[0].port, 0, 2) - await expectAccountFollows(servers[0].url, 'peertube@localhost:' + servers[1].port, 1, 0) - await expectAccountFollows(servers[0].url, 'peertube@localhost:' + servers[2].port, 1, 0) + await expectAccountFollows({ server: servers[0], handle: 'peertube@localhost:' + servers[0].port, followers: 0, following: 2 }) + await expectAccountFollows({ server: servers[0], handle: 'peertube@localhost:' + servers[1].port, followers: 1, following: 0 }) + await expectAccountFollows({ server: servers[0], handle: 'peertube@localhost:' + servers[2].port, followers: 1, following: 0 }) // Server 2 and 3 does not know server 1 follow another server (there was not a refresh) - await expectAccountFollows(servers[1].url, 'peertube@localhost:' + servers[0].port, 0, 1) - await expectAccountFollows(servers[1].url, 'peertube@localhost:' + servers[1].port, 1, 0) + await expectAccountFollows({ server: servers[1], handle: 'peertube@localhost:' + servers[0].port, followers: 0, following: 1 }) + await expectAccountFollows({ server: servers[1], handle: 'peertube@localhost:' + servers[1].port, followers: 1, following: 0 }) - await expectAccountFollows(servers[2].url, 'peertube@localhost:' + servers[0].port, 0, 1) - await expectAccountFollows(servers[2].url, 'peertube@localhost:' + servers[2].port, 1, 0) + await expectAccountFollows({ server: servers[2], handle: 'peertube@localhost:' + servers[0].port, followers: 0, following: 1 }) + await expectAccountFollows({ server: servers[2], handle: 'peertube@localhost:' + servers[2].port, followers: 1, following: 0 }) }) it('Should unfollow server 3 on server 1', async function () { @@ -283,14 +283,14 @@ describe('Test follows', function () { }) it('Should have the correct follows counts 2', async function () { - await expectAccountFollows(servers[0].url, 'peertube@localhost:' + servers[0].port, 0, 1) - await expectAccountFollows(servers[0].url, 'peertube@localhost:' + servers[1].port, 1, 0) + await expectAccountFollows({ server: servers[0], handle: 'peertube@localhost:' + servers[0].port, followers: 0, following: 1 }) + await expectAccountFollows({ server: servers[0], handle: 'peertube@localhost:' + servers[1].port, followers: 1, following: 0 }) - await expectAccountFollows(servers[1].url, 'peertube@localhost:' + servers[0].port, 0, 1) - await expectAccountFollows(servers[1].url, 'peertube@localhost:' + servers[1].port, 1, 0) + await expectAccountFollows({ server: servers[1], handle: 'peertube@localhost:' + servers[0].port, followers: 0, following: 1 }) + await expectAccountFollows({ server: servers[1], handle: 'peertube@localhost:' + servers[1].port, followers: 1, following: 0 }) - await expectAccountFollows(servers[2].url, 'peertube@localhost:' + servers[0].port, 0, 0) - await expectAccountFollows(servers[2].url, 'peertube@localhost:' + servers[2].port, 0, 0) + await expectAccountFollows({ server: servers[2], handle: 'peertube@localhost:' + servers[0].port, followers: 0, following: 0 }) + await expectAccountFollows({ server: servers[2], handle: 'peertube@localhost:' + servers[2].port, followers: 0, following: 0 }) }) it('Should upload a video on server 2 and 3 and propagate only the video of server 2', async function () { @@ -404,15 +404,15 @@ describe('Test follows', function () { }) it('Should have the correct follows counts 3', async function () { - await expectAccountFollows(servers[0].url, 'peertube@localhost:' + servers[0].port, 0, 2) - await expectAccountFollows(servers[0].url, 'peertube@localhost:' + servers[1].port, 1, 0) - await expectAccountFollows(servers[0].url, 'peertube@localhost:' + servers[2].port, 1, 0) + await expectAccountFollows({ server: servers[0], handle: 'peertube@localhost:' + servers[0].port, followers: 0, following: 2 }) + await expectAccountFollows({ server: servers[0], handle: 'peertube@localhost:' + servers[1].port, followers: 1, following: 0 }) + await expectAccountFollows({ server: servers[0], handle: 'peertube@localhost:' + servers[2].port, followers: 1, following: 0 }) - await expectAccountFollows(servers[1].url, 'peertube@localhost:' + servers[0].port, 0, 1) - await expectAccountFollows(servers[1].url, 'peertube@localhost:' + servers[1].port, 1, 0) + await expectAccountFollows({ server: servers[1], handle: 'peertube@localhost:' + servers[0].port, followers: 0, following: 1 }) + await expectAccountFollows({ server: servers[1], handle: 'peertube@localhost:' + servers[1].port, followers: 1, following: 0 }) - await expectAccountFollows(servers[2].url, 'peertube@localhost:' + servers[0].port, 0, 1) - await expectAccountFollows(servers[2].url, 'peertube@localhost:' + servers[2].port, 1, 0) + await expectAccountFollows({ server: servers[2], handle: 'peertube@localhost:' + servers[0].port, followers: 0, following: 1 }) + await expectAccountFollows({ server: servers[2], handle: 'peertube@localhost:' + servers[2].port, followers: 1, following: 0 }) }) it('Should have propagated videos', async function () { diff --git a/server/tests/api/users/users-multiple-servers.ts b/server/tests/api/users/users-multiple-servers.ts index f60c66e4b..03fbfabeb 100644 --- a/server/tests/api/users/users-multiple-servers.ts +++ b/server/tests/api/users/users-multiple-servers.ts @@ -1,9 +1,9 @@ /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */ -import * as chai from 'chai' import 'mocha' -import { Account } from '../../../../shared/models/actors' +import * as chai from 'chai' import { + checkActorFilesWereRemoved, checkTmpIsEmpty, checkVideoFilesWereRemoved, cleanupTests, @@ -11,17 +11,19 @@ import { doubleFollow, flushAndRunMultipleServers, getAccountVideos, + getMyUserInformation, getVideoChannelsList, removeUser, + ServerInfo, + setAccessTokensToServers, + testImage, + updateMyAvatar, updateMyUser, - userLogin -} from '../../../../shared/extra-utils' -import { getMyUserInformation, ServerInfo, testImage, updateMyAvatar, uploadVideo } from '../../../../shared/extra-utils/index' -import { checkActorFilesWereRemoved, getAccount, getAccountsList } from '../../../../shared/extra-utils/users/accounts' -import { setAccessTokensToServers } from '../../../../shared/extra-utils/users/login' -import { User } from '../../../../shared/models/users' -import { VideoChannel } from '../../../../shared/models/videos' -import { waitJobs } from '../../../../shared/extra-utils/server/jobs' + uploadVideo, + userLogin, + waitJobs +} from '@shared/extra-utils' +import { User, VideoChannel } from '@shared/models' const expect = chai.expect @@ -133,13 +135,12 @@ describe('Test users with multiple servers', function () { let createdAt: string | Date for (const server of servers) { - const resAccounts = await getAccountsList(server.url, '-createdAt') + const body = await server.accountsCommand.list({ sort: '-createdAt' }) - const resList = resAccounts.body.data.find(a => a.name === 'root' && a.host === 'localhost:' + servers[0].port) as Account + const resList = body.data.find(a => a.name === 'root' && a.host === 'localhost:' + servers[0].port) expect(resList).not.to.be.undefined - const resAccount = await getAccount(server.url, resList.name + '@' + resList.host) - const account = resAccount.body as Account + const account = await server.accountsCommand.get({ accountName: resList.name + '@' + resList.host }) if (!createdAt) createdAt = account.createdAt @@ -193,9 +194,9 @@ describe('Test users with multiple servers', function () { this.timeout(10_000) for (const server of servers) { - const resAccounts = await getAccountsList(server.url, '-createdAt') + const body = await server.accountsCommand.list({ sort: '-createdAt' }) - const accountDeleted = resAccounts.body.data.find(a => a.name === 'user1' && a.host === 'localhost:' + servers[0].port) as Account + const accountDeleted = body.data.find(a => a.name === 'user1' && a.host === 'localhost:' + servers[0].port) expect(accountDeleted).not.to.be.undefined const resVideoChannels = await getVideoChannelsList(server.url, 0, 10) @@ -210,9 +211,9 @@ describe('Test users with multiple servers', function () { await waitJobs(servers) for (const server of servers) { - const resAccounts = await getAccountsList(server.url, '-createdAt') + const body = await server.accountsCommand.list({ sort: '-createdAt' }) - const accountDeleted = resAccounts.body.data.find(a => a.name === 'user1' && a.host === 'localhost:' + servers[0].port) as Account + const accountDeleted = body.data.find(a => a.name === 'user1' && a.host === 'localhost:' + servers[0].port) expect(accountDeleted).to.be.undefined const resVideoChannels = await getVideoChannelsList(server.url, 0, 10) diff --git a/server/tests/api/users/users.ts b/server/tests/api/users/users.ts index 33bcc8701..3beea5d50 100644 --- a/server/tests/api/users/users.ts +++ b/server/tests/api/users/users.ts @@ -11,7 +11,6 @@ import { createUser, deleteMe, flushAndRunServer, - getAccountRatings, getBlacklistedVideosList, getMyUserInformation, getMyUserVideoQuotaUsed, @@ -194,25 +193,22 @@ describe('Test users', function () { it('Should retrieve ratings list', async function () { await rateVideo(server.url, accessToken, videoId, 'like') - const res = await getAccountRatings(server.url, server.user.username, server.accessToken, null, HttpStatusCode.OK_200) - const ratings = res.body + const body = await server.accountsCommand.listRatings({ accountName: server.user.username }) - expect(ratings.total).to.equal(1) - expect(ratings.data[0].video.id).to.equal(videoId) - expect(ratings.data[0].rating).to.equal('like') + expect(body.total).to.equal(1) + expect(body.data[0].video.id).to.equal(videoId) + expect(body.data[0].rating).to.equal('like') }) it('Should retrieve ratings list by rating type', async function () { { - const res = await getAccountRatings(server.url, server.user.username, server.accessToken, 'like') - const ratings = res.body - expect(ratings.data.length).to.equal(1) + const body = await server.accountsCommand.listRatings({ accountName: server.user.username, rating: 'like' }) + expect(body.data.length).to.equal(1) } { - const res = await getAccountRatings(server.url, server.user.username, server.accessToken, 'dislike') - const ratings = res.body - expect(ratings.data.length).to.equal(0) + const body = await server.accountsCommand.listRatings({ accountName: server.user.username, rating: 'dislike' }) + expect(body.data.length).to.equal(0) } }) }) -- cgit v1.2.3 From 5f8bd4cbb178290da7d8f81e996f19f0eccc8e4c Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Wed, 7 Jul 2021 16:02:46 +0200 Subject: Introduce blocklist command --- server/tests/api/moderation/abuses.ts | 14 ++- .../tests/api/moderation/blocklist-notification.ts | 41 ++++----- server/tests/api/moderation/blocklist.ts | 100 ++++++++------------- .../api/notifications/comments-notifications.ts | 10 +-- server/tests/api/videos/video-playlists.ts | 26 +++--- server/tests/api/videos/videos-overview.ts | 3 +- 6 files changed, 74 insertions(+), 120 deletions(-) (limited to 'server/tests/api') diff --git a/server/tests/api/moderation/abuses.ts b/server/tests/api/moderation/abuses.ts index 124833cf6..a2bd07b12 100644 --- a/server/tests/api/moderation/abuses.ts +++ b/server/tests/api/moderation/abuses.ts @@ -4,8 +4,6 @@ import 'mocha' import * as chai from 'chai' import { AbusesCommand, - addAccountToServerBlocklist, - addServerToServerBlocklist, addVideoCommentThread, cleanupTests, createUser, @@ -16,8 +14,6 @@ import { getVideoCommentThreads, getVideoIdFromUUID, getVideosList, - removeAccountFromServerBlocklist, - removeServerFromServerBlocklist, removeUser, removeVideo, ServerInfo, @@ -27,7 +23,7 @@ import { userLogin, waitJobs } from '@shared/extra-utils' -import { AbuseMessage, AbusePredefinedReasonsString, AbuseState, Account, AdminAbuse, UserAbuse, VideoComment } from '@shared/models' +import { AbuseMessage, AbusePredefinedReasonsString, AbuseState, AdminAbuse, UserAbuse, VideoComment } from '@shared/models' const expect = chai.expect @@ -225,7 +221,7 @@ describe('Test abuses', function () { const accountToBlock = 'root@' + servers[1].host { - await addAccountToServerBlocklist(servers[0].url, servers[0].accessToken, accountToBlock) + await servers[0].blocklistCommand.addToServerBlocklist({ account: accountToBlock }) const body = await commands[0].getAdminList() expect(body.total).to.equal(2) @@ -235,7 +231,7 @@ describe('Test abuses', function () { } { - await removeAccountFromServerBlocklist(servers[0].url, servers[0].accessToken, accountToBlock) + await servers[0].blocklistCommand.removeFromServerBlocklist({ account: accountToBlock }) const body = await commands[0].getAdminList() expect(body.total).to.equal(3) @@ -246,7 +242,7 @@ describe('Test abuses', function () { const serverToBlock = servers[1].host { - await addServerToServerBlocklist(servers[0].url, servers[0].accessToken, servers[1].host) + await servers[0].blocklistCommand.addToServerBlocklist({ server: serverToBlock }) const body = await commands[0].getAdminList() expect(body.total).to.equal(2) @@ -256,7 +252,7 @@ describe('Test abuses', function () { } { - await removeServerFromServerBlocklist(servers[0].url, servers[0].accessToken, serverToBlock) + await servers[0].blocklistCommand.removeFromServerBlocklist({ server: serverToBlock }) const body = await commands[0].getAdminList() expect(body.total).to.equal(3) diff --git a/server/tests/api/moderation/blocklist-notification.ts b/server/tests/api/moderation/blocklist-notification.ts index 4fb3c95f2..99da64a2d 100644 --- a/server/tests/api/moderation/blocklist-notification.ts +++ b/server/tests/api/moderation/blocklist-notification.ts @@ -2,30 +2,23 @@ import 'mocha' import * as chai from 'chai' -import { getUserNotifications, markAsReadAllNotifications } from '@shared/extra-utils/users/user-notifications' -import { addUserSubscription, removeUserSubscription } from '@shared/extra-utils/users/user-subscriptions' -import { UserNotification, UserNotificationType } from '@shared/models' import { + addUserSubscription, + addVideoCommentThread, cleanupTests, createUser, doubleFollow, flushAndRunMultipleServers, + getUserNotifications, + markAsReadAllNotifications, + removeUserSubscription, ServerInfo, + setAccessTokensToServers, uploadVideo, - userLogin -} from '../../../../shared/extra-utils/index' -import { waitJobs } from '../../../../shared/extra-utils/server/jobs' -import { - addAccountToAccountBlocklist, - addAccountToServerBlocklist, - addServerToAccountBlocklist, - addServerToServerBlocklist, - removeAccountFromAccountBlocklist, - removeAccountFromServerBlocklist, - removeServerFromAccountBlocklist -} from '../../../../shared/extra-utils/users/blocklist' -import { setAccessTokensToServers } from '../../../../shared/extra-utils/users/login' -import { addVideoCommentThread } from '../../../../shared/extra-utils/videos/video-comments' + userLogin, + waitJobs +} from '@shared/extra-utils' +import { UserNotification, UserNotificationType } from '@shared/models' const expect = chai.expect @@ -134,7 +127,7 @@ describe('Test blocklist', function () { it('Should block an account', async function () { this.timeout(10000) - await addAccountToAccountBlocklist(servers[0].url, userToken1, 'user3@' + servers[1].host) + await servers[0].blocklistCommand.addToMyBlocklist({ token: userToken1, account: 'user3@' + servers[1].host }) await waitJobs(servers) }) @@ -147,7 +140,7 @@ describe('Test blocklist', function () { await checkNotifications(servers[0].url, userToken2, notifs) - await removeAccountFromAccountBlocklist(servers[0].url, userToken1, 'user3@' + servers[1].host) + await servers[0].blocklistCommand.removeFromMyBlocklist({ token: userToken1, account: 'user3@' + servers[1].host }) }) }) @@ -167,7 +160,7 @@ describe('Test blocklist', function () { it('Should block an account', async function () { this.timeout(10000) - await addServerToAccountBlocklist(servers[0].url, userToken1, servers[1].host) + await servers[0].blocklistCommand.addToMyBlocklist({ token: userToken1, server: servers[1].host }) await waitJobs(servers) }) @@ -180,7 +173,7 @@ describe('Test blocklist', function () { await checkNotifications(servers[0].url, userToken2, notifs) - await removeServerFromAccountBlocklist(servers[0].url, userToken1, servers[1].host) + await servers[0].blocklistCommand.removeFromMyBlocklist({ token: userToken1, server: servers[1].host }) }) }) @@ -207,7 +200,7 @@ describe('Test blocklist', function () { it('Should block an account', async function () { this.timeout(10000) - await addAccountToServerBlocklist(servers[0].url, servers[0].accessToken, 'user3@' + servers[1].host) + await servers[0].blocklistCommand.addToServerBlocklist({ account: 'user3@' + servers[1].host }) await waitJobs(servers) }) @@ -215,7 +208,7 @@ describe('Test blocklist', function () { await checkNotifications(servers[0].url, userToken1, []) await checkNotifications(servers[0].url, userToken2, []) - await removeAccountFromServerBlocklist(servers[0].url, servers[0].accessToken, 'user3@' + servers[1].host) + await servers[0].blocklistCommand.removeFromServerBlocklist({ account: 'user3@' + servers[1].host }) }) }) @@ -242,7 +235,7 @@ describe('Test blocklist', function () { it('Should block an account', async function () { this.timeout(10000) - await addServerToServerBlocklist(servers[0].url, servers[0].accessToken, servers[1].host) + await servers[0].blocklistCommand.addToServerBlocklist({ server: servers[1].host }) await waitJobs(servers) }) diff --git a/server/tests/api/moderation/blocklist.ts b/server/tests/api/moderation/blocklist.ts index 9ca6324c2..1b8860571 100644 --- a/server/tests/api/moderation/blocklist.ts +++ b/server/tests/api/moderation/blocklist.ts @@ -3,46 +3,27 @@ import 'mocha' import * as chai from 'chai' import { - addAccountToAccountBlocklist, - addAccountToServerBlocklist, - addServerToAccountBlocklist, - addServerToServerBlocklist, addVideoCommentReply, addVideoCommentThread, + BlocklistCommand, cleanupTests, createUser, deleteVideoComment, doubleFollow, findCommentId, flushAndRunMultipleServers, - getAccountBlocklistByAccount, - getAccountBlocklistByServer, - getServerBlocklistByAccount, - getServerBlocklistByServer, getUserNotifications, getVideoCommentThreads, getVideosList, getVideosListWithToken, getVideoThreadComments, - removeAccountFromAccountBlocklist, - removeAccountFromServerBlocklist, - removeServerFromAccountBlocklist, - removeServerFromServerBlocklist, ServerInfo, setAccessTokensToServers, uploadVideo, userLogin, waitJobs } from '@shared/extra-utils' -import { - AccountBlock, - ServerBlock, - UserNotification, - UserNotificationType, - Video, - VideoComment, - VideoCommentThreadTree -} from '@shared/models' +import { UserNotification, UserNotificationType, Video, VideoComment, VideoCommentThreadTree } from '@shared/models' const expect = chai.expect @@ -108,6 +89,8 @@ describe('Test blocklist', function () { let userModeratorToken: string let userToken2: string + let command: BlocklistCommand + before(async function () { this.timeout(120000) @@ -167,6 +150,8 @@ describe('Test blocklist', function () { } await waitJobs(servers) + + command = servers[0].blocklistCommand }) describe('User blocklist', function () { @@ -181,7 +166,7 @@ describe('Test blocklist', function () { }) it('Should block a remote account', async function () { - await addAccountToAccountBlocklist(servers[0].url, servers[0].accessToken, 'user2@localhost:' + servers[1].port) + await command.addToMyBlocklist({ account: 'user2@localhost:' + servers[1].port }) }) it('Should hide its videos', async function () { @@ -195,7 +180,7 @@ describe('Test blocklist', function () { }) it('Should block a local account', async function () { - await addAccountToAccountBlocklist(servers[0].url, servers[0].accessToken, 'user1') + await command.addToMyBlocklist({ account: 'user1' }) }) it('Should hide its videos', async function () { @@ -251,12 +236,10 @@ describe('Test blocklist', function () { it('Should list blocked accounts', async function () { { - const res = await getAccountBlocklistByAccount(servers[0].url, servers[0].accessToken, 0, 1, 'createdAt') - const blocks: AccountBlock[] = res.body.data + const body = await command.listMyAccountBlocklist({ start: 0, count: 1, sort: 'createdAt' }) + expect(body.total).to.equal(2) - expect(res.body.total).to.equal(2) - - const block = blocks[0] + const block = body.data[0] expect(block.byAccount.displayName).to.equal('root') expect(block.byAccount.name).to.equal('root') expect(block.blockedAccount.displayName).to.equal('user2') @@ -265,12 +248,10 @@ describe('Test blocklist', function () { } { - const res = await getAccountBlocklistByAccount(servers[0].url, servers[0].accessToken, 1, 2, 'createdAt') - const blocks: AccountBlock[] = res.body.data - - expect(res.body.total).to.equal(2) + const body = await command.listMyAccountBlocklist({ start: 1, count: 2, sort: 'createdAt' }) + expect(body.total).to.equal(2) - const block = blocks[0] + const block = body.data[0] expect(block.byAccount.displayName).to.equal('root') expect(block.byAccount.name).to.equal('root') expect(block.blockedAccount.displayName).to.equal('user1') @@ -335,7 +316,7 @@ describe('Test blocklist', function () { }) it('Should unblock the remote account', async function () { - await removeAccountFromAccountBlocklist(servers[0].url, servers[0].accessToken, 'user2@localhost:' + servers[1].port) + await command.removeFromMyBlocklist({ account: 'user2@localhost:' + servers[1].port }) }) it('Should display its videos', async function () { @@ -374,7 +355,7 @@ describe('Test blocklist', function () { }) it('Should unblock the local account', async function () { - await removeAccountFromAccountBlocklist(servers[0].url, servers[0].accessToken, 'user1') + await command.removeFromMyBlocklist({ account: 'user1' }) }) it('Should display its comments', function () { @@ -402,6 +383,7 @@ describe('Test blocklist', function () { }) describe('When managing server blocklist', function () { + it('Should list all videos', function () { return checkAllVideos(servers[0].url, servers[0].accessToken) }) @@ -411,7 +393,7 @@ describe('Test blocklist', function () { }) it('Should block a remote server', async function () { - await addServerToAccountBlocklist(servers[0].url, servers[0].accessToken, 'localhost:' + servers[1].port) + await command.addToMyBlocklist({ server: 'localhost:' + servers[1].port }) }) it('Should hide its videos', async function () { @@ -464,19 +446,17 @@ describe('Test blocklist', function () { }) it('Should list blocked servers', async function () { - const res = await getServerBlocklistByAccount(servers[0].url, servers[0].accessToken, 0, 1, 'createdAt') - const blocks: ServerBlock[] = res.body.data - - expect(res.body.total).to.equal(1) + const body = await command.listMyServerBlocklist({ start: 0, count: 1, sort: 'createdAt' }) + expect(body.total).to.equal(1) - const block = blocks[0] + const block = body.data[0] expect(block.byAccount.displayName).to.equal('root') expect(block.byAccount.name).to.equal('root') expect(block.blockedServer.host).to.equal('localhost:' + servers[1].port) }) it('Should unblock the remote server', async function () { - await removeServerFromAccountBlocklist(servers[0].url, servers[0].accessToken, 'localhost:' + servers[1].port) + await command.removeFromMyBlocklist({ server: 'localhost:' + servers[1].port }) }) it('Should display its videos', function () { @@ -524,7 +504,7 @@ describe('Test blocklist', function () { }) it('Should block a remote account', async function () { - await addAccountToServerBlocklist(servers[0].url, servers[0].accessToken, 'user2@localhost:' + servers[1].port) + await command.addToServerBlocklist({ account: 'user2@localhost:' + servers[1].port }) }) it('Should hide its videos', async function () { @@ -540,7 +520,7 @@ describe('Test blocklist', function () { }) it('Should block a local account', async function () { - await addAccountToServerBlocklist(servers[0].url, servers[0].accessToken, 'user1') + await command.addToServerBlocklist({ account: 'user1' }) }) it('Should hide its videos', async function () { @@ -598,12 +578,10 @@ describe('Test blocklist', function () { it('Should list blocked accounts', async function () { { - const res = await getAccountBlocklistByServer(servers[0].url, servers[0].accessToken, 0, 1, 'createdAt') - const blocks: AccountBlock[] = res.body.data - - expect(res.body.total).to.equal(2) + const body = await command.listServerAccountBlocklist({ start: 0, count: 1, sort: 'createdAt' }) + expect(body.total).to.equal(2) - const block = blocks[0] + const block = body.data[0] expect(block.byAccount.displayName).to.equal('peertube') expect(block.byAccount.name).to.equal('peertube') expect(block.blockedAccount.displayName).to.equal('user2') @@ -612,12 +590,10 @@ describe('Test blocklist', function () { } { - const res = await getAccountBlocklistByServer(servers[0].url, servers[0].accessToken, 1, 2, 'createdAt') - const blocks: AccountBlock[] = res.body.data + const body = await command.listServerAccountBlocklist({ start: 1, count: 2, sort: 'createdAt' }) + expect(body.total).to.equal(2) - expect(res.body.total).to.equal(2) - - const block = blocks[0] + const block = body.data[0] expect(block.byAccount.displayName).to.equal('peertube') expect(block.byAccount.name).to.equal('peertube') expect(block.blockedAccount.displayName).to.equal('user1') @@ -627,7 +603,7 @@ describe('Test blocklist', function () { }) it('Should unblock the remote account', async function () { - await removeAccountFromServerBlocklist(servers[0].url, servers[0].accessToken, 'user2@localhost:' + servers[1].port) + await command.removeFromServerBlocklist({ account: 'user2@localhost:' + servers[1].port }) }) it('Should display its videos', async function () { @@ -643,7 +619,7 @@ describe('Test blocklist', function () { }) it('Should unblock the local account', async function () { - await removeAccountFromServerBlocklist(servers[0].url, servers[0].accessToken, 'user1') + await command.removeFromServerBlocklist({ account: 'user1' }) }) it('Should display its comments', async function () { @@ -686,7 +662,7 @@ describe('Test blocklist', function () { }) it('Should block a remote server', async function () { - await addServerToServerBlocklist(servers[0].url, servers[0].accessToken, 'localhost:' + servers[1].port) + await command.addToServerBlocklist({ server: 'localhost:' + servers[1].port }) }) it('Should hide its videos', async function () { @@ -758,19 +734,17 @@ describe('Test blocklist', function () { }) it('Should list blocked servers', async function () { - const res = await getServerBlocklistByServer(servers[0].url, servers[0].accessToken, 0, 1, 'createdAt') - const blocks: ServerBlock[] = res.body.data - - expect(res.body.total).to.equal(1) + const body = await command.listServerServerBlocklist({ start: 0, count: 1, sort: 'createdAt' }) + expect(body.total).to.equal(1) - const block = blocks[0] + const block = body.data[0] expect(block.byAccount.displayName).to.equal('peertube') expect(block.byAccount.name).to.equal('peertube') expect(block.blockedServer.host).to.equal('localhost:' + servers[1].port) }) it('Should unblock the remote server', async function () { - await removeServerFromServerBlocklist(servers[0].url, servers[0].accessToken, 'localhost:' + servers[1].port) + await command.removeFromServerBlocklist({ server: 'localhost:' + servers[1].port }) }) it('Should list all videos', async function () { diff --git a/server/tests/api/notifications/comments-notifications.ts b/server/tests/api/notifications/comments-notifications.ts index d2badf237..13fcee843 100644 --- a/server/tests/api/notifications/comments-notifications.ts +++ b/server/tests/api/notifications/comments-notifications.ts @@ -3,7 +3,6 @@ import 'mocha' import * as chai from 'chai' import { - addAccountToAccountBlocklist, addVideoCommentReply, addVideoCommentThread, checkCommentMention, @@ -14,7 +13,6 @@ import { getVideoThreadComments, MockSmtpServer, prepareNotificationsTest, - removeAccountFromAccountBlocklist, ServerInfo, updateMyUser, uploadVideo, @@ -86,7 +84,7 @@ describe('Test comments notifications', function () { it('Should not send a new comment notification if the account is muted', async function () { this.timeout(20000) - await addAccountToAccountBlocklist(servers[0].url, userAccessToken, 'root') + await servers[0].blocklistCommand.addToMyBlocklist({ token: userAccessToken, account: 'root' }) const resVideo = await uploadVideo(servers[0].url, userAccessToken, { name: 'super video' }) const uuid = resVideo.body.video.uuid @@ -97,7 +95,7 @@ describe('Test comments notifications', function () { await waitJobs(servers) await checkNewCommentOnMyVideo(baseParams, uuid, commentId, commentId, 'absence') - await removeAccountFromAccountBlocklist(servers[0].url, userAccessToken, 'root') + await servers[0].blocklistCommand.removeFromMyBlocklist({ token: userAccessToken, account: 'root' }) }) it('Should send a new comment notification after a local comment on my video', async function () { @@ -244,7 +242,7 @@ describe('Test comments notifications', function () { it('Should not send a new mention notification if the account is muted', async function () { this.timeout(10000) - await addAccountToAccountBlocklist(servers[0].url, userAccessToken, 'root') + await servers[0].blocklistCommand.addToMyBlocklist({ token: userAccessToken, account: 'root' }) const resVideo = await uploadVideo(servers[0].url, servers[0].accessToken, { name: 'super video' }) const uuid = resVideo.body.video.uuid @@ -255,7 +253,7 @@ describe('Test comments notifications', function () { await waitJobs(servers) await checkCommentMention(baseParams, uuid, commentId, commentId, 'super root name', 'absence') - await removeAccountFromAccountBlocklist(servers[0].url, userAccessToken, 'root') + await servers[0].blocklistCommand.removeFromMyBlocklist({ token: userAccessToken, account: 'root' }) }) it('Should not send a new mention notification if the remote account mention a local account', async function () { diff --git a/server/tests/api/videos/video-playlists.ts b/server/tests/api/videos/video-playlists.ts index 28f68dcfe..90189721a 100644 --- a/server/tests/api/videos/video-playlists.ts +++ b/server/tests/api/videos/video-playlists.ts @@ -4,10 +4,6 @@ import 'mocha' import * as chai from 'chai' import { HttpStatusCode } from '@shared/core-utils' import { - addAccountToAccountBlocklist, - addAccountToServerBlocklist, - addServerToAccountBlocklist, - addServerToServerBlocklist, addVideoChannel, addVideoInPlaylist, addVideoToBlacklist, @@ -31,10 +27,6 @@ import { getVideoPlaylistPrivacies, getVideoPlaylistsList, getVideoPlaylistWithToken, - removeAccountFromAccountBlocklist, - removeAccountFromServerBlocklist, - removeServerFromAccountBlocklist, - removeServerFromServerBlocklist, removeUser, removeVideoFromBlacklist, removeVideoFromPlaylist, @@ -760,56 +752,58 @@ describe('Test video playlists', function () { it('Should update the element type if the account or server of the video is blocked', async function () { this.timeout(90000) + const command = servers[0].blocklistCommand + const name = 'video 90' const position = 2 { - await addAccountToAccountBlocklist(servers[0].url, userAccessTokenServer1, 'root@localhost:' + servers[1].port) + await command.addToMyBlocklist({ token: userAccessTokenServer1, account: 'root@localhost:' + servers[1].port }) await waitJobs(servers) await checkPlaylistElementType(groupUser1, playlistServer1UUID2, VideoPlaylistElementType.UNAVAILABLE, position, name, 3) await checkPlaylistElementType(group2, playlistServer1UUID2, VideoPlaylistElementType.REGULAR, position, name, 3) - await removeAccountFromAccountBlocklist(servers[0].url, userAccessTokenServer1, 'root@localhost:' + servers[1].port) + await command.removeFromMyBlocklist({ token: userAccessTokenServer1, account: 'root@localhost:' + servers[1].port }) await waitJobs(servers) await checkPlaylistElementType(group2, playlistServer1UUID2, VideoPlaylistElementType.REGULAR, position, name, 3) } { - await addServerToAccountBlocklist(servers[0].url, userAccessTokenServer1, 'localhost:' + servers[1].port) + await command.addToMyBlocklist({ token: userAccessTokenServer1, server: 'localhost:' + servers[1].port }) await waitJobs(servers) await checkPlaylistElementType(groupUser1, playlistServer1UUID2, VideoPlaylistElementType.UNAVAILABLE, position, name, 3) await checkPlaylistElementType(group2, playlistServer1UUID2, VideoPlaylistElementType.REGULAR, position, name, 3) - await removeServerFromAccountBlocklist(servers[0].url, userAccessTokenServer1, 'localhost:' + servers[1].port) + await command.removeFromMyBlocklist({ token: userAccessTokenServer1, server: 'localhost:' + servers[1].port }) await waitJobs(servers) await checkPlaylistElementType(group2, playlistServer1UUID2, VideoPlaylistElementType.REGULAR, position, name, 3) } { - await addAccountToServerBlocklist(servers[0].url, servers[0].accessToken, 'root@localhost:' + servers[1].port) + await command.addToServerBlocklist({ account: 'root@localhost:' + servers[1].port }) await waitJobs(servers) await checkPlaylistElementType(groupUser1, playlistServer1UUID2, VideoPlaylistElementType.UNAVAILABLE, position, name, 3) await checkPlaylistElementType(group2, playlistServer1UUID2, VideoPlaylistElementType.REGULAR, position, name, 3) - await removeAccountFromServerBlocklist(servers[0].url, servers[0].accessToken, 'root@localhost:' + servers[1].port) + await command.removeFromServerBlocklist({ account: 'root@localhost:' + servers[1].port }) await waitJobs(servers) await checkPlaylistElementType(group2, playlistServer1UUID2, VideoPlaylistElementType.REGULAR, position, name, 3) } { - await addServerToServerBlocklist(servers[0].url, servers[0].accessToken, 'localhost:' + servers[1].port) + await command.addToServerBlocklist({ server: 'localhost:' + servers[1].port }) await waitJobs(servers) await checkPlaylistElementType(groupUser1, playlistServer1UUID2, VideoPlaylistElementType.UNAVAILABLE, position, name, 3) await checkPlaylistElementType(group2, playlistServer1UUID2, VideoPlaylistElementType.REGULAR, position, name, 3) - await removeServerFromServerBlocklist(servers[0].url, servers[0].accessToken, 'localhost:' + servers[1].port) + await command.removeFromServerBlocklist({ server: 'localhost:' + servers[1].port }) await waitJobs(servers) await checkPlaylistElementType(group2, playlistServer1UUID2, VideoPlaylistElementType.REGULAR, position, name, 3) diff --git a/server/tests/api/videos/videos-overview.ts b/server/tests/api/videos/videos-overview.ts index b3ab9e070..ccbc6f4a4 100644 --- a/server/tests/api/videos/videos-overview.ts +++ b/server/tests/api/videos/videos-overview.ts @@ -3,7 +3,6 @@ import 'mocha' import * as chai from 'chai' import { - addAccountToAccountBlocklist, cleanupTests, flushAndRunServer, generateUserAccessToken, @@ -115,7 +114,7 @@ describe('Test a videos overview', function () { it('Should hide muted accounts', async function () { const token = await generateUserAccessToken(server, 'choco') - await addAccountToAccountBlocklist(server.url, token, 'root@' + server.host) + await server.blocklistCommand.addToMyBlocklist({ token, account: 'root@' + server.host }) { const body = await server.overviewsCommand.getVideos({ page: 1 }) -- cgit v1.2.3 From 2c27e70471120c92e0bc8c8114141fbb31ff98ac Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Wed, 7 Jul 2021 16:40:49 +0200 Subject: Introduce subscriptions command --- .../tests/api/moderation/blocklist-notification.ts | 10 +- .../api/notifications/moderation-notifications.ts | 10 +- .../tests/api/notifications/notifications-api.ts | 19 +-- .../tests/api/notifications/user-notifications.ts | 42 +++--- server/tests/api/users/user-subscriptions.ts | 144 +++++++++------------ 5 files changed, 99 insertions(+), 126 deletions(-) (limited to 'server/tests/api') diff --git a/server/tests/api/moderation/blocklist-notification.ts b/server/tests/api/moderation/blocklist-notification.ts index 99da64a2d..5b9699816 100644 --- a/server/tests/api/moderation/blocklist-notification.ts +++ b/server/tests/api/moderation/blocklist-notification.ts @@ -3,7 +3,6 @@ import 'mocha' import * as chai from 'chai' import { - addUserSubscription, addVideoCommentThread, cleanupTests, createUser, @@ -11,7 +10,6 @@ import { flushAndRunMultipleServers, getUserNotifications, markAsReadAllNotifications, - removeUserSubscription, ServerInfo, setAccessTokensToServers, uploadVideo, @@ -44,8 +42,8 @@ describe('Test blocklist', function () { async function resetState () { try { - await removeUserSubscription(servers[1].url, remoteUserToken, 'user1_channel@' + servers[0].host) - await removeUserSubscription(servers[1].url, remoteUserToken, 'user2_channel@' + servers[0].host) + await servers[1].subscriptionsCommand.remove({ token: remoteUserToken, uri: 'user1_channel@' + servers[0].host }) + await servers[1].subscriptionsCommand.remove({ token: remoteUserToken, uri: 'user2_channel@' + servers[0].host }) } catch {} await waitJobs(servers) @@ -66,8 +64,8 @@ describe('Test blocklist', function () { { - await addUserSubscription(servers[1].url, remoteUserToken, 'user1_channel@' + servers[0].host) - await addUserSubscription(servers[1].url, remoteUserToken, 'user2_channel@' + servers[0].host) + await servers[1].subscriptionsCommand.add({ token: remoteUserToken, targetUri: 'user1_channel@' + servers[0].host }) + await servers[1].subscriptionsCommand.add({ token: remoteUserToken, targetUri: 'user2_channel@' + servers[0].host }) } await waitJobs(servers) diff --git a/server/tests/api/notifications/moderation-notifications.ts b/server/tests/api/notifications/moderation-notifications.ts index e90640ad6..605b41947 100644 --- a/server/tests/api/notifications/moderation-notifications.ts +++ b/server/tests/api/notifications/moderation-notifications.ts @@ -3,7 +3,6 @@ import 'mocha' import { buildUUID } from '@server/helpers/uuid' import { - addUserSubscription, addVideoCommentThread, addVideoToBlacklist, checkAbuseStateChange, @@ -29,7 +28,6 @@ import { MockSmtpServer, prepareNotificationsTest, registerUser, - removeUserSubscription, removeVideoFromBlacklist, ServerInfo, uploadVideo, @@ -488,8 +486,8 @@ describe('Test moderation notifications', function () { autoBlacklistTestsCustomConfig.transcoding.enabled = true await servers[0].configCommand.updateCustomConfig({ newCustomConfig: autoBlacklistTestsCustomConfig }) - await addUserSubscription(servers[0].url, servers[0].accessToken, 'user_1_channel@localhost:' + servers[0].port) - await addUserSubscription(servers[1].url, servers[1].accessToken, 'user_1_channel@localhost:' + servers[0].port) + await servers[0].subscriptionsCommand.add({ targetUri: 'user_1_channel@localhost:' + servers[0].port }) + await servers[1].subscriptionsCommand.add({ targetUri: 'user_1_channel@localhost:' + servers[0].port }) }) @@ -611,8 +609,8 @@ describe('Test moderation notifications', function () { after(async () => { await servers[0].configCommand.updateCustomConfig({ newCustomConfig: currentCustomConfig }) - await removeUserSubscription(servers[0].url, servers[0].accessToken, 'user_1_channel@localhost:' + servers[0].port) - await removeUserSubscription(servers[1].url, servers[1].accessToken, 'user_1_channel@localhost:' + servers[0].port) + await servers[0].subscriptionsCommand.remove({ uri: 'user_1_channel@localhost:' + servers[0].port }) + await servers[1].subscriptionsCommand.remove({ uri: 'user_1_channel@localhost:' + servers[0].port }) }) }) diff --git a/server/tests/api/notifications/notifications-api.ts b/server/tests/api/notifications/notifications-api.ts index 19f9dbbab..1ed98ae7a 100644 --- a/server/tests/api/notifications/notifications-api.ts +++ b/server/tests/api/notifications/notifications-api.ts @@ -2,21 +2,24 @@ import 'mocha' import * as chai from 'chai' -import { addUserSubscription } from '@shared/extra-utils/users/user-subscriptions' -import { cleanupTests, getMyUserInformation, immutableAssign, uploadRandomVideo, waitJobs } from '../../../../shared/extra-utils' -import { ServerInfo } from '../../../../shared/extra-utils/index' -import { MockSmtpServer } from '../../../../shared/extra-utils/mock-servers/mock-email' import { CheckerBaseParams, checkNewVideoFromSubscription, + cleanupTests, getAllNotificationsSettings, + getMyUserInformation, getUserNotifications, + immutableAssign, markAsReadAllNotifications, markAsReadNotifications, + MockSmtpServer, prepareNotificationsTest, - updateMyNotificationSettings -} from '../../../../shared/extra-utils/users/user-notifications' -import { User, UserNotification, UserNotificationSettingValue } from '../../../../shared/models/users' + ServerInfo, + updateMyNotificationSettings, + uploadRandomVideo, + waitJobs +} from '@shared/extra-utils' +import { User, UserNotification, UserNotificationSettingValue } from '@shared/models' const expect = chai.expect @@ -35,7 +38,7 @@ describe('Test notifications API', function () { userNotifications = res.userNotifications server = res.servers[0] - await addUserSubscription(server.url, userAccessToken, 'root_channel@localhost:' + server.port) + await server.subscriptionsCommand.add({ token: userAccessToken, targetUri: 'root_channel@localhost:' + server.port }) for (let i = 0; i < 10; i++) { await uploadRandomVideo(server, false) diff --git a/server/tests/api/notifications/user-notifications.ts b/server/tests/api/notifications/user-notifications.ts index ace7e48c7..15be983f2 100644 --- a/server/tests/api/notifications/user-notifications.ts +++ b/server/tests/api/notifications/user-notifications.ts @@ -3,30 +3,26 @@ import 'mocha' import * as chai from 'chai' import { buildUUID } from '@server/helpers/uuid' -import { - cleanupTests, - updateMyUser, - updateVideo, - updateVideoChannel, - uploadRandomVideoOnServers, - wait -} from '../../../../shared/extra-utils' -import { ServerInfo } from '../../../../shared/extra-utils/index' -import { MockSmtpServer } from '../../../../shared/extra-utils/mock-servers/mock-email' -import { waitJobs } from '../../../../shared/extra-utils/server/jobs' import { CheckerBaseParams, checkMyVideoImportIsFinished, checkNewActorFollow, checkNewVideoFromSubscription, checkVideoIsPublished, + cleanupTests, getLastNotification, - prepareNotificationsTest -} from '../../../../shared/extra-utils/users/user-notifications' -import { addUserSubscription, removeUserSubscription } from '../../../../shared/extra-utils/users/user-subscriptions' -import { getBadVideoUrl, getGoodVideoUrl, importVideo } from '../../../../shared/extra-utils/videos/video-imports' -import { UserNotification, UserNotificationType } from '../../../../shared/models/users' -import { VideoPrivacy } from '../../../../shared/models/videos' + MockSmtpServer, + prepareNotificationsTest, + ServerInfo, + updateMyUser, + updateVideo, + updateVideoChannel, + uploadRandomVideoOnServers, + wait, + waitJobs +} from '@shared/extra-utils' +import { getBadVideoUrl, getGoodVideoUrl, importVideo } from '@shared/extra-utils/videos/video-imports' +import { UserNotification, UserNotificationType, VideoPrivacy } from '@shared/models' const expect = chai.expect @@ -79,7 +75,7 @@ describe('Test user notifications', function () { it('Should send a new video notification if the user follows the local video publisher', async function () { this.timeout(15000) - await addUserSubscription(servers[0].url, userAccessToken, 'root_channel@localhost:' + servers[0].port) + await servers[0].subscriptionsCommand.add({ token: userAccessToken, targetUri: 'root_channel@localhost:' + servers[0].port }) await waitJobs(servers) const { name, uuid } = await uploadRandomVideoOnServers(servers, 1) @@ -89,7 +85,7 @@ describe('Test user notifications', function () { it('Should send a new video notification from a remote account', async function () { this.timeout(150000) // Server 2 has transcoding enabled - await addUserSubscription(servers[0].url, userAccessToken, 'root_channel@localhost:' + servers[1].port) + await servers[0].subscriptionsCommand.add({ token: userAccessToken, targetUri: 'root_channel@localhost:' + servers[1].port }) await waitJobs(servers) const { name, uuid } = await uploadRandomVideoOnServers(servers, 2) @@ -418,23 +414,23 @@ describe('Test user notifications', function () { it('Should notify when a local channel is following one of our channel', async function () { this.timeout(50000) - await addUserSubscription(servers[0].url, servers[0].accessToken, 'user_1_channel@localhost:' + servers[0].port) + await servers[0].subscriptionsCommand.add({ targetUri: 'user_1_channel@localhost:' + servers[0].port }) await waitJobs(servers) await checkNewActorFollow(baseParams, 'channel', 'root', 'super root name', myChannelName, 'presence') - await removeUserSubscription(servers[0].url, servers[0].accessToken, 'user_1_channel@localhost:' + servers[0].port) + await servers[0].subscriptionsCommand.remove({ uri: 'user_1_channel@localhost:' + servers[0].port }) }) it('Should notify when a remote channel is following one of our channel', async function () { this.timeout(50000) - await addUserSubscription(servers[1].url, servers[1].accessToken, 'user_1_channel@localhost:' + servers[0].port) + await servers[1].subscriptionsCommand.add({ targetUri: 'user_1_channel@localhost:' + servers[0].port }) await waitJobs(servers) await checkNewActorFollow(baseParams, 'channel', 'root', 'super root 2 name', myChannelName, 'presence') - await removeUserSubscription(servers[1].url, servers[1].accessToken, 'user_1_channel@localhost:' + servers[0].port) + await servers[1].subscriptionsCommand.remove({ uri: 'user_1_channel@localhost:' + servers[0].port }) }) // PeerTube does not support accout -> account follows diff --git a/server/tests/api/users/user-subscriptions.ts b/server/tests/api/users/user-subscriptions.ts index 7e365d797..c119622ad 100644 --- a/server/tests/api/users/user-subscriptions.ts +++ b/server/tests/api/users/user-subscriptions.ts @@ -3,25 +3,19 @@ import 'mocha' import * as chai from 'chai' import { - addUserSubscription, - areSubscriptionsExist, cleanupTests, createUser, doubleFollow, flushAndRunMultipleServers, - getUserSubscription, getVideosList, - listUserSubscriptions, - listUserSubscriptionVideos, - removeUserSubscription, ServerInfo, setAccessTokensToServers, + SubscriptionsCommand, updateVideo, uploadVideo, userLogin, waitJobs } from '@shared/extra-utils' -import { Video, VideoChannel } from '@shared/models' const expect = chai.expect @@ -30,6 +24,8 @@ describe('Test users subscriptions', function () { const users: { accessToken: string }[] = [] let video3UUID: string + let command: SubscriptionsCommand + before(async function () { this.timeout(120000) @@ -58,6 +54,8 @@ describe('Test users subscriptions', function () { } await waitJobs(servers) + + command = servers[0].subscriptionsCommand }) it('Should display videos of server 2 on server 1', async function () { @@ -69,8 +67,8 @@ describe('Test users subscriptions', function () { it('User of server 1 should follow user of server 3 and root of server 1', async function () { this.timeout(60000) - await addUserSubscription(servers[0].url, users[0].accessToken, 'user3_channel@localhost:' + servers[2].port) - await addUserSubscription(servers[0].url, users[0].accessToken, 'root_channel@localhost:' + servers[0].port) + await command.add({ token: users[0].accessToken, targetUri: 'user3_channel@localhost:' + servers[2].port }) + await command.add({ token: users[0].accessToken, targetUri: 'root_channel@localhost:' + servers[0].port }) await waitJobs(servers) @@ -93,17 +91,17 @@ describe('Test users subscriptions', function () { it('Should list subscriptions', async function () { { - const res = await listUserSubscriptions({ url: servers[0].url, token: servers[0].accessToken }) - expect(res.body.total).to.equal(0) - expect(res.body.data).to.be.an('array') - expect(res.body.data).to.have.lengthOf(0) + const body = await command.list() + expect(body.total).to.equal(0) + expect(body.data).to.be.an('array') + expect(body.data).to.have.lengthOf(0) } { - const res = await listUserSubscriptions({ url: servers[0].url, token: users[0].accessToken, sort: 'createdAt' }) - expect(res.body.total).to.equal(2) + const body = await command.list({ token: users[0].accessToken, sort: 'createdAt' }) + expect(body.total).to.equal(2) - const subscriptions: VideoChannel[] = res.body.data + const subscriptions = body.data expect(subscriptions).to.be.an('array') expect(subscriptions).to.have.lengthOf(2) @@ -114,8 +112,7 @@ describe('Test users subscriptions', function () { it('Should get subscription', async function () { { - const res = await getUserSubscription(servers[0].url, users[0].accessToken, 'user3_channel@localhost:' + servers[2].port) - const videoChannel: VideoChannel = res.body + const videoChannel = await command.get({ token: users[0].accessToken, uri: 'user3_channel@localhost:' + servers[2].port }) expect(videoChannel.name).to.equal('user3_channel') expect(videoChannel.host).to.equal('localhost:' + servers[2].port) @@ -125,8 +122,7 @@ describe('Test users subscriptions', function () { } { - const res = await getUserSubscription(servers[0].url, users[0].accessToken, 'root_channel@localhost:' + servers[0].port) - const videoChannel: VideoChannel = res.body + const videoChannel = await command.get({ token: users[0].accessToken, uri: 'root_channel@localhost:' + servers[0].port }) expect(videoChannel.name).to.equal('root_channel') expect(videoChannel.host).to.equal('localhost:' + servers[0].port) @@ -144,8 +140,7 @@ describe('Test users subscriptions', function () { 'user3_channel@localhost:' + servers[0].port ] - const res = await areSubscriptionsExist(servers[0].url, users[0].accessToken, uris) - const body = res.body + const body = await command.exist({ token: users[0].accessToken, uris }) expect(body['user3_channel@localhost:' + servers[2].port]).to.be.true expect(body['root2_channel@localhost:' + servers[0].port]).to.be.false @@ -155,45 +150,31 @@ describe('Test users subscriptions', function () { it('Should search among subscriptions', async function () { { - const res = await listUserSubscriptions({ - url: servers[0].url, - token: users[0].accessToken, - sort: '-createdAt', - search: 'user3_channel' - }) - expect(res.body.total).to.equal(1) - - const subscriptions = res.body.data - expect(subscriptions).to.have.lengthOf(1) + const body = await command.list({ token: users[0].accessToken, sort: '-createdAt', search: 'user3_channel' }) + expect(body.total).to.equal(1) + expect(body.data).to.have.lengthOf(1) } { - const res = await listUserSubscriptions({ - url: servers[0].url, - token: users[0].accessToken, - sort: '-createdAt', - search: 'toto' - }) - expect(res.body.total).to.equal(0) - - const subscriptions = res.body.data - expect(subscriptions).to.have.lengthOf(0) + const body = await command.list({ token: users[0].accessToken, sort: '-createdAt', search: 'toto' }) + expect(body.total).to.equal(0) + expect(body.data).to.have.lengthOf(0) } }) it('Should list subscription videos', async function () { { - const res = await listUserSubscriptionVideos(servers[0].url, servers[0].accessToken) - expect(res.body.total).to.equal(0) - expect(res.body.data).to.be.an('array') - expect(res.body.data).to.have.lengthOf(0) + const body = await command.listVideos() + expect(body.total).to.equal(0) + expect(body.data).to.be.an('array') + expect(body.data).to.have.lengthOf(0) } { - const res = await listUserSubscriptionVideos(servers[0].url, users[0].accessToken, 'createdAt') - expect(res.body.total).to.equal(3) + const body = await command.listVideos({ token: users[0].accessToken, sort: 'createdAt' }) + expect(body.total).to.equal(3) - const videos: Video[] = res.body.data + const videos = body.data expect(videos).to.be.an('array') expect(videos).to.have.lengthOf(3) @@ -212,17 +193,17 @@ describe('Test users subscriptions', function () { await waitJobs(servers) { - const res = await listUserSubscriptionVideos(servers[0].url, servers[0].accessToken) - expect(res.body.total).to.equal(0) - expect(res.body.data).to.be.an('array') - expect(res.body.data).to.have.lengthOf(0) + const body = await command.listVideos() + expect(body.total).to.equal(0) + expect(body.data).to.be.an('array') + expect(body.data).to.have.lengthOf(0) } { - const res = await listUserSubscriptionVideos(servers[0].url, users[0].accessToken, 'createdAt') - expect(res.body.total).to.equal(4) + const body = await command.listVideos({ token: users[0].accessToken, sort: 'createdAt' }) + expect(body.total).to.equal(4) - const videos: Video[] = res.body.data + const videos = body.data expect(videos).to.be.an('array') expect(videos).to.have.lengthOf(4) @@ -281,17 +262,17 @@ describe('Test users subscriptions', function () { it('Should still list subscription videos', async function () { { - const res = await listUserSubscriptionVideos(servers[0].url, servers[0].accessToken) - expect(res.body.total).to.equal(0) - expect(res.body.data).to.be.an('array') - expect(res.body.data).to.have.lengthOf(0) + const body = await command.listVideos() + expect(body.total).to.equal(0) + expect(body.data).to.be.an('array') + expect(body.data).to.have.lengthOf(0) } { - const res = await listUserSubscriptionVideos(servers[0].url, users[0].accessToken, 'createdAt') - expect(res.body.total).to.equal(4) + const body = await command.listVideos({ token: users[0].accessToken, sort: 'createdAt' }) + expect(body.total).to.equal(4) - const videos: Video[] = res.body.data + const videos = body.data expect(videos).to.be.an('array') expect(videos).to.have.lengthOf(4) @@ -309,44 +290,41 @@ describe('Test users subscriptions', function () { await waitJobs(servers) - const res = await listUserSubscriptionVideos(servers[0].url, users[0].accessToken, 'createdAt') - const videos: Video[] = res.body.data - expect(videos[2].name).to.equal('video server 3 added after follow updated') + const body = await command.listVideos({ token: users[0].accessToken, sort: 'createdAt' }) + expect(body.data[2].name).to.equal('video server 3 added after follow updated') }) it('Should remove user of server 3 subscription', async function () { this.timeout(30000) - await removeUserSubscription(servers[0].url, users[0].accessToken, 'user3_channel@localhost:' + servers[2].port) + await command.remove({ token: users[0].accessToken, uri: 'user3_channel@localhost:' + servers[2].port }) await waitJobs(servers) }) it('Should not display its videos anymore', async function () { - { - const res = await listUserSubscriptionVideos(servers[0].url, users[0].accessToken, 'createdAt') - expect(res.body.total).to.equal(1) + const body = await command.listVideos({ token: users[0].accessToken, sort: 'createdAt' }) + expect(body.total).to.equal(1) - const videos: Video[] = res.body.data - expect(videos).to.be.an('array') - expect(videos).to.have.lengthOf(1) + const videos = body.data + expect(videos).to.be.an('array') + expect(videos).to.have.lengthOf(1) - expect(videos[0].name).to.equal('video server 1 added after follow') - } + expect(videos[0].name).to.equal('video server 1 added after follow') }) it('Should remove the root subscription and not display the videos anymore', async function () { this.timeout(30000) - await removeUserSubscription(servers[0].url, users[0].accessToken, 'root_channel@localhost:' + servers[0].port) + await command.remove({ token: users[0].accessToken, uri: 'root_channel@localhost:' + servers[0].port }) await waitJobs(servers) { - const res = await listUserSubscriptionVideos(servers[0].url, users[0].accessToken, 'createdAt') - expect(res.body.total).to.equal(0) + const body = await command.list({ token: users[0].accessToken, sort: 'createdAt' }) + expect(body.total).to.equal(0) - const videos: Video[] = res.body.data + const videos = body.data expect(videos).to.be.an('array') expect(videos).to.have.lengthOf(0) } @@ -366,15 +344,15 @@ describe('Test users subscriptions', function () { it('Should follow user of server 3 again', async function () { this.timeout(60000) - await addUserSubscription(servers[0].url, users[0].accessToken, 'user3_channel@localhost:' + servers[2].port) + await command.add({ token: users[0].accessToken, targetUri: 'user3_channel@localhost:' + servers[2].port }) await waitJobs(servers) { - const res = await listUserSubscriptionVideos(servers[0].url, users[0].accessToken, 'createdAt') - expect(res.body.total).to.equal(3) + const body = await command.listVideos({ token: users[0].accessToken, sort: 'createdAt' }) + expect(body.total).to.equal(3) - const videos: Video[] = res.body.data + const videos = body.data expect(videos).to.be.an('array') expect(videos).to.have.lengthOf(3) -- 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 +++++++++--------- server/tests/api/live/live-constraints.ts | 21 +++--- server/tests/api/live/live-permanent.ts | 43 +++++------ server/tests/api/live/live-save-replay.ts | 29 +++----- server/tests/api/live/live-socket-messages.ts | 19 ++--- server/tests/api/live/live-views.ts | 8 +- server/tests/api/live/live.ts | 90 +++++++++++------------ server/tests/api/search/search-videos.ts | 22 +++--- server/tests/api/videos/video-change-ownership.ts | 5 +- 9 files changed, 140 insertions(+), 169 deletions(-) (limited to 'server/tests/api') 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) }) }) diff --git a/server/tests/api/live/live-constraints.ts b/server/tests/api/live/live-constraints.ts index c64d10dcd..5c4817b40 100644 --- a/server/tests/api/live/live-constraints.ts +++ b/server/tests/api/live/live-constraints.ts @@ -7,19 +7,16 @@ import { checkLiveCleanup, cleanupTests, ConfigCommand, - createLive, doubleFollow, flushAndRunMultipleServers, generateUser, getVideo, - runAndTestFfmpegStreamError, ServerInfo, setAccessTokensToServers, setDefaultVideoChannel, updateUser, wait, - waitJobs, - waitUntilLivePublished + waitJobs } from '../../../../shared/extra-utils' const expect = chai.expect @@ -38,8 +35,8 @@ describe('Test live constraints', function () { saveReplay } - const res = await createLive(servers[0].url, userAccessToken, liveAttributes) - return res.body.video.uuid as string + const { uuid } = await servers[0].liveCommand.createLive({ token: userAccessToken, fields: liveAttributes }) + return uuid } async function checkSaveReplay (videoId: string, resolutions = [ 720 ]) { @@ -56,7 +53,7 @@ describe('Test live constraints', function () { async function waitUntilLivePublishedOnAllServers (videoId: string) { for (const server of servers) { - await waitUntilLivePublished(server.url, server.accessToken, videoId) + await server.liveCommand.waitUntilLivePublished({ videoId }) } } @@ -108,7 +105,7 @@ describe('Test live constraints', function () { this.timeout(60000) const userVideoLiveoId = await createLiveWrapper(false) - await runAndTestFfmpegStreamError(servers[0].url, userAccessToken, userVideoLiveoId, false) + await servers[0].liveCommand.runAndTestFfmpegStreamError({ token: userAccessToken, videoId: userVideoLiveoId, shouldHaveError: false }) }) it('Should have size limit depending on user global quota if save replay is enabled', async function () { @@ -118,7 +115,7 @@ describe('Test live constraints', function () { await wait(5000) const userVideoLiveoId = await createLiveWrapper(true) - await runAndTestFfmpegStreamError(servers[0].url, userAccessToken, userVideoLiveoId, true) + await servers[0].liveCommand.runAndTestFfmpegStreamError({ token: userAccessToken, videoId: userVideoLiveoId, shouldHaveError: true }) await waitUntilLivePublishedOnAllServers(userVideoLiveoId) await waitJobs(servers) @@ -135,7 +132,7 @@ describe('Test live constraints', function () { await updateQuota({ total: -1, daily: 1 }) const userVideoLiveoId = await createLiveWrapper(true) - await runAndTestFfmpegStreamError(servers[0].url, userAccessToken, userVideoLiveoId, true) + await servers[0].liveCommand.runAndTestFfmpegStreamError({ token: userAccessToken, videoId: userVideoLiveoId, shouldHaveError: true }) await waitUntilLivePublishedOnAllServers(userVideoLiveoId) await waitJobs(servers) @@ -152,7 +149,7 @@ describe('Test live constraints', function () { await updateQuota({ total: 10 * 1000 * 1000, daily: -1 }) const userVideoLiveoId = await createLiveWrapper(true) - await runAndTestFfmpegStreamError(servers[0].url, userAccessToken, userVideoLiveoId, false) + await servers[0].liveCommand.runAndTestFfmpegStreamError({ token: userAccessToken, videoId: userVideoLiveoId, shouldHaveError: false }) }) it('Should have max duration limit', async function () { @@ -173,7 +170,7 @@ describe('Test live constraints', function () { }) const userVideoLiveoId = await createLiveWrapper(true) - await runAndTestFfmpegStreamError(servers[0].url, userAccessToken, userVideoLiveoId, true) + await servers[0].liveCommand.runAndTestFfmpegStreamError({ token: userAccessToken, videoId: userVideoLiveoId, shouldHaveError: true }) await waitUntilLivePublishedOnAllServers(userVideoLiveoId) await waitJobs(servers) diff --git a/server/tests/api/live/live-permanent.ts b/server/tests/api/live/live-permanent.ts index b9e37c834..a0f70dfdb 100644 --- a/server/tests/api/live/live-permanent.ts +++ b/server/tests/api/live/live-permanent.ts @@ -6,22 +6,15 @@ import { LiveVideoCreate, VideoDetails, VideoPrivacy, VideoState } from '@shared import { cleanupTests, ConfigCommand, - createLive, doubleFollow, flushAndRunMultipleServers, - getLive, - getPlaylistsCount, getVideo, - sendRTMPStreamInVideo, ServerInfo, setAccessTokensToServers, setDefaultVideoChannel, stopFfmpeg, - updateLive, wait, - waitJobs, - waitUntilLivePublished, - waitUntilLiveWaiting + waitJobs } from '../../../../shared/extra-utils' const expect = chai.expect @@ -39,8 +32,8 @@ describe('Permanent live', function () { permanentLive } - const res = await createLive(servers[0].url, servers[0].accessToken, attributes) - return res.body.video.uuid + const { uuid } = await servers[0].liveCommand.createLive({ fields: attributes }) + return uuid } async function checkVideoState (videoId: string, state: VideoState) { @@ -83,15 +76,15 @@ describe('Permanent live', function () { const videoUUID = await createLiveWrapper(false) { - const res = await getLive(servers[0].url, servers[0].accessToken, videoUUID) - expect(res.body.permanentLive).to.be.false + const live = await servers[0].liveCommand.getLive({ videoId: videoUUID }) + expect(live.permanentLive).to.be.false } - await updateLive(servers[0].url, servers[0].accessToken, videoUUID, { permanentLive: true }) + await servers[0].liveCommand.updateLive({ videoId: videoUUID, fields: { permanentLive: true } }) { - const res = await getLive(servers[0].url, servers[0].accessToken, videoUUID) - expect(res.body.permanentLive).to.be.true + const live = await servers[0].liveCommand.getLive({ videoId: videoUUID }) + expect(live.permanentLive).to.be.true } }) @@ -100,8 +93,8 @@ describe('Permanent live', function () { videoUUID = await createLiveWrapper(true) - const res = await getLive(servers[0].url, servers[0].accessToken, videoUUID) - expect(res.body.permanentLive).to.be.true + const live = await servers[0].liveCommand.getLive({ videoId: videoUUID }) + expect(live.permanentLive).to.be.true await waitJobs(servers) }) @@ -109,16 +102,16 @@ describe('Permanent live', function () { it('Should stream into this permanent live', async function () { this.timeout(120000) - const command = await sendRTMPStreamInVideo(servers[0].url, servers[0].accessToken, videoUUID) + const ffmpegCommand = await servers[0].liveCommand.sendRTMPStreamInVideo({ videoId: videoUUID }) for (const server of servers) { - await waitUntilLivePublished(server.url, server.accessToken, videoUUID) + await server.liveCommand.waitUntilLivePublished({ videoId: videoUUID }) } await checkVideoState(videoUUID, VideoState.PUBLISHED) - await stopFfmpeg(command) - await waitUntilLiveWaiting(servers[0].url, servers[0].accessToken, videoUUID) + await stopFfmpeg(ffmpegCommand) + await servers[0].liveCommand.waitUntilLiveWaiting({ videoId: videoUUID }) await waitJobs(servers) }) @@ -160,19 +153,19 @@ describe('Permanent live', function () { } }) - const command = await sendRTMPStreamInVideo(servers[0].url, servers[0].accessToken, videoUUID) + const ffmpegCommand = await servers[0].liveCommand.sendRTMPStreamInVideo({ videoId: videoUUID }) for (const server of servers) { - await waitUntilLivePublished(server.url, server.accessToken, videoUUID) + await server.liveCommand.waitUntilLivePublished({ videoId: videoUUID }) } await checkVideoState(videoUUID, VideoState.PUBLISHED) - const count = await getPlaylistsCount(servers[0], videoUUID) + const count = await servers[0].liveCommand.getPlaylistsCount({ videoUUID }) // master playlist and 720p playlist expect(count).to.equal(2) - await stopFfmpeg(command) + await stopFfmpeg(ffmpegCommand) }) after(async function () { diff --git a/server/tests/api/live/live-save-replay.ts b/server/tests/api/live/live-save-replay.ts index e74bc3e8d..d3c252ffd 100644 --- a/server/tests/api/live/live-save-replay.ts +++ b/server/tests/api/live/live-save-replay.ts @@ -10,13 +10,11 @@ import { checkLiveCleanup, cleanupTests, ConfigCommand, - createLive, doubleFollow, flushAndRunMultipleServers, getVideo, getVideosList, removeVideo, - sendRTMPStreamInVideo, ServerInfo, setAccessTokensToServers, setDefaultVideoChannel, @@ -24,10 +22,7 @@ import { testFfmpegStreamError, updateVideo, wait, - waitJobs, - waitUntilLiveEnded, - waitUntilLivePublished, - waitUntilLiveSaved + waitJobs } from '../../../../shared/extra-utils' const expect = chai.expect @@ -52,8 +47,8 @@ describe('Save replay setting', function () { saveReplay } - const res = await createLive(servers[0].url, servers[0].accessToken, attributes) - return res.body.video.uuid + const { uuid } = await servers[0].liveCommand.createLive({ fields: attributes }) + return uuid } async function checkVideosExist (videoId: string, existsInList: boolean, getStatus?: number) { @@ -79,13 +74,13 @@ describe('Save replay setting', function () { async function waitUntilLivePublishedOnAllServers (videoId: string) { for (const server of servers) { - await waitUntilLivePublished(server.url, server.accessToken, videoId) + await server.liveCommand.waitUntilLivePublished({ videoId }) } } async function waitUntilLiveSavedOnAllServers (videoId: string) { for (const server of servers) { - await waitUntilLiveSaved(server.url, server.accessToken, videoId) + await server.liveCommand.waitUntilLiveSaved({ videoId }) } } @@ -136,7 +131,7 @@ describe('Save replay setting', function () { it('Should correctly have updated the live and federated it when streaming in the live', async function () { this.timeout(30000) - ffmpegCommand = await sendRTMPStreamInVideo(servers[0].url, servers[0].accessToken, liveVideoUUID) + ffmpegCommand = await servers[0].liveCommand.sendRTMPStreamInVideo({ videoId: liveVideoUUID }) await waitUntilLivePublishedOnAllServers(liveVideoUUID) @@ -152,7 +147,7 @@ describe('Save replay setting', function () { await stopFfmpeg(ffmpegCommand) for (const server of servers) { - await waitUntilLiveEnded(server.url, server.accessToken, liveVideoUUID) + await server.liveCommand.waitUntilLiveEnded({ videoId: liveVideoUUID }) } await waitJobs(servers) @@ -169,7 +164,7 @@ describe('Save replay setting', function () { liveVideoUUID = await createLiveWrapper(false) - ffmpegCommand = await sendRTMPStreamInVideo(servers[0].url, servers[0].accessToken, liveVideoUUID) + ffmpegCommand = await servers[0].liveCommand.sendRTMPStreamInVideo({ videoId: liveVideoUUID }) await waitUntilLivePublishedOnAllServers(liveVideoUUID) @@ -198,7 +193,7 @@ describe('Save replay setting', function () { liveVideoUUID = await createLiveWrapper(false) - ffmpegCommand = await sendRTMPStreamInVideo(servers[0].url, servers[0].accessToken, liveVideoUUID) + ffmpegCommand = await servers[0].liveCommand.sendRTMPStreamInVideo({ videoId: liveVideoUUID }) await waitUntilLivePublishedOnAllServers(liveVideoUUID) @@ -234,7 +229,7 @@ describe('Save replay setting', function () { it('Should correctly have updated the live and federated it when streaming in the live', async function () { this.timeout(20000) - ffmpegCommand = await sendRTMPStreamInVideo(servers[0].url, servers[0].accessToken, liveVideoUUID) + ffmpegCommand = await servers[0].liveCommand.sendRTMPStreamInVideo({ videoId: liveVideoUUID }) await waitUntilLivePublishedOnAllServers(liveVideoUUID) await waitJobs(servers) @@ -278,7 +273,7 @@ describe('Save replay setting', function () { liveVideoUUID = await createLiveWrapper(true) - ffmpegCommand = await sendRTMPStreamInVideo(servers[0].url, servers[0].accessToken, liveVideoUUID) + ffmpegCommand = await servers[0].liveCommand.sendRTMPStreamInVideo({ videoId: liveVideoUUID }) await waitUntilLivePublishedOnAllServers(liveVideoUUID) await waitJobs(servers) @@ -306,7 +301,7 @@ describe('Save replay setting', function () { liveVideoUUID = await createLiveWrapper(true) - ffmpegCommand = await sendRTMPStreamInVideo(servers[0].url, servers[0].accessToken, liveVideoUUID) + ffmpegCommand = await servers[0].liveCommand.sendRTMPStreamInVideo({ videoId: liveVideoUUID }) await waitUntilLivePublishedOnAllServers(liveVideoUUID) await waitJobs(servers) diff --git a/server/tests/api/live/live-socket-messages.ts b/server/tests/api/live/live-socket-messages.ts index 20fec16a9..73a300384 100644 --- a/server/tests/api/live/live-socket-messages.ts +++ b/server/tests/api/live/live-socket-messages.ts @@ -5,11 +5,9 @@ import * as chai from 'chai' import { VideoPrivacy, VideoState } from '@shared/models' import { cleanupTests, - createLive, doubleFollow, flushAndRunMultipleServers, getVideoIdFromUUID, - sendRTMPStreamInVideo, ServerInfo, setAccessTokensToServers, setDefaultVideoChannel, @@ -17,7 +15,6 @@ import { viewVideo, wait, waitJobs, - waitUntilLiveEnded, waitUntilLivePublishedOnAllServers } from '../../../../shared/extra-utils' @@ -60,8 +57,8 @@ describe('Test live', function () { privacy: VideoPrivacy.PUBLIC } - const res = await createLive(servers[0].url, servers[0].accessToken, liveAttributes) - return res.body.video.uuid + const { uuid } = await servers[0].liveCommand.createLive({ fields: liveAttributes }) + return uuid } it('Should correctly send a message when the live starts and ends', async function () { @@ -89,7 +86,7 @@ describe('Test live', function () { remoteSocket.emit('subscribe', { videoId }) } - const command = await sendRTMPStreamInVideo(servers[0].url, servers[0].accessToken, liveVideoUUID) + const ffmpegCommand = await servers[0].liveCommand.sendRTMPStreamInVideo({ videoId: liveVideoUUID }) await waitUntilLivePublishedOnAllServers(servers, liveVideoUUID) await waitJobs(servers) @@ -99,10 +96,10 @@ describe('Test live', function () { expect(stateChanges[stateChanges.length - 1]).to.equal(VideoState.PUBLISHED) } - await stopFfmpeg(command) + await stopFfmpeg(ffmpegCommand) for (const server of servers) { - await waitUntilLiveEnded(server.url, server.accessToken, liveVideoUUID) + await server.liveCommand.waitUntilLiveEnded({ videoId: liveVideoUUID }) } await waitJobs(servers) @@ -137,7 +134,7 @@ describe('Test live', function () { remoteSocket.emit('subscribe', { videoId }) } - const command = await sendRTMPStreamInVideo(servers[0].url, servers[0].accessToken, liveVideoUUID) + const ffmpegCommand = await servers[0].liveCommand.sendRTMPStreamInVideo({ videoId: liveVideoUUID }) await waitUntilLivePublishedOnAllServers(servers, liveVideoUUID) await waitJobs(servers) @@ -155,7 +152,7 @@ describe('Test live', function () { expect(localLastVideoViews).to.equal(2) expect(remoteLastVideoViews).to.equal(2) - await stopFfmpeg(command) + await stopFfmpeg(ffmpegCommand) }) it('Should not receive a notification after unsubscribe', async function () { @@ -172,7 +169,7 @@ describe('Test live', function () { socket.on('state-change', data => stateChanges.push(data.state)) socket.emit('subscribe', { videoId }) - const command = await sendRTMPStreamInVideo(servers[0].url, servers[0].accessToken, liveVideoUUID) + const command = await servers[0].liveCommand.sendRTMPStreamInVideo({ videoId: liveVideoUUID }) await waitUntilLivePublishedOnAllServers(servers, liveVideoUUID) await waitJobs(servers) diff --git a/server/tests/api/live/live-views.ts b/server/tests/api/live/live-views.ts index ca571c962..ae6af7cfd 100644 --- a/server/tests/api/live/live-views.ts +++ b/server/tests/api/live/live-views.ts @@ -6,11 +6,9 @@ import { FfmpegCommand } from 'fluent-ffmpeg' import { VideoDetails, VideoPrivacy } from '@shared/models' import { cleanupTests, - createLive, doubleFollow, flushAndRunMultipleServers, getVideo, - sendRTMPStreamInVideo, ServerInfo, setAccessTokensToServers, setDefaultVideoChannel, @@ -73,10 +71,10 @@ describe('Test live', function () { privacy: VideoPrivacy.PUBLIC } - const res = await createLive(servers[0].url, servers[0].accessToken, liveAttributes) - liveVideoId = res.body.video.uuid + const live = await servers[0].liveCommand.createLive({ fields: liveAttributes }) + liveVideoId = live.uuid - command = await sendRTMPStreamInVideo(servers[0].url, servers[0].accessToken, liveVideoId) + command = await servers[0].liveCommand.sendRTMPStreamInVideo({ videoId: liveVideoId }) await waitUntilLivePublishedOnAllServers(servers, liveVideoId) await waitJobs(servers) }) diff --git a/server/tests/api/live/live.ts b/server/tests/api/live/live.ts index 2c3102994..5b4e479b6 100644 --- a/server/tests/api/live/live.ts +++ b/server/tests/api/live/live.ts @@ -13,41 +13,36 @@ import { checkLiveSegmentHash, checkResolutionsInMasterPlaylist, cleanupTests, - createLive, doubleFollow, flushAndRunMultipleServers, - getLive, getMyVideosWithFilter, getPlaylist, getVideo, getVideosList, getVideosWithFilters, killallServers, + LiveCommand, makeRawRequest, removeVideo, reRunServer, sendRTMPStream, - sendRTMPStreamInVideo, ServerInfo, setAccessTokensToServers, setDefaultVideoChannel, stopFfmpeg, testFfmpegStreamError, testImage, - updateLive, uploadVideoAndGetId, wait, waitJobs, - waitUntilLiveEnded, - waitUntilLivePublished, - waitUntilLivePublishedOnAllServers, - waitUntilLiveSegmentGeneration + waitUntilLivePublishedOnAllServers } from '../../../../shared/extra-utils' const expect = chai.expect describe('Test live', function () { let servers: ServerInfo[] = [] + let commands: LiveCommand[] before(async function () { this.timeout(120000) @@ -72,6 +67,8 @@ describe('Test live', function () { // Server 1 and server 2 follow each other await doubleFollow(servers[0], servers[1]) + + commands = servers.map(s => s.liveCommand) }) describe('Live creation, update and delete', function () { @@ -99,8 +96,8 @@ describe('Test live', function () { thumbnailfile: 'video_short1.webm.jpg' } - const res = await createLive(servers[0].url, servers[0].accessToken, attributes) - liveVideoUUID = res.body.video.uuid + const live = await commands[0].createLive({ fields: attributes }) + liveVideoUUID = live.uuid await waitJobs(servers) @@ -130,8 +127,7 @@ describe('Test live', function () { await testImage(server.url, 'video_short1-preview.webm', video.previewPath) await testImage(server.url, 'video_short1.webm', video.thumbnailPath) - const resLive = await getLive(server.url, server.accessToken, liveVideoUUID) - const live: LiveVideo = resLive.body + const live = await server.liveCommand.getLive({ videoId: liveVideoUUID }) if (server.url === servers[0].url) { expect(live.rtmpUrl).to.equal('rtmp://' + server.hostname + ':' + servers[0].rtmpPort + '/live') @@ -155,8 +151,8 @@ describe('Test live', function () { nsfw: true } - const res = await createLive(servers[0].url, servers[0].accessToken, attributes) - const videoId = res.body.video.uuid + const live = await commands[0].createLive({ fields: attributes }) + const videoId = live.uuid await waitJobs(servers) @@ -182,20 +178,19 @@ describe('Test live', function () { }) it('Should not be able to update a live of another server', async function () { - await updateLive(servers[1].url, servers[1].accessToken, liveVideoUUID, { saveReplay: false }, HttpStatusCode.FORBIDDEN_403) + await commands[1].updateLive({ videoId: liveVideoUUID, fields: { saveReplay: false }, expectedStatus: HttpStatusCode.FORBIDDEN_403 }) }) it('Should update the live', async function () { this.timeout(10000) - await updateLive(servers[0].url, servers[0].accessToken, liveVideoUUID, { saveReplay: false }) + await commands[0].updateLive({ videoId: liveVideoUUID, fields: { saveReplay: false } }) await waitJobs(servers) }) it('Have the live updated', async function () { for (const server of servers) { - const res = await getLive(server.url, server.accessToken, liveVideoUUID) - const live: LiveVideo = res.body + const live = await server.liveCommand.getLive({ videoId: liveVideoUUID }) if (server.url === servers[0].url) { expect(live.rtmpUrl).to.equal('rtmp://' + server.hostname + ':' + servers[0].rtmpPort + '/live') @@ -219,13 +214,13 @@ describe('Test live', function () { it('Should have the live deleted', async function () { for (const server of servers) { await getVideo(server.url, liveVideoUUID, HttpStatusCode.NOT_FOUND_404) - await getLive(server.url, server.accessToken, liveVideoUUID, HttpStatusCode.NOT_FOUND_404) + await server.liveCommand.getLive({ videoId: liveVideoUUID, expectedStatus: HttpStatusCode.NOT_FOUND_404 }) } }) }) describe('Live filters', function () { - let command: any + let ffmpegCommand: any let liveVideoId: string let vodVideoId: string @@ -235,10 +230,10 @@ describe('Test live', function () { vodVideoId = (await uploadVideoAndGetId({ server: servers[0], videoName: 'vod video' })).uuid const liveOptions = { name: 'live', privacy: VideoPrivacy.PUBLIC, channelId: servers[0].videoChannel.id } - const resLive = await createLive(servers[0].url, servers[0].accessToken, liveOptions) - liveVideoId = resLive.body.video.uuid + const live = await commands[0].createLive({ fields: liveOptions }) + liveVideoId = live.uuid - command = await sendRTMPStreamInVideo(servers[0].url, servers[0].accessToken, liveVideoId) + ffmpegCommand = await servers[0].liveCommand.sendRTMPStreamInVideo({ videoId: liveVideoId }) await waitUntilLivePublishedOnAllServers(servers, liveVideoId) await waitJobs(servers) }) @@ -262,7 +257,7 @@ describe('Test live', function () { it('Should display my lives', async function () { this.timeout(60000) - await stopFfmpeg(command) + await stopFfmpeg(ffmpegCommand) await waitJobs(servers) const res = await getMyVideosWithFilter(servers[0].url, servers[0].accessToken, { isLive: true }) @@ -302,13 +297,12 @@ describe('Test live', function () { saveReplay: false } - const res = await createLive(servers[0].url, servers[0].accessToken, liveAttributes) - const uuid = res.body.video.uuid + const { uuid } = await commands[0].createLive({ fields: liveAttributes }) - const resLive = await getLive(servers[0].url, servers[0].accessToken, uuid) + const live = await commands[0].getLive({ videoId: uuid }) const resVideo = await getVideo(servers[0].url, uuid) - return Object.assign(resVideo.body, resLive.body) as LiveVideo & VideoDetails + return Object.assign(resVideo.body as VideoDetails, live) } it('Should not allow a stream without the appropriate path', async function () { @@ -382,8 +376,8 @@ describe('Test live', function () { saveReplay } - const res = await createLive(servers[0].url, servers[0].accessToken, liveAttributes) - return res.body.video.uuid + const { uuid } = await commands[0].createLive({ fields: liveAttributes }) + return uuid } async function testVideoResolutions (liveVideoId: string, resolutions: number[]) { @@ -409,7 +403,7 @@ describe('Test live', function () { for (let i = 0; i < resolutions.length; i++) { const segmentNum = 3 const segmentName = `${i}-00000${segmentNum}.ts` - await waitUntilLiveSegmentGeneration(servers[0], video.uuid, i, segmentNum) + await commands[0].waitUntilLiveSegmentGeneration({ videoUUID: video.uuid, resolution: i, segment: segmentNum }) const res = await getPlaylist(`${servers[0].url}/static/streaming-playlists/hls/${video.uuid}/${i}.m3u8`) const subPlaylist = res.text @@ -454,13 +448,13 @@ describe('Test live', function () { liveVideoId = await createLiveWrapper(false) - const command = await sendRTMPStreamInVideo(servers[0].url, servers[0].accessToken, liveVideoId) + const ffmpegCommand = await commands[0].sendRTMPStreamInVideo({ videoId: liveVideoId }) await waitUntilLivePublishedOnAllServers(servers, liveVideoId) await waitJobs(servers) await testVideoResolutions(liveVideoId, [ 720 ]) - await stopFfmpeg(command) + await stopFfmpeg(ffmpegCommand) }) it('Should enable transcoding with some resolutions', async function () { @@ -470,13 +464,13 @@ describe('Test live', function () { await updateConf(resolutions) liveVideoId = await createLiveWrapper(false) - const command = await sendRTMPStreamInVideo(servers[0].url, servers[0].accessToken, liveVideoId) + const ffmpegCommand = await commands[0].sendRTMPStreamInVideo({ videoId: liveVideoId }) await waitUntilLivePublishedOnAllServers(servers, liveVideoId) await waitJobs(servers) await testVideoResolutions(liveVideoId, resolutions) - await stopFfmpeg(command) + await stopFfmpeg(ffmpegCommand) }) it('Should enable transcoding with some resolutions and correctly save them', async function () { @@ -487,14 +481,14 @@ describe('Test live', function () { await updateConf(resolutions) liveVideoId = await createLiveWrapper(true) - const command = await sendRTMPStreamInVideo(servers[0].url, servers[0].accessToken, liveVideoId, 'video_short2.webm') + const ffmpegCommand = await commands[0].sendRTMPStreamInVideo({ videoId: liveVideoId, fixtureName: 'video_short2.webm' }) await waitUntilLivePublishedOnAllServers(servers, liveVideoId) await waitJobs(servers) await testVideoResolutions(liveVideoId, resolutions) - await stopFfmpeg(command) - await waitUntilLiveEnded(servers[0].url, servers[0].accessToken, liveVideoId) + await stopFfmpeg(ffmpegCommand) + await commands[0].waitUntilLiveEnded({ videoId: liveVideoId }) await waitJobs(servers) @@ -565,8 +559,8 @@ describe('Test live', function () { saveReplay } - const res = await createLive(servers[0].url, servers[0].accessToken, liveAttributes) - return res.body.video.uuid + const { uuid } = await commands[0].createLive({ fields: liveAttributes }) + return uuid } before(async function () { @@ -576,17 +570,17 @@ describe('Test live', function () { liveVideoReplayId = await createLiveWrapper(true) await Promise.all([ - sendRTMPStreamInVideo(servers[0].url, servers[0].accessToken, liveVideoId), - sendRTMPStreamInVideo(servers[0].url, servers[0].accessToken, liveVideoReplayId) + commands[0].sendRTMPStreamInVideo({ videoId: liveVideoId }), + commands[0].sendRTMPStreamInVideo({ videoId: liveVideoReplayId }) ]) await Promise.all([ - waitUntilLivePublished(servers[0].url, servers[0].accessToken, liveVideoId), - waitUntilLivePublished(servers[0].url, servers[0].accessToken, liveVideoReplayId) + commands[0].waitUntilLivePublished({ videoId: liveVideoId }), + commands[0].waitUntilLivePublished({ videoId: liveVideoReplayId }) ]) - await waitUntilLiveSegmentGeneration(servers[0], liveVideoId, 0, 2) - await waitUntilLiveSegmentGeneration(servers[0], liveVideoReplayId, 0, 2) + await commands[0].waitUntilLiveSegmentGeneration({ videoUUID: liveVideoId, resolution: 0, segment: 2 }) + await commands[0].waitUntilLiveSegmentGeneration({ videoUUID: liveVideoReplayId, resolution: 0, segment: 2 }) await killallServers([ servers[0] ]) await reRunServer(servers[0]) @@ -597,13 +591,13 @@ describe('Test live', function () { it('Should cleanup lives', async function () { this.timeout(60000) - await waitUntilLiveEnded(servers[0].url, servers[0].accessToken, liveVideoId) + await commands[0].waitUntilLiveEnded({ videoId: liveVideoId }) }) it('Should save a live replay', async function () { this.timeout(120000) - await waitUntilLivePublished(servers[0].url, servers[0].accessToken, liveVideoReplayId) + await commands[0].waitUntilLivePublished({ videoId: liveVideoReplayId }) }) }) diff --git a/server/tests/api/search/search-videos.ts b/server/tests/api/search/search-videos.ts index 7dc89c447..af74b26a7 100644 --- a/server/tests/api/search/search-videos.ts +++ b/server/tests/api/search/search-videos.ts @@ -2,23 +2,20 @@ import 'mocha' import * as chai from 'chai' -import { VideoPrivacy } from '@shared/models' import { cleanupTests, - createLive, + createVideoCaption, flushAndRunServer, immutableAssign, SearchCommand, - sendRTMPStreamInVideo, ServerInfo, setAccessTokensToServers, setDefaultVideoChannel, stopFfmpeg, uploadVideo, - wait, - waitUntilLivePublished -} from '../../../../shared/extra-utils' -import { createVideoCaption } from '../../../../shared/extra-utils/videos/video-captions' + wait +} from '@shared/extra-utils' +import { VideoPrivacy } from '@shared/models' const expect = chai.expect @@ -502,12 +499,13 @@ describe('Test videos search', function () { } { - const liveOptions = { name: 'live', privacy: VideoPrivacy.PUBLIC, channelId: server.videoChannel.id } - const resLive = await createLive(server.url, server.accessToken, liveOptions) - const liveVideoId = resLive.body.video.uuid + const liveCommand = server.liveCommand + + const liveAttributes = { name: 'live', privacy: VideoPrivacy.PUBLIC, channelId: server.videoChannel.id } + const live = await liveCommand.createLive({ fields: liveAttributes }) - const ffmpegCommand = await sendRTMPStreamInVideo(server.url, server.accessToken, liveVideoId) - await waitUntilLivePublished(server.url, server.accessToken, liveVideoId) + const ffmpegCommand = await liveCommand.sendRTMPStreamInVideo({ videoId: live.id }) + await liveCommand.waitUntilLivePublished({ videoId: live.id }) const body = await command.advancedVideoSearch({ search: { isLive: true } }) diff --git a/server/tests/api/videos/video-change-ownership.ts b/server/tests/api/videos/video-change-ownership.ts index 89dba14b1..88e4d51a2 100644 --- a/server/tests/api/videos/video-change-ownership.ts +++ b/server/tests/api/videos/video-change-ownership.ts @@ -7,7 +7,6 @@ import { acceptChangeOwnership, changeVideoOwnership, cleanupTests, - createLive, createUser, doubleFollow, flushAndRunMultipleServers, @@ -112,9 +111,9 @@ describe('Test video change ownership - nominal', function () { { const attributes = { name: 'live', channelId: firstUserChannelId, privacy: VideoPrivacy.PUBLIC } - const res = await createLive(servers[0].url, firstUserAccessToken, attributes) + const video = await servers[0].liveCommand.createLive({ token: firstUserAccessToken, fields: attributes }) - liveId = res.body.video.id + liveId = video.id } await doubleFollow(servers[0], servers[1]) -- cgit v1.2.3 From d897210c2db1ca2acc1e7b28a13127647ab2222c Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Thu, 8 Jul 2021 10:23:21 +0200 Subject: Introduce services command --- server/tests/api/server/services.ts | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) (limited to 'server/tests/api') diff --git a/server/tests/api/server/services.ts b/server/tests/api/server/services.ts index ea64e4040..0adf6b667 100644 --- a/server/tests/api/server/services.ts +++ b/server/tests/api/server/services.ts @@ -6,7 +6,6 @@ import { Video, VideoPlaylistPrivacy } from '@shared/models' import { addVideoInPlaylist, createVideoPlaylist, - getOEmbed, getVideosList, ServerInfo, setAccessTokensToServers, @@ -70,7 +69,7 @@ describe('Test services', function () { for (const basePath of [ '/videos/watch/', '/w/' ]) { const oembedUrl = 'http://localhost:' + server.port + basePath + video.uuid - const res = await getOEmbed(server.url, oembedUrl) + const res = await server.servicesCommand.getOEmbed({ oembedUrl }) const expectedHtml = '' @@ -91,7 +90,7 @@ describe('Test services', function () { for (const basePath of [ '/videos/watch/playlist/', '/w/p/' ]) { const oembedUrl = 'http://localhost:' + server.port + basePath + playlistUUID - const res = await getOEmbed(server.url, oembedUrl) + const res = await server.servicesCommand.getOEmbed({ oembedUrl }) const expectedHtml = '' @@ -114,7 +113,7 @@ describe('Test services', function () { const maxHeight = 50 const maxWidth = 50 - const res = await getOEmbed(server.url, oembedUrl, format, maxHeight, maxWidth) + const res = await server.servicesCommand.getOEmbed({ oembedUrl, format, maxHeight, maxWidth }) const expectedHtml = '' -- 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 +++++++++++------------ server/tests/api/live/live-constraints.ts | 14 +++--- server/tests/api/live/live-permanent.ts | 18 ++++---- server/tests/api/live/live-save-replay.ts | 8 ++-- server/tests/api/live/live-socket-messages.ts | 4 +- server/tests/api/live/live-views.ts | 2 +- server/tests/api/live/live.ts | 42 +++++++++--------- server/tests/api/search/search-videos.ts | 4 +- server/tests/api/videos/video-change-ownership.ts | 2 +- 9 files changed, 73 insertions(+), 73 deletions(-) (limited to 'server/tests/api') 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) }) diff --git a/server/tests/api/live/live-constraints.ts b/server/tests/api/live/live-constraints.ts index 5c4817b40..46153f7b1 100644 --- a/server/tests/api/live/live-constraints.ts +++ b/server/tests/api/live/live-constraints.ts @@ -35,7 +35,7 @@ describe('Test live constraints', function () { saveReplay } - const { uuid } = await servers[0].liveCommand.createLive({ token: userAccessToken, fields: liveAttributes }) + const { uuid } = await servers[0].liveCommand.create({ token: userAccessToken, fields: liveAttributes }) return uuid } @@ -53,7 +53,7 @@ describe('Test live constraints', function () { async function waitUntilLivePublishedOnAllServers (videoId: string) { for (const server of servers) { - await server.liveCommand.waitUntilLivePublished({ videoId }) + await server.liveCommand.waitUntilPublished({ videoId }) } } @@ -105,7 +105,7 @@ describe('Test live constraints', function () { this.timeout(60000) const userVideoLiveoId = await createLiveWrapper(false) - await servers[0].liveCommand.runAndTestFfmpegStreamError({ token: userAccessToken, videoId: userVideoLiveoId, shouldHaveError: false }) + await servers[0].liveCommand.runAndTestStreamError({ token: userAccessToken, videoId: userVideoLiveoId, shouldHaveError: false }) }) it('Should have size limit depending on user global quota if save replay is enabled', async function () { @@ -115,7 +115,7 @@ describe('Test live constraints', function () { await wait(5000) const userVideoLiveoId = await createLiveWrapper(true) - await servers[0].liveCommand.runAndTestFfmpegStreamError({ token: userAccessToken, videoId: userVideoLiveoId, shouldHaveError: true }) + await servers[0].liveCommand.runAndTestStreamError({ token: userAccessToken, videoId: userVideoLiveoId, shouldHaveError: true }) await waitUntilLivePublishedOnAllServers(userVideoLiveoId) await waitJobs(servers) @@ -132,7 +132,7 @@ describe('Test live constraints', function () { await updateQuota({ total: -1, daily: 1 }) const userVideoLiveoId = await createLiveWrapper(true) - await servers[0].liveCommand.runAndTestFfmpegStreamError({ token: userAccessToken, videoId: userVideoLiveoId, shouldHaveError: true }) + await servers[0].liveCommand.runAndTestStreamError({ token: userAccessToken, videoId: userVideoLiveoId, shouldHaveError: true }) await waitUntilLivePublishedOnAllServers(userVideoLiveoId) await waitJobs(servers) @@ -149,7 +149,7 @@ describe('Test live constraints', function () { await updateQuota({ total: 10 * 1000 * 1000, daily: -1 }) const userVideoLiveoId = await createLiveWrapper(true) - await servers[0].liveCommand.runAndTestFfmpegStreamError({ token: userAccessToken, videoId: userVideoLiveoId, shouldHaveError: false }) + await servers[0].liveCommand.runAndTestStreamError({ token: userAccessToken, videoId: userVideoLiveoId, shouldHaveError: false }) }) it('Should have max duration limit', async function () { @@ -170,7 +170,7 @@ describe('Test live constraints', function () { }) const userVideoLiveoId = await createLiveWrapper(true) - await servers[0].liveCommand.runAndTestFfmpegStreamError({ token: userAccessToken, videoId: userVideoLiveoId, shouldHaveError: true }) + await servers[0].liveCommand.runAndTestStreamError({ token: userAccessToken, videoId: userVideoLiveoId, shouldHaveError: true }) await waitUntilLivePublishedOnAllServers(userVideoLiveoId) await waitJobs(servers) diff --git a/server/tests/api/live/live-permanent.ts b/server/tests/api/live/live-permanent.ts index a0f70dfdb..6f4915a6b 100644 --- a/server/tests/api/live/live-permanent.ts +++ b/server/tests/api/live/live-permanent.ts @@ -32,7 +32,7 @@ describe('Permanent live', function () { permanentLive } - const { uuid } = await servers[0].liveCommand.createLive({ fields: attributes }) + const { uuid } = await servers[0].liveCommand.create({ fields: attributes }) return uuid } @@ -76,14 +76,14 @@ describe('Permanent live', function () { const videoUUID = await createLiveWrapper(false) { - const live = await servers[0].liveCommand.getLive({ videoId: videoUUID }) + const live = await servers[0].liveCommand.get({ videoId: videoUUID }) expect(live.permanentLive).to.be.false } - await servers[0].liveCommand.updateLive({ videoId: videoUUID, fields: { permanentLive: true } }) + await servers[0].liveCommand.update({ videoId: videoUUID, fields: { permanentLive: true } }) { - const live = await servers[0].liveCommand.getLive({ videoId: videoUUID }) + const live = await servers[0].liveCommand.get({ videoId: videoUUID }) expect(live.permanentLive).to.be.true } }) @@ -93,7 +93,7 @@ describe('Permanent live', function () { videoUUID = await createLiveWrapper(true) - const live = await servers[0].liveCommand.getLive({ videoId: videoUUID }) + const live = await servers[0].liveCommand.get({ videoId: videoUUID }) expect(live.permanentLive).to.be.true await waitJobs(servers) @@ -105,13 +105,13 @@ describe('Permanent live', function () { const ffmpegCommand = await servers[0].liveCommand.sendRTMPStreamInVideo({ videoId: videoUUID }) for (const server of servers) { - await server.liveCommand.waitUntilLivePublished({ videoId: videoUUID }) + await server.liveCommand.waitUntilPublished({ videoId: videoUUID }) } await checkVideoState(videoUUID, VideoState.PUBLISHED) await stopFfmpeg(ffmpegCommand) - await servers[0].liveCommand.waitUntilLiveWaiting({ videoId: videoUUID }) + await servers[0].liveCommand.waitUntilWaiting({ videoId: videoUUID }) await waitJobs(servers) }) @@ -156,12 +156,12 @@ describe('Permanent live', function () { const ffmpegCommand = await servers[0].liveCommand.sendRTMPStreamInVideo({ videoId: videoUUID }) for (const server of servers) { - await server.liveCommand.waitUntilLivePublished({ videoId: videoUUID }) + await server.liveCommand.waitUntilPublished({ videoId: videoUUID }) } await checkVideoState(videoUUID, VideoState.PUBLISHED) - const count = await servers[0].liveCommand.getPlaylistsCount({ videoUUID }) + const count = await servers[0].liveCommand.countPlaylists({ videoUUID }) // master playlist and 720p playlist expect(count).to.equal(2) diff --git a/server/tests/api/live/live-save-replay.ts b/server/tests/api/live/live-save-replay.ts index d3c252ffd..9acd5601d 100644 --- a/server/tests/api/live/live-save-replay.ts +++ b/server/tests/api/live/live-save-replay.ts @@ -47,7 +47,7 @@ describe('Save replay setting', function () { saveReplay } - const { uuid } = await servers[0].liveCommand.createLive({ fields: attributes }) + const { uuid } = await servers[0].liveCommand.create({ fields: attributes }) return uuid } @@ -74,13 +74,13 @@ describe('Save replay setting', function () { async function waitUntilLivePublishedOnAllServers (videoId: string) { for (const server of servers) { - await server.liveCommand.waitUntilLivePublished({ videoId }) + await server.liveCommand.waitUntilPublished({ videoId }) } } async function waitUntilLiveSavedOnAllServers (videoId: string) { for (const server of servers) { - await server.liveCommand.waitUntilLiveSaved({ videoId }) + await server.liveCommand.waitUntilSaved({ videoId }) } } @@ -147,7 +147,7 @@ describe('Save replay setting', function () { await stopFfmpeg(ffmpegCommand) for (const server of servers) { - await server.liveCommand.waitUntilLiveEnded({ videoId: liveVideoUUID }) + await server.liveCommand.waitUntilEnded({ videoId: liveVideoUUID }) } await waitJobs(servers) diff --git a/server/tests/api/live/live-socket-messages.ts b/server/tests/api/live/live-socket-messages.ts index 73a300384..4a6677c0a 100644 --- a/server/tests/api/live/live-socket-messages.ts +++ b/server/tests/api/live/live-socket-messages.ts @@ -57,7 +57,7 @@ describe('Test live', function () { privacy: VideoPrivacy.PUBLIC } - const { uuid } = await servers[0].liveCommand.createLive({ fields: liveAttributes }) + const { uuid } = await servers[0].liveCommand.create({ fields: liveAttributes }) return uuid } @@ -99,7 +99,7 @@ describe('Test live', function () { await stopFfmpeg(ffmpegCommand) for (const server of servers) { - await server.liveCommand.waitUntilLiveEnded({ videoId: liveVideoUUID }) + await server.liveCommand.waitUntilEnded({ videoId: liveVideoUUID }) } await waitJobs(servers) diff --git a/server/tests/api/live/live-views.ts b/server/tests/api/live/live-views.ts index ae6af7cfd..75f95b167 100644 --- a/server/tests/api/live/live-views.ts +++ b/server/tests/api/live/live-views.ts @@ -71,7 +71,7 @@ describe('Test live', function () { privacy: VideoPrivacy.PUBLIC } - const live = await servers[0].liveCommand.createLive({ fields: liveAttributes }) + const live = await servers[0].liveCommand.create({ fields: liveAttributes }) liveVideoId = live.uuid command = await servers[0].liveCommand.sendRTMPStreamInVideo({ videoId: liveVideoId }) diff --git a/server/tests/api/live/live.ts b/server/tests/api/live/live.ts index 5b4e479b6..5d70d8513 100644 --- a/server/tests/api/live/live.ts +++ b/server/tests/api/live/live.ts @@ -96,7 +96,7 @@ describe('Test live', function () { thumbnailfile: 'video_short1.webm.jpg' } - const live = await commands[0].createLive({ fields: attributes }) + const live = await commands[0].create({ fields: attributes }) liveVideoUUID = live.uuid await waitJobs(servers) @@ -127,7 +127,7 @@ describe('Test live', function () { await testImage(server.url, 'video_short1-preview.webm', video.previewPath) await testImage(server.url, 'video_short1.webm', video.thumbnailPath) - const live = await server.liveCommand.getLive({ videoId: liveVideoUUID }) + const live = await server.liveCommand.get({ videoId: liveVideoUUID }) if (server.url === servers[0].url) { expect(live.rtmpUrl).to.equal('rtmp://' + server.hostname + ':' + servers[0].rtmpPort + '/live') @@ -151,7 +151,7 @@ describe('Test live', function () { nsfw: true } - const live = await commands[0].createLive({ fields: attributes }) + const live = await commands[0].create({ fields: attributes }) const videoId = live.uuid await waitJobs(servers) @@ -178,19 +178,19 @@ describe('Test live', function () { }) it('Should not be able to update a live of another server', async function () { - await commands[1].updateLive({ videoId: liveVideoUUID, fields: { saveReplay: false }, expectedStatus: HttpStatusCode.FORBIDDEN_403 }) + await commands[1].update({ videoId: liveVideoUUID, fields: { saveReplay: false }, expectedStatus: HttpStatusCode.FORBIDDEN_403 }) }) it('Should update the live', async function () { this.timeout(10000) - await commands[0].updateLive({ videoId: liveVideoUUID, fields: { saveReplay: false } }) + await commands[0].update({ videoId: liveVideoUUID, fields: { saveReplay: false } }) await waitJobs(servers) }) it('Have the live updated', async function () { for (const server of servers) { - const live = await server.liveCommand.getLive({ videoId: liveVideoUUID }) + const live = await server.liveCommand.get({ videoId: liveVideoUUID }) if (server.url === servers[0].url) { expect(live.rtmpUrl).to.equal('rtmp://' + server.hostname + ':' + servers[0].rtmpPort + '/live') @@ -214,7 +214,7 @@ describe('Test live', function () { it('Should have the live deleted', async function () { for (const server of servers) { await getVideo(server.url, liveVideoUUID, HttpStatusCode.NOT_FOUND_404) - await server.liveCommand.getLive({ videoId: liveVideoUUID, expectedStatus: HttpStatusCode.NOT_FOUND_404 }) + await server.liveCommand.get({ videoId: liveVideoUUID, expectedStatus: HttpStatusCode.NOT_FOUND_404 }) } }) }) @@ -230,7 +230,7 @@ describe('Test live', function () { vodVideoId = (await uploadVideoAndGetId({ server: servers[0], videoName: 'vod video' })).uuid const liveOptions = { name: 'live', privacy: VideoPrivacy.PUBLIC, channelId: servers[0].videoChannel.id } - const live = await commands[0].createLive({ fields: liveOptions }) + const live = await commands[0].create({ fields: liveOptions }) liveVideoId = live.uuid ffmpegCommand = await servers[0].liveCommand.sendRTMPStreamInVideo({ videoId: liveVideoId }) @@ -297,9 +297,9 @@ describe('Test live', function () { saveReplay: false } - const { uuid } = await commands[0].createLive({ fields: liveAttributes }) + const { uuid } = await commands[0].create({ fields: liveAttributes }) - const live = await commands[0].getLive({ videoId: uuid }) + const live = await commands[0].get({ videoId: uuid }) const resVideo = await getVideo(servers[0].url, uuid) return Object.assign(resVideo.body as VideoDetails, live) @@ -376,7 +376,7 @@ describe('Test live', function () { saveReplay } - const { uuid } = await commands[0].createLive({ fields: liveAttributes }) + const { uuid } = await commands[0].create({ fields: liveAttributes }) return uuid } @@ -403,7 +403,7 @@ describe('Test live', function () { for (let i = 0; i < resolutions.length; i++) { const segmentNum = 3 const segmentName = `${i}-00000${segmentNum}.ts` - await commands[0].waitUntilLiveSegmentGeneration({ videoUUID: video.uuid, resolution: i, segment: segmentNum }) + await commands[0].waitUntilSegmentGeneration({ videoUUID: video.uuid, resolution: i, segment: segmentNum }) const res = await getPlaylist(`${servers[0].url}/static/streaming-playlists/hls/${video.uuid}/${i}.m3u8`) const subPlaylist = res.text @@ -488,7 +488,7 @@ describe('Test live', function () { await testVideoResolutions(liveVideoId, resolutions) await stopFfmpeg(ffmpegCommand) - await commands[0].waitUntilLiveEnded({ videoId: liveVideoId }) + await commands[0].waitUntilEnded({ videoId: liveVideoId }) await waitJobs(servers) @@ -559,7 +559,7 @@ describe('Test live', function () { saveReplay } - const { uuid } = await commands[0].createLive({ fields: liveAttributes }) + const { uuid } = await commands[0].create({ fields: liveAttributes }) return uuid } @@ -575,14 +575,14 @@ describe('Test live', function () { ]) await Promise.all([ - commands[0].waitUntilLivePublished({ videoId: liveVideoId }), - commands[0].waitUntilLivePublished({ videoId: liveVideoReplayId }) + commands[0].waitUntilPublished({ videoId: liveVideoId }), + commands[0].waitUntilPublished({ videoId: liveVideoReplayId }) ]) - await commands[0].waitUntilLiveSegmentGeneration({ videoUUID: liveVideoId, resolution: 0, segment: 2 }) - await commands[0].waitUntilLiveSegmentGeneration({ videoUUID: liveVideoReplayId, resolution: 0, segment: 2 }) + await commands[0].waitUntilSegmentGeneration({ videoUUID: liveVideoId, resolution: 0, segment: 2 }) + await commands[0].waitUntilSegmentGeneration({ videoUUID: liveVideoReplayId, resolution: 0, segment: 2 }) - await killallServers([ servers[0] ]) + killallServers([ servers[0] ]) await reRunServer(servers[0]) await wait(5000) @@ -591,13 +591,13 @@ describe('Test live', function () { it('Should cleanup lives', async function () { this.timeout(60000) - await commands[0].waitUntilLiveEnded({ videoId: liveVideoId }) + await commands[0].waitUntilEnded({ videoId: liveVideoId }) }) it('Should save a live replay', async function () { this.timeout(120000) - await commands[0].waitUntilLivePublished({ videoId: liveVideoReplayId }) + await commands[0].waitUntilPublished({ videoId: liveVideoReplayId }) }) }) diff --git a/server/tests/api/search/search-videos.ts b/server/tests/api/search/search-videos.ts index af74b26a7..a0375fbf0 100644 --- a/server/tests/api/search/search-videos.ts +++ b/server/tests/api/search/search-videos.ts @@ -502,10 +502,10 @@ describe('Test videos search', function () { const liveCommand = server.liveCommand const liveAttributes = { name: 'live', privacy: VideoPrivacy.PUBLIC, channelId: server.videoChannel.id } - const live = await liveCommand.createLive({ fields: liveAttributes }) + const live = await liveCommand.create({ fields: liveAttributes }) const ffmpegCommand = await liveCommand.sendRTMPStreamInVideo({ videoId: live.id }) - await liveCommand.waitUntilLivePublished({ videoId: live.id }) + await liveCommand.waitUntilPublished({ videoId: live.id }) const body = await command.advancedVideoSearch({ search: { isLive: true } }) diff --git a/server/tests/api/videos/video-change-ownership.ts b/server/tests/api/videos/video-change-ownership.ts index 88e4d51a2..3c33cf015 100644 --- a/server/tests/api/videos/video-change-ownership.ts +++ b/server/tests/api/videos/video-change-ownership.ts @@ -111,7 +111,7 @@ describe('Test video change ownership - nominal', function () { { const attributes = { name: 'live', channelId: firstUserChannelId, privacy: VideoPrivacy.PUBLIC } - const video = await servers[0].liveCommand.createLive({ token: firstUserAccessToken, fields: attributes }) + const video = await servers[0].liveCommand.create({ token: firstUserAccessToken, fields: attributes }) liveId = video.id } -- 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 +++---- server/tests/api/live/live-save-replay.ts | 5 +- server/tests/api/live/live.ts | 3 +- server/tests/api/moderation/video-blacklist.ts | 144 ++++++++------------- .../api/notifications/moderation-notifications.ts | 12 +- server/tests/api/server/email.ts | 6 +- server/tests/api/users/users.ts | 3 +- server/tests/api/videos/video-playlists.ts | 6 +- 8 files changed, 88 insertions(+), 138 deletions(-) (limited to 'server/tests/api') 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 }) }) }) diff --git a/server/tests/api/live/live-save-replay.ts b/server/tests/api/live/live-save-replay.ts index 9acd5601d..363fb561c 100644 --- a/server/tests/api/live/live-save-replay.ts +++ b/server/tests/api/live/live-save-replay.ts @@ -6,7 +6,6 @@ import { FfmpegCommand } from 'fluent-ffmpeg' import { LiveVideoCreate, VideoDetails, VideoPrivacy, VideoState } from '@shared/models' import { HttpStatusCode } from '../../../../shared/core-utils/miscs/http-error-codes' import { - addVideoToBlacklist, checkLiveCleanup, cleanupTests, ConfigCommand, @@ -172,7 +171,7 @@ describe('Save replay setting', function () { await checkVideosExist(liveVideoUUID, true, HttpStatusCode.OK_200) await Promise.all([ - addVideoToBlacklist(servers[0].url, servers[0].accessToken, liveVideoUUID, 'bad live', true), + servers[0].blacklistCommand.add({ videoId: liveVideoUUID, reason: 'bad live', unfederate: true }), testFfmpegStreamError(ffmpegCommand, true) ]) @@ -280,7 +279,7 @@ describe('Save replay setting', function () { await checkVideosExist(liveVideoUUID, true, HttpStatusCode.OK_200) await Promise.all([ - addVideoToBlacklist(servers[0].url, servers[0].accessToken, liveVideoUUID, 'bad live', true), + servers[0].blacklistCommand.add({ videoId: liveVideoUUID, reason: 'bad live', unfederate: true }), testFfmpegStreamError(ffmpegCommand, true) ]) diff --git a/server/tests/api/live/live.ts b/server/tests/api/live/live.ts index 5d70d8513..cb52e4431 100644 --- a/server/tests/api/live/live.ts +++ b/server/tests/api/live/live.ts @@ -7,7 +7,6 @@ import { ffprobePromise, getVideoStreamFromFile } from '@server/helpers/ffprobe- import { LiveVideo, LiveVideoCreate, Video, VideoDetails, VideoPrivacy, VideoState, VideoStreamingPlaylistType } from '@shared/models' import { HttpStatusCode } from '../../../../shared/core-utils/miscs/http-error-codes' import { - addVideoToBlacklist, buildServerDirectory, checkLiveCleanup, checkLiveSegmentHash, @@ -347,7 +346,7 @@ describe('Test live', function () { liveVideo = await createLiveWrapper() - await addVideoToBlacklist(servers[0].url, servers[0].accessToken, liveVideo.uuid) + await servers[0].blacklistCommand.add({ videoId: liveVideo.uuid }) const command = sendRTMPStream(rtmpUrl + '/live', liveVideo.streamKey) await testFfmpegStreamError(command, true) diff --git a/server/tests/api/moderation/video-blacklist.ts b/server/tests/api/moderation/video-blacklist.ts index 4a4930c98..17a68e4a6 100644 --- a/server/tests/api/moderation/video-blacklist.ts +++ b/server/tests/api/moderation/video-blacklist.ts @@ -4,22 +4,19 @@ import 'mocha' import * as chai from 'chai' import { orderBy } from 'lodash' import { - addVideoToBlacklist, + BlacklistCommand, cleanupTests, createUser, doubleFollow, flushAndRunMultipleServers, - getBlacklistedVideosList, getMyUserInformation, getMyVideos, getVideosList, killallServers, - removeVideoFromBlacklist, reRunServer, ServerInfo, setAccessTokensToServers, updateVideo, - updateVideoBlacklist, uploadVideo, userLogin, waitJobs @@ -32,13 +29,14 @@ const expect = chai.expect describe('Test video blacklist', function () { let servers: ServerInfo[] = [] let videoId: number + let command: BlacklistCommand async function blacklistVideosOnServer (server: ServerInfo) { const res = await getVideosList(server.url) const videos = res.body.data for (const video of videos) { - await addVideoToBlacklist(server.url, server.accessToken, video.id, 'super reason') + await server.blacklistCommand.add({ videoId: video.id, reason: 'super reason' }) } } @@ -61,6 +59,8 @@ describe('Test video blacklist', function () { // Wait videos propagation, server 2 has transcoding enabled await waitJobs(servers) + command = servers[0].blacklistCommand + // Blacklist the two videos on server 1 await blacklistVideosOnServer(servers[0]) }) @@ -77,7 +77,7 @@ describe('Test video blacklist', function () { } { - const body = await servers[0].searchCommand.searchVideos({ search: 'name' }) + const body = await servers[0].searchCommand.searchVideos({ search: 'video' }) expect(body.total).to.equal(0) expect(body.data).to.be.an('array') @@ -95,7 +95,7 @@ describe('Test video blacklist', function () { } { - const body = await servers[1].searchCommand.searchVideos({ search: 'name' }) + const body = await servers[1].searchCommand.searchVideos({ search: 'video' }) expect(body.total).to.equal(2) expect(body.data).to.be.an('array') @@ -106,11 +106,10 @@ describe('Test video blacklist', function () { describe('When listing manually blacklisted videos', function () { it('Should display all the blacklisted videos', async function () { - const res = await getBlacklistedVideosList({ url: servers[0].url, token: servers[0].accessToken }) - - expect(res.body.total).to.equal(2) + const body = await command.list() + expect(body.total).to.equal(2) - const blacklistedVideos = res.body.data + const blacklistedVideos = body.data expect(blacklistedVideos).to.be.an('array') expect(blacklistedVideos.length).to.equal(2) @@ -121,79 +120,66 @@ describe('Test video blacklist', function () { }) it('Should display all the blacklisted videos when applying manual type filter', async function () { - const res = await getBlacklistedVideosList({ - url: servers[0].url, - token: servers[0].accessToken, - type: VideoBlacklistType.MANUAL - }) + const body = await command.list({ type: VideoBlacklistType.MANUAL }) + expect(body.total).to.equal(2) - expect(res.body.total).to.equal(2) - - const blacklistedVideos = res.body.data + const blacklistedVideos = body.data expect(blacklistedVideos).to.be.an('array') expect(blacklistedVideos.length).to.equal(2) }) it('Should display nothing when applying automatic type filter', async function () { - const res = await getBlacklistedVideosList({ - url: servers[0].url, - token: servers[0].accessToken, - type: VideoBlacklistType.AUTO_BEFORE_PUBLISHED - }) + const body = await command.list({ type: VideoBlacklistType.AUTO_BEFORE_PUBLISHED }) + expect(body.total).to.equal(0) - expect(res.body.total).to.equal(0) - - const blacklistedVideos = res.body.data + const blacklistedVideos = body.data expect(blacklistedVideos).to.be.an('array') expect(blacklistedVideos.length).to.equal(0) }) it('Should get the correct sort when sorting by descending id', async function () { - const res = await getBlacklistedVideosList({ url: servers[0].url, token: servers[0].accessToken, sort: '-id' }) - expect(res.body.total).to.equal(2) + const body = await command.list({ sort: '-id' }) + expect(body.total).to.equal(2) - const blacklistedVideos = res.body.data + const blacklistedVideos = body.data expect(blacklistedVideos).to.be.an('array') expect(blacklistedVideos.length).to.equal(2) - const result = orderBy(res.body.data, [ 'id' ], [ 'desc' ]) - + const result = orderBy(body.data, [ 'id' ], [ 'desc' ]) expect(blacklistedVideos).to.deep.equal(result) }) it('Should get the correct sort when sorting by descending video name', async function () { - const res = await getBlacklistedVideosList({ url: servers[0].url, token: servers[0].accessToken, sort: '-name' }) - expect(res.body.total).to.equal(2) + const body = await command.list({ sort: '-name' }) + expect(body.total).to.equal(2) - const blacklistedVideos = res.body.data + const blacklistedVideos = body.data expect(blacklistedVideos).to.be.an('array') expect(blacklistedVideos.length).to.equal(2) - const result = orderBy(res.body.data, [ 'name' ], [ 'desc' ]) - + const result = orderBy(body.data, [ 'name' ], [ 'desc' ]) expect(blacklistedVideos).to.deep.equal(result) }) it('Should get the correct sort when sorting by ascending creation date', async function () { - const res = await getBlacklistedVideosList({ url: servers[0].url, token: servers[0].accessToken, sort: 'createdAt' }) - expect(res.body.total).to.equal(2) + const body = await command.list({ sort: 'createdAt' }) + expect(body.total).to.equal(2) - const blacklistedVideos = res.body.data + const blacklistedVideos = body.data expect(blacklistedVideos).to.be.an('array') expect(blacklistedVideos.length).to.equal(2) - const result = orderBy(res.body.data, [ 'createdAt' ]) - + const result = orderBy(body.data, [ 'createdAt' ]) expect(blacklistedVideos).to.deep.equal(result) }) }) describe('When updating blacklisted videos', function () { it('Should change the reason', async function () { - await updateVideoBlacklist(servers[0].url, servers[0].accessToken, videoId, 'my super reason updated') + await command.update({ videoId, reason: 'my super reason updated' }) - const res = await getBlacklistedVideosList({ url: servers[0].url, token: servers[0].accessToken, sort: '-name' }) - const video = res.body.data.find(b => b.video.id === videoId) + const body = await command.list({ sort: '-name' }) + const video = body.data.find(b => b.video.id === videoId) expect(video.reason).to.equal('my super reason updated') }) @@ -228,12 +214,12 @@ describe('Test video blacklist', function () { it('Should remove a video from the blacklist on server 1', async function () { // Get one video in the blacklist - const res = await getBlacklistedVideosList({ url: servers[0].url, token: servers[0].accessToken, sort: '-name' }) - videoToRemove = res.body.data[0] - blacklist = res.body.data.slice(1) + const body = await command.list({ sort: '-name' }) + videoToRemove = body.data[0] + blacklist = body.data.slice(1) // Remove it - await removeVideoFromBlacklist(servers[0].url, servers[0].accessToken, videoToRemove.video.id) + await command.remove({ videoId: videoToRemove.video.id }) }) it('Should have the ex-blacklisted video in videos list on server 1', async function () { @@ -249,10 +235,10 @@ describe('Test video blacklist', function () { }) it('Should not have the ex-blacklisted video in videos blacklist list on server 1', async function () { - const res = await getBlacklistedVideosList({ url: servers[0].url, token: servers[0].accessToken, sort: '-name' }) - expect(res.body.total).to.equal(1) + const body = await command.list({ sort: '-name' }) + expect(body.total).to.equal(1) - const videos = res.body.data + const videos = body.data expect(videos).to.be.an('array') expect(videos.length).to.equal(1) expect(videos).to.deep.equal(blacklist) @@ -281,7 +267,7 @@ describe('Test video blacklist', function () { it('Should blacklist video 3 and keep it federated', async function () { this.timeout(10000) - await addVideoToBlacklist(servers[0].url, servers[0].accessToken, video3UUID, 'super reason', false) + await command.add({ videoId: video3UUID, reason: 'super reason', unfederate: false }) await waitJobs(servers) @@ -299,7 +285,7 @@ describe('Test video blacklist', function () { it('Should unfederate the video', async function () { this.timeout(10000) - await addVideoToBlacklist(servers[0].url, servers[0].accessToken, video4UUID, 'super reason', true) + await command.add({ videoId: video4UUID, reason: 'super reason', unfederate: true }) await waitJobs(servers) @@ -323,9 +309,9 @@ describe('Test video blacklist', function () { }) it('Should have the correct video blacklist unfederate attribute', async function () { - const res = await getBlacklistedVideosList({ url: servers[0].url, token: servers[0].accessToken, sort: 'createdAt' }) + const body = await command.list({ sort: 'createdAt' }) - const blacklistedVideos: VideoBlacklist[] = res.body.data + const blacklistedVideos = body.data const video3Blacklisted = blacklistedVideos.find(b => b.video.uuid === video3UUID) const video4Blacklisted = blacklistedVideos.find(b => b.video.uuid === video4UUID) @@ -336,7 +322,7 @@ describe('Test video blacklist', function () { it('Should remove the video from blacklist and refederate the video', async function () { this.timeout(10000) - await removeVideoFromBlacklist(servers[0].url, servers[0].accessToken, video4UUID) + await command.remove({ videoId: video4UUID }) await waitJobs(servers) @@ -407,14 +393,9 @@ describe('Test video blacklist', function () { it('Should auto blacklist a video on upload', async function () { await uploadVideo(servers[0].url, userWithoutFlag, { name: 'blacklisted' }) - const res = await getBlacklistedVideosList({ - url: servers[0].url, - token: servers[0].accessToken, - type: VideoBlacklistType.AUTO_BEFORE_PUBLISHED - }) - - expect(res.body.total).to.equal(1) - expect(res.body.data[0].video.name).to.equal('blacklisted') + const body = await command.list({ type: VideoBlacklistType.AUTO_BEFORE_PUBLISHED }) + expect(body.total).to.equal(1) + expect(body.data[0].video.name).to.equal('blacklisted') }) it('Should auto blacklist a video on URL import', async function () { @@ -427,15 +408,9 @@ describe('Test video blacklist', function () { } await importVideo(servers[0].url, userWithoutFlag, attributes) - const res = await getBlacklistedVideosList({ - url: servers[0].url, - token: servers[0].accessToken, - sort: 'createdAt', - type: VideoBlacklistType.AUTO_BEFORE_PUBLISHED - }) - - expect(res.body.total).to.equal(2) - expect(res.body.data[1].video.name).to.equal('URL import') + const body = await command.list({ sort: 'createdAt', type: VideoBlacklistType.AUTO_BEFORE_PUBLISHED }) + expect(body.total).to.equal(2) + expect(body.data[1].video.name).to.equal('URL import') }) it('Should auto blacklist a video on torrent import', async function () { @@ -446,27 +421,16 @@ describe('Test video blacklist', function () { } await importVideo(servers[0].url, userWithoutFlag, attributes) - const res = await getBlacklistedVideosList({ - url: servers[0].url, - token: servers[0].accessToken, - sort: 'createdAt', - type: VideoBlacklistType.AUTO_BEFORE_PUBLISHED - }) - - expect(res.body.total).to.equal(3) - expect(res.body.data[2].video.name).to.equal('Torrent import') + const body = await command.list({ sort: 'createdAt', type: VideoBlacklistType.AUTO_BEFORE_PUBLISHED }) + expect(body.total).to.equal(3) + expect(body.data[2].video.name).to.equal('Torrent import') }) it('Should not auto blacklist a video on upload if the user has the bypass blacklist flag', async function () { await uploadVideo(servers[0].url, userWithFlag, { name: 'not blacklisted' }) - const res = await getBlacklistedVideosList({ - url: servers[0].url, - token: servers[0].accessToken, - type: VideoBlacklistType.AUTO_BEFORE_PUBLISHED - }) - - expect(res.body.total).to.equal(3) + const body = await command.list({ type: VideoBlacklistType.AUTO_BEFORE_PUBLISHED }) + expect(body.total).to.equal(3) }) }) diff --git a/server/tests/api/notifications/moderation-notifications.ts b/server/tests/api/notifications/moderation-notifications.ts index 605b41947..52ade0548 100644 --- a/server/tests/api/notifications/moderation-notifications.ts +++ b/server/tests/api/notifications/moderation-notifications.ts @@ -4,7 +4,6 @@ import 'mocha' import { buildUUID } from '@server/helpers/uuid' import { addVideoCommentThread, - addVideoToBlacklist, checkAbuseStateChange, checkAutoInstanceFollowing, CheckerBaseParams, @@ -28,7 +27,6 @@ import { MockSmtpServer, prepareNotificationsTest, registerUser, - removeVideoFromBlacklist, ServerInfo, uploadVideo, wait, @@ -297,7 +295,7 @@ describe('Test moderation notifications', function () { const resVideo = await uploadVideo(servers[0].url, userAccessToken, { name }) const uuid = resVideo.body.video.uuid - await addVideoToBlacklist(servers[0].url, servers[0].accessToken, uuid) + await servers[0].blacklistCommand.add({ videoId: uuid }) await waitJobs(servers) await checkNewBlacklistOnMyVideo(baseParams, uuid, name, 'blacklist') @@ -310,10 +308,10 @@ describe('Test moderation notifications', function () { const resVideo = await uploadVideo(servers[0].url, userAccessToken, { name }) const uuid = resVideo.body.video.uuid - await addVideoToBlacklist(servers[0].url, servers[0].accessToken, uuid) + await servers[0].blacklistCommand.add({ videoId: uuid }) await waitJobs(servers) - await removeVideoFromBlacklist(servers[0].url, servers[0].accessToken, uuid) + await servers[0].blacklistCommand.remove({ videoId: uuid }) await waitJobs(servers) await wait(500) @@ -517,7 +515,7 @@ describe('Test moderation notifications', function () { it('Should send video published and unblacklist after video unblacklisted', async function () { this.timeout(40000) - await removeVideoFromBlacklist(servers[0].url, servers[0].accessToken, videoUUID) + await servers[0].blacklistCommand.remove({ videoId: videoUUID }) await waitJobs(servers) @@ -554,7 +552,7 @@ describe('Test moderation notifications', function () { const resVideo = await uploadVideo(servers[0].url, userAccessToken, data) const uuid = resVideo.body.video.uuid - await removeVideoFromBlacklist(servers[0].url, servers[0].accessToken, uuid) + await servers[0].blacklistCommand.remove({ videoId: uuid }) await waitJobs(servers) await checkNewBlacklistOnMyVideo(userBaseParams, uuid, name, 'unblacklist') diff --git a/server/tests/api/server/email.ts b/server/tests/api/server/email.ts index 85844ae9d..5d997713b 100644 --- a/server/tests/api/server/email.ts +++ b/server/tests/api/server/email.ts @@ -4,14 +4,12 @@ import 'mocha' import * as chai from 'chai' import { HttpStatusCode } from '../../../../shared/core-utils/miscs/http-error-codes' import { - addVideoToBlacklist, askResetPassword, askSendVerifyEmail, blockUser, cleanupTests, createUser, flushAndRunServer, - removeVideoFromBlacklist, resetPassword, ServerInfo, setAccessTokensToServers, @@ -248,7 +246,7 @@ describe('Test emails', function () { this.timeout(10000) const reason = 'my super reason' - await addVideoToBlacklist(server.url, server.accessToken, videoUserUUID, reason) + await server.blacklistCommand.add({ videoId: videoUserUUID, reason }) await waitJobs(server) expect(emails).to.have.lengthOf(6) @@ -266,7 +264,7 @@ describe('Test emails', function () { it('Should send the notification email', async function () { this.timeout(10000) - await removeVideoFromBlacklist(server.url, server.accessToken, videoUserUUID) + await server.blacklistCommand.remove({ videoId: videoUserUUID }) await waitJobs(server) expect(emails).to.have.lengthOf(7) diff --git a/server/tests/api/users/users.ts b/server/tests/api/users/users.ts index 3beea5d50..4b9056306 100644 --- a/server/tests/api/users/users.ts +++ b/server/tests/api/users/users.ts @@ -11,7 +11,6 @@ import { createUser, deleteMe, flushAndRunServer, - getBlacklistedVideosList, getMyUserInformation, getMyUserVideoQuotaUsed, getMyUserVideoRating, @@ -808,7 +807,7 @@ describe('Test users', function () { describe('Video blacklists', function () { it('Should be able to list video blacklist by a moderator', async function () { - await getBlacklistedVideosList({ url: server.url, token: accessTokenUser }) + await server.blacklistCommand.list({ token: accessTokenUser }) }) }) diff --git a/server/tests/api/videos/video-playlists.ts b/server/tests/api/videos/video-playlists.ts index 90189721a..069450453 100644 --- a/server/tests/api/videos/video-playlists.ts +++ b/server/tests/api/videos/video-playlists.ts @@ -6,7 +6,6 @@ import { HttpStatusCode } from '@shared/core-utils' import { addVideoChannel, addVideoInPlaylist, - addVideoToBlacklist, checkPlaylistFilesWereRemoved, cleanupTests, createUser, @@ -28,7 +27,6 @@ import { getVideoPlaylistsList, getVideoPlaylistWithToken, removeUser, - removeVideoFromBlacklist, removeVideoFromPlaylist, reorderVideosPlaylist, ServerInfo, @@ -728,7 +726,7 @@ describe('Test video playlists', function () { const position = 1 { - await addVideoToBlacklist(servers[0].url, servers[0].accessToken, video1, 'reason', true) + await servers[0].blacklistCommand.add({ videoId: video1, reason: 'reason', unfederate: true }) await waitJobs(servers) await checkPlaylistElementType(groupUser1, playlistServer1UUID2, VideoPlaylistElementType.REGULAR, position, name, 3) @@ -738,7 +736,7 @@ describe('Test video playlists', function () { } { - await removeVideoFromBlacklist(servers[0].url, servers[0].accessToken, video1) + await servers[0].blacklistCommand.remove({ videoId: video1 }) await waitJobs(servers) await checkPlaylistElementType(groupUser1, playlistServer1UUID2, VideoPlaylistElementType.REGULAR, position, name, 3) -- 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 ++-- server/tests/api/search/search-videos.ts | 9 +-- server/tests/api/server/follows.ts | 16 ++--- server/tests/api/videos/video-captions.ts | 77 ++++++++++--------------- server/tests/api/videos/video-imports.ts | 33 +++++------ 5 files changed, 60 insertions(+), 86 deletions(-) (limited to 'server/tests/api') 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', diff --git a/server/tests/api/search/search-videos.ts b/server/tests/api/search/search-videos.ts index a0375fbf0..513538917 100644 --- a/server/tests/api/search/search-videos.ts +++ b/server/tests/api/search/search-videos.ts @@ -4,7 +4,6 @@ import 'mocha' import * as chai from 'chai' import { cleanupTests, - createVideoCaption, flushAndRunServer, immutableAssign, SearchCommand, @@ -54,18 +53,14 @@ describe('Test videos search', function () { const videoId = res.body.video.id videoUUID = res.body.video.uuid - await createVideoCaption({ - url: server.url, - accessToken: server.accessToken, + await server.captionsCommand.createVideoCaption({ language: 'en', videoId, fixture: 'subtitle-good2.vtt', mimeType: 'application/octet-stream' }) - await createVideoCaption({ - url: server.url, - accessToken: server.accessToken, + await server.captionsCommand.createVideoCaption({ language: 'aa', videoId, fixture: 'subtitle-good2.vtt', diff --git a/server/tests/api/server/follows.ts b/server/tests/api/server/follows.ts index 466932d63..520442c6e 100644 --- a/server/tests/api/server/follows.ts +++ b/server/tests/api/server/follows.ts @@ -8,7 +8,6 @@ import { cleanupTests, completeVideoCheck, createUser, - createVideoCaption, dateIsValid, deleteVideoComment, expectAccountFollows, @@ -17,7 +16,6 @@ import { getVideoCommentThreads, getVideosList, getVideoThreadComments, - listVideoCaptions, rateVideo, ServerInfo, setAccessTokensToServers, @@ -26,7 +24,7 @@ import { userLogin, waitJobs } from '@shared/extra-utils' -import { Video, VideoCaption, VideoComment, VideoCommentThreadTree, VideoPrivacy } from '@shared/models' +import { Video, VideoComment, VideoCommentThreadTree, VideoPrivacy } from '@shared/models' const expect = chai.expect @@ -385,9 +383,7 @@ describe('Test follows', function () { } { - await createVideoCaption({ - url: servers[2].url, - accessToken: servers[2].accessToken, + await servers[2].captionsCommand.createVideoCaption({ language: 'ar', videoId: video4.id, fixture: 'subtitle-good2.vtt' @@ -543,11 +539,11 @@ describe('Test follows', function () { }) it('Should have propagated captions', async function () { - const res = await listVideoCaptions(servers[0].url, video4.id) - expect(res.body.total).to.equal(1) - expect(res.body.data).to.have.lengthOf(1) + const body = await servers[0].captionsCommand.listVideoCaptions({ videoId: video4.id }) + expect(body.total).to.equal(1) + expect(body.data).to.have.lengthOf(1) - const caption1: VideoCaption = res.body.data[0] + const caption1 = body.data[0] expect(caption1.language.id).to.equal('ar') expect(caption1.language.label).to.equal('Arabic') expect(caption1.captionPath).to.match(new RegExp('^/lazy-static/video-captions/.+-ar.vtt$')) diff --git a/server/tests/api/videos/video-captions.ts b/server/tests/api/videos/video-captions.ts index 14ecedfa6..83ee809b8 100644 --- a/server/tests/api/videos/video-captions.ts +++ b/server/tests/api/videos/video-captions.ts @@ -1,25 +1,20 @@ /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */ -import * as chai from 'chai' import 'mocha' +import * as chai from 'chai' import { checkVideoFilesWereRemoved, cleanupTests, doubleFollow, flushAndRunMultipleServers, removeVideo, + ServerInfo, + setAccessTokensToServers, + testCaptionFile, uploadVideo, - wait -} from '../../../../shared/extra-utils' -import { ServerInfo, setAccessTokensToServers } from '../../../../shared/extra-utils/index' -import { waitJobs } from '../../../../shared/extra-utils/server/jobs' -import { - createVideoCaption, - deleteVideoCaption, - listVideoCaptions, - testCaptionFile -} from '../../../../shared/extra-utils/videos/video-captions' -import { VideoCaption } from '../../../../shared/models/videos/caption/video-caption.model' + wait, + waitJobs +} from '@shared/extra-utils' const expect = chai.expect @@ -47,26 +42,22 @@ describe('Test video captions', function () { it('Should list the captions and return an empty list', async function () { for (const server of servers) { - const res = await listVideoCaptions(server.url, videoUUID) - expect(res.body.total).to.equal(0) - expect(res.body.data).to.have.lengthOf(0) + const body = await server.captionsCommand.listVideoCaptions({ videoId: videoUUID }) + expect(body.total).to.equal(0) + expect(body.data).to.have.lengthOf(0) } }) it('Should create two new captions', async function () { this.timeout(30000) - await createVideoCaption({ - url: servers[0].url, - accessToken: servers[0].accessToken, + await servers[0].captionsCommand.createVideoCaption({ language: 'ar', videoId: videoUUID, fixture: 'subtitle-good1.vtt' }) - await createVideoCaption({ - url: servers[0].url, - accessToken: servers[0].accessToken, + await servers[0].captionsCommand.createVideoCaption({ language: 'zh', videoId: videoUUID, fixture: 'subtitle-good2.vtt', @@ -78,17 +69,17 @@ describe('Test video captions', function () { it('Should list these uploaded captions', async function () { for (const server of servers) { - const res = await listVideoCaptions(server.url, videoUUID) - expect(res.body.total).to.equal(2) - expect(res.body.data).to.have.lengthOf(2) + const body = await server.captionsCommand.listVideoCaptions({ videoId: videoUUID }) + expect(body.total).to.equal(2) + expect(body.data).to.have.lengthOf(2) - const caption1: VideoCaption = res.body.data[0] + const caption1 = body.data[0] expect(caption1.language.id).to.equal('ar') expect(caption1.language.label).to.equal('Arabic') expect(caption1.captionPath).to.match(new RegExp('^/lazy-static/video-captions/' + uuidRegex + '-ar.vtt$')) await testCaptionFile(server.url, caption1.captionPath, 'Subtitle good 1.') - const caption2: VideoCaption = res.body.data[1] + const caption2 = body.data[1] expect(caption2.language.id).to.equal('zh') expect(caption2.language.label).to.equal('Chinese') expect(caption2.captionPath).to.match(new RegExp('^/lazy-static/video-captions/' + uuidRegex + '-zh.vtt$')) @@ -99,9 +90,7 @@ describe('Test video captions', function () { it('Should replace an existing caption', async function () { this.timeout(30000) - await createVideoCaption({ - url: servers[0].url, - accessToken: servers[0].accessToken, + await servers[0].captionsCommand.createVideoCaption({ language: 'ar', videoId: videoUUID, fixture: 'subtitle-good2.vtt' @@ -112,11 +101,11 @@ describe('Test video captions', function () { it('Should have this caption updated', async function () { for (const server of servers) { - const res = await listVideoCaptions(server.url, videoUUID) - expect(res.body.total).to.equal(2) - expect(res.body.data).to.have.lengthOf(2) + const body = await server.captionsCommand.listVideoCaptions({ videoId: videoUUID }) + expect(body.total).to.equal(2) + expect(body.data).to.have.lengthOf(2) - const caption1: VideoCaption = res.body.data[0] + const caption1 = body.data[0] expect(caption1.language.id).to.equal('ar') expect(caption1.language.label).to.equal('Arabic') expect(caption1.captionPath).to.match(new RegExp('^/lazy-static/video-captions/' + uuidRegex + '-ar.vtt$')) @@ -127,9 +116,7 @@ describe('Test video captions', function () { it('Should replace an existing caption with a srt file and convert it', async function () { this.timeout(30000) - await createVideoCaption({ - url: servers[0].url, - accessToken: servers[0].accessToken, + await servers[0].captionsCommand.createVideoCaption({ language: 'ar', videoId: videoUUID, fixture: 'subtitle-good.srt' @@ -143,11 +130,11 @@ describe('Test video captions', function () { it('Should have this caption updated and converted', async function () { for (const server of servers) { - const res = await listVideoCaptions(server.url, videoUUID) - expect(res.body.total).to.equal(2) - expect(res.body.data).to.have.lengthOf(2) + const body = await server.captionsCommand.listVideoCaptions({ videoId: videoUUID }) + expect(body.total).to.equal(2) + expect(body.data).to.have.lengthOf(2) - const caption1: VideoCaption = res.body.data[0] + const caption1 = body.data[0] expect(caption1.language.id).to.equal('ar') expect(caption1.language.label).to.equal('Arabic') expect(caption1.captionPath).to.match(new RegExp('^/lazy-static/video-captions/' + uuidRegex + '-ar.vtt$')) @@ -172,18 +159,18 @@ describe('Test video captions', function () { it('Should remove one caption', async function () { this.timeout(30000) - await deleteVideoCaption(servers[0].url, servers[0].accessToken, videoUUID, 'ar') + await servers[0].captionsCommand.deleteVideoCaption({ videoId: videoUUID, language: 'ar' }) await waitJobs(servers) }) it('Should only list the caption that was not deleted', async function () { for (const server of servers) { - const res = await listVideoCaptions(server.url, videoUUID) - expect(res.body.total).to.equal(1) - expect(res.body.data).to.have.lengthOf(1) + const body = await server.captionsCommand.listVideoCaptions({ videoId: videoUUID }) + expect(body.total).to.equal(1) + expect(body.data).to.have.lengthOf(1) - const caption: VideoCaption = res.body.data[0] + const caption = body.data[0] expect(caption.language.id).to.equal('zh') expect(caption.language.label).to.equal('Chinese') diff --git a/server/tests/api/videos/video-imports.ts b/server/tests/api/videos/video-imports.ts index a4a9132b4..14aed604f 100644 --- a/server/tests/api/videos/video-imports.ts +++ b/server/tests/api/videos/video-imports.ts @@ -11,7 +11,6 @@ import { getVideo, getVideosList, immutableAssign, - listVideoCaptions, ServerInfo, setAccessTokensToServers, testCaptionFile @@ -25,7 +24,7 @@ import { getYoutubeVideoUrl, importVideo } from '../../../../shared/extra-utils/videos/video-imports' -import { VideoCaption, VideoDetails, VideoImport, VideoPrivacy, VideoResolution } from '../../../../shared/models/videos' +import { VideoDetails, VideoImport, VideoPrivacy, VideoResolution } from '../../../../shared/models/videos' const expect = chai.expect @@ -36,8 +35,8 @@ describe('Test video imports', function () { if (areHttpImportTestsDisabled()) return - async function checkVideosServer1 (url: string, idHttp: string, idMagnet: string, idTorrent: string) { - const resHttp = await getVideo(url, idHttp) + async function checkVideosServer1 (server: ServerInfo, idHttp: string, idMagnet: string, idTorrent: string) { + const resHttp = await getVideo(server.url, idHttp) const videoHttp: VideoDetails = resHttp.body expect(videoHttp.name).to.equal('small video - youtube') @@ -55,9 +54,9 @@ describe('Test video imports', function () { expect(originallyPublishedAt.getMonth()).to.equal(0) expect(originallyPublishedAt.getFullYear()).to.equal(2019) - const resMagnet = await getVideo(url, idMagnet) + const resMagnet = await getVideo(server.url, idMagnet) const videoMagnet: VideoDetails = resMagnet.body - const resTorrent = await getVideo(url, idTorrent) + const resTorrent = await getVideo(server.url, idTorrent) const videoTorrent: VideoDetails = resTorrent.body for (const video of [ videoMagnet, videoTorrent ]) { @@ -73,12 +72,12 @@ describe('Test video imports', function () { expect(videoTorrent.name).to.contain('你好 世界 720p.mp4') expect(videoMagnet.name).to.contain('super peertube2 video') - const resCaptions = await listVideoCaptions(url, idHttp) - expect(resCaptions.body.total).to.equal(2) + const bodyCaptions = await server.captionsCommand.listVideoCaptions({ videoId: idHttp }) + expect(bodyCaptions.total).to.equal(2) } - async function checkVideoServer2 (url: string, id: number | string) { - const res = await getVideo(url, id) + async function checkVideoServer2 (server: ServerInfo, id: number | string) { + const res = await getVideo(server.url, id) const video: VideoDetails = res.body expect(video.name).to.equal('my super name') @@ -91,8 +90,8 @@ describe('Test video imports', function () { expect(video.files).to.have.lengthOf(1) - const resCaptions = await listVideoCaptions(url, id) - expect(resCaptions.body.total).to.equal(2) + const bodyCaptions = await server.captionsCommand.listVideoCaptions({ videoId: id }) + expect(bodyCaptions.total).to.equal(2) } before(async function () { @@ -135,8 +134,8 @@ describe('Test video imports', function () { await testImage(servers[0].url, 'video_import_thumbnail', res.body.video.thumbnailPath) await testImage(servers[0].url, 'video_import_preview', res.body.video.previewPath) - const resCaptions = await listVideoCaptions(servers[0].url, res.body.video.id) - const videoCaptions: VideoCaption[] = resCaptions.body.data + const bodyCaptions = await servers[0].captionsCommand.listVideoCaptions({ videoId: res.body.video.id }) + const videoCaptions = bodyCaptions.data expect(videoCaptions).to.have.lengthOf(2) const enCaption = videoCaptions.find(caption => caption.language.id === 'en') @@ -241,7 +240,7 @@ Ajouter un sous-titre est vraiment facile`) expect(res.body.data).to.have.lengthOf(3) const [ videoHttp, videoMagnet, videoTorrent ] = res.body.data - await checkVideosServer1(server.url, videoHttp.uuid, videoMagnet.uuid, videoTorrent.uuid) + await checkVideosServer1(server, videoHttp.uuid, videoMagnet.uuid, videoTorrent.uuid) } }) @@ -273,10 +272,10 @@ Ajouter un sous-titre est vraiment facile`) expect(res.body.total).to.equal(4) expect(res.body.data).to.have.lengthOf(4) - await checkVideoServer2(server.url, res.body.data[0].uuid) + await checkVideoServer2(server, res.body.data[0].uuid) const [ , videoHttp, videoMagnet, videoTorrent ] = res.body.data - await checkVideosServer1(server.url, videoHttp.uuid, videoMagnet.uuid, videoTorrent.uuid) + await checkVideosServer1(server, videoHttp.uuid, videoMagnet.uuid, videoTorrent.uuid) } }) -- cgit v1.2.3 From 72cbfc5695ec5ebdb9721d3648218f63feeaeac5 Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Thu, 8 Jul 2021 13:56:04 +0200 Subject: Introduce change ownership command --- server/tests/api/videos/video-change-ownership.ts | 185 ++++++++++++---------- 1 file changed, 100 insertions(+), 85 deletions(-) (limited to 'server/tests/api') diff --git a/server/tests/api/videos/video-change-ownership.ts b/server/tests/api/videos/video-change-ownership.ts index 3c33cf015..1b81fe047 100644 --- a/server/tests/api/videos/video-change-ownership.ts +++ b/server/tests/api/videos/video-change-ownership.ts @@ -4,8 +4,7 @@ import 'mocha' import * as chai from 'chai' import { HttpStatusCode } from '../../../../shared/core-utils/miscs/http-error-codes' import { - acceptChangeOwnership, - changeVideoOwnership, + ChangeOwnershipCommand, cleanupTests, createUser, doubleFollow, @@ -13,9 +12,7 @@ import { flushAndRunServer, getMyUserInformation, getVideo, - getVideoChangeOwnershipList, getVideosList, - refuseChangeOwnership, ServerInfo, setAccessTokensToServers, setDefaultVideoChannel, @@ -39,16 +36,18 @@ describe('Test video change ownership - nominal', function () { password: 'My other password' } - let firstUserAccessToken = '' + let firstUserToken = '' let firstUserChannelId: number - let secondUserAccessToken = '' + let secondUserToken = '' let secondUserChannelId: number - let lastRequestChangeOwnershipId = '' + let lastRequestId: number let liveId: number + let command: ChangeOwnershipCommand + before(async function () { this.timeout(50000) @@ -83,17 +82,17 @@ describe('Test video change ownership - nominal', function () { videoQuota: videoQuota }) - firstUserAccessToken = await userLogin(servers[0], firstUser) - secondUserAccessToken = await userLogin(servers[0], secondUser) + firstUserToken = await userLogin(servers[0], firstUser) + secondUserToken = await userLogin(servers[0], secondUser) { - const res = await getMyUserInformation(servers[0].url, firstUserAccessToken) + const res = await getMyUserInformation(servers[0].url, firstUserToken) const firstUserInformation: User = res.body firstUserChannelId = firstUserInformation.videoChannels[0].id } { - const res = await getMyUserInformation(servers[0].url, secondUserAccessToken) + const res = await getMyUserInformation(servers[0].url, secondUserToken) const secondUserInformation: User = res.body secondUserChannelId = secondUserInformation.videoChannels[0].id } @@ -103,7 +102,7 @@ describe('Test video change ownership - nominal', function () { name: 'my super name', description: 'my super description' } - const res = await uploadVideo(servers[0].url, firstUserAccessToken, videoAttributes) + const res = await uploadVideo(servers[0].url, firstUserToken, videoAttributes) const resVideo = await getVideo(servers[0].url, res.body.video.id) servers[0].video = resVideo.body @@ -111,116 +110,129 @@ describe('Test video change ownership - nominal', function () { { const attributes = { name: 'live', channelId: firstUserChannelId, privacy: VideoPrivacy.PUBLIC } - const video = await servers[0].liveCommand.create({ token: firstUserAccessToken, fields: attributes }) + const video = await servers[0].liveCommand.create({ token: firstUserToken, fields: attributes }) liveId = video.id } + command = servers[0].changeOwnershipCommand + await doubleFollow(servers[0], servers[1]) }) it('Should not have video change ownership', async function () { - const resFirstUser = await getVideoChangeOwnershipList(servers[0].url, firstUserAccessToken) + { + const body = await command.list({ token: firstUserToken }) - expect(resFirstUser.body.total).to.equal(0) - expect(resFirstUser.body.data).to.be.an('array') - expect(resFirstUser.body.data.length).to.equal(0) + expect(body.total).to.equal(0) + expect(body.data).to.be.an('array') + expect(body.data.length).to.equal(0) + } - const resSecondUser = await getVideoChangeOwnershipList(servers[0].url, secondUserAccessToken) + { + const body = await command.list({ token: secondUserToken }) - expect(resSecondUser.body.total).to.equal(0) - expect(resSecondUser.body.data).to.be.an('array') - expect(resSecondUser.body.data.length).to.equal(0) + expect(body.total).to.equal(0) + expect(body.data).to.be.an('array') + expect(body.data.length).to.equal(0) + } }) it('Should send a request to change ownership of a video', async function () { this.timeout(15000) - await changeVideoOwnership(servers[0].url, firstUserAccessToken, servers[0].video.id, secondUser.username) + await command.create({ token: firstUserToken, videoId: servers[0].video.id, username: secondUser.username }) }) it('Should only return a request to change ownership for the second user', async function () { - const resFirstUser = await getVideoChangeOwnershipList(servers[0].url, firstUserAccessToken) + { + const body = await command.list({ token: firstUserToken }) - expect(resFirstUser.body.total).to.equal(0) - expect(resFirstUser.body.data).to.be.an('array') - expect(resFirstUser.body.data.length).to.equal(0) + expect(body.total).to.equal(0) + expect(body.data).to.be.an('array') + expect(body.data.length).to.equal(0) + } - const resSecondUser = await getVideoChangeOwnershipList(servers[0].url, secondUserAccessToken) + { + const body = await command.list({ token: secondUserToken }) - expect(resSecondUser.body.total).to.equal(1) - expect(resSecondUser.body.data).to.be.an('array') - expect(resSecondUser.body.data.length).to.equal(1) + expect(body.total).to.equal(1) + expect(body.data).to.be.an('array') + expect(body.data.length).to.equal(1) - lastRequestChangeOwnershipId = resSecondUser.body.data[0].id + lastRequestId = body.data[0].id + } }) it('Should accept the same change ownership request without crashing', async function () { this.timeout(10000) - await changeVideoOwnership(servers[0].url, firstUserAccessToken, servers[0].video.id, secondUser.username) + await command.create({ token: firstUserToken, videoId: servers[0].video.id, username: secondUser.username }) }) it('Should not create multiple change ownership requests while one is waiting', async function () { this.timeout(10000) - const resSecondUser = await getVideoChangeOwnershipList(servers[0].url, secondUserAccessToken) + const body = await command.list({ token: secondUserToken }) - expect(resSecondUser.body.total).to.equal(1) - expect(resSecondUser.body.data).to.be.an('array') - expect(resSecondUser.body.data.length).to.equal(1) + expect(body.total).to.equal(1) + expect(body.data).to.be.an('array') + expect(body.data.length).to.equal(1) }) it('Should not be possible to refuse the change of ownership from first user', async function () { this.timeout(10000) - await refuseChangeOwnership(servers[0].url, firstUserAccessToken, lastRequestChangeOwnershipId, HttpStatusCode.FORBIDDEN_403) + await command.refuse({ token: firstUserToken, ownershipId: lastRequestId, expectedStatus: HttpStatusCode.FORBIDDEN_403 }) }) it('Should be possible to refuse the change of ownership from second user', async function () { this.timeout(10000) - await refuseChangeOwnership(servers[0].url, secondUserAccessToken, lastRequestChangeOwnershipId) + await command.refuse({ token: secondUserToken, ownershipId: lastRequestId }) }) it('Should send a new request to change ownership of a video', async function () { this.timeout(15000) - await changeVideoOwnership(servers[0].url, firstUserAccessToken, servers[0].video.id, secondUser.username) + await command.create({ token: firstUserToken, videoId: servers[0].video.id, username: secondUser.username }) }) it('Should return two requests to change ownership for the second user', async function () { - const resFirstUser = await getVideoChangeOwnershipList(servers[0].url, firstUserAccessToken) + { + const body = await command.list({ token: firstUserToken }) - expect(resFirstUser.body.total).to.equal(0) - expect(resFirstUser.body.data).to.be.an('array') - expect(resFirstUser.body.data.length).to.equal(0) + expect(body.total).to.equal(0) + expect(body.data).to.be.an('array') + expect(body.data.length).to.equal(0) + } - const resSecondUser = await getVideoChangeOwnershipList(servers[0].url, secondUserAccessToken) + { + const body = await command.list({ token: secondUserToken }) - expect(resSecondUser.body.total).to.equal(2) - expect(resSecondUser.body.data).to.be.an('array') - expect(resSecondUser.body.data.length).to.equal(2) + expect(body.total).to.equal(2) + expect(body.data).to.be.an('array') + expect(body.data.length).to.equal(2) - lastRequestChangeOwnershipId = resSecondUser.body.data[0].id + lastRequestId = body.data[0].id + } }) it('Should not be possible to accept the change of ownership from first user', async function () { this.timeout(10000) - await acceptChangeOwnership( - servers[0].url, - firstUserAccessToken, - lastRequestChangeOwnershipId, - secondUserChannelId, - HttpStatusCode.FORBIDDEN_403 - ) + await command.accept({ + token: firstUserToken, + ownershipId: lastRequestId, + channelId: secondUserChannelId, + expectedStatus: HttpStatusCode.FORBIDDEN_403 + }) }) it('Should be possible to accept the change of ownership from second user', async function () { this.timeout(10000) - await acceptChangeOwnership(servers[0].url, secondUserAccessToken, lastRequestChangeOwnershipId, secondUserChannelId) + await command.accept({ token: secondUserToken, ownershipId: lastRequestId, channelId: secondUserChannelId }) await waitJobs(servers) }) @@ -240,20 +252,20 @@ describe('Test video change ownership - nominal', function () { it('Should send a request to change ownership of a live', async function () { this.timeout(15000) - await changeVideoOwnership(servers[0].url, firstUserAccessToken, liveId, secondUser.username) + await command.create({ token: firstUserToken, videoId: liveId, username: secondUser.username }) - const resSecondUser = await getVideoChangeOwnershipList(servers[0].url, secondUserAccessToken) + const body = await command.list({ token: secondUserToken }) - expect(resSecondUser.body.total).to.equal(3) - expect(resSecondUser.body.data.length).to.equal(3) + expect(body.total).to.equal(3) + expect(body.data.length).to.equal(3) - lastRequestChangeOwnershipId = resSecondUser.body.data[0].id + lastRequestId = body.data[0].id }) it('Should accept a live ownership change', async function () { this.timeout(20000) - await acceptChangeOwnership(servers[0].url, secondUserAccessToken, lastRequestChangeOwnershipId, secondUserChannelId) + await command.accept({ token: secondUserToken, ownershipId: lastRequestId, channelId: secondUserChannelId }) await waitJobs(servers) @@ -283,9 +295,9 @@ describe('Test video change ownership - quota too small', function () { username: 'second', password: 'My other password' } - let firstUserAccessToken = '' - let secondUserAccessToken = '' - let lastRequestChangeOwnershipId = '' + let firstUserToken = '' + let secondUserToken = '' + let lastRequestId: number before(async function () { this.timeout(50000) @@ -311,15 +323,15 @@ describe('Test video change ownership - quota too small', function () { videoQuota: limitedVideoQuota }) - firstUserAccessToken = await userLogin(server, firstUser) - secondUserAccessToken = await userLogin(server, secondUser) + firstUserToken = await userLogin(server, firstUser) + secondUserToken = await userLogin(server, secondUser) // Upload some videos on the server const video1Attributes = { name: 'my super name', description: 'my super description' } - await uploadVideo(server.url, firstUserAccessToken, video1Attributes) + await uploadVideo(server.url, firstUserToken, video1Attributes) await waitJobs(server) @@ -334,39 +346,42 @@ describe('Test video change ownership - quota too small', function () { it('Should send a request to change ownership of a video', async function () { this.timeout(15000) - await changeVideoOwnership(server.url, firstUserAccessToken, server.video.id, secondUser.username) + await server.changeOwnershipCommand.create({ token: firstUserToken, videoId: server.video.id, username: secondUser.username }) }) it('Should only return a request to change ownership for the second user', async function () { - const resFirstUser = await getVideoChangeOwnershipList(server.url, firstUserAccessToken) + { + const body = await server.changeOwnershipCommand.list({ token: firstUserToken }) - expect(resFirstUser.body.total).to.equal(0) - expect(resFirstUser.body.data).to.be.an('array') - expect(resFirstUser.body.data.length).to.equal(0) + expect(body.total).to.equal(0) + expect(body.data).to.be.an('array') + expect(body.data.length).to.equal(0) + } - const resSecondUser = await getVideoChangeOwnershipList(server.url, secondUserAccessToken) + { + const body = await server.changeOwnershipCommand.list({ token: secondUserToken }) - expect(resSecondUser.body.total).to.equal(1) - expect(resSecondUser.body.data).to.be.an('array') - expect(resSecondUser.body.data.length).to.equal(1) + expect(body.total).to.equal(1) + expect(body.data).to.be.an('array') + expect(body.data.length).to.equal(1) - lastRequestChangeOwnershipId = resSecondUser.body.data[0].id + lastRequestId = body.data[0].id + } }) it('Should not be possible to accept the change of ownership from second user because of exceeded quota', async function () { this.timeout(10000) - const secondUserInformationResponse = await getMyUserInformation(server.url, secondUserAccessToken) + const secondUserInformationResponse = await getMyUserInformation(server.url, secondUserToken) const secondUserInformation: User = secondUserInformationResponse.body const channelId = secondUserInformation.videoChannels[0].id - await acceptChangeOwnership( - server.url, - secondUserAccessToken, - lastRequestChangeOwnershipId, + await server.changeOwnershipCommand.accept({ + token: secondUserToken, + ownershipId: lastRequestId, channelId, - HttpStatusCode.PAYLOAD_TOO_LARGE_413 - ) + expectedStatus: HttpStatusCode.PAYLOAD_TOO_LARGE_413 + }) }) after(async function () { -- 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/activitypub/client.ts | 6 +- server/tests/api/activitypub/refresher.ts | 22 +- server/tests/api/check-params/services.ts | 18 +- server/tests/api/check-params/video-playlists.ts | 347 +++++++------ .../search/search-activitypub-video-playlists.ts | 45 +- server/tests/api/search/search-playlists.ts | 26 +- server/tests/api/server/services.ts | 18 +- server/tests/api/server/stats.ts | 7 +- .../tests/api/videos/video-playlist-thumbnails.ts | 123 ++--- server/tests/api/videos/video-playlists.ts | 564 +++++++++------------ 10 files changed, 518 insertions(+), 658 deletions(-) (limited to 'server/tests/api') diff --git a/server/tests/api/activitypub/client.ts b/server/tests/api/activitypub/client.ts index be94e219c..e8536a214 100644 --- a/server/tests/api/activitypub/client.ts +++ b/server/tests/api/activitypub/client.ts @@ -6,7 +6,6 @@ import { VideoPlaylistPrivacy } from '@shared/models' import { HttpStatusCode } from '../../../../shared/core-utils/miscs/http-error-codes' import { cleanupTests, - createVideoPlaylist, doubleFollow, flushAndRunMultipleServers, makeActivityPubGetRequest, @@ -74,9 +73,8 @@ describe('Test activitypub', function () { } { - const playlistAttrs = { displayName: 'playlist', privacy: VideoPlaylistPrivacy.PUBLIC, videoChannelId: servers[0].videoChannel.id } - const resCreate = await createVideoPlaylist({ url: servers[0].url, token: servers[0].accessToken, playlistAttrs }) - playlist = resCreate.body.videoPlaylist + const attributes = { displayName: 'playlist', privacy: VideoPlaylistPrivacy.PUBLIC, videoChannelId: servers[0].videoChannel.id } + playlist = await servers[0].playlistsCommand.create({ attributes }) } await doubleFollow(servers[0], servers[1]) diff --git a/server/tests/api/activitypub/refresher.ts b/server/tests/api/activitypub/refresher.ts index 0d5452ea4..f295dfab7 100644 --- a/server/tests/api/activitypub/refresher.ts +++ b/server/tests/api/activitypub/refresher.ts @@ -5,12 +5,10 @@ import { HttpStatusCode } from '@shared/core-utils' import { cleanupTests, closeAllSequelize, - createVideoPlaylist, doubleFollow, flushAndRunMultipleServers, generateUserAccessToken, getVideo, - getVideoPlaylist, killallServers, reRunServer, ServerInfo, @@ -58,15 +56,15 @@ describe('Test AP refresher', function () { } { - const playlistAttrs = { displayName: 'playlist1', privacy: VideoPlaylistPrivacy.PUBLIC, videoChannelId: servers[1].videoChannel.id } - const res = await createVideoPlaylist({ url: servers[1].url, token: servers[1].accessToken, playlistAttrs }) - playlistUUID1 = res.body.videoPlaylist.uuid + const attributes = { displayName: 'playlist1', privacy: VideoPlaylistPrivacy.PUBLIC, videoChannelId: servers[1].videoChannel.id } + const created = await servers[1].playlistsCommand.create({ attributes }) + playlistUUID1 = created.uuid } { - const playlistAttrs = { displayName: 'playlist2', privacy: VideoPlaylistPrivacy.PUBLIC, videoChannelId: servers[1].videoChannel.id } - const res = await createVideoPlaylist({ url: servers[1].url, token: servers[1].accessToken, playlistAttrs }) - playlistUUID2 = res.body.videoPlaylist.uuid + const attributes = { displayName: 'playlist2', privacy: VideoPlaylistPrivacy.PUBLIC, videoChannelId: servers[1].videoChannel.id } + const created = await servers[1].playlistsCommand.create({ attributes }) + playlistUUID2 = created.uuid } await doubleFollow(servers[0], servers[1]) @@ -144,13 +142,13 @@ describe('Test AP refresher', function () { // Change UUID so the remote server returns a 404 await setPlaylistField(servers[1].internalServerNumber, playlistUUID2, 'uuid', '304afe4f-39f9-4d49-8ed7-ac57b86b178e') - await getVideoPlaylist(servers[0].url, playlistUUID1) - await getVideoPlaylist(servers[0].url, playlistUUID2) + await servers[0].playlistsCommand.get({ playlistId: playlistUUID1 }) + await servers[0].playlistsCommand.get({ playlistId: playlistUUID2 }) await waitJobs(servers) - await getVideoPlaylist(servers[0].url, playlistUUID1, HttpStatusCode.OK_200) - await getVideoPlaylist(servers[0].url, playlistUUID2, HttpStatusCode.NOT_FOUND_404) + await servers[0].playlistsCommand.get({ playlistId: playlistUUID1, expectedStatus: HttpStatusCode.OK_200 }) + await servers[0].playlistsCommand.get({ playlistId: playlistUUID2, expectedStatus: HttpStatusCode.NOT_FOUND_404 }) }) }) 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 }) }) }) diff --git a/server/tests/api/search/search-activitypub-video-playlists.ts b/server/tests/api/search/search-activitypub-video-playlists.ts index 1df18173a..cb7582d29 100644 --- a/server/tests/api/search/search-activitypub-video-playlists.ts +++ b/server/tests/api/search/search-activitypub-video-playlists.ts @@ -3,12 +3,8 @@ import 'mocha' import * as chai from 'chai' import { - addVideoInPlaylist, cleanupTests, - createVideoPlaylist, - deleteVideoPlaylist, flushAndRunMultipleServers, - getVideoPlaylistsList, SearchCommand, ServerInfo, setAccessTokensToServers, @@ -46,16 +42,11 @@ describe('Test ActivityPub playlists search', function () { privacy: VideoPlaylistPrivacy.PUBLIC, videoChannelId: servers[0].videoChannel.id } - const res = await createVideoPlaylist({ url: servers[0].url, token: servers[0].accessToken, playlistAttrs: attributes }) - playlistServer1UUID = res.body.videoPlaylist.uuid + const created = await servers[0].playlistsCommand.create({ attributes }) + playlistServer1UUID = created.uuid for (const videoId of [ video1, video2 ]) { - await addVideoInPlaylist({ - url: servers[0].url, - token: servers[0].accessToken, - playlistId: playlistServer1UUID, - elementAttrs: { videoId } - }) + await servers[0].playlistsCommand.addElement({ playlistId: playlistServer1UUID, attributes: { videoId } }) } } @@ -68,15 +59,10 @@ describe('Test ActivityPub playlists search', function () { privacy: VideoPlaylistPrivacy.PUBLIC, videoChannelId: servers[1].videoChannel.id } - const res = await createVideoPlaylist({ url: servers[1].url, token: servers[1].accessToken, playlistAttrs: attributes }) - playlistServer2UUID = res.body.videoPlaylist.uuid - - await addVideoInPlaylist({ - url: servers[1].url, - token: servers[1].accessToken, - playlistId: playlistServer2UUID, - elementAttrs: { videoId } - }) + const created = await servers[1].playlistsCommand.create({ attributes }) + playlistServer2UUID = created.uuid + + await servers[1].playlistsCommand.addElement({ playlistId: playlistServer2UUID, attributes: { videoId } }) } await waitJobs(servers) @@ -154,21 +140,16 @@ describe('Test ActivityPub playlists search', function () { }) it('Should not list this remote playlist', async function () { - const res = await getVideoPlaylistsList(servers[0].url, 0, 10) - expect(res.body.total).to.equal(1) - expect(res.body.data).to.have.lengthOf(1) - expect(res.body.data[0].displayName).to.equal('playlist 1 on server 1') + const body = await servers[0].playlistsCommand.list({ start: 0, count: 10 }) + expect(body.total).to.equal(1) + expect(body.data).to.have.lengthOf(1) + expect(body.data[0].displayName).to.equal('playlist 1 on server 1') }) it('Should update the playlist of server 2, and refresh it on server 1', async function () { this.timeout(60000) - await addVideoInPlaylist({ - url: servers[1].url, - token: servers[1].accessToken, - playlistId: playlistServer2UUID, - elementAttrs: { videoId: video2Server2 } - }) + await servers[1].playlistsCommand.addElement({ playlistId: playlistServer2UUID, attributes: { videoId: video2Server2 } }) await waitJobs(servers) // Expire playlist @@ -192,7 +173,7 @@ describe('Test ActivityPub playlists search', function () { it('Should delete playlist of server 2, and delete it on server 1', async function () { this.timeout(60000) - await deleteVideoPlaylist(servers[1].url, servers[1].accessToken, playlistServer2UUID) + await servers[1].playlistsCommand.delete({ playlistId: playlistServer2UUID }) await waitJobs(servers) // Expiration diff --git a/server/tests/api/search/search-playlists.ts b/server/tests/api/search/search-playlists.ts index 1862ecd31..517884503 100644 --- a/server/tests/api/search/search-playlists.ts +++ b/server/tests/api/search/search-playlists.ts @@ -4,9 +4,7 @@ import 'mocha' import * as chai from 'chai' import { VideoPlaylistPrivacy } from '@shared/models' import { - addVideoInPlaylist, cleanupTests, - createVideoPlaylist, flushAndRunServer, SearchCommand, ServerInfo, @@ -37,14 +35,9 @@ describe('Test playlists search', function () { privacy: VideoPlaylistPrivacy.PUBLIC, videoChannelId: server.videoChannel.id } - const res = await createVideoPlaylist({ url: server.url, token: server.accessToken, playlistAttrs: attributes }) - - await addVideoInPlaylist({ - url: server.url, - token: server.accessToken, - playlistId: res.body.videoPlaylist.id, - elementAttrs: { videoId } - }) + const created = await server.playlistsCommand.create({ attributes }) + + await server.playlistsCommand.addElement({ playlistId: created.id, attributes: { videoId } }) } { @@ -53,14 +46,9 @@ describe('Test playlists search', function () { privacy: VideoPlaylistPrivacy.PUBLIC, videoChannelId: server.videoChannel.id } - const res = await createVideoPlaylist({ url: server.url, token: server.accessToken, playlistAttrs: attributes }) - - await addVideoInPlaylist({ - url: server.url, - token: server.accessToken, - playlistId: res.body.videoPlaylist.id, - elementAttrs: { videoId } - }) + const created = await server.playlistsCommand.create({ attributes }) + + await server.playlistsCommand.addElement({ playlistId: created.id, attributes: { videoId } }) } { @@ -69,7 +57,7 @@ describe('Test playlists search', function () { privacy: VideoPlaylistPrivacy.PUBLIC, videoChannelId: server.videoChannel.id } - await createVideoPlaylist({ url: server.url, token: server.accessToken, playlistAttrs: attributes }) + await server.playlistsCommand.create({ attributes }) } command = server.searchCommand diff --git a/server/tests/api/server/services.ts b/server/tests/api/server/services.ts index 0adf6b667..77b95de10 100644 --- a/server/tests/api/server/services.ts +++ b/server/tests/api/server/services.ts @@ -4,8 +4,6 @@ import 'mocha' import * as chai from 'chai' import { Video, VideoPlaylistPrivacy } from '@shared/models' import { - addVideoInPlaylist, - createVideoPlaylist, getVideosList, ServerInfo, setAccessTokensToServers, @@ -41,24 +39,20 @@ describe('Test services', function () { } { - const res = await createVideoPlaylist({ - url: server.url, - token: server.accessToken, - playlistAttrs: { + const created = await server.playlistsCommand.create({ + attributes: { displayName: 'The Life and Times of Scrooge McDuck', privacy: VideoPlaylistPrivacy.PUBLIC, videoChannelId: server.videoChannel.id } }) - playlistUUID = res.body.videoPlaylist.uuid + playlistUUID = created.uuid playlistDisplayName = 'The Life and Times of Scrooge McDuck' - await addVideoInPlaylist({ - url: server.url, - token: server.accessToken, - playlistId: res.body.videoPlaylist.id, - elementAttrs: { + await server.playlistsCommand.addElement({ + playlistId: created.id, + attributes: { videoId: video.id } }) diff --git a/server/tests/api/server/stats.ts b/server/tests/api/server/stats.ts index f01188d67..c877a65eb 100644 --- a/server/tests/api/server/stats.ts +++ b/server/tests/api/server/stats.ts @@ -7,7 +7,6 @@ import { addVideoCommentThread, cleanupTests, createUser, - createVideoPlaylist, doubleFollow, flushAndRunMultipleServers, ServerInfo, @@ -178,10 +177,8 @@ describe('Test stats (excluding redundancy)', function () { } { - await createVideoPlaylist({ - url: server.url, - token: server.accessToken, - playlistAttrs: { + await server.playlistsCommand.create({ + attributes: { displayName: 'playlist for count', privacy: VideoPlaylistPrivacy.PUBLIC, videoChannelId: channelId diff --git a/server/tests/api/videos/video-playlist-thumbnails.ts b/server/tests/api/videos/video-playlist-thumbnails.ts index a93a0b7de..af5df8d90 100644 --- a/server/tests/api/videos/video-playlist-thumbnails.ts +++ b/server/tests/api/videos/video-playlist-thumbnails.ts @@ -1,16 +1,11 @@ /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */ -import * as chai from 'chai' import 'mocha' +import * as chai from 'chai' import { - addVideoInPlaylist, cleanupTests, - createVideoPlaylist, doubleFollow, flushAndRunMultipleServers, - getVideoPlaylistsList, - removeVideoFromPlaylist, - reorderVideosPlaylist, ServerInfo, setAccessTokensToServers, setDefaultVideoChannel, @@ -25,8 +20,8 @@ const expect = chai.expect describe('Playlist thumbnail', function () { let servers: ServerInfo[] = [] - let playlistWithoutThumbnail: number - let playlistWithThumbnail: number + let playlistWithoutThumbnailId: number + let playlistWithThumbnailId: number let withThumbnailE1: number let withThumbnailE2: number @@ -37,15 +32,15 @@ describe('Playlist thumbnail', function () { let video2: number async function getPlaylistWithoutThumbnail (server: ServerInfo) { - const res = await getVideoPlaylistsList(server.url, 0, 10) + const body = await server.playlistsCommand.list({ start: 0, count: 10 }) - return res.body.data.find(p => p.displayName === 'playlist without thumbnail') + return body.data.find(p => p.displayName === 'playlist without thumbnail') } async function getPlaylistWithThumbnail (server: ServerInfo) { - const res = await getVideoPlaylistsList(server.url, 0, 10) + const body = await server.playlistsCommand.list({ start: 0, count: 10 }) - return res.body.data.find(p => p.displayName === 'playlist with thumbnail') + return body.data.find(p => p.displayName === 'playlist with thumbnail') } before(async function () { @@ -69,24 +64,20 @@ describe('Playlist thumbnail', function () { it('Should automatically update the thumbnail when adding an element', async function () { this.timeout(30000) - const res = await createVideoPlaylist({ - url: servers[1].url, - token: servers[1].accessToken, - playlistAttrs: { + const created = await servers[1].playlistsCommand.create({ + attributes: { displayName: 'playlist without thumbnail', privacy: VideoPlaylistPrivacy.PUBLIC, videoChannelId: servers[1].videoChannel.id } }) - playlistWithoutThumbnail = res.body.videoPlaylist.id + playlistWithoutThumbnailId = created.id - const res2 = await addVideoInPlaylist({ - url: servers[1].url, - token: servers[1].accessToken, - playlistId: playlistWithoutThumbnail, - elementAttrs: { videoId: video1 } + const added = await servers[1].playlistsCommand.addElement({ + playlistId: playlistWithoutThumbnailId, + attributes: { videoId: video1 } }) - withoutThumbnailE1 = res2.body.videoPlaylistElement.id + withoutThumbnailE1 = added.id await waitJobs(servers) @@ -99,25 +90,21 @@ describe('Playlist thumbnail', function () { it('Should not update the thumbnail if we explicitly uploaded a thumbnail', async function () { this.timeout(30000) - const res = await createVideoPlaylist({ - url: servers[1].url, - token: servers[1].accessToken, - playlistAttrs: { + const created = await servers[1].playlistsCommand.create({ + attributes: { displayName: 'playlist with thumbnail', privacy: VideoPlaylistPrivacy.PUBLIC, videoChannelId: servers[1].videoChannel.id, thumbnailfile: 'thumbnail.jpg' } }) - playlistWithThumbnail = res.body.videoPlaylist.id + playlistWithThumbnailId = created.id - const res2 = await addVideoInPlaylist({ - url: servers[1].url, - token: servers[1].accessToken, - playlistId: playlistWithThumbnail, - elementAttrs: { videoId: video1 } + const added = await servers[1].playlistsCommand.addElement({ + playlistId: playlistWithThumbnailId, + attributes: { videoId: video1 } }) - withThumbnailE1 = res2.body.videoPlaylistElement.id + withThumbnailE1 = added.id await waitJobs(servers) @@ -130,19 +117,15 @@ describe('Playlist thumbnail', function () { it('Should automatically update the thumbnail when moving the first element', async function () { this.timeout(30000) - const res = await addVideoInPlaylist({ - url: servers[1].url, - token: servers[1].accessToken, - playlistId: playlistWithoutThumbnail, - elementAttrs: { videoId: video2 } + const added = await servers[1].playlistsCommand.addElement({ + playlistId: playlistWithoutThumbnailId, + attributes: { videoId: video2 } }) - withoutThumbnailE2 = res.body.videoPlaylistElement.id + withoutThumbnailE2 = added.id - await reorderVideosPlaylist({ - url: servers[1].url, - token: servers[1].accessToken, - playlistId: playlistWithoutThumbnail, - elementAttrs: { + await servers[1].playlistsCommand.reorderElements({ + playlistId: playlistWithoutThumbnailId, + attributes: { startPosition: 1, insertAfterPosition: 2 } @@ -159,19 +142,15 @@ describe('Playlist thumbnail', function () { it('Should not update the thumbnail when moving the first element if we explicitly uploaded a thumbnail', async function () { this.timeout(30000) - const res = await addVideoInPlaylist({ - url: servers[1].url, - token: servers[1].accessToken, - playlistId: playlistWithThumbnail, - elementAttrs: { videoId: video2 } + const added = await servers[1].playlistsCommand.addElement({ + playlistId: playlistWithThumbnailId, + attributes: { videoId: video2 } }) - withThumbnailE2 = res.body.videoPlaylistElement.id + withThumbnailE2 = added.id - await reorderVideosPlaylist({ - url: servers[1].url, - token: servers[1].accessToken, - playlistId: playlistWithThumbnail, - elementAttrs: { + await servers[1].playlistsCommand.reorderElements({ + playlistId: playlistWithThumbnailId, + attributes: { startPosition: 1, insertAfterPosition: 2 } @@ -188,11 +167,9 @@ describe('Playlist thumbnail', function () { it('Should automatically update the thumbnail when deleting the first element', async function () { this.timeout(30000) - await removeVideoFromPlaylist({ - url: servers[1].url, - token: servers[1].accessToken, - playlistId: playlistWithoutThumbnail, - playlistElementId: withoutThumbnailE1 + await servers[1].playlistsCommand.removeElement({ + playlistId: playlistWithoutThumbnailId, + elementId: withoutThumbnailE1 }) await waitJobs(servers) @@ -206,11 +183,9 @@ describe('Playlist thumbnail', function () { it('Should not update the thumbnail when deleting the first element if we explicitly uploaded a thumbnail', async function () { this.timeout(30000) - await removeVideoFromPlaylist({ - url: servers[1].url, - token: servers[1].accessToken, - playlistId: playlistWithThumbnail, - playlistElementId: withThumbnailE1 + await servers[1].playlistsCommand.removeElement({ + playlistId: playlistWithThumbnailId, + elementId: withThumbnailE1 }) await waitJobs(servers) @@ -224,11 +199,9 @@ describe('Playlist thumbnail', function () { it('Should the thumbnail when we delete the last element', async function () { this.timeout(30000) - await removeVideoFromPlaylist({ - url: servers[1].url, - token: servers[1].accessToken, - playlistId: playlistWithoutThumbnail, - playlistElementId: withoutThumbnailE2 + await servers[1].playlistsCommand.removeElement({ + playlistId: playlistWithoutThumbnailId, + elementId: withoutThumbnailE2 }) await waitJobs(servers) @@ -242,11 +215,9 @@ describe('Playlist thumbnail', function () { it('Should not update the thumbnail when we delete the last element if we explicitly uploaded a thumbnail', async function () { this.timeout(30000) - await removeVideoFromPlaylist({ - url: servers[1].url, - token: servers[1].accessToken, - playlistId: playlistWithThumbnail, - playlistElementId: withThumbnailE2 + await servers[1].playlistsCommand.removeElement({ + playlistId: playlistWithThumbnailId, + elementId: withThumbnailE2 }) await waitJobs(servers) diff --git a/server/tests/api/videos/video-playlists.ts b/server/tests/api/videos/video-playlists.ts index 069450453..4de6b3abf 100644 --- a/server/tests/api/videos/video-playlists.ts +++ b/server/tests/api/videos/video-playlists.ts @@ -5,37 +5,22 @@ import * as chai from 'chai' import { HttpStatusCode } from '@shared/core-utils' import { addVideoChannel, - addVideoInPlaylist, checkPlaylistFilesWereRemoved, cleanupTests, createUser, - createVideoPlaylist, deleteVideoChannel, - deleteVideoPlaylist, doubleFollow, - doVideosExistInMyPlaylist, flushAndRunMultipleServers, generateUserAccessToken, getAccessToken, - getAccountPlaylistsList, - getAccountPlaylistsListWithToken, getMyUserInformation, - getPlaylistVideos, - getVideoChannelPlaylistsList, - getVideoPlaylist, - getVideoPlaylistPrivacies, - getVideoPlaylistsList, - getVideoPlaylistWithToken, + PlaylistsCommand, removeUser, - removeVideoFromPlaylist, - reorderVideosPlaylist, ServerInfo, setAccessTokensToServers, setDefaultVideoChannel, testImage, updateVideo, - updateVideoPlaylist, - updateVideoPlaylistElement, uploadVideo, uploadVideoAndGetId, userLogin, @@ -44,10 +29,8 @@ import { } from '@shared/extra-utils' import { User, - VideoExistInPlaylist, VideoPlaylist, VideoPlaylistCreateResult, - VideoPlaylistElement, VideoPlaylistElementType, VideoPlaylistPrivacy, VideoPlaylistType, @@ -65,10 +48,10 @@ async function checkPlaylistElementType ( total: number ) { for (const server of servers) { - const res = await getPlaylistVideos(server.url, server.accessToken, playlistId, 0, 10) - expect(res.body.total).to.equal(total) + const body = await server.playlistsCommand.listVideos({ token: server.accessToken, playlistId, start: 0, count: 10 }) + expect(body.total).to.equal(total) - const videoElement: VideoPlaylistElement = res.body.data.find((e: VideoPlaylistElement) => e.position === position) + const videoElement = body.data.find(e => e.position === position) expect(videoElement.type).to.equal(type, 'On server ' + server.url) if (type === VideoPlaylistElementType.REGULAR) { @@ -85,7 +68,7 @@ describe('Test video playlists', function () { let playlistServer2Id1: number let playlistServer2Id2: number - let playlistServer2UUID2: number + let playlistServer2UUID2: string let playlistServer1Id: number let playlistServer1UUID: string @@ -97,7 +80,9 @@ describe('Test video playlists', function () { let nsfwVideoServer1: number - let userAccessTokenServer1: string + let userTokenServer1: string + + let commands: PlaylistsCommand[] before(async function () { this.timeout(120000) @@ -113,6 +98,8 @@ describe('Test video playlists', function () { // Server 1 and server 3 follow each other await doubleFollow(servers[0], servers[2]) + commands = servers.map(s => s.playlistsCommand) + { servers[0].videos = [] servers[1].videos = [] @@ -137,62 +124,60 @@ describe('Test video playlists', function () { username: 'user1', password: 'password' }) - userAccessTokenServer1 = await getAccessToken(servers[0].url, 'user1', 'password') + userTokenServer1 = await getAccessToken(servers[0].url, 'user1', 'password') } await waitJobs(servers) }) describe('Get default playlists', function () { + it('Should list video playlist privacies', async function () { - const res = await getVideoPlaylistPrivacies(servers[0].url) + const privacies = await commands[0].getPrivacies() - const privacies = res.body expect(Object.keys(privacies)).to.have.length.at.least(3) - expect(privacies[3]).to.equal('Private') }) it('Should list watch later playlist', async function () { - const url = servers[0].url - const accessToken = servers[0].accessToken + const token = servers[0].accessToken { - const res = await getAccountPlaylistsListWithToken(url, accessToken, 'root', 0, 5, VideoPlaylistType.WATCH_LATER) + const body = await commands[0].listByAccount({ token, handle: 'root', playlistType: VideoPlaylistType.WATCH_LATER }) - expect(res.body.total).to.equal(1) - expect(res.body.data).to.have.lengthOf(1) + expect(body.total).to.equal(1) + expect(body.data).to.have.lengthOf(1) - const playlist: VideoPlaylist = res.body.data[0] + const playlist = body.data[0] expect(playlist.displayName).to.equal('Watch later') expect(playlist.type.id).to.equal(VideoPlaylistType.WATCH_LATER) expect(playlist.type.label).to.equal('Watch later') } { - const res = await getAccountPlaylistsListWithToken(url, accessToken, 'root', 0, 5, VideoPlaylistType.REGULAR) + const body = await commands[0].listByAccount({ token, handle: 'root', playlistType: VideoPlaylistType.REGULAR }) - expect(res.body.total).to.equal(0) - expect(res.body.data).to.have.lengthOf(0) + expect(body.total).to.equal(0) + expect(body.data).to.have.lengthOf(0) } { - const res = await getAccountPlaylistsList(url, 'root', 0, 5) - expect(res.body.total).to.equal(0) - expect(res.body.data).to.have.lengthOf(0) + const body = await commands[0].listByAccount({ handle: 'root' }) + expect(body.total).to.equal(0) + expect(body.data).to.have.lengthOf(0) } }) it('Should get private playlist for a classic user', async function () { const token = await generateUserAccessToken(servers[0], 'toto') - const res = await getAccountPlaylistsListWithToken(servers[0].url, token, 'toto', 0, 5) + const body = await commands[0].listByAccount({ token, handle: 'toto' }) - expect(res.body.total).to.equal(1) - expect(res.body.data).to.have.lengthOf(1) + expect(body.total).to.equal(1) + expect(body.data).to.have.lengthOf(1) - const playlistId = res.body.data[0].id - await getPlaylistVideos(servers[0].url, token, playlistId, 0, 5) + const playlistId = body.data[0].id + await commands[0].listVideos({ token, playlistId }) }) }) @@ -201,10 +186,8 @@ describe('Test video playlists', function () { it('Should create a playlist on server 1 and have the playlist on server 2 and 3', async function () { this.timeout(30000) - await createVideoPlaylist({ - url: servers[0].url, - token: servers[0].accessToken, - playlistAttrs: { + await commands[0].create({ + attributes: { displayName: 'my super playlist', privacy: VideoPlaylistPrivacy.PUBLIC, description: 'my super description', @@ -218,14 +201,13 @@ describe('Test video playlists', function () { await wait(3000) for (const server of servers) { - const res = await getVideoPlaylistsList(server.url, 0, 5) - expect(res.body.total).to.equal(1) - expect(res.body.data).to.have.lengthOf(1) + const body = await server.playlistsCommand.list({ start: 0, count: 5 }) + expect(body.total).to.equal(1) + expect(body.data).to.have.lengthOf(1) - const playlistFromList = res.body.data[0] as VideoPlaylist + const playlistFromList = body.data[0] - const res2 = await getVideoPlaylist(server.url, playlistFromList.uuid) - const playlistFromGet = res2.body as VideoPlaylist + const playlistFromGet = await server.playlistsCommand.get({ playlistId: playlistFromList.uuid }) for (const playlist of [ playlistFromGet, playlistFromList ]) { expect(playlist.id).to.be.a('number') @@ -255,23 +237,19 @@ describe('Test video playlists', function () { this.timeout(30000) { - const res = await createVideoPlaylist({ - url: servers[1].url, - token: servers[1].accessToken, - playlistAttrs: { + const playlist = await servers[1].playlistsCommand.create({ + attributes: { displayName: 'playlist 2', privacy: VideoPlaylistPrivacy.PUBLIC, videoChannelId: servers[1].videoChannel.id } }) - playlistServer2Id1 = res.body.videoPlaylist.id + playlistServer2Id1 = playlist.id } { - const res = await createVideoPlaylist({ - url: servers[1].url, - token: servers[1].accessToken, - playlistAttrs: { + const playlist = await servers[1].playlistsCommand.create({ + attributes: { displayName: 'playlist 3', privacy: VideoPlaylistPrivacy.PUBLIC, thumbnailfile: 'thumbnail.jpg', @@ -279,22 +257,18 @@ describe('Test video playlists', function () { } }) - playlistServer2Id2 = res.body.videoPlaylist.id - playlistServer2UUID2 = res.body.videoPlaylist.uuid + playlistServer2Id2 = playlist.id + playlistServer2UUID2 = playlist.uuid } for (const id of [ playlistServer2Id1, playlistServer2Id2 ]) { - await addVideoInPlaylist({ - url: servers[1].url, - token: servers[1].accessToken, + await servers[1].playlistsCommand.addElement({ playlistId: id, - elementAttrs: { videoId: servers[1].videos[0].id, startTimestamp: 1, stopTimestamp: 2 } + attributes: { videoId: servers[1].videos[0].id, startTimestamp: 1, stopTimestamp: 2 } }) - await addVideoInPlaylist({ - url: servers[1].url, - token: servers[1].accessToken, + await servers[1].playlistsCommand.addElement({ playlistId: id, - elementAttrs: { videoId: servers[1].videos[1].id } + attributes: { videoId: servers[1].videos[1].id } }) } @@ -302,20 +276,20 @@ describe('Test video playlists', function () { await wait(3000) for (const server of [ servers[0], servers[1] ]) { - const res = await getVideoPlaylistsList(server.url, 0, 5) + const body = await server.playlistsCommand.list({ start: 0, count: 5 }) - const playlist2 = res.body.data.find(p => p.displayName === 'playlist 2') + const playlist2 = body.data.find(p => p.displayName === 'playlist 2') expect(playlist2).to.not.be.undefined await testImage(server.url, 'thumbnail-playlist', playlist2.thumbnailPath) - const playlist3 = res.body.data.find(p => p.displayName === 'playlist 3') + const playlist3 = body.data.find(p => p.displayName === 'playlist 3') expect(playlist3).to.not.be.undefined await testImage(server.url, 'thumbnail', playlist3.thumbnailPath) } - const res = await getVideoPlaylistsList(servers[2].url, 0, 5) - expect(res.body.data.find(p => p.displayName === 'playlist 2')).to.be.undefined - expect(res.body.data.find(p => p.displayName === 'playlist 3')).to.be.undefined + const body = await servers[2].playlistsCommand.list({ start: 0, count: 5 }) + expect(body.data.find(p => p.displayName === 'playlist 2')).to.be.undefined + expect(body.data.find(p => p.displayName === 'playlist 3')).to.be.undefined }) it('Should have the playlist on server 3 after a new follow', async function () { @@ -324,13 +298,13 @@ describe('Test video playlists', function () { // Server 2 and server 3 follow each other await doubleFollow(servers[1], servers[2]) - const res = await getVideoPlaylistsList(servers[2].url, 0, 5) + const body = await servers[2].playlistsCommand.list({ start: 0, count: 5 }) - const playlist2 = res.body.data.find(p => p.displayName === 'playlist 2') + const playlist2 = body.data.find(p => p.displayName === 'playlist 2') expect(playlist2).to.not.be.undefined await testImage(servers[2].url, 'thumbnail-playlist', playlist2.thumbnailPath) - expect(res.body.data.find(p => p.displayName === 'playlist 3')).to.not.be.undefined + expect(body.data.find(p => p.displayName === 'playlist 3')).to.not.be.undefined }) }) @@ -340,22 +314,20 @@ describe('Test video playlists', function () { this.timeout(30000) { - const res = await getVideoPlaylistsList(servers[2].url, 1, 2, 'createdAt') + const body = await servers[2].playlistsCommand.list({ start: 1, count: 2, sort: 'createdAt' }) + expect(body.total).to.equal(3) - expect(res.body.total).to.equal(3) - - const data: VideoPlaylist[] = res.body.data + const data = body.data expect(data).to.have.lengthOf(2) expect(data[0].displayName).to.equal('playlist 2') expect(data[1].displayName).to.equal('playlist 3') } { - const res = await getVideoPlaylistsList(servers[2].url, 1, 2, '-createdAt') - - expect(res.body.total).to.equal(3) + const body = await servers[2].playlistsCommand.list({ start: 1, count: 2, sort: '-createdAt' }) + expect(body.total).to.equal(3) - const data: VideoPlaylist[] = res.body.data + const data = body.data expect(data).to.have.lengthOf(2) expect(data[0].displayName).to.equal('playlist 2') expect(data[1].displayName).to.equal('my super playlist') @@ -366,11 +338,10 @@ describe('Test video playlists', function () { this.timeout(30000) { - const res = await getVideoChannelPlaylistsList(servers[0].url, 'root_channel', 0, 2, '-createdAt') + const body = await commands[0].listByChannel({ handle: 'root_channel', start: 0, count: 2, sort: '-createdAt' }) + expect(body.total).to.equal(1) - expect(res.body.total).to.equal(1) - - const data: VideoPlaylist[] = res.body.data + const data = body.data expect(data).to.have.lengthOf(1) expect(data[0].displayName).to.equal('my super playlist') } @@ -380,41 +351,37 @@ describe('Test video playlists', function () { this.timeout(30000) { - const res = await getAccountPlaylistsList(servers[1].url, 'root', 1, 2, '-createdAt') - - expect(res.body.total).to.equal(2) + const body = await servers[1].playlistsCommand.listByAccount({ handle: 'root', start: 1, count: 2, sort: '-createdAt' }) + expect(body.total).to.equal(2) - const data: VideoPlaylist[] = res.body.data + const data = body.data expect(data).to.have.lengthOf(1) expect(data[0].displayName).to.equal('playlist 2') } { - const res = await getAccountPlaylistsList(servers[1].url, 'root', 1, 2, 'createdAt') + const body = await servers[1].playlistsCommand.listByAccount({ handle: 'root', start: 1, count: 2, sort: 'createdAt' }) + expect(body.total).to.equal(2) - expect(res.body.total).to.equal(2) - - const data: VideoPlaylist[] = res.body.data + const data = body.data expect(data).to.have.lengthOf(1) expect(data[0].displayName).to.equal('playlist 3') } { - const res = await getAccountPlaylistsList(servers[1].url, 'root', 0, 10, 'createdAt', '3') - - expect(res.body.total).to.equal(1) + const body = await servers[1].playlistsCommand.listByAccount({ handle: 'root', sort: 'createdAt', search: '3' }) + expect(body.total).to.equal(1) - const data: VideoPlaylist[] = res.body.data + const data = body.data expect(data).to.have.lengthOf(1) expect(data[0].displayName).to.equal('playlist 3') } { - const res = await getAccountPlaylistsList(servers[1].url, 'root', 0, 10, 'createdAt', '4') - - expect(res.body.total).to.equal(0) + const body = await servers[1].playlistsCommand.listByAccount({ handle: 'root', sort: 'createdAt', search: '4' }) + expect(body.total).to.equal(0) - const data: VideoPlaylist[] = res.body.data + const data = body.data expect(data).to.have.lengthOf(0) } }) @@ -428,28 +395,22 @@ describe('Test video playlists', function () { this.timeout(30000) { - const res = await createVideoPlaylist({ - url: servers[1].url, - token: servers[1].accessToken, - playlistAttrs: { + unlistedPlaylist = await servers[1].playlistsCommand.create({ + attributes: { displayName: 'playlist unlisted', privacy: VideoPlaylistPrivacy.UNLISTED, videoChannelId: servers[1].videoChannel.id } }) - unlistedPlaylist = res.body.videoPlaylist } { - const res = await createVideoPlaylist({ - url: servers[1].url, - token: servers[1].accessToken, - playlistAttrs: { + privatePlaylist = await servers[1].playlistsCommand.create({ + attributes: { displayName: 'playlist private', privacy: VideoPlaylistPrivacy.PRIVATE } }) - privatePlaylist = res.body.videoPlaylist } await waitJobs(servers) @@ -459,15 +420,15 @@ describe('Test video playlists', function () { it('Should not list unlisted or private playlists', async function () { for (const server of servers) { const results = [ - await getAccountPlaylistsList(server.url, 'root@localhost:' + servers[1].port, 0, 5, '-createdAt'), - await getVideoPlaylistsList(server.url, 0, 2, '-createdAt') + await server.playlistsCommand.listByAccount({ handle: 'root@localhost:' + servers[1].port, sort: '-createdAt' }), + await server.playlistsCommand.list({ start: 0, count: 2, sort: '-createdAt' }) ] - expect(results[0].body.total).to.equal(2) - expect(results[1].body.total).to.equal(3) + expect(results[0].total).to.equal(2) + expect(results[1].total).to.equal(3) - for (const res of results) { - const data: VideoPlaylist[] = res.body.data + for (const body of results) { + const data = body.data expect(data).to.have.lengthOf(2) expect(data[0].displayName).to.equal('playlist 3') expect(data[1].displayName).to.equal('playlist 2') @@ -476,23 +437,23 @@ describe('Test video playlists', function () { }) it('Should not get unlisted playlist using only the id', async function () { - await getVideoPlaylist(servers[1].url, unlistedPlaylist.id, 404) + await servers[1].playlistsCommand.get({ playlistId: unlistedPlaylist.id, expectedStatus: 404 }) }) it('Should get unlisted plyaylist using uuid or shortUUID', async function () { - await getVideoPlaylist(servers[1].url, unlistedPlaylist.uuid) - await getVideoPlaylist(servers[1].url, unlistedPlaylist.shortUUID) + await servers[1].playlistsCommand.get({ playlistId: unlistedPlaylist.uuid }) + await servers[1].playlistsCommand.get({ playlistId: unlistedPlaylist.shortUUID }) }) it('Should not get private playlist without token', async function () { for (const id of [ privatePlaylist.id, privatePlaylist.uuid, privatePlaylist.shortUUID ]) { - await getVideoPlaylist(servers[1].url, id, 401) + await servers[1].playlistsCommand.get({ playlistId: id, expectedStatus: 401 }) } }) it('Should get private playlist with a token', async function () { for (const id of [ privatePlaylist.id, privatePlaylist.uuid, privatePlaylist.shortUUID ]) { - await getVideoPlaylistWithToken(servers[1].url, servers[1].accessToken, id) + await servers[1].playlistsCommand.get({ token: servers[1].accessToken, playlistId: id }) } }) }) @@ -502,10 +463,8 @@ describe('Test video playlists', function () { it('Should update a playlist', async function () { this.timeout(30000) - await updateVideoPlaylist({ - url: servers[1].url, - token: servers[1].accessToken, - playlistAttrs: { + await servers[1].playlistsCommand.update({ + attributes: { displayName: 'playlist 3 updated', description: 'description updated', privacy: VideoPlaylistPrivacy.UNLISTED, @@ -518,8 +477,7 @@ describe('Test video playlists', function () { await waitJobs(servers) for (const server of servers) { - const res = await getVideoPlaylist(server.url, playlistServer2UUID2) - const playlist: VideoPlaylist = res.body + const playlist = await server.playlistsCommand.get({ playlistId: playlistServer2UUID2 }) expect(playlist.displayName).to.equal('playlist 3 updated') expect(playlist.description).to.equal('description updated') @@ -545,39 +503,37 @@ describe('Test video playlists', function () { it('Should create a playlist containing different startTimestamp/endTimestamp videos', async function () { this.timeout(30000) - const addVideo = (elementAttrs: any) => { - return addVideoInPlaylist({ url: servers[0].url, token: servers[0].accessToken, playlistId: playlistServer1Id, elementAttrs }) + const addVideo = (attributes: any) => { + return commands[0].addElement({ playlistId: playlistServer1Id, attributes }) } - const res = await createVideoPlaylist({ - url: servers[0].url, - token: servers[0].accessToken, - playlistAttrs: { + const playlist = await commands[0].create({ + attributes: { displayName: 'playlist 4', privacy: VideoPlaylistPrivacy.PUBLIC, videoChannelId: servers[0].videoChannel.id } }) - playlistServer1Id = res.body.videoPlaylist.id - playlistServer1UUID = res.body.videoPlaylist.uuid + playlistServer1Id = playlist.id + playlistServer1UUID = playlist.uuid await addVideo({ videoId: servers[0].videos[0].uuid, startTimestamp: 15, stopTimestamp: 28 }) await addVideo({ videoId: servers[2].videos[1].uuid, startTimestamp: 35 }) await addVideo({ videoId: servers[2].videos[2].uuid }) { - const res = await addVideo({ videoId: servers[0].videos[3].uuid, stopTimestamp: 35 }) - playlistElementServer1Video4 = res.body.videoPlaylistElement.id + const element = await addVideo({ videoId: servers[0].videos[3].uuid, stopTimestamp: 35 }) + playlistElementServer1Video4 = element.id } { - const res = await addVideo({ videoId: servers[0].videos[4].uuid, startTimestamp: 45, stopTimestamp: 60 }) - playlistElementServer1Video5 = res.body.videoPlaylistElement.id + const element = await addVideo({ videoId: servers[0].videos[4].uuid, startTimestamp: 45, stopTimestamp: 60 }) + playlistElementServer1Video5 = element.id } { - const res = await addVideo({ videoId: nsfwVideoServer1, startTimestamp: 5 }) - playlistElementNSFW = res.body.videoPlaylistElement.id + const element = await addVideo({ videoId: nsfwVideoServer1, startTimestamp: 5 }) + playlistElementNSFW = element.id await addVideo({ videoId: nsfwVideoServer1, startTimestamp: 4 }) await addVideo({ videoId: nsfwVideoServer1 }) @@ -590,55 +546,59 @@ describe('Test video playlists', function () { this.timeout(30000) for (const server of servers) { - const res = await getPlaylistVideos(server.url, server.accessToken, playlistServer1UUID, 0, 10) - - expect(res.body.total).to.equal(8) - - const videoElements: VideoPlaylistElement[] = res.body.data - expect(videoElements).to.have.lengthOf(8) - - expect(videoElements[0].video.name).to.equal('video 0 server 1') - expect(videoElements[0].position).to.equal(1) - expect(videoElements[0].startTimestamp).to.equal(15) - expect(videoElements[0].stopTimestamp).to.equal(28) - - expect(videoElements[1].video.name).to.equal('video 1 server 3') - expect(videoElements[1].position).to.equal(2) - expect(videoElements[1].startTimestamp).to.equal(35) - expect(videoElements[1].stopTimestamp).to.be.null - - expect(videoElements[2].video.name).to.equal('video 2 server 3') - expect(videoElements[2].position).to.equal(3) - expect(videoElements[2].startTimestamp).to.be.null - expect(videoElements[2].stopTimestamp).to.be.null - - expect(videoElements[3].video.name).to.equal('video 3 server 1') - expect(videoElements[3].position).to.equal(4) - expect(videoElements[3].startTimestamp).to.be.null - expect(videoElements[3].stopTimestamp).to.equal(35) - - expect(videoElements[4].video.name).to.equal('video 4 server 1') - expect(videoElements[4].position).to.equal(5) - expect(videoElements[4].startTimestamp).to.equal(45) - expect(videoElements[4].stopTimestamp).to.equal(60) - - expect(videoElements[5].video.name).to.equal('NSFW video') - expect(videoElements[5].position).to.equal(6) - expect(videoElements[5].startTimestamp).to.equal(5) - expect(videoElements[5].stopTimestamp).to.be.null - - expect(videoElements[6].video.name).to.equal('NSFW video') - expect(videoElements[6].position).to.equal(7) - expect(videoElements[6].startTimestamp).to.equal(4) - expect(videoElements[6].stopTimestamp).to.be.null - - expect(videoElements[7].video.name).to.equal('NSFW video') - expect(videoElements[7].position).to.equal(8) - expect(videoElements[7].startTimestamp).to.be.null - expect(videoElements[7].stopTimestamp).to.be.null - - const res3 = await getPlaylistVideos(server.url, server.accessToken, playlistServer1UUID, 0, 2) - expect(res3.body.data).to.have.lengthOf(2) + { + const body = await server.playlistsCommand.listVideos({ playlistId: playlistServer1UUID, start: 0, count: 10 }) + + expect(body.total).to.equal(8) + + const videoElements = body.data + expect(videoElements).to.have.lengthOf(8) + + expect(videoElements[0].video.name).to.equal('video 0 server 1') + expect(videoElements[0].position).to.equal(1) + expect(videoElements[0].startTimestamp).to.equal(15) + expect(videoElements[0].stopTimestamp).to.equal(28) + + expect(videoElements[1].video.name).to.equal('video 1 server 3') + expect(videoElements[1].position).to.equal(2) + expect(videoElements[1].startTimestamp).to.equal(35) + expect(videoElements[1].stopTimestamp).to.be.null + + expect(videoElements[2].video.name).to.equal('video 2 server 3') + expect(videoElements[2].position).to.equal(3) + expect(videoElements[2].startTimestamp).to.be.null + expect(videoElements[2].stopTimestamp).to.be.null + + expect(videoElements[3].video.name).to.equal('video 3 server 1') + expect(videoElements[3].position).to.equal(4) + expect(videoElements[3].startTimestamp).to.be.null + expect(videoElements[3].stopTimestamp).to.equal(35) + + expect(videoElements[4].video.name).to.equal('video 4 server 1') + expect(videoElements[4].position).to.equal(5) + expect(videoElements[4].startTimestamp).to.equal(45) + expect(videoElements[4].stopTimestamp).to.equal(60) + + expect(videoElements[5].video.name).to.equal('NSFW video') + expect(videoElements[5].position).to.equal(6) + expect(videoElements[5].startTimestamp).to.equal(5) + expect(videoElements[5].stopTimestamp).to.be.null + + expect(videoElements[6].video.name).to.equal('NSFW video') + expect(videoElements[6].position).to.equal(7) + expect(videoElements[6].startTimestamp).to.equal(4) + expect(videoElements[6].stopTimestamp).to.be.null + + expect(videoElements[7].video.name).to.equal('NSFW video') + expect(videoElements[7].position).to.equal(8) + expect(videoElements[7].startTimestamp).to.be.null + expect(videoElements[7].stopTimestamp).to.be.null + } + + { + const body = await server.playlistsCommand.listVideos({ playlistId: playlistServer1UUID, start: 0, count: 2 }) + expect(body.data).to.have.lengthOf(2) + } } }) }) @@ -656,29 +616,28 @@ describe('Test video playlists', function () { before(async function () { this.timeout(60000) - groupUser1 = [ Object.assign({}, servers[0], { accessToken: userAccessTokenServer1 }) ] + groupUser1 = [ Object.assign({}, servers[0], { accessToken: userTokenServer1 }) ] groupWithoutToken1 = [ Object.assign({}, servers[0], { accessToken: undefined }) ] group1 = [ servers[0] ] group2 = [ servers[1], servers[2] ] - const res = await createVideoPlaylist({ - url: servers[0].url, - token: userAccessTokenServer1, - playlistAttrs: { + const playlist = await commands[0].create({ + token: userTokenServer1, + attributes: { displayName: 'playlist 56', privacy: VideoPlaylistPrivacy.PUBLIC, videoChannelId: servers[0].videoChannel.id } }) - const playlistServer1Id2 = res.body.videoPlaylist.id - playlistServer1UUID2 = res.body.videoPlaylist.uuid + const playlistServer1Id2 = playlist.id + playlistServer1UUID2 = playlist.uuid - const addVideo = (elementAttrs: any) => { - return addVideoInPlaylist({ url: servers[0].url, token: userAccessTokenServer1, playlistId: playlistServer1Id2, elementAttrs }) + const addVideo = (attributes: any) => { + return commands[0].addElement({ token: userTokenServer1, playlistId: playlistServer1Id2, attributes }) } - video1 = (await uploadVideoAndGetId({ server: servers[0], videoName: 'video 89', token: userAccessTokenServer1 })).uuid + video1 = (await uploadVideoAndGetId({ server: servers[0], videoName: 'video 89', token: userTokenServer1 })).uuid video2 = (await uploadVideoAndGetId({ server: servers[1], videoName: 'video 90' })).uuid video3 = (await uploadVideoAndGetId({ server: servers[0], videoName: 'video 91', nsfw: true })).uuid @@ -756,26 +715,26 @@ describe('Test video playlists', function () { const position = 2 { - await command.addToMyBlocklist({ token: userAccessTokenServer1, account: 'root@localhost:' + servers[1].port }) + await command.addToMyBlocklist({ token: userTokenServer1, account: 'root@localhost:' + servers[1].port }) await waitJobs(servers) await checkPlaylistElementType(groupUser1, playlistServer1UUID2, VideoPlaylistElementType.UNAVAILABLE, position, name, 3) await checkPlaylistElementType(group2, playlistServer1UUID2, VideoPlaylistElementType.REGULAR, position, name, 3) - await command.removeFromMyBlocklist({ token: userAccessTokenServer1, account: 'root@localhost:' + servers[1].port }) + await command.removeFromMyBlocklist({ token: userTokenServer1, account: 'root@localhost:' + servers[1].port }) await waitJobs(servers) await checkPlaylistElementType(group2, playlistServer1UUID2, VideoPlaylistElementType.REGULAR, position, name, 3) } { - await command.addToMyBlocklist({ token: userAccessTokenServer1, server: 'localhost:' + servers[1].port }) + await command.addToMyBlocklist({ token: userTokenServer1, server: 'localhost:' + servers[1].port }) await waitJobs(servers) await checkPlaylistElementType(groupUser1, playlistServer1UUID2, VideoPlaylistElementType.UNAVAILABLE, position, name, 3) await checkPlaylistElementType(group2, playlistServer1UUID2, VideoPlaylistElementType.REGULAR, position, name, 3) - await command.removeFromMyBlocklist({ token: userAccessTokenServer1, server: 'localhost:' + servers[1].port }) + await command.removeFromMyBlocklist({ token: userTokenServer1, server: 'localhost:' + servers[1].port }) await waitJobs(servers) await checkPlaylistElementType(group2, playlistServer1UUID2, VideoPlaylistElementType.REGULAR, position, name, 3) @@ -809,10 +768,10 @@ describe('Test video playlists', function () { }) it('Should hide the video if it is NSFW', async function () { - const res = await getPlaylistVideos(servers[0].url, userAccessTokenServer1, playlistServer1UUID2, 0, 10, { nsfw: false }) - expect(res.body.total).to.equal(3) + const body = await commands[0].listVideos({ token: userTokenServer1, playlistId: playlistServer1UUID2, query: { nsfw: 'false' } }) + expect(body.total).to.equal(3) - const elements: VideoPlaylistElement[] = res.body.data + const elements = body.data const element = elements.find(e => e.position === 3) expect(element).to.exist @@ -828,11 +787,9 @@ describe('Test video playlists', function () { this.timeout(30000) { - await reorderVideosPlaylist({ - url: servers[0].url, - token: servers[0].accessToken, + await commands[0].reorderElements({ playlistId: playlistServer1Id, - elementAttrs: { + attributes: { startPosition: 2, insertAfterPosition: 3 } @@ -841,8 +798,8 @@ describe('Test video playlists', function () { await waitJobs(servers) for (const server of servers) { - const res = await getPlaylistVideos(server.url, server.accessToken, playlistServer1UUID, 0, 10) - const names = (res.body.data as VideoPlaylistElement[]).map(v => v.video.name) + const body = await server.playlistsCommand.listVideos({ playlistId: playlistServer1UUID, start: 0, count: 10 }) + const names = body.data.map(v => v.video.name) expect(names).to.deep.equal([ 'video 0 server 1', @@ -858,11 +815,9 @@ describe('Test video playlists', function () { } { - await reorderVideosPlaylist({ - url: servers[0].url, - token: servers[0].accessToken, + await commands[0].reorderElements({ playlistId: playlistServer1Id, - elementAttrs: { + attributes: { startPosition: 1, reorderLength: 3, insertAfterPosition: 4 @@ -872,8 +827,8 @@ describe('Test video playlists', function () { await waitJobs(servers) for (const server of servers) { - const res = await getPlaylistVideos(server.url, server.accessToken, playlistServer1UUID, 0, 10) - const names = (res.body.data as VideoPlaylistElement[]).map(v => v.video.name) + const body = await server.playlistsCommand.listVideos({ playlistId: playlistServer1UUID, start: 0, count: 10 }) + const names = body.data.map(v => v.video.name) expect(names).to.deep.equal([ 'video 3 server 1', @@ -889,11 +844,9 @@ describe('Test video playlists', function () { } { - await reorderVideosPlaylist({ - url: servers[0].url, - token: servers[0].accessToken, + await commands[0].reorderElements({ playlistId: playlistServer1Id, - elementAttrs: { + attributes: { startPosition: 6, insertAfterPosition: 3 } @@ -902,8 +855,7 @@ describe('Test video playlists', function () { await waitJobs(servers) for (const server of servers) { - const res = await getPlaylistVideos(server.url, server.accessToken, playlistServer1UUID, 0, 10) - const elements: VideoPlaylistElement[] = res.body.data + const { data: elements } = await server.playlistsCommand.listVideos({ playlistId: playlistServer1UUID, start: 0, count: 10 }) const names = elements.map(v => v.video.name) expect(names).to.deep.equal([ @@ -927,22 +879,18 @@ describe('Test video playlists', function () { it('Should update startTimestamp/endTimestamp of some elements', async function () { this.timeout(30000) - await updateVideoPlaylistElement({ - url: servers[0].url, - token: servers[0].accessToken, + await commands[0].updateElement({ playlistId: playlistServer1Id, - playlistElementId: playlistElementServer1Video4, - elementAttrs: { + elementId: playlistElementServer1Video4, + attributes: { startTimestamp: 1 } }) - await updateVideoPlaylistElement({ - url: servers[0].url, - token: servers[0].accessToken, + await commands[0].updateElement({ playlistId: playlistServer1Id, - playlistElementId: playlistElementServer1Video5, - elementAttrs: { + elementId: playlistElementServer1Video5, + attributes: { stopTimestamp: null } }) @@ -950,8 +898,7 @@ describe('Test video playlists', function () { await waitJobs(servers) for (const server of servers) { - const res = await getPlaylistVideos(server.url, server.accessToken, playlistServer1UUID, 0, 10) - const elements: VideoPlaylistElement[] = res.body.data + const { data: elements } = await server.playlistsCommand.listVideos({ playlistId: playlistServer1UUID, start: 0, count: 10 }) expect(elements[0].video.name).to.equal('video 3 server 1') expect(elements[0].position).to.equal(1) @@ -973,8 +920,7 @@ describe('Test video playlists', function () { 43000, servers[0].videos[4].id ] - const res = await doVideosExistInMyPlaylist(servers[0].url, servers[0].accessToken, videoIds) - const obj = res.body as VideoExistInPlaylist + const obj = await commands[0].videosExist({ videoIds }) { const elem = obj[servers[0].videos[0].id] @@ -1011,39 +957,26 @@ describe('Test video playlists', function () { const videoId = servers[1].videos[5].id async function getPlaylistNames () { - const res = await getAccountPlaylistsListWithToken(server.url, server.accessToken, 'root', 0, 5, undefined, '-updatedAt') + const { data } = await server.playlistsCommand.listByAccount({ token: server.accessToken, handle: 'root', sort: '-updatedAt' }) - return (res.body.data as VideoPlaylist[]).map(p => p.displayName) + return data.map(p => p.displayName) } - const elementAttrs = { videoId } - const res1 = await addVideoInPlaylist({ url: server.url, token: server.accessToken, playlistId: playlistServer2Id1, elementAttrs }) - const res2 = await addVideoInPlaylist({ url: server.url, token: server.accessToken, playlistId: playlistServer2Id2, elementAttrs }) - - const element1 = res1.body.videoPlaylistElement.id - const element2 = res2.body.videoPlaylistElement.id + const attributes = { videoId } + const element1 = await server.playlistsCommand.addElement({ playlistId: playlistServer2Id1, attributes }) + const element2 = await server.playlistsCommand.addElement({ playlistId: playlistServer2Id2, attributes }) const names1 = await getPlaylistNames() expect(names1[0]).to.equal('playlist 3 updated') expect(names1[1]).to.equal('playlist 2') - await removeVideoFromPlaylist({ - url: server.url, - token: server.accessToken, - playlistId: playlistServer2Id1, - playlistElementId: element1 - }) + await server.playlistsCommand.removeElement({ playlistId: playlistServer2Id1, elementId: element1.id }) const names2 = await getPlaylistNames() expect(names2[0]).to.equal('playlist 2') expect(names2[1]).to.equal('playlist 3 updated') - await removeVideoFromPlaylist({ - url: server.url, - token: server.accessToken, - playlistId: playlistServer2Id2, - playlistElementId: element2 - }) + await server.playlistsCommand.removeElement({ playlistId: playlistServer2Id2, elementId: element2.id }) const names3 = await getPlaylistNames() expect(names3[0]).to.equal('playlist 3 updated') @@ -1053,28 +986,16 @@ describe('Test video playlists', function () { it('Should delete some elements', async function () { this.timeout(30000) - await removeVideoFromPlaylist({ - url: servers[0].url, - token: servers[0].accessToken, - playlistId: playlistServer1Id, - playlistElementId: playlistElementServer1Video4 - }) - - await removeVideoFromPlaylist({ - url: servers[0].url, - token: servers[0].accessToken, - playlistId: playlistServer1Id, - playlistElementId: playlistElementNSFW - }) + await commands[0].removeElement({ playlistId: playlistServer1Id, elementId: playlistElementServer1Video4 }) + await commands[0].removeElement({ playlistId: playlistServer1Id, elementId: playlistElementNSFW }) await waitJobs(servers) for (const server of servers) { - const res = await getPlaylistVideos(server.url, server.accessToken, playlistServer1UUID, 0, 10) - - expect(res.body.total).to.equal(6) + const body = await server.playlistsCommand.listVideos({ playlistId: playlistServer1UUID, start: 0, count: 10 }) + expect(body.total).to.equal(6) - const elements: VideoPlaylistElement[] = res.body.data + const elements = body.data expect(elements).to.have.lengthOf(6) expect(elements[0].video.name).to.equal('video 0 server 1') @@ -1100,34 +1021,31 @@ describe('Test video playlists', function () { it('Should be able to create a public playlist, and set it to private', async function () { this.timeout(30000) - const res = await createVideoPlaylist({ - url: servers[0].url, - token: servers[0].accessToken, - playlistAttrs: { + const videoPlaylistIds = await commands[0].create({ + attributes: { displayName: 'my super public playlist', privacy: VideoPlaylistPrivacy.PUBLIC, videoChannelId: servers[0].videoChannel.id } }) - const videoPlaylistIds = res.body.videoPlaylist await waitJobs(servers) for (const server of servers) { - await getVideoPlaylist(server.url, videoPlaylistIds.uuid, HttpStatusCode.OK_200) + await server.playlistsCommand.get({ playlistId: videoPlaylistIds.uuid, expectedStatus: HttpStatusCode.OK_200 }) } - const playlistAttrs = { privacy: VideoPlaylistPrivacy.PRIVATE } - await updateVideoPlaylist({ url: servers[0].url, token: servers[0].accessToken, playlistId: videoPlaylistIds.id, playlistAttrs }) + const attributes = { privacy: VideoPlaylistPrivacy.PRIVATE } + await commands[0].update({ playlistId: videoPlaylistIds.id, attributes }) await waitJobs(servers) for (const server of [ servers[1], servers[2] ]) { - await getVideoPlaylist(server.url, videoPlaylistIds.uuid, HttpStatusCode.NOT_FOUND_404) + await server.playlistsCommand.get({ playlistId: videoPlaylistIds.uuid, expectedStatus: HttpStatusCode.NOT_FOUND_404 }) } - await getVideoPlaylist(servers[0].url, videoPlaylistIds.uuid, HttpStatusCode.UNAUTHORIZED_401) - await getVideoPlaylistWithToken(servers[0].url, servers[0].accessToken, videoPlaylistIds.uuid, HttpStatusCode.OK_200) + await commands[0].get({ playlistId: videoPlaylistIds.uuid, expectedStatus: HttpStatusCode.UNAUTHORIZED_401 }) + await commands[0].get({ token: servers[0].accessToken, playlistId: videoPlaylistIds.uuid, expectedStatus: HttpStatusCode.OK_200 }) }) }) @@ -1136,12 +1054,12 @@ describe('Test video playlists', function () { it('Should delete the playlist on server 1 and delete on server 2 and 3', async function () { this.timeout(30000) - await deleteVideoPlaylist(servers[0].url, servers[0].accessToken, playlistServer1Id) + await commands[0].delete({ playlistId: playlistServer1Id }) await waitJobs(servers) for (const server of servers) { - await getVideoPlaylist(server.url, playlistServer1UUID, HttpStatusCode.NOT_FOUND_404) + await server.playlistsCommand.get({ playlistId: playlistServer1UUID, expectedStatus: HttpStatusCode.NOT_FOUND_404 }) } }) @@ -1156,21 +1074,22 @@ describe('Test video playlists', function () { it('Should unfollow servers 1 and 2 and hide their playlists', async function () { this.timeout(30000) - const finder = data => data.find(p => p.displayName === 'my super playlist') + const finder = (data: VideoPlaylist[]) => data.find(p => p.displayName === 'my super playlist') { - const res = await getVideoPlaylistsList(servers[2].url, 0, 5) - expect(res.body.total).to.equal(3) - expect(finder(res.body.data)).to.not.be.undefined + const body = await servers[2].playlistsCommand.list({ start: 0, count: 5 }) + expect(body.total).to.equal(3) + + expect(finder(body.data)).to.not.be.undefined } await servers[2].followsCommand.unfollow({ target: servers[0] }) { - const res = await getVideoPlaylistsList(servers[2].url, 0, 5) - expect(res.body.total).to.equal(1) + const body = await servers[2].playlistsCommand.list({ start: 0, count: 5 }) + expect(body.total).to.equal(1) - expect(finder(res.body.data)).to.be.undefined + expect(finder(body.data)).to.be.undefined } }) @@ -1180,16 +1099,13 @@ describe('Test video playlists', function () { const res = await addVideoChannel(servers[0].url, servers[0].accessToken, { name: 'super_channel', displayName: 'super channel' }) const videoChannelId = res.body.videoChannel.id - const res2 = await createVideoPlaylist({ - url: servers[0].url, - token: servers[0].accessToken, - playlistAttrs: { + const playlistCreated = await commands[0].create({ + attributes: { displayName: 'channel playlist', privacy: VideoPlaylistPrivacy.PUBLIC, videoChannelId } }) - const videoPlaylistUUID = res2.body.videoPlaylist.uuid await waitJobs(servers) @@ -1197,11 +1113,11 @@ describe('Test video playlists', function () { await waitJobs(servers) - const res3 = await getVideoPlaylistWithToken(servers[0].url, servers[0].accessToken, videoPlaylistUUID) - expect(res3.body.displayName).to.equal('channel playlist') - expect(res3.body.privacy.id).to.equal(VideoPlaylistPrivacy.PRIVATE) + const body = await commands[0].get({ token: servers[0].accessToken, playlistId: playlistCreated.uuid }) + expect(body.displayName).to.equal('channel playlist') + expect(body.privacy.id).to.equal(VideoPlaylistPrivacy.PRIVATE) - await getVideoPlaylist(servers[1].url, videoPlaylistUUID, HttpStatusCode.NOT_FOUND_404) + await servers[1].playlistsCommand.get({ playlistId: playlistCreated.uuid, expectedStatus: HttpStatusCode.NOT_FOUND_404 }) }) it('Should delete an account and delete its playlists', async function () { @@ -1221,10 +1137,8 @@ describe('Test video playlists', function () { const resChannel = await getMyUserInformation(servers[0].url, userAccessToken) const userChannel = (resChannel.body as User).videoChannels[0] - await createVideoPlaylist({ - url: servers[0].url, - token: userAccessToken, - playlistAttrs: { + await commands[0].create({ + attributes: { displayName: 'playlist to be deleted', privacy: VideoPlaylistPrivacy.PUBLIC, videoChannelId: userChannel.id @@ -1233,12 +1147,13 @@ describe('Test video playlists', function () { await waitJobs(servers) - const finder = data => data.find(p => p.displayName === 'playlist to be deleted') + const finder = (data: VideoPlaylist[]) => data.find(p => p.displayName === 'playlist to be deleted') { for (const server of [ servers[0], servers[1] ]) { - const res = await getVideoPlaylistsList(server.url, 0, 15) - expect(finder(res.body.data)).to.not.be.undefined + const body = await server.playlistsCommand.list({ start: 0, count: 15 }) + + expect(finder(body.data)).to.not.be.undefined } } @@ -1247,8 +1162,9 @@ describe('Test video playlists', function () { { for (const server of [ servers[0], servers[1] ]) { - const res = await getVideoPlaylistsList(server.url, 0, 15) - expect(finder(res.body.data)).to.be.undefined + const body = await server.playlistsCommand.list({ start: 0, count: 15 }) + + expect(finder(body.data)).to.be.undefined } } }) -- cgit v1.2.3 From 313228e9c3b5bcef5391228c9b949d05d32ad7bb Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Thu, 8 Jul 2021 16:21:42 +0200 Subject: Introduce history command --- server/tests/api/videos/videos-history.ts | 59 +++++++++++++++---------------- 1 file changed, 29 insertions(+), 30 deletions(-) (limited to 'server/tests/api') diff --git a/server/tests/api/videos/videos-history.ts b/server/tests/api/videos/videos-history.ts index 209b93014..731447135 100644 --- a/server/tests/api/videos/videos-history.ts +++ b/server/tests/api/videos/videos-history.ts @@ -9,6 +9,7 @@ import { flushAndRunServer, getVideosListWithToken, getVideoWithToken, + HistoryCommand, killallServers, reRunServer, ServerInfo, @@ -18,7 +19,6 @@ import { userLogin, wait } from '@shared/extra-utils' -import { listMyVideosHistory, removeMyVideosHistory, userWatchVideo } from '@shared/extra-utils/videos/video-history' import { Video, VideoDetails } from '@shared/models' const expect = chai.expect @@ -30,6 +30,7 @@ describe('Test videos history', function () { let video3UUID: string let video3WatchedDate: Date let userAccessToken: string + let command: HistoryCommand before(async function () { this.timeout(30000) @@ -38,6 +39,8 @@ describe('Test videos history', function () { await setAccessTokensToServers([ server ]) + command = server.historyCommand + { const res = await uploadVideo(server.url, server.accessToken, { name: 'video 1' }) video1UUID = res.body.video.uuid @@ -75,8 +78,8 @@ describe('Test videos history', function () { }) it('Should watch the first and second video', async function () { - await userWatchVideo(server.url, server.accessToken, video2UUID, 8) - await userWatchVideo(server.url, server.accessToken, video1UUID, 3) + await command.wathVideo({ videoId: video2UUID, currentTime: 8 }) + await command.wathVideo({ videoId: video1UUID, currentTime: 3 }) }) it('Should return the correct history when listing, searching and getting videos', async function () { @@ -132,44 +135,42 @@ describe('Test videos history', function () { it('Should have these videos when listing my history', async function () { video3WatchedDate = new Date() - await userWatchVideo(server.url, server.accessToken, video3UUID, 2) + await command.wathVideo({ videoId: video3UUID, currentTime: 2 }) - const res = await listMyVideosHistory(server.url, server.accessToken) + const body = await command.list() - expect(res.body.total).to.equal(3) + expect(body.total).to.equal(3) - const videos: Video[] = res.body.data + const videos = body.data expect(videos[0].name).to.equal('video 3') expect(videos[1].name).to.equal('video 1') expect(videos[2].name).to.equal('video 2') }) it('Should not have videos history on another user', async function () { - const res = await listMyVideosHistory(server.url, userAccessToken) + const body = await command.list({ token: userAccessToken }) - expect(res.body.total).to.equal(0) - expect(res.body.data).to.have.lengthOf(0) + expect(body.total).to.equal(0) + expect(body.data).to.have.lengthOf(0) }) it('Should be able to search through videos in my history', async function () { - const res = await listMyVideosHistory(server.url, server.accessToken, '2') - - expect(res.body.total).to.equal(1) + const body = await command.list({ search: '2' }) + expect(body.total).to.equal(1) - const videos: Video[] = res.body.data + const videos = body.data expect(videos[0].name).to.equal('video 2') }) it('Should clear my history', async function () { - await removeMyVideosHistory(server.url, server.accessToken, video3WatchedDate.toISOString()) + await command.remove({ beforeDate: video3WatchedDate.toISOString() }) }) it('Should have my history cleared', async function () { - const res = await listMyVideosHistory(server.url, server.accessToken) - - expect(res.body.total).to.equal(1) + const body = await command.list() + expect(body.total).to.equal(1) - const videos: Video[] = res.body.data + const videos = body.data expect(videos[0].name).to.equal('video 3') }) @@ -180,7 +181,7 @@ describe('Test videos history', function () { videosHistoryEnabled: false }) - await userWatchVideo(server.url, server.accessToken, video2UUID, 8, HttpStatusCode.CONFLICT_409) + await command.wathVideo({ videoId: video2UUID, currentTime: 8, expectedStatus: HttpStatusCode.CONFLICT_409 }) }) it('Should re-enable videos history', async function () { @@ -190,13 +191,12 @@ describe('Test videos history', function () { videosHistoryEnabled: true }) - await userWatchVideo(server.url, server.accessToken, video1UUID, 8) - - const res = await listMyVideosHistory(server.url, server.accessToken) + await command.wathVideo({ videoId: video1UUID, currentTime: 8 }) - expect(res.body.total).to.equal(2) + const body = await command.list() + expect(body.total).to.equal(2) - const videos: Video[] = res.body.data + const videos = body.data expect(videos[0].name).to.equal('video 1') expect(videos[1].name).to.equal('video 3') }) @@ -212,9 +212,8 @@ describe('Test videos history', function () { // Should still have history - const res = await listMyVideosHistory(server.url, server.accessToken) - - expect(res.body.total).to.equal(2) + const body = await command.list() + expect(body.total).to.equal(2) }) it('Should clean old history', async function () { @@ -226,8 +225,8 @@ describe('Test videos history', function () { await wait(6000) - const res = await listMyVideosHistory(server.url, server.accessToken) - expect(res.body.total).to.equal(0) + const body = await command.list() + expect(body.total).to.equal(0) }) after(async function () { -- 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 +- server/tests/api/moderation/video-blacklist.ts | 10 +-- .../tests/api/notifications/user-notifications.ts | 30 ++++----- server/tests/api/videos/video-imports.ts | 72 ++++++++++------------ 5 files changed, 61 insertions(+), 73 deletions(-) (limited to 'server/tests/api') 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, diff --git a/server/tests/api/moderation/video-blacklist.ts b/server/tests/api/moderation/video-blacklist.ts index 17a68e4a6..c72ebc16b 100644 --- a/server/tests/api/moderation/video-blacklist.ts +++ b/server/tests/api/moderation/video-blacklist.ts @@ -12,6 +12,7 @@ import { getMyUserInformation, getMyVideos, getVideosList, + ImportsCommand, killallServers, reRunServer, ServerInfo, @@ -21,7 +22,6 @@ import { userLogin, waitJobs } from '@shared/extra-utils' -import { getGoodVideoUrl, getMagnetURI, importVideo } from '@shared/extra-utils/videos/video-imports' import { User, UserAdminFlag, UserRole, VideoBlacklist, VideoBlacklistType } from '@shared/models' const expect = chai.expect @@ -402,11 +402,11 @@ describe('Test video blacklist', function () { this.timeout(15000) const attributes = { - targetUrl: getGoodVideoUrl(), + targetUrl: ImportsCommand.getGoodVideoUrl(), name: 'URL import', channelId: channelOfUserWithoutFlag } - await importVideo(servers[0].url, userWithoutFlag, attributes) + await servers[0].importsCommand.importVideo({ token: userWithoutFlag, attributes }) const body = await command.list({ sort: 'createdAt', type: VideoBlacklistType.AUTO_BEFORE_PUBLISHED }) expect(body.total).to.equal(2) @@ -415,11 +415,11 @@ describe('Test video blacklist', function () { it('Should auto blacklist a video on torrent import', async function () { const attributes = { - magnetUri: getMagnetURI(), + magnetUri: ImportsCommand.getMagnetURI(), name: 'Torrent import', channelId: channelOfUserWithoutFlag } - await importVideo(servers[0].url, userWithoutFlag, attributes) + await servers[0].importsCommand.importVideo({ token: userWithoutFlag, attributes }) const body = await command.list({ sort: 'createdAt', type: VideoBlacklistType.AUTO_BEFORE_PUBLISHED }) expect(body.total).to.equal(3) diff --git a/server/tests/api/notifications/user-notifications.ts b/server/tests/api/notifications/user-notifications.ts index 15be983f2..a9315c818 100644 --- a/server/tests/api/notifications/user-notifications.ts +++ b/server/tests/api/notifications/user-notifications.ts @@ -11,6 +11,7 @@ import { checkVideoIsPublished, cleanupTests, getLastNotification, + ImportsCommand, MockSmtpServer, prepareNotificationsTest, ServerInfo, @@ -21,7 +22,6 @@ import { wait, waitJobs } from '@shared/extra-utils' -import { getBadVideoUrl, getGoodVideoUrl, importVideo } from '@shared/extra-utils/videos/video-imports' import { UserNotification, UserNotificationType, VideoPrivacy } from '@shared/models' const expect = chai.expect @@ -209,14 +209,13 @@ describe('Test user notifications', function () { name, channelId, privacy: VideoPrivacy.PUBLIC, - targetUrl: getGoodVideoUrl() + targetUrl: ImportsCommand.getGoodVideoUrl() } - const res = await importVideo(servers[0].url, servers[0].accessToken, attributes) - const uuid = res.body.video.uuid + const { video } = await servers[0].importsCommand.importVideo({ attributes }) await waitJobs(servers) - await checkNewVideoFromSubscription(baseParams, name, uuid, 'presence') + await checkNewVideoFromSubscription(baseParams, name, video.uuid, 'presence') }) }) @@ -280,14 +279,13 @@ describe('Test user notifications', function () { name, channelId, privacy: VideoPrivacy.PUBLIC, - targetUrl: getGoodVideoUrl(), + targetUrl: ImportsCommand.getGoodVideoUrl(), waitTranscoding: true } - const res = await importVideo(servers[1].url, servers[1].accessToken, attributes) - const uuid = res.body.video.uuid + const { video } = await servers[1].importsCommand.importVideo({ attributes }) await waitJobs(servers) - await checkVideoIsPublished(baseParams, name, uuid, 'presence') + await checkVideoIsPublished(baseParams, name, video.uuid, 'presence') }) it('Should send a notification when the scheduled update has been proceeded', async function () { @@ -349,13 +347,12 @@ describe('Test user notifications', function () { name, channelId, privacy: VideoPrivacy.PRIVATE, - targetUrl: getBadVideoUrl() + targetUrl: ImportsCommand.getBadVideoUrl() } - const res = await importVideo(servers[0].url, servers[0].accessToken, attributes) - const uuid = res.body.video.uuid + const { video } = await servers[0].importsCommand.importVideo({ attributes }) await waitJobs(servers) - await checkMyVideoImportIsFinished(baseParams, name, uuid, getBadVideoUrl(), false, 'presence') + await checkMyVideoImportIsFinished(baseParams, name, video.uuid, ImportsCommand.getBadVideoUrl(), false, 'presence') }) it('Should send a notification when the video import succeeded', async function () { @@ -367,13 +364,12 @@ describe('Test user notifications', function () { name, channelId, privacy: VideoPrivacy.PRIVATE, - targetUrl: getGoodVideoUrl() + targetUrl: ImportsCommand.getGoodVideoUrl() } - const res = await importVideo(servers[0].url, servers[0].accessToken, attributes) - const uuid = res.body.video.uuid + const { video } = await servers[0].importsCommand.importVideo({ attributes }) await waitJobs(servers) - await checkMyVideoImportIsFinished(baseParams, name, uuid, getGoodVideoUrl(), true, 'presence') + await checkMyVideoImportIsFinished(baseParams, name, video.uuid, ImportsCommand.getGoodVideoUrl(), true, 'presence') }) }) diff --git a/server/tests/api/videos/video-imports.ts b/server/tests/api/videos/video-imports.ts index 14aed604f..4f9ecbe8e 100644 --- a/server/tests/api/videos/video-imports.ts +++ b/server/tests/api/videos/video-imports.ts @@ -3,6 +3,7 @@ import 'mocha' import * as chai from 'chai' import { + areHttpImportTestsDisabled, cleanupTests, doubleFollow, flushAndRunMultipleServers, @@ -11,20 +12,14 @@ import { getVideo, getVideosList, immutableAssign, + ImportsCommand, ServerInfo, setAccessTokensToServers, - testCaptionFile -} from '../../../../shared/extra-utils' -import { areHttpImportTestsDisabled, testImage } from '../../../../shared/extra-utils/miscs/miscs' -import { waitJobs } from '../../../../shared/extra-utils/server/jobs' -import { - getMagnetURI, - getMyVideoImports, - getYoutubeHDRVideoUrl, - getYoutubeVideoUrl, - importVideo -} from '../../../../shared/extra-utils/videos/video-imports' -import { VideoDetails, VideoImport, VideoPrivacy, VideoResolution } from '../../../../shared/models/videos' + testCaptionFile, + testImage, + waitJobs +} from '@shared/extra-utils' +import { VideoDetails, VideoPrivacy, VideoResolution } from '@shared/models' const expect = chai.expect @@ -124,17 +119,17 @@ describe('Test video imports', function () { } { - const attributes = immutableAssign(baseAttributes, { targetUrl: getYoutubeVideoUrl() }) - const res = await importVideo(servers[0].url, servers[0].accessToken, attributes) - expect(res.body.video.name).to.equal('small video - youtube') + const attributes = immutableAssign(baseAttributes, { targetUrl: ImportsCommand.getYoutubeVideoUrl() }) + const { video } = await servers[0].importsCommand.importVideo({ attributes }) + expect(video.name).to.equal('small video - youtube') - expect(res.body.video.thumbnailPath).to.match(new RegExp(`^/static/thumbnails/.+.jpg$`)) - expect(res.body.video.previewPath).to.match(new RegExp(`^/lazy-static/previews/.+.jpg$`)) + expect(video.thumbnailPath).to.match(new RegExp(`^/static/thumbnails/.+.jpg$`)) + expect(video.previewPath).to.match(new RegExp(`^/lazy-static/previews/.+.jpg$`)) - await testImage(servers[0].url, 'video_import_thumbnail', res.body.video.thumbnailPath) - await testImage(servers[0].url, 'video_import_preview', res.body.video.previewPath) + await testImage(servers[0].url, 'video_import_thumbnail', video.thumbnailPath) + await testImage(servers[0].url, 'video_import_preview', video.previewPath) - const bodyCaptions = await servers[0].captionsCommand.listVideoCaptions({ videoId: res.body.video.id }) + const bodyCaptions = await servers[0].captionsCommand.listVideoCaptions({ videoId: video.id }) const videoCaptions = bodyCaptions.data expect(videoCaptions).to.have.lengthOf(2) @@ -175,12 +170,12 @@ Ajouter un sous-titre est vraiment facile`) { const attributes = immutableAssign(baseAttributes, { - magnetUri: getMagnetURI(), + magnetUri: ImportsCommand.getMagnetURI(), description: 'this is a super torrent description', tags: [ 'tag_torrent1', 'tag_torrent2' ] }) - const res = await importVideo(servers[0].url, servers[0].accessToken, attributes) - expect(res.body.video.name).to.equal('super peertube2 video') + const { video } = await servers[0].importsCommand.importVideo({ attributes }) + expect(video.name).to.equal('super peertube2 video') } { @@ -189,8 +184,8 @@ Ajouter un sous-titre est vraiment facile`) description: 'this is a super torrent description', tags: [ 'tag_torrent1', 'tag_torrent2' ] }) - const res = await importVideo(servers[0].url, servers[0].accessToken, attributes) - expect(res.body.video.name).to.equal('你好 世界 720p.mp4') + const { video } = await servers[0].importsCommand.importVideo({ attributes }) + expect(video.name).to.equal('你好 世界 720p.mp4') } }) @@ -207,19 +202,18 @@ Ajouter un sous-titre est vraiment facile`) }) it('Should list the videos to import in my imports on server 1', async function () { - const res = await getMyVideoImports(servers[0].url, servers[0].accessToken, '-createdAt') + const { total, data: videoImports } = await servers[0].importsCommand.getMyVideoImports({ sort: '-createdAt' }) + expect(total).to.equal(3) - expect(res.body.total).to.equal(3) - const videoImports: VideoImport[] = res.body.data expect(videoImports).to.have.lengthOf(3) - expect(videoImports[2].targetUrl).to.equal(getYoutubeVideoUrl()) + expect(videoImports[2].targetUrl).to.equal(ImportsCommand.getYoutubeVideoUrl()) expect(videoImports[2].magnetUri).to.be.null expect(videoImports[2].torrentName).to.be.null expect(videoImports[2].video.name).to.equal('small video - youtube') expect(videoImports[1].targetUrl).to.be.null - expect(videoImports[1].magnetUri).to.equal(getMagnetURI()) + expect(videoImports[1].magnetUri).to.equal(ImportsCommand.getMagnetURI()) expect(videoImports[1].torrentName).to.be.null expect(videoImports[1].video.name).to.equal('super peertube2 video') @@ -248,7 +242,7 @@ Ajouter un sous-titre est vraiment facile`) this.timeout(60_000) const attributes = { - targetUrl: getYoutubeVideoUrl(), + targetUrl: ImportsCommand.getYoutubeVideoUrl(), channelId: channelIdServer2, privacy: VideoPrivacy.PUBLIC, category: 10, @@ -258,8 +252,8 @@ Ajouter un sous-titre est vraiment facile`) description: 'my super description', tags: [ 'supertag1', 'supertag2' ] } - const res = await importVideo(servers[1].url, servers[1].accessToken, attributes) - expect(res.body.video.name).to.equal('my super name') + const { video } = await servers[1].importsCommand.importVideo({ attributes }) + expect(video.name).to.equal('my super name') }) it('Should have the videos listed on the two instances', async function () { @@ -284,12 +278,12 @@ Ajouter un sous-titre est vraiment facile`) const attributes = { name: 'transcoded video', - magnetUri: getMagnetURI(), + magnetUri: ImportsCommand.getMagnetURI(), channelId: channelIdServer2, privacy: VideoPrivacy.PUBLIC } - const res = await importVideo(servers[1].url, servers[1].accessToken, attributes) - const videoUUID = res.body.video.uuid + const { video } = await servers[1].importsCommand.importVideo({ attributes }) + const videoUUID = video.uuid await waitJobs(servers) @@ -335,12 +329,12 @@ Ajouter un sous-titre est vraiment facile`) const attributes = { name: 'hdr video', - targetUrl: getYoutubeHDRVideoUrl(), + targetUrl: ImportsCommand.getYoutubeHDRVideoUrl(), channelId: channelIdServer1, privacy: VideoPrivacy.PUBLIC } - const res1 = await importVideo(servers[0].url, servers[0].accessToken, attributes) - const videoUUID = res1.body.video.uuid + const { video: videoImported } = await servers[0].importsCommand.importVideo({ attributes }) + const videoUUID = videoImported.uuid await waitJobs(servers) -- cgit v1.2.3 From 57f879a540551c3b958b0991c8e1e3657a4481d8 Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Fri, 9 Jul 2021 10:21:10 +0200 Subject: Introduce streaming playlists command --- server/tests/api/live/live.ts | 16 +++++++++++----- server/tests/api/redundancy/redundancy.ts | 2 +- server/tests/api/videos/video-hls.ts | 20 +++++++++++++------- 3 files changed, 25 insertions(+), 13 deletions(-) (limited to 'server/tests/api') diff --git a/server/tests/api/live/live.ts b/server/tests/api/live/live.ts index cb52e4431..0b06df44c 100644 --- a/server/tests/api/live/live.ts +++ b/server/tests/api/live/live.ts @@ -15,7 +15,6 @@ import { doubleFollow, flushAndRunMultipleServers, getMyVideosWithFilter, - getPlaylist, getVideo, getVideosList, getVideosWithFilters, @@ -397,20 +396,27 @@ describe('Test live', function () { // Only finite files are displayed expect(hlsPlaylist.files).to.have.lengthOf(0) - await checkResolutionsInMasterPlaylist(hlsPlaylist.playlistUrl, resolutions) + await checkResolutionsInMasterPlaylist({ server, playlistUrl: hlsPlaylist.playlistUrl, resolutions }) for (let i = 0; i < resolutions.length; i++) { const segmentNum = 3 const segmentName = `${i}-00000${segmentNum}.ts` await commands[0].waitUntilSegmentGeneration({ videoUUID: video.uuid, resolution: i, segment: segmentNum }) - const res = await getPlaylist(`${servers[0].url}/static/streaming-playlists/hls/${video.uuid}/${i}.m3u8`) - const subPlaylist = res.text + const subPlaylist = await servers[0].streamingPlaylistsCommand.get({ + url: `${servers[0].url}/static/streaming-playlists/hls/${video.uuid}/${i}.m3u8` + }) expect(subPlaylist).to.contain(segmentName) const baseUrlAndPath = servers[0].url + '/static/streaming-playlists/hls' - await checkLiveSegmentHash(baseUrlAndPath, video.uuid, segmentName, hlsPlaylist) + await checkLiveSegmentHash({ + server, + baseUrlSegment: baseUrlAndPath, + videoUUID: video.uuid, + segmentName, + hlsPlaylist + }) } } } diff --git a/server/tests/api/redundancy/redundancy.ts b/server/tests/api/redundancy/redundancy.ts index e4ea99de6..d20cb80f1 100644 --- a/server/tests/api/redundancy/redundancy.ts +++ b/server/tests/api/redundancy/redundancy.ts @@ -203,7 +203,7 @@ async function check1PlaylistRedundancies (videoUUID?: string) { const hlsPlaylist = (res.body as VideoDetails).streamingPlaylists[0] for (const resolution of [ 240, 360, 480, 720 ]) { - await checkSegmentHash(baseUrlPlaylist, baseUrlSegment, videoUUID, resolution, hlsPlaylist) + await checkSegmentHash({ server: servers[1], baseUrlPlaylist, baseUrlSegment, videoUUID, resolution, hlsPlaylist }) } const directories = [ diff --git a/server/tests/api/videos/video-hls.ts b/server/tests/api/videos/video-hls.ts index 3821cfed0..3dd8c9066 100644 --- a/server/tests/api/videos/video-hls.ts +++ b/server/tests/api/videos/video-hls.ts @@ -12,7 +12,6 @@ import { cleanupTests, doubleFollow, flushAndRunMultipleServers, - getPlaylist, getVideo, makeRawRequest, removeVideo, @@ -67,10 +66,9 @@ async function checkHlsPlaylist (servers: ServerInfo[], videoUUID: string, hlsOn } { - await checkResolutionsInMasterPlaylist(hlsPlaylist.playlistUrl, resolutions) + await checkResolutionsInMasterPlaylist({ server, playlistUrl: hlsPlaylist.playlistUrl, resolutions }) - const res = await getPlaylist(hlsPlaylist.playlistUrl) - const masterPlaylist = res.text + const masterPlaylist = await server.streamingPlaylistsCommand.get({ url: hlsPlaylist.playlistUrl }) for (const resolution of resolutions) { expect(masterPlaylist).to.contain(`${resolution}.m3u8`) @@ -80,9 +78,10 @@ async function checkHlsPlaylist (servers: ServerInfo[], videoUUID: string, hlsOn { for (const resolution of resolutions) { - const res = await getPlaylist(`${baseUrl}/static/streaming-playlists/hls/${videoUUID}/${resolution}.m3u8`) + const subPlaylist = await server.streamingPlaylistsCommand.get({ + url: `${baseUrl}/static/streaming-playlists/hls/${videoUUID}/${resolution}.m3u8` + }) - const subPlaylist = res.text expect(subPlaylist).to.contain(`${videoUUID}-${resolution}-fragmented.mp4`) } } @@ -91,7 +90,14 @@ async function checkHlsPlaylist (servers: ServerInfo[], videoUUID: string, hlsOn const baseUrlAndPath = baseUrl + '/static/streaming-playlists/hls' for (const resolution of resolutions) { - await checkSegmentHash(baseUrlAndPath, baseUrlAndPath, videoUUID, resolution, hlsPlaylist) + await checkSegmentHash({ + server, + baseUrlPlaylist: baseUrlAndPath, + baseUrlSegment: baseUrlAndPath, + videoUUID, + resolution, + hlsPlaylist + }) } } } -- 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 +- .../tests/api/notifications/user-notifications.ts | 7 +- .../tests/api/redundancy/redundancy-constraints.ts | 3 +- .../search/search-activitypub-video-channels.ts | 30 +-- .../tests/api/search/search-activitypub-videos.ts | 5 +- server/tests/api/search/search-channels.ts | 12 +- server/tests/api/server/plugins.ts | 2 + server/tests/api/server/stats.ts | 7 +- server/tests/api/users/users-multiple-servers.ts | 15 +- server/tests/api/users/users.ts | 5 +- server/tests/api/videos/multiple-servers.ts | 8 +- server/tests/api/videos/video-channels.ts | 249 ++++++++------------- server/tests/api/videos/video-playlists.ts | 9 +- 14 files changed, 143 insertions(+), 232 deletions(-) (limited to 'server/tests/api') 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 }) }) }) diff --git a/server/tests/api/notifications/user-notifications.ts b/server/tests/api/notifications/user-notifications.ts index a9315c818..1d159c48f 100644 --- a/server/tests/api/notifications/user-notifications.ts +++ b/server/tests/api/notifications/user-notifications.ts @@ -17,7 +17,6 @@ import { ServerInfo, updateMyUser, updateVideo, - updateVideoChannel, uploadRandomVideoOnServers, wait, waitJobs @@ -404,7 +403,11 @@ describe('Test user notifications', function () { displayName: 'super root 2 name' }) - await updateVideoChannel(servers[0].url, userAccessToken, 'user_1_channel', { displayName: myChannelName }) + await servers[0].channelsCommand.update({ + token: userAccessToken, + channelName: 'user_1_channel', + attributes: { displayName: myChannelName } + }) }) it('Should notify when a local channel is following one of our channel', async function () { diff --git a/server/tests/api/redundancy/redundancy-constraints.ts b/server/tests/api/redundancy/redundancy-constraints.ts index a666976b3..500b96747 100644 --- a/server/tests/api/redundancy/redundancy-constraints.ts +++ b/server/tests/api/redundancy/redundancy-constraints.ts @@ -1,6 +1,7 @@ /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */ import 'mocha' +import { expect } from 'chai' import { cleanupTests, flushAndRunServer, @@ -15,8 +16,6 @@ import { } from '@shared/extra-utils' import { VideoPrivacy } from '@shared/models' -const expect = chai.expect - describe('Test redundancy constraints', function () { let remoteServer: ServerInfo let localServer: ServerInfo diff --git a/server/tests/api/search/search-activitypub-video-channels.ts b/server/tests/api/search/search-activitypub-video-channels.ts index cf5158b66..83be9cd1e 100644 --- a/server/tests/api/search/search-activitypub-video-channels.ts +++ b/server/tests/api/search/search-activitypub-video-channels.ts @@ -3,19 +3,15 @@ import 'mocha' import * as chai from 'chai' import { - addVideoChannel, cleanupTests, createUser, - deleteVideoChannel, flushAndRunMultipleServers, - getVideoChannelsList, getVideoChannelVideos, SearchCommand, ServerInfo, setAccessTokensToServers, updateMyUser, updateVideo, - updateVideoChannel, uploadVideo, userLogin, wait, @@ -45,7 +41,7 @@ describe('Test ActivityPub video channels search', function () { name: 'channel1_server1', displayName: 'Channel 1 server 1' } - await addVideoChannel(servers[0].url, servers[0].accessToken, channel) + await servers[0].channelsCommand.create({ attributes: channel }) } { @@ -57,8 +53,8 @@ describe('Test ActivityPub video channels search', function () { name: 'channel1_server2', displayName: 'Channel 1 server 2' } - const resChannel = await addVideoChannel(servers[1].url, userServer2Token, channel) - channelIdServer2 = resChannel.body.videoChannel.id + const created = await servers[1].channelsCommand.create({ token: userServer2Token, attributes: channel }) + channelIdServer2 = created.id const res = await uploadVideo(servers[1].url, userServer2Token, { name: 'video 1 server 2', channelId: channelIdServer2 }) videoServer2UUID = res.body.video.uuid @@ -143,12 +139,12 @@ describe('Test ActivityPub video channels search', function () { }) it('Should not list this remote video channel', async function () { - const res = await getVideoChannelsList(servers[0].url, 0, 5) - expect(res.body.total).to.equal(3) - expect(res.body.data).to.have.lengthOf(3) - expect(res.body.data[0].name).to.equal('channel1_server1') - expect(res.body.data[1].name).to.equal('user1_server1_channel') - expect(res.body.data[2].name).to.equal('root_channel') + const body = await servers[0].channelsCommand.list() + expect(body.total).to.equal(3) + expect(body.data).to.have.lengthOf(3) + expect(body.data[0].name).to.equal('channel1_server1') + expect(body.data[1].name).to.equal('user1_server1_channel') + expect(body.data[2].name).to.equal('root_channel') }) it('Should list video channel videos of server 2 without token', async function () { @@ -171,7 +167,11 @@ describe('Test ActivityPub video channels search', function () { it('Should update video channel of server 2, and refresh it on server 1', async function () { this.timeout(60000) - await updateVideoChannel(servers[1].url, userServer2Token, 'channel1_server2', { displayName: 'channel updated' }) + await servers[1].channelsCommand.update({ + token: userServer2Token, + channelName: 'channel1_server2', + attributes: { displayName: 'channel updated' } + }) await updateMyUser({ url: servers[1].url, accessToken: userServer2Token, displayName: 'user updated' }) await waitJobs(servers) @@ -217,7 +217,7 @@ describe('Test ActivityPub video channels search', function () { it('Should delete video channel of server 2, and delete it on server 1', async function () { this.timeout(60000) - await deleteVideoChannel(servers[1].url, userServer2Token, 'channel1_server2') + await servers[1].channelsCommand.delete({ token: userServer2Token, channelName: 'channel1_server2' }) await waitJobs(servers) // Expire video diff --git a/server/tests/api/search/search-activitypub-videos.ts b/server/tests/api/search/search-activitypub-videos.ts index 7c6455258..403c84010 100644 --- a/server/tests/api/search/search-activitypub-videos.ts +++ b/server/tests/api/search/search-activitypub-videos.ts @@ -3,7 +3,6 @@ import 'mocha' import * as chai from 'chai' import { - addVideoChannel, cleanupTests, flushAndRunMultipleServers, getVideosList, @@ -123,8 +122,8 @@ describe('Test ActivityPub videos search', function () { name: 'super_channel', displayName: 'super channel' } - const resChannel = await addVideoChannel(servers[1].url, servers[1].accessToken, channelAttributes) - const videoChannelId = resChannel.body.videoChannel.id + const created = await servers[1].channelsCommand.create({ attributes: channelAttributes }) + const videoChannelId = created.id const attributes = { name: 'updated', diff --git a/server/tests/api/search/search-channels.ts b/server/tests/api/search/search-channels.ts index 307bc063d..6c9ee73ce 100644 --- a/server/tests/api/search/search-channels.ts +++ b/server/tests/api/search/search-channels.ts @@ -2,15 +2,7 @@ import 'mocha' import * as chai from 'chai' -import { - addVideoChannel, - cleanupTests, - createUser, - flushAndRunServer, - SearchCommand, - ServerInfo, - setAccessTokensToServers -} from '@shared/extra-utils' +import { cleanupTests, createUser, flushAndRunServer, SearchCommand, ServerInfo, setAccessTokensToServers } from '@shared/extra-utils' import { VideoChannel } from '@shared/models' const expect = chai.expect @@ -32,7 +24,7 @@ describe('Test channels search', function () { name: 'squall_channel', displayName: 'Squall channel' } - await addVideoChannel(server.url, server.accessToken, channel) + await server.channelsCommand.create({ attributes: channel }) } command = server.searchCommand diff --git a/server/tests/api/server/plugins.ts b/server/tests/api/server/plugins.ts index 528bbbe58..e22ecfad9 100644 --- a/server/tests/api/server/plugins.ts +++ b/server/tests/api/server/plugins.ts @@ -37,6 +37,8 @@ describe('Test plugins', function () { } server = await flushAndRunServer(1, configOverride) await setAccessTokensToServers([ server ]) + + command = server.pluginsCommand }) it('Should list and search available plugins and themes', async function () { diff --git a/server/tests/api/server/stats.ts b/server/tests/api/server/stats.ts index c877a65eb..9c954c347 100644 --- a/server/tests/api/server/stats.ts +++ b/server/tests/api/server/stats.ts @@ -3,7 +3,6 @@ import 'mocha' import * as chai from 'chai' import { - addVideoChannel, addVideoCommentThread, cleanupTests, createUser, @@ -143,12 +142,12 @@ describe('Test stats (excluding redundancy)', function () { } { - const channelAttributes = { + const attributes = { name: 'stats_channel', displayName: 'My stats channel' } - const resChannel = await addVideoChannel(server.url, server.accessToken, channelAttributes) - channelId = resChannel.body.videoChannel.id + const created = await server.channelsCommand.create({ attributes }) + channelId = created.id const data = await server.statsCommand.get() diff --git a/server/tests/api/users/users-multiple-servers.ts b/server/tests/api/users/users-multiple-servers.ts index 03fbfabeb..47056be78 100644 --- a/server/tests/api/users/users-multiple-servers.ts +++ b/server/tests/api/users/users-multiple-servers.ts @@ -12,7 +12,6 @@ import { flushAndRunMultipleServers, getAccountVideos, getMyUserInformation, - getVideoChannelsList, removeUser, ServerInfo, setAccessTokensToServers, @@ -23,7 +22,7 @@ import { userLogin, waitJobs } from '@shared/extra-utils' -import { User, VideoChannel } from '@shared/models' +import { User } from '@shared/models' const expect = chai.expect @@ -199,10 +198,8 @@ describe('Test users with multiple servers', function () { const accountDeleted = body.data.find(a => a.name === 'user1' && a.host === 'localhost:' + servers[0].port) expect(accountDeleted).not.to.be.undefined - const resVideoChannels = await getVideoChannelsList(server.url, 0, 10) - const videoChannelDeleted = resVideoChannels.body.data.find(a => { - return a.displayName === 'Main user1 channel' && a.host === 'localhost:' + servers[0].port - }) as VideoChannel + const { data } = await server.channelsCommand.list() + const videoChannelDeleted = data.find(a => a.displayName === 'Main user1 channel' && a.host === 'localhost:' + servers[0].port) expect(videoChannelDeleted).not.to.be.undefined } @@ -216,10 +213,8 @@ describe('Test users with multiple servers', function () { const accountDeleted = body.data.find(a => a.name === 'user1' && a.host === 'localhost:' + servers[0].port) expect(accountDeleted).to.be.undefined - const resVideoChannels = await getVideoChannelsList(server.url, 0, 10) - const videoChannelDeleted = resVideoChannels.body.data.find(a => { - return a.name === 'Main user1 channel' && a.host === 'localhost:' + servers[0].port - }) as VideoChannel + const { data } = await server.channelsCommand.list() + const videoChannelDeleted = data.find(a => a.name === 'Main user1 channel' && a.host === 'localhost:' + servers[0].port) expect(videoChannelDeleted).to.be.undefined } }) diff --git a/server/tests/api/users/users.ts b/server/tests/api/users/users.ts index 4b9056306..ed670b3c9 100644 --- a/server/tests/api/users/users.ts +++ b/server/tests/api/users/users.ts @@ -18,7 +18,6 @@ import { getUserInformation, getUsersList, getUsersListPaginationAndSort, - getVideoChannel, getVideosList, killallServers, login, @@ -864,9 +863,9 @@ describe('Test users', function () { }) it('Should have created the channel', async function () { - const res = await getVideoChannel(server.url, 'my_user_15_channel') + const { displayName } = await server.channelsCommand.get({ channelName: 'my_user_15_channel' }) - expect(res.body.displayName).to.equal('my channel rocks') + expect(displayName).to.equal('my channel rocks') }) it('Should remove me', async function () { diff --git a/server/tests/api/videos/multiple-servers.ts b/server/tests/api/videos/multiple-servers.ts index a8c8a889b..a59d5a858 100644 --- a/server/tests/api/videos/multiple-servers.ts +++ b/server/tests/api/videos/multiple-servers.ts @@ -5,7 +5,6 @@ import * as chai from 'chai' import * as request from 'supertest' import { HttpStatusCode } from '../../../../shared/core-utils/miscs/http-error-codes' import { - addVideoChannel, buildAbsoluteFixturePath, checkTmpIsEmpty, checkVideoFilesWereRemoved, @@ -17,7 +16,6 @@ import { flushAndRunMultipleServers, getLocalVideos, getVideo, - getVideoChannelsList, getVideosList, rateVideo, removeVideo, @@ -64,9 +62,9 @@ describe('Test multiple servers', function () { displayName: 'my channel', description: 'super channel' } - await addVideoChannel(servers[0].url, servers[0].accessToken, videoChannel) - const channelRes = await getVideoChannelsList(servers[0].url, 0, 1) - videoChannelId = channelRes.body.data[0].id + await servers[0].channelsCommand.create({ attributes: videoChannel }) + const { data } = await servers[0].channelsCommand.list({ start: 0, count: 1 }) + videoChannelId = data[0].id } // Server 1 and server 2 follow each other diff --git a/server/tests/api/videos/video-channels.ts b/server/tests/api/videos/video-channels.ts index 865098777..daf066eb1 100644 --- a/server/tests/api/videos/video-channels.ts +++ b/server/tests/api/videos/video-channels.ts @@ -7,43 +7,29 @@ import { ACTOR_IMAGES_SIZE } from '@server/initializers/constants' import { cleanupTests, createUser, - deleteVideoChannelImage, doubleFollow, flushAndRunMultipleServers, getActorImage, getVideo, - getVideoChannel, getVideoChannelVideos, setDefaultVideoChannel, testFileExistsOrNot, testImage, updateVideo, - updateVideoChannelImage, uploadVideo, userLogin, wait } from '../../../../shared/extra-utils' -import { - addVideoChannel, - deleteVideoChannel, - getAccountVideoChannelsList, - getMyUserInformation, - getVideoChannelsList, - ServerInfo, - setAccessTokensToServers, - updateVideoChannel, - viewVideo -} from '../../../../shared/extra-utils/index' +import { getMyUserInformation, ServerInfo, setAccessTokensToServers, viewVideo } from '../../../../shared/extra-utils/index' import { waitJobs } from '../../../../shared/extra-utils/server/jobs' import { User, Video, VideoChannel, VideoDetails } from '../../../../shared/index' const expect = chai.expect async function findChannel (server: ServerInfo, channelId: number) { - const res = await getVideoChannelsList(server.url, 0, 5, '-name') - const videoChannel = res.body.data.find(c => c.id === channelId) + const body = await server.channelsCommand.list({ sort: '-name' }) - return videoChannel as VideoChannel + return body.data.find(c => c.id === channelId) } describe('Test video channels', function () { @@ -69,11 +55,11 @@ describe('Test video channels', function () { }) it('Should have one video channel (created with root)', async () => { - const res = await getVideoChannelsList(servers[0].url, 0, 2) + const body = await servers[0].channelsCommand.list({ start: 0, count: 2 }) - expect(res.body.total).to.equal(1) - expect(res.body.data).to.be.an('array') - expect(res.body.data).to.have.lengthOf(1) + expect(body.total).to.equal(1) + expect(body.data).to.be.an('array') + expect(body.data).to.have.lengthOf(1) }) it('Should create another video channel', async function () { @@ -86,8 +72,8 @@ describe('Test video channels', function () { description: 'super video channel description', support: 'super video channel support text' } - const res = await addVideoChannel(servers[0].url, servers[0].accessToken, videoChannel) - secondVideoChannelId = res.body.videoChannel.id + const created = await servers[0].channelsCommand.create({ attributes: videoChannel }) + secondVideoChannelId = created.id } // The channel is 1 is propagated to servers 2 @@ -120,16 +106,14 @@ describe('Test video channels', function () { }) it('Should have two video channels when getting account channels on server 1', async function () { - const res = await getAccountVideoChannelsList({ - url: servers[0].url, - accountName - }) + const body = await servers[0].channelsCommand.listByAccount({ accountName }) + expect(body.total).to.equal(2) - expect(res.body.total).to.equal(2) - expect(res.body.data).to.be.an('array') - expect(res.body.data).to.have.lengthOf(2) + const videoChannels = body.data + + expect(videoChannels).to.be.an('array') + expect(videoChannels).to.have.lengthOf(2) - const videoChannels = res.body.data expect(videoChannels[0].name).to.equal('root_channel') expect(videoChannels[0].displayName).to.equal('Main root channel') @@ -141,79 +125,69 @@ describe('Test video channels', function () { it('Should paginate and sort account channels', async function () { { - const res = await getAccountVideoChannelsList({ - url: servers[0].url, + const body = await servers[0].channelsCommand.listByAccount({ accountName, start: 0, count: 1, sort: 'createdAt' }) - expect(res.body.total).to.equal(2) - expect(res.body.data).to.have.lengthOf(1) + expect(body.total).to.equal(2) + expect(body.data).to.have.lengthOf(1) - const videoChannel: VideoChannel = res.body.data[0] + const videoChannel: VideoChannel = body.data[0] expect(videoChannel.name).to.equal('root_channel') } { - const res = await getAccountVideoChannelsList({ - url: servers[0].url, + const body = await servers[0].channelsCommand.listByAccount({ accountName, start: 0, count: 1, sort: '-createdAt' }) - expect(res.body.total).to.equal(2) - expect(res.body.data).to.have.lengthOf(1) - - const videoChannel: VideoChannel = res.body.data[0] - expect(videoChannel.name).to.equal('second_video_channel') + expect(body.total).to.equal(2) + expect(body.data).to.have.lengthOf(1) + expect(body.data[0].name).to.equal('second_video_channel') } { - const res = await getAccountVideoChannelsList({ - url: servers[0].url, + const body = await servers[0].channelsCommand.listByAccount({ accountName, start: 1, count: 1, sort: '-createdAt' }) - expect(res.body.total).to.equal(2) - expect(res.body.data).to.have.lengthOf(1) - - const videoChannel: VideoChannel = res.body.data[0] - expect(videoChannel.name).to.equal('root_channel') + expect(body.total).to.equal(2) + expect(body.data).to.have.lengthOf(1) + expect(body.data[0].name).to.equal('root_channel') } }) it('Should have one video channel when getting account channels on server 2', async function () { - const res = await getAccountVideoChannelsList({ - url: servers[1].url, - accountName - }) + const body = await servers[1].channelsCommand.listByAccount({ accountName }) - expect(res.body.total).to.equal(1) - expect(res.body.data).to.be.an('array') - expect(res.body.data).to.have.lengthOf(1) + expect(body.total).to.equal(1) + expect(body.data).to.be.an('array') + expect(body.data).to.have.lengthOf(1) - const videoChannels = res.body.data - expect(videoChannels[0].name).to.equal('second_video_channel') - expect(videoChannels[0].displayName).to.equal('second video channel') - expect(videoChannels[0].description).to.equal('super video channel description') - expect(videoChannels[0].support).to.equal('super video channel support text') + const videoChannel = body.data[0] + expect(videoChannel.name).to.equal('second_video_channel') + expect(videoChannel.displayName).to.equal('second video channel') + expect(videoChannel.description).to.equal('super video channel description') + expect(videoChannel.support).to.equal('super video channel support text') }) it('Should list video channels', async function () { - const res = await getVideoChannelsList(servers[0].url, 1, 1, '-name') + const body = await servers[0].channelsCommand.list({ start: 1, count: 1, sort: '-name' }) - expect(res.body.total).to.equal(2) - expect(res.body.data).to.be.an('array') - expect(res.body.data).to.have.lengthOf(1) - expect(res.body.data[0].name).to.equal('root_channel') - expect(res.body.data[0].displayName).to.equal('Main root channel') + expect(body.total).to.equal(2) + expect(body.data).to.be.an('array') + expect(body.data).to.have.lengthOf(1) + expect(body.data[0].name).to.equal('root_channel') + expect(body.data[0].displayName).to.equal('Main root channel') }) it('Should update video channel', async function () { @@ -225,22 +199,23 @@ describe('Test video channels', function () { support: 'support updated' } - await updateVideoChannel(servers[0].url, servers[0].accessToken, 'second_video_channel', videoChannelAttributes) + await servers[0].channelsCommand.update({ channelName: 'second_video_channel', attributes: videoChannelAttributes }) await waitJobs(servers) }) it('Should have video channel updated', async function () { for (const server of servers) { - const res = await getVideoChannelsList(server.url, 0, 1, '-name') - - expect(res.body.total).to.equal(2) - expect(res.body.data).to.be.an('array') - expect(res.body.data).to.have.lengthOf(1) - expect(res.body.data[0].name).to.equal('second_video_channel') - expect(res.body.data[0].displayName).to.equal('video channel updated') - expect(res.body.data[0].description).to.equal('video channel description updated') - expect(res.body.data[0].support).to.equal('support updated') + const body = await server.channelsCommand.list({ start: 0, count: 1, sort: '-name' }) + + expect(body.total).to.equal(2) + expect(body.data).to.be.an('array') + expect(body.data).to.have.lengthOf(1) + + expect(body.data[0].name).to.equal('second_video_channel') + expect(body.data[0].displayName).to.equal('video channel updated') + expect(body.data[0].description).to.equal('video channel description updated') + expect(body.data[0].support).to.equal('support updated') } }) @@ -261,7 +236,7 @@ describe('Test video channels', function () { bulkVideosSupportUpdate: true } - await updateVideoChannel(servers[0].url, servers[0].accessToken, 'second_video_channel', videoChannelAttributes) + await servers[0].channelsCommand.update({ channelName: 'second_video_channel', attributes: videoChannelAttributes }) await waitJobs(servers) @@ -278,10 +253,8 @@ describe('Test video channels', function () { const fixture = 'avatar.png' - await updateVideoChannelImage({ - url: servers[0].url, - accessToken: servers[0].accessToken, - videoChannelName: 'second_video_channel', + await servers[0].channelsCommand.updateImage({ + channelName: 'second_video_channel', fixture, type: 'avatar' }) @@ -306,10 +279,8 @@ describe('Test video channels', function () { const fixture = 'banner.jpg' - await updateVideoChannelImage({ - url: servers[0].url, - accessToken: servers[0].accessToken, - videoChannelName: 'second_video_channel', + await servers[0].channelsCommand.updateImage({ + channelName: 'second_video_channel', fixture, type: 'banner' }) @@ -317,8 +288,7 @@ describe('Test video channels', function () { await waitJobs(servers) for (const server of servers) { - const res = await getVideoChannel(server.url, 'second_video_channel@' + servers[0].host) - const videoChannel = res.body + const videoChannel = await server.channelsCommand.get({ channelName: 'second_video_channel@' + servers[0].host }) bannerPaths[server.port] = videoChannel.banner.path await testImage(server.url, 'banner-resized', bannerPaths[server.port]) @@ -333,12 +303,7 @@ describe('Test video channels', function () { it('Should delete the video channel avatar', async function () { this.timeout(15000) - await deleteVideoChannelImage({ - url: servers[0].url, - accessToken: servers[0].accessToken, - videoChannelName: 'second_video_channel', - type: 'avatar' - }) + await servers[0].channelsCommand.deleteImage({ channelName: 'second_video_channel', type: 'avatar' }) await waitJobs(servers) @@ -353,12 +318,7 @@ describe('Test video channels', function () { it('Should delete the video channel banner', async function () { this.timeout(15000) - await deleteVideoChannelImage({ - url: servers[0].url, - accessToken: servers[0].accessToken, - videoChannelName: 'second_video_channel', - type: 'banner' - }) + await servers[0].channelsCommand.deleteImage({ channelName: 'second_video_channel', type: 'banner' }) await waitJobs(servers) @@ -411,23 +371,23 @@ describe('Test video channels', function () { }) it('Should delete video channel', async function () { - await deleteVideoChannel(servers[0].url, servers[0].accessToken, 'second_video_channel') + await servers[0].channelsCommand.delete({ channelName: 'second_video_channel' }) }) it('Should have video channel deleted', async function () { - const res = await getVideoChannelsList(servers[0].url, 0, 10) + const body = await servers[0].channelsCommand.list({ start: 0, count: 10 }) - expect(res.body.total).to.equal(1) - expect(res.body.data).to.be.an('array') - expect(res.body.data).to.have.lengthOf(1) - expect(res.body.data[0].displayName).to.equal('Main root channel') + expect(body.total).to.equal(1) + expect(body.data).to.be.an('array') + expect(body.data).to.have.lengthOf(1) + expect(body.data[0].displayName).to.equal('Main root channel') }) it('Should create the main channel with an uuid if there is a conflict', async function () { { const videoChannel = { name: 'toto_channel', displayName: 'My toto channel' } - const res = await addVideoChannel(servers[0].url, servers[0].accessToken, videoChannel) - totoChannel = res.body.videoChannel.id + const created = await servers[0].channelsCommand.create({ attributes: videoChannel }) + totoChannel = created.id } { @@ -444,15 +404,9 @@ describe('Test video channels', function () { this.timeout(10000) { - const res = await getAccountVideoChannelsList({ - url: servers[0].url, - accountName, - withStats: true - }) - - const channels: VideoChannel[] = res.body.data + const { data } = await servers[0].channelsCommand.listByAccount({ accountName, withStats: true }) - for (const channel of channels) { + for (const channel of data) { expect(channel).to.haveOwnProperty('viewsPerDay') expect(channel.viewsPerDay).to.have.length(30 + 1) // daysPrior + today @@ -471,26 +425,17 @@ describe('Test video channels', function () { // Wait the repeatable job await wait(8000) - const res = await getAccountVideoChannelsList({ - url: servers[0].url, - accountName, - withStats: true - }) - const channelWithView = res.body.data.find((channel: VideoChannel) => channel.id === servers[0].videoChannel.id) + const { data } = await servers[0].channelsCommand.listByAccount({ accountName, withStats: true }) + const channelWithView = data.find(channel => channel.id === servers[0].videoChannel.id) expect(channelWithView.viewsPerDay.slice(-1)[0].views).to.equal(2) } }) it('Should report correct videos count', async function () { - const res = await getAccountVideoChannelsList({ - url: servers[0].url, - accountName, - withStats: true - }) - const channels: VideoChannel[] = res.body.data + const { data } = await servers[0].channelsCommand.listByAccount({ accountName, withStats: true }) - const totoChannel = channels.find(c => c.name === 'toto_channel') - const rootChannel = channels.find(c => c.name === 'root_channel') + const totoChannel = data.find(c => c.name === 'toto_channel') + const rootChannel = data.find(c => c.name === 'root_channel') expect(rootChannel.videosCount).to.equal(1) expect(totoChannel.videosCount).to.equal(0) @@ -498,26 +443,18 @@ describe('Test video channels', function () { it('Should search among account video channels', async function () { { - const res = await getAccountVideoChannelsList({ - url: servers[0].url, - accountName, - search: 'root' - }) - expect(res.body.total).to.equal(1) + const body = await servers[0].channelsCommand.listByAccount({ accountName, search: 'root' }) + expect(body.total).to.equal(1) - const channels = res.body.data + const channels = body.data expect(channels).to.have.lengthOf(1) } { - const res = await getAccountVideoChannelsList({ - url: servers[0].url, - accountName, - search: 'does not exist' - }) - expect(res.body.total).to.equal(0) + const body = await servers[0].channelsCommand.listByAccount({ accountName, search: 'does not exist' }) + expect(body.total).to.equal(0) - const channels = res.body.data + const channels = body.data expect(channels).to.have.lengthOf(0) } }) @@ -529,30 +466,20 @@ describe('Test video channels', function () { await waitJobs(servers) for (const server of servers) { - const res = await getAccountVideoChannelsList({ - url: server.url, - accountName, - sort: '-updatedAt' - }) + const { data } = await server.channelsCommand.listByAccount({ accountName, sort: '-updatedAt' }) - const channels: VideoChannel[] = res.body.data - expect(channels[0].name).to.equal('toto_channel') - expect(channels[1].name).to.equal('root_channel') + expect(data[0].name).to.equal('toto_channel') + expect(data[1].name).to.equal('root_channel') } await uploadVideo(servers[0].url, servers[0].accessToken, { channelId: servers[0].videoChannel.id }) await waitJobs(servers) for (const server of servers) { - const res = await getAccountVideoChannelsList({ - url: server.url, - accountName, - sort: '-updatedAt' - }) + const { data } = await server.channelsCommand.listByAccount({ accountName, sort: '-updatedAt' }) - const channels: VideoChannel[] = res.body.data - expect(channels[0].name).to.equal('root_channel') - expect(channels[1].name).to.equal('toto_channel') + expect(data[0].name).to.equal('root_channel') + expect(data[1].name).to.equal('toto_channel') } }) diff --git a/server/tests/api/videos/video-playlists.ts b/server/tests/api/videos/video-playlists.ts index 4de6b3abf..2bb019348 100644 --- a/server/tests/api/videos/video-playlists.ts +++ b/server/tests/api/videos/video-playlists.ts @@ -4,11 +4,9 @@ import 'mocha' import * as chai from 'chai' import { HttpStatusCode } from '@shared/core-utils' import { - addVideoChannel, checkPlaylistFilesWereRemoved, cleanupTests, createUser, - deleteVideoChannel, doubleFollow, flushAndRunMultipleServers, generateUserAccessToken, @@ -1096,20 +1094,19 @@ describe('Test video playlists', function () { it('Should delete a channel and put the associated playlist in private mode', async function () { this.timeout(30000) - const res = await addVideoChannel(servers[0].url, servers[0].accessToken, { name: 'super_channel', displayName: 'super channel' }) - const videoChannelId = res.body.videoChannel.id + const channel = await servers[0].channelsCommand.create({ attributes: { name: 'super_channel', displayName: 'super channel' } }) const playlistCreated = await commands[0].create({ attributes: { displayName: 'channel playlist', privacy: VideoPlaylistPrivacy.PUBLIC, - videoChannelId + videoChannelId: channel.id } }) await waitJobs(servers) - await deleteVideoChannel(servers[0].url, servers[0].accessToken, 'super_channel') + await servers[0].channelsCommand.delete({ channelName: 'super_channel' }) await waitJobs(servers) -- 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/activitypub/cleaner.ts | 25 +-- server/tests/api/check-params/video-comments.ts | 27 ++- server/tests/api/moderation/abuses.ts | 29 ++- .../tests/api/moderation/blocklist-notification.ts | 7 +- server/tests/api/moderation/blocklist.ts | 196 ++++++++++----------- .../api/notifications/comments-notifications.ts | 123 ++++++------- .../api/notifications/moderation-notifications.ts | 20 ++- server/tests/api/server/bulk.ts | 63 ++++--- server/tests/api/server/follows.ts | 53 +++--- server/tests/api/server/handle-down.ts | 69 ++++---- server/tests/api/server/stats.ts | 3 +- server/tests/api/users/users.ts | 3 +- server/tests/api/videos/multiple-servers.ts | 99 +++++------ server/tests/api/videos/video-comments.ts | 193 +++++++++----------- 14 files changed, 419 insertions(+), 491 deletions(-) (limited to 'server/tests/api') diff --git a/server/tests/api/activitypub/cleaner.ts b/server/tests/api/activitypub/cleaner.ts index 75ef56ce3..27f17b4d6 100644 --- a/server/tests/api/activitypub/cleaner.ts +++ b/server/tests/api/activitypub/cleaner.ts @@ -7,16 +7,19 @@ import { closeAllSequelize, deleteAll, doubleFollow, + flushAndRunMultipleServers, getCount, + getVideo, + rateVideo, selectQuery, + ServerInfo, + setAccessTokensToServers, setVideoField, updateQuery, - wait -} from '../../../../shared/extra-utils' -import { flushAndRunMultipleServers, ServerInfo, setAccessTokensToServers } from '../../../../shared/extra-utils/index' -import { waitJobs } from '../../../../shared/extra-utils/server/jobs' -import { addVideoCommentThread, getVideoCommentThreads } from '../../../../shared/extra-utils/videos/video-comments' -import { getVideo, rateVideo, uploadVideoAndGetId } from '../../../../shared/extra-utils/videos/videos' + uploadVideoAndGetId, + wait, + waitJobs +} from '@shared/extra-utils' const expect = chai.expect @@ -63,7 +66,7 @@ describe('Test AP cleaner', function () { for (const server of servers) { for (const uuid of videoUUIDs) { await rateVideo(server.url, server.accessToken, uuid, 'like') - await addVideoCommentThread(server.url, server.accessToken, uuid, 'comment') + await server.commentsCommand.createThread({ videoId: uuid, text: 'comment' }) } } @@ -172,8 +175,8 @@ describe('Test AP cleaner', function () { this.timeout(20000) { - const res = await getVideoCommentThreads(servers[0].url, videoUUID1, 0, 5) - expect(res.body.total).to.equal(3) + const { total } = await servers[0].commentsCommand.listThreads({ videoId: videoUUID1 }) + expect(total).to.equal(3) } await deleteAll(servers[2].internalServerNumber, 'videoComment') @@ -182,8 +185,8 @@ describe('Test AP cleaner', function () { await waitJobs(servers) { - const res = await getVideoCommentThreads(servers[0].url, videoUUID1, 0, 5) - expect(res.body.total).to.equal(2) + const { total } = await servers[0].commentsCommand.listThreads({ videoId: videoUUID1 }) + expect(total).to.equal(2) } }) 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 diff --git a/server/tests/api/moderation/abuses.ts b/server/tests/api/moderation/abuses.ts index a2bd07b12..e428cf1a8 100644 --- a/server/tests/api/moderation/abuses.ts +++ b/server/tests/api/moderation/abuses.ts @@ -4,14 +4,11 @@ import 'mocha' import * as chai from 'chai' import { AbusesCommand, - addVideoCommentThread, cleanupTests, createUser, - deleteVideoComment, doubleFollow, flushAndRunMultipleServers, generateUserAccessToken, - getVideoCommentThreads, getVideoIdFromUUID, getVideosList, removeUser, @@ -23,7 +20,7 @@ import { userLogin, waitJobs } from '@shared/extra-utils' -import { AbuseMessage, AbusePredefinedReasonsString, AbuseState, AdminAbuse, UserAbuse, VideoComment } from '@shared/models' +import { AbuseMessage, AbusePredefinedReasonsString, AbuseState, AdminAbuse, UserAbuse } from '@shared/models' const expect = chai.expect @@ -399,14 +396,14 @@ describe('Test abuses', function () { describe('Comment abuses', function () { - async function getComment (url: string, videoIdArg: number | string) { + async function getComment (server: ServerInfo, videoIdArg: number | string) { const videoId = typeof videoIdArg === 'string' - ? await getVideoIdFromUUID(url, videoIdArg) + ? await getVideoIdFromUUID(server.url, videoIdArg) : videoIdArg - const res = await getVideoCommentThreads(url, videoId, 0, 5) + const { data } = await server.commentsCommand.listThreads({ videoId }) - return res.body.data[0] as VideoComment + return data[0] } before(async function () { @@ -415,8 +412,8 @@ describe('Test abuses', function () { servers[0].video = await uploadVideoAndGetId({ server: servers[0], videoName: 'server 1' }) servers[1].video = await uploadVideoAndGetId({ server: servers[1], videoName: 'server 2' }) - await addVideoCommentThread(servers[0].url, servers[0].accessToken, servers[0].video.id, 'comment server 1') - await addVideoCommentThread(servers[1].url, servers[1].accessToken, servers[1].video.id, 'comment server 2') + await servers[0].commentsCommand.createThread({ videoId: servers[0].video.id, text: 'comment server 1' }) + await servers[1].commentsCommand.createThread({ videoId: servers[1].video.id, text: 'comment server 2' }) await waitJobs(servers) }) @@ -424,7 +421,7 @@ describe('Test abuses', function () { it('Should report abuse on a comment', async function () { this.timeout(15000) - const comment = await getComment(servers[0].url, servers[0].video.id) + const comment = await getComment(servers[0], servers[0].video.id) const reason = 'it is a bad comment' await commands[0].report({ commentId: comment.id, reason }) @@ -434,7 +431,7 @@ describe('Test abuses', function () { it('Should have 1 comment abuse on server 1 and 0 on server 2', async function () { { - const comment = await getComment(servers[0].url, servers[0].video.id) + const comment = await getComment(servers[0], servers[0].video.id) const body = await commands[0].getAdminList({ filter: 'comment' }) expect(body.total).to.equal(1) @@ -469,7 +466,7 @@ describe('Test abuses', function () { it('Should report abuse on a remote comment', async function () { this.timeout(10000) - const comment = await getComment(servers[0].url, servers[1].video.uuid) + const comment = await getComment(servers[0], servers[1].video.uuid) const reason = 'it is a really bad comment' await commands[0].report({ commentId: comment.id, reason }) @@ -478,7 +475,7 @@ describe('Test abuses', function () { }) it('Should have 2 comment abuses on server 1 and 1 on server 2', async function () { - const commentServer2 = await getComment(servers[0].url, servers[1].video.id) + const commentServer2 = await getComment(servers[0], servers[1].video.id) { const body = await commands[0].getAdminList({ filter: 'comment' }) @@ -537,9 +534,9 @@ describe('Test abuses', function () { it('Should keep the comment abuse when deleting the comment', async function () { this.timeout(10000) - const commentServer2 = await getComment(servers[0].url, servers[1].video.id) + const commentServer2 = await getComment(servers[0], servers[1].video.id) - await deleteVideoComment(servers[0].url, servers[0].accessToken, servers[1].video.uuid, commentServer2.id) + await servers[0].commentsCommand.delete({ videoId: servers[1].video.uuid, commentId: commentServer2.id }) await waitJobs(servers) diff --git a/server/tests/api/moderation/blocklist-notification.ts b/server/tests/api/moderation/blocklist-notification.ts index 5b9699816..a077d8739 100644 --- a/server/tests/api/moderation/blocklist-notification.ts +++ b/server/tests/api/moderation/blocklist-notification.ts @@ -3,7 +3,6 @@ import 'mocha' import * as chai from 'chai' import { - addVideoCommentThread, cleanupTests, createUser, doubleFollow, @@ -59,7 +58,11 @@ describe('Test blocklist', function () { } { - await addVideoCommentThread(servers[1].url, remoteUserToken, videoUUID, '@user2@' + servers[0].host + ' hello') + await servers[1].commentsCommand.createThread({ + token: remoteUserToken, + videoId: videoUUID, + text: '@user2@' + servers[0].host + ' hello' + }) } { diff --git a/server/tests/api/moderation/blocklist.ts b/server/tests/api/moderation/blocklist.ts index 1b8860571..00cb6c65c 100644 --- a/server/tests/api/moderation/blocklist.ts +++ b/server/tests/api/moderation/blocklist.ts @@ -3,55 +3,47 @@ import 'mocha' import * as chai from 'chai' import { - addVideoCommentReply, - addVideoCommentThread, BlocklistCommand, cleanupTests, + CommentsCommand, createUser, - deleteVideoComment, doubleFollow, - findCommentId, flushAndRunMultipleServers, getUserNotifications, - getVideoCommentThreads, getVideosList, getVideosListWithToken, - getVideoThreadComments, ServerInfo, setAccessTokensToServers, uploadVideo, userLogin, waitJobs } from '@shared/extra-utils' -import { UserNotification, UserNotificationType, Video, VideoComment, VideoCommentThreadTree } from '@shared/models' +import { UserNotification, UserNotificationType, Video } from '@shared/models' const expect = chai.expect -async function checkAllVideos (url: string, token: string) { +async function checkAllVideos (server: ServerInfo, token: string) { { - const res = await getVideosListWithToken(url, token) + const res = await getVideosListWithToken(server.url, token) expect(res.body.data).to.have.lengthOf(5) } { - const res = await getVideosList(url) + const res = await getVideosList(server.url) expect(res.body.data).to.have.lengthOf(5) } } -async function checkAllComments (url: string, token: string, videoUUID: string) { - const resThreads = await getVideoCommentThreads(url, videoUUID, 0, 25, '-createdAt', token) +async function checkAllComments (server: ServerInfo, token: string, videoUUID: string) { + const { data } = await server.commentsCommand.listThreads({ videoId: videoUUID, start: 0, count: 25, sort: '-createdAt', token }) - const allThreads: VideoComment[] = resThreads.body.data - const threads = allThreads.filter(t => t.isDeleted === false) + const threads = data.filter(t => t.isDeleted === false) expect(threads).to.have.lengthOf(2) for (const thread of threads) { - const res = await getVideoThreadComments(url, videoUUID, thread.id, token) - - const tree: VideoCommentThreadTree = res.body + const tree = await server.commentsCommand.getThread({ videoId: videoUUID, threadId: thread.id, token }) expect(tree.children).to.have.lengthOf(1) } } @@ -61,10 +53,9 @@ async function checkCommentNotification ( comment: { server: ServerInfo, token: string, videoUUID: string, text: string }, check: 'presence' | 'absence' ) { - const resComment = await addVideoCommentThread(comment.server.url, comment.token, comment.videoUUID, comment.text) - const created = resComment.body.comment as VideoComment - const threadId = created.id - const createdAt = created.createdAt + const command = comment.server.commentsCommand + + const { threadId, createdAt } = await command.createThread({ token: comment.token, videoId: comment.videoUUID, text: comment.text }) await waitJobs([ mainServer, comment.server ]) @@ -75,7 +66,7 @@ async function checkCommentNotification ( if (check === 'presence') expect(commentNotifications).to.have.lengthOf(1) else expect(commentNotifications).to.have.lengthOf(0) - await deleteVideoComment(comment.server.url, comment.token, comment.videoUUID, threadId) + await command.delete({ token: comment.token, videoId: comment.videoUUID, commentId: threadId }) await waitJobs([ mainServer, comment.server ]) } @@ -90,6 +81,7 @@ describe('Test blocklist', function () { let userToken2: string let command: BlocklistCommand + let commentsCommand: CommentsCommand[] before(async function () { this.timeout(120000) @@ -97,6 +89,9 @@ describe('Test blocklist', function () { servers = await flushAndRunMultipleServers(3) await setAccessTokensToServers(servers) + command = servers[0].blocklistCommand + commentsCommand = servers.map(s => s.commentsCommand) + { const user = { username: 'user1', password: 'password' } await createUser({ url: servers[0].url, accessToken: servers[0].accessToken, username: user.username, password: user.password }) @@ -139,30 +134,33 @@ describe('Test blocklist', function () { await doubleFollow(servers[0], servers[2]) { - const resComment = await addVideoCommentThread(servers[0].url, servers[0].accessToken, videoUUID1, 'comment root 1') - const resReply = await addVideoCommentReply(servers[0].url, userToken1, videoUUID1, resComment.body.comment.id, 'comment user 1') - await addVideoCommentReply(servers[0].url, servers[0].accessToken, videoUUID1, resReply.body.comment.id, 'comment root 1') + const created = await commentsCommand[0].createThread({ videoId: videoUUID1, text: 'comment root 1' }) + const reply = await commentsCommand[0].addReply({ + token: userToken1, + videoId: videoUUID1, + toCommentId: created.id, + text: 'comment user 1' + }) + await commentsCommand[0].addReply({ videoId: videoUUID1, toCommentId: reply.id, text: 'comment root 1' }) } { - const resComment = await addVideoCommentThread(servers[0].url, userToken1, videoUUID1, 'comment user 1') - await addVideoCommentReply(servers[0].url, servers[0].accessToken, videoUUID1, resComment.body.comment.id, 'comment root 1') + const created = await commentsCommand[0].createThread({ token: userToken1, videoId: videoUUID1, text: 'comment user 1' }) + await commentsCommand[0].addReply({ videoId: videoUUID1, toCommentId: created.id, text: 'comment root 1' }) } await waitJobs(servers) - - command = servers[0].blocklistCommand }) describe('User blocklist', function () { describe('When managing account blocklist', function () { it('Should list all videos', function () { - return checkAllVideos(servers[0].url, servers[0].accessToken) + return checkAllVideos(servers[0], servers[0].accessToken) }) it('Should list the comments', function () { - return checkAllComments(servers[0].url, servers[0].accessToken, videoUUID1) + return checkAllComments(servers[0], servers[0].accessToken, videoUUID1) }) it('Should block a remote account', async function () { @@ -194,19 +192,26 @@ describe('Test blocklist', function () { }) it('Should hide its comments', async function () { - const resThreads = await getVideoCommentThreads(servers[0].url, videoUUID1, 0, 25, '-createdAt', servers[0].accessToken) - - const threads: VideoComment[] = resThreads.body.data - expect(threads).to.have.lengthOf(1) - expect(threads[0].totalReplies).to.equal(1) - - const t = threads.find(t => t.text === 'comment user 1') + const { data } = await commentsCommand[0].listThreads({ + token: servers[0].accessToken, + videoId: videoUUID1, + start: 0, + count: 25, + sort: '-createdAt' + }) + + expect(data).to.have.lengthOf(1) + expect(data[0].totalReplies).to.equal(1) + + const t = data.find(t => t.text === 'comment user 1') expect(t).to.be.undefined - for (const thread of threads) { - const res = await getVideoThreadComments(servers[0].url, videoUUID1, thread.id, servers[0].accessToken) - - const tree: VideoCommentThreadTree = res.body + for (const thread of data) { + const tree = await commentsCommand[0].getThread({ + videoId: videoUUID1, + threadId: thread.id, + token: servers[0].accessToken + }) expect(tree.children).to.have.lengthOf(0) } }) @@ -231,7 +236,7 @@ describe('Test blocklist', function () { }) it('Should list all the videos with another user', async function () { - return checkAllVideos(servers[0].url, userToken1) + return checkAllVideos(servers[0], userToken1) }) it('Should list blocked accounts', async function () { @@ -264,32 +269,29 @@ describe('Test blocklist', function () { this.timeout(60000) { - await addVideoCommentThread(servers[1].url, userToken2, videoUUID3, 'comment user 2') + await commentsCommand[1].createThread({ token: userToken2, videoId: videoUUID3, text: 'comment user 2' }) await waitJobs(servers) - await addVideoCommentThread(servers[0].url, servers[0].accessToken, videoUUID3, 'uploader') + await commentsCommand[0].createThread({ token: servers[0].accessToken, videoId: videoUUID3, text: 'uploader' }) await waitJobs(servers) - const commentId = await findCommentId(servers[1].url, videoUUID3, 'uploader') + const commentId = await commentsCommand[1].findCommentId({ videoId: videoUUID3, text: 'uploader' }) const message = 'reply by user 2' - const resReply = await addVideoCommentReply(servers[1].url, userToken2, videoUUID3, commentId, message) - await addVideoCommentReply(servers[1].url, servers[1].accessToken, videoUUID3, resReply.body.comment.id, 'another reply') + const reply = await commentsCommand[1].addReply({ token: userToken2, videoId: videoUUID3, toCommentId: commentId, text: message }) + await commentsCommand[1].addReply({ videoId: videoUUID3, toCommentId: reply.id, text: 'another reply' }) await waitJobs(servers) } // Server 2 has all the comments { - const resThreads = await getVideoCommentThreads(servers[1].url, videoUUID3, 0, 25, '-createdAt') - const threads: VideoComment[] = resThreads.body.data - - expect(threads).to.have.lengthOf(2) - expect(threads[0].text).to.equal('uploader') - expect(threads[1].text).to.equal('comment user 2') + const { data } = await commentsCommand[1].listThreads({ videoId: videoUUID3, count: 25, sort: '-createdAt' }) - const resReplies = await getVideoThreadComments(servers[1].url, videoUUID3, threads[0].id) + expect(data).to.have.lengthOf(2) + expect(data[0].text).to.equal('uploader') + expect(data[1].text).to.equal('comment user 2') - const tree: VideoCommentThreadTree = resReplies.body + const tree = await commentsCommand[1].getThread({ videoId: videoUUID3, threadId: data[0].id }) expect(tree.children).to.have.lengthOf(1) expect(tree.children[0].comment.text).to.equal('reply by user 2') expect(tree.children[0].children).to.have.lengthOf(1) @@ -298,20 +300,15 @@ describe('Test blocklist', function () { // Server 1 and 3 should only have uploader comments for (const server of [ servers[0], servers[2] ]) { - const resThreads = await getVideoCommentThreads(server.url, videoUUID3, 0, 25, '-createdAt') - const threads: VideoComment[] = resThreads.body.data + const { data } = await server.commentsCommand.listThreads({ videoId: videoUUID3, count: 25, sort: '-createdAt' }) - expect(threads).to.have.lengthOf(1) - expect(threads[0].text).to.equal('uploader') + expect(data).to.have.lengthOf(1) + expect(data[0].text).to.equal('uploader') - const resReplies = await getVideoThreadComments(server.url, videoUUID3, threads[0].id) + const tree = await server.commentsCommand.getThread({ videoId: videoUUID3, threadId: data[0].id }) - const tree: VideoCommentThreadTree = resReplies.body - if (server.serverNumber === 1) { - expect(tree.children).to.have.lengthOf(0) - } else { - expect(tree.children).to.have.lengthOf(1) - } + if (server.serverNumber === 1) expect(tree.children).to.have.lengthOf(0) + else expect(tree.children).to.have.lengthOf(1) } }) @@ -331,22 +328,19 @@ describe('Test blocklist', function () { it('Should display its comments on my video', async function () { for (const server of servers) { - const resThreads = await getVideoCommentThreads(server.url, videoUUID3, 0, 25, '-createdAt') - const threads: VideoComment[] = resThreads.body.data + const { data } = await server.commentsCommand.listThreads({ videoId: videoUUID3, count: 25, sort: '-createdAt' }) // Server 3 should not have 2 comment threads, because server 1 did not forward the server 2 comment if (server.serverNumber === 3) { - expect(threads).to.have.lengthOf(1) + expect(data).to.have.lengthOf(1) continue } - expect(threads).to.have.lengthOf(2) - expect(threads[0].text).to.equal('uploader') - expect(threads[1].text).to.equal('comment user 2') - - const resReplies = await getVideoThreadComments(server.url, videoUUID3, threads[0].id) + expect(data).to.have.lengthOf(2) + expect(data[0].text).to.equal('uploader') + expect(data[1].text).to.equal('comment user 2') - const tree: VideoCommentThreadTree = resReplies.body + const tree = await server.commentsCommand.getThread({ videoId: videoUUID3, threadId: data[0].id }) expect(tree.children).to.have.lengthOf(1) expect(tree.children[0].comment.text).to.equal('reply by user 2') expect(tree.children[0].children).to.have.lengthOf(1) @@ -359,7 +353,7 @@ describe('Test blocklist', function () { }) it('Should display its comments', function () { - return checkAllComments(servers[0].url, servers[0].accessToken, videoUUID1) + return checkAllComments(servers[0], servers[0].accessToken, videoUUID1) }) it('Should have a notification from a non blocked account', async function () { @@ -385,11 +379,11 @@ describe('Test blocklist', function () { describe('When managing server blocklist', function () { it('Should list all videos', function () { - return checkAllVideos(servers[0].url, servers[0].accessToken) + return checkAllVideos(servers[0], servers[0].accessToken) }) it('Should list the comments', function () { - return checkAllComments(servers[0].url, servers[0].accessToken, videoUUID1) + return checkAllComments(servers[0], servers[0].accessToken, videoUUID1) }) it('Should block a remote server', async function () { @@ -410,20 +404,19 @@ describe('Test blocklist', function () { }) it('Should list all the videos with another user', async function () { - return checkAllVideos(servers[0].url, userToken1) + return checkAllVideos(servers[0], userToken1) }) it('Should hide its comments', async function () { this.timeout(10000) - const resThreads = await addVideoCommentThread(servers[1].url, userToken2, videoUUID1, 'hidden comment 2') - const threadId = resThreads.body.comment.id + const { id } = await commentsCommand[1].createThread({ token: userToken2, videoId: videoUUID1, text: 'hidden comment 2' }) await waitJobs(servers) - await checkAllComments(servers[0].url, servers[0].accessToken, videoUUID1) + await checkAllComments(servers[0], servers[0].accessToken, videoUUID1) - await deleteVideoComment(servers[1].url, userToken2, videoUUID1, threadId) + await commentsCommand[1].delete({ token: userToken2, videoId: videoUUID1, commentId: id }) }) it('Should not have notifications from blocked server', async function () { @@ -460,11 +453,11 @@ describe('Test blocklist', function () { }) it('Should display its videos', function () { - return checkAllVideos(servers[0].url, servers[0].accessToken) + return checkAllVideos(servers[0], servers[0].accessToken) }) it('Should display its comments', function () { - return checkAllComments(servers[0].url, servers[0].accessToken, videoUUID1) + return checkAllComments(servers[0], servers[0].accessToken, videoUUID1) }) it('Should have notification from unblocked server', async function () { @@ -493,13 +486,13 @@ describe('Test blocklist', function () { describe('When managing account blocklist', function () { it('Should list all videos', async function () { for (const token of [ userModeratorToken, servers[0].accessToken ]) { - await checkAllVideos(servers[0].url, token) + await checkAllVideos(servers[0], token) } }) it('Should list the comments', async function () { for (const token of [ userModeratorToken, servers[0].accessToken ]) { - await checkAllComments(servers[0].url, token, videoUUID1) + await checkAllComments(servers[0], token, videoUUID1) } }) @@ -537,10 +530,8 @@ describe('Test blocklist', function () { it('Should hide its comments', async function () { for (const token of [ userModeratorToken, servers[0].accessToken ]) { - const resThreads = await getVideoCommentThreads(servers[0].url, videoUUID1, 0, 20, '-createdAt', token) - - let threads: VideoComment[] = resThreads.body.data - threads = threads.filter(t => t.isDeleted === false) + const { data } = await commentsCommand[0].listThreads({ videoId: videoUUID1, count: 20, sort: '-createdAt', token }) + const threads = data.filter(t => t.isDeleted === false) expect(threads).to.have.lengthOf(1) expect(threads[0].totalReplies).to.equal(1) @@ -549,9 +540,7 @@ describe('Test blocklist', function () { expect(t).to.be.undefined for (const thread of threads) { - const res = await getVideoThreadComments(servers[0].url, videoUUID1, thread.id, token) - - const tree: VideoCommentThreadTree = res.body + const tree = await commentsCommand[0].getThread({ videoId: videoUUID1, threadId: thread.id, token }) expect(tree.children).to.have.lengthOf(0) } } @@ -624,7 +613,7 @@ describe('Test blocklist', function () { it('Should display its comments', async function () { for (const token of [ userModeratorToken, servers[0].accessToken ]) { - await checkAllComments(servers[0].url, token, videoUUID1) + await checkAllComments(servers[0], token, videoUUID1) } }) @@ -651,13 +640,13 @@ describe('Test blocklist', function () { describe('When managing server blocklist', function () { it('Should list all videos', async function () { for (const token of [ userModeratorToken, servers[0].accessToken ]) { - await checkAllVideos(servers[0].url, token) + await checkAllVideos(servers[0], token) } }) it('Should list the comments', async function () { for (const token of [ userModeratorToken, servers[0].accessToken ]) { - await checkAllComments(servers[0].url, token, videoUUID1) + await checkAllComments(servers[0], token, videoUUID1) } }) @@ -686,14 +675,13 @@ describe('Test blocklist', function () { it('Should hide its comments', async function () { this.timeout(10000) - const resThreads = await addVideoCommentThread(servers[1].url, userToken2, videoUUID1, 'hidden comment 2') - const threadId = resThreads.body.comment.id + const { id } = await commentsCommand[1].createThread({ token: userToken2, videoId: videoUUID1, text: 'hidden comment 2' }) await waitJobs(servers) - await checkAllComments(servers[0].url, servers[0].accessToken, videoUUID1) + await checkAllComments(servers[0], servers[0].accessToken, videoUUID1) - await deleteVideoComment(servers[1].url, userToken2, videoUUID1, threadId) + await commentsCommand[1].delete({ token: userToken2, videoId: videoUUID1, commentId: id }) }) it('Should not have notification from blocked instances by instance', async function () { @@ -749,13 +737,13 @@ describe('Test blocklist', function () { it('Should list all videos', async function () { for (const token of [ userModeratorToken, servers[0].accessToken ]) { - await checkAllVideos(servers[0].url, token) + await checkAllVideos(servers[0], token) } }) it('Should list the comments', async function () { for (const token of [ userModeratorToken, servers[0].accessToken ]) { - await checkAllComments(servers[0].url, token, videoUUID1) + await checkAllComments(servers[0], token, videoUUID1) } }) diff --git a/server/tests/api/notifications/comments-notifications.ts b/server/tests/api/notifications/comments-notifications.ts index 13fcee843..ea6055386 100644 --- a/server/tests/api/notifications/comments-notifications.ts +++ b/server/tests/api/notifications/comments-notifications.ts @@ -3,14 +3,10 @@ import 'mocha' import * as chai from 'chai' import { - addVideoCommentReply, - addVideoCommentThread, checkCommentMention, CheckerBaseParams, checkNewCommentOnMyVideo, cleanupTests, - getVideoCommentThreads, - getVideoThreadComments, MockSmtpServer, prepareNotificationsTest, ServerInfo, @@ -18,13 +14,13 @@ import { uploadVideo, waitJobs } from '@shared/extra-utils' -import { UserNotification, VideoCommentThreadTree } from '@shared/models' +import { UserNotification } from '@shared/models' const expect = chai.expect describe('Test comments notifications', function () { let servers: ServerInfo[] = [] - let userAccessToken: string + let userToken: string let userNotifications: UserNotification[] = [] let emails: object[] = [] @@ -38,7 +34,7 @@ describe('Test comments notifications', function () { const res = await prepareNotificationsTest(2) emails = res.emails - userAccessToken = res.userAccessToken + userToken = res.userAccessToken servers = res.servers userNotifications = res.userNotifications }) @@ -51,7 +47,7 @@ describe('Test comments notifications', function () { server: servers[0], emails, socketNotifications: userNotifications, - token: userAccessToken + token: userToken } }) @@ -61,8 +57,8 @@ describe('Test comments notifications', function () { const resVideo = await uploadVideo(servers[0].url, servers[0].accessToken, { name: 'super video' }) const uuid = resVideo.body.video.uuid - const resComment = await addVideoCommentThread(servers[0].url, servers[0].accessToken, uuid, 'comment') - const commentId = resComment.body.comment.id + const created = await servers[0].commentsCommand.createThread({ videoId: uuid, text: 'comment' }) + const commentId = created.id await waitJobs(servers) await checkNewCommentOnMyVideo(baseParams, uuid, commentId, commentId, 'absence') @@ -71,11 +67,11 @@ describe('Test comments notifications', function () { it('Should not send a new comment notification if I comment my own video', async function () { this.timeout(20000) - const resVideo = await uploadVideo(servers[0].url, userAccessToken, { name: 'super video' }) + const resVideo = await uploadVideo(servers[0].url, userToken, { name: 'super video' }) const uuid = resVideo.body.video.uuid - const resComment = await addVideoCommentThread(servers[0].url, userAccessToken, uuid, 'comment') - const commentId = resComment.body.comment.id + const created = await servers[0].commentsCommand.createThread({ token: userToken, videoId: uuid, text: 'comment' }) + const commentId = created.id await waitJobs(servers) await checkNewCommentOnMyVideo(baseParams, uuid, commentId, commentId, 'absence') @@ -84,28 +80,28 @@ describe('Test comments notifications', function () { it('Should not send a new comment notification if the account is muted', async function () { this.timeout(20000) - await servers[0].blocklistCommand.addToMyBlocklist({ token: userAccessToken, account: 'root' }) + await servers[0].blocklistCommand.addToMyBlocklist({ token: userToken, account: 'root' }) - const resVideo = await uploadVideo(servers[0].url, userAccessToken, { name: 'super video' }) + const resVideo = await uploadVideo(servers[0].url, userToken, { name: 'super video' }) const uuid = resVideo.body.video.uuid - const resComment = await addVideoCommentThread(servers[0].url, servers[0].accessToken, uuid, 'comment') - const commentId = resComment.body.comment.id + const created = await servers[0].commentsCommand.createThread({ videoId: uuid, text: 'comment' }) + const commentId = created.id await waitJobs(servers) await checkNewCommentOnMyVideo(baseParams, uuid, commentId, commentId, 'absence') - await servers[0].blocklistCommand.removeFromMyBlocklist({ token: userAccessToken, account: 'root' }) + await servers[0].blocklistCommand.removeFromMyBlocklist({ token: userToken, account: 'root' }) }) it('Should send a new comment notification after a local comment on my video', async function () { this.timeout(20000) - const resVideo = await uploadVideo(servers[0].url, userAccessToken, { name: 'super video' }) + const resVideo = await uploadVideo(servers[0].url, userToken, { name: 'super video' }) const uuid = resVideo.body.video.uuid - const resComment = await addVideoCommentThread(servers[0].url, servers[0].accessToken, uuid, 'comment') - const commentId = resComment.body.comment.id + const created = await servers[0].commentsCommand.createThread({ videoId: uuid, text: 'comment' }) + const commentId = created.id await waitJobs(servers) await checkNewCommentOnMyVideo(baseParams, uuid, commentId, commentId, 'presence') @@ -114,33 +110,31 @@ describe('Test comments notifications', function () { it('Should send a new comment notification after a remote comment on my video', async function () { this.timeout(20000) - const resVideo = await uploadVideo(servers[0].url, userAccessToken, { name: 'super video' }) + const resVideo = await uploadVideo(servers[0].url, userToken, { name: 'super video' }) const uuid = resVideo.body.video.uuid await waitJobs(servers) - await addVideoCommentThread(servers[1].url, servers[1].accessToken, uuid, 'comment') + await servers[1].commentsCommand.createThread({ videoId: uuid, text: 'comment' }) await waitJobs(servers) - const resComment = await getVideoCommentThreads(servers[0].url, uuid, 0, 5) - expect(resComment.body.data).to.have.lengthOf(1) - const commentId = resComment.body.data[0].id + const { data } = await servers[0].commentsCommand.listThreads({ videoId: uuid }) + expect(data).to.have.lengthOf(1) + const commentId = data[0].id await checkNewCommentOnMyVideo(baseParams, uuid, commentId, commentId, 'presence') }) it('Should send a new comment notification after a local reply on my video', async function () { this.timeout(20000) - const resVideo = await uploadVideo(servers[0].url, userAccessToken, { name: 'super video' }) + const resVideo = await uploadVideo(servers[0].url, userToken, { name: 'super video' }) const uuid = resVideo.body.video.uuid - const resThread = await addVideoCommentThread(servers[0].url, servers[0].accessToken, uuid, 'comment') - const threadId = resThread.body.comment.id + const { id: threadId } = await servers[0].commentsCommand.createThread({ videoId: uuid, text: 'comment' }) - const resComment = await addVideoCommentReply(servers[0].url, servers[0].accessToken, uuid, threadId, 'reply') - const commentId = resComment.body.comment.id + const { id: commentId } = await servers[0].commentsCommand.addReply({ videoId: uuid, toCommentId: threadId, text: 'reply' }) await waitJobs(servers) await checkNewCommentOnMyVideo(baseParams, uuid, commentId, threadId, 'presence') @@ -149,24 +143,23 @@ describe('Test comments notifications', function () { it('Should send a new comment notification after a remote reply on my video', async function () { this.timeout(20000) - const resVideo = await uploadVideo(servers[0].url, userAccessToken, { name: 'super video' }) + const resVideo = await uploadVideo(servers[0].url, userToken, { name: 'super video' }) const uuid = resVideo.body.video.uuid await waitJobs(servers) { - const resThread = await addVideoCommentThread(servers[1].url, servers[1].accessToken, uuid, 'comment') - const threadId = resThread.body.comment.id - await addVideoCommentReply(servers[1].url, servers[1].accessToken, uuid, threadId, 'reply') + const created = await servers[1].commentsCommand.createThread({ videoId: uuid, text: 'comment' }) + const threadId = created.id + await servers[1].commentsCommand.addReply({ videoId: uuid, toCommentId: threadId, text: 'reply' }) } await waitJobs(servers) - const resThread = await getVideoCommentThreads(servers[0].url, uuid, 0, 5) - expect(resThread.body.data).to.have.lengthOf(1) - const threadId = resThread.body.data[0].id + const { data } = await servers[0].commentsCommand.listThreads({ videoId: uuid }) + expect(data).to.have.lengthOf(1) - const resComments = await getVideoThreadComments(servers[0].url, uuid, threadId) - const tree = resComments.body as VideoCommentThreadTree + const threadId = data[0].id + const tree = await servers[0].commentsCommand.getThread({ videoId: uuid, threadId }) expect(tree.children).to.have.lengthOf(1) const commentId = tree.children[0].comment.id @@ -177,10 +170,10 @@ describe('Test comments notifications', function () { it('Should convert markdown in comment to html', async function () { this.timeout(20000) - const resVideo = await uploadVideo(servers[0].url, userAccessToken, { name: 'cool video' }) + const resVideo = await uploadVideo(servers[0].url, userToken, { name: 'cool video' }) const uuid = resVideo.body.video.uuid - await addVideoCommentThread(servers[0].url, servers[0].accessToken, uuid, commentText) + await servers[0].commentsCommand.createThread({ videoId: uuid, text: commentText }) await waitJobs(servers) @@ -197,7 +190,7 @@ describe('Test comments notifications', function () { server: servers[0], emails, socketNotifications: userNotifications, - token: userAccessToken + token: userToken } await updateMyUser({ @@ -216,11 +209,10 @@ describe('Test comments notifications', function () { it('Should not send a new mention comment notification if I mention the video owner', async function () { this.timeout(10000) - const resVideo = await uploadVideo(servers[0].url, userAccessToken, { name: 'super video' }) + const resVideo = await uploadVideo(servers[0].url, userToken, { name: 'super video' }) const uuid = resVideo.body.video.uuid - const resComment = await addVideoCommentThread(servers[0].url, servers[0].accessToken, uuid, '@user_1 hello') - const commentId = resComment.body.comment.id + const { id: commentId } = await servers[0].commentsCommand.createThread({ videoId: uuid, text: '@user_1 hello' }) await waitJobs(servers) await checkCommentMention(baseParams, uuid, commentId, commentId, 'super root name', 'absence') @@ -232,8 +224,7 @@ describe('Test comments notifications', function () { const resVideo = await uploadVideo(servers[0].url, servers[0].accessToken, { name: 'super video' }) const uuid = resVideo.body.video.uuid - const resComment = await addVideoCommentThread(servers[0].url, userAccessToken, uuid, '@user_1 hello') - const commentId = resComment.body.comment.id + const { id: commentId } = await servers[0].commentsCommand.createThread({ token: userToken, videoId: uuid, text: '@user_1 hello' }) await waitJobs(servers) await checkCommentMention(baseParams, uuid, commentId, commentId, 'super root name', 'absence') @@ -242,18 +233,17 @@ describe('Test comments notifications', function () { it('Should not send a new mention notification if the account is muted', async function () { this.timeout(10000) - await servers[0].blocklistCommand.addToMyBlocklist({ token: userAccessToken, account: 'root' }) + await servers[0].blocklistCommand.addToMyBlocklist({ token: userToken, account: 'root' }) const resVideo = await uploadVideo(servers[0].url, servers[0].accessToken, { name: 'super video' }) const uuid = resVideo.body.video.uuid - const resComment = await addVideoCommentThread(servers[0].url, servers[0].accessToken, uuid, '@user_1 hello') - const commentId = resComment.body.comment.id + const { id: commentId } = await servers[0].commentsCommand.createThread({ videoId: uuid, text: '@user_1 hello' }) await waitJobs(servers) await checkCommentMention(baseParams, uuid, commentId, commentId, 'super root name', 'absence') - await servers[0].blocklistCommand.removeFromMyBlocklist({ token: userAccessToken, account: 'root' }) + await servers[0].blocklistCommand.removeFromMyBlocklist({ token: userToken, account: 'root' }) }) it('Should not send a new mention notification if the remote account mention a local account', async function () { @@ -263,8 +253,7 @@ describe('Test comments notifications', function () { const uuid = resVideo.body.video.uuid await waitJobs(servers) - const resThread = await addVideoCommentThread(servers[1].url, servers[1].accessToken, uuid, '@user_1 hello') - const threadId = resThread.body.comment.id + const { id: threadId } = await servers[1].commentsCommand.createThread({ videoId: uuid, text: '@user_1 hello' }) await waitJobs(servers) await checkCommentMention(baseParams, uuid, threadId, threadId, 'super root 2 name', 'absence') @@ -276,14 +265,12 @@ describe('Test comments notifications', function () { const resVideo = await uploadVideo(servers[0].url, servers[0].accessToken, { name: 'super video' }) const uuid = resVideo.body.video.uuid - const resThread = await addVideoCommentThread(servers[0].url, servers[0].accessToken, uuid, '@user_1 hello 1') - const threadId = resThread.body.comment.id + const { id: threadId } = await servers[0].commentsCommand.createThread({ videoId: uuid, text: '@user_1 hellotext: 1' }) await waitJobs(servers) await checkCommentMention(baseParams, uuid, threadId, threadId, 'super root name', 'presence') - const resComment = await addVideoCommentReply(servers[0].url, servers[0].accessToken, uuid, threadId, 'hello 2 @user_1') - const commentId = resComment.body.comment.id + const { id: commentId } = await servers[0].commentsCommand.addReply({ videoId: uuid, toCommentId: threadId, text: 'hello 2 @user_1' }) await waitJobs(servers) await checkCommentMention(baseParams, uuid, commentId, threadId, 'super root name', 'presence') @@ -298,23 +285,22 @@ describe('Test comments notifications', function () { await waitJobs(servers) const text1 = `hello @user_1@localhost:${servers[0].port} 1` - const resThread = await addVideoCommentThread(servers[1].url, servers[1].accessToken, uuid, text1) - const server2ThreadId = resThread.body.comment.id + const { id: server2ThreadId } = await servers[1].commentsCommand.createThread({ videoId: uuid, text: text1 }) await waitJobs(servers) - const resThread2 = await getVideoCommentThreads(servers[0].url, uuid, 0, 5) - expect(resThread2.body.data).to.have.lengthOf(1) - const server1ThreadId = resThread2.body.data[0].id + const { data } = await servers[0].commentsCommand.listThreads({ videoId: uuid }) + expect(data).to.have.lengthOf(1) + + const server1ThreadId = data[0].id await checkCommentMention(baseParams, uuid, server1ThreadId, server1ThreadId, 'super root 2 name', 'presence') const text2 = `@user_1@localhost:${servers[0].port} hello 2 @root@localhost:${servers[0].port}` - await addVideoCommentReply(servers[1].url, servers[1].accessToken, uuid, server2ThreadId, text2) + await servers[1].commentsCommand.addReply({ videoId: uuid, toCommentId: server2ThreadId, text: text2 }) await waitJobs(servers) - const resComments = await getVideoThreadComments(servers[0].url, uuid, server1ThreadId) - const tree = resComments.body as VideoCommentThreadTree + const tree = await servers[0].commentsCommand.getThread({ videoId: uuid, threadId: server1ThreadId }) expect(tree.children).to.have.lengthOf(1) const commentId = tree.children[0].comment.id @@ -328,10 +314,9 @@ describe('Test comments notifications', function () { const resVideo = await uploadVideo(servers[0].url, servers[0].accessToken, { name: 'super video' }) const uuid = resVideo.body.video.uuid - const resThread = await addVideoCommentThread(servers[0].url, servers[0].accessToken, uuid, '@user_1 hello 1') - const threadId = resThread.body.comment.id + const { id: threadId } = await servers[0].commentsCommand.createThread({ videoId: uuid, text: '@user_1 hello 1' }) - await addVideoCommentReply(servers[0].url, servers[0].accessToken, uuid, threadId, '@user_1 ' + commentText) + await servers[0].commentsCommand.addReply({ videoId: uuid, toCommentId: threadId, text: '@user_1 ' + commentText }) await waitJobs(servers) diff --git a/server/tests/api/notifications/moderation-notifications.ts b/server/tests/api/notifications/moderation-notifications.ts index 52ade0548..229f78811 100644 --- a/server/tests/api/notifications/moderation-notifications.ts +++ b/server/tests/api/notifications/moderation-notifications.ts @@ -3,7 +3,6 @@ import 'mocha' import { buildUUID } from '@server/helpers/uuid' import { - addVideoCommentThread, checkAbuseStateChange, checkAutoInstanceFollowing, CheckerBaseParams, @@ -20,7 +19,6 @@ import { cleanupTests, createUser, generateUserAccessToken, - getVideoCommentThreads, getVideoIdFromUUID, immutableAssign, MockInstancesIndex, @@ -101,8 +99,11 @@ describe('Test moderation notifications', function () { const name = 'video for abuse ' + buildUUID() const resVideo = await uploadVideo(servers[0].url, userAccessToken, { name }) const video = resVideo.body.video - const resComment = await addVideoCommentThread(servers[0].url, userAccessToken, video.id, 'comment abuse ' + buildUUID()) - const comment = resComment.body.comment + const comment = await servers[0].commentsCommand.createThread({ + token: userAccessToken, + videoId: video.id, + text: 'comment abuse ' + buildUUID() + }) await waitJobs(servers) @@ -118,12 +119,17 @@ describe('Test moderation notifications', function () { const name = 'video for abuse ' + buildUUID() const resVideo = await uploadVideo(servers[0].url, userAccessToken, { name }) const video = resVideo.body.video - await addVideoCommentThread(servers[0].url, userAccessToken, video.id, 'comment abuse ' + buildUUID()) + + await servers[0].commentsCommand.createThread({ + token: userAccessToken, + videoId: video.id, + text: 'comment abuse ' + buildUUID() + }) await waitJobs(servers) - const resComments = await getVideoCommentThreads(servers[1].url, video.uuid, 0, 5) - const commentId = resComments.body.data[0].id + const { data } = await servers[1].commentsCommand.listThreads({ videoId: video.uuid }) + const commentId = data[0].id await servers[1].abusesCommand.report({ commentId, reason: 'super reason' }) await waitJobs(servers) diff --git a/server/tests/api/server/bulk.ts b/server/tests/api/server/bulk.ts index ca98a2eb2..5c8673e00 100644 --- a/server/tests/api/server/bulk.ts +++ b/server/tests/api/server/bulk.ts @@ -2,16 +2,13 @@ import 'mocha' import * as chai from 'chai' -import { Video, VideoComment } from '@shared/models' +import { Video } from '@shared/models' import { - addVideoCommentReply, - addVideoCommentThread, BulkCommand, cleanupTests, createUser, doubleFollow, flushAndRunMultipleServers, - getVideoCommentThreads, getVideosList, ServerInfo, setAccessTokensToServers, @@ -26,9 +23,9 @@ describe('Test bulk actions', function () { const commentsUser3: { videoId: number, commentId: number }[] = [] let servers: ServerInfo[] = [] - let user1AccessToken: string - let user2AccessToken: string - let user3AccessToken: string + let user1Token: string + let user2Token: string + let user3Token: string let bulkCommand: BulkCommand @@ -44,21 +41,21 @@ describe('Test bulk actions', function () { const user = { username: 'user1', password: 'password' } await createUser({ url: servers[0].url, accessToken: servers[0].accessToken, username: user.username, password: user.password }) - user1AccessToken = await userLogin(servers[0], user) + user1Token = await userLogin(servers[0], user) } { const user = { username: 'user2', password: 'password' } await createUser({ url: servers[0].url, accessToken: servers[0].accessToken, username: user.username, password: user.password }) - user2AccessToken = await userLogin(servers[0], user) + user2Token = await userLogin(servers[0], user) } { const user = { username: 'user3', password: 'password' } await createUser({ url: servers[1].url, accessToken: servers[1].accessToken, username: user.username, password: user.password }) - user3AccessToken = await userLogin(servers[1], user) + user3Token = await userLogin(servers[1], user) } await doubleFollow(servers[0], servers[1]) @@ -74,9 +71,8 @@ describe('Test bulk actions', function () { // Server 1 should not have these comments anymore for (const video of videos) { - const resThreads = await getVideoCommentThreads(servers[0].url, video.id, 0, 10) - const comments = resThreads.body.data as VideoComment[] - const comment = comments.find(c => c.text === 'comment by user 3') + const { data } = await servers[0].commentsCommand.listThreads({ videoId: video.id }) + const comment = data.find(c => c.text === 'comment by user 3') expect(comment).to.not.exist } @@ -88,9 +84,8 @@ describe('Test bulk actions', function () { // Server 1 should not have these comments on videos of server 1 for (const video of videos) { - const resThreads = await getVideoCommentThreads(servers[1].url, video.id, 0, 10) - const comments = resThreads.body.data as VideoComment[] - const comment = comments.find(c => c.text === 'comment by user 3') + const { data } = await servers[1].commentsCommand.listThreads({ videoId: video.id }) + const comment = data.find(c => c.text === 'comment by user 3') if (video.account.host === 'localhost:' + servers[0].port) { expect(comment).to.not.exist @@ -106,7 +101,7 @@ describe('Test bulk actions', function () { await uploadVideo(servers[0].url, servers[0].accessToken, { name: 'video 1 server 1' }) await uploadVideo(servers[0].url, servers[0].accessToken, { name: 'video 2 server 1' }) - await uploadVideo(servers[0].url, user1AccessToken, { name: 'video 3 server 1' }) + await uploadVideo(servers[0].url, user1Token, { name: 'video 3 server 1' }) await uploadVideo(servers[1].url, servers[1].accessToken, { name: 'video 1 server 2' }) @@ -115,19 +110,20 @@ describe('Test bulk actions', function () { { const res = await getVideosList(servers[0].url) for (const video of res.body.data) { - await addVideoCommentThread(servers[0].url, servers[0].accessToken, video.id, 'comment by root server 1') - await addVideoCommentThread(servers[0].url, user1AccessToken, video.id, 'comment by user 1') - await addVideoCommentThread(servers[0].url, user2AccessToken, video.id, 'comment by user 2') + await servers[0].commentsCommand.createThread({ videoId: video.id, text: 'comment by root server 1' }) + await servers[0].commentsCommand.createThread({ token: user1Token, videoId: video.id, text: 'comment by user 1' }) + await servers[0].commentsCommand.createThread({ token: user2Token, videoId: video.id, text: 'comment by user 2' }) } } { const res = await getVideosList(servers[1].url) + for (const video of res.body.data) { - await addVideoCommentThread(servers[1].url, servers[1].accessToken, video.id, 'comment by root server 2') + await servers[1].commentsCommand.createThread({ videoId: video.id, text: 'comment by root server 2' }) - const res = await addVideoCommentThread(servers[1].url, user3AccessToken, video.id, 'comment by user 3') - commentsUser3.push({ videoId: video.id, commentId: res.body.comment.id }) + const comment = await servers[1].commentsCommand.createThread({ token: user3Token, videoId: video.id, text: 'comment by user 3' }) + commentsUser3.push({ videoId: video.id, commentId: comment.id }) } } @@ -138,7 +134,7 @@ describe('Test bulk actions', function () { this.timeout(60000) await bulkCommand.removeCommentsOf({ - token: user1AccessToken, + token: user1Token, attributes: { accountName: 'user2', scope: 'my-videos' @@ -151,15 +147,11 @@ describe('Test bulk actions', function () { const res = await getVideosList(server.url) for (const video of res.body.data) { - const resThreads = await getVideoCommentThreads(server.url, video.id, 0, 10) - const comments = resThreads.body.data as VideoComment[] - const comment = comments.find(c => c.text === 'comment by user 2') + const { data } = await server.commentsCommand.listThreads({ videoId: video.id }) + const comment = data.find(c => c.text === 'comment by user 2') - if (video.name === 'video 3 server 1') { - expect(comment).to.not.exist - } else { - expect(comment).to.exist - } + if (video.name === 'video 3 server 1') expect(comment).to.not.exist + else expect(comment).to.exist } } }) @@ -183,7 +175,12 @@ describe('Test bulk actions', function () { this.timeout(60000) for (const obj of commentsUser3) { - await addVideoCommentReply(servers[1].url, user3AccessToken, obj.videoId, obj.commentId, 'comment by user 3 bis') + await servers[1].commentsCommand.addReply({ + token: user3Token, + videoId: obj.videoId, + toCommentId: obj.commentId, + text: 'comment by user 3 bis' + }) } await waitJobs(servers) diff --git a/server/tests/api/server/follows.ts b/server/tests/api/server/follows.ts index 520442c6e..4a9ed2d05 100644 --- a/server/tests/api/server/follows.ts +++ b/server/tests/api/server/follows.ts @@ -3,19 +3,14 @@ import 'mocha' import * as chai from 'chai' import { - addVideoCommentReply, - addVideoCommentThread, cleanupTests, completeVideoCheck, createUser, dateIsValid, - deleteVideoComment, expectAccountFollows, flushAndRunMultipleServers, FollowsCommand, - getVideoCommentThreads, getVideosList, - getVideoThreadComments, rateVideo, ServerInfo, setAccessTokensToServers, @@ -24,7 +19,7 @@ import { userLogin, waitJobs } from '@shared/extra-utils' -import { Video, VideoComment, VideoCommentThreadTree, VideoPrivacy } from '@shared/models' +import { Video, VideoPrivacy } from '@shared/models' const expect = chai.expect @@ -348,37 +343,35 @@ describe('Test follows', function () { { { const text = 'my super first comment' - const res = await addVideoCommentThread(servers[2].url, servers[2].accessToken, video4.id, text) - const threadId = res.body.comment.id + const created = await servers[2].commentsCommand.createThread({ videoId: video4.id, text }) + const threadId = created.id const text1 = 'my super answer to thread 1' - const childCommentRes = await addVideoCommentReply(servers[2].url, servers[2].accessToken, video4.id, threadId, text1) - const childCommentId = childCommentRes.body.comment.id + const childComment = await servers[2].commentsCommand.addReply({ videoId: video4.id, toCommentId: threadId, text: text1 }) const text2 = 'my super answer to answer of thread 1' - await addVideoCommentReply(servers[2].url, servers[2].accessToken, video4.id, childCommentId, text2) + await servers[2].commentsCommand.addReply({ videoId: video4.id, toCommentId: childComment.id, text: text2 }) const text3 = 'my second answer to thread 1' - await addVideoCommentReply(servers[2].url, servers[2].accessToken, video4.id, threadId, text3) + await servers[2].commentsCommand.addReply({ videoId: video4.id, toCommentId: threadId, text: text3 }) } { const text = 'will be deleted' - const res = await addVideoCommentThread(servers[2].url, servers[2].accessToken, video4.id, text) - const threadId = res.body.comment.id + const created = await servers[2].commentsCommand.createThread({ videoId: video4.id, text }) + const threadId = created.id const text1 = 'answer to deleted' - await addVideoCommentReply(servers[2].url, servers[2].accessToken, video4.id, threadId, text1) + await servers[2].commentsCommand.addReply({ videoId: video4.id, toCommentId: threadId, text: text1 }) const text2 = 'will also be deleted' - const childCommentRes = await addVideoCommentReply(servers[2].url, servers[2].accessToken, video4.id, threadId, text2) - const childCommentId = childCommentRes.body.comment.id + const childComment = await servers[2].commentsCommand.addReply({ videoId: video4.id, toCommentId: threadId, text: text2 }) const text3 = 'my second answer to deleted' - await addVideoCommentReply(servers[2].url, servers[2].accessToken, video4.id, childCommentId, text3) + await servers[2].commentsCommand.addReply({ videoId: video4.id, toCommentId: childComment.id, text: text3 }) - await deleteVideoComment(servers[2].url, servers[2].accessToken, video4.id, threadId) - await deleteVideoComment(servers[2].url, servers[2].accessToken, video4.id, childCommentId) + await servers[2].commentsCommand.delete({ videoId: video4.id, commentId: threadId }) + await servers[2].commentsCommand.delete({ videoId: video4.id, commentId: childComment.id }) } } @@ -462,14 +455,14 @@ describe('Test follows', function () { }) it('Should have propagated comments', async function () { - const res1 = await getVideoCommentThreads(servers[0].url, video4.id, 0, 5, 'createdAt') + const { total, data } = await servers[0].commentsCommand.listThreads({ videoId: video4.id, sort: 'createdAt' }) - expect(res1.body.total).to.equal(2) - expect(res1.body.data).to.be.an('array') - expect(res1.body.data).to.have.lengthOf(2) + expect(total).to.equal(2) + expect(data).to.be.an('array') + expect(data).to.have.lengthOf(2) { - const comment: VideoComment = res1.body.data[0] + const comment = data[0] expect(comment.inReplyToCommentId).to.be.null expect(comment.text).equal('my super first comment') expect(comment.videoId).to.equal(video4.id) @@ -482,9 +475,7 @@ describe('Test follows', function () { const threadId = comment.threadId - const res2 = await getVideoThreadComments(servers[0].url, video4.id, threadId) - - const tree: VideoCommentThreadTree = res2.body + const tree = await servers[0].commentsCommand.getThread({ videoId: video4.id, threadId }) expect(tree.comment.text).equal('my super first comment') expect(tree.children).to.have.lengthOf(2) @@ -502,7 +493,7 @@ describe('Test follows', function () { } { - const deletedComment: VideoComment = res1.body.data[1] + const deletedComment = data[1] expect(deletedComment).to.not.be.undefined expect(deletedComment.isDeleted).to.be.true expect(deletedComment.deletedAt).to.not.be.null @@ -512,9 +503,7 @@ describe('Test follows', function () { expect(deletedComment.totalReplies).to.equal(2) expect(dateIsValid(deletedComment.deletedAt as string)).to.be.true - const res2 = await getVideoThreadComments(servers[0].url, video4.id, deletedComment.threadId) - - const tree: VideoCommentThreadTree = res2.body + const tree = await servers[0].commentsCommand.getThread({ videoId: video4.id, threadId: deletedComment.threadId }) const [ commentRoot, deletedChildRoot ] = tree.children expect(deletedChildRoot).to.not.be.undefined diff --git a/server/tests/api/server/handle-down.ts b/server/tests/api/server/handle-down.ts index c6202fdaa..94496a159 100644 --- a/server/tests/api/server/handle-down.ts +++ b/server/tests/api/server/handle-down.ts @@ -4,16 +4,13 @@ import 'mocha' import * as chai from 'chai' import { HttpStatusCode } from '@shared/core-utils' import { - addVideoCommentReply, - addVideoCommentThread, cleanupTests, closeAllSequelize, + CommentsCommand, completeVideoCheck, flushAndRunMultipleServers, getVideo, - getVideoCommentThreads, getVideosList, - getVideoThreadComments, immutableAssign, killallServers, reRunServer, @@ -26,7 +23,7 @@ import { wait, waitJobs } from '@shared/extra-utils' -import { JobState, Video, VideoCommentThreadTree, VideoPrivacy } from '@shared/models' +import { JobState, Video, VideoPrivacy } from '@shared/models' const expect = chai.expect @@ -62,10 +59,13 @@ describe('Test handle downs', function () { let checkAttributes: any let unlistedCheckAttributes: any + let commentCommands: CommentsCommand[] + before(async function () { this.timeout(30000) servers = await flushAndRunMultipleServers(3) + commentCommands = servers.map(s => s.commentsCommand) checkAttributes = { name: 'my super name for server 1', @@ -154,15 +154,13 @@ describe('Test handle downs', function () { // Add comments to video 2 { const text = 'thread 1' - let resComment = await addVideoCommentThread(servers[0].url, servers[0].accessToken, missedVideo2.uuid, text) - let comment = resComment.body.comment + let comment = await commentCommands[0].createThread({ videoId: missedVideo2.uuid, text }) threadIdServer1 = comment.id - resComment = await addVideoCommentReply(servers[0].url, servers[0].accessToken, missedVideo2.uuid, comment.id, 'comment 1-1') - comment = resComment.body.comment + comment = await commentCommands[0].addReply({ videoId: missedVideo2.uuid, toCommentId: comment.id, text: 'comment 1-1' }) - resComment = await addVideoCommentReply(servers[0].url, servers[0].accessToken, missedVideo2.uuid, comment.id, 'comment 1-2') - commentIdServer1 = resComment.body.comment.id + const created = await commentCommands[0].addReply({ videoId: missedVideo2.uuid, toCommentId: comment.id, text: 'comment 1-2' }) + commentIdServer1 = created.id } await waitJobs(servers[0]) @@ -235,7 +233,7 @@ describe('Test handle downs', function () { it('Should send comments on a video to server 3, and automatically fetch the video', async function () { this.timeout(25000) - await addVideoCommentReply(servers[0].url, servers[0].accessToken, missedVideo2.uuid, commentIdServer1, 'comment 1-3') + await commentCommands[0].addReply({ videoId: missedVideo2.uuid, toCommentId: commentIdServer1, text: 'comment 1-3' }) await waitJobs(servers) @@ -243,15 +241,13 @@ describe('Test handle downs', function () { expect(resVideo.body).not.to.be.undefined { - let resComment = await getVideoCommentThreads(servers[2].url, missedVideo2.uuid, 0, 5) - expect(resComment.body.data).to.be.an('array') - expect(resComment.body.data).to.have.lengthOf(1) - - threadIdServer2 = resComment.body.data[0].id + const { data } = await servers[2].commentsCommand.listThreads({ videoId: missedVideo2.uuid }) + expect(data).to.be.an('array') + expect(data).to.have.lengthOf(1) - resComment = await getVideoThreadComments(servers[2].url, missedVideo2.uuid, threadIdServer2) + threadIdServer2 = data[0].id - const tree: VideoCommentThreadTree = resComment.body + const tree = await servers[2].commentsCommand.getThread({ videoId: missedVideo2.uuid, threadId: threadIdServer2 }) expect(tree.comment.text).equal('thread 1') expect(tree.children).to.have.lengthOf(1) @@ -274,33 +270,30 @@ describe('Test handle downs', function () { it('Should correctly reply to the comment', async function () { this.timeout(15000) - await addVideoCommentReply(servers[2].url, servers[2].accessToken, missedVideo2.uuid, commentIdServer2, 'comment 1-4') + await servers[2].commentsCommand.addReply({ videoId: missedVideo2.uuid, toCommentId: commentIdServer2, text: 'comment 1-4' }) await waitJobs(servers) - { - const resComment = await getVideoThreadComments(servers[0].url, missedVideo2.uuid, threadIdServer1) + const tree = await commentCommands[0].getThread({ videoId: missedVideo2.uuid, threadId: threadIdServer1 }) - const tree: VideoCommentThreadTree = resComment.body - expect(tree.comment.text).equal('thread 1') - expect(tree.children).to.have.lengthOf(1) + expect(tree.comment.text).equal('thread 1') + expect(tree.children).to.have.lengthOf(1) - const firstChild = tree.children[0] - expect(firstChild.comment.text).to.equal('comment 1-1') - expect(firstChild.children).to.have.lengthOf(1) + const firstChild = tree.children[0] + expect(firstChild.comment.text).to.equal('comment 1-1') + expect(firstChild.children).to.have.lengthOf(1) - const childOfFirstChild = firstChild.children[0] - expect(childOfFirstChild.comment.text).to.equal('comment 1-2') - expect(childOfFirstChild.children).to.have.lengthOf(1) + const childOfFirstChild = firstChild.children[0] + expect(childOfFirstChild.comment.text).to.equal('comment 1-2') + expect(childOfFirstChild.children).to.have.lengthOf(1) - const childOfChildFirstChild = childOfFirstChild.children[0] - expect(childOfChildFirstChild.comment.text).to.equal('comment 1-3') - expect(childOfChildFirstChild.children).to.have.lengthOf(1) + const childOfChildFirstChild = childOfFirstChild.children[0] + expect(childOfChildFirstChild.comment.text).to.equal('comment 1-3') + expect(childOfChildFirstChild.children).to.have.lengthOf(1) - const childOfChildOfChildOfFirstChild = childOfChildFirstChild.children[0] - expect(childOfChildOfChildOfFirstChild.comment.text).to.equal('comment 1-4') - expect(childOfChildOfChildOfFirstChild.children).to.have.lengthOf(0) - } + const childOfChildOfChildOfFirstChild = childOfChildFirstChild.children[0] + expect(childOfChildOfChildOfFirstChild.comment.text).to.equal('comment 1-4') + expect(childOfChildOfChildOfFirstChild.children).to.have.lengthOf(0) }) it('Should upload many videos on server 1', async function () { diff --git a/server/tests/api/server/stats.ts b/server/tests/api/server/stats.ts index 9c954c347..ded305899 100644 --- a/server/tests/api/server/stats.ts +++ b/server/tests/api/server/stats.ts @@ -3,7 +3,6 @@ import 'mocha' import * as chai from 'chai' import { - addVideoCommentThread, cleanupTests, createUser, doubleFollow, @@ -42,7 +41,7 @@ describe('Test stats (excluding redundancy)', function () { const resVideo = await uploadVideo(servers[0].url, servers[0].accessToken, { fixture: 'video_short.webm' }) const videoUUID = resVideo.body.video.uuid - await addVideoCommentThread(servers[0].url, servers[0].accessToken, videoUUID, 'comment') + await servers[0].commentsCommand.createThread({ videoId: videoUUID, text: 'comment' }) await viewVideo(servers[0].url, videoUUID) diff --git a/server/tests/api/users/users.ts b/server/tests/api/users/users.ts index ed670b3c9..4d255f340 100644 --- a/server/tests/api/users/users.ts +++ b/server/tests/api/users/users.ts @@ -4,7 +4,6 @@ import 'mocha' import * as chai from 'chai' import { HttpStatusCode } from '@shared/core-utils' import { - addVideoCommentThread, blockUser, cleanupTests, closeAllSequelize, @@ -983,7 +982,7 @@ describe('Test users', function () { it('Should report correct video comments for user', async function () { const text = 'super comment' - await addVideoCommentThread(server.url, user17AccessToken, videoId, text) + await server.commentsCommand.createThread({ token: user17AccessToken, videoId, text }) const res = await getUserInformation(server.url, server.accessToken, user17Id, true) const user: User = res.body diff --git a/server/tests/api/videos/multiple-servers.ts b/server/tests/api/videos/multiple-servers.ts index a59d5a858..2148d8e1c 100644 --- a/server/tests/api/videos/multiple-servers.ts +++ b/server/tests/api/videos/multiple-servers.ts @@ -3,7 +3,7 @@ import 'mocha' import * as chai from 'chai' import * as request from 'supertest' -import { HttpStatusCode } from '../../../../shared/core-utils/miscs/http-error-codes' +import { HttpStatusCode } from '@shared/core-utils' import { buildAbsoluteFixturePath, checkTmpIsEmpty, @@ -27,18 +27,10 @@ import { userLogin, viewVideo, wait, + waitJobs, webtorrentAdd -} from '../../../../shared/extra-utils' -import { waitJobs } from '../../../../shared/extra-utils/server/jobs' -import { - addVideoCommentReply, - addVideoCommentThread, - deleteVideoComment, - findCommentId, - getVideoCommentThreads, - getVideoThreadComments -} from '../../../../shared/extra-utils/videos/video-comments' -import { VideoComment, VideoCommentThreadTree, VideoPrivacy } from '../../../../shared/models/videos' +} from '@shared/extra-utils' +import { VideoCommentThreadTree, VideoPrivacy } from '@shared/models' const expect = chai.expect @@ -762,36 +754,36 @@ describe('Test multiple servers', function () { { const text = 'my super first comment' - await addVideoCommentThread(servers[0].url, servers[0].accessToken, videoUUID, text) + await servers[0].commentsCommand.createThread({ videoId: videoUUID, text }) } { const text = 'my super second comment' - await addVideoCommentThread(servers[2].url, servers[2].accessToken, videoUUID, text) + await servers[2].commentsCommand.createThread({ videoId: videoUUID, text }) } await waitJobs(servers) { - const threadId = await findCommentId(servers[1].url, videoUUID, 'my super first comment') + const threadId = await servers[1].commentsCommand.findCommentId({ videoId: videoUUID, text: 'my super first comment' }) const text = 'my super answer to thread 1' - await addVideoCommentReply(servers[1].url, servers[1].accessToken, videoUUID, threadId, text) + await servers[1].commentsCommand.addReply({ videoId: videoUUID, toCommentId: threadId, text }) } await waitJobs(servers) { - const threadId = await findCommentId(servers[2].url, videoUUID, 'my super first comment') + const threadId = await servers[2].commentsCommand.findCommentId({ videoId: videoUUID, text: 'my super first comment' }) - const res2 = await getVideoThreadComments(servers[2].url, videoUUID, threadId) - const childCommentId = res2.body.children[0].comment.id + const body = await servers[2].commentsCommand.getThread({ videoId: videoUUID, threadId }) + const childCommentId = body.children[0].comment.id const text3 = 'my second answer to thread 1' - await addVideoCommentReply(servers[2].url, servers[2].accessToken, videoUUID, threadId, text3) + await servers[2].commentsCommand.addReply({ videoId: videoUUID, toCommentId: threadId, text: text3 }) const text2 = 'my super answer to answer of thread 1' - await addVideoCommentReply(servers[2].url, servers[2].accessToken, videoUUID, childCommentId, text2) + await servers[2].commentsCommand.addReply({ videoId: videoUUID, toCommentId: childCommentId, text: text2 }) } await waitJobs(servers) @@ -799,14 +791,14 @@ describe('Test multiple servers', function () { it('Should have these threads', async function () { for (const server of servers) { - const res = await getVideoCommentThreads(server.url, videoUUID, 0, 5) + const body = await server.commentsCommand.listThreads({ videoId: videoUUID }) - expect(res.body.total).to.equal(2) - expect(res.body.data).to.be.an('array') - expect(res.body.data).to.have.lengthOf(2) + expect(body.total).to.equal(2) + expect(body.data).to.be.an('array') + expect(body.data).to.have.lengthOf(2) { - const comment: VideoComment = res.body.data.find(c => c.text === 'my super first comment') + const comment = body.data.find(c => c.text === 'my super first comment') expect(comment).to.not.be.undefined expect(comment.inReplyToCommentId).to.be.null expect(comment.account.name).to.equal('root') @@ -817,7 +809,7 @@ describe('Test multiple servers', function () { } { - const comment: VideoComment = res.body.data.find(c => c.text === 'my super second comment') + const comment = body.data.find(c => c.text === 'my super second comment') expect(comment).to.not.be.undefined expect(comment.inReplyToCommentId).to.be.null expect(comment.account.name).to.equal('root') @@ -831,12 +823,11 @@ describe('Test multiple servers', function () { it('Should have these comments', async function () { for (const server of servers) { - const res1 = await getVideoCommentThreads(server.url, videoUUID, 0, 5) - const threadId = res1.body.data.find(c => c.text === 'my super first comment').id + const body = await server.commentsCommand.listThreads({ videoId: videoUUID }) + const threadId = body.data.find(c => c.text === 'my super first comment').id - const res2 = await getVideoThreadComments(server.url, videoUUID, threadId) + const tree = await server.commentsCommand.getThread({ videoId: videoUUID, threadId }) - const tree: VideoCommentThreadTree = res2.body expect(tree.comment.text).equal('my super first comment') expect(tree.comment.account.name).equal('root') expect(tree.comment.account.host).equal('localhost:' + servers[0].port) @@ -865,19 +856,17 @@ describe('Test multiple servers', function () { it('Should delete a reply', async function () { this.timeout(10000) - await deleteVideoComment(servers[2].url, servers[2].accessToken, videoUUID, childOfFirstChild.comment.id) + await servers[2].commentsCommand.delete({ videoId: videoUUID, commentId: childOfFirstChild.comment.id }) await waitJobs(servers) }) it('Should have this comment marked as deleted', async function () { for (const server of servers) { - const res1 = await getVideoCommentThreads(server.url, videoUUID, 0, 5) - const threadId = res1.body.data.find(c => c.text === 'my super first comment').id - - const res2 = await getVideoThreadComments(server.url, videoUUID, threadId) + const { data } = await server.commentsCommand.listThreads({ videoId: videoUUID }) + const threadId = data.find(c => c.text === 'my super first comment').id - const tree: VideoCommentThreadTree = res2.body + const tree = await server.commentsCommand.getThread({ videoId: videoUUID, threadId }) expect(tree.comment.text).equal('my super first comment') const firstChild = tree.children[0] @@ -898,23 +887,23 @@ describe('Test multiple servers', function () { it('Should delete the thread comments', async function () { this.timeout(10000) - const res = await getVideoCommentThreads(servers[0].url, videoUUID, 0, 5) - const threadId = res.body.data.find(c => c.text === 'my super first comment').id - await deleteVideoComment(servers[0].url, servers[0].accessToken, videoUUID, threadId) + const { data } = await servers[0].commentsCommand.listThreads({ videoId: videoUUID }) + const commentId = data.find(c => c.text === 'my super first comment').id + await servers[0].commentsCommand.delete({ videoId: videoUUID, commentId }) await waitJobs(servers) }) it('Should have the threads marked as deleted on other servers too', async function () { for (const server of servers) { - const res = await getVideoCommentThreads(server.url, videoUUID, 0, 5) + const body = await server.commentsCommand.listThreads({ videoId: videoUUID }) - expect(res.body.total).to.equal(2) - expect(res.body.data).to.be.an('array') - expect(res.body.data).to.have.lengthOf(2) + expect(body.total).to.equal(2) + expect(body.data).to.be.an('array') + expect(body.data).to.have.lengthOf(2) { - const comment: VideoComment = res.body.data[0] + const comment = body.data[0] expect(comment).to.not.be.undefined expect(comment.inReplyToCommentId).to.be.null expect(comment.account.name).to.equal('root') @@ -925,7 +914,7 @@ describe('Test multiple servers', function () { } { - const deletedComment: VideoComment = res.body.data[1] + const deletedComment = body.data[1] expect(deletedComment).to.not.be.undefined expect(deletedComment.isDeleted).to.be.true expect(deletedComment.deletedAt).to.not.be.null @@ -943,22 +932,22 @@ describe('Test multiple servers', function () { it('Should delete a remote thread by the origin server', async function () { this.timeout(5000) - const res = await getVideoCommentThreads(servers[0].url, videoUUID, 0, 5) - const threadId = res.body.data.find(c => c.text === 'my super second comment').id - await deleteVideoComment(servers[0].url, servers[0].accessToken, videoUUID, threadId) + const { data } = await servers[0].commentsCommand.listThreads({ videoId: videoUUID }) + const commentId = data.find(c => c.text === 'my super second comment').id + await servers[0].commentsCommand.delete({ videoId: videoUUID, commentId }) await waitJobs(servers) }) it('Should have the threads marked as deleted on other servers too', async function () { for (const server of servers) { - const res = await getVideoCommentThreads(server.url, videoUUID, 0, 5) + const body = await server.commentsCommand.listThreads({ videoId: videoUUID }) - expect(res.body.total).to.equal(2) - expect(res.body.data).to.have.lengthOf(2) + expect(body.total).to.equal(2) + expect(body.data).to.have.lengthOf(2) { - const comment: VideoComment = res.body.data[0] + const comment = body.data[0] expect(comment.text).to.equal('') expect(comment.isDeleted).to.be.true expect(comment.createdAt).to.not.be.null @@ -968,7 +957,7 @@ describe('Test multiple servers', function () { } { - const comment: VideoComment = res.body.data[1] + const comment = body.data[1] expect(comment.text).to.equal('') expect(comment.isDeleted).to.be.true expect(comment.createdAt).to.not.be.null @@ -997,7 +986,7 @@ describe('Test multiple servers', function () { expect(res.body.downloadEnabled).to.be.false const text = 'my super forbidden comment' - await addVideoCommentThread(server.url, server.accessToken, videoUUID, text, HttpStatusCode.CONFLICT_409) + await server.commentsCommand.createThread({ videoId: videoUUID, text, expectedStatus: HttpStatusCode.CONFLICT_409 }) } }) }) diff --git a/server/tests/api/videos/video-comments.ts b/server/tests/api/videos/video-comments.ts index b6b002307..548d9fbf5 100644 --- a/server/tests/api/videos/video-comments.ts +++ b/server/tests/api/videos/video-comments.ts @@ -2,38 +2,33 @@ import 'mocha' import * as chai from 'chai' -import { VideoComment, VideoCommentAdmin, VideoCommentThreadTree } from '@shared/models' -import { cleanupTests, testImage } from '../../../../shared/extra-utils' import { + cleanupTests, + CommentsCommand, createUser, dateIsValid, flushAndRunServer, getAccessToken, ServerInfo, setAccessTokensToServers, + testImage, updateMyAvatar, uploadVideo -} from '../../../../shared/extra-utils/index' -import { - addVideoCommentReply, - addVideoCommentThread, - deleteVideoComment, - getAdminVideoComments, - getVideoCommentThreads, - getVideoThreadComments -} from '../../../../shared/extra-utils/videos/video-comments' +} from '@shared/extra-utils' const expect = chai.expect describe('Test video comments', function () { let server: ServerInfo - let videoId - let videoUUID - let threadId + let videoId: number + let videoUUID: string + let threadId: number let replyToDeleteId: number let userAccessTokenServer1: string + let command: CommentsCommand + before(async function () { this.timeout(30000) @@ -58,24 +53,25 @@ describe('Test video comments', function () { password: 'password' }) userAccessTokenServer1 = await getAccessToken(server.url, 'user1', 'password') + + command = server.commentsCommand }) describe('User comments', function () { it('Should not have threads on this video', async function () { - const res = await getVideoCommentThreads(server.url, videoUUID, 0, 5) + const body = await command.listThreads({ videoId: videoUUID }) - expect(res.body.total).to.equal(0) - expect(res.body.totalNotDeletedComments).to.equal(0) - expect(res.body.data).to.be.an('array') - expect(res.body.data).to.have.lengthOf(0) + expect(body.total).to.equal(0) + expect(body.totalNotDeletedComments).to.equal(0) + expect(body.data).to.be.an('array') + expect(body.data).to.have.lengthOf(0) }) it('Should create a thread in this video', async function () { const text = 'my super first comment' - const res = await addVideoCommentThread(server.url, server.accessToken, videoUUID, text) - const comment = res.body.comment + const comment = await command.createThread({ videoId: videoUUID, text }) expect(comment.inReplyToCommentId).to.be.null expect(comment.text).equal('my super first comment') @@ -91,14 +87,14 @@ describe('Test video comments', function () { }) it('Should list threads of this video', async function () { - const res = await getVideoCommentThreads(server.url, videoUUID, 0, 5) + const body = await command.listThreads({ videoId: videoUUID }) - expect(res.body.total).to.equal(1) - expect(res.body.totalNotDeletedComments).to.equal(1) - expect(res.body.data).to.be.an('array') - expect(res.body.data).to.have.lengthOf(1) + expect(body.total).to.equal(1) + expect(body.totalNotDeletedComments).to.equal(1) + expect(body.data).to.be.an('array') + expect(body.data).to.have.lengthOf(1) - const comment: VideoComment = res.body.data[0] + const comment = body.data[0] expect(comment.inReplyToCommentId).to.be.null expect(comment.text).equal('my super first comment') expect(comment.videoId).to.equal(videoId) @@ -117,9 +113,9 @@ describe('Test video comments', function () { }) it('Should get all the thread created', async function () { - const res = await getVideoThreadComments(server.url, videoUUID, threadId) + const body = await command.getThread({ videoId: videoUUID, threadId }) - const rootComment = res.body.comment + const rootComment = body.comment expect(rootComment.inReplyToCommentId).to.be.null expect(rootComment.text).equal('my super first comment') expect(rootComment.videoId).to.equal(videoId) @@ -129,20 +125,19 @@ describe('Test video comments', function () { it('Should create multiple replies in this thread', async function () { const text1 = 'my super answer to thread 1' - const childCommentRes = await addVideoCommentReply(server.url, server.accessToken, videoId, threadId, text1) - const childCommentId = childCommentRes.body.comment.id + const created = await command.addReply({ videoId, toCommentId: threadId, text: text1 }) + const childCommentId = created.id const text2 = 'my super answer to answer of thread 1' - await addVideoCommentReply(server.url, server.accessToken, videoId, childCommentId, text2) + await command.addReply({ videoId, toCommentId: childCommentId, text: text2 }) const text3 = 'my second answer to thread 1' - await addVideoCommentReply(server.url, server.accessToken, videoId, threadId, text3) + await command.addReply({ videoId, toCommentId: threadId, text: text3 }) }) it('Should get correctly the replies', async function () { - const res = await getVideoThreadComments(server.url, videoUUID, threadId) + const tree = await command.getThread({ videoId: videoUUID, threadId }) - const tree: VideoCommentThreadTree = res.body expect(tree.comment.text).equal('my super first comment') expect(tree.children).to.have.lengthOf(2) @@ -163,42 +158,41 @@ describe('Test video comments', function () { it('Should create other threads', async function () { const text1 = 'super thread 2' - await addVideoCommentThread(server.url, server.accessToken, videoUUID, text1) + await command.createThread({ videoId: videoUUID, text: text1 }) const text2 = 'super thread 3' - await addVideoCommentThread(server.url, server.accessToken, videoUUID, text2) + await command.createThread({ videoId: videoUUID, text: text2 }) }) it('Should list the threads', async function () { - const res = await getVideoCommentThreads(server.url, videoUUID, 0, 5, 'createdAt') - - expect(res.body.total).to.equal(3) - expect(res.body.totalNotDeletedComments).to.equal(6) - expect(res.body.data).to.be.an('array') - expect(res.body.data).to.have.lengthOf(3) - - expect(res.body.data[0].text).to.equal('my super first comment') - expect(res.body.data[0].totalReplies).to.equal(3) - expect(res.body.data[1].text).to.equal('super thread 2') - expect(res.body.data[1].totalReplies).to.equal(0) - expect(res.body.data[2].text).to.equal('super thread 3') - expect(res.body.data[2].totalReplies).to.equal(0) + const body = await command.listThreads({ videoId: videoUUID, sort: 'createdAt' }) + + expect(body.total).to.equal(3) + expect(body.totalNotDeletedComments).to.equal(6) + expect(body.data).to.be.an('array') + expect(body.data).to.have.lengthOf(3) + + expect(body.data[0].text).to.equal('my super first comment') + expect(body.data[0].totalReplies).to.equal(3) + expect(body.data[1].text).to.equal('super thread 2') + expect(body.data[1].totalReplies).to.equal(0) + expect(body.data[2].text).to.equal('super thread 3') + expect(body.data[2].totalReplies).to.equal(0) }) it('Should delete a reply', async function () { - await deleteVideoComment(server.url, server.accessToken, videoId, replyToDeleteId) + await command.delete({ videoId, commentId: replyToDeleteId }) { - const res = await getVideoCommentThreads(server.url, videoUUID, 0, 5, 'createdAt') + const body = await command.listThreads({ videoId: videoUUID, sort: 'createdAt' }) - expect(res.body.total).to.equal(3) - expect(res.body.totalNotDeletedComments).to.equal(5) + expect(body.total).to.equal(3) + expect(body.totalNotDeletedComments).to.equal(5) } { - const res = await getVideoThreadComments(server.url, videoUUID, threadId) + const tree = await command.getThread({ videoId: videoUUID, threadId }) - const tree: VideoCommentThreadTree = res.body expect(tree.comment.text).equal('my super first comment') expect(tree.children).to.have.lengthOf(2) @@ -220,99 +214,88 @@ describe('Test video comments', function () { }) it('Should delete a complete thread', async function () { - await deleteVideoComment(server.url, server.accessToken, videoId, threadId) - - const res = await getVideoCommentThreads(server.url, videoUUID, 0, 5, 'createdAt') - expect(res.body.total).to.equal(3) - expect(res.body.data).to.be.an('array') - expect(res.body.data).to.have.lengthOf(3) - - expect(res.body.data[0].text).to.equal('') - expect(res.body.data[0].isDeleted).to.be.true - expect(res.body.data[0].deletedAt).to.not.be.null - expect(res.body.data[0].account).to.be.null - expect(res.body.data[0].totalReplies).to.equal(2) - expect(res.body.data[1].text).to.equal('super thread 2') - expect(res.body.data[1].totalReplies).to.equal(0) - expect(res.body.data[2].text).to.equal('super thread 3') - expect(res.body.data[2].totalReplies).to.equal(0) + await command.delete({ videoId, commentId: threadId }) + + const body = await command.listThreads({ videoId: videoUUID, sort: 'createdAt' }) + expect(body.total).to.equal(3) + expect(body.data).to.be.an('array') + expect(body.data).to.have.lengthOf(3) + + expect(body.data[0].text).to.equal('') + expect(body.data[0].isDeleted).to.be.true + expect(body.data[0].deletedAt).to.not.be.null + expect(body.data[0].account).to.be.null + expect(body.data[0].totalReplies).to.equal(2) + expect(body.data[1].text).to.equal('super thread 2') + expect(body.data[1].totalReplies).to.equal(0) + expect(body.data[2].text).to.equal('super thread 3') + expect(body.data[2].totalReplies).to.equal(0) }) it('Should count replies from the video author correctly', async function () { - const text = 'my super first comment' - await addVideoCommentThread(server.url, server.accessToken, videoUUID, text) - let res = await getVideoCommentThreads(server.url, videoUUID, 0, 5) - const comment: VideoComment = res.body.data[0] - const threadId2 = comment.threadId + await command.createThread({ videoId: videoUUID, text: 'my super first comment' }) + + const { data } = await command.listThreads({ videoId: videoUUID }) + const threadId2 = data[0].threadId const text2 = 'a first answer to thread 4 by a third party' - await addVideoCommentReply(server.url, userAccessTokenServer1, videoId, threadId2, text2) + await command.addReply({ token: userAccessTokenServer1, videoId, toCommentId: threadId2, text: text2 }) const text3 = 'my second answer to thread 4' - await addVideoCommentReply(server.url, server.accessToken, videoId, threadId2, text3) + await command.addReply({ videoId, toCommentId: threadId2, text: text3 }) - res = await getVideoThreadComments(server.url, videoUUID, threadId2) - const tree: VideoCommentThreadTree = res.body + const tree = await command.getThread({ videoId: videoUUID, threadId: threadId2 }) expect(tree.comment.totalReplies).to.equal(tree.comment.totalRepliesFromVideoAuthor + 1) }) }) describe('All instance comments', function () { - async function getComments (options: any = {}) { - const res = await getAdminVideoComments(Object.assign({ - url: server.url, - token: server.accessToken, - start: 0, - count: 10 - }, options)) - - return { comments: res.body.data as VideoCommentAdmin[], total: res.body.total as number } - } it('Should list instance comments as admin', async function () { - const { comments } = await getComments({ start: 0, count: 1 }) + const { data } = await command.listForAdmin({ start: 0, count: 1 }) - expect(comments[0].text).to.equal('my second answer to thread 4') + expect(data[0].text).to.equal('my second answer to thread 4') }) it('Should filter instance comments by isLocal', async function () { - const { total, comments } = await getComments({ isLocal: false }) + const { total, data } = await command.listForAdmin({ isLocal: false }) - expect(comments).to.have.lengthOf(0) + expect(data).to.have.lengthOf(0) expect(total).to.equal(0) }) it('Should search instance comments by account', async function () { - const { total, comments } = await getComments({ searchAccount: 'user' }) + const { total, data } = await command.listForAdmin({ searchAccount: 'user' }) - expect(comments).to.have.lengthOf(1) + expect(data).to.have.lengthOf(1) expect(total).to.equal(1) - expect(comments[0].text).to.equal('a first answer to thread 4 by a third party') + expect(data[0].text).to.equal('a first answer to thread 4 by a third party') }) it('Should search instance comments by video', async function () { { - const { total, comments } = await getComments({ searchVideo: 'video' }) + const { total, data } = await command.listForAdmin({ searchVideo: 'video' }) - expect(comments).to.have.lengthOf(7) + expect(data).to.have.lengthOf(7) expect(total).to.equal(7) } { - const { total, comments } = await getComments({ searchVideo: 'hello' }) + const { total, data } = await command.listForAdmin({ searchVideo: 'hello' }) - expect(comments).to.have.lengthOf(0) + expect(data).to.have.lengthOf(0) expect(total).to.equal(0) } }) it('Should search instance comments', async function () { - const { total, comments } = await getComments({ search: 'super thread 3' }) + const { total, data } = await command.listForAdmin({ search: 'super thread 3' }) - expect(comments).to.have.lengthOf(1) expect(total).to.equal(1) - expect(comments[0].text).to.equal('super thread 3') + + expect(data).to.have.lengthOf(1) + expect(data[0].text).to.equal('super thread 3') }) }) -- 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/activitypub/cleaner.ts | 32 ++++++++-------------- server/tests/api/activitypub/fetch.ts | 12 ++------ server/tests/api/activitypub/refresher.ts | 16 ++++------- server/tests/api/activitypub/security.ts | 14 ++++------ server/tests/api/check-params/contact-form.ts | 4 +-- server/tests/api/check-params/users.ts | 2 +- server/tests/api/live/live.ts | 2 +- server/tests/api/moderation/video-blacklist.ts | 2 +- .../tests/api/notifications/admin-notifications.ts | 10 +++---- .../tests/api/redundancy/redundancy-constraints.ts | 4 +-- server/tests/api/redundancy/redundancy.ts | 4 +-- server/tests/api/server/config.ts | 4 +-- server/tests/api/server/handle-down.ts | 12 +++----- server/tests/api/server/homepage.ts | 2 +- server/tests/api/server/logs.ts | 2 +- server/tests/api/server/plugins.ts | 9 ++---- server/tests/api/server/tracker.ts | 6 ++-- server/tests/api/users/users.ts | 13 ++++----- server/tests/api/videos/video-channels.ts | 5 ++-- server/tests/api/videos/videos-history.ts | 4 +-- server/tests/api/videos/videos-views-cleaner.ts | 20 ++++++-------- 21 files changed, 68 insertions(+), 111 deletions(-) (limited to 'server/tests/api') diff --git a/server/tests/api/activitypub/cleaner.ts b/server/tests/api/activitypub/cleaner.ts index 27f17b4d6..5b08880bf 100644 --- a/server/tests/api/activitypub/cleaner.ts +++ b/server/tests/api/activitypub/cleaner.ts @@ -4,18 +4,12 @@ import 'mocha' import * as chai from 'chai' import { cleanupTests, - closeAllSequelize, - deleteAll, doubleFollow, flushAndRunMultipleServers, - getCount, getVideo, rateVideo, - selectQuery, ServerInfo, setAccessTokensToServers, - setVideoField, - updateQuery, uploadVideoAndGetId, wait, waitJobs @@ -86,9 +80,9 @@ describe('Test AP cleaner', function () { it('Should destroy server 3 internal likes and correctly clean them', async function () { this.timeout(20000) - await deleteAll(servers[2].internalServerNumber, 'accountVideoRate') + await servers[2].sqlCommand.deleteAll('accountVideoRate') for (const uuid of videoUUIDs) { - await setVideoField(servers[2].internalServerNumber, uuid, 'likes', '0') + await servers[2].sqlCommand.setVideoField(uuid, 'likes', '0') } await wait(5000) @@ -132,10 +126,10 @@ describe('Test AP cleaner', function () { it('Should destroy server 3 internal dislikes and correctly clean them', async function () { this.timeout(20000) - await deleteAll(servers[2].internalServerNumber, 'accountVideoRate') + await servers[2].sqlCommand.deleteAll('accountVideoRate') for (const uuid of videoUUIDs) { - await setVideoField(servers[2].internalServerNumber, uuid, 'dislikes', '0') + await servers[2].sqlCommand.setVideoField(uuid, 'dislikes', '0') } await wait(5000) @@ -159,15 +153,15 @@ describe('Test AP cleaner', function () { it('Should destroy server 3 internal shares and correctly clean them', async function () { this.timeout(20000) - const preCount = await getCount(servers[0].internalServerNumber, 'videoShare') + const preCount = await servers[0].sqlCommand.getCount('videoShare') expect(preCount).to.equal(6) - await deleteAll(servers[2].internalServerNumber, 'videoShare') + await servers[2].sqlCommand.deleteAll('videoShare') await wait(5000) await waitJobs(servers) // Still 6 because we don't have remote shares on local videos - const postCount = await getCount(servers[0].internalServerNumber, 'videoShare') + const postCount = await servers[0].sqlCommand.getCount('videoShare') expect(postCount).to.equal(6) }) @@ -179,7 +173,7 @@ describe('Test AP cleaner', function () { expect(total).to.equal(3) } - await deleteAll(servers[2].internalServerNumber, 'videoComment') + await servers[2].sqlCommand.deleteAll('videoComment') await wait(5000) await waitJobs(servers) @@ -196,7 +190,7 @@ describe('Test AP cleaner', function () { async function check (like: string, ofServerUrl: string, urlSuffix: string, remote: 'true' | 'false') { const query = `SELECT "videoId", "accountVideoRate".url FROM "accountVideoRate" ` + `INNER JOIN video ON "accountVideoRate"."videoId" = video.id AND remote IS ${remote} WHERE "accountVideoRate"."url" LIKE '${like}'` - const res = await selectQuery(servers[0].internalServerNumber, query) + const res = await servers[0].sqlCommand.selectQuery(query) for (const rate of res) { const matcher = new RegExp(`^${ofServerUrl}/accounts/root/dislikes/\\d+${urlSuffix}$`) @@ -225,7 +219,7 @@ describe('Test AP cleaner', function () { { const query = `UPDATE "accountVideoRate" SET url = url || 'stan'` - await updateQuery(servers[1].internalServerNumber, query) + await servers[1].sqlCommand.updateQuery(query) await wait(5000) await waitJobs(servers) @@ -242,7 +236,7 @@ describe('Test AP cleaner', function () { const query = `SELECT "videoId", "videoComment".url, uuid as "videoUUID" FROM "videoComment" ` + `INNER JOIN video ON "videoComment"."videoId" = video.id AND remote IS ${remote} WHERE "videoComment"."url" LIKE '${like}'` - const res = await selectQuery(servers[0].internalServerNumber, query) + const res = await servers[0].sqlCommand.selectQuery(query) for (const comment of res) { const matcher = new RegExp(`${ofServerUrl}/videos/watch/${comment.videoUUID}/comments/\\d+${urlSuffix}`) @@ -268,7 +262,7 @@ describe('Test AP cleaner', function () { { const query = `UPDATE "videoComment" SET url = url || 'kyle'` - await updateQuery(servers[1].internalServerNumber, query) + await servers[1].sqlCommand.updateQuery(query) await wait(5000) await waitJobs(servers) @@ -280,7 +274,5 @@ describe('Test AP cleaner', function () { after(async function () { await cleanupTests(servers) - - await closeAllSequelize(servers) }) }) diff --git a/server/tests/api/activitypub/fetch.ts b/server/tests/api/activitypub/fetch.ts index 35fd94eed..d5e21404c 100644 --- a/server/tests/api/activitypub/fetch.ts +++ b/server/tests/api/activitypub/fetch.ts @@ -1,23 +1,19 @@ /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */ import 'mocha' - +import * as chai from 'chai' import { cleanupTests, - closeAllSequelize, createUser, doubleFollow, flushAndRunMultipleServers, getVideosListSort, ServerInfo, setAccessTokensToServers, - setActorField, - setVideoField, uploadVideo, userLogin, waitJobs } from '../../../../shared/extra-utils' -import * as chai from 'chai' import { Video } from '../../../../shared/models/videos' const expect = chai.expect @@ -50,12 +46,12 @@ describe('Test ActivityPub fetcher', function () { { const to = 'http://localhost:' + servers[0].port + '/accounts/user1' const value = 'http://localhost:' + servers[1].port + '/accounts/user1' - await setActorField(servers[0].internalServerNumber, to, 'url', value) + await servers[0].sqlCommand.setActorField(to, 'url', value) } { const value = 'http://localhost:' + servers[2].port + '/videos/watch/' + badVideoUUID - await setVideoField(servers[0].internalServerNumber, badVideoUUID, 'url', value) + await servers[0].sqlCommand.setVideoField(badVideoUUID, 'url', value) } }) @@ -88,7 +84,5 @@ describe('Test ActivityPub fetcher', function () { this.timeout(20000) await cleanupTests(servers) - - await closeAllSequelize(servers) }) }) diff --git a/server/tests/api/activitypub/refresher.ts b/server/tests/api/activitypub/refresher.ts index f295dfab7..af919f2f3 100644 --- a/server/tests/api/activitypub/refresher.ts +++ b/server/tests/api/activitypub/refresher.ts @@ -4,7 +4,6 @@ import 'mocha' import { HttpStatusCode } from '@shared/core-utils' import { cleanupTests, - closeAllSequelize, doubleFollow, flushAndRunMultipleServers, generateUserAccessToken, @@ -13,10 +12,7 @@ import { reRunServer, ServerInfo, setAccessTokensToServers, - setActorField, setDefaultVideoChannel, - setPlaylistField, - setVideoField, uploadVideo, uploadVideoAndGetId, wait, @@ -78,7 +74,7 @@ describe('Test AP refresher', function () { await wait(10000) // Change UUID so the remote server returns a 404 - await setVideoField(servers[1].internalServerNumber, videoUUID1, 'uuid', '304afe4f-39f9-4d49-8ed7-ac57b86b174f') + await servers[1].sqlCommand.setVideoField(videoUUID1, 'uuid', '304afe4f-39f9-4d49-8ed7-ac57b86b174f') await getVideo(servers[0].url, videoUUID1) await getVideo(servers[0].url, videoUUID2) @@ -92,9 +88,9 @@ describe('Test AP refresher', function () { it('Should not update a remote video if the remote instance is down', async function () { this.timeout(70000) - killallServers([ servers[1] ]) + await killallServers([ servers[1] ]) - await setVideoField(servers[1].internalServerNumber, videoUUID3, 'uuid', '304afe4f-39f9-4d49-8ed7-ac57b86b174e') + await servers[1].sqlCommand.setVideoField(videoUUID3, 'uuid', '304afe4f-39f9-4d49-8ed7-ac57b86b174e') // Video will need a refresh await wait(10000) @@ -120,7 +116,7 @@ describe('Test AP refresher', function () { // Change actor name so the remote server returns a 404 const to = 'http://localhost:' + servers[1].port + '/accounts/user2' - await setActorField(servers[1].internalServerNumber, to, 'preferredUsername', 'toto') + await servers[1].sqlCommand.setActorField(to, 'preferredUsername', 'toto') await command.get({ accountName: 'user1@localhost:' + servers[1].port }) await command.get({ accountName: 'user2@localhost:' + servers[1].port }) @@ -140,7 +136,7 @@ describe('Test AP refresher', function () { await wait(10000) // Change UUID so the remote server returns a 404 - await setPlaylistField(servers[1].internalServerNumber, playlistUUID2, 'uuid', '304afe4f-39f9-4d49-8ed7-ac57b86b178e') + await servers[1].sqlCommand.setPlaylistField(playlistUUID2, 'uuid', '304afe4f-39f9-4d49-8ed7-ac57b86b178e') await servers[0].playlistsCommand.get({ playlistId: playlistUUID1 }) await servers[0].playlistsCommand.get({ playlistId: playlistUUID2 }) @@ -156,7 +152,5 @@ describe('Test AP refresher', function () { this.timeout(10000) await cleanupTests(servers) - - await closeAllSequelize(servers) }) }) diff --git a/server/tests/api/activitypub/security.ts b/server/tests/api/activitypub/security.ts index 61db272f6..c32940070 100644 --- a/server/tests/api/activitypub/security.ts +++ b/server/tests/api/activitypub/security.ts @@ -7,12 +7,10 @@ import { HttpStatusCode } from '../../../../shared/core-utils/miscs/http-error-c import { buildAbsoluteFixturePath, cleanupTests, - closeAllSequelize, flushAndRunMultipleServers, killallServers, reRunServer, ServerInfo, - setActorField, wait } from '../../../../shared/extra-utils' import { makeFollowRequest, makePOSTAPRequest } from '../../../../shared/extra-utils/requests/activitypub' @@ -26,8 +24,8 @@ function setKeysOfServer (onServer: ServerInfo, ofServer: ServerInfo, publicKey: const url = 'http://localhost:' + ofServer.port + '/accounts/peertube' return Promise.all([ - setActorField(onServer.internalServerNumber, url, 'publicKey', publicKey), - setActorField(onServer.internalServerNumber, url, 'privateKey', privateKey) + onServer.sqlCommand.setActorField(url, 'publicKey', publicKey), + onServer.sqlCommand.setActorField(url, 'privateKey', privateKey) ]) } @@ -35,8 +33,8 @@ function setUpdatedAtOfServer (onServer: ServerInfo, ofServer: ServerInfo, updat const url = 'http://localhost:' + ofServer.port + '/accounts/peertube' return Promise.all([ - setActorField(onServer.internalServerNumber, url, 'createdAt', updatedAt), - setActorField(onServer.internalServerNumber, url, 'updatedAt', updatedAt) + onServer.sqlCommand.setActorField(url, 'createdAt', updatedAt), + onServer.sqlCommand.setActorField(url, 'updatedAt', updatedAt) ]) } @@ -173,7 +171,7 @@ describe('Test ActivityPub security', function () { await setUpdatedAtOfServer(servers[0], servers[1], '2015-07-17 22:00:00+00') // Invalid peertube actor cache - killallServers([ servers[1] ]) + await killallServers([ servers[1] ]) await reRunServer(servers[1]) const body = activityPubContextify(getAnnounceWithoutContext(servers[1])) @@ -294,7 +292,5 @@ describe('Test ActivityPub security', function () { this.timeout(10000) await cleanupTests(servers) - - await closeAllSequelize(servers) }) }) 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: { diff --git a/server/tests/api/live/live.ts b/server/tests/api/live/live.ts index 0b06df44c..f9a162df6 100644 --- a/server/tests/api/live/live.ts +++ b/server/tests/api/live/live.ts @@ -587,7 +587,7 @@ describe('Test live', function () { await commands[0].waitUntilSegmentGeneration({ videoUUID: liveVideoId, resolution: 0, segment: 2 }) await commands[0].waitUntilSegmentGeneration({ videoUUID: liveVideoReplayId, resolution: 0, segment: 2 }) - killallServers([ servers[0] ]) + await killallServers([ servers[0] ]) await reRunServer(servers[0]) await wait(5000) diff --git a/server/tests/api/moderation/video-blacklist.ts b/server/tests/api/moderation/video-blacklist.ts index c72ebc16b..8b4723a2b 100644 --- a/server/tests/api/moderation/video-blacklist.ts +++ b/server/tests/api/moderation/video-blacklist.ts @@ -342,7 +342,7 @@ describe('Test video blacklist', function () { before(async function () { this.timeout(20000) - killallServers([ servers[0] ]) + await killallServers([ servers[0] ]) const config = { auto_blacklist: { diff --git a/server/tests/api/notifications/admin-notifications.ts b/server/tests/api/notifications/admin-notifications.ts index da9767b74..03fbe0b70 100644 --- a/server/tests/api/notifications/admin-notifications.ts +++ b/server/tests/api/notifications/admin-notifications.ts @@ -11,8 +11,6 @@ import { MockSmtpServer, prepareNotificationsTest, ServerInfo, - setPluginLatestVersion, - setPluginVersion, wait } from '@shared/extra-utils' import { PluginType, UserNotification, UserNotificationType } from '@shared/models' @@ -120,8 +118,8 @@ describe('Test admin notifications', function () { it('Should send a notification to admins on new plugin version', async function () { this.timeout(30000) - await setPluginVersion(server.internalServerNumber, 'hello-world', '0.0.1') - await setPluginLatestVersion(server.internalServerNumber, 'hello-world', '0.0.1') + await server.sqlCommand.setPluginVersion('hello-world', '0.0.1') + await server.sqlCommand.setPluginLatestVersion('hello-world', '0.0.1') await wait(6000) await checkNewPluginVersion(baseParams, PluginType.PLUGIN, 'hello-world', 'presence') @@ -142,8 +140,8 @@ describe('Test admin notifications', function () { it('Should send a new notification after a new plugin release', async function () { this.timeout(30000) - await setPluginVersion(server.internalServerNumber, 'hello-world', '0.0.1') - await setPluginLatestVersion(server.internalServerNumber, 'hello-world', '0.0.1') + await server.sqlCommand.setPluginVersion('hello-world', '0.0.1') + await server.sqlCommand.setPluginLatestVersion('hello-world', '0.0.1') await wait(6000) expect(adminNotifications.filter(n => n.type === UserNotificationType.NEW_PEERTUBE_VERSION)).to.have.lengthOf(2) diff --git a/server/tests/api/redundancy/redundancy-constraints.ts b/server/tests/api/redundancy/redundancy-constraints.ts index 500b96747..82d952471 100644 --- a/server/tests/api/redundancy/redundancy-constraints.ts +++ b/server/tests/api/redundancy/redundancy-constraints.ts @@ -121,7 +121,7 @@ describe('Test redundancy constraints', function () { } } } - await killallServers([ localServer ]) + await await killallServers([ localServer ]) await reRunServer(localServer, config) await uploadWrapper('video 2 server 2') @@ -150,7 +150,7 @@ describe('Test redundancy constraints', function () { } } } - killallServers([ localServer ]) + await killallServers([ localServer ]) await reRunServer(localServer, config) await uploadWrapper('video 3 server 2') diff --git a/server/tests/api/redundancy/redundancy.ts b/server/tests/api/redundancy/redundancy.ts index d20cb80f1..56a2af395 100644 --- a/server/tests/api/redundancy/redundancy.ts +++ b/server/tests/api/redundancy/redundancy.ts @@ -634,7 +634,7 @@ describe('Test videos redundancy', function () { it('Should stop server 1 and expire video redundancy', async function () { this.timeout(80000) - killallServers([ servers[0] ]) + await killallServers([ servers[0] ]) await wait(15000) @@ -703,7 +703,7 @@ describe('Test videos redundancy', function () { await waitJobs(servers) - killallServers([ servers[0] ]) + await killallServers([ servers[0] ]) await reRunServer(servers[0], { redundancy: { videos: { diff --git a/server/tests/api/server/config.ts b/server/tests/api/server/config.ts index 037628c9d..55cf2a1b8 100644 --- a/server/tests/api/server/config.ts +++ b/server/tests/api/server/config.ts @@ -456,7 +456,7 @@ describe('Test config', function () { it('Should have the configuration updated after a restart', async function () { this.timeout(10000) - killallServers([ server ]) + await killallServers([ server ]) await reRunServer(server) @@ -507,7 +507,7 @@ describe('Test config', function () { expect(res.headers['x-frame-options']).to.exist } - killallServers([ server ]) + await killallServers([ server ]) const config = { security: { diff --git a/server/tests/api/server/handle-down.ts b/server/tests/api/server/handle-down.ts index 94496a159..dd06acb5e 100644 --- a/server/tests/api/server/handle-down.ts +++ b/server/tests/api/server/handle-down.ts @@ -5,7 +5,6 @@ import * as chai from 'chai' import { HttpStatusCode } from '@shared/core-utils' import { cleanupTests, - closeAllSequelize, CommentsCommand, completeVideoCheck, flushAndRunMultipleServers, @@ -16,7 +15,6 @@ import { reRunServer, ServerInfo, setAccessTokensToServers, - setActorFollowScores, updateVideo, uploadVideo, uploadVideoAndGetId, @@ -129,7 +127,7 @@ describe('Test handle downs', function () { } // Kill server 2 - killallServers([ servers[1] ]) + await killallServers([ servers[1] ]) // Remove server 2 follower for (let i = 0; i < 10; i++) { @@ -139,7 +137,7 @@ describe('Test handle downs', function () { await waitJobs([ servers[0], servers[2] ]) // Kill server 3 - killallServers([ servers[2] ]) + await killallServers([ servers[2] ]) const resLastVideo1 = await uploadVideo(servers[0].url, servers[0].accessToken, videoAttributes) missedVideo1 = resLastVideo1.body.video @@ -311,7 +309,7 @@ describe('Test handle downs', function () { } await waitJobs(servers) - await setActorFollowScores(servers[1].internalServerNumber, 20) + await servers[1].sqlCommand.setActorFollowScores(20) // Wait video expiration await wait(11000) @@ -325,7 +323,7 @@ describe('Test handle downs', function () { it('Should remove followings that are down', async function () { this.timeout(120000) - killallServers([ servers[0] ]) + await killallServers([ servers[0] ]) // Wait video expiration await wait(11000) @@ -344,8 +342,6 @@ describe('Test handle downs', function () { }) after(async function () { - await closeAllSequelize([ servers[1] ]) - await cleanupTests(servers) }) }) diff --git a/server/tests/api/server/homepage.ts b/server/tests/api/server/homepage.ts index c08067f3c..18b9edc31 100644 --- a/server/tests/api/server/homepage.ts +++ b/server/tests/api/server/homepage.ts @@ -54,7 +54,7 @@ describe('Test instance homepage actions', function () { it('Should have the same homepage after a restart', async function () { this.timeout(30000) - killallServers([ server ]) + await killallServers([ server ]) await reRunServer(server) diff --git a/server/tests/api/server/logs.ts b/server/tests/api/server/logs.ts index ab83a329f..365f6cc2b 100644 --- a/server/tests/api/server/logs.ts +++ b/server/tests/api/server/logs.ts @@ -113,7 +113,7 @@ describe('Test logs', function () { it('Should not log ping requests', async function () { this.timeout(30000) - killallServers([ server ]) + await killallServers([ server ]) await reRunServer(server, { log: { log_ping_requests: false } }) diff --git a/server/tests/api/server/plugins.ts b/server/tests/api/server/plugins.ts index e22ecfad9..655cf00fa 100644 --- a/server/tests/api/server/plugins.ts +++ b/server/tests/api/server/plugins.ts @@ -5,7 +5,6 @@ import * as chai from 'chai' import { HttpStatusCode } from '@shared/core-utils' import { cleanupTests, - closeAllSequelize, flushAndRunServer, getMyUserInformation, killallServers, @@ -13,7 +12,6 @@ import { reRunServer, ServerInfo, setAccessTokensToServers, - setPluginVersion, testHelloWorldRegisteredSettings, updateMyUser, wait, @@ -244,7 +242,7 @@ describe('Test plugins', function () { await wait(6000) // Fake update our plugin version - await setPluginVersion(server.internalServerNumber, 'hello-world', '0.0.1') + await server.sqlCommand.setPluginVersion('hello-world', '0.0.1') // Fake update package.json const packageJSON = await command.getPackageJSON('peertube-plugin-hello-world') @@ -254,7 +252,7 @@ describe('Test plugins', function () { await command.updatePackageJSON('peertube-plugin-hello-world', packageJSON) // Restart the server to take into account this change - killallServers([ server ]) + await killallServers([ server ]) await reRunServer(server) { @@ -335,14 +333,13 @@ describe('Test plugins', function () { await check() - killallServers([ server ]) + await killallServers([ server ]) await reRunServer(server) await check() }) after(async function () { - await closeAllSequelize([ server ]) await cleanupTests([ server ]) }) }) diff --git a/server/tests/api/server/tracker.ts b/server/tests/api/server/tracker.ts index 4b86e0b90..868dc8977 100644 --- a/server/tests/api/server/tracker.ts +++ b/server/tests/api/server/tracker.ts @@ -61,8 +61,7 @@ describe('Test tracker', function () { const errCb = () => done(new Error('Tracker is enabled')) killallServers([ server ]) - - reRunServer(server, { tracker: { enabled: false } }) + .then(() => reRunServer(server, { tracker: { enabled: false } })) .then(() => { const webtorrent = new WebTorrent() @@ -86,8 +85,7 @@ describe('Test tracker', function () { this.timeout(20000) killallServers([ server ]) - - reRunServer(server) + .then(() => reRunServer(server)) .then(() => { const webtorrent = new WebTorrent() diff --git a/server/tests/api/users/users.ts b/server/tests/api/users/users.ts index 4d255f340..69a8dba34 100644 --- a/server/tests/api/users/users.ts +++ b/server/tests/api/users/users.ts @@ -6,7 +6,6 @@ import { HttpStatusCode } from '@shared/core-utils' import { blockUser, cleanupTests, - closeAllSequelize, createUser, deleteMe, flushAndRunServer, @@ -30,7 +29,6 @@ import { reRunServer, ServerInfo, setAccessTokensToServers, - setTokenField, testImage, unblockUser, updateMyAvatar, @@ -264,10 +262,10 @@ describe('Test users', function () { it('Should have an expired access token', async function () { this.timeout(15000) - await setTokenField(server.internalServerNumber, server.accessToken, 'accessTokenExpiresAt', new Date().toISOString()) - await setTokenField(server.internalServerNumber, server.accessToken, 'refreshTokenExpiresAt', new Date().toISOString()) + await server.sqlCommand.setTokenField(server.accessToken, 'accessTokenExpiresAt', new Date().toISOString()) + await server.sqlCommand.setTokenField(server.accessToken, 'refreshTokenExpiresAt', new Date().toISOString()) - killallServers([ server ]) + await killallServers([ server ]) await reRunServer(server) await getMyUserInformation(server.url, server.accessToken, 401) @@ -281,9 +279,9 @@ describe('Test users', function () { this.timeout(15000) const futureDate = new Date(new Date().getTime() + 1000 * 60).toISOString() - await setTokenField(server.internalServerNumber, server.accessToken, 'refreshTokenExpiresAt', futureDate) + await server.sqlCommand.setTokenField(server.accessToken, 'refreshTokenExpiresAt', futureDate) - killallServers([ server ]) + await killallServers([ server ]) await reRunServer(server) const res = await refreshToken(server, server.refreshToken) @@ -1013,7 +1011,6 @@ describe('Test users', function () { }) after(async function () { - await closeAllSequelize([ server ]) await cleanupTests([ server ]) }) }) diff --git a/server/tests/api/videos/video-channels.ts b/server/tests/api/videos/video-channels.ts index daf066eb1..e441ebbd4 100644 --- a/server/tests/api/videos/video-channels.ts +++ b/server/tests/api/videos/video-channels.ts @@ -9,7 +9,6 @@ import { createUser, doubleFollow, flushAndRunMultipleServers, - getActorImage, getVideo, getVideoChannelVideos, setDefaultVideoChannel, @@ -268,7 +267,7 @@ describe('Test video channels', function () { await testImage(server.url, 'avatar-resized', avatarPaths[server.port], '.png') await testFileExistsOrNot(server, 'avatars', basename(avatarPaths[server.port]), true) - const row = await getActorImage(server.internalServerNumber, basename(avatarPaths[server.port])) + const row = await server.sqlCommand.getActorImage(basename(avatarPaths[server.port])) expect(row.height).to.equal(ACTOR_IMAGES_SIZE.AVATARS.height) expect(row.width).to.equal(ACTOR_IMAGES_SIZE.AVATARS.width) } @@ -294,7 +293,7 @@ describe('Test video channels', function () { await testImage(server.url, 'banner-resized', bannerPaths[server.port]) await testFileExistsOrNot(server, 'avatars', basename(bannerPaths[server.port]), true) - const row = await getActorImage(server.internalServerNumber, basename(bannerPaths[server.port])) + const row = await server.sqlCommand.getActorImage(basename(bannerPaths[server.port])) expect(row.height).to.equal(ACTOR_IMAGES_SIZE.BANNERS.height) expect(row.width).to.equal(ACTOR_IMAGES_SIZE.BANNERS.width) } diff --git a/server/tests/api/videos/videos-history.ts b/server/tests/api/videos/videos-history.ts index 731447135..9a7635c35 100644 --- a/server/tests/api/videos/videos-history.ts +++ b/server/tests/api/videos/videos-history.ts @@ -204,7 +204,7 @@ describe('Test videos history', function () { it('Should not clean old history', async function () { this.timeout(50000) - killallServers([ server ]) + await killallServers([ server ]) await reRunServer(server, { history: { videos: { max_age: '10 days' } } }) @@ -219,7 +219,7 @@ describe('Test videos history', function () { it('Should clean old history', async function () { this.timeout(50000) - killallServers([ server ]) + await killallServers([ server ]) await reRunServer(server, { history: { videos: { max_age: '5 seconds' } } }) diff --git a/server/tests/api/videos/videos-views-cleaner.ts b/server/tests/api/videos/videos-views-cleaner.ts index b89f33217..b6cde6b50 100644 --- a/server/tests/api/videos/videos-views-cleaner.ts +++ b/server/tests/api/videos/videos-views-cleaner.ts @@ -1,11 +1,9 @@ /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */ -import * as chai from 'chai' import 'mocha' +import * as chai from 'chai' import { cleanupTests, - closeAllSequelize, - countVideoViewsOf, doubleFollow, flushAndRunMultipleServers, killallServers, @@ -50,7 +48,7 @@ describe('Test video views cleaner', function () { it('Should not clean old video views', async function () { this.timeout(50000) - killallServers([ servers[0] ]) + await killallServers([ servers[0] ]) await reRunServer(servers[0], { views: { videos: { remote: { max_age: '10 days' } } } }) @@ -60,14 +58,14 @@ describe('Test video views cleaner', function () { { for (const server of servers) { - const total = await countVideoViewsOf(server.internalServerNumber, videoIdServer1) + const total = await server.sqlCommand.countVideoViewsOf(videoIdServer1) expect(total).to.equal(2, 'Server ' + server.serverNumber + ' does not have the correct amount of views') } } { for (const server of servers) { - const total = await countVideoViewsOf(server.internalServerNumber, videoIdServer2) + const total = await server.sqlCommand.countVideoViewsOf(videoIdServer2) expect(total).to.equal(2, 'Server ' + server.serverNumber + ' does not have the correct amount of views') } } @@ -76,7 +74,7 @@ describe('Test video views cleaner', function () { it('Should clean old video views', async function () { this.timeout(50000) - killallServers([ servers[0] ]) + await killallServers([ servers[0] ]) await reRunServer(servers[0], { views: { videos: { remote: { max_age: '5 seconds' } } } }) @@ -86,23 +84,21 @@ describe('Test video views cleaner', function () { { for (const server of servers) { - const total = await countVideoViewsOf(server.internalServerNumber, videoIdServer1) + const total = await server.sqlCommand.countVideoViewsOf(videoIdServer1) expect(total).to.equal(2) } } { - const totalServer1 = await countVideoViewsOf(servers[0].internalServerNumber, videoIdServer2) + const totalServer1 = await servers[0].sqlCommand.countVideoViewsOf(videoIdServer2) expect(totalServer1).to.equal(0) - const totalServer2 = await countVideoViewsOf(servers[1].internalServerNumber, videoIdServer2) + const totalServer2 = await servers[1].sqlCommand.countVideoViewsOf(videoIdServer2) expect(totalServer2).to.equal(2) } }) after(async function () { - await closeAllSequelize(servers) - await cleanupTests(servers) }) }) -- 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 +- .../tests/api/moderation/blocklist-notification.ts | 47 +++---- server/tests/api/moderation/blocklist.ts | 28 ++-- .../tests/api/notifications/notifications-api.ts | 92 ++++++------- .../tests/api/notifications/user-notifications.ts | 5 +- server/tests/api/server/plugins.ts | 3 +- server/tests/api/videos/video-hls.ts | 1 + server/tests/api/videos/video-nsfw.ts | 142 ++++++++++----------- 9 files changed, 154 insertions(+), 168 deletions(-) (limited to 'server/tests/api') 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 } diff --git a/server/tests/api/moderation/blocklist-notification.ts b/server/tests/api/moderation/blocklist-notification.ts index a077d8739..b676a4db4 100644 --- a/server/tests/api/moderation/blocklist-notification.ts +++ b/server/tests/api/moderation/blocklist-notification.ts @@ -7,27 +7,22 @@ import { createUser, doubleFollow, flushAndRunMultipleServers, - getUserNotifications, - markAsReadAllNotifications, ServerInfo, setAccessTokensToServers, uploadVideo, userLogin, waitJobs } from '@shared/extra-utils' -import { UserNotification, UserNotificationType } from '@shared/models' +import { UserNotificationType } from '@shared/models' const expect = chai.expect -async function checkNotifications (url: string, token: string, expected: UserNotificationType[]) { - const res = await getUserNotifications(url, token, 0, 10, true) - - const notifications: UserNotification[] = res.body.data - - expect(notifications).to.have.lengthOf(expected.length) +async function checkNotifications (server: ServerInfo, token: string, expected: UserNotificationType[]) { + const { data } = await server.notificationsCommand.list({ token, start: 0, count: 10, unread: true }) + expect(data).to.have.lengthOf(expected.length) for (const type of expected) { - expect(notifications.find(n => n.type === type)).to.exist + expect(data.find(n => n.type === type)).to.exist } } @@ -47,8 +42,8 @@ describe('Test blocklist', function () { await waitJobs(servers) - await markAsReadAllNotifications(servers[0].url, userToken1) - await markAsReadAllNotifications(servers[0].url, userToken2) + await servers[0].notificationsCommand.markAsReadAll({ token: userToken1 }) + await servers[0].notificationsCommand.markAsReadAll({ token: userToken2 }) { const res = await uploadVideo(servers[0].url, userToken1, { name: 'video' }) @@ -122,7 +117,7 @@ describe('Test blocklist', function () { it('Should have appropriate notifications', async function () { const notifs = [ UserNotificationType.NEW_COMMENT_ON_MY_VIDEO, UserNotificationType.NEW_FOLLOW ] - await checkNotifications(servers[0].url, userToken1, notifs) + await checkNotifications(servers[0], userToken1, notifs) }) it('Should block an account', async function () { @@ -133,13 +128,13 @@ describe('Test blocklist', function () { }) it('Should not have notifications from this account', async function () { - await checkNotifications(servers[0].url, userToken1, []) + await checkNotifications(servers[0], userToken1, []) }) it('Should have notifications of this account on user 2', async function () { const notifs = [ UserNotificationType.COMMENT_MENTION, UserNotificationType.NEW_FOLLOW ] - await checkNotifications(servers[0].url, userToken2, notifs) + await checkNotifications(servers[0], userToken2, notifs) await servers[0].blocklistCommand.removeFromMyBlocklist({ token: userToken1, account: 'user3@' + servers[1].host }) }) @@ -155,7 +150,7 @@ describe('Test blocklist', function () { it('Should have appropriate notifications', async function () { const notifs = [ UserNotificationType.NEW_COMMENT_ON_MY_VIDEO, UserNotificationType.NEW_FOLLOW ] - await checkNotifications(servers[0].url, userToken1, notifs) + await checkNotifications(servers[0], userToken1, notifs) }) it('Should block an account', async function () { @@ -166,13 +161,13 @@ describe('Test blocklist', function () { }) it('Should not have notifications from this account', async function () { - await checkNotifications(servers[0].url, userToken1, []) + await checkNotifications(servers[0], userToken1, []) }) it('Should have notifications of this account on user 2', async function () { const notifs = [ UserNotificationType.COMMENT_MENTION, UserNotificationType.NEW_FOLLOW ] - await checkNotifications(servers[0].url, userToken2, notifs) + await checkNotifications(servers[0], userToken2, notifs) await servers[0].blocklistCommand.removeFromMyBlocklist({ token: userToken1, server: servers[1].host }) }) @@ -189,12 +184,12 @@ describe('Test blocklist', function () { it('Should have appropriate notifications', async function () { { const notifs = [ UserNotificationType.NEW_COMMENT_ON_MY_VIDEO, UserNotificationType.NEW_FOLLOW ] - await checkNotifications(servers[0].url, userToken1, notifs) + await checkNotifications(servers[0], userToken1, notifs) } { const notifs = [ UserNotificationType.COMMENT_MENTION, UserNotificationType.NEW_FOLLOW ] - await checkNotifications(servers[0].url, userToken2, notifs) + await checkNotifications(servers[0], userToken2, notifs) } }) @@ -206,8 +201,8 @@ describe('Test blocklist', function () { }) it('Should not have notifications from this account', async function () { - await checkNotifications(servers[0].url, userToken1, []) - await checkNotifications(servers[0].url, userToken2, []) + await checkNotifications(servers[0], userToken1, []) + await checkNotifications(servers[0], userToken2, []) await servers[0].blocklistCommand.removeFromServerBlocklist({ account: 'user3@' + servers[1].host }) }) @@ -224,12 +219,12 @@ describe('Test blocklist', function () { it('Should have appropriate notifications', async function () { { const notifs = [ UserNotificationType.NEW_COMMENT_ON_MY_VIDEO, UserNotificationType.NEW_FOLLOW ] - await checkNotifications(servers[0].url, userToken1, notifs) + await checkNotifications(servers[0], userToken1, notifs) } { const notifs = [ UserNotificationType.COMMENT_MENTION, UserNotificationType.NEW_FOLLOW ] - await checkNotifications(servers[0].url, userToken2, notifs) + await checkNotifications(servers[0], userToken2, notifs) } }) @@ -241,8 +236,8 @@ describe('Test blocklist', function () { }) it('Should not have notifications from this account', async function () { - await checkNotifications(servers[0].url, userToken1, []) - await checkNotifications(servers[0].url, userToken2, []) + await checkNotifications(servers[0], userToken1, []) + await checkNotifications(servers[0], userToken2, []) }) }) diff --git a/server/tests/api/moderation/blocklist.ts b/server/tests/api/moderation/blocklist.ts index 00cb6c65c..44e3de4e4 100644 --- a/server/tests/api/moderation/blocklist.ts +++ b/server/tests/api/moderation/blocklist.ts @@ -9,7 +9,6 @@ import { createUser, doubleFollow, flushAndRunMultipleServers, - getUserNotifications, getVideosList, getVideosListWithToken, ServerInfo, @@ -18,7 +17,7 @@ import { userLogin, waitJobs } from '@shared/extra-utils' -import { UserNotification, UserNotificationType, Video } from '@shared/models' +import { UserNotificationType, Video } from '@shared/models' const expect = chai.expect @@ -59,9 +58,8 @@ async function checkCommentNotification ( await waitJobs([ mainServer, comment.server ]) - const res = await getUserNotifications(mainServer.url, mainServer.accessToken, 0, 30) - const commentNotifications = (res.body.data as UserNotification[]) - .filter(n => n.comment && n.comment.video.uuid === comment.videoUUID && n.createdAt >= createdAt) + const { data } = await mainServer.notificationsCommand.list({ start: 0, count: 30 }) + const commentNotifications = data.filter(n => n.comment && n.comment.video.uuid === comment.videoUUID && n.createdAt >= createdAt) if (check === 'presence') expect(commentNotifications).to.have.lengthOf(1) else expect(commentNotifications).to.have.lengthOf(0) @@ -710,12 +708,10 @@ describe('Test blocklist', function () { await waitJobs(servers) - const res = await getUserNotifications(servers[0].url, servers[0].accessToken, 0, 30) - const commentNotifications = (res.body.data as UserNotification[]) - .filter(n => { - return n.type === UserNotificationType.NEW_INSTANCE_FOLLOWER && - n.createdAt >= now.toISOString() - }) + const { data } = await servers[0].notificationsCommand.list({ start: 0, count: 30 }) + const commentNotifications = data.filter(n => { + return n.type === UserNotificationType.NEW_INSTANCE_FOLLOWER && n.createdAt >= now.toISOString() + }) expect(commentNotifications).to.have.lengthOf(0) } @@ -773,12 +769,10 @@ describe('Test blocklist', function () { await waitJobs(servers) - const res = await getUserNotifications(servers[0].url, servers[0].accessToken, 0, 30) - const commentNotifications = (res.body.data as UserNotification[]) - .filter(n => { - return n.type === UserNotificationType.NEW_INSTANCE_FOLLOWER && - n.createdAt >= now.toISOString() - }) + const { data } = await servers[0].notificationsCommand.list({ start: 0, count: 30 }) + const commentNotifications = data.filter(n => { + return n.type === UserNotificationType.NEW_INSTANCE_FOLLOWER && n.createdAt >= now.toISOString() + }) expect(commentNotifications).to.have.lengthOf(1) } diff --git a/server/tests/api/notifications/notifications-api.ts b/server/tests/api/notifications/notifications-api.ts index 1ed98ae7a..447492c5f 100644 --- a/server/tests/api/notifications/notifications-api.ts +++ b/server/tests/api/notifications/notifications-api.ts @@ -8,14 +8,10 @@ import { cleanupTests, getAllNotificationsSettings, getMyUserInformation, - getUserNotifications, immutableAssign, - markAsReadAllNotifications, - markAsReadNotifications, MockSmtpServer, prepareNotificationsTest, ServerInfo, - updateMyNotificationSettings, uploadRandomVideo, waitJobs } from '@shared/extra-utils' @@ -26,7 +22,7 @@ const expect = chai.expect describe('Test notifications API', function () { let server: ServerInfo let userNotifications: UserNotification[] = [] - let userAccessToken: string + let userToken: string let emails: object[] = [] before(async function () { @@ -34,11 +30,11 @@ describe('Test notifications API', function () { const res = await prepareNotificationsTest(1) emails = res.emails - userAccessToken = res.userAccessToken + userToken = res.userAccessToken userNotifications = res.userNotifications server = res.servers[0] - await server.subscriptionsCommand.add({ token: userAccessToken, targetUri: 'root_channel@localhost:' + server.port }) + await server.subscriptionsCommand.add({ token: userToken, targetUri: 'root_channel@localhost:' + server.port }) for (let i = 0; i < 10; i++) { await uploadRandomVideo(server, false) @@ -50,49 +46,46 @@ describe('Test notifications API', function () { describe('Mark as read', function () { it('Should mark as read some notifications', async function () { - const res = await getUserNotifications(server.url, userAccessToken, 2, 3) - const ids = res.body.data.map(n => n.id) + const { data } = await server.notificationsCommand.list({ token: userToken, start: 2, count: 3 }) + const ids = data.map(n => n.id) - await markAsReadNotifications(server.url, userAccessToken, ids) + await server.notificationsCommand.markAsRead({ token: userToken, ids }) }) it('Should have the notifications marked as read', async function () { - const res = await getUserNotifications(server.url, userAccessToken, 0, 10) - - const notifications = res.body.data as UserNotification[] - expect(notifications[0].read).to.be.false - expect(notifications[1].read).to.be.false - expect(notifications[2].read).to.be.true - expect(notifications[3].read).to.be.true - expect(notifications[4].read).to.be.true - expect(notifications[5].read).to.be.false + const { data } = await server.notificationsCommand.list({ token: userToken, start: 0, count: 10 }) + + expect(data[0].read).to.be.false + expect(data[1].read).to.be.false + expect(data[2].read).to.be.true + expect(data[3].read).to.be.true + expect(data[4].read).to.be.true + expect(data[5].read).to.be.false }) it('Should only list read notifications', async function () { - const res = await getUserNotifications(server.url, userAccessToken, 0, 10, false) + const { data } = await server.notificationsCommand.list({ token: userToken, start: 0, count: 10, unread: false }) - const notifications = res.body.data as UserNotification[] - for (const notification of notifications) { + for (const notification of data) { expect(notification.read).to.be.true } }) it('Should only list unread notifications', async function () { - const res = await getUserNotifications(server.url, userAccessToken, 0, 10, true) + const { data } = await server.notificationsCommand.list({ token: userToken, start: 0, count: 10, unread: true }) - const notifications = res.body.data as UserNotification[] - for (const notification of notifications) { + for (const notification of data) { expect(notification.read).to.be.false } }) it('Should mark as read all notifications', async function () { - await markAsReadAllNotifications(server.url, userAccessToken) + await server.notificationsCommand.markAsReadAll({ token: userToken }) - const res = await getUserNotifications(server.url, userAccessToken, 0, 10, true) + const body = await server.notificationsCommand.list({ token: userToken, start: 0, count: 10, unread: true }) - expect(res.body.total).to.equal(0) - expect(res.body.data).to.have.lengthOf(0) + expect(body.total).to.equal(0) + expect(body.data).to.have.lengthOf(0) }) }) @@ -104,19 +97,20 @@ describe('Test notifications API', function () { server: server, emails, socketNotifications: userNotifications, - token: userAccessToken + token: userToken } }) it('Should not have notifications', async function () { this.timeout(20000) - await updateMyNotificationSettings(server.url, userAccessToken, immutableAssign(getAllNotificationsSettings(), { - newVideoFromSubscription: UserNotificationSettingValue.NONE - })) + await server.notificationsCommand.updateMySettings({ + token: userToken, + settings: { ...getAllNotificationsSettings(), newVideoFromSubscription: UserNotificationSettingValue.NONE } + }) { - const res = await getMyUserInformation(server.url, userAccessToken) + const res = await getMyUserInformation(server.url, userToken) const info = res.body as User expect(info.notificationSettings.newVideoFromSubscription).to.equal(UserNotificationSettingValue.NONE) } @@ -130,12 +124,13 @@ describe('Test notifications API', function () { it('Should only have web notifications', async function () { this.timeout(20000) - await updateMyNotificationSettings(server.url, userAccessToken, immutableAssign(getAllNotificationsSettings(), { - newVideoFromSubscription: UserNotificationSettingValue.WEB - })) + await server.notificationsCommand.updateMySettings({ + token: userToken, + settings: { ...getAllNotificationsSettings(), newVideoFromSubscription: UserNotificationSettingValue.WEB } + }) { - const res = await getMyUserInformation(server.url, userAccessToken) + const res = await getMyUserInformation(server.url, userToken) const info = res.body as User expect(info.notificationSettings.newVideoFromSubscription).to.equal(UserNotificationSettingValue.WEB) } @@ -156,12 +151,13 @@ describe('Test notifications API', function () { it('Should only have mail notifications', async function () { this.timeout(20000) - await updateMyNotificationSettings(server.url, userAccessToken, immutableAssign(getAllNotificationsSettings(), { - newVideoFromSubscription: UserNotificationSettingValue.EMAIL - })) + await server.notificationsCommand.updateMySettings({ + token: userToken, + settings: { ...getAllNotificationsSettings(), newVideoFromSubscription: UserNotificationSettingValue.EMAIL } + }) { - const res = await getMyUserInformation(server.url, userAccessToken) + const res = await getMyUserInformation(server.url, userToken) const info = res.body as User expect(info.notificationSettings.newVideoFromSubscription).to.equal(UserNotificationSettingValue.EMAIL) } @@ -182,12 +178,16 @@ describe('Test notifications API', function () { it('Should have email and web notifications', async function () { this.timeout(20000) - await updateMyNotificationSettings(server.url, userAccessToken, immutableAssign(getAllNotificationsSettings(), { - newVideoFromSubscription: UserNotificationSettingValue.WEB | UserNotificationSettingValue.EMAIL - })) + await server.notificationsCommand.updateMySettings({ + token: userToken, + settings: { + ...getAllNotificationsSettings(), + newVideoFromSubscription: UserNotificationSettingValue.WEB | UserNotificationSettingValue.EMAIL + } + }) { - const res = await getMyUserInformation(server.url, userAccessToken) + const res = await getMyUserInformation(server.url, userToken) const info = res.body as User expect(info.notificationSettings.newVideoFromSubscription).to.equal( UserNotificationSettingValue.WEB | UserNotificationSettingValue.EMAIL diff --git a/server/tests/api/notifications/user-notifications.ts b/server/tests/api/notifications/user-notifications.ts index 1d159c48f..4b31edf25 100644 --- a/server/tests/api/notifications/user-notifications.ts +++ b/server/tests/api/notifications/user-notifications.ts @@ -10,7 +10,6 @@ import { checkNewVideoFromSubscription, checkVideoIsPublished, cleanupTests, - getLastNotification, ImportsCommand, MockSmtpServer, prepareNotificationsTest, @@ -64,7 +63,7 @@ describe('Test user notifications', function () { await uploadRandomVideoOnServers(servers, 1) - const notification = await getLastNotification(servers[0].url, userAccessToken) + const notification = await servers[0].notificationsCommand.getLastest({ token: userAccessToken }) expect(notification).to.be.undefined expect(emails).to.have.lengthOf(0) @@ -245,7 +244,7 @@ describe('Test user notifications', function () { await uploadRandomVideoOnServers(servers, 2, { waitTranscoding: false }) await waitJobs(servers) - const notification = await getLastNotification(servers[0].url, userAccessToken) + const notification = await servers[0].notificationsCommand.getLastest({ token: userAccessToken }) if (notification) { expect(notification.type).to.not.equal(UserNotificationType.MY_VIDEO_PUBLISHED) } diff --git a/server/tests/api/server/plugins.ts b/server/tests/api/server/plugins.ts index 655cf00fa..d4a43276f 100644 --- a/server/tests/api/server/plugins.ts +++ b/server/tests/api/server/plugins.ts @@ -146,13 +146,12 @@ describe('Test plugins', function () { } { - const body = await command.list({ + const { data } = await command.list({ count: 2, start: 0, sort: 'name' }) - const data = body expect(data[0].name).to.equal('background-red') expect(data[1].name).to.equal('hello-world') } diff --git a/server/tests/api/videos/video-hls.ts b/server/tests/api/videos/video-hls.ts index 3dd8c9066..428e1316d 100644 --- a/server/tests/api/videos/video-hls.ts +++ b/server/tests/api/videos/video-hls.ts @@ -109,6 +109,7 @@ describe('Test HLS videos', function () { let videoAudioUUID = '' function runTestSuite (hlsOnly: boolean) { + it('Should upload a video and transcode it to HLS', async function () { this.timeout(120000) diff --git a/server/tests/api/videos/video-nsfw.ts b/server/tests/api/videos/video-nsfw.ts index 65813517d..5f30939cc 100644 --- a/server/tests/api/videos/video-nsfw.ts +++ b/server/tests/api/videos/video-nsfw.ts @@ -18,13 +18,13 @@ import { uploadVideo, userLogin } from '@shared/extra-utils' -import { BooleanBothQuery, CustomConfig, User, VideosOverview } from '@shared/models' +import { BooleanBothQuery, CustomConfig, ResultList, User, Video, VideosOverview } from '@shared/models' const expect = chai.expect function createOverviewRes (overview: VideosOverview) { const videos = overview.categories[0].videos - return { body: { data: videos, total: videos.length } } + return { data: videos, total: videos.length } } describe('Test video NSFW policy', function () { @@ -32,49 +32,47 @@ describe('Test video NSFW policy', function () { let userAccessToken: string let customConfig: CustomConfig - function getVideosFunctions (token?: string, query: { nsfw?: BooleanBothQuery } = {}) { - return getMyUserInformation(server.url, server.accessToken) - .then(res => { - const user: User = res.body - const videoChannelName = user.videoChannels[0].name - const accountName = user.account.name + '@' + user.account.host - const hasQuery = Object.keys(query).length !== 0 - let promises: Promise[] - - if (token) { - promises = [ - getVideosListWithToken(server.url, token, query), - server.searchCommand.advancedVideoSearch({ token, search: { search: 'n', ...query } }), - getAccountVideos(server.url, token, accountName, 0, 5, undefined, query), - getVideoChannelVideos(server.url, token, videoChannelName, 0, 5, undefined, query) - ] - - // Overviews do not support video filters - if (!hasQuery) { - const p = server.overviewsCommand.getVideos({ page: 1, token }) - .then(res => createOverviewRes(res)) - promises.push(p) - } - - return Promise.all(promises) - } - - promises = [ - getVideosList(server.url), - server.searchCommand.searchVideos({ search: 'n' }), - getAccountVideos(server.url, undefined, accountName, 0, 5), - getVideoChannelVideos(server.url, undefined, videoChannelName, 0, 5) - ] - - // Overviews do not support video filters - if (!hasQuery) { - const p = server.overviewsCommand.getVideos({ page: 1 }) - .then(res => createOverviewRes(res)) - promises.push(p) - } - - return Promise.all(promises) - }) + async function getVideosFunctions (token?: string, query: { nsfw?: BooleanBothQuery } = {}) { + const res = await getMyUserInformation(server.url, server.accessToken) + const user: User = res.body + const videoChannelName = user.videoChannels[0].name + const accountName = user.account.name + '@' + user.account.host + const hasQuery = Object.keys(query).length !== 0 + let promises: Promise>[] + + if (token) { + promises = [ + getVideosListWithToken(server.url, token, query).then(res => res.body), + server.searchCommand.advancedVideoSearch({ token, search: { search: 'n', ...query } }), + getAccountVideos(server.url, token, accountName, 0, 5, undefined, query).then(res => res.body), + getVideoChannelVideos(server.url, token, videoChannelName, 0, 5, undefined, query).then(res => res.body) + ] + + // Overviews do not support video filters + if (!hasQuery) { + const p = server.overviewsCommand.getVideos({ page: 1, token }) + .then(res => createOverviewRes(res)) + promises.push(p) + } + + return Promise.all(promises) + } + + promises = [ + getVideosList(server.url).then(res => res.body), + server.searchCommand.searchVideos({ search: 'n' }), + getAccountVideos(server.url, undefined, accountName, 0, 5).then(res => res.body), + getVideoChannelVideos(server.url, undefined, videoChannelName, 0, 5).then(res => res.body) + ] + + // Overviews do not support video filters + if (!hasQuery) { + const p = server.overviewsCommand.getVideos({ page: 1 }) + .then(res => createOverviewRes(res)) + promises.push(p) + } + + return Promise.all(promises) } before(async function () { @@ -102,10 +100,10 @@ describe('Test video NSFW policy', function () { const serverConfig = await server.configCommand.getConfig() expect(serverConfig.instance.defaultNSFWPolicy).to.equal('display') - for (const res of await getVideosFunctions()) { - expect(res.body.total).to.equal(2) + for (const body of await getVideosFunctions()) { + expect(body.total).to.equal(2) - const videos = res.body.data + const videos = body.data expect(videos).to.have.lengthOf(2) expect(videos[0].name).to.equal('normal') expect(videos[1].name).to.equal('nsfw') @@ -119,10 +117,10 @@ describe('Test video NSFW policy', function () { const serverConfig = await server.configCommand.getConfig() expect(serverConfig.instance.defaultNSFWPolicy).to.equal('do_not_list') - for (const res of await getVideosFunctions()) { - expect(res.body.total).to.equal(1) + for (const body of await getVideosFunctions()) { + expect(body.total).to.equal(1) - const videos = res.body.data + const videos = body.data expect(videos).to.have.lengthOf(1) expect(videos[0].name).to.equal('normal') } @@ -135,10 +133,10 @@ describe('Test video NSFW policy', function () { const serverConfig = await server.configCommand.getConfig() expect(serverConfig.instance.defaultNSFWPolicy).to.equal('blur') - for (const res of await getVideosFunctions()) { - expect(res.body.total).to.equal(2) + for (const body of await getVideosFunctions()) { + expect(body.total).to.equal(2) - const videos = res.body.data + const videos = body.data expect(videos).to.have.lengthOf(2) expect(videos[0].name).to.equal('normal') expect(videos[1].name).to.equal('nsfw') @@ -165,10 +163,10 @@ describe('Test video NSFW policy', function () { customConfig.instance.defaultNSFWPolicy = 'do_not_list' await server.configCommand.updateCustomConfig({ newCustomConfig: customConfig }) - for (const res of await getVideosFunctions(userAccessToken)) { - expect(res.body.total).to.equal(2) + for (const body of await getVideosFunctions(userAccessToken)) { + expect(body.total).to.equal(2) - const videos = res.body.data + const videos = body.data expect(videos).to.have.lengthOf(2) expect(videos[0].name).to.equal('normal') expect(videos[1].name).to.equal('nsfw') @@ -182,10 +180,10 @@ describe('Test video NSFW policy', function () { nsfwPolicy: 'display' }) - for (const res of await getVideosFunctions(server.accessToken)) { - expect(res.body.total).to.equal(2) + for (const body of await getVideosFunctions(server.accessToken)) { + expect(body.total).to.equal(2) - const videos = res.body.data + const videos = body.data expect(videos).to.have.lengthOf(2) expect(videos[0].name).to.equal('normal') expect(videos[1].name).to.equal('nsfw') @@ -199,10 +197,10 @@ describe('Test video NSFW policy', function () { nsfwPolicy: 'do_not_list' }) - for (const res of await getVideosFunctions(server.accessToken)) { - expect(res.body.total).to.equal(1) + for (const body of await getVideosFunctions(server.accessToken)) { + expect(body.total).to.equal(1) - const videos = res.body.data + const videos = body.data expect(videos).to.have.lengthOf(1) expect(videos[0].name).to.equal('normal') } @@ -219,30 +217,30 @@ describe('Test video NSFW policy', function () { }) it('Should display NSFW videos when the nsfw param === true', async function () { - for (const res of await getVideosFunctions(server.accessToken, { nsfw: 'true' })) { - expect(res.body.total).to.equal(1) + for (const body of await getVideosFunctions(server.accessToken, { nsfw: 'true' })) { + expect(body.total).to.equal(1) - const videos = res.body.data + const videos = body.data expect(videos).to.have.lengthOf(1) expect(videos[0].name).to.equal('nsfw') } }) it('Should hide NSFW videos when the nsfw param === true', async function () { - for (const res of await getVideosFunctions(server.accessToken, { nsfw: 'false' })) { - expect(res.body.total).to.equal(1) + for (const body of await getVideosFunctions(server.accessToken, { nsfw: 'false' })) { + expect(body.total).to.equal(1) - const videos = res.body.data + const videos = body.data expect(videos).to.have.lengthOf(1) expect(videos[0].name).to.equal('normal') } }) it('Should display both videos when the nsfw param === both', async function () { - for (const res of await getVideosFunctions(server.accessToken, { nsfw: 'both' })) { - expect(res.body.total).to.equal(2) + for (const body of await getVideosFunctions(server.accessToken, { nsfw: 'both' })) { + expect(body.total).to.equal(2) - const videos = res.body.data + const videos = body.data expect(videos).to.have.lengthOf(2) expect(videos[0].name).to.equal('normal') expect(videos[1].name).to.equal('nsfw') -- cgit v1.2.3 From 0d8ecb7592577f54012413a2b5a9b159cfc90399 Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Tue, 13 Jul 2021 08:33:02 +0200 Subject: Fix NSFW tests --- server/tests/api/videos/multiple-servers.ts | 1 + server/tests/api/videos/video-nsfw.ts | 4 ++-- 2 files changed, 3 insertions(+), 2 deletions(-) (limited to 'server/tests/api') diff --git a/server/tests/api/videos/multiple-servers.ts b/server/tests/api/videos/multiple-servers.ts index 2148d8e1c..1b6f0f48a 100644 --- a/server/tests/api/videos/multiple-servers.ts +++ b/server/tests/api/videos/multiple-servers.ts @@ -582,6 +582,7 @@ describe('Test multiple servers', function () { await waitJobs(servers) await wait(5000) + await waitJobs(servers) let baseVideos = null for (const server of servers) { diff --git a/server/tests/api/videos/video-nsfw.ts b/server/tests/api/videos/video-nsfw.ts index 5f30939cc..c9c3792eb 100644 --- a/server/tests/api/videos/video-nsfw.ts +++ b/server/tests/api/videos/video-nsfw.ts @@ -43,7 +43,7 @@ describe('Test video NSFW policy', function () { if (token) { promises = [ getVideosListWithToken(server.url, token, query).then(res => res.body), - server.searchCommand.advancedVideoSearch({ token, search: { search: 'n', ...query } }), + server.searchCommand.advancedVideoSearch({ token, search: { search: 'n', sort: '-publishedAt', ...query } }), getAccountVideos(server.url, token, accountName, 0, 5, undefined, query).then(res => res.body), getVideoChannelVideos(server.url, token, videoChannelName, 0, 5, undefined, query).then(res => res.body) ] @@ -60,7 +60,7 @@ describe('Test video NSFW policy', function () { promises = [ getVideosList(server.url).then(res => res.body), - server.searchCommand.searchVideos({ search: 'n' }), + server.searchCommand.searchVideos({ search: 'n', sort: '-publishedAt' }), getAccountVideos(server.url, undefined, accountName, 0, 5).then(res => res.body), getVideoChannelVideos(server.url, undefined, videoChannelName, 0, 5).then(res => res.body) ] -- 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/activitypub/helpers.ts | 5 +- 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 +++++++++++---------- server/tests/api/live/live.ts | 3 +- .../api/notifications/moderation-notifications.ts | 13 ++-- .../tests/api/notifications/notifications-api.ts | 11 ++-- server/tests/api/redundancy/manage-redundancy.ts | 7 +- .../tests/api/redundancy/redundancy-constraints.ts | 11 ++-- server/tests/api/redundancy/redundancy.ts | 36 +++++----- server/tests/api/search/search-index.ts | 24 +++---- server/tests/api/search/search-videos.ts | 46 +++++++------ server/tests/api/server/handle-down.ts | 9 +-- server/tests/api/server/logs.ts | 5 +- server/tests/api/server/plugins.ts | 5 +- server/tests/api/users/users-multiple-servers.ts | 2 +- server/tests/api/videos/audio-only.ts | 5 +- server/tests/api/videos/multiple-servers.ts | 4 +- server/tests/api/videos/resumable-upload.ts | 5 +- server/tests/api/videos/single-server.ts | 2 +- server/tests/api/videos/video-captions.ts | 2 +- server/tests/api/videos/video-imports.ts | 13 ++-- server/tests/api/videos/video-transcoder.ts | 22 +++---- 30 files changed, 281 insertions(+), 305 deletions(-) (limited to 'server/tests/api') diff --git a/server/tests/api/activitypub/helpers.ts b/server/tests/api/activitypub/helpers.ts index 66d7631b7..57b1cab23 100644 --- a/server/tests/api/activitypub/helpers.ts +++ b/server/tests/api/activitypub/helpers.ts @@ -2,11 +2,10 @@ import 'mocha' import { expect } from 'chai' -import { buildRequestStub } from '../../../../shared/extra-utils/miscs/stubs' -import { isHTTPSignatureVerified, isJsonLDSignatureVerified, parseHTTPSignature } from '../../../helpers/peertube-crypto' import { cloneDeep } from 'lodash' +import { buildAbsoluteFixturePath, buildRequestStub } from '@shared/extra-utils' import { buildSignedActivity } from '../../../helpers/activitypub' -import { buildAbsoluteFixturePath } from '@shared/extra-utils' +import { isHTTPSignatureVerified, isJsonLDSignatureVerified, parseHTTPSignature } from '../../../helpers/peertube-crypto' describe('Test activity pub helpers', function () { describe('When checking the Linked Signature', function () { 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 diff --git a/server/tests/api/live/live.ts b/server/tests/api/live/live.ts index f9a162df6..999a49051 100644 --- a/server/tests/api/live/live.ts +++ b/server/tests/api/live/live.ts @@ -7,7 +7,6 @@ import { ffprobePromise, getVideoStreamFromFile } from '@server/helpers/ffprobe- import { LiveVideo, LiveVideoCreate, Video, VideoDetails, VideoPrivacy, VideoState, VideoStreamingPlaylistType } from '@shared/models' import { HttpStatusCode } from '../../../../shared/core-utils/miscs/http-error-codes' import { - buildServerDirectory, checkLiveCleanup, checkLiveSegmentHash, checkResolutionsInMasterPlaylist, @@ -532,7 +531,7 @@ describe('Test live', function () { } const filename = `${video.uuid}-${resolution}-fragmented.mp4` - const segmentPath = buildServerDirectory(servers[0], join('streaming-playlists', 'hls', video.uuid, filename)) + const segmentPath = servers[0].serversCommand.buildDirectory(join('streaming-playlists', 'hls', video.uuid, filename)) const probe = await ffprobePromise(segmentPath) const videoStream = await getVideoStreamFromFile(segmentPath, probe) diff --git a/server/tests/api/notifications/moderation-notifications.ts b/server/tests/api/notifications/moderation-notifications.ts index 229f78811..99b434606 100644 --- a/server/tests/api/notifications/moderation-notifications.ts +++ b/server/tests/api/notifications/moderation-notifications.ts @@ -20,7 +20,6 @@ import { createUser, generateUserAccessToken, getVideoIdFromUUID, - immutableAssign, MockInstancesIndex, MockSmtpServer, prepareNotificationsTest, @@ -347,7 +346,7 @@ describe('Test moderation notifications', function () { await checkUserRegistered(baseParams, 'user_45', 'presence') const userOverride = { socketNotifications: userNotifications, token: userAccessToken, check: { web: true, mail: false } } - await checkUserRegistered(immutableAssign(baseParams, userOverride), 'user_45', 'absence') + await checkUserRegistered({ ...baseParams, ...userOverride }, 'user_45', 'absence') }) }) @@ -389,7 +388,7 @@ describe('Test moderation notifications', function () { await checkNewInstanceFollower(baseParams, 'localhost:' + servers[2].port, 'presence') const userOverride = { socketNotifications: userNotifications, token: userAccessToken, check: { web: true, mail: false } } - await checkNewInstanceFollower(immutableAssign(baseParams, userOverride), 'localhost:' + servers[2].port, 'absence') + await checkNewInstanceFollower({ ...baseParams, ...userOverride }, 'localhost:' + servers[2].port, 'absence') }) it('Should send a notification on auto follow back', async function () { @@ -416,7 +415,7 @@ describe('Test moderation notifications', function () { await checkAutoInstanceFollowing(baseParams, followerHost, followingHost, 'presence') const userOverride = { socketNotifications: userNotifications, token: userAccessToken, check: { web: true, mail: false } } - await checkAutoInstanceFollowing(immutableAssign(baseParams, userOverride), followerHost, followingHost, 'absence') + await checkAutoInstanceFollowing({ ...baseParams, ...userOverride }, followerHost, followingHost, 'absence') config.followings.instance.autoFollowBack.enabled = false await servers[0].configCommand.updateCustomSubConfig({ newConfig: config }) @@ -476,7 +475,9 @@ describe('Test moderation notifications', function () { currentCustomConfig = await servers[0].configCommand.getCustomConfig() - const autoBlacklistTestsCustomConfig = immutableAssign(currentCustomConfig, { + const autoBlacklistTestsCustomConfig = { + ...currentCustomConfig, + autoBlacklist: { videos: { ofUsers: { @@ -484,7 +485,7 @@ describe('Test moderation notifications', function () { } } } - }) + } // enable transcoding otherwise own publish notification after transcoding not expected autoBlacklistTestsCustomConfig.transcoding.enabled = true diff --git a/server/tests/api/notifications/notifications-api.ts b/server/tests/api/notifications/notifications-api.ts index 447492c5f..e5864f1c2 100644 --- a/server/tests/api/notifications/notifications-api.ts +++ b/server/tests/api/notifications/notifications-api.ts @@ -8,7 +8,6 @@ import { cleanupTests, getAllNotificationsSettings, getMyUserInformation, - immutableAssign, MockSmtpServer, prepareNotificationsTest, ServerInfo, @@ -118,7 +117,7 @@ describe('Test notifications API', function () { const { name, uuid } = await uploadRandomVideo(server) const check = { web: true, mail: true } - await checkNewVideoFromSubscription(immutableAssign(baseParams, { check }), name, uuid, 'absence') + await checkNewVideoFromSubscription({ ...baseParams, ...check }, name, uuid, 'absence') }) it('Should only have web notifications', async function () { @@ -139,12 +138,12 @@ describe('Test notifications API', function () { { const check = { mail: true, web: false } - await checkNewVideoFromSubscription(immutableAssign(baseParams, { check }), name, uuid, 'absence') + await checkNewVideoFromSubscription({ ...baseParams, ...check }, name, uuid, 'absence') } { const check = { mail: false, web: true } - await checkNewVideoFromSubscription(immutableAssign(baseParams, { check }), name, uuid, 'presence') + await checkNewVideoFromSubscription({ ...baseParams, ...check }, name, uuid, 'presence') } }) @@ -166,12 +165,12 @@ describe('Test notifications API', function () { { const check = { mail: false, web: true } - await checkNewVideoFromSubscription(immutableAssign(baseParams, { check }), name, uuid, 'absence') + await checkNewVideoFromSubscription({ ...baseParams, ...check }, name, uuid, 'absence') } { const check = { mail: true, web: false } - await checkNewVideoFromSubscription(immutableAssign(baseParams, { check }), name, uuid, 'presence') + await checkNewVideoFromSubscription({ ...baseParams, ...check }, name, uuid, 'presence') } }) diff --git a/server/tests/api/redundancy/manage-redundancy.ts b/server/tests/api/redundancy/manage-redundancy.ts index 363e4cbfe..03857f512 100644 --- a/server/tests/api/redundancy/manage-redundancy.ts +++ b/server/tests/api/redundancy/manage-redundancy.ts @@ -12,8 +12,7 @@ import { setAccessTokensToServers, uploadVideo, uploadVideoAndGetId, - waitJobs, - waitUntilLog + waitJobs } from '@shared/extra-utils' import { VideoPrivacy, VideoRedundanciesTarget } from '@shared/models' @@ -91,7 +90,7 @@ describe('Test manage videos redundancy', function () { this.timeout(120000) await waitJobs(servers) - await waitUntilLog(servers[0], 'Duplicated ', 10) + await servers[0].serversCommand.waitUntilLog('Duplicated ', 10) await waitJobs(servers) const body = await commands[1].listVideos({ target: 'remote-videos' }) @@ -214,7 +213,7 @@ describe('Test manage videos redundancy', function () { await commands[0].addVideo({ videoId }) await waitJobs(servers) - await waitUntilLog(servers[0], 'Duplicated ', 15) + await servers[0].serversCommand.waitUntilLog('Duplicated ', 15) await waitJobs(servers) { diff --git a/server/tests/api/redundancy/redundancy-constraints.ts b/server/tests/api/redundancy/redundancy-constraints.ts index 82d952471..a31278de7 100644 --- a/server/tests/api/redundancy/redundancy-constraints.ts +++ b/server/tests/api/redundancy/redundancy-constraints.ts @@ -11,8 +11,7 @@ import { setAccessTokensToServers, updateVideo, uploadVideo, - waitJobs, - waitUntilLog + waitJobs } from '@shared/extra-utils' import { VideoPrivacy } from '@shared/models' @@ -97,7 +96,7 @@ describe('Test redundancy constraints', function () { this.timeout(120000) await waitJobs(servers) - await waitUntilLog(remoteServer, 'Duplicated ', 5) + await remoteServer.serversCommand.waitUntilLog('Duplicated ', 5) await waitJobs(servers) { @@ -126,7 +125,7 @@ describe('Test redundancy constraints', function () { await uploadWrapper('video 2 server 2') - await waitUntilLog(remoteServer, 'Duplicated ', 10) + await remoteServer.serversCommand.waitUntilLog('Duplicated ', 10) await waitJobs(servers) { @@ -155,7 +154,7 @@ describe('Test redundancy constraints', function () { await uploadWrapper('video 3 server 2') - await waitUntilLog(remoteServer, 'Duplicated ', 15) + await remoteServer.serversCommand.waitUntilLog('Duplicated ', 15) await waitJobs(servers) { @@ -176,7 +175,7 @@ describe('Test redundancy constraints', function () { await waitJobs(servers) await uploadWrapper('video 4 server 2') - await waitUntilLog(remoteServer, 'Duplicated ', 20) + await remoteServer.serversCommand.waitUntilLog('Duplicated ', 20) await waitJobs(servers) { diff --git a/server/tests/api/redundancy/redundancy.ts b/server/tests/api/redundancy/redundancy.ts index 56a2af395..00a5e86cc 100644 --- a/server/tests/api/redundancy/redundancy.ts +++ b/server/tests/api/redundancy/redundancy.ts @@ -14,7 +14,6 @@ import { flushAndRunMultipleServers, getVideo, getVideoWithToken, - immutableAssign, killallServers, makeGetRequest, removeVideo, @@ -26,8 +25,7 @@ import { uploadVideo, viewVideo, wait, - waitJobs, - waitUntilLog + waitJobs } from '@shared/extra-utils' import { VideoDetails, VideoPrivacy, VideoRedundancyStrategy, VideoRedundancyStrategyWithManual } from '@shared/models' @@ -53,11 +51,13 @@ async function flushAndRunServers (strategy: VideoRedundancyStrategy | null, add if (strategy !== null) { strategies.push( - immutableAssign({ + { min_lifetime: '1 hour', strategy: strategy, - size: '400KB' - }, additionalParams) + size: '400KB', + + ...additionalParams + } ) } @@ -316,7 +316,7 @@ describe('Test videos redundancy', function () { this.timeout(80000) await waitJobs(servers) - await waitUntilLog(servers[0], 'Duplicated ', 5) + await servers[0].serversCommand.waitUntilLog('Duplicated ', 5) await waitJobs(servers) await check2Webseeds() @@ -335,7 +335,7 @@ describe('Test videos redundancy', function () { await check1WebSeed() await check0PlaylistRedundancies() - await checkVideoFilesWereRemoved(video1Server2UUID, servers[0].internalServerNumber, [ 'videos', join('playlists', 'hls') ]) + await checkVideoFilesWereRemoved(video1Server2UUID, servers[0], [ 'videos', join('playlists', 'hls') ]) }) after(async function () { @@ -366,7 +366,7 @@ describe('Test videos redundancy', function () { this.timeout(80000) await waitJobs(servers) - await waitUntilLog(servers[0], 'Duplicated ', 5) + await servers[0].serversCommand.waitUntilLog('Duplicated ', 5) await waitJobs(servers) await check2Webseeds() @@ -385,7 +385,7 @@ describe('Test videos redundancy', function () { await check1WebSeed() await check0PlaylistRedundancies() - await checkVideoFilesWereRemoved(video1Server2UUID, servers[0].internalServerNumber, [ 'videos' ]) + await checkVideoFilesWereRemoved(video1Server2UUID, servers[0], [ 'videos' ]) }) after(async function () { @@ -438,7 +438,7 @@ describe('Test videos redundancy', function () { this.timeout(80000) await waitJobs(servers) - await waitUntilLog(servers[0], 'Duplicated ', 5) + await servers[0].serversCommand.waitUntilLog('Duplicated ', 5) await waitJobs(servers) await check2Webseeds() @@ -454,7 +454,7 @@ describe('Test videos redundancy', function () { await waitJobs(servers) for (const server of servers) { - await checkVideoFilesWereRemoved(video1Server2UUID, server.internalServerNumber) + await checkVideoFilesWereRemoved(video1Server2UUID, server) } }) @@ -502,7 +502,7 @@ describe('Test videos redundancy', function () { await waitJobs(servers) await waitJobs(servers) - await waitUntilLog(servers[0], 'Duplicated ', 1) + await servers[0].serversCommand.waitUntilLog('Duplicated ', 1) await waitJobs(servers) await check1PlaylistRedundancies() @@ -517,7 +517,7 @@ describe('Test videos redundancy', function () { await waitJobs(servers) for (const server of servers) { - await checkVideoFilesWereRemoved(video1Server2UUID, server.internalServerNumber) + await checkVideoFilesWereRemoved(video1Server2UUID, server) } }) @@ -547,7 +547,7 @@ describe('Test videos redundancy', function () { this.timeout(80000) await waitJobs(servers) - await waitUntilLog(servers[0], 'Duplicated ', 5) + await servers[0].serversCommand.waitUntilLog('Duplicated ', 5) await waitJobs(servers) await check2Webseeds() @@ -575,7 +575,7 @@ describe('Test videos redundancy', function () { await check1WebSeed() await check0PlaylistRedundancies() - await checkVideoFilesWereRemoved(video1Server2UUID, servers[0].serverNumber, [ 'videos' ]) + await checkVideoFilesWereRemoved(video1Server2UUID, servers[0], [ 'videos' ]) }) after(async function () { @@ -658,7 +658,7 @@ describe('Test videos redundancy', function () { await enableRedundancyOnServer1() await waitJobs(servers) - await waitUntilLog(servers[0], 'Duplicated ', 5) + await servers[0].serversCommand.waitUntilLog('Duplicated ', 5) await waitJobs(servers) await check2Webseeds(video1Server2UUID) @@ -715,7 +715,7 @@ describe('Test videos redundancy', function () { await waitJobs(servers) - await checkVideoFilesWereRemoved(video1Server2UUID, servers[0].internalServerNumber, [ join('redundancy', 'hls') ]) + await checkVideoFilesWereRemoved(video1Server2UUID, servers[0], [ join('redundancy', 'hls') ]) }) after(async function () { diff --git a/server/tests/api/search/search-index.ts b/server/tests/api/search/search-index.ts index e4c5f5796..306f84c3a 100644 --- a/server/tests/api/search/search-index.ts +++ b/server/tests/api/search/search-index.ts @@ -2,16 +2,8 @@ import 'mocha' import * as chai from 'chai' -import { - cleanupTests, - flushAndRunServer, - immutableAssign, - SearchCommand, - ServerInfo, - setAccessTokensToServers, - uploadVideo -} from '@shared/extra-utils' -import { VideoPlaylistPrivacy, VideoPlaylistType, VideosSearchQuery } from '@shared/models' +import { cleanupTests, flushAndRunServer, SearchCommand, ServerInfo, setAccessTokensToServers, uploadVideo } from '@shared/extra-utils' +import { BooleanBothQuery, VideoPlaylistPrivacy, VideoPlaylistType, VideosSearchQuery } from '@shared/models' const expect = chai.expect @@ -174,32 +166,32 @@ describe('Test videos search', function () { } { - const search = immutableAssign(baseSearch, { startDate: '2018-10-01T10:54:46.396Z' }) + const search = { ...baseSearch, startDate: '2018-10-01T10:54:46.396Z' } await check(search, false) } { - const search = immutableAssign(baseSearch, { tagsAllOf: [ 'toto', 'framasoft' ] }) + const search = { ...baseSearch, tagsAllOf: [ 'toto', 'framasoft' ] } await check(search, false) } { - const search = immutableAssign(baseSearch, { durationMin: 2000 }) + const search = { ...baseSearch, durationMin: 2000 } await check(search, false) } { - const search = immutableAssign(baseSearch, { nsfw: 'true' }) + const search = { ...baseSearch, nsfw: 'true' as BooleanBothQuery } await check(search, false) } { - const search = immutableAssign(baseSearch, { nsfw: 'false' }) + const search = { ...baseSearch, nsfw: 'false' as BooleanBothQuery } await check(search, true) } { - const search = immutableAssign(baseSearch, { nsfw: 'both' }) + const search = { ...baseSearch, nsfw: 'both' as BooleanBothQuery } await check(search, true) } }) diff --git a/server/tests/api/search/search-videos.ts b/server/tests/api/search/search-videos.ts index 513538917..66f5f3182 100644 --- a/server/tests/api/search/search-videos.ts +++ b/server/tests/api/search/search-videos.ts @@ -5,7 +5,6 @@ import * as chai from 'chai' import { cleanupTests, flushAndRunServer, - immutableAssign, SearchCommand, ServerInfo, setAccessTokensToServers, @@ -44,11 +43,11 @@ describe('Test videos search', function () { } await uploadVideo(server.url, server.accessToken, attributes1) - const attributes2 = immutableAssign(attributes1, { name: attributes1.name + ' - 2', fixture: 'video_short.mp4' }) + const attributes2 = { ...attributes1, name: attributes1.name + ' - 2', fixture: 'video_short.mp4' } await uploadVideo(server.url, server.accessToken, attributes2) { - const attributes3 = immutableAssign(attributes1, { name: attributes1.name + ' - 3', language: undefined }) + const attributes3 = { ...attributes1, name: attributes1.name + ' - 3', language: undefined } const res = await uploadVideo(server.url, server.accessToken, attributes3) const videoId = res.body.video.id videoUUID = res.body.video.uuid @@ -68,26 +67,23 @@ describe('Test videos search', function () { }) } - const attributes4 = immutableAssign(attributes1, { name: attributes1.name + ' - 4', language: 'pl', nsfw: true }) + const attributes4 = { ...attributes1, name: attributes1.name + ' - 4', language: 'pl', nsfw: true } await uploadVideo(server.url, server.accessToken, attributes4) await wait(1000) startDate = new Date().toISOString() - const attributes5 = immutableAssign(attributes1, { name: attributes1.name + ' - 5', licence: 2, language: undefined }) + const attributes5 = { ...attributes1, name: attributes1.name + ' - 5', licence: 2, language: undefined } await uploadVideo(server.url, server.accessToken, attributes5) - const attributes6 = immutableAssign(attributes1, { name: attributes1.name + ' - 6', tags: [ 't1', 't2' ] }) + const attributes6 = { ...attributes1, name: attributes1.name + ' - 6', tags: [ 't1', 't2' ] } await uploadVideo(server.url, server.accessToken, attributes6) - const attributes7 = immutableAssign(attributes1, { - name: attributes1.name + ' - 7', - originallyPublishedAt: '2019-02-12T09:58:08.286Z' - }) + const attributes7 = { ...attributes1, name: attributes1.name + ' - 7', originallyPublishedAt: '2019-02-12T09:58:08.286Z' } await uploadVideo(server.url, server.accessToken, attributes7) - const attributes8 = immutableAssign(attributes1, { name: attributes1.name + ' - 8', licence: 4 }) + const attributes8 = { ...attributes1, name: attributes1.name + ' - 8', licence: 4 } await uploadVideo(server.url, server.accessToken, attributes8) } @@ -101,7 +97,7 @@ describe('Test videos search', function () { } await uploadVideo(server.url, server.accessToken, attributes) - await uploadVideo(server.url, server.accessToken, immutableAssign(attributes, { name: attributes.name + ' duplicate' })) + await uploadVideo(server.url, server.accessToken, { ...attributes, name: attributes.name + ' duplicate' }) } { @@ -122,10 +118,10 @@ describe('Test videos search', function () { category: 1 } await uploadVideo(server.url, server.accessToken, attributes1) - await uploadVideo(server.url, server.accessToken, immutableAssign(attributes1, { category: 2 })) + await uploadVideo(server.url, server.accessToken, { ...attributes1, category: 2 }) - await uploadVideo(server.url, server.accessToken, immutableAssign(attributes1, { tags: [ 'cccc', 'dddd' ] })) - await uploadVideo(server.url, server.accessToken, immutableAssign(attributes1, { tags: [ 'eeee', 'ffff' ] })) + await uploadVideo(server.url, server.accessToken, { ...attributes1, tags: [ 'cccc', 'dddd' ] }) + await uploadVideo(server.url, server.accessToken, { ...attributes1, tags: [ 'eeee', 'ffff' ] }) } { @@ -134,7 +130,7 @@ describe('Test videos search', function () { category: 1 } await uploadVideo(server.url, server.accessToken, attributes1) - await uploadVideo(server.url, server.accessToken, immutableAssign(attributes1, { category: 2 })) + await uploadVideo(server.url, server.accessToken, { ...attributes1, category: 2 }) } command = server.searchCommand @@ -414,7 +410,7 @@ describe('Test videos search', function () { } { - const query = immutableAssign(baseQuery, { originallyPublishedStartDate: '2019-02-11T09:58:08.286Z' }) + const query = { ...baseQuery, originallyPublishedStartDate: '2019-02-11T09:58:08.286Z' } const body = await command.advancedVideoSearch({ search: query }) expect(body.total).to.equal(1) @@ -422,7 +418,7 @@ describe('Test videos search', function () { } { - const query = immutableAssign(baseQuery, { originallyPublishedEndDate: '2019-03-11T09:58:08.286Z' }) + const query = { ...baseQuery, originallyPublishedEndDate: '2019-03-11T09:58:08.286Z' } const body = await command.advancedVideoSearch({ search: query }) expect(body.total).to.equal(1) @@ -430,34 +426,36 @@ describe('Test videos search', function () { } { - const query = immutableAssign(baseQuery, { originallyPublishedEndDate: '2019-01-11T09:58:08.286Z' }) + const query = { ...baseQuery, originallyPublishedEndDate: '2019-01-11T09:58:08.286Z' } const body = await command.advancedVideoSearch({ search: query }) expect(body.total).to.equal(0) } { - const query = immutableAssign(baseQuery, { originallyPublishedStartDate: '2019-03-11T09:58:08.286Z' }) + const query = { ...baseQuery, originallyPublishedStartDate: '2019-03-11T09:58:08.286Z' } const body = await command.advancedVideoSearch({ search: query }) expect(body.total).to.equal(0) } { - const query = immutableAssign(baseQuery, { + const query = { + ...baseQuery, originallyPublishedStartDate: '2019-01-11T09:58:08.286Z', originallyPublishedEndDate: '2019-01-10T09:58:08.286Z' - }) + } const body = await command.advancedVideoSearch({ search: query }) expect(body.total).to.equal(0) } { - const query = immutableAssign(baseQuery, { + const query = { + ...baseQuery, originallyPublishedStartDate: '2019-01-11T09:58:08.286Z', originallyPublishedEndDate: '2019-04-11T09:58:08.286Z' - }) + } const body = await command.advancedVideoSearch({ search: query }) expect(body.total).to.equal(1) diff --git a/server/tests/api/server/handle-down.ts b/server/tests/api/server/handle-down.ts index dd06acb5e..d45c3ae8a 100644 --- a/server/tests/api/server/handle-down.ts +++ b/server/tests/api/server/handle-down.ts @@ -10,7 +10,6 @@ import { flushAndRunMultipleServers, getVideo, getVideosList, - immutableAssign, killallServers, reRunServer, ServerInfo, @@ -50,9 +49,7 @@ describe('Test handle downs', function () { fixture: 'video_short1.webm' } - const unlistedVideoAttributes = immutableAssign(videoAttributes, { - privacy: VideoPrivacy.UNLISTED - }) + const unlistedVideoAttributes = { ...videoAttributes, privacy: VideoPrivacy.UNLISTED } let checkAttributes: any let unlistedCheckAttributes: any @@ -97,9 +94,7 @@ describe('Test handle downs', function () { } ] } - unlistedCheckAttributes = immutableAssign(checkAttributes, { - privacy: VideoPrivacy.UNLISTED - }) + unlistedCheckAttributes = { ...checkAttributes, privacy: VideoPrivacy.UNLISTED } // Get the access tokens await setAccessTokensToServers(servers) diff --git a/server/tests/api/server/logs.ts b/server/tests/api/server/logs.ts index 365f6cc2b..096d63e21 100644 --- a/server/tests/api/server/logs.ts +++ b/server/tests/api/server/logs.ts @@ -7,7 +7,6 @@ import { flushAndRunServer, killallServers, LogsCommand, - makePingRequest, reRunServer, ServerInfo, setAccessTokensToServers, @@ -102,7 +101,7 @@ describe('Test logs', function () { const now = new Date() - await makePingRequest(server) + await server.serversCommand.ping() const body = await logsCommand.getLogs({ startDate: now, level: 'info' }) const logsString = JSON.stringify(body) @@ -119,7 +118,7 @@ describe('Test logs', function () { const now = new Date() - await makePingRequest(server) + await server.serversCommand.ping() const body = await logsCommand.getLogs({ startDate: now, level: 'info' }) const logsString = JSON.stringify(body) diff --git a/server/tests/api/server/plugins.ts b/server/tests/api/server/plugins.ts index d4a43276f..a81ac961a 100644 --- a/server/tests/api/server/plugins.ts +++ b/server/tests/api/server/plugins.ts @@ -14,8 +14,7 @@ import { setAccessTokensToServers, testHelloWorldRegisteredSettings, updateMyUser, - wait, - waitUntilLog + wait } from '@shared/extra-utils' import { PluginType, User } from '@shared/models' @@ -194,7 +193,7 @@ describe('Test plugins', function () { it('Should have watched settings changes', async function () { this.timeout(10000) - await waitUntilLog(server, 'Settings changed!') + await server.serversCommand.waitUntilLog('Settings changed!') }) it('Should get a plugin and a theme', async function () { diff --git a/server/tests/api/users/users-multiple-servers.ts b/server/tests/api/users/users-multiple-servers.ts index 47056be78..7b650cb8f 100644 --- a/server/tests/api/users/users-multiple-servers.ts +++ b/server/tests/api/users/users-multiple-servers.ts @@ -227,7 +227,7 @@ describe('Test users with multiple servers', function () { it('Should not have video files', async () => { for (const server of servers) { - await checkVideoFilesWereRemoved(videoUUID, server.internalServerNumber) + await checkVideoFilesWereRemoved(videoUUID, server) } }) diff --git a/server/tests/api/videos/audio-only.ts b/server/tests/api/videos/audio-only.ts index 7ddbd5cd9..9b516af81 100644 --- a/server/tests/api/videos/audio-only.ts +++ b/server/tests/api/videos/audio-only.ts @@ -5,7 +5,6 @@ import * as chai from 'chai' import { join } from 'path' import { getAudioStream, getVideoStreamSize } from '@server/helpers/ffprobe-utils' import { - buildServerDirectory, cleanupTests, doubleFollow, flushAndRunMultipleServers, @@ -81,8 +80,8 @@ describe('Test audio only video transcoding', function () { it('0p transcoded video should not have video', async function () { const paths = [ - buildServerDirectory(servers[0], join('videos', videoUUID + '-0.mp4')), - buildServerDirectory(servers[0], join('streaming-playlists', 'hls', videoUUID, videoUUID + '-0-fragmented.mp4')) + servers[0].serversCommand.buildDirectory(join('videos', videoUUID + '-0.mp4')), + servers[0].serversCommand.buildDirectory(join('streaming-playlists', 'hls', videoUUID, videoUUID + '-0-fragmented.mp4')) ] for (const path of paths) { diff --git a/server/tests/api/videos/multiple-servers.ts b/server/tests/api/videos/multiple-servers.ts index 1b6f0f48a..1905aac83 100644 --- a/server/tests/api/videos/multiple-servers.ts +++ b/server/tests/api/videos/multiple-servers.ts @@ -689,8 +689,8 @@ describe('Test multiple servers', function () { it('Should not have files of videos 3 and 3-2 on each server', async function () { for (const server of servers) { - await checkVideoFilesWereRemoved(toRemove[0].uuid, server.internalServerNumber) - await checkVideoFilesWereRemoved(toRemove[1].uuid, server.internalServerNumber) + await checkVideoFilesWereRemoved(toRemove[0].uuid, server) + await checkVideoFilesWereRemoved(toRemove[1].uuid, server) } }) diff --git a/server/tests/api/videos/resumable-upload.ts b/server/tests/api/videos/resumable-upload.ts index 6c01c7e78..5845efc86 100644 --- a/server/tests/api/videos/resumable-upload.ts +++ b/server/tests/api/videos/resumable-upload.ts @@ -7,7 +7,6 @@ import { join } from 'path' import { HttpStatusCode } from '@shared/core-utils' import { buildAbsoluteFixturePath, - buildServerDirectory, cleanupTests, flushAndRunServer, getMyUserInformation, @@ -82,7 +81,7 @@ describe('Test resumable upload', function () { const uploadId = uploadIdArg.replace(/^upload_id=/, '') const subPath = join('tmp', 'resumable-uploads', uploadId) - const filePath = buildServerDirectory(server, subPath) + const filePath = server.serversCommand.buildDirectory(subPath) const exists = await pathExists(filePath) if (expectedSize === null) { @@ -97,7 +96,7 @@ describe('Test resumable upload', function () { async function countResumableUploads () { const subPath = join('tmp', 'resumable-uploads') - const filePath = buildServerDirectory(server, subPath) + const filePath = server.serversCommand.buildDirectory(subPath) const files = await readdir(filePath) return files.length diff --git a/server/tests/api/videos/single-server.ts b/server/tests/api/videos/single-server.ts index 1058a1e9c..af1703e02 100644 --- a/server/tests/api/videos/single-server.ts +++ b/server/tests/api/videos/single-server.ts @@ -230,7 +230,7 @@ describe('Test a single server', function () { it('Should remove the video', async function () { await removeVideo(server.url, server.accessToken, videoId) - await checkVideoFilesWereRemoved(videoUUID, 1) + await checkVideoFilesWereRemoved(videoUUID, server) }) it('Should not have videos', async function () { diff --git a/server/tests/api/videos/video-captions.ts b/server/tests/api/videos/video-captions.ts index 83ee809b8..d4a5385ab 100644 --- a/server/tests/api/videos/video-captions.ts +++ b/server/tests/api/videos/video-captions.ts @@ -182,7 +182,7 @@ describe('Test video captions', function () { it('Should remove the video, and thus all video captions', async function () { await removeVideo(servers[0].url, servers[0].accessToken, videoUUID) - await checkVideoFilesWereRemoved(videoUUID, 1) + await checkVideoFilesWereRemoved(videoUUID, servers[0]) }) after(async function () { diff --git a/server/tests/api/videos/video-imports.ts b/server/tests/api/videos/video-imports.ts index 4f9ecbe8e..f6ae8cab1 100644 --- a/server/tests/api/videos/video-imports.ts +++ b/server/tests/api/videos/video-imports.ts @@ -11,7 +11,6 @@ import { getMyVideos, getVideo, getVideosList, - immutableAssign, ImportsCommand, ServerInfo, setAccessTokensToServers, @@ -119,7 +118,7 @@ describe('Test video imports', function () { } { - const attributes = immutableAssign(baseAttributes, { targetUrl: ImportsCommand.getYoutubeVideoUrl() }) + const attributes = { ...baseAttributes, targetUrl: ImportsCommand.getYoutubeVideoUrl() } const { video } = await servers[0].importsCommand.importVideo({ attributes }) expect(video.name).to.equal('small video - youtube') @@ -169,21 +168,23 @@ Ajouter un sous-titre est vraiment facile`) } { - const attributes = immutableAssign(baseAttributes, { + const attributes = { + ...baseAttributes, magnetUri: ImportsCommand.getMagnetURI(), description: 'this is a super torrent description', tags: [ 'tag_torrent1', 'tag_torrent2' ] - }) + } const { video } = await servers[0].importsCommand.importVideo({ attributes }) expect(video.name).to.equal('super peertube2 video') } { - const attributes = immutableAssign(baseAttributes, { + const attributes = { + ...baseAttributes, torrentfile: 'video-720p.torrent' as any, description: 'this is a super torrent description', tags: [ 'tag_torrent1', 'tag_torrent2' ] - }) + } const { video } = await servers[0].importsCommand.importVideo({ attributes }) expect(video.name).to.equal('你好 世界 720p.mp4') } diff --git a/server/tests/api/videos/video-transcoder.ts b/server/tests/api/videos/video-transcoder.ts index e74fb5bef..f16b22bae 100644 --- a/server/tests/api/videos/video-transcoder.ts +++ b/server/tests/api/videos/video-transcoder.ts @@ -9,14 +9,12 @@ import { VIDEO_TRANSCODING_FPS } from '../../../../server/initializers/constants import { HttpStatusCode } from '../../../../shared/core-utils/miscs/http-error-codes' import { buildAbsoluteFixturePath, - buildServerDirectory, cleanupTests, doubleFollow, flushAndRunMultipleServers, generateHighBitrateVideo, generateVideoWithFramerate, getMyVideos, - getServerFileSize, getVideo, getVideoFileMetadataUrl, getVideosList, @@ -285,7 +283,7 @@ describe('Test video transcoding', function () { expect(videoDetails.files).to.have.lengthOf(4) - const path = buildServerDirectory(servers[1], join('videos', video.uuid + '-240.mp4')) + const path = servers[1].serversCommand.buildDirectory(join('videos', video.uuid + '-240.mp4')) const probe = await getAudioStream(path) if (probe.audioStream) { @@ -316,7 +314,7 @@ describe('Test video transcoding', function () { const videoDetails: VideoDetails = res2.body expect(videoDetails.files).to.have.lengthOf(4) - const path = buildServerDirectory(servers[1], join('videos', video.uuid + '-240.mp4')) + const path = servers[1].serversCommand.buildDirectory(join('videos', video.uuid + '-240.mp4')) const probe = await getAudioStream(path) expect(probe).to.not.have.property('audioStream') } @@ -344,7 +342,7 @@ describe('Test video transcoding', function () { const fixturePath = buildAbsoluteFixturePath(videoAttributes.fixture) const fixtureVideoProbe = await getAudioStream(fixturePath) - const path = buildServerDirectory(servers[1], join('videos', video.uuid + '-240.mp4')) + const path = servers[1].serversCommand.buildDirectory(join('videos', video.uuid + '-240.mp4')) const videoProbe = await getAudioStream(path) @@ -506,13 +504,13 @@ describe('Test video transcoding', function () { expect(videoDetails.files[3].fps).to.be.below(31) for (const resolution of [ '240', '360', '480' ]) { - const path = buildServerDirectory(servers[1], join('videos', video.uuid + '-' + resolution + '.mp4')) + const path = servers[1].serversCommand.buildDirectory(join('videos', video.uuid + '-' + resolution + '.mp4')) const fps = await getVideoFileFPS(path) expect(fps).to.be.below(31) } - const path = buildServerDirectory(servers[1], join('videos', video.uuid + '-720.mp4')) + const path = servers[1].serversCommand.buildDirectory(join('videos', video.uuid + '-720.mp4')) const fps = await getVideoFileFPS(path) expect(fps).to.be.above(58).and.below(62) @@ -547,13 +545,13 @@ describe('Test video transcoding', function () { const video = res.body.data.find(v => v.name === videoAttributes.name) { - const path = buildServerDirectory(servers[1], join('videos', video.uuid + '-240.mp4')) + const path = servers[1].serversCommand.buildDirectory(join('videos', video.uuid + '-240.mp4')) const fps = await getVideoFileFPS(path) expect(fps).to.be.equal(25) } { - const path = buildServerDirectory(servers[1], join('videos', video.uuid + '-720.mp4')) + const path = servers[1].serversCommand.buildDirectory(join('videos', video.uuid + '-720.mp4')) const fps = await getVideoFileFPS(path) expect(fps).to.be.equal(59) } @@ -590,7 +588,7 @@ describe('Test video transcoding', function () { const video = res.body.data.find(v => v.name === videoAttributes.name) for (const resolution of [ '240', '360', '480', '720', '1080' ]) { - const path = buildServerDirectory(servers[1], join('videos', video.uuid + '-' + resolution + '.mp4')) + const path = servers[1].serversCommand.buildDirectory(join('videos', video.uuid + '-' + resolution + '.mp4')) const bitrate = await getVideoFileBitrate(path) const fps = await getVideoFileFPS(path) @@ -636,7 +634,7 @@ describe('Test video transcoding', function () { const resolutions = [ 240, 360, 480, 720, 1080 ] for (const r of resolutions) { const path = `videos/${videoUUID}-${r}.mp4` - const size = await getServerFileSize(servers[1], path) + const size = await servers[1].serversCommand.getServerFileSize(path) expect(size, `${path} not below ${60_000}`).to.be.below(60_000) } }) @@ -651,7 +649,7 @@ describe('Test video transcoding', function () { await waitJobs(servers) { - const path = buildServerDirectory(servers[1], join('videos', videoUUID + '-240.mp4')) + const path = servers[1].serversCommand.buildDirectory(join('videos', videoUUID + '-240.mp4')) const metadata = await getMetadataFromFile(path) // expected format properties -- 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/activitypub/fetch.ts | 3 +- 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 +- .../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 +- server/tests/api/moderation/abuses.ts | 3 +- .../tests/api/moderation/blocklist-notification.ts | 7 +- server/tests/api/moderation/blocklist.ts | 7 +- server/tests/api/moderation/video-blacklist.ts | 5 +- .../search/search-activitypub-video-channels.ts | 3 +- server/tests/api/server/bulk.ts | 11 ++- server/tests/api/server/email.ts | 7 +- server/tests/api/server/follow-constraints.ts | 5 +- server/tests/api/server/follows.ts | 3 +- server/tests/api/server/reverse-proxy.ts | 23 +++--- server/tests/api/server/stats.ts | 3 +- server/tests/api/users/user-subscriptions.ts | 3 +- server/tests/api/users/users-multiple-servers.ts | 3 +- server/tests/api/users/users-verification.ts | 28 ++++--- server/tests/api/users/users.ts | 91 +++++++++++----------- server/tests/api/videos/multiple-servers.ts | 3 +- server/tests/api/videos/video-change-ownership.ts | 11 ++- server/tests/api/videos/video-channels.ts | 3 +- server/tests/api/videos/video-comments.ts | 3 +- server/tests/api/videos/video-nsfw.ts | 5 +- server/tests/api/videos/video-playlists.ts | 6 +- server/tests/api/videos/video-privacy.ts | 23 +++--- server/tests/api/videos/videos-filter.ts | 11 ++- server/tests/api/videos/videos-history.ts | 3 +- 47 files changed, 175 insertions(+), 218 deletions(-) (limited to 'server/tests/api') diff --git a/server/tests/api/activitypub/fetch.ts b/server/tests/api/activitypub/fetch.ts index d5e21404c..c1af23016 100644 --- a/server/tests/api/activitypub/fetch.ts +++ b/server/tests/api/activitypub/fetch.ts @@ -11,7 +11,6 @@ import { ServerInfo, setAccessTokensToServers, uploadVideo, - userLogin, waitJobs } from '../../../../shared/extra-utils' import { Video } from '../../../../shared/models/videos' @@ -36,7 +35,7 @@ describe('Test ActivityPub fetcher', function () { await createUser({ url: server.url, accessToken: server.accessToken, username: user.username, password: user.password }) } - const userAccessToken = await userLogin(servers[0], user) + const userAccessToken = await servers[0].loginCommand.getAccessToken(user) await uploadVideo(servers[0].url, servers[0].accessToken, { name: 'video root' }) const res = await uploadVideo(servers[0].url, servers[0].accessToken, { name: 'bad video root' }) 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 diff --git a/server/tests/api/moderation/abuses.ts b/server/tests/api/moderation/abuses.ts index e428cf1a8..d7462f38f 100644 --- a/server/tests/api/moderation/abuses.ts +++ b/server/tests/api/moderation/abuses.ts @@ -17,7 +17,6 @@ import { setAccessTokensToServers, uploadVideo, uploadVideoAndGetId, - userLogin, waitJobs } from '@shared/extra-utils' import { AbuseMessage, AbusePredefinedReasonsString, AbuseState, AdminAbuse, UserAbuse } from '@shared/models' @@ -280,7 +279,7 @@ describe('Test abuses', function () { // register a second user to have two reporters/reportees const user = { username: 'user2', password: 'password' } await createUser({ url: servers[0].url, accessToken: servers[0].accessToken, ...user }) - const userAccessToken = await userLogin(servers[0], user) + const userAccessToken = await servers[0].loginCommand.getAccessToken(user) // upload a third video via this user const video3Attributes = { diff --git a/server/tests/api/moderation/blocklist-notification.ts b/server/tests/api/moderation/blocklist-notification.ts index b676a4db4..4f2be6198 100644 --- a/server/tests/api/moderation/blocklist-notification.ts +++ b/server/tests/api/moderation/blocklist-notification.ts @@ -10,7 +10,6 @@ import { ServerInfo, setAccessTokensToServers, uploadVideo, - userLogin, waitJobs } from '@shared/extra-utils' import { UserNotificationType } from '@shared/models' @@ -86,7 +85,7 @@ describe('Test blocklist', function () { videoQuotaDaily: -1 }) - userToken1 = await userLogin(servers[0], user) + userToken1 = await servers[0].loginCommand.getAccessToken(user) await uploadVideo(servers[0].url, userToken1, { name: 'video user 1' }) } @@ -94,14 +93,14 @@ describe('Test blocklist', function () { const user = { username: 'user2', password: 'password' } await createUser({ url: servers[0].url, accessToken: servers[0].accessToken, username: user.username, password: user.password }) - userToken2 = await userLogin(servers[0], user) + userToken2 = await servers[0].loginCommand.getAccessToken(user) } { const user = { username: 'user3', password: 'password' } await createUser({ url: servers[1].url, accessToken: servers[1].accessToken, username: user.username, password: user.password }) - remoteUserToken = await userLogin(servers[1], user) + remoteUserToken = await servers[1].loginCommand.getAccessToken(user) } await doubleFollow(servers[0], servers[1]) diff --git a/server/tests/api/moderation/blocklist.ts b/server/tests/api/moderation/blocklist.ts index 44e3de4e4..c38a7dad4 100644 --- a/server/tests/api/moderation/blocklist.ts +++ b/server/tests/api/moderation/blocklist.ts @@ -14,7 +14,6 @@ import { ServerInfo, setAccessTokensToServers, uploadVideo, - userLogin, waitJobs } from '@shared/extra-utils' import { UserNotificationType, Video } from '@shared/models' @@ -94,7 +93,7 @@ describe('Test blocklist', function () { const user = { username: 'user1', password: 'password' } await createUser({ url: servers[0].url, accessToken: servers[0].accessToken, username: user.username, password: user.password }) - userToken1 = await userLogin(servers[0], user) + userToken1 = await servers[0].loginCommand.getAccessToken(user) await uploadVideo(servers[0].url, userToken1, { name: 'video user 1' }) } @@ -102,14 +101,14 @@ describe('Test blocklist', function () { const user = { username: 'moderator', password: 'password' } await createUser({ url: servers[0].url, accessToken: servers[0].accessToken, username: user.username, password: user.password }) - userModeratorToken = await userLogin(servers[0], user) + userModeratorToken = await servers[0].loginCommand.getAccessToken(user) } { const user = { username: 'user2', password: 'password' } await createUser({ url: servers[1].url, accessToken: servers[1].accessToken, username: user.username, password: user.password }) - userToken2 = await userLogin(servers[1], user) + userToken2 = await servers[1].loginCommand.getAccessToken(user) await uploadVideo(servers[1].url, userToken2, { name: 'video user 2' }) } diff --git a/server/tests/api/moderation/video-blacklist.ts b/server/tests/api/moderation/video-blacklist.ts index 8b4723a2b..b61effc57 100644 --- a/server/tests/api/moderation/video-blacklist.ts +++ b/server/tests/api/moderation/video-blacklist.ts @@ -19,7 +19,6 @@ import { setAccessTokensToServers, updateVideo, uploadVideo, - userLogin, waitJobs } from '@shared/extra-utils' import { User, UserAdminFlag, UserRole, VideoBlacklist, VideoBlacklistType } from '@shared/models' @@ -366,7 +365,7 @@ describe('Test video blacklist', function () { role: UserRole.USER }) - userWithoutFlag = await userLogin(servers[0], user) + userWithoutFlag = await servers[0].loginCommand.getAccessToken(user) const res = await getMyUserInformation(servers[0].url, userWithoutFlag) const body: User = res.body @@ -384,7 +383,7 @@ describe('Test video blacklist', function () { role: UserRole.USER }) - userWithFlag = await userLogin(servers[0], user) + userWithFlag = await servers[0].loginCommand.getAccessToken(user) } await waitJobs(servers) diff --git a/server/tests/api/search/search-activitypub-video-channels.ts b/server/tests/api/search/search-activitypub-video-channels.ts index 83be9cd1e..3cba2b019 100644 --- a/server/tests/api/search/search-activitypub-video-channels.ts +++ b/server/tests/api/search/search-activitypub-video-channels.ts @@ -13,7 +13,6 @@ import { updateMyUser, updateVideo, uploadVideo, - userLogin, wait, waitJobs } from '@shared/extra-utils' @@ -47,7 +46,7 @@ describe('Test ActivityPub video channels search', function () { { const user = { username: 'user1_server2', password: 'password' } await createUser({ url: servers[1].url, accessToken: servers[1].accessToken, username: user.username, password: user.password }) - userServer2Token = await userLogin(servers[1], user) + userServer2Token = await servers[1].loginCommand.getAccessToken(user) const channel = { name: 'channel1_server2', diff --git a/server/tests/api/server/bulk.ts b/server/tests/api/server/bulk.ts index 5c8673e00..a09c21228 100644 --- a/server/tests/api/server/bulk.ts +++ b/server/tests/api/server/bulk.ts @@ -2,7 +2,6 @@ import 'mocha' import * as chai from 'chai' -import { Video } from '@shared/models' import { BulkCommand, cleanupTests, @@ -13,9 +12,9 @@ import { ServerInfo, setAccessTokensToServers, uploadVideo, - userLogin, waitJobs -} from '../../../../shared/extra-utils/index' +} from '@shared/extra-utils' +import { Video } from '@shared/models' const expect = chai.expect @@ -41,21 +40,21 @@ describe('Test bulk actions', function () { const user = { username: 'user1', password: 'password' } await createUser({ url: servers[0].url, accessToken: servers[0].accessToken, username: user.username, password: user.password }) - user1Token = await userLogin(servers[0], user) + user1Token = await servers[0].loginCommand.getAccessToken(user) } { const user = { username: 'user2', password: 'password' } await createUser({ url: servers[0].url, accessToken: servers[0].accessToken, username: user.username, password: user.password }) - user2Token = await userLogin(servers[0], user) + user2Token = await servers[0].loginCommand.getAccessToken(user) } { const user = { username: 'user3', password: 'password' } await createUser({ url: servers[1].url, accessToken: servers[1].accessToken, username: user.username, password: user.password }) - user3Token = await userLogin(servers[1], user) + user3Token = await servers[1].loginCommand.getAccessToken(user) } await doubleFollow(servers[0], servers[1]) diff --git a/server/tests/api/server/email.ts b/server/tests/api/server/email.ts index 5d997713b..c64c120e3 100644 --- a/server/tests/api/server/email.ts +++ b/server/tests/api/server/email.ts @@ -15,7 +15,6 @@ import { setAccessTokensToServers, unblockUser, uploadVideo, - userLogin, verifyEmail } from '../../../../shared/extra-utils' import { MockSmtpServer } from '../../../../shared/extra-utils/mock-servers/mock-email' @@ -62,7 +61,7 @@ describe('Test emails', function () { const res = await createUser({ url: server.url, accessToken: server.accessToken, username: user.username, password: user.password }) userId = res.body.user.id - userAccessToken = await userLogin(server, user) + userAccessToken = await server.loginCommand.getAccessToken(user) } { @@ -128,7 +127,7 @@ describe('Test emails', function () { it('Should login with this new password', async function () { user.password = 'super_password2' - await userLogin(server, user) + await server.loginCommand.getAccessToken(user) }) }) @@ -175,7 +174,7 @@ describe('Test emails', function () { }) it('Should login with this new password', async function () { - await userLogin(server, { + await server.loginCommand.getAccessToken({ username: 'create_password', password: 'newly_created_password' }) diff --git a/server/tests/api/server/follow-constraints.ts b/server/tests/api/server/follow-constraints.ts index 0f1c6264d..74cdf353b 100644 --- a/server/tests/api/server/follow-constraints.ts +++ b/server/tests/api/server/follow-constraints.ts @@ -15,8 +15,7 @@ import { getVideoWithToken, ServerInfo, setAccessTokensToServers, - uploadVideo, - userLogin + uploadVideo } from '../../../../shared/extra-utils' const expect = chai.expect @@ -49,7 +48,7 @@ describe('Test follow constraints', function () { password: 'super_password' } 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) await doubleFollow(servers[0], servers[1]) }) diff --git a/server/tests/api/server/follows.ts b/server/tests/api/server/follows.ts index 4a9ed2d05..c2a0620a5 100644 --- a/server/tests/api/server/follows.ts +++ b/server/tests/api/server/follows.ts @@ -16,7 +16,6 @@ import { setAccessTokensToServers, testCaptionFile, uploadVideo, - userLogin, waitJobs } from '@shared/extra-utils' import { Video, VideoPrivacy } from '@shared/models' @@ -330,7 +329,7 @@ describe('Test follows', function () { { const user = { username: 'captain', password: 'password' } await createUser({ url: servers[2].url, accessToken: servers[2].accessToken, username: user.username, password: user.password }) - const userAccessToken = await userLogin(servers[2], user) + const userAccessToken = await servers[2].loginCommand.getAccessToken(user) const resVideos = await getVideosList(servers[2].url) video4 = resVideos.body.data.find(v => v.name === 'server3-4') diff --git a/server/tests/api/server/reverse-proxy.ts b/server/tests/api/server/reverse-proxy.ts index 17d1ee4a5..d9c669571 100644 --- a/server/tests/api/server/reverse-proxy.ts +++ b/server/tests/api/server/reverse-proxy.ts @@ -1,12 +1,17 @@ /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */ -import 'mocha' -import * as chai from 'chai' -import { cleanupTests, getVideo, registerUser, uploadVideo, userLogin, viewVideo, wait } from '../../../../shared/extra-utils' -import { flushAndRunServer, setAccessTokensToServers } from '../../../../shared/extra-utils/index' -import { HttpStatusCode } from '../../../../shared/core-utils/miscs/http-error-codes' - -const expect = chai.expect +import { expect } from 'chai' +import { HttpStatusCode } from '@shared/core-utils' +import { + cleanupTests, + flushAndRunServer, + getVideo, + registerUser, + setAccessTokensToServers, + uploadVideo, + viewVideo, + wait +} from '@shared/extra-utils' describe('Test application behind a reverse proxy', function () { let server = null @@ -97,10 +102,10 @@ describe('Test application behind a reverse proxy', function () { const user = { username: 'root', password: 'fail' } for (let i = 0; i < 19; i++) { - await userLogin(server, user, HttpStatusCode.BAD_REQUEST_400) + await server.loginCommand.getAccessToken(user, HttpStatusCode.BAD_REQUEST_400) } - await userLogin(server, user, HttpStatusCode.TOO_MANY_REQUESTS_429) + await server.loginCommand.getAccessToken(user, HttpStatusCode.TOO_MANY_REQUESTS_429) }) it('Should rate limit signup', async function () { diff --git a/server/tests/api/server/stats.ts b/server/tests/api/server/stats.ts index ded305899..aa26f978d 100644 --- a/server/tests/api/server/stats.ts +++ b/server/tests/api/server/stats.ts @@ -10,7 +10,6 @@ import { ServerInfo, setAccessTokensToServers, uploadVideo, - userLogin, viewVideo, wait, waitJobs @@ -119,7 +118,7 @@ describe('Test stats (excluding redundancy)', function () { } { - await userLogin(server, user) + await server.loginCommand.getAccessToken(user) const data = await server.statsCommand.get() diff --git a/server/tests/api/users/user-subscriptions.ts b/server/tests/api/users/user-subscriptions.ts index c119622ad..1d0fc35f1 100644 --- a/server/tests/api/users/user-subscriptions.ts +++ b/server/tests/api/users/user-subscriptions.ts @@ -13,7 +13,6 @@ import { SubscriptionsCommand, updateVideo, uploadVideo, - userLogin, waitJobs } from '@shared/extra-utils' @@ -42,7 +41,7 @@ describe('Test users subscriptions', function () { const user = { username: 'user' + server.serverNumber, password: 'password' } await createUser({ url: server.url, accessToken: server.accessToken, username: user.username, password: user.password }) - const accessToken = await userLogin(server, user) + const accessToken = await server.loginCommand.getAccessToken(user) users.push({ accessToken }) const videoName1 = 'video 1-' + server.serverNumber diff --git a/server/tests/api/users/users-multiple-servers.ts b/server/tests/api/users/users-multiple-servers.ts index 7b650cb8f..99fa08fe2 100644 --- a/server/tests/api/users/users-multiple-servers.ts +++ b/server/tests/api/users/users-multiple-servers.ts @@ -19,7 +19,6 @@ import { updateMyAvatar, updateMyUser, uploadVideo, - userLogin, waitJobs } from '@shared/extra-utils' import { User } from '@shared/models' @@ -64,7 +63,7 @@ describe('Test users with multiple servers', function () { password: user.password }) userId = res.body.user.id - userAccessToken = await userLogin(servers[0], user) + userAccessToken = await servers[0].loginCommand.getAccessToken(user) } { diff --git a/server/tests/api/users/users-verification.ts b/server/tests/api/users/users-verification.ts index 23f81d804..ade730323 100644 --- a/server/tests/api/users/users-verification.ts +++ b/server/tests/api/users/users-verification.ts @@ -2,23 +2,21 @@ import 'mocha' import * as chai from 'chai' -import { HttpStatusCode } from '../../../../shared/core-utils/miscs/http-error-codes' +import { HttpStatusCode } from '@shared/core-utils' import { cleanupTests, flushAndRunServer, getMyUserInformation, getUserInformation, - login, + MockSmtpServer, registerUser, ServerInfo, + setAccessTokensToServers, updateMyUser, - userLogin, - verifyEmail -} from '../../../../shared/extra-utils' -import { MockSmtpServer } from '../../../../shared/extra-utils/mock-servers/mock-email' -import { waitJobs } from '../../../../shared/extra-utils/server/jobs' -import { setAccessTokensToServers } from '../../../../shared/extra-utils/users/login' -import { User } from '../../../../shared/models/users' + verifyEmail, + waitJobs +} from '@shared/extra-utils' +import { User } from '@shared/models' const expect = chai.expect @@ -91,15 +89,15 @@ describe('Test users account verification', function () { }) it('Should not allow login for user with unverified email', async function () { - const resLogin = await login(server.url, server.client, user1, HttpStatusCode.BAD_REQUEST_400) - expect(resLogin.body.detail).to.contain('User email is not verified.') + const { detail } = await server.loginCommand.login({ user: user1, expectedStatus: HttpStatusCode.BAD_REQUEST_400 }) + expect(detail).to.contain('User email is not verified.') }) it('Should verify the user via email and allow login', async function () { await verifyEmail(server.url, userId, verificationString) - const res = await login(server.url, server.client, user1) - userAccessToken = res.body.access_token + const body = await server.loginCommand.login({ user: user1 }) + userAccessToken = body.access_token const resUserVerified = await getUserInformation(server.url, server.accessToken, userId) expect(resUserVerified.body.emailVerified).to.be.true @@ -164,7 +162,7 @@ describe('Test users account verification', function () { await waitJobs(server) expect(emails).to.have.lengthOf(expectedEmailsLength) - const accessToken = await userLogin(server, user2) + const accessToken = await server.loginCommand.getAccessToken(user2) const resMyUserInfo = await getMyUserInformation(server.url, accessToken) expect(resMyUserInfo.body.emailVerified).to.be.null @@ -181,7 +179,7 @@ describe('Test users account verification', function () { } }) - await userLogin(server, user2) + await server.loginCommand.getAccessToken(user2) }) after(async function () { diff --git a/server/tests/api/users/users.ts b/server/tests/api/users/users.ts index 69a8dba34..608bedb8b 100644 --- a/server/tests/api/users/users.ts +++ b/server/tests/api/users/users.ts @@ -18,11 +18,8 @@ import { getUsersListPaginationAndSort, getVideosList, killallServers, - login, - logout, makePutBodyRequest, rateVideo, - refreshToken, registerUserWithChannel, removeUser, removeVideo, @@ -35,7 +32,6 @@ import { updateMyUser, updateUser, uploadVideo, - userLogin, waitJobs } from '@shared/extra-utils' import { AbuseState, MyUser, OAuth2ErrorCode, User, UserAdminFlag, UserRole, Video, VideoPlaylistType } from '@shared/models' @@ -78,22 +74,22 @@ describe('Test users', function () { it('Should not login with an invalid client id', async function () { const client = { id: 'client', secret: server.client.secret } - const res = await login(server.url, client, server.user, HttpStatusCode.BAD_REQUEST_400) + const body = await server.loginCommand.login({ client, expectedStatus: HttpStatusCode.BAD_REQUEST_400 }) - expect(res.body.code).to.equal(OAuth2ErrorCode.INVALID_CLIENT) - expect(res.body.error).to.contain('client is invalid') - expect(res.body.type.startsWith('https://')).to.be.true - expect(res.body.type).to.contain(OAuth2ErrorCode.INVALID_CLIENT) + expect(body.code).to.equal(OAuth2ErrorCode.INVALID_CLIENT) + expect(body.error).to.contain('client is invalid') + expect(body.type.startsWith('https://')).to.be.true + expect(body.type).to.contain(OAuth2ErrorCode.INVALID_CLIENT) }) it('Should not login with an invalid client secret', async function () { const client = { id: server.client.id, secret: 'coucou' } - const res = await login(server.url, client, server.user, HttpStatusCode.BAD_REQUEST_400) + const body = await server.loginCommand.login({ client, expectedStatus: HttpStatusCode.BAD_REQUEST_400 }) - expect(res.body.code).to.equal(OAuth2ErrorCode.INVALID_CLIENT) - expect(res.body.error).to.contain('client is invalid') - expect(res.body.type.startsWith('https://')).to.be.true - expect(res.body.type).to.contain(OAuth2ErrorCode.INVALID_CLIENT) + expect(body.code).to.equal(OAuth2ErrorCode.INVALID_CLIENT) + expect(body.error).to.contain('client is invalid') + expect(body.type.startsWith('https://')).to.be.true + expect(body.type).to.contain(OAuth2ErrorCode.INVALID_CLIENT) }) }) @@ -101,22 +97,22 @@ describe('Test users', function () { it('Should not login with an invalid username', async function () { const user = { username: 'captain crochet', password: server.user.password } - const res = await login(server.url, server.client, user, HttpStatusCode.BAD_REQUEST_400) + const body = await server.loginCommand.login({ user, expectedStatus: HttpStatusCode.BAD_REQUEST_400 }) - expect(res.body.code).to.equal(OAuth2ErrorCode.INVALID_GRANT) - expect(res.body.error).to.contain('credentials are invalid') - expect(res.body.type.startsWith('https://')).to.be.true - expect(res.body.type).to.contain(OAuth2ErrorCode.INVALID_GRANT) + expect(body.code).to.equal(OAuth2ErrorCode.INVALID_GRANT) + expect(body.error).to.contain('credentials are invalid') + expect(body.type.startsWith('https://')).to.be.true + expect(body.type).to.contain(OAuth2ErrorCode.INVALID_GRANT) }) it('Should not login with an invalid password', async function () { const user = { username: server.user.username, password: 'mew_three' } - const res = await login(server.url, server.client, user, HttpStatusCode.BAD_REQUEST_400) + const body = await server.loginCommand.login({ user, expectedStatus: HttpStatusCode.BAD_REQUEST_400 }) - expect(res.body.code).to.equal(OAuth2ErrorCode.INVALID_GRANT) - expect(res.body.error).to.contain('credentials are invalid') - expect(res.body.type.startsWith('https://')).to.be.true - expect(res.body.type).to.contain(OAuth2ErrorCode.INVALID_GRANT) + expect(body.code).to.equal(OAuth2ErrorCode.INVALID_GRANT) + expect(body.error).to.contain('credentials are invalid') + expect(body.type.startsWith('https://')).to.be.true + expect(body.type).to.contain(OAuth2ErrorCode.INVALID_GRANT) }) it('Should not be able to upload a video', async function () { @@ -139,20 +135,20 @@ describe('Test users', function () { it('Should not be able to unfollow') it('Should be able to login', async function () { - const res = await login(server.url, server.client, server.user, HttpStatusCode.OK_200) + const body = await server.loginCommand.login({ expectedStatus: HttpStatusCode.OK_200 }) - accessToken = res.body.access_token + accessToken = body.access_token }) it('Should be able to login with an insensitive username', async function () { const user = { username: 'RoOt', password: server.user.password } - await login(server.url, server.client, user, HttpStatusCode.OK_200) + await server.loginCommand.login({ user, expectedStatus: HttpStatusCode.OK_200 }) const user2 = { username: 'rOoT', password: server.user.password } - await login(server.url, server.client, user2, HttpStatusCode.OK_200) + await server.loginCommand.login({ user: user2, expectedStatus: HttpStatusCode.OK_200 }) const user3 = { username: 'ROOt', password: server.user.password } - await login(server.url, server.client, user3, HttpStatusCode.OK_200) + await server.loginCommand.login({ user: user3, expectedStatus: HttpStatusCode.OK_200 }) }) }) @@ -222,7 +218,7 @@ describe('Test users', function () { describe('Logout', function () { it('Should logout (revoke token)', async function () { - await logout(server.url, server.accessToken) + await server.loginCommand.logout({ token: server.accessToken }) }) it('Should not be able to get the user information', async function () { @@ -250,9 +246,9 @@ describe('Test users', function () { }) it('Should be able to login again', async function () { - const res = await login(server.url, server.client, server.user) - server.accessToken = res.body.access_token - server.refreshToken = res.body.refresh_token + const body = await server.loginCommand.login() + server.accessToken = body.access_token + server.refreshToken = body.refresh_token }) it('Should be able to get my user information again', async function () { @@ -268,11 +264,11 @@ describe('Test users', function () { await killallServers([ server ]) await reRunServer(server) - await getMyUserInformation(server.url, server.accessToken, 401) + await getMyUserInformation(server.url, server.accessToken, HttpStatusCode.UNAUTHORIZED_401) }) it('Should not be able to refresh an access token with an expired refresh token', async function () { - await refreshToken(server, server.refreshToken, 400) + await server.loginCommand.refreshToken({ refreshToken: server.refreshToken, expectedStatus: HttpStatusCode.BAD_REQUEST_400 }) }) it('Should refresh the token', async function () { @@ -284,7 +280,7 @@ describe('Test users', function () { await killallServers([ server ]) await reRunServer(server) - const res = await refreshToken(server, server.refreshToken) + const res = await server.loginCommand.refreshToken({ refreshToken: server.refreshToken }) server.accessToken = res.body.access_token server.refreshToken = res.body.refresh_token }) @@ -308,7 +304,7 @@ describe('Test users', function () { }) it('Should be able to login with this user', async function () { - accessTokenUser = await userLogin(server, user) + accessTokenUser = await server.loginCommand.getAccessToken(user) }) it('Should be able to get user information', async function () { @@ -562,6 +558,7 @@ describe('Test users', function () { }) describe('Update my account', function () { + it('Should update my password', async function () { await updateMyUser({ url: server.url, @@ -571,7 +568,7 @@ describe('Test users', function () { }) user.password = 'new password' - await userLogin(server, user, HttpStatusCode.OK_200) + await server.loginCommand.login({ user }) }) it('Should be able to change the NSFW display attribute', async function () { @@ -781,7 +778,7 @@ describe('Test users', function () { it('Should have removed the user token', async function () { await getMyUserVideoQuotaUsed(server.url, accessTokenUser, HttpStatusCode.UNAUTHORIZED_401) - accessTokenUser = await userLogin(server, user) + accessTokenUser = await server.loginCommand.getAccessToken(user) }) it('Should be able to update another user password', async function () { @@ -794,10 +791,10 @@ describe('Test users', function () { await getMyUserVideoQuotaUsed(server.url, accessTokenUser, HttpStatusCode.UNAUTHORIZED_401) - await userLogin(server, user, HttpStatusCode.BAD_REQUEST_400) + await server.loginCommand.login({ user, expectedStatus: HttpStatusCode.BAD_REQUEST_400 }) user.password = 'password updated' - accessTokenUser = await userLogin(server, user) + accessTokenUser = await server.loginCommand.getAccessToken(user) }) }) @@ -813,7 +810,7 @@ describe('Test users', function () { }) it('Should not be able to login with this user', async function () { - await userLogin(server, user, HttpStatusCode.BAD_REQUEST_400) + await server.loginCommand.login({ user, expectedStatus: HttpStatusCode.BAD_REQUEST_400 }) }) it('Should not have videos of this user', async function () { @@ -842,7 +839,7 @@ describe('Test users', function () { password: 'my super password' } - user15AccessToken = await userLogin(server, user15) + user15AccessToken = await server.loginCommand.getAccessToken(user15) }) it('Should have the correct display name', async function () { @@ -897,13 +894,13 @@ describe('Test users', function () { }) user16Id = resUser.body.user.id - user16AccessToken = await userLogin(server, user16) + user16AccessToken = await server.loginCommand.getAccessToken(user16) await getMyUserInformation(server.url, user16AccessToken, HttpStatusCode.OK_200) await blockUser(server.url, user16Id, server.accessToken) await getMyUserInformation(server.url, user16AccessToken, HttpStatusCode.UNAUTHORIZED_401) - await userLogin(server, user16, HttpStatusCode.BAD_REQUEST_400) + await server.loginCommand.login({ user: user16, expectedStatus: HttpStatusCode.BAD_REQUEST_400 }) }) it('Should search user by banned status', async function () { @@ -930,7 +927,7 @@ describe('Test users', function () { it('Should unblock a user', async function () { await unblockUser(server.url, user16Id, server.accessToken) - user16AccessToken = await userLogin(server, user16) + user16AccessToken = await server.loginCommand.getAccessToken(user16) await getMyUserInformation(server.url, user16AccessToken, HttpStatusCode.OK_200) }) }) @@ -952,7 +949,7 @@ describe('Test users', function () { }) user17Id = resUser.body.user.id - user17AccessToken = await userLogin(server, user17) + user17AccessToken = await server.loginCommand.getAccessToken(user17) const res = await getUserInformation(server.url, server.accessToken, user17Id, true) const user: User = res.body diff --git a/server/tests/api/videos/multiple-servers.ts b/server/tests/api/videos/multiple-servers.ts index 1905aac83..740314bfd 100644 --- a/server/tests/api/videos/multiple-servers.ts +++ b/server/tests/api/videos/multiple-servers.ts @@ -24,7 +24,6 @@ import { testImage, updateVideo, uploadVideo, - userLogin, viewVideo, wait, waitJobs, @@ -155,7 +154,7 @@ describe('Test multiple servers', function () { password: 'super_password' } await createUser({ url: servers[1].url, accessToken: servers[1].accessToken, username: user.username, password: user.password }) - const userAccessToken = await userLogin(servers[1], user) + const userAccessToken = await servers[1].loginCommand.getAccessToken(user) const videoAttributes = { name: 'my super name for server 2', diff --git a/server/tests/api/videos/video-change-ownership.ts b/server/tests/api/videos/video-change-ownership.ts index 1b81fe047..17c738e6f 100644 --- a/server/tests/api/videos/video-change-ownership.ts +++ b/server/tests/api/videos/video-change-ownership.ts @@ -16,8 +16,7 @@ import { ServerInfo, setAccessTokensToServers, setDefaultVideoChannel, - uploadVideo, - userLogin + uploadVideo } from '../../../../shared/extra-utils' import { waitJobs } from '../../../../shared/extra-utils/server/jobs' import { User } from '../../../../shared/models/users' @@ -82,8 +81,8 @@ describe('Test video change ownership - nominal', function () { videoQuota: videoQuota }) - firstUserToken = await userLogin(servers[0], firstUser) - secondUserToken = await userLogin(servers[0], secondUser) + firstUserToken = await servers[0].loginCommand.getAccessToken(firstUser) + secondUserToken = await servers[0].loginCommand.getAccessToken(secondUser) { const res = await getMyUserInformation(servers[0].url, firstUserToken) @@ -323,8 +322,8 @@ describe('Test video change ownership - quota too small', function () { videoQuota: limitedVideoQuota }) - firstUserToken = await userLogin(server, firstUser) - secondUserToken = await userLogin(server, secondUser) + firstUserToken = await server.loginCommand.getAccessToken(firstUser) + secondUserToken = await server.loginCommand.getAccessToken(secondUser) // Upload some videos on the server const video1Attributes = { diff --git a/server/tests/api/videos/video-channels.ts b/server/tests/api/videos/video-channels.ts index e441ebbd4..83645640c 100644 --- a/server/tests/api/videos/video-channels.ts +++ b/server/tests/api/videos/video-channels.ts @@ -16,7 +16,6 @@ import { testImage, updateVideo, uploadVideo, - userLogin, wait } from '../../../../shared/extra-utils' import { getMyUserInformation, ServerInfo, setAccessTokensToServers, viewVideo } from '../../../../shared/extra-utils/index' @@ -391,7 +390,7 @@ describe('Test video channels', function () { { await createUser({ url: servers[0].url, accessToken: servers[0].accessToken, username: 'toto', password: 'password' }) - const accessToken = await userLogin(servers[0], { username: 'toto', password: 'password' }) + const accessToken = await servers[0].loginCommand.getAccessToken({ username: 'toto', password: 'password' }) const res = await getMyUserInformation(servers[0].url, accessToken) const videoChannel = res.body.videoChannels[0] diff --git a/server/tests/api/videos/video-comments.ts b/server/tests/api/videos/video-comments.ts index 548d9fbf5..f9bd23646 100644 --- a/server/tests/api/videos/video-comments.ts +++ b/server/tests/api/videos/video-comments.ts @@ -8,7 +8,6 @@ import { createUser, dateIsValid, flushAndRunServer, - getAccessToken, ServerInfo, setAccessTokensToServers, testImage, @@ -52,7 +51,7 @@ describe('Test video comments', function () { username: 'user1', password: 'password' }) - userAccessTokenServer1 = await getAccessToken(server.url, 'user1', 'password') + userAccessTokenServer1 = await server.loginCommand.getAccessToken('user1', 'password') command = server.commentsCommand }) diff --git a/server/tests/api/videos/video-nsfw.ts b/server/tests/api/videos/video-nsfw.ts index c9c3792eb..a30b11ace 100644 --- a/server/tests/api/videos/video-nsfw.ts +++ b/server/tests/api/videos/video-nsfw.ts @@ -15,8 +15,7 @@ import { ServerInfo, setAccessTokensToServers, updateMyUser, - uploadVideo, - userLogin + uploadVideo } from '@shared/extra-utils' import { BooleanBothQuery, CustomConfig, ResultList, User, Video, VideosOverview } from '@shared/models' @@ -151,7 +150,7 @@ describe('Test video NSFW policy', function () { 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, userAccessToken) const user = res.body diff --git a/server/tests/api/videos/video-playlists.ts b/server/tests/api/videos/video-playlists.ts index 2bb019348..38133e2ce 100644 --- a/server/tests/api/videos/video-playlists.ts +++ b/server/tests/api/videos/video-playlists.ts @@ -10,7 +10,6 @@ import { doubleFollow, flushAndRunMultipleServers, generateUserAccessToken, - getAccessToken, getMyUserInformation, PlaylistsCommand, removeUser, @@ -21,7 +20,6 @@ import { updateVideo, uploadVideo, uploadVideoAndGetId, - userLogin, wait, waitJobs } from '@shared/extra-utils' @@ -122,7 +120,7 @@ describe('Test video playlists', function () { username: 'user1', password: 'password' }) - userTokenServer1 = await getAccessToken(servers[0].url, 'user1', 'password') + userTokenServer1 = await servers[0].loginCommand.getAccessToken('user1', 'password') } await waitJobs(servers) @@ -1129,7 +1127,7 @@ describe('Test video playlists', function () { }) const userId = res.body.user.id - const userAccessToken = await userLogin(servers[0], user) + const userAccessToken = await servers[0].loginCommand.getAccessToken(user) const resChannel = await getMyUserInformation(servers[0].url, userAccessToken) const userChannel = (resChannel.body as User).videoChannels[0] diff --git a/server/tests/api/videos/video-privacy.ts b/server/tests/api/videos/video-privacy.ts index 950aeb7cf..f831dd8a9 100644 --- a/server/tests/api/videos/video-privacy.ts +++ b/server/tests/api/videos/video-privacy.ts @@ -2,23 +2,24 @@ import 'mocha' import * as chai from 'chai' -import { HttpStatusCode } from '@shared/core-utils/miscs/http-error-codes' -import { Video, VideoCreateResult } from '@shared/models' +import { HttpStatusCode } from '@shared/core-utils' import { cleanupTests, + createUser, + doubleFollow, flushAndRunServer, + getMyVideos, + getVideo, getVideosList, getVideosListWithToken, + getVideoWithToken, ServerInfo, setAccessTokensToServers, - uploadVideo -} from '../../../../shared/extra-utils/index' -import { doubleFollow } from '../../../../shared/extra-utils/server/follows' -import { waitJobs } from '../../../../shared/extra-utils/server/jobs' -import { userLogin } from '../../../../shared/extra-utils/users/login' -import { createUser } from '../../../../shared/extra-utils/users/users' -import { getMyVideos, getVideo, getVideoWithToken, updateVideo } from '../../../../shared/extra-utils/videos/videos' -import { VideoPrivacy } from '../../../../shared/models/videos/video-privacy.enum' + updateVideo, + uploadVideo, + waitJobs +} from '@shared/extra-utils' +import { Video, VideoCreateResult, VideoPrivacy } from '@shared/models' const expect = chai.expect @@ -126,7 +127,7 @@ describe('Test video privacy', function () { } await createUser({ url: servers[0].url, accessToken: servers[0].accessToken, username: user.username, password: user.password }) - anotherUserToken = await userLogin(servers[0], user) + anotherUserToken = await servers[0].loginCommand.getAccessToken(user) await getVideoWithToken(servers[0].url, anotherUserToken, privateVideoUUID, HttpStatusCode.FORBIDDEN_403) }) diff --git a/server/tests/api/videos/videos-filter.ts b/server/tests/api/videos/videos-filter.ts index 7428b82c5..519dad646 100644 --- a/server/tests/api/videos/videos-filter.ts +++ b/server/tests/api/videos/videos-filter.ts @@ -1,7 +1,8 @@ /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */ -import * as chai from 'chai' import 'mocha' +import * as chai from 'chai' +import { HttpStatusCode } from '../../../../shared/core-utils/miscs/http-error-codes' import { cleanupTests, createUser, @@ -10,12 +11,10 @@ import { makeGetRequest, ServerInfo, setAccessTokensToServers, - uploadVideo, - userLogin + uploadVideo } from '../../../../shared/extra-utils' -import { Video, VideoPrivacy } from '../../../../shared/models/videos' import { UserRole } from '../../../../shared/models/users' -import { HttpStatusCode } from '../../../../shared/core-utils/miscs/http-error-codes' +import { Video, VideoPrivacy } from '../../../../shared/models/videos' const expect = chai.expect @@ -72,7 +71,7 @@ describe('Test videos filter', function () { role: UserRole.MODERATOR } ) - server['moderatorAccessToken'] = await userLogin(server, moderator) + server['moderatorAccessToken'] = await server.loginCommand.getAccessToken(moderator) await uploadVideo(server.url, server.accessToken, { name: 'public ' + server.serverNumber }) diff --git a/server/tests/api/videos/videos-history.ts b/server/tests/api/videos/videos-history.ts index 9a7635c35..256271bd0 100644 --- a/server/tests/api/videos/videos-history.ts +++ b/server/tests/api/videos/videos-history.ts @@ -16,7 +16,6 @@ import { setAccessTokensToServers, updateMyUser, uploadVideo, - userLogin, wait } from '@shared/extra-utils' import { Video, VideoDetails } from '@shared/models' @@ -61,7 +60,7 @@ describe('Test videos history', function () { password: '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) }) it('Should get videos, without watching history', async function () { -- 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/activitypub/fetch.ts | 3 +- server/tests/api/activitypub/refresher.ts | 5 +- 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 +- server/tests/api/live/live-constraints.ts | 8 +- server/tests/api/moderation/abuses.ts | 15 +- .../tests/api/moderation/blocklist-notification.ts | 9 +- server/tests/api/moderation/blocklist.ts | 7 +- server/tests/api/moderation/video-blacklist.ts | 17 +- .../api/notifications/comments-notifications.ts | 14 +- .../api/notifications/moderation-notifications.ts | 11 +- .../tests/api/notifications/notifications-api.ts | 25 +- .../tests/api/notifications/user-notifications.ts | 18 +- .../search/search-activitypub-video-channels.ts | 8 +- server/tests/api/search/search-channels.ts | 4 +- server/tests/api/server/bulk.ts | 7 +- server/tests/api/server/config.ts | 7 +- server/tests/api/server/email.ts | 73 ++-- server/tests/api/server/follow-constraints.ts | 3 +- server/tests/api/server/follows.ts | 5 +- server/tests/api/server/jobs.ts | 2 +- server/tests/api/server/plugins.ts | 18 +- server/tests/api/server/reverse-proxy.ts | 18 +- server/tests/api/server/stats.ts | 3 +- server/tests/api/users/user-subscriptions.ts | 3 +- server/tests/api/users/users-multiple-servers.ts | 45 +-- server/tests/api/users/users-verification.ts | 48 +-- server/tests/api/users/users.ts | 374 +++++++-------------- server/tests/api/videos/multiple-servers.ts | 3 +- server/tests/api/videos/resumable-upload.ts | 17 +- server/tests/api/videos/video-change-ownership.ts | 89 ++--- server/tests/api/videos/video-channels.ts | 22 +- server/tests/api/videos/video-comments.ts | 16 +- server/tests/api/videos/video-imports.ts | 9 +- server/tests/api/videos/video-nsfw.ts | 26 +- server/tests/api/videos/video-playlists.ts | 34 +- server/tests/api/videos/video-privacy.ts | 3 +- server/tests/api/videos/videos-filter.ts | 13 +- server/tests/api/videos/videos-history.ts | 12 +- server/tests/api/videos/videos-overview.ts | 12 +- 61 files changed, 484 insertions(+), 926 deletions(-) (limited to 'server/tests/api') diff --git a/server/tests/api/activitypub/fetch.ts b/server/tests/api/activitypub/fetch.ts index c1af23016..162f3ec83 100644 --- a/server/tests/api/activitypub/fetch.ts +++ b/server/tests/api/activitypub/fetch.ts @@ -4,7 +4,6 @@ import 'mocha' import * as chai from 'chai' import { cleanupTests, - createUser, doubleFollow, flushAndRunMultipleServers, getVideosListSort, @@ -32,7 +31,7 @@ describe('Test ActivityPub fetcher', function () { const user = { username: 'user1', password: 'password' } for (const server of servers) { - 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 userAccessToken = await servers[0].loginCommand.getAccessToken(user) diff --git a/server/tests/api/activitypub/refresher.ts b/server/tests/api/activitypub/refresher.ts index af919f2f3..5a37dbc40 100644 --- a/server/tests/api/activitypub/refresher.ts +++ b/server/tests/api/activitypub/refresher.ts @@ -6,7 +6,6 @@ import { cleanupTests, doubleFollow, flushAndRunMultipleServers, - generateUserAccessToken, getVideo, killallServers, reRunServer, @@ -44,10 +43,10 @@ describe('Test AP refresher', function () { } { - const a1 = await generateUserAccessToken(servers[1], 'user1') + const a1 = await servers[1].usersCommand.generateUserAndToken('user1') await uploadVideo(servers[1].url, a1, { name: 'video4' }) - const a2 = await generateUserAccessToken(servers[1], 'user2') + const a2 = await servers[1].usersCommand.generateUserAndToken('user2') await uploadVideo(servers[1].url, a2, { name: 'video5' }) } 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 diff --git a/server/tests/api/live/live-constraints.ts b/server/tests/api/live/live-constraints.ts index 46153f7b1..290d325d4 100644 --- a/server/tests/api/live/live-constraints.ts +++ b/server/tests/api/live/live-constraints.ts @@ -9,12 +9,10 @@ import { ConfigCommand, doubleFollow, flushAndRunMultipleServers, - generateUser, getVideo, ServerInfo, setAccessTokensToServers, setDefaultVideoChannel, - updateUser, wait, waitJobs } from '../../../../shared/extra-utils' @@ -58,9 +56,7 @@ describe('Test live constraints', function () { } function updateQuota (options: { total: number, daily: number }) { - return updateUser({ - url: servers[0].url, - accessToken: servers[0].accessToken, + return servers[0].usersCommand.update({ userId, videoQuota: options.total, videoQuotaDaily: options.daily @@ -89,7 +85,7 @@ describe('Test live constraints', function () { }) { - const res = await generateUser(servers[0], 'user1') + const res = await servers[0].usersCommand.generate('user1') userId = res.userId userChannelId = res.userChannelId userAccessToken = res.token diff --git a/server/tests/api/moderation/abuses.ts b/server/tests/api/moderation/abuses.ts index d7462f38f..a7119263c 100644 --- a/server/tests/api/moderation/abuses.ts +++ b/server/tests/api/moderation/abuses.ts @@ -5,13 +5,10 @@ import * as chai from 'chai' import { AbusesCommand, cleanupTests, - createUser, doubleFollow, flushAndRunMultipleServers, - generateUserAccessToken, getVideoIdFromUUID, getVideosList, - removeUser, removeVideo, ServerInfo, setAccessTokensToServers, @@ -278,7 +275,7 @@ describe('Test abuses', function () { // register a second user to have two reporters/reportees const user = { username: 'user2', password: 'password' } - await createUser({ url: servers[0].url, accessToken: servers[0].accessToken, ...user }) + await servers[0].usersCommand.create({ ...user }) const userAccessToken = await servers[0].loginCommand.getAccessToken(user) // upload a third video via this user @@ -604,9 +601,9 @@ describe('Test abuses', function () { before(async function () { this.timeout(50000) - await createUser({ url: servers[0].url, accessToken: servers[0].accessToken, username: 'user_1', password: 'donald' }) + await servers[0].usersCommand.create({ username: 'user_1', password: 'donald' }) - const token = await generateUserAccessToken(servers[1], 'user_2') + const token = await servers[1].usersCommand.generateUserAndToken('user_2') await uploadVideo(servers[1].url, token, { name: 'super video' }) await waitJobs(servers) @@ -708,7 +705,7 @@ describe('Test abuses', function () { this.timeout(10000) const account = await getAccountFromServer(servers[1], 'user_2', servers[1]) - await removeUser(servers[1].url, account.userId, servers[1].accessToken) + await servers[1].usersCommand.remove({ userId: account.userId }) await waitJobs(servers) @@ -765,7 +762,7 @@ describe('Test abuses', function () { let userAccessToken: string before(async function () { - userAccessToken = await generateUserAccessToken(servers[0], 'user_42') + userAccessToken = await servers[0].usersCommand.generateUserAndToken('user_42') await commands[0].report({ token: userAccessToken, videoId: servers[0].video.id, reason: 'user reason 1' }) @@ -836,7 +833,7 @@ describe('Test abuses', function () { let abuseMessageModerationId: number before(async function () { - userToken = await generateUserAccessToken(servers[0], 'user_43') + userToken = await servers[0].usersCommand.generateUserAndToken('user_43') const body = await commands[0].report({ token: userToken, videoId: servers[0].video.id, reason: 'user 43 reason 1' }) abuseId = body.abuse.id diff --git a/server/tests/api/moderation/blocklist-notification.ts b/server/tests/api/moderation/blocklist-notification.ts index 4f2be6198..b44bcb012 100644 --- a/server/tests/api/moderation/blocklist-notification.ts +++ b/server/tests/api/moderation/blocklist-notification.ts @@ -4,7 +4,6 @@ import 'mocha' import * as chai from 'chai' import { cleanupTests, - createUser, doubleFollow, flushAndRunMultipleServers, ServerInfo, @@ -76,9 +75,7 @@ describe('Test blocklist', function () { { const user = { username: 'user1', password: 'password' } - await createUser({ - url: servers[0].url, - accessToken: servers[0].accessToken, + await servers[0].usersCommand.create({ username: user.username, password: user.password, videoQuota: -1, @@ -91,14 +88,14 @@ describe('Test blocklist', function () { { const user = { username: 'user2', 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 }) userToken2 = await servers[0].loginCommand.getAccessToken(user) } { const user = { username: 'user3', password: 'password' } - await createUser({ url: servers[1].url, accessToken: servers[1].accessToken, username: user.username, password: user.password }) + await servers[1].usersCommand.create({ username: user.username, password: user.password }) remoteUserToken = await servers[1].loginCommand.getAccessToken(user) } diff --git a/server/tests/api/moderation/blocklist.ts b/server/tests/api/moderation/blocklist.ts index c38a7dad4..c253b5c11 100644 --- a/server/tests/api/moderation/blocklist.ts +++ b/server/tests/api/moderation/blocklist.ts @@ -6,7 +6,6 @@ import { BlocklistCommand, cleanupTests, CommentsCommand, - createUser, doubleFollow, flushAndRunMultipleServers, getVideosList, @@ -91,7 +90,7 @@ describe('Test blocklist', function () { { const user = { username: 'user1', 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 }) userToken1 = await servers[0].loginCommand.getAccessToken(user) await uploadVideo(servers[0].url, userToken1, { name: 'video user 1' }) @@ -99,14 +98,14 @@ describe('Test blocklist', function () { { const user = { username: 'moderator', 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 }) userModeratorToken = await servers[0].loginCommand.getAccessToken(user) } { const user = { username: 'user2', password: 'password' } - await createUser({ url: servers[1].url, accessToken: servers[1].accessToken, username: user.username, password: user.password }) + await servers[1].usersCommand.create({ username: user.username, password: user.password }) userToken2 = await servers[1].loginCommand.getAccessToken(user) await uploadVideo(servers[1].url, userToken2, { name: 'video user 2' }) diff --git a/server/tests/api/moderation/video-blacklist.ts b/server/tests/api/moderation/video-blacklist.ts index b61effc57..ef25cfb8e 100644 --- a/server/tests/api/moderation/video-blacklist.ts +++ b/server/tests/api/moderation/video-blacklist.ts @@ -6,10 +6,8 @@ import { orderBy } from 'lodash' import { BlacklistCommand, cleanupTests, - createUser, doubleFollow, flushAndRunMultipleServers, - getMyUserInformation, getMyVideos, getVideosList, ImportsCommand, @@ -21,7 +19,7 @@ import { uploadVideo, waitJobs } from '@shared/extra-utils' -import { User, UserAdminFlag, UserRole, VideoBlacklist, VideoBlacklistType } from '@shared/models' +import { UserAdminFlag, UserRole, VideoBlacklist, VideoBlacklistType } from '@shared/models' const expect = chai.expect @@ -356,9 +354,7 @@ describe('Test video blacklist', function () { { const user = { username: 'user_without_flag', password: 'password' } - await createUser({ - url: servers[0].url, - accessToken: servers[0].accessToken, + await servers[0].usersCommand.create({ username: user.username, adminFlags: UserAdminFlag.NONE, password: user.password, @@ -367,16 +363,13 @@ describe('Test video blacklist', function () { userWithoutFlag = await servers[0].loginCommand.getAccessToken(user) - const res = await getMyUserInformation(servers[0].url, userWithoutFlag) - const body: User = res.body - channelOfUserWithoutFlag = body.videoChannels[0].id + const { videoChannels } = await servers[0].usersCommand.getMyInfo({ token: userWithoutFlag }) + channelOfUserWithoutFlag = videoChannels[0].id } { const user = { username: 'user_with_flag', password: 'password' } - await createUser({ - url: servers[0].url, - accessToken: servers[0].accessToken, + await servers[0].usersCommand.create({ username: user.username, adminFlags: UserAdminFlag.BYPASS_VIDEO_AUTO_BLACKLIST, password: user.password, diff --git a/server/tests/api/notifications/comments-notifications.ts b/server/tests/api/notifications/comments-notifications.ts index ea6055386..62569f810 100644 --- a/server/tests/api/notifications/comments-notifications.ts +++ b/server/tests/api/notifications/comments-notifications.ts @@ -10,7 +10,6 @@ import { MockSmtpServer, prepareNotificationsTest, ServerInfo, - updateMyUser, uploadVideo, waitJobs } from '@shared/extra-utils' @@ -193,17 +192,8 @@ describe('Test comments notifications', function () { token: userToken } - await updateMyUser({ - url: servers[0].url, - accessToken: servers[0].accessToken, - displayName: 'super root name' - }) - - await updateMyUser({ - url: servers[1].url, - accessToken: servers[1].accessToken, - displayName: 'super root 2 name' - }) + await servers[0].usersCommand.updateMe({ displayName: 'super root name' }) + await servers[1].usersCommand.updateMe({ displayName: 'super root 2 name' }) }) it('Should not send a new mention comment notification if I mention the video owner', async function () { diff --git a/server/tests/api/notifications/moderation-notifications.ts b/server/tests/api/notifications/moderation-notifications.ts index 99b434606..0269124c5 100644 --- a/server/tests/api/notifications/moderation-notifications.ts +++ b/server/tests/api/notifications/moderation-notifications.ts @@ -17,13 +17,10 @@ import { checkVideoAutoBlacklistForModerators, checkVideoIsPublished, cleanupTests, - createUser, - generateUserAccessToken, getVideoIdFromUUID, MockInstancesIndex, MockSmtpServer, prepareNotificationsTest, - registerUser, ServerInfo, uploadVideo, wait, @@ -139,8 +136,8 @@ describe('Test moderation notifications', function () { this.timeout(20000) const username = 'user' + new Date().getTime() - const resUser = await createUser({ url: servers[0].url, accessToken: servers[0].accessToken, username, password: 'donald' }) - const accountId = resUser.body.user.account.id + const { account } = await servers[0].usersCommand.create({ username, password: 'donald' }) + const accountId = account.id await servers[0].abusesCommand.report({ accountId, reason: 'super reason' }) @@ -152,7 +149,7 @@ describe('Test moderation notifications', function () { this.timeout(20000) const username = 'user' + new Date().getTime() - const tmpToken = await generateUserAccessToken(servers[0], username) + const tmpToken = await servers[0].usersCommand.generateUserAndToken(username) await uploadVideo(servers[0].url, tmpToken, { name: 'super video' }) await waitJobs(servers) @@ -339,7 +336,7 @@ describe('Test moderation notifications', function () { it('Should send a notification only to moderators when a user registers on the instance', async function () { this.timeout(10000) - await registerUser(servers[0].url, 'user_45', 'password') + await servers[0].usersCommand.register({ username: 'user_45' }) await waitJobs(servers) diff --git a/server/tests/api/notifications/notifications-api.ts b/server/tests/api/notifications/notifications-api.ts index e5864f1c2..f33d8e64d 100644 --- a/server/tests/api/notifications/notifications-api.ts +++ b/server/tests/api/notifications/notifications-api.ts @@ -7,14 +7,13 @@ import { checkNewVideoFromSubscription, cleanupTests, getAllNotificationsSettings, - getMyUserInformation, MockSmtpServer, prepareNotificationsTest, ServerInfo, uploadRandomVideo, waitJobs } from '@shared/extra-utils' -import { User, UserNotification, UserNotificationSettingValue } from '@shared/models' +import { UserNotification, UserNotificationSettingValue } from '@shared/models' const expect = chai.expect @@ -109,15 +108,14 @@ describe('Test notifications API', function () { }) { - const res = await getMyUserInformation(server.url, userToken) - const info = res.body as User + const info = await server.usersCommand.getMyInfo({ token: userToken }) expect(info.notificationSettings.newVideoFromSubscription).to.equal(UserNotificationSettingValue.NONE) } const { name, uuid } = await uploadRandomVideo(server) const check = { web: true, mail: true } - await checkNewVideoFromSubscription({ ...baseParams, ...check }, name, uuid, 'absence') + await checkNewVideoFromSubscription({ ...baseParams, check }, name, uuid, 'absence') }) it('Should only have web notifications', async function () { @@ -129,8 +127,7 @@ describe('Test notifications API', function () { }) { - const res = await getMyUserInformation(server.url, userToken) - const info = res.body as User + const info = await server.usersCommand.getMyInfo({ token: userToken }) expect(info.notificationSettings.newVideoFromSubscription).to.equal(UserNotificationSettingValue.WEB) } @@ -138,12 +135,12 @@ describe('Test notifications API', function () { { const check = { mail: true, web: false } - await checkNewVideoFromSubscription({ ...baseParams, ...check }, name, uuid, 'absence') + await checkNewVideoFromSubscription({ ...baseParams, check }, name, uuid, 'absence') } { const check = { mail: false, web: true } - await checkNewVideoFromSubscription({ ...baseParams, ...check }, name, uuid, 'presence') + await checkNewVideoFromSubscription({ ...baseParams, check }, name, uuid, 'presence') } }) @@ -156,8 +153,7 @@ describe('Test notifications API', function () { }) { - const res = await getMyUserInformation(server.url, userToken) - const info = res.body as User + const info = await server.usersCommand.getMyInfo({ token: userToken }) expect(info.notificationSettings.newVideoFromSubscription).to.equal(UserNotificationSettingValue.EMAIL) } @@ -165,12 +161,12 @@ describe('Test notifications API', function () { { const check = { mail: false, web: true } - await checkNewVideoFromSubscription({ ...baseParams, ...check }, name, uuid, 'absence') + await checkNewVideoFromSubscription({ ...baseParams, check }, name, uuid, 'absence') } { const check = { mail: true, web: false } - await checkNewVideoFromSubscription({ ...baseParams, ...check }, name, uuid, 'presence') + await checkNewVideoFromSubscription({ ...baseParams, check }, name, uuid, 'presence') } }) @@ -186,8 +182,7 @@ describe('Test notifications API', function () { }) { - const res = await getMyUserInformation(server.url, userToken) - const info = res.body as User + const info = await server.usersCommand.getMyInfo({ token: userToken }) expect(info.notificationSettings.newVideoFromSubscription).to.equal( UserNotificationSettingValue.WEB | UserNotificationSettingValue.EMAIL ) diff --git a/server/tests/api/notifications/user-notifications.ts b/server/tests/api/notifications/user-notifications.ts index 4b31edf25..465349fb9 100644 --- a/server/tests/api/notifications/user-notifications.ts +++ b/server/tests/api/notifications/user-notifications.ts @@ -14,7 +14,6 @@ import { MockSmtpServer, prepareNotificationsTest, ServerInfo, - updateMyUser, updateVideo, uploadRandomVideoOnServers, wait, @@ -384,23 +383,14 @@ describe('Test user notifications', function () { token: userAccessToken } - await updateMyUser({ - url: servers[0].url, - accessToken: servers[0].accessToken, - displayName: 'super root name' - }) + await servers[0].usersCommand.updateMe({ displayName: 'super root name' }) - await updateMyUser({ - url: servers[0].url, - accessToken: userAccessToken, + await servers[0].usersCommand.updateMe({ + token: userAccessToken, displayName: myUserName }) - await updateMyUser({ - url: servers[1].url, - accessToken: servers[1].accessToken, - displayName: 'super root 2 name' - }) + await servers[1].usersCommand.updateMe({ displayName: 'super root 2 name' }) await servers[0].channelsCommand.update({ token: userAccessToken, diff --git a/server/tests/api/search/search-activitypub-video-channels.ts b/server/tests/api/search/search-activitypub-video-channels.ts index 3cba2b019..bcc21381c 100644 --- a/server/tests/api/search/search-activitypub-video-channels.ts +++ b/server/tests/api/search/search-activitypub-video-channels.ts @@ -4,13 +4,11 @@ import 'mocha' import * as chai from 'chai' import { cleanupTests, - createUser, flushAndRunMultipleServers, getVideoChannelVideos, SearchCommand, ServerInfo, setAccessTokensToServers, - updateMyUser, updateVideo, uploadVideo, wait, @@ -35,7 +33,7 @@ describe('Test ActivityPub video channels search', function () { await setAccessTokensToServers(servers) { - await createUser({ url: servers[0].url, accessToken: servers[0].accessToken, username: 'user1_server1', password: 'password' }) + await servers[0].usersCommand.create({ username: 'user1_server1', password: 'password' }) const channel = { name: 'channel1_server1', displayName: 'Channel 1 server 1' @@ -45,7 +43,7 @@ describe('Test ActivityPub video channels search', function () { { const user = { username: 'user1_server2', password: 'password' } - await createUser({ url: servers[1].url, accessToken: servers[1].accessToken, username: user.username, password: user.password }) + await servers[1].usersCommand.create({ username: user.username, password: user.password }) userServer2Token = await servers[1].loginCommand.getAccessToken(user) const channel = { @@ -171,7 +169,7 @@ describe('Test ActivityPub video channels search', function () { channelName: 'channel1_server2', attributes: { displayName: 'channel updated' } }) - await updateMyUser({ url: servers[1].url, accessToken: userServer2Token, displayName: 'user updated' }) + await servers[1].usersCommand.updateMe({ token: userServer2Token, displayName: 'user updated' }) await waitJobs(servers) // Expire video channel diff --git a/server/tests/api/search/search-channels.ts b/server/tests/api/search/search-channels.ts index 6c9ee73ce..4d2104708 100644 --- a/server/tests/api/search/search-channels.ts +++ b/server/tests/api/search/search-channels.ts @@ -2,7 +2,7 @@ import 'mocha' import * as chai from 'chai' -import { cleanupTests, createUser, flushAndRunServer, SearchCommand, ServerInfo, setAccessTokensToServers } from '@shared/extra-utils' +import { cleanupTests, flushAndRunServer, SearchCommand, ServerInfo, setAccessTokensToServers } from '@shared/extra-utils' import { VideoChannel } from '@shared/models' const expect = chai.expect @@ -19,7 +19,7 @@ describe('Test channels search', function () { await setAccessTokensToServers([ server ]) { - await createUser({ url: server.url, accessToken: server.accessToken, username: 'user1', password: 'password' }) + await server.usersCommand.create({ username: 'user1', password: 'password' }) const channel = { name: 'squall_channel', displayName: 'Squall channel' diff --git a/server/tests/api/server/bulk.ts b/server/tests/api/server/bulk.ts index a09c21228..20a9a3dc7 100644 --- a/server/tests/api/server/bulk.ts +++ b/server/tests/api/server/bulk.ts @@ -5,7 +5,6 @@ import * as chai from 'chai' import { BulkCommand, cleanupTests, - createUser, doubleFollow, flushAndRunMultipleServers, getVideosList, @@ -38,21 +37,21 @@ describe('Test bulk actions', function () { { const user = { username: 'user1', 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 }) user1Token = await servers[0].loginCommand.getAccessToken(user) } { const user = { username: 'user2', 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 }) user2Token = await servers[0].loginCommand.getAccessToken(user) } { const user = { username: 'user3', password: 'password' } - await createUser({ url: servers[1].url, accessToken: servers[1].accessToken, username: user.username, password: user.password }) + await servers[1].usersCommand.create({ username: user.username, password: user.password }) user3Token = await servers[1].loginCommand.getAccessToken(user) } diff --git a/server/tests/api/server/config.ts b/server/tests/api/server/config.ts index 55cf2a1b8..95dafd378 100644 --- a/server/tests/api/server/config.ts +++ b/server/tests/api/server/config.ts @@ -9,7 +9,6 @@ import { killallServers, makeGetRequest, parallelTests, - registerUser, reRunServer, ServerInfo, setAccessTokensToServers, @@ -225,9 +224,9 @@ describe('Test config', function () { this.timeout(5000) await Promise.all([ - registerUser(server.url, 'user1', 'super password'), - registerUser(server.url, 'user2', 'super password'), - registerUser(server.url, 'user3', 'super password') + server.usersCommand.register({ username: 'user1' }), + server.usersCommand.register({ username: 'user2' }), + server.usersCommand.register({ username: 'user3' }) ]) const data = await server.configCommand.getConfig() diff --git a/server/tests/api/server/email.ts b/server/tests/api/server/email.ts index c64c120e3..422db6ceb 100644 --- a/server/tests/api/server/email.ts +++ b/server/tests/api/server/email.ts @@ -2,23 +2,16 @@ import 'mocha' import * as chai from 'chai' -import { HttpStatusCode } from '../../../../shared/core-utils/miscs/http-error-codes' +import { HttpStatusCode } from '@shared/core-utils' import { - askResetPassword, - askSendVerifyEmail, - blockUser, cleanupTests, - createUser, flushAndRunServer, - resetPassword, + MockSmtpServer, ServerInfo, setAccessTokensToServers, - unblockUser, uploadVideo, - verifyEmail -} from '../../../../shared/extra-utils' -import { MockSmtpServer } from '../../../../shared/extra-utils/mock-servers/mock-email' -import { waitJobs } from '../../../../shared/extra-utils/server/jobs' + waitJobs +} from '@shared/extra-utils' const expect = chai.expect @@ -58,8 +51,8 @@ describe('Test emails', function () { await setAccessTokensToServers([ server ]) { - const res = await createUser({ url: server.url, accessToken: server.accessToken, username: user.username, password: user.password }) - userId = res.body.user.id + const created = await server.usersCommand.create({ username: user.username, password: user.password }) + userId = created.id userAccessToken = await server.loginCommand.getAccessToken(user) } @@ -87,7 +80,7 @@ describe('Test emails', function () { it('Should ask to reset the password', async function () { this.timeout(10000) - await askResetPassword(server.url, 'user_1@example.com') + await server.usersCommand.askResetPassword({ email: 'user_1@example.com' }) await waitJobs(server) expect(emails).to.have.lengthOf(1) @@ -113,15 +106,25 @@ describe('Test emails', function () { }) it('Should not reset the password with an invalid verification string', async function () { - await resetPassword(server.url, userId, verificationString + 'b', 'super_password2', HttpStatusCode.FORBIDDEN_403) + await server.usersCommand.resetPassword({ + userId, + verificationString: verificationString + 'b', + password: 'super_password2', + expectedStatus: HttpStatusCode.FORBIDDEN_403 + }) }) it('Should reset the password', async function () { - await resetPassword(server.url, userId, verificationString, 'super_password2') + await server.usersCommand.resetPassword({ userId, verificationString, password: 'super_password2' }) }) it('Should not reset the password with the same verification string', async function () { - await resetPassword(server.url, userId, verificationString, 'super_password3', HttpStatusCode.FORBIDDEN_403) + await server.usersCommand.resetPassword({ + userId, + verificationString, + password: 'super_password3', + expectedStatus: HttpStatusCode.FORBIDDEN_403 + }) }) it('Should login with this new password', async function () { @@ -132,15 +135,11 @@ describe('Test emails', function () { }) describe('When creating a user without password', function () { + it('Should send a create password email', async function () { this.timeout(10000) - await createUser({ - url: server.url, - accessToken: server.accessToken, - username: 'create_password', - password: '' - }) + await server.usersCommand.create({ username: 'create_password', password: '' }) await waitJobs(server) expect(emails).to.have.lengthOf(2) @@ -166,11 +165,20 @@ describe('Test emails', function () { }) it('Should not reset the password with an invalid verification string', async function () { - await resetPassword(server.url, userId2, verificationString2 + 'c', 'newly_created_password', HttpStatusCode.FORBIDDEN_403) + await server.usersCommand.resetPassword({ + userId: userId2, + verificationString: verificationString2 + 'c', + password: 'newly_created_password', + expectedStatus: HttpStatusCode.FORBIDDEN_403 + }) }) it('Should reset the password', async function () { - await resetPassword(server.url, userId2, verificationString2, 'newly_created_password') + await server.usersCommand.resetPassword({ + userId: userId2, + verificationString: verificationString2, + password: 'newly_created_password' + }) }) it('Should login with this new password', async function () { @@ -207,7 +215,7 @@ describe('Test emails', function () { this.timeout(10000) const reason = 'my super bad reason' - await blockUser(server.url, userId, server.accessToken, HttpStatusCode.NO_CONTENT_204, reason) + await server.usersCommand.banUser({ userId, reason }) await waitJobs(server) expect(emails).to.have.lengthOf(4) @@ -225,7 +233,7 @@ describe('Test emails', function () { it('Should send the notification email when unblocking a user', async function () { this.timeout(10000) - await unblockUser(server.url, userId, server.accessToken, HttpStatusCode.NO_CONTENT_204) + await server.usersCommand.unbanUser({ userId }) await waitJobs(server) expect(emails).to.have.lengthOf(5) @@ -288,7 +296,7 @@ describe('Test emails', function () { it('Should ask to send the verification email', async function () { this.timeout(10000) - await askSendVerifyEmail(server.url, 'user_1@example.com') + await server.usersCommand.askSendVerifyEmail({ email: 'user_1@example.com' }) await waitJobs(server) expect(emails).to.have.lengthOf(8) @@ -314,11 +322,16 @@ describe('Test emails', function () { }) it('Should not verify the email with an invalid verification string', async function () { - await verifyEmail(server.url, userId, verificationString + 'b', false, HttpStatusCode.FORBIDDEN_403) + await server.usersCommand.verifyEmail({ + userId, + verificationString: verificationString + 'b', + isPendingEmail: false, + expectedStatus: HttpStatusCode.FORBIDDEN_403 + }) }) it('Should verify the email', async function () { - await verifyEmail(server.url, userId, verificationString) + await server.usersCommand.verifyEmail({ userId, verificationString }) }) }) diff --git a/server/tests/api/server/follow-constraints.ts b/server/tests/api/server/follow-constraints.ts index 74cdf353b..29ccb264d 100644 --- a/server/tests/api/server/follow-constraints.ts +++ b/server/tests/api/server/follow-constraints.ts @@ -6,7 +6,6 @@ import { HttpStatusCode } from '@shared/core-utils' import { PeerTubeProblemDocument, ServerErrorCode } from '@shared/models' import { cleanupTests, - createUser, doubleFollow, flushAndRunMultipleServers, getAccountVideos, @@ -47,7 +46,7 @@ describe('Test follow constraints', function () { username: 'user1', password: 'super_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) await doubleFollow(servers[0], servers[1]) diff --git a/server/tests/api/server/follows.ts b/server/tests/api/server/follows.ts index c2a0620a5..02d25e67f 100644 --- a/server/tests/api/server/follows.ts +++ b/server/tests/api/server/follows.ts @@ -5,7 +5,6 @@ import * as chai from 'chai' import { cleanupTests, completeVideoCheck, - createUser, dateIsValid, expectAccountFollows, flushAndRunMultipleServers, @@ -327,9 +326,7 @@ describe('Test follows', function () { await uploadVideo(servers[2].url, servers[2].accessToken, { name: 'server3-6' }) { - const user = { username: 'captain', password: 'password' } - await createUser({ url: servers[2].url, accessToken: servers[2].accessToken, username: user.username, password: user.password }) - const userAccessToken = await servers[2].loginCommand.getAccessToken(user) + const userAccessToken = await servers[2].usersCommand.generateUserAndToken('captain') const resVideos = await getVideosList(servers[2].url) video4 = resVideos.body.data.find(v => v.name === 'server3-4') diff --git a/server/tests/api/server/jobs.ts b/server/tests/api/server/jobs.ts index c0b9facff..6854568d3 100644 --- a/server/tests/api/server/jobs.ts +++ b/server/tests/api/server/jobs.ts @@ -30,7 +30,7 @@ describe('Test jobs', function () { }) it('Should create some jobs', async function () { - this.timeout(60000) + this.timeout(120000) await uploadVideo(servers[1].url, servers[1].accessToken, { name: 'video1' }) await uploadVideo(servers[1].url, servers[1].accessToken, { name: 'video2' }) diff --git a/server/tests/api/server/plugins.ts b/server/tests/api/server/plugins.ts index a81ac961a..1fd5e613b 100644 --- a/server/tests/api/server/plugins.ts +++ b/server/tests/api/server/plugins.ts @@ -6,17 +6,15 @@ import { HttpStatusCode } from '@shared/core-utils' import { cleanupTests, flushAndRunServer, - getMyUserInformation, killallServers, PluginsCommand, reRunServer, ServerInfo, setAccessTokensToServers, testHelloWorldRegisteredSettings, - updateMyUser, wait } from '@shared/extra-utils' -import { PluginType, User } from '@shared/models' +import { PluginType } from '@shared/models' const expect = chai.expect @@ -120,14 +118,10 @@ describe('Test plugins', function () { }) it('Should update my default theme', async function () { - await updateMyUser({ - url: server.url, - accessToken: server.accessToken, - theme: 'background-red' - }) + await server.usersCommand.updateMe({ theme: 'background-red' }) - const res = await getMyUserInformation(server.url, server.accessToken) - expect((res.body as User).theme).to.equal('background-red') + const user = await server.usersCommand.getMyInfo() + expect(user.theme).to.equal('background-red') }) it('Should list plugins and themes', async function () { @@ -311,8 +305,8 @@ describe('Test plugins', function () { }) it('Should have updated the user theme', async function () { - const res = await getMyUserInformation(server.url, server.accessToken) - expect((res.body as User).theme).to.equal('instance-default') + const user = await server.usersCommand.getMyInfo() + expect(user.theme).to.equal('instance-default') }) it('Should not install a broken plugin', async function () { diff --git a/server/tests/api/server/reverse-proxy.ts b/server/tests/api/server/reverse-proxy.ts index d9c669571..b8bae161a 100644 --- a/server/tests/api/server/reverse-proxy.ts +++ b/server/tests/api/server/reverse-proxy.ts @@ -6,7 +6,7 @@ import { cleanupTests, flushAndRunServer, getVideo, - registerUser, + ServerInfo, setAccessTokensToServers, uploadVideo, viewVideo, @@ -14,8 +14,8 @@ import { } from '@shared/extra-utils' describe('Test application behind a reverse proxy', function () { - let server = null - let videoId + let server: ServerInfo + let videoId: number before(async function () { this.timeout(30000) @@ -102,22 +102,22 @@ describe('Test application behind a reverse proxy', function () { const user = { username: 'root', password: 'fail' } for (let i = 0; i < 19; i++) { - await server.loginCommand.getAccessToken(user, HttpStatusCode.BAD_REQUEST_400) + await server.loginCommand.login({ user, expectedStatus: HttpStatusCode.BAD_REQUEST_400 }) } - await server.loginCommand.getAccessToken(user, HttpStatusCode.TOO_MANY_REQUESTS_429) + await server.loginCommand.login({ user, expectedStatus: HttpStatusCode.TOO_MANY_REQUESTS_429 }) }) it('Should rate limit signup', async function () { for (let i = 0; i < 10; i++) { try { - await registerUser(server.url, 'test' + i, 'password') + await server.usersCommand.register({ username: 'test' + i }) } catch { // empty } } - await registerUser(server.url, 'test42', 'password', HttpStatusCode.TOO_MANY_REQUESTS_429) + await server.usersCommand.register({ username: 'test42', expectedStatus: HttpStatusCode.TOO_MANY_REQUESTS_429 }) }) it('Should not rate limit failed signup', async function () { @@ -126,10 +126,10 @@ describe('Test application behind a reverse proxy', function () { await wait(7000) for (let i = 0; i < 3; i++) { - await registerUser(server.url, 'test' + i, 'password', HttpStatusCode.CONFLICT_409) + await server.usersCommand.register({ username: 'test' + i, expectedStatus: HttpStatusCode.CONFLICT_409 }) } - await registerUser(server.url, 'test43', 'password', HttpStatusCode.NO_CONTENT_204) + await server.usersCommand.register({ username: 'test43', expectedStatus: HttpStatusCode.NO_CONTENT_204 }) }) diff --git a/server/tests/api/server/stats.ts b/server/tests/api/server/stats.ts index aa26f978d..a35709c26 100644 --- a/server/tests/api/server/stats.ts +++ b/server/tests/api/server/stats.ts @@ -4,7 +4,6 @@ import 'mocha' import * as chai from 'chai' import { cleanupTests, - createUser, doubleFollow, flushAndRunMultipleServers, ServerInfo, @@ -35,7 +34,7 @@ describe('Test stats (excluding redundancy)', function () { await doubleFollow(servers[0], servers[1]) - 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 }) const resVideo = await uploadVideo(servers[0].url, servers[0].accessToken, { fixture: 'video_short.webm' }) const videoUUID = resVideo.body.video.uuid diff --git a/server/tests/api/users/user-subscriptions.ts b/server/tests/api/users/user-subscriptions.ts index 1d0fc35f1..c09a85a32 100644 --- a/server/tests/api/users/user-subscriptions.ts +++ b/server/tests/api/users/user-subscriptions.ts @@ -4,7 +4,6 @@ import 'mocha' import * as chai from 'chai' import { cleanupTests, - createUser, doubleFollow, flushAndRunMultipleServers, getVideosList, @@ -39,7 +38,7 @@ describe('Test users subscriptions', function () { { for (const server of servers) { const user = { username: 'user' + server.serverNumber, 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 }) const accessToken = await server.loginCommand.getAccessToken(user) users.push({ accessToken }) diff --git a/server/tests/api/users/users-multiple-servers.ts b/server/tests/api/users/users-multiple-servers.ts index 99fa08fe2..43e67ee60 100644 --- a/server/tests/api/users/users-multiple-servers.ts +++ b/server/tests/api/users/users-multiple-servers.ts @@ -7,17 +7,12 @@ import { checkTmpIsEmpty, checkVideoFilesWereRemoved, cleanupTests, - createUser, doubleFollow, flushAndRunMultipleServers, getAccountVideos, - getMyUserInformation, - removeUser, ServerInfo, setAccessTokensToServers, testImage, - updateMyAvatar, - updateMyUser, uploadVideo, waitJobs } from '@shared/extra-utils' @@ -56,13 +51,8 @@ describe('Test users with multiple servers', function () { username: 'user1', password: 'password' } - const res = await createUser({ - url: servers[0].url, - accessToken: servers[0].accessToken, - username: user.username, - password: user.password - }) - userId = res.body.user.id + const created = await servers[0].usersCommand.create(user) + userId = created.id userAccessToken = await servers[0].loginCommand.getAccessToken(user) } @@ -77,15 +67,9 @@ describe('Test users with multiple servers', function () { it('Should be able to update my display name', async function () { this.timeout(10000) - await updateMyUser({ - url: servers[0].url, - accessToken: servers[0].accessToken, - displayName: 'my super display name' - }) - - const res = await getMyUserInformation(servers[0].url, servers[0].accessToken) - user = res.body + await servers[0].usersCommand.updateMe({ displayName: 'my super display name' }) + user = await servers[0].usersCommand.getMyInfo() expect(user.account.displayName).to.equal('my super display name') await waitJobs(servers) @@ -94,14 +78,9 @@ describe('Test users with multiple servers', function () { it('Should be able to update my description', async function () { this.timeout(10_000) - await updateMyUser({ - url: servers[0].url, - accessToken: servers[0].accessToken, - description: 'my super description updated' - }) + await servers[0].usersCommand.updateMe({ description: 'my super description updated' }) - const res = await getMyUserInformation(servers[0].url, servers[0].accessToken) - user = res.body + user = await servers[0].usersCommand.getMyInfo() expect(user.account.displayName).to.equal('my super display name') expect(user.account.description).to.equal('my super description updated') @@ -113,15 +92,9 @@ describe('Test users with multiple servers', function () { const fixture = 'avatar2.png' - await updateMyAvatar({ - url: servers[0].url, - accessToken: servers[0].accessToken, - fixture - }) - - const res = await getMyUserInformation(servers[0].url, servers[0].accessToken) - user = res.body + await servers[0].usersCommand.updateMyAvatar({ fixture }) + user = await servers[0].usersCommand.getMyInfo() userAvatarFilename = user.account.avatar.path await testImage(servers[0].url, 'avatar2-resized', userAvatarFilename, '.png') @@ -202,7 +175,7 @@ describe('Test users with multiple servers', function () { expect(videoChannelDeleted).not.to.be.undefined } - await removeUser(servers[0].url, userId, servers[0].accessToken) + await servers[0].usersCommand.remove({ userId }) await waitJobs(servers) diff --git a/server/tests/api/users/users-verification.ts b/server/tests/api/users/users-verification.ts index ade730323..271aa3c7a 100644 --- a/server/tests/api/users/users-verification.ts +++ b/server/tests/api/users/users-verification.ts @@ -3,20 +3,7 @@ import 'mocha' import * as chai from 'chai' import { HttpStatusCode } from '@shared/core-utils' -import { - cleanupTests, - flushAndRunServer, - getMyUserInformation, - getUserInformation, - MockSmtpServer, - registerUser, - ServerInfo, - setAccessTokensToServers, - updateMyUser, - verifyEmail, - waitJobs -} from '@shared/extra-utils' -import { User } from '@shared/models' +import { cleanupTests, flushAndRunServer, MockSmtpServer, ServerInfo, setAccessTokensToServers, waitJobs } from '@shared/extra-utils' const expect = chai.expect @@ -65,7 +52,7 @@ describe('Test users account verification', function () { } }) - await registerUser(server.url, user1.username, user1.password) + await server.usersCommand.register(user1) await waitJobs(server) expectedEmailsLength++ @@ -84,8 +71,8 @@ describe('Test users account verification', function () { userId = parseInt(userIdMatches[1], 10) - const resUserInfo = await getUserInformation(server.url, server.accessToken, userId) - expect(resUserInfo.body.emailVerified).to.be.false + const body = await server.usersCommand.get({ userId }) + expect(body.emailVerified).to.be.false }) it('Should not allow login for user with unverified email', async function () { @@ -94,13 +81,13 @@ describe('Test users account verification', function () { }) it('Should verify the user via email and allow login', async function () { - await verifyEmail(server.url, userId, verificationString) + await server.usersCommand.verifyEmail({ userId, verificationString }) const body = await server.loginCommand.login({ user: user1 }) userAccessToken = body.access_token - const resUserVerified = await getUserInformation(server.url, server.accessToken, userId) - expect(resUserVerified.body.emailVerified).to.be.true + const user = await server.usersCommand.get({ userId }) + expect(user.emailVerified).to.be.true }) it('Should be able to change the user email', async function () { @@ -109,9 +96,8 @@ describe('Test users account verification', function () { let updateVerificationString: string { - await updateMyUser({ - url: server.url, - accessToken: userAccessToken, + await server.usersCommand.updateMe({ + token: userAccessToken, email: 'updated@example.com', currentPassword: user1.password }) @@ -127,19 +113,15 @@ describe('Test users account verification', function () { } { - const res = await getMyUserInformation(server.url, userAccessToken) - const me: User = res.body - + const me = await server.usersCommand.getMyInfo({ token: userAccessToken }) expect(me.email).to.equal('user_1@example.com') expect(me.pendingEmail).to.equal('updated@example.com') } { - await verifyEmail(server.url, userId, updateVerificationString, true) - - const res = await getMyUserInformation(server.url, userAccessToken) - const me: User = res.body + await server.usersCommand.verifyEmail({ userId, verificationString: updateVerificationString, isPendingEmail: true }) + const me = await server.usersCommand.getMyInfo({ token: userAccessToken }) expect(me.email).to.equal('updated@example.com') expect(me.pendingEmail).to.be.null } @@ -157,15 +139,15 @@ describe('Test users account verification', function () { } }) - await registerUser(server.url, user2.username, user2.password) + await server.usersCommand.register(user2) await waitJobs(server) expect(emails).to.have.lengthOf(expectedEmailsLength) const accessToken = await server.loginCommand.getAccessToken(user2) - const resMyUserInfo = await getMyUserInformation(server.url, accessToken) - expect(resMyUserInfo.body.emailVerified).to.be.null + const user = await server.usersCommand.getMyInfo({ token: accessToken }) + expect(user.emailVerified).to.be.null }) it('Should allow login for user with unverified email when setting later enabled', async function () { diff --git a/server/tests/api/users/users.ts b/server/tests/api/users/users.ts index 608bedb8b..30d7e850d 100644 --- a/server/tests/api/users/users.ts +++ b/server/tests/api/users/users.ts @@ -4,37 +4,22 @@ import 'mocha' import * as chai from 'chai' import { HttpStatusCode } from '@shared/core-utils' import { - blockUser, cleanupTests, - createUser, - deleteMe, flushAndRunServer, - getMyUserInformation, - getMyUserVideoQuotaUsed, - getMyUserVideoRating, getMyVideos, - getUserInformation, - getUsersList, - getUsersListPaginationAndSort, getVideosList, killallServers, makePutBodyRequest, rateVideo, - registerUserWithChannel, - removeUser, removeVideo, reRunServer, ServerInfo, setAccessTokensToServers, testImage, - unblockUser, - updateMyAvatar, - updateMyUser, - updateUser, uploadVideo, waitJobs } from '@shared/extra-utils' -import { AbuseState, MyUser, OAuth2ErrorCode, User, UserAdminFlag, UserRole, Video, VideoPlaylistType } from '@shared/models' +import { AbuseState, OAuth2ErrorCode, UserAdminFlag, UserRole, Video, VideoPlaylistType } from '@shared/models' const expect = chai.expect @@ -174,8 +159,7 @@ describe('Test users', function () { it('Should retrieve a video rating', async function () { await rateVideo(server.url, accessToken, videoId, 'like') - const res = await getMyUserVideoRating(server.url, accessToken, videoId) - const rating = res.body + const rating = await server.usersCommand.getMyRating({ token: accessToken, videoId }) expect(rating.videoId).to.equal(videoId) expect(rating.rating).to.equal('like') @@ -222,7 +206,7 @@ describe('Test users', function () { }) it('Should not be able to get the user information', async function () { - await getMyUserInformation(server.url, server.accessToken, HttpStatusCode.UNAUTHORIZED_401) + await server.usersCommand.getMyInfo({ expectedStatus: HttpStatusCode.UNAUTHORIZED_401 }) }) it('Should not be able to upload a video', async function () { @@ -252,7 +236,7 @@ describe('Test users', function () { }) it('Should be able to get my user information again', async function () { - await getMyUserInformation(server.url, server.accessToken) + await server.usersCommand.getMyInfo() }) it('Should have an expired access token', async function () { @@ -264,7 +248,7 @@ describe('Test users', function () { await killallServers([ server ]) await reRunServer(server) - await getMyUserInformation(server.url, server.accessToken, HttpStatusCode.UNAUTHORIZED_401) + await server.usersCommand.getMyInfo({ expectedStatus: HttpStatusCode.UNAUTHORIZED_401 }) }) it('Should not be able to refresh an access token with an expired refresh token', async function () { @@ -286,21 +270,14 @@ describe('Test users', function () { }) it('Should be able to get my user information again', async function () { - await getMyUserInformation(server.url, server.accessToken) + await server.usersCommand.getMyInfo() }) }) describe('Creating a user', function () { it('Should be able to create a new user', async function () { - await createUser({ - url: server.url, - accessToken: accessToken, - username: user.username, - password: user.password, - videoQuota: 2 * 1024 * 1024, - adminFlags: UserAdminFlag.BYPASS_VIDEO_AUTO_BLACKLIST - }) + await server.usersCommand.create({ ...user, videoQuota: 2 * 1024 * 1024, adminFlags: UserAdminFlag.BYPASS_VIDEO_AUTO_BLACKLIST }) }) it('Should be able to login with this user', async function () { @@ -308,11 +285,9 @@ describe('Test users', function () { }) it('Should be able to get user information', async function () { - const res1 = await getMyUserInformation(server.url, accessTokenUser) - const userMe: MyUser = res1.body + const userMe = await server.usersCommand.getMyInfo({ token: accessTokenUser }) - const res2 = await getUserInformation(server.url, server.accessToken, userMe.id, true) - const userGet: User = res2.body + const userGet = await server.usersCommand.get({ userId: userMe.id, withStats: true }) for (const user of [ userMe, userGet ]) { expect(user.username).to.equal('user_1') @@ -356,15 +331,11 @@ describe('Test users', function () { }) it('Should have video quota updated', async function () { - const res = await getMyUserVideoQuotaUsed(server.url, accessTokenUser) - const data = res.body - - expect(data.videoQuotaUsed).to.equal(218910) - - const resUsers = await getUsersList(server.url, server.accessToken) + const quota = await server.usersCommand.getMyQuotaUsed({ token: accessTokenUser }) + expect(quota.videoQuotaUsed).to.equal(218910) - const users: User[] = resUsers.body.data - const tmpUser = users.find(u => u.username === user.username) + const { data } = await server.usersCommand.list() + const tmpUser = data.find(u => u.username === user.username) expect(tmpUser.videoQuotaUsed).to.equal(218910) }) @@ -421,9 +392,7 @@ describe('Test users', function () { } { - const res = await getMyUserVideoQuotaUsed(server.url, accessTokenUser) - const data = res.body - + const data = await server.usersCommand.getMyQuotaUsed({ token: accessTokenUser }) expect(data.videoQuotaUsed).to.be.greaterThan(220000) } }) @@ -432,21 +401,18 @@ describe('Test users', function () { describe('Users listing', function () { it('Should list all the users', async function () { - const res = await getUsersList(server.url, server.accessToken) - const result = res.body - const total = result.total - const users = result.data + const { data, total } = await server.usersCommand.list() expect(total).to.equal(2) - expect(users).to.be.an('array') - expect(users.length).to.equal(2) + expect(data).to.be.an('array') + expect(data.length).to.equal(2) - const user = users[0] + const user = data[0] expect(user.username).to.equal('user_1') expect(user.email).to.equal('user_1@example.com') expect(user.nsfwPolicy).to.equal('display') - const rootUser = users[1] + const rootUser = data[1] expect(rootUser.username).to.equal('root') expect(rootUser.email).to.equal('admin' + server.internalServerNumber + '@example.com') expect(user.nsfwPolicy).to.equal('display') @@ -458,16 +424,12 @@ describe('Test users', function () { }) it('Should list only the first user by username asc', async function () { - const res = await getUsersListPaginationAndSort(server.url, server.accessToken, 0, 1, 'username') - - const result = res.body - const total = result.total - const users = result.data + const { total, data } = await server.usersCommand.list({ start: 0, count: 1, sort: 'username' }) expect(total).to.equal(2) - expect(users.length).to.equal(1) + expect(data.length).to.equal(1) - const user = users[0] + const user = data[0] expect(user.username).to.equal('root') expect(user.email).to.equal('admin' + server.internalServerNumber + '@example.com') expect(user.roleLabel).to.equal('Administrator') @@ -475,84 +437,66 @@ describe('Test users', function () { }) it('Should list only the first user by username desc', async function () { - const res = await getUsersListPaginationAndSort(server.url, server.accessToken, 0, 1, '-username') - const result = res.body - const total = result.total - const users = result.data + const { total, data } = await server.usersCommand.list({ start: 0, count: 1, sort: '-username' }) expect(total).to.equal(2) - expect(users.length).to.equal(1) + expect(data.length).to.equal(1) - const user = users[0] + const user = data[0] expect(user.username).to.equal('user_1') expect(user.email).to.equal('user_1@example.com') expect(user.nsfwPolicy).to.equal('display') }) it('Should list only the second user by createdAt desc', async function () { - const res = await getUsersListPaginationAndSort(server.url, server.accessToken, 0, 1, '-createdAt') - const result = res.body - const total = result.total - const users = result.data - + const { data, total } = await server.usersCommand.list({ start: 0, count: 1, sort: '-createdAt' }) expect(total).to.equal(2) - expect(users.length).to.equal(1) - const user = users[0] + expect(data.length).to.equal(1) + + const user = data[0] expect(user.username).to.equal('user_1') expect(user.email).to.equal('user_1@example.com') expect(user.nsfwPolicy).to.equal('display') }) it('Should list all the users by createdAt asc', async function () { - const res = await getUsersListPaginationAndSort(server.url, server.accessToken, 0, 2, 'createdAt') - const result = res.body - const total = result.total - const users = result.data + const { data, total } = await server.usersCommand.list({ start: 0, count: 2, sort: 'createdAt' }) expect(total).to.equal(2) - expect(users.length).to.equal(2) + expect(data.length).to.equal(2) - expect(users[0].username).to.equal('root') - expect(users[0].email).to.equal('admin' + server.internalServerNumber + '@example.com') - expect(users[0].nsfwPolicy).to.equal('display') + expect(data[0].username).to.equal('root') + expect(data[0].email).to.equal('admin' + server.internalServerNumber + '@example.com') + expect(data[0].nsfwPolicy).to.equal('display') - expect(users[1].username).to.equal('user_1') - expect(users[1].email).to.equal('user_1@example.com') - expect(users[1].nsfwPolicy).to.equal('display') + expect(data[1].username).to.equal('user_1') + expect(data[1].email).to.equal('user_1@example.com') + expect(data[1].nsfwPolicy).to.equal('display') }) it('Should search user by username', async function () { - const res = await getUsersListPaginationAndSort(server.url, server.accessToken, 0, 2, 'createdAt', 'oot') - const users = res.body.data as User[] - - expect(res.body.total).to.equal(1) - expect(users.length).to.equal(1) - - expect(users[0].username).to.equal('root') + const { data, total } = await server.usersCommand.list({ start: 0, count: 2, sort: 'createdAt', search: 'oot' }) + expect(total).to.equal(1) + expect(data.length).to.equal(1) + expect(data[0].username).to.equal('root') }) it('Should search user by email', async function () { { - const res = await getUsersListPaginationAndSort(server.url, server.accessToken, 0, 2, 'createdAt', 'r_1@exam') - const users = res.body.data as User[] - - expect(res.body.total).to.equal(1) - expect(users.length).to.equal(1) - - expect(users[0].username).to.equal('user_1') - expect(users[0].email).to.equal('user_1@example.com') + const { total, data } = await server.usersCommand.list({ start: 0, count: 2, sort: 'createdAt', search: 'r_1@exam' }) + expect(total).to.equal(1) + expect(data.length).to.equal(1) + expect(data[0].username).to.equal('user_1') + expect(data[0].email).to.equal('user_1@example.com') } { - const res = await getUsersListPaginationAndSort(server.url, server.accessToken, 0, 2, 'createdAt', 'example') - const users = res.body.data as User[] - - expect(res.body.total).to.equal(2) - expect(users.length).to.equal(2) - - expect(users[0].username).to.equal('root') - expect(users[1].username).to.equal('user_1') + const { total, data } = await server.usersCommand.list({ start: 0, count: 2, sort: 'createdAt', search: 'example' }) + expect(total).to.equal(2) + expect(data.length).to.equal(2) + expect(data[0].username).to.equal('root') + expect(data[1].username).to.equal('user_1') } }) }) @@ -560,9 +504,8 @@ describe('Test users', function () { describe('Update my account', function () { it('Should update my password', async function () { - await updateMyUser({ - url: server.url, - accessToken: accessTokenUser, + await server.usersCommand.updateMe({ + token: accessTokenUser, currentPassword: 'super password', password: 'new password' }) @@ -572,15 +515,12 @@ describe('Test users', function () { }) it('Should be able to change the NSFW display attribute', async function () { - await updateMyUser({ - url: server.url, - accessToken: accessTokenUser, + await server.usersCommand.updateMe({ + token: accessTokenUser, nsfwPolicy: 'do_not_list' }) - const res = await getMyUserInformation(server.url, accessTokenUser) - const user = res.body - + const user = await server.usersCommand.getMyInfo({ token: accessTokenUser }) expect(user.username).to.equal('user_1') expect(user.email).to.equal('user_1@example.com') expect(user.nsfwPolicy).to.equal('do_not_list') @@ -591,42 +531,33 @@ describe('Test users', function () { }) it('Should be able to change the autoPlayVideo attribute', async function () { - await updateMyUser({ - url: server.url, - accessToken: accessTokenUser, + await server.usersCommand.updateMe({ + token: accessTokenUser, autoPlayVideo: false }) - const res = await getMyUserInformation(server.url, accessTokenUser) - const user = res.body - + const user = await server.usersCommand.getMyInfo({ token: accessTokenUser }) expect(user.autoPlayVideo).to.be.false }) it('Should be able to change the autoPlayNextVideo attribute', async function () { - await updateMyUser({ - url: server.url, - accessToken: accessTokenUser, + await server.usersCommand.updateMe({ + token: accessTokenUser, autoPlayNextVideo: true }) - const res = await getMyUserInformation(server.url, accessTokenUser) - const user = res.body - + const user = await server.usersCommand.getMyInfo({ token: accessTokenUser }) expect(user.autoPlayNextVideo).to.be.true }) it('Should be able to change the email attribute', async function () { - await updateMyUser({ - url: server.url, - accessToken: accessTokenUser, + await server.usersCommand.updateMe({ + token: accessTokenUser, currentPassword: 'new password', email: 'updated@example.com' }) - const res = await getMyUserInformation(server.url, accessTokenUser) - const user = res.body - + const user = await server.usersCommand.getMyInfo({ token: accessTokenUser }) expect(user.username).to.equal('user_1') expect(user.email).to.equal('updated@example.com') expect(user.nsfwPolicy).to.equal('do_not_list') @@ -639,15 +570,9 @@ describe('Test users', function () { it('Should be able to update my avatar with a gif', async function () { const fixture = 'avatar.gif' - await updateMyAvatar({ - url: server.url, - accessToken: accessTokenUser, - fixture - }) - - const res = await getMyUserInformation(server.url, accessTokenUser) - const user = res.body + await server.usersCommand.updateMyAvatar({ token: accessTokenUser, fixture }) + const user = await server.usersCommand.getMyInfo({ token: accessTokenUser }) await testImage(server.url, 'avatar-resized', user.account.avatar.path, '.gif') }) @@ -655,29 +580,17 @@ describe('Test users', function () { for (const extension of [ '.png', '.gif' ]) { const fixture = 'avatar' + extension - await updateMyAvatar({ - url: server.url, - accessToken: accessTokenUser, - fixture - }) - - const res = await getMyUserInformation(server.url, accessTokenUser) - const user = res.body + await server.usersCommand.updateMyAvatar({ token: accessTokenUser, fixture }) + const user = await server.usersCommand.getMyInfo({ token: accessTokenUser }) await testImage(server.url, 'avatar-resized', user.account.avatar.path, extension) } }) it('Should be able to update my display name', async function () { - await updateMyUser({ - url: server.url, - accessToken: accessTokenUser, - displayName: 'new display name' - }) - - const res = await getMyUserInformation(server.url, accessTokenUser) - const user = res.body + await server.usersCommand.updateMe({ token: accessTokenUser, displayName: 'new display name' }) + const user = await server.usersCommand.getMyInfo({ token: accessTokenUser }) expect(user.username).to.equal('user_1') expect(user.email).to.equal('updated@example.com') expect(user.nsfwPolicy).to.equal('do_not_list') @@ -688,15 +601,9 @@ describe('Test users', function () { }) it('Should be able to update my description', async function () { - await updateMyUser({ - url: server.url, - accessToken: accessTokenUser, - description: 'my super description updated' - }) - - const res = await getMyUserInformation(server.url, accessTokenUser) - const user: User = res.body + await server.usersCommand.updateMe({ token: accessTokenUser, description: 'my super description updated' }) + const user = await server.usersCommand.getMyInfo({ token: accessTokenUser }) expect(user.username).to.equal('user_1') expect(user.email).to.equal('updated@example.com') expect(user.nsfwPolicy).to.equal('do_not_list') @@ -710,30 +617,21 @@ describe('Test users', function () { it('Should be able to update my theme', async function () { for (const theme of [ 'background-red', 'default', 'instance-default' ]) { - await updateMyUser({ - url: server.url, - accessToken: accessTokenUser, - theme - }) + await server.usersCommand.updateMe({ token: accessTokenUser, theme }) - const res = await getMyUserInformation(server.url, accessTokenUser) - const body: User = res.body - - expect(body.theme).to.equal(theme) + const user = await server.usersCommand.getMyInfo({ token: accessTokenUser }) + expect(user.theme).to.equal(theme) } }) it('Should be able to update my modal preferences', async function () { - await updateMyUser({ - url: server.url, - accessToken: accessTokenUser, + await server.usersCommand.updateMe({ + token: accessTokenUser, noInstanceConfigWarningModal: true, noWelcomeModal: true }) - const res = await getMyUserInformation(server.url, accessTokenUser) - const user: User = res.body - + const user = await server.usersCommand.getMyInfo({ token: accessTokenUser }) expect(user.noWelcomeModal).to.be.true expect(user.noInstanceConfigWarningModal).to.be.true }) @@ -741,10 +639,9 @@ describe('Test users', function () { describe('Updating another user', function () { it('Should be able to update another user', async function () { - await updateUser({ - url: server.url, + await server.usersCommand.update({ userId, - accessToken, + token: accessToken, email: 'updated2@example.com', emailVerified: true, videoQuota: 42, @@ -753,8 +650,7 @@ describe('Test users', function () { pluginAuth: 'toto' }) - const res = await getUserInformation(server.url, accessToken, userId) - const user = res.body as User + const user = await server.usersCommand.get({ token: accessToken, userId }) expect(user.username).to.equal('user_1') expect(user.email).to.equal('updated2@example.com') @@ -768,28 +664,22 @@ describe('Test users', function () { }) it('Should reset the auth plugin', async function () { - await updateUser({ url: server.url, userId, accessToken, pluginAuth: null }) + await server.usersCommand.update({ userId, token: accessToken, pluginAuth: null }) - const res = await getUserInformation(server.url, accessToken, userId) - const user = res.body as User + const user = await server.usersCommand.get({ token: accessToken, userId }) expect(user.pluginAuth).to.be.null }) it('Should have removed the user token', async function () { - await getMyUserVideoQuotaUsed(server.url, accessTokenUser, HttpStatusCode.UNAUTHORIZED_401) + await server.usersCommand.getMyQuotaUsed({ token: accessTokenUser, expectedStatus: HttpStatusCode.UNAUTHORIZED_401 }) accessTokenUser = await server.loginCommand.getAccessToken(user) }) it('Should be able to update another user password', async function () { - await updateUser({ - url: server.url, - userId, - accessToken, - password: 'password updated' - }) + await server.usersCommand.update({ userId, token: accessToken, password: 'password updated' }) - await getMyUserVideoQuotaUsed(server.url, accessTokenUser, HttpStatusCode.UNAUTHORIZED_401) + await server.usersCommand.getMyQuotaUsed({ token: accessTokenUser, expectedStatus: HttpStatusCode.UNAUTHORIZED_401 }) await server.loginCommand.login({ user, expectedStatus: HttpStatusCode.BAD_REQUEST_400 }) @@ -806,7 +696,7 @@ describe('Test users', function () { describe('Remove a user', function () { it('Should be able to remove this user', async function () { - await removeUser(server.url, userId, accessToken) + await server.usersCommand.remove({ userId, token: accessToken }) }) it('Should not be able to login with this user', async function () { @@ -830,7 +720,7 @@ describe('Test users', function () { const user = { displayName: 'super user 15', username: 'user_15', password: 'my super password' } const channel = { name: 'my_user_15_channel', displayName: 'my channel rocks' } - await registerUserWithChannel({ url: server.url, user, channel }) + await server.usersCommand.register({ ...user, channel }) }) it('Should be able to login with this registered user', async function () { @@ -843,16 +733,12 @@ describe('Test users', function () { }) it('Should have the correct display name', async function () { - const res = await getMyUserInformation(server.url, user15AccessToken) - const user: User = res.body - + const user = await server.usersCommand.getMyInfo({ token: user15AccessToken }) expect(user.account.displayName).to.equal('super user 15') }) it('Should have the correct video quota', async function () { - const res = await getMyUserInformation(server.url, user15AccessToken) - const user = res.body - + const user = await server.usersCommand.getMyInfo({ token: user15AccessToken }) expect(user.videoQuota).to.equal(5 * 1024 * 1024) }) @@ -864,15 +750,15 @@ describe('Test users', function () { it('Should remove me', async function () { { - const res = await getUsersList(server.url, server.accessToken) - expect(res.body.data.find(u => u.username === 'user_15')).to.not.be.undefined + const { data } = await server.usersCommand.list() + expect(data.find(u => u.username === 'user_15')).to.not.be.undefined } - await deleteMe(server.url, user15AccessToken) + await server.usersCommand.deleteMe({ token: user15AccessToken }) { - const res = await getUsersList(server.url, server.accessToken) - expect(res.body.data.find(u => u.username === 'user_15')).to.be.undefined + const { data } = await server.usersCommand.list() + expect(data.find(u => u.username === 'user_15')).to.be.undefined } }) }) @@ -886,49 +772,40 @@ describe('Test users', function () { } it('Should block a user', async function () { - const resUser = await createUser({ - url: server.url, - accessToken: server.accessToken, - username: user16.username, - password: user16.password - }) - user16Id = resUser.body.user.id + const user = await server.usersCommand.create({ ...user16 }) + user16Id = user.id user16AccessToken = await server.loginCommand.getAccessToken(user16) - await getMyUserInformation(server.url, user16AccessToken, HttpStatusCode.OK_200) - await blockUser(server.url, user16Id, server.accessToken) + await server.usersCommand.getMyInfo({ token: user16AccessToken, expectedStatus: HttpStatusCode.OK_200 }) + await server.usersCommand.banUser({ userId: user16Id }) - await getMyUserInformation(server.url, user16AccessToken, HttpStatusCode.UNAUTHORIZED_401) + await server.usersCommand.getMyInfo({ token: user16AccessToken, expectedStatus: HttpStatusCode.UNAUTHORIZED_401 }) await server.loginCommand.login({ user: user16, expectedStatus: HttpStatusCode.BAD_REQUEST_400 }) }) it('Should search user by banned status', async function () { { - const res = await getUsersListPaginationAndSort(server.url, server.accessToken, 0, 2, 'createdAt', undefined, true) - const users = res.body.data as User[] + const { data, total } = await server.usersCommand.list({ start: 0, count: 2, sort: 'createdAt', blocked: true }) + expect(total).to.equal(1) + expect(data.length).to.equal(1) - expect(res.body.total).to.equal(1) - expect(users.length).to.equal(1) - - expect(users[0].username).to.equal(user16.username) + expect(data[0].username).to.equal(user16.username) } { - const res = await getUsersListPaginationAndSort(server.url, server.accessToken, 0, 2, 'createdAt', undefined, false) - const users = res.body.data as User[] - - expect(res.body.total).to.equal(1) - expect(users.length).to.equal(1) + const { data, total } = await server.usersCommand.list({ start: 0, count: 2, sort: 'createdAt', blocked: false }) + expect(total).to.equal(1) + expect(data.length).to.equal(1) - expect(users[0].username).to.not.equal(user16.username) + expect(data[0].username).to.not.equal(user16.username) } }) it('Should unblock a user', async function () { - await unblockUser(server.url, user16Id, server.accessToken) + await server.usersCommand.unbanUser({ userId: user16Id }) user16AccessToken = await server.loginCommand.getAccessToken(user16) - await getMyUserInformation(server.url, user16AccessToken, HttpStatusCode.OK_200) + await server.usersCommand.getMyInfo({ token: user16AccessToken, expectedStatus: HttpStatusCode.OK_200 }) }) }) @@ -941,19 +818,12 @@ describe('Test users', function () { username: 'user_17', password: 'my super password' } - const resUser = await createUser({ - url: server.url, - accessToken: server.accessToken, - username: user17.username, - password: user17.password - }) + const created = await server.usersCommand.create({ ...user17 }) - user17Id = resUser.body.user.id + user17Id = created.id user17AccessToken = await server.loginCommand.getAccessToken(user17) - const res = await getUserInformation(server.url, server.accessToken, user17Id, true) - const user: User = res.body - + const user = await server.usersCommand.get({ userId: user17Id, withStats: true }) expect(user.videosCount).to.equal(0) expect(user.videoCommentsCount).to.equal(0) expect(user.abusesCount).to.equal(0) @@ -969,9 +839,7 @@ describe('Test users', function () { const res1 = await getVideosList(server.url) videoId = res1.body.data.find(video => video.name === videoAttributes.name).id - const res2 = await getUserInformation(server.url, server.accessToken, user17Id, true) - const user: User = res2.body - + const user = await server.usersCommand.get({ userId: user17Id, withStats: true }) expect(user.videosCount).to.equal(1) }) @@ -979,9 +847,7 @@ describe('Test users', function () { const text = 'super comment' await server.commentsCommand.createThread({ token: user17AccessToken, videoId, text }) - const res = await getUserInformation(server.url, server.accessToken, user17Id, true) - const user: User = res.body - + const user = await server.usersCommand.get({ userId: user17Id, withStats: true }) expect(user.videoCommentsCount).to.equal(1) }) @@ -992,17 +858,13 @@ describe('Test users', function () { const body1 = await server.abusesCommand.getAdminList() const abuseId = body1.data[0].id - const res2 = await getUserInformation(server.url, server.accessToken, user17Id, true) - const user2: User = res2.body - + const user2 = await server.usersCommand.get({ userId: user17Id, withStats: true }) expect(user2.abusesCount).to.equal(1) // number of incriminations expect(user2.abusesCreatedCount).to.equal(1) // number of reports created await server.abusesCommand.update({ abuseId, body: { state: AbuseState.ACCEPTED } }) - const res3 = await getUserInformation(server.url, server.accessToken, user17Id, true) - const user3: User = res3.body - + const user3 = await server.usersCommand.get({ userId: user17Id, withStats: true }) expect(user3.abusesAcceptedCount).to.equal(1) // number of reports created accepted }) }) diff --git a/server/tests/api/videos/multiple-servers.ts b/server/tests/api/videos/multiple-servers.ts index 740314bfd..169bb2e23 100644 --- a/server/tests/api/videos/multiple-servers.ts +++ b/server/tests/api/videos/multiple-servers.ts @@ -10,7 +10,6 @@ import { checkVideoFilesWereRemoved, cleanupTests, completeVideoCheck, - createUser, dateIsValid, doubleFollow, flushAndRunMultipleServers, @@ -153,7 +152,7 @@ describe('Test multiple servers', function () { username: 'user1', password: 'super_password' } - await createUser({ url: servers[1].url, accessToken: servers[1].accessToken, username: user.username, password: user.password }) + await servers[1].usersCommand.create({ username: user.username, password: user.password }) const userAccessToken = await servers[1].loginCommand.getAccessToken(user) const videoAttributes = { diff --git a/server/tests/api/videos/resumable-upload.ts b/server/tests/api/videos/resumable-upload.ts index 5845efc86..642c115d0 100644 --- a/server/tests/api/videos/resumable-upload.ts +++ b/server/tests/api/videos/resumable-upload.ts @@ -9,15 +9,13 @@ import { buildAbsoluteFixturePath, cleanupTests, flushAndRunServer, - getMyUserInformation, prepareResumableUpload, sendResumableChunks, ServerInfo, setAccessTokensToServers, - setDefaultVideoChannel, - updateUser + setDefaultVideoChannel } from '@shared/extra-utils' -import { MyUser, VideoPrivacy } from '@shared/models' +import { VideoPrivacy } from '@shared/models' const expect = chai.expect @@ -109,15 +107,10 @@ describe('Test resumable upload', function () { await setAccessTokensToServers([ server ]) await setDefaultVideoChannel([ server ]) - const res = await getMyUserInformation(server.url, server.accessToken) - rootId = (res.body as MyUser).id + const body = await server.usersCommand.getMyInfo() + rootId = body.id - await updateUser({ - url: server.url, - userId: rootId, - accessToken: server.accessToken, - videoQuota: 10_000_000 - }) + await server.usersCommand.update({ userId: rootId, videoQuota: 10_000_000 }) }) describe('Directory cleaning', function () { diff --git a/server/tests/api/videos/video-change-ownership.ts b/server/tests/api/videos/video-change-ownership.ts index 17c738e6f..b0bbd5a0d 100644 --- a/server/tests/api/videos/video-change-ownership.ts +++ b/server/tests/api/videos/video-change-ownership.ts @@ -6,11 +6,9 @@ import { HttpStatusCode } from '../../../../shared/core-utils/miscs/http-error-c import { ChangeOwnershipCommand, cleanupTests, - createUser, doubleFollow, flushAndRunMultipleServers, flushAndRunServer, - getMyUserInformation, getVideo, getVideosList, ServerInfo, @@ -19,21 +17,15 @@ import { uploadVideo } from '../../../../shared/extra-utils' import { waitJobs } from '../../../../shared/extra-utils/server/jobs' -import { User } from '../../../../shared/models/users' import { VideoDetails, VideoPrivacy } from '../../../../shared/models/videos' const expect = chai.expect describe('Test video change ownership - nominal', function () { let servers: ServerInfo[] = [] - const firstUser = { - username: 'first', - password: 'My great password' - } - const secondUser = { - username: 'second', - password: 'My other password' - } + + const firstUser = 'first' + const secondUser = 'second' let firstUserToken = '' let firstUserChannelId: number @@ -65,35 +57,17 @@ describe('Test video change ownership - nominal', function () { } }) - const videoQuota = 42000000 - await createUser({ - url: servers[0].url, - accessToken: servers[0].accessToken, - username: firstUser.username, - password: firstUser.password, - videoQuota: videoQuota - }) - await createUser({ - url: servers[0].url, - accessToken: servers[0].accessToken, - username: secondUser.username, - password: secondUser.password, - videoQuota: videoQuota - }) - - firstUserToken = await servers[0].loginCommand.getAccessToken(firstUser) - secondUserToken = await servers[0].loginCommand.getAccessToken(secondUser) + firstUserToken = await servers[0].usersCommand.generateUserAndToken(firstUser) + secondUserToken = await servers[0].usersCommand.generateUserAndToken(secondUser) { - const res = await getMyUserInformation(servers[0].url, firstUserToken) - const firstUserInformation: User = res.body - firstUserChannelId = firstUserInformation.videoChannels[0].id + const { videoChannels } = await servers[0].usersCommand.getMyInfo({ token: firstUserToken }) + firstUserChannelId = videoChannels[0].id } { - const res = await getMyUserInformation(servers[0].url, secondUserToken) - const secondUserInformation: User = res.body - secondUserChannelId = secondUserInformation.videoChannels[0].id + const { videoChannels } = await servers[0].usersCommand.getMyInfo({ token: secondUserToken }) + secondUserChannelId = videoChannels[0].id } { @@ -140,7 +114,7 @@ describe('Test video change ownership - nominal', function () { it('Should send a request to change ownership of a video', async function () { this.timeout(15000) - await command.create({ token: firstUserToken, videoId: servers[0].video.id, username: secondUser.username }) + await command.create({ token: firstUserToken, videoId: servers[0].video.id, username: secondUser }) }) it('Should only return a request to change ownership for the second user', async function () { @@ -166,7 +140,7 @@ describe('Test video change ownership - nominal', function () { it('Should accept the same change ownership request without crashing', async function () { this.timeout(10000) - await command.create({ token: firstUserToken, videoId: servers[0].video.id, username: secondUser.username }) + await command.create({ token: firstUserToken, videoId: servers[0].video.id, username: secondUser }) }) it('Should not create multiple change ownership requests while one is waiting', async function () { @@ -194,7 +168,7 @@ describe('Test video change ownership - nominal', function () { it('Should send a new request to change ownership of a video', async function () { this.timeout(15000) - await command.create({ token: firstUserToken, videoId: servers[0].video.id, username: secondUser.username }) + await command.create({ token: firstUserToken, videoId: servers[0].video.id, username: secondUser }) }) it('Should return two requests to change ownership for the second user', async function () { @@ -251,7 +225,7 @@ describe('Test video change ownership - nominal', function () { it('Should send a request to change ownership of a live', async function () { this.timeout(15000) - await command.create({ token: firstUserToken, videoId: liveId, username: secondUser.username }) + await command.create({ token: firstUserToken, videoId: liveId, username: secondUser }) const body = await command.list({ token: secondUserToken }) @@ -286,14 +260,9 @@ describe('Test video change ownership - nominal', function () { describe('Test video change ownership - quota too small', function () { let server: ServerInfo - const firstUser = { - username: 'first', - password: 'My great password' - } - const secondUser = { - username: 'second', - password: 'My other password' - } + const firstUser = 'first' + const secondUser = 'second' + let firstUserToken = '' let secondUserToken = '' let lastRequestId: number @@ -305,24 +274,9 @@ describe('Test video change ownership - quota too small', function () { server = await flushAndRunServer(1) await setAccessTokensToServers([ server ]) - const videoQuota = 42000000 - const limitedVideoQuota = 10 - await createUser({ - url: server.url, - accessToken: server.accessToken, - username: firstUser.username, - password: firstUser.password, - videoQuota: videoQuota - }) - await createUser({ - url: server.url, - accessToken: server.accessToken, - username: secondUser.username, - password: secondUser.password, - videoQuota: limitedVideoQuota - }) + await server.usersCommand.create({ username: secondUser, videoQuota: 10 }) - firstUserToken = await server.loginCommand.getAccessToken(firstUser) + firstUserToken = await server.usersCommand.generateUserAndToken(firstUser) secondUserToken = await server.loginCommand.getAccessToken(secondUser) // Upload some videos on the server @@ -345,7 +299,7 @@ describe('Test video change ownership - quota too small', function () { it('Should send a request to change ownership of a video', async function () { this.timeout(15000) - await server.changeOwnershipCommand.create({ token: firstUserToken, videoId: server.video.id, username: secondUser.username }) + await server.changeOwnershipCommand.create({ token: firstUserToken, videoId: server.video.id, username: secondUser }) }) it('Should only return a request to change ownership for the second user', async function () { @@ -371,9 +325,8 @@ describe('Test video change ownership - quota too small', function () { it('Should not be possible to accept the change of ownership from second user because of exceeded quota', async function () { this.timeout(10000) - const secondUserInformationResponse = await getMyUserInformation(server.url, secondUserToken) - const secondUserInformation: User = secondUserInformationResponse.body - const channelId = secondUserInformation.videoChannels[0].id + const { videoChannels } = await server.usersCommand.getMyInfo({ token: secondUserToken }) + const channelId = videoChannels[0].id await server.changeOwnershipCommand.accept({ token: secondUserToken, diff --git a/server/tests/api/videos/video-channels.ts b/server/tests/api/videos/video-channels.ts index 83645640c..2e57cbbff 100644 --- a/server/tests/api/videos/video-channels.ts +++ b/server/tests/api/videos/video-channels.ts @@ -6,21 +6,22 @@ import { basename } from 'path' import { ACTOR_IMAGES_SIZE } from '@server/initializers/constants' import { cleanupTests, - createUser, doubleFollow, flushAndRunMultipleServers, getVideo, getVideoChannelVideos, + ServerInfo, + setAccessTokensToServers, setDefaultVideoChannel, testFileExistsOrNot, testImage, updateVideo, uploadVideo, - wait -} from '../../../../shared/extra-utils' -import { getMyUserInformation, ServerInfo, setAccessTokensToServers, viewVideo } from '../../../../shared/extra-utils/index' -import { waitJobs } from '../../../../shared/extra-utils/server/jobs' -import { User, Video, VideoChannel, VideoDetails } from '../../../../shared/index' + viewVideo, + wait, + waitJobs +} from '@shared/extra-utils' +import { User, Video, VideoChannel, VideoDetails } from '@shared/models' const expect = chai.expect @@ -85,8 +86,7 @@ describe('Test video channels', function () { }) it('Should have two video channels when getting my information', async () => { - const res = await getMyUserInformation(servers[0].url, servers[0].accessToken) - userInfo = res.body + userInfo = await servers[0].usersCommand.getMyInfo() expect(userInfo.videoChannels).to.be.an('array') expect(userInfo.videoChannels).to.have.lengthOf(2) @@ -389,11 +389,11 @@ describe('Test video channels', function () { } { - await createUser({ url: servers[0].url, accessToken: servers[0].accessToken, username: 'toto', password: 'password' }) + await servers[0].usersCommand.create({ username: 'toto', password: 'password' }) const accessToken = await servers[0].loginCommand.getAccessToken({ username: 'toto', password: 'password' }) - const res = await getMyUserInformation(servers[0].url, accessToken) - const videoChannel = res.body.videoChannels[0] + const { videoChannels } = await servers[0].usersCommand.getMyInfo({ token: accessToken }) + const videoChannel = videoChannels[0] expect(videoChannel.name).to.match(/[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}/) } }) diff --git a/server/tests/api/videos/video-comments.ts b/server/tests/api/videos/video-comments.ts index f9bd23646..266824d58 100644 --- a/server/tests/api/videos/video-comments.ts +++ b/server/tests/api/videos/video-comments.ts @@ -5,13 +5,11 @@ import * as chai from 'chai' import { cleanupTests, CommentsCommand, - createUser, dateIsValid, flushAndRunServer, ServerInfo, setAccessTokensToServers, testImage, - updateMyAvatar, uploadVideo } from '@shared/extra-utils' @@ -39,19 +37,9 @@ describe('Test video comments', function () { videoUUID = res.body.video.uuid videoId = res.body.video.id - await updateMyAvatar({ - url: server.url, - accessToken: server.accessToken, - fixture: 'avatar.png' - }) + await server.usersCommand.updateMyAvatar({ fixture: 'avatar.png' }) - await createUser({ - url: server.url, - accessToken: server.accessToken, - username: 'user1', - password: 'password' - }) - userAccessTokenServer1 = await server.loginCommand.getAccessToken('user1', 'password') + userAccessTokenServer1 = await server.usersCommand.generateUserAndToken('user1') command = server.commentsCommand }) diff --git a/server/tests/api/videos/video-imports.ts b/server/tests/api/videos/video-imports.ts index f6ae8cab1..052c052b4 100644 --- a/server/tests/api/videos/video-imports.ts +++ b/server/tests/api/videos/video-imports.ts @@ -7,7 +7,6 @@ import { cleanupTests, doubleFollow, flushAndRunMultipleServers, - getMyUserInformation, getMyVideos, getVideo, getVideosList, @@ -97,13 +96,13 @@ describe('Test video imports', function () { await setAccessTokensToServers(servers) { - const res = await getMyUserInformation(servers[0].url, servers[0].accessToken) - channelIdServer1 = res.body.videoChannels[0].id + const { videoChannels } = await servers[0].usersCommand.getMyInfo() + channelIdServer1 = videoChannels[0].id } { - const res = await getMyUserInformation(servers[1].url, servers[1].accessToken) - channelIdServer2 = res.body.videoChannels[0].id + const { videoChannels } = await servers[1].usersCommand.getMyInfo() + channelIdServer2 = videoChannels[0].id } await doubleFollow(servers[0], servers[1]) diff --git a/server/tests/api/videos/video-nsfw.ts b/server/tests/api/videos/video-nsfw.ts index a30b11ace..9dc26fca6 100644 --- a/server/tests/api/videos/video-nsfw.ts +++ b/server/tests/api/videos/video-nsfw.ts @@ -4,20 +4,17 @@ import 'mocha' import * as chai from 'chai' import { cleanupTests, - createUser, flushAndRunServer, getAccountVideos, - getMyUserInformation, getMyVideos, getVideoChannelVideos, getVideosList, getVideosListWithToken, ServerInfo, setAccessTokensToServers, - updateMyUser, uploadVideo } from '@shared/extra-utils' -import { BooleanBothQuery, CustomConfig, ResultList, User, Video, VideosOverview } from '@shared/models' +import { BooleanBothQuery, CustomConfig, ResultList, Video, VideosOverview } from '@shared/models' const expect = chai.expect @@ -32,8 +29,7 @@ describe('Test video NSFW policy', function () { let customConfig: CustomConfig async function getVideosFunctions (token?: string, query: { nsfw?: BooleanBothQuery } = {}) { - const res = await getMyUserInformation(server.url, server.accessToken) - const user: User = res.body + const user = await server.usersCommand.getMyInfo() const videoChannelName = user.videoChannels[0].name const accountName = user.account.name + '@' + user.account.host const hasQuery = Object.keys(query).length !== 0 @@ -148,13 +144,11 @@ describe('Test video NSFW policy', function () { it('Should create a user having the default nsfw policy', async 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, userAccessToken) - const user = res.body - + const user = await server.usersCommand.getMyInfo({ token: userAccessToken }) expect(user.nsfwPolicy).to.equal('blur') }) @@ -173,11 +167,7 @@ describe('Test video NSFW policy', function () { }) it('Should display NSFW videos with display user NSFW policy', async function () { - await updateMyUser({ - url: server.url, - accessToken: server.accessToken, - nsfwPolicy: 'display' - }) + await server.usersCommand.updateMe({ nsfwPolicy: 'display' }) for (const body of await getVideosFunctions(server.accessToken)) { expect(body.total).to.equal(2) @@ -190,11 +180,7 @@ describe('Test video NSFW policy', function () { }) it('Should not display NSFW videos with do_not_list user NSFW policy', async function () { - await updateMyUser({ - url: server.url, - accessToken: server.accessToken, - nsfwPolicy: 'do_not_list' - }) + await server.usersCommand.updateMe({ nsfwPolicy: 'do_not_list' }) for (const body of await getVideosFunctions(server.accessToken)) { expect(body.total).to.equal(1) diff --git a/server/tests/api/videos/video-playlists.ts b/server/tests/api/videos/video-playlists.ts index 38133e2ce..e57d86c14 100644 --- a/server/tests/api/videos/video-playlists.ts +++ b/server/tests/api/videos/video-playlists.ts @@ -6,13 +6,9 @@ import { HttpStatusCode } from '@shared/core-utils' import { checkPlaylistFilesWereRemoved, cleanupTests, - createUser, doubleFollow, flushAndRunMultipleServers, - generateUserAccessToken, - getMyUserInformation, PlaylistsCommand, - removeUser, ServerInfo, setAccessTokensToServers, setDefaultVideoChannel, @@ -24,7 +20,6 @@ import { waitJobs } from '@shared/extra-utils' import { - User, VideoPlaylist, VideoPlaylistCreateResult, VideoPlaylistElementType, @@ -113,15 +108,7 @@ describe('Test video playlists', function () { nsfwVideoServer1 = (await uploadVideoAndGetId({ server: servers[0], videoName: 'NSFW video', nsfw: true })).id - { - await createUser({ - url: servers[0].url, - accessToken: servers[0].accessToken, - username: 'user1', - password: 'password' - }) - userTokenServer1 = await servers[0].loginCommand.getAccessToken('user1', 'password') - } + userTokenServer1 = await servers[0].usersCommand.generateUserAndToken('user1') await waitJobs(servers) }) @@ -165,7 +152,7 @@ describe('Test video playlists', function () { }) it('Should get private playlist for a classic user', async function () { - const token = await generateUserAccessToken(servers[0], 'toto') + const token = await servers[0].usersCommand.generateUserAndToken('toto') const body = await commands[0].listByAccount({ token, handle: 'toto' }) @@ -1118,19 +1105,10 @@ describe('Test video playlists', function () { it('Should delete an account and delete its playlists', async function () { this.timeout(30000) - const user = { username: 'user_1', password: 'password' } - const res = await createUser({ - url: servers[0].url, - accessToken: servers[0].accessToken, - username: user.username, - password: user.password - }) - - const userId = res.body.user.id - const userAccessToken = await servers[0].loginCommand.getAccessToken(user) + const { userId, token } = await servers[0].usersCommand.generate('user_1') - const resChannel = await getMyUserInformation(servers[0].url, userAccessToken) - const userChannel = (resChannel.body as User).videoChannels[0] + const { videoChannels } = await servers[0].usersCommand.getMyInfo({ token }) + const userChannel = videoChannels[0] await commands[0].create({ attributes: { @@ -1152,7 +1130,7 @@ describe('Test video playlists', function () { } } - await removeUser(servers[0].url, userId, servers[0].accessToken) + await servers[0].usersCommand.remove({ userId }) await waitJobs(servers) { diff --git a/server/tests/api/videos/video-privacy.ts b/server/tests/api/videos/video-privacy.ts index f831dd8a9..4e349e350 100644 --- a/server/tests/api/videos/video-privacy.ts +++ b/server/tests/api/videos/video-privacy.ts @@ -5,7 +5,6 @@ import * as chai from 'chai' import { HttpStatusCode } from '@shared/core-utils' import { cleanupTests, - createUser, doubleFollow, flushAndRunServer, getMyVideos, @@ -125,7 +124,7 @@ describe('Test video privacy', function () { username: 'hello', password: 'super 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 }) anotherUserToken = await servers[0].loginCommand.getAccessToken(user) await getVideoWithToken(servers[0].url, anotherUserToken, privateVideoUUID, HttpStatusCode.FORBIDDEN_403) diff --git a/server/tests/api/videos/videos-filter.ts b/server/tests/api/videos/videos-filter.ts index 519dad646..4aa00cfc4 100644 --- a/server/tests/api/videos/videos-filter.ts +++ b/server/tests/api/videos/videos-filter.ts @@ -5,7 +5,6 @@ import * as chai from 'chai' import { HttpStatusCode } from '../../../../shared/core-utils/miscs/http-error-codes' import { cleanupTests, - createUser, doubleFollow, flushAndRunMultipleServers, makeGetRequest, @@ -60,17 +59,7 @@ describe('Test videos filter', function () { for (const server of servers) { 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 }) server['moderatorAccessToken'] = await server.loginCommand.getAccessToken(moderator) await uploadVideo(server.url, server.accessToken, { name: 'public ' + server.serverNumber }) diff --git a/server/tests/api/videos/videos-history.ts b/server/tests/api/videos/videos-history.ts index 256271bd0..aa0623f7d 100644 --- a/server/tests/api/videos/videos-history.ts +++ b/server/tests/api/videos/videos-history.ts @@ -5,7 +5,6 @@ import * as chai from 'chai' import { HttpStatusCode } from '@shared/core-utils' import { cleanupTests, - createUser, flushAndRunServer, getVideosListWithToken, getVideoWithToken, @@ -14,7 +13,6 @@ import { reRunServer, ServerInfo, setAccessTokensToServers, - updateMyUser, uploadVideo, wait } from '@shared/extra-utils' @@ -59,7 +57,7 @@ describe('Test videos history', function () { username: 'user_1', password: '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) }) @@ -174,9 +172,7 @@ describe('Test videos history', function () { }) it('Should disable videos history', async function () { - await updateMyUser({ - url: server.url, - accessToken: server.accessToken, + await server.usersCommand.updateMe({ videosHistoryEnabled: false }) @@ -184,9 +180,7 @@ describe('Test videos history', function () { }) it('Should re-enable videos history', async function () { - await updateMyUser({ - url: server.url, - accessToken: server.accessToken, + await server.usersCommand.updateMe({ videosHistoryEnabled: true }) diff --git a/server/tests/api/videos/videos-overview.ts b/server/tests/api/videos/videos-overview.ts index ccbc6f4a4..a2da2eaef 100644 --- a/server/tests/api/videos/videos-overview.ts +++ b/server/tests/api/videos/videos-overview.ts @@ -2,15 +2,7 @@ import 'mocha' import * as chai from 'chai' -import { - cleanupTests, - flushAndRunServer, - generateUserAccessToken, - ServerInfo, - setAccessTokensToServers, - uploadVideo, - wait -} from '@shared/extra-utils' +import { cleanupTests, flushAndRunServer, ServerInfo, setAccessTokensToServers, uploadVideo, wait } from '@shared/extra-utils' import { VideosOverview } from '@shared/models' const expect = chai.expect @@ -112,7 +104,7 @@ describe('Test a videos overview', function () { }) it('Should hide muted accounts', async function () { - const token = await generateUserAccessToken(server, 'choco') + const token = await server.usersCommand.generateUserAndToken('choco') await server.blocklistCommand.addToMyBlocklist({ token, account: 'root@' + server.host }) -- 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/activitypub/cleaner.ts | 50 ++- server/tests/api/activitypub/client.ts | 11 +- server/tests/api/activitypub/fetch.ts | 33 +- server/tests/api/activitypub/refresher.ts | 29 +- 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 ++++--- server/tests/api/live/live-constraints.ts | 7 +- server/tests/api/live/live-permanent.ts | 11 +- server/tests/api/live/live-save-replay.ts | 48 ++- server/tests/api/live/live-socket-messages.ts | 16 +- server/tests/api/live/live-views.ts | 18 +- server/tests/api/live/live.ts | 88 +++--- server/tests/api/moderation/abuses.ts | 57 ++-- .../tests/api/moderation/blocklist-notification.ts | 16 +- server/tests/api/moderation/blocklist.ts | 100 +++--- server/tests/api/moderation/video-blacklist.ts | 92 +++--- .../api/notifications/comments-notifications.ts | 46 +-- .../api/notifications/moderation-notifications.ts | 51 ++-- .../tests/api/notifications/notifications-api.ts | 11 +- .../tests/api/notifications/user-notifications.ts | 19 +- server/tests/api/redundancy/manage-redundancy.ts | 15 +- .../tests/api/redundancy/redundancy-constraints.ts | 8 +- server/tests/api/redundancy/redundancy.ts | 57 ++-- .../search/search-activitypub-video-channels.ts | 37 +-- .../search/search-activitypub-video-playlists.ts | 9 +- .../tests/api/search/search-activitypub-videos.ts | 32 +- server/tests/api/search/search-index.ts | 4 +- server/tests/api/search/search-playlists.ts | 9 +- server/tests/api/search/search-videos.ts | 42 ++- server/tests/api/server/bulk.ts | 33 +- server/tests/api/server/config.ts | 11 +- server/tests/api/server/email.ts | 24 +- server/tests/api/server/follow-constraints.ts | 146 +++++---- server/tests/api/server/follows.ts | 65 ++-- server/tests/api/server/handle-down.ts | 73 ++--- server/tests/api/server/jobs.ts | 5 +- server/tests/api/server/logs.ts | 23 +- server/tests/api/server/reverse-proxy.ts | 53 ++-- server/tests/api/server/services.ts | 19 +- server/tests/api/server/stats.ts | 15 +- server/tests/api/server/tracker.ts | 21 +- server/tests/api/users/user-subscriptions.ts | 56 ++-- server/tests/api/users/users-multiple-servers.ts | 34 +-- server/tests/api/users/users.ts | 166 +++++----- server/tests/api/videos/audio-only.ts | 20 +- server/tests/api/videos/multiple-servers.ts | 334 ++++++++++----------- server/tests/api/videos/resumable-upload.ts | 10 +- server/tests/api/videos/single-server.ts | 276 ++++++++--------- server/tests/api/videos/video-captions.ts | 8 +- server/tests/api/videos/video-change-ownership.ts | 38 +-- server/tests/api/videos/video-channels.ts | 69 ++--- server/tests/api/videos/video-comments.ts | 9 +- server/tests/api/videos/video-description.ts | 41 +-- server/tests/api/videos/video-hls.ts | 32 +- server/tests/api/videos/video-imports.ts | 54 ++-- server/tests/api/videos/video-nsfw.ts | 40 +-- .../tests/api/videos/video-playlist-thumbnails.ts | 5 +- server/tests/api/videos/video-playlists.ts | 19 +- server/tests/api/videos/video-privacy.ts | 146 ++++----- server/tests/api/videos/video-schedule-update.ts | 69 ++--- server/tests/api/videos/video-transcoder.ts | 208 ++++++------- server/tests/api/videos/videos-filter.ts | 20 +- server/tests/api/videos/videos-history.ts | 38 +-- server/tests/api/videos/videos-overview.ts | 22 +- server/tests/api/videos/videos-views-cleaner.ts | 14 +- 75 files changed, 1495 insertions(+), 1942 deletions(-) (limited to 'server/tests/api') diff --git a/server/tests/api/activitypub/cleaner.ts b/server/tests/api/activitypub/cleaner.ts index 5b08880bf..dcf758711 100644 --- a/server/tests/api/activitypub/cleaner.ts +++ b/server/tests/api/activitypub/cleaner.ts @@ -6,11 +6,8 @@ import { cleanupTests, doubleFollow, flushAndRunMultipleServers, - getVideo, - rateVideo, ServerInfo, setAccessTokensToServers, - uploadVideoAndGetId, wait, waitJobs } from '@shared/extra-utils' @@ -49,9 +46,9 @@ describe('Test AP cleaner', function () { // Create 1 comment per video // Update 1 remote URL and 1 local URL on - videoUUID1 = (await uploadVideoAndGetId({ server: servers[0], videoName: 'server 1' })).uuid - videoUUID2 = (await uploadVideoAndGetId({ server: servers[1], videoName: 'server 2' })).uuid - videoUUID3 = (await uploadVideoAndGetId({ server: servers[2], videoName: 'server 3' })).uuid + videoUUID1 = (await servers[0].videosCommand.quickUpload({ name: 'server 1' })).uuid + videoUUID2 = (await servers[1].videosCommand.quickUpload({ name: 'server 2' })).uuid + videoUUID3 = (await servers[2].videosCommand.quickUpload({ name: 'server 3' })).uuid videoUUIDs = [ videoUUID1, videoUUID2, videoUUID3 ] @@ -59,7 +56,7 @@ describe('Test AP cleaner', function () { for (const server of servers) { for (const uuid of videoUUIDs) { - await rateVideo(server.url, server.accessToken, uuid, 'like') + await server.videosCommand.rate({ id: uuid, rating: 'like' }) await server.commentsCommand.createThread({ videoId: uuid, text: 'comment' }) } } @@ -70,9 +67,10 @@ describe('Test AP cleaner', function () { it('Should have the correct likes', async function () { for (const server of servers) { for (const uuid of videoUUIDs) { - const res = await getVideo(server.url, uuid) - expect(res.body.likes).to.equal(3) - expect(res.body.dislikes).to.equal(0) + const video = await server.videosCommand.get({ id: uuid }) + + expect(video.likes).to.equal(3) + expect(video.dislikes).to.equal(0) } } }) @@ -90,16 +88,16 @@ describe('Test AP cleaner', function () { // Updated rates of my video { - const res = await getVideo(servers[0].url, videoUUID1) - expect(res.body.likes).to.equal(2) - expect(res.body.dislikes).to.equal(0) + const video = await servers[0].videosCommand.get({ id: videoUUID1 }) + expect(video.likes).to.equal(2) + expect(video.dislikes).to.equal(0) } // Did not update rates of a remote video { - const res = await getVideo(servers[0].url, videoUUID2) - expect(res.body.likes).to.equal(3) - expect(res.body.dislikes).to.equal(0) + const video = await servers[0].videosCommand.get({ id: videoUUID2 }) + expect(video.likes).to.equal(3) + expect(video.dislikes).to.equal(0) } }) @@ -108,7 +106,7 @@ describe('Test AP cleaner', function () { for (const server of servers) { for (const uuid of videoUUIDs) { - await rateVideo(server.url, server.accessToken, uuid, 'dislike') + await server.videosCommand.rate({ id: uuid, rating: 'dislike' }) } } @@ -116,9 +114,9 @@ describe('Test AP cleaner', function () { for (const server of servers) { for (const uuid of videoUUIDs) { - const res = await getVideo(server.url, uuid) - expect(res.body.likes).to.equal(0) - expect(res.body.dislikes).to.equal(3) + const video = await server.videosCommand.get({ id: uuid }) + expect(video.likes).to.equal(0) + expect(video.dislikes).to.equal(3) } } }) @@ -137,16 +135,16 @@ describe('Test AP cleaner', function () { // Updated rates of my video { - const res = await getVideo(servers[0].url, videoUUID1) - expect(res.body.likes).to.equal(0) - expect(res.body.dislikes).to.equal(2) + const video = await servers[0].videosCommand.get({ id: videoUUID1 }) + expect(video.likes).to.equal(0) + expect(video.dislikes).to.equal(2) } // Did not update rates of a remote video { - const res = await getVideo(servers[0].url, videoUUID2) - expect(res.body.likes).to.equal(0) - expect(res.body.dislikes).to.equal(3) + const video = await servers[0].videosCommand.get({ id: videoUUID2 }) + expect(video.likes).to.equal(0) + expect(video.dislikes).to.equal(3) } }) diff --git a/server/tests/api/activitypub/client.ts b/server/tests/api/activitypub/client.ts index e8536a214..0190df04c 100644 --- a/server/tests/api/activitypub/client.ts +++ b/server/tests/api/activitypub/client.ts @@ -2,8 +2,7 @@ import 'mocha' import * as chai from 'chai' -import { VideoPlaylistPrivacy } from '@shared/models' -import { HttpStatusCode } from '../../../../shared/core-utils/miscs/http-error-codes' +import { HttpStatusCode } from '@shared/core-utils' import { cleanupTests, doubleFollow, @@ -11,9 +10,9 @@ import { makeActivityPubGetRequest, ServerInfo, setAccessTokensToServers, - setDefaultVideoChannel, - uploadVideoAndGetId -} from '../../../../shared/extra-utils' + setDefaultVideoChannel +} from '@shared/extra-utils' +import { VideoPlaylistPrivacy } from '@shared/models' const expect = chai.expect @@ -69,7 +68,7 @@ describe('Test activitypub', function () { await setDefaultVideoChannel(servers) { - video = await uploadVideoAndGetId({ server: servers[0], videoName: 'video' }) + video = await await servers[0].videosCommand.quickUpload({ name: 'video' }) } { diff --git a/server/tests/api/activitypub/fetch.ts b/server/tests/api/activitypub/fetch.ts index 162f3ec83..5ab4a85d7 100644 --- a/server/tests/api/activitypub/fetch.ts +++ b/server/tests/api/activitypub/fetch.ts @@ -2,17 +2,7 @@ import 'mocha' import * as chai from 'chai' -import { - cleanupTests, - doubleFollow, - flushAndRunMultipleServers, - getVideosListSort, - ServerInfo, - setAccessTokensToServers, - uploadVideo, - waitJobs -} from '../../../../shared/extra-utils' -import { Video } from '../../../../shared/models/videos' +import { cleanupTests, doubleFollow, flushAndRunMultipleServers, ServerInfo, setAccessTokensToServers, waitJobs } from '@shared/extra-utils' const expect = chai.expect @@ -36,10 +26,9 @@ describe('Test ActivityPub fetcher', function () { const userAccessToken = await servers[0].loginCommand.getAccessToken(user) - await uploadVideo(servers[0].url, servers[0].accessToken, { name: 'video root' }) - const res = await uploadVideo(servers[0].url, servers[0].accessToken, { name: 'bad video root' }) - const badVideoUUID = res.body.video.uuid - await uploadVideo(servers[0].url, userAccessToken, { name: 'video user' }) + await servers[0].videosCommand.upload({ attributes: { name: 'video root' } }) + const { uuid } = await servers[0].videosCommand.upload({ attributes: { name: 'bad video root' } }) + await servers[0].videosCommand.upload({ token: userAccessToken, attributes: { name: 'video user' } }) { const to = 'http://localhost:' + servers[0].port + '/accounts/user1' @@ -48,8 +37,8 @@ describe('Test ActivityPub fetcher', function () { } { - const value = 'http://localhost:' + servers[2].port + '/videos/watch/' + badVideoUUID - await servers[0].sqlCommand.setVideoField(badVideoUUID, 'url', value) + const value = 'http://localhost:' + servers[2].port + '/videos/watch/' + uuid + await servers[0].sqlCommand.setVideoField(uuid, 'url', value) } }) @@ -60,20 +49,18 @@ describe('Test ActivityPub fetcher', function () { await waitJobs(servers) { - const res = await getVideosListSort(servers[0].url, 'createdAt') - expect(res.body.total).to.equal(3) + const { total, data } = await servers[0].videosCommand.list({ sort: 'createdAt' }) - const data: Video[] = res.body.data + expect(total).to.equal(3) expect(data[0].name).to.equal('video root') expect(data[1].name).to.equal('bad video root') expect(data[2].name).to.equal('video user') } { - const res = await getVideosListSort(servers[1].url, 'createdAt') - expect(res.body.total).to.equal(1) + const { total, data } = await servers[1].videosCommand.list({ sort: 'createdAt' }) - const data: Video[] = res.body.data + expect(total).to.equal(1) expect(data[0].name).to.equal('video root') } }) diff --git a/server/tests/api/activitypub/refresher.ts b/server/tests/api/activitypub/refresher.ts index 5a37dbc40..5af4b1edb 100644 --- a/server/tests/api/activitypub/refresher.ts +++ b/server/tests/api/activitypub/refresher.ts @@ -6,14 +6,11 @@ import { cleanupTests, doubleFollow, flushAndRunMultipleServers, - getVideo, killallServers, reRunServer, ServerInfo, setAccessTokensToServers, setDefaultVideoChannel, - uploadVideo, - uploadVideoAndGetId, wait, waitJobs } from '@shared/extra-utils' @@ -37,17 +34,17 @@ describe('Test AP refresher', function () { await setDefaultVideoChannel(servers) { - videoUUID1 = (await uploadVideoAndGetId({ server: servers[1], videoName: 'video1' })).uuid - videoUUID2 = (await uploadVideoAndGetId({ server: servers[1], videoName: 'video2' })).uuid - videoUUID3 = (await uploadVideoAndGetId({ server: servers[1], videoName: 'video3' })).uuid + videoUUID1 = (await servers[1].videosCommand.quickUpload({ name: 'video1' })).uuid + videoUUID2 = (await servers[1].videosCommand.quickUpload({ name: 'video2' })).uuid + videoUUID3 = (await servers[1].videosCommand.quickUpload({ name: 'video3' })).uuid } { - const a1 = await servers[1].usersCommand.generateUserAndToken('user1') - await uploadVideo(servers[1].url, a1, { name: 'video4' }) + const token1 = await servers[1].usersCommand.generateUserAndToken('user1') + await servers[1].videosCommand.upload({ token: token1, attributes: { name: 'video4' } }) - const a2 = await servers[1].usersCommand.generateUserAndToken('user2') - await uploadVideo(servers[1].url, a2, { name: 'video5' }) + const token2 = await servers[1].usersCommand.generateUserAndToken('user2') + await servers[1].videosCommand.upload({ token: token2, attributes: { name: 'video5' } }) } { @@ -75,13 +72,13 @@ describe('Test AP refresher', function () { // Change UUID so the remote server returns a 404 await servers[1].sqlCommand.setVideoField(videoUUID1, 'uuid', '304afe4f-39f9-4d49-8ed7-ac57b86b174f') - await getVideo(servers[0].url, videoUUID1) - await getVideo(servers[0].url, videoUUID2) + await servers[0].videosCommand.get({ id: videoUUID1 }) + await servers[0].videosCommand.get({ id: videoUUID2 }) await waitJobs(servers) - await getVideo(servers[0].url, videoUUID1, HttpStatusCode.NOT_FOUND_404) - await getVideo(servers[0].url, videoUUID2, HttpStatusCode.OK_200) + await servers[0].videosCommand.get({ id: videoUUID1, expectedStatus: HttpStatusCode.NOT_FOUND_404 }) + await servers[0].videosCommand.get({ id: videoUUID2 }) }) it('Should not update a remote video if the remote instance is down', async function () { @@ -94,13 +91,13 @@ describe('Test AP refresher', function () { // Video will need a refresh await wait(10000) - await getVideo(servers[0].url, videoUUID3) + await servers[0].videosCommand.get({ id: videoUUID3 }) // The refresh should fail await waitJobs([ servers[0] ]) await reRunServer(servers[1]) - await getVideo(servers[0].url, videoUUID3, HttpStatusCode.OK_200) + await servers[0].videosCommand.get({ id: videoUUID3 }) }) }) 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 }) }) }) diff --git a/server/tests/api/live/live-constraints.ts b/server/tests/api/live/live-constraints.ts index 290d325d4..7900b1abe 100644 --- a/server/tests/api/live/live-constraints.ts +++ b/server/tests/api/live/live-constraints.ts @@ -2,14 +2,13 @@ import 'mocha' import * as chai from 'chai' -import { VideoDetails, VideoPrivacy } from '@shared/models' +import { VideoPrivacy } from '@shared/models' import { checkLiveCleanup, cleanupTests, ConfigCommand, doubleFollow, flushAndRunMultipleServers, - getVideo, ServerInfo, setAccessTokensToServers, setDefaultVideoChannel, @@ -39,9 +38,7 @@ describe('Test live constraints', function () { async function checkSaveReplay (videoId: string, resolutions = [ 720 ]) { for (const server of servers) { - const res = await getVideo(server.url, videoId) - - const video: VideoDetails = res.body + const video = await server.videosCommand.get({ id: videoId }) expect(video.isLive).to.be.false expect(video.duration).to.be.greaterThan(0) } diff --git a/server/tests/api/live/live-permanent.ts b/server/tests/api/live/live-permanent.ts index 6f4915a6b..707f2edf8 100644 --- a/server/tests/api/live/live-permanent.ts +++ b/server/tests/api/live/live-permanent.ts @@ -2,13 +2,12 @@ import 'mocha' import * as chai from 'chai' -import { LiveVideoCreate, VideoDetails, VideoPrivacy, VideoState } from '@shared/models' +import { LiveVideoCreate, VideoPrivacy, VideoState } from '@shared/models' import { cleanupTests, ConfigCommand, doubleFollow, flushAndRunMultipleServers, - getVideo, ServerInfo, setAccessTokensToServers, setDefaultVideoChannel, @@ -38,8 +37,8 @@ describe('Permanent live', function () { async function checkVideoState (videoId: string, state: VideoState) { for (const server of servers) { - const res = await getVideo(server.url, videoId) - expect((res.body as VideoDetails).state.id).to.equal(state) + const video = await server.videosCommand.get({ id: videoId }) + expect(video.state.id).to.equal(state) } } @@ -123,9 +122,7 @@ describe('Permanent live', function () { await waitJobs(servers) for (const server of servers) { - const res = await getVideo(server.url, videoUUID) - - const videoDetails = res.body as VideoDetails + const videoDetails = await server.videosCommand.get({ id: videoUUID }) expect(videoDetails.streamingPlaylists).to.have.lengthOf(1) } }) diff --git a/server/tests/api/live/live-save-replay.ts b/server/tests/api/live/live-save-replay.ts index 363fb561c..a87a2cd12 100644 --- a/server/tests/api/live/live-save-replay.ts +++ b/server/tests/api/live/live-save-replay.ts @@ -3,26 +3,22 @@ import 'mocha' import * as chai from 'chai' import { FfmpegCommand } from 'fluent-ffmpeg' -import { LiveVideoCreate, VideoDetails, VideoPrivacy, VideoState } from '@shared/models' -import { HttpStatusCode } from '../../../../shared/core-utils/miscs/http-error-codes' +import { HttpStatusCode } from '@shared/core-utils' import { checkLiveCleanup, cleanupTests, ConfigCommand, doubleFollow, flushAndRunMultipleServers, - getVideo, - getVideosList, - removeVideo, ServerInfo, setAccessTokensToServers, setDefaultVideoChannel, stopFfmpeg, testFfmpegStreamError, - updateVideo, wait, waitJobs -} from '../../../../shared/extra-utils' +} from '@shared/extra-utils' +import { LiveVideoCreate, VideoPrivacy, VideoState } from '@shared/models' const expect = chai.expect @@ -34,7 +30,7 @@ describe('Save replay setting', function () { async function createLiveWrapper (saveReplay: boolean) { if (liveVideoUUID) { try { - await removeVideo(servers[0].url, servers[0].accessToken, liveVideoUUID) + await servers[0].videosCommand.remove({ id: liveVideoUUID }) await waitJobs(servers) } catch {} } @@ -50,24 +46,24 @@ describe('Save replay setting', function () { return uuid } - async function checkVideosExist (videoId: string, existsInList: boolean, getStatus?: number) { + async function checkVideosExist (videoId: string, existsInList: boolean, expectedStatus?: number) { for (const server of servers) { const length = existsInList ? 1 : 0 - const resVideos = await getVideosList(server.url) - expect(resVideos.body.data).to.have.lengthOf(length) - expect(resVideos.body.total).to.equal(length) + const { data, total } = await server.videosCommand.list() + expect(data).to.have.lengthOf(length) + expect(total).to.equal(length) - if (getStatus) { - await getVideo(server.url, videoId, getStatus) + if (expectedStatus) { + await server.videosCommand.get({ id: videoId, expectedStatus }) } } } async function checkVideoState (videoId: string, state: VideoState) { for (const server of servers) { - const res = await getVideo(server.url, videoId) - expect((res.body as VideoDetails).state.id).to.equal(state) + const video = await server.videosCommand.get({ id: videoId }) + expect(video.state.id).to.equal(state) } } @@ -179,8 +175,8 @@ describe('Save replay setting', function () { await checkVideosExist(liveVideoUUID, false) - await getVideo(servers[0].url, liveVideoUUID, HttpStatusCode.UNAUTHORIZED_401) - await getVideo(servers[1].url, liveVideoUUID, HttpStatusCode.NOT_FOUND_404) + await servers[0].videosCommand.get({ id: liveVideoUUID, expectedStatus: HttpStatusCode.UNAUTHORIZED_401 }) + await servers[1].videosCommand.get({ id: liveVideoUUID, expectedStatus: HttpStatusCode.NOT_FOUND_404 }) await wait(5000) await waitJobs(servers) @@ -201,7 +197,7 @@ describe('Save replay setting', function () { await Promise.all([ testFfmpegStreamError(ffmpegCommand, true), - removeVideo(servers[0].url, servers[0].accessToken, liveVideoUUID) + servers[0].videosCommand.remove({ id: liveVideoUUID }) ]) await wait(5000) @@ -253,13 +249,13 @@ describe('Save replay setting', function () { it('Should update the saved live and correctly federate the updated attributes', async function () { this.timeout(30000) - await updateVideo(servers[0].url, servers[0].accessToken, liveVideoUUID, { name: 'video updated' }) + await servers[0].videosCommand.update({ id: liveVideoUUID, attributes: { name: 'video updated' } }) await waitJobs(servers) for (const server of servers) { - const res = await getVideo(server.url, liveVideoUUID) - expect(res.body.name).to.equal('video updated') - expect(res.body.isLive).to.be.false + const video = await server.videosCommand.get({ id: liveVideoUUID }) + expect(video.name).to.equal('video updated') + expect(video.isLive).to.be.false } }) @@ -287,8 +283,8 @@ describe('Save replay setting', function () { await checkVideosExist(liveVideoUUID, false) - await getVideo(servers[0].url, liveVideoUUID, HttpStatusCode.UNAUTHORIZED_401) - await getVideo(servers[1].url, liveVideoUUID, HttpStatusCode.NOT_FOUND_404) + await servers[0].videosCommand.get({ id: liveVideoUUID, expectedStatus: HttpStatusCode.UNAUTHORIZED_401 }) + await servers[1].videosCommand.get({ id: liveVideoUUID, expectedStatus: HttpStatusCode.NOT_FOUND_404 }) await wait(5000) await waitJobs(servers) @@ -307,7 +303,7 @@ describe('Save replay setting', function () { await checkVideosExist(liveVideoUUID, true, HttpStatusCode.OK_200) await Promise.all([ - removeVideo(servers[0].url, servers[0].accessToken, liveVideoUUID), + servers[0].videosCommand.remove({ id: liveVideoUUID }), testFfmpegStreamError(ffmpegCommand, true) ]) diff --git a/server/tests/api/live/live-socket-messages.ts b/server/tests/api/live/live-socket-messages.ts index 4a6677c0a..1f3d455a8 100644 --- a/server/tests/api/live/live-socket-messages.ts +++ b/server/tests/api/live/live-socket-messages.ts @@ -7,12 +7,10 @@ import { cleanupTests, doubleFollow, flushAndRunMultipleServers, - getVideoIdFromUUID, ServerInfo, setAccessTokensToServers, setDefaultVideoChannel, stopFfmpeg, - viewVideo, wait, waitJobs, waitUntilLivePublishedOnAllServers @@ -71,7 +69,7 @@ describe('Test live', function () { await waitJobs(servers) { - const videoId = await getVideoIdFromUUID(servers[0].url, liveVideoUUID) + const videoId = await servers[0].videosCommand.getId({ uuid: liveVideoUUID }) const localSocket = servers[0].socketIOCommand.getLiveNotificationSocket() localSocket.on('state-change', data => localStateChanges.push(data.state)) @@ -79,7 +77,7 @@ describe('Test live', function () { } { - const videoId = await getVideoIdFromUUID(servers[1].url, liveVideoUUID) + const videoId = await servers[1].videosCommand.getId({ uuid: liveVideoUUID }) const remoteSocket = servers[1].socketIOCommand.getLiveNotificationSocket() remoteSocket.on('state-change', data => remoteStateChanges.push(data.state)) @@ -119,7 +117,7 @@ describe('Test live', function () { await waitJobs(servers) { - const videoId = await getVideoIdFromUUID(servers[0].url, liveVideoUUID) + const videoId = await servers[0].videosCommand.getId({ uuid: liveVideoUUID }) const localSocket = servers[0].socketIOCommand.getLiveNotificationSocket() localSocket.on('views-change', data => { localLastVideoViews = data.views }) @@ -127,7 +125,7 @@ describe('Test live', function () { } { - const videoId = await getVideoIdFromUUID(servers[1].url, liveVideoUUID) + const videoId = await servers[1].videosCommand.getId({ uuid: liveVideoUUID }) const remoteSocket = servers[1].socketIOCommand.getLiveNotificationSocket() remoteSocket.on('views-change', data => { remoteLastVideoViews = data.views }) @@ -142,8 +140,8 @@ describe('Test live', function () { expect(localLastVideoViews).to.equal(0) expect(remoteLastVideoViews).to.equal(0) - await viewVideo(servers[0].url, liveVideoUUID) - await viewVideo(servers[1].url, liveVideoUUID) + await servers[0].videosCommand.view({ id: liveVideoUUID }) + await servers[1].videosCommand.view({ id: liveVideoUUID }) await waitJobs(servers) await wait(5000) @@ -163,7 +161,7 @@ describe('Test live', function () { const liveVideoUUID = await createLiveWrapper() await waitJobs(servers) - const videoId = await getVideoIdFromUUID(servers[0].url, liveVideoUUID) + const videoId = await servers[0].videosCommand.getId({ uuid: liveVideoUUID }) const socket = servers[0].socketIOCommand.getLiveNotificationSocket() socket.on('state-change', data => stateChanges.push(data.state)) diff --git a/server/tests/api/live/live-views.ts b/server/tests/api/live/live-views.ts index 75f95b167..1951b11a5 100644 --- a/server/tests/api/live/live-views.ts +++ b/server/tests/api/live/live-views.ts @@ -3,17 +3,15 @@ import 'mocha' import * as chai from 'chai' import { FfmpegCommand } from 'fluent-ffmpeg' -import { VideoDetails, VideoPrivacy } from '@shared/models' +import { VideoPrivacy } from '@shared/models' import { cleanupTests, doubleFollow, flushAndRunMultipleServers, - getVideo, ServerInfo, setAccessTokensToServers, setDefaultVideoChannel, stopFfmpeg, - viewVideo, wait, waitJobs, waitUntilLivePublishedOnAllServers @@ -55,9 +53,7 @@ describe('Test live', function () { async function countViews (expected: number) { for (const server of servers) { - const res = await getVideo(server.url, liveVideoId) - const video: VideoDetails = res.body - + const video = await server.videosCommand.get({ id: liveVideoId }) expect(video.views).to.equal(expected) } } @@ -86,8 +82,8 @@ describe('Test live', function () { it('Should view a live twice and display 1 view', async function () { this.timeout(30000) - await viewVideo(servers[0].url, liveVideoId) - await viewVideo(servers[0].url, liveVideoId) + await servers[0].videosCommand.view({ id: liveVideoId }) + await servers[0].videosCommand.view({ id: liveVideoId }) await wait(7000) @@ -108,9 +104,9 @@ describe('Test live', function () { it('Should view a live on a remote and on local and display 2 views', async function () { this.timeout(30000) - await viewVideo(servers[0].url, liveVideoId) - await viewVideo(servers[1].url, liveVideoId) - await viewVideo(servers[1].url, liveVideoId) + await servers[0].videosCommand.view({ id: liveVideoId }) + await servers[1].videosCommand.view({ id: liveVideoId }) + await servers[1].videosCommand.view({ id: liveVideoId }) await wait(7000) await waitJobs(servers) diff --git a/server/tests/api/live/live.ts b/server/tests/api/live/live.ts index 999a49051..c88143982 100644 --- a/server/tests/api/live/live.ts +++ b/server/tests/api/live/live.ts @@ -4,8 +4,7 @@ import 'mocha' import * as chai from 'chai' import { join } from 'path' import { ffprobePromise, getVideoStreamFromFile } from '@server/helpers/ffprobe-utils' -import { LiveVideo, LiveVideoCreate, Video, VideoDetails, VideoPrivacy, VideoState, VideoStreamingPlaylistType } from '@shared/models' -import { HttpStatusCode } from '../../../../shared/core-utils/miscs/http-error-codes' +import { HttpStatusCode } from '@shared/core-utils' import { checkLiveCleanup, checkLiveSegmentHash, @@ -13,14 +12,9 @@ import { cleanupTests, doubleFollow, flushAndRunMultipleServers, - getMyVideosWithFilter, - getVideo, - getVideosList, - getVideosWithFilters, killallServers, LiveCommand, makeRawRequest, - removeVideo, reRunServer, sendRTMPStream, ServerInfo, @@ -29,11 +23,11 @@ import { stopFfmpeg, testFfmpegStreamError, testImage, - uploadVideoAndGetId, wait, waitJobs, waitUntilLivePublishedOnAllServers -} from '../../../../shared/extra-utils' +} from '@shared/extra-utils' +import { LiveVideo, LiveVideoCreate, VideoDetails, VideoPrivacy, VideoState, VideoStreamingPlaylistType } from '@shared/models' const expect = chai.expect @@ -99,8 +93,7 @@ describe('Test live', function () { await waitJobs(servers) for (const server of servers) { - const resVideo = await getVideo(server.url, liveVideoUUID) - const video: VideoDetails = resVideo.body + const video = await server.videosCommand.get({ id: liveVideoUUID }) expect(video.category.id).to.equal(1) expect(video.licence.id).to.equal(2) @@ -154,9 +147,7 @@ describe('Test live', function () { await waitJobs(servers) for (const server of servers) { - const resVideo = await getVideo(server.url, videoId) - const video: VideoDetails = resVideo.body - + const video = await server.videosCommand.get({ id: videoId }) expect(video.privacy.id).to.equal(VideoPrivacy.UNLISTED) expect(video.nsfw).to.be.true @@ -167,10 +158,10 @@ describe('Test live', function () { it('Should not have the live listed since nobody streams into', async function () { for (const server of servers) { - const res = await getVideosList(server.url) + const { total, data } = await server.videosCommand.list() - expect(res.body.total).to.equal(0) - expect(res.body.data).to.have.lengthOf(0) + expect(total).to.equal(0) + expect(data).to.have.lengthOf(0) } }) @@ -204,13 +195,13 @@ describe('Test live', function () { it('Delete the live', async function () { this.timeout(10000) - await removeVideo(servers[0].url, servers[0].accessToken, liveVideoUUID) + await servers[0].videosCommand.remove({ id: liveVideoUUID }) await waitJobs(servers) }) it('Should have the live deleted', async function () { for (const server of servers) { - await getVideo(server.url, liveVideoUUID, HttpStatusCode.NOT_FOUND_404) + await server.videosCommand.get({ id: liveVideoUUID, expectedStatus: HttpStatusCode.NOT_FOUND_404 }) await server.liveCommand.get({ videoId: liveVideoUUID, expectedStatus: HttpStatusCode.NOT_FOUND_404 }) } }) @@ -224,7 +215,7 @@ describe('Test live', function () { before(async function () { this.timeout(120000) - vodVideoId = (await uploadVideoAndGetId({ server: servers[0], videoName: 'vod video' })).uuid + vodVideoId = (await servers[0].videosCommand.quickUpload({ name: 'vod video' })).uuid const liveOptions = { name: 'live', privacy: VideoPrivacy.PUBLIC, channelId: servers[0].videoChannel.id } const live = await commands[0].create({ fields: liveOptions }) @@ -236,19 +227,19 @@ describe('Test live', function () { }) it('Should only display lives', async function () { - const res = await getVideosWithFilters(servers[0].url, { isLive: true }) + const { data, total } = await servers[0].videosCommand.list({ isLive: true }) - expect(res.body.total).to.equal(1) - expect(res.body.data).to.have.lengthOf(1) - expect(res.body.data[0].name).to.equal('live') + expect(total).to.equal(1) + expect(data).to.have.lengthOf(1) + expect(data[0].name).to.equal('live') }) it('Should not display lives', async function () { - const res = await getVideosWithFilters(servers[0].url, { isLive: false }) + const { data, total } = await servers[0].videosCommand.list({ isLive: false }) - expect(res.body.total).to.equal(1) - expect(res.body.data).to.have.lengthOf(1) - expect(res.body.data[0].name).to.equal('vod video') + expect(total).to.equal(1) + expect(data).to.have.lengthOf(1) + expect(data[0].name).to.equal('vod video') }) it('Should display my lives', async function () { @@ -257,24 +248,22 @@ describe('Test live', function () { await stopFfmpeg(ffmpegCommand) await waitJobs(servers) - const res = await getMyVideosWithFilter(servers[0].url, servers[0].accessToken, { isLive: true }) - const videos = res.body.data as Video[] + const { data } = await servers[0].videosCommand.listMyVideos({ isLive: true }) - const result = videos.every(v => v.isLive) + const result = data.every(v => v.isLive) expect(result).to.be.true }) it('Should not display my lives', async function () { - const res = await getMyVideosWithFilter(servers[0].url, servers[0].accessToken, { isLive: false }) - const videos = res.body.data as Video[] + const { data } = await servers[0].videosCommand.listMyVideos({ isLive: false }) - const result = videos.every(v => !v.isLive) + const result = data.every(v => !v.isLive) expect(result).to.be.true }) after(async function () { - await removeVideo(servers[0].url, servers[0].accessToken, vodVideoId) - await removeVideo(servers[0].url, servers[0].accessToken, liveVideoId) + await servers[0].videosCommand.remove({ id: vodVideoId }) + await servers[0].videosCommand.remove({ id: liveVideoId }) }) }) @@ -297,9 +286,9 @@ describe('Test live', function () { const { uuid } = await commands[0].create({ fields: liveAttributes }) const live = await commands[0].get({ videoId: uuid }) - const resVideo = await getVideo(servers[0].url, uuid) + const video = await servers[0].videosCommand.get({ id: uuid }) - return Object.assign(resVideo.body as VideoDetails, live) + return Object.assign(video, live) } it('Should not allow a stream without the appropriate path', async function () { @@ -327,13 +316,12 @@ describe('Test live', function () { it('Should list this live now someone stream into it', async function () { for (const server of servers) { - const res = await getVideosList(server.url) - - expect(res.body.total).to.equal(1) - expect(res.body.data).to.have.lengthOf(1) + const { total, data } = await server.videosCommand.list() - const video: Video = res.body.data[0] + expect(total).to.equal(1) + expect(data).to.have.lengthOf(1) + const video = data[0] expect(video.name).to.equal('user live') expect(video.isLive).to.be.true } @@ -355,7 +343,7 @@ describe('Test live', function () { liveVideo = await createLiveWrapper() - await removeVideo(servers[0].url, servers[0].accessToken, liveVideo.uuid) + await servers[0].videosCommand.remove({ id: liveVideo.uuid }) const command = sendRTMPStream(rtmpUrl + '/live', liveVideo.streamKey) await testFfmpegStreamError(command, true) @@ -379,13 +367,10 @@ describe('Test live', function () { async function testVideoResolutions (liveVideoId: string, resolutions: number[]) { for (const server of servers) { - const resList = await getVideosList(server.url) - const videos: Video[] = resList.body.data - - expect(videos.find(v => v.uuid === liveVideoId)).to.exist + const { data } = await server.videosCommand.list() + expect(data.find(v => v.uuid === liveVideoId)).to.exist - const resVideo = await getVideo(server.url, liveVideoId) - const video: VideoDetails = resVideo.body + const video = await server.videosCommand.get({ id: liveVideoId }) expect(video.streamingPlaylists).to.have.lengthOf(1) @@ -505,8 +490,7 @@ describe('Test live', function () { } for (const server of servers) { - const resVideo = await getVideo(server.url, liveVideoId) - const video: VideoDetails = resVideo.body + const video = await server.videosCommand.get({ id: liveVideoId }) expect(video.state.id).to.equal(VideoState.PUBLISHED) expect(video.duration).to.be.greaterThan(1) diff --git a/server/tests/api/moderation/abuses.ts b/server/tests/api/moderation/abuses.ts index a7119263c..7574b8f4a 100644 --- a/server/tests/api/moderation/abuses.ts +++ b/server/tests/api/moderation/abuses.ts @@ -7,13 +7,8 @@ import { cleanupTests, doubleFollow, flushAndRunMultipleServers, - getVideoIdFromUUID, - getVideosList, - removeVideo, ServerInfo, setAccessTokensToServers, - uploadVideo, - uploadVideoAndGetId, waitJobs } from '@shared/extra-utils' import { AbuseMessage, AbusePredefinedReasonsString, AbuseState, AdminAbuse, UserAbuse } from '@shared/models' @@ -47,28 +42,30 @@ describe('Test abuses', function () { this.timeout(50000) // Upload some videos on each servers - const video1Attributes = { - name: 'my super name for server 1', - description: 'my super description for server 1' + { + const attributes = { + name: 'my super name for server 1', + description: 'my super description for server 1' + } + await servers[0].videosCommand.upload({ attributes }) } - await uploadVideo(servers[0].url, servers[0].accessToken, video1Attributes) - const video2Attributes = { - name: 'my super name for server 2', - description: 'my super description for server 2' + { + const attributes = { + name: 'my super name for server 2', + description: 'my super description for server 2' + } + await servers[1].videosCommand.upload({ attributes }) } - await uploadVideo(servers[1].url, servers[1].accessToken, video2Attributes) // Wait videos propagation, server 2 has transcoding enabled await waitJobs(servers) - const res = await getVideosList(servers[0].url) - const videos = res.body.data - - expect(videos.length).to.equal(2) + const { data } = await servers[0].videosCommand.list() + expect(data.length).to.equal(2) - servers[0].video = videos.find(video => video.name === 'my super name for server 1') - servers[1].video = videos.find(video => video.name === 'my super name for server 2') + servers[0].video = data.find(video => video.name === 'my super name for server 1') + servers[1].video = data.find(video => video.name === 'my super name for server 2') }) it('Should not have abuses', async function () { @@ -130,7 +127,7 @@ describe('Test abuses', function () { this.timeout(10000) const reason = 'my super bad reason 2' - const videoId = await getVideoIdFromUUID(servers[0].url, servers[1].video.uuid) + const videoId = await servers[0].videosCommand.getId({ uuid: servers[1].video.uuid }) await commands[0].report({ videoId, reason }) // We wait requests propagation @@ -203,7 +200,7 @@ describe('Test abuses', function () { this.timeout(10000) { - const videoId = await getVideoIdFromUUID(servers[1].url, servers[0].video.uuid) + const videoId = await servers[1].videosCommand.getId({ uuid: servers[0].video.uuid }) await commands[1].report({ videoId, reason: 'will mute this' }) await waitJobs(servers) @@ -255,7 +252,7 @@ describe('Test abuses', function () { it('Should keep the video abuse when deleting the video', async function () { this.timeout(10000) - await removeVideo(servers[1].url, servers[1].accessToken, abuseServer2.video.uuid) + await servers[1].videosCommand.remove({ id: abuseServer2.video.uuid }) await waitJobs(servers) @@ -279,12 +276,12 @@ describe('Test abuses', function () { const userAccessToken = await servers[0].loginCommand.getAccessToken(user) // upload a third video via this user - const video3Attributes = { + const attributes = { name: 'my second super name for server 1', description: 'my second super description for server 1' } - const resUpload = await uploadVideo(servers[0].url, userAccessToken, video3Attributes) - const video3Id = resUpload.body.video.id + const { id } = await servers[0].videosCommand.upload({ token: userAccessToken, attributes }) + const video3Id = id // resume with the test const reason3 = 'my super bad reason 3' @@ -394,7 +391,7 @@ describe('Test abuses', function () { async function getComment (server: ServerInfo, videoIdArg: number | string) { const videoId = typeof videoIdArg === 'string' - ? await getVideoIdFromUUID(server.url, videoIdArg) + ? await server.videosCommand.getId({ uuid: videoIdArg }) : videoIdArg const { data } = await server.commentsCommand.listThreads({ videoId }) @@ -405,8 +402,8 @@ describe('Test abuses', function () { before(async function () { this.timeout(50000) - servers[0].video = await uploadVideoAndGetId({ server: servers[0], videoName: 'server 1' }) - servers[1].video = await uploadVideoAndGetId({ server: servers[1], videoName: 'server 2' }) + servers[0].video = await await servers[0].videosCommand.quickUpload({ name: 'server 1' }) + servers[1].video = await await servers[1].videosCommand.quickUpload({ name: 'server 2' }) await servers[0].commentsCommand.createThread({ videoId: servers[0].video.id, text: 'comment server 1' }) await servers[1].commentsCommand.createThread({ videoId: servers[1].video.id, text: 'comment server 2' }) @@ -604,7 +601,7 @@ describe('Test abuses', function () { await servers[0].usersCommand.create({ username: 'user_1', password: 'donald' }) const token = await servers[1].usersCommand.generateUserAndToken('user_2') - await uploadVideo(servers[1].url, token, { name: 'super video' }) + await servers[1].videosCommand.upload({ token, attributes: { name: 'super video' } }) await waitJobs(servers) }) @@ -766,7 +763,7 @@ describe('Test abuses', function () { await commands[0].report({ token: userAccessToken, videoId: servers[0].video.id, reason: 'user reason 1' }) - const videoId = await getVideoIdFromUUID(servers[0].url, servers[1].video.uuid) + const videoId = await servers[0].videosCommand.getId({ uuid: servers[1].video.uuid }) await commands[0].report({ token: userAccessToken, videoId, reason: 'user reason 2' }) }) diff --git a/server/tests/api/moderation/blocklist-notification.ts b/server/tests/api/moderation/blocklist-notification.ts index b44bcb012..92a0ec681 100644 --- a/server/tests/api/moderation/blocklist-notification.ts +++ b/server/tests/api/moderation/blocklist-notification.ts @@ -2,15 +2,7 @@ import 'mocha' import * as chai from 'chai' -import { - cleanupTests, - doubleFollow, - flushAndRunMultipleServers, - ServerInfo, - setAccessTokensToServers, - uploadVideo, - waitJobs -} from '@shared/extra-utils' +import { cleanupTests, doubleFollow, flushAndRunMultipleServers, ServerInfo, setAccessTokensToServers, waitJobs } from '@shared/extra-utils' import { UserNotificationType } from '@shared/models' const expect = chai.expect @@ -44,8 +36,8 @@ describe('Test blocklist', function () { await servers[0].notificationsCommand.markAsReadAll({ token: userToken2 }) { - const res = await uploadVideo(servers[0].url, userToken1, { name: 'video' }) - videoUUID = res.body.video.uuid + const { uuid } = await servers[0].videosCommand.upload({ token: userToken1, attributes: { name: 'video' } }) + videoUUID = uuid await waitJobs(servers) } @@ -83,7 +75,7 @@ describe('Test blocklist', function () { }) userToken1 = await servers[0].loginCommand.getAccessToken(user) - await uploadVideo(servers[0].url, userToken1, { name: 'video user 1' }) + await servers[0].videosCommand.upload({ token: userToken1, attributes: { name: 'video user 1' } }) } { diff --git a/server/tests/api/moderation/blocklist.ts b/server/tests/api/moderation/blocklist.ts index c253b5c11..3c3b2d6fd 100644 --- a/server/tests/api/moderation/blocklist.ts +++ b/server/tests/api/moderation/blocklist.ts @@ -8,28 +8,23 @@ import { CommentsCommand, doubleFollow, flushAndRunMultipleServers, - getVideosList, - getVideosListWithToken, ServerInfo, setAccessTokensToServers, - uploadVideo, waitJobs } from '@shared/extra-utils' -import { UserNotificationType, Video } from '@shared/models' +import { UserNotificationType } from '@shared/models' const expect = chai.expect async function checkAllVideos (server: ServerInfo, token: string) { { - const res = await getVideosListWithToken(server.url, token) - - expect(res.body.data).to.have.lengthOf(5) + const { data } = await server.videosCommand.listWithToken({ token }) + expect(data).to.have.lengthOf(5) } { - const res = await getVideosList(server.url) - - expect(res.body.data).to.have.lengthOf(5) + const { data } = await server.videosCommand.list() + expect(data).to.have.lengthOf(5) } } @@ -93,7 +88,7 @@ describe('Test blocklist', function () { await servers[0].usersCommand.create({ username: user.username, password: user.password }) userToken1 = await servers[0].loginCommand.getAccessToken(user) - await uploadVideo(servers[0].url, userToken1, { name: 'video user 1' }) + await servers[0].videosCommand.upload({ token: userToken1, attributes: { name: 'video user 1' } }) } { @@ -108,22 +103,22 @@ describe('Test blocklist', function () { await servers[1].usersCommand.create({ username: user.username, password: user.password }) userToken2 = await servers[1].loginCommand.getAccessToken(user) - await uploadVideo(servers[1].url, userToken2, { name: 'video user 2' }) + await servers[1].videosCommand.upload({ token: userToken2, attributes: { name: 'video user 2' } }) } { - const res = await uploadVideo(servers[0].url, servers[0].accessToken, { name: 'video server 1' }) - videoUUID1 = res.body.video.uuid + const { uuid } = await servers[0].videosCommand.upload({ attributes: { name: 'video server 1' } }) + videoUUID1 = uuid } { - const res = await uploadVideo(servers[1].url, servers[1].accessToken, { name: 'video server 2' }) - videoUUID2 = res.body.video.uuid + const { uuid } = await servers[1].videosCommand.upload({ attributes: { name: 'video server 2' } }) + videoUUID2 = uuid } { - const res = await uploadVideo(servers[0].url, servers[0].accessToken, { name: 'video 2 server 1' }) - videoUUID3 = res.body.video.uuid + const { uuid } = await servers[0].videosCommand.upload({ attributes: { name: 'video 2 server 1' } }) + videoUUID3 = uuid } await doubleFollow(servers[0], servers[1]) @@ -164,12 +159,11 @@ describe('Test blocklist', function () { }) it('Should hide its videos', async function () { - const res = await getVideosListWithToken(servers[0].url, servers[0].accessToken) + const { data } = await servers[0].videosCommand.listWithToken() - const videos: Video[] = res.body.data - expect(videos).to.have.lengthOf(4) + expect(data).to.have.lengthOf(4) - const v = videos.find(v => v.name === 'video user 2') + const v = data.find(v => v.name === 'video user 2') expect(v).to.be.undefined }) @@ -178,12 +172,11 @@ describe('Test blocklist', function () { }) it('Should hide its videos', async function () { - const res = await getVideosListWithToken(servers[0].url, servers[0].accessToken) + const { data } = await servers[0].videosCommand.listWithToken() - const videos: Video[] = res.body.data - expect(videos).to.have.lengthOf(3) + expect(data).to.have.lengthOf(3) - const v = videos.find(v => v.name === 'video user 1') + const v = data.find(v => v.name === 'video user 1') expect(v).to.be.undefined }) @@ -313,12 +306,10 @@ describe('Test blocklist', function () { }) it('Should display its videos', async function () { - const res = await getVideosListWithToken(servers[0].url, servers[0].accessToken) + const { data } = await servers[0].videosCommand.listWithToken() + expect(data).to.have.lengthOf(4) - const videos: Video[] = res.body.data - expect(videos).to.have.lengthOf(4) - - const v = videos.find(v => v.name === 'video user 2') + const v = data.find(v => v.name === 'video user 2') expect(v).not.to.be.undefined }) @@ -387,13 +378,12 @@ describe('Test blocklist', function () { }) it('Should hide its videos', async function () { - const res = await getVideosListWithToken(servers[0].url, servers[0].accessToken) + const { data } = await servers[0].videosCommand.listWithToken() - const videos: Video[] = res.body.data - expect(videos).to.have.lengthOf(3) + expect(data).to.have.lengthOf(3) - const v1 = videos.find(v => v.name === 'video user 2') - const v2 = videos.find(v => v.name === 'video server 2') + const v1 = data.find(v => v.name === 'video user 2') + const v2 = data.find(v => v.name === 'video server 2') expect(v1).to.be.undefined expect(v2).to.be.undefined @@ -498,12 +488,11 @@ describe('Test blocklist', function () { it('Should hide its videos', async function () { for (const token of [ userModeratorToken, servers[0].accessToken ]) { - const res = await getVideosListWithToken(servers[0].url, token) + const { data } = await servers[0].videosCommand.listWithToken({ token }) - const videos: Video[] = res.body.data - expect(videos).to.have.lengthOf(4) + expect(data).to.have.lengthOf(4) - const v = videos.find(v => v.name === 'video user 2') + const v = data.find(v => v.name === 'video user 2') expect(v).to.be.undefined } }) @@ -514,12 +503,11 @@ describe('Test blocklist', function () { it('Should hide its videos', async function () { for (const token of [ userModeratorToken, servers[0].accessToken ]) { - const res = await getVideosListWithToken(servers[0].url, token) + const { data } = await servers[0].videosCommand.listWithToken({ token }) - const videos: Video[] = res.body.data - expect(videos).to.have.lengthOf(3) + expect(data).to.have.lengthOf(3) - const v = videos.find(v => v.name === 'video user 1') + const v = data.find(v => v.name === 'video user 1') expect(v).to.be.undefined } }) @@ -593,12 +581,10 @@ describe('Test blocklist', function () { it('Should display its videos', async function () { for (const token of [ userModeratorToken, servers[0].accessToken ]) { - const res = await getVideosListWithToken(servers[0].url, token) - - const videos: Video[] = res.body.data - expect(videos).to.have.lengthOf(4) + const { data } = await servers[0].videosCommand.listWithToken({ token }) + expect(data).to.have.lengthOf(4) - const v = videos.find(v => v.name === 'video user 2') + const v = data.find(v => v.name === 'video user 2') expect(v).not.to.be.undefined } }) @@ -652,15 +638,17 @@ describe('Test blocklist', function () { it('Should hide its videos', async function () { for (const token of [ userModeratorToken, servers[0].accessToken ]) { - const res1 = await getVideosList(servers[0].url) - const res2 = await getVideosListWithToken(servers[0].url, token) + const requests = [ + servers[0].videosCommand.list(), + servers[0].videosCommand.listWithToken({ token }) + ] - for (const res of [ res1, res2 ]) { - const videos: Video[] = res.body.data - expect(videos).to.have.lengthOf(3) + for (const req of requests) { + const { data } = await req + expect(data).to.have.lengthOf(3) - const v1 = videos.find(v => v.name === 'video user 2') - const v2 = videos.find(v => v.name === 'video server 2') + const v1 = data.find(v => v.name === 'video user 2') + const v2 = data.find(v => v.name === 'video server 2') expect(v1).to.be.undefined expect(v2).to.be.undefined diff --git a/server/tests/api/moderation/video-blacklist.ts b/server/tests/api/moderation/video-blacklist.ts index ef25cfb8e..2f2e678e7 100644 --- a/server/tests/api/moderation/video-blacklist.ts +++ b/server/tests/api/moderation/video-blacklist.ts @@ -8,15 +8,11 @@ import { cleanupTests, doubleFollow, flushAndRunMultipleServers, - getMyVideos, - getVideosList, ImportsCommand, killallServers, reRunServer, ServerInfo, setAccessTokensToServers, - updateVideo, - uploadVideo, waitJobs } from '@shared/extra-utils' import { UserAdminFlag, UserRole, VideoBlacklist, VideoBlacklistType } from '@shared/models' @@ -29,10 +25,9 @@ describe('Test video blacklist', function () { let command: BlacklistCommand async function blacklistVideosOnServer (server: ServerInfo) { - const res = await getVideosList(server.url) + const { data } = await server.videosCommand.list() - const videos = res.body.data - for (const video of videos) { + for (const video of data) { await server.blacklistCommand.add({ videoId: video.id, reason: 'super reason' }) } } @@ -50,8 +45,8 @@ describe('Test video blacklist', function () { await doubleFollow(servers[0], servers[1]) // Upload 2 videos on server 2 - await uploadVideo(servers[1].url, servers[1].accessToken, { name: 'My 1st video', description: 'A video on server 2' }) - await uploadVideo(servers[1].url, servers[1].accessToken, { name: 'My 2nd video', description: 'A video on server 2' }) + await servers[1].videosCommand.upload({ attributes: { name: 'My 1st video', description: 'A video on server 2' } }) + await servers[1].videosCommand.upload({ attributes: { name: 'My 2nd video', description: 'A video on server 2' } }) // Wait videos propagation, server 2 has transcoding enabled await waitJobs(servers) @@ -66,11 +61,11 @@ describe('Test video blacklist', function () { it('Should not have the video blacklisted in videos list/search on server 1', async function () { { - const res = await getVideosList(servers[0].url) + const { total, data } = await servers[0].videosCommand.list() - expect(res.body.total).to.equal(0) - expect(res.body.data).to.be.an('array') - expect(res.body.data.length).to.equal(0) + expect(total).to.equal(0) + expect(data).to.be.an('array') + expect(data.length).to.equal(0) } { @@ -84,11 +79,11 @@ describe('Test video blacklist', function () { it('Should have the blacklisted video in videos list/search on server 2', async function () { { - const res = await getVideosList(servers[1].url) + const { total, data } = await servers[1].videosCommand.list() - expect(res.body.total).to.equal(2) - expect(res.body.data).to.be.an('array') - expect(res.body.data.length).to.equal(2) + expect(total).to.equal(2) + expect(data).to.be.an('array') + expect(data.length).to.equal(2) } { @@ -186,12 +181,12 @@ describe('Test video blacklist', function () { it('Should display blacklisted videos', async function () { await blacklistVideosOnServer(servers[1]) - const res = await getMyVideos(servers[1].url, servers[1].accessToken, 0, 5) + const { total, data } = await servers[1].videosCommand.listMyVideos() - expect(res.body.total).to.equal(2) - expect(res.body.data).to.have.lengthOf(2) + expect(total).to.equal(2) + expect(data).to.have.lengthOf(2) - for (const video of res.body.data) { + for (const video of data) { expect(video.blacklisted).to.be.true expect(video.blacklistedReason).to.equal('super reason') } @@ -203,10 +198,10 @@ describe('Test video blacklist', function () { let blacklist = [] it('Should not have any video in videos list on server 1', async function () { - const res = await getVideosList(servers[0].url) - expect(res.body.total).to.equal(0) - expect(res.body.data).to.be.an('array') - expect(res.body.data.length).to.equal(0) + const { total, data } = await servers[0].videosCommand.list() + expect(total).to.equal(0) + expect(data).to.be.an('array') + expect(data.length).to.equal(0) }) it('Should remove a video from the blacklist on server 1', async function () { @@ -220,15 +215,14 @@ describe('Test video blacklist', function () { }) it('Should have the ex-blacklisted video in videos list on server 1', async function () { - const res = await getVideosList(servers[0].url) - expect(res.body.total).to.equal(1) + const { total, data } = await servers[0].videosCommand.list() + expect(total).to.equal(1) - const videos = res.body.data - expect(videos).to.be.an('array') - expect(videos.length).to.equal(1) + expect(data).to.be.an('array') + expect(data.length).to.equal(1) - expect(videos[0].name).to.equal(videoToRemove.video.name) - expect(videos[0].id).to.equal(videoToRemove.video.id) + expect(data[0].name).to.equal(videoToRemove.video.name) + expect(data[0].id).to.equal(videoToRemove.video.id) }) it('Should not have the ex-blacklisted video in videos blacklist list on server 1', async function () { @@ -250,12 +244,12 @@ describe('Test video blacklist', function () { this.timeout(10000) { - const res = await uploadVideo(servers[0].url, servers[0].accessToken, { name: 'Video 3' }) - video3UUID = res.body.video.uuid + const { uuid } = await servers[0].videosCommand.upload({ attributes: { name: 'Video 3' } }) + video3UUID = uuid } { - const res = await uploadVideo(servers[0].url, servers[0].accessToken, { name: 'Video 4' }) - video4UUID = res.body.video.uuid + const { uuid } = await servers[0].videosCommand.upload({ attributes: { name: 'Video 4' } }) + video4UUID = uuid } await waitJobs(servers) @@ -269,13 +263,13 @@ describe('Test video blacklist', function () { await waitJobs(servers) { - const res = await getVideosList(servers[0].url) - expect(res.body.data.find(v => v.uuid === video3UUID)).to.be.undefined + const { data } = await servers[0].videosCommand.list() + expect(data.find(v => v.uuid === video3UUID)).to.be.undefined } { - const res = await getVideosList(servers[1].url) - expect(res.body.data.find(v => v.uuid === video3UUID)).to.not.be.undefined + const { data } = await servers[1].videosCommand.list() + expect(data.find(v => v.uuid === video3UUID)).to.not.be.undefined } }) @@ -287,21 +281,21 @@ describe('Test video blacklist', function () { await waitJobs(servers) for (const server of servers) { - const res = await getVideosList(server.url) - expect(res.body.data.find(v => v.uuid === video4UUID)).to.be.undefined + const { data } = await server.videosCommand.list() + expect(data.find(v => v.uuid === video4UUID)).to.be.undefined } }) it('Should have the video unfederated even after an Update AP message', async function () { this.timeout(10000) - await updateVideo(servers[0].url, servers[0].accessToken, video4UUID, { description: 'super description' }) + await servers[0].videosCommand.update({ id: video4UUID, attributes: { description: 'super description' } }) await waitJobs(servers) for (const server of servers) { - const res = await getVideosList(server.url) - expect(res.body.data.find(v => v.uuid === video4UUID)).to.be.undefined + const { data } = await server.videosCommand.list() + expect(data.find(v => v.uuid === video4UUID)).to.be.undefined } }) @@ -324,8 +318,8 @@ describe('Test video blacklist', function () { await waitJobs(servers) for (const server of servers) { - const res = await getVideosList(server.url) - expect(res.body.data.find(v => v.uuid === video4UUID)).to.not.be.undefined + const { data } = await server.videosCommand.list() + expect(data.find(v => v.uuid === video4UUID)).to.not.be.undefined } }) @@ -383,7 +377,7 @@ describe('Test video blacklist', function () { }) it('Should auto blacklist a video on upload', async function () { - await uploadVideo(servers[0].url, userWithoutFlag, { name: 'blacklisted' }) + await servers[0].videosCommand.upload({ token: userWithoutFlag, attributes: { name: 'blacklisted' } }) const body = await command.list({ type: VideoBlacklistType.AUTO_BEFORE_PUBLISHED }) expect(body.total).to.equal(1) @@ -419,7 +413,7 @@ describe('Test video blacklist', function () { }) it('Should not auto blacklist a video on upload if the user has the bypass blacklist flag', async function () { - await uploadVideo(servers[0].url, userWithFlag, { name: 'not blacklisted' }) + await servers[0].videosCommand.upload({ token: userWithFlag, attributes: { name: 'not blacklisted' } }) const body = await command.list({ type: VideoBlacklistType.AUTO_BEFORE_PUBLISHED }) expect(body.total).to.equal(3) diff --git a/server/tests/api/notifications/comments-notifications.ts b/server/tests/api/notifications/comments-notifications.ts index 62569f810..a74b38e8a 100644 --- a/server/tests/api/notifications/comments-notifications.ts +++ b/server/tests/api/notifications/comments-notifications.ts @@ -10,7 +10,6 @@ import { MockSmtpServer, prepareNotificationsTest, ServerInfo, - uploadVideo, waitJobs } from '@shared/extra-utils' import { UserNotification } from '@shared/models' @@ -53,8 +52,7 @@ describe('Test comments notifications', function () { it('Should not send a new comment notification after a comment on another video', async function () { this.timeout(20000) - const resVideo = await uploadVideo(servers[0].url, servers[0].accessToken, { name: 'super video' }) - const uuid = resVideo.body.video.uuid + const { uuid } = await servers[0].videosCommand.upload({ attributes: { name: 'super video' } }) const created = await servers[0].commentsCommand.createThread({ videoId: uuid, text: 'comment' }) const commentId = created.id @@ -66,8 +64,7 @@ describe('Test comments notifications', function () { it('Should not send a new comment notification if I comment my own video', async function () { this.timeout(20000) - const resVideo = await uploadVideo(servers[0].url, userToken, { name: 'super video' }) - const uuid = resVideo.body.video.uuid + const { uuid } = await servers[0].videosCommand.upload({ token: userToken, attributes: { name: 'super video' } }) const created = await servers[0].commentsCommand.createThread({ token: userToken, videoId: uuid, text: 'comment' }) const commentId = created.id @@ -81,8 +78,7 @@ describe('Test comments notifications', function () { await servers[0].blocklistCommand.addToMyBlocklist({ token: userToken, account: 'root' }) - const resVideo = await uploadVideo(servers[0].url, userToken, { name: 'super video' }) - const uuid = resVideo.body.video.uuid + const { uuid } = await servers[0].videosCommand.upload({ token: userToken, attributes: { name: 'super video' } }) const created = await servers[0].commentsCommand.createThread({ videoId: uuid, text: 'comment' }) const commentId = created.id @@ -96,8 +92,7 @@ describe('Test comments notifications', function () { it('Should send a new comment notification after a local comment on my video', async function () { this.timeout(20000) - const resVideo = await uploadVideo(servers[0].url, userToken, { name: 'super video' }) - const uuid = resVideo.body.video.uuid + const { uuid } = await servers[0].videosCommand.upload({ token: userToken, attributes: { name: 'super video' } }) const created = await servers[0].commentsCommand.createThread({ videoId: uuid, text: 'comment' }) const commentId = created.id @@ -109,8 +104,7 @@ describe('Test comments notifications', function () { it('Should send a new comment notification after a remote comment on my video', async function () { this.timeout(20000) - const resVideo = await uploadVideo(servers[0].url, userToken, { name: 'super video' }) - const uuid = resVideo.body.video.uuid + const { uuid } = await servers[0].videosCommand.upload({ token: userToken, attributes: { name: 'super video' } }) await waitJobs(servers) @@ -128,8 +122,7 @@ describe('Test comments notifications', function () { it('Should send a new comment notification after a local reply on my video', async function () { this.timeout(20000) - const resVideo = await uploadVideo(servers[0].url, userToken, { name: 'super video' }) - const uuid = resVideo.body.video.uuid + const { uuid } = await servers[0].videosCommand.upload({ token: userToken, attributes: { name: 'super video' } }) const { id: threadId } = await servers[0].commentsCommand.createThread({ videoId: uuid, text: 'comment' }) @@ -142,8 +135,7 @@ describe('Test comments notifications', function () { it('Should send a new comment notification after a remote reply on my video', async function () { this.timeout(20000) - const resVideo = await uploadVideo(servers[0].url, userToken, { name: 'super video' }) - const uuid = resVideo.body.video.uuid + const { uuid } = await servers[0].videosCommand.upload({ token: userToken, attributes: { name: 'super video' } }) await waitJobs(servers) { @@ -169,8 +161,7 @@ describe('Test comments notifications', function () { it('Should convert markdown in comment to html', async function () { this.timeout(20000) - const resVideo = await uploadVideo(servers[0].url, userToken, { name: 'cool video' }) - const uuid = resVideo.body.video.uuid + const { uuid } = await servers[0].videosCommand.upload({ token: userToken, attributes: { name: 'cool video' } }) await servers[0].commentsCommand.createThread({ videoId: uuid, text: commentText }) @@ -199,8 +190,7 @@ describe('Test comments notifications', function () { it('Should not send a new mention comment notification if I mention the video owner', async function () { this.timeout(10000) - const resVideo = await uploadVideo(servers[0].url, userToken, { name: 'super video' }) - const uuid = resVideo.body.video.uuid + const { uuid } = await servers[0].videosCommand.upload({ token: userToken, attributes: { name: 'super video' } }) const { id: commentId } = await servers[0].commentsCommand.createThread({ videoId: uuid, text: '@user_1 hello' }) @@ -211,8 +201,7 @@ describe('Test comments notifications', function () { it('Should not send a new mention comment notification if I mention myself', async function () { this.timeout(10000) - const resVideo = await uploadVideo(servers[0].url, servers[0].accessToken, { name: 'super video' }) - const uuid = resVideo.body.video.uuid + const { uuid } = await servers[0].videosCommand.upload({ attributes: { name: 'super video' } }) const { id: commentId } = await servers[0].commentsCommand.createThread({ token: userToken, videoId: uuid, text: '@user_1 hello' }) @@ -225,8 +214,7 @@ describe('Test comments notifications', function () { await servers[0].blocklistCommand.addToMyBlocklist({ token: userToken, account: 'root' }) - const resVideo = await uploadVideo(servers[0].url, servers[0].accessToken, { name: 'super video' }) - const uuid = resVideo.body.video.uuid + const { uuid } = await servers[0].videosCommand.upload({ attributes: { name: 'super video' } }) const { id: commentId } = await servers[0].commentsCommand.createThread({ videoId: uuid, text: '@user_1 hello' }) @@ -239,8 +227,7 @@ describe('Test comments notifications', function () { it('Should not send a new mention notification if the remote account mention a local account', async function () { this.timeout(20000) - const resVideo = await uploadVideo(servers[0].url, servers[0].accessToken, { name: 'super video' }) - const uuid = resVideo.body.video.uuid + const { uuid } = await servers[0].videosCommand.upload({ attributes: { name: 'super video' } }) await waitJobs(servers) const { id: threadId } = await servers[1].commentsCommand.createThread({ videoId: uuid, text: '@user_1 hello' }) @@ -252,8 +239,7 @@ describe('Test comments notifications', function () { it('Should send a new mention notification after local comments', async function () { this.timeout(10000) - const resVideo = await uploadVideo(servers[0].url, servers[0].accessToken, { name: 'super video' }) - const uuid = resVideo.body.video.uuid + const { uuid } = await servers[0].videosCommand.upload({ attributes: { name: 'super video' } }) const { id: threadId } = await servers[0].commentsCommand.createThread({ videoId: uuid, text: '@user_1 hellotext: 1' }) @@ -269,8 +255,7 @@ describe('Test comments notifications', function () { it('Should send a new mention notification after remote comments', async function () { this.timeout(20000) - const resVideo = await uploadVideo(servers[0].url, servers[0].accessToken, { name: 'super video' }) - const uuid = resVideo.body.video.uuid + const { uuid } = await servers[0].videosCommand.upload({ attributes: { name: 'super video' } }) await waitJobs(servers) @@ -301,8 +286,7 @@ describe('Test comments notifications', function () { it('Should convert markdown in comment to html', async function () { this.timeout(10000) - const resVideo = await uploadVideo(servers[0].url, servers[0].accessToken, { name: 'super video' }) - const uuid = resVideo.body.video.uuid + const { uuid } = await servers[0].videosCommand.upload({ attributes: { name: 'super video' } }) const { id: threadId } = await servers[0].commentsCommand.createThread({ videoId: uuid, text: '@user_1 hello 1' }) diff --git a/server/tests/api/notifications/moderation-notifications.ts b/server/tests/api/notifications/moderation-notifications.ts index 0269124c5..91a2b4fa5 100644 --- a/server/tests/api/notifications/moderation-notifications.ts +++ b/server/tests/api/notifications/moderation-notifications.ts @@ -17,12 +17,10 @@ import { checkVideoAutoBlacklistForModerators, checkVideoIsPublished, cleanupTests, - getVideoIdFromUUID, MockInstancesIndex, MockSmtpServer, prepareNotificationsTest, ServerInfo, - uploadVideo, wait, waitJobs } from '@shared/extra-utils' @@ -64,8 +62,7 @@ describe('Test moderation notifications', function () { this.timeout(20000) const name = 'video for abuse ' + buildUUID() - const resVideo = await uploadVideo(servers[0].url, userAccessToken, { name }) - const video = resVideo.body.video + const video = await servers[0].videosCommand.upload({ token: userAccessToken, attributes: { name } }) await servers[0].abusesCommand.report({ videoId: video.id, reason: 'super reason' }) @@ -77,12 +74,11 @@ describe('Test moderation notifications', function () { this.timeout(20000) const name = 'video for abuse ' + buildUUID() - const resVideo = await uploadVideo(servers[0].url, userAccessToken, { name }) - const video = resVideo.body.video + const video = await servers[0].videosCommand.upload({ token: userAccessToken, attributes: { name } }) await waitJobs(servers) - const videoId = await getVideoIdFromUUID(servers[1].url, video.uuid) + const videoId = await servers[1].videosCommand.getId({ uuid: video.uuid }) await servers[1].abusesCommand.report({ videoId, reason: 'super reason' }) await waitJobs(servers) @@ -93,8 +89,7 @@ describe('Test moderation notifications', function () { this.timeout(20000) const name = 'video for abuse ' + buildUUID() - const resVideo = await uploadVideo(servers[0].url, userAccessToken, { name }) - const video = resVideo.body.video + const video = await servers[0].videosCommand.upload({ token: userAccessToken, attributes: { name } }) const comment = await servers[0].commentsCommand.createThread({ token: userAccessToken, videoId: video.id, @@ -113,8 +108,7 @@ describe('Test moderation notifications', function () { this.timeout(20000) const name = 'video for abuse ' + buildUUID() - const resVideo = await uploadVideo(servers[0].url, userAccessToken, { name }) - const video = resVideo.body.video + const video = await servers[0].videosCommand.upload({ token: userAccessToken, attributes: { name } }) await servers[0].commentsCommand.createThread({ token: userAccessToken, @@ -150,7 +144,7 @@ describe('Test moderation notifications', function () { const username = 'user' + new Date().getTime() const tmpToken = await servers[0].usersCommand.generateUserAndToken(username) - await uploadVideo(servers[0].url, tmpToken, { name: 'super video' }) + await servers[0].videosCommand.upload({ token: tmpToken, attributes: { name: 'super video' } }) await waitJobs(servers) @@ -175,8 +169,7 @@ describe('Test moderation notifications', function () { } const name = 'abuse ' + buildUUID() - const resVideo = await uploadVideo(servers[0].url, userAccessToken, { name }) - const video = resVideo.body.video + const video = await servers[0].videosCommand.upload({ token: userAccessToken, attributes: { name } }) const body = await servers[0].abusesCommand.report({ token: userAccessToken, videoId: video.id, reason: 'super reason' }) abuseId = body.abuse.id @@ -223,8 +216,7 @@ describe('Test moderation notifications', function () { } const name = 'abuse ' + buildUUID() - const resVideo = await uploadVideo(servers[0].url, userAccessToken, { name }) - const video = resVideo.body.video + const video = await servers[0].videosCommand.upload({ token: userAccessToken, attributes: { name } }) { const body = await servers[0].abusesCommand.report({ token: userAccessToken, videoId: video.id, reason: 'super reason' }) @@ -294,8 +286,7 @@ describe('Test moderation notifications', function () { this.timeout(10000) const name = 'video for abuse ' + buildUUID() - const resVideo = await uploadVideo(servers[0].url, userAccessToken, { name }) - const uuid = resVideo.body.video.uuid + const { uuid } = await servers[0].videosCommand.upload({ token: userAccessToken, attributes: { name } }) await servers[0].blacklistCommand.add({ videoId: uuid }) @@ -307,8 +298,7 @@ describe('Test moderation notifications', function () { this.timeout(10000) const name = 'video for abuse ' + buildUUID() - const resVideo = await uploadVideo(servers[0].url, userAccessToken, { name }) - const uuid = resVideo.body.video.uuid + const { uuid } = await servers[0].videosCommand.upload({ token: userAccessToken, attributes: { name } }) await servers[0].blacklistCommand.add({ videoId: uuid }) @@ -497,8 +487,8 @@ describe('Test moderation notifications', function () { this.timeout(40000) videoName = 'video with auto-blacklist ' + buildUUID() - const resVideo = await uploadVideo(servers[0].url, userAccessToken, { name: videoName }) - videoUUID = resVideo.body.video.uuid + const { uuid } = await servers[0].videosCommand.upload({ token: userAccessToken, attributes: { name: videoName } }) + videoUUID = uuid await waitJobs(servers) await checkVideoAutoBlacklistForModerators(adminBaseParamsServer1, videoUUID, videoName, 'presence') @@ -544,17 +534,16 @@ describe('Test moderation notifications', function () { const name = 'video with auto-blacklist and future schedule ' + buildUUID() - const data = { + const attributes = { name, privacy: VideoPrivacy.PRIVATE, scheduleUpdate: { updateAt: updateAt.toISOString(), - privacy: VideoPrivacy.PUBLIC + privacy: VideoPrivacy.PUBLIC as VideoPrivacy.PUBLIC } } - const resVideo = await uploadVideo(servers[0].url, userAccessToken, data) - const uuid = resVideo.body.video.uuid + const { uuid } = await servers[0].videosCommand.upload({ token: userAccessToken, attributes }) await servers[0].blacklistCommand.remove({ videoId: uuid }) @@ -577,17 +566,16 @@ describe('Test moderation notifications', function () { const name = 'video with schedule done and still auto-blacklisted ' + buildUUID() - const data = { + const attributes = { name, privacy: VideoPrivacy.PRIVATE, scheduleUpdate: { updateAt: updateAt.toISOString(), - privacy: VideoPrivacy.PUBLIC + privacy: VideoPrivacy.PUBLIC as VideoPrivacy.PUBLIC } } - const resVideo = await uploadVideo(servers[0].url, userAccessToken, data) - const uuid = resVideo.body.video.uuid + const { uuid } = await servers[0].videosCommand.upload({ token: userAccessToken, attributes }) await wait(6000) await checkVideoIsPublished(userBaseParams, name, uuid, 'absence') @@ -601,8 +589,7 @@ describe('Test moderation notifications', function () { const name = 'video without auto-blacklist ' + buildUUID() // admin with blacklist right will not be auto-blacklisted - const resVideo = await uploadVideo(servers[0].url, servers[0].accessToken, { name }) - const uuid = resVideo.body.video.uuid + const { uuid } = await servers[0].videosCommand.upload({ attributes: { name } }) await waitJobs(servers) await checkVideoAutoBlacklistForModerators(adminBaseParamsServer1, uuid, name, 'absence') diff --git a/server/tests/api/notifications/notifications-api.ts b/server/tests/api/notifications/notifications-api.ts index f33d8e64d..41e1b8015 100644 --- a/server/tests/api/notifications/notifications-api.ts +++ b/server/tests/api/notifications/notifications-api.ts @@ -10,7 +10,6 @@ import { MockSmtpServer, prepareNotificationsTest, ServerInfo, - uploadRandomVideo, waitJobs } from '@shared/extra-utils' import { UserNotification, UserNotificationSettingValue } from '@shared/models' @@ -35,7 +34,7 @@ describe('Test notifications API', function () { await server.subscriptionsCommand.add({ token: userToken, targetUri: 'root_channel@localhost:' + server.port }) for (let i = 0; i < 10; i++) { - await uploadRandomVideo(server, false) + await server.videosCommand.randomUpload({ wait: false }) } await waitJobs([ server ]) @@ -112,7 +111,7 @@ describe('Test notifications API', function () { expect(info.notificationSettings.newVideoFromSubscription).to.equal(UserNotificationSettingValue.NONE) } - const { name, uuid } = await uploadRandomVideo(server) + const { name, uuid } = await server.videosCommand.randomUpload() const check = { web: true, mail: true } await checkNewVideoFromSubscription({ ...baseParams, check }, name, uuid, 'absence') @@ -131,7 +130,7 @@ describe('Test notifications API', function () { expect(info.notificationSettings.newVideoFromSubscription).to.equal(UserNotificationSettingValue.WEB) } - const { name, uuid } = await uploadRandomVideo(server) + const { name, uuid } = await server.videosCommand.randomUpload() { const check = { mail: true, web: false } @@ -157,7 +156,7 @@ describe('Test notifications API', function () { expect(info.notificationSettings.newVideoFromSubscription).to.equal(UserNotificationSettingValue.EMAIL) } - const { name, uuid } = await uploadRandomVideo(server) + const { name, uuid } = await server.videosCommand.randomUpload() { const check = { mail: false, web: true } @@ -188,7 +187,7 @@ describe('Test notifications API', function () { ) } - const { name, uuid } = await uploadRandomVideo(server) + const { name, uuid } = await server.videosCommand.randomUpload() await checkNewVideoFromSubscription(baseParams, name, uuid, 'presence') }) diff --git a/server/tests/api/notifications/user-notifications.ts b/server/tests/api/notifications/user-notifications.ts index 465349fb9..4db8c1576 100644 --- a/server/tests/api/notifications/user-notifications.ts +++ b/server/tests/api/notifications/user-notifications.ts @@ -14,7 +14,6 @@ import { MockSmtpServer, prepareNotificationsTest, ServerInfo, - updateVideo, uploadRandomVideoOnServers, wait, waitJobs @@ -99,7 +98,7 @@ describe('Test user notifications', function () { privacy: VideoPrivacy.PRIVATE, scheduleUpdate: { updateAt: updateAt.toISOString(), - privacy: VideoPrivacy.PUBLIC + privacy: VideoPrivacy.PUBLIC as VideoPrivacy.PUBLIC } } const { name, uuid } = await uploadRandomVideoOnServers(servers, 1, data) @@ -118,7 +117,7 @@ describe('Test user notifications', function () { privacy: VideoPrivacy.PRIVATE, scheduleUpdate: { updateAt: updateAt.toISOString(), - privacy: VideoPrivacy.PUBLIC + privacy: VideoPrivacy.PUBLIC as VideoPrivacy.PUBLIC } } const { name, uuid } = await uploadRandomVideoOnServers(servers, 2, data) @@ -137,7 +136,7 @@ describe('Test user notifications', function () { privacy: VideoPrivacy.PRIVATE, scheduleUpdate: { updateAt: updateAt.toISOString(), - privacy: VideoPrivacy.PUBLIC + privacy: VideoPrivacy.PUBLIC as VideoPrivacy.PUBLIC } } const { name, uuid } = await uploadRandomVideoOnServers(servers, 1, data) @@ -154,7 +153,7 @@ describe('Test user notifications', function () { await checkNewVideoFromSubscription(baseParams, name, uuid, 'absence') - await updateVideo(servers[0].url, servers[0].accessToken, uuid, { privacy: VideoPrivacy.PUBLIC }) + await servers[0].videosCommand.update({ id: uuid, attributes: { privacy: VideoPrivacy.PUBLIC } }) await waitJobs(servers) await checkNewVideoFromSubscription(baseParams, name, uuid, 'presence') @@ -168,7 +167,7 @@ describe('Test user notifications', function () { await checkNewVideoFromSubscription(baseParams, name, uuid, 'absence') - await updateVideo(servers[1].url, servers[1].accessToken, uuid, { privacy: VideoPrivacy.PUBLIC }) + await servers[1].videosCommand.update({ id: uuid, attributes: { privacy: VideoPrivacy.PUBLIC } }) await waitJobs(servers) await checkNewVideoFromSubscription(baseParams, name, uuid, 'presence') @@ -180,7 +179,7 @@ describe('Test user notifications', function () { const data = { privacy: VideoPrivacy.PRIVATE } const { name, uuid } = await uploadRandomVideoOnServers(servers, 1, data) - await updateVideo(servers[0].url, servers[0].accessToken, uuid, { privacy: VideoPrivacy.UNLISTED }) + await servers[0].videosCommand.update({ id: uuid, attributes: { privacy: VideoPrivacy.UNLISTED } }) await checkNewVideoFromSubscription(baseParams, name, uuid, 'absence') }) @@ -191,7 +190,7 @@ describe('Test user notifications', function () { const data = { privacy: VideoPrivacy.PRIVATE } const { name, uuid } = await uploadRandomVideoOnServers(servers, 2, data) - await updateVideo(servers[1].url, servers[1].accessToken, uuid, { privacy: VideoPrivacy.UNLISTED }) + await servers[1].videosCommand.update({ id: uuid, attributes: { privacy: VideoPrivacy.UNLISTED } }) await waitJobs(servers) await checkNewVideoFromSubscription(baseParams, name, uuid, 'absence') @@ -295,7 +294,7 @@ describe('Test user notifications', function () { privacy: VideoPrivacy.PRIVATE, scheduleUpdate: { updateAt: updateAt.toISOString(), - privacy: VideoPrivacy.PUBLIC + privacy: VideoPrivacy.PUBLIC as VideoPrivacy.PUBLIC } } const { name, uuid } = await uploadRandomVideoOnServers(servers, 2, data) @@ -313,7 +312,7 @@ describe('Test user notifications', function () { privacy: VideoPrivacy.PRIVATE, scheduleUpdate: { updateAt: updateAt.toISOString(), - privacy: VideoPrivacy.PUBLIC + privacy: VideoPrivacy.PUBLIC as VideoPrivacy.PUBLIC } } const { name, uuid } = await uploadRandomVideoOnServers(servers, 2, data) diff --git a/server/tests/api/redundancy/manage-redundancy.ts b/server/tests/api/redundancy/manage-redundancy.ts index 03857f512..efb60dc56 100644 --- a/server/tests/api/redundancy/manage-redundancy.ts +++ b/server/tests/api/redundancy/manage-redundancy.ts @@ -6,12 +6,9 @@ import { cleanupTests, doubleFollow, flushAndRunMultipleServers, - getLocalIdByUUID, RedundancyCommand, ServerInfo, setAccessTokensToServers, - uploadVideo, - uploadVideoAndGetId, waitJobs } from '@shared/extra-utils' import { VideoPrivacy, VideoRedundanciesTarget } from '@shared/models' @@ -59,13 +56,13 @@ describe('Test manage videos redundancy', function () { commands = servers.map(s => s.redundancyCommand) { - const res = await uploadVideo(servers[1].url, servers[1].accessToken, { name: 'video 1 server 2' }) - video1Server2UUID = res.body.video.uuid + const { uuid } = await servers[1].videosCommand.upload({ attributes: { name: 'video 1 server 2' } }) + video1Server2UUID = uuid } { - const res = await uploadVideo(servers[1].url, servers[1].accessToken, { name: 'video 2 server 2' }) - video2Server2UUID = res.body.video.uuid + const { uuid } = await servers[1].videosCommand.upload({ attributes: { name: 'video 2 server 2' } }) + video2Server2UUID = uuid } await waitJobs(servers) @@ -206,9 +203,9 @@ describe('Test manage videos redundancy', function () { it('Should manually add a redundancy and list it', async function () { this.timeout(120000) - const uuid = (await uploadVideoAndGetId({ server: servers[1], videoName: 'video 3 server 2', privacy: VideoPrivacy.UNLISTED })).uuid + const uuid = (await servers[1].videosCommand.quickUpload({ name: 'video 3 server 2', privacy: VideoPrivacy.UNLISTED })).uuid await waitJobs(servers) - const videoId = await getLocalIdByUUID(servers[0].url, uuid) + const videoId = await servers[0].videosCommand.getId({ uuid }) await commands[0].addVideo({ videoId }) diff --git a/server/tests/api/redundancy/redundancy-constraints.ts b/server/tests/api/redundancy/redundancy-constraints.ts index a31278de7..b3f6ed160 100644 --- a/server/tests/api/redundancy/redundancy-constraints.ts +++ b/server/tests/api/redundancy/redundancy-constraints.ts @@ -9,8 +9,6 @@ import { reRunServer, ServerInfo, setAccessTokensToServers, - updateVideo, - uploadVideo, waitJobs } from '@shared/extra-utils' import { VideoPrivacy } from '@shared/models' @@ -38,11 +36,11 @@ describe('Test redundancy constraints', function () { async function uploadWrapper (videoName: string) { // Wait for transcoding - const res = await uploadVideo(localServer.url, localServer.accessToken, { name: 'to transcode', privacy: VideoPrivacy.PRIVATE }) + const { id } = await localServer.videosCommand.upload({ attributes: { name: 'to transcode', privacy: VideoPrivacy.PRIVATE } }) await waitJobs([ localServer ]) // Update video to schedule a federation - await updateVideo(localServer.url, localServer.accessToken, res.body.video.id, { name: videoName, privacy: VideoPrivacy.PUBLIC }) + await localServer.videosCommand.update({ id, attributes: { name: videoName, privacy: VideoPrivacy.PUBLIC } }) } async function getTotalRedundanciesLocalServer () { @@ -80,7 +78,7 @@ describe('Test redundancy constraints', function () { // Get the access tokens await setAccessTokensToServers(servers) - await uploadVideo(localServer.url, localServer.accessToken, { name: 'video 1 server 2' }) + await localServer.videosCommand.upload({ attributes: { name: 'video 1 server 2' } }) await waitJobs(servers) diff --git a/server/tests/api/redundancy/redundancy.ts b/server/tests/api/redundancy/redundancy.ts index 00a5e86cc..6ca9c9303 100644 --- a/server/tests/api/redundancy/redundancy.ts +++ b/server/tests/api/redundancy/redundancy.ts @@ -12,22 +12,16 @@ import { cleanupTests, doubleFollow, flushAndRunMultipleServers, - getVideo, - getVideoWithToken, killallServers, makeGetRequest, - removeVideo, reRunServer, root, ServerInfo, setAccessTokensToServers, - updateVideo, - uploadVideo, - viewVideo, wait, waitJobs } from '@shared/extra-utils' -import { VideoDetails, VideoPrivacy, VideoRedundancyStrategy, VideoRedundancyStrategyWithManual } from '@shared/models' +import { VideoPrivacy, VideoRedundancyStrategy, VideoRedundancyStrategyWithManual } from '@shared/models' const expect = chai.expect @@ -84,11 +78,11 @@ async function flushAndRunServers (strategy: VideoRedundancyStrategy | null, add await setAccessTokensToServers(servers) { - const res = await uploadVideo(servers[1].url, servers[1].accessToken, { name: 'video 1 server 2' }) - video1Server2UUID = res.body.video.uuid - video1Server2Id = res.body.video.id + const { uuid, id } = await servers[1].videosCommand.upload({ attributes: { name: 'video 1 server 2' } }) + video1Server2UUID = uuid + video1Server2Id = id - await viewVideo(servers[1].url, video1Server2UUID) + await servers[1].videosCommand.view({ id: video1Server2UUID }) } await waitJobs(servers) @@ -112,9 +106,8 @@ async function check1WebSeed (videoUUID?: string) { for (const server of servers) { // With token to avoid issues with video follow constraints - const res = await getVideoWithToken(server.url, server.accessToken, videoUUID) + const video = await server.videosCommand.getWithToken({ id: videoUUID }) - const video: VideoDetails = res.body for (const f of video.files) { checkMagnetWebseeds(f, webseeds, server) } @@ -130,9 +123,7 @@ async function check2Webseeds (videoUUID?: string) { ] for (const server of servers) { - const res = await getVideo(server.url, videoUUID) - - const video: VideoDetails = res.body + const video = await server.videosCommand.get({ id: videoUUID }) for (const file of video.files) { checkMagnetWebseeds(file, webseeds, server) @@ -172,8 +163,7 @@ async function check0PlaylistRedundancies (videoUUID?: string) { for (const server of servers) { // With token to avoid issues with video follow constraints - const res = await getVideoWithToken(server.url, server.accessToken, videoUUID) - const video: VideoDetails = res.body + const video = await server.videosCommand.getWithToken({ id: videoUUID }) expect(video.streamingPlaylists).to.be.an('array') expect(video.streamingPlaylists).to.have.lengthOf(1) @@ -185,8 +175,7 @@ async function check1PlaylistRedundancies (videoUUID?: string) { if (!videoUUID) videoUUID = video1Server2UUID for (const server of servers) { - const res = await getVideo(server.url, videoUUID) - const video: VideoDetails = res.body + const video = await server.videosCommand.get({ id: videoUUID }) expect(video.streamingPlaylists).to.have.lengthOf(1) expect(video.streamingPlaylists[0].redundancies).to.have.lengthOf(1) @@ -199,8 +188,8 @@ async function check1PlaylistRedundancies (videoUUID?: string) { const baseUrlPlaylist = servers[1].url + '/static/streaming-playlists/hls' const baseUrlSegment = servers[0].url + '/static/redundancy/hls' - const res = await getVideo(servers[0].url, videoUUID) - const hlsPlaylist = (res.body as VideoDetails).streamingPlaylists[0] + const video = await servers[0].videosCommand.get({ id: videoUUID }) + const hlsPlaylist = video.streamingPlaylists[0] for (const resolution of [ 240, 360, 480, 720 ]) { await checkSegmentHash({ server: servers[1], baseUrlPlaylist, baseUrlSegment, videoUUID, resolution, hlsPlaylist }) @@ -427,8 +416,8 @@ describe('Test videos redundancy', function () { it('Should view 2 times the first video to have > min_views config', async function () { this.timeout(80000) - await viewVideo(servers[0].url, video1Server2UUID) - await viewVideo(servers[2].url, video1Server2UUID) + await servers[0].videosCommand.view({ id: video1Server2UUID }) + await servers[2].videosCommand.view({ id: video1Server2UUID }) await wait(10000) await waitJobs(servers) @@ -449,7 +438,7 @@ describe('Test videos redundancy', function () { it('Should remove the video and the redundancy files', async function () { this.timeout(20000) - await removeVideo(servers[1].url, servers[1].accessToken, video1Server2UUID) + await servers[1].videosCommand.remove({ id: video1Server2UUID }) await waitJobs(servers) @@ -495,8 +484,8 @@ describe('Test videos redundancy', function () { it('Should have 1 redundancy on the first video', async function () { this.timeout(160000) - await viewVideo(servers[0].url, video1Server2UUID) - await viewVideo(servers[2].url, video1Server2UUID) + await servers[0].videosCommand.view({ id: video1Server2UUID }) + await servers[2].videosCommand.view({ id: video1Server2UUID }) await wait(10000) await waitJobs(servers) @@ -512,7 +501,7 @@ describe('Test videos redundancy', function () { it('Should remove the video and the redundancy files', async function () { this.timeout(20000) - await removeVideo(servers[1].url, servers[1].accessToken, video1Server2UUID) + await servers[1].videosCommand.remove({ id: video1Server2UUID }) await waitJobs(servers) @@ -588,8 +577,7 @@ describe('Test videos redundancy', function () { async function checkContains (servers: ServerInfo[], str: string) { for (const server of servers) { - const res = await getVideo(server.url, video1Server2UUID) - const video: VideoDetails = res.body + const video = await server.videosCommand.get({ id: video1Server2UUID }) for (const f of video.files) { expect(f.magnetUri).to.contain(str) @@ -599,8 +587,7 @@ describe('Test videos redundancy', function () { async function checkNotContains (servers: ServerInfo[], str: string) { for (const server of servers) { - const res = await getVideo(server.url, video1Server2UUID) - const video: VideoDetails = res.body + const video = await server.videosCommand.get({ id: video1Server2UUID }) for (const f of video.files) { expect(f.magnetUri).to.not.contain(str) @@ -665,13 +652,13 @@ describe('Test videos redundancy', function () { await check1PlaylistRedundancies(video1Server2UUID) await checkStatsWith1Redundancy(strategy) - const res = await uploadVideo(servers[1].url, servers[1].accessToken, { name: 'video 2 server 2', privacy: VideoPrivacy.PRIVATE }) - video2Server2UUID = res.body.video.uuid + const { uuid } = await servers[1].videosCommand.upload({ attributes: { name: 'video 2 server 2', privacy: VideoPrivacy.PRIVATE } }) + video2Server2UUID = uuid // Wait transcoding before federation await waitJobs(servers) - await updateVideo(servers[1].url, servers[1].accessToken, video2Server2UUID, { privacy: VideoPrivacy.PUBLIC }) + await servers[1].videosCommand.update({ id: video2Server2UUID, attributes: { privacy: VideoPrivacy.PUBLIC } }) }) it('Should cache video 2 webseeds on the first video', async function () { diff --git a/server/tests/api/search/search-activitypub-video-channels.ts b/server/tests/api/search/search-activitypub-video-channels.ts index bcc21381c..75794402d 100644 --- a/server/tests/api/search/search-activitypub-video-channels.ts +++ b/server/tests/api/search/search-activitypub-video-channels.ts @@ -5,12 +5,9 @@ import * as chai from 'chai' import { cleanupTests, flushAndRunMultipleServers, - getVideoChannelVideos, SearchCommand, ServerInfo, setAccessTokensToServers, - updateVideo, - uploadVideo, wait, waitJobs } from '@shared/extra-utils' @@ -53,8 +50,9 @@ describe('Test ActivityPub video channels search', function () { const created = await servers[1].channelsCommand.create({ token: userServer2Token, attributes: channel }) channelIdServer2 = created.id - const res = await uploadVideo(servers[1].url, userServer2Token, { name: 'video 1 server 2', channelId: channelIdServer2 }) - videoServer2UUID = res.body.video.uuid + const attributes = { name: 'video 1 server 2', channelId: channelIdServer2 } + const { uuid } = await servers[1].videosCommand.upload({ token: userServer2Token, attributes }) + videoServer2UUID = uuid } await waitJobs(servers) @@ -149,16 +147,21 @@ describe('Test ActivityPub video channels search', function () { await waitJobs(servers) - const res = await getVideoChannelVideos(servers[0].url, null, 'channel1_server2@localhost:' + servers[1].port, 0, 5) - expect(res.body.total).to.equal(0) - expect(res.body.data).to.have.lengthOf(0) + const { total, data } = await servers[0].videosCommand.listByChannel({ + token: null, + videoChannelName: 'channel1_server2@localhost:' + servers[1].port + }) + expect(total).to.equal(0) + expect(data).to.have.lengthOf(0) }) it('Should list video channel videos of server 2 with token', async function () { - const res = await getVideoChannelVideos(servers[0].url, servers[0].accessToken, 'channel1_server2@localhost:' + servers[1].port, 0, 5) + const { total, data } = await servers[0].videosCommand.listByChannel({ + videoChannelName: 'channel1_server2@localhost:' + servers[1].port + }) - expect(res.body.total).to.equal(1) - expect(res.body.data[0].name).to.equal('video 1 server 2') + expect(total).to.equal(1) + expect(data[0].name).to.equal('video 1 server 2') }) it('Should update video channel of server 2, and refresh it on server 1', async function () { @@ -190,8 +193,8 @@ describe('Test ActivityPub video channels search', function () { it('Should update and add a video on server 2, and update it on server 1 after a search', async function () { this.timeout(60000) - await updateVideo(servers[1].url, userServer2Token, videoServer2UUID, { name: 'video 1 updated' }) - await uploadVideo(servers[1].url, userServer2Token, { name: 'video 2 server 2', channelId: channelIdServer2 }) + await servers[1].videosCommand.update({ token: userServer2Token, id: videoServer2UUID, attributes: { name: 'video 1 updated' } }) + await servers[1].videosCommand.upload({ token: userServer2Token, attributes: { name: 'video 2 server 2', channelId: channelIdServer2 } }) await waitJobs(servers) @@ -204,11 +207,11 @@ describe('Test ActivityPub video channels search', function () { await waitJobs(servers) const videoChannelName = 'channel1_server2@localhost:' + servers[1].port - const res = await getVideoChannelVideos(servers[0].url, servers[0].accessToken, videoChannelName, 0, 5, '-createdAt') + const { total, data } = await servers[0].videosCommand.listByChannel({ videoChannelName, sort: '-createdAt' }) - expect(res.body.total).to.equal(2) - expect(res.body.data[0].name).to.equal('video 2 server 2') - expect(res.body.data[1].name).to.equal('video 1 updated') + expect(total).to.equal(2) + expect(data[0].name).to.equal('video 2 server 2') + expect(data[1].name).to.equal('video 1 updated') }) it('Should delete video channel of server 2, and delete it on server 1', async function () { diff --git a/server/tests/api/search/search-activitypub-video-playlists.ts b/server/tests/api/search/search-activitypub-video-playlists.ts index cb7582d29..46105c12c 100644 --- a/server/tests/api/search/search-activitypub-video-playlists.ts +++ b/server/tests/api/search/search-activitypub-video-playlists.ts @@ -9,7 +9,6 @@ import { ServerInfo, setAccessTokensToServers, setDefaultVideoChannel, - uploadVideoAndGetId, wait, waitJobs } from '@shared/extra-utils' @@ -34,8 +33,8 @@ describe('Test ActivityPub playlists search', function () { await setDefaultVideoChannel(servers) { - const video1 = (await uploadVideoAndGetId({ server: servers[0], videoName: 'video 1' })).uuid - const video2 = (await uploadVideoAndGetId({ server: servers[0], videoName: 'video 2' })).uuid + const video1 = (await servers[0].videosCommand.quickUpload({ name: 'video 1' })).uuid + const video2 = (await servers[0].videosCommand.quickUpload({ name: 'video 2' })).uuid const attributes = { displayName: 'playlist 1 on server 1', @@ -51,8 +50,8 @@ describe('Test ActivityPub playlists search', function () { } { - const videoId = (await uploadVideoAndGetId({ server: servers[1], videoName: 'video 1' })).uuid - video2Server2 = (await uploadVideoAndGetId({ server: servers[1], videoName: 'video 2' })).uuid + const videoId = (await servers[1].videosCommand.quickUpload({ name: 'video 1' })).uuid + video2Server2 = (await servers[1].videosCommand.quickUpload({ name: 'video 2' })).uuid const attributes = { displayName: 'playlist 1 on server 2', diff --git a/server/tests/api/search/search-activitypub-videos.ts b/server/tests/api/search/search-activitypub-videos.ts index 403c84010..19b4d5ed8 100644 --- a/server/tests/api/search/search-activitypub-videos.ts +++ b/server/tests/api/search/search-activitypub-videos.ts @@ -5,17 +5,13 @@ import * as chai from 'chai' import { cleanupTests, flushAndRunMultipleServers, - getVideosList, - removeVideo, SearchCommand, ServerInfo, setAccessTokensToServers, - updateVideo, - uploadVideo, - wait -} from '../../../../shared/extra-utils' -import { waitJobs } from '../../../../shared/extra-utils/server/jobs' -import { VideoPrivacy } from '../../../../shared/models/videos' + wait, + waitJobs +} from '@shared/extra-utils' +import { VideoPrivacy } from '@shared/models' const expect = chai.expect @@ -34,13 +30,13 @@ describe('Test ActivityPub videos search', function () { await setAccessTokensToServers(servers) { - const res = await uploadVideo(servers[0].url, servers[0].accessToken, { name: 'video 1 on server 1' }) - videoServer1UUID = res.body.video.uuid + const { uuid } = await servers[0].videosCommand.upload({ attributes: { name: 'video 1 on server 1' } }) + videoServer1UUID = uuid } { - const res = await uploadVideo(servers[1].url, servers[1].accessToken, { name: 'video 1 on server 2' }) - videoServer2UUID = res.body.video.uuid + const { uuid } = await servers[1].videosCommand.upload({ attributes: { name: 'video 1 on server 2' } }) + videoServer2UUID = uuid } await waitJobs(servers) @@ -109,10 +105,10 @@ describe('Test ActivityPub videos search', function () { }) it('Should not list this remote video', async function () { - const res = await getVideosList(servers[0].url) - expect(res.body.total).to.equal(1) - expect(res.body.data).to.have.lengthOf(1) - expect(res.body.data[0].name).to.equal('video 1 on server 1') + const { total, data } = await servers[0].videosCommand.list() + expect(total).to.equal(1) + expect(data).to.have.lengthOf(1) + expect(data[0].name).to.equal('video 1 on server 1') }) it('Should update video of server 2, and refresh it on server 1', async function () { @@ -131,7 +127,7 @@ describe('Test ActivityPub videos search', function () { privacy: VideoPrivacy.UNLISTED, channelId: videoChannelId } - await updateVideo(servers[1].url, servers[1].accessToken, videoServer2UUID, attributes) + await servers[1].videosCommand.update({ id: videoServer2UUID, attributes }) await waitJobs(servers) // Expire video @@ -157,7 +153,7 @@ describe('Test ActivityPub videos search', function () { it('Should delete video of server 2, and delete it on server 1', async function () { this.timeout(120000) - await removeVideo(servers[1].url, servers[1].accessToken, videoServer2UUID) + await servers[1].videosCommand.remove({ id: videoServer2UUID }) await waitJobs(servers) // Expire video diff --git a/server/tests/api/search/search-index.ts b/server/tests/api/search/search-index.ts index 306f84c3a..d5dc40f60 100644 --- a/server/tests/api/search/search-index.ts +++ b/server/tests/api/search/search-index.ts @@ -2,7 +2,7 @@ import 'mocha' import * as chai from 'chai' -import { cleanupTests, flushAndRunServer, SearchCommand, ServerInfo, setAccessTokensToServers, uploadVideo } from '@shared/extra-utils' +import { cleanupTests, flushAndRunServer, SearchCommand, ServerInfo, setAccessTokensToServers } from '@shared/extra-utils' import { BooleanBothQuery, VideoPlaylistPrivacy, VideoPlaylistType, VideosSearchQuery } from '@shared/models' const expect = chai.expect @@ -20,7 +20,7 @@ describe('Test videos search', function () { await setAccessTokensToServers([ server ]) - await uploadVideo(server.url, server.accessToken, { name: localVideoName }) + await server.videosCommand.upload({ attributes: { name: localVideoName } }) command = server.searchCommand }) diff --git a/server/tests/api/search/search-playlists.ts b/server/tests/api/search/search-playlists.ts index 517884503..2e4773ed6 100644 --- a/server/tests/api/search/search-playlists.ts +++ b/server/tests/api/search/search-playlists.ts @@ -2,16 +2,15 @@ import 'mocha' import * as chai from 'chai' -import { VideoPlaylistPrivacy } from '@shared/models' import { cleanupTests, flushAndRunServer, SearchCommand, ServerInfo, setAccessTokensToServers, - setDefaultVideoChannel, - uploadVideoAndGetId -} from '../../../../shared/extra-utils' + setDefaultVideoChannel +} from '@shared/extra-utils' +import { VideoPlaylistPrivacy } from '@shared/models' const expect = chai.expect @@ -27,7 +26,7 @@ describe('Test playlists search', function () { await setAccessTokensToServers([ server ]) await setDefaultVideoChannel([ server ]) - const videoId = (await uploadVideoAndGetId({ server: server, videoName: 'video' })).uuid + const videoId = (await server.videosCommand.quickUpload({ name: 'video' })).uuid { const attributes = { diff --git a/server/tests/api/search/search-videos.ts b/server/tests/api/search/search-videos.ts index 66f5f3182..148499d5f 100644 --- a/server/tests/api/search/search-videos.ts +++ b/server/tests/api/search/search-videos.ts @@ -10,7 +10,6 @@ import { setAccessTokensToServers, setDefaultVideoChannel, stopFfmpeg, - uploadVideo, wait } from '@shared/extra-utils' import { VideoPrivacy } from '@shared/models' @@ -41,50 +40,49 @@ describe('Test videos search', function () { nsfw: false, language: 'fr' } - await uploadVideo(server.url, server.accessToken, attributes1) + await server.videosCommand.upload({ attributes: attributes1 }) const attributes2 = { ...attributes1, name: attributes1.name + ' - 2', fixture: 'video_short.mp4' } - await uploadVideo(server.url, server.accessToken, attributes2) + await server.videosCommand.upload({ attributes: attributes2 }) { const attributes3 = { ...attributes1, name: attributes1.name + ' - 3', language: undefined } - const res = await uploadVideo(server.url, server.accessToken, attributes3) - const videoId = res.body.video.id - videoUUID = res.body.video.uuid + const { id, uuid } = await server.videosCommand.upload({ attributes: attributes3 }) + videoUUID = uuid await server.captionsCommand.createVideoCaption({ language: 'en', - videoId, + videoId: id, fixture: 'subtitle-good2.vtt', mimeType: 'application/octet-stream' }) await server.captionsCommand.createVideoCaption({ language: 'aa', - videoId, + videoId: id, fixture: 'subtitle-good2.vtt', mimeType: 'application/octet-stream' }) } const attributes4 = { ...attributes1, name: attributes1.name + ' - 4', language: 'pl', nsfw: true } - await uploadVideo(server.url, server.accessToken, attributes4) + await server.videosCommand.upload({ attributes: attributes4 }) await wait(1000) startDate = new Date().toISOString() const attributes5 = { ...attributes1, name: attributes1.name + ' - 5', licence: 2, language: undefined } - await uploadVideo(server.url, server.accessToken, attributes5) + await server.videosCommand.upload({ attributes: attributes5 }) const attributes6 = { ...attributes1, name: attributes1.name + ' - 6', tags: [ 't1', 't2' ] } - await uploadVideo(server.url, server.accessToken, attributes6) + await server.videosCommand.upload({ attributes: attributes6 }) const attributes7 = { ...attributes1, name: attributes1.name + ' - 7', originallyPublishedAt: '2019-02-12T09:58:08.286Z' } - await uploadVideo(server.url, server.accessToken, attributes7) + await server.videosCommand.upload({ attributes: attributes7 }) const attributes8 = { ...attributes1, name: attributes1.name + ' - 8', licence: 4 } - await uploadVideo(server.url, server.accessToken, attributes8) + await server.videosCommand.upload({ attributes: attributes8 }) } { @@ -95,9 +93,9 @@ describe('Test videos search', function () { licence: 2, language: 'en' } - await uploadVideo(server.url, server.accessToken, attributes) + await server.videosCommand.upload({ attributes: attributes }) - await uploadVideo(server.url, server.accessToken, { ...attributes, name: attributes.name + ' duplicate' }) + await server.videosCommand.upload({ attributes: { ...attributes, name: attributes.name + ' duplicate' } }) } { @@ -108,7 +106,7 @@ describe('Test videos search', function () { licence: 3, language: 'pl' } - await uploadVideo(server.url, server.accessToken, attributes) + await server.videosCommand.upload({ attributes: attributes }) } { @@ -117,11 +115,11 @@ describe('Test videos search', function () { tags: [ 'aaaa', 'bbbb', 'cccc' ], category: 1 } - await uploadVideo(server.url, server.accessToken, attributes1) - await uploadVideo(server.url, server.accessToken, { ...attributes1, category: 2 }) + await server.videosCommand.upload({ attributes: attributes1 }) + await server.videosCommand.upload({ attributes: { ...attributes1, category: 2 } }) - await uploadVideo(server.url, server.accessToken, { ...attributes1, tags: [ 'cccc', 'dddd' ] }) - await uploadVideo(server.url, server.accessToken, { ...attributes1, tags: [ 'eeee', 'ffff' ] }) + await server.videosCommand.upload({ attributes: { ...attributes1, tags: [ 'cccc', 'dddd' ] } }) + await server.videosCommand.upload({ attributes: { ...attributes1, tags: [ 'eeee', 'ffff' ] } }) } { @@ -129,8 +127,8 @@ describe('Test videos search', function () { name: 'aaaa 2', category: 1 } - await uploadVideo(server.url, server.accessToken, attributes1) - await uploadVideo(server.url, server.accessToken, { ...attributes1, category: 2 }) + await server.videosCommand.upload({ attributes: attributes1 }) + await server.videosCommand.upload({ attributes: { ...attributes1, category: 2 } }) } command = server.searchCommand diff --git a/server/tests/api/server/bulk.ts b/server/tests/api/server/bulk.ts index 20a9a3dc7..c83bcfb22 100644 --- a/server/tests/api/server/bulk.ts +++ b/server/tests/api/server/bulk.ts @@ -7,13 +7,10 @@ import { cleanupTests, doubleFollow, flushAndRunMultipleServers, - getVideosList, ServerInfo, setAccessTokensToServers, - uploadVideo, waitJobs } from '@shared/extra-utils' -import { Video } from '@shared/models' const expect = chai.expect @@ -64,11 +61,10 @@ describe('Test bulk actions', function () { describe('Bulk remove comments', function () { async function checkInstanceCommentsRemoved () { { - const res = await getVideosList(servers[0].url) - const videos = res.body.data as Video[] + const { data } = await servers[0].videosCommand.list() // Server 1 should not have these comments anymore - for (const video of videos) { + for (const video of data) { const { data } = await servers[0].commentsCommand.listThreads({ videoId: video.id }) const comment = data.find(c => c.text === 'comment by user 3') @@ -77,11 +73,10 @@ describe('Test bulk actions', function () { } { - const res = await getVideosList(servers[1].url) - const videos = res.body.data as Video[] + const { data } = await servers[1].videosCommand.list() // Server 1 should not have these comments on videos of server 1 - for (const video of videos) { + for (const video of data) { const { data } = await servers[1].commentsCommand.listThreads({ videoId: video.id }) const comment = data.find(c => c.text === 'comment by user 3') @@ -97,17 +92,17 @@ describe('Test bulk actions', function () { before(async function () { this.timeout(120000) - await uploadVideo(servers[0].url, servers[0].accessToken, { name: 'video 1 server 1' }) - await uploadVideo(servers[0].url, servers[0].accessToken, { name: 'video 2 server 1' }) - await uploadVideo(servers[0].url, user1Token, { name: 'video 3 server 1' }) + await servers[0].videosCommand.upload({ attributes: { name: 'video 1 server 1' } }) + await servers[0].videosCommand.upload({ attributes: { name: 'video 2 server 1' } }) + await servers[0].videosCommand.upload({ token: user1Token, attributes: { name: 'video 3 server 1' } }) - await uploadVideo(servers[1].url, servers[1].accessToken, { name: 'video 1 server 2' }) + await servers[1].videosCommand.upload({ attributes: { name: 'video 1 server 2' } }) await waitJobs(servers) { - const res = await getVideosList(servers[0].url) - for (const video of res.body.data) { + const { data } = await servers[0].videosCommand.list() + for (const video of data) { await servers[0].commentsCommand.createThread({ videoId: video.id, text: 'comment by root server 1' }) await servers[0].commentsCommand.createThread({ token: user1Token, videoId: video.id, text: 'comment by user 1' }) await servers[0].commentsCommand.createThread({ token: user2Token, videoId: video.id, text: 'comment by user 2' }) @@ -115,9 +110,9 @@ describe('Test bulk actions', function () { } { - const res = await getVideosList(servers[1].url) + const { data } = await servers[1].videosCommand.list() - for (const video of res.body.data) { + for (const video of data) { await servers[1].commentsCommand.createThread({ videoId: video.id, text: 'comment by root server 2' }) const comment = await servers[1].commentsCommand.createThread({ token: user3Token, videoId: video.id, text: 'comment by user 3' }) @@ -142,9 +137,9 @@ describe('Test bulk actions', function () { await waitJobs(servers) for (const server of servers) { - const res = await getVideosList(server.url) + const { data } = await server.videosCommand.list() - for (const video of res.body.data) { + for (const video of data) { const { data } = await server.commentsCommand.listThreads({ videoId: video.id }) const comment = data.find(c => c.text === 'comment by user 2') diff --git a/server/tests/api/server/config.ts b/server/tests/api/server/config.ts index 95dafd378..c613511ed 100644 --- a/server/tests/api/server/config.ts +++ b/server/tests/api/server/config.ts @@ -11,8 +11,7 @@ import { parallelTests, reRunServer, ServerInfo, - setAccessTokensToServers, - uploadVideo + setAccessTokensToServers } from '@shared/extra-utils' import { CustomConfig } from '@shared/models' @@ -242,8 +241,8 @@ describe('Test config', function () { expect(data.video.file.extensions).to.contain('.webm') expect(data.video.file.extensions).to.contain('.ogv') - await uploadVideo(server.url, server.accessToken, { fixture: 'video_short.mkv' }, HttpStatusCode.UNSUPPORTED_MEDIA_TYPE_415) - await uploadVideo(server.url, server.accessToken, { fixture: 'sample.ogg' }, HttpStatusCode.UNSUPPORTED_MEDIA_TYPE_415) + await server.videosCommand.upload({ attributes: { fixture: 'video_short.mkv' }, expectedStatus: HttpStatusCode.UNSUPPORTED_MEDIA_TYPE_415 }) + await server.videosCommand.upload({ attributes: { fixture: 'sample.ogg' }, expectedStatus: HttpStatusCode.UNSUPPORTED_MEDIA_TYPE_415 }) expect(data.contactForm.enabled).to.be.true }) @@ -448,8 +447,8 @@ describe('Test config', function () { expect(data.video.file.extensions).to.contain('.ogg') expect(data.video.file.extensions).to.contain('.flac') - await uploadVideo(server.url, server.accessToken, { fixture: 'video_short.mkv' }, HttpStatusCode.OK_200) - await uploadVideo(server.url, server.accessToken, { fixture: 'sample.ogg' }, HttpStatusCode.OK_200) + await server.videosCommand.upload({ attributes: { fixture: 'video_short.mkv' }, expectedStatus: HttpStatusCode.OK_200 }) + await server.videosCommand.upload({ attributes: { fixture: 'sample.ogg' }, expectedStatus: HttpStatusCode.OK_200 }) }) it('Should have the configuration updated after a restart', async function () { diff --git a/server/tests/api/server/email.ts b/server/tests/api/server/email.ts index 422db6ceb..aeda5fddb 100644 --- a/server/tests/api/server/email.ts +++ b/server/tests/api/server/email.ts @@ -3,15 +3,7 @@ import 'mocha' import * as chai from 'chai' import { HttpStatusCode } from '@shared/core-utils' -import { - cleanupTests, - flushAndRunServer, - MockSmtpServer, - ServerInfo, - setAccessTokensToServers, - uploadVideo, - waitJobs -} from '@shared/extra-utils' +import { cleanupTests, flushAndRunServer, MockSmtpServer, ServerInfo, setAccessTokensToServers, waitJobs } from '@shared/extra-utils' const expect = chai.expect @@ -58,20 +50,18 @@ describe('Test emails', function () { } { - const attributes = { - name: 'my super user video' - } - const res = await uploadVideo(server.url, userAccessToken, attributes) - videoUserUUID = res.body.video.uuid + const attributes = { name: 'my super user video' } + const { uuid } = await server.videosCommand.upload({ token: userAccessToken, attributes }) + videoUserUUID = uuid } { const attributes = { name: 'my super name' } - const res = await uploadVideo(server.url, server.accessToken, attributes) - videoUUID = res.body.video.uuid - videoId = res.body.video.id + const { uuid, id } = await server.videosCommand.upload({ attributes }) + videoUUID = uuid + videoId = id } }) diff --git a/server/tests/api/server/follow-constraints.ts b/server/tests/api/server/follow-constraints.ts index 29ccb264d..f9014aeee 100644 --- a/server/tests/api/server/follow-constraints.ts +++ b/server/tests/api/server/follow-constraints.ts @@ -3,19 +3,8 @@ import 'mocha' import * as chai from 'chai' import { HttpStatusCode } from '@shared/core-utils' +import { cleanupTests, doubleFollow, flushAndRunMultipleServers, ServerInfo, setAccessTokensToServers } from '@shared/extra-utils' import { PeerTubeProblemDocument, ServerErrorCode } from '@shared/models' -import { - cleanupTests, - doubleFollow, - flushAndRunMultipleServers, - getAccountVideos, - getVideo, - getVideoChannelVideos, - getVideoWithToken, - ServerInfo, - setAccessTokensToServers, - uploadVideo -} from '../../../../shared/extra-utils' const expect = chai.expect @@ -23,7 +12,7 @@ describe('Test follow constraints', function () { let servers: ServerInfo[] = [] let video1UUID: string let video2UUID: string - let userAccessToken: string + let userToken: string before(async function () { this.timeout(90000) @@ -34,12 +23,12 @@ describe('Test follow constraints', function () { await setAccessTokensToServers(servers) { - const res = await uploadVideo(servers[0].url, servers[0].accessToken, { name: 'video server 1' }) - video1UUID = res.body.video.uuid + const { uuid } = await servers[0].videosCommand.upload({ attributes: { name: 'video server 1' } }) + video1UUID = uuid } { - const res = await uploadVideo(servers[1].url, servers[1].accessToken, { name: 'video server 2' }) - video2UUID = res.body.video.uuid + const { uuid } = await servers[1].videosCommand.upload({ attributes: { name: 'video server 2' } }) + video2UUID = uuid } const user = { @@ -47,7 +36,7 @@ describe('Test follow constraints', function () { password: 'super_password' } await servers[0].usersCommand.create({ username: user.username, password: user.password }) - userAccessToken = await servers[0].loginCommand.getAccessToken(user) + userToken = await servers[0].loginCommand.getAccessToken(user) await doubleFollow(servers[0], servers[1]) }) @@ -57,81 +46,81 @@ describe('Test follow constraints', function () { describe('With an unlogged user', function () { it('Should get the local video', async function () { - await getVideo(servers[0].url, video1UUID, HttpStatusCode.OK_200) + await servers[0].videosCommand.get({ id: video1UUID }) }) it('Should get the remote video', async function () { - await getVideo(servers[0].url, video2UUID, HttpStatusCode.OK_200) + await servers[0].videosCommand.get({ id: video2UUID }) }) it('Should list local account videos', async function () { - const res = await getAccountVideos(servers[0].url, undefined, 'root@localhost:' + servers[0].port, 0, 5) + const { total, data } = await servers[0].videosCommand.listByAccount({ accountName: 'root@localhost:' + servers[0].port }) - expect(res.body.total).to.equal(1) - expect(res.body.data).to.have.lengthOf(1) + expect(total).to.equal(1) + expect(data).to.have.lengthOf(1) }) it('Should list remote account videos', async function () { - const res = await getAccountVideos(servers[0].url, undefined, 'root@localhost:' + servers[1].port, 0, 5) + const { total, data } = await servers[0].videosCommand.listByAccount({ accountName: 'root@localhost:' + servers[1].port }) - expect(res.body.total).to.equal(1) - expect(res.body.data).to.have.lengthOf(1) + expect(total).to.equal(1) + expect(data).to.have.lengthOf(1) }) it('Should list local channel videos', async function () { const videoChannelName = 'root_channel@localhost:' + servers[0].port - const res = await getVideoChannelVideos(servers[0].url, undefined, videoChannelName, 0, 5) + const { total, data } = await servers[0].videosCommand.listByChannel({ videoChannelName }) - expect(res.body.total).to.equal(1) - expect(res.body.data).to.have.lengthOf(1) + expect(total).to.equal(1) + expect(data).to.have.lengthOf(1) }) it('Should list remote channel videos', async function () { const videoChannelName = 'root_channel@localhost:' + servers[1].port - const res = await getVideoChannelVideos(servers[0].url, undefined, videoChannelName, 0, 5) + const { total, data } = await servers[0].videosCommand.listByChannel({ videoChannelName }) - expect(res.body.total).to.equal(1) - expect(res.body.data).to.have.lengthOf(1) + expect(total).to.equal(1) + expect(data).to.have.lengthOf(1) }) }) describe('With a logged user', function () { it('Should get the local video', async function () { - await getVideoWithToken(servers[0].url, userAccessToken, video1UUID, HttpStatusCode.OK_200) + await servers[0].videosCommand.getWithToken({ token: userToken, id: video1UUID }) }) it('Should get the remote video', async function () { - await getVideoWithToken(servers[0].url, userAccessToken, video2UUID, HttpStatusCode.OK_200) + await servers[0].videosCommand.getWithToken({ token: userToken, id: video2UUID }) }) it('Should list local account videos', async function () { - const res = await getAccountVideos(servers[0].url, userAccessToken, 'root@localhost:' + servers[0].port, 0, 5) + const { total, data } = await servers[0].videosCommand.listByAccount({ token: userToken, accountName: 'root@localhost:' + servers[0].port }) - expect(res.body.total).to.equal(1) - expect(res.body.data).to.have.lengthOf(1) + expect(total).to.equal(1) + expect(data).to.have.lengthOf(1) }) it('Should list remote account videos', async function () { - const res = await getAccountVideos(servers[0].url, userAccessToken, 'root@localhost:' + servers[1].port, 0, 5) + const { total, data } = await servers[0].videosCommand.listByAccount({ token: userToken, accountName: 'root@localhost:' + servers[1].port }) - expect(res.body.total).to.equal(1) - expect(res.body.data).to.have.lengthOf(1) + expect(total).to.equal(1) + expect(data).to.have.lengthOf(1) }) it('Should list local channel videos', async function () { const videoChannelName = 'root_channel@localhost:' + servers[0].port - const res = await getVideoChannelVideos(servers[0].url, userAccessToken, videoChannelName, 0, 5) + const { total, data } = await servers[0].videosCommand.listByChannel({ token: userToken, videoChannelName }) - expect(res.body.total).to.equal(1) - expect(res.body.data).to.have.lengthOf(1) + expect(total).to.equal(1) + expect(data).to.have.lengthOf(1) }) it('Should list remote channel videos', async function () { const videoChannelName = 'root_channel@localhost:' + servers[1].port - const res = await getVideoChannelVideos(servers[0].url, userAccessToken, videoChannelName, 0, 5) + const { total, data } = await servers[0].videosCommand.listByChannel({ token: userToken, videoChannelName }) - expect(res.body.total).to.equal(1) - expect(res.body.data).to.have.lengthOf(1) + expect(total).to.equal(1) + expect(data).to.have.lengthOf(1) }) }) }) @@ -147,13 +136,12 @@ describe('Test follow constraints', function () { describe('With an unlogged user', function () { it('Should get the local video', async function () { - await getVideo(servers[0].url, video1UUID, HttpStatusCode.OK_200) + await servers[0].videosCommand.get({ id: video1UUID }) }) it('Should not get the remote video', async function () { - const res = await getVideo(servers[0].url, video2UUID, HttpStatusCode.FORBIDDEN_403) - - const error = res.body as PeerTubeProblemDocument + const body = await servers[0].videosCommand.get({ id: video2UUID, expectedStatus: HttpStatusCode.FORBIDDEN_403 }) + const error = body as unknown as PeerTubeProblemDocument const doc = 'https://docs.joinpeertube.org/api-rest-reference.html#section/Errors/does_not_respect_follow_constraints' expect(error.type).to.equal(doc) @@ -168,73 +156,79 @@ describe('Test follow constraints', function () { }) it('Should list local account videos', async function () { - const res = await getAccountVideos(servers[0].url, undefined, 'root@localhost:' + servers[0].port, 0, 5) + const { total, data } = await servers[0].videosCommand.listByAccount({ + token: undefined, + accountName: 'root@localhost:' + servers[0].port + }) - expect(res.body.total).to.equal(1) - expect(res.body.data).to.have.lengthOf(1) + expect(total).to.equal(1) + expect(data).to.have.lengthOf(1) }) it('Should not list remote account videos', async function () { - const res = await getAccountVideos(servers[0].url, undefined, 'root@localhost:' + servers[1].port, 0, 5) + const { total, data } = await servers[0].videosCommand.listByAccount({ + token: undefined, + accountName: 'root@localhost:' + servers[1].port + }) - expect(res.body.total).to.equal(0) - expect(res.body.data).to.have.lengthOf(0) + expect(total).to.equal(0) + expect(data).to.have.lengthOf(0) }) it('Should list local channel videos', async function () { const videoChannelName = 'root_channel@localhost:' + servers[0].port - const res = await getVideoChannelVideos(servers[0].url, undefined, videoChannelName, 0, 5) + const { total, data } = await servers[0].videosCommand.listByChannel({ token: undefined, videoChannelName }) - expect(res.body.total).to.equal(1) - expect(res.body.data).to.have.lengthOf(1) + expect(total).to.equal(1) + expect(data).to.have.lengthOf(1) }) it('Should not list remote channel videos', async function () { const videoChannelName = 'root_channel@localhost:' + servers[1].port - const res = await getVideoChannelVideos(servers[0].url, undefined, videoChannelName, 0, 5) + const { total, data } = await servers[0].videosCommand.listByChannel({ token: undefined, videoChannelName }) - expect(res.body.total).to.equal(0) - expect(res.body.data).to.have.lengthOf(0) + expect(total).to.equal(0) + expect(data).to.have.lengthOf(0) }) }) describe('With a logged user', function () { it('Should get the local video', async function () { - await getVideoWithToken(servers[0].url, userAccessToken, video1UUID, HttpStatusCode.OK_200) + await servers[0].videosCommand.getWithToken({ token: userToken, id: video1UUID }) }) it('Should get the remote video', async function () { - await getVideoWithToken(servers[0].url, userAccessToken, video2UUID, HttpStatusCode.OK_200) + await servers[0].videosCommand.getWithToken({ token: userToken, id: video2UUID }) }) it('Should list local account videos', async function () { - const res = await getAccountVideos(servers[0].url, userAccessToken, 'root@localhost:' + servers[0].port, 0, 5) + const { total, data } = await servers[0].videosCommand.listByAccount({ token: userToken, accountName: 'root@localhost:' + servers[0].port }) - expect(res.body.total).to.equal(1) - expect(res.body.data).to.have.lengthOf(1) + expect(total).to.equal(1) + expect(data).to.have.lengthOf(1) }) it('Should list remote account videos', async function () { - const res = await getAccountVideos(servers[0].url, userAccessToken, 'root@localhost:' + servers[1].port, 0, 5) + const { total, data } = await servers[0].videosCommand.listByAccount({ token: userToken, accountName: 'root@localhost:' + servers[1].port }) - expect(res.body.total).to.equal(1) - expect(res.body.data).to.have.lengthOf(1) + expect(total).to.equal(1) + expect(data).to.have.lengthOf(1) }) it('Should list local channel videos', async function () { const videoChannelName = 'root_channel@localhost:' + servers[0].port - const res = await getVideoChannelVideos(servers[0].url, userAccessToken, videoChannelName, 0, 5) + const { total, data } = await servers[0].videosCommand.listByChannel({ token: userToken, videoChannelName }) - expect(res.body.total).to.equal(1) - expect(res.body.data).to.have.lengthOf(1) + expect(total).to.equal(1) + expect(data).to.have.lengthOf(1) }) it('Should list remote channel videos', async function () { const videoChannelName = 'root_channel@localhost:' + servers[1].port - const res = await getVideoChannelVideos(servers[0].url, userAccessToken, videoChannelName, 0, 5) + const { total, data } = await servers[0].videosCommand.listByChannel({ token: userToken, videoChannelName }) - expect(res.body.total).to.equal(1) - expect(res.body.data).to.have.lengthOf(1) + expect(total).to.equal(1) + expect(data).to.have.lengthOf(1) }) }) }) diff --git a/server/tests/api/server/follows.ts b/server/tests/api/server/follows.ts index 02d25e67f..5ce8938fa 100644 --- a/server/tests/api/server/follows.ts +++ b/server/tests/api/server/follows.ts @@ -9,12 +9,9 @@ import { expectAccountFollows, flushAndRunMultipleServers, FollowsCommand, - getVideosList, - rateVideo, ServerInfo, setAccessTokensToServers, testCaptionFile, - uploadVideo, waitJobs } from '@shared/extra-utils' import { Video, VideoPrivacy } from '@shared/models' @@ -287,22 +284,28 @@ describe('Test follows', function () { it('Should upload a video on server 2 and 3 and propagate only the video of server 2', async function () { this.timeout(60000) - await uploadVideo(servers[1].url, servers[1].accessToken, { name: 'server2' }) - await uploadVideo(servers[2].url, servers[2].accessToken, { name: 'server3' }) + await servers[1].videosCommand.upload({ attributes: { name: 'server2' } }) + await servers[2].videosCommand.upload({ attributes: { name: 'server3' } }) await waitJobs(servers) - let res = await getVideosList(servers[0].url) - expect(res.body.total).to.equal(1) - expect(res.body.data[0].name).to.equal('server2') + { + const { total, data } = await servers[0].videosCommand.list() + expect(total).to.equal(1) + expect(data[0].name).to.equal('server2') + } - res = await getVideosList(servers[1].url) - expect(res.body.total).to.equal(1) - expect(res.body.data[0].name).to.equal('server2') + { + const { total, data } = await servers[1].videosCommand.list() + expect(total).to.equal(1) + expect(data[0].name).to.equal('server2') + } - res = await getVideosList(servers[2].url) - expect(res.body.total).to.equal(1) - expect(res.body.data[0].name).to.equal('server3') + { + const { total, data } = await servers[2].videosCommand.list() + expect(total).to.equal(1) + expect(data[0].name).to.equal('server3') + } }) describe('Should propagate data on a new following', function () { @@ -319,21 +322,21 @@ describe('Test follows', function () { tags: [ 'tag1', 'tag2', 'tag3' ] } - await uploadVideo(servers[2].url, servers[2].accessToken, { name: 'server3-2' }) - await uploadVideo(servers[2].url, servers[2].accessToken, { name: 'server3-3' }) - await uploadVideo(servers[2].url, servers[2].accessToken, video4Attributes) - await uploadVideo(servers[2].url, servers[2].accessToken, { name: 'server3-5' }) - await uploadVideo(servers[2].url, servers[2].accessToken, { name: 'server3-6' }) + await servers[2].videosCommand.upload({ attributes: { name: 'server3-2' } }) + await servers[2].videosCommand.upload({ attributes: { name: 'server3-3' } }) + await servers[2].videosCommand.upload({ attributes: video4Attributes }) + await servers[2].videosCommand.upload({ attributes: { name: 'server3-5' } }) + await servers[2].videosCommand.upload({ attributes: { name: 'server3-6' } }) { const userAccessToken = await servers[2].usersCommand.generateUserAndToken('captain') - const resVideos = await getVideosList(servers[2].url) - video4 = resVideos.body.data.find(v => v.name === 'server3-4') + const { data } = await servers[2].videosCommand.list() + video4 = data.find(v => v.name === 'server3-4') { - await rateVideo(servers[2].url, servers[2].accessToken, video4.id, 'like') - await rateVideo(servers[2].url, userAccessToken, video4.id, 'dislike') + await servers[2].videosCommand.rate({ id: video4.id, rating: 'like' }) + await servers[2].videosCommand.rate({ token: userAccessToken, id: video4.id, rating: 'dislike' }) } { @@ -401,12 +404,12 @@ describe('Test follows', function () { }) it('Should have propagated videos', async function () { - const res = await getVideosList(servers[0].url) - expect(res.body.total).to.equal(7) + const { total, data } = await servers[0].videosCommand.list() + expect(total).to.equal(7) - const video2 = res.body.data.find(v => v.name === 'server3-2') - video4 = res.body.data.find(v => v.name === 'server3-4') - const video6 = res.body.data.find(v => v.name === 'server3-6') + const video2 = data.find(v => v.name === 'server3-2') + video4 = data.find(v => v.name === 'server3-4') + const video6 = data.find(v => v.name === 'server3-6') expect(video2).to.not.be.undefined expect(video4).to.not.be.undefined @@ -447,7 +450,7 @@ describe('Test follows', function () { } ] } - await completeVideoCheck(servers[0].url, video4, checkAttributes) + await completeVideoCheck(servers[0], video4, checkAttributes) }) it('Should have propagated comments', async function () { @@ -542,8 +545,8 @@ describe('Test follows', function () { await waitJobs(servers) - const res = await getVideosList(servers[0].url) - expect(res.body.total).to.equal(1) + const { total } = await servers[0].videosCommand.list() + expect(total).to.equal(1) }) }) diff --git a/server/tests/api/server/handle-down.ts b/server/tests/api/server/handle-down.ts index d45c3ae8a..35b905a8c 100644 --- a/server/tests/api/server/handle-down.ts +++ b/server/tests/api/server/handle-down.ts @@ -8,19 +8,14 @@ import { CommentsCommand, completeVideoCheck, flushAndRunMultipleServers, - getVideo, - getVideosList, killallServers, reRunServer, ServerInfo, setAccessTokensToServers, - updateVideo, - uploadVideo, - uploadVideoAndGetId, wait, waitJobs } from '@shared/extra-utils' -import { JobState, Video, VideoPrivacy } from '@shared/models' +import { JobState, VideoCreateResult, VideoPrivacy } from '@shared/models' const expect = chai.expect @@ -30,9 +25,9 @@ describe('Test handle downs', function () { let threadIdServer2: number let commentIdServer1: number let commentIdServer2: number - let missedVideo1: Video - let missedVideo2: Video - let unlistedVideo: Video + let missedVideo1: VideoCreateResult + let missedVideo2: VideoCreateResult + let unlistedVideo: VideoCreateResult const videoIdsServer1: string[] = [] @@ -110,15 +105,15 @@ describe('Test handle downs', function () { await waitJobs(servers) // Upload a video to server 1 - await uploadVideo(servers[0].url, servers[0].accessToken, videoAttributes) + await servers[0].videosCommand.upload({ attributes: videoAttributes }) await waitJobs(servers) // And check all servers have this video for (const server of servers) { - const res = await getVideosList(server.url) - expect(res.body.data).to.be.an('array') - expect(res.body.data).to.have.lengthOf(1) + const { data } = await server.videosCommand.list() + expect(data).to.be.an('array') + expect(data).to.have.lengthOf(1) } // Kill server 2 @@ -126,7 +121,7 @@ describe('Test handle downs', function () { // Remove server 2 follower for (let i = 0; i < 10; i++) { - await uploadVideo(servers[0].url, servers[0].accessToken, videoAttributes) + await servers[0].videosCommand.upload({ attributes: videoAttributes }) } await waitJobs([ servers[0], servers[2] ]) @@ -134,15 +129,12 @@ describe('Test handle downs', function () { // Kill server 3 await killallServers([ servers[2] ]) - const resLastVideo1 = await uploadVideo(servers[0].url, servers[0].accessToken, videoAttributes) - missedVideo1 = resLastVideo1.body.video + missedVideo1 = await servers[0].videosCommand.upload({ attributes: videoAttributes }) - const resLastVideo2 = await uploadVideo(servers[0].url, servers[0].accessToken, videoAttributes) - missedVideo2 = resLastVideo2.body.video + missedVideo2 = await servers[0].videosCommand.upload({ attributes: videoAttributes }) // Unlisted video - const resVideo = await uploadVideo(servers[0].url, servers[0].accessToken, unlistedVideoAttributes) - unlistedVideo = resVideo.body.video + unlistedVideo = await servers[0].videosCommand.upload({ attributes: unlistedVideoAttributes }) // Add comments to video 2 { @@ -202,25 +194,27 @@ describe('Test handle downs', function () { it('Should send an update to server 3, and automatically fetch the video', async function () { this.timeout(15000) - const res1 = await getVideosList(servers[2].url) - expect(res1.body.data).to.be.an('array') - expect(res1.body.data).to.have.lengthOf(11) + { + const { data } = await servers[2].videosCommand.list() + expect(data).to.be.an('array') + expect(data).to.have.lengthOf(11) + } - await updateVideo(servers[0].url, servers[0].accessToken, missedVideo1.uuid, {}) - await updateVideo(servers[0].url, servers[0].accessToken, unlistedVideo.uuid, {}) + await servers[0].videosCommand.update({ id: missedVideo1.uuid }) + await servers[0].videosCommand.update({ id: unlistedVideo.uuid }) await waitJobs(servers) - const res = await getVideosList(servers[2].url) - expect(res.body.data).to.be.an('array') - // 1 video is unlisted - expect(res.body.data).to.have.lengthOf(12) + { + const { data } = await servers[2].videosCommand.list() + expect(data).to.be.an('array') + // 1 video is unlisted + expect(data).to.have.lengthOf(12) + } // Check unlisted video - const resVideo = await getVideo(servers[2].url, unlistedVideo.uuid) - expect(resVideo.body).not.to.be.undefined - - await completeVideoCheck(servers[2].url, resVideo.body, unlistedCheckAttributes) + const video = await servers[2].videosCommand.get({ id: unlistedVideo.uuid }) + await completeVideoCheck(servers[2], video, unlistedCheckAttributes) }) it('Should send comments on a video to server 3, and automatically fetch the video', async function () { @@ -230,8 +224,7 @@ describe('Test handle downs', function () { await waitJobs(servers) - const resVideo = await getVideo(servers[2].url, missedVideo2.uuid) - expect(resVideo.body).not.to.be.undefined + await servers[2].videosCommand.get({ id: missedVideo2.uuid }) { const { data } = await servers[2].commentsCommand.listThreads({ videoId: missedVideo2.uuid }) @@ -293,14 +286,14 @@ describe('Test handle downs', function () { this.timeout(120000) for (let i = 0; i < 10; i++) { - const uuid = (await uploadVideoAndGetId({ server: servers[0], videoName: 'video ' + i })).uuid + const uuid = (await servers[0].videosCommand.quickUpload({ name: 'video ' + i })).uuid videoIdsServer1.push(uuid) } await waitJobs(servers) for (const id of videoIdsServer1) { - await getVideo(servers[1].url, id) + await servers[1].videosCommand.get({ id }) } await waitJobs(servers) @@ -310,7 +303,7 @@ describe('Test handle downs', function () { await wait(11000) // Refresh video -> score + 10 = 30 - await getVideo(servers[1].url, videoIdsServer1[0]) + await servers[1].videosCommand.get({ id: videoIdsServer1[0] }) await waitJobs(servers) }) @@ -325,14 +318,14 @@ describe('Test handle downs', function () { for (let i = 0; i < 5; i++) { try { - await getVideo(servers[1].url, videoIdsServer1[i]) + await servers[1].videosCommand.get({ id: videoIdsServer1[i] }) await waitJobs([ servers[1] ]) await wait(1500) } catch {} } for (const id of videoIdsServer1) { - await getVideo(servers[1].url, id, HttpStatusCode.FORBIDDEN_403) + await servers[1].videosCommand.get({ id, expectedStatus: HttpStatusCode.FORBIDDEN_403 }) } }) diff --git a/server/tests/api/server/jobs.ts b/server/tests/api/server/jobs.ts index 6854568d3..aa4c7587b 100644 --- a/server/tests/api/server/jobs.ts +++ b/server/tests/api/server/jobs.ts @@ -9,7 +9,6 @@ import { flushAndRunMultipleServers, ServerInfo, setAccessTokensToServers, - uploadVideo, waitJobs } from '@shared/extra-utils' @@ -32,8 +31,8 @@ describe('Test jobs', function () { it('Should create some jobs', async function () { this.timeout(120000) - await uploadVideo(servers[1].url, servers[1].accessToken, { name: 'video1' }) - await uploadVideo(servers[1].url, servers[1].accessToken, { name: 'video2' }) + await servers[1].videosCommand.upload({ attributes: { name: 'video1' } }) + await servers[1].videosCommand.upload({ attributes: { name: 'video2' } }) await waitJobs(servers) }) diff --git a/server/tests/api/server/logs.ts b/server/tests/api/server/logs.ts index 096d63e21..e7bef5a4a 100644 --- a/server/tests/api/server/logs.ts +++ b/server/tests/api/server/logs.ts @@ -10,7 +10,6 @@ import { reRunServer, ServerInfo, setAccessTokensToServers, - uploadVideo, waitJobs } from '@shared/extra-utils' @@ -34,12 +33,12 @@ describe('Test logs', function () { it('Should get logs with a start date', async function () { this.timeout(20000) - await uploadVideo(server.url, server.accessToken, { name: 'video 1' }) + await server.videosCommand.upload({ attributes: { name: 'video 1' } }) await waitJobs([ server ]) const now = new Date() - await uploadVideo(server.url, server.accessToken, { name: 'video 2' }) + await server.videosCommand.upload({ attributes: { name: 'video 2' } }) await waitJobs([ server ]) const body = await logsCommand.getLogs({ startDate: now }) @@ -52,17 +51,17 @@ describe('Test logs', function () { it('Should get logs with an end date', async function () { this.timeout(30000) - await uploadVideo(server.url, server.accessToken, { name: 'video 3' }) + await server.videosCommand.upload({ attributes: { name: 'video 3' } }) await waitJobs([ server ]) const now1 = new Date() - await uploadVideo(server.url, server.accessToken, { name: 'video 4' }) + await server.videosCommand.upload({ attributes: { name: 'video 4' } }) await waitJobs([ server ]) const now2 = new Date() - await uploadVideo(server.url, server.accessToken, { name: 'video 5' }) + await server.videosCommand.upload({ attributes: { name: 'video 5' } }) await waitJobs([ server ]) const body = await logsCommand.getLogs({ startDate: now1, endDate: now2 }) @@ -78,7 +77,7 @@ describe('Test logs', function () { const now = new Date() - await uploadVideo(server.url, server.accessToken, { name: 'video 6' }) + await server.videosCommand.upload({ attributes: { name: 'video 6' } }) await waitJobs([ server ]) { @@ -131,12 +130,12 @@ describe('Test logs', function () { it('Should get logs with a start date', async function () { this.timeout(20000) - await uploadVideo(server.url, server.accessToken, { name: 'video 7' }) + await server.videosCommand.upload({ attributes: { name: 'video 7' } }) await waitJobs([ server ]) const now = new Date() - await uploadVideo(server.url, server.accessToken, { name: 'video 8' }) + await server.videosCommand.upload({ attributes: { name: 'video 8' } }) await waitJobs([ server ]) const body = await logsCommand.getAuditLogs({ startDate: now }) @@ -157,17 +156,17 @@ describe('Test logs', function () { it('Should get logs with an end date', async function () { this.timeout(30000) - await uploadVideo(server.url, server.accessToken, { name: 'video 9' }) + await server.videosCommand.upload({ attributes: { name: 'video 9' } }) await waitJobs([ server ]) const now1 = new Date() - await uploadVideo(server.url, server.accessToken, { name: 'video 10' }) + await server.videosCommand.upload({ attributes: { name: 'video 10' } }) await waitJobs([ server ]) const now2 = new Date() - await uploadVideo(server.url, server.accessToken, { name: 'video 11' }) + await server.videosCommand.upload({ attributes: { name: 'video 11' } }) await waitJobs([ server ]) const body = await logsCommand.getAuditLogs({ startDate: now1, endDate: now2 }) diff --git a/server/tests/api/server/reverse-proxy.ts b/server/tests/api/server/reverse-proxy.ts index b8bae161a..5a6491430 100644 --- a/server/tests/api/server/reverse-proxy.ts +++ b/server/tests/api/server/reverse-proxy.ts @@ -2,20 +2,11 @@ import { expect } from 'chai' import { HttpStatusCode } from '@shared/core-utils' -import { - cleanupTests, - flushAndRunServer, - getVideo, - ServerInfo, - setAccessTokensToServers, - uploadVideo, - viewVideo, - wait -} from '@shared/extra-utils' +import { cleanupTests, flushAndRunServer, ServerInfo, setAccessTokensToServers, wait } from '@shared/extra-utils' describe('Test application behind a reverse proxy', function () { let server: ServerInfo - let videoId: number + let videoId: string before(async function () { this.timeout(30000) @@ -42,60 +33,60 @@ describe('Test application behind a reverse proxy', function () { server = await flushAndRunServer(1, config) await setAccessTokensToServers([ server ]) - const { body } = await uploadVideo(server.url, server.accessToken, {}) - videoId = body.video.uuid + const { uuid } = await server.videosCommand.upload() + videoId = uuid }) it('Should view a video only once with the same IP by default', async function () { this.timeout(20000) - await viewVideo(server.url, videoId) - await viewVideo(server.url, videoId) + await server.videosCommand.view({ id: videoId }) + await server.videosCommand.view({ id: videoId }) // Wait the repeatable job await wait(8000) - const { body } = await getVideo(server.url, videoId) - expect(body.views).to.equal(1) + const video = await server.videosCommand.get({ id: videoId }) + expect(video.views).to.equal(1) }) it('Should view a video 2 times with the X-Forwarded-For header set', async function () { this.timeout(20000) - await viewVideo(server.url, videoId, HttpStatusCode.NO_CONTENT_204, '0.0.0.1,127.0.0.1') - await viewVideo(server.url, videoId, HttpStatusCode.NO_CONTENT_204, '0.0.0.2,127.0.0.1') + await server.videosCommand.view({ id: videoId, xForwardedFor: '0.0.0.1,127.0.0.1' }) + await server.videosCommand.view({ id: videoId, xForwardedFor: '0.0.0.2,127.0.0.1' }) // Wait the repeatable job await wait(8000) - const { body } = await getVideo(server.url, videoId) - expect(body.views).to.equal(3) + const video = await server.videosCommand.get({ id: videoId }) + expect(video.views).to.equal(3) }) it('Should view a video only once with the same client IP in the X-Forwarded-For header', async function () { this.timeout(20000) - await viewVideo(server.url, videoId, HttpStatusCode.NO_CONTENT_204, '0.0.0.4,0.0.0.3,::ffff:127.0.0.1') - await viewVideo(server.url, videoId, HttpStatusCode.NO_CONTENT_204, '0.0.0.5,0.0.0.3,127.0.0.1') + await server.videosCommand.view({ id: videoId, xForwardedFor: '0.0.0.4,0.0.0.3,::ffff:127.0.0.1' }) + await server.videosCommand.view({ id: videoId, xForwardedFor: '0.0.0.5,0.0.0.3,127.0.0.1' }) // Wait the repeatable job await wait(8000) - const { body } = await getVideo(server.url, videoId) - expect(body.views).to.equal(4) + const video = await server.videosCommand.get({ id: videoId }) + expect(video.views).to.equal(4) }) it('Should view a video two times with a different client IP in the X-Forwarded-For header', async function () { this.timeout(20000) - await viewVideo(server.url, videoId, HttpStatusCode.NO_CONTENT_204, '0.0.0.8,0.0.0.6,127.0.0.1') - await viewVideo(server.url, videoId, HttpStatusCode.NO_CONTENT_204, '0.0.0.8,0.0.0.7,127.0.0.1') + await server.videosCommand.view({ id: videoId, xForwardedFor: '0.0.0.8,0.0.0.6,127.0.0.1' }) + await server.videosCommand.view({ id: videoId, xForwardedFor: '0.0.0.8,0.0.0.7,127.0.0.1' }) // Wait the repeatable job await wait(8000) - const { body } = await getVideo(server.url, videoId) - expect(body.views).to.equal(6) + const video = await server.videosCommand.get({ id: videoId }) + expect(video.views).to.equal(6) }) it('Should rate limit logins', async function () { @@ -140,13 +131,13 @@ describe('Test application behind a reverse proxy', function () { for (let i = 0; i < 100; i++) { try { - await getVideo(server.url, videoId) + await server.videosCommand.get({ id: videoId }) } catch { // don't care if it fails } } - await getVideo(server.url, videoId, HttpStatusCode.TOO_MANY_REQUESTS_429) + await server.videosCommand.get({ id: videoId, expectedStatus: HttpStatusCode.TOO_MANY_REQUESTS_429 }) }) after(async function () { diff --git a/server/tests/api/server/services.ts b/server/tests/api/server/services.ts index 77b95de10..a62fb3939 100644 --- a/server/tests/api/server/services.ts +++ b/server/tests/api/server/services.ts @@ -2,15 +2,8 @@ import 'mocha' import * as chai from 'chai' +import { cleanupTests, flushAndRunServer, ServerInfo, setAccessTokensToServers, setDefaultVideoChannel } from '@shared/extra-utils' import { Video, VideoPlaylistPrivacy } from '@shared/models' -import { - getVideosList, - ServerInfo, - setAccessTokensToServers, - setDefaultVideoChannel, - uploadVideo -} from '../../../../shared/extra-utils' -import { cleanupTests, flushAndRunServer } from '../../../../shared/extra-utils/server/servers' const expect = chai.expect @@ -29,13 +22,11 @@ describe('Test services', function () { await setDefaultVideoChannel([ server ]) { - const videoAttributes = { - name: 'my super name' - } - await uploadVideo(server.url, server.accessToken, videoAttributes) + const attributes = { name: 'my super name' } + await server.videosCommand.upload({ attributes }) - const res = await getVideosList(server.url) - video = res.body.data[0] + const { data } = await server.videosCommand.list() + video = data[0] } { diff --git a/server/tests/api/server/stats.ts b/server/tests/api/server/stats.ts index a35709c26..3eb1efb94 100644 --- a/server/tests/api/server/stats.ts +++ b/server/tests/api/server/stats.ts @@ -8,8 +8,6 @@ import { flushAndRunMultipleServers, ServerInfo, setAccessTokensToServers, - uploadVideo, - viewVideo, wait, waitJobs } from '@shared/extra-utils' @@ -36,12 +34,11 @@ describe('Test stats (excluding redundancy)', function () { await servers[0].usersCommand.create({ username: user.username, password: user.password }) - const resVideo = await uploadVideo(servers[0].url, servers[0].accessToken, { fixture: 'video_short.webm' }) - const videoUUID = resVideo.body.video.uuid + const { uuid } = await servers[0].videosCommand.upload({ attributes: { fixture: 'video_short.webm' } }) - await servers[0].commentsCommand.createThread({ videoId: videoUUID, text: 'comment' }) + await servers[0].commentsCommand.createThread({ videoId: uuid, text: 'comment' }) - await viewVideo(servers[0].url, videoUUID) + await servers[0].videosCommand.view({ id: uuid }) // Wait the video views repeatable job await wait(8000) @@ -154,7 +151,7 @@ describe('Test stats (excluding redundancy)', function () { } { - await uploadVideo(server.url, server.accessToken, { fixture: 'video_short.webm', channelId }) + await server.videosCommand.upload({ attributes: { fixture: 'video_short.webm', channelId } }) const data = await server.statsCommand.get() @@ -213,7 +210,7 @@ describe('Test stats (excluding redundancy)', function () { } }) - await uploadVideo(servers[0].url, servers[0].accessToken, { name: 'video', fixture: 'video_short.webm' }) + await servers[0].videosCommand.upload({ attributes: { name: 'video', fixture: 'video_short.webm' } }) await waitJobs(servers) @@ -243,7 +240,7 @@ describe('Test stats (excluding redundancy)', function () { const first = await servers[1].statsCommand.get() for (let i = 0; i < 10; i++) { - await uploadVideo(servers[0].url, servers[0].accessToken, { name: 'video' }) + await servers[0].videosCommand.upload({ attributes: { name: 'video' } }) } await waitJobs(servers) diff --git a/server/tests/api/server/tracker.ts b/server/tests/api/server/tracker.ts index 868dc8977..032012edf 100644 --- a/server/tests/api/server/tracker.ts +++ b/server/tests/api/server/tracker.ts @@ -1,19 +1,9 @@ /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await,@typescript-eslint/no-floating-promises */ -import * as magnetUtil from 'magnet-uri' import 'mocha' -import { - cleanupTests, - flushAndRunServer, - getVideo, - killallServers, - reRunServer, - ServerInfo, - uploadVideo -} from '../../../../shared/extra-utils' -import { setAccessTokensToServers } from '../../../../shared/extra-utils/index' -import { VideoDetails } from '../../../../shared/models/videos' +import * as magnetUtil from 'magnet-uri' import * as WebTorrent from 'webtorrent' +import { cleanupTests, flushAndRunServer, killallServers, reRunServer, ServerInfo, setAccessTokensToServers } from '@shared/extra-utils' describe('Test tracker', function () { let server: ServerInfo @@ -26,11 +16,8 @@ describe('Test tracker', function () { await setAccessTokensToServers([ server ]) { - const res = await uploadVideo(server.url, server.accessToken, {}) - const videoUUID = res.body.video.uuid - - const resGet = await getVideo(server.url, videoUUID) - const video: VideoDetails = resGet.body + const { uuid } = await server.videosCommand.upload() + const video = await server.videosCommand.get({ id: uuid }) goodMagnet = video.files[0].magnetUri const parsed = magnetUtil.decode(goodMagnet) diff --git a/server/tests/api/users/user-subscriptions.ts b/server/tests/api/users/user-subscriptions.ts index c09a85a32..622cddb7d 100644 --- a/server/tests/api/users/user-subscriptions.ts +++ b/server/tests/api/users/user-subscriptions.ts @@ -6,12 +6,9 @@ import { cleanupTests, doubleFollow, flushAndRunMultipleServers, - getVideosList, ServerInfo, setAccessTokensToServers, SubscriptionsCommand, - updateVideo, - uploadVideo, waitJobs } from '@shared/extra-utils' @@ -44,10 +41,10 @@ describe('Test users subscriptions', function () { users.push({ accessToken }) const videoName1 = 'video 1-' + server.serverNumber - await uploadVideo(server.url, accessToken, { name: videoName1 }) + await server.videosCommand.upload({ token: accessToken, attributes: { name: videoName1 } }) const videoName2 = 'video 2-' + server.serverNumber - await uploadVideo(server.url, accessToken, { name: videoName2 }) + await server.videosCommand.upload({ token: accessToken, attributes: { name: videoName2 } }) } } @@ -57,9 +54,9 @@ describe('Test users subscriptions', function () { }) it('Should display videos of server 2 on server 1', async function () { - const res = await getVideosList(servers[0].url) + const { total } = await servers[0].videosCommand.list() - expect(res.body.total).to.equal(4) + expect(total).to.equal(4) }) it('User of server 1 should follow user of server 3 and root of server 1', async function () { @@ -70,17 +67,17 @@ describe('Test users subscriptions', function () { await waitJobs(servers) - const res = await uploadVideo(servers[2].url, users[2].accessToken, { name: 'video server 3 added after follow' }) - video3UUID = res.body.video.uuid + const { uuid } = await servers[2].videosCommand.upload({ attributes: { name: 'video server 3 added after follow' } }) + video3UUID = uuid await waitJobs(servers) }) it('Should not display videos of server 3 on server 1', async function () { - const res = await getVideosList(servers[0].url) + const { total, data } = await servers[0].videosCommand.list() + expect(total).to.equal(4) - expect(res.body.total).to.equal(4) - for (const video of res.body.data) { + for (const video of data) { expect(video.name).to.not.contain('1-3') expect(video.name).to.not.contain('2-3') expect(video.name).to.not.contain('video server 3 added after follow') @@ -186,7 +183,7 @@ describe('Test users subscriptions', function () { this.timeout(60000) const videoName = 'video server 1 added after follow' - await uploadVideo(servers[0].url, servers[0].accessToken, { name: videoName }) + await servers[0].videosCommand.upload({ attributes: { name: videoName } }) await waitJobs(servers) @@ -212,10 +209,10 @@ describe('Test users subscriptions', function () { } { - const res = await getVideosList(servers[0].url) + const { data, total } = await servers[0].videosCommand.list() + expect(total).to.equal(5) - expect(res.body.total).to.equal(5) - for (const video of res.body.data) { + for (const video of data) { expect(video.name).to.not.contain('1-3') expect(video.name).to.not.contain('2-3') expect(video.name).to.not.contain('video server 3 added after follow') @@ -230,13 +227,12 @@ describe('Test users subscriptions', function () { await waitJobs(servers) - const res = await getVideosList(servers[0].url) - - expect(res.body.total).to.equal(8) + const { data, total } = await servers[0].videosCommand.list() + expect(total).to.equal(8) const names = [ '1-3', '2-3', 'video server 3 added after follow' ] for (const name of names) { - const video = res.body.data.find(v => v.name.indexOf(name) === -1) + const video = data.find(v => v.name.includes(name)) expect(video).to.not.be.undefined } }) @@ -248,10 +244,10 @@ describe('Test users subscriptions', function () { await waitJobs(servers) - const res = await getVideosList(servers[0].url) + const { total, data } = await servers[0].videosCommand.list() + expect(total).to.equal(5) - expect(res.body.total).to.equal(5) - for (const video of res.body.data) { + for (const video of data) { expect(video.name).to.not.contain('1-3') expect(video.name).to.not.contain('2-3') expect(video.name).to.not.contain('video server 3 added after follow') @@ -284,7 +280,7 @@ describe('Test users subscriptions', function () { it('Should update a video of server 3 and see the updated video on server 1', async function () { this.timeout(30000) - await updateVideo(servers[2].url, users[2].accessToken, video3UUID, { name: 'video server 3 added after follow updated' }) + await servers[2].videosCommand.update({ id: video3UUID, attributes: { name: 'video server 3 added after follow updated' } }) await waitJobs(servers) @@ -329,10 +325,10 @@ describe('Test users subscriptions', function () { }) it('Should correctly display public videos on server 1', async function () { - const res = await getVideosList(servers[0].url) + const { total, data } = await servers[0].videosCommand.list() + expect(total).to.equal(5) - expect(res.body.total).to.equal(5) - for (const video of res.body.data) { + for (const video of data) { expect(video.name).to.not.contain('1-3') expect(video.name).to.not.contain('2-3') expect(video.name).to.not.contain('video server 3 added after follow updated') @@ -360,10 +356,10 @@ describe('Test users subscriptions', function () { } { - const res = await getVideosList(servers[0].url) + const { total, data } = await servers[0].videosCommand.list() + expect(total).to.equal(5) - expect(res.body.total).to.equal(5) - for (const video of res.body.data) { + for (const video of data) { expect(video.name).to.not.contain('1-3') expect(video.name).to.not.contain('2-3') expect(video.name).to.not.contain('video server 3 added after follow updated') diff --git a/server/tests/api/users/users-multiple-servers.ts b/server/tests/api/users/users-multiple-servers.ts index 43e67ee60..3ae105008 100644 --- a/server/tests/api/users/users-multiple-servers.ts +++ b/server/tests/api/users/users-multiple-servers.ts @@ -9,11 +9,9 @@ import { cleanupTests, doubleFollow, flushAndRunMultipleServers, - getAccountVideos, ServerInfo, setAccessTokensToServers, testImage, - uploadVideo, waitJobs } from '@shared/extra-utils' import { User } from '@shared/models' @@ -44,7 +42,7 @@ describe('Test users with multiple servers', function () { await doubleFollow(servers[1], servers[2]) // The root user of server 1 is propagated to servers 2 and 3 - await uploadVideo(servers[0].url, servers[0].accessToken, {}) + await servers[0].videosCommand.upload() { const user = { @@ -57,8 +55,8 @@ describe('Test users with multiple servers', function () { } { - const resVideo = await uploadVideo(servers[0].url, userAccessToken, {}) - videoUUID = resVideo.body.video.uuid + const { uuid } = await servers[0].videosCommand.upload({ token: userAccessToken }) + videoUUID = uuid } await waitJobs(servers) @@ -133,31 +131,29 @@ describe('Test users with multiple servers', function () { it('Should list account videos', async function () { for (const server of servers) { - const res = await getAccountVideos(server.url, server.accessToken, 'user1@localhost:' + servers[0].port, 0, 5) + const { total, data } = await server.videosCommand.listByAccount({ accountName: 'user1@localhost:' + servers[0].port }) - expect(res.body.total).to.equal(1) - expect(res.body.data).to.be.an('array') - expect(res.body.data).to.have.lengthOf(1) - expect(res.body.data[0].uuid).to.equal(videoUUID) + expect(total).to.equal(1) + expect(data).to.be.an('array') + expect(data).to.have.lengthOf(1) + expect(data[0].uuid).to.equal(videoUUID) } }) it('Should search through account videos', async function () { this.timeout(10_000) - const resVideo = await uploadVideo(servers[0].url, userAccessToken, { name: 'Kami no chikara' }) + const created = await servers[0].videosCommand.upload({ token: userAccessToken, attributes: { name: 'Kami no chikara' } }) await waitJobs(servers) for (const server of servers) { - const res = await getAccountVideos(server.url, server.accessToken, 'user1@localhost:' + servers[0].port, 0, 5, undefined, { - search: 'Kami' - }) - - expect(res.body.total).to.equal(1) - expect(res.body.data).to.be.an('array') - expect(res.body.data).to.have.lengthOf(1) - expect(res.body.data[0].uuid).to.equal(resVideo.body.video.uuid) + const { total, data } = await server.videosCommand.listByAccount({ accountName: 'user1@localhost:' + servers[0].port, search: 'Kami' }) + + expect(total).to.equal(1) + expect(data).to.be.an('array') + expect(data).to.have.lengthOf(1) + expect(data[0].uuid).to.equal(created.uuid) } }) diff --git a/server/tests/api/users/users.ts b/server/tests/api/users/users.ts index 30d7e850d..6f3873939 100644 --- a/server/tests/api/users/users.ts +++ b/server/tests/api/users/users.ts @@ -6,17 +6,12 @@ import { HttpStatusCode } from '@shared/core-utils' import { cleanupTests, flushAndRunServer, - getMyVideos, - getVideosList, killallServers, makePutBodyRequest, - rateVideo, - removeVideo, reRunServer, ServerInfo, setAccessTokensToServers, testImage, - uploadVideo, waitJobs } from '@shared/extra-utils' import { AbuseState, OAuth2ErrorCode, UserAdminFlag, UserRole, Video, VideoPlaylistType } from '@shared/models' @@ -25,8 +20,8 @@ const expect = chai.expect describe('Test users', function () { let server: ServerInfo - let accessToken: string - let accessTokenUser: string + let token: string + let userToken: string let videoId: number let userId: number const user = { @@ -101,18 +96,17 @@ describe('Test users', function () { }) it('Should not be able to upload a video', async function () { - accessToken = 'my_super_token' + token = 'my_super_token' - const videoAttributes = {} - await uploadVideo(server.url, accessToken, videoAttributes, HttpStatusCode.UNAUTHORIZED_401) + await server.videosCommand.upload({ token, expectedStatus: HttpStatusCode.UNAUTHORIZED_401 }) }) it('Should not be able to follow', async function () { - accessToken = 'my_super_token' + token = 'my_super_token' await server.followsCommand.follow({ targets: [ 'http://example.com' ], - token: accessToken, + token, expectedStatus: HttpStatusCode.UNAUTHORIZED_401 }) }) @@ -122,7 +116,7 @@ describe('Test users', function () { it('Should be able to login', async function () { const body = await server.loginCommand.login({ expectedStatus: HttpStatusCode.OK_200 }) - accessToken = body.access_token + token = body.access_token }) it('Should be able to login with an insensitive username', async function () { @@ -140,33 +134,31 @@ describe('Test users', function () { describe('Upload', function () { it('Should upload the video with the correct token', async function () { - const videoAttributes = {} - await uploadVideo(server.url, accessToken, videoAttributes) - const res = await getVideosList(server.url) - const video = res.body.data[0] + await server.videosCommand.upload({ token }) + const { data } = await server.videosCommand.list() + const video = data[0] expect(video.account.name).to.equal('root') videoId = video.id }) it('Should upload the video again with the correct token', async function () { - const videoAttributes = {} - await uploadVideo(server.url, accessToken, videoAttributes) + await server.videosCommand.upload({ token }) }) }) describe('Ratings', function () { it('Should retrieve a video rating', async function () { - await rateVideo(server.url, accessToken, videoId, 'like') - const rating = await server.usersCommand.getMyRating({ token: accessToken, videoId }) + await server.videosCommand.rate({ id: videoId, rating: 'like' }) + const rating = await server.usersCommand.getMyRating({ token, videoId }) expect(rating.videoId).to.equal(videoId) expect(rating.rating).to.equal('like') }) it('Should retrieve ratings list', async function () { - await rateVideo(server.url, accessToken, videoId, 'like') + await server.videosCommand.rate({ id: videoId, rating: 'like' }) const body = await server.accountsCommand.listRatings({ accountName: server.user.username }) @@ -190,13 +182,13 @@ describe('Test users', function () { describe('Remove video', function () { it('Should not be able to remove the video with an incorrect token', async function () { - await removeVideo(server.url, 'bad_token', videoId, HttpStatusCode.UNAUTHORIZED_401) + await server.videosCommand.remove({ token: 'bad_token', id: videoId, expectedStatus: HttpStatusCode.UNAUTHORIZED_401 }) }) it('Should not be able to remove the video with the token of another account') it('Should be able to remove the video with the correct token', async function () { - await removeVideo(server.url, accessToken, videoId) + await server.videosCommand.remove({ token, id: videoId }) }) }) @@ -210,7 +202,7 @@ describe('Test users', function () { }) it('Should not be able to upload a video', async function () { - await uploadVideo(server.url, server.accessToken, { name: 'video' }, HttpStatusCode.UNAUTHORIZED_401) + await server.videosCommand.upload({ attributes: { name: 'video' }, expectedStatus: HttpStatusCode.UNAUTHORIZED_401 }) }) it('Should not be able to rate a video', async function () { @@ -281,11 +273,11 @@ describe('Test users', function () { }) it('Should be able to login with this user', async function () { - accessTokenUser = await server.loginCommand.getAccessToken(user) + userToken = await server.loginCommand.getAccessToken(user) }) it('Should be able to get user information', async function () { - const userMe = await server.usersCommand.getMyInfo({ token: accessTokenUser }) + const userMe = await server.usersCommand.getMyInfo({ token: userToken }) const userGet = await server.usersCommand.get({ userId: userMe.id, withStats: true }) @@ -323,15 +315,15 @@ describe('Test users', function () { it('Should be able to upload a video with this user', async function () { this.timeout(10000) - const videoAttributes = { + const attributes = { name: 'super user video', fixture: 'video_short.webm' } - await uploadVideo(server.url, accessTokenUser, videoAttributes) + await server.videosCommand.upload({ token: userToken, attributes }) }) it('Should have video quota updated', async function () { - const quota = await server.usersCommand.getMyQuotaUsed({ token: accessTokenUser }) + const quota = await server.usersCommand.getMyQuotaUsed({ token: userToken }) expect(quota.videoQuotaUsed).to.equal(218910) const { data } = await server.usersCommand.list() @@ -340,13 +332,11 @@ describe('Test users', function () { }) it('Should be able to list my videos', async function () { - const res = await getMyVideos(server.url, accessTokenUser, 0, 5) - expect(res.body.total).to.equal(1) - - const videos = res.body.data - expect(videos).to.have.lengthOf(1) + const { total, data } = await server.videosCommand.listMyVideos({ token: userToken }) + expect(total).to.equal(1) + expect(data).to.have.lengthOf(1) - const video: Video = videos[0] + const video: Video = data[0] expect(video.name).to.equal('super user video') expect(video.thumbnailPath).to.not.be.null expect(video.previewPath).to.not.be.null @@ -354,19 +344,15 @@ describe('Test users', function () { it('Should be able to search in my videos', async function () { { - const res = await getMyVideos(server.url, accessTokenUser, 0, 5, '-createdAt', 'user video') - expect(res.body.total).to.equal(1) - - const videos = res.body.data - expect(videos).to.have.lengthOf(1) + const { total, data } = await server.videosCommand.listMyVideos({ token: userToken, sort: '-createdAt', search: 'user video' }) + expect(total).to.equal(1) + expect(data).to.have.lengthOf(1) } { - const res = await getMyVideos(server.url, accessTokenUser, 0, 5, '-createdAt', 'toto') - expect(res.body.total).to.equal(0) - - const videos = res.body.data - expect(videos).to.have.lengthOf(0) + const { total, data } = await server.videosCommand.listMyVideos({ token: userToken, sort: '-createdAt', search: 'toto' }) + expect(total).to.equal(0) + expect(data).to.have.lengthOf(0) } }) @@ -382,17 +368,17 @@ describe('Test users', function () { } { - const videoAttributes = { + const attributes = { name: 'super user video 2', fixture: 'video_short.webm' } - await uploadVideo(server.url, accessTokenUser, videoAttributes) + await server.videosCommand.upload({ token: userToken, attributes }) await waitJobs([ server ]) } { - const data = await server.usersCommand.getMyQuotaUsed({ token: accessTokenUser }) + const data = await server.usersCommand.getMyQuotaUsed({ token: userToken }) expect(data.videoQuotaUsed).to.be.greaterThan(220000) } }) @@ -505,7 +491,7 @@ describe('Test users', function () { it('Should update my password', async function () { await server.usersCommand.updateMe({ - token: accessTokenUser, + token: userToken, currentPassword: 'super password', password: 'new password' }) @@ -516,11 +502,11 @@ describe('Test users', function () { it('Should be able to change the NSFW display attribute', async function () { await server.usersCommand.updateMe({ - token: accessTokenUser, + token: userToken, nsfwPolicy: 'do_not_list' }) - const user = await server.usersCommand.getMyInfo({ token: accessTokenUser }) + const user = await server.usersCommand.getMyInfo({ token: userToken }) expect(user.username).to.equal('user_1') expect(user.email).to.equal('user_1@example.com') expect(user.nsfwPolicy).to.equal('do_not_list') @@ -532,32 +518,32 @@ describe('Test users', function () { it('Should be able to change the autoPlayVideo attribute', async function () { await server.usersCommand.updateMe({ - token: accessTokenUser, + token: userToken, autoPlayVideo: false }) - const user = await server.usersCommand.getMyInfo({ token: accessTokenUser }) + const user = await server.usersCommand.getMyInfo({ token: userToken }) expect(user.autoPlayVideo).to.be.false }) it('Should be able to change the autoPlayNextVideo attribute', async function () { await server.usersCommand.updateMe({ - token: accessTokenUser, + token: userToken, autoPlayNextVideo: true }) - const user = await server.usersCommand.getMyInfo({ token: accessTokenUser }) + const user = await server.usersCommand.getMyInfo({ token: userToken }) expect(user.autoPlayNextVideo).to.be.true }) it('Should be able to change the email attribute', async function () { await server.usersCommand.updateMe({ - token: accessTokenUser, + token: userToken, currentPassword: 'new password', email: 'updated@example.com' }) - const user = await server.usersCommand.getMyInfo({ token: accessTokenUser }) + const user = await server.usersCommand.getMyInfo({ token: userToken }) expect(user.username).to.equal('user_1') expect(user.email).to.equal('updated@example.com') expect(user.nsfwPolicy).to.equal('do_not_list') @@ -570,9 +556,9 @@ describe('Test users', function () { it('Should be able to update my avatar with a gif', async function () { const fixture = 'avatar.gif' - await server.usersCommand.updateMyAvatar({ token: accessTokenUser, fixture }) + await server.usersCommand.updateMyAvatar({ token: userToken, fixture }) - const user = await server.usersCommand.getMyInfo({ token: accessTokenUser }) + const user = await server.usersCommand.getMyInfo({ token: userToken }) await testImage(server.url, 'avatar-resized', user.account.avatar.path, '.gif') }) @@ -580,17 +566,17 @@ describe('Test users', function () { for (const extension of [ '.png', '.gif' ]) { const fixture = 'avatar' + extension - await server.usersCommand.updateMyAvatar({ token: accessTokenUser, fixture }) + await server.usersCommand.updateMyAvatar({ token: userToken, fixture }) - const user = await server.usersCommand.getMyInfo({ token: accessTokenUser }) + const user = await server.usersCommand.getMyInfo({ token: userToken }) await testImage(server.url, 'avatar-resized', user.account.avatar.path, extension) } }) it('Should be able to update my display name', async function () { - await server.usersCommand.updateMe({ token: accessTokenUser, displayName: 'new display name' }) + await server.usersCommand.updateMe({ token: userToken, displayName: 'new display name' }) - const user = await server.usersCommand.getMyInfo({ token: accessTokenUser }) + const user = await server.usersCommand.getMyInfo({ token: userToken }) expect(user.username).to.equal('user_1') expect(user.email).to.equal('updated@example.com') expect(user.nsfwPolicy).to.equal('do_not_list') @@ -601,9 +587,9 @@ describe('Test users', function () { }) it('Should be able to update my description', async function () { - await server.usersCommand.updateMe({ token: accessTokenUser, description: 'my super description updated' }) + await server.usersCommand.updateMe({ token: userToken, description: 'my super description updated' }) - const user = await server.usersCommand.getMyInfo({ token: accessTokenUser }) + const user = await server.usersCommand.getMyInfo({ token: userToken }) expect(user.username).to.equal('user_1') expect(user.email).to.equal('updated@example.com') expect(user.nsfwPolicy).to.equal('do_not_list') @@ -617,21 +603,21 @@ describe('Test users', function () { it('Should be able to update my theme', async function () { for (const theme of [ 'background-red', 'default', 'instance-default' ]) { - await server.usersCommand.updateMe({ token: accessTokenUser, theme }) + await server.usersCommand.updateMe({ token: userToken, theme }) - const user = await server.usersCommand.getMyInfo({ token: accessTokenUser }) + const user = await server.usersCommand.getMyInfo({ token: userToken }) expect(user.theme).to.equal(theme) } }) it('Should be able to update my modal preferences', async function () { await server.usersCommand.updateMe({ - token: accessTokenUser, + token: userToken, noInstanceConfigWarningModal: true, noWelcomeModal: true }) - const user = await server.usersCommand.getMyInfo({ token: accessTokenUser }) + const user = await server.usersCommand.getMyInfo({ token: userToken }) expect(user.noWelcomeModal).to.be.true expect(user.noInstanceConfigWarningModal).to.be.true }) @@ -641,7 +627,7 @@ describe('Test users', function () { it('Should be able to update another user', async function () { await server.usersCommand.update({ userId, - token: accessToken, + token, email: 'updated2@example.com', emailVerified: true, videoQuota: 42, @@ -650,7 +636,7 @@ describe('Test users', function () { pluginAuth: 'toto' }) - const user = await server.usersCommand.get({ token: accessToken, userId }) + const user = await server.usersCommand.get({ token, userId }) expect(user.username).to.equal('user_1') expect(user.email).to.equal('updated2@example.com') @@ -664,39 +650,39 @@ describe('Test users', function () { }) it('Should reset the auth plugin', async function () { - await server.usersCommand.update({ userId, token: accessToken, pluginAuth: null }) + await server.usersCommand.update({ userId, token, pluginAuth: null }) - const user = await server.usersCommand.get({ token: accessToken, userId }) + const user = await server.usersCommand.get({ token, userId }) expect(user.pluginAuth).to.be.null }) it('Should have removed the user token', async function () { - await server.usersCommand.getMyQuotaUsed({ token: accessTokenUser, expectedStatus: HttpStatusCode.UNAUTHORIZED_401 }) + await server.usersCommand.getMyQuotaUsed({ token: userToken, expectedStatus: HttpStatusCode.UNAUTHORIZED_401 }) - accessTokenUser = await server.loginCommand.getAccessToken(user) + userToken = await server.loginCommand.getAccessToken(user) }) it('Should be able to update another user password', async function () { - await server.usersCommand.update({ userId, token: accessToken, password: 'password updated' }) + await server.usersCommand.update({ userId, token, password: 'password updated' }) - await server.usersCommand.getMyQuotaUsed({ token: accessTokenUser, expectedStatus: HttpStatusCode.UNAUTHORIZED_401 }) + await server.usersCommand.getMyQuotaUsed({ token: userToken, expectedStatus: HttpStatusCode.UNAUTHORIZED_401 }) await server.loginCommand.login({ user, expectedStatus: HttpStatusCode.BAD_REQUEST_400 }) user.password = 'password updated' - accessTokenUser = await server.loginCommand.getAccessToken(user) + userToken = await server.loginCommand.getAccessToken(user) }) }) describe('Video blacklists', function () { it('Should be able to list video blacklist by a moderator', async function () { - await server.blacklistCommand.list({ token: accessTokenUser }) + await server.blacklistCommand.list({ token: userToken }) }) }) describe('Remove a user', function () { it('Should be able to remove this user', async function () { - await server.usersCommand.remove({ userId, token: accessToken }) + await server.usersCommand.remove({ userId, token }) }) it('Should not be able to login with this user', async function () { @@ -704,11 +690,10 @@ describe('Test users', function () { }) it('Should not have videos of this user', async function () { - const res = await getVideosList(server.url) - - expect(res.body.total).to.equal(1) + const { data, total } = await server.videosCommand.list() + expect(total).to.equal(1) - const video = res.body.data[0] + const video = data[0] expect(video.account.name).to.equal('root') }) }) @@ -832,12 +817,11 @@ describe('Test users', function () { }) it('Should report correct videos count', async function () { - const videoAttributes = { - name: 'video to test user stats' - } - await uploadVideo(server.url, user17AccessToken, videoAttributes) - const res1 = await getVideosList(server.url) - videoId = res1.body.data.find(video => video.name === videoAttributes.name).id + const attributes = { name: 'video to test user stats' } + await server.videosCommand.upload({ token: user17AccessToken, attributes }) + + const { data } = await server.videosCommand.list() + videoId = data.find(video => video.name === attributes.name).id const user = await server.usersCommand.get({ userId: user17Id, withStats: true }) expect(user.videosCount).to.equal(1) diff --git a/server/tests/api/videos/audio-only.ts b/server/tests/api/videos/audio-only.ts index 9b516af81..e31905b36 100644 --- a/server/tests/api/videos/audio-only.ts +++ b/server/tests/api/videos/audio-only.ts @@ -4,17 +4,7 @@ import 'mocha' import * as chai from 'chai' import { join } from 'path' import { getAudioStream, getVideoStreamSize } from '@server/helpers/ffprobe-utils' -import { - cleanupTests, - doubleFollow, - flushAndRunMultipleServers, - getVideo, - ServerInfo, - setAccessTokensToServers, - uploadVideo, - waitJobs -} from '../../../../shared/extra-utils' -import { VideoDetails } from '../../../../shared/models/videos' +import { cleanupTests, doubleFollow, flushAndRunMultipleServers, ServerInfo, setAccessTokensToServers, waitJobs } from '@shared/extra-utils' const expect = chai.expect @@ -58,15 +48,13 @@ describe('Test audio only video transcoding', function () { it('Should upload a video and transcode it', async function () { this.timeout(120000) - const resUpload = await uploadVideo(servers[0].url, servers[0].accessToken, { name: 'audio only' }) - videoUUID = resUpload.body.video.uuid + const { uuid } = await servers[0].videosCommand.upload({ attributes: { name: 'audio only' } }) + videoUUID = uuid await waitJobs(servers) for (const server of servers) { - const res = await getVideo(server.url, videoUUID) - const video: VideoDetails = res.body - + const video = await server.videosCommand.get({ id: videoUUID }) expect(video.streamingPlaylists).to.have.lengthOf(1) for (const files of [ video.files, video.streamingPlaylists[0].files ]) { diff --git a/server/tests/api/videos/multiple-servers.ts b/server/tests/api/videos/multiple-servers.ts index 169bb2e23..5c13ac629 100644 --- a/server/tests/api/videos/multiple-servers.ts +++ b/server/tests/api/videos/multiple-servers.ts @@ -13,17 +13,9 @@ import { dateIsValid, doubleFollow, flushAndRunMultipleServers, - getLocalVideos, - getVideo, - getVideosList, - rateVideo, - removeVideo, ServerInfo, setAccessTokensToServers, testImage, - updateVideo, - uploadVideo, - viewVideo, wait, waitJobs, webtorrentAdd @@ -67,10 +59,9 @@ describe('Test multiple servers', function () { it('Should not have videos for all servers', async function () { for (const server of servers) { - const res = await getVideosList(server.url) - const videos = res.body.data - expect(videos).to.be.an('array') - expect(videos.length).to.equal(0) + const { data } = await server.videosCommand.list() + expect(data).to.be.an('array') + expect(data.length).to.equal(0) } }) @@ -78,7 +69,7 @@ describe('Test multiple servers', function () { it('Should upload the video on server 1 and propagate on each server', async function () { this.timeout(25000) - const videoAttributes = { + const attributes = { name: 'my super name for server 1', category: 5, licence: 4, @@ -91,7 +82,7 @@ describe('Test multiple servers', function () { channelId: videoChannelId, fixture: 'video_short1.webm' } - await uploadVideo(servers[0].url, servers[0].accessToken, videoAttributes) + await servers[0].videosCommand.upload({ attributes }) await waitJobs(servers) @@ -134,14 +125,13 @@ describe('Test multiple servers', function () { ] } - const res = await getVideosList(server.url) - const videos = res.body.data - expect(videos).to.be.an('array') - expect(videos.length).to.equal(1) - const video = videos[0] + const { data } = await server.videosCommand.list() + expect(data).to.be.an('array') + expect(data.length).to.equal(1) + const video = data[0] - await completeVideoCheck(server.url, video, checkAttributes) - publishedAt = video.publishedAt + await completeVideoCheck(server, video, checkAttributes) + publishedAt = video.publishedAt as string } }) @@ -155,7 +145,7 @@ describe('Test multiple servers', function () { await servers[1].usersCommand.create({ username: user.username, password: user.password }) const userAccessToken = await servers[1].loginCommand.getAccessToken(user) - const videoAttributes = { + const attributes = { name: 'my super name for server 2', category: 4, licence: 3, @@ -168,7 +158,7 @@ describe('Test multiple servers', function () { thumbnailfile: 'thumbnail.jpg', previewfile: 'preview.jpg' } - await uploadVideo(servers[1].url, userAccessToken, videoAttributes, HttpStatusCode.OK_200, 'resumable') + await servers[1].videosCommand.upload({ token: userAccessToken, attributes, mode: 'resumable' }) // Transcoding await waitJobs(servers) @@ -223,65 +213,67 @@ describe('Test multiple servers', function () { previewfile: 'preview' } - const res = await getVideosList(server.url) - const videos = res.body.data - expect(videos).to.be.an('array') - expect(videos.length).to.equal(2) - const video = videos[1] + const { data } = await server.videosCommand.list() + expect(data).to.be.an('array') + expect(data.length).to.equal(2) + const video = data[1] - await completeVideoCheck(server.url, video, checkAttributes) + await completeVideoCheck(server, video, checkAttributes) } }) it('Should upload two videos on server 3 and propagate on each server', async function () { this.timeout(45000) - const videoAttributes1 = { - name: 'my super name for server 3', - category: 6, - licence: 5, - language: 'de', - nsfw: true, - description: 'my super description for server 3', - support: 'my super support text for server 3', - tags: [ 'tag1p3' ], - fixture: 'video_short3.webm' + { + const attributes = { + name: 'my super name for server 3', + category: 6, + licence: 5, + language: 'de', + nsfw: true, + description: 'my super description for server 3', + support: 'my super support text for server 3', + tags: [ 'tag1p3' ], + fixture: 'video_short3.webm' + } + await servers[2].videosCommand.upload({ attributes }) } - await uploadVideo(servers[2].url, servers[2].accessToken, videoAttributes1) - - const videoAttributes2 = { - name: 'my super name for server 3-2', - category: 7, - licence: 6, - language: 'ko', - nsfw: false, - description: 'my super description for server 3-2', - support: 'my super support text for server 3-2', - tags: [ 'tag2p3', 'tag3p3', 'tag4p3' ], - fixture: 'video_short.webm' + + { + const attributes = { + name: 'my super name for server 3-2', + category: 7, + licence: 6, + language: 'ko', + nsfw: false, + description: 'my super description for server 3-2', + support: 'my super support text for server 3-2', + tags: [ 'tag2p3', 'tag3p3', 'tag4p3' ], + fixture: 'video_short.webm' + } + await servers[2].videosCommand.upload({ attributes }) } - await uploadVideo(servers[2].url, servers[2].accessToken, videoAttributes2) await waitJobs(servers) // All servers should have this video for (const server of servers) { const isLocal = server.url === 'http://localhost:' + servers[2].port - const res = await getVideosList(server.url) + const { data } = await server.videosCommand.list() - const videos = res.body.data - expect(videos).to.be.an('array') - expect(videos.length).to.equal(4) + expect(data).to.be.an('array') + expect(data.length).to.equal(4) // We not sure about the order of the two last uploads let video1 = null let video2 = null - if (videos[2].name === 'my super name for server 3') { - video1 = videos[2] - video2 = videos[3] + if (data[2].name === 'my super name for server 3') { + video1 = data[2] + video2 = data[3] } else { - video1 = videos[3] - video2 = videos[2] + video1 = data[3] + video2 = data[2] } const checkAttributesVideo1 = { @@ -316,7 +308,7 @@ describe('Test multiple servers', function () { } ] } - await completeVideoCheck(server.url, video1, checkAttributesVideo1) + await completeVideoCheck(server, video1, checkAttributesVideo1) const checkAttributesVideo2 = { name: 'my super name for server 3-2', @@ -350,38 +342,38 @@ describe('Test multiple servers', function () { } ] } - await completeVideoCheck(server.url, video2, checkAttributesVideo2) + await completeVideoCheck(server, video2, checkAttributesVideo2) } }) }) describe('It should list local videos', function () { it('Should list only local videos on server 1', async function () { - const { body } = await getLocalVideos(servers[0].url) + const { data, total } = await servers[0].videosCommand.list({ filter: 'local' }) - expect(body.total).to.equal(1) - expect(body.data).to.be.an('array') - expect(body.data.length).to.equal(1) - expect(body.data[0].name).to.equal('my super name for server 1') + expect(total).to.equal(1) + expect(data).to.be.an('array') + expect(data.length).to.equal(1) + expect(data[0].name).to.equal('my super name for server 1') }) it('Should list only local videos on server 2', async function () { - const { body } = await getLocalVideos(servers[1].url) + const { data, total } = await servers[1].videosCommand.list({ filter: 'local' }) - expect(body.total).to.equal(1) - expect(body.data).to.be.an('array') - expect(body.data.length).to.equal(1) - expect(body.data[0].name).to.equal('my super name for server 2') + expect(total).to.equal(1) + expect(data).to.be.an('array') + expect(data.length).to.equal(1) + expect(data[0].name).to.equal('my super name for server 2') }) it('Should list only local videos on server 3', async function () { - const { body } = await getLocalVideos(servers[2].url) + const { data, total } = await servers[2].videosCommand.list({ filter: 'local' }) - expect(body.total).to.equal(2) - expect(body.data).to.be.an('array') - expect(body.data.length).to.equal(2) - expect(body.data[0].name).to.equal('my super name for server 3') - expect(body.data[1].name).to.equal('my super name for server 3-2') + expect(total).to.equal(2) + expect(data).to.be.an('array') + expect(data.length).to.equal(2) + expect(data[0].name).to.equal('my super name for server 3') + expect(data[1].name).to.equal('my super name for server 3-2') }) }) @@ -389,15 +381,13 @@ describe('Test multiple servers', function () { it('Should add the file 1 by asking server 3', async function () { this.timeout(10000) - const res = await getVideosList(servers[2].url) - - const video = res.body.data[0] - toRemove.push(res.body.data[2]) - toRemove.push(res.body.data[3]) + const { data } = await servers[2].videosCommand.list() - const res2 = await getVideo(servers[2].url, video.id) - const videoDetails = res2.body + const video = data[0] + toRemove.push(data[2]) + toRemove.push(data[3]) + const videoDetails = await servers[2].videosCommand.get({ id: video.id }) const torrent = await webtorrentAdd(videoDetails.files[0].magnetUri, true) expect(torrent.files).to.be.an('array') expect(torrent.files.length).to.equal(1) @@ -407,11 +397,10 @@ describe('Test multiple servers', function () { it('Should add the file 2 by asking server 1', async function () { this.timeout(10000) - const res = await getVideosList(servers[0].url) + const { data } = await servers[0].videosCommand.list() - const video = res.body.data[1] - const res2 = await getVideo(servers[0].url, video.id) - const videoDetails = res2.body + const video = data[1] + const videoDetails = await servers[0].videosCommand.get({ id: video.id }) const torrent = await webtorrentAdd(videoDetails.files[0].magnetUri, true) expect(torrent.files).to.be.an('array') @@ -422,11 +411,10 @@ describe('Test multiple servers', function () { it('Should add the file 3 by asking server 2', async function () { this.timeout(10000) - const res = await getVideosList(servers[1].url) + const { data } = await servers[1].videosCommand.list() - const video = res.body.data[2] - const res2 = await getVideo(servers[1].url, video.id) - const videoDetails = res2.body + const video = data[2] + const videoDetails = await servers[1].videosCommand.get({ id: video.id }) const torrent = await webtorrentAdd(videoDetails.files[0].magnetUri, true) expect(torrent.files).to.be.an('array') @@ -437,11 +425,10 @@ describe('Test multiple servers', function () { it('Should add the file 3-2 by asking server 1', async function () { this.timeout(10000) - const res = await getVideosList(servers[0].url) + const { data } = await servers[0].videosCommand.list() - const video = res.body.data[3] - const res2 = await getVideo(servers[0].url, video.id) - const videoDetails = res2.body + const video = data[3] + const videoDetails = await servers[0].videosCommand.get({ id: video.id }) const torrent = await webtorrentAdd(videoDetails.files[0].magnetUri) expect(torrent.files).to.be.an('array') @@ -452,11 +439,10 @@ describe('Test multiple servers', function () { it('Should add the file 2 in 360p by asking server 1', async function () { this.timeout(10000) - const res = await getVideosList(servers[0].url) + const { data } = await servers[0].videosCommand.list() - const video = res.body.data.find(v => v.name === 'my super name for server 2') - const res2 = await getVideo(servers[0].url, video.id) - const videoDetails = res2.body + const video = data.find(v => v.name === 'my super name for server 2') + const videoDetails = await servers[0].videosCommand.get({ id: video.id }) const file = videoDetails.files.find(f => f.resolution.id === 360) expect(file).not.to.be.undefined @@ -475,30 +461,36 @@ describe('Test multiple servers', function () { let remoteVideosServer3 = [] before(async function () { - const res1 = await getVideosList(servers[0].url) - remoteVideosServer1 = res1.body.data.filter(video => video.isLocal === false).map(video => video.uuid) + { + const { data } = await servers[0].videosCommand.list() + remoteVideosServer1 = data.filter(video => video.isLocal === false).map(video => video.uuid) + } - const res2 = await getVideosList(servers[1].url) - remoteVideosServer2 = res2.body.data.filter(video => video.isLocal === false).map(video => video.uuid) + { + const { data } = await servers[1].videosCommand.list() + remoteVideosServer2 = data.filter(video => video.isLocal === false).map(video => video.uuid) + } - const res3 = await getVideosList(servers[2].url) - localVideosServer3 = res3.body.data.filter(video => video.isLocal === true).map(video => video.uuid) - remoteVideosServer3 = res3.body.data.filter(video => video.isLocal === false).map(video => video.uuid) + { + const { data } = await servers[2].videosCommand.list() + localVideosServer3 = data.filter(video => video.isLocal === true).map(video => video.uuid) + remoteVideosServer3 = data.filter(video => video.isLocal === false).map(video => video.uuid) + } }) it('Should view multiple videos on owned servers', async function () { this.timeout(30000) - await viewVideo(servers[2].url, localVideosServer3[0]) + await servers[2].videosCommand.view({ id: localVideosServer3[0] }) await wait(1000) - await viewVideo(servers[2].url, localVideosServer3[0]) - await viewVideo(servers[2].url, localVideosServer3[1]) + await servers[2].videosCommand.view({ id: localVideosServer3[0] }) + await servers[2].videosCommand.view({ id: localVideosServer3[1] }) await wait(1000) - await viewVideo(servers[2].url, localVideosServer3[0]) - await viewVideo(servers[2].url, localVideosServer3[0]) + await servers[2].videosCommand.view({ id: localVideosServer3[0] }) + await servers[2].videosCommand.view({ id: localVideosServer3[0] }) await waitJobs(servers) @@ -508,11 +500,10 @@ describe('Test multiple servers', function () { await waitJobs(servers) for (const server of servers) { - const res = await getVideosList(server.url) + const { data } = await server.videosCommand.list() - const videos = res.body.data - const video0 = videos.find(v => v.uuid === localVideosServer3[0]) - const video1 = videos.find(v => v.uuid === localVideosServer3[1]) + const video0 = data.find(v => v.uuid === localVideosServer3[0]) + const video1 = data.find(v => v.uuid === localVideosServer3[1]) expect(video0.views).to.equal(3) expect(video1.views).to.equal(1) @@ -523,16 +514,16 @@ describe('Test multiple servers', function () { this.timeout(45000) const tasks: Promise[] = [] - tasks.push(viewVideo(servers[0].url, remoteVideosServer1[0])) - tasks.push(viewVideo(servers[1].url, remoteVideosServer2[0])) - tasks.push(viewVideo(servers[1].url, remoteVideosServer2[0])) - tasks.push(viewVideo(servers[2].url, remoteVideosServer3[0])) - tasks.push(viewVideo(servers[2].url, remoteVideosServer3[1])) - tasks.push(viewVideo(servers[2].url, remoteVideosServer3[1])) - tasks.push(viewVideo(servers[2].url, remoteVideosServer3[1])) - tasks.push(viewVideo(servers[2].url, localVideosServer3[1])) - tasks.push(viewVideo(servers[2].url, localVideosServer3[1])) - tasks.push(viewVideo(servers[2].url, localVideosServer3[1])) + tasks.push(servers[0].videosCommand.view({ id: remoteVideosServer1[0] })) + tasks.push(servers[1].videosCommand.view({ id: remoteVideosServer2[0] })) + tasks.push(servers[1].videosCommand.view({ id: remoteVideosServer2[0] })) + tasks.push(servers[2].videosCommand.view({ id: remoteVideosServer3[0] })) + tasks.push(servers[2].videosCommand.view({ id: remoteVideosServer3[1] })) + tasks.push(servers[2].videosCommand.view({ id: remoteVideosServer3[1] })) + tasks.push(servers[2].videosCommand.view({ id: remoteVideosServer3[1] })) + tasks.push(servers[2].videosCommand.view({ id: localVideosServer3[1] })) + tasks.push(servers[2].videosCommand.view({ id: localVideosServer3[1] })) + tasks.push(servers[2].videosCommand.view({ id: localVideosServer3[1] })) await Promise.all(tasks) @@ -546,18 +537,16 @@ describe('Test multiple servers', function () { let baseVideos = null for (const server of servers) { - const res = await getVideosList(server.url) - - const videos = res.body.data + const { data } = await server.videosCommand.list() // Initialize base videos for future comparisons if (baseVideos === null) { - baseVideos = videos + baseVideos = data continue } for (const baseVideo of baseVideos) { - const sameVideo = videos.find(video => video.name === baseVideo.name) + const sameVideo = data.find(video => video.name === baseVideo.name) expect(baseVideo.views).to.equal(sameVideo.views) } } @@ -566,17 +555,17 @@ describe('Test multiple servers', function () { it('Should like and dislikes videos on different services', async function () { this.timeout(50000) - await rateVideo(servers[0].url, servers[0].accessToken, remoteVideosServer1[0], 'like') + await servers[0].videosCommand.rate({ id: remoteVideosServer1[0], rating: 'like' }) await wait(500) - await rateVideo(servers[0].url, servers[0].accessToken, remoteVideosServer1[0], 'dislike') + await servers[0].videosCommand.rate({ id: remoteVideosServer1[0], rating: 'dislike' }) await wait(500) - await rateVideo(servers[0].url, servers[0].accessToken, remoteVideosServer1[0], 'like') - await rateVideo(servers[2].url, servers[2].accessToken, localVideosServer3[1], 'like') + await servers[0].videosCommand.rate({ id: remoteVideosServer1[0], rating: 'like' }) + await servers[2].videosCommand.rate({ id: localVideosServer3[1], rating: 'like' }) await wait(500) - await rateVideo(servers[2].url, servers[2].accessToken, localVideosServer3[1], 'dislike') - await rateVideo(servers[2].url, servers[2].accessToken, remoteVideosServer3[1], 'dislike') + await servers[2].videosCommand.rate({ id: localVideosServer3[1], rating: 'dislike' }) + await servers[2].videosCommand.rate({ id: remoteVideosServer3[1], rating: 'dislike' }) await wait(500) - await rateVideo(servers[2].url, servers[2].accessToken, remoteVideosServer3[0], 'like') + await servers[2].videosCommand.rate({ id: remoteVideosServer3[0], rating: 'like' }) await waitJobs(servers) await wait(5000) @@ -584,18 +573,16 @@ describe('Test multiple servers', function () { let baseVideos = null for (const server of servers) { - const res = await getVideosList(server.url) - - const videos = res.body.data + const { data } = await server.videosCommand.list() // Initialize base videos for future comparisons if (baseVideos === null) { - baseVideos = videos + baseVideos = data continue } for (const baseVideo of baseVideos) { - const sameVideo = videos.find(video => video.name === baseVideo.name) + const sameVideo = data.find(video => video.name === baseVideo.name) expect(baseVideo.likes).to.equal(sameVideo.likes) expect(baseVideo.dislikes).to.equal(sameVideo.dislikes) } @@ -621,7 +608,7 @@ describe('Test multiple servers', function () { previewfile: 'preview.jpg' } - await updateVideo(servers[2].url, servers[2].accessToken, toRemove[0].id, attributes) + await servers[2].videosCommand.update({ id: toRemove[0].id, attributes }) await waitJobs(servers) }) @@ -630,10 +617,9 @@ describe('Test multiple servers', function () { this.timeout(10000) for (const server of servers) { - const res = await getVideosList(server.url) + const { data } = await server.videosCommand.list() - const videos = res.body.data - const videoUpdated = videos.find(video => video.name === 'my super video updated') + const videoUpdated = data.find(video => video.name === 'my super video updated') expect(!!videoUpdated).to.be.true const isLocal = server.url === 'http://localhost:' + servers[2].port @@ -672,15 +658,15 @@ describe('Test multiple servers', function () { thumbnailfile: 'thumbnail', previewfile: 'preview' } - await completeVideoCheck(server.url, videoUpdated, checkAttributes) + await completeVideoCheck(server, videoUpdated, checkAttributes) } }) it('Should remove the videos 3 and 3-2 by asking server 3', async function () { this.timeout(10000) - await removeVideo(servers[2].url, servers[2].accessToken, toRemove[0].id) - await removeVideo(servers[2].url, servers[2].accessToken, toRemove[1].id) + await servers[2].videosCommand.remove({ id: toRemove[0].id }) + await servers[2].videosCommand.remove({ id: toRemove[1].id }) await waitJobs(servers) }) @@ -694,27 +680,24 @@ describe('Test multiple servers', function () { it('Should have videos 1 and 3 on each server', async function () { for (const server of servers) { - const res = await getVideosList(server.url) - - const videos = res.body.data - expect(videos).to.be.an('array') - expect(videos.length).to.equal(2) - expect(videos[0].name).not.to.equal(videos[1].name) - expect(videos[0].name).not.to.equal(toRemove[0].name) - expect(videos[1].name).not.to.equal(toRemove[0].name) - expect(videos[0].name).not.to.equal(toRemove[1].name) - expect(videos[1].name).not.to.equal(toRemove[1].name) - - videoUUID = videos.find(video => video.name === 'my super name for server 1').uuid + const { data } = await server.videosCommand.list() + + expect(data).to.be.an('array') + expect(data.length).to.equal(2) + expect(data[0].name).not.to.equal(data[1].name) + expect(data[0].name).not.to.equal(toRemove[0].name) + expect(data[1].name).not.to.equal(toRemove[0].name) + expect(data[0].name).not.to.equal(toRemove[1].name) + expect(data[1].name).not.to.equal(toRemove[1].name) + + videoUUID = data.find(video => video.name === 'my super name for server 1').uuid } }) it('Should get the same video by UUID on each server', async function () { let baseVideo = null for (const server of servers) { - const res = await getVideo(server.url, videoUUID) - - const video = res.body + const video = await server.videosCommand.get({ id: videoUUID }) if (baseVideo === null) { baseVideo = video @@ -737,8 +720,7 @@ describe('Test multiple servers', function () { it('Should get the preview from each server', async function () { for (const server of servers) { - const res = await getVideo(server.url, videoUUID) - const video = res.body + const video = await server.videosCommand.get({ id: videoUUID }) await testImage(server.url, 'video_short1-preview.webm', video.previewPath) } @@ -975,14 +957,14 @@ describe('Test multiple servers', function () { downloadEnabled: false } - await updateVideo(servers[0].url, servers[0].accessToken, videoUUID, attributes) + await servers[0].videosCommand.update({ id: videoUUID, attributes }) await waitJobs(servers) for (const server of servers) { - const res = await getVideo(server.url, videoUUID) - expect(res.body.commentsEnabled).to.be.false - expect(res.body.downloadEnabled).to.be.false + const video = await server.videosCommand.get({ id: videoUUID }) + expect(video.commentsEnabled).to.be.false + expect(video.downloadEnabled).to.be.false const text = 'my super forbidden comment' await server.commentsCommand.createThread({ videoId: videoUUID, text, expectedStatus: HttpStatusCode.CONFLICT_409 }) @@ -1010,8 +992,8 @@ describe('Test multiple servers', function () { await waitJobs(servers) for (const server of servers) { - const res = await getVideosList(server.url) - const video = res.body.data.find(v => v.name === 'minimum parameters') + const { data } = await server.videosCommand.list() + const video = data.find(v => v.name === 'minimum parameters') const isLocal = server.url === 'http://localhost:' + servers[1].port const checkAttributes = { @@ -1058,7 +1040,7 @@ describe('Test multiple servers', function () { } ] } - await completeVideoCheck(server.url, video, checkAttributes) + await completeVideoCheck(server, video, checkAttributes) } }) }) diff --git a/server/tests/api/videos/resumable-upload.ts b/server/tests/api/videos/resumable-upload.ts index 642c115d0..b7756a4a8 100644 --- a/server/tests/api/videos/resumable-upload.ts +++ b/server/tests/api/videos/resumable-upload.ts @@ -9,8 +9,6 @@ import { buildAbsoluteFixturePath, cleanupTests, flushAndRunServer, - prepareResumableUpload, - sendResumableChunks, ServerInfo, setAccessTokensToServers, setDefaultVideoChannel @@ -45,7 +43,7 @@ describe('Test resumable upload', function () { const mimetype = 'video/mp4' - const res = await prepareResumableUpload({ url: server.url, token: server.accessToken, attributes, size, mimetype }) + const res = await server.videosCommand.prepareResumableUpload({ attributes, size, mimetype }) return res.header['location'].split('?')[1] } @@ -63,15 +61,13 @@ describe('Test resumable upload', function () { const size = await buildSize(defaultFixture, options.size) const absoluteFilePath = buildAbsoluteFixturePath(defaultFixture) - return sendResumableChunks({ - url: server.url, - token: server.accessToken, + return server.videosCommand.sendResumableChunks({ pathUploadId, videoFilePath: absoluteFilePath, size, contentLength, contentRangeBuilder, - specialStatus: expectedStatus + expectedStatus }) } diff --git a/server/tests/api/videos/single-server.ts b/server/tests/api/videos/single-server.ts index af1703e02..da0b2011e 100644 --- a/server/tests/api/videos/single-server.ts +++ b/server/tests/api/videos/single-server.ts @@ -2,34 +2,17 @@ import 'mocha' import * as chai from 'chai' -import { keyBy } from 'lodash' - import { checkVideoFilesWereRemoved, cleanupTests, completeVideoCheck, flushAndRunServer, - getVideo, - getVideoCategories, - getVideoLanguages, - getVideoLicences, - getVideoPrivacies, - getVideosList, - getVideosListPagination, - getVideosListSort, - getVideosWithFilters, - rateVideo, - removeVideo, ServerInfo, setAccessTokensToServers, testImage, - updateVideo, - uploadVideo, - viewVideo, wait -} from '../../../../shared/extra-utils' -import { VideoPrivacy } from '../../../../shared/models/videos' -import { HttpStatusCode } from '@shared/core-utils' +} from '@shared/extra-utils' +import { Video, VideoPrivacy } from '@shared/models' const expect = chai.expect @@ -37,8 +20,8 @@ describe('Test a single server', function () { function runSuite (mode: 'legacy' | 'resumable') { let server: ServerInfo = null - let videoId = -1 - let videoId2 = -1 + let videoId: number | string + let videoId2: string let videoUUID = '' let videosListBase: any[] = null @@ -117,128 +100,116 @@ describe('Test a single server', function () { }) it('Should list video categories', async function () { - const res = await getVideoCategories(server.url) - - const categories = res.body + const categories = await server.videosCommand.getCategories() expect(Object.keys(categories)).to.have.length.above(10) expect(categories[11]).to.equal('News & Politics') }) it('Should list video licences', async function () { - const res = await getVideoLicences(server.url) - - const licences = res.body + const licences = await server.videosCommand.getLicences() expect(Object.keys(licences)).to.have.length.above(5) expect(licences[3]).to.equal('Attribution - No Derivatives') }) it('Should list video languages', async function () { - const res = await getVideoLanguages(server.url) - - const languages = res.body + const languages = await server.videosCommand.getLanguages() expect(Object.keys(languages)).to.have.length.above(5) expect(languages['ru']).to.equal('Russian') }) it('Should list video privacies', async function () { - const res = await getVideoPrivacies(server.url) - - const privacies = res.body + const privacies = await server.videosCommand.getPrivacies() expect(Object.keys(privacies)).to.have.length.at.least(3) expect(privacies[3]).to.equal('Private') }) it('Should not have videos', async function () { - const res = await getVideosList(server.url) + const { data, total } = await server.videosCommand.list() - expect(res.body.total).to.equal(0) - expect(res.body.data).to.be.an('array') - expect(res.body.data.length).to.equal(0) + expect(total).to.equal(0) + expect(data).to.be.an('array') + expect(data.length).to.equal(0) }) it('Should upload the video', async function () { this.timeout(10000) - const videoAttributes = { + const attributes = { name: 'my super name', category: 2, nsfw: true, licence: 6, tags: [ 'tag1', 'tag2', 'tag3' ] } - const res = await uploadVideo(server.url, server.accessToken, videoAttributes, HttpStatusCode.OK_200, mode) - expect(res.body.video).to.not.be.undefined - expect(res.body.video.id).to.equal(1) - expect(res.body.video.uuid).to.have.length.above(5) + const video = await server.videosCommand.upload({ attributes, mode }) + expect(video).to.not.be.undefined + expect(video.id).to.equal(1) + expect(video.uuid).to.have.length.above(5) - videoId = res.body.video.id - videoUUID = res.body.video.uuid + videoId = video.id + videoUUID = video.uuid }) it('Should get and seed the uploaded video', async function () { this.timeout(5000) - const res = await getVideosList(server.url) + const { data, total } = await server.videosCommand.list() - expect(res.body.total).to.equal(1) - expect(res.body.data).to.be.an('array') - expect(res.body.data.length).to.equal(1) + expect(total).to.equal(1) + expect(data).to.be.an('array') + expect(data.length).to.equal(1) - const video = res.body.data[0] - await completeVideoCheck(server.url, video, getCheckAttributes()) + const video = data[0] + await completeVideoCheck(server, video, getCheckAttributes()) }) it('Should get the video by UUID', async function () { this.timeout(5000) - const res = await getVideo(server.url, videoUUID) - - const video = res.body - await completeVideoCheck(server.url, video, getCheckAttributes()) + const video = await server.videosCommand.get({ id: videoUUID }) + await completeVideoCheck(server, video, getCheckAttributes()) }) it('Should have the views updated', async function () { this.timeout(20000) - await viewVideo(server.url, videoId) - await viewVideo(server.url, videoId) - await viewVideo(server.url, videoId) + await server.videosCommand.view({ id: videoId }) + await server.videosCommand.view({ id: videoId }) + await server.videosCommand.view({ id: videoId }) await wait(1500) - await viewVideo(server.url, videoId) - await viewVideo(server.url, videoId) + await server.videosCommand.view({ id: videoId }) + await server.videosCommand.view({ id: videoId }) await wait(1500) - await viewVideo(server.url, videoId) - await viewVideo(server.url, videoId) + await server.videosCommand.view({ id: videoId }) + await server.videosCommand.view({ id: videoId }) // Wait the repeatable job await wait(8000) - const res = await getVideo(server.url, videoId) - - const video = res.body + const video = await server.videosCommand.get({ id: videoId }) expect(video.views).to.equal(3) }) it('Should remove the video', async function () { - await removeVideo(server.url, server.accessToken, videoId) + await server.videosCommand.remove({ id: videoId }) await checkVideoFilesWereRemoved(videoUUID, server) }) it('Should not have videos', async function () { - const res = await getVideosList(server.url) + const { total, data } = await server.videosCommand.list() - expect(res.body.total).to.equal(0) - expect(res.body.data).to.be.an('array') - expect(res.body.data).to.have.lengthOf(0) + expect(total).to.equal(0) + expect(data).to.be.an('array') + expect(data).to.have.lengthOf(0) }) it('Should upload 6 videos', async function () { @@ -250,7 +221,7 @@ describe('Test a single server', function () { ]) for (const video of videos) { - const videoAttributes = { + const attributes = { name: video + ' name', description: video + ' description', category: 2, @@ -261,19 +232,20 @@ describe('Test a single server', function () { fixture: video } - await uploadVideo(server.url, server.accessToken, videoAttributes, HttpStatusCode.OK_200, mode) + await server.videosCommand.upload({ attributes, mode }) } }) it('Should have the correct durations', async function () { - const res = await getVideosList(server.url) + const { total, data } = await server.videosCommand.list() + + expect(total).to.equal(6) + expect(data).to.be.an('array') + expect(data).to.have.lengthOf(6) - expect(res.body.total).to.equal(6) - const videos = res.body.data - expect(videos).to.be.an('array') - expect(videos).to.have.lengthOf(6) + const videosByName: { [ name: string ]: Video } = {} + data.forEach(v => { videosByName[v.name] = v }) - const videosByName = keyBy<{ duration: number }>(videos, 'name') expect(videosByName['video_short.mp4 name'].duration).to.equal(5) expect(videosByName['video_short.ogv name'].duration).to.equal(5) expect(videosByName['video_short.webm name'].duration).to.equal(5) @@ -283,96 +255,87 @@ describe('Test a single server', function () { }) it('Should have the correct thumbnails', async function () { - const res = await getVideosList(server.url) + const { data } = await server.videosCommand.list() - const videos = res.body.data // For the next test - videosListBase = videos + videosListBase = data - for (const video of videos) { + for (const video of data) { const videoName = video.name.replace(' name', '') await testImage(server.url, videoName, video.thumbnailPath) } }) it('Should list only the two first videos', async function () { - const res = await getVideosListPagination(server.url, 0, 2, 'name') + const { total, data } = await server.videosCommand.list({ start: 0, count: 2, sort: 'name' }) - const videos = res.body.data - expect(res.body.total).to.equal(6) - expect(videos.length).to.equal(2) - expect(videos[0].name).to.equal(videosListBase[0].name) - expect(videos[1].name).to.equal(videosListBase[1].name) + expect(total).to.equal(6) + expect(data.length).to.equal(2) + expect(data[0].name).to.equal(videosListBase[0].name) + expect(data[1].name).to.equal(videosListBase[1].name) }) it('Should list only the next three videos', async function () { - const res = await getVideosListPagination(server.url, 2, 3, 'name') + const { total, data } = await server.videosCommand.list({ start: 2, count: 3, sort: 'name' }) - const videos = res.body.data - expect(res.body.total).to.equal(6) - expect(videos.length).to.equal(3) - expect(videos[0].name).to.equal(videosListBase[2].name) - expect(videos[1].name).to.equal(videosListBase[3].name) - expect(videos[2].name).to.equal(videosListBase[4].name) + expect(total).to.equal(6) + expect(data.length).to.equal(3) + expect(data[0].name).to.equal(videosListBase[2].name) + expect(data[1].name).to.equal(videosListBase[3].name) + expect(data[2].name).to.equal(videosListBase[4].name) }) it('Should list the last video', async function () { - const res = await getVideosListPagination(server.url, 5, 6, 'name') + const { total, data } = await server.videosCommand.list({ start: 5, count: 6, sort: 'name' }) - const videos = res.body.data - expect(res.body.total).to.equal(6) - expect(videos.length).to.equal(1) - expect(videos[0].name).to.equal(videosListBase[5].name) + expect(total).to.equal(6) + expect(data.length).to.equal(1) + expect(data[0].name).to.equal(videosListBase[5].name) }) it('Should not have the total field', async function () { - const res = await getVideosListPagination(server.url, 5, 6, 'name', true) + const { total, data } = await server.videosCommand.list({ start: 5, count: 6, sort: 'name', skipCount: true }) - const videos = res.body.data - expect(res.body.total).to.not.exist - expect(videos.length).to.equal(1) - expect(videos[0].name).to.equal(videosListBase[5].name) + expect(total).to.not.exist + expect(data.length).to.equal(1) + expect(data[0].name).to.equal(videosListBase[5].name) }) it('Should list and sort by name in descending order', async function () { - const res = await getVideosListSort(server.url, '-name') + const { total, data } = await server.videosCommand.list({ sort: '-name' }) - const videos = res.body.data - expect(res.body.total).to.equal(6) - expect(videos.length).to.equal(6) - expect(videos[0].name).to.equal('video_short.webm name') - expect(videos[1].name).to.equal('video_short.ogv name') - expect(videos[2].name).to.equal('video_short.mp4 name') - expect(videos[3].name).to.equal('video_short3.webm name') - expect(videos[4].name).to.equal('video_short2.webm name') - expect(videos[5].name).to.equal('video_short1.webm name') + expect(total).to.equal(6) + expect(data.length).to.equal(6) + expect(data[0].name).to.equal('video_short.webm name') + expect(data[1].name).to.equal('video_short.ogv name') + expect(data[2].name).to.equal('video_short.mp4 name') + expect(data[3].name).to.equal('video_short3.webm name') + expect(data[4].name).to.equal('video_short2.webm name') + expect(data[5].name).to.equal('video_short1.webm name') - videoId = videos[3].uuid - videoId2 = videos[5].uuid + videoId = data[3].uuid + videoId2 = data[5].uuid }) it('Should list and sort by trending in descending order', async function () { - const res = await getVideosListPagination(server.url, 0, 2, '-trending') + const { total, data } = await server.videosCommand.list({ start: 0, count: 2, sort: '-trending' }) - const videos = res.body.data - expect(res.body.total).to.equal(6) - expect(videos.length).to.equal(2) + expect(total).to.equal(6) + expect(data.length).to.equal(2) }) it('Should list and sort by hotness in descending order', async function () { - const res = await getVideosListPagination(server.url, 0, 2, '-hot') + const { total, data } = await server.videosCommand.list({ start: 0, count: 2, sort: '-hot' }) - const videos = res.body.data - expect(res.body.total).to.equal(6) - expect(videos.length).to.equal(2) + expect(total).to.equal(6) + expect(data.length).to.equal(2) }) it('Should list and sort by best in descending order', async function () { - const res = await getVideosListPagination(server.url, 0, 2, '-best') + const { total, data } = await server.videosCommand.list({ start: 0, count: 2, sort: '-best' }) - const videos = res.body.data - expect(res.body.total).to.equal(6) - expect(videos.length).to.equal(2) + expect(total).to.equal(6) + expect(data.length).to.equal(2) }) it('Should update a video', async function () { @@ -387,67 +350,66 @@ describe('Test a single server', function () { downloadEnabled: false, tags: [ 'tagup1', 'tagup2' ] } - await updateVideo(server.url, server.accessToken, videoId, attributes) + await server.videosCommand.update({ id: videoId, attributes }) }) it('Should filter by tags and category', async function () { - const res1 = await getVideosWithFilters(server.url, { tagsAllOf: [ 'tagup1', 'tagup2' ], categoryOneOf: [ 4 ] }) - expect(res1.body.total).to.equal(1) - expect(res1.body.data[0].name).to.equal('my super video updated') + { + const { data, total } = await server.videosCommand.list({ tagsAllOf: [ 'tagup1', 'tagup2' ], categoryOneOf: [ 4 ] }) + expect(total).to.equal(1) + expect(data[0].name).to.equal('my super video updated') + } - const res2 = await getVideosWithFilters(server.url, { tagsAllOf: [ 'tagup1', 'tagup2' ], categoryOneOf: [ 3 ] }) - expect(res2.body.total).to.equal(0) + { + const { total } = await server.videosCommand.list({ tagsAllOf: [ 'tagup1', 'tagup2' ], categoryOneOf: [ 3 ] }) + expect(total).to.equal(0) + } }) it('Should have the video updated', async function () { this.timeout(60000) - const res = await getVideo(server.url, videoId) - const video = res.body + const video = await server.videosCommand.get({ id: videoId }) - await completeVideoCheck(server.url, video, updateCheckAttributes()) + await completeVideoCheck(server, video, updateCheckAttributes()) }) it('Should update only the tags of a video', async function () { const attributes = { tags: [ 'supertag', 'tag1', 'tag2' ] } - await updateVideo(server.url, server.accessToken, videoId, attributes) + await server.videosCommand.update({ id: videoId, attributes }) - const res = await getVideo(server.url, videoId) - const video = res.body + const video = await server.videosCommand.get({ id: videoId }) - await completeVideoCheck(server.url, video, Object.assign(updateCheckAttributes(), attributes)) + await completeVideoCheck(server, video, Object.assign(updateCheckAttributes(), attributes)) }) it('Should update only the description of a video', async function () { const attributes = { description: 'hello everybody' } - await updateVideo(server.url, server.accessToken, videoId, attributes) + await server.videosCommand.update({ id: videoId, attributes }) - const res = await getVideo(server.url, videoId) - const video = res.body + const video = await server.videosCommand.get({ id: videoId }) const expectedAttributes = Object.assign(updateCheckAttributes(), { tags: [ 'supertag', 'tag1', 'tag2' ] }, attributes) - await completeVideoCheck(server.url, video, expectedAttributes) + await completeVideoCheck(server, video, expectedAttributes) }) it('Should like a video', async function () { - await rateVideo(server.url, server.accessToken, videoId, 'like') + await server.videosCommand.rate({ id: videoId, rating: 'like' }) - const res = await getVideo(server.url, videoId) - const video = res.body + const video = await server.videosCommand.get({ id: videoId }) expect(video.likes).to.equal(1) expect(video.dislikes).to.equal(0) }) it('Should dislike the same video', async function () { - await rateVideo(server.url, server.accessToken, videoId, 'dislike') + await server.videosCommand.rate({ id: videoId, rating: 'dislike' }) - const res = await getVideo(server.url, videoId) - const video = res.body + const video = await server.videosCommand.get({ id: videoId }) expect(video.likes).to.equal(0) expect(video.dislikes).to.equal(1) @@ -457,10 +419,10 @@ describe('Test a single server', function () { { const now = new Date() const attributes = { originallyPublishedAt: now.toISOString() } - await updateVideo(server.url, server.accessToken, videoId, attributes) + await server.videosCommand.update({ id: videoId, attributes }) - const res = await getVideosListSort(server.url, '-originallyPublishedAt') - const names = res.body.data.map(v => v.name) + const { data } = await server.videosCommand.list({ sort: '-originallyPublishedAt' }) + const names = data.map(v => v.name) expect(names[0]).to.equal('my super video updated') expect(names[1]).to.equal('video_short2.webm name') @@ -473,10 +435,10 @@ describe('Test a single server', function () { { const now = new Date() const attributes = { originallyPublishedAt: now.toISOString() } - await updateVideo(server.url, server.accessToken, videoId2, attributes) + await server.videosCommand.update({ id: videoId2, attributes }) - const res = await getVideosListSort(server.url, '-originallyPublishedAt') - const names = res.body.data.map(v => v.name) + const { data } = await server.videosCommand.list({ sort: '-originallyPublishedAt' }) + const names = data.map(v => v.name) expect(names[0]).to.equal('video_short1.webm name') expect(names[1]).to.equal('my super video updated') diff --git a/server/tests/api/videos/video-captions.ts b/server/tests/api/videos/video-captions.ts index d4a5385ab..4c67e96f7 100644 --- a/server/tests/api/videos/video-captions.ts +++ b/server/tests/api/videos/video-captions.ts @@ -7,11 +7,9 @@ import { cleanupTests, doubleFollow, flushAndRunMultipleServers, - removeVideo, ServerInfo, setAccessTokensToServers, testCaptionFile, - uploadVideo, wait, waitJobs } from '@shared/extra-utils' @@ -34,8 +32,8 @@ describe('Test video captions', function () { await waitJobs(servers) - const res = await uploadVideo(servers[0].url, servers[0].accessToken, { name: 'my video name' }) - videoUUID = res.body.video.uuid + const { uuid } = await servers[0].videosCommand.upload({ attributes: { name: 'my video name' } }) + videoUUID = uuid await waitJobs(servers) }) @@ -180,7 +178,7 @@ describe('Test video captions', function () { }) it('Should remove the video, and thus all video captions', async function () { - await removeVideo(servers[0].url, servers[0].accessToken, videoUUID) + await servers[0].videosCommand.remove({ id: videoUUID }) await checkVideoFilesWereRemoved(videoUUID, servers[0]) }) diff --git a/server/tests/api/videos/video-change-ownership.ts b/server/tests/api/videos/video-change-ownership.ts index b0bbd5a0d..b85edd920 100644 --- a/server/tests/api/videos/video-change-ownership.ts +++ b/server/tests/api/videos/video-change-ownership.ts @@ -2,22 +2,19 @@ import 'mocha' import * as chai from 'chai' -import { HttpStatusCode } from '../../../../shared/core-utils/miscs/http-error-codes' +import { HttpStatusCode } from '@shared/core-utils' import { ChangeOwnershipCommand, cleanupTests, doubleFollow, flushAndRunMultipleServers, flushAndRunServer, - getVideo, - getVideosList, ServerInfo, setAccessTokensToServers, setDefaultVideoChannel, - uploadVideo -} from '../../../../shared/extra-utils' -import { waitJobs } from '../../../../shared/extra-utils/server/jobs' -import { VideoDetails, VideoPrivacy } from '../../../../shared/models/videos' + waitJobs +} from '@shared/extra-utils' +import { VideoPrivacy } from '@shared/models' const expect = chai.expect @@ -71,14 +68,13 @@ describe('Test video change ownership - nominal', function () { } { - const videoAttributes = { + const attributes = { name: 'my super name', description: 'my super description' } - const res = await uploadVideo(servers[0].url, firstUserToken, videoAttributes) + const { id } = await servers[0].videosCommand.upload({ token: firstUserToken, attributes }) - const resVideo = await getVideo(servers[0].url, res.body.video.id) - servers[0].video = resVideo.body + servers[0].video = await servers[0].videosCommand.get({ id }) } { @@ -212,9 +208,7 @@ describe('Test video change ownership - nominal', function () { it('Should have the channel of the video updated', async function () { for (const server of servers) { - const res = await getVideo(server.url, servers[0].video.uuid) - - const video: VideoDetails = res.body + const video = await server.videosCommand.get({ id: servers[0].video.uuid }) expect(video.name).to.equal('my super name') expect(video.channel.displayName).to.equal('Main second channel') @@ -243,9 +237,7 @@ describe('Test video change ownership - nominal', function () { await waitJobs(servers) for (const server of servers) { - const res = await getVideo(server.url, servers[0].video.uuid) - - const video: VideoDetails = res.body + const video = await server.videosCommand.get({ id: servers[0].video.uuid }) expect(video.name).to.equal('my super name') expect(video.channel.displayName).to.equal('Main second channel') @@ -280,20 +272,18 @@ describe('Test video change ownership - quota too small', function () { secondUserToken = await server.loginCommand.getAccessToken(secondUser) // Upload some videos on the server - const video1Attributes = { + const attributes = { name: 'my super name', description: 'my super description' } - await uploadVideo(server.url, firstUserToken, video1Attributes) + await server.videosCommand.upload({ token: firstUserToken, attributes }) await waitJobs(server) - const res = await getVideosList(server.url) - const videos = res.body.data - - expect(videos.length).to.equal(1) + const { data } = await server.videosCommand.list() + expect(data.length).to.equal(1) - server.video = videos.find(video => video.name === 'my super name') + server.video = data.find(video => video.name === 'my super name') }) it('Should send a request to change ownership of a video', async function () { diff --git a/server/tests/api/videos/video-channels.ts b/server/tests/api/videos/video-channels.ts index 2e57cbbff..170cc942e 100644 --- a/server/tests/api/videos/video-channels.ts +++ b/server/tests/api/videos/video-channels.ts @@ -8,20 +8,15 @@ import { cleanupTests, doubleFollow, flushAndRunMultipleServers, - getVideo, - getVideoChannelVideos, ServerInfo, setAccessTokensToServers, setDefaultVideoChannel, testFileExistsOrNot, testImage, - updateVideo, - uploadVideo, - viewVideo, wait, waitJobs } from '@shared/extra-utils' -import { User, Video, VideoChannel, VideoDetails } from '@shared/models' +import { User, VideoChannel } from '@shared/models' const expect = chai.expect @@ -77,9 +72,9 @@ describe('Test video channels', function () { // The channel is 1 is propagated to servers 2 { - const videoAttributesArg = { name: 'my video name', channelId: secondVideoChannelId, support: 'video support field' } - const res = await uploadVideo(servers[0].url, servers[0].accessToken, videoAttributesArg) - videoUUID = res.body.video.uuid + const attributes = { name: 'my video name', channelId: secondVideoChannelId, support: 'video support field' } + const { uuid } = await servers[0].videosCommand.upload({ attributes }) + videoUUID = uuid } await waitJobs(servers) @@ -219,9 +214,7 @@ describe('Test video channels', function () { it('Should not have updated the video support field', async function () { for (const server of servers) { - const res = await getVideo(server.url, videoUUID) - const video: VideoDetails = res.body - + const video = await server.videosCommand.get({ id: videoUUID }) expect(video.support).to.equal('video support field') } }) @@ -239,9 +232,7 @@ describe('Test video channels', function () { await waitJobs(servers) for (const server of servers) { - const res = await getVideo(server.url, videoUUID) - const video: VideoDetails = res.body - + const video = await server.videosCommand.get({ id: videoUUID }) expect(video.support).to.equal(videoChannelAttributes.support) } }) @@ -333,18 +324,19 @@ describe('Test video channels', function () { for (const server of servers) { const channelURI = 'second_video_channel@localhost:' + servers[0].port - const res1 = await getVideoChannelVideos(server.url, server.accessToken, channelURI, 0, 5) - expect(res1.body.total).to.equal(1) - expect(res1.body.data).to.be.an('array') - expect(res1.body.data).to.have.lengthOf(1) - expect(res1.body.data[0].name).to.equal('my video name') + const { total, data } = await server.videosCommand.listByChannel({ videoChannelName: channelURI }) + + expect(total).to.equal(1) + expect(data).to.be.an('array') + expect(data).to.have.lengthOf(1) + expect(data[0].name).to.equal('my video name') } }) it('Should change the video channel of a video', async function () { this.timeout(10000) - await updateVideo(servers[0].url, servers[0].accessToken, videoUUID, { channelId: servers[0].videoChannel.id }) + await servers[0].videosCommand.update({ id: videoUUID, attributes: { channelId: servers[0].videoChannel.id } }) await waitJobs(servers) }) @@ -353,18 +345,21 @@ describe('Test video channels', function () { this.timeout(10000) for (const server of servers) { - const secondChannelURI = 'second_video_channel@localhost:' + servers[0].port - const res1 = await getVideoChannelVideos(server.url, server.accessToken, secondChannelURI, 0, 5) - expect(res1.body.total).to.equal(0) - - const channelURI = 'root_channel@localhost:' + servers[0].port - const res2 = await getVideoChannelVideos(server.url, server.accessToken, channelURI, 0, 5) - expect(res2.body.total).to.equal(1) - - const videos: Video[] = res2.body.data - expect(videos).to.be.an('array') - expect(videos).to.have.lengthOf(1) - expect(videos[0].name).to.equal('my video name') + { + const secondChannelURI = 'second_video_channel@localhost:' + servers[0].port + const { total } = await server.videosCommand.listByChannel({ videoChannelName: secondChannelURI }) + expect(total).to.equal(0) + } + + { + const channelURI = 'root_channel@localhost:' + servers[0].port + const { total, data } = await server.videosCommand.listByChannel({ videoChannelName: channelURI }) + expect(total).to.equal(1) + + expect(data).to.be.an('array') + expect(data).to.have.lengthOf(1) + expect(data[0].name).to.equal('my video name') + } } }) @@ -417,8 +412,8 @@ describe('Test video channels', function () { { // video has been posted on channel servers[0].videoChannel.id since last update - await viewVideo(servers[0].url, videoUUID, 204, '0.0.0.1,127.0.0.1') - await viewVideo(servers[0].url, videoUUID, 204, '0.0.0.2,127.0.0.1') + await servers[0].videosCommand.view({ id: videoUUID, xForwardedFor: '0.0.0.1,127.0.0.1' }) + await servers[0].videosCommand.view({ id: videoUUID, xForwardedFor: '0.0.0.2,127.0.0.1' }) // Wait the repeatable job await wait(8000) @@ -460,7 +455,7 @@ describe('Test video channels', function () { it('Should list channels by updatedAt desc if a video has been uploaded', async function () { this.timeout(30000) - await uploadVideo(servers[0].url, servers[0].accessToken, { channelId: totoChannel }) + await servers[0].videosCommand.upload({ attributes: { channelId: totoChannel } }) await waitJobs(servers) for (const server of servers) { @@ -470,7 +465,7 @@ describe('Test video channels', function () { expect(data[1].name).to.equal('root_channel') } - await uploadVideo(servers[0].url, servers[0].accessToken, { channelId: servers[0].videoChannel.id }) + await servers[0].videosCommand.upload({ attributes: { channelId: servers[0].videoChannel.id } }) await waitJobs(servers) for (const server of servers) { diff --git a/server/tests/api/videos/video-comments.ts b/server/tests/api/videos/video-comments.ts index 266824d58..41be54c81 100644 --- a/server/tests/api/videos/video-comments.ts +++ b/server/tests/api/videos/video-comments.ts @@ -9,8 +9,7 @@ import { flushAndRunServer, ServerInfo, setAccessTokensToServers, - testImage, - uploadVideo + testImage } from '@shared/extra-utils' const expect = chai.expect @@ -33,9 +32,9 @@ describe('Test video comments', function () { await setAccessTokensToServers([ server ]) - const res = await uploadVideo(server.url, server.accessToken, {}) - videoUUID = res.body.video.uuid - videoId = res.body.video.id + const { id, uuid } = await server.videosCommand.upload() + videoUUID = uuid + videoId = id await server.usersCommand.updateMyAvatar({ fixture: 'avatar.png' }) diff --git a/server/tests/api/videos/video-description.ts b/server/tests/api/videos/video-description.ts index e1c9afe79..6ac9206f5 100644 --- a/server/tests/api/videos/video-description.ts +++ b/server/tests/api/videos/video-description.ts @@ -2,19 +2,7 @@ import 'mocha' import * as chai from 'chai' -import { - cleanupTests, - flushAndRunMultipleServers, - getVideo, - getVideoDescription, - getVideosList, - ServerInfo, - setAccessTokensToServers, - updateVideo, - uploadVideo -} from '../../../../shared/extra-utils/index' -import { doubleFollow } from '../../../../shared/extra-utils/server/follows' -import { waitJobs } from '../../../../shared/extra-utils/server/jobs' +import { cleanupTests, doubleFollow, flushAndRunMultipleServers, ServerInfo, setAccessTokensToServers, waitJobs } from '@shared/extra-utils' const expect = chai.expect @@ -43,20 +31,19 @@ describe('Test video description', function () { const attributes = { description: longDescription } - await uploadVideo(servers[0].url, servers[0].accessToken, attributes) + await servers[0].videosCommand.upload({ attributes }) await waitJobs(servers) - const res = await getVideosList(servers[0].url) + const { data } = await servers[0].videosCommand.list() - videoId = res.body.data[0].id - videoUUID = res.body.data[0].uuid + videoId = data[0].id + videoUUID = data[0].uuid }) it('Should have a truncated description on each server', async function () { for (const server of servers) { - const res = await getVideo(server.url, videoUUID) - const video = res.body + const video = await server.videosCommand.get({ id: videoUUID }) // 30 characters * 6 -> 240 characters const truncatedDescription = 'my super description for server 1'.repeat(7) + @@ -68,11 +55,10 @@ describe('Test video description', function () { it('Should fetch long description on each server', async function () { for (const server of servers) { - const res = await getVideo(server.url, videoUUID) - const video = res.body + const video = await server.videosCommand.get({ id: videoUUID }) - const res2 = await getVideoDescription(server.url, video.descriptionPath) - expect(res2.body.description).to.equal(longDescription) + const { description } = await server.videosCommand.getDescription({ descriptionPath: video.descriptionPath }) + expect(description).to.equal(longDescription) } }) @@ -82,20 +68,19 @@ describe('Test video description', function () { const attributes = { description: 'short description' } - await updateVideo(servers[0].url, servers[0].accessToken, videoId, attributes) + await servers[0].videosCommand.update({ id: videoId, attributes }) await waitJobs(servers) }) it('Should have a small description on each server', async function () { for (const server of servers) { - const res = await getVideo(server.url, videoUUID) - const video = res.body + const video = await server.videosCommand.get({ id: videoUUID }) expect(video.description).to.equal('short description') - const res2 = await getVideoDescription(server.url, video.descriptionPath) - expect(res2.body.description).to.equal('short description') + const { description } = await server.videosCommand.getDescription({ descriptionPath: video.descriptionPath }) + expect(description).to.equal('short description') } }) diff --git a/server/tests/api/videos/video-hls.ts b/server/tests/api/videos/video-hls.ts index 428e1316d..d63b81694 100644 --- a/server/tests/api/videos/video-hls.ts +++ b/server/tests/api/videos/video-hls.ts @@ -3,7 +3,7 @@ import 'mocha' import * as chai from 'chai' import { join } from 'path' -import { HttpStatusCode } from '../../../../shared/core-utils/miscs/http-error-codes' +import { HttpStatusCode } from '@shared/core-utils' import { checkDirectoryIsEmpty, checkResolutionsInMasterPlaylist, @@ -12,26 +12,20 @@ import { cleanupTests, doubleFollow, flushAndRunMultipleServers, - getVideo, makeRawRequest, - removeVideo, ServerInfo, setAccessTokensToServers, - updateVideo, - uploadVideo, waitJobs, webtorrentAdd -} from '../../../../shared/extra-utils' -import { VideoDetails } from '../../../../shared/models/videos' -import { VideoStreamingPlaylistType } from '../../../../shared/models/videos/video-streaming-playlist.type' +} from '@shared/extra-utils' +import { VideoStreamingPlaylistType } from '@shared/models' import { DEFAULT_AUDIO_RESOLUTION } from '../../../initializers/constants' const expect = chai.expect async function checkHlsPlaylist (servers: ServerInfo[], videoUUID: string, hlsOnly: boolean, resolutions = [ 240, 360, 480, 720 ]) { for (const server of servers) { - const resVideoDetails = await getVideo(server.url, videoUUID) - const videoDetails: VideoDetails = resVideoDetails.body + const videoDetails = await server.videosCommand.get({ id: videoUUID }) const baseUrl = `http://${videoDetails.account.host}` expect(videoDetails.streamingPlaylists).to.have.lengthOf(1) @@ -113,8 +107,8 @@ describe('Test HLS videos', function () { it('Should upload a video and transcode it to HLS', async function () { this.timeout(120000) - const res = await uploadVideo(servers[0].url, servers[0].accessToken, { name: 'video 1', fixture: 'video_short.webm' }) - videoUUID = res.body.video.uuid + const { uuid } = await servers[0].videosCommand.upload({ attributes: { name: 'video 1', fixture: 'video_short.webm' } }) + videoUUID = uuid await waitJobs(servers) @@ -124,8 +118,8 @@ describe('Test HLS videos', function () { it('Should upload an audio file and transcode it to HLS', async function () { this.timeout(120000) - const res = await uploadVideo(servers[0].url, servers[0].accessToken, { name: 'video audio', fixture: 'sample.ogg' }) - videoAudioUUID = res.body.video.uuid + const { uuid } = await servers[0].videosCommand.upload({ attributes: { name: 'video audio', fixture: 'sample.ogg' } }) + videoAudioUUID = uuid await waitJobs(servers) @@ -135,7 +129,7 @@ describe('Test HLS videos', function () { it('Should update the video', async function () { this.timeout(10000) - await updateVideo(servers[0].url, servers[0].accessToken, videoUUID, { name: 'video 1 updated' }) + await servers[0].videosCommand.update({ id: videoUUID, attributes: { name: 'video 1 updated' } }) await waitJobs(servers) @@ -145,14 +139,14 @@ describe('Test HLS videos', function () { it('Should delete videos', async function () { this.timeout(10000) - await removeVideo(servers[0].url, servers[0].accessToken, videoUUID) - await removeVideo(servers[0].url, servers[0].accessToken, videoAudioUUID) + await servers[0].videosCommand.remove({ id: videoUUID }) + await servers[0].videosCommand.remove({ id: videoAudioUUID }) await waitJobs(servers) for (const server of servers) { - await getVideo(server.url, videoUUID, HttpStatusCode.NOT_FOUND_404) - await getVideo(server.url, videoAudioUUID, HttpStatusCode.NOT_FOUND_404) + await server.videosCommand.get({ id: videoUUID, expectedStatus: HttpStatusCode.NOT_FOUND_404 }) + await server.videosCommand.get({ id: videoAudioUUID, expectedStatus: HttpStatusCode.NOT_FOUND_404 }) } }) diff --git a/server/tests/api/videos/video-imports.ts b/server/tests/api/videos/video-imports.ts index 052c052b4..31fdfe12e 100644 --- a/server/tests/api/videos/video-imports.ts +++ b/server/tests/api/videos/video-imports.ts @@ -7,9 +7,6 @@ import { cleanupTests, doubleFollow, flushAndRunMultipleServers, - getMyVideos, - getVideo, - getVideosList, ImportsCommand, ServerInfo, setAccessTokensToServers, @@ -17,7 +14,7 @@ import { testImage, waitJobs } from '@shared/extra-utils' -import { VideoDetails, VideoPrivacy, VideoResolution } from '@shared/models' +import { VideoPrivacy, VideoResolution } from '@shared/models' const expect = chai.expect @@ -29,8 +26,7 @@ describe('Test video imports', function () { if (areHttpImportTestsDisabled()) return async function checkVideosServer1 (server: ServerInfo, idHttp: string, idMagnet: string, idTorrent: string) { - const resHttp = await getVideo(server.url, idHttp) - const videoHttp: VideoDetails = resHttp.body + const videoHttp = await server.videosCommand.get({ id: idHttp }) expect(videoHttp.name).to.equal('small video - youtube') // FIXME: youtube-dl seems broken @@ -47,10 +43,8 @@ describe('Test video imports', function () { expect(originallyPublishedAt.getMonth()).to.equal(0) expect(originallyPublishedAt.getFullYear()).to.equal(2019) - const resMagnet = await getVideo(server.url, idMagnet) - const videoMagnet: VideoDetails = resMagnet.body - const resTorrent = await getVideo(server.url, idTorrent) - const videoTorrent: VideoDetails = resTorrent.body + const videoMagnet = await server.videosCommand.get({ id: idMagnet }) + const videoTorrent = await server.videosCommand.get({ id: idTorrent }) for (const video of [ videoMagnet, videoTorrent ]) { expect(video.category.label).to.equal('Misc') @@ -70,8 +64,7 @@ describe('Test video imports', function () { } async function checkVideoServer2 (server: ServerInfo, id: number | string) { - const res = await getVideo(server.url, id) - const video: VideoDetails = res.body + const video = await server.videosCommand.get({ id }) expect(video.name).to.equal('my super name') expect(video.category.label).to.equal('Entertainment') @@ -190,15 +183,14 @@ Ajouter un sous-titre est vraiment facile`) }) it('Should list the videos to import in my videos on server 1', async function () { - const res = await getMyVideos(servers[0].url, servers[0].accessToken, 0, 5, 'createdAt') + const { total, data } = await servers[0].videosCommand.listMyVideos({ sort: 'createdAt' }) - expect(res.body.total).to.equal(3) + expect(total).to.equal(3) - const videos = res.body.data - expect(videos).to.have.lengthOf(3) - expect(videos[0].name).to.equal('small video - youtube') - expect(videos[1].name).to.equal('super peertube2 video') - expect(videos[2].name).to.equal('你好 世界 720p.mp4') + expect(data).to.have.lengthOf(3) + expect(data[0].name).to.equal('small video - youtube') + expect(data[1].name).to.equal('super peertube2 video') + expect(data[2].name).to.equal('你好 世界 720p.mp4') }) it('Should list the videos to import in my imports on server 1', async function () { @@ -229,11 +221,11 @@ Ajouter un sous-titre est vraiment facile`) await waitJobs(servers) for (const server of servers) { - const res = await getVideosList(server.url) - expect(res.body.total).to.equal(3) - expect(res.body.data).to.have.lengthOf(3) + const { total, data } = await server.videosCommand.list() + expect(total).to.equal(3) + expect(data).to.have.lengthOf(3) - const [ videoHttp, videoMagnet, videoTorrent ] = res.body.data + const [ videoHttp, videoMagnet, videoTorrent ] = data await checkVideosServer1(server, videoHttp.uuid, videoMagnet.uuid, videoTorrent.uuid) } }) @@ -262,13 +254,13 @@ Ajouter un sous-titre est vraiment facile`) await waitJobs(servers) for (const server of servers) { - const res = await getVideosList(server.url) - expect(res.body.total).to.equal(4) - expect(res.body.data).to.have.lengthOf(4) + const { total, data } = await server.videosCommand.list() + expect(total).to.equal(4) + expect(data).to.have.lengthOf(4) - await checkVideoServer2(server, res.body.data[0].uuid) + await checkVideoServer2(server, data[0].uuid) - const [ , videoHttp, videoMagnet, videoTorrent ] = res.body.data + const [ , videoHttp, videoMagnet, videoTorrent ] = data await checkVideosServer1(server, videoHttp.uuid, videoMagnet.uuid, videoTorrent.uuid) } }) @@ -288,8 +280,7 @@ Ajouter un sous-titre est vraiment facile`) await waitJobs(servers) for (const server of servers) { - const res = await getVideo(server.url, videoUUID) - const video: VideoDetails = res.body + const video = await server.videosCommand.get({ id: videoUUID }) expect(video.name).to.equal('transcoded video') expect(video.files).to.have.lengthOf(4) @@ -339,8 +330,7 @@ Ajouter un sous-titre est vraiment facile`) await waitJobs(servers) // test resolution - const res2 = await getVideo(servers[0].url, videoUUID) - const video: VideoDetails = res2.body + const video = await servers[0].videosCommand.get({ id: videoUUID }) expect(video.name).to.equal('hdr video') const maxResolution = Math.max.apply(Math, video.files.map(function (o) { return o.resolution.id })) expect(maxResolution, 'expected max resolution not met').to.equals(VideoResolution.H_1080P) diff --git a/server/tests/api/videos/video-nsfw.ts b/server/tests/api/videos/video-nsfw.ts index 9dc26fca6..b8fff096d 100644 --- a/server/tests/api/videos/video-nsfw.ts +++ b/server/tests/api/videos/video-nsfw.ts @@ -2,18 +2,7 @@ import 'mocha' import * as chai from 'chai' -import { - cleanupTests, - flushAndRunServer, - getAccountVideos, - getMyVideos, - getVideoChannelVideos, - getVideosList, - getVideosListWithToken, - ServerInfo, - setAccessTokensToServers, - uploadVideo -} from '@shared/extra-utils' +import { cleanupTests, flushAndRunServer, ServerInfo, setAccessTokensToServers } from '@shared/extra-utils' import { BooleanBothQuery, CustomConfig, ResultList, Video, VideosOverview } from '@shared/models' const expect = chai.expect @@ -37,10 +26,10 @@ describe('Test video NSFW policy', function () { if (token) { promises = [ - getVideosListWithToken(server.url, token, query).then(res => res.body), server.searchCommand.advancedVideoSearch({ token, search: { search: 'n', sort: '-publishedAt', ...query } }), - getAccountVideos(server.url, token, accountName, 0, 5, undefined, query).then(res => res.body), - getVideoChannelVideos(server.url, token, videoChannelName, 0, 5, undefined, query).then(res => res.body) + server.videosCommand.listWithToken({ token, ...query }), + server.videosCommand.listByAccount({ token, accountName, ...query }), + server.videosCommand.listByChannel({ token, videoChannelName, ...query }) ] // Overviews do not support video filters @@ -54,10 +43,10 @@ describe('Test video NSFW policy', function () { } promises = [ - getVideosList(server.url).then(res => res.body), server.searchCommand.searchVideos({ search: 'n', sort: '-publishedAt' }), - getAccountVideos(server.url, undefined, accountName, 0, 5).then(res => res.body), - getVideoChannelVideos(server.url, undefined, videoChannelName, 0, 5).then(res => res.body) + server.videosCommand.list(), + server.videosCommand.listByAccount({ accountName }), + server.videosCommand.listByChannel({ videoChannelName }) ] // Overviews do not support video filters @@ -79,12 +68,12 @@ describe('Test video NSFW policy', function () { { const attributes = { name: 'nsfw', nsfw: true, category: 1 } - await uploadVideo(server.url, server.accessToken, attributes) + await server.videosCommand.upload({ attributes }) } { const attributes = { name: 'normal', nsfw: false, category: 1 } - await uploadVideo(server.url, server.accessToken, attributes) + await server.videosCommand.upload({ attributes }) } customConfig = await server.configCommand.getCustomConfig() @@ -192,13 +181,12 @@ describe('Test video NSFW policy', function () { }) it('Should be able to see my NSFW videos even with do_not_list user NSFW policy', async function () { - const res = await getMyVideos(server.url, server.accessToken, 0, 5) - expect(res.body.total).to.equal(2) + const { total, data } = await server.videosCommand.listMyVideos() + expect(total).to.equal(2) - const videos = res.body.data - expect(videos).to.have.lengthOf(2) - expect(videos[0].name).to.equal('normal') - expect(videos[1].name).to.equal('nsfw') + expect(data).to.have.lengthOf(2) + expect(data[0].name).to.equal('normal') + expect(data[1].name).to.equal('nsfw') }) it('Should display NSFW videos when the nsfw param === true', async function () { diff --git a/server/tests/api/videos/video-playlist-thumbnails.ts b/server/tests/api/videos/video-playlist-thumbnails.ts index af5df8d90..14739af20 100644 --- a/server/tests/api/videos/video-playlist-thumbnails.ts +++ b/server/tests/api/videos/video-playlist-thumbnails.ts @@ -10,7 +10,6 @@ import { setAccessTokensToServers, setDefaultVideoChannel, testImage, - uploadVideoAndGetId, waitJobs } from '../../../../shared/extra-utils' import { VideoPlaylistPrivacy } from '../../../../shared/models/videos/playlist/video-playlist-privacy.model' @@ -55,8 +54,8 @@ describe('Playlist thumbnail', function () { // Server 1 and server 2 follow each other await doubleFollow(servers[0], servers[1]) - video1 = (await uploadVideoAndGetId({ server: servers[0], videoName: 'video 1' })).id - video2 = (await uploadVideoAndGetId({ server: servers[0], videoName: 'video 2' })).id + video1 = (await servers[0].videosCommand.quickUpload({ name: 'video 1' })).id + video2 = (await servers[0].videosCommand.quickUpload({ name: 'video 2' })).id await waitJobs(servers) }) diff --git a/server/tests/api/videos/video-playlists.ts b/server/tests/api/videos/video-playlists.ts index e57d86c14..40f61ca19 100644 --- a/server/tests/api/videos/video-playlists.ts +++ b/server/tests/api/videos/video-playlists.ts @@ -13,9 +13,6 @@ import { setAccessTokensToServers, setDefaultVideoChannel, testImage, - updateVideo, - uploadVideo, - uploadVideoAndGetId, wait, waitJobs } from '@shared/extra-utils' @@ -99,14 +96,14 @@ describe('Test video playlists', function () { for (const server of servers) { for (let i = 0; i < 7; i++) { const name = `video ${i} server ${server.serverNumber}` - const resVideo = await uploadVideo(server.url, server.accessToken, { name, nsfw: false }) + const video = await server.videosCommand.upload({ attributes: { name, nsfw: false } }) - server.videos.push(resVideo.body.video) + server.videos.push(video) } } } - nsfwVideoServer1 = (await uploadVideoAndGetId({ server: servers[0], videoName: 'NSFW video', nsfw: true })).id + nsfwVideoServer1 = (await servers[0].videosCommand.quickUpload({ name: 'NSFW video', nsfw: true })).id userTokenServer1 = await servers[0].usersCommand.generateUserAndToken('user1') @@ -620,9 +617,9 @@ describe('Test video playlists', function () { return commands[0].addElement({ token: userTokenServer1, playlistId: playlistServer1Id2, attributes }) } - video1 = (await uploadVideoAndGetId({ server: servers[0], videoName: 'video 89', token: userTokenServer1 })).uuid - video2 = (await uploadVideoAndGetId({ server: servers[1], videoName: 'video 90' })).uuid - video3 = (await uploadVideoAndGetId({ server: servers[0], videoName: 'video 91', nsfw: true })).uuid + video1 = (await servers[0].videosCommand.quickUpload({ name: 'video 89', token: userTokenServer1 })).uuid + video2 = (await servers[1].videosCommand.quickUpload({ name: 'video 90' })).uuid + video3 = (await servers[0].videosCommand.quickUpload({ name: 'video 91', nsfw: true })).uuid await waitJobs(servers) @@ -640,7 +637,7 @@ describe('Test video playlists', function () { const position = 1 { - await updateVideo(servers[0].url, servers[0].accessToken, video1, { privacy: VideoPrivacy.PRIVATE }) + await servers[0].videosCommand.update({ id: video1, attributes: { privacy: VideoPrivacy.PRIVATE } }) await waitJobs(servers) await checkPlaylistElementType(groupUser1, playlistServer1UUID2, VideoPlaylistElementType.REGULAR, position, name, 3) @@ -650,7 +647,7 @@ describe('Test video playlists', function () { } { - await updateVideo(servers[0].url, servers[0].accessToken, video1, { privacy: VideoPrivacy.PUBLIC }) + await servers[0].videosCommand.update({ id: video1, attributes: { privacy: VideoPrivacy.PUBLIC } }) await waitJobs(servers) await checkPlaylistElementType(groupUser1, playlistServer1UUID2, VideoPlaylistElementType.REGULAR, position, name, 3) diff --git a/server/tests/api/videos/video-privacy.ts b/server/tests/api/videos/video-privacy.ts index 4e349e350..bcf431edb 100644 --- a/server/tests/api/videos/video-privacy.ts +++ b/server/tests/api/videos/video-privacy.ts @@ -3,22 +3,8 @@ import 'mocha' import * as chai from 'chai' import { HttpStatusCode } from '@shared/core-utils' -import { - cleanupTests, - doubleFollow, - flushAndRunServer, - getMyVideos, - getVideo, - getVideosList, - getVideosListWithToken, - getVideoWithToken, - ServerInfo, - setAccessTokensToServers, - updateVideo, - uploadVideo, - waitJobs -} from '@shared/extra-utils' -import { Video, VideoCreateResult, VideoPrivacy } from '@shared/models' +import { cleanupTests, doubleFollow, flushAndRunServer, ServerInfo, setAccessTokensToServers, waitJobs } from '@shared/extra-utils' +import { VideoCreateResult, VideoPrivacy } from '@shared/models' const expect = chai.expect @@ -66,55 +52,53 @@ describe('Test video privacy', function () { for (const privacy of [ VideoPrivacy.PRIVATE, VideoPrivacy.INTERNAL ]) { const attributes = { privacy } - await uploadVideo(servers[0].url, servers[0].accessToken, attributes) + await servers[0].videosCommand.upload({ attributes }) } await waitJobs(servers) }) it('Should not have these private and internal videos on server 2', async function () { - const res = await getVideosList(servers[1].url) + const { total, data } = await servers[1].videosCommand.list() - expect(res.body.total).to.equal(0) - expect(res.body.data).to.have.lengthOf(0) + expect(total).to.equal(0) + expect(data).to.have.lengthOf(0) }) it('Should not list the private and internal videos for an unauthenticated user on server 1', async function () { - const res = await getVideosList(servers[0].url) + const { total, data } = await servers[0].videosCommand.list() - expect(res.body.total).to.equal(0) - expect(res.body.data).to.have.lengthOf(0) + expect(total).to.equal(0) + expect(data).to.have.lengthOf(0) }) it('Should not list the private video and list the internal video for an authenticated user on server 1', async function () { - const res = await getVideosListWithToken(servers[0].url, servers[0].accessToken) + const { total, data } = await servers[0].videosCommand.listWithToken() - expect(res.body.total).to.equal(1) - expect(res.body.data).to.have.lengthOf(1) + expect(total).to.equal(1) + expect(data).to.have.lengthOf(1) - expect(res.body.data[0].privacy.id).to.equal(VideoPrivacy.INTERNAL) + expect(data[0].privacy.id).to.equal(VideoPrivacy.INTERNAL) }) it('Should list my (private and internal) videos', async function () { - const res = await getMyVideos(servers[0].url, servers[0].accessToken, 0, 10) + const { total, data } = await servers[0].videosCommand.listMyVideos() - expect(res.body.total).to.equal(2) - expect(res.body.data).to.have.lengthOf(2) + expect(total).to.equal(2) + expect(data).to.have.lengthOf(2) - const videos: Video[] = res.body.data - - const privateVideo = videos.find(v => v.privacy.id === VideoPrivacy.PRIVATE) + const privateVideo = data.find(v => v.privacy.id === VideoPrivacy.PRIVATE) privateVideoId = privateVideo.id privateVideoUUID = privateVideo.uuid - const internalVideo = videos.find(v => v.privacy.id === VideoPrivacy.INTERNAL) + const internalVideo = data.find(v => v.privacy.id === VideoPrivacy.INTERNAL) internalVideoId = internalVideo.id internalVideoUUID = internalVideo.uuid }) it('Should not be able to watch the private/internal video with non authenticated user', async function () { - await getVideo(servers[0].url, privateVideoUUID, HttpStatusCode.UNAUTHORIZED_401) - await getVideo(servers[0].url, internalVideoUUID, HttpStatusCode.UNAUTHORIZED_401) + await servers[0].videosCommand.get({ id: privateVideoUUID, expectedStatus: HttpStatusCode.UNAUTHORIZED_401 }) + await servers[0].videosCommand.get({ id: internalVideoUUID, expectedStatus: HttpStatusCode.UNAUTHORIZED_401 }) }) it('Should not be able to watch the private video with another user', async function () { @@ -127,15 +111,20 @@ describe('Test video privacy', function () { await servers[0].usersCommand.create({ username: user.username, password: user.password }) anotherUserToken = await servers[0].loginCommand.getAccessToken(user) - await getVideoWithToken(servers[0].url, anotherUserToken, privateVideoUUID, HttpStatusCode.FORBIDDEN_403) + + await servers[0].videosCommand.getWithToken({ + token: anotherUserToken, + id: privateVideoUUID, + expectedStatus: HttpStatusCode.FORBIDDEN_403 + }) }) it('Should be able to watch the internal video with another user', async function () { - await getVideoWithToken(servers[0].url, anotherUserToken, internalVideoUUID, HttpStatusCode.OK_200) + await servers[0].videosCommand.getWithToken({ token: anotherUserToken, id: internalVideoUUID }) }) it('Should be able to watch the private video with the correct user', async function () { - await getVideoWithToken(servers[0].url, servers[0].accessToken, privateVideoUUID, HttpStatusCode.OK_200) + await servers[0].videosCommand.getWithToken({ id: privateVideoUUID }) }) }) @@ -148,7 +137,7 @@ describe('Test video privacy', function () { name: 'unlisted video', privacy: VideoPrivacy.UNLISTED } - await uploadVideo(servers[1].url, servers[1].accessToken, attributes) + await servers[1].videosCommand.upload({ attributes }) // Server 2 has transcoding enabled await waitJobs(servers) @@ -156,32 +145,32 @@ describe('Test video privacy', function () { it('Should not have this unlisted video listed on server 1 and 2', async function () { for (const server of servers) { - const res = await getVideosList(server.url) + const { total, data } = await server.videosCommand.list() - expect(res.body.total).to.equal(0) - expect(res.body.data).to.have.lengthOf(0) + expect(total).to.equal(0) + expect(data).to.have.lengthOf(0) } }) it('Should list my (unlisted) videos', async function () { - const res = await getMyVideos(servers[1].url, servers[1].accessToken, 0, 1) + const { total, data } = await servers[1].videosCommand.listMyVideos() - expect(res.body.total).to.equal(1) - expect(res.body.data).to.have.lengthOf(1) + expect(total).to.equal(1) + expect(data).to.have.lengthOf(1) - unlistedVideo = res.body.data[0] + unlistedVideo = data[0] }) it('Should not be able to get this unlisted video using its id', async function () { - await getVideo(servers[1].url, unlistedVideo.id, 404) + await servers[1].videosCommand.get({ id: unlistedVideo.id, expectedStatus: HttpStatusCode.BAD_REQUEST_400 }) }) it('Should be able to get this unlisted video using its uuid/shortUUID', async function () { for (const server of servers) { for (const id of [ unlistedVideo.uuid, unlistedVideo.shortUUID ]) { - const res = await getVideo(server.url, id) + const video = await server.videosCommand.get({ id }) - expect(res.body.name).to.equal('unlisted video') + expect(video.name).to.equal('unlisted video') } } }) @@ -193,28 +182,28 @@ describe('Test video privacy', function () { name: 'unlisted video', privacy: VideoPrivacy.UNLISTED } - await uploadVideo(servers[0].url, servers[0].accessToken, attributes) + await servers[0].videosCommand.upload({ attributes }) await waitJobs(servers) }) it('Should list my new unlisted video', async function () { - const res = await getMyVideos(servers[0].url, servers[0].accessToken, 0, 3) + const { total, data } = await servers[0].videosCommand.listMyVideos() - expect(res.body.total).to.equal(3) - expect(res.body.data).to.have.lengthOf(3) + expect(total).to.equal(3) + expect(data).to.have.lengthOf(3) - nonFederatedUnlistedVideoUUID = res.body.data[0].uuid + nonFederatedUnlistedVideoUUID = data[0].uuid }) it('Should be able to get non-federated unlisted video from origin', async function () { - const res = await getVideo(servers[0].url, nonFederatedUnlistedVideoUUID) + const video = await servers[0].videosCommand.get({ id: nonFederatedUnlistedVideoUUID }) - expect(res.body.name).to.equal('unlisted video') + expect(video.name).to.equal('unlisted video') }) it('Should not be able to get non-federated unlisted video from federated server', async function () { - await getVideo(servers[1].url, nonFederatedUnlistedVideoUUID, HttpStatusCode.NOT_FOUND_404) + await servers[1].videosCommand.get({ id: nonFederatedUnlistedVideoUUID, expectedStatus: HttpStatusCode.NOT_FOUND_404 }) }) }) @@ -226,20 +215,20 @@ describe('Test video privacy', function () { now = Date.now() { - const attribute = { + const attributes = { name: 'private video becomes public', privacy: VideoPrivacy.PUBLIC } - await updateVideo(servers[0].url, servers[0].accessToken, privateVideoId, attribute) + await servers[0].videosCommand.update({ id: privateVideoId, attributes }) } { - const attribute = { + const attributes = { name: 'internal video becomes public', privacy: VideoPrivacy.PUBLIC } - await updateVideo(servers[0].url, servers[0].accessToken, internalVideoId, attribute) + await servers[0].videosCommand.update({ id: internalVideoId, attributes }) } await waitJobs(servers) @@ -247,13 +236,12 @@ describe('Test video privacy', function () { it('Should have this new public video listed on server 1 and 2', async function () { for (const server of servers) { - const res = await getVideosList(server.url) - expect(res.body.total).to.equal(2) - expect(res.body.data).to.have.lengthOf(2) + const { total, data } = await server.videosCommand.list() + expect(total).to.equal(2) + expect(data).to.have.lengthOf(2) - const videos: Video[] = res.body.data - const privateVideo = videos.find(v => v.name === 'private video becomes public') - const internalVideo = videos.find(v => v.name === 'internal video becomes public') + const privateVideo = data.find(v => v.name === 'private video becomes public') + const internalVideo = data.find(v => v.name === 'internal video becomes public') expect(privateVideo).to.not.be.undefined expect(internalVideo).to.not.be.undefined @@ -270,27 +258,25 @@ describe('Test video privacy', function () { it('Should set these videos as private and internal', async function () { this.timeout(10000) - await updateVideo(servers[0].url, servers[0].accessToken, internalVideoId, { privacy: VideoPrivacy.PRIVATE }) - await updateVideo(servers[0].url, servers[0].accessToken, privateVideoId, { privacy: VideoPrivacy.INTERNAL }) + await servers[0].videosCommand.update({ id: internalVideoId, attributes: { privacy: VideoPrivacy.PRIVATE } }) + await servers[0].videosCommand.update({ id: privateVideoId, attributes: { privacy: VideoPrivacy.INTERNAL } }) await waitJobs(servers) for (const server of servers) { - const res = await getVideosList(server.url) + const { total, data } = await server.videosCommand.list() - expect(res.body.total).to.equal(0) - expect(res.body.data).to.have.lengthOf(0) + expect(total).to.equal(0) + expect(data).to.have.lengthOf(0) } { - const res = await getMyVideos(servers[0].url, servers[0].accessToken, 0, 5) - const videos = res.body.data - - expect(res.body.total).to.equal(3) - expect(videos).to.have.lengthOf(3) + const { total, data } = await servers[0].videosCommand.listMyVideos() + expect(total).to.equal(3) + expect(data).to.have.lengthOf(3) - const privateVideo = videos.find(v => v.name === 'private video becomes public') - const internalVideo = videos.find(v => v.name === 'internal video becomes public') + const privateVideo = data.find(v => v.name === 'private video becomes public') + const internalVideo = data.find(v => v.name === 'internal video becomes public') expect(privateVideo).to.not.be.undefined expect(internalVideo).to.not.be.undefined diff --git a/server/tests/api/videos/video-schedule-update.ts b/server/tests/api/videos/video-schedule-update.ts index 204f43611..635ae6ff1 100644 --- a/server/tests/api/videos/video-schedule-update.ts +++ b/server/tests/api/videos/video-schedule-update.ts @@ -1,22 +1,17 @@ /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */ -import * as chai from 'chai' import 'mocha' -import { VideoPrivacy } from '../../../../shared/models/videos' +import * as chai from 'chai' import { cleanupTests, doubleFollow, flushAndRunMultipleServers, - getMyVideos, - getVideosList, - getVideoWithToken, ServerInfo, setAccessTokensToServers, - updateVideo, - uploadVideo, - wait -} from '../../../../shared/extra-utils' -import { waitJobs } from '../../../../shared/extra-utils/server/jobs' + wait, + waitJobs +} from '@shared/extra-utils' +import { VideoPrivacy } from '@shared/models' const expect = chai.expect @@ -45,35 +40,34 @@ describe('Test video update scheduler', function () { it('Should upload a video and schedule an update in 10 seconds', async function () { this.timeout(10000) - const videoAttributes = { + const attributes = { name: 'video 1', privacy: VideoPrivacy.PRIVATE, scheduleUpdate: { updateAt: in10Seconds().toISOString(), - privacy: VideoPrivacy.PUBLIC + privacy: VideoPrivacy.PUBLIC as VideoPrivacy.PUBLIC } } - await uploadVideo(servers[0].url, servers[0].accessToken, videoAttributes) + await servers[0].videosCommand.upload({ attributes }) await waitJobs(servers) }) it('Should not list the video (in privacy mode)', async function () { for (const server of servers) { - const res = await getVideosList(server.url) + const { total } = await server.videosCommand.list() - expect(res.body.total).to.equal(0) + expect(total).to.equal(0) } }) it('Should have my scheduled video in my account videos', async function () { - const res = await getMyVideos(servers[0].url, servers[0].accessToken, 0, 5) - expect(res.body.total).to.equal(1) + const { total, data } = await servers[0].videosCommand.listMyVideos() + expect(total).to.equal(1) - const videoFromList = res.body.data[0] - const res2 = await getVideoWithToken(servers[0].url, servers[0].accessToken, videoFromList.uuid) - const videoFromGet = res2.body + const videoFromList = data[0] + const videoFromGet = await servers[0].videosCommand.getWithToken({ id: videoFromList.uuid }) for (const video of [ videoFromList, videoFromGet ]) { expect(video.name).to.equal('video 1') @@ -90,23 +84,23 @@ describe('Test video update scheduler', function () { await waitJobs(servers) for (const server of servers) { - const res = await getVideosList(server.url) + const { total, data } = await server.videosCommand.list() - expect(res.body.total).to.equal(1) - expect(res.body.data[0].name).to.equal('video 1') + expect(total).to.equal(1) + expect(data[0].name).to.equal('video 1') } }) it('Should upload a video without scheduling an update', async function () { this.timeout(10000) - const videoAttributes = { + const attributes = { name: 'video 2', privacy: VideoPrivacy.PRIVATE } - const res = await uploadVideo(servers[0].url, servers[0].accessToken, videoAttributes) - video2UUID = res.body.video.uuid + const { uuid } = await servers[0].videosCommand.upload({ attributes }) + video2UUID = uuid await waitJobs(servers) }) @@ -114,31 +108,31 @@ describe('Test video update scheduler', function () { it('Should update a video by scheduling an update', async function () { this.timeout(10000) - const videoAttributes = { + const attributes = { name: 'video 2 updated', scheduleUpdate: { updateAt: in10Seconds().toISOString(), - privacy: VideoPrivacy.PUBLIC + privacy: VideoPrivacy.PUBLIC as VideoPrivacy.PUBLIC } } - await updateVideo(servers[0].url, servers[0].accessToken, video2UUID, videoAttributes) + await servers[0].videosCommand.update({ id: video2UUID, attributes }) await waitJobs(servers) }) it('Should not display the updated video', async function () { for (const server of servers) { - const res = await getVideosList(server.url) + const { total } = await server.videosCommand.list() - expect(res.body.total).to.equal(1) + expect(total).to.equal(1) } }) it('Should have my scheduled updated video in my account videos', async function () { - const res = await getMyVideos(servers[0].url, servers[0].accessToken, 0, 5) - expect(res.body.total).to.equal(2) + const { total, data } = await servers[0].videosCommand.listMyVideos() + expect(total).to.equal(2) - const video = res.body.data.find(v => v.uuid === video2UUID) + const video = data.find(v => v.uuid === video2UUID) expect(video).not.to.be.undefined expect(video.name).to.equal('video 2 updated') @@ -155,11 +149,10 @@ describe('Test video update scheduler', function () { await waitJobs(servers) for (const server of servers) { - const res = await getVideosList(server.url) - - expect(res.body.total).to.equal(2) + const { total, data } = await server.videosCommand.list() + expect(total).to.equal(2) - const video = res.body.data.find(v => v.uuid === video2UUID) + const video = data.find(v => v.uuid === video2UUID) expect(video).not.to.be.undefined expect(video.name).to.equal('video 2 updated') } diff --git a/server/tests/api/videos/video-transcoder.ts b/server/tests/api/videos/video-transcoder.ts index f16b22bae..b41c68283 100644 --- a/server/tests/api/videos/video-transcoder.ts +++ b/server/tests/api/videos/video-transcoder.ts @@ -2,11 +2,9 @@ import 'mocha' import * as chai from 'chai' -import { FfprobeData } from 'fluent-ffmpeg' import { omit } from 'lodash' import { join } from 'path' -import { VIDEO_TRANSCODING_FPS } from '../../../../server/initializers/constants' -import { HttpStatusCode } from '../../../../shared/core-utils/miscs/http-error-codes' +import { HttpStatusCode } from '@shared/core-utils' import { buildAbsoluteFixturePath, cleanupTests, @@ -14,19 +12,14 @@ import { flushAndRunMultipleServers, generateHighBitrateVideo, generateVideoWithFramerate, - getMyVideos, - getVideo, - getVideoFileMetadataUrl, - getVideosList, makeGetRequest, ServerInfo, setAccessTokensToServers, - uploadVideo, - uploadVideoAndGetId, waitJobs, webtorrentAdd -} from '../../../../shared/extra-utils' -import { getMaxBitrate, VideoDetails, VideoResolution, VideoState } from '../../../../shared/models/videos' +} from '@shared/extra-utils' +import { getMaxBitrate, VideoResolution, VideoState } from '@shared/models' +import { VIDEO_TRANSCODING_FPS } from '../../../../server/initializers/constants' import { canDoQuickTranscode, getAudioStream, @@ -84,21 +77,20 @@ describe('Test video transcoding', function () { it('Should not transcode video on server 1', async function () { this.timeout(60_000) - const videoAttributes = { + const attributes = { name: 'my super name for server 1', description: 'my super description for server 1', fixture: 'video_short.webm' } - await uploadVideo(servers[0].url, servers[0].accessToken, videoAttributes) + await servers[0].videosCommand.upload({ attributes }) await waitJobs(servers) for (const server of servers) { - const res = await getVideosList(server.url) - const video = res.body.data[0] + const { data } = await server.videosCommand.list() + const video = data[0] - const res2 = await getVideo(server.url, video.id) - const videoDetails = res2.body + const videoDetails = await server.videosCommand.get({ id: video.id }) expect(videoDetails.files).to.have.lengthOf(1) const magnetUri = videoDetails.files[0].magnetUri @@ -114,21 +106,20 @@ describe('Test video transcoding', function () { it('Should transcode video on server 2', async function () { this.timeout(120_000) - const videoAttributes = { + const attributes = { name: 'my super name for server 2', description: 'my super description for server 2', fixture: 'video_short.webm' } - await uploadVideo(servers[1].url, servers[1].accessToken, videoAttributes) + await servers[1].videosCommand.upload({ attributes }) await waitJobs(servers) for (const server of servers) { - const res = await getVideosList(server.url) + const { data } = await server.videosCommand.list() - const video = res.body.data.find(v => v.name === videoAttributes.name) - const res2 = await getVideo(server.url, video.id) - const videoDetails = res2.body + const video = data.find(v => v.name === attributes.name) + const videoDetails = await server.videosCommand.get({ id: video.id }) expect(videoDetails.files).to.have.lengthOf(4) @@ -147,47 +138,50 @@ describe('Test video transcoding', function () { { // Upload the video, but wait transcoding - const videoAttributes = { + const attributes = { name: 'waiting video', fixture: 'video_short1.webm', waitTranscoding: true } - const resVideo = await uploadVideo(servers[1].url, servers[1].accessToken, videoAttributes) - const videoId = resVideo.body.video.uuid + const { uuid } = await servers[1].videosCommand.upload({ attributes }) + const videoId = uuid // Should be in transcode state - const { body } = await getVideo(servers[1].url, videoId) + const body = await servers[1].videosCommand.get({ id: videoId }) expect(body.name).to.equal('waiting video') expect(body.state.id).to.equal(VideoState.TO_TRANSCODE) expect(body.state.label).to.equal('To transcode') expect(body.waitTranscoding).to.be.true - // Should have my video - const resMyVideos = await getMyVideos(servers[1].url, servers[1].accessToken, 0, 10) - const videoToFindInMine = resMyVideos.body.data.find(v => v.name === videoAttributes.name) - expect(videoToFindInMine).not.to.be.undefined - expect(videoToFindInMine.state.id).to.equal(VideoState.TO_TRANSCODE) - expect(videoToFindInMine.state.label).to.equal('To transcode') - expect(videoToFindInMine.waitTranscoding).to.be.true + { + // Should have my video + const { data } = await servers[1].videosCommand.listMyVideos() + const videoToFindInMine = data.find(v => v.name === attributes.name) + expect(videoToFindInMine).not.to.be.undefined + expect(videoToFindInMine.state.id).to.equal(VideoState.TO_TRANSCODE) + expect(videoToFindInMine.state.label).to.equal('To transcode') + expect(videoToFindInMine.waitTranscoding).to.be.true + } - // Should not list this video - const resVideos = await getVideosList(servers[1].url) - const videoToFindInList = resVideos.body.data.find(v => v.name === videoAttributes.name) - expect(videoToFindInList).to.be.undefined + { + // Should not list this video + const { data } = await servers[1].videosCommand.list() + const videoToFindInList = data.find(v => v.name === attributes.name) + expect(videoToFindInList).to.be.undefined + } // Server 1 should not have the video yet - await getVideo(servers[0].url, videoId, HttpStatusCode.NOT_FOUND_404) + await servers[0].videosCommand.get({ id: videoId, expectedStatus: HttpStatusCode.NOT_FOUND_404 }) } await waitJobs(servers) for (const server of servers) { - const res = await getVideosList(server.url) - const videoToFind = res.body.data.find(v => v.name === 'waiting video') + const { data } = await server.videosCommand.list() + const videoToFind = data.find(v => v.name === 'waiting video') expect(videoToFind).not.to.be.undefined - const res2 = await getVideo(server.url, videoToFind.id) - const videoDetails: VideoDetails = res2.body + const videoDetails = await server.videosCommand.get({ id: videoToFind.id }) expect(videoDetails.state.id).to.equal(VideoState.PUBLISHED) expect(videoDetails.state.label).to.equal('Published') @@ -208,22 +202,20 @@ describe('Test video transcoding', function () { } for (const fixture of [ 'video_short.mkv', 'video_short.avi' ]) { - const videoAttributes = { + const attributes = { name: fixture, fixture } - await uploadVideo(servers[1].url, servers[1].accessToken, videoAttributes) + await servers[1].videosCommand.upload({ attributes }) await waitJobs(servers) for (const server of servers) { - const res = await getVideosList(server.url) - - const video = res.body.data.find(v => v.name === videoAttributes.name) - const res2 = await getVideo(server.url, video.id) - const videoDetails = res2.body + const { data } = await server.videosCommand.list() + const video = data.find(v => v.name === attributes.name) + const videoDetails = await server.videosCommand.get({ id: video.id }) expect(videoDetails.files).to.have.lengthOf(4) const magnetUri = videoDetails.files[0].magnetUri @@ -235,22 +227,20 @@ describe('Test video transcoding', function () { it('Should transcode a 4k video', async function () { this.timeout(200_000) - const videoAttributes = { + const attributes = { name: '4k video', fixture: 'video_short_4k.mp4' } - const resUpload = await uploadVideo(servers[1].url, servers[1].accessToken, videoAttributes) - video4k = resUpload.body.video.uuid + const { uuid } = await servers[1].videosCommand.upload({ attributes }) + video4k = uuid await waitJobs(servers) const resolutions = [ 240, 360, 480, 720, 1080, 1440, 2160 ] for (const server of servers) { - const res = await getVideo(server.url, video4k) - const videoDetails: VideoDetails = res.body - + const videoDetails = await server.videosCommand.get({ id: video4k }) expect(videoDetails.files).to.have.lengthOf(resolutions.length) for (const r of resolutions) { @@ -266,20 +256,19 @@ describe('Test video transcoding', function () { it('Should transcode high bit rate mp3 to proper bit rate', async function () { this.timeout(60_000) - const videoAttributes = { + const attributes = { name: 'mp3_256k', fixture: 'video_short_mp3_256k.mp4' } - await uploadVideo(servers[1].url, servers[1].accessToken, videoAttributes) + await servers[1].videosCommand.upload({ attributes }) await waitJobs(servers) for (const server of servers) { - const res = await getVideosList(server.url) + const { data } = await server.videosCommand.list() - const video = res.body.data.find(v => v.name === videoAttributes.name) - const res2 = await getVideo(server.url, video.id) - const videoDetails: VideoDetails = res2.body + const video = data.find(v => v.name === attributes.name) + const videoDetails = await server.videosCommand.get({ id: video.id }) expect(videoDetails.files).to.have.lengthOf(4) @@ -298,20 +287,19 @@ describe('Test video transcoding', function () { it('Should transcode video with no audio and have no audio itself', async function () { this.timeout(60_000) - const videoAttributes = { + const attributes = { name: 'no_audio', fixture: 'video_short_no_audio.mp4' } - await uploadVideo(servers[1].url, servers[1].accessToken, videoAttributes) + await servers[1].videosCommand.upload({ attributes }) await waitJobs(servers) for (const server of servers) { - const res = await getVideosList(server.url) + const { data } = await server.videosCommand.list() - const video = res.body.data.find(v => v.name === videoAttributes.name) - const res2 = await getVideo(server.url, video.id) - const videoDetails: VideoDetails = res2.body + const video = data.find(v => v.name === attributes.name) + const videoDetails = await server.videosCommand.get({ id: video.id }) expect(videoDetails.files).to.have.lengthOf(4) const path = servers[1].serversCommand.buildDirectory(join('videos', video.uuid + '-240.mp4')) @@ -323,24 +311,23 @@ describe('Test video transcoding', function () { it('Should leave the audio untouched, but properly transcode the video', async function () { this.timeout(60_000) - const videoAttributes = { + const attributes = { name: 'untouched_audio', fixture: 'video_short.mp4' } - await uploadVideo(servers[1].url, servers[1].accessToken, videoAttributes) + await servers[1].videosCommand.upload({ attributes }) await waitJobs(servers) for (const server of servers) { - const res = await getVideosList(server.url) + const { data } = await server.videosCommand.list() - const video = res.body.data.find(v => v.name === videoAttributes.name) - const res2 = await getVideo(server.url, video.id) - const videoDetails: VideoDetails = res2.body + const video = data.find(v => v.name === attributes.name) + const videoDetails = await server.videosCommand.get({ id: video.id }) expect(videoDetails.files).to.have.lengthOf(4) - const fixturePath = buildAbsoluteFixturePath(videoAttributes.fixture) + const fixturePath = buildAbsoluteFixturePath(attributes.fixture) const fixtureVideoProbe = await getAudioStream(fixturePath) const path = servers[1].serversCommand.buildDirectory(join('videos', video.uuid + '-240.mp4')) @@ -384,17 +371,16 @@ describe('Test video transcoding', function () { it('Should merge an audio file with the preview file', async function () { this.timeout(60_000) - const videoAttributesArg = { name: 'audio_with_preview', previewfile: 'preview.jpg', fixture: 'sample.ogg' } - await uploadVideo(servers[1].url, servers[1].accessToken, videoAttributesArg, HttpStatusCode.OK_200, mode) + const attributes = { name: 'audio_with_preview', previewfile: 'preview.jpg', fixture: 'sample.ogg' } + await servers[1].videosCommand.upload({ attributes, mode }) await waitJobs(servers) for (const server of servers) { - const res = await getVideosList(server.url) + const { data } = await server.videosCommand.list() - const video = res.body.data.find(v => v.name === 'audio_with_preview') - const res2 = await getVideo(server.url, video.id) - const videoDetails: VideoDetails = res2.body + const video = data.find(v => v.name === 'audio_with_preview') + const videoDetails = await server.videosCommand.get({ id: video.id }) expect(videoDetails.files).to.have.lengthOf(1) @@ -409,17 +395,16 @@ describe('Test video transcoding', function () { it('Should upload an audio file and choose a default background image', async function () { this.timeout(60_000) - const videoAttributesArg = { name: 'audio_without_preview', fixture: 'sample.ogg' } - await uploadVideo(servers[1].url, servers[1].accessToken, videoAttributesArg, HttpStatusCode.OK_200, mode) + const attributes = { name: 'audio_without_preview', fixture: 'sample.ogg' } + await servers[1].videosCommand.upload({ attributes, mode }) await waitJobs(servers) for (const server of servers) { - const res = await getVideosList(server.url) + const { data } = await server.videosCommand.list() - const video = res.body.data.find(v => v.name === 'audio_without_preview') - const res2 = await getVideo(server.url, video.id) - const videoDetails = res2.body + const video = data.find(v => v.name === 'audio_without_preview') + const videoDetails = await server.videosCommand.get({ id: video.id }) expect(videoDetails.files).to.have.lengthOf(1) @@ -448,14 +433,13 @@ describe('Test video transcoding', function () { } }) - const videoAttributesArg = { name: 'audio_with_preview', previewfile: 'preview.jpg', fixture: 'sample.ogg' } - const resVideo = await uploadVideo(servers[1].url, servers[1].accessToken, videoAttributesArg, HttpStatusCode.OK_200, mode) + const attributes = { name: 'audio_with_preview', previewfile: 'preview.jpg', fixture: 'sample.ogg' } + const { id } = await servers[1].videosCommand.upload({ attributes, mode }) await waitJobs(servers) for (const server of servers) { - const res2 = await getVideo(server.url, resVideo.body.video.id) - const videoDetails: VideoDetails = res2.body + const videoDetails = await server.videosCommand.get({ id }) for (const files of [ videoDetails.files, videoDetails.streamingPlaylists[0].files ]) { expect(files).to.have.lengthOf(2) @@ -481,21 +465,20 @@ describe('Test video transcoding', function () { it('Should transcode a 60 FPS video', async function () { this.timeout(60_000) - const videoAttributes = { + const attributes = { name: 'my super 30fps name for server 2', description: 'my super 30fps description for server 2', fixture: '60fps_720p_small.mp4' } - await uploadVideo(servers[1].url, servers[1].accessToken, videoAttributes) + await servers[1].videosCommand.upload({ attributes }) await waitJobs(servers) for (const server of servers) { - const res = await getVideosList(server.url) + const { data } = await server.videosCommand.list() - const video = res.body.data.find(v => v.name === videoAttributes.name) - const res2 = await getVideo(server.url, video.id) - const videoDetails: VideoDetails = res2.body + const video = data.find(v => v.name === attributes.name) + const videoDetails = await server.videosCommand.get({ id: video.id }) expect(videoDetails.files).to.have.lengthOf(4) expect(videoDetails.files[0].fps).to.be.above(58).and.below(62) @@ -529,20 +512,20 @@ describe('Test video transcoding', function () { expect(fps).to.be.equal(59) } - const videoAttributes = { + const attributes = { name: '59fps video', description: '59fps video', fixture: tempFixturePath } - await uploadVideo(servers[1].url, servers[1].accessToken, videoAttributes) + await servers[1].videosCommand.upload({ attributes }) await waitJobs(servers) for (const server of servers) { - const res = await getVideosList(server.url) + const { data } = await server.videosCommand.list() - const video = res.body.data.find(v => v.name === videoAttributes.name) + const video = data.find(v => v.name === attributes.name) { const path = servers[1].serversCommand.buildDirectory(join('videos', video.uuid + '-240.mp4')) @@ -572,20 +555,20 @@ describe('Test video transcoding', function () { expect(bitrate).to.be.above(getMaxBitrate(VideoResolution.H_1080P, 25, VIDEO_TRANSCODING_FPS)) } - const videoAttributes = { + const attributes = { name: 'high bitrate video', description: 'high bitrate video', fixture: tempFixturePath } - await uploadVideo(servers[1].url, servers[1].accessToken, videoAttributes) + await servers[1].videosCommand.upload({ attributes }) await waitJobs(servers) for (const server of servers) { - const res = await getVideosList(server.url) + const { data } = await server.videosCommand.list() - const video = res.body.data.find(v => v.name === videoAttributes.name) + const video = data.find(v => v.name === attributes.name) for (const resolution of [ '240', '360', '480', '720', '1080' ]) { const path = servers[1].serversCommand.buildDirectory(join('videos', video.uuid + '-' + resolution + '.mp4')) @@ -621,19 +604,18 @@ describe('Test video transcoding', function () { } await servers[1].configCommand.updateCustomSubConfig({ newConfig }) - const videoAttributes = { + const attributes = { name: 'low bitrate', fixture: 'low-bitrate.mp4' } - const resUpload = await uploadVideo(servers[1].url, servers[1].accessToken, videoAttributes) - const videoUUID = resUpload.body.video.uuid + const { uuid } = await servers[1].videosCommand.upload({ attributes }) await waitJobs(servers) const resolutions = [ 240, 360, 480, 720, 1080 ] for (const r of resolutions) { - const path = `videos/${videoUUID}-${r}.mp4` + const path = `videos/${uuid}-${r}.mp4` const size = await servers[1].serversCommand.getServerFileSize(path) expect(size, `${path} not below ${60_000}`).to.be.below(60_000) } @@ -645,7 +627,7 @@ describe('Test video transcoding', function () { it('Should provide valid ffprobe data', async function () { this.timeout(160_000) - const videoUUID = (await uploadVideoAndGetId({ server: servers[1], videoName: 'ffprobe data' })).uuid + const videoUUID = (await servers[1].videosCommand.quickUpload({ name: 'ffprobe data' })).uuid await waitJobs(servers) { @@ -679,8 +661,7 @@ describe('Test video transcoding', function () { } for (const server of servers) { - const res2 = await getVideo(server.url, videoUUID) - const videoDetails: VideoDetails = res2.body + const videoDetails = await server.videosCommand.get({ id: videoUUID }) const videoFiles = videoDetails.files .concat(videoDetails.streamingPlaylists[0].files) @@ -692,8 +673,7 @@ describe('Test video transcoding', function () { expect(file.metadataUrl).to.contain(servers[1].url) expect(file.metadataUrl).to.contain(videoUUID) - const res3 = await getVideoFileMetadataUrl(file.metadataUrl) - const metadata: FfprobeData = res3.body + const metadata = await server.videosCommand.getFileMetadata({ url: file.metadataUrl }) expect(metadata).to.have.nested.property('format.size') } } diff --git a/server/tests/api/videos/videos-filter.ts b/server/tests/api/videos/videos-filter.ts index 4aa00cfc4..4a5a83ee6 100644 --- a/server/tests/api/videos/videos-filter.ts +++ b/server/tests/api/videos/videos-filter.ts @@ -1,21 +1,17 @@ /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */ import 'mocha' -import * as chai from 'chai' -import { HttpStatusCode } from '../../../../shared/core-utils/miscs/http-error-codes' +import { expect } from 'chai' +import { HttpStatusCode } from '@shared/core-utils' import { cleanupTests, doubleFollow, flushAndRunMultipleServers, makeGetRequest, ServerInfo, - setAccessTokensToServers, - uploadVideo -} from '../../../../shared/extra-utils' -import { UserRole } from '../../../../shared/models/users' -import { Video, VideoPrivacy } from '../../../../shared/models/videos' - -const expect = chai.expect + setAccessTokensToServers +} from '@shared/extra-utils' +import { UserRole, Video, VideoPrivacy } from '@shared/models' async function getVideosNames (server: ServerInfo, token: string, filter: string, statusCodeExpected = HttpStatusCode.OK_200) { const paths = [ @@ -62,16 +58,16 @@ describe('Test videos filter', function () { await server.usersCommand.create({ username: moderator.username, password: moderator.password, role: UserRole.MODERATOR }) server['moderatorAccessToken'] = await server.loginCommand.getAccessToken(moderator) - await uploadVideo(server.url, server.accessToken, { name: 'public ' + server.serverNumber }) + await server.videosCommand.upload({ attributes: { name: 'public ' + server.serverNumber } }) { const attributes = { name: 'unlisted ' + server.serverNumber, privacy: VideoPrivacy.UNLISTED } - await uploadVideo(server.url, server.accessToken, attributes) + await server.videosCommand.upload({ attributes }) } { const attributes = { name: 'private ' + server.serverNumber, privacy: VideoPrivacy.PRIVATE } - await uploadVideo(server.url, server.accessToken, attributes) + await server.videosCommand.upload({ attributes }) } } diff --git a/server/tests/api/videos/videos-history.ts b/server/tests/api/videos/videos-history.ts index aa0623f7d..8614078f1 100644 --- a/server/tests/api/videos/videos-history.ts +++ b/server/tests/api/videos/videos-history.ts @@ -6,17 +6,14 @@ import { HttpStatusCode } from '@shared/core-utils' import { cleanupTests, flushAndRunServer, - getVideosListWithToken, - getVideoWithToken, HistoryCommand, killallServers, reRunServer, ServerInfo, setAccessTokensToServers, - uploadVideo, wait } from '@shared/extra-utils' -import { Video, VideoDetails } from '@shared/models' +import { Video } from '@shared/models' const expect = chai.expect @@ -39,18 +36,18 @@ describe('Test videos history', function () { command = server.historyCommand { - const res = await uploadVideo(server.url, server.accessToken, { name: 'video 1' }) - video1UUID = res.body.video.uuid + const { uuid } = await server.videosCommand.upload({ attributes: { name: 'video 1' } }) + video1UUID = uuid } { - const res = await uploadVideo(server.url, server.accessToken, { name: 'video 2' }) - video2UUID = res.body.video.uuid + const { uuid } = await server.videosCommand.upload({ attributes: { name: 'video 2' } }) + video2UUID = uuid } { - const res = await uploadVideo(server.url, server.accessToken, { name: 'video 3' }) - video3UUID = res.body.video.uuid + const { uuid } = await server.videosCommand.upload({ attributes: { name: 'video 3' } }) + video3UUID = uuid } const user = { @@ -62,12 +59,10 @@ describe('Test videos history', function () { }) it('Should get videos, without watching history', async function () { - const res = await getVideosListWithToken(server.url, server.accessToken) - const videos: Video[] = res.body.data + const { data } = await server.videosCommand.listWithToken() - for (const video of videos) { - const resDetail = await getVideoWithToken(server.url, server.accessToken, video.id) - const videoDetails: VideoDetails = resDetail.body + for (const video of data) { + const videoDetails = await server.videosCommand.getWithToken({ id: video.id }) expect(video.userHistory).to.be.undefined expect(videoDetails.userHistory).to.be.undefined @@ -83,8 +78,8 @@ describe('Test videos history', function () { const videosOfVideos: Video[][] = [] { - const res = await getVideosListWithToken(server.url, server.accessToken) - videosOfVideos.push(res.body.data) + const { data } = await server.videosCommand.listWithToken() + videosOfVideos.push(data) } { @@ -107,24 +102,21 @@ describe('Test videos history', function () { } { - const resDetail = await getVideoWithToken(server.url, server.accessToken, video1UUID) - const videoDetails: VideoDetails = resDetail.body + const videoDetails = await server.videosCommand.getWithToken({ id: video1UUID }) expect(videoDetails.userHistory).to.not.be.undefined expect(videoDetails.userHistory.currentTime).to.equal(3) } { - const resDetail = await getVideoWithToken(server.url, server.accessToken, video2UUID) - const videoDetails: VideoDetails = resDetail.body + const videoDetails = await server.videosCommand.getWithToken({ id: video2UUID }) expect(videoDetails.userHistory).to.not.be.undefined expect(videoDetails.userHistory.currentTime).to.equal(8) } { - const resDetail = await getVideoWithToken(server.url, server.accessToken, video3UUID) - const videoDetails: VideoDetails = resDetail.body + const videoDetails = await server.videosCommand.getWithToken({ id: video3UUID }) expect(videoDetails.userHistory).to.be.undefined } diff --git a/server/tests/api/videos/videos-overview.ts b/server/tests/api/videos/videos-overview.ts index a2da2eaef..969393842 100644 --- a/server/tests/api/videos/videos-overview.ts +++ b/server/tests/api/videos/videos-overview.ts @@ -2,7 +2,7 @@ import 'mocha' import * as chai from 'chai' -import { cleanupTests, flushAndRunServer, ServerInfo, setAccessTokensToServers, uploadVideo, wait } from '@shared/extra-utils' +import { cleanupTests, flushAndRunServer, ServerInfo, setAccessTokensToServers, wait } from '@shared/extra-utils' import { VideosOverview } from '@shared/models' const expect = chai.expect @@ -35,10 +35,12 @@ describe('Test a videos overview', function () { await wait(3000) - await uploadVideo(server.url, server.accessToken, { - name: 'video 0', - category: 3, - tags: [ 'coucou1', 'coucou2' ] + await server.videosCommand.upload({ + attributes: { + name: 'video 0', + category: 3, + tags: [ 'coucou1', 'coucou2' ] + } }) const body = await server.overviewsCommand.getVideos({ page: 1 }) @@ -51,10 +53,12 @@ describe('Test a videos overview', function () { { for (let i = 1; i < 6; i++) { - await uploadVideo(server.url, server.accessToken, { - name: 'video ' + i, - category: 3, - tags: [ 'coucou1', 'coucou2' ] + await server.videosCommand.upload({ + attributes: { + name: 'video ' + i, + category: 3, + tags: [ 'coucou1', 'coucou2' ] + } }) } diff --git a/server/tests/api/videos/videos-views-cleaner.ts b/server/tests/api/videos/videos-views-cleaner.ts index b6cde6b50..7ded1bf38 100644 --- a/server/tests/api/videos/videos-views-cleaner.ts +++ b/server/tests/api/videos/videos-views-cleaner.ts @@ -10,8 +10,6 @@ import { reRunServer, ServerInfo, setAccessTokensToServers, - uploadVideoAndGetId, - viewVideo, wait, waitJobs } from '../../../../shared/extra-utils' @@ -32,15 +30,15 @@ describe('Test video views cleaner', function () { await doubleFollow(servers[0], servers[1]) - videoIdServer1 = (await uploadVideoAndGetId({ server: servers[0], videoName: 'video server 1' })).uuid - videoIdServer2 = (await uploadVideoAndGetId({ server: servers[1], videoName: 'video server 2' })).uuid + videoIdServer1 = (await servers[0].videosCommand.quickUpload({ name: 'video server 1' })).uuid + videoIdServer2 = (await servers[1].videosCommand.quickUpload({ name: 'video server 2' })).uuid await waitJobs(servers) - await viewVideo(servers[0].url, videoIdServer1) - await viewVideo(servers[1].url, videoIdServer1) - await viewVideo(servers[0].url, videoIdServer2) - await viewVideo(servers[1].url, videoIdServer2) + await servers[0].videosCommand.view({ id: videoIdServer1 }) + await servers[1].videosCommand.view({ id: videoIdServer1 }) + await servers[0].videosCommand.view({ id: videoIdServer2 }) + await servers[1].videosCommand.view({ id: videoIdServer2 }) await waitJobs(servers) }) -- 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/activitypub/cleaner.ts | 52 ++-- server/tests/api/activitypub/client.ts | 6 +- server/tests/api/activitypub/fetch.ts | 18 +- server/tests/api/activitypub/refresher.ts | 52 ++-- server/tests/api/activitypub/security.ts | 8 +- 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 +-- server/tests/api/live/live-constraints.ts | 24 +- server/tests/api/live/live-permanent.ts | 32 +-- server/tests/api/live/live-save-replay.ts | 52 ++-- server/tests/api/live/live-socket-messages.ts | 38 +-- server/tests/api/live/live-views.ts | 20 +- server/tests/api/live/live.ts | 72 +++--- server/tests/api/moderation/abuses.ts | 96 ++++---- .../tests/api/moderation/blocklist-notification.ts | 46 ++-- server/tests/api/moderation/blocklist.ts | 76 +++--- server/tests/api/moderation/video-blacklist.ts | 58 ++--- .../tests/api/notifications/admin-notifications.ts | 12 +- .../api/notifications/comments-notifications.ts | 92 ++++---- .../api/notifications/moderation-notifications.ts | 118 +++++----- .../tests/api/notifications/notifications-api.ts | 42 ++-- .../tests/api/notifications/user-notifications.ts | 40 ++-- server/tests/api/redundancy/manage-redundancy.ts | 14 +- .../tests/api/redundancy/redundancy-constraints.ts | 24 +- server/tests/api/redundancy/redundancy.ts | 62 ++--- .../search/search-activitypub-video-channels.ts | 32 +-- .../search/search-activitypub-video-playlists.ts | 28 +-- .../tests/api/search/search-activitypub-videos.ts | 14 +- server/tests/api/search/search-channels.ts | 6 +- server/tests/api/search/search-index.ts | 14 +- server/tests/api/search/search-playlists.ts | 20 +- server/tests/api/search/search-videos.ts | 46 ++-- server/tests/api/server/auto-follows.ts | 20 +- server/tests/api/server/bulk.ts | 48 ++-- server/tests/api/server/config.ts | 36 +-- server/tests/api/server/contact-form.ts | 2 +- server/tests/api/server/email.ts | 42 ++-- server/tests/api/server/follow-constraints.ts | 58 ++--- server/tests/api/server/follows-moderation.ts | 18 +- server/tests/api/server/follows.ts | 72 +++--- server/tests/api/server/handle-down.ts | 58 ++--- server/tests/api/server/homepage.ts | 4 +- server/tests/api/server/jobs.ts | 12 +- server/tests/api/server/logs.ts | 28 +-- server/tests/api/server/plugins.ts | 20 +- server/tests/api/server/reverse-proxy.ts | 42 ++-- server/tests/api/server/services.ts | 22 +- server/tests/api/server/stats.ts | 60 ++--- server/tests/api/server/tracker.ts | 4 +- server/tests/api/users/user-subscriptions.ts | 34 +-- server/tests/api/users/users-multiple-servers.ts | 40 ++-- server/tests/api/users/users-verification.ts | 34 +-- server/tests/api/users/users.ts | 262 ++++++++++----------- server/tests/api/videos/audio-only.ts | 8 +- server/tests/api/videos/multiple-servers.ts | 168 ++++++------- server/tests/api/videos/resumable-upload.ts | 18 +- server/tests/api/videos/single-server.ts | 90 +++---- server/tests/api/videos/video-captions.ts | 24 +- server/tests/api/videos/video-change-ownership.ts | 50 ++-- server/tests/api/videos/video-channels.ts | 92 ++++---- server/tests/api/videos/video-comments.ts | 8 +- server/tests/api/videos/video-description.ts | 16 +- server/tests/api/videos/video-hls.ts | 22 +- server/tests/api/videos/video-imports.ts | 44 ++-- server/tests/api/videos/video-nsfw.ts | 52 ++-- .../tests/api/videos/video-playlist-thumbnails.ts | 36 +-- server/tests/api/videos/video-playlists.ts | 184 +++++++-------- server/tests/api/videos/video-privacy.ts | 56 ++--- server/tests/api/videos/video-schedule-update.ts | 20 +- server/tests/api/videos/video-transcoder.ts | 122 +++++----- server/tests/api/videos/videos-filter.ts | 10 +- server/tests/api/videos/videos-history.ts | 30 +-- server/tests/api/videos/videos-overview.ts | 24 +- server/tests/api/videos/videos-views-cleaner.ts | 22 +- 101 files changed, 1823 insertions(+), 1823 deletions(-) (limited to 'server/tests/api') diff --git a/server/tests/api/activitypub/cleaner.ts b/server/tests/api/activitypub/cleaner.ts index dcf758711..1421824da 100644 --- a/server/tests/api/activitypub/cleaner.ts +++ b/server/tests/api/activitypub/cleaner.ts @@ -46,9 +46,9 @@ describe('Test AP cleaner', function () { // Create 1 comment per video // Update 1 remote URL and 1 local URL on - videoUUID1 = (await servers[0].videosCommand.quickUpload({ name: 'server 1' })).uuid - videoUUID2 = (await servers[1].videosCommand.quickUpload({ name: 'server 2' })).uuid - videoUUID3 = (await servers[2].videosCommand.quickUpload({ name: 'server 3' })).uuid + videoUUID1 = (await servers[0].videos.quickUpload({ name: 'server 1' })).uuid + videoUUID2 = (await servers[1].videos.quickUpload({ name: 'server 2' })).uuid + videoUUID3 = (await servers[2].videos.quickUpload({ name: 'server 3' })).uuid videoUUIDs = [ videoUUID1, videoUUID2, videoUUID3 ] @@ -56,8 +56,8 @@ describe('Test AP cleaner', function () { for (const server of servers) { for (const uuid of videoUUIDs) { - await server.videosCommand.rate({ id: uuid, rating: 'like' }) - await server.commentsCommand.createThread({ videoId: uuid, text: 'comment' }) + await server.videos.rate({ id: uuid, rating: 'like' }) + await server.comments.createThread({ videoId: uuid, text: 'comment' }) } } @@ -67,7 +67,7 @@ describe('Test AP cleaner', function () { it('Should have the correct likes', async function () { for (const server of servers) { for (const uuid of videoUUIDs) { - const video = await server.videosCommand.get({ id: uuid }) + const video = await server.videos.get({ id: uuid }) expect(video.likes).to.equal(3) expect(video.dislikes).to.equal(0) @@ -78,9 +78,9 @@ describe('Test AP cleaner', function () { it('Should destroy server 3 internal likes and correctly clean them', async function () { this.timeout(20000) - await servers[2].sqlCommand.deleteAll('accountVideoRate') + await servers[2].sql.deleteAll('accountVideoRate') for (const uuid of videoUUIDs) { - await servers[2].sqlCommand.setVideoField(uuid, 'likes', '0') + await servers[2].sql.setVideoField(uuid, 'likes', '0') } await wait(5000) @@ -88,14 +88,14 @@ describe('Test AP cleaner', function () { // Updated rates of my video { - const video = await servers[0].videosCommand.get({ id: videoUUID1 }) + const video = await servers[0].videos.get({ id: videoUUID1 }) expect(video.likes).to.equal(2) expect(video.dislikes).to.equal(0) } // Did not update rates of a remote video { - const video = await servers[0].videosCommand.get({ id: videoUUID2 }) + const video = await servers[0].videos.get({ id: videoUUID2 }) expect(video.likes).to.equal(3) expect(video.dislikes).to.equal(0) } @@ -106,7 +106,7 @@ describe('Test AP cleaner', function () { for (const server of servers) { for (const uuid of videoUUIDs) { - await server.videosCommand.rate({ id: uuid, rating: 'dislike' }) + await server.videos.rate({ id: uuid, rating: 'dislike' }) } } @@ -114,7 +114,7 @@ describe('Test AP cleaner', function () { for (const server of servers) { for (const uuid of videoUUIDs) { - const video = await server.videosCommand.get({ id: uuid }) + const video = await server.videos.get({ id: uuid }) expect(video.likes).to.equal(0) expect(video.dislikes).to.equal(3) } @@ -124,10 +124,10 @@ describe('Test AP cleaner', function () { it('Should destroy server 3 internal dislikes and correctly clean them', async function () { this.timeout(20000) - await servers[2].sqlCommand.deleteAll('accountVideoRate') + await servers[2].sql.deleteAll('accountVideoRate') for (const uuid of videoUUIDs) { - await servers[2].sqlCommand.setVideoField(uuid, 'dislikes', '0') + await servers[2].sql.setVideoField(uuid, 'dislikes', '0') } await wait(5000) @@ -135,14 +135,14 @@ describe('Test AP cleaner', function () { // Updated rates of my video { - const video = await servers[0].videosCommand.get({ id: videoUUID1 }) + const video = await servers[0].videos.get({ id: videoUUID1 }) expect(video.likes).to.equal(0) expect(video.dislikes).to.equal(2) } // Did not update rates of a remote video { - const video = await servers[0].videosCommand.get({ id: videoUUID2 }) + const video = await servers[0].videos.get({ id: videoUUID2 }) expect(video.likes).to.equal(0) expect(video.dislikes).to.equal(3) } @@ -151,15 +151,15 @@ describe('Test AP cleaner', function () { it('Should destroy server 3 internal shares and correctly clean them', async function () { this.timeout(20000) - const preCount = await servers[0].sqlCommand.getCount('videoShare') + const preCount = await servers[0].sql.getCount('videoShare') expect(preCount).to.equal(6) - await servers[2].sqlCommand.deleteAll('videoShare') + await servers[2].sql.deleteAll('videoShare') await wait(5000) await waitJobs(servers) // Still 6 because we don't have remote shares on local videos - const postCount = await servers[0].sqlCommand.getCount('videoShare') + const postCount = await servers[0].sql.getCount('videoShare') expect(postCount).to.equal(6) }) @@ -167,17 +167,17 @@ describe('Test AP cleaner', function () { this.timeout(20000) { - const { total } = await servers[0].commentsCommand.listThreads({ videoId: videoUUID1 }) + const { total } = await servers[0].comments.listThreads({ videoId: videoUUID1 }) expect(total).to.equal(3) } - await servers[2].sqlCommand.deleteAll('videoComment') + await servers[2].sql.deleteAll('videoComment') await wait(5000) await waitJobs(servers) { - const { total } = await servers[0].commentsCommand.listThreads({ videoId: videoUUID1 }) + const { total } = await servers[0].comments.listThreads({ videoId: videoUUID1 }) expect(total).to.equal(2) } }) @@ -188,7 +188,7 @@ describe('Test AP cleaner', function () { async function check (like: string, ofServerUrl: string, urlSuffix: string, remote: 'true' | 'false') { const query = `SELECT "videoId", "accountVideoRate".url FROM "accountVideoRate" ` + `INNER JOIN video ON "accountVideoRate"."videoId" = video.id AND remote IS ${remote} WHERE "accountVideoRate"."url" LIKE '${like}'` - const res = await servers[0].sqlCommand.selectQuery(query) + const res = await servers[0].sql.selectQuery(query) for (const rate of res) { const matcher = new RegExp(`^${ofServerUrl}/accounts/root/dislikes/\\d+${urlSuffix}$`) @@ -217,7 +217,7 @@ describe('Test AP cleaner', function () { { const query = `UPDATE "accountVideoRate" SET url = url || 'stan'` - await servers[1].sqlCommand.updateQuery(query) + await servers[1].sql.updateQuery(query) await wait(5000) await waitJobs(servers) @@ -234,7 +234,7 @@ describe('Test AP cleaner', function () { const query = `SELECT "videoId", "videoComment".url, uuid as "videoUUID" FROM "videoComment" ` + `INNER JOIN video ON "videoComment"."videoId" = video.id AND remote IS ${remote} WHERE "videoComment"."url" LIKE '${like}'` - const res = await servers[0].sqlCommand.selectQuery(query) + const res = await servers[0].sql.selectQuery(query) for (const comment of res) { const matcher = new RegExp(`${ofServerUrl}/videos/watch/${comment.videoUUID}/comments/\\d+${urlSuffix}`) @@ -260,7 +260,7 @@ describe('Test AP cleaner', function () { { const query = `UPDATE "videoComment" SET url = url || 'kyle'` - await servers[1].sqlCommand.updateQuery(query) + await servers[1].sql.updateQuery(query) await wait(5000) await waitJobs(servers) diff --git a/server/tests/api/activitypub/client.ts b/server/tests/api/activitypub/client.ts index 0190df04c..5845045a3 100644 --- a/server/tests/api/activitypub/client.ts +++ b/server/tests/api/activitypub/client.ts @@ -68,12 +68,12 @@ describe('Test activitypub', function () { await setDefaultVideoChannel(servers) { - video = await await servers[0].videosCommand.quickUpload({ name: 'video' }) + video = await await servers[0].videos.quickUpload({ name: 'video' }) } { - const attributes = { displayName: 'playlist', privacy: VideoPlaylistPrivacy.PUBLIC, videoChannelId: servers[0].videoChannel.id } - playlist = await servers[0].playlistsCommand.create({ attributes }) + const attributes = { displayName: 'playlist', privacy: VideoPlaylistPrivacy.PUBLIC, videoChannelId: servers[0].store.channel.id } + playlist = await servers[0].playlists.create({ attributes }) } await doubleFollow(servers[0], servers[1]) diff --git a/server/tests/api/activitypub/fetch.ts b/server/tests/api/activitypub/fetch.ts index 5ab4a85d7..34694a773 100644 --- a/server/tests/api/activitypub/fetch.ts +++ b/server/tests/api/activitypub/fetch.ts @@ -21,24 +21,24 @@ describe('Test ActivityPub fetcher', function () { const user = { username: 'user1', password: 'password' } for (const server of servers) { - await server.usersCommand.create({ username: user.username, password: user.password }) + await server.users.create({ username: user.username, password: user.password }) } - const userAccessToken = await servers[0].loginCommand.getAccessToken(user) + const userAccessToken = await servers[0].login.getAccessToken(user) - await servers[0].videosCommand.upload({ attributes: { name: 'video root' } }) - const { uuid } = await servers[0].videosCommand.upload({ attributes: { name: 'bad video root' } }) - await servers[0].videosCommand.upload({ token: userAccessToken, attributes: { name: 'video user' } }) + await servers[0].videos.upload({ attributes: { name: 'video root' } }) + const { uuid } = await servers[0].videos.upload({ attributes: { name: 'bad video root' } }) + await servers[0].videos.upload({ token: userAccessToken, attributes: { name: 'video user' } }) { const to = 'http://localhost:' + servers[0].port + '/accounts/user1' const value = 'http://localhost:' + servers[1].port + '/accounts/user1' - await servers[0].sqlCommand.setActorField(to, 'url', value) + await servers[0].sql.setActorField(to, 'url', value) } { const value = 'http://localhost:' + servers[2].port + '/videos/watch/' + uuid - await servers[0].sqlCommand.setVideoField(uuid, 'url', value) + await servers[0].sql.setVideoField(uuid, 'url', value) } }) @@ -49,7 +49,7 @@ describe('Test ActivityPub fetcher', function () { await waitJobs(servers) { - const { total, data } = await servers[0].videosCommand.list({ sort: 'createdAt' }) + const { total, data } = await servers[0].videos.list({ sort: 'createdAt' }) expect(total).to.equal(3) expect(data[0].name).to.equal('video root') @@ -58,7 +58,7 @@ describe('Test ActivityPub fetcher', function () { } { - const { total, data } = await servers[1].videosCommand.list({ sort: 'createdAt' }) + const { total, data } = await servers[1].videos.list({ sort: 'createdAt' }) expect(total).to.equal(1) expect(data[0].name).to.equal('video root') diff --git a/server/tests/api/activitypub/refresher.ts b/server/tests/api/activitypub/refresher.ts index 5af4b1edb..d2f71e857 100644 --- a/server/tests/api/activitypub/refresher.ts +++ b/server/tests/api/activitypub/refresher.ts @@ -34,28 +34,28 @@ describe('Test AP refresher', function () { await setDefaultVideoChannel(servers) { - videoUUID1 = (await servers[1].videosCommand.quickUpload({ name: 'video1' })).uuid - videoUUID2 = (await servers[1].videosCommand.quickUpload({ name: 'video2' })).uuid - videoUUID3 = (await servers[1].videosCommand.quickUpload({ name: 'video3' })).uuid + videoUUID1 = (await servers[1].videos.quickUpload({ name: 'video1' })).uuid + videoUUID2 = (await servers[1].videos.quickUpload({ name: 'video2' })).uuid + videoUUID3 = (await servers[1].videos.quickUpload({ name: 'video3' })).uuid } { - const token1 = await servers[1].usersCommand.generateUserAndToken('user1') - await servers[1].videosCommand.upload({ token: token1, attributes: { name: 'video4' } }) + const token1 = await servers[1].users.generateUserAndToken('user1') + await servers[1].videos.upload({ token: token1, attributes: { name: 'video4' } }) - const token2 = await servers[1].usersCommand.generateUserAndToken('user2') - await servers[1].videosCommand.upload({ token: token2, attributes: { name: 'video5' } }) + const token2 = await servers[1].users.generateUserAndToken('user2') + await servers[1].videos.upload({ token: token2, attributes: { name: 'video5' } }) } { - const attributes = { displayName: 'playlist1', privacy: VideoPlaylistPrivacy.PUBLIC, videoChannelId: servers[1].videoChannel.id } - const created = await servers[1].playlistsCommand.create({ attributes }) + const attributes = { displayName: 'playlist1', privacy: VideoPlaylistPrivacy.PUBLIC, videoChannelId: servers[1].store.channel.id } + const created = await servers[1].playlists.create({ attributes }) playlistUUID1 = created.uuid } { - const attributes = { displayName: 'playlist2', privacy: VideoPlaylistPrivacy.PUBLIC, videoChannelId: servers[1].videoChannel.id } - const created = await servers[1].playlistsCommand.create({ attributes }) + const attributes = { displayName: 'playlist2', privacy: VideoPlaylistPrivacy.PUBLIC, videoChannelId: servers[1].store.channel.id } + const created = await servers[1].playlists.create({ attributes }) playlistUUID2 = created.uuid } @@ -70,15 +70,15 @@ describe('Test AP refresher', function () { await wait(10000) // Change UUID so the remote server returns a 404 - await servers[1].sqlCommand.setVideoField(videoUUID1, 'uuid', '304afe4f-39f9-4d49-8ed7-ac57b86b174f') + await servers[1].sql.setVideoField(videoUUID1, 'uuid', '304afe4f-39f9-4d49-8ed7-ac57b86b174f') - await servers[0].videosCommand.get({ id: videoUUID1 }) - await servers[0].videosCommand.get({ id: videoUUID2 }) + await servers[0].videos.get({ id: videoUUID1 }) + await servers[0].videos.get({ id: videoUUID2 }) await waitJobs(servers) - await servers[0].videosCommand.get({ id: videoUUID1, expectedStatus: HttpStatusCode.NOT_FOUND_404 }) - await servers[0].videosCommand.get({ id: videoUUID2 }) + await servers[0].videos.get({ id: videoUUID1, expectedStatus: HttpStatusCode.NOT_FOUND_404 }) + await servers[0].videos.get({ id: videoUUID2 }) }) it('Should not update a remote video if the remote instance is down', async function () { @@ -86,18 +86,18 @@ describe('Test AP refresher', function () { await killallServers([ servers[1] ]) - await servers[1].sqlCommand.setVideoField(videoUUID3, 'uuid', '304afe4f-39f9-4d49-8ed7-ac57b86b174e') + await servers[1].sql.setVideoField(videoUUID3, 'uuid', '304afe4f-39f9-4d49-8ed7-ac57b86b174e') // Video will need a refresh await wait(10000) - await servers[0].videosCommand.get({ id: videoUUID3 }) + await servers[0].videos.get({ id: videoUUID3 }) // The refresh should fail await waitJobs([ servers[0] ]) await reRunServer(servers[1]) - await servers[0].videosCommand.get({ id: videoUUID3 }) + await servers[0].videos.get({ id: videoUUID3 }) }) }) @@ -106,13 +106,13 @@ describe('Test AP refresher', function () { it('Should remove a deleted actor', async function () { this.timeout(60000) - const command = servers[0].accountsCommand + const command = servers[0].accounts await wait(10000) // Change actor name so the remote server returns a 404 const to = 'http://localhost:' + servers[1].port + '/accounts/user2' - await servers[1].sqlCommand.setActorField(to, 'preferredUsername', 'toto') + await servers[1].sql.setActorField(to, 'preferredUsername', 'toto') await command.get({ accountName: 'user1@localhost:' + servers[1].port }) await command.get({ accountName: 'user2@localhost:' + servers[1].port }) @@ -132,15 +132,15 @@ describe('Test AP refresher', function () { await wait(10000) // Change UUID so the remote server returns a 404 - await servers[1].sqlCommand.setPlaylistField(playlistUUID2, 'uuid', '304afe4f-39f9-4d49-8ed7-ac57b86b178e') + await servers[1].sql.setPlaylistField(playlistUUID2, 'uuid', '304afe4f-39f9-4d49-8ed7-ac57b86b178e') - await servers[0].playlistsCommand.get({ playlistId: playlistUUID1 }) - await servers[0].playlistsCommand.get({ playlistId: playlistUUID2 }) + await servers[0].playlists.get({ playlistId: playlistUUID1 }) + await servers[0].playlists.get({ playlistId: playlistUUID2 }) await waitJobs(servers) - await servers[0].playlistsCommand.get({ playlistId: playlistUUID1, expectedStatus: HttpStatusCode.OK_200 }) - await servers[0].playlistsCommand.get({ playlistId: playlistUUID2, expectedStatus: HttpStatusCode.NOT_FOUND_404 }) + await servers[0].playlists.get({ playlistId: playlistUUID1, expectedStatus: HttpStatusCode.OK_200 }) + await servers[0].playlists.get({ playlistId: playlistUUID2, expectedStatus: HttpStatusCode.NOT_FOUND_404 }) }) }) diff --git a/server/tests/api/activitypub/security.ts b/server/tests/api/activitypub/security.ts index c32940070..ab0eb256e 100644 --- a/server/tests/api/activitypub/security.ts +++ b/server/tests/api/activitypub/security.ts @@ -24,8 +24,8 @@ function setKeysOfServer (onServer: ServerInfo, ofServer: ServerInfo, publicKey: const url = 'http://localhost:' + ofServer.port + '/accounts/peertube' return Promise.all([ - onServer.sqlCommand.setActorField(url, 'publicKey', publicKey), - onServer.sqlCommand.setActorField(url, 'privateKey', privateKey) + onServer.sql.setActorField(url, 'publicKey', publicKey), + onServer.sql.setActorField(url, 'privateKey', privateKey) ]) } @@ -33,8 +33,8 @@ function setUpdatedAtOfServer (onServer: ServerInfo, ofServer: ServerInfo, updat const url = 'http://localhost:' + ofServer.port + '/accounts/peertube' return Promise.all([ - onServer.sqlCommand.setActorField(url, 'createdAt', updatedAt), - onServer.sqlCommand.setActorField(url, 'updatedAt', updatedAt) + onServer.sql.setActorField(url, 'createdAt', updatedAt), + onServer.sql.setActorField(url, 'updatedAt', updatedAt) ]) } 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 }) }) }) diff --git a/server/tests/api/live/live-constraints.ts b/server/tests/api/live/live-constraints.ts index 7900b1abe..1c380883c 100644 --- a/server/tests/api/live/live-constraints.ts +++ b/server/tests/api/live/live-constraints.ts @@ -32,13 +32,13 @@ describe('Test live constraints', function () { saveReplay } - const { uuid } = await servers[0].liveCommand.create({ token: userAccessToken, fields: liveAttributes }) + const { uuid } = await servers[0].live.create({ token: userAccessToken, fields: liveAttributes }) return uuid } async function checkSaveReplay (videoId: string, resolutions = [ 720 ]) { for (const server of servers) { - const video = await server.videosCommand.get({ id: videoId }) + const video = await server.videos.get({ id: videoId }) expect(video.isLive).to.be.false expect(video.duration).to.be.greaterThan(0) } @@ -48,12 +48,12 @@ describe('Test live constraints', function () { async function waitUntilLivePublishedOnAllServers (videoId: string) { for (const server of servers) { - await server.liveCommand.waitUntilPublished({ videoId }) + await server.live.waitUntilPublished({ videoId }) } } function updateQuota (options: { total: number, daily: number }) { - return servers[0].usersCommand.update({ + return servers[0].users.update({ userId, videoQuota: options.total, videoQuotaDaily: options.daily @@ -69,7 +69,7 @@ describe('Test live constraints', function () { await setAccessTokensToServers(servers) await setDefaultVideoChannel(servers) - await servers[0].configCommand.updateCustomSubConfig({ + await servers[0].config.updateCustomSubConfig({ newConfig: { live: { enabled: true, @@ -82,7 +82,7 @@ describe('Test live constraints', function () { }) { - const res = await servers[0].usersCommand.generate('user1') + const res = await servers[0].users.generate('user1') userId = res.userId userChannelId = res.userChannelId userAccessToken = res.token @@ -98,7 +98,7 @@ describe('Test live constraints', function () { this.timeout(60000) const userVideoLiveoId = await createLiveWrapper(false) - await servers[0].liveCommand.runAndTestStreamError({ token: userAccessToken, videoId: userVideoLiveoId, shouldHaveError: false }) + await servers[0].live.runAndTestStreamError({ token: userAccessToken, videoId: userVideoLiveoId, shouldHaveError: false }) }) it('Should have size limit depending on user global quota if save replay is enabled', async function () { @@ -108,7 +108,7 @@ describe('Test live constraints', function () { await wait(5000) const userVideoLiveoId = await createLiveWrapper(true) - await servers[0].liveCommand.runAndTestStreamError({ token: userAccessToken, videoId: userVideoLiveoId, shouldHaveError: true }) + await servers[0].live.runAndTestStreamError({ token: userAccessToken, videoId: userVideoLiveoId, shouldHaveError: true }) await waitUntilLivePublishedOnAllServers(userVideoLiveoId) await waitJobs(servers) @@ -125,7 +125,7 @@ describe('Test live constraints', function () { await updateQuota({ total: -1, daily: 1 }) const userVideoLiveoId = await createLiveWrapper(true) - await servers[0].liveCommand.runAndTestStreamError({ token: userAccessToken, videoId: userVideoLiveoId, shouldHaveError: true }) + await servers[0].live.runAndTestStreamError({ token: userAccessToken, videoId: userVideoLiveoId, shouldHaveError: true }) await waitUntilLivePublishedOnAllServers(userVideoLiveoId) await waitJobs(servers) @@ -142,13 +142,13 @@ describe('Test live constraints', function () { await updateQuota({ total: 10 * 1000 * 1000, daily: -1 }) const userVideoLiveoId = await createLiveWrapper(true) - await servers[0].liveCommand.runAndTestStreamError({ token: userAccessToken, videoId: userVideoLiveoId, shouldHaveError: false }) + await servers[0].live.runAndTestStreamError({ token: userAccessToken, videoId: userVideoLiveoId, shouldHaveError: false }) }) it('Should have max duration limit', async function () { this.timeout(60000) - await servers[0].configCommand.updateCustomSubConfig({ + await servers[0].config.updateCustomSubConfig({ newConfig: { live: { enabled: true, @@ -163,7 +163,7 @@ describe('Test live constraints', function () { }) const userVideoLiveoId = await createLiveWrapper(true) - await servers[0].liveCommand.runAndTestStreamError({ token: userAccessToken, videoId: userVideoLiveoId, shouldHaveError: true }) + await servers[0].live.runAndTestStreamError({ token: userAccessToken, videoId: userVideoLiveoId, shouldHaveError: true }) await waitUntilLivePublishedOnAllServers(userVideoLiveoId) await waitJobs(servers) diff --git a/server/tests/api/live/live-permanent.ts b/server/tests/api/live/live-permanent.ts index 707f2edf8..900bd6f5c 100644 --- a/server/tests/api/live/live-permanent.ts +++ b/server/tests/api/live/live-permanent.ts @@ -24,20 +24,20 @@ describe('Permanent live', function () { async function createLiveWrapper (permanentLive: boolean) { const attributes: LiveVideoCreate = { - channelId: servers[0].videoChannel.id, + channelId: servers[0].store.channel.id, privacy: VideoPrivacy.PUBLIC, name: 'my super live', saveReplay: false, permanentLive } - const { uuid } = await servers[0].liveCommand.create({ fields: attributes }) + const { uuid } = await servers[0].live.create({ fields: attributes }) return uuid } async function checkVideoState (videoId: string, state: VideoState) { for (const server of servers) { - const video = await server.videosCommand.get({ id: videoId }) + const video = await server.videos.get({ id: videoId }) expect(video.state.id).to.equal(state) } } @@ -54,7 +54,7 @@ describe('Permanent live', function () { // Server 1 and server 2 follow each other await doubleFollow(servers[0], servers[1]) - await servers[0].configCommand.updateCustomSubConfig({ + await servers[0].config.updateCustomSubConfig({ newConfig: { live: { enabled: true, @@ -75,14 +75,14 @@ describe('Permanent live', function () { const videoUUID = await createLiveWrapper(false) { - const live = await servers[0].liveCommand.get({ videoId: videoUUID }) + const live = await servers[0].live.get({ videoId: videoUUID }) expect(live.permanentLive).to.be.false } - await servers[0].liveCommand.update({ videoId: videoUUID, fields: { permanentLive: true } }) + await servers[0].live.update({ videoId: videoUUID, fields: { permanentLive: true } }) { - const live = await servers[0].liveCommand.get({ videoId: videoUUID }) + const live = await servers[0].live.get({ videoId: videoUUID }) expect(live.permanentLive).to.be.true } }) @@ -92,7 +92,7 @@ describe('Permanent live', function () { videoUUID = await createLiveWrapper(true) - const live = await servers[0].liveCommand.get({ videoId: videoUUID }) + const live = await servers[0].live.get({ videoId: videoUUID }) expect(live.permanentLive).to.be.true await waitJobs(servers) @@ -101,16 +101,16 @@ describe('Permanent live', function () { it('Should stream into this permanent live', async function () { this.timeout(120000) - const ffmpegCommand = await servers[0].liveCommand.sendRTMPStreamInVideo({ videoId: videoUUID }) + const ffmpegCommand = await servers[0].live.sendRTMPStreamInVideo({ videoId: videoUUID }) for (const server of servers) { - await server.liveCommand.waitUntilPublished({ videoId: videoUUID }) + await server.live.waitUntilPublished({ videoId: videoUUID }) } await checkVideoState(videoUUID, VideoState.PUBLISHED) await stopFfmpeg(ffmpegCommand) - await servers[0].liveCommand.waitUntilWaiting({ videoId: videoUUID }) + await servers[0].live.waitUntilWaiting({ videoId: videoUUID }) await waitJobs(servers) }) @@ -122,7 +122,7 @@ describe('Permanent live', function () { await waitJobs(servers) for (const server of servers) { - const videoDetails = await server.videosCommand.get({ id: videoUUID }) + const videoDetails = await server.videos.get({ id: videoUUID }) expect(videoDetails.streamingPlaylists).to.have.lengthOf(1) } }) @@ -136,7 +136,7 @@ describe('Permanent live', function () { it('Should be able to stream again in the permanent live', async function () { this.timeout(20000) - await servers[0].configCommand.updateCustomSubConfig({ + await servers[0].config.updateCustomSubConfig({ newConfig: { live: { enabled: true, @@ -150,15 +150,15 @@ describe('Permanent live', function () { } }) - const ffmpegCommand = await servers[0].liveCommand.sendRTMPStreamInVideo({ videoId: videoUUID }) + const ffmpegCommand = await servers[0].live.sendRTMPStreamInVideo({ videoId: videoUUID }) for (const server of servers) { - await server.liveCommand.waitUntilPublished({ videoId: videoUUID }) + await server.live.waitUntilPublished({ videoId: videoUUID }) } await checkVideoState(videoUUID, VideoState.PUBLISHED) - const count = await servers[0].liveCommand.countPlaylists({ videoUUID }) + const count = await servers[0].live.countPlaylists({ videoUUID }) // master playlist and 720p playlist expect(count).to.equal(2) diff --git a/server/tests/api/live/live-save-replay.ts b/server/tests/api/live/live-save-replay.ts index a87a2cd12..7a33df90a 100644 --- a/server/tests/api/live/live-save-replay.ts +++ b/server/tests/api/live/live-save-replay.ts @@ -30,19 +30,19 @@ describe('Save replay setting', function () { async function createLiveWrapper (saveReplay: boolean) { if (liveVideoUUID) { try { - await servers[0].videosCommand.remove({ id: liveVideoUUID }) + await servers[0].videos.remove({ id: liveVideoUUID }) await waitJobs(servers) } catch {} } const attributes: LiveVideoCreate = { - channelId: servers[0].videoChannel.id, + channelId: servers[0].store.channel.id, privacy: VideoPrivacy.PUBLIC, name: 'my super live', saveReplay } - const { uuid } = await servers[0].liveCommand.create({ fields: attributes }) + const { uuid } = await servers[0].live.create({ fields: attributes }) return uuid } @@ -50,32 +50,32 @@ describe('Save replay setting', function () { for (const server of servers) { const length = existsInList ? 1 : 0 - const { data, total } = await server.videosCommand.list() + const { data, total } = await server.videos.list() expect(data).to.have.lengthOf(length) expect(total).to.equal(length) if (expectedStatus) { - await server.videosCommand.get({ id: videoId, expectedStatus }) + await server.videos.get({ id: videoId, expectedStatus }) } } } async function checkVideoState (videoId: string, state: VideoState) { for (const server of servers) { - const video = await server.videosCommand.get({ id: videoId }) + const video = await server.videos.get({ id: videoId }) expect(video.state.id).to.equal(state) } } async function waitUntilLivePublishedOnAllServers (videoId: string) { for (const server of servers) { - await server.liveCommand.waitUntilPublished({ videoId }) + await server.live.waitUntilPublished({ videoId }) } } async function waitUntilLiveSavedOnAllServers (videoId: string) { for (const server of servers) { - await server.liveCommand.waitUntilSaved({ videoId }) + await server.live.waitUntilSaved({ videoId }) } } @@ -91,7 +91,7 @@ describe('Save replay setting', function () { // Server 1 and server 2 follow each other await doubleFollow(servers[0], servers[1]) - await servers[0].configCommand.updateCustomSubConfig({ + await servers[0].config.updateCustomSubConfig({ newConfig: { live: { enabled: true, @@ -126,7 +126,7 @@ describe('Save replay setting', function () { it('Should correctly have updated the live and federated it when streaming in the live', async function () { this.timeout(30000) - ffmpegCommand = await servers[0].liveCommand.sendRTMPStreamInVideo({ videoId: liveVideoUUID }) + ffmpegCommand = await servers[0].live.sendRTMPStreamInVideo({ videoId: liveVideoUUID }) await waitUntilLivePublishedOnAllServers(liveVideoUUID) @@ -142,7 +142,7 @@ describe('Save replay setting', function () { await stopFfmpeg(ffmpegCommand) for (const server of servers) { - await server.liveCommand.waitUntilEnded({ videoId: liveVideoUUID }) + await server.live.waitUntilEnded({ videoId: liveVideoUUID }) } await waitJobs(servers) @@ -159,7 +159,7 @@ describe('Save replay setting', function () { liveVideoUUID = await createLiveWrapper(false) - ffmpegCommand = await servers[0].liveCommand.sendRTMPStreamInVideo({ videoId: liveVideoUUID }) + ffmpegCommand = await servers[0].live.sendRTMPStreamInVideo({ videoId: liveVideoUUID }) await waitUntilLivePublishedOnAllServers(liveVideoUUID) @@ -167,7 +167,7 @@ describe('Save replay setting', function () { await checkVideosExist(liveVideoUUID, true, HttpStatusCode.OK_200) await Promise.all([ - servers[0].blacklistCommand.add({ videoId: liveVideoUUID, reason: 'bad live', unfederate: true }), + servers[0].blacklist.add({ videoId: liveVideoUUID, reason: 'bad live', unfederate: true }), testFfmpegStreamError(ffmpegCommand, true) ]) @@ -175,8 +175,8 @@ describe('Save replay setting', function () { await checkVideosExist(liveVideoUUID, false) - await servers[0].videosCommand.get({ id: liveVideoUUID, expectedStatus: HttpStatusCode.UNAUTHORIZED_401 }) - await servers[1].videosCommand.get({ id: liveVideoUUID, expectedStatus: HttpStatusCode.NOT_FOUND_404 }) + await servers[0].videos.get({ id: liveVideoUUID, expectedStatus: HttpStatusCode.UNAUTHORIZED_401 }) + await servers[1].videos.get({ id: liveVideoUUID, expectedStatus: HttpStatusCode.NOT_FOUND_404 }) await wait(5000) await waitJobs(servers) @@ -188,7 +188,7 @@ describe('Save replay setting', function () { liveVideoUUID = await createLiveWrapper(false) - ffmpegCommand = await servers[0].liveCommand.sendRTMPStreamInVideo({ videoId: liveVideoUUID }) + ffmpegCommand = await servers[0].live.sendRTMPStreamInVideo({ videoId: liveVideoUUID }) await waitUntilLivePublishedOnAllServers(liveVideoUUID) @@ -197,7 +197,7 @@ describe('Save replay setting', function () { await Promise.all([ testFfmpegStreamError(ffmpegCommand, true), - servers[0].videosCommand.remove({ id: liveVideoUUID }) + servers[0].videos.remove({ id: liveVideoUUID }) ]) await wait(5000) @@ -224,7 +224,7 @@ describe('Save replay setting', function () { it('Should correctly have updated the live and federated it when streaming in the live', async function () { this.timeout(20000) - ffmpegCommand = await servers[0].liveCommand.sendRTMPStreamInVideo({ videoId: liveVideoUUID }) + ffmpegCommand = await servers[0].live.sendRTMPStreamInVideo({ videoId: liveVideoUUID }) await waitUntilLivePublishedOnAllServers(liveVideoUUID) await waitJobs(servers) @@ -249,11 +249,11 @@ describe('Save replay setting', function () { it('Should update the saved live and correctly federate the updated attributes', async function () { this.timeout(30000) - await servers[0].videosCommand.update({ id: liveVideoUUID, attributes: { name: 'video updated' } }) + await servers[0].videos.update({ id: liveVideoUUID, attributes: { name: 'video updated' } }) await waitJobs(servers) for (const server of servers) { - const video = await server.videosCommand.get({ id: liveVideoUUID }) + const video = await server.videos.get({ id: liveVideoUUID }) expect(video.name).to.equal('video updated') expect(video.isLive).to.be.false } @@ -268,14 +268,14 @@ describe('Save replay setting', function () { liveVideoUUID = await createLiveWrapper(true) - ffmpegCommand = await servers[0].liveCommand.sendRTMPStreamInVideo({ videoId: liveVideoUUID }) + ffmpegCommand = await servers[0].live.sendRTMPStreamInVideo({ videoId: liveVideoUUID }) await waitUntilLivePublishedOnAllServers(liveVideoUUID) await waitJobs(servers) await checkVideosExist(liveVideoUUID, true, HttpStatusCode.OK_200) await Promise.all([ - servers[0].blacklistCommand.add({ videoId: liveVideoUUID, reason: 'bad live', unfederate: true }), + servers[0].blacklist.add({ videoId: liveVideoUUID, reason: 'bad live', unfederate: true }), testFfmpegStreamError(ffmpegCommand, true) ]) @@ -283,8 +283,8 @@ describe('Save replay setting', function () { await checkVideosExist(liveVideoUUID, false) - await servers[0].videosCommand.get({ id: liveVideoUUID, expectedStatus: HttpStatusCode.UNAUTHORIZED_401 }) - await servers[1].videosCommand.get({ id: liveVideoUUID, expectedStatus: HttpStatusCode.NOT_FOUND_404 }) + await servers[0].videos.get({ id: liveVideoUUID, expectedStatus: HttpStatusCode.UNAUTHORIZED_401 }) + await servers[1].videos.get({ id: liveVideoUUID, expectedStatus: HttpStatusCode.NOT_FOUND_404 }) await wait(5000) await waitJobs(servers) @@ -296,14 +296,14 @@ describe('Save replay setting', function () { liveVideoUUID = await createLiveWrapper(true) - ffmpegCommand = await servers[0].liveCommand.sendRTMPStreamInVideo({ videoId: liveVideoUUID }) + ffmpegCommand = await servers[0].live.sendRTMPStreamInVideo({ videoId: liveVideoUUID }) await waitUntilLivePublishedOnAllServers(liveVideoUUID) await waitJobs(servers) await checkVideosExist(liveVideoUUID, true, HttpStatusCode.OK_200) await Promise.all([ - servers[0].videosCommand.remove({ id: liveVideoUUID }), + servers[0].videos.remove({ id: liveVideoUUID }), testFfmpegStreamError(ffmpegCommand, true) ]) diff --git a/server/tests/api/live/live-socket-messages.ts b/server/tests/api/live/live-socket-messages.ts index 1f3d455a8..ad67d6285 100644 --- a/server/tests/api/live/live-socket-messages.ts +++ b/server/tests/api/live/live-socket-messages.ts @@ -30,7 +30,7 @@ describe('Test live', function () { await setAccessTokensToServers(servers) await setDefaultVideoChannel(servers) - await servers[0].configCommand.updateCustomSubConfig({ + await servers[0].config.updateCustomSubConfig({ newConfig: { live: { enabled: true, @@ -51,11 +51,11 @@ describe('Test live', function () { async function createLiveWrapper () { const liveAttributes = { name: 'live video', - channelId: servers[0].videoChannel.id, + channelId: servers[0].store.channel.id, privacy: VideoPrivacy.PUBLIC } - const { uuid } = await servers[0].liveCommand.create({ fields: liveAttributes }) + const { uuid } = await servers[0].live.create({ fields: liveAttributes }) return uuid } @@ -69,22 +69,22 @@ describe('Test live', function () { await waitJobs(servers) { - const videoId = await servers[0].videosCommand.getId({ uuid: liveVideoUUID }) + const videoId = await servers[0].videos.getId({ uuid: liveVideoUUID }) - const localSocket = servers[0].socketIOCommand.getLiveNotificationSocket() + const localSocket = servers[0].socketIO.getLiveNotificationSocket() localSocket.on('state-change', data => localStateChanges.push(data.state)) localSocket.emit('subscribe', { videoId }) } { - const videoId = await servers[1].videosCommand.getId({ uuid: liveVideoUUID }) + const videoId = await servers[1].videos.getId({ uuid: liveVideoUUID }) - const remoteSocket = servers[1].socketIOCommand.getLiveNotificationSocket() + const remoteSocket = servers[1].socketIO.getLiveNotificationSocket() remoteSocket.on('state-change', data => remoteStateChanges.push(data.state)) remoteSocket.emit('subscribe', { videoId }) } - const ffmpegCommand = await servers[0].liveCommand.sendRTMPStreamInVideo({ videoId: liveVideoUUID }) + const ffmpegCommand = await servers[0].live.sendRTMPStreamInVideo({ videoId: liveVideoUUID }) await waitUntilLivePublishedOnAllServers(servers, liveVideoUUID) await waitJobs(servers) @@ -97,7 +97,7 @@ describe('Test live', function () { await stopFfmpeg(ffmpegCommand) for (const server of servers) { - await server.liveCommand.waitUntilEnded({ videoId: liveVideoUUID }) + await server.live.waitUntilEnded({ videoId: liveVideoUUID }) } await waitJobs(servers) @@ -117,22 +117,22 @@ describe('Test live', function () { await waitJobs(servers) { - const videoId = await servers[0].videosCommand.getId({ uuid: liveVideoUUID }) + const videoId = await servers[0].videos.getId({ uuid: liveVideoUUID }) - const localSocket = servers[0].socketIOCommand.getLiveNotificationSocket() + const localSocket = servers[0].socketIO.getLiveNotificationSocket() localSocket.on('views-change', data => { localLastVideoViews = data.views }) localSocket.emit('subscribe', { videoId }) } { - const videoId = await servers[1].videosCommand.getId({ uuid: liveVideoUUID }) + const videoId = await servers[1].videos.getId({ uuid: liveVideoUUID }) - const remoteSocket = servers[1].socketIOCommand.getLiveNotificationSocket() + const remoteSocket = servers[1].socketIO.getLiveNotificationSocket() remoteSocket.on('views-change', data => { remoteLastVideoViews = data.views }) remoteSocket.emit('subscribe', { videoId }) } - const ffmpegCommand = await servers[0].liveCommand.sendRTMPStreamInVideo({ videoId: liveVideoUUID }) + const ffmpegCommand = await servers[0].live.sendRTMPStreamInVideo({ videoId: liveVideoUUID }) await waitUntilLivePublishedOnAllServers(servers, liveVideoUUID) await waitJobs(servers) @@ -140,8 +140,8 @@ describe('Test live', function () { expect(localLastVideoViews).to.equal(0) expect(remoteLastVideoViews).to.equal(0) - await servers[0].videosCommand.view({ id: liveVideoUUID }) - await servers[1].videosCommand.view({ id: liveVideoUUID }) + await servers[0].videos.view({ id: liveVideoUUID }) + await servers[1].videos.view({ id: liveVideoUUID }) await waitJobs(servers) await wait(5000) @@ -161,13 +161,13 @@ describe('Test live', function () { const liveVideoUUID = await createLiveWrapper() await waitJobs(servers) - const videoId = await servers[0].videosCommand.getId({ uuid: liveVideoUUID }) + const videoId = await servers[0].videos.getId({ uuid: liveVideoUUID }) - const socket = servers[0].socketIOCommand.getLiveNotificationSocket() + const socket = servers[0].socketIO.getLiveNotificationSocket() socket.on('state-change', data => stateChanges.push(data.state)) socket.emit('subscribe', { videoId }) - const command = await servers[0].liveCommand.sendRTMPStreamInVideo({ videoId: liveVideoUUID }) + const command = await servers[0].live.sendRTMPStreamInVideo({ videoId: liveVideoUUID }) await waitUntilLivePublishedOnAllServers(servers, liveVideoUUID) await waitJobs(servers) diff --git a/server/tests/api/live/live-views.ts b/server/tests/api/live/live-views.ts index 1951b11a5..43222f9c9 100644 --- a/server/tests/api/live/live-views.ts +++ b/server/tests/api/live/live-views.ts @@ -31,7 +31,7 @@ describe('Test live', function () { await setAccessTokensToServers(servers) await setDefaultVideoChannel(servers) - await servers[0].configCommand.updateCustomSubConfig({ + await servers[0].config.updateCustomSubConfig({ newConfig: { live: { enabled: true, @@ -53,7 +53,7 @@ describe('Test live', function () { async function countViews (expected: number) { for (const server of servers) { - const video = await server.videosCommand.get({ id: liveVideoId }) + const video = await server.videos.get({ id: liveVideoId }) expect(video.views).to.equal(expected) } } @@ -63,14 +63,14 @@ describe('Test live', function () { const liveAttributes = { name: 'live video', - channelId: servers[0].videoChannel.id, + channelId: servers[0].store.channel.id, privacy: VideoPrivacy.PUBLIC } - const live = await servers[0].liveCommand.create({ fields: liveAttributes }) + const live = await servers[0].live.create({ fields: liveAttributes }) liveVideoId = live.uuid - command = await servers[0].liveCommand.sendRTMPStreamInVideo({ videoId: liveVideoId }) + command = await servers[0].live.sendRTMPStreamInVideo({ videoId: liveVideoId }) await waitUntilLivePublishedOnAllServers(servers, liveVideoId) await waitJobs(servers) }) @@ -82,8 +82,8 @@ describe('Test live', function () { it('Should view a live twice and display 1 view', async function () { this.timeout(30000) - await servers[0].videosCommand.view({ id: liveVideoId }) - await servers[0].videosCommand.view({ id: liveVideoId }) + await servers[0].videos.view({ id: liveVideoId }) + await servers[0].videos.view({ id: liveVideoId }) await wait(7000) @@ -104,9 +104,9 @@ describe('Test live', function () { it('Should view a live on a remote and on local and display 2 views', async function () { this.timeout(30000) - await servers[0].videosCommand.view({ id: liveVideoId }) - await servers[1].videosCommand.view({ id: liveVideoId }) - await servers[1].videosCommand.view({ id: liveVideoId }) + await servers[0].videos.view({ id: liveVideoId }) + await servers[1].videos.view({ id: liveVideoId }) + await servers[1].videos.view({ id: liveVideoId }) await wait(7000) await waitJobs(servers) diff --git a/server/tests/api/live/live.ts b/server/tests/api/live/live.ts index c88143982..2cce1f448 100644 --- a/server/tests/api/live/live.ts +++ b/server/tests/api/live/live.ts @@ -44,7 +44,7 @@ describe('Test live', function () { await setAccessTokensToServers(servers) await setDefaultVideoChannel(servers) - await servers[0].configCommand.updateCustomSubConfig({ + await servers[0].config.updateCustomSubConfig({ newConfig: { live: { enabled: true, @@ -59,7 +59,7 @@ describe('Test live', function () { // Server 1 and server 2 follow each other await doubleFollow(servers[0], servers[1]) - commands = servers.map(s => s.liveCommand) + commands = servers.map(s => s.live) }) describe('Live creation, update and delete', function () { @@ -74,7 +74,7 @@ describe('Test live', function () { language: 'fr', description: 'super live description', support: 'support field', - channelId: servers[0].videoChannel.id, + channelId: servers[0].store.channel.id, nsfw: false, waitTranscoding: false, name: 'my super live', @@ -93,7 +93,7 @@ describe('Test live', function () { await waitJobs(servers) for (const server of servers) { - const video = await server.videosCommand.get({ id: liveVideoUUID }) + const video = await server.videos.get({ id: liveVideoUUID }) expect(video.category.id).to.equal(1) expect(video.licence.id).to.equal(2) @@ -101,8 +101,8 @@ describe('Test live', function () { expect(video.description).to.equal('super live description') expect(video.support).to.equal('support field') - expect(video.channel.name).to.equal(servers[0].videoChannel.name) - expect(video.channel.host).to.equal(servers[0].videoChannel.host) + expect(video.channel.name).to.equal(servers[0].store.channel.name) + expect(video.channel.host).to.equal(servers[0].store.channel.host) expect(video.isLive).to.be.true @@ -117,7 +117,7 @@ describe('Test live', function () { await testImage(server.url, 'video_short1-preview.webm', video.previewPath) await testImage(server.url, 'video_short1.webm', video.thumbnailPath) - const live = await server.liveCommand.get({ videoId: liveVideoUUID }) + const live = await server.live.get({ videoId: liveVideoUUID }) if (server.url === servers[0].url) { expect(live.rtmpUrl).to.equal('rtmp://' + server.hostname + ':' + servers[0].rtmpPort + '/live') @@ -136,7 +136,7 @@ describe('Test live', function () { const attributes: LiveVideoCreate = { name: 'default live thumbnail', - channelId: servers[0].videoChannel.id, + channelId: servers[0].store.channel.id, privacy: VideoPrivacy.UNLISTED, nsfw: true } @@ -147,7 +147,7 @@ describe('Test live', function () { await waitJobs(servers) for (const server of servers) { - const video = await server.videosCommand.get({ id: videoId }) + const video = await server.videos.get({ id: videoId }) expect(video.privacy.id).to.equal(VideoPrivacy.UNLISTED) expect(video.nsfw).to.be.true @@ -158,7 +158,7 @@ describe('Test live', function () { it('Should not have the live listed since nobody streams into', async function () { for (const server of servers) { - const { total, data } = await server.videosCommand.list() + const { total, data } = await server.videos.list() expect(total).to.equal(0) expect(data).to.have.lengthOf(0) @@ -178,7 +178,7 @@ describe('Test live', function () { it('Have the live updated', async function () { for (const server of servers) { - const live = await server.liveCommand.get({ videoId: liveVideoUUID }) + const live = await server.live.get({ videoId: liveVideoUUID }) if (server.url === servers[0].url) { expect(live.rtmpUrl).to.equal('rtmp://' + server.hostname + ':' + servers[0].rtmpPort + '/live') @@ -195,14 +195,14 @@ describe('Test live', function () { it('Delete the live', async function () { this.timeout(10000) - await servers[0].videosCommand.remove({ id: liveVideoUUID }) + await servers[0].videos.remove({ id: liveVideoUUID }) await waitJobs(servers) }) it('Should have the live deleted', async function () { for (const server of servers) { - await server.videosCommand.get({ id: liveVideoUUID, expectedStatus: HttpStatusCode.NOT_FOUND_404 }) - await server.liveCommand.get({ videoId: liveVideoUUID, expectedStatus: HttpStatusCode.NOT_FOUND_404 }) + await server.videos.get({ id: liveVideoUUID, expectedStatus: HttpStatusCode.NOT_FOUND_404 }) + await server.live.get({ videoId: liveVideoUUID, expectedStatus: HttpStatusCode.NOT_FOUND_404 }) } }) }) @@ -215,19 +215,19 @@ describe('Test live', function () { before(async function () { this.timeout(120000) - vodVideoId = (await servers[0].videosCommand.quickUpload({ name: 'vod video' })).uuid + vodVideoId = (await servers[0].videos.quickUpload({ name: 'vod video' })).uuid - const liveOptions = { name: 'live', privacy: VideoPrivacy.PUBLIC, channelId: servers[0].videoChannel.id } + const liveOptions = { name: 'live', privacy: VideoPrivacy.PUBLIC, channelId: servers[0].store.channel.id } const live = await commands[0].create({ fields: liveOptions }) liveVideoId = live.uuid - ffmpegCommand = await servers[0].liveCommand.sendRTMPStreamInVideo({ videoId: liveVideoId }) + ffmpegCommand = await servers[0].live.sendRTMPStreamInVideo({ videoId: liveVideoId }) await waitUntilLivePublishedOnAllServers(servers, liveVideoId) await waitJobs(servers) }) it('Should only display lives', async function () { - const { data, total } = await servers[0].videosCommand.list({ isLive: true }) + const { data, total } = await servers[0].videos.list({ isLive: true }) expect(total).to.equal(1) expect(data).to.have.lengthOf(1) @@ -235,7 +235,7 @@ describe('Test live', function () { }) it('Should not display lives', async function () { - const { data, total } = await servers[0].videosCommand.list({ isLive: false }) + const { data, total } = await servers[0].videos.list({ isLive: false }) expect(total).to.equal(1) expect(data).to.have.lengthOf(1) @@ -248,22 +248,22 @@ describe('Test live', function () { await stopFfmpeg(ffmpegCommand) await waitJobs(servers) - const { data } = await servers[0].videosCommand.listMyVideos({ isLive: true }) + const { data } = await servers[0].videos.listMyVideos({ isLive: true }) const result = data.every(v => v.isLive) expect(result).to.be.true }) it('Should not display my lives', async function () { - const { data } = await servers[0].videosCommand.listMyVideos({ isLive: false }) + const { data } = await servers[0].videos.listMyVideos({ isLive: false }) const result = data.every(v => !v.isLive) expect(result).to.be.true }) after(async function () { - await servers[0].videosCommand.remove({ id: vodVideoId }) - await servers[0].videosCommand.remove({ id: liveVideoId }) + await servers[0].videos.remove({ id: vodVideoId }) + await servers[0].videos.remove({ id: liveVideoId }) }) }) @@ -278,7 +278,7 @@ describe('Test live', function () { async function createLiveWrapper () { const liveAttributes = { name: 'user live', - channelId: servers[0].videoChannel.id, + channelId: servers[0].store.channel.id, privacy: VideoPrivacy.PUBLIC, saveReplay: false } @@ -286,7 +286,7 @@ describe('Test live', function () { const { uuid } = await commands[0].create({ fields: liveAttributes }) const live = await commands[0].get({ videoId: uuid }) - const video = await servers[0].videosCommand.get({ id: uuid }) + const video = await servers[0].videos.get({ id: uuid }) return Object.assign(video, live) } @@ -316,7 +316,7 @@ describe('Test live', function () { it('Should list this live now someone stream into it', async function () { for (const server of servers) { - const { total, data } = await server.videosCommand.list() + const { total, data } = await server.videos.list() expect(total).to.equal(1) expect(data).to.have.lengthOf(1) @@ -332,7 +332,7 @@ describe('Test live', function () { liveVideo = await createLiveWrapper() - await servers[0].blacklistCommand.add({ videoId: liveVideo.uuid }) + await servers[0].blacklist.add({ videoId: liveVideo.uuid }) const command = sendRTMPStream(rtmpUrl + '/live', liveVideo.streamKey) await testFfmpegStreamError(command, true) @@ -343,7 +343,7 @@ describe('Test live', function () { liveVideo = await createLiveWrapper() - await servers[0].videosCommand.remove({ id: liveVideo.uuid }) + await servers[0].videos.remove({ id: liveVideo.uuid }) const command = sendRTMPStream(rtmpUrl + '/live', liveVideo.streamKey) await testFfmpegStreamError(command, true) @@ -356,7 +356,7 @@ describe('Test live', function () { async function createLiveWrapper (saveReplay: boolean) { const liveAttributes = { name: 'live video', - channelId: servers[0].videoChannel.id, + channelId: servers[0].store.channel.id, privacy: VideoPrivacy.PUBLIC, saveReplay } @@ -367,10 +367,10 @@ describe('Test live', function () { async function testVideoResolutions (liveVideoId: string, resolutions: number[]) { for (const server of servers) { - const { data } = await server.videosCommand.list() + const { data } = await server.videos.list() expect(data.find(v => v.uuid === liveVideoId)).to.exist - const video = await server.videosCommand.get({ id: liveVideoId }) + const video = await server.videos.get({ id: liveVideoId }) expect(video.streamingPlaylists).to.have.lengthOf(1) @@ -387,7 +387,7 @@ describe('Test live', function () { const segmentName = `${i}-00000${segmentNum}.ts` await commands[0].waitUntilSegmentGeneration({ videoUUID: video.uuid, resolution: i, segment: segmentNum }) - const subPlaylist = await servers[0].streamingPlaylistsCommand.get({ + const subPlaylist = await servers[0].streamingPlaylists.get({ url: `${servers[0].url}/static/streaming-playlists/hls/${video.uuid}/${i}.m3u8` }) @@ -406,7 +406,7 @@ describe('Test live', function () { } function updateConf (resolutions: number[]) { - return servers[0].configCommand.updateCustomSubConfig({ + return servers[0].config.updateCustomSubConfig({ newConfig: { live: { enabled: true, @@ -490,7 +490,7 @@ describe('Test live', function () { } for (const server of servers) { - const video = await server.videosCommand.get({ id: liveVideoId }) + const video = await server.videos.get({ id: liveVideoId }) expect(video.state.id).to.equal(VideoState.PUBLISHED) expect(video.duration).to.be.greaterThan(1) @@ -515,7 +515,7 @@ describe('Test live', function () { } const filename = `${video.uuid}-${resolution}-fragmented.mp4` - const segmentPath = servers[0].serversCommand.buildDirectory(join('streaming-playlists', 'hls', video.uuid, filename)) + const segmentPath = servers[0].servers.buildDirectory(join('streaming-playlists', 'hls', video.uuid, filename)) const probe = await ffprobePromise(segmentPath) const videoStream = await getVideoStreamFromFile(segmentPath, probe) @@ -542,7 +542,7 @@ describe('Test live', function () { async function createLiveWrapper (saveReplay: boolean) { const liveAttributes = { name: 'live video', - channelId: servers[0].videoChannel.id, + channelId: servers[0].store.channel.id, privacy: VideoPrivacy.PUBLIC, saveReplay } diff --git a/server/tests/api/moderation/abuses.ts b/server/tests/api/moderation/abuses.ts index 7574b8f4a..97a0d95c4 100644 --- a/server/tests/api/moderation/abuses.ts +++ b/server/tests/api/moderation/abuses.ts @@ -33,7 +33,7 @@ describe('Test abuses', function () { // Server 1 and server 2 follow each other await doubleFollow(servers[0], servers[1]) - commands = servers.map(s => s.abusesCommand) + commands = servers.map(s => s.abuses) }) describe('Video abuses', function () { @@ -47,7 +47,7 @@ describe('Test abuses', function () { name: 'my super name for server 1', description: 'my super description for server 1' } - await servers[0].videosCommand.upload({ attributes }) + await servers[0].videos.upload({ attributes }) } { @@ -55,17 +55,17 @@ describe('Test abuses', function () { name: 'my super name for server 2', description: 'my super description for server 2' } - await servers[1].videosCommand.upload({ attributes }) + await servers[1].videos.upload({ attributes }) } // Wait videos propagation, server 2 has transcoding enabled await waitJobs(servers) - const { data } = await servers[0].videosCommand.list() + const { data } = await servers[0].videos.list() expect(data.length).to.equal(2) - servers[0].video = data.find(video => video.name === 'my super name for server 1') - servers[1].video = data.find(video => video.name === 'my super name for server 2') + servers[0].store.video = data.find(video => video.name === 'my super name for server 1') + servers[1].store.video = data.find(video => video.name === 'my super name for server 2') }) it('Should not have abuses', async function () { @@ -80,7 +80,7 @@ describe('Test abuses', function () { this.timeout(15000) const reason = 'my super bad reason' - await commands[0].report({ videoId: servers[0].video.id, reason }) + await commands[0].report({ videoId: servers[0].store.video.id, reason }) // We wait requests propagation, even if the server 1 is not supposed to make a request to server 2 await waitJobs(servers) @@ -100,7 +100,7 @@ describe('Test abuses', function () { expect(abuse.reporterAccount.name).to.equal('root') expect(abuse.reporterAccount.host).to.equal(servers[0].host) - expect(abuse.video.id).to.equal(servers[0].video.id) + expect(abuse.video.id).to.equal(servers[0].store.video.id) expect(abuse.video.channel).to.exist expect(abuse.comment).to.be.null @@ -127,7 +127,7 @@ describe('Test abuses', function () { this.timeout(10000) const reason = 'my super bad reason 2' - const videoId = await servers[0].videosCommand.getId({ uuid: servers[1].video.uuid }) + const videoId = await servers[0].videos.getId({ uuid: servers[1].store.video.uuid }) await commands[0].report({ videoId, reason }) // We wait requests propagation @@ -146,7 +146,7 @@ describe('Test abuses', function () { expect(abuse1.reporterAccount.name).to.equal('root') expect(abuse1.reporterAccount.host).to.equal(servers[0].host) - expect(abuse1.video.id).to.equal(servers[0].video.id) + expect(abuse1.video.id).to.equal(servers[0].store.video.id) expect(abuse1.video.countReports).to.equal(1) expect(abuse1.video.nthReport).to.equal(1) @@ -165,7 +165,7 @@ describe('Test abuses', function () { expect(abuse2.reporterAccount.name).to.equal('root') expect(abuse2.reporterAccount.host).to.equal(servers[0].host) - expect(abuse2.video.id).to.equal(servers[1].video.id) + expect(abuse2.video.id).to.equal(servers[1].store.video.id) expect(abuse2.comment).to.be.null @@ -200,7 +200,7 @@ describe('Test abuses', function () { this.timeout(10000) { - const videoId = await servers[1].videosCommand.getId({ uuid: servers[0].video.uuid }) + const videoId = await servers[1].videos.getId({ uuid: servers[0].store.video.uuid }) await commands[1].report({ videoId, reason: 'will mute this' }) await waitJobs(servers) @@ -211,7 +211,7 @@ describe('Test abuses', function () { const accountToBlock = 'root@' + servers[1].host { - await servers[0].blocklistCommand.addToServerBlocklist({ account: accountToBlock }) + await servers[0].blocklist.addToServerBlocklist({ account: accountToBlock }) const body = await commands[0].getAdminList() expect(body.total).to.equal(2) @@ -221,7 +221,7 @@ describe('Test abuses', function () { } { - await servers[0].blocklistCommand.removeFromServerBlocklist({ account: accountToBlock }) + await servers[0].blocklist.removeFromServerBlocklist({ account: accountToBlock }) const body = await commands[0].getAdminList() expect(body.total).to.equal(3) @@ -232,7 +232,7 @@ describe('Test abuses', function () { const serverToBlock = servers[1].host { - await servers[0].blocklistCommand.addToServerBlocklist({ server: serverToBlock }) + await servers[0].blocklist.addToServerBlocklist({ server: serverToBlock }) const body = await commands[0].getAdminList() expect(body.total).to.equal(2) @@ -242,7 +242,7 @@ describe('Test abuses', function () { } { - await servers[0].blocklistCommand.removeFromServerBlocklist({ server: serverToBlock }) + await servers[0].blocklist.removeFromServerBlocklist({ server: serverToBlock }) const body = await commands[0].getAdminList() expect(body.total).to.equal(3) @@ -252,7 +252,7 @@ describe('Test abuses', function () { it('Should keep the video abuse when deleting the video', async function () { this.timeout(10000) - await servers[1].videosCommand.remove({ id: abuseServer2.video.uuid }) + await servers[1].videos.remove({ id: abuseServer2.video.uuid }) await waitJobs(servers) @@ -272,15 +272,15 @@ describe('Test abuses', function () { // register a second user to have two reporters/reportees const user = { username: 'user2', password: 'password' } - await servers[0].usersCommand.create({ ...user }) - const userAccessToken = await servers[0].loginCommand.getAccessToken(user) + await servers[0].users.create({ ...user }) + const userAccessToken = await servers[0].login.getAccessToken(user) // upload a third video via this user const attributes = { name: 'my second super name for server 1', description: 'my second super description for server 1' } - const { id } = await servers[0].videosCommand.upload({ token: userAccessToken, attributes }) + const { id } = await servers[0].videos.upload({ token: userAccessToken, attributes }) const video3Id = id // resume with the test @@ -288,7 +288,7 @@ describe('Test abuses', function () { await commands[0].report({ videoId: video3Id, reason: reason3 }) const reason4 = 'my super bad reason 4' - await commands[0].report({ token: userAccessToken, videoId: servers[0].video.id, reason: reason4 }) + await commands[0].report({ token: userAccessToken, videoId: servers[0].store.video.id, reason: reason4 }) { const body = await commands[0].getAdminList() @@ -301,7 +301,7 @@ describe('Test abuses', function () { expect(abuseVideo3.countReportsForReportee).to.equal(1, "wrong reports count for reporter on video 3 abuse") expect(abuseVideo3.countReportsForReporter).to.equal(3, "wrong reports count for reportee on video 3 abuse") - const abuseServer1 = abuses.find(a => a.video.id === servers[0].video.id) + const abuseServer1 = abuses.find(a => a.video.id === servers[0].store.video.id) expect(abuseServer1.countReportsForReportee).to.equal(3, "wrong reports count for reporter on video 1 abuse") } }) @@ -312,7 +312,7 @@ describe('Test abuses', function () { const reason5 = 'my super bad reason 5' const predefinedReasons5: AbusePredefinedReasonsString[] = [ 'violentOrRepulsive', 'captions' ] const createRes = await commands[0].report({ - videoId: servers[0].video.id, + videoId: servers[0].store.video.id, reason: reason5, predefinedReasons: predefinedReasons5, startAt: 1, @@ -391,10 +391,10 @@ describe('Test abuses', function () { async function getComment (server: ServerInfo, videoIdArg: number | string) { const videoId = typeof videoIdArg === 'string' - ? await server.videosCommand.getId({ uuid: videoIdArg }) + ? await server.videos.getId({ uuid: videoIdArg }) : videoIdArg - const { data } = await server.commentsCommand.listThreads({ videoId }) + const { data } = await server.comments.listThreads({ videoId }) return data[0] } @@ -402,11 +402,11 @@ describe('Test abuses', function () { before(async function () { this.timeout(50000) - servers[0].video = await await servers[0].videosCommand.quickUpload({ name: 'server 1' }) - servers[1].video = await await servers[1].videosCommand.quickUpload({ name: 'server 2' }) + servers[0].store.video = await await servers[0].videos.quickUpload({ name: 'server 1' }) + servers[1].store.video = await await servers[1].videos.quickUpload({ name: 'server 2' }) - await servers[0].commentsCommand.createThread({ videoId: servers[0].video.id, text: 'comment server 1' }) - await servers[1].commentsCommand.createThread({ videoId: servers[1].video.id, text: 'comment server 2' }) + await servers[0].comments.createThread({ videoId: servers[0].store.video.id, text: 'comment server 1' }) + await servers[1].comments.createThread({ videoId: servers[1].store.video.id, text: 'comment server 2' }) await waitJobs(servers) }) @@ -414,7 +414,7 @@ describe('Test abuses', function () { it('Should report abuse on a comment', async function () { this.timeout(15000) - const comment = await getComment(servers[0], servers[0].video.id) + const comment = await getComment(servers[0], servers[0].store.video.id) const reason = 'it is a bad comment' await commands[0].report({ commentId: comment.id, reason }) @@ -424,7 +424,7 @@ describe('Test abuses', function () { it('Should have 1 comment abuse on server 1 and 0 on server 2', async function () { { - const comment = await getComment(servers[0], servers[0].video.id) + const comment = await getComment(servers[0], servers[0].store.video.id) const body = await commands[0].getAdminList({ filter: 'comment' }) expect(body.total).to.equal(1) @@ -442,8 +442,8 @@ describe('Test abuses', function () { expect(abuse.comment.id).to.equal(comment.id) expect(abuse.comment.text).to.equal(comment.text) expect(abuse.comment.video.name).to.equal('server 1') - expect(abuse.comment.video.id).to.equal(servers[0].video.id) - expect(abuse.comment.video.uuid).to.equal(servers[0].video.uuid) + expect(abuse.comment.video.id).to.equal(servers[0].store.video.id) + expect(abuse.comment.video.uuid).to.equal(servers[0].store.video.uuid) expect(abuse.countReportsForReporter).to.equal(5) expect(abuse.countReportsForReportee).to.equal(5) @@ -459,7 +459,7 @@ describe('Test abuses', function () { it('Should report abuse on a remote comment', async function () { this.timeout(10000) - const comment = await getComment(servers[0], servers[1].video.uuid) + const comment = await getComment(servers[0], servers[1].store.video.uuid) const reason = 'it is a really bad comment' await commands[0].report({ commentId: comment.id, reason }) @@ -468,7 +468,7 @@ describe('Test abuses', function () { }) it('Should have 2 comment abuses on server 1 and 1 on server 2', async function () { - const commentServer2 = await getComment(servers[0], servers[1].video.id) + const commentServer2 = await getComment(servers[0], servers[1].store.video.id) { const body = await commands[0].getAdminList({ filter: 'comment' }) @@ -493,7 +493,7 @@ describe('Test abuses', function () { expect(abuse2.comment.id).to.equal(commentServer2.id) expect(abuse2.comment.text).to.equal(commentServer2.text) expect(abuse2.comment.video.name).to.equal('server 2') - expect(abuse2.comment.video.uuid).to.equal(servers[1].video.uuid) + expect(abuse2.comment.video.uuid).to.equal(servers[1].store.video.uuid) expect(abuse2.state.id).to.equal(AbuseState.PENDING) expect(abuse2.state.label).to.equal('Pending') @@ -527,9 +527,9 @@ describe('Test abuses', function () { it('Should keep the comment abuse when deleting the comment', async function () { this.timeout(10000) - const commentServer2 = await getComment(servers[0], servers[1].video.id) + const commentServer2 = await getComment(servers[0], servers[1].store.video.id) - await servers[0].commentsCommand.delete({ videoId: servers[1].video.uuid, commentId: commentServer2.id }) + await servers[0].comments.delete({ videoId: servers[1].store.video.uuid, commentId: commentServer2.id }) await waitJobs(servers) @@ -592,16 +592,16 @@ describe('Test abuses', function () { describe('Account abuses', function () { function getAccountFromServer (server: ServerInfo, targetName: string, targetServer: ServerInfo) { - return server.accountsCommand.get({ accountName: targetName + '@' + targetServer.host }) + return server.accounts.get({ accountName: targetName + '@' + targetServer.host }) } before(async function () { this.timeout(50000) - await servers[0].usersCommand.create({ username: 'user_1', password: 'donald' }) + await servers[0].users.create({ username: 'user_1', password: 'donald' }) - const token = await servers[1].usersCommand.generateUserAndToken('user_2') - await servers[1].videosCommand.upload({ token, attributes: { name: 'super video' } }) + const token = await servers[1].users.generateUserAndToken('user_2') + await servers[1].videos.upload({ token, attributes: { name: 'super video' } }) await waitJobs(servers) }) @@ -702,7 +702,7 @@ describe('Test abuses', function () { this.timeout(10000) const account = await getAccountFromServer(servers[1], 'user_2', servers[1]) - await servers[1].usersCommand.remove({ userId: account.userId }) + await servers[1].users.remove({ userId: account.userId }) await waitJobs(servers) @@ -759,11 +759,11 @@ describe('Test abuses', function () { let userAccessToken: string before(async function () { - userAccessToken = await servers[0].usersCommand.generateUserAndToken('user_42') + userAccessToken = await servers[0].users.generateUserAndToken('user_42') - await commands[0].report({ token: userAccessToken, videoId: servers[0].video.id, reason: 'user reason 1' }) + await commands[0].report({ token: userAccessToken, videoId: servers[0].store.video.id, reason: 'user reason 1' }) - const videoId = await servers[0].videosCommand.getId({ uuid: servers[1].video.uuid }) + const videoId = await servers[0].videos.getId({ uuid: servers[1].store.video.uuid }) await commands[0].report({ token: userAccessToken, videoId, reason: 'user reason 2' }) }) @@ -830,9 +830,9 @@ describe('Test abuses', function () { let abuseMessageModerationId: number before(async function () { - userToken = await servers[0].usersCommand.generateUserAndToken('user_43') + userToken = await servers[0].users.generateUserAndToken('user_43') - const body = await commands[0].report({ token: userToken, videoId: servers[0].video.id, reason: 'user 43 reason 1' }) + const body = await commands[0].report({ token: userToken, videoId: servers[0].store.video.id, reason: 'user 43 reason 1' }) abuseId = body.abuse.id }) diff --git a/server/tests/api/moderation/blocklist-notification.ts b/server/tests/api/moderation/blocklist-notification.ts index 92a0ec681..6b56fdd65 100644 --- a/server/tests/api/moderation/blocklist-notification.ts +++ b/server/tests/api/moderation/blocklist-notification.ts @@ -8,7 +8,7 @@ import { UserNotificationType } from '@shared/models' const expect = chai.expect async function checkNotifications (server: ServerInfo, token: string, expected: UserNotificationType[]) { - const { data } = await server.notificationsCommand.list({ token, start: 0, count: 10, unread: true }) + const { data } = await server.notifications.list({ token, start: 0, count: 10, unread: true }) expect(data).to.have.lengthOf(expected.length) for (const type of expected) { @@ -26,24 +26,24 @@ describe('Test blocklist', function () { async function resetState () { try { - await servers[1].subscriptionsCommand.remove({ token: remoteUserToken, uri: 'user1_channel@' + servers[0].host }) - await servers[1].subscriptionsCommand.remove({ token: remoteUserToken, uri: 'user2_channel@' + servers[0].host }) + await servers[1].subscriptions.remove({ token: remoteUserToken, uri: 'user1_channel@' + servers[0].host }) + await servers[1].subscriptions.remove({ token: remoteUserToken, uri: 'user2_channel@' + servers[0].host }) } catch {} await waitJobs(servers) - await servers[0].notificationsCommand.markAsReadAll({ token: userToken1 }) - await servers[0].notificationsCommand.markAsReadAll({ token: userToken2 }) + await servers[0].notifications.markAsReadAll({ token: userToken1 }) + await servers[0].notifications.markAsReadAll({ token: userToken2 }) { - const { uuid } = await servers[0].videosCommand.upload({ token: userToken1, attributes: { name: 'video' } }) + const { uuid } = await servers[0].videos.upload({ token: userToken1, attributes: { name: 'video' } }) videoUUID = uuid await waitJobs(servers) } { - await servers[1].commentsCommand.createThread({ + await servers[1].comments.createThread({ token: remoteUserToken, videoId: videoUUID, text: '@user2@' + servers[0].host + ' hello' @@ -52,8 +52,8 @@ describe('Test blocklist', function () { { - await servers[1].subscriptionsCommand.add({ token: remoteUserToken, targetUri: 'user1_channel@' + servers[0].host }) - await servers[1].subscriptionsCommand.add({ token: remoteUserToken, targetUri: 'user2_channel@' + servers[0].host }) + await servers[1].subscriptions.add({ token: remoteUserToken, targetUri: 'user1_channel@' + servers[0].host }) + await servers[1].subscriptions.add({ token: remoteUserToken, targetUri: 'user2_channel@' + servers[0].host }) } await waitJobs(servers) @@ -67,29 +67,29 @@ describe('Test blocklist', function () { { const user = { username: 'user1', password: 'password' } - await servers[0].usersCommand.create({ + await servers[0].users.create({ username: user.username, password: user.password, videoQuota: -1, videoQuotaDaily: -1 }) - userToken1 = await servers[0].loginCommand.getAccessToken(user) - await servers[0].videosCommand.upload({ token: userToken1, attributes: { name: 'video user 1' } }) + userToken1 = await servers[0].login.getAccessToken(user) + await servers[0].videos.upload({ token: userToken1, attributes: { name: 'video user 1' } }) } { const user = { username: 'user2', password: 'password' } - await servers[0].usersCommand.create({ username: user.username, password: user.password }) + await servers[0].users.create({ username: user.username, password: user.password }) - userToken2 = await servers[0].loginCommand.getAccessToken(user) + userToken2 = await servers[0].login.getAccessToken(user) } { const user = { username: 'user3', password: 'password' } - await servers[1].usersCommand.create({ username: user.username, password: user.password }) + await servers[1].users.create({ username: user.username, password: user.password }) - remoteUserToken = await servers[1].loginCommand.getAccessToken(user) + remoteUserToken = await servers[1].login.getAccessToken(user) } await doubleFollow(servers[0], servers[1]) @@ -111,7 +111,7 @@ describe('Test blocklist', function () { it('Should block an account', async function () { this.timeout(10000) - await servers[0].blocklistCommand.addToMyBlocklist({ token: userToken1, account: 'user3@' + servers[1].host }) + await servers[0].blocklist.addToMyBlocklist({ token: userToken1, account: 'user3@' + servers[1].host }) await waitJobs(servers) }) @@ -124,7 +124,7 @@ describe('Test blocklist', function () { await checkNotifications(servers[0], userToken2, notifs) - await servers[0].blocklistCommand.removeFromMyBlocklist({ token: userToken1, account: 'user3@' + servers[1].host }) + await servers[0].blocklist.removeFromMyBlocklist({ token: userToken1, account: 'user3@' + servers[1].host }) }) }) @@ -144,7 +144,7 @@ describe('Test blocklist', function () { it('Should block an account', async function () { this.timeout(10000) - await servers[0].blocklistCommand.addToMyBlocklist({ token: userToken1, server: servers[1].host }) + await servers[0].blocklist.addToMyBlocklist({ token: userToken1, server: servers[1].host }) await waitJobs(servers) }) @@ -157,7 +157,7 @@ describe('Test blocklist', function () { await checkNotifications(servers[0], userToken2, notifs) - await servers[0].blocklistCommand.removeFromMyBlocklist({ token: userToken1, server: servers[1].host }) + await servers[0].blocklist.removeFromMyBlocklist({ token: userToken1, server: servers[1].host }) }) }) @@ -184,7 +184,7 @@ describe('Test blocklist', function () { it('Should block an account', async function () { this.timeout(10000) - await servers[0].blocklistCommand.addToServerBlocklist({ account: 'user3@' + servers[1].host }) + await servers[0].blocklist.addToServerBlocklist({ account: 'user3@' + servers[1].host }) await waitJobs(servers) }) @@ -192,7 +192,7 @@ describe('Test blocklist', function () { await checkNotifications(servers[0], userToken1, []) await checkNotifications(servers[0], userToken2, []) - await servers[0].blocklistCommand.removeFromServerBlocklist({ account: 'user3@' + servers[1].host }) + await servers[0].blocklist.removeFromServerBlocklist({ account: 'user3@' + servers[1].host }) }) }) @@ -219,7 +219,7 @@ describe('Test blocklist', function () { it('Should block an account', async function () { this.timeout(10000) - await servers[0].blocklistCommand.addToServerBlocklist({ server: servers[1].host }) + await servers[0].blocklist.addToServerBlocklist({ server: servers[1].host }) await waitJobs(servers) }) diff --git a/server/tests/api/moderation/blocklist.ts b/server/tests/api/moderation/blocklist.ts index 3c3b2d6fd..9a4a3b3b9 100644 --- a/server/tests/api/moderation/blocklist.ts +++ b/server/tests/api/moderation/blocklist.ts @@ -18,24 +18,24 @@ const expect = chai.expect async function checkAllVideos (server: ServerInfo, token: string) { { - const { data } = await server.videosCommand.listWithToken({ token }) + const { data } = await server.videos.listWithToken({ token }) expect(data).to.have.lengthOf(5) } { - const { data } = await server.videosCommand.list() + const { data } = await server.videos.list() expect(data).to.have.lengthOf(5) } } async function checkAllComments (server: ServerInfo, token: string, videoUUID: string) { - const { data } = await server.commentsCommand.listThreads({ videoId: videoUUID, start: 0, count: 25, sort: '-createdAt', token }) + const { data } = await server.comments.listThreads({ videoId: videoUUID, start: 0, count: 25, sort: '-createdAt', token }) const threads = data.filter(t => t.isDeleted === false) expect(threads).to.have.lengthOf(2) for (const thread of threads) { - const tree = await server.commentsCommand.getThread({ videoId: videoUUID, threadId: thread.id, token }) + const tree = await server.comments.getThread({ videoId: videoUUID, threadId: thread.id, token }) expect(tree.children).to.have.lengthOf(1) } } @@ -45,13 +45,13 @@ async function checkCommentNotification ( comment: { server: ServerInfo, token: string, videoUUID: string, text: string }, check: 'presence' | 'absence' ) { - const command = comment.server.commentsCommand + const command = comment.server.comments const { threadId, createdAt } = await command.createThread({ token: comment.token, videoId: comment.videoUUID, text: comment.text }) await waitJobs([ mainServer, comment.server ]) - const { data } = await mainServer.notificationsCommand.list({ start: 0, count: 30 }) + const { data } = await mainServer.notifications.list({ start: 0, count: 30 }) const commentNotifications = data.filter(n => n.comment && n.comment.video.uuid === comment.videoUUID && n.createdAt >= createdAt) if (check === 'presence') expect(commentNotifications).to.have.lengthOf(1) @@ -80,44 +80,44 @@ describe('Test blocklist', function () { servers = await flushAndRunMultipleServers(3) await setAccessTokensToServers(servers) - command = servers[0].blocklistCommand - commentsCommand = servers.map(s => s.commentsCommand) + command = servers[0].blocklist + commentsCommand = servers.map(s => s.comments) { const user = { username: 'user1', password: 'password' } - await servers[0].usersCommand.create({ username: user.username, password: user.password }) + await servers[0].users.create({ username: user.username, password: user.password }) - userToken1 = await servers[0].loginCommand.getAccessToken(user) - await servers[0].videosCommand.upload({ token: userToken1, attributes: { name: 'video user 1' } }) + userToken1 = await servers[0].login.getAccessToken(user) + await servers[0].videos.upload({ token: userToken1, attributes: { name: 'video user 1' } }) } { const user = { username: 'moderator', password: 'password' } - await servers[0].usersCommand.create({ username: user.username, password: user.password }) + await servers[0].users.create({ username: user.username, password: user.password }) - userModeratorToken = await servers[0].loginCommand.getAccessToken(user) + userModeratorToken = await servers[0].login.getAccessToken(user) } { const user = { username: 'user2', password: 'password' } - await servers[1].usersCommand.create({ username: user.username, password: user.password }) + await servers[1].users.create({ username: user.username, password: user.password }) - userToken2 = await servers[1].loginCommand.getAccessToken(user) - await servers[1].videosCommand.upload({ token: userToken2, attributes: { name: 'video user 2' } }) + userToken2 = await servers[1].login.getAccessToken(user) + await servers[1].videos.upload({ token: userToken2, attributes: { name: 'video user 2' } }) } { - const { uuid } = await servers[0].videosCommand.upload({ attributes: { name: 'video server 1' } }) + const { uuid } = await servers[0].videos.upload({ attributes: { name: 'video server 1' } }) videoUUID1 = uuid } { - const { uuid } = await servers[1].videosCommand.upload({ attributes: { name: 'video server 2' } }) + const { uuid } = await servers[1].videos.upload({ attributes: { name: 'video server 2' } }) videoUUID2 = uuid } { - const { uuid } = await servers[0].videosCommand.upload({ attributes: { name: 'video 2 server 1' } }) + const { uuid } = await servers[0].videos.upload({ attributes: { name: 'video 2 server 1' } }) videoUUID3 = uuid } @@ -159,7 +159,7 @@ describe('Test blocklist', function () { }) it('Should hide its videos', async function () { - const { data } = await servers[0].videosCommand.listWithToken() + const { data } = await servers[0].videos.listWithToken() expect(data).to.have.lengthOf(4) @@ -172,7 +172,7 @@ describe('Test blocklist', function () { }) it('Should hide its videos', async function () { - const { data } = await servers[0].videosCommand.listWithToken() + const { data } = await servers[0].videos.listWithToken() expect(data).to.have.lengthOf(3) @@ -289,12 +289,12 @@ describe('Test blocklist', function () { // Server 1 and 3 should only have uploader comments for (const server of [ servers[0], servers[2] ]) { - const { data } = await server.commentsCommand.listThreads({ videoId: videoUUID3, count: 25, sort: '-createdAt' }) + const { data } = await server.comments.listThreads({ videoId: videoUUID3, count: 25, sort: '-createdAt' }) expect(data).to.have.lengthOf(1) expect(data[0].text).to.equal('uploader') - const tree = await server.commentsCommand.getThread({ videoId: videoUUID3, threadId: data[0].id }) + const tree = await server.comments.getThread({ videoId: videoUUID3, threadId: data[0].id }) if (server.serverNumber === 1) expect(tree.children).to.have.lengthOf(0) else expect(tree.children).to.have.lengthOf(1) @@ -306,7 +306,7 @@ describe('Test blocklist', function () { }) it('Should display its videos', async function () { - const { data } = await servers[0].videosCommand.listWithToken() + const { data } = await servers[0].videos.listWithToken() expect(data).to.have.lengthOf(4) const v = data.find(v => v.name === 'video user 2') @@ -315,7 +315,7 @@ describe('Test blocklist', function () { it('Should display its comments on my video', async function () { for (const server of servers) { - const { data } = await server.commentsCommand.listThreads({ videoId: videoUUID3, count: 25, sort: '-createdAt' }) + const { data } = await server.comments.listThreads({ videoId: videoUUID3, count: 25, sort: '-createdAt' }) // Server 3 should not have 2 comment threads, because server 1 did not forward the server 2 comment if (server.serverNumber === 3) { @@ -327,7 +327,7 @@ describe('Test blocklist', function () { expect(data[0].text).to.equal('uploader') expect(data[1].text).to.equal('comment user 2') - const tree = await server.commentsCommand.getThread({ videoId: videoUUID3, threadId: data[0].id }) + const tree = await server.comments.getThread({ videoId: videoUUID3, threadId: data[0].id }) expect(tree.children).to.have.lengthOf(1) expect(tree.children[0].comment.text).to.equal('reply by user 2') expect(tree.children[0].children).to.have.lengthOf(1) @@ -378,7 +378,7 @@ describe('Test blocklist', function () { }) it('Should hide its videos', async function () { - const { data } = await servers[0].videosCommand.listWithToken() + const { data } = await servers[0].videos.listWithToken() expect(data).to.have.lengthOf(3) @@ -488,7 +488,7 @@ describe('Test blocklist', function () { it('Should hide its videos', async function () { for (const token of [ userModeratorToken, servers[0].accessToken ]) { - const { data } = await servers[0].videosCommand.listWithToken({ token }) + const { data } = await servers[0].videos.listWithToken({ token }) expect(data).to.have.lengthOf(4) @@ -503,7 +503,7 @@ describe('Test blocklist', function () { it('Should hide its videos', async function () { for (const token of [ userModeratorToken, servers[0].accessToken ]) { - const { data } = await servers[0].videosCommand.listWithToken({ token }) + const { data } = await servers[0].videos.listWithToken({ token }) expect(data).to.have.lengthOf(3) @@ -581,7 +581,7 @@ describe('Test blocklist', function () { it('Should display its videos', async function () { for (const token of [ userModeratorToken, servers[0].accessToken ]) { - const { data } = await servers[0].videosCommand.listWithToken({ token }) + const { data } = await servers[0].videos.listWithToken({ token }) expect(data).to.have.lengthOf(4) const v = data.find(v => v.name === 'video user 2') @@ -639,8 +639,8 @@ describe('Test blocklist', function () { it('Should hide its videos', async function () { for (const token of [ userModeratorToken, servers[0].accessToken ]) { const requests = [ - servers[0].videosCommand.list(), - servers[0].videosCommand.listWithToken({ token }) + servers[0].videos.list(), + servers[0].videos.listWithToken({ token }) ] for (const req of requests) { @@ -688,13 +688,13 @@ describe('Test blocklist', function () { { const now = new Date() - await servers[1].followsCommand.unfollow({ target: servers[0] }) + await servers[1].follows.unfollow({ target: servers[0] }) await waitJobs(servers) - await servers[1].followsCommand.follow({ targets: [ servers[0].host ] }) + await servers[1].follows.follow({ targets: [ servers[0].host ] }) await waitJobs(servers) - const { data } = await servers[0].notificationsCommand.list({ start: 0, count: 30 }) + const { data } = await servers[0].notifications.list({ start: 0, count: 30 }) const commentNotifications = data.filter(n => { return n.type === UserNotificationType.NEW_INSTANCE_FOLLOWER && n.createdAt >= now.toISOString() }) @@ -749,13 +749,13 @@ describe('Test blocklist', function () { { const now = new Date() - await servers[1].followsCommand.unfollow({ target: servers[0] }) + await servers[1].follows.unfollow({ target: servers[0] }) await waitJobs(servers) - await servers[1].followsCommand.follow({ targets: [ servers[0].host ] }) + await servers[1].follows.follow({ targets: [ servers[0].host ] }) await waitJobs(servers) - const { data } = await servers[0].notificationsCommand.list({ start: 0, count: 30 }) + const { data } = await servers[0].notifications.list({ start: 0, count: 30 }) const commentNotifications = data.filter(n => { return n.type === UserNotificationType.NEW_INSTANCE_FOLLOWER && n.createdAt >= now.toISOString() }) diff --git a/server/tests/api/moderation/video-blacklist.ts b/server/tests/api/moderation/video-blacklist.ts index 2f2e678e7..d23d23bcb 100644 --- a/server/tests/api/moderation/video-blacklist.ts +++ b/server/tests/api/moderation/video-blacklist.ts @@ -25,10 +25,10 @@ describe('Test video blacklist', function () { let command: BlacklistCommand async function blacklistVideosOnServer (server: ServerInfo) { - const { data } = await server.videosCommand.list() + const { data } = await server.videos.list() for (const video of data) { - await server.blacklistCommand.add({ videoId: video.id, reason: 'super reason' }) + await server.blacklist.add({ videoId: video.id, reason: 'super reason' }) } } @@ -45,13 +45,13 @@ describe('Test video blacklist', function () { await doubleFollow(servers[0], servers[1]) // Upload 2 videos on server 2 - await servers[1].videosCommand.upload({ attributes: { name: 'My 1st video', description: 'A video on server 2' } }) - await servers[1].videosCommand.upload({ attributes: { name: 'My 2nd video', description: 'A video on server 2' } }) + await servers[1].videos.upload({ attributes: { name: 'My 1st video', description: 'A video on server 2' } }) + await servers[1].videos.upload({ attributes: { name: 'My 2nd video', description: 'A video on server 2' } }) // Wait videos propagation, server 2 has transcoding enabled await waitJobs(servers) - command = servers[0].blacklistCommand + command = servers[0].blacklist // Blacklist the two videos on server 1 await blacklistVideosOnServer(servers[0]) @@ -61,7 +61,7 @@ describe('Test video blacklist', function () { it('Should not have the video blacklisted in videos list/search on server 1', async function () { { - const { total, data } = await servers[0].videosCommand.list() + const { total, data } = await servers[0].videos.list() expect(total).to.equal(0) expect(data).to.be.an('array') @@ -69,7 +69,7 @@ describe('Test video blacklist', function () { } { - const body = await servers[0].searchCommand.searchVideos({ search: 'video' }) + const body = await servers[0].search.searchVideos({ search: 'video' }) expect(body.total).to.equal(0) expect(body.data).to.be.an('array') @@ -79,7 +79,7 @@ describe('Test video blacklist', function () { it('Should have the blacklisted video in videos list/search on server 2', async function () { { - const { total, data } = await servers[1].videosCommand.list() + const { total, data } = await servers[1].videos.list() expect(total).to.equal(2) expect(data).to.be.an('array') @@ -87,7 +87,7 @@ describe('Test video blacklist', function () { } { - const body = await servers[1].searchCommand.searchVideos({ search: 'video' }) + const body = await servers[1].search.searchVideos({ search: 'video' }) expect(body.total).to.equal(2) expect(body.data).to.be.an('array') @@ -181,7 +181,7 @@ describe('Test video blacklist', function () { it('Should display blacklisted videos', async function () { await blacklistVideosOnServer(servers[1]) - const { total, data } = await servers[1].videosCommand.listMyVideos() + const { total, data } = await servers[1].videos.listMyVideos() expect(total).to.equal(2) expect(data).to.have.lengthOf(2) @@ -198,7 +198,7 @@ describe('Test video blacklist', function () { let blacklist = [] it('Should not have any video in videos list on server 1', async function () { - const { total, data } = await servers[0].videosCommand.list() + const { total, data } = await servers[0].videos.list() expect(total).to.equal(0) expect(data).to.be.an('array') expect(data.length).to.equal(0) @@ -215,7 +215,7 @@ describe('Test video blacklist', function () { }) it('Should have the ex-blacklisted video in videos list on server 1', async function () { - const { total, data } = await servers[0].videosCommand.list() + const { total, data } = await servers[0].videos.list() expect(total).to.equal(1) expect(data).to.be.an('array') @@ -244,11 +244,11 @@ describe('Test video blacklist', function () { this.timeout(10000) { - const { uuid } = await servers[0].videosCommand.upload({ attributes: { name: 'Video 3' } }) + const { uuid } = await servers[0].videos.upload({ attributes: { name: 'Video 3' } }) video3UUID = uuid } { - const { uuid } = await servers[0].videosCommand.upload({ attributes: { name: 'Video 4' } }) + const { uuid } = await servers[0].videos.upload({ attributes: { name: 'Video 4' } }) video4UUID = uuid } @@ -263,12 +263,12 @@ describe('Test video blacklist', function () { await waitJobs(servers) { - const { data } = await servers[0].videosCommand.list() + const { data } = await servers[0].videos.list() expect(data.find(v => v.uuid === video3UUID)).to.be.undefined } { - const { data } = await servers[1].videosCommand.list() + const { data } = await servers[1].videos.list() expect(data.find(v => v.uuid === video3UUID)).to.not.be.undefined } }) @@ -281,7 +281,7 @@ describe('Test video blacklist', function () { await waitJobs(servers) for (const server of servers) { - const { data } = await server.videosCommand.list() + const { data } = await server.videos.list() expect(data.find(v => v.uuid === video4UUID)).to.be.undefined } }) @@ -289,12 +289,12 @@ describe('Test video blacklist', function () { it('Should have the video unfederated even after an Update AP message', async function () { this.timeout(10000) - await servers[0].videosCommand.update({ id: video4UUID, attributes: { description: 'super description' } }) + await servers[0].videos.update({ id: video4UUID, attributes: { description: 'super description' } }) await waitJobs(servers) for (const server of servers) { - const { data } = await server.videosCommand.list() + const { data } = await server.videos.list() expect(data.find(v => v.uuid === video4UUID)).to.be.undefined } }) @@ -318,7 +318,7 @@ describe('Test video blacklist', function () { await waitJobs(servers) for (const server of servers) { - const { data } = await server.videosCommand.list() + const { data } = await server.videos.list() expect(data.find(v => v.uuid === video4UUID)).to.not.be.undefined } }) @@ -348,36 +348,36 @@ describe('Test video blacklist', function () { { const user = { username: 'user_without_flag', password: 'password' } - await servers[0].usersCommand.create({ + await servers[0].users.create({ username: user.username, adminFlags: UserAdminFlag.NONE, password: user.password, role: UserRole.USER }) - userWithoutFlag = await servers[0].loginCommand.getAccessToken(user) + userWithoutFlag = await servers[0].login.getAccessToken(user) - const { videoChannels } = await servers[0].usersCommand.getMyInfo({ token: userWithoutFlag }) + const { videoChannels } = await servers[0].users.getMyInfo({ token: userWithoutFlag }) channelOfUserWithoutFlag = videoChannels[0].id } { const user = { username: 'user_with_flag', password: 'password' } - await servers[0].usersCommand.create({ + await servers[0].users.create({ username: user.username, adminFlags: UserAdminFlag.BYPASS_VIDEO_AUTO_BLACKLIST, password: user.password, role: UserRole.USER }) - userWithFlag = await servers[0].loginCommand.getAccessToken(user) + userWithFlag = await servers[0].login.getAccessToken(user) } await waitJobs(servers) }) it('Should auto blacklist a video on upload', async function () { - await servers[0].videosCommand.upload({ token: userWithoutFlag, attributes: { name: 'blacklisted' } }) + await servers[0].videos.upload({ token: userWithoutFlag, attributes: { name: 'blacklisted' } }) const body = await command.list({ type: VideoBlacklistType.AUTO_BEFORE_PUBLISHED }) expect(body.total).to.equal(1) @@ -392,7 +392,7 @@ describe('Test video blacklist', function () { name: 'URL import', channelId: channelOfUserWithoutFlag } - await servers[0].importsCommand.importVideo({ token: userWithoutFlag, attributes }) + await servers[0].imports.importVideo({ token: userWithoutFlag, attributes }) const body = await command.list({ sort: 'createdAt', type: VideoBlacklistType.AUTO_BEFORE_PUBLISHED }) expect(body.total).to.equal(2) @@ -405,7 +405,7 @@ describe('Test video blacklist', function () { name: 'Torrent import', channelId: channelOfUserWithoutFlag } - await servers[0].importsCommand.importVideo({ token: userWithoutFlag, attributes }) + await servers[0].imports.importVideo({ token: userWithoutFlag, attributes }) const body = await command.list({ sort: 'createdAt', type: VideoBlacklistType.AUTO_BEFORE_PUBLISHED }) expect(body.total).to.equal(3) @@ -413,7 +413,7 @@ describe('Test video blacklist', function () { }) it('Should not auto blacklist a video on upload if the user has the bypass blacklist flag', async function () { - await servers[0].videosCommand.upload({ token: userWithFlag, attributes: { name: 'not blacklisted' } }) + await servers[0].videos.upload({ token: userWithFlag, attributes: { name: 'not blacklisted' } }) const body = await command.list({ type: VideoBlacklistType.AUTO_BEFORE_PUBLISHED }) expect(body.total).to.equal(3) diff --git a/server/tests/api/notifications/admin-notifications.ts b/server/tests/api/notifications/admin-notifications.ts index 03fbe0b70..5a5bdb0c8 100644 --- a/server/tests/api/notifications/admin-notifications.ts +++ b/server/tests/api/notifications/admin-notifications.ts @@ -58,8 +58,8 @@ describe('Test admin notifications', function () { token: server.accessToken } - await server.pluginsCommand.install({ npmName: 'peertube-plugin-hello-world' }) - await server.pluginsCommand.install({ npmName: 'peertube-theme-background-red' }) + await server.plugins.install({ npmName: 'peertube-plugin-hello-world' }) + await server.plugins.install({ npmName: 'peertube-theme-background-red' }) }) describe('Latest PeerTube version notification', function () { @@ -118,8 +118,8 @@ describe('Test admin notifications', function () { it('Should send a notification to admins on new plugin version', async function () { this.timeout(30000) - await server.sqlCommand.setPluginVersion('hello-world', '0.0.1') - await server.sqlCommand.setPluginLatestVersion('hello-world', '0.0.1') + await server.sql.setPluginVersion('hello-world', '0.0.1') + await server.sql.setPluginLatestVersion('hello-world', '0.0.1') await wait(6000) await checkNewPluginVersion(baseParams, PluginType.PLUGIN, 'hello-world', 'presence') @@ -140,8 +140,8 @@ describe('Test admin notifications', function () { it('Should send a new notification after a new plugin release', async function () { this.timeout(30000) - await server.sqlCommand.setPluginVersion('hello-world', '0.0.1') - await server.sqlCommand.setPluginLatestVersion('hello-world', '0.0.1') + await server.sql.setPluginVersion('hello-world', '0.0.1') + await server.sql.setPluginLatestVersion('hello-world', '0.0.1') await wait(6000) expect(adminNotifications.filter(n => n.type === UserNotificationType.NEW_PEERTUBE_VERSION)).to.have.lengthOf(2) diff --git a/server/tests/api/notifications/comments-notifications.ts b/server/tests/api/notifications/comments-notifications.ts index a74b38e8a..133b6340f 100644 --- a/server/tests/api/notifications/comments-notifications.ts +++ b/server/tests/api/notifications/comments-notifications.ts @@ -52,9 +52,9 @@ describe('Test comments notifications', function () { it('Should not send a new comment notification after a comment on another video', async function () { this.timeout(20000) - const { uuid } = await servers[0].videosCommand.upload({ attributes: { name: 'super video' } }) + const { uuid } = await servers[0].videos.upload({ attributes: { name: 'super video' } }) - const created = await servers[0].commentsCommand.createThread({ videoId: uuid, text: 'comment' }) + const created = await servers[0].comments.createThread({ videoId: uuid, text: 'comment' }) const commentId = created.id await waitJobs(servers) @@ -64,9 +64,9 @@ describe('Test comments notifications', function () { it('Should not send a new comment notification if I comment my own video', async function () { this.timeout(20000) - const { uuid } = await servers[0].videosCommand.upload({ token: userToken, attributes: { name: 'super video' } }) + const { uuid } = await servers[0].videos.upload({ token: userToken, attributes: { name: 'super video' } }) - const created = await servers[0].commentsCommand.createThread({ token: userToken, videoId: uuid, text: 'comment' }) + const created = await servers[0].comments.createThread({ token: userToken, videoId: uuid, text: 'comment' }) const commentId = created.id await waitJobs(servers) @@ -76,25 +76,25 @@ describe('Test comments notifications', function () { it('Should not send a new comment notification if the account is muted', async function () { this.timeout(20000) - await servers[0].blocklistCommand.addToMyBlocklist({ token: userToken, account: 'root' }) + await servers[0].blocklist.addToMyBlocklist({ token: userToken, account: 'root' }) - const { uuid } = await servers[0].videosCommand.upload({ token: userToken, attributes: { name: 'super video' } }) + const { uuid } = await servers[0].videos.upload({ token: userToken, attributes: { name: 'super video' } }) - const created = await servers[0].commentsCommand.createThread({ videoId: uuid, text: 'comment' }) + const created = await servers[0].comments.createThread({ videoId: uuid, text: 'comment' }) const commentId = created.id await waitJobs(servers) await checkNewCommentOnMyVideo(baseParams, uuid, commentId, commentId, 'absence') - await servers[0].blocklistCommand.removeFromMyBlocklist({ token: userToken, account: 'root' }) + await servers[0].blocklist.removeFromMyBlocklist({ token: userToken, account: 'root' }) }) it('Should send a new comment notification after a local comment on my video', async function () { this.timeout(20000) - const { uuid } = await servers[0].videosCommand.upload({ token: userToken, attributes: { name: 'super video' } }) + const { uuid } = await servers[0].videos.upload({ token: userToken, attributes: { name: 'super video' } }) - const created = await servers[0].commentsCommand.createThread({ videoId: uuid, text: 'comment' }) + const created = await servers[0].comments.createThread({ videoId: uuid, text: 'comment' }) const commentId = created.id await waitJobs(servers) @@ -104,15 +104,15 @@ describe('Test comments notifications', function () { it('Should send a new comment notification after a remote comment on my video', async function () { this.timeout(20000) - const { uuid } = await servers[0].videosCommand.upload({ token: userToken, attributes: { name: 'super video' } }) + const { uuid } = await servers[0].videos.upload({ token: userToken, attributes: { name: 'super video' } }) await waitJobs(servers) - await servers[1].commentsCommand.createThread({ videoId: uuid, text: 'comment' }) + await servers[1].comments.createThread({ videoId: uuid, text: 'comment' }) await waitJobs(servers) - const { data } = await servers[0].commentsCommand.listThreads({ videoId: uuid }) + const { data } = await servers[0].comments.listThreads({ videoId: uuid }) expect(data).to.have.lengthOf(1) const commentId = data[0].id @@ -122,11 +122,11 @@ describe('Test comments notifications', function () { it('Should send a new comment notification after a local reply on my video', async function () { this.timeout(20000) - const { uuid } = await servers[0].videosCommand.upload({ token: userToken, attributes: { name: 'super video' } }) + const { uuid } = await servers[0].videos.upload({ token: userToken, attributes: { name: 'super video' } }) - const { id: threadId } = await servers[0].commentsCommand.createThread({ videoId: uuid, text: 'comment' }) + const { id: threadId } = await servers[0].comments.createThread({ videoId: uuid, text: 'comment' }) - const { id: commentId } = await servers[0].commentsCommand.addReply({ videoId: uuid, toCommentId: threadId, text: 'reply' }) + const { id: commentId } = await servers[0].comments.addReply({ videoId: uuid, toCommentId: threadId, text: 'reply' }) await waitJobs(servers) await checkNewCommentOnMyVideo(baseParams, uuid, commentId, threadId, 'presence') @@ -135,22 +135,22 @@ describe('Test comments notifications', function () { it('Should send a new comment notification after a remote reply on my video', async function () { this.timeout(20000) - const { uuid } = await servers[0].videosCommand.upload({ token: userToken, attributes: { name: 'super video' } }) + const { uuid } = await servers[0].videos.upload({ token: userToken, attributes: { name: 'super video' } }) await waitJobs(servers) { - const created = await servers[1].commentsCommand.createThread({ videoId: uuid, text: 'comment' }) + const created = await servers[1].comments.createThread({ videoId: uuid, text: 'comment' }) const threadId = created.id - await servers[1].commentsCommand.addReply({ videoId: uuid, toCommentId: threadId, text: 'reply' }) + await servers[1].comments.addReply({ videoId: uuid, toCommentId: threadId, text: 'reply' }) } await waitJobs(servers) - const { data } = await servers[0].commentsCommand.listThreads({ videoId: uuid }) + const { data } = await servers[0].comments.listThreads({ videoId: uuid }) expect(data).to.have.lengthOf(1) const threadId = data[0].id - const tree = await servers[0].commentsCommand.getThread({ videoId: uuid, threadId }) + const tree = await servers[0].comments.getThread({ videoId: uuid, threadId }) expect(tree.children).to.have.lengthOf(1) const commentId = tree.children[0].comment.id @@ -161,9 +161,9 @@ describe('Test comments notifications', function () { it('Should convert markdown in comment to html', async function () { this.timeout(20000) - const { uuid } = await servers[0].videosCommand.upload({ token: userToken, attributes: { name: 'cool video' } }) + const { uuid } = await servers[0].videos.upload({ token: userToken, attributes: { name: 'cool video' } }) - await servers[0].commentsCommand.createThread({ videoId: uuid, text: commentText }) + await servers[0].comments.createThread({ videoId: uuid, text: commentText }) await waitJobs(servers) @@ -183,16 +183,16 @@ describe('Test comments notifications', function () { token: userToken } - await servers[0].usersCommand.updateMe({ displayName: 'super root name' }) - await servers[1].usersCommand.updateMe({ displayName: 'super root 2 name' }) + await servers[0].users.updateMe({ displayName: 'super root name' }) + await servers[1].users.updateMe({ displayName: 'super root 2 name' }) }) it('Should not send a new mention comment notification if I mention the video owner', async function () { this.timeout(10000) - const { uuid } = await servers[0].videosCommand.upload({ token: userToken, attributes: { name: 'super video' } }) + const { uuid } = await servers[0].videos.upload({ token: userToken, attributes: { name: 'super video' } }) - const { id: commentId } = await servers[0].commentsCommand.createThread({ videoId: uuid, text: '@user_1 hello' }) + const { id: commentId } = await servers[0].comments.createThread({ videoId: uuid, text: '@user_1 hello' }) await waitJobs(servers) await checkCommentMention(baseParams, uuid, commentId, commentId, 'super root name', 'absence') @@ -201,9 +201,9 @@ describe('Test comments notifications', function () { it('Should not send a new mention comment notification if I mention myself', async function () { this.timeout(10000) - const { uuid } = await servers[0].videosCommand.upload({ attributes: { name: 'super video' } }) + const { uuid } = await servers[0].videos.upload({ attributes: { name: 'super video' } }) - const { id: commentId } = await servers[0].commentsCommand.createThread({ token: userToken, videoId: uuid, text: '@user_1 hello' }) + const { id: commentId } = await servers[0].comments.createThread({ token: userToken, videoId: uuid, text: '@user_1 hello' }) await waitJobs(servers) await checkCommentMention(baseParams, uuid, commentId, commentId, 'super root name', 'absence') @@ -212,25 +212,25 @@ describe('Test comments notifications', function () { it('Should not send a new mention notification if the account is muted', async function () { this.timeout(10000) - await servers[0].blocklistCommand.addToMyBlocklist({ token: userToken, account: 'root' }) + await servers[0].blocklist.addToMyBlocklist({ token: userToken, account: 'root' }) - const { uuid } = await servers[0].videosCommand.upload({ attributes: { name: 'super video' } }) + const { uuid } = await servers[0].videos.upload({ attributes: { name: 'super video' } }) - const { id: commentId } = await servers[0].commentsCommand.createThread({ videoId: uuid, text: '@user_1 hello' }) + const { id: commentId } = await servers[0].comments.createThread({ videoId: uuid, text: '@user_1 hello' }) await waitJobs(servers) await checkCommentMention(baseParams, uuid, commentId, commentId, 'super root name', 'absence') - await servers[0].blocklistCommand.removeFromMyBlocklist({ token: userToken, account: 'root' }) + await servers[0].blocklist.removeFromMyBlocklist({ token: userToken, account: 'root' }) }) it('Should not send a new mention notification if the remote account mention a local account', async function () { this.timeout(20000) - const { uuid } = await servers[0].videosCommand.upload({ attributes: { name: 'super video' } }) + const { uuid } = await servers[0].videos.upload({ attributes: { name: 'super video' } }) await waitJobs(servers) - const { id: threadId } = await servers[1].commentsCommand.createThread({ videoId: uuid, text: '@user_1 hello' }) + const { id: threadId } = await servers[1].comments.createThread({ videoId: uuid, text: '@user_1 hello' }) await waitJobs(servers) await checkCommentMention(baseParams, uuid, threadId, threadId, 'super root 2 name', 'absence') @@ -239,14 +239,14 @@ describe('Test comments notifications', function () { it('Should send a new mention notification after local comments', async function () { this.timeout(10000) - const { uuid } = await servers[0].videosCommand.upload({ attributes: { name: 'super video' } }) + const { uuid } = await servers[0].videos.upload({ attributes: { name: 'super video' } }) - const { id: threadId } = await servers[0].commentsCommand.createThread({ videoId: uuid, text: '@user_1 hellotext: 1' }) + const { id: threadId } = await servers[0].comments.createThread({ videoId: uuid, text: '@user_1 hellotext: 1' }) await waitJobs(servers) await checkCommentMention(baseParams, uuid, threadId, threadId, 'super root name', 'presence') - const { id: commentId } = await servers[0].commentsCommand.addReply({ videoId: uuid, toCommentId: threadId, text: 'hello 2 @user_1' }) + const { id: commentId } = await servers[0].comments.addReply({ videoId: uuid, toCommentId: threadId, text: 'hello 2 @user_1' }) await waitJobs(servers) await checkCommentMention(baseParams, uuid, commentId, threadId, 'super root name', 'presence') @@ -255,27 +255,27 @@ describe('Test comments notifications', function () { it('Should send a new mention notification after remote comments', async function () { this.timeout(20000) - const { uuid } = await servers[0].videosCommand.upload({ attributes: { name: 'super video' } }) + const { uuid } = await servers[0].videos.upload({ attributes: { name: 'super video' } }) await waitJobs(servers) const text1 = `hello @user_1@localhost:${servers[0].port} 1` - const { id: server2ThreadId } = await servers[1].commentsCommand.createThread({ videoId: uuid, text: text1 }) + const { id: server2ThreadId } = await servers[1].comments.createThread({ videoId: uuid, text: text1 }) await waitJobs(servers) - const { data } = await servers[0].commentsCommand.listThreads({ videoId: uuid }) + const { data } = await servers[0].comments.listThreads({ videoId: uuid }) expect(data).to.have.lengthOf(1) const server1ThreadId = data[0].id await checkCommentMention(baseParams, uuid, server1ThreadId, server1ThreadId, 'super root 2 name', 'presence') const text2 = `@user_1@localhost:${servers[0].port} hello 2 @root@localhost:${servers[0].port}` - await servers[1].commentsCommand.addReply({ videoId: uuid, toCommentId: server2ThreadId, text: text2 }) + await servers[1].comments.addReply({ videoId: uuid, toCommentId: server2ThreadId, text: text2 }) await waitJobs(servers) - const tree = await servers[0].commentsCommand.getThread({ videoId: uuid, threadId: server1ThreadId }) + const tree = await servers[0].comments.getThread({ videoId: uuid, threadId: server1ThreadId }) expect(tree.children).to.have.lengthOf(1) const commentId = tree.children[0].comment.id @@ -286,11 +286,11 @@ describe('Test comments notifications', function () { it('Should convert markdown in comment to html', async function () { this.timeout(10000) - const { uuid } = await servers[0].videosCommand.upload({ attributes: { name: 'super video' } }) + const { uuid } = await servers[0].videos.upload({ attributes: { name: 'super video' } }) - const { id: threadId } = await servers[0].commentsCommand.createThread({ videoId: uuid, text: '@user_1 hello 1' }) + const { id: threadId } = await servers[0].comments.createThread({ videoId: uuid, text: '@user_1 hello 1' }) - await servers[0].commentsCommand.addReply({ videoId: uuid, toCommentId: threadId, text: '@user_1 ' + commentText }) + await servers[0].comments.addReply({ videoId: uuid, toCommentId: threadId, text: '@user_1 ' + commentText }) await waitJobs(servers) diff --git a/server/tests/api/notifications/moderation-notifications.ts b/server/tests/api/notifications/moderation-notifications.ts index 91a2b4fa5..e7c5badd2 100644 --- a/server/tests/api/notifications/moderation-notifications.ts +++ b/server/tests/api/notifications/moderation-notifications.ts @@ -62,9 +62,9 @@ describe('Test moderation notifications', function () { this.timeout(20000) const name = 'video for abuse ' + buildUUID() - const video = await servers[0].videosCommand.upload({ token: userAccessToken, attributes: { name } }) + const video = await servers[0].videos.upload({ token: userAccessToken, attributes: { name } }) - await servers[0].abusesCommand.report({ videoId: video.id, reason: 'super reason' }) + await servers[0].abuses.report({ videoId: video.id, reason: 'super reason' }) await waitJobs(servers) await checkNewVideoAbuseForModerators(baseParams, video.uuid, name, 'presence') @@ -74,12 +74,12 @@ describe('Test moderation notifications', function () { this.timeout(20000) const name = 'video for abuse ' + buildUUID() - const video = await servers[0].videosCommand.upload({ token: userAccessToken, attributes: { name } }) + const video = await servers[0].videos.upload({ token: userAccessToken, attributes: { name } }) await waitJobs(servers) - const videoId = await servers[1].videosCommand.getId({ uuid: video.uuid }) - await servers[1].abusesCommand.report({ videoId, reason: 'super reason' }) + const videoId = await servers[1].videos.getId({ uuid: video.uuid }) + await servers[1].abuses.report({ videoId, reason: 'super reason' }) await waitJobs(servers) await checkNewVideoAbuseForModerators(baseParams, video.uuid, name, 'presence') @@ -89,8 +89,8 @@ describe('Test moderation notifications', function () { this.timeout(20000) const name = 'video for abuse ' + buildUUID() - const video = await servers[0].videosCommand.upload({ token: userAccessToken, attributes: { name } }) - const comment = await servers[0].commentsCommand.createThread({ + const video = await servers[0].videos.upload({ token: userAccessToken, attributes: { name } }) + const comment = await servers[0].comments.createThread({ token: userAccessToken, videoId: video.id, text: 'comment abuse ' + buildUUID() @@ -98,7 +98,7 @@ describe('Test moderation notifications', function () { await waitJobs(servers) - await servers[0].abusesCommand.report({ commentId: comment.id, reason: 'super reason' }) + await servers[0].abuses.report({ commentId: comment.id, reason: 'super reason' }) await waitJobs(servers) await checkNewCommentAbuseForModerators(baseParams, video.uuid, name, 'presence') @@ -108,9 +108,9 @@ describe('Test moderation notifications', function () { this.timeout(20000) const name = 'video for abuse ' + buildUUID() - const video = await servers[0].videosCommand.upload({ token: userAccessToken, attributes: { name } }) + const video = await servers[0].videos.upload({ token: userAccessToken, attributes: { name } }) - await servers[0].commentsCommand.createThread({ + await servers[0].comments.createThread({ token: userAccessToken, videoId: video.id, text: 'comment abuse ' + buildUUID() @@ -118,9 +118,9 @@ describe('Test moderation notifications', function () { await waitJobs(servers) - const { data } = await servers[1].commentsCommand.listThreads({ videoId: video.uuid }) + const { data } = await servers[1].comments.listThreads({ videoId: video.uuid }) const commentId = data[0].id - await servers[1].abusesCommand.report({ commentId, reason: 'super reason' }) + await servers[1].abuses.report({ commentId, reason: 'super reason' }) await waitJobs(servers) await checkNewCommentAbuseForModerators(baseParams, video.uuid, name, 'presence') @@ -130,10 +130,10 @@ describe('Test moderation notifications', function () { this.timeout(20000) const username = 'user' + new Date().getTime() - const { account } = await servers[0].usersCommand.create({ username, password: 'donald' }) + const { account } = await servers[0].users.create({ username, password: 'donald' }) const accountId = account.id - await servers[0].abusesCommand.report({ accountId, reason: 'super reason' }) + await servers[0].abuses.report({ accountId, reason: 'super reason' }) await waitJobs(servers) await checkNewAccountAbuseForModerators(baseParams, username, 'presence') @@ -143,13 +143,13 @@ describe('Test moderation notifications', function () { this.timeout(20000) const username = 'user' + new Date().getTime() - const tmpToken = await servers[0].usersCommand.generateUserAndToken(username) - await servers[0].videosCommand.upload({ token: tmpToken, attributes: { name: 'super video' } }) + const tmpToken = await servers[0].users.generateUserAndToken(username) + await servers[0].videos.upload({ token: tmpToken, attributes: { name: 'super video' } }) await waitJobs(servers) - const account = await servers[1].accountsCommand.get({ accountName: username + '@' + servers[0].host }) - await servers[1].abusesCommand.report({ accountId: account.id, reason: 'super reason' }) + const account = await servers[1].accounts.get({ accountName: username + '@' + servers[0].host }) + await servers[1].abuses.report({ accountId: account.id, reason: 'super reason' }) await waitJobs(servers) await checkNewAccountAbuseForModerators(baseParams, username, 'presence') @@ -169,16 +169,16 @@ describe('Test moderation notifications', function () { } const name = 'abuse ' + buildUUID() - const video = await servers[0].videosCommand.upload({ token: userAccessToken, attributes: { name } }) + const video = await servers[0].videos.upload({ token: userAccessToken, attributes: { name } }) - const body = await servers[0].abusesCommand.report({ token: userAccessToken, videoId: video.id, reason: 'super reason' }) + const body = await servers[0].abuses.report({ token: userAccessToken, videoId: video.id, reason: 'super reason' }) abuseId = body.abuse.id }) it('Should send a notification to reporter if the abuse has been accepted', async function () { this.timeout(10000) - await servers[0].abusesCommand.update({ abuseId, body: { state: AbuseState.ACCEPTED } }) + await servers[0].abuses.update({ abuseId, body: { state: AbuseState.ACCEPTED } }) await waitJobs(servers) await checkAbuseStateChange(baseParams, abuseId, AbuseState.ACCEPTED, 'presence') @@ -187,7 +187,7 @@ describe('Test moderation notifications', function () { it('Should send a notification to reporter if the abuse has been rejected', async function () { this.timeout(10000) - await servers[0].abusesCommand.update({ abuseId, body: { state: AbuseState.REJECTED } }) + await servers[0].abuses.update({ abuseId, body: { state: AbuseState.REJECTED } }) await waitJobs(servers) await checkAbuseStateChange(baseParams, abuseId, AbuseState.REJECTED, 'presence') @@ -216,15 +216,15 @@ describe('Test moderation notifications', function () { } const name = 'abuse ' + buildUUID() - const video = await servers[0].videosCommand.upload({ token: userAccessToken, attributes: { name } }) + const video = await servers[0].videos.upload({ token: userAccessToken, attributes: { name } }) { - const body = await servers[0].abusesCommand.report({ token: userAccessToken, videoId: video.id, reason: 'super reason' }) + const body = await servers[0].abuses.report({ token: userAccessToken, videoId: video.id, reason: 'super reason' }) abuseId = body.abuse.id } { - const body = await servers[0].abusesCommand.report({ token: userAccessToken, videoId: video.id, reason: 'super reason 2' }) + const body = await servers[0].abuses.report({ token: userAccessToken, videoId: video.id, reason: 'super reason 2' }) abuseId2 = body.abuse.id } }) @@ -233,7 +233,7 @@ describe('Test moderation notifications', function () { this.timeout(10000) const message = 'my super message to users' - await servers[0].abusesCommand.addMessage({ abuseId, message }) + await servers[0].abuses.addMessage({ abuseId, message }) await waitJobs(servers) await checkNewAbuseMessage(baseParamsUser, abuseId, message, 'user_1@example.com', 'presence') @@ -243,7 +243,7 @@ describe('Test moderation notifications', function () { this.timeout(10000) const message = 'my super message that should not be sent to the admin' - await servers[0].abusesCommand.addMessage({ abuseId, message }) + await servers[0].abuses.addMessage({ abuseId, message }) await waitJobs(servers) await checkNewAbuseMessage(baseParamsAdmin, abuseId, message, 'admin' + servers[0].internalServerNumber + '@example.com', 'absence') @@ -253,7 +253,7 @@ describe('Test moderation notifications', function () { this.timeout(10000) const message = 'my super message to moderators' - await servers[0].abusesCommand.addMessage({ token: userAccessToken, abuseId: abuseId2, message }) + await servers[0].abuses.addMessage({ token: userAccessToken, abuseId: abuseId2, message }) await waitJobs(servers) await checkNewAbuseMessage(baseParamsAdmin, abuseId2, message, 'admin' + servers[0].internalServerNumber + '@example.com', 'presence') @@ -263,7 +263,7 @@ describe('Test moderation notifications', function () { this.timeout(10000) const message = 'my super message that should not be sent to reporter' - await servers[0].abusesCommand.addMessage({ token: userAccessToken, abuseId: abuseId2, message }) + await servers[0].abuses.addMessage({ token: userAccessToken, abuseId: abuseId2, message }) await waitJobs(servers) await checkNewAbuseMessage(baseParamsUser, abuseId2, message, 'user_1@example.com', 'absence') @@ -286,9 +286,9 @@ describe('Test moderation notifications', function () { this.timeout(10000) const name = 'video for abuse ' + buildUUID() - const { uuid } = await servers[0].videosCommand.upload({ token: userAccessToken, attributes: { name } }) + const { uuid } = await servers[0].videos.upload({ token: userAccessToken, attributes: { name } }) - await servers[0].blacklistCommand.add({ videoId: uuid }) + await servers[0].blacklist.add({ videoId: uuid }) await waitJobs(servers) await checkNewBlacklistOnMyVideo(baseParams, uuid, name, 'blacklist') @@ -298,12 +298,12 @@ describe('Test moderation notifications', function () { this.timeout(10000) const name = 'video for abuse ' + buildUUID() - const { uuid } = await servers[0].videosCommand.upload({ token: userAccessToken, attributes: { name } }) + const { uuid } = await servers[0].videos.upload({ token: userAccessToken, attributes: { name } }) - await servers[0].blacklistCommand.add({ videoId: uuid }) + await servers[0].blacklist.add({ videoId: uuid }) await waitJobs(servers) - await servers[0].blacklistCommand.remove({ videoId: uuid }) + await servers[0].blacklist.remove({ videoId: uuid }) await waitJobs(servers) await wait(500) @@ -326,7 +326,7 @@ describe('Test moderation notifications', function () { it('Should send a notification only to moderators when a user registers on the instance', async function () { this.timeout(10000) - await servers[0].usersCommand.register({ username: 'user_45' }) + await servers[0].users.register({ username: 'user_45' }) await waitJobs(servers) @@ -368,7 +368,7 @@ describe('Test moderation notifications', function () { it('Should send a notification only to admin when there is a new instance follower', async function () { this.timeout(20000) - await servers[2].followsCommand.follow({ targets: [ servers[0].url ] }) + await servers[2].follows.follow({ targets: [ servers[0].url ] }) await waitJobs(servers) @@ -381,7 +381,7 @@ describe('Test moderation notifications', function () { it('Should send a notification on auto follow back', async function () { this.timeout(40000) - await servers[2].followsCommand.unfollow({ target: servers[0] }) + await servers[2].follows.unfollow({ target: servers[0] }) await waitJobs(servers) const config = { @@ -391,9 +391,9 @@ describe('Test moderation notifications', function () { } } } - await servers[0].configCommand.updateCustomSubConfig({ newConfig: config }) + await servers[0].config.updateCustomSubConfig({ newConfig: config }) - await servers[2].followsCommand.follow({ targets: [ servers[0].url ] }) + await servers[2].follows.follow({ targets: [ servers[0].url ] }) await waitJobs(servers) @@ -405,16 +405,16 @@ describe('Test moderation notifications', function () { await checkAutoInstanceFollowing({ ...baseParams, ...userOverride }, followerHost, followingHost, 'absence') config.followings.instance.autoFollowBack.enabled = false - await servers[0].configCommand.updateCustomSubConfig({ newConfig: config }) - await servers[0].followsCommand.unfollow({ target: servers[2] }) - await servers[2].followsCommand.unfollow({ target: servers[0] }) + await servers[0].config.updateCustomSubConfig({ newConfig: config }) + await servers[0].follows.unfollow({ target: servers[2] }) + await servers[2].follows.unfollow({ target: servers[0] }) }) it('Should send a notification on auto instances index follow', async function () { this.timeout(30000) - await servers[0].followsCommand.unfollow({ target: servers[1] }) + await servers[0].follows.unfollow({ target: servers[1] }) - await servers[0].configCommand.updateCustomSubConfig({ newConfig: config }) + await servers[0].config.updateCustomSubConfig({ newConfig: config }) await wait(5000) await waitJobs(servers) @@ -424,8 +424,8 @@ describe('Test moderation notifications', function () { await checkAutoInstanceFollowing(baseParams, followerHost, followingHost, 'presence') config.followings.instance.autoFollowIndex.enabled = false - await servers[0].configCommand.updateCustomSubConfig({ newConfig: config }) - await servers[0].followsCommand.unfollow({ target: servers[1] }) + await servers[0].config.updateCustomSubConfig({ newConfig: config }) + await servers[0].follows.unfollow({ target: servers[1] }) }) }) @@ -460,7 +460,7 @@ describe('Test moderation notifications', function () { token: userAccessToken } - currentCustomConfig = await servers[0].configCommand.getCustomConfig() + currentCustomConfig = await servers[0].config.getCustomConfig() const autoBlacklistTestsCustomConfig = { ...currentCustomConfig, @@ -476,10 +476,10 @@ describe('Test moderation notifications', function () { // enable transcoding otherwise own publish notification after transcoding not expected autoBlacklistTestsCustomConfig.transcoding.enabled = true - await servers[0].configCommand.updateCustomConfig({ newCustomConfig: autoBlacklistTestsCustomConfig }) + await servers[0].config.updateCustomConfig({ newCustomConfig: autoBlacklistTestsCustomConfig }) - await servers[0].subscriptionsCommand.add({ targetUri: 'user_1_channel@localhost:' + servers[0].port }) - await servers[1].subscriptionsCommand.add({ targetUri: 'user_1_channel@localhost:' + servers[0].port }) + await servers[0].subscriptions.add({ targetUri: 'user_1_channel@localhost:' + servers[0].port }) + await servers[1].subscriptions.add({ targetUri: 'user_1_channel@localhost:' + servers[0].port }) }) @@ -487,7 +487,7 @@ describe('Test moderation notifications', function () { this.timeout(40000) videoName = 'video with auto-blacklist ' + buildUUID() - const { uuid } = await servers[0].videosCommand.upload({ token: userAccessToken, attributes: { name: videoName } }) + const { uuid } = await servers[0].videos.upload({ token: userAccessToken, attributes: { name: videoName } }) videoUUID = uuid await waitJobs(servers) @@ -509,7 +509,7 @@ describe('Test moderation notifications', function () { it('Should send video published and unblacklist after video unblacklisted', async function () { this.timeout(40000) - await servers[0].blacklistCommand.remove({ videoId: videoUUID }) + await servers[0].blacklist.remove({ videoId: videoUUID }) await waitJobs(servers) @@ -543,9 +543,9 @@ describe('Test moderation notifications', function () { } } - const { uuid } = await servers[0].videosCommand.upload({ token: userAccessToken, attributes }) + const { uuid } = await servers[0].videos.upload({ token: userAccessToken, attributes }) - await servers[0].blacklistCommand.remove({ videoId: uuid }) + await servers[0].blacklist.remove({ videoId: uuid }) await waitJobs(servers) await checkNewBlacklistOnMyVideo(userBaseParams, uuid, name, 'unblacklist') @@ -575,7 +575,7 @@ describe('Test moderation notifications', function () { } } - const { uuid } = await servers[0].videosCommand.upload({ token: userAccessToken, attributes }) + const { uuid } = await servers[0].videos.upload({ token: userAccessToken, attributes }) await wait(6000) await checkVideoIsPublished(userBaseParams, name, uuid, 'absence') @@ -589,17 +589,17 @@ describe('Test moderation notifications', function () { const name = 'video without auto-blacklist ' + buildUUID() // admin with blacklist right will not be auto-blacklisted - const { uuid } = await servers[0].videosCommand.upload({ attributes: { name } }) + const { uuid } = await servers[0].videos.upload({ attributes: { name } }) await waitJobs(servers) await checkVideoAutoBlacklistForModerators(adminBaseParamsServer1, uuid, name, 'absence') }) after(async () => { - await servers[0].configCommand.updateCustomConfig({ newCustomConfig: currentCustomConfig }) + await servers[0].config.updateCustomConfig({ newCustomConfig: currentCustomConfig }) - await servers[0].subscriptionsCommand.remove({ uri: 'user_1_channel@localhost:' + servers[0].port }) - await servers[1].subscriptionsCommand.remove({ uri: 'user_1_channel@localhost:' + servers[0].port }) + await servers[0].subscriptions.remove({ uri: 'user_1_channel@localhost:' + servers[0].port }) + await servers[1].subscriptions.remove({ uri: 'user_1_channel@localhost:' + servers[0].port }) }) }) diff --git a/server/tests/api/notifications/notifications-api.ts b/server/tests/api/notifications/notifications-api.ts index 41e1b8015..647d783b5 100644 --- a/server/tests/api/notifications/notifications-api.ts +++ b/server/tests/api/notifications/notifications-api.ts @@ -31,10 +31,10 @@ describe('Test notifications API', function () { userNotifications = res.userNotifications server = res.servers[0] - await server.subscriptionsCommand.add({ token: userToken, targetUri: 'root_channel@localhost:' + server.port }) + await server.subscriptions.add({ token: userToken, targetUri: 'root_channel@localhost:' + server.port }) for (let i = 0; i < 10; i++) { - await server.videosCommand.randomUpload({ wait: false }) + await server.videos.randomUpload({ wait: false }) } await waitJobs([ server ]) @@ -43,14 +43,14 @@ describe('Test notifications API', function () { describe('Mark as read', function () { it('Should mark as read some notifications', async function () { - const { data } = await server.notificationsCommand.list({ token: userToken, start: 2, count: 3 }) + const { data } = await server.notifications.list({ token: userToken, start: 2, count: 3 }) const ids = data.map(n => n.id) - await server.notificationsCommand.markAsRead({ token: userToken, ids }) + await server.notifications.markAsRead({ token: userToken, ids }) }) it('Should have the notifications marked as read', async function () { - const { data } = await server.notificationsCommand.list({ token: userToken, start: 0, count: 10 }) + const { data } = await server.notifications.list({ token: userToken, start: 0, count: 10 }) expect(data[0].read).to.be.false expect(data[1].read).to.be.false @@ -61,7 +61,7 @@ describe('Test notifications API', function () { }) it('Should only list read notifications', async function () { - const { data } = await server.notificationsCommand.list({ token: userToken, start: 0, count: 10, unread: false }) + const { data } = await server.notifications.list({ token: userToken, start: 0, count: 10, unread: false }) for (const notification of data) { expect(notification.read).to.be.true @@ -69,7 +69,7 @@ describe('Test notifications API', function () { }) it('Should only list unread notifications', async function () { - const { data } = await server.notificationsCommand.list({ token: userToken, start: 0, count: 10, unread: true }) + const { data } = await server.notifications.list({ token: userToken, start: 0, count: 10, unread: true }) for (const notification of data) { expect(notification.read).to.be.false @@ -77,9 +77,9 @@ describe('Test notifications API', function () { }) it('Should mark as read all notifications', async function () { - await server.notificationsCommand.markAsReadAll({ token: userToken }) + await server.notifications.markAsReadAll({ token: userToken }) - const body = await server.notificationsCommand.list({ token: userToken, start: 0, count: 10, unread: true }) + const body = await server.notifications.list({ token: userToken, start: 0, count: 10, unread: true }) expect(body.total).to.equal(0) expect(body.data).to.have.lengthOf(0) @@ -101,17 +101,17 @@ describe('Test notifications API', function () { it('Should not have notifications', async function () { this.timeout(20000) - await server.notificationsCommand.updateMySettings({ + await server.notifications.updateMySettings({ token: userToken, settings: { ...getAllNotificationsSettings(), newVideoFromSubscription: UserNotificationSettingValue.NONE } }) { - const info = await server.usersCommand.getMyInfo({ token: userToken }) + const info = await server.users.getMyInfo({ token: userToken }) expect(info.notificationSettings.newVideoFromSubscription).to.equal(UserNotificationSettingValue.NONE) } - const { name, uuid } = await server.videosCommand.randomUpload() + const { name, uuid } = await server.videos.randomUpload() const check = { web: true, mail: true } await checkNewVideoFromSubscription({ ...baseParams, check }, name, uuid, 'absence') @@ -120,17 +120,17 @@ describe('Test notifications API', function () { it('Should only have web notifications', async function () { this.timeout(20000) - await server.notificationsCommand.updateMySettings({ + await server.notifications.updateMySettings({ token: userToken, settings: { ...getAllNotificationsSettings(), newVideoFromSubscription: UserNotificationSettingValue.WEB } }) { - const info = await server.usersCommand.getMyInfo({ token: userToken }) + const info = await server.users.getMyInfo({ token: userToken }) expect(info.notificationSettings.newVideoFromSubscription).to.equal(UserNotificationSettingValue.WEB) } - const { name, uuid } = await server.videosCommand.randomUpload() + const { name, uuid } = await server.videos.randomUpload() { const check = { mail: true, web: false } @@ -146,17 +146,17 @@ describe('Test notifications API', function () { it('Should only have mail notifications', async function () { this.timeout(20000) - await server.notificationsCommand.updateMySettings({ + await server.notifications.updateMySettings({ token: userToken, settings: { ...getAllNotificationsSettings(), newVideoFromSubscription: UserNotificationSettingValue.EMAIL } }) { - const info = await server.usersCommand.getMyInfo({ token: userToken }) + const info = await server.users.getMyInfo({ token: userToken }) expect(info.notificationSettings.newVideoFromSubscription).to.equal(UserNotificationSettingValue.EMAIL) } - const { name, uuid } = await server.videosCommand.randomUpload() + const { name, uuid } = await server.videos.randomUpload() { const check = { mail: false, web: true } @@ -172,7 +172,7 @@ describe('Test notifications API', function () { it('Should have email and web notifications', async function () { this.timeout(20000) - await server.notificationsCommand.updateMySettings({ + await server.notifications.updateMySettings({ token: userToken, settings: { ...getAllNotificationsSettings(), @@ -181,13 +181,13 @@ describe('Test notifications API', function () { }) { - const info = await server.usersCommand.getMyInfo({ token: userToken }) + const info = await server.users.getMyInfo({ token: userToken }) expect(info.notificationSettings.newVideoFromSubscription).to.equal( UserNotificationSettingValue.WEB | UserNotificationSettingValue.EMAIL ) } - const { name, uuid } = await server.videosCommand.randomUpload() + const { name, uuid } = await server.videos.randomUpload() await checkNewVideoFromSubscription(baseParams, name, uuid, 'presence') }) diff --git a/server/tests/api/notifications/user-notifications.ts b/server/tests/api/notifications/user-notifications.ts index 4db8c1576..53f8c7594 100644 --- a/server/tests/api/notifications/user-notifications.ts +++ b/server/tests/api/notifications/user-notifications.ts @@ -61,7 +61,7 @@ describe('Test user notifications', function () { await uploadRandomVideoOnServers(servers, 1) - const notification = await servers[0].notificationsCommand.getLastest({ token: userAccessToken }) + const notification = await servers[0].notifications.getLastest({ token: userAccessToken }) expect(notification).to.be.undefined expect(emails).to.have.lengthOf(0) @@ -71,7 +71,7 @@ describe('Test user notifications', function () { it('Should send a new video notification if the user follows the local video publisher', async function () { this.timeout(15000) - await servers[0].subscriptionsCommand.add({ token: userAccessToken, targetUri: 'root_channel@localhost:' + servers[0].port }) + await servers[0].subscriptions.add({ token: userAccessToken, targetUri: 'root_channel@localhost:' + servers[0].port }) await waitJobs(servers) const { name, uuid } = await uploadRandomVideoOnServers(servers, 1) @@ -81,7 +81,7 @@ describe('Test user notifications', function () { it('Should send a new video notification from a remote account', async function () { this.timeout(150000) // Server 2 has transcoding enabled - await servers[0].subscriptionsCommand.add({ token: userAccessToken, targetUri: 'root_channel@localhost:' + servers[1].port }) + await servers[0].subscriptions.add({ token: userAccessToken, targetUri: 'root_channel@localhost:' + servers[1].port }) await waitJobs(servers) const { name, uuid } = await uploadRandomVideoOnServers(servers, 2) @@ -153,7 +153,7 @@ describe('Test user notifications', function () { await checkNewVideoFromSubscription(baseParams, name, uuid, 'absence') - await servers[0].videosCommand.update({ id: uuid, attributes: { privacy: VideoPrivacy.PUBLIC } }) + await servers[0].videos.update({ id: uuid, attributes: { privacy: VideoPrivacy.PUBLIC } }) await waitJobs(servers) await checkNewVideoFromSubscription(baseParams, name, uuid, 'presence') @@ -167,7 +167,7 @@ describe('Test user notifications', function () { await checkNewVideoFromSubscription(baseParams, name, uuid, 'absence') - await servers[1].videosCommand.update({ id: uuid, attributes: { privacy: VideoPrivacy.PUBLIC } }) + await servers[1].videos.update({ id: uuid, attributes: { privacy: VideoPrivacy.PUBLIC } }) await waitJobs(servers) await checkNewVideoFromSubscription(baseParams, name, uuid, 'presence') @@ -179,7 +179,7 @@ describe('Test user notifications', function () { const data = { privacy: VideoPrivacy.PRIVATE } const { name, uuid } = await uploadRandomVideoOnServers(servers, 1, data) - await servers[0].videosCommand.update({ id: uuid, attributes: { privacy: VideoPrivacy.UNLISTED } }) + await servers[0].videos.update({ id: uuid, attributes: { privacy: VideoPrivacy.UNLISTED } }) await checkNewVideoFromSubscription(baseParams, name, uuid, 'absence') }) @@ -190,7 +190,7 @@ describe('Test user notifications', function () { const data = { privacy: VideoPrivacy.PRIVATE } const { name, uuid } = await uploadRandomVideoOnServers(servers, 2, data) - await servers[1].videosCommand.update({ id: uuid, attributes: { privacy: VideoPrivacy.UNLISTED } }) + await servers[1].videos.update({ id: uuid, attributes: { privacy: VideoPrivacy.UNLISTED } }) await waitJobs(servers) await checkNewVideoFromSubscription(baseParams, name, uuid, 'absence') @@ -207,7 +207,7 @@ describe('Test user notifications', function () { privacy: VideoPrivacy.PUBLIC, targetUrl: ImportsCommand.getGoodVideoUrl() } - const { video } = await servers[0].importsCommand.importVideo({ attributes }) + const { video } = await servers[0].imports.importVideo({ attributes }) await waitJobs(servers) @@ -242,7 +242,7 @@ describe('Test user notifications', function () { await uploadRandomVideoOnServers(servers, 2, { waitTranscoding: false }) await waitJobs(servers) - const notification = await servers[0].notificationsCommand.getLastest({ token: userAccessToken }) + const notification = await servers[0].notifications.getLastest({ token: userAccessToken }) if (notification) { expect(notification.type).to.not.equal(UserNotificationType.MY_VIDEO_PUBLISHED) } @@ -278,7 +278,7 @@ describe('Test user notifications', function () { targetUrl: ImportsCommand.getGoodVideoUrl(), waitTranscoding: true } - const { video } = await servers[1].importsCommand.importVideo({ attributes }) + const { video } = await servers[1].imports.importVideo({ attributes }) await waitJobs(servers) await checkVideoIsPublished(baseParams, name, video.uuid, 'presence') @@ -345,7 +345,7 @@ describe('Test user notifications', function () { privacy: VideoPrivacy.PRIVATE, targetUrl: ImportsCommand.getBadVideoUrl() } - const { video } = await servers[0].importsCommand.importVideo({ attributes }) + const { video } = await servers[0].imports.importVideo({ attributes }) await waitJobs(servers) await checkMyVideoImportIsFinished(baseParams, name, video.uuid, ImportsCommand.getBadVideoUrl(), false, 'presence') @@ -362,7 +362,7 @@ describe('Test user notifications', function () { privacy: VideoPrivacy.PRIVATE, targetUrl: ImportsCommand.getGoodVideoUrl() } - const { video } = await servers[0].importsCommand.importVideo({ attributes }) + const { video } = await servers[0].imports.importVideo({ attributes }) await waitJobs(servers) await checkMyVideoImportIsFinished(baseParams, name, video.uuid, ImportsCommand.getGoodVideoUrl(), true, 'presence') @@ -382,16 +382,16 @@ describe('Test user notifications', function () { token: userAccessToken } - await servers[0].usersCommand.updateMe({ displayName: 'super root name' }) + await servers[0].users.updateMe({ displayName: 'super root name' }) - await servers[0].usersCommand.updateMe({ + await servers[0].users.updateMe({ token: userAccessToken, displayName: myUserName }) - await servers[1].usersCommand.updateMe({ displayName: 'super root 2 name' }) + await servers[1].users.updateMe({ displayName: 'super root 2 name' }) - await servers[0].channelsCommand.update({ + await servers[0].channels.update({ token: userAccessToken, channelName: 'user_1_channel', attributes: { displayName: myChannelName } @@ -401,23 +401,23 @@ describe('Test user notifications', function () { it('Should notify when a local channel is following one of our channel', async function () { this.timeout(50000) - await servers[0].subscriptionsCommand.add({ targetUri: 'user_1_channel@localhost:' + servers[0].port }) + await servers[0].subscriptions.add({ targetUri: 'user_1_channel@localhost:' + servers[0].port }) await waitJobs(servers) await checkNewActorFollow(baseParams, 'channel', 'root', 'super root name', myChannelName, 'presence') - await servers[0].subscriptionsCommand.remove({ uri: 'user_1_channel@localhost:' + servers[0].port }) + await servers[0].subscriptions.remove({ uri: 'user_1_channel@localhost:' + servers[0].port }) }) it('Should notify when a remote channel is following one of our channel', async function () { this.timeout(50000) - await servers[1].subscriptionsCommand.add({ targetUri: 'user_1_channel@localhost:' + servers[0].port }) + await servers[1].subscriptions.add({ targetUri: 'user_1_channel@localhost:' + servers[0].port }) await waitJobs(servers) await checkNewActorFollow(baseParams, 'channel', 'root', 'super root 2 name', myChannelName, 'presence') - await servers[1].subscriptionsCommand.remove({ uri: 'user_1_channel@localhost:' + servers[0].port }) + await servers[1].subscriptions.remove({ uri: 'user_1_channel@localhost:' + servers[0].port }) }) // PeerTube does not support accout -> account follows diff --git a/server/tests/api/redundancy/manage-redundancy.ts b/server/tests/api/redundancy/manage-redundancy.ts index efb60dc56..e193b968e 100644 --- a/server/tests/api/redundancy/manage-redundancy.ts +++ b/server/tests/api/redundancy/manage-redundancy.ts @@ -53,15 +53,15 @@ describe('Test manage videos redundancy', function () { // Get the access tokens await setAccessTokensToServers(servers) - commands = servers.map(s => s.redundancyCommand) + commands = servers.map(s => s.redundancy) { - const { uuid } = await servers[1].videosCommand.upload({ attributes: { name: 'video 1 server 2' } }) + const { uuid } = await servers[1].videos.upload({ attributes: { name: 'video 1 server 2' } }) video1Server2UUID = uuid } { - const { uuid } = await servers[1].videosCommand.upload({ attributes: { name: 'video 2 server 2' } }) + const { uuid } = await servers[1].videos.upload({ attributes: { name: 'video 2 server 2' } }) video2Server2UUID = uuid } @@ -87,7 +87,7 @@ describe('Test manage videos redundancy', function () { this.timeout(120000) await waitJobs(servers) - await servers[0].serversCommand.waitUntilLog('Duplicated ', 10) + await servers[0].servers.waitUntilLog('Duplicated ', 10) await waitJobs(servers) const body = await commands[1].listVideos({ target: 'remote-videos' }) @@ -203,14 +203,14 @@ describe('Test manage videos redundancy', function () { it('Should manually add a redundancy and list it', async function () { this.timeout(120000) - const uuid = (await servers[1].videosCommand.quickUpload({ name: 'video 3 server 2', privacy: VideoPrivacy.UNLISTED })).uuid + const uuid = (await servers[1].videos.quickUpload({ name: 'video 3 server 2', privacy: VideoPrivacy.UNLISTED })).uuid await waitJobs(servers) - const videoId = await servers[0].videosCommand.getId({ uuid }) + const videoId = await servers[0].videos.getId({ uuid }) await commands[0].addVideo({ videoId }) await waitJobs(servers) - await servers[0].serversCommand.waitUntilLog('Duplicated ', 15) + await servers[0].servers.waitUntilLog('Duplicated ', 15) await waitJobs(servers) { diff --git a/server/tests/api/redundancy/redundancy-constraints.ts b/server/tests/api/redundancy/redundancy-constraints.ts index b3f6ed160..0378cc122 100644 --- a/server/tests/api/redundancy/redundancy-constraints.ts +++ b/server/tests/api/redundancy/redundancy-constraints.ts @@ -36,21 +36,21 @@ describe('Test redundancy constraints', function () { async function uploadWrapper (videoName: string) { // Wait for transcoding - const { id } = await localServer.videosCommand.upload({ attributes: { name: 'to transcode', privacy: VideoPrivacy.PRIVATE } }) + const { id } = await localServer.videos.upload({ attributes: { name: 'to transcode', privacy: VideoPrivacy.PRIVATE } }) await waitJobs([ localServer ]) // Update video to schedule a federation - await localServer.videosCommand.update({ id, attributes: { name: videoName, privacy: VideoPrivacy.PUBLIC } }) + await localServer.videos.update({ id, attributes: { name: videoName, privacy: VideoPrivacy.PUBLIC } }) } async function getTotalRedundanciesLocalServer () { - const body = await localServer.redundancyCommand.listVideos({ target: 'my-videos' }) + const body = await localServer.redundancy.listVideos({ target: 'my-videos' }) return body.total } async function getTotalRedundanciesRemoteServer () { - const body = await remoteServer.redundancyCommand.listVideos({ target: 'remote-videos' }) + const body = await remoteServer.redundancy.listVideos({ target: 'remote-videos' }) return body.total } @@ -78,14 +78,14 @@ describe('Test redundancy constraints', function () { // Get the access tokens await setAccessTokensToServers(servers) - await localServer.videosCommand.upload({ attributes: { name: 'video 1 server 2' } }) + await localServer.videos.upload({ attributes: { name: 'video 1 server 2' } }) await waitJobs(servers) // Server 1 and server 2 follow each other - await remoteServer.followsCommand.follow({ targets: [ localServer.url ] }) + await remoteServer.follows.follow({ targets: [ localServer.url ] }) await waitJobs(servers) - await remoteServer.redundancyCommand.updateRedundancy({ host: localServer.host, redundancyAllowed: true }) + await remoteServer.redundancy.updateRedundancy({ host: localServer.host, redundancyAllowed: true }) await waitJobs(servers) }) @@ -94,7 +94,7 @@ describe('Test redundancy constraints', function () { this.timeout(120000) await waitJobs(servers) - await remoteServer.serversCommand.waitUntilLog('Duplicated ', 5) + await remoteServer.servers.waitUntilLog('Duplicated ', 5) await waitJobs(servers) { @@ -123,7 +123,7 @@ describe('Test redundancy constraints', function () { await uploadWrapper('video 2 server 2') - await remoteServer.serversCommand.waitUntilLog('Duplicated ', 10) + await remoteServer.servers.waitUntilLog('Duplicated ', 10) await waitJobs(servers) { @@ -152,7 +152,7 @@ describe('Test redundancy constraints', function () { await uploadWrapper('video 3 server 2') - await remoteServer.serversCommand.waitUntilLog('Duplicated ', 15) + await remoteServer.servers.waitUntilLog('Duplicated ', 15) await waitJobs(servers) { @@ -169,11 +169,11 @@ describe('Test redundancy constraints', function () { it('Should have redundancy on server 1 and on server 2 with followings filter now server 2 follows server 1', async function () { this.timeout(120000) - await localServer.followsCommand.follow({ targets: [ remoteServer.url ] }) + await localServer.follows.follow({ targets: [ remoteServer.url ] }) await waitJobs(servers) await uploadWrapper('video 4 server 2') - await remoteServer.serversCommand.waitUntilLog('Duplicated ', 20) + await remoteServer.servers.waitUntilLog('Duplicated ', 20) await waitJobs(servers) { diff --git a/server/tests/api/redundancy/redundancy.ts b/server/tests/api/redundancy/redundancy.ts index 6ca9c9303..77ea2278e 100644 --- a/server/tests/api/redundancy/redundancy.ts +++ b/server/tests/api/redundancy/redundancy.ts @@ -78,11 +78,11 @@ async function flushAndRunServers (strategy: VideoRedundancyStrategy | null, add await setAccessTokensToServers(servers) { - const { uuid, id } = await servers[1].videosCommand.upload({ attributes: { name: 'video 1 server 2' } }) + const { uuid, id } = await servers[1].videos.upload({ attributes: { name: 'video 1 server 2' } }) video1Server2UUID = uuid video1Server2Id = id - await servers[1].videosCommand.view({ id: video1Server2UUID }) + await servers[1].videos.view({ id: video1Server2UUID }) } await waitJobs(servers) @@ -106,7 +106,7 @@ async function check1WebSeed (videoUUID?: string) { for (const server of servers) { // With token to avoid issues with video follow constraints - const video = await server.videosCommand.getWithToken({ id: videoUUID }) + const video = await server.videos.getWithToken({ id: videoUUID }) for (const f of video.files) { checkMagnetWebseeds(f, webseeds, server) @@ -123,7 +123,7 @@ async function check2Webseeds (videoUUID?: string) { ] for (const server of servers) { - const video = await server.videosCommand.get({ id: videoUUID }) + const video = await server.videos.get({ id: videoUUID }) for (const file of video.files) { checkMagnetWebseeds(file, webseeds, server) @@ -163,7 +163,7 @@ async function check0PlaylistRedundancies (videoUUID?: string) { for (const server of servers) { // With token to avoid issues with video follow constraints - const video = await server.videosCommand.getWithToken({ id: videoUUID }) + const video = await server.videos.getWithToken({ id: videoUUID }) expect(video.streamingPlaylists).to.be.an('array') expect(video.streamingPlaylists).to.have.lengthOf(1) @@ -175,7 +175,7 @@ async function check1PlaylistRedundancies (videoUUID?: string) { if (!videoUUID) videoUUID = video1Server2UUID for (const server of servers) { - const video = await server.videosCommand.get({ id: videoUUID }) + const video = await server.videos.get({ id: videoUUID }) expect(video.streamingPlaylists).to.have.lengthOf(1) expect(video.streamingPlaylists[0].redundancies).to.have.lengthOf(1) @@ -188,7 +188,7 @@ async function check1PlaylistRedundancies (videoUUID?: string) { const baseUrlPlaylist = servers[1].url + '/static/streaming-playlists/hls' const baseUrlSegment = servers[0].url + '/static/redundancy/hls' - const video = await servers[0].videosCommand.get({ id: videoUUID }) + const video = await servers[0].videos.get({ id: videoUUID }) const hlsPlaylist = video.streamingPlaylists[0] for (const resolution of [ 240, 360, 480, 720 ]) { @@ -221,7 +221,7 @@ async function checkStatsGlobal (strategy: VideoRedundancyStrategyWithManual) { statsLength = 2 } - const data = await servers[0].statsCommand.get() + const data = await servers[0].stats.get() expect(data.videosRedundancy).to.have.lengthOf(statsLength) const stat = data.videosRedundancy[0] @@ -248,7 +248,7 @@ async function checkStatsWithoutRedundancy (strategy: VideoRedundancyStrategyWit } async function findServerFollows () { - const body = await servers[0].followsCommand.getFollowings({ start: 0, count: 5, sort: '-createdAt' }) + const body = await servers[0].follows.getFollowings({ start: 0, count: 5, sort: '-createdAt' }) const follows = body.data const server2 = follows.find(f => f.following.host === `localhost:${servers[1].port}`) const server3 = follows.find(f => f.following.host === `localhost:${servers[2].port}`) @@ -257,7 +257,7 @@ async function findServerFollows () { } async function enableRedundancyOnServer1 () { - await servers[0].redundancyCommand.updateRedundancy({ host: servers[1].host, redundancyAllowed: true }) + await servers[0].redundancy.updateRedundancy({ host: servers[1].host, redundancyAllowed: true }) const { server2, server3 } = await findServerFollows() @@ -269,7 +269,7 @@ async function enableRedundancyOnServer1 () { } async function disableRedundancyOnServer1 () { - await servers[0].redundancyCommand.updateRedundancy({ host: servers[1].host, redundancyAllowed: false }) + await servers[0].redundancy.updateRedundancy({ host: servers[1].host, redundancyAllowed: false }) const { server2, server3 } = await findServerFollows() @@ -305,7 +305,7 @@ describe('Test videos redundancy', function () { this.timeout(80000) await waitJobs(servers) - await servers[0].serversCommand.waitUntilLog('Duplicated ', 5) + await servers[0].servers.waitUntilLog('Duplicated ', 5) await waitJobs(servers) await check2Webseeds() @@ -355,7 +355,7 @@ describe('Test videos redundancy', function () { this.timeout(80000) await waitJobs(servers) - await servers[0].serversCommand.waitUntilLog('Duplicated ', 5) + await servers[0].servers.waitUntilLog('Duplicated ', 5) await waitJobs(servers) await check2Webseeds() @@ -366,7 +366,7 @@ describe('Test videos redundancy', function () { it('Should unfollow on server 1 and remove duplicated videos', async function () { this.timeout(80000) - await servers[0].followsCommand.unfollow({ target: servers[1] }) + await servers[0].follows.unfollow({ target: servers[1] }) await waitJobs(servers) await wait(5000) @@ -416,8 +416,8 @@ describe('Test videos redundancy', function () { it('Should view 2 times the first video to have > min_views config', async function () { this.timeout(80000) - await servers[0].videosCommand.view({ id: video1Server2UUID }) - await servers[2].videosCommand.view({ id: video1Server2UUID }) + await servers[0].videos.view({ id: video1Server2UUID }) + await servers[2].videos.view({ id: video1Server2UUID }) await wait(10000) await waitJobs(servers) @@ -427,7 +427,7 @@ describe('Test videos redundancy', function () { this.timeout(80000) await waitJobs(servers) - await servers[0].serversCommand.waitUntilLog('Duplicated ', 5) + await servers[0].servers.waitUntilLog('Duplicated ', 5) await waitJobs(servers) await check2Webseeds() @@ -438,7 +438,7 @@ describe('Test videos redundancy', function () { it('Should remove the video and the redundancy files', async function () { this.timeout(20000) - await servers[1].videosCommand.remove({ id: video1Server2UUID }) + await servers[1].videos.remove({ id: video1Server2UUID }) await waitJobs(servers) @@ -484,14 +484,14 @@ describe('Test videos redundancy', function () { it('Should have 1 redundancy on the first video', async function () { this.timeout(160000) - await servers[0].videosCommand.view({ id: video1Server2UUID }) - await servers[2].videosCommand.view({ id: video1Server2UUID }) + await servers[0].videos.view({ id: video1Server2UUID }) + await servers[2].videos.view({ id: video1Server2UUID }) await wait(10000) await waitJobs(servers) await waitJobs(servers) - await servers[0].serversCommand.waitUntilLog('Duplicated ', 1) + await servers[0].servers.waitUntilLog('Duplicated ', 1) await waitJobs(servers) await check1PlaylistRedundancies() @@ -501,7 +501,7 @@ describe('Test videos redundancy', function () { it('Should remove the video and the redundancy files', async function () { this.timeout(20000) - await servers[1].videosCommand.remove({ id: video1Server2UUID }) + await servers[1].videos.remove({ id: video1Server2UUID }) await waitJobs(servers) @@ -529,14 +529,14 @@ describe('Test videos redundancy', function () { }) it('Should create a redundancy on first video', async function () { - await servers[0].redundancyCommand.addVideo({ videoId: video1Server2Id }) + await servers[0].redundancy.addVideo({ videoId: video1Server2Id }) }) it('Should have 2 webseeds on the first video', async function () { this.timeout(80000) await waitJobs(servers) - await servers[0].serversCommand.waitUntilLog('Duplicated ', 5) + await servers[0].servers.waitUntilLog('Duplicated ', 5) await waitJobs(servers) await check2Webseeds() @@ -547,7 +547,7 @@ describe('Test videos redundancy', function () { it('Should manually remove redundancies on server 1 and remove duplicated videos', async function () { this.timeout(80000) - const body = await servers[0].redundancyCommand.listVideos({ target: 'remote-videos' }) + const body = await servers[0].redundancy.listVideos({ target: 'remote-videos' }) const videos = body.data expect(videos).to.have.lengthOf(1) @@ -555,7 +555,7 @@ describe('Test videos redundancy', function () { const video = videos[0] for (const r of video.redundancies.files.concat(video.redundancies.streamingPlaylists)) { - await servers[0].redundancyCommand.removeVideo({ redundancyId: r.id }) + await servers[0].redundancy.removeVideo({ redundancyId: r.id }) } await waitJobs(servers) @@ -577,7 +577,7 @@ describe('Test videos redundancy', function () { async function checkContains (servers: ServerInfo[], str: string) { for (const server of servers) { - const video = await server.videosCommand.get({ id: video1Server2UUID }) + const video = await server.videos.get({ id: video1Server2UUID }) for (const f of video.files) { expect(f.magnetUri).to.contain(str) @@ -587,7 +587,7 @@ describe('Test videos redundancy', function () { async function checkNotContains (servers: ServerInfo[], str: string) { for (const server of servers) { - const video = await server.videosCommand.get({ id: video1Server2UUID }) + const video = await server.videos.get({ id: video1Server2UUID }) for (const f of video.files) { expect(f.magnetUri).to.not.contain(str) @@ -645,20 +645,20 @@ describe('Test videos redundancy', function () { await enableRedundancyOnServer1() await waitJobs(servers) - await servers[0].serversCommand.waitUntilLog('Duplicated ', 5) + await servers[0].servers.waitUntilLog('Duplicated ', 5) await waitJobs(servers) await check2Webseeds(video1Server2UUID) await check1PlaylistRedundancies(video1Server2UUID) await checkStatsWith1Redundancy(strategy) - const { uuid } = await servers[1].videosCommand.upload({ attributes: { name: 'video 2 server 2', privacy: VideoPrivacy.PRIVATE } }) + const { uuid } = await servers[1].videos.upload({ attributes: { name: 'video 2 server 2', privacy: VideoPrivacy.PRIVATE } }) video2Server2UUID = uuid // Wait transcoding before federation await waitJobs(servers) - await servers[1].videosCommand.update({ id: video2Server2UUID, attributes: { privacy: VideoPrivacy.PUBLIC } }) + await servers[1].videos.update({ id: video2Server2UUID, attributes: { privacy: VideoPrivacy.PUBLIC } }) }) it('Should cache video 2 webseeds on the first video', async function () { diff --git a/server/tests/api/search/search-activitypub-video-channels.ts b/server/tests/api/search/search-activitypub-video-channels.ts index 75794402d..71e9367e5 100644 --- a/server/tests/api/search/search-activitypub-video-channels.ts +++ b/server/tests/api/search/search-activitypub-video-channels.ts @@ -30,34 +30,34 @@ describe('Test ActivityPub video channels search', function () { await setAccessTokensToServers(servers) { - await servers[0].usersCommand.create({ username: 'user1_server1', password: 'password' }) + await servers[0].users.create({ username: 'user1_server1', password: 'password' }) const channel = { name: 'channel1_server1', displayName: 'Channel 1 server 1' } - await servers[0].channelsCommand.create({ attributes: channel }) + await servers[0].channels.create({ attributes: channel }) } { const user = { username: 'user1_server2', password: 'password' } - await servers[1].usersCommand.create({ username: user.username, password: user.password }) - userServer2Token = await servers[1].loginCommand.getAccessToken(user) + await servers[1].users.create({ username: user.username, password: user.password }) + userServer2Token = await servers[1].login.getAccessToken(user) const channel = { name: 'channel1_server2', displayName: 'Channel 1 server 2' } - const created = await servers[1].channelsCommand.create({ token: userServer2Token, attributes: channel }) + const created = await servers[1].channels.create({ token: userServer2Token, attributes: channel }) channelIdServer2 = created.id const attributes = { name: 'video 1 server 2', channelId: channelIdServer2 } - const { uuid } = await servers[1].videosCommand.upload({ token: userServer2Token, attributes }) + const { uuid } = await servers[1].videos.upload({ token: userServer2Token, attributes }) videoServer2UUID = uuid } await waitJobs(servers) - command = servers[0].searchCommand + command = servers[0].search }) it('Should not find a remote video channel', async function () { @@ -134,7 +134,7 @@ describe('Test ActivityPub video channels search', function () { }) it('Should not list this remote video channel', async function () { - const body = await servers[0].channelsCommand.list() + const body = await servers[0].channels.list() expect(body.total).to.equal(3) expect(body.data).to.have.lengthOf(3) expect(body.data[0].name).to.equal('channel1_server1') @@ -147,7 +147,7 @@ describe('Test ActivityPub video channels search', function () { await waitJobs(servers) - const { total, data } = await servers[0].videosCommand.listByChannel({ + const { total, data } = await servers[0].videos.listByChannel({ token: null, videoChannelName: 'channel1_server2@localhost:' + servers[1].port }) @@ -156,7 +156,7 @@ describe('Test ActivityPub video channels search', function () { }) it('Should list video channel videos of server 2 with token', async function () { - const { total, data } = await servers[0].videosCommand.listByChannel({ + const { total, data } = await servers[0].videos.listByChannel({ videoChannelName: 'channel1_server2@localhost:' + servers[1].port }) @@ -167,12 +167,12 @@ describe('Test ActivityPub video channels search', function () { it('Should update video channel of server 2, and refresh it on server 1', async function () { this.timeout(60000) - await servers[1].channelsCommand.update({ + await servers[1].channels.update({ token: userServer2Token, channelName: 'channel1_server2', attributes: { displayName: 'channel updated' } }) - await servers[1].usersCommand.updateMe({ token: userServer2Token, displayName: 'user updated' }) + await servers[1].users.updateMe({ token: userServer2Token, displayName: 'user updated' }) await waitJobs(servers) // Expire video channel @@ -193,8 +193,8 @@ describe('Test ActivityPub video channels search', function () { it('Should update and add a video on server 2, and update it on server 1 after a search', async function () { this.timeout(60000) - await servers[1].videosCommand.update({ token: userServer2Token, id: videoServer2UUID, attributes: { name: 'video 1 updated' } }) - await servers[1].videosCommand.upload({ token: userServer2Token, attributes: { name: 'video 2 server 2', channelId: channelIdServer2 } }) + await servers[1].videos.update({ token: userServer2Token, id: videoServer2UUID, attributes: { name: 'video 1 updated' } }) + await servers[1].videos.upload({ token: userServer2Token, attributes: { name: 'video 2 server 2', channelId: channelIdServer2 } }) await waitJobs(servers) @@ -207,7 +207,7 @@ describe('Test ActivityPub video channels search', function () { await waitJobs(servers) const videoChannelName = 'channel1_server2@localhost:' + servers[1].port - const { total, data } = await servers[0].videosCommand.listByChannel({ videoChannelName, sort: '-createdAt' }) + const { total, data } = await servers[0].videos.listByChannel({ videoChannelName, sort: '-createdAt' }) expect(total).to.equal(2) expect(data[0].name).to.equal('video 2 server 2') @@ -217,7 +217,7 @@ describe('Test ActivityPub video channels search', function () { it('Should delete video channel of server 2, and delete it on server 1', async function () { this.timeout(60000) - await servers[1].channelsCommand.delete({ token: userServer2Token, channelName: 'channel1_server2' }) + await servers[1].channels.delete({ token: userServer2Token, channelName: 'channel1_server2' }) await waitJobs(servers) // Expire video diff --git a/server/tests/api/search/search-activitypub-video-playlists.ts b/server/tests/api/search/search-activitypub-video-playlists.ts index 46105c12c..7c99b954b 100644 --- a/server/tests/api/search/search-activitypub-video-playlists.ts +++ b/server/tests/api/search/search-activitypub-video-playlists.ts @@ -33,40 +33,40 @@ describe('Test ActivityPub playlists search', function () { await setDefaultVideoChannel(servers) { - const video1 = (await servers[0].videosCommand.quickUpload({ name: 'video 1' })).uuid - const video2 = (await servers[0].videosCommand.quickUpload({ name: 'video 2' })).uuid + const video1 = (await servers[0].videos.quickUpload({ name: 'video 1' })).uuid + const video2 = (await servers[0].videos.quickUpload({ name: 'video 2' })).uuid const attributes = { displayName: 'playlist 1 on server 1', privacy: VideoPlaylistPrivacy.PUBLIC, - videoChannelId: servers[0].videoChannel.id + videoChannelId: servers[0].store.channel.id } - const created = await servers[0].playlistsCommand.create({ attributes }) + const created = await servers[0].playlists.create({ attributes }) playlistServer1UUID = created.uuid for (const videoId of [ video1, video2 ]) { - await servers[0].playlistsCommand.addElement({ playlistId: playlistServer1UUID, attributes: { videoId } }) + await servers[0].playlists.addElement({ playlistId: playlistServer1UUID, attributes: { videoId } }) } } { - const videoId = (await servers[1].videosCommand.quickUpload({ name: 'video 1' })).uuid - video2Server2 = (await servers[1].videosCommand.quickUpload({ name: 'video 2' })).uuid + const videoId = (await servers[1].videos.quickUpload({ name: 'video 1' })).uuid + video2Server2 = (await servers[1].videos.quickUpload({ name: 'video 2' })).uuid const attributes = { displayName: 'playlist 1 on server 2', privacy: VideoPlaylistPrivacy.PUBLIC, - videoChannelId: servers[1].videoChannel.id + videoChannelId: servers[1].store.channel.id } - const created = await servers[1].playlistsCommand.create({ attributes }) + const created = await servers[1].playlists.create({ attributes }) playlistServer2UUID = created.uuid - await servers[1].playlistsCommand.addElement({ playlistId: playlistServer2UUID, attributes: { videoId } }) + await servers[1].playlists.addElement({ playlistId: playlistServer2UUID, attributes: { videoId } }) } await waitJobs(servers) - command = servers[0].searchCommand + command = servers[0].search }) it('Should not find a remote playlist', async function () { @@ -139,7 +139,7 @@ describe('Test ActivityPub playlists search', function () { }) it('Should not list this remote playlist', async function () { - const body = await servers[0].playlistsCommand.list({ start: 0, count: 10 }) + const body = await servers[0].playlists.list({ start: 0, count: 10 }) expect(body.total).to.equal(1) expect(body.data).to.have.lengthOf(1) expect(body.data[0].displayName).to.equal('playlist 1 on server 1') @@ -148,7 +148,7 @@ describe('Test ActivityPub playlists search', function () { it('Should update the playlist of server 2, and refresh it on server 1', async function () { this.timeout(60000) - await servers[1].playlistsCommand.addElement({ playlistId: playlistServer2UUID, attributes: { videoId: video2Server2 } }) + await servers[1].playlists.addElement({ playlistId: playlistServer2UUID, attributes: { videoId: video2Server2 } }) await waitJobs(servers) // Expire playlist @@ -172,7 +172,7 @@ describe('Test ActivityPub playlists search', function () { it('Should delete playlist of server 2, and delete it on server 1', async function () { this.timeout(60000) - await servers[1].playlistsCommand.delete({ playlistId: playlistServer2UUID }) + await servers[1].playlists.delete({ playlistId: playlistServer2UUID }) await waitJobs(servers) // Expiration diff --git a/server/tests/api/search/search-activitypub-videos.ts b/server/tests/api/search/search-activitypub-videos.ts index 19b4d5ed8..0dfc63446 100644 --- a/server/tests/api/search/search-activitypub-videos.ts +++ b/server/tests/api/search/search-activitypub-videos.ts @@ -30,18 +30,18 @@ describe('Test ActivityPub videos search', function () { await setAccessTokensToServers(servers) { - const { uuid } = await servers[0].videosCommand.upload({ attributes: { name: 'video 1 on server 1' } }) + const { uuid } = await servers[0].videos.upload({ attributes: { name: 'video 1 on server 1' } }) videoServer1UUID = uuid } { - const { uuid } = await servers[1].videosCommand.upload({ attributes: { name: 'video 1 on server 2' } }) + const { uuid } = await servers[1].videos.upload({ attributes: { name: 'video 1 on server 2' } }) videoServer2UUID = uuid } await waitJobs(servers) - command = servers[0].searchCommand + command = servers[0].search }) it('Should not find a remote video', async function () { @@ -105,7 +105,7 @@ describe('Test ActivityPub videos search', function () { }) it('Should not list this remote video', async function () { - const { total, data } = await servers[0].videosCommand.list() + const { total, data } = await servers[0].videos.list() expect(total).to.equal(1) expect(data).to.have.lengthOf(1) expect(data[0].name).to.equal('video 1 on server 1') @@ -118,7 +118,7 @@ describe('Test ActivityPub videos search', function () { name: 'super_channel', displayName: 'super channel' } - const created = await servers[1].channelsCommand.create({ attributes: channelAttributes }) + const created = await servers[1].channels.create({ attributes: channelAttributes }) const videoChannelId = created.id const attributes = { @@ -127,7 +127,7 @@ describe('Test ActivityPub videos search', function () { privacy: VideoPrivacy.UNLISTED, channelId: videoChannelId } - await servers[1].videosCommand.update({ id: videoServer2UUID, attributes }) + await servers[1].videos.update({ id: videoServer2UUID, attributes }) await waitJobs(servers) // Expire video @@ -153,7 +153,7 @@ describe('Test ActivityPub videos search', function () { it('Should delete video of server 2, and delete it on server 1', async function () { this.timeout(120000) - await servers[1].videosCommand.remove({ id: videoServer2UUID }) + await servers[1].videos.remove({ id: videoServer2UUID }) await waitJobs(servers) // Expire video diff --git a/server/tests/api/search/search-channels.ts b/server/tests/api/search/search-channels.ts index 4d2104708..7035fbd62 100644 --- a/server/tests/api/search/search-channels.ts +++ b/server/tests/api/search/search-channels.ts @@ -19,15 +19,15 @@ describe('Test channels search', function () { await setAccessTokensToServers([ server ]) { - await server.usersCommand.create({ username: 'user1', password: 'password' }) + await server.users.create({ username: 'user1', password: 'password' }) const channel = { name: 'squall_channel', displayName: 'Squall channel' } - await server.channelsCommand.create({ attributes: channel }) + await server.channels.create({ attributes: channel }) } - command = server.searchCommand + command = server.search }) it('Should make a simple search and not have results', async function () { diff --git a/server/tests/api/search/search-index.ts b/server/tests/api/search/search-index.ts index d5dc40f60..b54c0da22 100644 --- a/server/tests/api/search/search-index.ts +++ b/server/tests/api/search/search-index.ts @@ -20,9 +20,9 @@ describe('Test videos search', function () { await setAccessTokensToServers([ server ]) - await server.videosCommand.upload({ attributes: { name: localVideoName } }) + await server.videos.upload({ attributes: { name: localVideoName } }) - command = server.searchCommand + command = server.search }) describe('Default search', async function () { @@ -30,7 +30,7 @@ describe('Test videos search', function () { it('Should make a local videos search by default', async function () { this.timeout(10000) - await server.configCommand.updateCustomSubConfig({ + await server.config.updateCustomSubConfig({ newConfig: { search: { searchIndex: { @@ -57,7 +57,7 @@ describe('Test videos search', function () { }) it('Should make an index videos search by default', async function () { - await server.configCommand.updateCustomSubConfig({ + await server.config.updateCustomSubConfig({ newConfig: { search: { searchIndex: { @@ -79,7 +79,7 @@ describe('Test videos search', function () { }) it('Should make an index videos search if local search is disabled', async function () { - await server.configCommand.updateCustomSubConfig({ + await server.config.updateCustomSubConfig({ newConfig: { search: { searchIndex: { @@ -213,7 +213,7 @@ describe('Test videos search', function () { let nsfwUUID: string { - await server.configCommand.updateCustomSubConfig({ + await server.config.updateCustomSubConfig({ newConfig: { instance: { defaultNSFWPolicy: 'display' } } @@ -229,7 +229,7 @@ describe('Test videos search', function () { } { - await server.configCommand.updateCustomSubConfig({ + await server.config.updateCustomSubConfig({ newConfig: { instance: { defaultNSFWPolicy: 'do_not_list' } } diff --git a/server/tests/api/search/search-playlists.ts b/server/tests/api/search/search-playlists.ts index 2e4773ed6..e15128c8e 100644 --- a/server/tests/api/search/search-playlists.ts +++ b/server/tests/api/search/search-playlists.ts @@ -26,40 +26,40 @@ describe('Test playlists search', function () { await setAccessTokensToServers([ server ]) await setDefaultVideoChannel([ server ]) - const videoId = (await server.videosCommand.quickUpload({ name: 'video' })).uuid + const videoId = (await server.videos.quickUpload({ name: 'video' })).uuid { const attributes = { displayName: 'Dr. Kenzo Tenma hospital videos', privacy: VideoPlaylistPrivacy.PUBLIC, - videoChannelId: server.videoChannel.id + videoChannelId: server.store.channel.id } - const created = await server.playlistsCommand.create({ attributes }) + const created = await server.playlists.create({ attributes }) - await server.playlistsCommand.addElement({ playlistId: created.id, attributes: { videoId } }) + await server.playlists.addElement({ playlistId: created.id, attributes: { videoId } }) } { const attributes = { displayName: 'Johan & Anna Libert musics', privacy: VideoPlaylistPrivacy.PUBLIC, - videoChannelId: server.videoChannel.id + videoChannelId: server.store.channel.id } - const created = await server.playlistsCommand.create({ attributes }) + const created = await server.playlists.create({ attributes }) - await server.playlistsCommand.addElement({ playlistId: created.id, attributes: { videoId } }) + await server.playlists.addElement({ playlistId: created.id, attributes: { videoId } }) } { const attributes = { displayName: 'Inspector Lunge playlist', privacy: VideoPlaylistPrivacy.PUBLIC, - videoChannelId: server.videoChannel.id + videoChannelId: server.store.channel.id } - await server.playlistsCommand.create({ attributes }) + await server.playlists.create({ attributes }) } - command = server.searchCommand + command = server.search }) it('Should make a simple search and not have results', async function () { diff --git a/server/tests/api/search/search-videos.ts b/server/tests/api/search/search-videos.ts index 148499d5f..478ebafc9 100644 --- a/server/tests/api/search/search-videos.ts +++ b/server/tests/api/search/search-videos.ts @@ -40,24 +40,24 @@ describe('Test videos search', function () { nsfw: false, language: 'fr' } - await server.videosCommand.upload({ attributes: attributes1 }) + await server.videos.upload({ attributes: attributes1 }) const attributes2 = { ...attributes1, name: attributes1.name + ' - 2', fixture: 'video_short.mp4' } - await server.videosCommand.upload({ attributes: attributes2 }) + await server.videos.upload({ attributes: attributes2 }) { const attributes3 = { ...attributes1, name: attributes1.name + ' - 3', language: undefined } - const { id, uuid } = await server.videosCommand.upload({ attributes: attributes3 }) + const { id, uuid } = await server.videos.upload({ attributes: attributes3 }) videoUUID = uuid - await server.captionsCommand.createVideoCaption({ + await server.captions.createVideoCaption({ language: 'en', videoId: id, fixture: 'subtitle-good2.vtt', mimeType: 'application/octet-stream' }) - await server.captionsCommand.createVideoCaption({ + await server.captions.createVideoCaption({ language: 'aa', videoId: id, fixture: 'subtitle-good2.vtt', @@ -66,23 +66,23 @@ describe('Test videos search', function () { } const attributes4 = { ...attributes1, name: attributes1.name + ' - 4', language: 'pl', nsfw: true } - await server.videosCommand.upload({ attributes: attributes4 }) + await server.videos.upload({ attributes: attributes4 }) await wait(1000) startDate = new Date().toISOString() const attributes5 = { ...attributes1, name: attributes1.name + ' - 5', licence: 2, language: undefined } - await server.videosCommand.upload({ attributes: attributes5 }) + await server.videos.upload({ attributes: attributes5 }) const attributes6 = { ...attributes1, name: attributes1.name + ' - 6', tags: [ 't1', 't2' ] } - await server.videosCommand.upload({ attributes: attributes6 }) + await server.videos.upload({ attributes: attributes6 }) const attributes7 = { ...attributes1, name: attributes1.name + ' - 7', originallyPublishedAt: '2019-02-12T09:58:08.286Z' } - await server.videosCommand.upload({ attributes: attributes7 }) + await server.videos.upload({ attributes: attributes7 }) const attributes8 = { ...attributes1, name: attributes1.name + ' - 8', licence: 4 } - await server.videosCommand.upload({ attributes: attributes8 }) + await server.videos.upload({ attributes: attributes8 }) } { @@ -93,9 +93,9 @@ describe('Test videos search', function () { licence: 2, language: 'en' } - await server.videosCommand.upload({ attributes: attributes }) + await server.videos.upload({ attributes: attributes }) - await server.videosCommand.upload({ attributes: { ...attributes, name: attributes.name + ' duplicate' } }) + await server.videos.upload({ attributes: { ...attributes, name: attributes.name + ' duplicate' } }) } { @@ -106,7 +106,7 @@ describe('Test videos search', function () { licence: 3, language: 'pl' } - await server.videosCommand.upload({ attributes: attributes }) + await server.videos.upload({ attributes: attributes }) } { @@ -115,11 +115,11 @@ describe('Test videos search', function () { tags: [ 'aaaa', 'bbbb', 'cccc' ], category: 1 } - await server.videosCommand.upload({ attributes: attributes1 }) - await server.videosCommand.upload({ attributes: { ...attributes1, category: 2 } }) + await server.videos.upload({ attributes: attributes1 }) + await server.videos.upload({ attributes: { ...attributes1, category: 2 } }) - await server.videosCommand.upload({ attributes: { ...attributes1, tags: [ 'cccc', 'dddd' ] } }) - await server.videosCommand.upload({ attributes: { ...attributes1, tags: [ 'eeee', 'ffff' ] } }) + await server.videos.upload({ attributes: { ...attributes1, tags: [ 'cccc', 'dddd' ] } }) + await server.videos.upload({ attributes: { ...attributes1, tags: [ 'eeee', 'ffff' ] } }) } { @@ -127,11 +127,11 @@ describe('Test videos search', function () { name: 'aaaa 2', category: 1 } - await server.videosCommand.upload({ attributes: attributes1 }) - await server.videosCommand.upload({ attributes: { ...attributes1, category: 2 } }) + await server.videos.upload({ attributes: attributes1 }) + await server.videos.upload({ attributes: { ...attributes1, category: 2 } }) } - command = server.searchCommand + command = server.search }) it('Should make a simple search and not have results', async function () { @@ -479,7 +479,7 @@ describe('Test videos search', function () { }, live: { enabled: true } } - await server.configCommand.updateCustomSubConfig({ newConfig }) + await server.config.updateCustomSubConfig({ newConfig }) } { @@ -490,9 +490,9 @@ describe('Test videos search', function () { } { - const liveCommand = server.liveCommand + const liveCommand = server.live - const liveAttributes = { name: 'live', privacy: VideoPrivacy.PUBLIC, channelId: server.videoChannel.id } + const liveAttributes = { name: 'live', privacy: VideoPrivacy.PUBLIC, channelId: server.store.channel.id } const live = await liveCommand.create({ fields: liveAttributes }) const ffmpegCommand = await liveCommand.sendRTMPStreamInVideo({ videoId: live.id }) diff --git a/server/tests/api/server/auto-follows.ts b/server/tests/api/server/auto-follows.ts index 34c4f6882..e9fb5b4b1 100644 --- a/server/tests/api/server/auto-follows.ts +++ b/server/tests/api/server/auto-follows.ts @@ -16,7 +16,7 @@ const expect = chai.expect async function checkFollow (follower: ServerInfo, following: ServerInfo, exists: boolean) { { - const body = await following.followsCommand.getFollowers({ start: 0, count: 5, sort: '-createdAt' }) + const body = await following.follows.getFollowers({ start: 0, count: 5, sort: '-createdAt' }) const follow = body.data.find(f => f.follower.host === follower.host && f.state === 'accepted') if (exists === true) expect(follow).to.exist @@ -24,7 +24,7 @@ async function checkFollow (follower: ServerInfo, following: ServerInfo, exists: } { - const body = await follower.followsCommand.getFollowings({ start: 0, count: 5, sort: '-createdAt' }) + const body = await follower.follows.getFollowings({ start: 0, count: 5, sort: '-createdAt' }) const follow = body.data.find(f => f.following.host === following.host && f.state === 'accepted') if (exists === true) expect(follow).to.exist @@ -33,15 +33,15 @@ async function checkFollow (follower: ServerInfo, following: ServerInfo, exists: } async function server1Follows2 (servers: ServerInfo[]) { - await servers[0].followsCommand.follow({ targets: [ servers[1].host ] }) + await servers[0].follows.follow({ targets: [ servers[1].host ] }) await waitJobs(servers) } async function resetFollows (servers: ServerInfo[]) { try { - await servers[0].followsCommand.unfollow({ target: servers[1] }) - await servers[1].followsCommand.unfollow({ target: servers[0] }) + await servers[0].follows.unfollow({ target: servers[1] }) + await servers[1].follows.unfollow({ target: servers[0] }) } catch { /* empty */ } @@ -86,7 +86,7 @@ describe('Test auto follows', function () { } } } - await servers[1].configCommand.updateCustomSubConfig({ newConfig: config }) + await servers[1].config.updateCustomSubConfig({ newConfig: config }) await server1Follows2(servers) @@ -111,14 +111,14 @@ describe('Test auto follows', function () { } } } - await servers[1].configCommand.updateCustomSubConfig({ newConfig: config }) + await servers[1].config.updateCustomSubConfig({ newConfig: config }) await server1Follows2(servers) await checkFollow(servers[0], servers[1], false) await checkFollow(servers[1], servers[0], false) - await servers[1].followsCommand.acceptFollower({ follower: 'peertube@' + servers[0].host }) + await servers[1].follows.acceptFollower({ follower: 'peertube@' + servers[0].host }) await waitJobs(servers) await checkFollow(servers[0], servers[1], true) @@ -128,7 +128,7 @@ describe('Test auto follows', function () { config.followings.instance.autoFollowBack.enabled = false config.followers.instance.manualApproval = false - await servers[1].configCommand.updateCustomSubConfig({ newConfig: config }) + await servers[1].config.updateCustomSubConfig({ newConfig: config }) }) }) @@ -165,7 +165,7 @@ describe('Test auto follows', function () { } } } - await servers[0].configCommand.updateCustomSubConfig({ newConfig: config }) + await servers[0].config.updateCustomSubConfig({ newConfig: config }) await wait(5000) await waitJobs(servers) diff --git a/server/tests/api/server/bulk.ts b/server/tests/api/server/bulk.ts index c83bcfb22..acc17092d 100644 --- a/server/tests/api/server/bulk.ts +++ b/server/tests/api/server/bulk.ts @@ -34,23 +34,23 @@ describe('Test bulk actions', function () { { const user = { username: 'user1', password: 'password' } - await servers[0].usersCommand.create({ username: user.username, password: user.password }) + await servers[0].users.create({ username: user.username, password: user.password }) - user1Token = await servers[0].loginCommand.getAccessToken(user) + user1Token = await servers[0].login.getAccessToken(user) } { const user = { username: 'user2', password: 'password' } - await servers[0].usersCommand.create({ username: user.username, password: user.password }) + await servers[0].users.create({ username: user.username, password: user.password }) - user2Token = await servers[0].loginCommand.getAccessToken(user) + user2Token = await servers[0].login.getAccessToken(user) } { const user = { username: 'user3', password: 'password' } - await servers[1].usersCommand.create({ username: user.username, password: user.password }) + await servers[1].users.create({ username: user.username, password: user.password }) - user3Token = await servers[1].loginCommand.getAccessToken(user) + user3Token = await servers[1].login.getAccessToken(user) } await doubleFollow(servers[0], servers[1]) @@ -61,11 +61,11 @@ describe('Test bulk actions', function () { describe('Bulk remove comments', function () { async function checkInstanceCommentsRemoved () { { - const { data } = await servers[0].videosCommand.list() + const { data } = await servers[0].videos.list() // Server 1 should not have these comments anymore for (const video of data) { - const { data } = await servers[0].commentsCommand.listThreads({ videoId: video.id }) + const { data } = await servers[0].comments.listThreads({ videoId: video.id }) const comment = data.find(c => c.text === 'comment by user 3') expect(comment).to.not.exist @@ -73,11 +73,11 @@ describe('Test bulk actions', function () { } { - const { data } = await servers[1].videosCommand.list() + const { data } = await servers[1].videos.list() // Server 1 should not have these comments on videos of server 1 for (const video of data) { - const { data } = await servers[1].commentsCommand.listThreads({ videoId: video.id }) + const { data } = await servers[1].comments.listThreads({ videoId: video.id }) const comment = data.find(c => c.text === 'comment by user 3') if (video.account.host === 'localhost:' + servers[0].port) { @@ -92,30 +92,30 @@ describe('Test bulk actions', function () { before(async function () { this.timeout(120000) - await servers[0].videosCommand.upload({ attributes: { name: 'video 1 server 1' } }) - await servers[0].videosCommand.upload({ attributes: { name: 'video 2 server 1' } }) - await servers[0].videosCommand.upload({ token: user1Token, attributes: { name: 'video 3 server 1' } }) + await servers[0].videos.upload({ attributes: { name: 'video 1 server 1' } }) + await servers[0].videos.upload({ attributes: { name: 'video 2 server 1' } }) + await servers[0].videos.upload({ token: user1Token, attributes: { name: 'video 3 server 1' } }) - await servers[1].videosCommand.upload({ attributes: { name: 'video 1 server 2' } }) + await servers[1].videos.upload({ attributes: { name: 'video 1 server 2' } }) await waitJobs(servers) { - const { data } = await servers[0].videosCommand.list() + const { data } = await servers[0].videos.list() for (const video of data) { - await servers[0].commentsCommand.createThread({ videoId: video.id, text: 'comment by root server 1' }) - await servers[0].commentsCommand.createThread({ token: user1Token, videoId: video.id, text: 'comment by user 1' }) - await servers[0].commentsCommand.createThread({ token: user2Token, videoId: video.id, text: 'comment by user 2' }) + await servers[0].comments.createThread({ videoId: video.id, text: 'comment by root server 1' }) + await servers[0].comments.createThread({ token: user1Token, videoId: video.id, text: 'comment by user 1' }) + await servers[0].comments.createThread({ token: user2Token, videoId: video.id, text: 'comment by user 2' }) } } { - const { data } = await servers[1].videosCommand.list() + const { data } = await servers[1].videos.list() for (const video of data) { - await servers[1].commentsCommand.createThread({ videoId: video.id, text: 'comment by root server 2' }) + await servers[1].comments.createThread({ videoId: video.id, text: 'comment by root server 2' }) - const comment = await servers[1].commentsCommand.createThread({ token: user3Token, videoId: video.id, text: 'comment by user 3' }) + const comment = await servers[1].comments.createThread({ token: user3Token, videoId: video.id, text: 'comment by user 3' }) commentsUser3.push({ videoId: video.id, commentId: comment.id }) } } @@ -137,10 +137,10 @@ describe('Test bulk actions', function () { await waitJobs(servers) for (const server of servers) { - const { data } = await server.videosCommand.list() + const { data } = await server.videos.list() for (const video of data) { - const { data } = await server.commentsCommand.listThreads({ videoId: video.id }) + const { data } = await server.comments.listThreads({ videoId: video.id }) const comment = data.find(c => c.text === 'comment by user 2') if (video.name === 'video 3 server 1') expect(comment).to.not.exist @@ -168,7 +168,7 @@ describe('Test bulk actions', function () { this.timeout(60000) for (const obj of commentsUser3) { - await servers[1].commentsCommand.addReply({ + await servers[1].comments.addReply({ token: user3Token, videoId: obj.videoId, toCommentId: obj.commentId, diff --git a/server/tests/api/server/config.ts b/server/tests/api/server/config.ts index c613511ed..479e177a8 100644 --- a/server/tests/api/server/config.ts +++ b/server/tests/api/server/config.ts @@ -214,7 +214,7 @@ describe('Test config', function () { }) it('Should have a correct config on a server with registration enabled', async function () { - const data = await server.configCommand.getConfig() + const data = await server.config.getConfig() expect(data.signup.allowed).to.be.true }) @@ -223,32 +223,32 @@ describe('Test config', function () { this.timeout(5000) await Promise.all([ - server.usersCommand.register({ username: 'user1' }), - server.usersCommand.register({ username: 'user2' }), - server.usersCommand.register({ username: 'user3' }) + server.users.register({ username: 'user1' }), + server.users.register({ username: 'user2' }), + server.users.register({ username: 'user3' }) ]) - const data = await server.configCommand.getConfig() + const data = await server.config.getConfig() expect(data.signup.allowed).to.be.false }) it('Should have the correct video allowed extensions', async function () { - const data = await server.configCommand.getConfig() + const data = await server.config.getConfig() expect(data.video.file.extensions).to.have.lengthOf(3) expect(data.video.file.extensions).to.contain('.mp4') expect(data.video.file.extensions).to.contain('.webm') expect(data.video.file.extensions).to.contain('.ogv') - await server.videosCommand.upload({ attributes: { fixture: 'video_short.mkv' }, expectedStatus: HttpStatusCode.UNSUPPORTED_MEDIA_TYPE_415 }) - await server.videosCommand.upload({ attributes: { fixture: 'sample.ogg' }, expectedStatus: HttpStatusCode.UNSUPPORTED_MEDIA_TYPE_415 }) + await server.videos.upload({ attributes: { fixture: 'video_short.mkv' }, expectedStatus: HttpStatusCode.UNSUPPORTED_MEDIA_TYPE_415 }) + await server.videos.upload({ attributes: { fixture: 'sample.ogg' }, expectedStatus: HttpStatusCode.UNSUPPORTED_MEDIA_TYPE_415 }) expect(data.contactForm.enabled).to.be.true }) it('Should get the customized configuration', async function () { - const data = await server.configCommand.getCustomConfig() + const data = await server.config.getCustomConfig() checkInitialConfig(server, data) }) @@ -425,16 +425,16 @@ describe('Test config', function () { } } } - await server.configCommand.updateCustomConfig({ newCustomConfig }) + await server.config.updateCustomConfig({ newCustomConfig }) - const data = await server.configCommand.getCustomConfig() + const data = await server.config.getCustomConfig() checkUpdatedConfig(data) }) it('Should have the correct updated video allowed extensions', async function () { this.timeout(10000) - const data = await server.configCommand.getConfig() + const data = await server.config.getConfig() expect(data.video.file.extensions).to.have.length.above(4) expect(data.video.file.extensions).to.contain('.mp4') @@ -447,8 +447,8 @@ describe('Test config', function () { expect(data.video.file.extensions).to.contain('.ogg') expect(data.video.file.extensions).to.contain('.flac') - await server.videosCommand.upload({ attributes: { fixture: 'video_short.mkv' }, expectedStatus: HttpStatusCode.OK_200 }) - await server.videosCommand.upload({ attributes: { fixture: 'sample.ogg' }, expectedStatus: HttpStatusCode.OK_200 }) + await server.videos.upload({ attributes: { fixture: 'video_short.mkv' }, expectedStatus: HttpStatusCode.OK_200 }) + await server.videos.upload({ attributes: { fixture: 'sample.ogg' }, expectedStatus: HttpStatusCode.OK_200 }) }) it('Should have the configuration updated after a restart', async function () { @@ -458,13 +458,13 @@ describe('Test config', function () { await reRunServer(server) - const data = await server.configCommand.getCustomConfig() + const data = await server.config.getCustomConfig() checkUpdatedConfig(data) }) it('Should fetch the about information', async function () { - const data = await server.configCommand.getAbout() + const data = await server.config.getAbout() expect(data.instance.name).to.equal('PeerTube updated') expect(data.instance.shortDescription).to.equal('my short description') @@ -486,9 +486,9 @@ describe('Test config', function () { it('Should remove the custom configuration', async function () { this.timeout(10000) - await server.configCommand.deleteCustomConfig() + await server.config.deleteCustomConfig() - const data = await server.configCommand.getCustomConfig() + const data = await server.config.getCustomConfig() checkInitialConfig(server, data) }) diff --git a/server/tests/api/server/contact-form.ts b/server/tests/api/server/contact-form.ts index 79c4c6748..353fed80a 100644 --- a/server/tests/api/server/contact-form.ts +++ b/server/tests/api/server/contact-form.ts @@ -27,7 +27,7 @@ describe('Test contact form', function () { server = await flushAndRunServer(1, overrideConfig) await setAccessTokensToServers([ server ]) - command = server.contactFormCommand + command = server.contactForm }) it('Should send a contact form', async function () { diff --git a/server/tests/api/server/email.ts b/server/tests/api/server/email.ts index aeda5fddb..258e835e7 100644 --- a/server/tests/api/server/email.ts +++ b/server/tests/api/server/email.ts @@ -43,15 +43,15 @@ describe('Test emails', function () { await setAccessTokensToServers([ server ]) { - const created = await server.usersCommand.create({ username: user.username, password: user.password }) + const created = await server.users.create({ username: user.username, password: user.password }) userId = created.id - userAccessToken = await server.loginCommand.getAccessToken(user) + userAccessToken = await server.login.getAccessToken(user) } { const attributes = { name: 'my super user video' } - const { uuid } = await server.videosCommand.upload({ token: userAccessToken, attributes }) + const { uuid } = await server.videos.upload({ token: userAccessToken, attributes }) videoUserUUID = uuid } @@ -59,7 +59,7 @@ describe('Test emails', function () { const attributes = { name: 'my super name' } - const { uuid, id } = await server.videosCommand.upload({ attributes }) + const { uuid, id } = await server.videos.upload({ attributes }) videoUUID = uuid videoId = id } @@ -70,7 +70,7 @@ describe('Test emails', function () { it('Should ask to reset the password', async function () { this.timeout(10000) - await server.usersCommand.askResetPassword({ email: 'user_1@example.com' }) + await server.users.askResetPassword({ email: 'user_1@example.com' }) await waitJobs(server) expect(emails).to.have.lengthOf(1) @@ -96,7 +96,7 @@ describe('Test emails', function () { }) it('Should not reset the password with an invalid verification string', async function () { - await server.usersCommand.resetPassword({ + await server.users.resetPassword({ userId, verificationString: verificationString + 'b', password: 'super_password2', @@ -105,11 +105,11 @@ describe('Test emails', function () { }) it('Should reset the password', async function () { - await server.usersCommand.resetPassword({ userId, verificationString, password: 'super_password2' }) + await server.users.resetPassword({ userId, verificationString, password: 'super_password2' }) }) it('Should not reset the password with the same verification string', async function () { - await server.usersCommand.resetPassword({ + await server.users.resetPassword({ userId, verificationString, password: 'super_password3', @@ -120,7 +120,7 @@ describe('Test emails', function () { it('Should login with this new password', async function () { user.password = 'super_password2' - await server.loginCommand.getAccessToken(user) + await server.login.getAccessToken(user) }) }) @@ -129,7 +129,7 @@ describe('Test emails', function () { it('Should send a create password email', async function () { this.timeout(10000) - await server.usersCommand.create({ username: 'create_password', password: '' }) + await server.users.create({ username: 'create_password', password: '' }) await waitJobs(server) expect(emails).to.have.lengthOf(2) @@ -155,7 +155,7 @@ describe('Test emails', function () { }) it('Should not reset the password with an invalid verification string', async function () { - await server.usersCommand.resetPassword({ + await server.users.resetPassword({ userId: userId2, verificationString: verificationString2 + 'c', password: 'newly_created_password', @@ -164,7 +164,7 @@ describe('Test emails', function () { }) it('Should reset the password', async function () { - await server.usersCommand.resetPassword({ + await server.users.resetPassword({ userId: userId2, verificationString: verificationString2, password: 'newly_created_password' @@ -172,7 +172,7 @@ describe('Test emails', function () { }) it('Should login with this new password', async function () { - await server.loginCommand.getAccessToken({ + await server.login.getAccessToken({ username: 'create_password', password: 'newly_created_password' }) @@ -184,7 +184,7 @@ describe('Test emails', function () { this.timeout(10000) const reason = 'my super bad reason' - await server.abusesCommand.report({ videoId, reason }) + await server.abuses.report({ videoId, reason }) await waitJobs(server) expect(emails).to.have.lengthOf(3) @@ -205,7 +205,7 @@ describe('Test emails', function () { this.timeout(10000) const reason = 'my super bad reason' - await server.usersCommand.banUser({ userId, reason }) + await server.users.banUser({ userId, reason }) await waitJobs(server) expect(emails).to.have.lengthOf(4) @@ -223,7 +223,7 @@ describe('Test emails', function () { it('Should send the notification email when unblocking a user', async function () { this.timeout(10000) - await server.usersCommand.unbanUser({ userId }) + await server.users.unbanUser({ userId }) await waitJobs(server) expect(emails).to.have.lengthOf(5) @@ -243,7 +243,7 @@ describe('Test emails', function () { this.timeout(10000) const reason = 'my super reason' - await server.blacklistCommand.add({ videoId: videoUserUUID, reason }) + await server.blacklist.add({ videoId: videoUserUUID, reason }) await waitJobs(server) expect(emails).to.have.lengthOf(6) @@ -261,7 +261,7 @@ describe('Test emails', function () { it('Should send the notification email', async function () { this.timeout(10000) - await server.blacklistCommand.remove({ videoId: videoUserUUID }) + await server.blacklist.remove({ videoId: videoUserUUID }) await waitJobs(server) expect(emails).to.have.lengthOf(7) @@ -286,7 +286,7 @@ describe('Test emails', function () { it('Should ask to send the verification email', async function () { this.timeout(10000) - await server.usersCommand.askSendVerifyEmail({ email: 'user_1@example.com' }) + await server.users.askSendVerifyEmail({ email: 'user_1@example.com' }) await waitJobs(server) expect(emails).to.have.lengthOf(8) @@ -312,7 +312,7 @@ describe('Test emails', function () { }) it('Should not verify the email with an invalid verification string', async function () { - await server.usersCommand.verifyEmail({ + await server.users.verifyEmail({ userId, verificationString: verificationString + 'b', isPendingEmail: false, @@ -321,7 +321,7 @@ describe('Test emails', function () { }) it('Should verify the email', async function () { - await server.usersCommand.verifyEmail({ userId, verificationString }) + await server.users.verifyEmail({ userId, verificationString }) }) }) diff --git a/server/tests/api/server/follow-constraints.ts b/server/tests/api/server/follow-constraints.ts index f9014aeee..887e400e9 100644 --- a/server/tests/api/server/follow-constraints.ts +++ b/server/tests/api/server/follow-constraints.ts @@ -23,11 +23,11 @@ describe('Test follow constraints', function () { await setAccessTokensToServers(servers) { - const { uuid } = await servers[0].videosCommand.upload({ attributes: { name: 'video server 1' } }) + const { uuid } = await servers[0].videos.upload({ attributes: { name: 'video server 1' } }) video1UUID = uuid } { - const { uuid } = await servers[1].videosCommand.upload({ attributes: { name: 'video server 2' } }) + const { uuid } = await servers[1].videos.upload({ attributes: { name: 'video server 2' } }) video2UUID = uuid } @@ -35,8 +35,8 @@ describe('Test follow constraints', function () { username: 'user1', password: 'super_password' } - await servers[0].usersCommand.create({ username: user.username, password: user.password }) - userToken = await servers[0].loginCommand.getAccessToken(user) + await servers[0].users.create({ username: user.username, password: user.password }) + userToken = await servers[0].login.getAccessToken(user) await doubleFollow(servers[0], servers[1]) }) @@ -46,22 +46,22 @@ describe('Test follow constraints', function () { describe('With an unlogged user', function () { it('Should get the local video', async function () { - await servers[0].videosCommand.get({ id: video1UUID }) + await servers[0].videos.get({ id: video1UUID }) }) it('Should get the remote video', async function () { - await servers[0].videosCommand.get({ id: video2UUID }) + await servers[0].videos.get({ id: video2UUID }) }) it('Should list local account videos', async function () { - const { total, data } = await servers[0].videosCommand.listByAccount({ accountName: 'root@localhost:' + servers[0].port }) + const { total, data } = await servers[0].videos.listByAccount({ accountName: 'root@localhost:' + servers[0].port }) expect(total).to.equal(1) expect(data).to.have.lengthOf(1) }) it('Should list remote account videos', async function () { - const { total, data } = await servers[0].videosCommand.listByAccount({ accountName: 'root@localhost:' + servers[1].port }) + const { total, data } = await servers[0].videos.listByAccount({ accountName: 'root@localhost:' + servers[1].port }) expect(total).to.equal(1) expect(data).to.have.lengthOf(1) @@ -69,7 +69,7 @@ describe('Test follow constraints', function () { it('Should list local channel videos', async function () { const videoChannelName = 'root_channel@localhost:' + servers[0].port - const { total, data } = await servers[0].videosCommand.listByChannel({ videoChannelName }) + const { total, data } = await servers[0].videos.listByChannel({ videoChannelName }) expect(total).to.equal(1) expect(data).to.have.lengthOf(1) @@ -77,7 +77,7 @@ describe('Test follow constraints', function () { it('Should list remote channel videos', async function () { const videoChannelName = 'root_channel@localhost:' + servers[1].port - const { total, data } = await servers[0].videosCommand.listByChannel({ videoChannelName }) + const { total, data } = await servers[0].videos.listByChannel({ videoChannelName }) expect(total).to.equal(1) expect(data).to.have.lengthOf(1) @@ -86,22 +86,22 @@ describe('Test follow constraints', function () { describe('With a logged user', function () { it('Should get the local video', async function () { - await servers[0].videosCommand.getWithToken({ token: userToken, id: video1UUID }) + await servers[0].videos.getWithToken({ token: userToken, id: video1UUID }) }) it('Should get the remote video', async function () { - await servers[0].videosCommand.getWithToken({ token: userToken, id: video2UUID }) + await servers[0].videos.getWithToken({ token: userToken, id: video2UUID }) }) it('Should list local account videos', async function () { - const { total, data } = await servers[0].videosCommand.listByAccount({ token: userToken, accountName: 'root@localhost:' + servers[0].port }) + const { total, data } = await servers[0].videos.listByAccount({ token: userToken, accountName: 'root@localhost:' + servers[0].port }) expect(total).to.equal(1) expect(data).to.have.lengthOf(1) }) it('Should list remote account videos', async function () { - const { total, data } = await servers[0].videosCommand.listByAccount({ token: userToken, accountName: 'root@localhost:' + servers[1].port }) + const { total, data } = await servers[0].videos.listByAccount({ token: userToken, accountName: 'root@localhost:' + servers[1].port }) expect(total).to.equal(1) expect(data).to.have.lengthOf(1) @@ -109,7 +109,7 @@ describe('Test follow constraints', function () { it('Should list local channel videos', async function () { const videoChannelName = 'root_channel@localhost:' + servers[0].port - const { total, data } = await servers[0].videosCommand.listByChannel({ token: userToken, videoChannelName }) + const { total, data } = await servers[0].videos.listByChannel({ token: userToken, videoChannelName }) expect(total).to.equal(1) expect(data).to.have.lengthOf(1) @@ -117,7 +117,7 @@ describe('Test follow constraints', function () { it('Should list remote channel videos', async function () { const videoChannelName = 'root_channel@localhost:' + servers[1].port - const { total, data } = await servers[0].videosCommand.listByChannel({ token: userToken, videoChannelName }) + const { total, data } = await servers[0].videos.listByChannel({ token: userToken, videoChannelName }) expect(total).to.equal(1) expect(data).to.have.lengthOf(1) @@ -130,17 +130,17 @@ describe('Test follow constraints', function () { before(async function () { this.timeout(30000) - await servers[0].followsCommand.unfollow({ target: servers[1] }) + await servers[0].follows.unfollow({ target: servers[1] }) }) describe('With an unlogged user', function () { it('Should get the local video', async function () { - await servers[0].videosCommand.get({ id: video1UUID }) + await servers[0].videos.get({ id: video1UUID }) }) it('Should not get the remote video', async function () { - const body = await servers[0].videosCommand.get({ id: video2UUID, expectedStatus: HttpStatusCode.FORBIDDEN_403 }) + const body = await servers[0].videos.get({ id: video2UUID, expectedStatus: HttpStatusCode.FORBIDDEN_403 }) const error = body as unknown as PeerTubeProblemDocument const doc = 'https://docs.joinpeertube.org/api-rest-reference.html#section/Errors/does_not_respect_follow_constraints' @@ -156,7 +156,7 @@ describe('Test follow constraints', function () { }) it('Should list local account videos', async function () { - const { total, data } = await servers[0].videosCommand.listByAccount({ + const { total, data } = await servers[0].videos.listByAccount({ token: undefined, accountName: 'root@localhost:' + servers[0].port }) @@ -166,7 +166,7 @@ describe('Test follow constraints', function () { }) it('Should not list remote account videos', async function () { - const { total, data } = await servers[0].videosCommand.listByAccount({ + const { total, data } = await servers[0].videos.listByAccount({ token: undefined, accountName: 'root@localhost:' + servers[1].port }) @@ -177,7 +177,7 @@ describe('Test follow constraints', function () { it('Should list local channel videos', async function () { const videoChannelName = 'root_channel@localhost:' + servers[0].port - const { total, data } = await servers[0].videosCommand.listByChannel({ token: undefined, videoChannelName }) + const { total, data } = await servers[0].videos.listByChannel({ token: undefined, videoChannelName }) expect(total).to.equal(1) expect(data).to.have.lengthOf(1) @@ -185,7 +185,7 @@ describe('Test follow constraints', function () { it('Should not list remote channel videos', async function () { const videoChannelName = 'root_channel@localhost:' + servers[1].port - const { total, data } = await servers[0].videosCommand.listByChannel({ token: undefined, videoChannelName }) + const { total, data } = await servers[0].videos.listByChannel({ token: undefined, videoChannelName }) expect(total).to.equal(0) expect(data).to.have.lengthOf(0) @@ -194,22 +194,22 @@ describe('Test follow constraints', function () { describe('With a logged user', function () { it('Should get the local video', async function () { - await servers[0].videosCommand.getWithToken({ token: userToken, id: video1UUID }) + await servers[0].videos.getWithToken({ token: userToken, id: video1UUID }) }) it('Should get the remote video', async function () { - await servers[0].videosCommand.getWithToken({ token: userToken, id: video2UUID }) + await servers[0].videos.getWithToken({ token: userToken, id: video2UUID }) }) it('Should list local account videos', async function () { - const { total, data } = await servers[0].videosCommand.listByAccount({ token: userToken, accountName: 'root@localhost:' + servers[0].port }) + const { total, data } = await servers[0].videos.listByAccount({ token: userToken, accountName: 'root@localhost:' + servers[0].port }) expect(total).to.equal(1) expect(data).to.have.lengthOf(1) }) it('Should list remote account videos', async function () { - const { total, data } = await servers[0].videosCommand.listByAccount({ token: userToken, accountName: 'root@localhost:' + servers[1].port }) + const { total, data } = await servers[0].videos.listByAccount({ token: userToken, accountName: 'root@localhost:' + servers[1].port }) expect(total).to.equal(1) expect(data).to.have.lengthOf(1) @@ -217,7 +217,7 @@ describe('Test follow constraints', function () { it('Should list local channel videos', async function () { const videoChannelName = 'root_channel@localhost:' + servers[0].port - const { total, data } = await servers[0].videosCommand.listByChannel({ token: userToken, videoChannelName }) + const { total, data } = await servers[0].videos.listByChannel({ token: userToken, videoChannelName }) expect(total).to.equal(1) expect(data).to.have.lengthOf(1) @@ -225,7 +225,7 @@ describe('Test follow constraints', function () { it('Should list remote channel videos', async function () { const videoChannelName = 'root_channel@localhost:' + servers[1].port - const { total, data } = await servers[0].videosCommand.listByChannel({ token: userToken, videoChannelName }) + const { total, data } = await servers[0].videos.listByChannel({ token: userToken, videoChannelName }) expect(total).to.equal(1) expect(data).to.have.lengthOf(1) diff --git a/server/tests/api/server/follows-moderation.ts b/server/tests/api/server/follows-moderation.ts index 6d6eca9a8..045024544 100644 --- a/server/tests/api/server/follows-moderation.ts +++ b/server/tests/api/server/follows-moderation.ts @@ -15,8 +15,8 @@ const expect = chai.expect async function checkServer1And2HasFollowers (servers: ServerInfo[], state = 'accepted') { const fns = [ - servers[0].followsCommand.getFollowings.bind(servers[0].followsCommand), - servers[1].followsCommand.getFollowers.bind(servers[1].followsCommand) + servers[0].follows.getFollowings.bind(servers[0].follows), + servers[1].follows.getFollowers.bind(servers[1].follows) ] for (const fn of fns) { @@ -32,8 +32,8 @@ async function checkServer1And2HasFollowers (servers: ServerInfo[], state = 'acc async function checkNoFollowers (servers: ServerInfo[]) { const fns = [ - servers[0].followsCommand.getFollowings.bind(servers[0].followsCommand), - servers[1].followsCommand.getFollowers.bind(servers[1].followsCommand) + servers[0].follows.getFollowings.bind(servers[0].follows), + servers[1].follows.getFollowers.bind(servers[1].follows) ] for (const fn of fns) { @@ -54,7 +54,7 @@ describe('Test follows moderation', function () { // Get the access tokens await setAccessTokensToServers(servers) - commands = servers.map(s => s.followsCommand) + commands = servers.map(s => s.follows) }) it('Should have server 1 following server 2', async function () { @@ -93,7 +93,7 @@ describe('Test follows moderation', function () { } } - await servers[1].configCommand.updateCustomSubConfig({ newConfig: subConfig }) + await servers[1].config.updateCustomSubConfig({ newConfig: subConfig }) await commands[0].follow({ targets: [ servers[1].url ] }) await waitJobs(servers) @@ -113,7 +113,7 @@ describe('Test follows moderation', function () { } } - await servers[1].configCommand.updateCustomSubConfig({ newConfig: subConfig }) + await servers[1].config.updateCustomSubConfig({ newConfig: subConfig }) await commands[0].follow({ targets: [ servers[1].url ] }) await waitJobs(servers) @@ -136,8 +136,8 @@ describe('Test follows moderation', function () { } } - await servers[1].configCommand.updateCustomSubConfig({ newConfig: subConfig }) - await servers[2].configCommand.updateCustomSubConfig({ newConfig: subConfig }) + await servers[1].config.updateCustomSubConfig({ newConfig: subConfig }) + await servers[2].config.updateCustomSubConfig({ newConfig: subConfig }) await commands[0].follow({ targets: [ servers[1].url ] }) await waitJobs(servers) diff --git a/server/tests/api/server/follows.ts b/server/tests/api/server/follows.ts index 5ce8938fa..d43064689 100644 --- a/server/tests/api/server/follows.ts +++ b/server/tests/api/server/follows.ts @@ -26,7 +26,7 @@ describe('Test follows', function () { this.timeout(30000) servers = await flushAndRunMultipleServers(3) - followsCommands = servers.map(s => s.followsCommand) + followsCommands = servers.map(s => s.follows) // Get the access tokens await setAccessTokensToServers(servers) @@ -34,7 +34,7 @@ describe('Test follows', function () { it('Should not have followers', async function () { for (const server of servers) { - const body = await server.followsCommand.getFollowers({ start: 0, count: 5, sort: 'createdAt' }) + const body = await server.follows.getFollowers({ start: 0, count: 5, sort: 'createdAt' }) expect(body.total).to.equal(0) const follows = body.data @@ -45,7 +45,7 @@ describe('Test follows', function () { it('Should not have following', async function () { for (const server of servers) { - const body = await server.followsCommand.getFollowings({ start: 0, count: 5, sort: 'createdAt' }) + const body = await server.follows.getFollowings({ start: 0, count: 5, sort: 'createdAt' }) expect(body.total).to.equal(0) const follows = body.data @@ -141,7 +141,7 @@ describe('Test follows', function () { it('Should have 0 followings on server 2 and 3', async function () { for (const server of [ servers[1], servers[2] ]) { - const body = await server.followsCommand.getFollowings({ start: 0, count: 5, sort: 'createdAt' }) + const body = await server.follows.getFollowings({ start: 0, count: 5, sort: 'createdAt' }) expect(body.total).to.equal(0) const follows = body.data @@ -152,7 +152,7 @@ describe('Test follows', function () { it('Should have 1 followers on server 2 and 3', async function () { for (const server of [ servers[1], servers[2] ]) { - const body = await server.followsCommand.getFollowers({ start: 0, count: 1, sort: 'createdAt' }) + const body = await server.follows.getFollowers({ start: 0, count: 1, sort: 'createdAt' }) expect(body.total).to.equal(1) const follows = body.data @@ -284,25 +284,25 @@ describe('Test follows', function () { it('Should upload a video on server 2 and 3 and propagate only the video of server 2', async function () { this.timeout(60000) - await servers[1].videosCommand.upload({ attributes: { name: 'server2' } }) - await servers[2].videosCommand.upload({ attributes: { name: 'server3' } }) + await servers[1].videos.upload({ attributes: { name: 'server2' } }) + await servers[2].videos.upload({ attributes: { name: 'server3' } }) await waitJobs(servers) { - const { total, data } = await servers[0].videosCommand.list() + const { total, data } = await servers[0].videos.list() expect(total).to.equal(1) expect(data[0].name).to.equal('server2') } { - const { total, data } = await servers[1].videosCommand.list() + const { total, data } = await servers[1].videos.list() expect(total).to.equal(1) expect(data[0].name).to.equal('server2') } { - const { total, data } = await servers[2].videosCommand.list() + const { total, data } = await servers[2].videos.list() expect(total).to.equal(1) expect(data[0].name).to.equal('server3') } @@ -322,60 +322,60 @@ describe('Test follows', function () { tags: [ 'tag1', 'tag2', 'tag3' ] } - await servers[2].videosCommand.upload({ attributes: { name: 'server3-2' } }) - await servers[2].videosCommand.upload({ attributes: { name: 'server3-3' } }) - await servers[2].videosCommand.upload({ attributes: video4Attributes }) - await servers[2].videosCommand.upload({ attributes: { name: 'server3-5' } }) - await servers[2].videosCommand.upload({ attributes: { name: 'server3-6' } }) + await servers[2].videos.upload({ attributes: { name: 'server3-2' } }) + await servers[2].videos.upload({ attributes: { name: 'server3-3' } }) + await servers[2].videos.upload({ attributes: video4Attributes }) + await servers[2].videos.upload({ attributes: { name: 'server3-5' } }) + await servers[2].videos.upload({ attributes: { name: 'server3-6' } }) { - const userAccessToken = await servers[2].usersCommand.generateUserAndToken('captain') + const userAccessToken = await servers[2].users.generateUserAndToken('captain') - const { data } = await servers[2].videosCommand.list() + const { data } = await servers[2].videos.list() video4 = data.find(v => v.name === 'server3-4') { - await servers[2].videosCommand.rate({ id: video4.id, rating: 'like' }) - await servers[2].videosCommand.rate({ token: userAccessToken, id: video4.id, rating: 'dislike' }) + await servers[2].videos.rate({ id: video4.id, rating: 'like' }) + await servers[2].videos.rate({ token: userAccessToken, id: video4.id, rating: 'dislike' }) } { { const text = 'my super first comment' - const created = await servers[2].commentsCommand.createThread({ videoId: video4.id, text }) + const created = await servers[2].comments.createThread({ videoId: video4.id, text }) const threadId = created.id const text1 = 'my super answer to thread 1' - const childComment = await servers[2].commentsCommand.addReply({ videoId: video4.id, toCommentId: threadId, text: text1 }) + const childComment = await servers[2].comments.addReply({ videoId: video4.id, toCommentId: threadId, text: text1 }) const text2 = 'my super answer to answer of thread 1' - await servers[2].commentsCommand.addReply({ videoId: video4.id, toCommentId: childComment.id, text: text2 }) + await servers[2].comments.addReply({ videoId: video4.id, toCommentId: childComment.id, text: text2 }) const text3 = 'my second answer to thread 1' - await servers[2].commentsCommand.addReply({ videoId: video4.id, toCommentId: threadId, text: text3 }) + await servers[2].comments.addReply({ videoId: video4.id, toCommentId: threadId, text: text3 }) } { const text = 'will be deleted' - const created = await servers[2].commentsCommand.createThread({ videoId: video4.id, text }) + const created = await servers[2].comments.createThread({ videoId: video4.id, text }) const threadId = created.id const text1 = 'answer to deleted' - await servers[2].commentsCommand.addReply({ videoId: video4.id, toCommentId: threadId, text: text1 }) + await servers[2].comments.addReply({ videoId: video4.id, toCommentId: threadId, text: text1 }) const text2 = 'will also be deleted' - const childComment = await servers[2].commentsCommand.addReply({ videoId: video4.id, toCommentId: threadId, text: text2 }) + const childComment = await servers[2].comments.addReply({ videoId: video4.id, toCommentId: threadId, text: text2 }) const text3 = 'my second answer to deleted' - await servers[2].commentsCommand.addReply({ videoId: video4.id, toCommentId: childComment.id, text: text3 }) + await servers[2].comments.addReply({ videoId: video4.id, toCommentId: childComment.id, text: text3 }) - await servers[2].commentsCommand.delete({ videoId: video4.id, commentId: threadId }) - await servers[2].commentsCommand.delete({ videoId: video4.id, commentId: childComment.id }) + await servers[2].comments.delete({ videoId: video4.id, commentId: threadId }) + await servers[2].comments.delete({ videoId: video4.id, commentId: childComment.id }) } } { - await servers[2].captionsCommand.createVideoCaption({ + await servers[2].captions.createVideoCaption({ language: 'ar', videoId: video4.id, fixture: 'subtitle-good2.vtt' @@ -404,7 +404,7 @@ describe('Test follows', function () { }) it('Should have propagated videos', async function () { - const { total, data } = await servers[0].videosCommand.list() + const { total, data } = await servers[0].videos.list() expect(total).to.equal(7) const video2 = data.find(v => v.name === 'server3-2') @@ -454,7 +454,7 @@ describe('Test follows', function () { }) it('Should have propagated comments', async function () { - const { total, data } = await servers[0].commentsCommand.listThreads({ videoId: video4.id, sort: 'createdAt' }) + const { total, data } = await servers[0].comments.listThreads({ videoId: video4.id, sort: 'createdAt' }) expect(total).to.equal(2) expect(data).to.be.an('array') @@ -474,7 +474,7 @@ describe('Test follows', function () { const threadId = comment.threadId - const tree = await servers[0].commentsCommand.getThread({ videoId: video4.id, threadId }) + const tree = await servers[0].comments.getThread({ videoId: video4.id, threadId }) expect(tree.comment.text).equal('my super first comment') expect(tree.children).to.have.lengthOf(2) @@ -502,7 +502,7 @@ describe('Test follows', function () { expect(deletedComment.totalReplies).to.equal(2) expect(dateIsValid(deletedComment.deletedAt as string)).to.be.true - const tree = await servers[0].commentsCommand.getThread({ videoId: video4.id, threadId: deletedComment.threadId }) + const tree = await servers[0].comments.getThread({ videoId: video4.id, threadId: deletedComment.threadId }) const [ commentRoot, deletedChildRoot ] = tree.children expect(deletedChildRoot).to.not.be.undefined @@ -527,7 +527,7 @@ describe('Test follows', function () { }) it('Should have propagated captions', async function () { - const body = await servers[0].captionsCommand.listVideoCaptions({ videoId: video4.id }) + const body = await servers[0].captions.listVideoCaptions({ videoId: video4.id }) expect(body.total).to.equal(1) expect(body.data).to.have.lengthOf(1) @@ -545,7 +545,7 @@ describe('Test follows', function () { await waitJobs(servers) - const { total } = await servers[0].videosCommand.list() + const { total } = await servers[0].videos.list() expect(total).to.equal(1) }) diff --git a/server/tests/api/server/handle-down.ts b/server/tests/api/server/handle-down.ts index 35b905a8c..de3dee826 100644 --- a/server/tests/api/server/handle-down.ts +++ b/server/tests/api/server/handle-down.ts @@ -55,7 +55,7 @@ describe('Test handle downs', function () { this.timeout(30000) servers = await flushAndRunMultipleServers(3) - commentCommands = servers.map(s => s.commentsCommand) + commentCommands = servers.map(s => s.comments) checkAttributes = { name: 'my super name for server 1', @@ -99,19 +99,19 @@ describe('Test handle downs', function () { this.timeout(240000) // Server 2 and 3 follow server 1 - await servers[1].followsCommand.follow({ targets: [ servers[0].url ] }) - await servers[2].followsCommand.follow({ targets: [ servers[0].url ] }) + await servers[1].follows.follow({ targets: [ servers[0].url ] }) + await servers[2].follows.follow({ targets: [ servers[0].url ] }) await waitJobs(servers) // Upload a video to server 1 - await servers[0].videosCommand.upload({ attributes: videoAttributes }) + await servers[0].videos.upload({ attributes: videoAttributes }) await waitJobs(servers) // And check all servers have this video for (const server of servers) { - const { data } = await server.videosCommand.list() + const { data } = await server.videos.list() expect(data).to.be.an('array') expect(data).to.have.lengthOf(1) } @@ -121,7 +121,7 @@ describe('Test handle downs', function () { // Remove server 2 follower for (let i = 0; i < 10; i++) { - await servers[0].videosCommand.upload({ attributes: videoAttributes }) + await servers[0].videos.upload({ attributes: videoAttributes }) } await waitJobs([ servers[0], servers[2] ]) @@ -129,12 +129,12 @@ describe('Test handle downs', function () { // Kill server 3 await killallServers([ servers[2] ]) - missedVideo1 = await servers[0].videosCommand.upload({ attributes: videoAttributes }) + missedVideo1 = await servers[0].videos.upload({ attributes: videoAttributes }) - missedVideo2 = await servers[0].videosCommand.upload({ attributes: videoAttributes }) + missedVideo2 = await servers[0].videos.upload({ attributes: videoAttributes }) // Unlisted video - unlistedVideo = await servers[0].videosCommand.upload({ attributes: unlistedVideoAttributes }) + unlistedVideo = await servers[0].videos.upload({ attributes: unlistedVideoAttributes }) // Add comments to video 2 { @@ -153,7 +153,7 @@ describe('Test handle downs', function () { await wait(11000) // Only server 3 is still a follower of server 1 - const body = await servers[0].followsCommand.getFollowers({ start: 0, count: 2, sort: 'createdAt' }) + const body = await servers[0].follows.getFollowers({ start: 0, count: 2, sort: 'createdAt' }) expect(body.data).to.be.an('array') expect(body.data).to.have.lengthOf(1) expect(body.data[0].follower.host).to.equal('localhost:' + servers[2].port) @@ -163,7 +163,7 @@ describe('Test handle downs', function () { const states: JobState[] = [ 'waiting', 'active' ] for (const state of states) { - const body = await servers[0].jobsCommand.getJobsList({ + const body = await servers[0].jobs.getJobsList({ state: state, start: 0, count: 50, @@ -179,14 +179,14 @@ describe('Test handle downs', function () { await reRunServer(servers[1]) await reRunServer(servers[2]) - await servers[1].followsCommand.unfollow({ target: servers[0] }) + await servers[1].follows.unfollow({ target: servers[0] }) await waitJobs(servers) - await servers[1].followsCommand.follow({ targets: [ servers[0].url ] }) + await servers[1].follows.follow({ targets: [ servers[0].url ] }) await waitJobs(servers) - const body = await servers[0].followsCommand.getFollowers({ start: 0, count: 2, sort: 'createdAt' }) + const body = await servers[0].follows.getFollowers({ start: 0, count: 2, sort: 'createdAt' }) expect(body.data).to.be.an('array') expect(body.data).to.have.lengthOf(2) }) @@ -195,25 +195,25 @@ describe('Test handle downs', function () { this.timeout(15000) { - const { data } = await servers[2].videosCommand.list() + const { data } = await servers[2].videos.list() expect(data).to.be.an('array') expect(data).to.have.lengthOf(11) } - await servers[0].videosCommand.update({ id: missedVideo1.uuid }) - await servers[0].videosCommand.update({ id: unlistedVideo.uuid }) + await servers[0].videos.update({ id: missedVideo1.uuid }) + await servers[0].videos.update({ id: unlistedVideo.uuid }) await waitJobs(servers) { - const { data } = await servers[2].videosCommand.list() + const { data } = await servers[2].videos.list() expect(data).to.be.an('array') // 1 video is unlisted expect(data).to.have.lengthOf(12) } // Check unlisted video - const video = await servers[2].videosCommand.get({ id: unlistedVideo.uuid }) + const video = await servers[2].videos.get({ id: unlistedVideo.uuid }) await completeVideoCheck(servers[2], video, unlistedCheckAttributes) }) @@ -224,16 +224,16 @@ describe('Test handle downs', function () { await waitJobs(servers) - await servers[2].videosCommand.get({ id: missedVideo2.uuid }) + await servers[2].videos.get({ id: missedVideo2.uuid }) { - const { data } = await servers[2].commentsCommand.listThreads({ videoId: missedVideo2.uuid }) + const { data } = await servers[2].comments.listThreads({ videoId: missedVideo2.uuid }) expect(data).to.be.an('array') expect(data).to.have.lengthOf(1) threadIdServer2 = data[0].id - const tree = await servers[2].commentsCommand.getThread({ videoId: missedVideo2.uuid, threadId: threadIdServer2 }) + const tree = await servers[2].comments.getThread({ videoId: missedVideo2.uuid, threadId: threadIdServer2 }) expect(tree.comment.text).equal('thread 1') expect(tree.children).to.have.lengthOf(1) @@ -256,7 +256,7 @@ describe('Test handle downs', function () { it('Should correctly reply to the comment', async function () { this.timeout(15000) - await servers[2].commentsCommand.addReply({ videoId: missedVideo2.uuid, toCommentId: commentIdServer2, text: 'comment 1-4' }) + await servers[2].comments.addReply({ videoId: missedVideo2.uuid, toCommentId: commentIdServer2, text: 'comment 1-4' }) await waitJobs(servers) @@ -286,24 +286,24 @@ describe('Test handle downs', function () { this.timeout(120000) for (let i = 0; i < 10; i++) { - const uuid = (await servers[0].videosCommand.quickUpload({ name: 'video ' + i })).uuid + const uuid = (await servers[0].videos.quickUpload({ name: 'video ' + i })).uuid videoIdsServer1.push(uuid) } await waitJobs(servers) for (const id of videoIdsServer1) { - await servers[1].videosCommand.get({ id }) + await servers[1].videos.get({ id }) } await waitJobs(servers) - await servers[1].sqlCommand.setActorFollowScores(20) + await servers[1].sql.setActorFollowScores(20) // Wait video expiration await wait(11000) // Refresh video -> score + 10 = 30 - await servers[1].videosCommand.get({ id: videoIdsServer1[0] }) + await servers[1].videos.get({ id: videoIdsServer1[0] }) await waitJobs(servers) }) @@ -318,14 +318,14 @@ describe('Test handle downs', function () { for (let i = 0; i < 5; i++) { try { - await servers[1].videosCommand.get({ id: videoIdsServer1[i] }) + await servers[1].videos.get({ id: videoIdsServer1[i] }) await waitJobs([ servers[1] ]) await wait(1500) } catch {} } for (const id of videoIdsServer1) { - await servers[1].videosCommand.get({ id, expectedStatus: HttpStatusCode.FORBIDDEN_403 }) + await servers[1].videos.get({ id, expectedStatus: HttpStatusCode.FORBIDDEN_403 }) } }) diff --git a/server/tests/api/server/homepage.ts b/server/tests/api/server/homepage.ts index 18b9edc31..aac075321 100644 --- a/server/tests/api/server/homepage.ts +++ b/server/tests/api/server/homepage.ts @@ -16,7 +16,7 @@ import { const expect = chai.expect async function getHomepageState (server: ServerInfo) { - const config = await server.configCommand.getConfig() + const config = await server.config.getConfig() return config.homepage.enabled } @@ -31,7 +31,7 @@ describe('Test instance homepage actions', function () { server = await flushAndRunServer(1) await setAccessTokensToServers([ server ]) - command = server.customPageCommand + command = server.customPage }) it('Should not have a homepage', async function () { diff --git a/server/tests/api/server/jobs.ts b/server/tests/api/server/jobs.ts index aa4c7587b..0c44e4dad 100644 --- a/server/tests/api/server/jobs.ts +++ b/server/tests/api/server/jobs.ts @@ -31,21 +31,21 @@ describe('Test jobs', function () { it('Should create some jobs', async function () { this.timeout(120000) - await servers[1].videosCommand.upload({ attributes: { name: 'video1' } }) - await servers[1].videosCommand.upload({ attributes: { name: 'video2' } }) + await servers[1].videos.upload({ attributes: { name: 'video1' } }) + await servers[1].videos.upload({ attributes: { name: 'video2' } }) await waitJobs(servers) }) it('Should list jobs', async function () { - const body = await servers[1].jobsCommand.getJobsList({ state: 'completed' }) + const body = await servers[1].jobs.getJobsList({ state: 'completed' }) expect(body.total).to.be.above(2) expect(body.data).to.have.length.above(2) }) it('Should list jobs with sort, pagination and job type', async function () { { - const body = await servers[1].jobsCommand.getJobsList({ + const body = await servers[1].jobs.getJobsList({ state: 'completed', start: 1, count: 2, @@ -66,7 +66,7 @@ describe('Test jobs', function () { } { - const body = await servers[1].jobsCommand.getJobsList({ + const body = await servers[1].jobs.getJobsList({ state: 'completed', start: 0, count: 100, @@ -82,7 +82,7 @@ describe('Test jobs', function () { }) it('Should list all jobs', async function () { - const body = await servers[1].jobsCommand.getJobsList() + const body = await servers[1].jobs.getJobsList() expect(body.total).to.be.above(2) const jobs = body.data diff --git a/server/tests/api/server/logs.ts b/server/tests/api/server/logs.ts index e7bef5a4a..2d141fd8c 100644 --- a/server/tests/api/server/logs.ts +++ b/server/tests/api/server/logs.ts @@ -25,7 +25,7 @@ describe('Test logs', function () { server = await flushAndRunServer(1) await setAccessTokensToServers([ server ]) - logsCommand = server.logsCommand + logsCommand = server.logs }) describe('With the standard log file', function () { @@ -33,12 +33,12 @@ describe('Test logs', function () { it('Should get logs with a start date', async function () { this.timeout(20000) - await server.videosCommand.upload({ attributes: { name: 'video 1' } }) + await server.videos.upload({ attributes: { name: 'video 1' } }) await waitJobs([ server ]) const now = new Date() - await server.videosCommand.upload({ attributes: { name: 'video 2' } }) + await server.videos.upload({ attributes: { name: 'video 2' } }) await waitJobs([ server ]) const body = await logsCommand.getLogs({ startDate: now }) @@ -51,17 +51,17 @@ describe('Test logs', function () { it('Should get logs with an end date', async function () { this.timeout(30000) - await server.videosCommand.upload({ attributes: { name: 'video 3' } }) + await server.videos.upload({ attributes: { name: 'video 3' } }) await waitJobs([ server ]) const now1 = new Date() - await server.videosCommand.upload({ attributes: { name: 'video 4' } }) + await server.videos.upload({ attributes: { name: 'video 4' } }) await waitJobs([ server ]) const now2 = new Date() - await server.videosCommand.upload({ attributes: { name: 'video 5' } }) + await server.videos.upload({ attributes: { name: 'video 5' } }) await waitJobs([ server ]) const body = await logsCommand.getLogs({ startDate: now1, endDate: now2 }) @@ -77,7 +77,7 @@ describe('Test logs', function () { const now = new Date() - await server.videosCommand.upload({ attributes: { name: 'video 6' } }) + await server.videos.upload({ attributes: { name: 'video 6' } }) await waitJobs([ server ]) { @@ -100,7 +100,7 @@ describe('Test logs', function () { const now = new Date() - await server.serversCommand.ping() + await server.servers.ping() const body = await logsCommand.getLogs({ startDate: now, level: 'info' }) const logsString = JSON.stringify(body) @@ -117,7 +117,7 @@ describe('Test logs', function () { const now = new Date() - await server.serversCommand.ping() + await server.servers.ping() const body = await logsCommand.getLogs({ startDate: now, level: 'info' }) const logsString = JSON.stringify(body) @@ -130,12 +130,12 @@ describe('Test logs', function () { it('Should get logs with a start date', async function () { this.timeout(20000) - await server.videosCommand.upload({ attributes: { name: 'video 7' } }) + await server.videos.upload({ attributes: { name: 'video 7' } }) await waitJobs([ server ]) const now = new Date() - await server.videosCommand.upload({ attributes: { name: 'video 8' } }) + await server.videos.upload({ attributes: { name: 'video 8' } }) await waitJobs([ server ]) const body = await logsCommand.getAuditLogs({ startDate: now }) @@ -156,17 +156,17 @@ describe('Test logs', function () { it('Should get logs with an end date', async function () { this.timeout(30000) - await server.videosCommand.upload({ attributes: { name: 'video 9' } }) + await server.videos.upload({ attributes: { name: 'video 9' } }) await waitJobs([ server ]) const now1 = new Date() - await server.videosCommand.upload({ attributes: { name: 'video 10' } }) + await server.videos.upload({ attributes: { name: 'video 10' } }) await waitJobs([ server ]) const now2 = new Date() - await server.videosCommand.upload({ attributes: { name: 'video 11' } }) + await server.videos.upload({ attributes: { name: 'video 11' } }) await waitJobs([ server ]) const body = await logsCommand.getAuditLogs({ startDate: now1, endDate: now2 }) diff --git a/server/tests/api/server/plugins.ts b/server/tests/api/server/plugins.ts index 1fd5e613b..45a22e48d 100644 --- a/server/tests/api/server/plugins.ts +++ b/server/tests/api/server/plugins.ts @@ -33,7 +33,7 @@ describe('Test plugins', function () { server = await flushAndRunServer(1, configOverride) await setAccessTokensToServers([ server ]) - command = server.pluginsCommand + command = server.plugins }) it('Should list and search available plugins and themes', async function () { @@ -97,7 +97,7 @@ describe('Test plugins', function () { }) it('Should have the plugin loaded in the configuration', async function () { - const config = await server.configCommand.getConfig() + const config = await server.config.getConfig() const theme = config.theme.registered.find(r => r.name === 'background-red') expect(theme).to.not.be.undefined @@ -107,20 +107,20 @@ describe('Test plugins', function () { }) it('Should update the default theme in the configuration', async function () { - await server.configCommand.updateCustomSubConfig({ + await server.config.updateCustomSubConfig({ newConfig: { theme: { default: 'background-red' } } }) - const config = await server.configCommand.getConfig() + const config = await server.config.getConfig() expect(config.theme.default).to.equal('background-red') }) it('Should update my default theme', async function () { - await server.usersCommand.updateMe({ theme: 'background-red' }) + await server.users.updateMe({ theme: 'background-red' }) - const user = await server.usersCommand.getMyInfo() + const user = await server.users.getMyInfo() expect(user.theme).to.equal('background-red') }) @@ -187,7 +187,7 @@ describe('Test plugins', function () { it('Should have watched settings changes', async function () { this.timeout(10000) - await server.serversCommand.waitUntilLog('Settings changed!') + await server.servers.waitUntilLog('Settings changed!') }) it('Should get a plugin and a theme', async function () { @@ -234,7 +234,7 @@ describe('Test plugins', function () { await wait(6000) // Fake update our plugin version - await server.sqlCommand.setPluginVersion('hello-world', '0.0.1') + await server.sql.setPluginVersion('hello-world', '0.0.1') // Fake update package.json const packageJSON = await command.getPackageJSON('peertube-plugin-hello-world') @@ -293,7 +293,7 @@ describe('Test plugins', function () { }) it('Should have updated the configuration', async function () { - const config = await server.configCommand.getConfig() + const config = await server.config.getConfig() expect(config.theme.default).to.equal('default') @@ -305,7 +305,7 @@ describe('Test plugins', function () { }) it('Should have updated the user theme', async function () { - const user = await server.usersCommand.getMyInfo() + const user = await server.users.getMyInfo() expect(user.theme).to.equal('instance-default') }) diff --git a/server/tests/api/server/reverse-proxy.ts b/server/tests/api/server/reverse-proxy.ts index 5a6491430..de3cf02f2 100644 --- a/server/tests/api/server/reverse-proxy.ts +++ b/server/tests/api/server/reverse-proxy.ts @@ -33,59 +33,59 @@ describe('Test application behind a reverse proxy', function () { server = await flushAndRunServer(1, config) await setAccessTokensToServers([ server ]) - const { uuid } = await server.videosCommand.upload() + const { uuid } = await server.videos.upload() videoId = uuid }) it('Should view a video only once with the same IP by default', async function () { this.timeout(20000) - await server.videosCommand.view({ id: videoId }) - await server.videosCommand.view({ id: videoId }) + await server.videos.view({ id: videoId }) + await server.videos.view({ id: videoId }) // Wait the repeatable job await wait(8000) - const video = await server.videosCommand.get({ id: videoId }) + const video = await server.videos.get({ id: videoId }) expect(video.views).to.equal(1) }) it('Should view a video 2 times with the X-Forwarded-For header set', async function () { this.timeout(20000) - await server.videosCommand.view({ id: videoId, xForwardedFor: '0.0.0.1,127.0.0.1' }) - await server.videosCommand.view({ id: videoId, xForwardedFor: '0.0.0.2,127.0.0.1' }) + await server.videos.view({ id: videoId, xForwardedFor: '0.0.0.1,127.0.0.1' }) + await server.videos.view({ id: videoId, xForwardedFor: '0.0.0.2,127.0.0.1' }) // Wait the repeatable job await wait(8000) - const video = await server.videosCommand.get({ id: videoId }) + const video = await server.videos.get({ id: videoId }) expect(video.views).to.equal(3) }) it('Should view a video only once with the same client IP in the X-Forwarded-For header', async function () { this.timeout(20000) - await server.videosCommand.view({ id: videoId, xForwardedFor: '0.0.0.4,0.0.0.3,::ffff:127.0.0.1' }) - await server.videosCommand.view({ id: videoId, xForwardedFor: '0.0.0.5,0.0.0.3,127.0.0.1' }) + await server.videos.view({ id: videoId, xForwardedFor: '0.0.0.4,0.0.0.3,::ffff:127.0.0.1' }) + await server.videos.view({ id: videoId, xForwardedFor: '0.0.0.5,0.0.0.3,127.0.0.1' }) // Wait the repeatable job await wait(8000) - const video = await server.videosCommand.get({ id: videoId }) + const video = await server.videos.get({ id: videoId }) expect(video.views).to.equal(4) }) it('Should view a video two times with a different client IP in the X-Forwarded-For header', async function () { this.timeout(20000) - await server.videosCommand.view({ id: videoId, xForwardedFor: '0.0.0.8,0.0.0.6,127.0.0.1' }) - await server.videosCommand.view({ id: videoId, xForwardedFor: '0.0.0.8,0.0.0.7,127.0.0.1' }) + await server.videos.view({ id: videoId, xForwardedFor: '0.0.0.8,0.0.0.6,127.0.0.1' }) + await server.videos.view({ id: videoId, xForwardedFor: '0.0.0.8,0.0.0.7,127.0.0.1' }) // Wait the repeatable job await wait(8000) - const video = await server.videosCommand.get({ id: videoId }) + const video = await server.videos.get({ id: videoId }) expect(video.views).to.equal(6) }) @@ -93,22 +93,22 @@ describe('Test application behind a reverse proxy', function () { const user = { username: 'root', password: 'fail' } for (let i = 0; i < 19; i++) { - await server.loginCommand.login({ user, expectedStatus: HttpStatusCode.BAD_REQUEST_400 }) + await server.login.login({ user, expectedStatus: HttpStatusCode.BAD_REQUEST_400 }) } - await server.loginCommand.login({ user, expectedStatus: HttpStatusCode.TOO_MANY_REQUESTS_429 }) + await server.login.login({ user, expectedStatus: HttpStatusCode.TOO_MANY_REQUESTS_429 }) }) it('Should rate limit signup', async function () { for (let i = 0; i < 10; i++) { try { - await server.usersCommand.register({ username: 'test' + i }) + await server.users.register({ username: 'test' + i }) } catch { // empty } } - await server.usersCommand.register({ username: 'test42', expectedStatus: HttpStatusCode.TOO_MANY_REQUESTS_429 }) + await server.users.register({ username: 'test42', expectedStatus: HttpStatusCode.TOO_MANY_REQUESTS_429 }) }) it('Should not rate limit failed signup', async function () { @@ -117,10 +117,10 @@ describe('Test application behind a reverse proxy', function () { await wait(7000) for (let i = 0; i < 3; i++) { - await server.usersCommand.register({ username: 'test' + i, expectedStatus: HttpStatusCode.CONFLICT_409 }) + await server.users.register({ username: 'test' + i, expectedStatus: HttpStatusCode.CONFLICT_409 }) } - await server.usersCommand.register({ username: 'test43', expectedStatus: HttpStatusCode.NO_CONTENT_204 }) + await server.users.register({ username: 'test43', expectedStatus: HttpStatusCode.NO_CONTENT_204 }) }) @@ -131,13 +131,13 @@ describe('Test application behind a reverse proxy', function () { for (let i = 0; i < 100; i++) { try { - await server.videosCommand.get({ id: videoId }) + await server.videos.get({ id: videoId }) } catch { // don't care if it fails } } - await server.videosCommand.get({ id: videoId, expectedStatus: HttpStatusCode.TOO_MANY_REQUESTS_429 }) + await server.videos.get({ id: videoId, expectedStatus: HttpStatusCode.TOO_MANY_REQUESTS_429 }) }) after(async function () { diff --git a/server/tests/api/server/services.ts b/server/tests/api/server/services.ts index a62fb3939..28f9ae3b6 100644 --- a/server/tests/api/server/services.ts +++ b/server/tests/api/server/services.ts @@ -23,25 +23,25 @@ describe('Test services', function () { { const attributes = { name: 'my super name' } - await server.videosCommand.upload({ attributes }) + await server.videos.upload({ attributes }) - const { data } = await server.videosCommand.list() + const { data } = await server.videos.list() video = data[0] } { - const created = await server.playlistsCommand.create({ + const created = await server.playlists.create({ attributes: { displayName: 'The Life and Times of Scrooge McDuck', privacy: VideoPlaylistPrivacy.PUBLIC, - videoChannelId: server.videoChannel.id + videoChannelId: server.store.channel.id } }) playlistUUID = created.uuid playlistDisplayName = 'The Life and Times of Scrooge McDuck' - await server.playlistsCommand.addElement({ + await server.playlists.addElement({ playlistId: created.id, attributes: { videoId: video.id @@ -54,7 +54,7 @@ describe('Test services', function () { for (const basePath of [ '/videos/watch/', '/w/' ]) { const oembedUrl = 'http://localhost:' + server.port + basePath + video.uuid - const res = await server.servicesCommand.getOEmbed({ oembedUrl }) + const res = await server.services.getOEmbed({ oembedUrl }) const expectedHtml = '' @@ -62,7 +62,7 @@ describe('Test services', function () { expect(res.body.html).to.equal(expectedHtml) expect(res.body.title).to.equal(video.name) - expect(res.body.author_name).to.equal(server.videoChannel.displayName) + expect(res.body.author_name).to.equal(server.store.channel.displayName) expect(res.body.width).to.equal(560) expect(res.body.height).to.equal(315) expect(res.body.thumbnail_url).to.equal(expectedThumbnailUrl) @@ -75,14 +75,14 @@ describe('Test services', function () { for (const basePath of [ '/videos/watch/playlist/', '/w/p/' ]) { const oembedUrl = 'http://localhost:' + server.port + basePath + playlistUUID - const res = await server.servicesCommand.getOEmbed({ oembedUrl }) + const res = await server.services.getOEmbed({ oembedUrl }) const expectedHtml = '' expect(res.body.html).to.equal(expectedHtml) expect(res.body.title).to.equal('The Life and Times of Scrooge McDuck') - expect(res.body.author_name).to.equal(server.videoChannel.displayName) + expect(res.body.author_name).to.equal(server.store.channel.displayName) expect(res.body.width).to.equal(560) expect(res.body.height).to.equal(315) expect(res.body.thumbnail_url).exist @@ -98,14 +98,14 @@ describe('Test services', function () { const maxHeight = 50 const maxWidth = 50 - const res = await server.servicesCommand.getOEmbed({ oembedUrl, format, maxHeight, maxWidth }) + const res = await server.services.getOEmbed({ oembedUrl, format, maxHeight, maxWidth }) const expectedHtml = '' expect(res.body.html).to.equal(expectedHtml) expect(res.body.title).to.equal(video.name) - expect(res.body.author_name).to.equal(server.videoChannel.displayName) + expect(res.body.author_name).to.equal(server.store.channel.displayName) expect(res.body.height).to.equal(50) expect(res.body.width).to.equal(50) expect(res.body).to.not.have.property('thumbnail_url') diff --git a/server/tests/api/server/stats.ts b/server/tests/api/server/stats.ts index 3eb1efb94..be5abad52 100644 --- a/server/tests/api/server/stats.ts +++ b/server/tests/api/server/stats.ts @@ -32,23 +32,23 @@ describe('Test stats (excluding redundancy)', function () { await doubleFollow(servers[0], servers[1]) - await servers[0].usersCommand.create({ username: user.username, password: user.password }) + await servers[0].users.create({ username: user.username, password: user.password }) - const { uuid } = await servers[0].videosCommand.upload({ attributes: { fixture: 'video_short.webm' } }) + const { uuid } = await servers[0].videos.upload({ attributes: { fixture: 'video_short.webm' } }) - await servers[0].commentsCommand.createThread({ videoId: uuid, text: 'comment' }) + await servers[0].comments.createThread({ videoId: uuid, text: 'comment' }) - await servers[0].videosCommand.view({ id: uuid }) + await servers[0].videos.view({ id: uuid }) // Wait the video views repeatable job await wait(8000) - await servers[2].followsCommand.follow({ targets: [ servers[0].url ] }) + await servers[2].follows.follow({ targets: [ servers[0].url ] }) await waitJobs(servers) }) it('Should have the correct stats on instance 1', async function () { - const data = await servers[0].statsCommand.get() + const data = await servers[0].stats.get() expect(data.totalLocalVideoComments).to.equal(1) expect(data.totalLocalVideos).to.equal(1) @@ -63,7 +63,7 @@ describe('Test stats (excluding redundancy)', function () { }) it('Should have the correct stats on instance 2', async function () { - const data = await servers[1].statsCommand.get() + const data = await servers[1].stats.get() expect(data.totalLocalVideoComments).to.equal(0) expect(data.totalLocalVideos).to.equal(0) @@ -78,7 +78,7 @@ describe('Test stats (excluding redundancy)', function () { }) it('Should have the correct stats on instance 3', async function () { - const data = await servers[2].statsCommand.get() + const data = await servers[2].stats.get() expect(data.totalLocalVideoComments).to.equal(0) expect(data.totalLocalVideos).to.equal(0) @@ -94,10 +94,10 @@ describe('Test stats (excluding redundancy)', function () { it('Should have the correct total videos stats after an unfollow', async function () { this.timeout(15000) - await servers[2].followsCommand.unfollow({ target: servers[0] }) + await servers[2].follows.unfollow({ target: servers[0] }) await waitJobs(servers) - const data = await servers[2].statsCommand.get() + const data = await servers[2].stats.get() expect(data.totalVideos).to.equal(0) }) @@ -106,7 +106,7 @@ describe('Test stats (excluding redundancy)', function () { const server = servers[0] { - const data = await server.statsCommand.get() + const data = await server.stats.get() expect(data.totalDailyActiveUsers).to.equal(1) expect(data.totalWeeklyActiveUsers).to.equal(1) @@ -114,9 +114,9 @@ describe('Test stats (excluding redundancy)', function () { } { - await server.loginCommand.getAccessToken(user) + await server.login.getAccessToken(user) - const data = await server.statsCommand.get() + const data = await server.stats.get() expect(data.totalDailyActiveUsers).to.equal(2) expect(data.totalWeeklyActiveUsers).to.equal(2) @@ -128,7 +128,7 @@ describe('Test stats (excluding redundancy)', function () { const server = servers[0] { - const data = await server.statsCommand.get() + const data = await server.stats.get() expect(data.totalLocalDailyActiveVideoChannels).to.equal(1) expect(data.totalLocalWeeklyActiveVideoChannels).to.equal(1) @@ -140,10 +140,10 @@ describe('Test stats (excluding redundancy)', function () { name: 'stats_channel', displayName: 'My stats channel' } - const created = await server.channelsCommand.create({ attributes }) + const created = await server.channels.create({ attributes }) channelId = created.id - const data = await server.statsCommand.get() + const data = await server.stats.get() expect(data.totalLocalDailyActiveVideoChannels).to.equal(1) expect(data.totalLocalWeeklyActiveVideoChannels).to.equal(1) @@ -151,9 +151,9 @@ describe('Test stats (excluding redundancy)', function () { } { - await server.videosCommand.upload({ attributes: { fixture: 'video_short.webm', channelId } }) + await server.videos.upload({ attributes: { fixture: 'video_short.webm', channelId } }) - const data = await server.statsCommand.get() + const data = await server.stats.get() expect(data.totalLocalDailyActiveVideoChannels).to.equal(2) expect(data.totalLocalWeeklyActiveVideoChannels).to.equal(2) @@ -165,12 +165,12 @@ describe('Test stats (excluding redundancy)', function () { const server = servers[0] { - const data = await server.statsCommand.get() + const data = await server.stats.get() expect(data.totalLocalPlaylists).to.equal(0) } { - await server.playlistsCommand.create({ + await server.playlists.create({ attributes: { displayName: 'playlist for count', privacy: VideoPlaylistPrivacy.PUBLIC, @@ -178,7 +178,7 @@ describe('Test stats (excluding redundancy)', function () { } }) - const data = await server.statsCommand.get() + const data = await server.stats.get() expect(data.totalLocalPlaylists).to.equal(1) } }) @@ -186,7 +186,7 @@ describe('Test stats (excluding redundancy)', function () { it('Should correctly count video file sizes if transcoding is enabled', async function () { this.timeout(60000) - await servers[0].configCommand.updateCustomSubConfig({ + await servers[0].config.updateCustomSubConfig({ newConfig: { transcoding: { enabled: true, @@ -210,17 +210,17 @@ describe('Test stats (excluding redundancy)', function () { } }) - await servers[0].videosCommand.upload({ attributes: { name: 'video', fixture: 'video_short.webm' } }) + await servers[0].videos.upload({ attributes: { name: 'video', fixture: 'video_short.webm' } }) await waitJobs(servers) { - const data = await servers[1].statsCommand.get() + const data = await servers[1].stats.get() expect(data.totalLocalVideoFilesSize).to.equal(0) } { - const data = await servers[0].statsCommand.get() + const data = await servers[0].stats.get() expect(data.totalLocalVideoFilesSize).to.be.greaterThan(500000) expect(data.totalLocalVideoFilesSize).to.be.lessThan(600000) } @@ -229,7 +229,7 @@ describe('Test stats (excluding redundancy)', function () { it('Should have the correct AP stats', async function () { this.timeout(60000) - await servers[0].configCommand.updateCustomSubConfig({ + await servers[0].config.updateCustomSubConfig({ newConfig: { transcoding: { enabled: false @@ -237,17 +237,17 @@ describe('Test stats (excluding redundancy)', function () { } }) - const first = await servers[1].statsCommand.get() + const first = await servers[1].stats.get() for (let i = 0; i < 10; i++) { - await servers[0].videosCommand.upload({ attributes: { name: 'video' } }) + await servers[0].videos.upload({ attributes: { name: 'video' } }) } await waitJobs(servers) await wait(6000) - const second = await servers[1].statsCommand.get() + const second = await servers[1].stats.get() expect(second.totalActivityPubMessagesProcessed).to.be.greaterThan(first.totalActivityPubMessagesProcessed) const apTypes: ActivityType[] = [ @@ -269,7 +269,7 @@ describe('Test stats (excluding redundancy)', function () { await wait(6000) - const third = await servers[1].statsCommand.get() + const third = await servers[1].stats.get() expect(third.totalActivityPubMessagesWaiting).to.equal(0) expect(third.activityPubMessagesProcessedPerSecond).to.be.lessThan(second.activityPubMessagesProcessedPerSecond) }) diff --git a/server/tests/api/server/tracker.ts b/server/tests/api/server/tracker.ts index 032012edf..d80362fee 100644 --- a/server/tests/api/server/tracker.ts +++ b/server/tests/api/server/tracker.ts @@ -16,8 +16,8 @@ describe('Test tracker', function () { await setAccessTokensToServers([ server ]) { - const { uuid } = await server.videosCommand.upload() - const video = await server.videosCommand.get({ id: uuid }) + const { uuid } = await server.videos.upload() + const video = await server.videos.get({ id: uuid }) goodMagnet = video.files[0].magnetUri const parsed = magnetUtil.decode(goodMagnet) diff --git a/server/tests/api/users/user-subscriptions.ts b/server/tests/api/users/user-subscriptions.ts index 622cddb7d..1b15a98dc 100644 --- a/server/tests/api/users/user-subscriptions.ts +++ b/server/tests/api/users/user-subscriptions.ts @@ -35,26 +35,26 @@ describe('Test users subscriptions', function () { { for (const server of servers) { const user = { username: 'user' + server.serverNumber, password: 'password' } - await server.usersCommand.create({ username: user.username, password: user.password }) + await server.users.create({ username: user.username, password: user.password }) - const accessToken = await server.loginCommand.getAccessToken(user) + const accessToken = await server.login.getAccessToken(user) users.push({ accessToken }) const videoName1 = 'video 1-' + server.serverNumber - await server.videosCommand.upload({ token: accessToken, attributes: { name: videoName1 } }) + await server.videos.upload({ token: accessToken, attributes: { name: videoName1 } }) const videoName2 = 'video 2-' + server.serverNumber - await server.videosCommand.upload({ token: accessToken, attributes: { name: videoName2 } }) + await server.videos.upload({ token: accessToken, attributes: { name: videoName2 } }) } } await waitJobs(servers) - command = servers[0].subscriptionsCommand + command = servers[0].subscriptions }) it('Should display videos of server 2 on server 1', async function () { - const { total } = await servers[0].videosCommand.list() + const { total } = await servers[0].videos.list() expect(total).to.equal(4) }) @@ -67,14 +67,14 @@ describe('Test users subscriptions', function () { await waitJobs(servers) - const { uuid } = await servers[2].videosCommand.upload({ attributes: { name: 'video server 3 added after follow' } }) + const { uuid } = await servers[2].videos.upload({ attributes: { name: 'video server 3 added after follow' } }) video3UUID = uuid await waitJobs(servers) }) it('Should not display videos of server 3 on server 1', async function () { - const { total, data } = await servers[0].videosCommand.list() + const { total, data } = await servers[0].videos.list() expect(total).to.equal(4) for (const video of data) { @@ -183,7 +183,7 @@ describe('Test users subscriptions', function () { this.timeout(60000) const videoName = 'video server 1 added after follow' - await servers[0].videosCommand.upload({ attributes: { name: videoName } }) + await servers[0].videos.upload({ attributes: { name: videoName } }) await waitJobs(servers) @@ -209,7 +209,7 @@ describe('Test users subscriptions', function () { } { - const { data, total } = await servers[0].videosCommand.list() + const { data, total } = await servers[0].videos.list() expect(total).to.equal(5) for (const video of data) { @@ -223,11 +223,11 @@ describe('Test users subscriptions', function () { it('Should have server 1 follow server 3 and display server 3 videos', async function () { this.timeout(60000) - await servers[0].followsCommand.follow({ targets: [ servers[2].url ] }) + await servers[0].follows.follow({ targets: [ servers[2].url ] }) await waitJobs(servers) - const { data, total } = await servers[0].videosCommand.list() + const { data, total } = await servers[0].videos.list() expect(total).to.equal(8) const names = [ '1-3', '2-3', 'video server 3 added after follow' ] @@ -240,11 +240,11 @@ describe('Test users subscriptions', function () { it('Should remove follow server 1 -> server 3 and hide server 3 videos', async function () { this.timeout(60000) - await servers[0].followsCommand.unfollow({ target: servers[2] }) + await servers[0].follows.unfollow({ target: servers[2] }) await waitJobs(servers) - const { total, data } = await servers[0].videosCommand.list() + const { total, data } = await servers[0].videos.list() expect(total).to.equal(5) for (const video of data) { @@ -280,7 +280,7 @@ describe('Test users subscriptions', function () { it('Should update a video of server 3 and see the updated video on server 1', async function () { this.timeout(30000) - await servers[2].videosCommand.update({ id: video3UUID, attributes: { name: 'video server 3 added after follow updated' } }) + await servers[2].videos.update({ id: video3UUID, attributes: { name: 'video server 3 added after follow updated' } }) await waitJobs(servers) @@ -325,7 +325,7 @@ describe('Test users subscriptions', function () { }) it('Should correctly display public videos on server 1', async function () { - const { total, data } = await servers[0].videosCommand.list() + const { total, data } = await servers[0].videos.list() expect(total).to.equal(5) for (const video of data) { @@ -356,7 +356,7 @@ describe('Test users subscriptions', function () { } { - const { total, data } = await servers[0].videosCommand.list() + const { total, data } = await servers[0].videos.list() expect(total).to.equal(5) for (const video of data) { diff --git a/server/tests/api/users/users-multiple-servers.ts b/server/tests/api/users/users-multiple-servers.ts index 3ae105008..f8d7ae88e 100644 --- a/server/tests/api/users/users-multiple-servers.ts +++ b/server/tests/api/users/users-multiple-servers.ts @@ -42,20 +42,20 @@ describe('Test users with multiple servers', function () { await doubleFollow(servers[1], servers[2]) // The root user of server 1 is propagated to servers 2 and 3 - await servers[0].videosCommand.upload() + await servers[0].videos.upload() { const user = { username: 'user1', password: 'password' } - const created = await servers[0].usersCommand.create(user) + const created = await servers[0].users.create(user) userId = created.id - userAccessToken = await servers[0].loginCommand.getAccessToken(user) + userAccessToken = await servers[0].login.getAccessToken(user) } { - const { uuid } = await servers[0].videosCommand.upload({ token: userAccessToken }) + const { uuid } = await servers[0].videos.upload({ token: userAccessToken }) videoUUID = uuid } @@ -65,9 +65,9 @@ describe('Test users with multiple servers', function () { it('Should be able to update my display name', async function () { this.timeout(10000) - await servers[0].usersCommand.updateMe({ displayName: 'my super display name' }) + await servers[0].users.updateMe({ displayName: 'my super display name' }) - user = await servers[0].usersCommand.getMyInfo() + user = await servers[0].users.getMyInfo() expect(user.account.displayName).to.equal('my super display name') await waitJobs(servers) @@ -76,9 +76,9 @@ describe('Test users with multiple servers', function () { it('Should be able to update my description', async function () { this.timeout(10_000) - await servers[0].usersCommand.updateMe({ description: 'my super description updated' }) + await servers[0].users.updateMe({ description: 'my super description updated' }) - user = await servers[0].usersCommand.getMyInfo() + user = await servers[0].users.getMyInfo() expect(user.account.displayName).to.equal('my super display name') expect(user.account.description).to.equal('my super description updated') @@ -90,9 +90,9 @@ describe('Test users with multiple servers', function () { const fixture = 'avatar2.png' - await servers[0].usersCommand.updateMyAvatar({ fixture }) + await servers[0].users.updateMyAvatar({ fixture }) - user = await servers[0].usersCommand.getMyInfo() + user = await servers[0].users.getMyInfo() userAvatarFilename = user.account.avatar.path await testImage(servers[0].url, 'avatar2-resized', userAvatarFilename, '.png') @@ -104,12 +104,12 @@ describe('Test users with multiple servers', function () { let createdAt: string | Date for (const server of servers) { - const body = await server.accountsCommand.list({ sort: '-createdAt' }) + const body = await server.accounts.list({ sort: '-createdAt' }) const resList = body.data.find(a => a.name === 'root' && a.host === 'localhost:' + servers[0].port) expect(resList).not.to.be.undefined - const account = await server.accountsCommand.get({ accountName: resList.name + '@' + resList.host }) + const account = await server.accounts.get({ accountName: resList.name + '@' + resList.host }) if (!createdAt) createdAt = account.createdAt @@ -131,7 +131,7 @@ describe('Test users with multiple servers', function () { it('Should list account videos', async function () { for (const server of servers) { - const { total, data } = await server.videosCommand.listByAccount({ accountName: 'user1@localhost:' + servers[0].port }) + const { total, data } = await server.videos.listByAccount({ accountName: 'user1@localhost:' + servers[0].port }) expect(total).to.equal(1) expect(data).to.be.an('array') @@ -143,12 +143,12 @@ describe('Test users with multiple servers', function () { it('Should search through account videos', async function () { this.timeout(10_000) - const created = await servers[0].videosCommand.upload({ token: userAccessToken, attributes: { name: 'Kami no chikara' } }) + const created = await servers[0].videos.upload({ token: userAccessToken, attributes: { name: 'Kami no chikara' } }) await waitJobs(servers) for (const server of servers) { - const { total, data } = await server.videosCommand.listByAccount({ accountName: 'user1@localhost:' + servers[0].port, search: 'Kami' }) + const { total, data } = await server.videos.listByAccount({ accountName: 'user1@localhost:' + servers[0].port, search: 'Kami' }) expect(total).to.equal(1) expect(data).to.be.an('array') @@ -161,27 +161,27 @@ describe('Test users with multiple servers', function () { this.timeout(10_000) for (const server of servers) { - const body = await server.accountsCommand.list({ sort: '-createdAt' }) + const body = await server.accounts.list({ sort: '-createdAt' }) const accountDeleted = body.data.find(a => a.name === 'user1' && a.host === 'localhost:' + servers[0].port) expect(accountDeleted).not.to.be.undefined - const { data } = await server.channelsCommand.list() + const { data } = await server.channels.list() const videoChannelDeleted = data.find(a => a.displayName === 'Main user1 channel' && a.host === 'localhost:' + servers[0].port) expect(videoChannelDeleted).not.to.be.undefined } - await servers[0].usersCommand.remove({ userId }) + await servers[0].users.remove({ userId }) await waitJobs(servers) for (const server of servers) { - const body = await server.accountsCommand.list({ sort: '-createdAt' }) + const body = await server.accounts.list({ sort: '-createdAt' }) const accountDeleted = body.data.find(a => a.name === 'user1' && a.host === 'localhost:' + servers[0].port) expect(accountDeleted).to.be.undefined - const { data } = await server.channelsCommand.list() + const { data } = await server.channels.list() const videoChannelDeleted = data.find(a => a.name === 'Main user1 channel' && a.host === 'localhost:' + servers[0].port) expect(videoChannelDeleted).to.be.undefined } diff --git a/server/tests/api/users/users-verification.ts b/server/tests/api/users/users-verification.ts index 271aa3c7a..c8c226fa8 100644 --- a/server/tests/api/users/users-verification.ts +++ b/server/tests/api/users/users-verification.ts @@ -42,7 +42,7 @@ describe('Test users account verification', function () { it('Should register user and send verification email if verification required', async function () { this.timeout(30000) - await server.configCommand.updateCustomSubConfig({ + await server.config.updateCustomSubConfig({ newConfig: { signup: { enabled: true, @@ -52,7 +52,7 @@ describe('Test users account verification', function () { } }) - await server.usersCommand.register(user1) + await server.users.register(user1) await waitJobs(server) expectedEmailsLength++ @@ -71,22 +71,22 @@ describe('Test users account verification', function () { userId = parseInt(userIdMatches[1], 10) - const body = await server.usersCommand.get({ userId }) + const body = await server.users.get({ userId }) expect(body.emailVerified).to.be.false }) it('Should not allow login for user with unverified email', async function () { - const { detail } = await server.loginCommand.login({ user: user1, expectedStatus: HttpStatusCode.BAD_REQUEST_400 }) + const { detail } = await server.login.login({ user: user1, expectedStatus: HttpStatusCode.BAD_REQUEST_400 }) expect(detail).to.contain('User email is not verified.') }) it('Should verify the user via email and allow login', async function () { - await server.usersCommand.verifyEmail({ userId, verificationString }) + await server.users.verifyEmail({ userId, verificationString }) - const body = await server.loginCommand.login({ user: user1 }) + const body = await server.login.login({ user: user1 }) userAccessToken = body.access_token - const user = await server.usersCommand.get({ userId }) + const user = await server.users.get({ userId }) expect(user.emailVerified).to.be.true }) @@ -96,7 +96,7 @@ describe('Test users account verification', function () { let updateVerificationString: string { - await server.usersCommand.updateMe({ + await server.users.updateMe({ token: userAccessToken, email: 'updated@example.com', currentPassword: user1.password @@ -113,15 +113,15 @@ describe('Test users account verification', function () { } { - const me = await server.usersCommand.getMyInfo({ token: userAccessToken }) + const me = await server.users.getMyInfo({ token: userAccessToken }) expect(me.email).to.equal('user_1@example.com') expect(me.pendingEmail).to.equal('updated@example.com') } { - await server.usersCommand.verifyEmail({ userId, verificationString: updateVerificationString, isPendingEmail: true }) + await server.users.verifyEmail({ userId, verificationString: updateVerificationString, isPendingEmail: true }) - const me = await server.usersCommand.getMyInfo({ token: userAccessToken }) + const me = await server.users.getMyInfo({ token: userAccessToken }) expect(me.email).to.equal('updated@example.com') expect(me.pendingEmail).to.be.null } @@ -129,7 +129,7 @@ describe('Test users account verification', function () { it('Should register user not requiring email verification if setting not enabled', async function () { this.timeout(5000) - await server.configCommand.updateCustomSubConfig({ + await server.config.updateCustomSubConfig({ newConfig: { signup: { enabled: true, @@ -139,19 +139,19 @@ describe('Test users account verification', function () { } }) - await server.usersCommand.register(user2) + await server.users.register(user2) await waitJobs(server) expect(emails).to.have.lengthOf(expectedEmailsLength) - const accessToken = await server.loginCommand.getAccessToken(user2) + const accessToken = await server.login.getAccessToken(user2) - const user = await server.usersCommand.getMyInfo({ token: accessToken }) + const user = await server.users.getMyInfo({ token: accessToken }) expect(user.emailVerified).to.be.null }) it('Should allow login for user with unverified email when setting later enabled', async function () { - await server.configCommand.updateCustomSubConfig({ + await server.config.updateCustomSubConfig({ newConfig: { signup: { enabled: true, @@ -161,7 +161,7 @@ describe('Test users account verification', function () { } }) - await server.loginCommand.getAccessToken(user2) + await server.login.getAccessToken(user2) }) after(async function () { diff --git a/server/tests/api/users/users.ts b/server/tests/api/users/users.ts index 6f3873939..310136a37 100644 --- a/server/tests/api/users/users.ts +++ b/server/tests/api/users/users.ts @@ -42,7 +42,7 @@ describe('Test users', function () { await setAccessTokensToServers([ server ]) - await server.pluginsCommand.install({ npmName: 'peertube-theme-background-red' }) + await server.plugins.install({ npmName: 'peertube-theme-background-red' }) }) describe('OAuth client', function () { @@ -53,8 +53,8 @@ describe('Test users', function () { it('Should remove the last client') it('Should not login with an invalid client id', async function () { - const client = { id: 'client', secret: server.client.secret } - const body = await server.loginCommand.login({ client, expectedStatus: HttpStatusCode.BAD_REQUEST_400 }) + const client = { id: 'client', secret: server.store.client.secret } + const body = await server.login.login({ client, expectedStatus: HttpStatusCode.BAD_REQUEST_400 }) expect(body.code).to.equal(OAuth2ErrorCode.INVALID_CLIENT) expect(body.error).to.contain('client is invalid') @@ -63,8 +63,8 @@ describe('Test users', function () { }) it('Should not login with an invalid client secret', async function () { - const client = { id: server.client.id, secret: 'coucou' } - const body = await server.loginCommand.login({ client, expectedStatus: HttpStatusCode.BAD_REQUEST_400 }) + const client = { id: server.store.client.id, secret: 'coucou' } + const body = await server.login.login({ client, expectedStatus: HttpStatusCode.BAD_REQUEST_400 }) expect(body.code).to.equal(OAuth2ErrorCode.INVALID_CLIENT) expect(body.error).to.contain('client is invalid') @@ -76,8 +76,8 @@ describe('Test users', function () { describe('Login', function () { it('Should not login with an invalid username', async function () { - const user = { username: 'captain crochet', password: server.user.password } - const body = await server.loginCommand.login({ user, expectedStatus: HttpStatusCode.BAD_REQUEST_400 }) + const user = { username: 'captain crochet', password: server.store.user.password } + const body = await server.login.login({ user, expectedStatus: HttpStatusCode.BAD_REQUEST_400 }) expect(body.code).to.equal(OAuth2ErrorCode.INVALID_GRANT) expect(body.error).to.contain('credentials are invalid') @@ -86,8 +86,8 @@ describe('Test users', function () { }) it('Should not login with an invalid password', async function () { - const user = { username: server.user.username, password: 'mew_three' } - const body = await server.loginCommand.login({ user, expectedStatus: HttpStatusCode.BAD_REQUEST_400 }) + const user = { username: server.store.user.username, password: 'mew_three' } + const body = await server.login.login({ user, expectedStatus: HttpStatusCode.BAD_REQUEST_400 }) expect(body.code).to.equal(OAuth2ErrorCode.INVALID_GRANT) expect(body.error).to.contain('credentials are invalid') @@ -98,13 +98,13 @@ describe('Test users', function () { it('Should not be able to upload a video', async function () { token = 'my_super_token' - await server.videosCommand.upload({ token, expectedStatus: HttpStatusCode.UNAUTHORIZED_401 }) + await server.videos.upload({ token, expectedStatus: HttpStatusCode.UNAUTHORIZED_401 }) }) it('Should not be able to follow', async function () { token = 'my_super_token' - await server.followsCommand.follow({ + await server.follows.follow({ targets: [ 'http://example.com' ], token, expectedStatus: HttpStatusCode.UNAUTHORIZED_401 @@ -114,28 +114,28 @@ describe('Test users', function () { it('Should not be able to unfollow') it('Should be able to login', async function () { - const body = await server.loginCommand.login({ expectedStatus: HttpStatusCode.OK_200 }) + const body = await server.login.login({ expectedStatus: HttpStatusCode.OK_200 }) token = body.access_token }) it('Should be able to login with an insensitive username', async function () { - const user = { username: 'RoOt', password: server.user.password } - await server.loginCommand.login({ user, expectedStatus: HttpStatusCode.OK_200 }) + const user = { username: 'RoOt', password: server.store.user.password } + await server.login.login({ user, expectedStatus: HttpStatusCode.OK_200 }) - const user2 = { username: 'rOoT', password: server.user.password } - await server.loginCommand.login({ user: user2, expectedStatus: HttpStatusCode.OK_200 }) + const user2 = { username: 'rOoT', password: server.store.user.password } + await server.login.login({ user: user2, expectedStatus: HttpStatusCode.OK_200 }) - const user3 = { username: 'ROOt', password: server.user.password } - await server.loginCommand.login({ user: user3, expectedStatus: HttpStatusCode.OK_200 }) + const user3 = { username: 'ROOt', password: server.store.user.password } + await server.login.login({ user: user3, expectedStatus: HttpStatusCode.OK_200 }) }) }) describe('Upload', function () { it('Should upload the video with the correct token', async function () { - await server.videosCommand.upload({ token }) - const { data } = await server.videosCommand.list() + await server.videos.upload({ token }) + const { data } = await server.videos.list() const video = data[0] expect(video.account.name).to.equal('root') @@ -143,24 +143,24 @@ describe('Test users', function () { }) it('Should upload the video again with the correct token', async function () { - await server.videosCommand.upload({ token }) + await server.videos.upload({ token }) }) }) describe('Ratings', function () { it('Should retrieve a video rating', async function () { - await server.videosCommand.rate({ id: videoId, rating: 'like' }) - const rating = await server.usersCommand.getMyRating({ token, videoId }) + await server.videos.rate({ id: videoId, rating: 'like' }) + const rating = await server.users.getMyRating({ token, videoId }) expect(rating.videoId).to.equal(videoId) expect(rating.rating).to.equal('like') }) it('Should retrieve ratings list', async function () { - await server.videosCommand.rate({ id: videoId, rating: 'like' }) + await server.videos.rate({ id: videoId, rating: 'like' }) - const body = await server.accountsCommand.listRatings({ accountName: server.user.username }) + const body = await server.accounts.listRatings({ accountName: server.store.user.username }) expect(body.total).to.equal(1) expect(body.data[0].video.id).to.equal(videoId) @@ -169,12 +169,12 @@ describe('Test users', function () { it('Should retrieve ratings list by rating type', async function () { { - const body = await server.accountsCommand.listRatings({ accountName: server.user.username, rating: 'like' }) + const body = await server.accounts.listRatings({ accountName: server.store.user.username, rating: 'like' }) expect(body.data.length).to.equal(1) } { - const body = await server.accountsCommand.listRatings({ accountName: server.user.username, rating: 'dislike' }) + const body = await server.accounts.listRatings({ accountName: server.store.user.username, rating: 'dislike' }) expect(body.data.length).to.equal(0) } }) @@ -182,27 +182,27 @@ describe('Test users', function () { describe('Remove video', function () { it('Should not be able to remove the video with an incorrect token', async function () { - await server.videosCommand.remove({ token: 'bad_token', id: videoId, expectedStatus: HttpStatusCode.UNAUTHORIZED_401 }) + await server.videos.remove({ token: 'bad_token', id: videoId, expectedStatus: HttpStatusCode.UNAUTHORIZED_401 }) }) it('Should not be able to remove the video with the token of another account') it('Should be able to remove the video with the correct token', async function () { - await server.videosCommand.remove({ token, id: videoId }) + await server.videos.remove({ token, id: videoId }) }) }) describe('Logout', function () { it('Should logout (revoke token)', async function () { - await server.loginCommand.logout({ token: server.accessToken }) + await server.login.logout({ token: server.accessToken }) }) it('Should not be able to get the user information', async function () { - await server.usersCommand.getMyInfo({ expectedStatus: HttpStatusCode.UNAUTHORIZED_401 }) + await server.users.getMyInfo({ expectedStatus: HttpStatusCode.UNAUTHORIZED_401 }) }) it('Should not be able to upload a video', async function () { - await server.videosCommand.upload({ attributes: { name: 'video' }, expectedStatus: HttpStatusCode.UNAUTHORIZED_401 }) + await server.videos.upload({ attributes: { name: 'video' }, expectedStatus: HttpStatusCode.UNAUTHORIZED_401 }) }) it('Should not be able to rate a video', async function () { @@ -222,64 +222,64 @@ describe('Test users', function () { }) it('Should be able to login again', async function () { - const body = await server.loginCommand.login() + const body = await server.login.login() server.accessToken = body.access_token server.refreshToken = body.refresh_token }) it('Should be able to get my user information again', async function () { - await server.usersCommand.getMyInfo() + await server.users.getMyInfo() }) it('Should have an expired access token', async function () { this.timeout(15000) - await server.sqlCommand.setTokenField(server.accessToken, 'accessTokenExpiresAt', new Date().toISOString()) - await server.sqlCommand.setTokenField(server.accessToken, 'refreshTokenExpiresAt', new Date().toISOString()) + await server.sql.setTokenField(server.accessToken, 'accessTokenExpiresAt', new Date().toISOString()) + await server.sql.setTokenField(server.accessToken, 'refreshTokenExpiresAt', new Date().toISOString()) await killallServers([ server ]) await reRunServer(server) - await server.usersCommand.getMyInfo({ expectedStatus: HttpStatusCode.UNAUTHORIZED_401 }) + await server.users.getMyInfo({ expectedStatus: HttpStatusCode.UNAUTHORIZED_401 }) }) it('Should not be able to refresh an access token with an expired refresh token', async function () { - await server.loginCommand.refreshToken({ refreshToken: server.refreshToken, expectedStatus: HttpStatusCode.BAD_REQUEST_400 }) + await server.login.refreshToken({ refreshToken: server.refreshToken, expectedStatus: HttpStatusCode.BAD_REQUEST_400 }) }) it('Should refresh the token', async function () { this.timeout(15000) const futureDate = new Date(new Date().getTime() + 1000 * 60).toISOString() - await server.sqlCommand.setTokenField(server.accessToken, 'refreshTokenExpiresAt', futureDate) + await server.sql.setTokenField(server.accessToken, 'refreshTokenExpiresAt', futureDate) await killallServers([ server ]) await reRunServer(server) - const res = await server.loginCommand.refreshToken({ refreshToken: server.refreshToken }) + const res = await server.login.refreshToken({ refreshToken: server.refreshToken }) server.accessToken = res.body.access_token server.refreshToken = res.body.refresh_token }) it('Should be able to get my user information again', async function () { - await server.usersCommand.getMyInfo() + await server.users.getMyInfo() }) }) describe('Creating a user', function () { it('Should be able to create a new user', async function () { - await server.usersCommand.create({ ...user, videoQuota: 2 * 1024 * 1024, adminFlags: UserAdminFlag.BYPASS_VIDEO_AUTO_BLACKLIST }) + await server.users.create({ ...user, videoQuota: 2 * 1024 * 1024, adminFlags: UserAdminFlag.BYPASS_VIDEO_AUTO_BLACKLIST }) }) it('Should be able to login with this user', async function () { - userToken = await server.loginCommand.getAccessToken(user) + userToken = await server.login.getAccessToken(user) }) it('Should be able to get user information', async function () { - const userMe = await server.usersCommand.getMyInfo({ token: userToken }) + const userMe = await server.users.getMyInfo({ token: userToken }) - const userGet = await server.usersCommand.get({ userId: userMe.id, withStats: true }) + const userGet = await server.users.get({ userId: userMe.id, withStats: true }) for (const user of [ userMe, userGet ]) { expect(user.username).to.equal('user_1') @@ -319,20 +319,20 @@ describe('Test users', function () { name: 'super user video', fixture: 'video_short.webm' } - await server.videosCommand.upload({ token: userToken, attributes }) + await server.videos.upload({ token: userToken, attributes }) }) it('Should have video quota updated', async function () { - const quota = await server.usersCommand.getMyQuotaUsed({ token: userToken }) + const quota = await server.users.getMyQuotaUsed({ token: userToken }) expect(quota.videoQuotaUsed).to.equal(218910) - const { data } = await server.usersCommand.list() + const { data } = await server.users.list() const tmpUser = data.find(u => u.username === user.username) expect(tmpUser.videoQuotaUsed).to.equal(218910) }) it('Should be able to list my videos', async function () { - const { total, data } = await server.videosCommand.listMyVideos({ token: userToken }) + const { total, data } = await server.videos.listMyVideos({ token: userToken }) expect(total).to.equal(1) expect(data).to.have.lengthOf(1) @@ -344,13 +344,13 @@ describe('Test users', function () { it('Should be able to search in my videos', async function () { { - const { total, data } = await server.videosCommand.listMyVideos({ token: userToken, sort: '-createdAt', search: 'user video' }) + const { total, data } = await server.videos.listMyVideos({ token: userToken, sort: '-createdAt', search: 'user video' }) expect(total).to.equal(1) expect(data).to.have.lengthOf(1) } { - const { total, data } = await server.videosCommand.listMyVideos({ token: userToken, sort: '-createdAt', search: 'toto' }) + const { total, data } = await server.videos.listMyVideos({ token: userToken, sort: '-createdAt', search: 'toto' }) expect(total).to.equal(0) expect(data).to.have.lengthOf(0) } @@ -360,11 +360,11 @@ describe('Test users', function () { this.timeout(60000) { - const config = await server.configCommand.getCustomConfig() + const config = await server.config.getCustomConfig() config.transcoding.webtorrent.enabled = false config.transcoding.hls.enabled = true config.transcoding.enabled = true - await server.configCommand.updateCustomSubConfig({ newConfig: config }) + await server.config.updateCustomSubConfig({ newConfig: config }) } { @@ -372,13 +372,13 @@ describe('Test users', function () { name: 'super user video 2', fixture: 'video_short.webm' } - await server.videosCommand.upload({ token: userToken, attributes }) + await server.videos.upload({ token: userToken, attributes }) await waitJobs([ server ]) } { - const data = await server.usersCommand.getMyQuotaUsed({ token: userToken }) + const data = await server.users.getMyQuotaUsed({ token: userToken }) expect(data.videoQuotaUsed).to.be.greaterThan(220000) } }) @@ -387,7 +387,7 @@ describe('Test users', function () { describe('Users listing', function () { it('Should list all the users', async function () { - const { data, total } = await server.usersCommand.list() + const { data, total } = await server.users.list() expect(total).to.equal(2) expect(data).to.be.an('array') @@ -410,7 +410,7 @@ describe('Test users', function () { }) it('Should list only the first user by username asc', async function () { - const { total, data } = await server.usersCommand.list({ start: 0, count: 1, sort: 'username' }) + const { total, data } = await server.users.list({ start: 0, count: 1, sort: 'username' }) expect(total).to.equal(2) expect(data.length).to.equal(1) @@ -423,7 +423,7 @@ describe('Test users', function () { }) it('Should list only the first user by username desc', async function () { - const { total, data } = await server.usersCommand.list({ start: 0, count: 1, sort: '-username' }) + const { total, data } = await server.users.list({ start: 0, count: 1, sort: '-username' }) expect(total).to.equal(2) expect(data.length).to.equal(1) @@ -435,7 +435,7 @@ describe('Test users', function () { }) it('Should list only the second user by createdAt desc', async function () { - const { data, total } = await server.usersCommand.list({ start: 0, count: 1, sort: '-createdAt' }) + const { data, total } = await server.users.list({ start: 0, count: 1, sort: '-createdAt' }) expect(total).to.equal(2) expect(data.length).to.equal(1) @@ -447,7 +447,7 @@ describe('Test users', function () { }) it('Should list all the users by createdAt asc', async function () { - const { data, total } = await server.usersCommand.list({ start: 0, count: 2, sort: 'createdAt' }) + const { data, total } = await server.users.list({ start: 0, count: 2, sort: 'createdAt' }) expect(total).to.equal(2) expect(data.length).to.equal(2) @@ -462,7 +462,7 @@ describe('Test users', function () { }) it('Should search user by username', async function () { - const { data, total } = await server.usersCommand.list({ start: 0, count: 2, sort: 'createdAt', search: 'oot' }) + const { data, total } = await server.users.list({ start: 0, count: 2, sort: 'createdAt', search: 'oot' }) expect(total).to.equal(1) expect(data.length).to.equal(1) expect(data[0].username).to.equal('root') @@ -470,7 +470,7 @@ describe('Test users', function () { it('Should search user by email', async function () { { - const { total, data } = await server.usersCommand.list({ start: 0, count: 2, sort: 'createdAt', search: 'r_1@exam' }) + const { total, data } = await server.users.list({ start: 0, count: 2, sort: 'createdAt', search: 'r_1@exam' }) expect(total).to.equal(1) expect(data.length).to.equal(1) expect(data[0].username).to.equal('user_1') @@ -478,7 +478,7 @@ describe('Test users', function () { } { - const { total, data } = await server.usersCommand.list({ start: 0, count: 2, sort: 'createdAt', search: 'example' }) + const { total, data } = await server.users.list({ start: 0, count: 2, sort: 'createdAt', search: 'example' }) expect(total).to.equal(2) expect(data.length).to.equal(2) expect(data[0].username).to.equal('root') @@ -490,23 +490,23 @@ describe('Test users', function () { describe('Update my account', function () { it('Should update my password', async function () { - await server.usersCommand.updateMe({ + await server.users.updateMe({ token: userToken, currentPassword: 'super password', password: 'new password' }) user.password = 'new password' - await server.loginCommand.login({ user }) + await server.login.login({ user }) }) it('Should be able to change the NSFW display attribute', async function () { - await server.usersCommand.updateMe({ + await server.users.updateMe({ token: userToken, nsfwPolicy: 'do_not_list' }) - const user = await server.usersCommand.getMyInfo({ token: userToken }) + const user = await server.users.getMyInfo({ token: userToken }) expect(user.username).to.equal('user_1') expect(user.email).to.equal('user_1@example.com') expect(user.nsfwPolicy).to.equal('do_not_list') @@ -517,33 +517,33 @@ describe('Test users', function () { }) it('Should be able to change the autoPlayVideo attribute', async function () { - await server.usersCommand.updateMe({ + await server.users.updateMe({ token: userToken, autoPlayVideo: false }) - const user = await server.usersCommand.getMyInfo({ token: userToken }) + const user = await server.users.getMyInfo({ token: userToken }) expect(user.autoPlayVideo).to.be.false }) it('Should be able to change the autoPlayNextVideo attribute', async function () { - await server.usersCommand.updateMe({ + await server.users.updateMe({ token: userToken, autoPlayNextVideo: true }) - const user = await server.usersCommand.getMyInfo({ token: userToken }) + const user = await server.users.getMyInfo({ token: userToken }) expect(user.autoPlayNextVideo).to.be.true }) it('Should be able to change the email attribute', async function () { - await server.usersCommand.updateMe({ + await server.users.updateMe({ token: userToken, currentPassword: 'new password', email: 'updated@example.com' }) - const user = await server.usersCommand.getMyInfo({ token: userToken }) + const user = await server.users.getMyInfo({ token: userToken }) expect(user.username).to.equal('user_1') expect(user.email).to.equal('updated@example.com') expect(user.nsfwPolicy).to.equal('do_not_list') @@ -556,9 +556,9 @@ describe('Test users', function () { it('Should be able to update my avatar with a gif', async function () { const fixture = 'avatar.gif' - await server.usersCommand.updateMyAvatar({ token: userToken, fixture }) + await server.users.updateMyAvatar({ token: userToken, fixture }) - const user = await server.usersCommand.getMyInfo({ token: userToken }) + const user = await server.users.getMyInfo({ token: userToken }) await testImage(server.url, 'avatar-resized', user.account.avatar.path, '.gif') }) @@ -566,17 +566,17 @@ describe('Test users', function () { for (const extension of [ '.png', '.gif' ]) { const fixture = 'avatar' + extension - await server.usersCommand.updateMyAvatar({ token: userToken, fixture }) + await server.users.updateMyAvatar({ token: userToken, fixture }) - const user = await server.usersCommand.getMyInfo({ token: userToken }) + const user = await server.users.getMyInfo({ token: userToken }) await testImage(server.url, 'avatar-resized', user.account.avatar.path, extension) } }) it('Should be able to update my display name', async function () { - await server.usersCommand.updateMe({ token: userToken, displayName: 'new display name' }) + await server.users.updateMe({ token: userToken, displayName: 'new display name' }) - const user = await server.usersCommand.getMyInfo({ token: userToken }) + const user = await server.users.getMyInfo({ token: userToken }) expect(user.username).to.equal('user_1') expect(user.email).to.equal('updated@example.com') expect(user.nsfwPolicy).to.equal('do_not_list') @@ -587,9 +587,9 @@ describe('Test users', function () { }) it('Should be able to update my description', async function () { - await server.usersCommand.updateMe({ token: userToken, description: 'my super description updated' }) + await server.users.updateMe({ token: userToken, description: 'my super description updated' }) - const user = await server.usersCommand.getMyInfo({ token: userToken }) + const user = await server.users.getMyInfo({ token: userToken }) expect(user.username).to.equal('user_1') expect(user.email).to.equal('updated@example.com') expect(user.nsfwPolicy).to.equal('do_not_list') @@ -603,21 +603,21 @@ describe('Test users', function () { it('Should be able to update my theme', async function () { for (const theme of [ 'background-red', 'default', 'instance-default' ]) { - await server.usersCommand.updateMe({ token: userToken, theme }) + await server.users.updateMe({ token: userToken, theme }) - const user = await server.usersCommand.getMyInfo({ token: userToken }) + const user = await server.users.getMyInfo({ token: userToken }) expect(user.theme).to.equal(theme) } }) it('Should be able to update my modal preferences', async function () { - await server.usersCommand.updateMe({ + await server.users.updateMe({ token: userToken, noInstanceConfigWarningModal: true, noWelcomeModal: true }) - const user = await server.usersCommand.getMyInfo({ token: userToken }) + const user = await server.users.getMyInfo({ token: userToken }) expect(user.noWelcomeModal).to.be.true expect(user.noInstanceConfigWarningModal).to.be.true }) @@ -625,7 +625,7 @@ describe('Test users', function () { describe('Updating another user', function () { it('Should be able to update another user', async function () { - await server.usersCommand.update({ + await server.users.update({ userId, token, email: 'updated2@example.com', @@ -636,7 +636,7 @@ describe('Test users', function () { pluginAuth: 'toto' }) - const user = await server.usersCommand.get({ token, userId }) + const user = await server.users.get({ token, userId }) expect(user.username).to.equal('user_1') expect(user.email).to.equal('updated2@example.com') @@ -650,47 +650,47 @@ describe('Test users', function () { }) it('Should reset the auth plugin', async function () { - await server.usersCommand.update({ userId, token, pluginAuth: null }) + await server.users.update({ userId, token, pluginAuth: null }) - const user = await server.usersCommand.get({ token, userId }) + const user = await server.users.get({ token, userId }) expect(user.pluginAuth).to.be.null }) it('Should have removed the user token', async function () { - await server.usersCommand.getMyQuotaUsed({ token: userToken, expectedStatus: HttpStatusCode.UNAUTHORIZED_401 }) + await server.users.getMyQuotaUsed({ token: userToken, expectedStatus: HttpStatusCode.UNAUTHORIZED_401 }) - userToken = await server.loginCommand.getAccessToken(user) + userToken = await server.login.getAccessToken(user) }) it('Should be able to update another user password', async function () { - await server.usersCommand.update({ userId, token, password: 'password updated' }) + await server.users.update({ userId, token, password: 'password updated' }) - await server.usersCommand.getMyQuotaUsed({ token: userToken, expectedStatus: HttpStatusCode.UNAUTHORIZED_401 }) + await server.users.getMyQuotaUsed({ token: userToken, expectedStatus: HttpStatusCode.UNAUTHORIZED_401 }) - await server.loginCommand.login({ user, expectedStatus: HttpStatusCode.BAD_REQUEST_400 }) + await server.login.login({ user, expectedStatus: HttpStatusCode.BAD_REQUEST_400 }) user.password = 'password updated' - userToken = await server.loginCommand.getAccessToken(user) + userToken = await server.login.getAccessToken(user) }) }) describe('Video blacklists', function () { it('Should be able to list video blacklist by a moderator', async function () { - await server.blacklistCommand.list({ token: userToken }) + await server.blacklist.list({ token: userToken }) }) }) describe('Remove a user', function () { it('Should be able to remove this user', async function () { - await server.usersCommand.remove({ userId, token }) + await server.users.remove({ userId, token }) }) it('Should not be able to login with this user', async function () { - await server.loginCommand.login({ user, expectedStatus: HttpStatusCode.BAD_REQUEST_400 }) + await server.login.login({ user, expectedStatus: HttpStatusCode.BAD_REQUEST_400 }) }) it('Should not have videos of this user', async function () { - const { data, total } = await server.videosCommand.list() + const { data, total } = await server.videos.list() expect(total).to.equal(1) const video = data[0] @@ -705,7 +705,7 @@ describe('Test users', function () { const user = { displayName: 'super user 15', username: 'user_15', password: 'my super password' } const channel = { name: 'my_user_15_channel', displayName: 'my channel rocks' } - await server.usersCommand.register({ ...user, channel }) + await server.users.register({ ...user, channel }) }) it('Should be able to login with this registered user', async function () { @@ -714,35 +714,35 @@ describe('Test users', function () { password: 'my super password' } - user15AccessToken = await server.loginCommand.getAccessToken(user15) + user15AccessToken = await server.login.getAccessToken(user15) }) it('Should have the correct display name', async function () { - const user = await server.usersCommand.getMyInfo({ token: user15AccessToken }) + const user = await server.users.getMyInfo({ token: user15AccessToken }) expect(user.account.displayName).to.equal('super user 15') }) it('Should have the correct video quota', async function () { - const user = await server.usersCommand.getMyInfo({ token: user15AccessToken }) + const user = await server.users.getMyInfo({ token: user15AccessToken }) expect(user.videoQuota).to.equal(5 * 1024 * 1024) }) it('Should have created the channel', async function () { - const { displayName } = await server.channelsCommand.get({ channelName: 'my_user_15_channel' }) + const { displayName } = await server.channels.get({ channelName: 'my_user_15_channel' }) expect(displayName).to.equal('my channel rocks') }) it('Should remove me', async function () { { - const { data } = await server.usersCommand.list() + const { data } = await server.users.list() expect(data.find(u => u.username === 'user_15')).to.not.be.undefined } - await server.usersCommand.deleteMe({ token: user15AccessToken }) + await server.users.deleteMe({ token: user15AccessToken }) { - const { data } = await server.usersCommand.list() + const { data } = await server.users.list() expect(data.find(u => u.username === 'user_15')).to.be.undefined } }) @@ -757,21 +757,21 @@ describe('Test users', function () { } it('Should block a user', async function () { - const user = await server.usersCommand.create({ ...user16 }) + const user = await server.users.create({ ...user16 }) user16Id = user.id - user16AccessToken = await server.loginCommand.getAccessToken(user16) + user16AccessToken = await server.login.getAccessToken(user16) - await server.usersCommand.getMyInfo({ token: user16AccessToken, expectedStatus: HttpStatusCode.OK_200 }) - await server.usersCommand.banUser({ userId: user16Id }) + await server.users.getMyInfo({ token: user16AccessToken, expectedStatus: HttpStatusCode.OK_200 }) + await server.users.banUser({ userId: user16Id }) - await server.usersCommand.getMyInfo({ token: user16AccessToken, expectedStatus: HttpStatusCode.UNAUTHORIZED_401 }) - await server.loginCommand.login({ user: user16, expectedStatus: HttpStatusCode.BAD_REQUEST_400 }) + await server.users.getMyInfo({ token: user16AccessToken, expectedStatus: HttpStatusCode.UNAUTHORIZED_401 }) + await server.login.login({ user: user16, expectedStatus: HttpStatusCode.BAD_REQUEST_400 }) }) it('Should search user by banned status', async function () { { - const { data, total } = await server.usersCommand.list({ start: 0, count: 2, sort: 'createdAt', blocked: true }) + const { data, total } = await server.users.list({ start: 0, count: 2, sort: 'createdAt', blocked: true }) expect(total).to.equal(1) expect(data.length).to.equal(1) @@ -779,7 +779,7 @@ describe('Test users', function () { } { - const { data, total } = await server.usersCommand.list({ start: 0, count: 2, sort: 'createdAt', blocked: false }) + const { data, total } = await server.users.list({ start: 0, count: 2, sort: 'createdAt', blocked: false }) expect(total).to.equal(1) expect(data.length).to.equal(1) @@ -788,9 +788,9 @@ describe('Test users', function () { }) it('Should unblock a user', async function () { - await server.usersCommand.unbanUser({ userId: user16Id }) - user16AccessToken = await server.loginCommand.getAccessToken(user16) - await server.usersCommand.getMyInfo({ token: user16AccessToken, expectedStatus: HttpStatusCode.OK_200 }) + await server.users.unbanUser({ userId: user16Id }) + user16AccessToken = await server.login.getAccessToken(user16) + await server.users.getMyInfo({ token: user16AccessToken, expectedStatus: HttpStatusCode.OK_200 }) }) }) @@ -803,12 +803,12 @@ describe('Test users', function () { username: 'user_17', password: 'my super password' } - const created = await server.usersCommand.create({ ...user17 }) + const created = await server.users.create({ ...user17 }) user17Id = created.id - user17AccessToken = await server.loginCommand.getAccessToken(user17) + user17AccessToken = await server.login.getAccessToken(user17) - const user = await server.usersCommand.get({ userId: user17Id, withStats: true }) + const user = await server.users.get({ userId: user17Id, withStats: true }) expect(user.videosCount).to.equal(0) expect(user.videoCommentsCount).to.equal(0) expect(user.abusesCount).to.equal(0) @@ -818,37 +818,37 @@ describe('Test users', function () { it('Should report correct videos count', async function () { const attributes = { name: 'video to test user stats' } - await server.videosCommand.upload({ token: user17AccessToken, attributes }) + await server.videos.upload({ token: user17AccessToken, attributes }) - const { data } = await server.videosCommand.list() + const { data } = await server.videos.list() videoId = data.find(video => video.name === attributes.name).id - const user = await server.usersCommand.get({ userId: user17Id, withStats: true }) + const user = await server.users.get({ userId: user17Id, withStats: true }) expect(user.videosCount).to.equal(1) }) it('Should report correct video comments for user', async function () { const text = 'super comment' - await server.commentsCommand.createThread({ token: user17AccessToken, videoId, text }) + await server.comments.createThread({ token: user17AccessToken, videoId, text }) - const user = await server.usersCommand.get({ userId: user17Id, withStats: true }) + const user = await server.users.get({ userId: user17Id, withStats: true }) expect(user.videoCommentsCount).to.equal(1) }) it('Should report correct abuses counts', async function () { const reason = 'my super bad reason' - await server.abusesCommand.report({ token: user17AccessToken, videoId, reason }) + await server.abuses.report({ token: user17AccessToken, videoId, reason }) - const body1 = await server.abusesCommand.getAdminList() + const body1 = await server.abuses.getAdminList() const abuseId = body1.data[0].id - const user2 = await server.usersCommand.get({ userId: user17Id, withStats: true }) + const user2 = await server.users.get({ userId: user17Id, withStats: true }) expect(user2.abusesCount).to.equal(1) // number of incriminations expect(user2.abusesCreatedCount).to.equal(1) // number of reports created - await server.abusesCommand.update({ abuseId, body: { state: AbuseState.ACCEPTED } }) + await server.abuses.update({ abuseId, body: { state: AbuseState.ACCEPTED } }) - const user3 = await server.usersCommand.get({ userId: user17Id, withStats: true }) + const user3 = await server.users.get({ userId: user17Id, withStats: true }) expect(user3.abusesAcceptedCount).to.equal(1) // number of reports created accepted }) }) diff --git a/server/tests/api/videos/audio-only.ts b/server/tests/api/videos/audio-only.ts index e31905b36..b2952e38b 100644 --- a/server/tests/api/videos/audio-only.ts +++ b/server/tests/api/videos/audio-only.ts @@ -48,13 +48,13 @@ describe('Test audio only video transcoding', function () { it('Should upload a video and transcode it', async function () { this.timeout(120000) - const { uuid } = await servers[0].videosCommand.upload({ attributes: { name: 'audio only' } }) + const { uuid } = await servers[0].videos.upload({ attributes: { name: 'audio only' } }) videoUUID = uuid await waitJobs(servers) for (const server of servers) { - const video = await server.videosCommand.get({ id: videoUUID }) + const video = await server.videos.get({ id: videoUUID }) expect(video.streamingPlaylists).to.have.lengthOf(1) for (const files of [ video.files, video.streamingPlaylists[0].files ]) { @@ -68,8 +68,8 @@ describe('Test audio only video transcoding', function () { it('0p transcoded video should not have video', async function () { const paths = [ - servers[0].serversCommand.buildDirectory(join('videos', videoUUID + '-0.mp4')), - servers[0].serversCommand.buildDirectory(join('streaming-playlists', 'hls', videoUUID, videoUUID + '-0-fragmented.mp4')) + servers[0].servers.buildDirectory(join('videos', videoUUID + '-0.mp4')), + servers[0].servers.buildDirectory(join('streaming-playlists', 'hls', videoUUID, videoUUID + '-0-fragmented.mp4')) ] for (const path of paths) { diff --git a/server/tests/api/videos/multiple-servers.ts b/server/tests/api/videos/multiple-servers.ts index 5c13ac629..89d842307 100644 --- a/server/tests/api/videos/multiple-servers.ts +++ b/server/tests/api/videos/multiple-servers.ts @@ -44,8 +44,8 @@ describe('Test multiple servers', function () { displayName: 'my channel', description: 'super channel' } - await servers[0].channelsCommand.create({ attributes: videoChannel }) - const { data } = await servers[0].channelsCommand.list({ start: 0, count: 1 }) + await servers[0].channels.create({ attributes: videoChannel }) + const { data } = await servers[0].channels.list({ start: 0, count: 1 }) videoChannelId = data[0].id } @@ -59,7 +59,7 @@ describe('Test multiple servers', function () { it('Should not have videos for all servers', async function () { for (const server of servers) { - const { data } = await server.videosCommand.list() + const { data } = await server.videos.list() expect(data).to.be.an('array') expect(data.length).to.equal(0) } @@ -82,7 +82,7 @@ describe('Test multiple servers', function () { channelId: videoChannelId, fixture: 'video_short1.webm' } - await servers[0].videosCommand.upload({ attributes }) + await servers[0].videos.upload({ attributes }) await waitJobs(servers) @@ -125,7 +125,7 @@ describe('Test multiple servers', function () { ] } - const { data } = await server.videosCommand.list() + const { data } = await server.videos.list() expect(data).to.be.an('array') expect(data.length).to.equal(1) const video = data[0] @@ -142,8 +142,8 @@ describe('Test multiple servers', function () { username: 'user1', password: 'super_password' } - await servers[1].usersCommand.create({ username: user.username, password: user.password }) - const userAccessToken = await servers[1].loginCommand.getAccessToken(user) + await servers[1].users.create({ username: user.username, password: user.password }) + const userAccessToken = await servers[1].login.getAccessToken(user) const attributes = { name: 'my super name for server 2', @@ -158,7 +158,7 @@ describe('Test multiple servers', function () { thumbnailfile: 'thumbnail.jpg', previewfile: 'preview.jpg' } - await servers[1].videosCommand.upload({ token: userAccessToken, attributes, mode: 'resumable' }) + await servers[1].videos.upload({ token: userAccessToken, attributes, mode: 'resumable' }) // Transcoding await waitJobs(servers) @@ -213,7 +213,7 @@ describe('Test multiple servers', function () { previewfile: 'preview' } - const { data } = await server.videosCommand.list() + const { data } = await server.videos.list() expect(data).to.be.an('array') expect(data.length).to.equal(2) const video = data[1] @@ -237,7 +237,7 @@ describe('Test multiple servers', function () { tags: [ 'tag1p3' ], fixture: 'video_short3.webm' } - await servers[2].videosCommand.upload({ attributes }) + await servers[2].videos.upload({ attributes }) } { @@ -252,7 +252,7 @@ describe('Test multiple servers', function () { tags: [ 'tag2p3', 'tag3p3', 'tag4p3' ], fixture: 'video_short.webm' } - await servers[2].videosCommand.upload({ attributes }) + await servers[2].videos.upload({ attributes }) } await waitJobs(servers) @@ -260,7 +260,7 @@ describe('Test multiple servers', function () { // All servers should have this video for (const server of servers) { const isLocal = server.url === 'http://localhost:' + servers[2].port - const { data } = await server.videosCommand.list() + const { data } = await server.videos.list() expect(data).to.be.an('array') expect(data.length).to.equal(4) @@ -349,7 +349,7 @@ describe('Test multiple servers', function () { describe('It should list local videos', function () { it('Should list only local videos on server 1', async function () { - const { data, total } = await servers[0].videosCommand.list({ filter: 'local' }) + const { data, total } = await servers[0].videos.list({ filter: 'local' }) expect(total).to.equal(1) expect(data).to.be.an('array') @@ -358,7 +358,7 @@ describe('Test multiple servers', function () { }) it('Should list only local videos on server 2', async function () { - const { data, total } = await servers[1].videosCommand.list({ filter: 'local' }) + const { data, total } = await servers[1].videos.list({ filter: 'local' }) expect(total).to.equal(1) expect(data).to.be.an('array') @@ -367,7 +367,7 @@ describe('Test multiple servers', function () { }) it('Should list only local videos on server 3', async function () { - const { data, total } = await servers[2].videosCommand.list({ filter: 'local' }) + const { data, total } = await servers[2].videos.list({ filter: 'local' }) expect(total).to.equal(2) expect(data).to.be.an('array') @@ -381,13 +381,13 @@ describe('Test multiple servers', function () { it('Should add the file 1 by asking server 3', async function () { this.timeout(10000) - const { data } = await servers[2].videosCommand.list() + const { data } = await servers[2].videos.list() const video = data[0] toRemove.push(data[2]) toRemove.push(data[3]) - const videoDetails = await servers[2].videosCommand.get({ id: video.id }) + const videoDetails = await servers[2].videos.get({ id: video.id }) const torrent = await webtorrentAdd(videoDetails.files[0].magnetUri, true) expect(torrent.files).to.be.an('array') expect(torrent.files.length).to.equal(1) @@ -397,10 +397,10 @@ describe('Test multiple servers', function () { it('Should add the file 2 by asking server 1', async function () { this.timeout(10000) - const { data } = await servers[0].videosCommand.list() + const { data } = await servers[0].videos.list() const video = data[1] - const videoDetails = await servers[0].videosCommand.get({ id: video.id }) + const videoDetails = await servers[0].videos.get({ id: video.id }) const torrent = await webtorrentAdd(videoDetails.files[0].magnetUri, true) expect(torrent.files).to.be.an('array') @@ -411,10 +411,10 @@ describe('Test multiple servers', function () { it('Should add the file 3 by asking server 2', async function () { this.timeout(10000) - const { data } = await servers[1].videosCommand.list() + const { data } = await servers[1].videos.list() const video = data[2] - const videoDetails = await servers[1].videosCommand.get({ id: video.id }) + const videoDetails = await servers[1].videos.get({ id: video.id }) const torrent = await webtorrentAdd(videoDetails.files[0].magnetUri, true) expect(torrent.files).to.be.an('array') @@ -425,10 +425,10 @@ describe('Test multiple servers', function () { it('Should add the file 3-2 by asking server 1', async function () { this.timeout(10000) - const { data } = await servers[0].videosCommand.list() + const { data } = await servers[0].videos.list() const video = data[3] - const videoDetails = await servers[0].videosCommand.get({ id: video.id }) + const videoDetails = await servers[0].videos.get({ id: video.id }) const torrent = await webtorrentAdd(videoDetails.files[0].magnetUri) expect(torrent.files).to.be.an('array') @@ -439,10 +439,10 @@ describe('Test multiple servers', function () { it('Should add the file 2 in 360p by asking server 1', async function () { this.timeout(10000) - const { data } = await servers[0].videosCommand.list() + const { data } = await servers[0].videos.list() const video = data.find(v => v.name === 'my super name for server 2') - const videoDetails = await servers[0].videosCommand.get({ id: video.id }) + const videoDetails = await servers[0].videos.get({ id: video.id }) const file = videoDetails.files.find(f => f.resolution.id === 360) expect(file).not.to.be.undefined @@ -462,17 +462,17 @@ describe('Test multiple servers', function () { before(async function () { { - const { data } = await servers[0].videosCommand.list() + const { data } = await servers[0].videos.list() remoteVideosServer1 = data.filter(video => video.isLocal === false).map(video => video.uuid) } { - const { data } = await servers[1].videosCommand.list() + const { data } = await servers[1].videos.list() remoteVideosServer2 = data.filter(video => video.isLocal === false).map(video => video.uuid) } { - const { data } = await servers[2].videosCommand.list() + const { data } = await servers[2].videos.list() localVideosServer3 = data.filter(video => video.isLocal === true).map(video => video.uuid) remoteVideosServer3 = data.filter(video => video.isLocal === false).map(video => video.uuid) } @@ -481,16 +481,16 @@ describe('Test multiple servers', function () { it('Should view multiple videos on owned servers', async function () { this.timeout(30000) - await servers[2].videosCommand.view({ id: localVideosServer3[0] }) + await servers[2].videos.view({ id: localVideosServer3[0] }) await wait(1000) - await servers[2].videosCommand.view({ id: localVideosServer3[0] }) - await servers[2].videosCommand.view({ id: localVideosServer3[1] }) + await servers[2].videos.view({ id: localVideosServer3[0] }) + await servers[2].videos.view({ id: localVideosServer3[1] }) await wait(1000) - await servers[2].videosCommand.view({ id: localVideosServer3[0] }) - await servers[2].videosCommand.view({ id: localVideosServer3[0] }) + await servers[2].videos.view({ id: localVideosServer3[0] }) + await servers[2].videos.view({ id: localVideosServer3[0] }) await waitJobs(servers) @@ -500,7 +500,7 @@ describe('Test multiple servers', function () { await waitJobs(servers) for (const server of servers) { - const { data } = await server.videosCommand.list() + const { data } = await server.videos.list() const video0 = data.find(v => v.uuid === localVideosServer3[0]) const video1 = data.find(v => v.uuid === localVideosServer3[1]) @@ -514,16 +514,16 @@ describe('Test multiple servers', function () { this.timeout(45000) const tasks: Promise[] = [] - tasks.push(servers[0].videosCommand.view({ id: remoteVideosServer1[0] })) - tasks.push(servers[1].videosCommand.view({ id: remoteVideosServer2[0] })) - tasks.push(servers[1].videosCommand.view({ id: remoteVideosServer2[0] })) - tasks.push(servers[2].videosCommand.view({ id: remoteVideosServer3[0] })) - tasks.push(servers[2].videosCommand.view({ id: remoteVideosServer3[1] })) - tasks.push(servers[2].videosCommand.view({ id: remoteVideosServer3[1] })) - tasks.push(servers[2].videosCommand.view({ id: remoteVideosServer3[1] })) - tasks.push(servers[2].videosCommand.view({ id: localVideosServer3[1] })) - tasks.push(servers[2].videosCommand.view({ id: localVideosServer3[1] })) - tasks.push(servers[2].videosCommand.view({ id: localVideosServer3[1] })) + tasks.push(servers[0].videos.view({ id: remoteVideosServer1[0] })) + tasks.push(servers[1].videos.view({ id: remoteVideosServer2[0] })) + tasks.push(servers[1].videos.view({ id: remoteVideosServer2[0] })) + tasks.push(servers[2].videos.view({ id: remoteVideosServer3[0] })) + tasks.push(servers[2].videos.view({ id: remoteVideosServer3[1] })) + tasks.push(servers[2].videos.view({ id: remoteVideosServer3[1] })) + tasks.push(servers[2].videos.view({ id: remoteVideosServer3[1] })) + tasks.push(servers[2].videos.view({ id: localVideosServer3[1] })) + tasks.push(servers[2].videos.view({ id: localVideosServer3[1] })) + tasks.push(servers[2].videos.view({ id: localVideosServer3[1] })) await Promise.all(tasks) @@ -537,7 +537,7 @@ describe('Test multiple servers', function () { let baseVideos = null for (const server of servers) { - const { data } = await server.videosCommand.list() + const { data } = await server.videos.list() // Initialize base videos for future comparisons if (baseVideos === null) { @@ -555,17 +555,17 @@ describe('Test multiple servers', function () { it('Should like and dislikes videos on different services', async function () { this.timeout(50000) - await servers[0].videosCommand.rate({ id: remoteVideosServer1[0], rating: 'like' }) + await servers[0].videos.rate({ id: remoteVideosServer1[0], rating: 'like' }) await wait(500) - await servers[0].videosCommand.rate({ id: remoteVideosServer1[0], rating: 'dislike' }) + await servers[0].videos.rate({ id: remoteVideosServer1[0], rating: 'dislike' }) await wait(500) - await servers[0].videosCommand.rate({ id: remoteVideosServer1[0], rating: 'like' }) - await servers[2].videosCommand.rate({ id: localVideosServer3[1], rating: 'like' }) + await servers[0].videos.rate({ id: remoteVideosServer1[0], rating: 'like' }) + await servers[2].videos.rate({ id: localVideosServer3[1], rating: 'like' }) await wait(500) - await servers[2].videosCommand.rate({ id: localVideosServer3[1], rating: 'dislike' }) - await servers[2].videosCommand.rate({ id: remoteVideosServer3[1], rating: 'dislike' }) + await servers[2].videos.rate({ id: localVideosServer3[1], rating: 'dislike' }) + await servers[2].videos.rate({ id: remoteVideosServer3[1], rating: 'dislike' }) await wait(500) - await servers[2].videosCommand.rate({ id: remoteVideosServer3[0], rating: 'like' }) + await servers[2].videos.rate({ id: remoteVideosServer3[0], rating: 'like' }) await waitJobs(servers) await wait(5000) @@ -573,7 +573,7 @@ describe('Test multiple servers', function () { let baseVideos = null for (const server of servers) { - const { data } = await server.videosCommand.list() + const { data } = await server.videos.list() // Initialize base videos for future comparisons if (baseVideos === null) { @@ -608,7 +608,7 @@ describe('Test multiple servers', function () { previewfile: 'preview.jpg' } - await servers[2].videosCommand.update({ id: toRemove[0].id, attributes }) + await servers[2].videos.update({ id: toRemove[0].id, attributes }) await waitJobs(servers) }) @@ -617,7 +617,7 @@ describe('Test multiple servers', function () { this.timeout(10000) for (const server of servers) { - const { data } = await server.videosCommand.list() + const { data } = await server.videos.list() const videoUpdated = data.find(video => video.name === 'my super video updated') expect(!!videoUpdated).to.be.true @@ -665,8 +665,8 @@ describe('Test multiple servers', function () { it('Should remove the videos 3 and 3-2 by asking server 3', async function () { this.timeout(10000) - await servers[2].videosCommand.remove({ id: toRemove[0].id }) - await servers[2].videosCommand.remove({ id: toRemove[1].id }) + await servers[2].videos.remove({ id: toRemove[0].id }) + await servers[2].videos.remove({ id: toRemove[1].id }) await waitJobs(servers) }) @@ -680,7 +680,7 @@ describe('Test multiple servers', function () { it('Should have videos 1 and 3 on each server', async function () { for (const server of servers) { - const { data } = await server.videosCommand.list() + const { data } = await server.videos.list() expect(data).to.be.an('array') expect(data.length).to.equal(2) @@ -697,7 +697,7 @@ describe('Test multiple servers', function () { it('Should get the same video by UUID on each server', async function () { let baseVideo = null for (const server of servers) { - const video = await server.videosCommand.get({ id: videoUUID }) + const video = await server.videos.get({ id: videoUUID }) if (baseVideo === null) { baseVideo = video @@ -720,7 +720,7 @@ describe('Test multiple servers', function () { it('Should get the preview from each server', async function () { for (const server of servers) { - const video = await server.videosCommand.get({ id: videoUUID }) + const video = await server.videos.get({ id: videoUUID }) await testImage(server.url, 'video_short1-preview.webm', video.previewPath) } @@ -735,36 +735,36 @@ describe('Test multiple servers', function () { { const text = 'my super first comment' - await servers[0].commentsCommand.createThread({ videoId: videoUUID, text }) + await servers[0].comments.createThread({ videoId: videoUUID, text }) } { const text = 'my super second comment' - await servers[2].commentsCommand.createThread({ videoId: videoUUID, text }) + await servers[2].comments.createThread({ videoId: videoUUID, text }) } await waitJobs(servers) { - const threadId = await servers[1].commentsCommand.findCommentId({ videoId: videoUUID, text: 'my super first comment' }) + const threadId = await servers[1].comments.findCommentId({ videoId: videoUUID, text: 'my super first comment' }) const text = 'my super answer to thread 1' - await servers[1].commentsCommand.addReply({ videoId: videoUUID, toCommentId: threadId, text }) + await servers[1].comments.addReply({ videoId: videoUUID, toCommentId: threadId, text }) } await waitJobs(servers) { - const threadId = await servers[2].commentsCommand.findCommentId({ videoId: videoUUID, text: 'my super first comment' }) + const threadId = await servers[2].comments.findCommentId({ videoId: videoUUID, text: 'my super first comment' }) - const body = await servers[2].commentsCommand.getThread({ videoId: videoUUID, threadId }) + const body = await servers[2].comments.getThread({ videoId: videoUUID, threadId }) const childCommentId = body.children[0].comment.id const text3 = 'my second answer to thread 1' - await servers[2].commentsCommand.addReply({ videoId: videoUUID, toCommentId: threadId, text: text3 }) + await servers[2].comments.addReply({ videoId: videoUUID, toCommentId: threadId, text: text3 }) const text2 = 'my super answer to answer of thread 1' - await servers[2].commentsCommand.addReply({ videoId: videoUUID, toCommentId: childCommentId, text: text2 }) + await servers[2].comments.addReply({ videoId: videoUUID, toCommentId: childCommentId, text: text2 }) } await waitJobs(servers) @@ -772,7 +772,7 @@ describe('Test multiple servers', function () { it('Should have these threads', async function () { for (const server of servers) { - const body = await server.commentsCommand.listThreads({ videoId: videoUUID }) + const body = await server.comments.listThreads({ videoId: videoUUID }) expect(body.total).to.equal(2) expect(body.data).to.be.an('array') @@ -804,10 +804,10 @@ describe('Test multiple servers', function () { it('Should have these comments', async function () { for (const server of servers) { - const body = await server.commentsCommand.listThreads({ videoId: videoUUID }) + const body = await server.comments.listThreads({ videoId: videoUUID }) const threadId = body.data.find(c => c.text === 'my super first comment').id - const tree = await server.commentsCommand.getThread({ videoId: videoUUID, threadId }) + const tree = await server.comments.getThread({ videoId: videoUUID, threadId }) expect(tree.comment.text).equal('my super first comment') expect(tree.comment.account.name).equal('root') @@ -837,17 +837,17 @@ describe('Test multiple servers', function () { it('Should delete a reply', async function () { this.timeout(10000) - await servers[2].commentsCommand.delete({ videoId: videoUUID, commentId: childOfFirstChild.comment.id }) + await servers[2].comments.delete({ videoId: videoUUID, commentId: childOfFirstChild.comment.id }) await waitJobs(servers) }) it('Should have this comment marked as deleted', async function () { for (const server of servers) { - const { data } = await server.commentsCommand.listThreads({ videoId: videoUUID }) + const { data } = await server.comments.listThreads({ videoId: videoUUID }) const threadId = data.find(c => c.text === 'my super first comment').id - const tree = await server.commentsCommand.getThread({ videoId: videoUUID, threadId }) + const tree = await server.comments.getThread({ videoId: videoUUID, threadId }) expect(tree.comment.text).equal('my super first comment') const firstChild = tree.children[0] @@ -868,16 +868,16 @@ describe('Test multiple servers', function () { it('Should delete the thread comments', async function () { this.timeout(10000) - const { data } = await servers[0].commentsCommand.listThreads({ videoId: videoUUID }) + const { data } = await servers[0].comments.listThreads({ videoId: videoUUID }) const commentId = data.find(c => c.text === 'my super first comment').id - await servers[0].commentsCommand.delete({ videoId: videoUUID, commentId }) + await servers[0].comments.delete({ videoId: videoUUID, commentId }) await waitJobs(servers) }) it('Should have the threads marked as deleted on other servers too', async function () { for (const server of servers) { - const body = await server.commentsCommand.listThreads({ videoId: videoUUID }) + const body = await server.comments.listThreads({ videoId: videoUUID }) expect(body.total).to.equal(2) expect(body.data).to.be.an('array') @@ -913,16 +913,16 @@ describe('Test multiple servers', function () { it('Should delete a remote thread by the origin server', async function () { this.timeout(5000) - const { data } = await servers[0].commentsCommand.listThreads({ videoId: videoUUID }) + const { data } = await servers[0].comments.listThreads({ videoId: videoUUID }) const commentId = data.find(c => c.text === 'my super second comment').id - await servers[0].commentsCommand.delete({ videoId: videoUUID, commentId }) + await servers[0].comments.delete({ videoId: videoUUID, commentId }) await waitJobs(servers) }) it('Should have the threads marked as deleted on other servers too', async function () { for (const server of servers) { - const body = await server.commentsCommand.listThreads({ videoId: videoUUID }) + const body = await server.comments.listThreads({ videoId: videoUUID }) expect(body.total).to.equal(2) expect(body.data).to.have.lengthOf(2) @@ -957,17 +957,17 @@ describe('Test multiple servers', function () { downloadEnabled: false } - await servers[0].videosCommand.update({ id: videoUUID, attributes }) + await servers[0].videos.update({ id: videoUUID, attributes }) await waitJobs(servers) for (const server of servers) { - const video = await server.videosCommand.get({ id: videoUUID }) + const video = await server.videos.get({ id: videoUUID }) expect(video.commentsEnabled).to.be.false expect(video.downloadEnabled).to.be.false const text = 'my super forbidden comment' - await server.commentsCommand.createThread({ videoId: videoUUID, text, expectedStatus: HttpStatusCode.CONFLICT_409 }) + await server.comments.createThread({ videoId: videoUUID, text, expectedStatus: HttpStatusCode.CONFLICT_409 }) } }) }) @@ -992,7 +992,7 @@ describe('Test multiple servers', function () { await waitJobs(servers) for (const server of servers) { - const { data } = await server.videosCommand.list() + const { data } = await server.videos.list() const video = data.find(v => v.name === 'minimum parameters') const isLocal = server.url === 'http://localhost:' + servers[1].port diff --git a/server/tests/api/videos/resumable-upload.ts b/server/tests/api/videos/resumable-upload.ts index b7756a4a8..2f1cf8a55 100644 --- a/server/tests/api/videos/resumable-upload.ts +++ b/server/tests/api/videos/resumable-upload.ts @@ -36,14 +36,14 @@ describe('Test resumable upload', function () { const attributes = { name: 'video', - channelId: server.videoChannel.id, + channelId: server.store.channel.id, privacy: VideoPrivacy.PUBLIC, fixture: defaultFixture } const mimetype = 'video/mp4' - const res = await server.videosCommand.prepareResumableUpload({ attributes, size, mimetype }) + const res = await server.videos.prepareResumableUpload({ attributes, size, mimetype }) return res.header['location'].split('?')[1] } @@ -61,7 +61,7 @@ describe('Test resumable upload', function () { const size = await buildSize(defaultFixture, options.size) const absoluteFilePath = buildAbsoluteFixturePath(defaultFixture) - return server.videosCommand.sendResumableChunks({ + return server.videos.sendResumableChunks({ pathUploadId, videoFilePath: absoluteFilePath, size, @@ -75,7 +75,7 @@ describe('Test resumable upload', function () { const uploadId = uploadIdArg.replace(/^upload_id=/, '') const subPath = join('tmp', 'resumable-uploads', uploadId) - const filePath = server.serversCommand.buildDirectory(subPath) + const filePath = server.servers.buildDirectory(subPath) const exists = await pathExists(filePath) if (expectedSize === null) { @@ -90,7 +90,7 @@ describe('Test resumable upload', function () { async function countResumableUploads () { const subPath = join('tmp', 'resumable-uploads') - const filePath = server.serversCommand.buildDirectory(subPath) + const filePath = server.servers.buildDirectory(subPath) const files = await readdir(filePath) return files.length @@ -103,10 +103,10 @@ describe('Test resumable upload', function () { await setAccessTokensToServers([ server ]) await setDefaultVideoChannel([ server ]) - const body = await server.usersCommand.getMyInfo() + const body = await server.users.getMyInfo() rootId = body.id - await server.usersCommand.update({ userId: rootId, videoQuota: 10_000_000 }) + await server.users.update({ userId: rootId, videoQuota: 10_000_000 }) }) describe('Directory cleaning', function () { @@ -125,13 +125,13 @@ describe('Test resumable upload', function () { }) it('Should not delete recent uploads', async function () { - await server.debugCommand.sendCommand({ body: { command: 'remove-dandling-resumable-uploads' } }) + await server.debug.sendCommand({ body: { command: 'remove-dandling-resumable-uploads' } }) expect(await countResumableUploads()).to.equal(2) }) it('Should delete old uploads', async function () { - await server.debugCommand.sendCommand({ body: { command: 'remove-dandling-resumable-uploads' } }) + await server.debug.sendCommand({ body: { command: 'remove-dandling-resumable-uploads' } }) expect(await countResumableUploads()).to.equal(0) }) diff --git a/server/tests/api/videos/single-server.ts b/server/tests/api/videos/single-server.ts index da0b2011e..12c1f7b2f 100644 --- a/server/tests/api/videos/single-server.ts +++ b/server/tests/api/videos/single-server.ts @@ -100,35 +100,35 @@ describe('Test a single server', function () { }) it('Should list video categories', async function () { - const categories = await server.videosCommand.getCategories() + const categories = await server.videos.getCategories() expect(Object.keys(categories)).to.have.length.above(10) expect(categories[11]).to.equal('News & Politics') }) it('Should list video licences', async function () { - const licences = await server.videosCommand.getLicences() + const licences = await server.videos.getLicences() expect(Object.keys(licences)).to.have.length.above(5) expect(licences[3]).to.equal('Attribution - No Derivatives') }) it('Should list video languages', async function () { - const languages = await server.videosCommand.getLanguages() + const languages = await server.videos.getLanguages() expect(Object.keys(languages)).to.have.length.above(5) expect(languages['ru']).to.equal('Russian') }) it('Should list video privacies', async function () { - const privacies = await server.videosCommand.getPrivacies() + const privacies = await server.videos.getPrivacies() expect(Object.keys(privacies)).to.have.length.at.least(3) expect(privacies[3]).to.equal('Private') }) it('Should not have videos', async function () { - const { data, total } = await server.videosCommand.list() + const { data, total } = await server.videos.list() expect(total).to.equal(0) expect(data).to.be.an('array') @@ -145,7 +145,7 @@ describe('Test a single server', function () { licence: 6, tags: [ 'tag1', 'tag2', 'tag3' ] } - const video = await server.videosCommand.upload({ attributes, mode }) + const video = await server.videos.upload({ attributes, mode }) expect(video).to.not.be.undefined expect(video.id).to.equal(1) expect(video.uuid).to.have.length.above(5) @@ -157,7 +157,7 @@ describe('Test a single server', function () { it('Should get and seed the uploaded video', async function () { this.timeout(5000) - const { data, total } = await server.videosCommand.list() + const { data, total } = await server.videos.list() expect(total).to.equal(1) expect(data).to.be.an('array') @@ -170,42 +170,42 @@ describe('Test a single server', function () { it('Should get the video by UUID', async function () { this.timeout(5000) - const video = await server.videosCommand.get({ id: videoUUID }) + const video = await server.videos.get({ id: videoUUID }) await completeVideoCheck(server, video, getCheckAttributes()) }) it('Should have the views updated', async function () { this.timeout(20000) - await server.videosCommand.view({ id: videoId }) - await server.videosCommand.view({ id: videoId }) - await server.videosCommand.view({ id: videoId }) + await server.videos.view({ id: videoId }) + await server.videos.view({ id: videoId }) + await server.videos.view({ id: videoId }) await wait(1500) - await server.videosCommand.view({ id: videoId }) - await server.videosCommand.view({ id: videoId }) + await server.videos.view({ id: videoId }) + await server.videos.view({ id: videoId }) await wait(1500) - await server.videosCommand.view({ id: videoId }) - await server.videosCommand.view({ id: videoId }) + await server.videos.view({ id: videoId }) + await server.videos.view({ id: videoId }) // Wait the repeatable job await wait(8000) - const video = await server.videosCommand.get({ id: videoId }) + const video = await server.videos.get({ id: videoId }) expect(video.views).to.equal(3) }) it('Should remove the video', async function () { - await server.videosCommand.remove({ id: videoId }) + await server.videos.remove({ id: videoId }) await checkVideoFilesWereRemoved(videoUUID, server) }) it('Should not have videos', async function () { - const { total, data } = await server.videosCommand.list() + const { total, data } = await server.videos.list() expect(total).to.equal(0) expect(data).to.be.an('array') @@ -232,12 +232,12 @@ describe('Test a single server', function () { fixture: video } - await server.videosCommand.upload({ attributes, mode }) + await server.videos.upload({ attributes, mode }) } }) it('Should have the correct durations', async function () { - const { total, data } = await server.videosCommand.list() + const { total, data } = await server.videos.list() expect(total).to.equal(6) expect(data).to.be.an('array') @@ -255,7 +255,7 @@ describe('Test a single server', function () { }) it('Should have the correct thumbnails', async function () { - const { data } = await server.videosCommand.list() + const { data } = await server.videos.list() // For the next test videosListBase = data @@ -267,7 +267,7 @@ describe('Test a single server', function () { }) it('Should list only the two first videos', async function () { - const { total, data } = await server.videosCommand.list({ start: 0, count: 2, sort: 'name' }) + const { total, data } = await server.videos.list({ start: 0, count: 2, sort: 'name' }) expect(total).to.equal(6) expect(data.length).to.equal(2) @@ -276,7 +276,7 @@ describe('Test a single server', function () { }) it('Should list only the next three videos', async function () { - const { total, data } = await server.videosCommand.list({ start: 2, count: 3, sort: 'name' }) + const { total, data } = await server.videos.list({ start: 2, count: 3, sort: 'name' }) expect(total).to.equal(6) expect(data.length).to.equal(3) @@ -286,7 +286,7 @@ describe('Test a single server', function () { }) it('Should list the last video', async function () { - const { total, data } = await server.videosCommand.list({ start: 5, count: 6, sort: 'name' }) + const { total, data } = await server.videos.list({ start: 5, count: 6, sort: 'name' }) expect(total).to.equal(6) expect(data.length).to.equal(1) @@ -294,7 +294,7 @@ describe('Test a single server', function () { }) it('Should not have the total field', async function () { - const { total, data } = await server.videosCommand.list({ start: 5, count: 6, sort: 'name', skipCount: true }) + const { total, data } = await server.videos.list({ start: 5, count: 6, sort: 'name', skipCount: true }) expect(total).to.not.exist expect(data.length).to.equal(1) @@ -302,7 +302,7 @@ describe('Test a single server', function () { }) it('Should list and sort by name in descending order', async function () { - const { total, data } = await server.videosCommand.list({ sort: '-name' }) + const { total, data } = await server.videos.list({ sort: '-name' }) expect(total).to.equal(6) expect(data.length).to.equal(6) @@ -318,21 +318,21 @@ describe('Test a single server', function () { }) it('Should list and sort by trending in descending order', async function () { - const { total, data } = await server.videosCommand.list({ start: 0, count: 2, sort: '-trending' }) + const { total, data } = await server.videos.list({ start: 0, count: 2, sort: '-trending' }) expect(total).to.equal(6) expect(data.length).to.equal(2) }) it('Should list and sort by hotness in descending order', async function () { - const { total, data } = await server.videosCommand.list({ start: 0, count: 2, sort: '-hot' }) + const { total, data } = await server.videos.list({ start: 0, count: 2, sort: '-hot' }) expect(total).to.equal(6) expect(data.length).to.equal(2) }) it('Should list and sort by best in descending order', async function () { - const { total, data } = await server.videosCommand.list({ start: 0, count: 2, sort: '-best' }) + const { total, data } = await server.videos.list({ start: 0, count: 2, sort: '-best' }) expect(total).to.equal(6) expect(data.length).to.equal(2) @@ -350,18 +350,18 @@ describe('Test a single server', function () { downloadEnabled: false, tags: [ 'tagup1', 'tagup2' ] } - await server.videosCommand.update({ id: videoId, attributes }) + await server.videos.update({ id: videoId, attributes }) }) it('Should filter by tags and category', async function () { { - const { data, total } = await server.videosCommand.list({ tagsAllOf: [ 'tagup1', 'tagup2' ], categoryOneOf: [ 4 ] }) + const { data, total } = await server.videos.list({ tagsAllOf: [ 'tagup1', 'tagup2' ], categoryOneOf: [ 4 ] }) expect(total).to.equal(1) expect(data[0].name).to.equal('my super video updated') } { - const { total } = await server.videosCommand.list({ tagsAllOf: [ 'tagup1', 'tagup2' ], categoryOneOf: [ 3 ] }) + const { total } = await server.videos.list({ tagsAllOf: [ 'tagup1', 'tagup2' ], categoryOneOf: [ 3 ] }) expect(total).to.equal(0) } }) @@ -369,7 +369,7 @@ describe('Test a single server', function () { it('Should have the video updated', async function () { this.timeout(60000) - const video = await server.videosCommand.get({ id: videoId }) + const video = await server.videos.get({ id: videoId }) await completeVideoCheck(server, video, updateCheckAttributes()) }) @@ -378,9 +378,9 @@ describe('Test a single server', function () { const attributes = { tags: [ 'supertag', 'tag1', 'tag2' ] } - await server.videosCommand.update({ id: videoId, attributes }) + await server.videos.update({ id: videoId, attributes }) - const video = await server.videosCommand.get({ id: videoId }) + const video = await server.videos.get({ id: videoId }) await completeVideoCheck(server, video, Object.assign(updateCheckAttributes(), attributes)) }) @@ -389,27 +389,27 @@ describe('Test a single server', function () { const attributes = { description: 'hello everybody' } - await server.videosCommand.update({ id: videoId, attributes }) + await server.videos.update({ id: videoId, attributes }) - const video = await server.videosCommand.get({ id: videoId }) + const video = await server.videos.get({ id: videoId }) const expectedAttributes = Object.assign(updateCheckAttributes(), { tags: [ 'supertag', 'tag1', 'tag2' ] }, attributes) await completeVideoCheck(server, video, expectedAttributes) }) it('Should like a video', async function () { - await server.videosCommand.rate({ id: videoId, rating: 'like' }) + await server.videos.rate({ id: videoId, rating: 'like' }) - const video = await server.videosCommand.get({ id: videoId }) + const video = await server.videos.get({ id: videoId }) expect(video.likes).to.equal(1) expect(video.dislikes).to.equal(0) }) it('Should dislike the same video', async function () { - await server.videosCommand.rate({ id: videoId, rating: 'dislike' }) + await server.videos.rate({ id: videoId, rating: 'dislike' }) - const video = await server.videosCommand.get({ id: videoId }) + const video = await server.videos.get({ id: videoId }) expect(video.likes).to.equal(0) expect(video.dislikes).to.equal(1) @@ -419,9 +419,9 @@ describe('Test a single server', function () { { const now = new Date() const attributes = { originallyPublishedAt: now.toISOString() } - await server.videosCommand.update({ id: videoId, attributes }) + await server.videos.update({ id: videoId, attributes }) - const { data } = await server.videosCommand.list({ sort: '-originallyPublishedAt' }) + const { data } = await server.videos.list({ sort: '-originallyPublishedAt' }) const names = data.map(v => v.name) expect(names[0]).to.equal('my super video updated') @@ -435,9 +435,9 @@ describe('Test a single server', function () { { const now = new Date() const attributes = { originallyPublishedAt: now.toISOString() } - await server.videosCommand.update({ id: videoId2, attributes }) + await server.videos.update({ id: videoId2, attributes }) - const { data } = await server.videosCommand.list({ sort: '-originallyPublishedAt' }) + const { data } = await server.videos.list({ sort: '-originallyPublishedAt' }) const names = data.map(v => v.name) expect(names[0]).to.equal('video_short1.webm name') diff --git a/server/tests/api/videos/video-captions.ts b/server/tests/api/videos/video-captions.ts index 4c67e96f7..abc07194d 100644 --- a/server/tests/api/videos/video-captions.ts +++ b/server/tests/api/videos/video-captions.ts @@ -32,7 +32,7 @@ describe('Test video captions', function () { await waitJobs(servers) - const { uuid } = await servers[0].videosCommand.upload({ attributes: { name: 'my video name' } }) + const { uuid } = await servers[0].videos.upload({ attributes: { name: 'my video name' } }) videoUUID = uuid await waitJobs(servers) @@ -40,7 +40,7 @@ describe('Test video captions', function () { it('Should list the captions and return an empty list', async function () { for (const server of servers) { - const body = await server.captionsCommand.listVideoCaptions({ videoId: videoUUID }) + const body = await server.captions.listVideoCaptions({ videoId: videoUUID }) expect(body.total).to.equal(0) expect(body.data).to.have.lengthOf(0) } @@ -49,13 +49,13 @@ describe('Test video captions', function () { it('Should create two new captions', async function () { this.timeout(30000) - await servers[0].captionsCommand.createVideoCaption({ + await servers[0].captions.createVideoCaption({ language: 'ar', videoId: videoUUID, fixture: 'subtitle-good1.vtt' }) - await servers[0].captionsCommand.createVideoCaption({ + await servers[0].captions.createVideoCaption({ language: 'zh', videoId: videoUUID, fixture: 'subtitle-good2.vtt', @@ -67,7 +67,7 @@ describe('Test video captions', function () { it('Should list these uploaded captions', async function () { for (const server of servers) { - const body = await server.captionsCommand.listVideoCaptions({ videoId: videoUUID }) + const body = await server.captions.listVideoCaptions({ videoId: videoUUID }) expect(body.total).to.equal(2) expect(body.data).to.have.lengthOf(2) @@ -88,7 +88,7 @@ describe('Test video captions', function () { it('Should replace an existing caption', async function () { this.timeout(30000) - await servers[0].captionsCommand.createVideoCaption({ + await servers[0].captions.createVideoCaption({ language: 'ar', videoId: videoUUID, fixture: 'subtitle-good2.vtt' @@ -99,7 +99,7 @@ describe('Test video captions', function () { it('Should have this caption updated', async function () { for (const server of servers) { - const body = await server.captionsCommand.listVideoCaptions({ videoId: videoUUID }) + const body = await server.captions.listVideoCaptions({ videoId: videoUUID }) expect(body.total).to.equal(2) expect(body.data).to.have.lengthOf(2) @@ -114,7 +114,7 @@ describe('Test video captions', function () { it('Should replace an existing caption with a srt file and convert it', async function () { this.timeout(30000) - await servers[0].captionsCommand.createVideoCaption({ + await servers[0].captions.createVideoCaption({ language: 'ar', videoId: videoUUID, fixture: 'subtitle-good.srt' @@ -128,7 +128,7 @@ describe('Test video captions', function () { it('Should have this caption updated and converted', async function () { for (const server of servers) { - const body = await server.captionsCommand.listVideoCaptions({ videoId: videoUUID }) + const body = await server.captions.listVideoCaptions({ videoId: videoUUID }) expect(body.total).to.equal(2) expect(body.data).to.have.lengthOf(2) @@ -157,14 +157,14 @@ describe('Test video captions', function () { it('Should remove one caption', async function () { this.timeout(30000) - await servers[0].captionsCommand.deleteVideoCaption({ videoId: videoUUID, language: 'ar' }) + await servers[0].captions.deleteVideoCaption({ videoId: videoUUID, language: 'ar' }) await waitJobs(servers) }) it('Should only list the caption that was not deleted', async function () { for (const server of servers) { - const body = await server.captionsCommand.listVideoCaptions({ videoId: videoUUID }) + const body = await server.captions.listVideoCaptions({ videoId: videoUUID }) expect(body.total).to.equal(1) expect(body.data).to.have.lengthOf(1) @@ -178,7 +178,7 @@ describe('Test video captions', function () { }) it('Should remove the video, and thus all video captions', async function () { - await servers[0].videosCommand.remove({ id: videoUUID }) + await servers[0].videos.remove({ id: videoUUID }) await checkVideoFilesWereRemoved(videoUUID, servers[0]) }) diff --git a/server/tests/api/videos/video-change-ownership.ts b/server/tests/api/videos/video-change-ownership.ts index b85edd920..352eb5ea3 100644 --- a/server/tests/api/videos/video-change-ownership.ts +++ b/server/tests/api/videos/video-change-ownership.ts @@ -43,7 +43,7 @@ describe('Test video change ownership - nominal', function () { await setAccessTokensToServers(servers) await setDefaultVideoChannel(servers) - await servers[0].configCommand.updateCustomSubConfig({ + await servers[0].config.updateCustomSubConfig({ newConfig: { transcoding: { enabled: false @@ -54,16 +54,16 @@ describe('Test video change ownership - nominal', function () { } }) - firstUserToken = await servers[0].usersCommand.generateUserAndToken(firstUser) - secondUserToken = await servers[0].usersCommand.generateUserAndToken(secondUser) + firstUserToken = await servers[0].users.generateUserAndToken(firstUser) + secondUserToken = await servers[0].users.generateUserAndToken(secondUser) { - const { videoChannels } = await servers[0].usersCommand.getMyInfo({ token: firstUserToken }) + const { videoChannels } = await servers[0].users.getMyInfo({ token: firstUserToken }) firstUserChannelId = videoChannels[0].id } { - const { videoChannels } = await servers[0].usersCommand.getMyInfo({ token: secondUserToken }) + const { videoChannels } = await servers[0].users.getMyInfo({ token: secondUserToken }) secondUserChannelId = videoChannels[0].id } @@ -72,19 +72,19 @@ describe('Test video change ownership - nominal', function () { name: 'my super name', description: 'my super description' } - const { id } = await servers[0].videosCommand.upload({ token: firstUserToken, attributes }) + const { id } = await servers[0].videos.upload({ token: firstUserToken, attributes }) - servers[0].video = await servers[0].videosCommand.get({ id }) + servers[0].store.video = await servers[0].videos.get({ id }) } { const attributes = { name: 'live', channelId: firstUserChannelId, privacy: VideoPrivacy.PUBLIC } - const video = await servers[0].liveCommand.create({ token: firstUserToken, fields: attributes }) + const video = await servers[0].live.create({ token: firstUserToken, fields: attributes }) liveId = video.id } - command = servers[0].changeOwnershipCommand + command = servers[0].changeOwnership await doubleFollow(servers[0], servers[1]) }) @@ -110,7 +110,7 @@ describe('Test video change ownership - nominal', function () { it('Should send a request to change ownership of a video', async function () { this.timeout(15000) - await command.create({ token: firstUserToken, videoId: servers[0].video.id, username: secondUser }) + await command.create({ token: firstUserToken, videoId: servers[0].store.video.id, username: secondUser }) }) it('Should only return a request to change ownership for the second user', async function () { @@ -136,7 +136,7 @@ describe('Test video change ownership - nominal', function () { it('Should accept the same change ownership request without crashing', async function () { this.timeout(10000) - await command.create({ token: firstUserToken, videoId: servers[0].video.id, username: secondUser }) + await command.create({ token: firstUserToken, videoId: servers[0].store.video.id, username: secondUser }) }) it('Should not create multiple change ownership requests while one is waiting', async function () { @@ -164,7 +164,7 @@ describe('Test video change ownership - nominal', function () { it('Should send a new request to change ownership of a video', async function () { this.timeout(15000) - await command.create({ token: firstUserToken, videoId: servers[0].video.id, username: secondUser }) + await command.create({ token: firstUserToken, videoId: servers[0].store.video.id, username: secondUser }) }) it('Should return two requests to change ownership for the second user', async function () { @@ -208,7 +208,7 @@ describe('Test video change ownership - nominal', function () { it('Should have the channel of the video updated', async function () { for (const server of servers) { - const video = await server.videosCommand.get({ id: servers[0].video.uuid }) + const video = await server.videos.get({ id: servers[0].store.video.uuid }) expect(video.name).to.equal('my super name') expect(video.channel.displayName).to.equal('Main second channel') @@ -237,7 +237,7 @@ describe('Test video change ownership - nominal', function () { await waitJobs(servers) for (const server of servers) { - const video = await server.videosCommand.get({ id: servers[0].video.uuid }) + const video = await server.videos.get({ id: servers[0].store.video.uuid }) expect(video.name).to.equal('my super name') expect(video.channel.displayName).to.equal('Main second channel') @@ -266,35 +266,35 @@ describe('Test video change ownership - quota too small', function () { server = await flushAndRunServer(1) await setAccessTokensToServers([ server ]) - await server.usersCommand.create({ username: secondUser, videoQuota: 10 }) + await server.users.create({ username: secondUser, videoQuota: 10 }) - firstUserToken = await server.usersCommand.generateUserAndToken(firstUser) - secondUserToken = await server.loginCommand.getAccessToken(secondUser) + firstUserToken = await server.users.generateUserAndToken(firstUser) + secondUserToken = await server.login.getAccessToken(secondUser) // Upload some videos on the server const attributes = { name: 'my super name', description: 'my super description' } - await server.videosCommand.upload({ token: firstUserToken, attributes }) + await server.videos.upload({ token: firstUserToken, attributes }) await waitJobs(server) - const { data } = await server.videosCommand.list() + const { data } = await server.videos.list() expect(data.length).to.equal(1) - server.video = data.find(video => video.name === 'my super name') + server.store.video = data.find(video => video.name === 'my super name') }) it('Should send a request to change ownership of a video', async function () { this.timeout(15000) - await server.changeOwnershipCommand.create({ token: firstUserToken, videoId: server.video.id, username: secondUser }) + await server.changeOwnership.create({ token: firstUserToken, videoId: server.store.video.id, username: secondUser }) }) it('Should only return a request to change ownership for the second user', async function () { { - const body = await server.changeOwnershipCommand.list({ token: firstUserToken }) + const body = await server.changeOwnership.list({ token: firstUserToken }) expect(body.total).to.equal(0) expect(body.data).to.be.an('array') @@ -302,7 +302,7 @@ describe('Test video change ownership - quota too small', function () { } { - const body = await server.changeOwnershipCommand.list({ token: secondUserToken }) + const body = await server.changeOwnership.list({ token: secondUserToken }) expect(body.total).to.equal(1) expect(body.data).to.be.an('array') @@ -315,10 +315,10 @@ describe('Test video change ownership - quota too small', function () { it('Should not be possible to accept the change of ownership from second user because of exceeded quota', async function () { this.timeout(10000) - const { videoChannels } = await server.usersCommand.getMyInfo({ token: secondUserToken }) + const { videoChannels } = await server.users.getMyInfo({ token: secondUserToken }) const channelId = videoChannels[0].id - await server.changeOwnershipCommand.accept({ + await server.changeOwnership.accept({ token: secondUserToken, ownershipId: lastRequestId, channelId, diff --git a/server/tests/api/videos/video-channels.ts b/server/tests/api/videos/video-channels.ts index 170cc942e..1efef932c 100644 --- a/server/tests/api/videos/video-channels.ts +++ b/server/tests/api/videos/video-channels.ts @@ -21,7 +21,7 @@ import { User, VideoChannel } from '@shared/models' const expect = chai.expect async function findChannel (server: ServerInfo, channelId: number) { - const body = await server.channelsCommand.list({ sort: '-name' }) + const body = await server.channels.list({ sort: '-name' }) return body.data.find(c => c.id === channelId) } @@ -49,7 +49,7 @@ describe('Test video channels', function () { }) it('Should have one video channel (created with root)', async () => { - const body = await servers[0].channelsCommand.list({ start: 0, count: 2 }) + const body = await servers[0].channels.list({ start: 0, count: 2 }) expect(body.total).to.equal(1) expect(body.data).to.be.an('array') @@ -66,14 +66,14 @@ describe('Test video channels', function () { description: 'super video channel description', support: 'super video channel support text' } - const created = await servers[0].channelsCommand.create({ attributes: videoChannel }) + const created = await servers[0].channels.create({ attributes: videoChannel }) secondVideoChannelId = created.id } // The channel is 1 is propagated to servers 2 { const attributes = { name: 'my video name', channelId: secondVideoChannelId, support: 'video support field' } - const { uuid } = await servers[0].videosCommand.upload({ attributes }) + const { uuid } = await servers[0].videos.upload({ attributes }) videoUUID = uuid } @@ -81,7 +81,7 @@ describe('Test video channels', function () { }) it('Should have two video channels when getting my information', async () => { - userInfo = await servers[0].usersCommand.getMyInfo() + userInfo = await servers[0].users.getMyInfo() expect(userInfo.videoChannels).to.be.an('array') expect(userInfo.videoChannels).to.have.lengthOf(2) @@ -99,7 +99,7 @@ describe('Test video channels', function () { }) it('Should have two video channels when getting account channels on server 1', async function () { - const body = await servers[0].channelsCommand.listByAccount({ accountName }) + const body = await servers[0].channels.listByAccount({ accountName }) expect(body.total).to.equal(2) const videoChannels = body.data @@ -118,7 +118,7 @@ describe('Test video channels', function () { it('Should paginate and sort account channels', async function () { { - const body = await servers[0].channelsCommand.listByAccount({ + const body = await servers[0].channels.listByAccount({ accountName, start: 0, count: 1, @@ -133,7 +133,7 @@ describe('Test video channels', function () { } { - const body = await servers[0].channelsCommand.listByAccount({ + const body = await servers[0].channels.listByAccount({ accountName, start: 0, count: 1, @@ -146,7 +146,7 @@ describe('Test video channels', function () { } { - const body = await servers[0].channelsCommand.listByAccount({ + const body = await servers[0].channels.listByAccount({ accountName, start: 1, count: 1, @@ -160,7 +160,7 @@ describe('Test video channels', function () { }) it('Should have one video channel when getting account channels on server 2', async function () { - const body = await servers[1].channelsCommand.listByAccount({ accountName }) + const body = await servers[1].channels.listByAccount({ accountName }) expect(body.total).to.equal(1) expect(body.data).to.be.an('array') @@ -174,7 +174,7 @@ describe('Test video channels', function () { }) it('Should list video channels', async function () { - const body = await servers[0].channelsCommand.list({ start: 1, count: 1, sort: '-name' }) + const body = await servers[0].channels.list({ start: 1, count: 1, sort: '-name' }) expect(body.total).to.equal(2) expect(body.data).to.be.an('array') @@ -192,14 +192,14 @@ describe('Test video channels', function () { support: 'support updated' } - await servers[0].channelsCommand.update({ channelName: 'second_video_channel', attributes: videoChannelAttributes }) + await servers[0].channels.update({ channelName: 'second_video_channel', attributes: videoChannelAttributes }) await waitJobs(servers) }) it('Should have video channel updated', async function () { for (const server of servers) { - const body = await server.channelsCommand.list({ start: 0, count: 1, sort: '-name' }) + const body = await server.channels.list({ start: 0, count: 1, sort: '-name' }) expect(body.total).to.equal(2) expect(body.data).to.be.an('array') @@ -214,7 +214,7 @@ describe('Test video channels', function () { it('Should not have updated the video support field', async function () { for (const server of servers) { - const video = await server.videosCommand.get({ id: videoUUID }) + const video = await server.videos.get({ id: videoUUID }) expect(video.support).to.equal('video support field') } }) @@ -227,12 +227,12 @@ describe('Test video channels', function () { bulkVideosSupportUpdate: true } - await servers[0].channelsCommand.update({ channelName: 'second_video_channel', attributes: videoChannelAttributes }) + await servers[0].channels.update({ channelName: 'second_video_channel', attributes: videoChannelAttributes }) await waitJobs(servers) for (const server of servers) { - const video = await server.videosCommand.get({ id: videoUUID }) + const video = await server.videos.get({ id: videoUUID }) expect(video.support).to.equal(videoChannelAttributes.support) } }) @@ -242,7 +242,7 @@ describe('Test video channels', function () { const fixture = 'avatar.png' - await servers[0].channelsCommand.updateImage({ + await servers[0].channels.updateImage({ channelName: 'second_video_channel', fixture, type: 'avatar' @@ -257,7 +257,7 @@ describe('Test video channels', function () { await testImage(server.url, 'avatar-resized', avatarPaths[server.port], '.png') await testFileExistsOrNot(server, 'avatars', basename(avatarPaths[server.port]), true) - const row = await server.sqlCommand.getActorImage(basename(avatarPaths[server.port])) + const row = await server.sql.getActorImage(basename(avatarPaths[server.port])) expect(row.height).to.equal(ACTOR_IMAGES_SIZE.AVATARS.height) expect(row.width).to.equal(ACTOR_IMAGES_SIZE.AVATARS.width) } @@ -268,7 +268,7 @@ describe('Test video channels', function () { const fixture = 'banner.jpg' - await servers[0].channelsCommand.updateImage({ + await servers[0].channels.updateImage({ channelName: 'second_video_channel', fixture, type: 'banner' @@ -277,13 +277,13 @@ describe('Test video channels', function () { await waitJobs(servers) for (const server of servers) { - const videoChannel = await server.channelsCommand.get({ channelName: 'second_video_channel@' + servers[0].host }) + const videoChannel = await server.channels.get({ channelName: 'second_video_channel@' + servers[0].host }) bannerPaths[server.port] = videoChannel.banner.path await testImage(server.url, 'banner-resized', bannerPaths[server.port]) await testFileExistsOrNot(server, 'avatars', basename(bannerPaths[server.port]), true) - const row = await server.sqlCommand.getActorImage(basename(bannerPaths[server.port])) + const row = await server.sql.getActorImage(basename(bannerPaths[server.port])) expect(row.height).to.equal(ACTOR_IMAGES_SIZE.BANNERS.height) expect(row.width).to.equal(ACTOR_IMAGES_SIZE.BANNERS.width) } @@ -292,7 +292,7 @@ describe('Test video channels', function () { it('Should delete the video channel avatar', async function () { this.timeout(15000) - await servers[0].channelsCommand.deleteImage({ channelName: 'second_video_channel', type: 'avatar' }) + await servers[0].channels.deleteImage({ channelName: 'second_video_channel', type: 'avatar' }) await waitJobs(servers) @@ -307,7 +307,7 @@ describe('Test video channels', function () { it('Should delete the video channel banner', async function () { this.timeout(15000) - await servers[0].channelsCommand.deleteImage({ channelName: 'second_video_channel', type: 'banner' }) + await servers[0].channels.deleteImage({ channelName: 'second_video_channel', type: 'banner' }) await waitJobs(servers) @@ -324,7 +324,7 @@ describe('Test video channels', function () { for (const server of servers) { const channelURI = 'second_video_channel@localhost:' + servers[0].port - const { total, data } = await server.videosCommand.listByChannel({ videoChannelName: channelURI }) + const { total, data } = await server.videos.listByChannel({ videoChannelName: channelURI }) expect(total).to.equal(1) expect(data).to.be.an('array') @@ -336,7 +336,7 @@ describe('Test video channels', function () { it('Should change the video channel of a video', async function () { this.timeout(10000) - await servers[0].videosCommand.update({ id: videoUUID, attributes: { channelId: servers[0].videoChannel.id } }) + await servers[0].videos.update({ id: videoUUID, attributes: { channelId: servers[0].store.channel.id } }) await waitJobs(servers) }) @@ -347,13 +347,13 @@ describe('Test video channels', function () { for (const server of servers) { { const secondChannelURI = 'second_video_channel@localhost:' + servers[0].port - const { total } = await server.videosCommand.listByChannel({ videoChannelName: secondChannelURI }) + const { total } = await server.videos.listByChannel({ videoChannelName: secondChannelURI }) expect(total).to.equal(0) } { const channelURI = 'root_channel@localhost:' + servers[0].port - const { total, data } = await server.videosCommand.listByChannel({ videoChannelName: channelURI }) + const { total, data } = await server.videos.listByChannel({ videoChannelName: channelURI }) expect(total).to.equal(1) expect(data).to.be.an('array') @@ -364,11 +364,11 @@ describe('Test video channels', function () { }) it('Should delete video channel', async function () { - await servers[0].channelsCommand.delete({ channelName: 'second_video_channel' }) + await servers[0].channels.delete({ channelName: 'second_video_channel' }) }) it('Should have video channel deleted', async function () { - const body = await servers[0].channelsCommand.list({ start: 0, count: 10 }) + const body = await servers[0].channels.list({ start: 0, count: 10 }) expect(body.total).to.equal(1) expect(body.data).to.be.an('array') @@ -379,15 +379,15 @@ describe('Test video channels', function () { it('Should create the main channel with an uuid if there is a conflict', async function () { { const videoChannel = { name: 'toto_channel', displayName: 'My toto channel' } - const created = await servers[0].channelsCommand.create({ attributes: videoChannel }) + const created = await servers[0].channels.create({ attributes: videoChannel }) totoChannel = created.id } { - await servers[0].usersCommand.create({ username: 'toto', password: 'password' }) - const accessToken = await servers[0].loginCommand.getAccessToken({ username: 'toto', password: 'password' }) + await servers[0].users.create({ username: 'toto', password: 'password' }) + const accessToken = await servers[0].login.getAccessToken({ username: 'toto', password: 'password' }) - const { videoChannels } = await servers[0].usersCommand.getMyInfo({ token: accessToken }) + const { videoChannels } = await servers[0].users.getMyInfo({ token: accessToken }) const videoChannel = videoChannels[0] expect(videoChannel.name).to.match(/[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}/) } @@ -397,7 +397,7 @@ describe('Test video channels', function () { this.timeout(10000) { - const { data } = await servers[0].channelsCommand.listByAccount({ accountName, withStats: true }) + const { data } = await servers[0].channels.listByAccount({ accountName, withStats: true }) for (const channel of data) { expect(channel).to.haveOwnProperty('viewsPerDay') @@ -411,21 +411,21 @@ describe('Test video channels', function () { } { - // video has been posted on channel servers[0].videoChannel.id since last update - await servers[0].videosCommand.view({ id: videoUUID, xForwardedFor: '0.0.0.1,127.0.0.1' }) - await servers[0].videosCommand.view({ id: videoUUID, xForwardedFor: '0.0.0.2,127.0.0.1' }) + // video has been posted on channel servers[0].store.videoChannel.id since last update + await servers[0].videos.view({ id: videoUUID, xForwardedFor: '0.0.0.1,127.0.0.1' }) + await servers[0].videos.view({ id: videoUUID, xForwardedFor: '0.0.0.2,127.0.0.1' }) // Wait the repeatable job await wait(8000) - const { data } = await servers[0].channelsCommand.listByAccount({ accountName, withStats: true }) - const channelWithView = data.find(channel => channel.id === servers[0].videoChannel.id) + const { data } = await servers[0].channels.listByAccount({ accountName, withStats: true }) + const channelWithView = data.find(channel => channel.id === servers[0].store.channel.id) expect(channelWithView.viewsPerDay.slice(-1)[0].views).to.equal(2) } }) it('Should report correct videos count', async function () { - const { data } = await servers[0].channelsCommand.listByAccount({ accountName, withStats: true }) + const { data } = await servers[0].channels.listByAccount({ accountName, withStats: true }) const totoChannel = data.find(c => c.name === 'toto_channel') const rootChannel = data.find(c => c.name === 'root_channel') @@ -436,7 +436,7 @@ describe('Test video channels', function () { it('Should search among account video channels', async function () { { - const body = await servers[0].channelsCommand.listByAccount({ accountName, search: 'root' }) + const body = await servers[0].channels.listByAccount({ accountName, search: 'root' }) expect(body.total).to.equal(1) const channels = body.data @@ -444,7 +444,7 @@ describe('Test video channels', function () { } { - const body = await servers[0].channelsCommand.listByAccount({ accountName, search: 'does not exist' }) + const body = await servers[0].channels.listByAccount({ accountName, search: 'does not exist' }) expect(body.total).to.equal(0) const channels = body.data @@ -455,21 +455,21 @@ describe('Test video channels', function () { it('Should list channels by updatedAt desc if a video has been uploaded', async function () { this.timeout(30000) - await servers[0].videosCommand.upload({ attributes: { channelId: totoChannel } }) + await servers[0].videos.upload({ attributes: { channelId: totoChannel } }) await waitJobs(servers) for (const server of servers) { - const { data } = await server.channelsCommand.listByAccount({ accountName, sort: '-updatedAt' }) + const { data } = await server.channels.listByAccount({ accountName, sort: '-updatedAt' }) expect(data[0].name).to.equal('toto_channel') expect(data[1].name).to.equal('root_channel') } - await servers[0].videosCommand.upload({ attributes: { channelId: servers[0].videoChannel.id } }) + await servers[0].videos.upload({ attributes: { channelId: servers[0].store.channel.id } }) await waitJobs(servers) for (const server of servers) { - const { data } = await server.channelsCommand.listByAccount({ accountName, sort: '-updatedAt' }) + const { data } = await server.channels.listByAccount({ accountName, sort: '-updatedAt' }) expect(data[0].name).to.equal('root_channel') expect(data[1].name).to.equal('toto_channel') diff --git a/server/tests/api/videos/video-comments.ts b/server/tests/api/videos/video-comments.ts index 41be54c81..adb59bd74 100644 --- a/server/tests/api/videos/video-comments.ts +++ b/server/tests/api/videos/video-comments.ts @@ -32,15 +32,15 @@ describe('Test video comments', function () { await setAccessTokensToServers([ server ]) - const { id, uuid } = await server.videosCommand.upload() + const { id, uuid } = await server.videos.upload() videoUUID = uuid videoId = id - await server.usersCommand.updateMyAvatar({ fixture: 'avatar.png' }) + await server.users.updateMyAvatar({ fixture: 'avatar.png' }) - userAccessTokenServer1 = await server.usersCommand.generateUserAndToken('user1') + userAccessTokenServer1 = await server.users.generateUserAndToken('user1') - command = server.commentsCommand + command = server.comments }) describe('User comments', function () { diff --git a/server/tests/api/videos/video-description.ts b/server/tests/api/videos/video-description.ts index 6ac9206f5..b89247288 100644 --- a/server/tests/api/videos/video-description.ts +++ b/server/tests/api/videos/video-description.ts @@ -31,11 +31,11 @@ describe('Test video description', function () { const attributes = { description: longDescription } - await servers[0].videosCommand.upload({ attributes }) + await servers[0].videos.upload({ attributes }) await waitJobs(servers) - const { data } = await servers[0].videosCommand.list() + const { data } = await servers[0].videos.list() videoId = data[0].id videoUUID = data[0].uuid @@ -43,7 +43,7 @@ describe('Test video description', function () { it('Should have a truncated description on each server', async function () { for (const server of servers) { - const video = await server.videosCommand.get({ id: videoUUID }) + const video = await server.videos.get({ id: videoUUID }) // 30 characters * 6 -> 240 characters const truncatedDescription = 'my super description for server 1'.repeat(7) + @@ -55,9 +55,9 @@ describe('Test video description', function () { it('Should fetch long description on each server', async function () { for (const server of servers) { - const video = await server.videosCommand.get({ id: videoUUID }) + const video = await server.videos.get({ id: videoUUID }) - const { description } = await server.videosCommand.getDescription({ descriptionPath: video.descriptionPath }) + const { description } = await server.videos.getDescription({ descriptionPath: video.descriptionPath }) expect(description).to.equal(longDescription) } }) @@ -68,18 +68,18 @@ describe('Test video description', function () { const attributes = { description: 'short description' } - await servers[0].videosCommand.update({ id: videoId, attributes }) + await servers[0].videos.update({ id: videoId, attributes }) await waitJobs(servers) }) it('Should have a small description on each server', async function () { for (const server of servers) { - const video = await server.videosCommand.get({ id: videoUUID }) + const video = await server.videos.get({ id: videoUUID }) expect(video.description).to.equal('short description') - const { description } = await server.videosCommand.getDescription({ descriptionPath: video.descriptionPath }) + const { description } = await server.videos.getDescription({ descriptionPath: video.descriptionPath }) expect(description).to.equal('short description') } }) diff --git a/server/tests/api/videos/video-hls.ts b/server/tests/api/videos/video-hls.ts index d63b81694..9d79f2683 100644 --- a/server/tests/api/videos/video-hls.ts +++ b/server/tests/api/videos/video-hls.ts @@ -25,7 +25,7 @@ const expect = chai.expect async function checkHlsPlaylist (servers: ServerInfo[], videoUUID: string, hlsOnly: boolean, resolutions = [ 240, 360, 480, 720 ]) { for (const server of servers) { - const videoDetails = await server.videosCommand.get({ id: videoUUID }) + const videoDetails = await server.videos.get({ id: videoUUID }) const baseUrl = `http://${videoDetails.account.host}` expect(videoDetails.streamingPlaylists).to.have.lengthOf(1) @@ -62,7 +62,7 @@ async function checkHlsPlaylist (servers: ServerInfo[], videoUUID: string, hlsOn { await checkResolutionsInMasterPlaylist({ server, playlistUrl: hlsPlaylist.playlistUrl, resolutions }) - const masterPlaylist = await server.streamingPlaylistsCommand.get({ url: hlsPlaylist.playlistUrl }) + const masterPlaylist = await server.streamingPlaylists.get({ url: hlsPlaylist.playlistUrl }) for (const resolution of resolutions) { expect(masterPlaylist).to.contain(`${resolution}.m3u8`) @@ -72,7 +72,7 @@ async function checkHlsPlaylist (servers: ServerInfo[], videoUUID: string, hlsOn { for (const resolution of resolutions) { - const subPlaylist = await server.streamingPlaylistsCommand.get({ + const subPlaylist = await server.streamingPlaylists.get({ url: `${baseUrl}/static/streaming-playlists/hls/${videoUUID}/${resolution}.m3u8` }) @@ -107,7 +107,7 @@ describe('Test HLS videos', function () { it('Should upload a video and transcode it to HLS', async function () { this.timeout(120000) - const { uuid } = await servers[0].videosCommand.upload({ attributes: { name: 'video 1', fixture: 'video_short.webm' } }) + const { uuid } = await servers[0].videos.upload({ attributes: { name: 'video 1', fixture: 'video_short.webm' } }) videoUUID = uuid await waitJobs(servers) @@ -118,7 +118,7 @@ describe('Test HLS videos', function () { it('Should upload an audio file and transcode it to HLS', async function () { this.timeout(120000) - const { uuid } = await servers[0].videosCommand.upload({ attributes: { name: 'video audio', fixture: 'sample.ogg' } }) + const { uuid } = await servers[0].videos.upload({ attributes: { name: 'video audio', fixture: 'sample.ogg' } }) videoAudioUUID = uuid await waitJobs(servers) @@ -129,7 +129,7 @@ describe('Test HLS videos', function () { it('Should update the video', async function () { this.timeout(10000) - await servers[0].videosCommand.update({ id: videoUUID, attributes: { name: 'video 1 updated' } }) + await servers[0].videos.update({ id: videoUUID, attributes: { name: 'video 1 updated' } }) await waitJobs(servers) @@ -139,14 +139,14 @@ describe('Test HLS videos', function () { it('Should delete videos', async function () { this.timeout(10000) - await servers[0].videosCommand.remove({ id: videoUUID }) - await servers[0].videosCommand.remove({ id: videoAudioUUID }) + await servers[0].videos.remove({ id: videoUUID }) + await servers[0].videos.remove({ id: videoAudioUUID }) await waitJobs(servers) for (const server of servers) { - await server.videosCommand.get({ id: videoUUID, expectedStatus: HttpStatusCode.NOT_FOUND_404 }) - await server.videosCommand.get({ id: videoAudioUUID, expectedStatus: HttpStatusCode.NOT_FOUND_404 }) + await server.videos.get({ id: videoUUID, expectedStatus: HttpStatusCode.NOT_FOUND_404 }) + await server.videos.get({ id: videoAudioUUID, expectedStatus: HttpStatusCode.NOT_FOUND_404 }) } }) @@ -192,7 +192,7 @@ describe('Test HLS videos', function () { describe('With only HLS enabled', function () { before(async function () { - await servers[0].configCommand.updateCustomSubConfig({ + await servers[0].config.updateCustomSubConfig({ newConfig: { transcoding: { enabled: true, diff --git a/server/tests/api/videos/video-imports.ts b/server/tests/api/videos/video-imports.ts index 31fdfe12e..8b6542aa4 100644 --- a/server/tests/api/videos/video-imports.ts +++ b/server/tests/api/videos/video-imports.ts @@ -26,7 +26,7 @@ describe('Test video imports', function () { if (areHttpImportTestsDisabled()) return async function checkVideosServer1 (server: ServerInfo, idHttp: string, idMagnet: string, idTorrent: string) { - const videoHttp = await server.videosCommand.get({ id: idHttp }) + const videoHttp = await server.videos.get({ id: idHttp }) expect(videoHttp.name).to.equal('small video - youtube') // FIXME: youtube-dl seems broken @@ -43,8 +43,8 @@ describe('Test video imports', function () { expect(originallyPublishedAt.getMonth()).to.equal(0) expect(originallyPublishedAt.getFullYear()).to.equal(2019) - const videoMagnet = await server.videosCommand.get({ id: idMagnet }) - const videoTorrent = await server.videosCommand.get({ id: idTorrent }) + const videoMagnet = await server.videos.get({ id: idMagnet }) + const videoTorrent = await server.videos.get({ id: idTorrent }) for (const video of [ videoMagnet, videoTorrent ]) { expect(video.category.label).to.equal('Misc') @@ -59,12 +59,12 @@ describe('Test video imports', function () { expect(videoTorrent.name).to.contain('你好 世界 720p.mp4') expect(videoMagnet.name).to.contain('super peertube2 video') - const bodyCaptions = await server.captionsCommand.listVideoCaptions({ videoId: idHttp }) + const bodyCaptions = await server.captions.listVideoCaptions({ videoId: idHttp }) expect(bodyCaptions.total).to.equal(2) } async function checkVideoServer2 (server: ServerInfo, id: number | string) { - const video = await server.videosCommand.get({ id }) + const video = await server.videos.get({ id }) expect(video.name).to.equal('my super name') expect(video.category.label).to.equal('Entertainment') @@ -76,7 +76,7 @@ describe('Test video imports', function () { expect(video.files).to.have.lengthOf(1) - const bodyCaptions = await server.captionsCommand.listVideoCaptions({ videoId: id }) + const bodyCaptions = await server.captions.listVideoCaptions({ videoId: id }) expect(bodyCaptions.total).to.equal(2) } @@ -89,12 +89,12 @@ describe('Test video imports', function () { await setAccessTokensToServers(servers) { - const { videoChannels } = await servers[0].usersCommand.getMyInfo() + const { videoChannels } = await servers[0].users.getMyInfo() channelIdServer1 = videoChannels[0].id } { - const { videoChannels } = await servers[1].usersCommand.getMyInfo() + const { videoChannels } = await servers[1].users.getMyInfo() channelIdServer2 = videoChannels[0].id } @@ -111,7 +111,7 @@ describe('Test video imports', function () { { const attributes = { ...baseAttributes, targetUrl: ImportsCommand.getYoutubeVideoUrl() } - const { video } = await servers[0].importsCommand.importVideo({ attributes }) + const { video } = await servers[0].imports.importVideo({ attributes }) expect(video.name).to.equal('small video - youtube') expect(video.thumbnailPath).to.match(new RegExp(`^/static/thumbnails/.+.jpg$`)) @@ -120,7 +120,7 @@ describe('Test video imports', function () { await testImage(servers[0].url, 'video_import_thumbnail', video.thumbnailPath) await testImage(servers[0].url, 'video_import_preview', video.previewPath) - const bodyCaptions = await servers[0].captionsCommand.listVideoCaptions({ videoId: video.id }) + const bodyCaptions = await servers[0].captions.listVideoCaptions({ videoId: video.id }) const videoCaptions = bodyCaptions.data expect(videoCaptions).to.have.lengthOf(2) @@ -166,7 +166,7 @@ Ajouter un sous-titre est vraiment facile`) description: 'this is a super torrent description', tags: [ 'tag_torrent1', 'tag_torrent2' ] } - const { video } = await servers[0].importsCommand.importVideo({ attributes }) + const { video } = await servers[0].imports.importVideo({ attributes }) expect(video.name).to.equal('super peertube2 video') } @@ -177,13 +177,13 @@ Ajouter un sous-titre est vraiment facile`) description: 'this is a super torrent description', tags: [ 'tag_torrent1', 'tag_torrent2' ] } - const { video } = await servers[0].importsCommand.importVideo({ attributes }) + const { video } = await servers[0].imports.importVideo({ attributes }) expect(video.name).to.equal('你好 世界 720p.mp4') } }) it('Should list the videos to import in my videos on server 1', async function () { - const { total, data } = await servers[0].videosCommand.listMyVideos({ sort: 'createdAt' }) + const { total, data } = await servers[0].videos.listMyVideos({ sort: 'createdAt' }) expect(total).to.equal(3) @@ -194,7 +194,7 @@ Ajouter un sous-titre est vraiment facile`) }) it('Should list the videos to import in my imports on server 1', async function () { - const { total, data: videoImports } = await servers[0].importsCommand.getMyVideoImports({ sort: '-createdAt' }) + const { total, data: videoImports } = await servers[0].imports.getMyVideoImports({ sort: '-createdAt' }) expect(total).to.equal(3) expect(videoImports).to.have.lengthOf(3) @@ -221,7 +221,7 @@ Ajouter un sous-titre est vraiment facile`) await waitJobs(servers) for (const server of servers) { - const { total, data } = await server.videosCommand.list() + const { total, data } = await server.videos.list() expect(total).to.equal(3) expect(data).to.have.lengthOf(3) @@ -244,7 +244,7 @@ Ajouter un sous-titre est vraiment facile`) description: 'my super description', tags: [ 'supertag1', 'supertag2' ] } - const { video } = await servers[1].importsCommand.importVideo({ attributes }) + const { video } = await servers[1].imports.importVideo({ attributes }) expect(video.name).to.equal('my super name') }) @@ -254,7 +254,7 @@ Ajouter un sous-titre est vraiment facile`) await waitJobs(servers) for (const server of servers) { - const { total, data } = await server.videosCommand.list() + const { total, data } = await server.videos.list() expect(total).to.equal(4) expect(data).to.have.lengthOf(4) @@ -274,13 +274,13 @@ Ajouter un sous-titre est vraiment facile`) channelId: channelIdServer2, privacy: VideoPrivacy.PUBLIC } - const { video } = await servers[1].importsCommand.importVideo({ attributes }) + const { video } = await servers[1].imports.importVideo({ attributes }) const videoUUID = video.uuid await waitJobs(servers) for (const server of servers) { - const video = await server.videosCommand.get({ id: videoUUID }) + const video = await server.videos.get({ id: videoUUID }) expect(video.name).to.equal('transcoded video') expect(video.files).to.have.lengthOf(4) @@ -316,7 +316,7 @@ Ajouter un sous-titre est vraiment facile`) } } } - await servers[0].configCommand.updateCustomSubConfig({ newConfig: config }) + await servers[0].config.updateCustomSubConfig({ newConfig: config }) const attributes = { name: 'hdr video', @@ -324,13 +324,13 @@ Ajouter un sous-titre est vraiment facile`) channelId: channelIdServer1, privacy: VideoPrivacy.PUBLIC } - const { video: videoImported } = await servers[0].importsCommand.importVideo({ attributes }) + const { video: videoImported } = await servers[0].imports.importVideo({ attributes }) const videoUUID = videoImported.uuid await waitJobs(servers) // test resolution - const video = await servers[0].videosCommand.get({ id: videoUUID }) + const video = await servers[0].videos.get({ id: videoUUID }) expect(video.name).to.equal('hdr video') const maxResolution = Math.max.apply(Math, video.files.map(function (o) { return o.resolution.id })) expect(maxResolution, 'expected max resolution not met').to.equals(VideoResolution.H_1080P) diff --git a/server/tests/api/videos/video-nsfw.ts b/server/tests/api/videos/video-nsfw.ts index b8fff096d..95395a582 100644 --- a/server/tests/api/videos/video-nsfw.ts +++ b/server/tests/api/videos/video-nsfw.ts @@ -18,7 +18,7 @@ describe('Test video NSFW policy', function () { let customConfig: CustomConfig async function getVideosFunctions (token?: string, query: { nsfw?: BooleanBothQuery } = {}) { - const user = await server.usersCommand.getMyInfo() + const user = await server.users.getMyInfo() const videoChannelName = user.videoChannels[0].name const accountName = user.account.name + '@' + user.account.host const hasQuery = Object.keys(query).length !== 0 @@ -26,15 +26,15 @@ describe('Test video NSFW policy', function () { if (token) { promises = [ - server.searchCommand.advancedVideoSearch({ token, search: { search: 'n', sort: '-publishedAt', ...query } }), - server.videosCommand.listWithToken({ token, ...query }), - server.videosCommand.listByAccount({ token, accountName, ...query }), - server.videosCommand.listByChannel({ token, videoChannelName, ...query }) + server.search.advancedVideoSearch({ token, search: { search: 'n', sort: '-publishedAt', ...query } }), + server.videos.listWithToken({ token, ...query }), + server.videos.listByAccount({ token, accountName, ...query }), + server.videos.listByChannel({ token, videoChannelName, ...query }) ] // Overviews do not support video filters if (!hasQuery) { - const p = server.overviewsCommand.getVideos({ page: 1, token }) + const p = server.overviews.getVideos({ page: 1, token }) .then(res => createOverviewRes(res)) promises.push(p) } @@ -43,15 +43,15 @@ describe('Test video NSFW policy', function () { } promises = [ - server.searchCommand.searchVideos({ search: 'n', sort: '-publishedAt' }), - server.videosCommand.list(), - server.videosCommand.listByAccount({ accountName }), - server.videosCommand.listByChannel({ videoChannelName }) + server.search.searchVideos({ search: 'n', sort: '-publishedAt' }), + server.videos.list(), + server.videos.listByAccount({ accountName }), + server.videos.listByChannel({ videoChannelName }) ] // Overviews do not support video filters if (!hasQuery) { - const p = server.overviewsCommand.getVideos({ page: 1 }) + const p = server.overviews.getVideos({ page: 1 }) .then(res => createOverviewRes(res)) promises.push(p) } @@ -68,20 +68,20 @@ describe('Test video NSFW policy', function () { { const attributes = { name: 'nsfw', nsfw: true, category: 1 } - await server.videosCommand.upload({ attributes }) + await server.videos.upload({ attributes }) } { const attributes = { name: 'normal', nsfw: false, category: 1 } - await server.videosCommand.upload({ attributes }) + await server.videos.upload({ attributes }) } - customConfig = await server.configCommand.getCustomConfig() + customConfig = await server.config.getCustomConfig() }) describe('Instance default NSFW policy', function () { it('Should display NSFW videos with display default NSFW policy', async function () { - const serverConfig = await server.configCommand.getConfig() + const serverConfig = await server.config.getConfig() expect(serverConfig.instance.defaultNSFWPolicy).to.equal('display') for (const body of await getVideosFunctions()) { @@ -96,9 +96,9 @@ describe('Test video NSFW policy', function () { it('Should not display NSFW videos with do_not_list default NSFW policy', async function () { customConfig.instance.defaultNSFWPolicy = 'do_not_list' - await server.configCommand.updateCustomConfig({ newCustomConfig: customConfig }) + await server.config.updateCustomConfig({ newCustomConfig: customConfig }) - const serverConfig = await server.configCommand.getConfig() + const serverConfig = await server.config.getConfig() expect(serverConfig.instance.defaultNSFWPolicy).to.equal('do_not_list') for (const body of await getVideosFunctions()) { @@ -112,9 +112,9 @@ describe('Test video NSFW policy', function () { it('Should display NSFW videos with blur default NSFW policy', async function () { customConfig.instance.defaultNSFWPolicy = 'blur' - await server.configCommand.updateCustomConfig({ newCustomConfig: customConfig }) + await server.config.updateCustomConfig({ newCustomConfig: customConfig }) - const serverConfig = await server.configCommand.getConfig() + const serverConfig = await server.config.getConfig() expect(serverConfig.instance.defaultNSFWPolicy).to.equal('blur') for (const body of await getVideosFunctions()) { @@ -133,17 +133,17 @@ describe('Test video NSFW policy', function () { it('Should create a user having the default nsfw policy', async function () { const username = 'user1' const password = 'my super password' - await server.usersCommand.create({ username: username, password: password }) + await server.users.create({ username: username, password: password }) - userAccessToken = await server.loginCommand.getAccessToken({ username, password }) + userAccessToken = await server.login.getAccessToken({ username, password }) - const user = await server.usersCommand.getMyInfo({ token: userAccessToken }) + const user = await server.users.getMyInfo({ token: userAccessToken }) expect(user.nsfwPolicy).to.equal('blur') }) it('Should display NSFW videos with blur user NSFW policy', async function () { customConfig.instance.defaultNSFWPolicy = 'do_not_list' - await server.configCommand.updateCustomConfig({ newCustomConfig: customConfig }) + await server.config.updateCustomConfig({ newCustomConfig: customConfig }) for (const body of await getVideosFunctions(userAccessToken)) { expect(body.total).to.equal(2) @@ -156,7 +156,7 @@ describe('Test video NSFW policy', function () { }) it('Should display NSFW videos with display user NSFW policy', async function () { - await server.usersCommand.updateMe({ nsfwPolicy: 'display' }) + await server.users.updateMe({ nsfwPolicy: 'display' }) for (const body of await getVideosFunctions(server.accessToken)) { expect(body.total).to.equal(2) @@ -169,7 +169,7 @@ describe('Test video NSFW policy', function () { }) it('Should not display NSFW videos with do_not_list user NSFW policy', async function () { - await server.usersCommand.updateMe({ nsfwPolicy: 'do_not_list' }) + await server.users.updateMe({ nsfwPolicy: 'do_not_list' }) for (const body of await getVideosFunctions(server.accessToken)) { expect(body.total).to.equal(1) @@ -181,7 +181,7 @@ describe('Test video NSFW policy', function () { }) it('Should be able to see my NSFW videos even with do_not_list user NSFW policy', async function () { - const { total, data } = await server.videosCommand.listMyVideos() + const { total, data } = await server.videos.listMyVideos() expect(total).to.equal(2) expect(data).to.have.lengthOf(2) diff --git a/server/tests/api/videos/video-playlist-thumbnails.ts b/server/tests/api/videos/video-playlist-thumbnails.ts index 14739af20..709f64c4d 100644 --- a/server/tests/api/videos/video-playlist-thumbnails.ts +++ b/server/tests/api/videos/video-playlist-thumbnails.ts @@ -31,13 +31,13 @@ describe('Playlist thumbnail', function () { let video2: number async function getPlaylistWithoutThumbnail (server: ServerInfo) { - const body = await server.playlistsCommand.list({ start: 0, count: 10 }) + const body = await server.playlists.list({ start: 0, count: 10 }) return body.data.find(p => p.displayName === 'playlist without thumbnail') } async function getPlaylistWithThumbnail (server: ServerInfo) { - const body = await server.playlistsCommand.list({ start: 0, count: 10 }) + const body = await server.playlists.list({ start: 0, count: 10 }) return body.data.find(p => p.displayName === 'playlist with thumbnail') } @@ -54,8 +54,8 @@ describe('Playlist thumbnail', function () { // Server 1 and server 2 follow each other await doubleFollow(servers[0], servers[1]) - video1 = (await servers[0].videosCommand.quickUpload({ name: 'video 1' })).id - video2 = (await servers[0].videosCommand.quickUpload({ name: 'video 2' })).id + video1 = (await servers[0].videos.quickUpload({ name: 'video 1' })).id + video2 = (await servers[0].videos.quickUpload({ name: 'video 2' })).id await waitJobs(servers) }) @@ -63,16 +63,16 @@ describe('Playlist thumbnail', function () { it('Should automatically update the thumbnail when adding an element', async function () { this.timeout(30000) - const created = await servers[1].playlistsCommand.create({ + const created = await servers[1].playlists.create({ attributes: { displayName: 'playlist without thumbnail', privacy: VideoPlaylistPrivacy.PUBLIC, - videoChannelId: servers[1].videoChannel.id + videoChannelId: servers[1].store.channel.id } }) playlistWithoutThumbnailId = created.id - const added = await servers[1].playlistsCommand.addElement({ + const added = await servers[1].playlists.addElement({ playlistId: playlistWithoutThumbnailId, attributes: { videoId: video1 } }) @@ -89,17 +89,17 @@ describe('Playlist thumbnail', function () { it('Should not update the thumbnail if we explicitly uploaded a thumbnail', async function () { this.timeout(30000) - const created = await servers[1].playlistsCommand.create({ + const created = await servers[1].playlists.create({ attributes: { displayName: 'playlist with thumbnail', privacy: VideoPlaylistPrivacy.PUBLIC, - videoChannelId: servers[1].videoChannel.id, + videoChannelId: servers[1].store.channel.id, thumbnailfile: 'thumbnail.jpg' } }) playlistWithThumbnailId = created.id - const added = await servers[1].playlistsCommand.addElement({ + const added = await servers[1].playlists.addElement({ playlistId: playlistWithThumbnailId, attributes: { videoId: video1 } }) @@ -116,13 +116,13 @@ describe('Playlist thumbnail', function () { it('Should automatically update the thumbnail when moving the first element', async function () { this.timeout(30000) - const added = await servers[1].playlistsCommand.addElement({ + const added = await servers[1].playlists.addElement({ playlistId: playlistWithoutThumbnailId, attributes: { videoId: video2 } }) withoutThumbnailE2 = added.id - await servers[1].playlistsCommand.reorderElements({ + await servers[1].playlists.reorderElements({ playlistId: playlistWithoutThumbnailId, attributes: { startPosition: 1, @@ -141,13 +141,13 @@ describe('Playlist thumbnail', function () { it('Should not update the thumbnail when moving the first element if we explicitly uploaded a thumbnail', async function () { this.timeout(30000) - const added = await servers[1].playlistsCommand.addElement({ + const added = await servers[1].playlists.addElement({ playlistId: playlistWithThumbnailId, attributes: { videoId: video2 } }) withThumbnailE2 = added.id - await servers[1].playlistsCommand.reorderElements({ + await servers[1].playlists.reorderElements({ playlistId: playlistWithThumbnailId, attributes: { startPosition: 1, @@ -166,7 +166,7 @@ describe('Playlist thumbnail', function () { it('Should automatically update the thumbnail when deleting the first element', async function () { this.timeout(30000) - await servers[1].playlistsCommand.removeElement({ + await servers[1].playlists.removeElement({ playlistId: playlistWithoutThumbnailId, elementId: withoutThumbnailE1 }) @@ -182,7 +182,7 @@ describe('Playlist thumbnail', function () { it('Should not update the thumbnail when deleting the first element if we explicitly uploaded a thumbnail', async function () { this.timeout(30000) - await servers[1].playlistsCommand.removeElement({ + await servers[1].playlists.removeElement({ playlistId: playlistWithThumbnailId, elementId: withThumbnailE1 }) @@ -198,7 +198,7 @@ describe('Playlist thumbnail', function () { it('Should the thumbnail when we delete the last element', async function () { this.timeout(30000) - await servers[1].playlistsCommand.removeElement({ + await servers[1].playlists.removeElement({ playlistId: playlistWithoutThumbnailId, elementId: withoutThumbnailE2 }) @@ -214,7 +214,7 @@ describe('Playlist thumbnail', function () { it('Should not update the thumbnail when we delete the last element if we explicitly uploaded a thumbnail', async function () { this.timeout(30000) - await servers[1].playlistsCommand.removeElement({ + await servers[1].playlists.removeElement({ playlistId: playlistWithThumbnailId, elementId: withThumbnailE2 }) diff --git a/server/tests/api/videos/video-playlists.ts b/server/tests/api/videos/video-playlists.ts index 40f61ca19..0dc53d4c0 100644 --- a/server/tests/api/videos/video-playlists.ts +++ b/server/tests/api/videos/video-playlists.ts @@ -36,7 +36,7 @@ async function checkPlaylistElementType ( total: number ) { for (const server of servers) { - const body = await server.playlistsCommand.listVideos({ token: server.accessToken, playlistId, start: 0, count: 10 }) + const body = await server.playlists.listVideos({ token: server.accessToken, playlistId, start: 0, count: 10 }) expect(body.total).to.equal(total) const videoElement = body.data.find(e => e.position === position) @@ -86,26 +86,26 @@ describe('Test video playlists', function () { // Server 1 and server 3 follow each other await doubleFollow(servers[0], servers[2]) - commands = servers.map(s => s.playlistsCommand) + commands = servers.map(s => s.playlists) { - servers[0].videos = [] - servers[1].videos = [] - servers[2].videos = [] + servers[0].store.videos = [] + servers[1].store.videos = [] + servers[2].store.videos = [] for (const server of servers) { for (let i = 0; i < 7; i++) { const name = `video ${i} server ${server.serverNumber}` - const video = await server.videosCommand.upload({ attributes: { name, nsfw: false } }) + const video = await server.videos.upload({ attributes: { name, nsfw: false } }) - server.videos.push(video) + server.store.videos.push(video) } } } - nsfwVideoServer1 = (await servers[0].videosCommand.quickUpload({ name: 'NSFW video', nsfw: true })).id + nsfwVideoServer1 = (await servers[0].videos.quickUpload({ name: 'NSFW video', nsfw: true })).id - userTokenServer1 = await servers[0].usersCommand.generateUserAndToken('user1') + userTokenServer1 = await servers[0].users.generateUserAndToken('user1') await waitJobs(servers) }) @@ -149,7 +149,7 @@ describe('Test video playlists', function () { }) it('Should get private playlist for a classic user', async function () { - const token = await servers[0].usersCommand.generateUserAndToken('toto') + const token = await servers[0].users.generateUserAndToken('toto') const body = await commands[0].listByAccount({ token, handle: 'toto' }) @@ -172,7 +172,7 @@ describe('Test video playlists', function () { privacy: VideoPlaylistPrivacy.PUBLIC, description: 'my super description', thumbnailfile: 'thumbnail.jpg', - videoChannelId: servers[0].videoChannel.id + videoChannelId: servers[0].store.channel.id } }) @@ -181,13 +181,13 @@ describe('Test video playlists', function () { await wait(3000) for (const server of servers) { - const body = await server.playlistsCommand.list({ start: 0, count: 5 }) + const body = await server.playlists.list({ start: 0, count: 5 }) expect(body.total).to.equal(1) expect(body.data).to.have.lengthOf(1) const playlistFromList = body.data[0] - const playlistFromGet = await server.playlistsCommand.get({ playlistId: playlistFromList.uuid }) + const playlistFromGet = await server.playlists.get({ playlistId: playlistFromList.uuid }) for (const playlist of [ playlistFromGet, playlistFromList ]) { expect(playlist.id).to.be.a('number') @@ -217,23 +217,23 @@ describe('Test video playlists', function () { this.timeout(30000) { - const playlist = await servers[1].playlistsCommand.create({ + const playlist = await servers[1].playlists.create({ attributes: { displayName: 'playlist 2', privacy: VideoPlaylistPrivacy.PUBLIC, - videoChannelId: servers[1].videoChannel.id + videoChannelId: servers[1].store.channel.id } }) playlistServer2Id1 = playlist.id } { - const playlist = await servers[1].playlistsCommand.create({ + const playlist = await servers[1].playlists.create({ attributes: { displayName: 'playlist 3', privacy: VideoPlaylistPrivacy.PUBLIC, thumbnailfile: 'thumbnail.jpg', - videoChannelId: servers[1].videoChannel.id + videoChannelId: servers[1].store.channel.id } }) @@ -242,13 +242,13 @@ describe('Test video playlists', function () { } for (const id of [ playlistServer2Id1, playlistServer2Id2 ]) { - await servers[1].playlistsCommand.addElement({ + await servers[1].playlists.addElement({ playlistId: id, - attributes: { videoId: servers[1].videos[0].id, startTimestamp: 1, stopTimestamp: 2 } + attributes: { videoId: servers[1].store.videos[0].id, startTimestamp: 1, stopTimestamp: 2 } }) - await servers[1].playlistsCommand.addElement({ + await servers[1].playlists.addElement({ playlistId: id, - attributes: { videoId: servers[1].videos[1].id } + attributes: { videoId: servers[1].store.videos[1].id } }) } @@ -256,7 +256,7 @@ describe('Test video playlists', function () { await wait(3000) for (const server of [ servers[0], servers[1] ]) { - const body = await server.playlistsCommand.list({ start: 0, count: 5 }) + const body = await server.playlists.list({ start: 0, count: 5 }) const playlist2 = body.data.find(p => p.displayName === 'playlist 2') expect(playlist2).to.not.be.undefined @@ -267,7 +267,7 @@ describe('Test video playlists', function () { await testImage(server.url, 'thumbnail', playlist3.thumbnailPath) } - const body = await servers[2].playlistsCommand.list({ start: 0, count: 5 }) + const body = await servers[2].playlists.list({ start: 0, count: 5 }) expect(body.data.find(p => p.displayName === 'playlist 2')).to.be.undefined expect(body.data.find(p => p.displayName === 'playlist 3')).to.be.undefined }) @@ -278,7 +278,7 @@ describe('Test video playlists', function () { // Server 2 and server 3 follow each other await doubleFollow(servers[1], servers[2]) - const body = await servers[2].playlistsCommand.list({ start: 0, count: 5 }) + const body = await servers[2].playlists.list({ start: 0, count: 5 }) const playlist2 = body.data.find(p => p.displayName === 'playlist 2') expect(playlist2).to.not.be.undefined @@ -294,7 +294,7 @@ describe('Test video playlists', function () { this.timeout(30000) { - const body = await servers[2].playlistsCommand.list({ start: 1, count: 2, sort: 'createdAt' }) + const body = await servers[2].playlists.list({ start: 1, count: 2, sort: 'createdAt' }) expect(body.total).to.equal(3) const data = body.data @@ -304,7 +304,7 @@ describe('Test video playlists', function () { } { - const body = await servers[2].playlistsCommand.list({ start: 1, count: 2, sort: '-createdAt' }) + const body = await servers[2].playlists.list({ start: 1, count: 2, sort: '-createdAt' }) expect(body.total).to.equal(3) const data = body.data @@ -331,7 +331,7 @@ describe('Test video playlists', function () { this.timeout(30000) { - const body = await servers[1].playlistsCommand.listByAccount({ handle: 'root', start: 1, count: 2, sort: '-createdAt' }) + const body = await servers[1].playlists.listByAccount({ handle: 'root', start: 1, count: 2, sort: '-createdAt' }) expect(body.total).to.equal(2) const data = body.data @@ -340,7 +340,7 @@ describe('Test video playlists', function () { } { - const body = await servers[1].playlistsCommand.listByAccount({ handle: 'root', start: 1, count: 2, sort: 'createdAt' }) + const body = await servers[1].playlists.listByAccount({ handle: 'root', start: 1, count: 2, sort: 'createdAt' }) expect(body.total).to.equal(2) const data = body.data @@ -349,7 +349,7 @@ describe('Test video playlists', function () { } { - const body = await servers[1].playlistsCommand.listByAccount({ handle: 'root', sort: 'createdAt', search: '3' }) + const body = await servers[1].playlists.listByAccount({ handle: 'root', sort: 'createdAt', search: '3' }) expect(body.total).to.equal(1) const data = body.data @@ -358,7 +358,7 @@ describe('Test video playlists', function () { } { - const body = await servers[1].playlistsCommand.listByAccount({ handle: 'root', sort: 'createdAt', search: '4' }) + const body = await servers[1].playlists.listByAccount({ handle: 'root', sort: 'createdAt', search: '4' }) expect(body.total).to.equal(0) const data = body.data @@ -375,17 +375,17 @@ describe('Test video playlists', function () { this.timeout(30000) { - unlistedPlaylist = await servers[1].playlistsCommand.create({ + unlistedPlaylist = await servers[1].playlists.create({ attributes: { displayName: 'playlist unlisted', privacy: VideoPlaylistPrivacy.UNLISTED, - videoChannelId: servers[1].videoChannel.id + videoChannelId: servers[1].store.channel.id } }) } { - privatePlaylist = await servers[1].playlistsCommand.create({ + privatePlaylist = await servers[1].playlists.create({ attributes: { displayName: 'playlist private', privacy: VideoPlaylistPrivacy.PRIVATE @@ -400,8 +400,8 @@ describe('Test video playlists', function () { it('Should not list unlisted or private playlists', async function () { for (const server of servers) { const results = [ - await server.playlistsCommand.listByAccount({ handle: 'root@localhost:' + servers[1].port, sort: '-createdAt' }), - await server.playlistsCommand.list({ start: 0, count: 2, sort: '-createdAt' }) + await server.playlists.listByAccount({ handle: 'root@localhost:' + servers[1].port, sort: '-createdAt' }), + await server.playlists.list({ start: 0, count: 2, sort: '-createdAt' }) ] expect(results[0].total).to.equal(2) @@ -417,23 +417,23 @@ describe('Test video playlists', function () { }) it('Should not get unlisted playlist using only the id', async function () { - await servers[1].playlistsCommand.get({ playlistId: unlistedPlaylist.id, expectedStatus: 404 }) + await servers[1].playlists.get({ playlistId: unlistedPlaylist.id, expectedStatus: 404 }) }) it('Should get unlisted plyaylist using uuid or shortUUID', async function () { - await servers[1].playlistsCommand.get({ playlistId: unlistedPlaylist.uuid }) - await servers[1].playlistsCommand.get({ playlistId: unlistedPlaylist.shortUUID }) + await servers[1].playlists.get({ playlistId: unlistedPlaylist.uuid }) + await servers[1].playlists.get({ playlistId: unlistedPlaylist.shortUUID }) }) it('Should not get private playlist without token', async function () { for (const id of [ privatePlaylist.id, privatePlaylist.uuid, privatePlaylist.shortUUID ]) { - await servers[1].playlistsCommand.get({ playlistId: id, expectedStatus: 401 }) + await servers[1].playlists.get({ playlistId: id, expectedStatus: 401 }) } }) it('Should get private playlist with a token', async function () { for (const id of [ privatePlaylist.id, privatePlaylist.uuid, privatePlaylist.shortUUID ]) { - await servers[1].playlistsCommand.get({ token: servers[1].accessToken, playlistId: id }) + await servers[1].playlists.get({ token: servers[1].accessToken, playlistId: id }) } }) }) @@ -443,13 +443,13 @@ describe('Test video playlists', function () { it('Should update a playlist', async function () { this.timeout(30000) - await servers[1].playlistsCommand.update({ + await servers[1].playlists.update({ attributes: { displayName: 'playlist 3 updated', description: 'description updated', privacy: VideoPlaylistPrivacy.UNLISTED, thumbnailfile: 'thumbnail.jpg', - videoChannelId: servers[1].videoChannel.id + videoChannelId: servers[1].store.channel.id }, playlistId: playlistServer2Id2 }) @@ -457,7 +457,7 @@ describe('Test video playlists', function () { await waitJobs(servers) for (const server of servers) { - const playlist = await server.playlistsCommand.get({ playlistId: playlistServer2UUID2 }) + const playlist = await server.playlists.get({ playlistId: playlistServer2UUID2 }) expect(playlist.displayName).to.equal('playlist 3 updated') expect(playlist.description).to.equal('description updated') @@ -491,23 +491,23 @@ describe('Test video playlists', function () { attributes: { displayName: 'playlist 4', privacy: VideoPlaylistPrivacy.PUBLIC, - videoChannelId: servers[0].videoChannel.id + videoChannelId: servers[0].store.channel.id } }) playlistServer1Id = playlist.id playlistServer1UUID = playlist.uuid - await addVideo({ videoId: servers[0].videos[0].uuid, startTimestamp: 15, stopTimestamp: 28 }) - await addVideo({ videoId: servers[2].videos[1].uuid, startTimestamp: 35 }) - await addVideo({ videoId: servers[2].videos[2].uuid }) + await addVideo({ videoId: servers[0].store.videos[0].uuid, startTimestamp: 15, stopTimestamp: 28 }) + await addVideo({ videoId: servers[2].store.videos[1].uuid, startTimestamp: 35 }) + await addVideo({ videoId: servers[2].store.videos[2].uuid }) { - const element = await addVideo({ videoId: servers[0].videos[3].uuid, stopTimestamp: 35 }) + const element = await addVideo({ videoId: servers[0].store.videos[3].uuid, stopTimestamp: 35 }) playlistElementServer1Video4 = element.id } { - const element = await addVideo({ videoId: servers[0].videos[4].uuid, startTimestamp: 45, stopTimestamp: 60 }) + const element = await addVideo({ videoId: servers[0].store.videos[4].uuid, startTimestamp: 45, stopTimestamp: 60 }) playlistElementServer1Video5 = element.id } @@ -527,7 +527,7 @@ describe('Test video playlists', function () { for (const server of servers) { { - const body = await server.playlistsCommand.listVideos({ playlistId: playlistServer1UUID, start: 0, count: 10 }) + const body = await server.playlists.listVideos({ playlistId: playlistServer1UUID, start: 0, count: 10 }) expect(body.total).to.equal(8) @@ -576,7 +576,7 @@ describe('Test video playlists', function () { } { - const body = await server.playlistsCommand.listVideos({ playlistId: playlistServer1UUID, start: 0, count: 2 }) + const body = await server.playlists.listVideos({ playlistId: playlistServer1UUID, start: 0, count: 2 }) expect(body.data).to.have.lengthOf(2) } } @@ -606,7 +606,7 @@ describe('Test video playlists', function () { attributes: { displayName: 'playlist 56', privacy: VideoPlaylistPrivacy.PUBLIC, - videoChannelId: servers[0].videoChannel.id + videoChannelId: servers[0].store.channel.id } }) @@ -617,9 +617,9 @@ describe('Test video playlists', function () { return commands[0].addElement({ token: userTokenServer1, playlistId: playlistServer1Id2, attributes }) } - video1 = (await servers[0].videosCommand.quickUpload({ name: 'video 89', token: userTokenServer1 })).uuid - video2 = (await servers[1].videosCommand.quickUpload({ name: 'video 90' })).uuid - video3 = (await servers[0].videosCommand.quickUpload({ name: 'video 91', nsfw: true })).uuid + video1 = (await servers[0].videos.quickUpload({ name: 'video 89', token: userTokenServer1 })).uuid + video2 = (await servers[1].videos.quickUpload({ name: 'video 90' })).uuid + video3 = (await servers[0].videos.quickUpload({ name: 'video 91', nsfw: true })).uuid await waitJobs(servers) @@ -637,7 +637,7 @@ describe('Test video playlists', function () { const position = 1 { - await servers[0].videosCommand.update({ id: video1, attributes: { privacy: VideoPrivacy.PRIVATE } }) + await servers[0].videos.update({ id: video1, attributes: { privacy: VideoPrivacy.PRIVATE } }) await waitJobs(servers) await checkPlaylistElementType(groupUser1, playlistServer1UUID2, VideoPlaylistElementType.REGULAR, position, name, 3) @@ -647,7 +647,7 @@ describe('Test video playlists', function () { } { - await servers[0].videosCommand.update({ id: video1, attributes: { privacy: VideoPrivacy.PUBLIC } }) + await servers[0].videos.update({ id: video1, attributes: { privacy: VideoPrivacy.PUBLIC } }) await waitJobs(servers) await checkPlaylistElementType(groupUser1, playlistServer1UUID2, VideoPlaylistElementType.REGULAR, position, name, 3) @@ -665,7 +665,7 @@ describe('Test video playlists', function () { const position = 1 { - await servers[0].blacklistCommand.add({ videoId: video1, reason: 'reason', unfederate: true }) + await servers[0].blacklist.add({ videoId: video1, reason: 'reason', unfederate: true }) await waitJobs(servers) await checkPlaylistElementType(groupUser1, playlistServer1UUID2, VideoPlaylistElementType.REGULAR, position, name, 3) @@ -675,7 +675,7 @@ describe('Test video playlists', function () { } { - await servers[0].blacklistCommand.remove({ videoId: video1 }) + await servers[0].blacklist.remove({ videoId: video1 }) await waitJobs(servers) await checkPlaylistElementType(groupUser1, playlistServer1UUID2, VideoPlaylistElementType.REGULAR, position, name, 3) @@ -689,7 +689,7 @@ describe('Test video playlists', function () { it('Should update the element type if the account or server of the video is blocked', async function () { this.timeout(90000) - const command = servers[0].blocklistCommand + const command = servers[0].blocklist const name = 'video 90' const position = 2 @@ -778,7 +778,7 @@ describe('Test video playlists', function () { await waitJobs(servers) for (const server of servers) { - const body = await server.playlistsCommand.listVideos({ playlistId: playlistServer1UUID, start: 0, count: 10 }) + const body = await server.playlists.listVideos({ playlistId: playlistServer1UUID, start: 0, count: 10 }) const names = body.data.map(v => v.video.name) expect(names).to.deep.equal([ @@ -807,7 +807,7 @@ describe('Test video playlists', function () { await waitJobs(servers) for (const server of servers) { - const body = await server.playlistsCommand.listVideos({ playlistId: playlistServer1UUID, start: 0, count: 10 }) + const body = await server.playlists.listVideos({ playlistId: playlistServer1UUID, start: 0, count: 10 }) const names = body.data.map(v => v.video.name) expect(names).to.deep.equal([ @@ -835,7 +835,7 @@ describe('Test video playlists', function () { await waitJobs(servers) for (const server of servers) { - const { data: elements } = await server.playlistsCommand.listVideos({ playlistId: playlistServer1UUID, start: 0, count: 10 }) + const { data: elements } = await server.playlists.listVideos({ playlistId: playlistServer1UUID, start: 0, count: 10 }) const names = elements.map(v => v.video.name) expect(names).to.deep.equal([ @@ -878,7 +878,7 @@ describe('Test video playlists', function () { await waitJobs(servers) for (const server of servers) { - const { data: elements } = await server.playlistsCommand.listVideos({ playlistId: playlistServer1UUID, start: 0, count: 10 }) + const { data: elements } = await server.playlists.listVideos({ playlistId: playlistServer1UUID, start: 0, count: 10 }) expect(elements[0].video.name).to.equal('video 3 server 1') expect(elements[0].position).to.equal(1) @@ -894,16 +894,16 @@ describe('Test video playlists', function () { it('Should check videos existence in my playlist', async function () { const videoIds = [ - servers[0].videos[0].id, + servers[0].store.videos[0].id, 42000, - servers[0].videos[3].id, + servers[0].store.videos[3].id, 43000, - servers[0].videos[4].id + servers[0].store.videos[4].id ] const obj = await commands[0].videosExist({ videoIds }) { - const elem = obj[servers[0].videos[0].id] + const elem = obj[servers[0].store.videos[0].id] expect(elem).to.have.lengthOf(1) expect(elem[0].playlistElementId).to.exist expect(elem[0].playlistId).to.equal(playlistServer1Id) @@ -912,7 +912,7 @@ describe('Test video playlists', function () { } { - const elem = obj[servers[0].videos[3].id] + const elem = obj[servers[0].store.videos[3].id] expect(elem).to.have.lengthOf(1) expect(elem[0].playlistElementId).to.equal(playlistElementServer1Video4) expect(elem[0].playlistId).to.equal(playlistServer1Id) @@ -921,7 +921,7 @@ describe('Test video playlists', function () { } { - const elem = obj[servers[0].videos[4].id] + const elem = obj[servers[0].store.videos[4].id] expect(elem).to.have.lengthOf(1) expect(elem[0].playlistId).to.equal(playlistServer1Id) expect(elem[0].startTimestamp).to.equal(45) @@ -934,29 +934,29 @@ describe('Test video playlists', function () { it('Should automatically update updatedAt field of playlists', async function () { const server = servers[1] - const videoId = servers[1].videos[5].id + const videoId = servers[1].store.videos[5].id async function getPlaylistNames () { - const { data } = await server.playlistsCommand.listByAccount({ token: server.accessToken, handle: 'root', sort: '-updatedAt' }) + const { data } = await server.playlists.listByAccount({ token: server.accessToken, handle: 'root', sort: '-updatedAt' }) return data.map(p => p.displayName) } const attributes = { videoId } - const element1 = await server.playlistsCommand.addElement({ playlistId: playlistServer2Id1, attributes }) - const element2 = await server.playlistsCommand.addElement({ playlistId: playlistServer2Id2, attributes }) + const element1 = await server.playlists.addElement({ playlistId: playlistServer2Id1, attributes }) + const element2 = await server.playlists.addElement({ playlistId: playlistServer2Id2, attributes }) const names1 = await getPlaylistNames() expect(names1[0]).to.equal('playlist 3 updated') expect(names1[1]).to.equal('playlist 2') - await server.playlistsCommand.removeElement({ playlistId: playlistServer2Id1, elementId: element1.id }) + await server.playlists.removeElement({ playlistId: playlistServer2Id1, elementId: element1.id }) const names2 = await getPlaylistNames() expect(names2[0]).to.equal('playlist 2') expect(names2[1]).to.equal('playlist 3 updated') - await server.playlistsCommand.removeElement({ playlistId: playlistServer2Id2, elementId: element2.id }) + await server.playlists.removeElement({ playlistId: playlistServer2Id2, elementId: element2.id }) const names3 = await getPlaylistNames() expect(names3[0]).to.equal('playlist 3 updated') @@ -972,7 +972,7 @@ describe('Test video playlists', function () { await waitJobs(servers) for (const server of servers) { - const body = await server.playlistsCommand.listVideos({ playlistId: playlistServer1UUID, start: 0, count: 10 }) + const body = await server.playlists.listVideos({ playlistId: playlistServer1UUID, start: 0, count: 10 }) expect(body.total).to.equal(6) const elements = body.data @@ -1005,14 +1005,14 @@ describe('Test video playlists', function () { attributes: { displayName: 'my super public playlist', privacy: VideoPlaylistPrivacy.PUBLIC, - videoChannelId: servers[0].videoChannel.id + videoChannelId: servers[0].store.channel.id } }) await waitJobs(servers) for (const server of servers) { - await server.playlistsCommand.get({ playlistId: videoPlaylistIds.uuid, expectedStatus: HttpStatusCode.OK_200 }) + await server.playlists.get({ playlistId: videoPlaylistIds.uuid, expectedStatus: HttpStatusCode.OK_200 }) } const attributes = { privacy: VideoPlaylistPrivacy.PRIVATE } @@ -1021,7 +1021,7 @@ describe('Test video playlists', function () { await waitJobs(servers) for (const server of [ servers[1], servers[2] ]) { - await server.playlistsCommand.get({ playlistId: videoPlaylistIds.uuid, expectedStatus: HttpStatusCode.NOT_FOUND_404 }) + await server.playlists.get({ playlistId: videoPlaylistIds.uuid, expectedStatus: HttpStatusCode.NOT_FOUND_404 }) } await commands[0].get({ playlistId: videoPlaylistIds.uuid, expectedStatus: HttpStatusCode.UNAUTHORIZED_401 }) @@ -1039,7 +1039,7 @@ describe('Test video playlists', function () { await waitJobs(servers) for (const server of servers) { - await server.playlistsCommand.get({ playlistId: playlistServer1UUID, expectedStatus: HttpStatusCode.NOT_FOUND_404 }) + await server.playlists.get({ playlistId: playlistServer1UUID, expectedStatus: HttpStatusCode.NOT_FOUND_404 }) } }) @@ -1057,16 +1057,16 @@ describe('Test video playlists', function () { const finder = (data: VideoPlaylist[]) => data.find(p => p.displayName === 'my super playlist') { - const body = await servers[2].playlistsCommand.list({ start: 0, count: 5 }) + const body = await servers[2].playlists.list({ start: 0, count: 5 }) expect(body.total).to.equal(3) expect(finder(body.data)).to.not.be.undefined } - await servers[2].followsCommand.unfollow({ target: servers[0] }) + await servers[2].follows.unfollow({ target: servers[0] }) { - const body = await servers[2].playlistsCommand.list({ start: 0, count: 5 }) + const body = await servers[2].playlists.list({ start: 0, count: 5 }) expect(body.total).to.equal(1) expect(finder(body.data)).to.be.undefined @@ -1076,7 +1076,7 @@ describe('Test video playlists', function () { it('Should delete a channel and put the associated playlist in private mode', async function () { this.timeout(30000) - const channel = await servers[0].channelsCommand.create({ attributes: { name: 'super_channel', displayName: 'super channel' } }) + const channel = await servers[0].channels.create({ attributes: { name: 'super_channel', displayName: 'super channel' } }) const playlistCreated = await commands[0].create({ attributes: { @@ -1088,7 +1088,7 @@ describe('Test video playlists', function () { await waitJobs(servers) - await servers[0].channelsCommand.delete({ channelName: 'super_channel' }) + await servers[0].channels.delete({ channelName: 'super_channel' }) await waitJobs(servers) @@ -1096,15 +1096,15 @@ describe('Test video playlists', function () { expect(body.displayName).to.equal('channel playlist') expect(body.privacy.id).to.equal(VideoPlaylistPrivacy.PRIVATE) - await servers[1].playlistsCommand.get({ playlistId: playlistCreated.uuid, expectedStatus: HttpStatusCode.NOT_FOUND_404 }) + await servers[1].playlists.get({ playlistId: playlistCreated.uuid, expectedStatus: HttpStatusCode.NOT_FOUND_404 }) }) it('Should delete an account and delete its playlists', async function () { this.timeout(30000) - const { userId, token } = await servers[0].usersCommand.generate('user_1') + const { userId, token } = await servers[0].users.generate('user_1') - const { videoChannels } = await servers[0].usersCommand.getMyInfo({ token }) + const { videoChannels } = await servers[0].users.getMyInfo({ token }) const userChannel = videoChannels[0] await commands[0].create({ @@ -1121,18 +1121,18 @@ describe('Test video playlists', function () { { for (const server of [ servers[0], servers[1] ]) { - const body = await server.playlistsCommand.list({ start: 0, count: 15 }) + const body = await server.playlists.list({ start: 0, count: 15 }) expect(finder(body.data)).to.not.be.undefined } } - await servers[0].usersCommand.remove({ userId }) + await servers[0].users.remove({ userId }) await waitJobs(servers) { for (const server of [ servers[0], servers[1] ]) { - const body = await server.playlistsCommand.list({ start: 0, count: 15 }) + const body = await server.playlists.list({ start: 0, count: 15 }) expect(finder(body.data)).to.be.undefined } diff --git a/server/tests/api/videos/video-privacy.ts b/server/tests/api/videos/video-privacy.ts index bcf431edb..de08a9e7b 100644 --- a/server/tests/api/videos/video-privacy.ts +++ b/server/tests/api/videos/video-privacy.ts @@ -52,28 +52,28 @@ describe('Test video privacy', function () { for (const privacy of [ VideoPrivacy.PRIVATE, VideoPrivacy.INTERNAL ]) { const attributes = { privacy } - await servers[0].videosCommand.upload({ attributes }) + await servers[0].videos.upload({ attributes }) } await waitJobs(servers) }) it('Should not have these private and internal videos on server 2', async function () { - const { total, data } = await servers[1].videosCommand.list() + const { total, data } = await servers[1].videos.list() expect(total).to.equal(0) expect(data).to.have.lengthOf(0) }) it('Should not list the private and internal videos for an unauthenticated user on server 1', async function () { - const { total, data } = await servers[0].videosCommand.list() + const { total, data } = await servers[0].videos.list() expect(total).to.equal(0) expect(data).to.have.lengthOf(0) }) it('Should not list the private video and list the internal video for an authenticated user on server 1', async function () { - const { total, data } = await servers[0].videosCommand.listWithToken() + const { total, data } = await servers[0].videos.listWithToken() expect(total).to.equal(1) expect(data).to.have.lengthOf(1) @@ -82,7 +82,7 @@ describe('Test video privacy', function () { }) it('Should list my (private and internal) videos', async function () { - const { total, data } = await servers[0].videosCommand.listMyVideos() + const { total, data } = await servers[0].videos.listMyVideos() expect(total).to.equal(2) expect(data).to.have.lengthOf(2) @@ -97,8 +97,8 @@ describe('Test video privacy', function () { }) it('Should not be able to watch the private/internal video with non authenticated user', async function () { - await servers[0].videosCommand.get({ id: privateVideoUUID, expectedStatus: HttpStatusCode.UNAUTHORIZED_401 }) - await servers[0].videosCommand.get({ id: internalVideoUUID, expectedStatus: HttpStatusCode.UNAUTHORIZED_401 }) + await servers[0].videos.get({ id: privateVideoUUID, expectedStatus: HttpStatusCode.UNAUTHORIZED_401 }) + await servers[0].videos.get({ id: internalVideoUUID, expectedStatus: HttpStatusCode.UNAUTHORIZED_401 }) }) it('Should not be able to watch the private video with another user', async function () { @@ -108,11 +108,11 @@ describe('Test video privacy', function () { username: 'hello', password: 'super password' } - await servers[0].usersCommand.create({ username: user.username, password: user.password }) + await servers[0].users.create({ username: user.username, password: user.password }) - anotherUserToken = await servers[0].loginCommand.getAccessToken(user) + anotherUserToken = await servers[0].login.getAccessToken(user) - await servers[0].videosCommand.getWithToken({ + await servers[0].videos.getWithToken({ token: anotherUserToken, id: privateVideoUUID, expectedStatus: HttpStatusCode.FORBIDDEN_403 @@ -120,11 +120,11 @@ describe('Test video privacy', function () { }) it('Should be able to watch the internal video with another user', async function () { - await servers[0].videosCommand.getWithToken({ token: anotherUserToken, id: internalVideoUUID }) + await servers[0].videos.getWithToken({ token: anotherUserToken, id: internalVideoUUID }) }) it('Should be able to watch the private video with the correct user', async function () { - await servers[0].videosCommand.getWithToken({ id: privateVideoUUID }) + await servers[0].videos.getWithToken({ id: privateVideoUUID }) }) }) @@ -137,7 +137,7 @@ describe('Test video privacy', function () { name: 'unlisted video', privacy: VideoPrivacy.UNLISTED } - await servers[1].videosCommand.upload({ attributes }) + await servers[1].videos.upload({ attributes }) // Server 2 has transcoding enabled await waitJobs(servers) @@ -145,7 +145,7 @@ describe('Test video privacy', function () { it('Should not have this unlisted video listed on server 1 and 2', async function () { for (const server of servers) { - const { total, data } = await server.videosCommand.list() + const { total, data } = await server.videos.list() expect(total).to.equal(0) expect(data).to.have.lengthOf(0) @@ -153,7 +153,7 @@ describe('Test video privacy', function () { }) it('Should list my (unlisted) videos', async function () { - const { total, data } = await servers[1].videosCommand.listMyVideos() + const { total, data } = await servers[1].videos.listMyVideos() expect(total).to.equal(1) expect(data).to.have.lengthOf(1) @@ -162,13 +162,13 @@ describe('Test video privacy', function () { }) it('Should not be able to get this unlisted video using its id', async function () { - await servers[1].videosCommand.get({ id: unlistedVideo.id, expectedStatus: HttpStatusCode.BAD_REQUEST_400 }) + await servers[1].videos.get({ id: unlistedVideo.id, expectedStatus: HttpStatusCode.BAD_REQUEST_400 }) }) it('Should be able to get this unlisted video using its uuid/shortUUID', async function () { for (const server of servers) { for (const id of [ unlistedVideo.uuid, unlistedVideo.shortUUID ]) { - const video = await server.videosCommand.get({ id }) + const video = await server.videos.get({ id }) expect(video.name).to.equal('unlisted video') } @@ -182,13 +182,13 @@ describe('Test video privacy', function () { name: 'unlisted video', privacy: VideoPrivacy.UNLISTED } - await servers[0].videosCommand.upload({ attributes }) + await servers[0].videos.upload({ attributes }) await waitJobs(servers) }) it('Should list my new unlisted video', async function () { - const { total, data } = await servers[0].videosCommand.listMyVideos() + const { total, data } = await servers[0].videos.listMyVideos() expect(total).to.equal(3) expect(data).to.have.lengthOf(3) @@ -197,13 +197,13 @@ describe('Test video privacy', function () { }) it('Should be able to get non-federated unlisted video from origin', async function () { - const video = await servers[0].videosCommand.get({ id: nonFederatedUnlistedVideoUUID }) + const video = await servers[0].videos.get({ id: nonFederatedUnlistedVideoUUID }) expect(video.name).to.equal('unlisted video') }) it('Should not be able to get non-federated unlisted video from federated server', async function () { - await servers[1].videosCommand.get({ id: nonFederatedUnlistedVideoUUID, expectedStatus: HttpStatusCode.NOT_FOUND_404 }) + await servers[1].videos.get({ id: nonFederatedUnlistedVideoUUID, expectedStatus: HttpStatusCode.NOT_FOUND_404 }) }) }) @@ -220,7 +220,7 @@ describe('Test video privacy', function () { privacy: VideoPrivacy.PUBLIC } - await servers[0].videosCommand.update({ id: privateVideoId, attributes }) + await servers[0].videos.update({ id: privateVideoId, attributes }) } { @@ -228,7 +228,7 @@ describe('Test video privacy', function () { name: 'internal video becomes public', privacy: VideoPrivacy.PUBLIC } - await servers[0].videosCommand.update({ id: internalVideoId, attributes }) + await servers[0].videos.update({ id: internalVideoId, attributes }) } await waitJobs(servers) @@ -236,7 +236,7 @@ describe('Test video privacy', function () { it('Should have this new public video listed on server 1 and 2', async function () { for (const server of servers) { - const { total, data } = await server.videosCommand.list() + const { total, data } = await server.videos.list() expect(total).to.equal(2) expect(data).to.have.lengthOf(2) @@ -258,20 +258,20 @@ describe('Test video privacy', function () { it('Should set these videos as private and internal', async function () { this.timeout(10000) - await servers[0].videosCommand.update({ id: internalVideoId, attributes: { privacy: VideoPrivacy.PRIVATE } }) - await servers[0].videosCommand.update({ id: privateVideoId, attributes: { privacy: VideoPrivacy.INTERNAL } }) + await servers[0].videos.update({ id: internalVideoId, attributes: { privacy: VideoPrivacy.PRIVATE } }) + await servers[0].videos.update({ id: privateVideoId, attributes: { privacy: VideoPrivacy.INTERNAL } }) await waitJobs(servers) for (const server of servers) { - const { total, data } = await server.videosCommand.list() + const { total, data } = await server.videos.list() expect(total).to.equal(0) expect(data).to.have.lengthOf(0) } { - const { total, data } = await servers[0].videosCommand.listMyVideos() + const { total, data } = await servers[0].videos.listMyVideos() expect(total).to.equal(3) expect(data).to.have.lengthOf(3) diff --git a/server/tests/api/videos/video-schedule-update.ts b/server/tests/api/videos/video-schedule-update.ts index 635ae6ff1..3938b47c8 100644 --- a/server/tests/api/videos/video-schedule-update.ts +++ b/server/tests/api/videos/video-schedule-update.ts @@ -49,25 +49,25 @@ describe('Test video update scheduler', function () { } } - await servers[0].videosCommand.upload({ attributes }) + await servers[0].videos.upload({ attributes }) await waitJobs(servers) }) it('Should not list the video (in privacy mode)', async function () { for (const server of servers) { - const { total } = await server.videosCommand.list() + const { total } = await server.videos.list() expect(total).to.equal(0) } }) it('Should have my scheduled video in my account videos', async function () { - const { total, data } = await servers[0].videosCommand.listMyVideos() + const { total, data } = await servers[0].videos.listMyVideos() expect(total).to.equal(1) const videoFromList = data[0] - const videoFromGet = await servers[0].videosCommand.getWithToken({ id: videoFromList.uuid }) + const videoFromGet = await servers[0].videos.getWithToken({ id: videoFromList.uuid }) for (const video of [ videoFromList, videoFromGet ]) { expect(video.name).to.equal('video 1') @@ -84,7 +84,7 @@ describe('Test video update scheduler', function () { await waitJobs(servers) for (const server of servers) { - const { total, data } = await server.videosCommand.list() + const { total, data } = await server.videos.list() expect(total).to.equal(1) expect(data[0].name).to.equal('video 1') @@ -99,7 +99,7 @@ describe('Test video update scheduler', function () { privacy: VideoPrivacy.PRIVATE } - const { uuid } = await servers[0].videosCommand.upload({ attributes }) + const { uuid } = await servers[0].videos.upload({ attributes }) video2UUID = uuid await waitJobs(servers) @@ -116,20 +116,20 @@ describe('Test video update scheduler', function () { } } - await servers[0].videosCommand.update({ id: video2UUID, attributes }) + await servers[0].videos.update({ id: video2UUID, attributes }) await waitJobs(servers) }) it('Should not display the updated video', async function () { for (const server of servers) { - const { total } = await server.videosCommand.list() + const { total } = await server.videos.list() expect(total).to.equal(1) } }) it('Should have my scheduled updated video in my account videos', async function () { - const { total, data } = await servers[0].videosCommand.listMyVideos() + const { total, data } = await servers[0].videos.listMyVideos() expect(total).to.equal(2) const video = data.find(v => v.uuid === video2UUID) @@ -149,7 +149,7 @@ describe('Test video update scheduler', function () { await waitJobs(servers) for (const server of servers) { - const { total, data } = await server.videosCommand.list() + const { total, data } = await server.videos.list() expect(total).to.equal(2) const video = data.find(v => v.uuid === video2UUID) diff --git a/server/tests/api/videos/video-transcoder.ts b/server/tests/api/videos/video-transcoder.ts index b41c68283..37450eeeb 100644 --- a/server/tests/api/videos/video-transcoder.ts +++ b/server/tests/api/videos/video-transcoder.ts @@ -32,7 +32,7 @@ import { const expect = chai.expect function updateConfigForTranscoding (server: ServerInfo) { - return server.configCommand.updateCustomSubConfig({ + return server.config.updateCustomSubConfig({ newConfig: { transcoding: { enabled: true, @@ -82,15 +82,15 @@ describe('Test video transcoding', function () { description: 'my super description for server 1', fixture: 'video_short.webm' } - await servers[0].videosCommand.upload({ attributes }) + await servers[0].videos.upload({ attributes }) await waitJobs(servers) for (const server of servers) { - const { data } = await server.videosCommand.list() + const { data } = await server.videos.list() const video = data[0] - const videoDetails = await server.videosCommand.get({ id: video.id }) + const videoDetails = await server.videos.get({ id: video.id }) expect(videoDetails.files).to.have.lengthOf(1) const magnetUri = videoDetails.files[0].magnetUri @@ -111,15 +111,15 @@ describe('Test video transcoding', function () { description: 'my super description for server 2', fixture: 'video_short.webm' } - await servers[1].videosCommand.upload({ attributes }) + await servers[1].videos.upload({ attributes }) await waitJobs(servers) for (const server of servers) { - const { data } = await server.videosCommand.list() + const { data } = await server.videos.list() const video = data.find(v => v.name === attributes.name) - const videoDetails = await server.videosCommand.get({ id: video.id }) + const videoDetails = await server.videos.get({ id: video.id }) expect(videoDetails.files).to.have.lengthOf(4) @@ -143,11 +143,11 @@ describe('Test video transcoding', function () { fixture: 'video_short1.webm', waitTranscoding: true } - const { uuid } = await servers[1].videosCommand.upload({ attributes }) + const { uuid } = await servers[1].videos.upload({ attributes }) const videoId = uuid // Should be in transcode state - const body = await servers[1].videosCommand.get({ id: videoId }) + const body = await servers[1].videos.get({ id: videoId }) expect(body.name).to.equal('waiting video') expect(body.state.id).to.equal(VideoState.TO_TRANSCODE) expect(body.state.label).to.equal('To transcode') @@ -155,7 +155,7 @@ describe('Test video transcoding', function () { { // Should have my video - const { data } = await servers[1].videosCommand.listMyVideos() + const { data } = await servers[1].videos.listMyVideos() const videoToFindInMine = data.find(v => v.name === attributes.name) expect(videoToFindInMine).not.to.be.undefined expect(videoToFindInMine.state.id).to.equal(VideoState.TO_TRANSCODE) @@ -165,23 +165,23 @@ describe('Test video transcoding', function () { { // Should not list this video - const { data } = await servers[1].videosCommand.list() + const { data } = await servers[1].videos.list() const videoToFindInList = data.find(v => v.name === attributes.name) expect(videoToFindInList).to.be.undefined } // Server 1 should not have the video yet - await servers[0].videosCommand.get({ id: videoId, expectedStatus: HttpStatusCode.NOT_FOUND_404 }) + await servers[0].videos.get({ id: videoId, expectedStatus: HttpStatusCode.NOT_FOUND_404 }) } await waitJobs(servers) for (const server of servers) { - const { data } = await server.videosCommand.list() + const { data } = await server.videos.list() const videoToFind = data.find(v => v.name === 'waiting video') expect(videoToFind).not.to.be.undefined - const videoDetails = await server.videosCommand.get({ id: videoToFind.id }) + const videoDetails = await server.videos.get({ id: videoToFind.id }) expect(videoDetails.state.id).to.equal(VideoState.PUBLISHED) expect(videoDetails.state.label).to.equal('Published') @@ -207,15 +207,15 @@ describe('Test video transcoding', function () { fixture } - await servers[1].videosCommand.upload({ attributes }) + await servers[1].videos.upload({ attributes }) await waitJobs(servers) for (const server of servers) { - const { data } = await server.videosCommand.list() + const { data } = await server.videos.list() const video = data.find(v => v.name === attributes.name) - const videoDetails = await server.videosCommand.get({ id: video.id }) + const videoDetails = await server.videos.get({ id: video.id }) expect(videoDetails.files).to.have.lengthOf(4) const magnetUri = videoDetails.files[0].magnetUri @@ -232,7 +232,7 @@ describe('Test video transcoding', function () { fixture: 'video_short_4k.mp4' } - const { uuid } = await servers[1].videosCommand.upload({ attributes }) + const { uuid } = await servers[1].videos.upload({ attributes }) video4k = uuid await waitJobs(servers) @@ -240,7 +240,7 @@ describe('Test video transcoding', function () { const resolutions = [ 240, 360, 480, 720, 1080, 1440, 2160 ] for (const server of servers) { - const videoDetails = await server.videosCommand.get({ id: video4k }) + const videoDetails = await server.videos.get({ id: video4k }) expect(videoDetails.files).to.have.lengthOf(resolutions.length) for (const r of resolutions) { @@ -260,19 +260,19 @@ describe('Test video transcoding', function () { name: 'mp3_256k', fixture: 'video_short_mp3_256k.mp4' } - await servers[1].videosCommand.upload({ attributes }) + await servers[1].videos.upload({ attributes }) await waitJobs(servers) for (const server of servers) { - const { data } = await server.videosCommand.list() + const { data } = await server.videos.list() const video = data.find(v => v.name === attributes.name) - const videoDetails = await server.videosCommand.get({ id: video.id }) + const videoDetails = await server.videos.get({ id: video.id }) expect(videoDetails.files).to.have.lengthOf(4) - const path = servers[1].serversCommand.buildDirectory(join('videos', video.uuid + '-240.mp4')) + const path = servers[1].servers.buildDirectory(join('videos', video.uuid + '-240.mp4')) const probe = await getAudioStream(path) if (probe.audioStream) { @@ -291,18 +291,18 @@ describe('Test video transcoding', function () { name: 'no_audio', fixture: 'video_short_no_audio.mp4' } - await servers[1].videosCommand.upload({ attributes }) + await servers[1].videos.upload({ attributes }) await waitJobs(servers) for (const server of servers) { - const { data } = await server.videosCommand.list() + const { data } = await server.videos.list() const video = data.find(v => v.name === attributes.name) - const videoDetails = await server.videosCommand.get({ id: video.id }) + const videoDetails = await server.videos.get({ id: video.id }) expect(videoDetails.files).to.have.lengthOf(4) - const path = servers[1].serversCommand.buildDirectory(join('videos', video.uuid + '-240.mp4')) + const path = servers[1].servers.buildDirectory(join('videos', video.uuid + '-240.mp4')) const probe = await getAudioStream(path) expect(probe).to.not.have.property('audioStream') } @@ -315,21 +315,21 @@ describe('Test video transcoding', function () { name: 'untouched_audio', fixture: 'video_short.mp4' } - await servers[1].videosCommand.upload({ attributes }) + await servers[1].videos.upload({ attributes }) await waitJobs(servers) for (const server of servers) { - const { data } = await server.videosCommand.list() + const { data } = await server.videos.list() const video = data.find(v => v.name === attributes.name) - const videoDetails = await server.videosCommand.get({ id: video.id }) + const videoDetails = await server.videos.get({ id: video.id }) expect(videoDetails.files).to.have.lengthOf(4) const fixturePath = buildAbsoluteFixturePath(attributes.fixture) const fixtureVideoProbe = await getAudioStream(fixturePath) - const path = servers[1].serversCommand.buildDirectory(join('videos', video.uuid + '-240.mp4')) + const path = servers[1].servers.buildDirectory(join('videos', video.uuid + '-240.mp4')) const videoProbe = await getAudioStream(path) @@ -348,7 +348,7 @@ describe('Test video transcoding', function () { function runSuite (mode: 'legacy' | 'resumable') { before(async function () { - await servers[1].configCommand.updateCustomSubConfig({ + await servers[1].config.updateCustomSubConfig({ newConfig: { transcoding: { hls: { enabled: true }, @@ -372,15 +372,15 @@ describe('Test video transcoding', function () { this.timeout(60_000) const attributes = { name: 'audio_with_preview', previewfile: 'preview.jpg', fixture: 'sample.ogg' } - await servers[1].videosCommand.upload({ attributes, mode }) + await servers[1].videos.upload({ attributes, mode }) await waitJobs(servers) for (const server of servers) { - const { data } = await server.videosCommand.list() + const { data } = await server.videos.list() const video = data.find(v => v.name === 'audio_with_preview') - const videoDetails = await server.videosCommand.get({ id: video.id }) + const videoDetails = await server.videos.get({ id: video.id }) expect(videoDetails.files).to.have.lengthOf(1) @@ -396,15 +396,15 @@ describe('Test video transcoding', function () { this.timeout(60_000) const attributes = { name: 'audio_without_preview', fixture: 'sample.ogg' } - await servers[1].videosCommand.upload({ attributes, mode }) + await servers[1].videos.upload({ attributes, mode }) await waitJobs(servers) for (const server of servers) { - const { data } = await server.videosCommand.list() + const { data } = await server.videos.list() const video = data.find(v => v.name === 'audio_without_preview') - const videoDetails = await server.videosCommand.get({ id: video.id }) + const videoDetails = await server.videos.get({ id: video.id }) expect(videoDetails.files).to.have.lengthOf(1) @@ -419,7 +419,7 @@ describe('Test video transcoding', function () { it('Should upload an audio file and create an audio version only', async function () { this.timeout(60_000) - await servers[1].configCommand.updateCustomSubConfig({ + await servers[1].config.updateCustomSubConfig({ newConfig: { transcoding: { hls: { enabled: true }, @@ -434,12 +434,12 @@ describe('Test video transcoding', function () { }) const attributes = { name: 'audio_with_preview', previewfile: 'preview.jpg', fixture: 'sample.ogg' } - const { id } = await servers[1].videosCommand.upload({ attributes, mode }) + const { id } = await servers[1].videos.upload({ attributes, mode }) await waitJobs(servers) for (const server of servers) { - const videoDetails = await server.videosCommand.get({ id }) + const videoDetails = await server.videos.get({ id }) for (const files of [ videoDetails.files, videoDetails.streamingPlaylists[0].files ]) { expect(files).to.have.lengthOf(2) @@ -470,15 +470,15 @@ describe('Test video transcoding', function () { description: 'my super 30fps description for server 2', fixture: '60fps_720p_small.mp4' } - await servers[1].videosCommand.upload({ attributes }) + await servers[1].videos.upload({ attributes }) await waitJobs(servers) for (const server of servers) { - const { data } = await server.videosCommand.list() + const { data } = await server.videos.list() const video = data.find(v => v.name === attributes.name) - const videoDetails = await server.videosCommand.get({ id: video.id }) + const videoDetails = await server.videos.get({ id: video.id }) expect(videoDetails.files).to.have.lengthOf(4) expect(videoDetails.files[0].fps).to.be.above(58).and.below(62) @@ -487,13 +487,13 @@ describe('Test video transcoding', function () { expect(videoDetails.files[3].fps).to.be.below(31) for (const resolution of [ '240', '360', '480' ]) { - const path = servers[1].serversCommand.buildDirectory(join('videos', video.uuid + '-' + resolution + '.mp4')) + const path = servers[1].servers.buildDirectory(join('videos', video.uuid + '-' + resolution + '.mp4')) const fps = await getVideoFileFPS(path) expect(fps).to.be.below(31) } - const path = servers[1].serversCommand.buildDirectory(join('videos', video.uuid + '-720.mp4')) + const path = servers[1].servers.buildDirectory(join('videos', video.uuid + '-720.mp4')) const fps = await getVideoFileFPS(path) expect(fps).to.be.above(58).and.below(62) @@ -518,23 +518,23 @@ describe('Test video transcoding', function () { fixture: tempFixturePath } - await servers[1].videosCommand.upload({ attributes }) + await servers[1].videos.upload({ attributes }) await waitJobs(servers) for (const server of servers) { - const { data } = await server.videosCommand.list() + const { data } = await server.videos.list() const video = data.find(v => v.name === attributes.name) { - const path = servers[1].serversCommand.buildDirectory(join('videos', video.uuid + '-240.mp4')) + const path = servers[1].servers.buildDirectory(join('videos', video.uuid + '-240.mp4')) const fps = await getVideoFileFPS(path) expect(fps).to.be.equal(25) } { - const path = servers[1].serversCommand.buildDirectory(join('videos', video.uuid + '-720.mp4')) + const path = servers[1].servers.buildDirectory(join('videos', video.uuid + '-720.mp4')) const fps = await getVideoFileFPS(path) expect(fps).to.be.equal(59) } @@ -561,17 +561,17 @@ describe('Test video transcoding', function () { fixture: tempFixturePath } - await servers[1].videosCommand.upload({ attributes }) + await servers[1].videos.upload({ attributes }) await waitJobs(servers) for (const server of servers) { - const { data } = await server.videosCommand.list() + const { data } = await server.videos.list() const video = data.find(v => v.name === attributes.name) for (const resolution of [ '240', '360', '480', '720', '1080' ]) { - const path = servers[1].serversCommand.buildDirectory(join('videos', video.uuid + '-' + resolution + '.mp4')) + const path = servers[1].servers.buildDirectory(join('videos', video.uuid + '-' + resolution + '.mp4')) const bitrate = await getVideoFileBitrate(path) const fps = await getVideoFileFPS(path) @@ -602,21 +602,21 @@ describe('Test video transcoding', function () { hls: { enabled: true } } } - await servers[1].configCommand.updateCustomSubConfig({ newConfig }) + await servers[1].config.updateCustomSubConfig({ newConfig }) const attributes = { name: 'low bitrate', fixture: 'low-bitrate.mp4' } - const { uuid } = await servers[1].videosCommand.upload({ attributes }) + const { uuid } = await servers[1].videos.upload({ attributes }) await waitJobs(servers) const resolutions = [ 240, 360, 480, 720, 1080 ] for (const r of resolutions) { const path = `videos/${uuid}-${r}.mp4` - const size = await servers[1].serversCommand.getServerFileSize(path) + const size = await servers[1].servers.getServerFileSize(path) expect(size, `${path} not below ${60_000}`).to.be.below(60_000) } }) @@ -627,11 +627,11 @@ describe('Test video transcoding', function () { it('Should provide valid ffprobe data', async function () { this.timeout(160_000) - const videoUUID = (await servers[1].videosCommand.quickUpload({ name: 'ffprobe data' })).uuid + const videoUUID = (await servers[1].videos.quickUpload({ name: 'ffprobe data' })).uuid await waitJobs(servers) { - const path = servers[1].serversCommand.buildDirectory(join('videos', videoUUID + '-240.mp4')) + const path = servers[1].servers.buildDirectory(join('videos', videoUUID + '-240.mp4')) const metadata = await getMetadataFromFile(path) // expected format properties @@ -661,7 +661,7 @@ describe('Test video transcoding', function () { } for (const server of servers) { - const videoDetails = await server.videosCommand.get({ id: videoUUID }) + const videoDetails = await server.videos.get({ id: videoUUID }) const videoFiles = videoDetails.files .concat(videoDetails.streamingPlaylists[0].files) @@ -673,7 +673,7 @@ describe('Test video transcoding', function () { expect(file.metadataUrl).to.contain(servers[1].url) expect(file.metadataUrl).to.contain(videoUUID) - const metadata = await server.videosCommand.getFileMetadata({ url: file.metadataUrl }) + const metadata = await server.videos.getFileMetadata({ url: file.metadataUrl }) expect(metadata).to.have.nested.property('format.size') } } @@ -690,7 +690,7 @@ describe('Test video transcoding', function () { describe('Transcoding job queue', function () { it('Should have the appropriate priorities for transcoding jobs', async function () { - const body = await servers[1].jobsCommand.getJobsList({ + const body = await servers[1].jobs.getJobsList({ start: 0, count: 100, sort: '-createdAt', diff --git a/server/tests/api/videos/videos-filter.ts b/server/tests/api/videos/videos-filter.ts index 4a5a83ee6..af1541dbd 100644 --- a/server/tests/api/videos/videos-filter.ts +++ b/server/tests/api/videos/videos-filter.ts @@ -55,19 +55,19 @@ describe('Test videos filter', function () { for (const server of servers) { const moderator = { username: 'moderator', password: 'my super password' } - await server.usersCommand.create({ username: moderator.username, password: moderator.password, role: UserRole.MODERATOR }) - server['moderatorAccessToken'] = await server.loginCommand.getAccessToken(moderator) + await server.users.create({ username: moderator.username, password: moderator.password, role: UserRole.MODERATOR }) + server['moderatorAccessToken'] = await server.login.getAccessToken(moderator) - await server.videosCommand.upload({ attributes: { name: 'public ' + server.serverNumber } }) + await server.videos.upload({ attributes: { name: 'public ' + server.serverNumber } }) { const attributes = { name: 'unlisted ' + server.serverNumber, privacy: VideoPrivacy.UNLISTED } - await server.videosCommand.upload({ attributes }) + await server.videos.upload({ attributes }) } { const attributes = { name: 'private ' + server.serverNumber, privacy: VideoPrivacy.PRIVATE } - await server.videosCommand.upload({ attributes }) + await server.videos.upload({ attributes }) } } diff --git a/server/tests/api/videos/videos-history.ts b/server/tests/api/videos/videos-history.ts index 8614078f1..4b5e581d1 100644 --- a/server/tests/api/videos/videos-history.ts +++ b/server/tests/api/videos/videos-history.ts @@ -33,20 +33,20 @@ describe('Test videos history', function () { await setAccessTokensToServers([ server ]) - command = server.historyCommand + command = server.history { - const { uuid } = await server.videosCommand.upload({ attributes: { name: 'video 1' } }) + const { uuid } = await server.videos.upload({ attributes: { name: 'video 1' } }) video1UUID = uuid } { - const { uuid } = await server.videosCommand.upload({ attributes: { name: 'video 2' } }) + const { uuid } = await server.videos.upload({ attributes: { name: 'video 2' } }) video2UUID = uuid } { - const { uuid } = await server.videosCommand.upload({ attributes: { name: 'video 3' } }) + const { uuid } = await server.videos.upload({ attributes: { name: 'video 3' } }) video3UUID = uuid } @@ -54,15 +54,15 @@ describe('Test videos history', function () { username: 'user_1', password: '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) }) it('Should get videos, without watching history', async function () { - const { data } = await server.videosCommand.listWithToken() + const { data } = await server.videos.listWithToken() for (const video of data) { - const videoDetails = await server.videosCommand.getWithToken({ id: video.id }) + const videoDetails = await server.videos.getWithToken({ id: video.id }) expect(video.userHistory).to.be.undefined expect(videoDetails.userHistory).to.be.undefined @@ -78,12 +78,12 @@ describe('Test videos history', function () { const videosOfVideos: Video[][] = [] { - const { data } = await server.videosCommand.listWithToken() + const { data } = await server.videos.listWithToken() videosOfVideos.push(data) } { - const body = await server.searchCommand.searchVideos({ token: server.accessToken, search: 'video' }) + const body = await server.search.searchVideos({ token: server.accessToken, search: 'video' }) videosOfVideos.push(body.data) } @@ -102,21 +102,21 @@ describe('Test videos history', function () { } { - const videoDetails = await server.videosCommand.getWithToken({ id: video1UUID }) + const videoDetails = await server.videos.getWithToken({ id: video1UUID }) expect(videoDetails.userHistory).to.not.be.undefined expect(videoDetails.userHistory.currentTime).to.equal(3) } { - const videoDetails = await server.videosCommand.getWithToken({ id: video2UUID }) + const videoDetails = await server.videos.getWithToken({ id: video2UUID }) expect(videoDetails.userHistory).to.not.be.undefined expect(videoDetails.userHistory.currentTime).to.equal(8) } { - const videoDetails = await server.videosCommand.getWithToken({ id: video3UUID }) + const videoDetails = await server.videos.getWithToken({ id: video3UUID }) expect(videoDetails.userHistory).to.be.undefined } @@ -164,7 +164,7 @@ describe('Test videos history', function () { }) it('Should disable videos history', async function () { - await server.usersCommand.updateMe({ + await server.users.updateMe({ videosHistoryEnabled: false }) @@ -172,7 +172,7 @@ describe('Test videos history', function () { }) it('Should re-enable videos history', async function () { - await server.usersCommand.updateMe({ + await server.users.updateMe({ videosHistoryEnabled: true }) diff --git a/server/tests/api/videos/videos-overview.ts b/server/tests/api/videos/videos-overview.ts index 969393842..f0657b334 100644 --- a/server/tests/api/videos/videos-overview.ts +++ b/server/tests/api/videos/videos-overview.ts @@ -25,7 +25,7 @@ describe('Test a videos overview', function () { }) it('Should send empty overview', async function () { - const body = await server.overviewsCommand.getVideos({ page: 1 }) + const body = await server.overviews.getVideos({ page: 1 }) testOverviewCount(body, 0) }) @@ -35,7 +35,7 @@ describe('Test a videos overview', function () { await wait(3000) - await server.videosCommand.upload({ + await server.videos.upload({ attributes: { name: 'video 0', category: 3, @@ -43,7 +43,7 @@ describe('Test a videos overview', function () { } }) - const body = await server.overviewsCommand.getVideos({ page: 1 }) + const body = await server.overviews.getVideos({ page: 1 }) testOverviewCount(body, 0) }) @@ -53,7 +53,7 @@ describe('Test a videos overview', function () { { for (let i = 1; i < 6; i++) { - await server.videosCommand.upload({ + await server.videos.upload({ attributes: { name: 'video ' + i, category: 3, @@ -66,13 +66,13 @@ describe('Test a videos overview', function () { } { - const body = await server.overviewsCommand.getVideos({ page: 1 }) + const body = await server.overviews.getVideos({ page: 1 }) testOverviewCount(body, 1) } { - const overview = await server.overviewsCommand.getVideos({ page: 2 }) + const overview = await server.overviews.getVideos({ page: 2 }) expect(overview.tags).to.have.lengthOf(1) expect(overview.categories).to.have.lengthOf(0) @@ -81,8 +81,8 @@ describe('Test a videos overview', function () { }) it('Should have the correct overview', async function () { - const overview1 = await server.overviewsCommand.getVideos({ page: 1 }) - const overview2 = await server.overviewsCommand.getVideos({ page: 2 }) + const overview1 = await server.overviews.getVideos({ page: 1 }) + const overview2 = await server.overviews.getVideos({ page: 2 }) for (const arr of [ overview1.tags, overview1.categories, overview1.channels, overview2.tags ]) { expect(arr).to.have.lengthOf(1) @@ -108,18 +108,18 @@ describe('Test a videos overview', function () { }) it('Should hide muted accounts', async function () { - const token = await server.usersCommand.generateUserAndToken('choco') + const token = await server.users.generateUserAndToken('choco') - await server.blocklistCommand.addToMyBlocklist({ token, account: 'root@' + server.host }) + await server.blocklist.addToMyBlocklist({ token, account: 'root@' + server.host }) { - const body = await server.overviewsCommand.getVideos({ page: 1 }) + const body = await server.overviews.getVideos({ page: 1 }) testOverviewCount(body, 1) } { - const body = await server.overviewsCommand.getVideos({ page: 1, token }) + const body = await server.overviews.getVideos({ page: 1, token }) testOverviewCount(body, 0) } diff --git a/server/tests/api/videos/videos-views-cleaner.ts b/server/tests/api/videos/videos-views-cleaner.ts index 7ded1bf38..238662cf3 100644 --- a/server/tests/api/videos/videos-views-cleaner.ts +++ b/server/tests/api/videos/videos-views-cleaner.ts @@ -30,15 +30,15 @@ describe('Test video views cleaner', function () { await doubleFollow(servers[0], servers[1]) - videoIdServer1 = (await servers[0].videosCommand.quickUpload({ name: 'video server 1' })).uuid - videoIdServer2 = (await servers[1].videosCommand.quickUpload({ name: 'video server 2' })).uuid + videoIdServer1 = (await servers[0].videos.quickUpload({ name: 'video server 1' })).uuid + videoIdServer2 = (await servers[1].videos.quickUpload({ name: 'video server 2' })).uuid await waitJobs(servers) - await servers[0].videosCommand.view({ id: videoIdServer1 }) - await servers[1].videosCommand.view({ id: videoIdServer1 }) - await servers[0].videosCommand.view({ id: videoIdServer2 }) - await servers[1].videosCommand.view({ id: videoIdServer2 }) + await servers[0].videos.view({ id: videoIdServer1 }) + await servers[1].videos.view({ id: videoIdServer1 }) + await servers[0].videos.view({ id: videoIdServer2 }) + await servers[1].videos.view({ id: videoIdServer2 }) await waitJobs(servers) }) @@ -56,14 +56,14 @@ describe('Test video views cleaner', function () { { for (const server of servers) { - const total = await server.sqlCommand.countVideoViewsOf(videoIdServer1) + const total = await server.sql.countVideoViewsOf(videoIdServer1) expect(total).to.equal(2, 'Server ' + server.serverNumber + ' does not have the correct amount of views') } } { for (const server of servers) { - const total = await server.sqlCommand.countVideoViewsOf(videoIdServer2) + const total = await server.sql.countVideoViewsOf(videoIdServer2) expect(total).to.equal(2, 'Server ' + server.serverNumber + ' does not have the correct amount of views') } } @@ -82,16 +82,16 @@ describe('Test video views cleaner', function () { { for (const server of servers) { - const total = await server.sqlCommand.countVideoViewsOf(videoIdServer1) + const total = await server.sql.countVideoViewsOf(videoIdServer1) expect(total).to.equal(2) } } { - const totalServer1 = await servers[0].sqlCommand.countVideoViewsOf(videoIdServer2) + const totalServer1 = await servers[0].sql.countVideoViewsOf(videoIdServer2) expect(totalServer1).to.equal(0) - const totalServer2 = await servers[1].sqlCommand.countVideoViewsOf(videoIdServer2) + const totalServer2 = await servers[1].sql.countVideoViewsOf(videoIdServer2) expect(totalServer2).to.equal(2) } }) -- 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/activitypub/cleaner.ts | 8 +++--- server/tests/api/activitypub/client.ts | 8 +++--- server/tests/api/activitypub/fetch.ts | 6 ++-- server/tests/api/activitypub/refresher.ts | 11 ++++---- server/tests/api/activitypub/security.ts | 17 ++++++----- 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 +++--- .../tests/api/check-params/user-notifications.ts | 8 +++--- .../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 +++--- server/tests/api/live/live-constraints.ts | 8 +++--- server/tests/api/live/live-permanent.ts | 8 +++--- server/tests/api/live/live-save-replay.ts | 8 +++--- server/tests/api/live/live-socket-messages.ts | 8 +++--- server/tests/api/live/live-views.ts | 8 +++--- server/tests/api/live/live.ts | 11 ++++---- server/tests/api/moderation/abuses.ts | 12 ++++---- .../tests/api/moderation/blocklist-notification.ts | 8 +++--- server/tests/api/moderation/blocklist.ts | 16 +++++------ server/tests/api/moderation/video-blacklist.ts | 13 ++++----- .../tests/api/notifications/admin-notifications.ts | 4 +-- .../api/notifications/comments-notifications.ts | 4 +-- .../api/notifications/moderation-notifications.ts | 4 +-- .../tests/api/notifications/notifications-api.ts | 4 +-- .../tests/api/notifications/user-notifications.ts | 4 +-- server/tests/api/redundancy/manage-redundancy.ts | 8 +++--- .../tests/api/redundancy/redundancy-constraints.ts | 19 ++++++------- server/tests/api/redundancy/redundancy.ts | 33 +++++++++++----------- .../search/search-activitypub-video-channels.ts | 8 +++--- .../search/search-activitypub-video-playlists.ts | 8 +++--- .../tests/api/search/search-activitypub-videos.ts | 8 +++--- server/tests/api/search/search-channels.ts | 6 ++-- server/tests/api/search/search-index.ts | 6 ++-- server/tests/api/search/search-playlists.ts | 8 +++--- server/tests/api/search/search-videos.ts | 8 +++--- server/tests/api/server/auto-follows.ts | 14 ++++----- server/tests/api/server/bulk.ts | 8 +++--- server/tests/api/server/config.ts | 15 +++++----- server/tests/api/server/contact-form.ts | 16 ++++++++--- server/tests/api/server/email.ts | 6 ++-- server/tests/api/server/follow-constraints.ts | 6 ++-- server/tests/api/server/follows-moderation.ts | 12 ++++---- server/tests/api/server/follows.ts | 8 +++--- server/tests/api/server/handle-down.ts | 13 ++++----- server/tests/api/server/homepage.ts | 13 ++++----- server/tests/api/server/jobs.ts | 8 +++--- server/tests/api/server/logs.ts | 11 ++++---- server/tests/api/server/no-client.ts | 8 +++--- server/tests/api/server/plugins.ts | 13 ++++----- server/tests/api/server/reverse-proxy.ts | 6 ++-- server/tests/api/server/services.ts | 6 ++-- server/tests/api/server/stats.ts | 8 +++--- server/tests/api/server/tracker.ts | 10 +++---- server/tests/api/users/user-subscriptions.ts | 8 +++--- server/tests/api/users/users-multiple-servers.ts | 8 +++--- server/tests/api/users/users-verification.ts | 6 ++-- server/tests/api/users/users.ts | 13 ++++----- server/tests/api/videos/audio-only.ts | 6 ++-- server/tests/api/videos/multiple-servers.ts | 8 +++--- server/tests/api/videos/resumable-upload.ts | 8 +++--- server/tests/api/videos/single-server.ts | 8 +++--- server/tests/api/videos/video-captions.ts | 8 +++--- server/tests/api/videos/video-change-ownership.ts | 14 ++++----- server/tests/api/videos/video-channels.ts | 10 +++---- server/tests/api/videos/video-comments.ts | 8 +++--- server/tests/api/videos/video-description.ts | 6 ++-- server/tests/api/videos/video-hls.ts | 10 +++---- server/tests/api/videos/video-imports.ts | 12 ++++---- server/tests/api/videos/video-nsfw.ts | 6 ++-- .../tests/api/videos/video-playlist-thumbnails.ts | 12 ++++---- server/tests/api/videos/video-playlists.ts | 18 ++++++------ server/tests/api/videos/video-privacy.ts | 8 +++--- server/tests/api/videos/video-schedule-update.ts | 8 +++--- server/tests/api/videos/video-transcoder.ts | 10 +++---- server/tests/api/videos/videos-filter.ts | 10 +++---- server/tests/api/videos/videos-history.ts | 13 ++++----- server/tests/api/videos/videos-overview.ts | 6 ++-- server/tests/api/videos/videos-views-cleaner.ts | 13 ++++----- 103 files changed, 476 insertions(+), 483 deletions(-) (limited to 'server/tests/api') diff --git a/server/tests/api/activitypub/cleaner.ts b/server/tests/api/activitypub/cleaner.ts index 1421824da..a5ce449f3 100644 --- a/server/tests/api/activitypub/cleaner.ts +++ b/server/tests/api/activitypub/cleaner.ts @@ -5,8 +5,8 @@ import * as chai from 'chai' import { cleanupTests, doubleFollow, - flushAndRunMultipleServers, - ServerInfo, + createMultipleServers, + PeerTubeServer, setAccessTokensToServers, wait, waitJobs @@ -15,7 +15,7 @@ import { const expect = chai.expect describe('Test AP cleaner', function () { - let servers: ServerInfo[] = [] + let servers: PeerTubeServer[] = [] let videoUUID1: string let videoUUID2: string let videoUUID3: string @@ -30,7 +30,7 @@ describe('Test AP cleaner', function () { videos: { cleanup_remote_interactions: true } } } - servers = await flushAndRunMultipleServers(3, config) + servers = await createMultipleServers(3, config) // Get the access tokens await setAccessTokensToServers(servers) diff --git a/server/tests/api/activitypub/client.ts b/server/tests/api/activitypub/client.ts index 5845045a3..720231f02 100644 --- a/server/tests/api/activitypub/client.ts +++ b/server/tests/api/activitypub/client.ts @@ -6,9 +6,9 @@ import { HttpStatusCode } from '@shared/core-utils' import { cleanupTests, doubleFollow, - flushAndRunMultipleServers, + createMultipleServers, makeActivityPubGetRequest, - ServerInfo, + PeerTubeServer, setAccessTokensToServers, setDefaultVideoChannel } from '@shared/extra-utils' @@ -17,7 +17,7 @@ import { VideoPlaylistPrivacy } from '@shared/models' const expect = chai.expect describe('Test activitypub', function () { - let servers: ServerInfo[] = [] + let servers: PeerTubeServer[] = [] let video: { id: number, uuid: string, shortUUID: string } let playlist: { id: number, uuid: string, shortUUID: string } @@ -62,7 +62,7 @@ describe('Test activitypub', function () { before(async function () { this.timeout(30000) - servers = await flushAndRunMultipleServers(2) + servers = await createMultipleServers(2) await setAccessTokensToServers(servers) await setDefaultVideoChannel(servers) diff --git a/server/tests/api/activitypub/fetch.ts b/server/tests/api/activitypub/fetch.ts index 34694a773..ddfe6cfe0 100644 --- a/server/tests/api/activitypub/fetch.ts +++ b/server/tests/api/activitypub/fetch.ts @@ -2,19 +2,19 @@ import 'mocha' import * as chai from 'chai' -import { cleanupTests, doubleFollow, flushAndRunMultipleServers, ServerInfo, setAccessTokensToServers, waitJobs } from '@shared/extra-utils' +import { cleanupTests, doubleFollow, createMultipleServers, PeerTubeServer, setAccessTokensToServers, waitJobs } from '@shared/extra-utils' const expect = chai.expect describe('Test ActivityPub fetcher', function () { - let servers: ServerInfo[] + let servers: PeerTubeServer[] // --------------------------------------------------------------- before(async function () { this.timeout(60000) - servers = await flushAndRunMultipleServers(3) + servers = await createMultipleServers(3) // Get the access tokens await setAccessTokensToServers(servers) diff --git a/server/tests/api/activitypub/refresher.ts b/server/tests/api/activitypub/refresher.ts index d2f71e857..bbec0d309 100644 --- a/server/tests/api/activitypub/refresher.ts +++ b/server/tests/api/activitypub/refresher.ts @@ -5,10 +5,9 @@ import { HttpStatusCode } from '@shared/core-utils' import { cleanupTests, doubleFollow, - flushAndRunMultipleServers, + createMultipleServers, killallServers, - reRunServer, - ServerInfo, + PeerTubeServer, setAccessTokensToServers, setDefaultVideoChannel, wait, @@ -17,7 +16,7 @@ import { import { VideoPlaylistPrivacy } from '@shared/models' describe('Test AP refresher', function () { - let servers: ServerInfo[] = [] + let servers: PeerTubeServer[] = [] let videoUUID1: string let videoUUID2: string let videoUUID3: string @@ -27,7 +26,7 @@ describe('Test AP refresher', function () { before(async function () { this.timeout(60000) - servers = await flushAndRunMultipleServers(2, { transcoding: { enabled: false } }) + servers = await createMultipleServers(2, { transcoding: { enabled: false } }) // Get the access tokens await setAccessTokensToServers(servers) @@ -95,7 +94,7 @@ describe('Test AP refresher', function () { // The refresh should fail await waitJobs([ servers[0] ]) - await reRunServer(servers[1]) + await servers[1].run() await servers[0].videos.get({ id: videoUUID3 }) }) diff --git a/server/tests/api/activitypub/security.ts b/server/tests/api/activitypub/security.ts index ab0eb256e..c173648b3 100644 --- a/server/tests/api/activitypub/security.ts +++ b/server/tests/api/activitypub/security.ts @@ -7,10 +7,9 @@ import { HttpStatusCode } from '../../../../shared/core-utils/miscs/http-error-c import { buildAbsoluteFixturePath, cleanupTests, - flushAndRunMultipleServers, + createMultipleServers, killallServers, - reRunServer, - ServerInfo, + PeerTubeServer, wait } from '../../../../shared/extra-utils' import { makeFollowRequest, makePOSTAPRequest } from '../../../../shared/extra-utils/requests/activitypub' @@ -20,7 +19,7 @@ import { buildGlobalHeaders } from '../../../lib/job-queue/handlers/utils/activi const expect = chai.expect -function setKeysOfServer (onServer: ServerInfo, ofServer: ServerInfo, publicKey: string, privateKey: string) { +function setKeysOfServer (onServer: PeerTubeServer, ofServer: PeerTubeServer, publicKey: string, privateKey: string) { const url = 'http://localhost:' + ofServer.port + '/accounts/peertube' return Promise.all([ @@ -29,7 +28,7 @@ function setKeysOfServer (onServer: ServerInfo, ofServer: ServerInfo, publicKey: ]) } -function setUpdatedAtOfServer (onServer: ServerInfo, ofServer: ServerInfo, updatedAt: string) { +function setUpdatedAtOfServer (onServer: PeerTubeServer, ofServer: PeerTubeServer, updatedAt: string) { const url = 'http://localhost:' + ofServer.port + '/accounts/peertube' return Promise.all([ @@ -38,7 +37,7 @@ function setUpdatedAtOfServer (onServer: ServerInfo, ofServer: ServerInfo, updat ]) } -function getAnnounceWithoutContext (server: ServerInfo) { +function getAnnounceWithoutContext (server: PeerTubeServer) { const json = require(buildAbsoluteFixturePath('./ap-json/peertube/announce-without-context.json')) const result: typeof json = {} @@ -54,7 +53,7 @@ function getAnnounceWithoutContext (server: ServerInfo) { } describe('Test ActivityPub security', function () { - let servers: ServerInfo[] + let servers: PeerTubeServer[] let url: string const keys = require(buildAbsoluteFixturePath('./ap-json/peertube/keys.json')) @@ -72,7 +71,7 @@ describe('Test ActivityPub security', function () { before(async function () { this.timeout(60000) - servers = await flushAndRunMultipleServers(3) + servers = await createMultipleServers(3) url = servers[0].url + '/inbox' @@ -172,7 +171,7 @@ describe('Test ActivityPub security', function () { // Invalid peertube actor cache await killallServers([ servers[1] ]) - await reRunServer(servers[1]) + await servers[1].run() const body = activityPubContextify(getAnnounceWithoutContext(servers[1])) const headers = buildGlobalHeaders(body) 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 ]) diff --git a/server/tests/api/live/live-constraints.ts b/server/tests/api/live/live-constraints.ts index 1c380883c..a00833569 100644 --- a/server/tests/api/live/live-constraints.ts +++ b/server/tests/api/live/live-constraints.ts @@ -8,8 +8,8 @@ import { cleanupTests, ConfigCommand, doubleFollow, - flushAndRunMultipleServers, - ServerInfo, + createMultipleServers, + PeerTubeServer, setAccessTokensToServers, setDefaultVideoChannel, wait, @@ -19,7 +19,7 @@ import { const expect = chai.expect describe('Test live constraints', function () { - let servers: ServerInfo[] = [] + let servers: PeerTubeServer[] = [] let userId: number let userAccessToken: string let userChannelId: number @@ -63,7 +63,7 @@ describe('Test live constraints', function () { before(async function () { this.timeout(120000) - servers = await flushAndRunMultipleServers(2) + servers = await createMultipleServers(2) // Get the access tokens await setAccessTokensToServers(servers) diff --git a/server/tests/api/live/live-permanent.ts b/server/tests/api/live/live-permanent.ts index 900bd6f5c..30d499e20 100644 --- a/server/tests/api/live/live-permanent.ts +++ b/server/tests/api/live/live-permanent.ts @@ -7,8 +7,8 @@ import { cleanupTests, ConfigCommand, doubleFollow, - flushAndRunMultipleServers, - ServerInfo, + createMultipleServers, + PeerTubeServer, setAccessTokensToServers, setDefaultVideoChannel, stopFfmpeg, @@ -19,7 +19,7 @@ import { const expect = chai.expect describe('Permanent live', function () { - let servers: ServerInfo[] = [] + let servers: PeerTubeServer[] = [] let videoUUID: string async function createLiveWrapper (permanentLive: boolean) { @@ -45,7 +45,7 @@ describe('Permanent live', function () { before(async function () { this.timeout(120000) - servers = await flushAndRunMultipleServers(2) + servers = await createMultipleServers(2) // Get the access tokens await setAccessTokensToServers(servers) diff --git a/server/tests/api/live/live-save-replay.ts b/server/tests/api/live/live-save-replay.ts index 7a33df90a..d403f27bf 100644 --- a/server/tests/api/live/live-save-replay.ts +++ b/server/tests/api/live/live-save-replay.ts @@ -9,8 +9,8 @@ import { cleanupTests, ConfigCommand, doubleFollow, - flushAndRunMultipleServers, - ServerInfo, + createMultipleServers, + PeerTubeServer, setAccessTokensToServers, setDefaultVideoChannel, stopFfmpeg, @@ -23,7 +23,7 @@ import { LiveVideoCreate, VideoPrivacy, VideoState } from '@shared/models' const expect = chai.expect describe('Save replay setting', function () { - let servers: ServerInfo[] = [] + let servers: PeerTubeServer[] = [] let liveVideoUUID: string let ffmpegCommand: FfmpegCommand @@ -82,7 +82,7 @@ describe('Save replay setting', function () { before(async function () { this.timeout(120000) - servers = await flushAndRunMultipleServers(2) + servers = await createMultipleServers(2) // Get the access tokens await setAccessTokensToServers(servers) diff --git a/server/tests/api/live/live-socket-messages.ts b/server/tests/api/live/live-socket-messages.ts index ad67d6285..3808964d1 100644 --- a/server/tests/api/live/live-socket-messages.ts +++ b/server/tests/api/live/live-socket-messages.ts @@ -6,8 +6,8 @@ import { VideoPrivacy, VideoState } from '@shared/models' import { cleanupTests, doubleFollow, - flushAndRunMultipleServers, - ServerInfo, + createMultipleServers, + PeerTubeServer, setAccessTokensToServers, setDefaultVideoChannel, stopFfmpeg, @@ -19,12 +19,12 @@ import { const expect = chai.expect describe('Test live', function () { - let servers: ServerInfo[] = [] + let servers: PeerTubeServer[] = [] before(async function () { this.timeout(120000) - servers = await flushAndRunMultipleServers(2) + servers = await createMultipleServers(2) // Get the access tokens await setAccessTokensToServers(servers) diff --git a/server/tests/api/live/live-views.ts b/server/tests/api/live/live-views.ts index 43222f9c9..4a137b185 100644 --- a/server/tests/api/live/live-views.ts +++ b/server/tests/api/live/live-views.ts @@ -7,8 +7,8 @@ import { VideoPrivacy } from '@shared/models' import { cleanupTests, doubleFollow, - flushAndRunMultipleServers, - ServerInfo, + createMultipleServers, + PeerTubeServer, setAccessTokensToServers, setDefaultVideoChannel, stopFfmpeg, @@ -20,12 +20,12 @@ import { const expect = chai.expect describe('Test live', function () { - let servers: ServerInfo[] = [] + let servers: PeerTubeServer[] = [] before(async function () { this.timeout(120000) - servers = await flushAndRunMultipleServers(2) + servers = await createMultipleServers(2) // Get the access tokens await setAccessTokensToServers(servers) diff --git a/server/tests/api/live/live.ts b/server/tests/api/live/live.ts index 2cce1f448..7cfac522c 100644 --- a/server/tests/api/live/live.ts +++ b/server/tests/api/live/live.ts @@ -11,13 +11,12 @@ import { checkResolutionsInMasterPlaylist, cleanupTests, doubleFollow, - flushAndRunMultipleServers, + createMultipleServers, killallServers, LiveCommand, makeRawRequest, - reRunServer, sendRTMPStream, - ServerInfo, + PeerTubeServer, setAccessTokensToServers, setDefaultVideoChannel, stopFfmpeg, @@ -32,13 +31,13 @@ import { LiveVideo, LiveVideoCreate, VideoDetails, VideoPrivacy, VideoState, Vid const expect = chai.expect describe('Test live', function () { - let servers: ServerInfo[] = [] + let servers: PeerTubeServer[] = [] let commands: LiveCommand[] before(async function () { this.timeout(120000) - servers = await flushAndRunMultipleServers(2) + servers = await createMultipleServers(2) // Get the access tokens await setAccessTokensToServers(servers) @@ -571,7 +570,7 @@ describe('Test live', function () { await commands[0].waitUntilSegmentGeneration({ videoUUID: liveVideoReplayId, resolution: 0, segment: 2 }) await killallServers([ servers[0] ]) - await reRunServer(servers[0]) + await servers[0].run() await wait(5000) }) diff --git a/server/tests/api/moderation/abuses.ts b/server/tests/api/moderation/abuses.ts index 97a0d95c4..360b9de35 100644 --- a/server/tests/api/moderation/abuses.ts +++ b/server/tests/api/moderation/abuses.ts @@ -6,8 +6,8 @@ import { AbusesCommand, cleanupTests, doubleFollow, - flushAndRunMultipleServers, - ServerInfo, + createMultipleServers, + PeerTubeServer, setAccessTokensToServers, waitJobs } from '@shared/extra-utils' @@ -16,7 +16,7 @@ import { AbuseMessage, AbusePredefinedReasonsString, AbuseState, AdminAbuse, Use const expect = chai.expect describe('Test abuses', function () { - let servers: ServerInfo[] = [] + let servers: PeerTubeServer[] = [] let abuseServer1: AdminAbuse let abuseServer2: AdminAbuse let commands: AbusesCommand[] @@ -25,7 +25,7 @@ describe('Test abuses', function () { this.timeout(50000) // Run servers - servers = await flushAndRunMultipleServers(2) + servers = await createMultipleServers(2) // Get the access tokens await setAccessTokensToServers(servers) @@ -389,7 +389,7 @@ describe('Test abuses', function () { describe('Comment abuses', function () { - async function getComment (server: ServerInfo, videoIdArg: number | string) { + async function getComment (server: PeerTubeServer, videoIdArg: number | string) { const videoId = typeof videoIdArg === 'string' ? await server.videos.getId({ uuid: videoIdArg }) : videoIdArg @@ -591,7 +591,7 @@ describe('Test abuses', function () { describe('Account abuses', function () { - function getAccountFromServer (server: ServerInfo, targetName: string, targetServer: ServerInfo) { + function getAccountFromServer (server: PeerTubeServer, targetName: string, targetServer: PeerTubeServer) { return server.accounts.get({ accountName: targetName + '@' + targetServer.host }) } diff --git a/server/tests/api/moderation/blocklist-notification.ts b/server/tests/api/moderation/blocklist-notification.ts index 6b56fdd65..fdfbcbced 100644 --- a/server/tests/api/moderation/blocklist-notification.ts +++ b/server/tests/api/moderation/blocklist-notification.ts @@ -2,12 +2,12 @@ import 'mocha' import * as chai from 'chai' -import { cleanupTests, doubleFollow, flushAndRunMultipleServers, ServerInfo, setAccessTokensToServers, waitJobs } from '@shared/extra-utils' +import { cleanupTests, doubleFollow, createMultipleServers, PeerTubeServer, setAccessTokensToServers, waitJobs } from '@shared/extra-utils' import { UserNotificationType } from '@shared/models' const expect = chai.expect -async function checkNotifications (server: ServerInfo, token: string, expected: UserNotificationType[]) { +async function checkNotifications (server: PeerTubeServer, token: string, expected: UserNotificationType[]) { const { data } = await server.notifications.list({ token, start: 0, count: 10, unread: true }) expect(data).to.have.lengthOf(expected.length) @@ -17,7 +17,7 @@ async function checkNotifications (server: ServerInfo, token: string, expected: } describe('Test blocklist', function () { - let servers: ServerInfo[] + let servers: PeerTubeServer[] let videoUUID: string let userToken1: string @@ -62,7 +62,7 @@ describe('Test blocklist', function () { before(async function () { this.timeout(60000) - servers = await flushAndRunMultipleServers(2) + servers = await createMultipleServers(2) await setAccessTokensToServers(servers) { diff --git a/server/tests/api/moderation/blocklist.ts b/server/tests/api/moderation/blocklist.ts index 9a4a3b3b9..593291e87 100644 --- a/server/tests/api/moderation/blocklist.ts +++ b/server/tests/api/moderation/blocklist.ts @@ -7,8 +7,8 @@ import { cleanupTests, CommentsCommand, doubleFollow, - flushAndRunMultipleServers, - ServerInfo, + createMultipleServers, + PeerTubeServer, setAccessTokensToServers, waitJobs } from '@shared/extra-utils' @@ -16,7 +16,7 @@ import { UserNotificationType } from '@shared/models' const expect = chai.expect -async function checkAllVideos (server: ServerInfo, token: string) { +async function checkAllVideos (server: PeerTubeServer, token: string) { { const { data } = await server.videos.listWithToken({ token }) expect(data).to.have.lengthOf(5) @@ -28,7 +28,7 @@ async function checkAllVideos (server: ServerInfo, token: string) { } } -async function checkAllComments (server: ServerInfo, token: string, videoUUID: string) { +async function checkAllComments (server: PeerTubeServer, token: string, videoUUID: string) { const { data } = await server.comments.listThreads({ videoId: videoUUID, start: 0, count: 25, sort: '-createdAt', token }) const threads = data.filter(t => t.isDeleted === false) @@ -41,8 +41,8 @@ async function checkAllComments (server: ServerInfo, token: string, videoUUID: s } async function checkCommentNotification ( - mainServer: ServerInfo, - comment: { server: ServerInfo, token: string, videoUUID: string, text: string }, + mainServer: PeerTubeServer, + comment: { server: PeerTubeServer, token: string, videoUUID: string, text: string }, check: 'presence' | 'absence' ) { const command = comment.server.comments @@ -63,7 +63,7 @@ async function checkCommentNotification ( } describe('Test blocklist', function () { - let servers: ServerInfo[] + let servers: PeerTubeServer[] let videoUUID1: string let videoUUID2: string let videoUUID3: string @@ -77,7 +77,7 @@ describe('Test blocklist', function () { before(async function () { this.timeout(120000) - servers = await flushAndRunMultipleServers(3) + servers = await createMultipleServers(3) await setAccessTokensToServers(servers) command = servers[0].blocklist diff --git a/server/tests/api/moderation/video-blacklist.ts b/server/tests/api/moderation/video-blacklist.ts index d23d23bcb..62cbf2e07 100644 --- a/server/tests/api/moderation/video-blacklist.ts +++ b/server/tests/api/moderation/video-blacklist.ts @@ -7,11 +7,10 @@ import { BlacklistCommand, cleanupTests, doubleFollow, - flushAndRunMultipleServers, + createMultipleServers, ImportsCommand, killallServers, - reRunServer, - ServerInfo, + PeerTubeServer, setAccessTokensToServers, waitJobs } from '@shared/extra-utils' @@ -20,11 +19,11 @@ import { UserAdminFlag, UserRole, VideoBlacklist, VideoBlacklistType } from '@sh const expect = chai.expect describe('Test video blacklist', function () { - let servers: ServerInfo[] = [] + let servers: PeerTubeServer[] = [] let videoId: number let command: BlacklistCommand - async function blacklistVideosOnServer (server: ServerInfo) { + async function blacklistVideosOnServer (server: PeerTubeServer) { const { data } = await server.videos.list() for (const video of data) { @@ -36,7 +35,7 @@ describe('Test video blacklist', function () { this.timeout(50000) // Run servers - servers = await flushAndRunMultipleServers(2) + servers = await createMultipleServers(2) // Get the access tokens await setAccessTokensToServers(servers) @@ -344,7 +343,7 @@ describe('Test video blacklist', function () { } } } - await reRunServer(servers[0], config) + await servers[0].run(config) { const user = { username: 'user_without_flag', password: 'password' } diff --git a/server/tests/api/notifications/admin-notifications.ts b/server/tests/api/notifications/admin-notifications.ts index 5a5bdb0c8..d65551f0a 100644 --- a/server/tests/api/notifications/admin-notifications.ts +++ b/server/tests/api/notifications/admin-notifications.ts @@ -10,13 +10,13 @@ import { MockJoinPeerTubeVersions, MockSmtpServer, prepareNotificationsTest, - ServerInfo, + PeerTubeServer, wait } from '@shared/extra-utils' import { PluginType, UserNotification, UserNotificationType } from '@shared/models' describe('Test admin notifications', function () { - let server: ServerInfo + let server: PeerTubeServer let userNotifications: UserNotification[] = [] let adminNotifications: UserNotification[] = [] let emails: object[] = [] diff --git a/server/tests/api/notifications/comments-notifications.ts b/server/tests/api/notifications/comments-notifications.ts index 133b6340f..d54819aaa 100644 --- a/server/tests/api/notifications/comments-notifications.ts +++ b/server/tests/api/notifications/comments-notifications.ts @@ -9,7 +9,7 @@ import { cleanupTests, MockSmtpServer, prepareNotificationsTest, - ServerInfo, + PeerTubeServer, waitJobs } from '@shared/extra-utils' import { UserNotification } from '@shared/models' @@ -17,7 +17,7 @@ import { UserNotification } from '@shared/models' const expect = chai.expect describe('Test comments notifications', function () { - let servers: ServerInfo[] = [] + let servers: PeerTubeServer[] = [] let userToken: string let userNotifications: UserNotification[] = [] let emails: object[] = [] diff --git a/server/tests/api/notifications/moderation-notifications.ts b/server/tests/api/notifications/moderation-notifications.ts index e7c5badd2..3a294192b 100644 --- a/server/tests/api/notifications/moderation-notifications.ts +++ b/server/tests/api/notifications/moderation-notifications.ts @@ -20,14 +20,14 @@ import { MockInstancesIndex, MockSmtpServer, prepareNotificationsTest, - ServerInfo, + PeerTubeServer, wait, waitJobs } from '@shared/extra-utils' import { AbuseState, CustomConfig, UserNotification, VideoPrivacy } from '@shared/models' describe('Test moderation notifications', function () { - let servers: ServerInfo[] = [] + let servers: PeerTubeServer[] = [] let userAccessToken: string let userNotifications: UserNotification[] = [] let adminNotifications: UserNotification[] = [] diff --git a/server/tests/api/notifications/notifications-api.ts b/server/tests/api/notifications/notifications-api.ts index 647d783b5..178b20687 100644 --- a/server/tests/api/notifications/notifications-api.ts +++ b/server/tests/api/notifications/notifications-api.ts @@ -9,7 +9,7 @@ import { getAllNotificationsSettings, MockSmtpServer, prepareNotificationsTest, - ServerInfo, + PeerTubeServer, waitJobs } from '@shared/extra-utils' import { UserNotification, UserNotificationSettingValue } from '@shared/models' @@ -17,7 +17,7 @@ import { UserNotification, UserNotificationSettingValue } from '@shared/models' const expect = chai.expect describe('Test notifications API', function () { - let server: ServerInfo + let server: PeerTubeServer let userNotifications: UserNotification[] = [] let userToken: string let emails: object[] = [] diff --git a/server/tests/api/notifications/user-notifications.ts b/server/tests/api/notifications/user-notifications.ts index 53f8c7594..b7c22d118 100644 --- a/server/tests/api/notifications/user-notifications.ts +++ b/server/tests/api/notifications/user-notifications.ts @@ -13,7 +13,7 @@ import { ImportsCommand, MockSmtpServer, prepareNotificationsTest, - ServerInfo, + PeerTubeServer, uploadRandomVideoOnServers, wait, waitJobs @@ -23,7 +23,7 @@ import { UserNotification, UserNotificationType, VideoPrivacy } from '@shared/mo const expect = chai.expect describe('Test user notifications', function () { - let servers: ServerInfo[] = [] + let servers: PeerTubeServer[] = [] let userAccessToken: string let userNotifications: UserNotification[] = [] let adminNotifications: UserNotification[] = [] diff --git a/server/tests/api/redundancy/manage-redundancy.ts b/server/tests/api/redundancy/manage-redundancy.ts index e193b968e..aff64e2eb 100644 --- a/server/tests/api/redundancy/manage-redundancy.ts +++ b/server/tests/api/redundancy/manage-redundancy.ts @@ -5,9 +5,9 @@ import * as chai from 'chai' import { cleanupTests, doubleFollow, - flushAndRunMultipleServers, + createMultipleServers, RedundancyCommand, - ServerInfo, + PeerTubeServer, setAccessTokensToServers, waitJobs } from '@shared/extra-utils' @@ -18,7 +18,7 @@ const expect = chai.expect describe('Test manage videos redundancy', function () { const targets: VideoRedundanciesTarget[] = [ 'my-videos', 'remote-videos' ] - let servers: ServerInfo[] + let servers: PeerTubeServer[] let video1Server2UUID: string let video2Server2UUID: string let redundanciesToRemove: number[] = [] @@ -48,7 +48,7 @@ describe('Test manage videos redundancy', function () { } } } - servers = await flushAndRunMultipleServers(3, config) + servers = await createMultipleServers(3, config) // Get the access tokens await setAccessTokensToServers(servers) diff --git a/server/tests/api/redundancy/redundancy-constraints.ts b/server/tests/api/redundancy/redundancy-constraints.ts index 0378cc122..217691fb6 100644 --- a/server/tests/api/redundancy/redundancy-constraints.ts +++ b/server/tests/api/redundancy/redundancy-constraints.ts @@ -4,19 +4,18 @@ import 'mocha' import { expect } from 'chai' import { cleanupTests, - flushAndRunServer, + createSingleServer, killallServers, - reRunServer, - ServerInfo, + PeerTubeServer, setAccessTokensToServers, waitJobs } from '@shared/extra-utils' import { VideoPrivacy } from '@shared/models' describe('Test redundancy constraints', function () { - let remoteServer: ServerInfo - let localServer: ServerInfo - let servers: ServerInfo[] + let remoteServer: PeerTubeServer + let localServer: PeerTubeServer + let servers: PeerTubeServer[] const remoteServerConfig = { redundancy: { @@ -59,7 +58,7 @@ describe('Test redundancy constraints', function () { this.timeout(120000) { - remoteServer = await flushAndRunServer(1, remoteServerConfig) + remoteServer = await createSingleServer(1, remoteServerConfig) } { @@ -70,7 +69,7 @@ describe('Test redundancy constraints', function () { } } } - localServer = await flushAndRunServer(2, config) + localServer = await createSingleServer(2, config) } servers = [ remoteServer, localServer ] @@ -119,7 +118,7 @@ describe('Test redundancy constraints', function () { } } await await killallServers([ localServer ]) - await reRunServer(localServer, config) + await localServer.run(config) await uploadWrapper('video 2 server 2') @@ -148,7 +147,7 @@ describe('Test redundancy constraints', function () { } } await killallServers([ localServer ]) - await reRunServer(localServer, config) + await localServer.run(config) await uploadWrapper('video 3 server 2') diff --git a/server/tests/api/redundancy/redundancy.ts b/server/tests/api/redundancy/redundancy.ts index 77ea2278e..9d5d96efd 100644 --- a/server/tests/api/redundancy/redundancy.ts +++ b/server/tests/api/redundancy/redundancy.ts @@ -11,12 +11,11 @@ import { checkVideoFilesWereRemoved, cleanupTests, doubleFollow, - flushAndRunMultipleServers, + createMultipleServers, killallServers, makeGetRequest, - reRunServer, root, - ServerInfo, + PeerTubeServer, setAccessTokensToServers, wait, waitJobs @@ -25,11 +24,11 @@ import { VideoPrivacy, VideoRedundancyStrategy, VideoRedundancyStrategyWithManua const expect = chai.expect -let servers: ServerInfo[] = [] +let servers: PeerTubeServer[] = [] let video1Server2UUID: string let video1Server2Id: number -function checkMagnetWebseeds (file: { magnetUri: string, resolution: { id: number } }, baseWebseeds: string[], server: ServerInfo) { +function checkMagnetWebseeds (file: { magnetUri: string, resolution: { id: number } }, baseWebseeds: string[], server: PeerTubeServer) { const parsed = magnetUtil.decode(file.magnetUri) for (const ws of baseWebseeds) { @@ -40,7 +39,7 @@ function checkMagnetWebseeds (file: { magnetUri: string, resolution: { id: numbe expect(parsed.urlList).to.have.lengthOf(baseWebseeds.length) } -async function flushAndRunServers (strategy: VideoRedundancyStrategy | null, additionalParams: any = {}, withWebtorrent = true) { +async function createSingleServers (strategy: VideoRedundancyStrategy | null, additionalParams: any = {}, withWebtorrent = true) { const strategies: any[] = [] if (strategy !== null) { @@ -72,7 +71,7 @@ async function flushAndRunServers (strategy: VideoRedundancyStrategy | null, add } } - servers = await flushAndRunMultipleServers(3, config) + servers = await createMultipleServers(3, config) // Get the access tokens await setAccessTokensToServers(servers) @@ -288,7 +287,7 @@ describe('Test videos redundancy', function () { before(function () { this.timeout(120000) - return flushAndRunServers(strategy) + return createSingleServers(strategy) }) it('Should have 1 webseed on the first video', async function () { @@ -338,7 +337,7 @@ describe('Test videos redundancy', function () { before(function () { this.timeout(120000) - return flushAndRunServers(strategy) + return createSingleServers(strategy) }) it('Should have 1 webseed on the first video', async function () { @@ -388,7 +387,7 @@ describe('Test videos redundancy', function () { before(function () { this.timeout(120000) - return flushAndRunServers(strategy, { min_views: 3 }) + return createSingleServers(strategy, { min_views: 3 }) }) it('Should have 1 webseed on the first video', async function () { @@ -458,7 +457,7 @@ describe('Test videos redundancy', function () { before(async function () { this.timeout(120000) - await flushAndRunServers(strategy, { min_views: 3 }, false) + await createSingleServers(strategy, { min_views: 3 }, false) }) it('Should have 0 playlist redundancy on the first video', async function () { @@ -519,7 +518,7 @@ describe('Test videos redundancy', function () { before(function () { this.timeout(120000) - return flushAndRunServers(null) + return createSingleServers(null) }) it('Should have 1 webseed on the first video', async function () { @@ -575,7 +574,7 @@ describe('Test videos redundancy', function () { describe('Test expiration', function () { const strategy = 'recently-added' - async function checkContains (servers: ServerInfo[], str: string) { + async function checkContains (servers: PeerTubeServer[], str: string) { for (const server of servers) { const video = await server.videos.get({ id: video1Server2UUID }) @@ -585,7 +584,7 @@ describe('Test videos redundancy', function () { } } - async function checkNotContains (servers: ServerInfo[], str: string) { + async function checkNotContains (servers: PeerTubeServer[], str: string) { for (const server of servers) { const video = await server.videos.get({ id: video1Server2UUID }) @@ -598,7 +597,7 @@ describe('Test videos redundancy', function () { before(async function () { this.timeout(120000) - await flushAndRunServers(strategy, { min_lifetime: '7 seconds', min_views: 0 }) + await createSingleServers(strategy, { min_lifetime: '7 seconds', min_views: 0 }) await enableRedundancyOnServer1() }) @@ -640,7 +639,7 @@ describe('Test videos redundancy', function () { before(async function () { this.timeout(120000) - await flushAndRunServers(strategy, { min_lifetime: '7 seconds', min_views: 0 }) + await createSingleServers(strategy, { min_lifetime: '7 seconds', min_views: 0 }) await enableRedundancyOnServer1() @@ -691,7 +690,7 @@ describe('Test videos redundancy', function () { await waitJobs(servers) await killallServers([ servers[0] ]) - await reRunServer(servers[0], { + await servers[0].run({ redundancy: { videos: { check_interval: '1 second', diff --git a/server/tests/api/search/search-activitypub-video-channels.ts b/server/tests/api/search/search-activitypub-video-channels.ts index 71e9367e5..f5896ec25 100644 --- a/server/tests/api/search/search-activitypub-video-channels.ts +++ b/server/tests/api/search/search-activitypub-video-channels.ts @@ -4,9 +4,9 @@ import 'mocha' import * as chai from 'chai' import { cleanupTests, - flushAndRunMultipleServers, + createMultipleServers, SearchCommand, - ServerInfo, + PeerTubeServer, setAccessTokensToServers, wait, waitJobs @@ -16,7 +16,7 @@ import { VideoChannel } from '@shared/models' const expect = chai.expect describe('Test ActivityPub video channels search', function () { - let servers: ServerInfo[] + let servers: PeerTubeServer[] let userServer2Token: string let videoServer2UUID: string let channelIdServer2: number @@ -25,7 +25,7 @@ describe('Test ActivityPub video channels search', function () { before(async function () { this.timeout(120000) - servers = await flushAndRunMultipleServers(2) + servers = await createMultipleServers(2) await setAccessTokensToServers(servers) diff --git a/server/tests/api/search/search-activitypub-video-playlists.ts b/server/tests/api/search/search-activitypub-video-playlists.ts index 7c99b954b..ada2d3d6c 100644 --- a/server/tests/api/search/search-activitypub-video-playlists.ts +++ b/server/tests/api/search/search-activitypub-video-playlists.ts @@ -4,9 +4,9 @@ import 'mocha' import * as chai from 'chai' import { cleanupTests, - flushAndRunMultipleServers, + createMultipleServers, SearchCommand, - ServerInfo, + PeerTubeServer, setAccessTokensToServers, setDefaultVideoChannel, wait, @@ -17,7 +17,7 @@ import { VideoPlaylistPrivacy } from '@shared/models' const expect = chai.expect describe('Test ActivityPub playlists search', function () { - let servers: ServerInfo[] + let servers: PeerTubeServer[] let playlistServer1UUID: string let playlistServer2UUID: string let video2Server2: string @@ -27,7 +27,7 @@ describe('Test ActivityPub playlists search', function () { before(async function () { this.timeout(120000) - servers = await flushAndRunMultipleServers(2) + servers = await createMultipleServers(2) await setAccessTokensToServers(servers) await setDefaultVideoChannel(servers) diff --git a/server/tests/api/search/search-activitypub-videos.ts b/server/tests/api/search/search-activitypub-videos.ts index 0dfc63446..a015b72a7 100644 --- a/server/tests/api/search/search-activitypub-videos.ts +++ b/server/tests/api/search/search-activitypub-videos.ts @@ -4,9 +4,9 @@ import 'mocha' import * as chai from 'chai' import { cleanupTests, - flushAndRunMultipleServers, + createMultipleServers, SearchCommand, - ServerInfo, + PeerTubeServer, setAccessTokensToServers, wait, waitJobs @@ -16,7 +16,7 @@ import { VideoPrivacy } from '@shared/models' const expect = chai.expect describe('Test ActivityPub videos search', function () { - let servers: ServerInfo[] + let servers: PeerTubeServer[] let videoServer1UUID: string let videoServer2UUID: string @@ -25,7 +25,7 @@ describe('Test ActivityPub videos search', function () { before(async function () { this.timeout(120000) - servers = await flushAndRunMultipleServers(2) + servers = await createMultipleServers(2) await setAccessTokensToServers(servers) diff --git a/server/tests/api/search/search-channels.ts b/server/tests/api/search/search-channels.ts index 7035fbd62..07e00a214 100644 --- a/server/tests/api/search/search-channels.ts +++ b/server/tests/api/search/search-channels.ts @@ -2,19 +2,19 @@ import 'mocha' import * as chai from 'chai' -import { cleanupTests, flushAndRunServer, SearchCommand, ServerInfo, setAccessTokensToServers } from '@shared/extra-utils' +import { cleanupTests, createSingleServer, SearchCommand, PeerTubeServer, setAccessTokensToServers } from '@shared/extra-utils' import { VideoChannel } from '@shared/models' const expect = chai.expect describe('Test channels search', function () { - let server: ServerInfo = null + let server: PeerTubeServer = null let command: SearchCommand before(async function () { this.timeout(30000) - server = await flushAndRunServer(1) + server = await createSingleServer(1) await setAccessTokensToServers([ server ]) diff --git a/server/tests/api/search/search-index.ts b/server/tests/api/search/search-index.ts index b54c0da22..38edcf7c6 100644 --- a/server/tests/api/search/search-index.ts +++ b/server/tests/api/search/search-index.ts @@ -2,7 +2,7 @@ import 'mocha' import * as chai from 'chai' -import { cleanupTests, flushAndRunServer, SearchCommand, ServerInfo, setAccessTokensToServers } from '@shared/extra-utils' +import { cleanupTests, createSingleServer, SearchCommand, PeerTubeServer, setAccessTokensToServers } from '@shared/extra-utils' import { BooleanBothQuery, VideoPlaylistPrivacy, VideoPlaylistType, VideosSearchQuery } from '@shared/models' const expect = chai.expect @@ -10,13 +10,13 @@ const expect = chai.expect describe('Test videos search', function () { const localVideoName = 'local video' + new Date().toISOString() - let server: ServerInfo = null + let server: PeerTubeServer = null let command: SearchCommand before(async function () { this.timeout(30000) - server = await flushAndRunServer(1) + server = await createSingleServer(1) await setAccessTokensToServers([ server ]) diff --git a/server/tests/api/search/search-playlists.ts b/server/tests/api/search/search-playlists.ts index e15128c8e..b29c2d127 100644 --- a/server/tests/api/search/search-playlists.ts +++ b/server/tests/api/search/search-playlists.ts @@ -4,9 +4,9 @@ import 'mocha' import * as chai from 'chai' import { cleanupTests, - flushAndRunServer, + createSingleServer, SearchCommand, - ServerInfo, + PeerTubeServer, setAccessTokensToServers, setDefaultVideoChannel } from '@shared/extra-utils' @@ -15,13 +15,13 @@ import { VideoPlaylistPrivacy } from '@shared/models' const expect = chai.expect describe('Test playlists search', function () { - let server: ServerInfo = null + let server: PeerTubeServer = null let command: SearchCommand 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/search/search-videos.ts b/server/tests/api/search/search-videos.ts index 478ebafc9..a9b0a4fcd 100644 --- a/server/tests/api/search/search-videos.ts +++ b/server/tests/api/search/search-videos.ts @@ -4,9 +4,9 @@ import 'mocha' import * as chai from 'chai' import { cleanupTests, - flushAndRunServer, + createSingleServer, SearchCommand, - ServerInfo, + PeerTubeServer, setAccessTokensToServers, setDefaultVideoChannel, stopFfmpeg, @@ -17,7 +17,7 @@ import { VideoPrivacy } from '@shared/models' const expect = chai.expect describe('Test videos search', function () { - let server: ServerInfo = null + let server: PeerTubeServer = null let startDate: string let videoUUID: string @@ -26,7 +26,7 @@ describe('Test videos search', function () { before(async function () { this.timeout(60000) - server = await flushAndRunServer(1) + server = await createSingleServer(1) await setAccessTokensToServers([ server ]) await setDefaultVideoChannel([ server ]) diff --git a/server/tests/api/server/auto-follows.ts b/server/tests/api/server/auto-follows.ts index e9fb5b4b1..8dca2e5e5 100644 --- a/server/tests/api/server/auto-follows.ts +++ b/server/tests/api/server/auto-follows.ts @@ -4,9 +4,9 @@ import 'mocha' import * as chai from 'chai' import { cleanupTests, - flushAndRunMultipleServers, + createMultipleServers, MockInstancesIndex, - ServerInfo, + PeerTubeServer, setAccessTokensToServers, wait, waitJobs @@ -14,7 +14,7 @@ import { const expect = chai.expect -async function checkFollow (follower: ServerInfo, following: ServerInfo, exists: boolean) { +async function checkFollow (follower: PeerTubeServer, following: PeerTubeServer, exists: boolean) { { const body = await following.follows.getFollowers({ start: 0, count: 5, sort: '-createdAt' }) const follow = body.data.find(f => f.follower.host === follower.host && f.state === 'accepted') @@ -32,13 +32,13 @@ async function checkFollow (follower: ServerInfo, following: ServerInfo, exists: } } -async function server1Follows2 (servers: ServerInfo[]) { +async function server1Follows2 (servers: PeerTubeServer[]) { await servers[0].follows.follow({ targets: [ servers[1].host ] }) await waitJobs(servers) } -async function resetFollows (servers: ServerInfo[]) { +async function resetFollows (servers: PeerTubeServer[]) { try { await servers[0].follows.unfollow({ target: servers[1] }) await servers[1].follows.unfollow({ target: servers[0] }) @@ -52,12 +52,12 @@ async function resetFollows (servers: ServerInfo[]) { } describe('Test auto follows', function () { - let servers: ServerInfo[] = [] + let servers: PeerTubeServer[] = [] before(async function () { this.timeout(30000) - servers = await flushAndRunMultipleServers(3) + servers = await createMultipleServers(3) // Get the access tokens await setAccessTokensToServers(servers) diff --git a/server/tests/api/server/bulk.ts b/server/tests/api/server/bulk.ts index acc17092d..5d8c87983 100644 --- a/server/tests/api/server/bulk.ts +++ b/server/tests/api/server/bulk.ts @@ -6,8 +6,8 @@ import { BulkCommand, cleanupTests, doubleFollow, - flushAndRunMultipleServers, - ServerInfo, + createMultipleServers, + PeerTubeServer, setAccessTokensToServers, waitJobs } from '@shared/extra-utils' @@ -17,7 +17,7 @@ const expect = chai.expect describe('Test bulk actions', function () { const commentsUser3: { videoId: number, commentId: number }[] = [] - let servers: ServerInfo[] = [] + let servers: PeerTubeServer[] = [] let user1Token: string let user2Token: string let user3Token: string @@ -27,7 +27,7 @@ describe('Test bulk actions', function () { before(async function () { this.timeout(30000) - servers = await flushAndRunMultipleServers(2) + servers = await createMultipleServers(2) // Get the access tokens await setAccessTokensToServers(servers) diff --git a/server/tests/api/server/config.ts b/server/tests/api/server/config.ts index 479e177a8..a7191c5ef 100644 --- a/server/tests/api/server/config.ts +++ b/server/tests/api/server/config.ts @@ -5,19 +5,18 @@ import * as chai from 'chai' import { HttpStatusCode } from '@shared/core-utils' import { cleanupTests, - flushAndRunServer, + createSingleServer, killallServers, makeGetRequest, parallelTests, - reRunServer, - ServerInfo, + PeerTubeServer, setAccessTokensToServers } from '@shared/extra-utils' import { CustomConfig } from '@shared/models' const expect = chai.expect -function checkInitialConfig (server: ServerInfo, data: CustomConfig) { +function checkInitialConfig (server: PeerTubeServer, data: CustomConfig) { expect(data.instance.name).to.equal('PeerTube') expect(data.instance.shortDescription).to.equal( 'PeerTube, an ActivityPub-federated video streaming platform using P2P directly in your web browser.' @@ -204,12 +203,12 @@ function checkUpdatedConfig (data: CustomConfig) { } describe('Test config', function () { - let server: ServerInfo = null + let server: PeerTubeServer = null before(async function () { this.timeout(30000) - server = await flushAndRunServer(1) + server = await createSingleServer(1) await setAccessTokensToServers([ server ]) }) @@ -456,7 +455,7 @@ describe('Test config', function () { await killallServers([ server ]) - await reRunServer(server) + await server.run() const data = await server.config.getCustomConfig() @@ -512,7 +511,7 @@ describe('Test config', function () { frameguard: { enabled: false } } } - server = await reRunServer(server, config) + await server.run(config) { const res = await makeGetRequest({ diff --git a/server/tests/api/server/contact-form.ts b/server/tests/api/server/contact-form.ts index 353fed80a..f0905bb3b 100644 --- a/server/tests/api/server/contact-form.ts +++ b/server/tests/api/server/contact-form.ts @@ -3,13 +3,21 @@ import 'mocha' import * as chai from 'chai' import { HttpStatusCode } from '@shared/core-utils' -import { cleanupTests, flushAndRunServer, MockSmtpServer, ServerInfo, setAccessTokensToServers, wait, waitJobs } from '@shared/extra-utils' -import { ContactFormCommand } from '@shared/extra-utils/server' +import { + cleanupTests, + ContactFormCommand, + createSingleServer, + MockSmtpServer, + PeerTubeServer, + setAccessTokensToServers, + wait, + waitJobs +} from '@shared/extra-utils' const expect = chai.expect describe('Test contact form', function () { - let server: ServerInfo + let server: PeerTubeServer const emails: object[] = [] let command: ContactFormCommand @@ -24,7 +32,7 @@ describe('Test contact form', function () { port } } - server = await flushAndRunServer(1, overrideConfig) + server = await createSingleServer(1, overrideConfig) await setAccessTokensToServers([ server ]) command = server.contactForm diff --git a/server/tests/api/server/email.ts b/server/tests/api/server/email.ts index 258e835e7..b202cf8a7 100644 --- a/server/tests/api/server/email.ts +++ b/server/tests/api/server/email.ts @@ -3,12 +3,12 @@ import 'mocha' import * as chai from 'chai' import { HttpStatusCode } from '@shared/core-utils' -import { cleanupTests, flushAndRunServer, MockSmtpServer, ServerInfo, setAccessTokensToServers, waitJobs } from '@shared/extra-utils' +import { cleanupTests, createSingleServer, MockSmtpServer, PeerTubeServer, setAccessTokensToServers, waitJobs } from '@shared/extra-utils' const expect = chai.expect describe('Test emails', function () { - let server: ServerInfo + let server: PeerTubeServer let userId: number let userId2: number let userAccessToken: string @@ -39,7 +39,7 @@ describe('Test emails', function () { port: emailPort } } - server = await flushAndRunServer(1, overrideConfig) + server = await createSingleServer(1, overrideConfig) await setAccessTokensToServers([ server ]) { diff --git a/server/tests/api/server/follow-constraints.ts b/server/tests/api/server/follow-constraints.ts index 887e400e9..4ed593b76 100644 --- a/server/tests/api/server/follow-constraints.ts +++ b/server/tests/api/server/follow-constraints.ts @@ -3,13 +3,13 @@ import 'mocha' import * as chai from 'chai' import { HttpStatusCode } from '@shared/core-utils' -import { cleanupTests, doubleFollow, flushAndRunMultipleServers, ServerInfo, setAccessTokensToServers } from '@shared/extra-utils' +import { cleanupTests, doubleFollow, createMultipleServers, PeerTubeServer, setAccessTokensToServers } from '@shared/extra-utils' import { PeerTubeProblemDocument, ServerErrorCode } from '@shared/models' const expect = chai.expect describe('Test follow constraints', function () { - let servers: ServerInfo[] = [] + let servers: PeerTubeServer[] = [] let video1UUID: string let video2UUID: string let userToken: string @@ -17,7 +17,7 @@ describe('Test follow constraints', function () { before(async function () { this.timeout(90000) - servers = await flushAndRunMultipleServers(2) + servers = await createMultipleServers(2) // Get the access tokens await setAccessTokensToServers(servers) diff --git a/server/tests/api/server/follows-moderation.ts b/server/tests/api/server/follows-moderation.ts index 045024544..0aa328c5a 100644 --- a/server/tests/api/server/follows-moderation.ts +++ b/server/tests/api/server/follows-moderation.ts @@ -4,16 +4,16 @@ import 'mocha' import * as chai from 'chai' import { cleanupTests, - flushAndRunMultipleServers, + createMultipleServers, FollowsCommand, - ServerInfo, + PeerTubeServer, setAccessTokensToServers, waitJobs } from '@shared/extra-utils' const expect = chai.expect -async function checkServer1And2HasFollowers (servers: ServerInfo[], state = 'accepted') { +async function checkServer1And2HasFollowers (servers: PeerTubeServer[], state = 'accepted') { const fns = [ servers[0].follows.getFollowings.bind(servers[0].follows), servers[1].follows.getFollowers.bind(servers[1].follows) @@ -30,7 +30,7 @@ async function checkServer1And2HasFollowers (servers: ServerInfo[], state = 'acc } } -async function checkNoFollowers (servers: ServerInfo[]) { +async function checkNoFollowers (servers: PeerTubeServer[]) { const fns = [ servers[0].follows.getFollowings.bind(servers[0].follows), servers[1].follows.getFollowers.bind(servers[1].follows) @@ -43,13 +43,13 @@ async function checkNoFollowers (servers: ServerInfo[]) { } describe('Test follows moderation', function () { - let servers: ServerInfo[] = [] + let servers: PeerTubeServer[] = [] let commands: FollowsCommand[] before(async function () { this.timeout(30000) - servers = await flushAndRunMultipleServers(3) + servers = await createMultipleServers(3) // Get the access tokens await setAccessTokensToServers(servers) diff --git a/server/tests/api/server/follows.ts b/server/tests/api/server/follows.ts index d43064689..8856177b8 100644 --- a/server/tests/api/server/follows.ts +++ b/server/tests/api/server/follows.ts @@ -7,9 +7,9 @@ import { completeVideoCheck, dateIsValid, expectAccountFollows, - flushAndRunMultipleServers, + createMultipleServers, FollowsCommand, - ServerInfo, + PeerTubeServer, setAccessTokensToServers, testCaptionFile, waitJobs @@ -19,13 +19,13 @@ import { Video, VideoPrivacy } from '@shared/models' const expect = chai.expect describe('Test follows', function () { - let servers: ServerInfo[] = [] + let servers: PeerTubeServer[] = [] let followsCommands: FollowsCommand[] before(async function () { this.timeout(30000) - servers = await flushAndRunMultipleServers(3) + servers = await createMultipleServers(3) followsCommands = servers.map(s => s.follows) // Get the access tokens diff --git a/server/tests/api/server/handle-down.ts b/server/tests/api/server/handle-down.ts index de3dee826..5f20b0093 100644 --- a/server/tests/api/server/handle-down.ts +++ b/server/tests/api/server/handle-down.ts @@ -7,10 +7,9 @@ import { cleanupTests, CommentsCommand, completeVideoCheck, - flushAndRunMultipleServers, + createMultipleServers, killallServers, - reRunServer, - ServerInfo, + PeerTubeServer, setAccessTokensToServers, wait, waitJobs @@ -20,7 +19,7 @@ import { JobState, VideoCreateResult, VideoPrivacy } from '@shared/models' const expect = chai.expect describe('Test handle downs', function () { - let servers: ServerInfo[] = [] + let servers: PeerTubeServer[] = [] let threadIdServer1: number let threadIdServer2: number let commentIdServer1: number @@ -54,7 +53,7 @@ describe('Test handle downs', function () { before(async function () { this.timeout(30000) - servers = await flushAndRunMultipleServers(3) + servers = await createMultipleServers(3) commentCommands = servers.map(s => s.comments) checkAttributes = { @@ -176,8 +175,8 @@ describe('Test handle downs', function () { it('Should re-follow server 1', async function () { this.timeout(35000) - await reRunServer(servers[1]) - await reRunServer(servers[2]) + await servers[1].run() + await servers[2].run() await servers[1].follows.unfollow({ target: servers[0] }) await waitJobs(servers) diff --git a/server/tests/api/server/homepage.ts b/server/tests/api/server/homepage.ts index aac075321..c291037f2 100644 --- a/server/tests/api/server/homepage.ts +++ b/server/tests/api/server/homepage.ts @@ -6,29 +6,28 @@ import { HttpStatusCode } from '@shared/core-utils' import { cleanupTests, CustomPagesCommand, - flushAndRunServer, + createSingleServer, killallServers, - reRunServer, - ServerInfo, + PeerTubeServer, setAccessTokensToServers } from '../../../../shared/extra-utils/index' const expect = chai.expect -async function getHomepageState (server: ServerInfo) { +async function getHomepageState (server: PeerTubeServer) { const config = await server.config.getConfig() return config.homepage.enabled } describe('Test instance homepage actions', function () { - let server: ServerInfo + let server: PeerTubeServer let command: CustomPagesCommand before(async function () { this.timeout(30000) - server = await flushAndRunServer(1) + server = await createSingleServer(1) await setAccessTokensToServers([ server ]) command = server.customPage @@ -56,7 +55,7 @@ describe('Test instance homepage actions', function () { await killallServers([ server ]) - await reRunServer(server) + await server.run() const page = await command.getInstanceHomepage() expect(page.content).to.equal('') diff --git a/server/tests/api/server/jobs.ts b/server/tests/api/server/jobs.ts index 0c44e4dad..376cd10d0 100644 --- a/server/tests/api/server/jobs.ts +++ b/server/tests/api/server/jobs.ts @@ -6,8 +6,8 @@ import { cleanupTests, dateIsValid, doubleFollow, - flushAndRunMultipleServers, - ServerInfo, + createMultipleServers, + PeerTubeServer, setAccessTokensToServers, waitJobs } from '@shared/extra-utils' @@ -15,12 +15,12 @@ import { const expect = chai.expect describe('Test jobs', function () { - let servers: ServerInfo[] + let servers: PeerTubeServer[] before(async function () { this.timeout(30000) - servers = await flushAndRunMultipleServers(2) + servers = await createMultipleServers(2) await setAccessTokensToServers(servers) diff --git a/server/tests/api/server/logs.ts b/server/tests/api/server/logs.ts index 2d141fd8c..bcd94dda3 100644 --- a/server/tests/api/server/logs.ts +++ b/server/tests/api/server/logs.ts @@ -4,11 +4,10 @@ import 'mocha' import * as chai from 'chai' import { cleanupTests, - flushAndRunServer, + createSingleServer, killallServers, LogsCommand, - reRunServer, - ServerInfo, + PeerTubeServer, setAccessTokensToServers, waitJobs } from '@shared/extra-utils' @@ -16,13 +15,13 @@ import { const expect = chai.expect describe('Test logs', function () { - let server: ServerInfo + let server: PeerTubeServer let logsCommand: LogsCommand before(async function () { this.timeout(30000) - server = await flushAndRunServer(1) + server = await createSingleServer(1) await setAccessTokensToServers([ server ]) logsCommand = server.logs @@ -113,7 +112,7 @@ describe('Test logs', function () { await killallServers([ server ]) - await reRunServer(server, { log: { log_ping_requests: false } }) + await server.run({ log: { log_ping_requests: false } }) const now = new Date() diff --git a/server/tests/api/server/no-client.ts b/server/tests/api/server/no-client.ts index d589f51f3..f45222f2f 100644 --- a/server/tests/api/server/no-client.ts +++ b/server/tests/api/server/no-client.ts @@ -1,16 +1,16 @@ import 'mocha' import * as request from 'supertest' -import { ServerInfo } from '../../../../shared/extra-utils' -import { cleanupTests, flushAndRunServer } from '../../../../shared/extra-utils/server/servers' +import { PeerTubeServer } from '../../../../shared/extra-utils' +import { cleanupTests, createSingleServer } from '../../../../shared/extra-utils/server/servers' import { HttpStatusCode } from '../../../../shared/core-utils/miscs/http-error-codes' describe('Start and stop server without web client routes', function () { - let server: ServerInfo + let server: PeerTubeServer before(async function () { this.timeout(30000) - server = await flushAndRunServer(1, {}, [ '--no-client' ]) + server = await createSingleServer(1, {}, [ '--no-client' ]) }) it('Should fail getting the client', function () { diff --git a/server/tests/api/server/plugins.ts b/server/tests/api/server/plugins.ts index 45a22e48d..db03d026a 100644 --- a/server/tests/api/server/plugins.ts +++ b/server/tests/api/server/plugins.ts @@ -5,11 +5,10 @@ import * as chai from 'chai' import { HttpStatusCode } from '@shared/core-utils' import { cleanupTests, - flushAndRunServer, + createSingleServer, killallServers, PluginsCommand, - reRunServer, - ServerInfo, + PeerTubeServer, setAccessTokensToServers, testHelloWorldRegisteredSettings, wait @@ -19,7 +18,7 @@ import { PluginType } from '@shared/models' const expect = chai.expect describe('Test plugins', function () { - let server: ServerInfo = null + let server: PeerTubeServer = null let command: PluginsCommand before(async function () { @@ -30,7 +29,7 @@ describe('Test plugins', function () { index: { check_latest_versions_interval: '5 seconds' } } } - server = await flushAndRunServer(1, configOverride) + server = await createSingleServer(1, configOverride) await setAccessTokensToServers([ server ]) command = server.plugins @@ -245,7 +244,7 @@ describe('Test plugins', function () { // Restart the server to take into account this change await killallServers([ server ]) - await reRunServer(server) + await server.run() { const body = await command.list({ pluginType: PluginType.PLUGIN }) @@ -326,7 +325,7 @@ describe('Test plugins', function () { await check() await killallServers([ server ]) - await reRunServer(server) + await server.run() await check() }) diff --git a/server/tests/api/server/reverse-proxy.ts b/server/tests/api/server/reverse-proxy.ts index de3cf02f2..c20b7a5f0 100644 --- a/server/tests/api/server/reverse-proxy.ts +++ b/server/tests/api/server/reverse-proxy.ts @@ -2,10 +2,10 @@ import { expect } from 'chai' import { HttpStatusCode } from '@shared/core-utils' -import { cleanupTests, flushAndRunServer, ServerInfo, setAccessTokensToServers, wait } from '@shared/extra-utils' +import { cleanupTests, createSingleServer, PeerTubeServer, setAccessTokensToServers, wait } from '@shared/extra-utils' describe('Test application behind a reverse proxy', function () { - let server: ServerInfo + let server: PeerTubeServer let videoId: string before(async function () { @@ -30,7 +30,7 @@ describe('Test application behind a reverse proxy', function () { } } - server = await flushAndRunServer(1, config) + server = await createSingleServer(1, config) await setAccessTokensToServers([ server ]) const { uuid } = await server.videos.upload() diff --git a/server/tests/api/server/services.ts b/server/tests/api/server/services.ts index 28f9ae3b6..69d030dbb 100644 --- a/server/tests/api/server/services.ts +++ b/server/tests/api/server/services.ts @@ -2,13 +2,13 @@ import 'mocha' import * as chai from 'chai' -import { cleanupTests, flushAndRunServer, ServerInfo, setAccessTokensToServers, setDefaultVideoChannel } from '@shared/extra-utils' +import { cleanupTests, createSingleServer, PeerTubeServer, setAccessTokensToServers, setDefaultVideoChannel } from '@shared/extra-utils' import { Video, VideoPlaylistPrivacy } from '@shared/models' const expect = chai.expect describe('Test services', function () { - let server: ServerInfo = null + let server: PeerTubeServer = null let playlistUUID: string let playlistDisplayName: string let video: Video @@ -16,7 +16,7 @@ describe('Test services', 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/server/stats.ts b/server/tests/api/server/stats.ts index be5abad52..f07d0fd39 100644 --- a/server/tests/api/server/stats.ts +++ b/server/tests/api/server/stats.ts @@ -5,8 +5,8 @@ import * as chai from 'chai' import { cleanupTests, doubleFollow, - flushAndRunMultipleServers, - ServerInfo, + createMultipleServers, + PeerTubeServer, setAccessTokensToServers, wait, waitJobs @@ -16,7 +16,7 @@ import { ActivityType, VideoPlaylistPrivacy } from '@shared/models' const expect = chai.expect describe('Test stats (excluding redundancy)', function () { - let servers: ServerInfo[] = [] + let servers: PeerTubeServer[] = [] let channelId const user = { username: 'user1', @@ -26,7 +26,7 @@ describe('Test stats (excluding redundancy)', function () { before(async function () { this.timeout(60000) - servers = await flushAndRunMultipleServers(3) + servers = await createMultipleServers(3) await setAccessTokensToServers(servers) diff --git a/server/tests/api/server/tracker.ts b/server/tests/api/server/tracker.ts index d80362fee..f597ac60c 100644 --- a/server/tests/api/server/tracker.ts +++ b/server/tests/api/server/tracker.ts @@ -3,16 +3,16 @@ import 'mocha' import * as magnetUtil from 'magnet-uri' import * as WebTorrent from 'webtorrent' -import { cleanupTests, flushAndRunServer, killallServers, reRunServer, ServerInfo, setAccessTokensToServers } from '@shared/extra-utils' +import { cleanupTests, createSingleServer, killallServers, PeerTubeServer, setAccessTokensToServers } from '@shared/extra-utils' describe('Test tracker', function () { - let server: ServerInfo + let server: PeerTubeServer let badMagnet: string let goodMagnet: string before(async function () { this.timeout(60000) - server = await flushAndRunServer(1) + server = await createSingleServer(1) await setAccessTokensToServers([ server ]) { @@ -48,7 +48,7 @@ describe('Test tracker', function () { const errCb = () => done(new Error('Tracker is enabled')) killallServers([ server ]) - .then(() => reRunServer(server, { tracker: { enabled: false } })) + .then(() => server.run({ tracker: { enabled: false } })) .then(() => { const webtorrent = new WebTorrent() @@ -72,7 +72,7 @@ describe('Test tracker', function () { this.timeout(20000) killallServers([ server ]) - .then(() => reRunServer(server)) + .then(() => server.run()) .then(() => { const webtorrent = new WebTorrent() diff --git a/server/tests/api/users/user-subscriptions.ts b/server/tests/api/users/user-subscriptions.ts index 1b15a98dc..d2bb9c387 100644 --- a/server/tests/api/users/user-subscriptions.ts +++ b/server/tests/api/users/user-subscriptions.ts @@ -5,8 +5,8 @@ import * as chai from 'chai' import { cleanupTests, doubleFollow, - flushAndRunMultipleServers, - ServerInfo, + createMultipleServers, + PeerTubeServer, setAccessTokensToServers, SubscriptionsCommand, waitJobs @@ -15,7 +15,7 @@ import { const expect = chai.expect describe('Test users subscriptions', function () { - let servers: ServerInfo[] = [] + let servers: PeerTubeServer[] = [] const users: { accessToken: string }[] = [] let video3UUID: string @@ -24,7 +24,7 @@ describe('Test users subscriptions', function () { before(async function () { this.timeout(120000) - servers = await flushAndRunMultipleServers(3) + servers = await createMultipleServers(3) // Get the access tokens await setAccessTokensToServers(servers) diff --git a/server/tests/api/users/users-multiple-servers.ts b/server/tests/api/users/users-multiple-servers.ts index f8d7ae88e..e629966bb 100644 --- a/server/tests/api/users/users-multiple-servers.ts +++ b/server/tests/api/users/users-multiple-servers.ts @@ -8,8 +8,8 @@ import { checkVideoFilesWereRemoved, cleanupTests, doubleFollow, - flushAndRunMultipleServers, - ServerInfo, + createMultipleServers, + PeerTubeServer, setAccessTokensToServers, testImage, waitJobs @@ -19,7 +19,7 @@ import { User } from '@shared/models' const expect = chai.expect describe('Test users with multiple servers', function () { - let servers: ServerInfo[] = [] + let servers: PeerTubeServer[] = [] let user: User let userId: number let videoUUID: string @@ -29,7 +29,7 @@ describe('Test users with multiple servers', function () { before(async function () { this.timeout(120_000) - servers = await flushAndRunMultipleServers(3) + servers = await createMultipleServers(3) // Get the access tokens await setAccessTokensToServers(servers) diff --git a/server/tests/api/users/users-verification.ts b/server/tests/api/users/users-verification.ts index c8c226fa8..5dbe2af59 100644 --- a/server/tests/api/users/users-verification.ts +++ b/server/tests/api/users/users-verification.ts @@ -3,12 +3,12 @@ import 'mocha' import * as chai from 'chai' import { HttpStatusCode } from '@shared/core-utils' -import { cleanupTests, flushAndRunServer, MockSmtpServer, ServerInfo, setAccessTokensToServers, waitJobs } from '@shared/extra-utils' +import { cleanupTests, createSingleServer, MockSmtpServer, PeerTubeServer, setAccessTokensToServers, waitJobs } from '@shared/extra-utils' const expect = chai.expect describe('Test users account verification', function () { - let server: ServerInfo + let server: PeerTubeServer let userId: number let userAccessToken: string let verificationString: string @@ -34,7 +34,7 @@ describe('Test users account verification', function () { port } } - server = await flushAndRunServer(1, overrideConfig) + server = await createSingleServer(1, overrideConfig) await setAccessTokensToServers([ server ]) }) diff --git a/server/tests/api/users/users.ts b/server/tests/api/users/users.ts index 310136a37..6ae5410b3 100644 --- a/server/tests/api/users/users.ts +++ b/server/tests/api/users/users.ts @@ -5,11 +5,10 @@ import * as chai from 'chai' import { HttpStatusCode } from '@shared/core-utils' import { cleanupTests, - flushAndRunServer, + createSingleServer, killallServers, makePutBodyRequest, - reRunServer, - ServerInfo, + PeerTubeServer, setAccessTokensToServers, testImage, waitJobs @@ -19,7 +18,7 @@ import { AbuseState, OAuth2ErrorCode, UserAdminFlag, UserRole, Video, VideoPlayl const expect = chai.expect describe('Test users', function () { - let server: ServerInfo + let server: PeerTubeServer let token: string let userToken: string let videoId: number @@ -32,7 +31,7 @@ describe('Test users', function () { before(async function () { this.timeout(30000) - server = await flushAndRunServer(1, { + server = await createSingleServer(1, { rates_limit: { login: { max: 30 @@ -238,7 +237,7 @@ describe('Test users', function () { await server.sql.setTokenField(server.accessToken, 'refreshTokenExpiresAt', new Date().toISOString()) await killallServers([ server ]) - await reRunServer(server) + await server.run() await server.users.getMyInfo({ expectedStatus: HttpStatusCode.UNAUTHORIZED_401 }) }) @@ -254,7 +253,7 @@ describe('Test users', function () { await server.sql.setTokenField(server.accessToken, 'refreshTokenExpiresAt', futureDate) await killallServers([ server ]) - await reRunServer(server) + await server.run() const res = await server.login.refreshToken({ refreshToken: server.refreshToken }) server.accessToken = res.body.access_token diff --git a/server/tests/api/videos/audio-only.ts b/server/tests/api/videos/audio-only.ts index b2952e38b..b9bf96650 100644 --- a/server/tests/api/videos/audio-only.ts +++ b/server/tests/api/videos/audio-only.ts @@ -4,12 +4,12 @@ import 'mocha' import * as chai from 'chai' import { join } from 'path' import { getAudioStream, getVideoStreamSize } from '@server/helpers/ffprobe-utils' -import { cleanupTests, doubleFollow, flushAndRunMultipleServers, ServerInfo, setAccessTokensToServers, waitJobs } from '@shared/extra-utils' +import { cleanupTests, doubleFollow, createMultipleServers, PeerTubeServer, setAccessTokensToServers, waitJobs } from '@shared/extra-utils' const expect = chai.expect describe('Test audio only video transcoding', function () { - let servers: ServerInfo[] = [] + let servers: PeerTubeServer[] = [] let videoUUID: string before(async function () { @@ -36,7 +36,7 @@ describe('Test audio only video transcoding', function () { } } } - servers = await flushAndRunMultipleServers(2, configOverride) + servers = await createMultipleServers(2, configOverride) // Get the access tokens await setAccessTokensToServers(servers) diff --git a/server/tests/api/videos/multiple-servers.ts b/server/tests/api/videos/multiple-servers.ts index 89d842307..562079a15 100644 --- a/server/tests/api/videos/multiple-servers.ts +++ b/server/tests/api/videos/multiple-servers.ts @@ -12,8 +12,8 @@ import { completeVideoCheck, dateIsValid, doubleFollow, - flushAndRunMultipleServers, - ServerInfo, + createMultipleServers, + PeerTubeServer, setAccessTokensToServers, testImage, wait, @@ -25,7 +25,7 @@ import { VideoCommentThreadTree, VideoPrivacy } from '@shared/models' const expect = chai.expect describe('Test multiple servers', function () { - let servers: ServerInfo[] = [] + let servers: PeerTubeServer[] = [] const toRemove = [] let videoUUID = '' let videoChannelId: number @@ -33,7 +33,7 @@ describe('Test multiple servers', function () { before(async function () { this.timeout(120000) - servers = await flushAndRunMultipleServers(3) + servers = await createMultipleServers(3) // Get the access tokens await setAccessTokensToServers(servers) diff --git a/server/tests/api/videos/resumable-upload.ts b/server/tests/api/videos/resumable-upload.ts index 2f1cf8a55..b4fc5ee09 100644 --- a/server/tests/api/videos/resumable-upload.ts +++ b/server/tests/api/videos/resumable-upload.ts @@ -8,8 +8,8 @@ import { HttpStatusCode } from '@shared/core-utils' import { buildAbsoluteFixturePath, cleanupTests, - flushAndRunServer, - ServerInfo, + createSingleServer, + PeerTubeServer, setAccessTokensToServers, setDefaultVideoChannel } from '@shared/extra-utils' @@ -21,7 +21,7 @@ const expect = chai.expect describe('Test resumable upload', function () { const defaultFixture = 'video_short.mp4' - let server: ServerInfo + let server: PeerTubeServer let rootId: number async function buildSize (fixture: string, size?: number) { @@ -99,7 +99,7 @@ describe('Test resumable upload', 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/videos/single-server.ts b/server/tests/api/videos/single-server.ts index 12c1f7b2f..c0535be09 100644 --- a/server/tests/api/videos/single-server.ts +++ b/server/tests/api/videos/single-server.ts @@ -6,8 +6,8 @@ import { checkVideoFilesWereRemoved, cleanupTests, completeVideoCheck, - flushAndRunServer, - ServerInfo, + createSingleServer, + PeerTubeServer, setAccessTokensToServers, testImage, wait @@ -19,7 +19,7 @@ const expect = chai.expect describe('Test a single server', function () { function runSuite (mode: 'legacy' | 'resumable') { - let server: ServerInfo = null + let server: PeerTubeServer = null let videoId: number | string let videoId2: string let videoUUID = '' @@ -94,7 +94,7 @@ describe('Test a single server', function () { before(async function () { this.timeout(30000) - server = await flushAndRunServer(1) + server = await createSingleServer(1) await setAccessTokensToServers([ server ]) }) diff --git a/server/tests/api/videos/video-captions.ts b/server/tests/api/videos/video-captions.ts index abc07194d..6caba6aa6 100644 --- a/server/tests/api/videos/video-captions.ts +++ b/server/tests/api/videos/video-captions.ts @@ -6,8 +6,8 @@ import { checkVideoFilesWereRemoved, cleanupTests, doubleFollow, - flushAndRunMultipleServers, - ServerInfo, + createMultipleServers, + PeerTubeServer, setAccessTokensToServers, testCaptionFile, wait, @@ -19,13 +19,13 @@ const expect = chai.expect describe('Test video captions', function () { const uuidRegex = '[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}' - let servers: ServerInfo[] + let servers: PeerTubeServer[] let videoUUID: string before(async function () { this.timeout(60000) - servers = await flushAndRunMultipleServers(2) + servers = await createMultipleServers(2) await setAccessTokensToServers(servers) await doubleFollow(servers[0], servers[1]) diff --git a/server/tests/api/videos/video-change-ownership.ts b/server/tests/api/videos/video-change-ownership.ts index 352eb5ea3..cefddb68e 100644 --- a/server/tests/api/videos/video-change-ownership.ts +++ b/server/tests/api/videos/video-change-ownership.ts @@ -7,9 +7,9 @@ import { ChangeOwnershipCommand, cleanupTests, doubleFollow, - flushAndRunMultipleServers, - flushAndRunServer, - ServerInfo, + createMultipleServers, + createSingleServer, + PeerTubeServer, setAccessTokensToServers, setDefaultVideoChannel, waitJobs @@ -19,7 +19,7 @@ import { VideoPrivacy } from '@shared/models' const expect = chai.expect describe('Test video change ownership - nominal', function () { - let servers: ServerInfo[] = [] + let servers: PeerTubeServer[] = [] const firstUser = 'first' const secondUser = 'second' @@ -39,7 +39,7 @@ describe('Test video change ownership - nominal', function () { before(async function () { this.timeout(50000) - servers = await flushAndRunMultipleServers(2) + servers = await createMultipleServers(2) await setAccessTokensToServers(servers) await setDefaultVideoChannel(servers) @@ -251,7 +251,7 @@ describe('Test video change ownership - nominal', function () { }) describe('Test video change ownership - quota too small', function () { - let server: ServerInfo + let server: PeerTubeServer const firstUser = 'first' const secondUser = 'second' @@ -263,7 +263,7 @@ describe('Test video change ownership - quota too small', function () { this.timeout(50000) // Run one server - server = await flushAndRunServer(1) + server = await createSingleServer(1) await setAccessTokensToServers([ server ]) await server.users.create({ username: secondUser, videoQuota: 10 }) diff --git a/server/tests/api/videos/video-channels.ts b/server/tests/api/videos/video-channels.ts index 1efef932c..140fee7fe 100644 --- a/server/tests/api/videos/video-channels.ts +++ b/server/tests/api/videos/video-channels.ts @@ -7,8 +7,8 @@ import { ACTOR_IMAGES_SIZE } from '@server/initializers/constants' import { cleanupTests, doubleFollow, - flushAndRunMultipleServers, - ServerInfo, + createMultipleServers, + PeerTubeServer, setAccessTokensToServers, setDefaultVideoChannel, testFileExistsOrNot, @@ -20,14 +20,14 @@ import { User, VideoChannel } from '@shared/models' const expect = chai.expect -async function findChannel (server: ServerInfo, channelId: number) { +async function findChannel (server: PeerTubeServer, channelId: number) { const body = await server.channels.list({ sort: '-name' }) return body.data.find(c => c.id === channelId) } describe('Test video channels', function () { - let servers: ServerInfo[] + let servers: PeerTubeServer[] let userInfo: User let secondVideoChannelId: number let totoChannel: number @@ -40,7 +40,7 @@ describe('Test video channels', function () { before(async function () { this.timeout(60000) - servers = await flushAndRunMultipleServers(2) + servers = await createMultipleServers(2) await setAccessTokensToServers(servers) await setDefaultVideoChannel(servers) diff --git a/server/tests/api/videos/video-comments.ts b/server/tests/api/videos/video-comments.ts index adb59bd74..9709e0628 100644 --- a/server/tests/api/videos/video-comments.ts +++ b/server/tests/api/videos/video-comments.ts @@ -6,8 +6,8 @@ import { cleanupTests, CommentsCommand, dateIsValid, - flushAndRunServer, - ServerInfo, + createSingleServer, + PeerTubeServer, setAccessTokensToServers, testImage } from '@shared/extra-utils' @@ -15,7 +15,7 @@ import { const expect = chai.expect describe('Test video comments', function () { - let server: ServerInfo + let server: PeerTubeServer let videoId: number let videoUUID: string let threadId: number @@ -28,7 +28,7 @@ describe('Test video comments', function () { before(async function () { this.timeout(30000) - server = await flushAndRunServer(1) + server = await createSingleServer(1) await setAccessTokensToServers([ server ]) diff --git a/server/tests/api/videos/video-description.ts b/server/tests/api/videos/video-description.ts index b89247288..ce45eac80 100644 --- a/server/tests/api/videos/video-description.ts +++ b/server/tests/api/videos/video-description.ts @@ -2,12 +2,12 @@ import 'mocha' import * as chai from 'chai' -import { cleanupTests, doubleFollow, flushAndRunMultipleServers, ServerInfo, setAccessTokensToServers, waitJobs } from '@shared/extra-utils' +import { cleanupTests, doubleFollow, createMultipleServers, PeerTubeServer, setAccessTokensToServers, waitJobs } from '@shared/extra-utils' const expect = chai.expect describe('Test video description', function () { - let servers: ServerInfo[] = [] + let servers: PeerTubeServer[] = [] let videoUUID = '' let videoId: number const longDescription = 'my super description for server 1'.repeat(50) @@ -16,7 +16,7 @@ describe('Test video description', function () { this.timeout(40000) // Run servers - servers = await flushAndRunMultipleServers(2) + servers = await createMultipleServers(2) // Get the access tokens await setAccessTokensToServers(servers) diff --git a/server/tests/api/videos/video-hls.ts b/server/tests/api/videos/video-hls.ts index 9d79f2683..4c4b18887 100644 --- a/server/tests/api/videos/video-hls.ts +++ b/server/tests/api/videos/video-hls.ts @@ -11,9 +11,9 @@ import { checkTmpIsEmpty, cleanupTests, doubleFollow, - flushAndRunMultipleServers, + createMultipleServers, makeRawRequest, - ServerInfo, + PeerTubeServer, setAccessTokensToServers, waitJobs, webtorrentAdd @@ -23,7 +23,7 @@ import { DEFAULT_AUDIO_RESOLUTION } from '../../../initializers/constants' const expect = chai.expect -async function checkHlsPlaylist (servers: ServerInfo[], videoUUID: string, hlsOnly: boolean, resolutions = [ 240, 360, 480, 720 ]) { +async function checkHlsPlaylist (servers: PeerTubeServer[], videoUUID: string, hlsOnly: boolean, resolutions = [ 240, 360, 480, 720 ]) { for (const server of servers) { const videoDetails = await server.videos.get({ id: videoUUID }) const baseUrl = `http://${videoDetails.account.host}` @@ -98,7 +98,7 @@ async function checkHlsPlaylist (servers: ServerInfo[], videoUUID: string, hlsOn } describe('Test HLS videos', function () { - let servers: ServerInfo[] = [] + let servers: PeerTubeServer[] = [] let videoUUID = '' let videoAudioUUID = '' @@ -176,7 +176,7 @@ describe('Test HLS videos', function () { } } } - servers = await flushAndRunMultipleServers(2, configOverride) + servers = await createMultipleServers(2, configOverride) // Get the access tokens await setAccessTokensToServers(servers) diff --git a/server/tests/api/videos/video-imports.ts b/server/tests/api/videos/video-imports.ts index 8b6542aa4..4ef55c3af 100644 --- a/server/tests/api/videos/video-imports.ts +++ b/server/tests/api/videos/video-imports.ts @@ -6,9 +6,9 @@ import { areHttpImportTestsDisabled, cleanupTests, doubleFollow, - flushAndRunMultipleServers, + createMultipleServers, ImportsCommand, - ServerInfo, + PeerTubeServer, setAccessTokensToServers, testCaptionFile, testImage, @@ -19,13 +19,13 @@ import { VideoPrivacy, VideoResolution } from '@shared/models' const expect = chai.expect describe('Test video imports', function () { - let servers: ServerInfo[] = [] + let servers: PeerTubeServer[] = [] let channelIdServer1: number let channelIdServer2: number if (areHttpImportTestsDisabled()) return - async function checkVideosServer1 (server: ServerInfo, idHttp: string, idMagnet: string, idTorrent: string) { + async function checkVideosServer1 (server: PeerTubeServer, idHttp: string, idMagnet: string, idTorrent: string) { const videoHttp = await server.videos.get({ id: idHttp }) expect(videoHttp.name).to.equal('small video - youtube') @@ -63,7 +63,7 @@ describe('Test video imports', function () { expect(bodyCaptions.total).to.equal(2) } - async function checkVideoServer2 (server: ServerInfo, id: number | string) { + async function checkVideoServer2 (server: PeerTubeServer, id: number | string) { const video = await server.videos.get({ id }) expect(video.name).to.equal('my super name') @@ -84,7 +84,7 @@ describe('Test video imports', function () { this.timeout(30_000) // Run servers - servers = await flushAndRunMultipleServers(2) + servers = await createMultipleServers(2) await setAccessTokensToServers(servers) diff --git a/server/tests/api/videos/video-nsfw.ts b/server/tests/api/videos/video-nsfw.ts index 95395a582..b25dcda20 100644 --- a/server/tests/api/videos/video-nsfw.ts +++ b/server/tests/api/videos/video-nsfw.ts @@ -2,7 +2,7 @@ import 'mocha' import * as chai from 'chai' -import { cleanupTests, flushAndRunServer, ServerInfo, setAccessTokensToServers } from '@shared/extra-utils' +import { cleanupTests, createSingleServer, PeerTubeServer, setAccessTokensToServers } from '@shared/extra-utils' import { BooleanBothQuery, CustomConfig, ResultList, Video, VideosOverview } from '@shared/models' const expect = chai.expect @@ -13,7 +13,7 @@ function createOverviewRes (overview: VideosOverview) { } describe('Test video NSFW policy', function () { - let server: ServerInfo + let server: PeerTubeServer let userAccessToken: string let customConfig: CustomConfig @@ -61,7 +61,7 @@ describe('Test video NSFW policy', function () { before(async function () { this.timeout(50000) - server = await flushAndRunServer(1) + server = await createSingleServer(1) // Get the access tokens await setAccessTokensToServers([ server ]) diff --git a/server/tests/api/videos/video-playlist-thumbnails.ts b/server/tests/api/videos/video-playlist-thumbnails.ts index 709f64c4d..9a682c12b 100644 --- a/server/tests/api/videos/video-playlist-thumbnails.ts +++ b/server/tests/api/videos/video-playlist-thumbnails.ts @@ -5,8 +5,8 @@ import * as chai from 'chai' import { cleanupTests, doubleFollow, - flushAndRunMultipleServers, - ServerInfo, + createMultipleServers, + PeerTubeServer, setAccessTokensToServers, setDefaultVideoChannel, testImage, @@ -17,7 +17,7 @@ import { VideoPlaylistPrivacy } from '../../../../shared/models/videos/playlist/ const expect = chai.expect describe('Playlist thumbnail', function () { - let servers: ServerInfo[] = [] + let servers: PeerTubeServer[] = [] let playlistWithoutThumbnailId: number let playlistWithThumbnailId: number @@ -30,13 +30,13 @@ describe('Playlist thumbnail', function () { let video1: number let video2: number - async function getPlaylistWithoutThumbnail (server: ServerInfo) { + async function getPlaylistWithoutThumbnail (server: PeerTubeServer) { const body = await server.playlists.list({ start: 0, count: 10 }) return body.data.find(p => p.displayName === 'playlist without thumbnail') } - async function getPlaylistWithThumbnail (server: ServerInfo) { + async function getPlaylistWithThumbnail (server: PeerTubeServer) { const body = await server.playlists.list({ start: 0, count: 10 }) return body.data.find(p => p.displayName === 'playlist with thumbnail') @@ -45,7 +45,7 @@ describe('Playlist thumbnail', function () { before(async function () { this.timeout(120000) - servers = await flushAndRunMultipleServers(2, { transcoding: { enabled: false } }) + servers = await createMultipleServers(2, { transcoding: { enabled: false } }) // Get the access tokens await setAccessTokensToServers(servers) diff --git a/server/tests/api/videos/video-playlists.ts b/server/tests/api/videos/video-playlists.ts index 0dc53d4c0..71ca3e63a 100644 --- a/server/tests/api/videos/video-playlists.ts +++ b/server/tests/api/videos/video-playlists.ts @@ -7,9 +7,9 @@ import { checkPlaylistFilesWereRemoved, cleanupTests, doubleFollow, - flushAndRunMultipleServers, + createMultipleServers, PlaylistsCommand, - ServerInfo, + PeerTubeServer, setAccessTokensToServers, setDefaultVideoChannel, testImage, @@ -28,7 +28,7 @@ import { const expect = chai.expect async function checkPlaylistElementType ( - servers: ServerInfo[], + servers: PeerTubeServer[], playlistId: string, type: VideoPlaylistElementType, position: number, @@ -52,7 +52,7 @@ async function checkPlaylistElementType ( } describe('Test video playlists', function () { - let servers: ServerInfo[] = [] + let servers: PeerTubeServer[] = [] let playlistServer2Id1: number let playlistServer2Id2: number @@ -75,7 +75,7 @@ describe('Test video playlists', function () { before(async function () { this.timeout(120000) - servers = await flushAndRunMultipleServers(3, { transcoding: { enabled: false } }) + servers = await createMultipleServers(3, { transcoding: { enabled: false } }) // Get the access tokens await setAccessTokensToServers(servers) @@ -584,10 +584,10 @@ describe('Test video playlists', function () { }) describe('Element type', function () { - let groupUser1: ServerInfo[] - let groupWithoutToken1: ServerInfo[] - let group1: ServerInfo[] - let group2: ServerInfo[] + let groupUser1: PeerTubeServer[] + let groupWithoutToken1: PeerTubeServer[] + let group1: PeerTubeServer[] + let group2: PeerTubeServer[] let video1: string let video2: string diff --git a/server/tests/api/videos/video-privacy.ts b/server/tests/api/videos/video-privacy.ts index de08a9e7b..5ec626155 100644 --- a/server/tests/api/videos/video-privacy.ts +++ b/server/tests/api/videos/video-privacy.ts @@ -3,13 +3,13 @@ import 'mocha' import * as chai from 'chai' import { HttpStatusCode } from '@shared/core-utils' -import { cleanupTests, doubleFollow, flushAndRunServer, ServerInfo, setAccessTokensToServers, waitJobs } from '@shared/extra-utils' +import { cleanupTests, doubleFollow, createSingleServer, PeerTubeServer, setAccessTokensToServers, waitJobs } from '@shared/extra-utils' import { VideoCreateResult, VideoPrivacy } from '@shared/models' const expect = chai.expect describe('Test video privacy', function () { - const servers: ServerInfo[] = [] + const servers: PeerTubeServer[] = [] let anotherUserToken: string let privateVideoId: number @@ -35,8 +35,8 @@ describe('Test video privacy', function () { this.timeout(50000) // Run servers - servers.push(await flushAndRunServer(1, dontFederateUnlistedConfig)) - servers.push(await flushAndRunServer(2)) + servers.push(await createSingleServer(1, dontFederateUnlistedConfig)) + servers.push(await createSingleServer(2)) // Get the access tokens await setAccessTokensToServers(servers) diff --git a/server/tests/api/videos/video-schedule-update.ts b/server/tests/api/videos/video-schedule-update.ts index 3938b47c8..22b5cf1c2 100644 --- a/server/tests/api/videos/video-schedule-update.ts +++ b/server/tests/api/videos/video-schedule-update.ts @@ -5,8 +5,8 @@ import * as chai from 'chai' import { cleanupTests, doubleFollow, - flushAndRunMultipleServers, - ServerInfo, + createMultipleServers, + PeerTubeServer, setAccessTokensToServers, wait, waitJobs @@ -23,14 +23,14 @@ function in10Seconds () { } describe('Test video update scheduler', function () { - let servers: ServerInfo[] = [] + let servers: PeerTubeServer[] = [] let video2UUID: string before(async function () { this.timeout(30000) // Run servers - servers = await flushAndRunMultipleServers(2) + servers = await createMultipleServers(2) await setAccessTokensToServers(servers) diff --git a/server/tests/api/videos/video-transcoder.ts b/server/tests/api/videos/video-transcoder.ts index 37450eeeb..2465d2d89 100644 --- a/server/tests/api/videos/video-transcoder.ts +++ b/server/tests/api/videos/video-transcoder.ts @@ -9,11 +9,11 @@ import { buildAbsoluteFixturePath, cleanupTests, doubleFollow, - flushAndRunMultipleServers, + createMultipleServers, generateHighBitrateVideo, generateVideoWithFramerate, makeGetRequest, - ServerInfo, + PeerTubeServer, setAccessTokensToServers, waitJobs, webtorrentAdd @@ -31,7 +31,7 @@ import { const expect = chai.expect -function updateConfigForTranscoding (server: ServerInfo) { +function updateConfigForTranscoding (server: PeerTubeServer) { return server.config.updateCustomSubConfig({ newConfig: { transcoding: { @@ -56,14 +56,14 @@ function updateConfigForTranscoding (server: ServerInfo) { } describe('Test video transcoding', function () { - let servers: ServerInfo[] = [] + let servers: PeerTubeServer[] = [] let video4k: string before(async function () { this.timeout(30_000) // Run servers - servers = await flushAndRunMultipleServers(2) + servers = await createMultipleServers(2) await setAccessTokensToServers(servers) diff --git a/server/tests/api/videos/videos-filter.ts b/server/tests/api/videos/videos-filter.ts index af1541dbd..db9150655 100644 --- a/server/tests/api/videos/videos-filter.ts +++ b/server/tests/api/videos/videos-filter.ts @@ -6,14 +6,14 @@ import { HttpStatusCode } from '@shared/core-utils' import { cleanupTests, doubleFollow, - flushAndRunMultipleServers, + createMultipleServers, makeGetRequest, - ServerInfo, + PeerTubeServer, setAccessTokensToServers } from '@shared/extra-utils' import { UserRole, Video, VideoPrivacy } from '@shared/models' -async function getVideosNames (server: ServerInfo, token: string, filter: string, statusCodeExpected = HttpStatusCode.OK_200) { +async function getVideosNames (server: PeerTubeServer, token: string, filter: string, statusCodeExpected = HttpStatusCode.OK_200) { const paths = [ '/api/v1/video-channels/root_channel/videos', '/api/v1/accounts/root/videos', @@ -42,14 +42,14 @@ async function getVideosNames (server: ServerInfo, token: string, filter: string } describe('Test videos filter', function () { - let servers: ServerInfo[] + let servers: PeerTubeServer[] // --------------------------------------------------------------- before(async function () { this.timeout(160000) - servers = await flushAndRunMultipleServers(2) + servers = await createMultipleServers(2) await setAccessTokensToServers(servers) diff --git a/server/tests/api/videos/videos-history.ts b/server/tests/api/videos/videos-history.ts index 4b5e581d1..55e53cb94 100644 --- a/server/tests/api/videos/videos-history.ts +++ b/server/tests/api/videos/videos-history.ts @@ -5,11 +5,10 @@ import * as chai from 'chai' import { HttpStatusCode } from '@shared/core-utils' import { cleanupTests, - flushAndRunServer, + createSingleServer, HistoryCommand, killallServers, - reRunServer, - ServerInfo, + PeerTubeServer, setAccessTokensToServers, wait } from '@shared/extra-utils' @@ -18,7 +17,7 @@ import { Video } from '@shared/models' const expect = chai.expect describe('Test videos history', function () { - let server: ServerInfo = null + let server: PeerTubeServer = null let video1UUID: string let video2UUID: string let video3UUID: string @@ -29,7 +28,7 @@ describe('Test videos history', function () { before(async function () { this.timeout(30000) - server = await flushAndRunServer(1) + server = await createSingleServer(1) await setAccessTokensToServers([ server ]) @@ -191,7 +190,7 @@ describe('Test videos history', function () { await killallServers([ server ]) - await reRunServer(server, { history: { videos: { max_age: '10 days' } } }) + await server.run({ history: { videos: { max_age: '10 days' } } }) await wait(6000) @@ -206,7 +205,7 @@ describe('Test videos history', function () { await killallServers([ server ]) - await reRunServer(server, { history: { videos: { max_age: '5 seconds' } } }) + await server.run({ history: { videos: { max_age: '5 seconds' } } }) await wait(6000) diff --git a/server/tests/api/videos/videos-overview.ts b/server/tests/api/videos/videos-overview.ts index f0657b334..70aa66549 100644 --- a/server/tests/api/videos/videos-overview.ts +++ b/server/tests/api/videos/videos-overview.ts @@ -2,13 +2,13 @@ import 'mocha' import * as chai from 'chai' -import { cleanupTests, flushAndRunServer, ServerInfo, setAccessTokensToServers, wait } from '@shared/extra-utils' +import { cleanupTests, createSingleServer, PeerTubeServer, setAccessTokensToServers, wait } from '@shared/extra-utils' import { VideosOverview } from '@shared/models' const expect = chai.expect describe('Test a videos overview', function () { - let server: ServerInfo = null + let server: PeerTubeServer = null function testOverviewCount (overview: VideosOverview, expected: number) { expect(overview.tags).to.have.lengthOf(expected) @@ -19,7 +19,7 @@ describe('Test a videos overview', function () { before(async function () { this.timeout(30000) - server = await flushAndRunServer(1) + server = await createSingleServer(1) await setAccessTokensToServers([ server ]) }) diff --git a/server/tests/api/videos/videos-views-cleaner.ts b/server/tests/api/videos/videos-views-cleaner.ts index 238662cf3..0be03ddd2 100644 --- a/server/tests/api/videos/videos-views-cleaner.ts +++ b/server/tests/api/videos/videos-views-cleaner.ts @@ -5,10 +5,9 @@ import * as chai from 'chai' import { cleanupTests, doubleFollow, - flushAndRunMultipleServers, + createMultipleServers, killallServers, - reRunServer, - ServerInfo, + PeerTubeServer, setAccessTokensToServers, wait, waitJobs @@ -17,7 +16,7 @@ import { const expect = chai.expect describe('Test video views cleaner', function () { - let servers: ServerInfo[] + let servers: PeerTubeServer[] let videoIdServer1: string let videoIdServer2: string @@ -25,7 +24,7 @@ describe('Test video views cleaner', function () { before(async function () { this.timeout(120000) - servers = await flushAndRunMultipleServers(2) + servers = await createMultipleServers(2) await setAccessTokensToServers(servers) await doubleFollow(servers[0], servers[1]) @@ -48,7 +47,7 @@ describe('Test video views cleaner', function () { await killallServers([ servers[0] ]) - await reRunServer(servers[0], { views: { videos: { remote: { max_age: '10 days' } } } }) + await servers[0].run({ views: { videos: { remote: { max_age: '10 days' } } } }) await wait(6000) @@ -74,7 +73,7 @@ describe('Test video views cleaner', function () { await killallServers([ servers[0] ]) - await reRunServer(servers[0], { views: { videos: { remote: { max_age: '5 seconds' } } } }) + await servers[0].run({ views: { videos: { remote: { max_age: '5 seconds' } } } }) await wait(6000) -- 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 +++--- server/tests/api/moderation/video-blacklist.ts | 8 ++++---- server/tests/api/notifications/user-notifications.ts | 16 ++++++++-------- server/tests/api/videos/video-imports.ts | 18 +++++++++--------- 5 files changed, 27 insertions(+), 27 deletions(-) (limited to 'server/tests/api') 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, diff --git a/server/tests/api/moderation/video-blacklist.ts b/server/tests/api/moderation/video-blacklist.ts index 62cbf2e07..d5838191a 100644 --- a/server/tests/api/moderation/video-blacklist.ts +++ b/server/tests/api/moderation/video-blacklist.ts @@ -6,9 +6,9 @@ import { orderBy } from 'lodash' import { BlacklistCommand, cleanupTests, - doubleFollow, createMultipleServers, - ImportsCommand, + doubleFollow, + FIXTURE_URLS, killallServers, PeerTubeServer, setAccessTokensToServers, @@ -387,7 +387,7 @@ describe('Test video blacklist', function () { this.timeout(15000) const attributes = { - targetUrl: ImportsCommand.getGoodVideoUrl(), + targetUrl: FIXTURE_URLS.goodVideo, name: 'URL import', channelId: channelOfUserWithoutFlag } @@ -400,7 +400,7 @@ describe('Test video blacklist', function () { it('Should auto blacklist a video on torrent import', async function () { const attributes = { - magnetUri: ImportsCommand.getMagnetURI(), + magnetUri: FIXTURE_URLS.magnet, name: 'Torrent import', channelId: channelOfUserWithoutFlag } diff --git a/server/tests/api/notifications/user-notifications.ts b/server/tests/api/notifications/user-notifications.ts index b7c22d118..ca592d466 100644 --- a/server/tests/api/notifications/user-notifications.ts +++ b/server/tests/api/notifications/user-notifications.ts @@ -10,10 +10,10 @@ import { checkNewVideoFromSubscription, checkVideoIsPublished, cleanupTests, - ImportsCommand, + FIXTURE_URLS, MockSmtpServer, - prepareNotificationsTest, PeerTubeServer, + prepareNotificationsTest, uploadRandomVideoOnServers, wait, waitJobs @@ -205,7 +205,7 @@ describe('Test user notifications', function () { name, channelId, privacy: VideoPrivacy.PUBLIC, - targetUrl: ImportsCommand.getGoodVideoUrl() + targetUrl: FIXTURE_URLS.goodVideo } const { video } = await servers[0].imports.importVideo({ attributes }) @@ -275,7 +275,7 @@ describe('Test user notifications', function () { name, channelId, privacy: VideoPrivacy.PUBLIC, - targetUrl: ImportsCommand.getGoodVideoUrl(), + targetUrl: FIXTURE_URLS.goodVideo, waitTranscoding: true } const { video } = await servers[1].imports.importVideo({ attributes }) @@ -343,12 +343,12 @@ describe('Test user notifications', function () { name, channelId, privacy: VideoPrivacy.PRIVATE, - targetUrl: ImportsCommand.getBadVideoUrl() + targetUrl: FIXTURE_URLS.badVideo } const { video } = await servers[0].imports.importVideo({ attributes }) await waitJobs(servers) - await checkMyVideoImportIsFinished(baseParams, name, video.uuid, ImportsCommand.getBadVideoUrl(), false, 'presence') + await checkMyVideoImportIsFinished(baseParams, name, video.uuid, FIXTURE_URLS.badVideo, false, 'presence') }) it('Should send a notification when the video import succeeded', async function () { @@ -360,12 +360,12 @@ describe('Test user notifications', function () { name, channelId, privacy: VideoPrivacy.PRIVATE, - targetUrl: ImportsCommand.getGoodVideoUrl() + targetUrl: FIXTURE_URLS.goodVideo } const { video } = await servers[0].imports.importVideo({ attributes }) await waitJobs(servers) - await checkMyVideoImportIsFinished(baseParams, name, video.uuid, ImportsCommand.getGoodVideoUrl(), true, 'presence') + await checkMyVideoImportIsFinished(baseParams, name, video.uuid, FIXTURE_URLS.goodVideo, true, 'presence') }) }) diff --git a/server/tests/api/videos/video-imports.ts b/server/tests/api/videos/video-imports.ts index 4ef55c3af..192f5232e 100644 --- a/server/tests/api/videos/video-imports.ts +++ b/server/tests/api/videos/video-imports.ts @@ -5,9 +5,9 @@ import * as chai from 'chai' import { areHttpImportTestsDisabled, cleanupTests, - doubleFollow, createMultipleServers, - ImportsCommand, + doubleFollow, + FIXTURE_URLS, PeerTubeServer, setAccessTokensToServers, testCaptionFile, @@ -110,7 +110,7 @@ describe('Test video imports', function () { } { - const attributes = { ...baseAttributes, targetUrl: ImportsCommand.getYoutubeVideoUrl() } + const attributes = { ...baseAttributes, targetUrl: FIXTURE_URLS.youtube } const { video } = await servers[0].imports.importVideo({ attributes }) expect(video.name).to.equal('small video - youtube') @@ -162,7 +162,7 @@ Ajouter un sous-titre est vraiment facile`) { const attributes = { ...baseAttributes, - magnetUri: ImportsCommand.getMagnetURI(), + magnetUri: FIXTURE_URLS.magnet, description: 'this is a super torrent description', tags: [ 'tag_torrent1', 'tag_torrent2' ] } @@ -199,13 +199,13 @@ Ajouter un sous-titre est vraiment facile`) expect(videoImports).to.have.lengthOf(3) - expect(videoImports[2].targetUrl).to.equal(ImportsCommand.getYoutubeVideoUrl()) + expect(videoImports[2].targetUrl).to.equal(FIXTURE_URLS.youtube) expect(videoImports[2].magnetUri).to.be.null expect(videoImports[2].torrentName).to.be.null expect(videoImports[2].video.name).to.equal('small video - youtube') expect(videoImports[1].targetUrl).to.be.null - expect(videoImports[1].magnetUri).to.equal(ImportsCommand.getMagnetURI()) + expect(videoImports[1].magnetUri).to.equal(FIXTURE_URLS.magnet) expect(videoImports[1].torrentName).to.be.null expect(videoImports[1].video.name).to.equal('super peertube2 video') @@ -234,7 +234,7 @@ Ajouter un sous-titre est vraiment facile`) this.timeout(60_000) const attributes = { - targetUrl: ImportsCommand.getYoutubeVideoUrl(), + targetUrl: FIXTURE_URLS.youtube, channelId: channelIdServer2, privacy: VideoPrivacy.PUBLIC, category: 10, @@ -270,7 +270,7 @@ Ajouter un sous-titre est vraiment facile`) const attributes = { name: 'transcoded video', - magnetUri: ImportsCommand.getMagnetURI(), + magnetUri: FIXTURE_URLS.magnet, channelId: channelIdServer2, privacy: VideoPrivacy.PUBLIC } @@ -320,7 +320,7 @@ Ajouter un sous-titre est vraiment facile`) const attributes = { name: 'hdr video', - targetUrl: ImportsCommand.getYoutubeHDRVideoUrl(), + targetUrl: FIXTURE_URLS.youtubeHDR, channelId: channelIdServer1, privacy: VideoPrivacy.PUBLIC } -- 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') 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/activitypub/client.ts | 4 +- server/tests/api/activitypub/refresher.ts | 2 +- server/tests/api/activitypub/security.ts | 19 ++--- 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 ++++----- server/tests/api/live/live-save-replay.ts | 2 +- server/tests/api/live/live.ts | 2 +- server/tests/api/moderation/abuses.ts | 8 +- .../tests/api/redundancy/redundancy-constraints.ts | 2 +- server/tests/api/redundancy/redundancy.ts | 6 +- .../search/search-activitypub-video-channels.ts | 8 +- server/tests/api/server/config.ts | 6 +- server/tests/api/server/contact-form.ts | 2 +- server/tests/api/server/email.ts | 2 +- server/tests/api/server/follow-constraints.ts | 50 ++++++------ server/tests/api/server/handle-down.ts | 2 +- server/tests/api/server/homepage.ts | 2 +- server/tests/api/server/no-client.ts | 5 +- server/tests/api/server/plugins.ts | 2 +- server/tests/api/server/reverse-proxy.ts | 2 +- server/tests/api/users/users-multiple-servers.ts | 4 +- server/tests/api/users/users-verification.ts | 2 +- server/tests/api/users/users.ts | 4 +- server/tests/api/videos/multiple-servers.ts | 2 +- server/tests/api/videos/resumable-upload.ts | 2 +- server/tests/api/videos/video-change-ownership.ts | 2 +- server/tests/api/videos/video-channels.ts | 6 +- server/tests/api/videos/video-hls.ts | 2 +- server/tests/api/videos/video-nsfw.ts | 12 +-- server/tests/api/videos/video-playlists.ts | 2 +- server/tests/api/videos/video-privacy.ts | 2 +- server/tests/api/videos/video-transcoder.ts | 10 +-- server/tests/api/videos/videos-filter.ts | 6 +- server/tests/api/videos/videos-history.ts | 2 +- 61 files changed, 524 insertions(+), 562 deletions(-) (limited to 'server/tests/api') diff --git a/server/tests/api/activitypub/client.ts b/server/tests/api/activitypub/client.ts index 720231f02..53cc40663 100644 --- a/server/tests/api/activitypub/client.ts +++ b/server/tests/api/activitypub/client.ts @@ -2,7 +2,7 @@ import 'mocha' import * as chai from 'chai' -import { HttpStatusCode } from '@shared/core-utils' +import { HttpStatusCode } from '@shared/models' import { cleanupTests, doubleFollow, @@ -68,7 +68,7 @@ describe('Test activitypub', function () { await setDefaultVideoChannel(servers) { - video = await await servers[0].videos.quickUpload({ name: 'video' }) + video = await servers[0].videos.quickUpload({ name: 'video' }) } { diff --git a/server/tests/api/activitypub/refresher.ts b/server/tests/api/activitypub/refresher.ts index bbec0d309..a0b72c7e6 100644 --- a/server/tests/api/activitypub/refresher.ts +++ b/server/tests/api/activitypub/refresher.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, doubleFollow, diff --git a/server/tests/api/activitypub/security.ts b/server/tests/api/activitypub/security.ts index c173648b3..94d946563 100644 --- a/server/tests/api/activitypub/security.ts +++ b/server/tests/api/activitypub/security.ts @@ -2,20 +2,13 @@ import 'mocha' import * as chai from 'chai' +import { activityPubContextify, buildSignedActivity } from '@server/helpers/activitypub' import { buildDigest } from '@server/helpers/peertube-crypto' -import { HttpStatusCode } from '../../../../shared/core-utils/miscs/http-error-codes' -import { - buildAbsoluteFixturePath, - cleanupTests, - createMultipleServers, - killallServers, - PeerTubeServer, - wait -} from '../../../../shared/extra-utils' -import { makeFollowRequest, makePOSTAPRequest } from '../../../../shared/extra-utils/requests/activitypub' -import { activityPubContextify, buildSignedActivity } from '../../../helpers/activitypub' -import { HTTP_SIGNATURE } from '../../../initializers/constants' -import { buildGlobalHeaders } from '../../../lib/job-queue/handlers/utils/activitypub-http-utils' +import { HTTP_SIGNATURE } from '@server/initializers/constants' +import { buildGlobalHeaders } from '@server/lib/job-queue/handlers/utils/activitypub-http-utils' +import { buildAbsoluteFixturePath, cleanupTests, createMultipleServers, killallServers, PeerTubeServer, wait } from '@shared/extra-utils' +import { makeFollowRequest, makePOSTAPRequest } from '@shared/extra-utils/requests/activitypub' +import { HttpStatusCode } from '@shared/models' const expect = chai.expect 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') diff --git a/server/tests/api/live/live-save-replay.ts b/server/tests/api/live/live-save-replay.ts index d403f27bf..095c51b97 100644 --- a/server/tests/api/live/live-save-replay.ts +++ b/server/tests/api/live/live-save-replay.ts @@ -3,7 +3,7 @@ import 'mocha' import * as chai from 'chai' import { FfmpegCommand } from 'fluent-ffmpeg' -import { HttpStatusCode } from '@shared/core-utils' +import { HttpStatusCode } from '@shared/models' import { checkLiveCleanup, cleanupTests, diff --git a/server/tests/api/live/live.ts b/server/tests/api/live/live.ts index 7cfac522c..88995910c 100644 --- a/server/tests/api/live/live.ts +++ b/server/tests/api/live/live.ts @@ -4,7 +4,7 @@ import 'mocha' import * as chai from 'chai' import { join } from 'path' import { ffprobePromise, getVideoStreamFromFile } from '@server/helpers/ffprobe-utils' -import { HttpStatusCode } from '@shared/core-utils' +import { HttpStatusCode } from '@shared/models' import { checkLiveCleanup, checkLiveSegmentHash, diff --git a/server/tests/api/moderation/abuses.ts b/server/tests/api/moderation/abuses.ts index 360b9de35..8d6360eb3 100644 --- a/server/tests/api/moderation/abuses.ts +++ b/server/tests/api/moderation/abuses.ts @@ -5,8 +5,8 @@ import * as chai from 'chai' import { AbusesCommand, cleanupTests, - doubleFollow, createMultipleServers, + doubleFollow, PeerTubeServer, setAccessTokensToServers, waitJobs @@ -65,7 +65,7 @@ describe('Test abuses', function () { expect(data.length).to.equal(2) servers[0].store.video = data.find(video => video.name === 'my super name for server 1') - servers[1].store.video = data.find(video => video.name === 'my super name for server 2') + servers[1].store.video = data.find(video => video.name === 'my super name for server 2') }) it('Should not have abuses', async function () { @@ -402,8 +402,8 @@ describe('Test abuses', function () { before(async function () { this.timeout(50000) - servers[0].store.video = await await servers[0].videos.quickUpload({ name: 'server 1' }) - servers[1].store.video = await await servers[1].videos.quickUpload({ name: 'server 2' }) + servers[0].store.video = await servers[0].videos.quickUpload({ name: 'server 1' }) + servers[1].store.video = await servers[1].videos.quickUpload({ name: 'server 2' }) await servers[0].comments.createThread({ videoId: servers[0].store.video.id, text: 'comment server 1' }) await servers[1].comments.createThread({ videoId: servers[1].store.video.id, text: 'comment server 2' }) diff --git a/server/tests/api/redundancy/redundancy-constraints.ts b/server/tests/api/redundancy/redundancy-constraints.ts index 217691fb6..71b93901e 100644 --- a/server/tests/api/redundancy/redundancy-constraints.ts +++ b/server/tests/api/redundancy/redundancy-constraints.ts @@ -117,7 +117,7 @@ describe('Test redundancy constraints', function () { } } } - await await killallServers([ localServer ]) + await killallServers([ localServer ]) await localServer.run(config) await uploadWrapper('video 2 server 2') diff --git a/server/tests/api/redundancy/redundancy.ts b/server/tests/api/redundancy/redundancy.ts index 9d5d96efd..921a48856 100644 --- a/server/tests/api/redundancy/redundancy.ts +++ b/server/tests/api/redundancy/redundancy.ts @@ -5,7 +5,7 @@ import * as chai from 'chai' import { readdir } from 'fs-extra' import * as magnetUtil from 'magnet-uri' import { join } from 'path' -import { HttpStatusCode } from '@shared/core-utils' +import { HttpStatusCode } from '@shared/models' import { checkSegmentHash, checkVideoFilesWereRemoved, @@ -129,13 +129,13 @@ async function check2Webseeds (videoUUID?: string) { await makeGetRequest({ url: servers[0].url, - statusCodeExpected: HttpStatusCode.OK_200, + expectedStatus: HttpStatusCode.OK_200, path: '/static/redundancy/' + `${videoUUID}-${file.resolution.id}.mp4`, contentType: null }) await makeGetRequest({ url: servers[1].url, - statusCodeExpected: HttpStatusCode.OK_200, + expectedStatus: HttpStatusCode.OK_200, path: `/static/webseed/${videoUUID}-${file.resolution.id}.mp4`, contentType: null }) diff --git a/server/tests/api/search/search-activitypub-video-channels.ts b/server/tests/api/search/search-activitypub-video-channels.ts index f5896ec25..b33f28266 100644 --- a/server/tests/api/search/search-activitypub-video-channels.ts +++ b/server/tests/api/search/search-activitypub-video-channels.ts @@ -149,7 +149,7 @@ describe('Test ActivityPub video channels search', function () { const { total, data } = await servers[0].videos.listByChannel({ token: null, - videoChannelName: 'channel1_server2@localhost:' + servers[1].port + handle: 'channel1_server2@localhost:' + servers[1].port }) expect(total).to.equal(0) expect(data).to.have.lengthOf(0) @@ -157,7 +157,7 @@ describe('Test ActivityPub video channels search', function () { it('Should list video channel videos of server 2 with token', async function () { const { total, data } = await servers[0].videos.listByChannel({ - videoChannelName: 'channel1_server2@localhost:' + servers[1].port + handle: 'channel1_server2@localhost:' + servers[1].port }) expect(total).to.equal(1) @@ -206,8 +206,8 @@ describe('Test ActivityPub video channels search', function () { await waitJobs(servers) - const videoChannelName = 'channel1_server2@localhost:' + servers[1].port - const { total, data } = await servers[0].videos.listByChannel({ videoChannelName, sort: '-createdAt' }) + const handle = 'channel1_server2@localhost:' + servers[1].port + const { total, data } = await servers[0].videos.listByChannel({ handle, sort: '-createdAt' }) expect(total).to.equal(2) expect(data[0].name).to.equal('video 2 server 2') diff --git a/server/tests/api/server/config.ts b/server/tests/api/server/config.ts index a7191c5ef..a1c2f0f39 100644 --- a/server/tests/api/server/config.ts +++ b/server/tests/api/server/config.ts @@ -2,7 +2,7 @@ import 'mocha' import * as chai from 'chai' -import { HttpStatusCode } from '@shared/core-utils' +import { HttpStatusCode } from '@shared/models' import { cleanupTests, createSingleServer, @@ -498,7 +498,7 @@ describe('Test config', function () { const res = await makeGetRequest({ url: server.url, path: '/api/v1/config', - statusCodeExpected: 200 + expectedStatus: 200 }) expect(res.headers['x-frame-options']).to.exist @@ -517,7 +517,7 @@ describe('Test config', function () { const res = await makeGetRequest({ url: server.url, path: '/api/v1/config', - statusCodeExpected: 200 + expectedStatus: 200 }) expect(res.headers['x-frame-options']).to.not.exist diff --git a/server/tests/api/server/contact-form.ts b/server/tests/api/server/contact-form.ts index f0905bb3b..fc5d0ad6a 100644 --- a/server/tests/api/server/contact-form.ts +++ b/server/tests/api/server/contact-form.ts @@ -2,7 +2,7 @@ import 'mocha' import * as chai from 'chai' -import { HttpStatusCode } from '@shared/core-utils' +import { HttpStatusCode } from '@shared/models' import { cleanupTests, ContactFormCommand, diff --git a/server/tests/api/server/email.ts b/server/tests/api/server/email.ts index b202cf8a7..4c5b296ee 100644 --- a/server/tests/api/server/email.ts +++ b/server/tests/api/server/email.ts @@ -2,7 +2,7 @@ import 'mocha' import * as chai from 'chai' -import { HttpStatusCode } from '@shared/core-utils' +import { HttpStatusCode } from '@shared/models' import { cleanupTests, createSingleServer, MockSmtpServer, PeerTubeServer, setAccessTokensToServers, waitJobs } from '@shared/extra-utils' const expect = chai.expect diff --git a/server/tests/api/server/follow-constraints.ts b/server/tests/api/server/follow-constraints.ts index 4ed593b76..bd7b215db 100644 --- a/server/tests/api/server/follow-constraints.ts +++ b/server/tests/api/server/follow-constraints.ts @@ -2,7 +2,7 @@ import 'mocha' import * as chai from 'chai' -import { HttpStatusCode } from '@shared/core-utils' +import { HttpStatusCode } from '@shared/models' import { cleanupTests, doubleFollow, createMultipleServers, PeerTubeServer, setAccessTokensToServers } from '@shared/extra-utils' import { PeerTubeProblemDocument, ServerErrorCode } from '@shared/models' @@ -54,30 +54,30 @@ describe('Test follow constraints', function () { }) it('Should list local account videos', async function () { - const { total, data } = await servers[0].videos.listByAccount({ accountName: 'root@localhost:' + servers[0].port }) + const { total, data } = await servers[0].videos.listByAccount({ handle: 'root@localhost:' + servers[0].port }) expect(total).to.equal(1) expect(data).to.have.lengthOf(1) }) it('Should list remote account videos', async function () { - const { total, data } = await servers[0].videos.listByAccount({ accountName: 'root@localhost:' + servers[1].port }) + const { total, data } = await servers[0].videos.listByAccount({ handle: 'root@localhost:' + servers[1].port }) expect(total).to.equal(1) expect(data).to.have.lengthOf(1) }) it('Should list local channel videos', async function () { - const videoChannelName = 'root_channel@localhost:' + servers[0].port - const { total, data } = await servers[0].videos.listByChannel({ videoChannelName }) + const handle = 'root_channel@localhost:' + servers[0].port + const { total, data } = await servers[0].videos.listByChannel({ handle }) expect(total).to.equal(1) expect(data).to.have.lengthOf(1) }) it('Should list remote channel videos', async function () { - const videoChannelName = 'root_channel@localhost:' + servers[1].port - const { total, data } = await servers[0].videos.listByChannel({ videoChannelName }) + const handle = 'root_channel@localhost:' + servers[1].port + const { total, data } = await servers[0].videos.listByChannel({ handle }) expect(total).to.equal(1) expect(data).to.have.lengthOf(1) @@ -94,30 +94,30 @@ describe('Test follow constraints', function () { }) it('Should list local account videos', async function () { - const { total, data } = await servers[0].videos.listByAccount({ token: userToken, accountName: 'root@localhost:' + servers[0].port }) + const { total, data } = await servers[0].videos.listByAccount({ token: userToken, handle: 'root@localhost:' + servers[0].port }) expect(total).to.equal(1) expect(data).to.have.lengthOf(1) }) it('Should list remote account videos', async function () { - const { total, data } = await servers[0].videos.listByAccount({ token: userToken, accountName: 'root@localhost:' + servers[1].port }) + const { total, data } = await servers[0].videos.listByAccount({ token: userToken, handle: 'root@localhost:' + servers[1].port }) expect(total).to.equal(1) expect(data).to.have.lengthOf(1) }) it('Should list local channel videos', async function () { - const videoChannelName = 'root_channel@localhost:' + servers[0].port - const { total, data } = await servers[0].videos.listByChannel({ token: userToken, videoChannelName }) + const handle = 'root_channel@localhost:' + servers[0].port + const { total, data } = await servers[0].videos.listByChannel({ token: userToken, handle }) expect(total).to.equal(1) expect(data).to.have.lengthOf(1) }) it('Should list remote channel videos', async function () { - const videoChannelName = 'root_channel@localhost:' + servers[1].port - const { total, data } = await servers[0].videos.listByChannel({ token: userToken, videoChannelName }) + const handle = 'root_channel@localhost:' + servers[1].port + const { total, data } = await servers[0].videos.listByChannel({ token: userToken, handle }) expect(total).to.equal(1) expect(data).to.have.lengthOf(1) @@ -158,7 +158,7 @@ describe('Test follow constraints', function () { it('Should list local account videos', async function () { const { total, data } = await servers[0].videos.listByAccount({ token: undefined, - accountName: 'root@localhost:' + servers[0].port + handle: 'root@localhost:' + servers[0].port }) expect(total).to.equal(1) @@ -168,7 +168,7 @@ describe('Test follow constraints', function () { it('Should not list remote account videos', async function () { const { total, data } = await servers[0].videos.listByAccount({ token: undefined, - accountName: 'root@localhost:' + servers[1].port + handle: 'root@localhost:' + servers[1].port }) expect(total).to.equal(0) @@ -176,16 +176,16 @@ describe('Test follow constraints', function () { }) it('Should list local channel videos', async function () { - const videoChannelName = 'root_channel@localhost:' + servers[0].port - const { total, data } = await servers[0].videos.listByChannel({ token: undefined, videoChannelName }) + const handle = 'root_channel@localhost:' + servers[0].port + const { total, data } = await servers[0].videos.listByChannel({ token: undefined, handle }) expect(total).to.equal(1) expect(data).to.have.lengthOf(1) }) it('Should not list remote channel videos', async function () { - const videoChannelName = 'root_channel@localhost:' + servers[1].port - const { total, data } = await servers[0].videos.listByChannel({ token: undefined, videoChannelName }) + const handle = 'root_channel@localhost:' + servers[1].port + const { total, data } = await servers[0].videos.listByChannel({ token: undefined, handle }) expect(total).to.equal(0) expect(data).to.have.lengthOf(0) @@ -202,30 +202,30 @@ describe('Test follow constraints', function () { }) it('Should list local account videos', async function () { - const { total, data } = await servers[0].videos.listByAccount({ token: userToken, accountName: 'root@localhost:' + servers[0].port }) + const { total, data } = await servers[0].videos.listByAccount({ token: userToken, handle: 'root@localhost:' + servers[0].port }) expect(total).to.equal(1) expect(data).to.have.lengthOf(1) }) it('Should list remote account videos', async function () { - const { total, data } = await servers[0].videos.listByAccount({ token: userToken, accountName: 'root@localhost:' + servers[1].port }) + const { total, data } = await servers[0].videos.listByAccount({ token: userToken, handle: 'root@localhost:' + servers[1].port }) expect(total).to.equal(1) expect(data).to.have.lengthOf(1) }) it('Should list local channel videos', async function () { - const videoChannelName = 'root_channel@localhost:' + servers[0].port - const { total, data } = await servers[0].videos.listByChannel({ token: userToken, videoChannelName }) + const handle = 'root_channel@localhost:' + servers[0].port + const { total, data } = await servers[0].videos.listByChannel({ token: userToken, handle }) expect(total).to.equal(1) expect(data).to.have.lengthOf(1) }) it('Should list remote channel videos', async function () { - const videoChannelName = 'root_channel@localhost:' + servers[1].port - const { total, data } = await servers[0].videos.listByChannel({ token: userToken, videoChannelName }) + const handle = 'root_channel@localhost:' + servers[1].port + const { total, data } = await servers[0].videos.listByChannel({ token: userToken, handle }) expect(total).to.equal(1) expect(data).to.have.lengthOf(1) diff --git a/server/tests/api/server/handle-down.ts b/server/tests/api/server/handle-down.ts index 5f20b0093..d22e843e0 100644 --- a/server/tests/api/server/handle-down.ts +++ b/server/tests/api/server/handle-down.ts @@ -2,7 +2,7 @@ import 'mocha' import * as chai from 'chai' -import { HttpStatusCode } from '@shared/core-utils' +import { HttpStatusCode } from '@shared/models' import { cleanupTests, CommentsCommand, diff --git a/server/tests/api/server/homepage.ts b/server/tests/api/server/homepage.ts index c291037f2..7eae3df20 100644 --- a/server/tests/api/server/homepage.ts +++ b/server/tests/api/server/homepage.ts @@ -2,7 +2,7 @@ import 'mocha' import * as chai from 'chai' -import { HttpStatusCode } from '@shared/core-utils' +import { HttpStatusCode } from '@shared/models' import { cleanupTests, CustomPagesCommand, diff --git a/server/tests/api/server/no-client.ts b/server/tests/api/server/no-client.ts index f45222f2f..efa890ad4 100644 --- a/server/tests/api/server/no-client.ts +++ b/server/tests/api/server/no-client.ts @@ -1,8 +1,7 @@ import 'mocha' import * as request from 'supertest' -import { PeerTubeServer } from '../../../../shared/extra-utils' -import { cleanupTests, createSingleServer } from '../../../../shared/extra-utils/server/servers' -import { HttpStatusCode } from '../../../../shared/core-utils/miscs/http-error-codes' +import { cleanupTests, createSingleServer, PeerTubeServer } from '@shared/extra-utils' +import { HttpStatusCode } from '@shared/models' describe('Start and stop server without web client routes', function () { let server: PeerTubeServer diff --git a/server/tests/api/server/plugins.ts b/server/tests/api/server/plugins.ts index db03d026a..334adfe9d 100644 --- a/server/tests/api/server/plugins.ts +++ b/server/tests/api/server/plugins.ts @@ -2,7 +2,7 @@ import 'mocha' import * as chai from 'chai' -import { HttpStatusCode } from '@shared/core-utils' +import { HttpStatusCode } from '@shared/models' import { cleanupTests, createSingleServer, diff --git a/server/tests/api/server/reverse-proxy.ts b/server/tests/api/server/reverse-proxy.ts index c20b7a5f0..13b22bc0e 100644 --- a/server/tests/api/server/reverse-proxy.ts +++ b/server/tests/api/server/reverse-proxy.ts @@ -1,7 +1,7 @@ /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */ import { expect } from 'chai' -import { HttpStatusCode } from '@shared/core-utils' +import { HttpStatusCode } from '@shared/models' import { cleanupTests, createSingleServer, PeerTubeServer, setAccessTokensToServers, wait } from '@shared/extra-utils' describe('Test application behind a reverse proxy', function () { diff --git a/server/tests/api/users/users-multiple-servers.ts b/server/tests/api/users/users-multiple-servers.ts index e629966bb..e304e5d67 100644 --- a/server/tests/api/users/users-multiple-servers.ts +++ b/server/tests/api/users/users-multiple-servers.ts @@ -131,7 +131,7 @@ describe('Test users with multiple servers', function () { it('Should list account videos', async function () { for (const server of servers) { - const { total, data } = await server.videos.listByAccount({ accountName: 'user1@localhost:' + servers[0].port }) + const { total, data } = await server.videos.listByAccount({ handle: 'user1@localhost:' + servers[0].port }) expect(total).to.equal(1) expect(data).to.be.an('array') @@ -148,7 +148,7 @@ describe('Test users with multiple servers', function () { await waitJobs(servers) for (const server of servers) { - const { total, data } = await server.videos.listByAccount({ accountName: 'user1@localhost:' + servers[0].port, search: 'Kami' }) + const { total, data } = await server.videos.listByAccount({ handle: 'user1@localhost:' + servers[0].port, search: 'Kami' }) expect(total).to.equal(1) expect(data).to.be.an('array') diff --git a/server/tests/api/users/users-verification.ts b/server/tests/api/users/users-verification.ts index 5dbe2af59..56fc25048 100644 --- a/server/tests/api/users/users-verification.ts +++ b/server/tests/api/users/users-verification.ts @@ -2,7 +2,7 @@ import 'mocha' import * as chai from 'chai' -import { HttpStatusCode } from '@shared/core-utils' +import { HttpStatusCode } from '@shared/models' import { cleanupTests, createSingleServer, MockSmtpServer, PeerTubeServer, setAccessTokensToServers, waitJobs } from '@shared/extra-utils' const expect = chai.expect diff --git a/server/tests/api/users/users.ts b/server/tests/api/users/users.ts index 6ae5410b3..be80c2616 100644 --- a/server/tests/api/users/users.ts +++ b/server/tests/api/users/users.ts @@ -2,7 +2,7 @@ import 'mocha' import * as chai from 'chai' -import { HttpStatusCode } from '@shared/core-utils' +import { HttpStatusCode } from '@shared/models' import { cleanupTests, createSingleServer, @@ -215,7 +215,7 @@ describe('Test users', function () { path: path + videoId, token: 'wrong token', fields: data, - statusCodeExpected: HttpStatusCode.UNAUTHORIZED_401 + expectedStatus: HttpStatusCode.UNAUTHORIZED_401 } await makePutBodyRequest(options) }) diff --git a/server/tests/api/videos/multiple-servers.ts b/server/tests/api/videos/multiple-servers.ts index 562079a15..edf2773cd 100644 --- a/server/tests/api/videos/multiple-servers.ts +++ b/server/tests/api/videos/multiple-servers.ts @@ -3,7 +3,7 @@ import 'mocha' import * as chai from 'chai' import * as request from 'supertest' -import { HttpStatusCode } from '@shared/core-utils' +import { HttpStatusCode } from '@shared/models' import { buildAbsoluteFixturePath, checkTmpIsEmpty, diff --git a/server/tests/api/videos/resumable-upload.ts b/server/tests/api/videos/resumable-upload.ts index b4fc5ee09..0e62972c2 100644 --- a/server/tests/api/videos/resumable-upload.ts +++ b/server/tests/api/videos/resumable-upload.ts @@ -4,7 +4,7 @@ import 'mocha' import * as chai from 'chai' import { pathExists, readdir, stat } from 'fs-extra' import { join } from 'path' -import { HttpStatusCode } from '@shared/core-utils' +import { HttpStatusCode } from '@shared/models' import { buildAbsoluteFixturePath, cleanupTests, diff --git a/server/tests/api/videos/video-change-ownership.ts b/server/tests/api/videos/video-change-ownership.ts index cefddb68e..792550101 100644 --- a/server/tests/api/videos/video-change-ownership.ts +++ b/server/tests/api/videos/video-change-ownership.ts @@ -2,7 +2,7 @@ import 'mocha' import * as chai from 'chai' -import { HttpStatusCode } from '@shared/core-utils' +import { HttpStatusCode } from '@shared/models' import { ChangeOwnershipCommand, cleanupTests, diff --git a/server/tests/api/videos/video-channels.ts b/server/tests/api/videos/video-channels.ts index 140fee7fe..eeaec5ad2 100644 --- a/server/tests/api/videos/video-channels.ts +++ b/server/tests/api/videos/video-channels.ts @@ -324,7 +324,7 @@ describe('Test video channels', function () { for (const server of servers) { const channelURI = 'second_video_channel@localhost:' + servers[0].port - const { total, data } = await server.videos.listByChannel({ videoChannelName: channelURI }) + const { total, data } = await server.videos.listByChannel({ handle: channelURI }) expect(total).to.equal(1) expect(data).to.be.an('array') @@ -347,13 +347,13 @@ describe('Test video channels', function () { for (const server of servers) { { const secondChannelURI = 'second_video_channel@localhost:' + servers[0].port - const { total } = await server.videos.listByChannel({ videoChannelName: secondChannelURI }) + const { total } = await server.videos.listByChannel({ handle: secondChannelURI }) expect(total).to.equal(0) } { const channelURI = 'root_channel@localhost:' + servers[0].port - const { total, data } = await server.videos.listByChannel({ videoChannelName: channelURI }) + const { total, data } = await server.videos.listByChannel({ handle: channelURI }) expect(total).to.equal(1) expect(data).to.be.an('array') diff --git a/server/tests/api/videos/video-hls.ts b/server/tests/api/videos/video-hls.ts index 4c4b18887..df030110b 100644 --- a/server/tests/api/videos/video-hls.ts +++ b/server/tests/api/videos/video-hls.ts @@ -3,7 +3,7 @@ import 'mocha' import * as chai from 'chai' import { join } from 'path' -import { HttpStatusCode } from '@shared/core-utils' +import { HttpStatusCode } from '@shared/models' import { checkDirectoryIsEmpty, checkResolutionsInMasterPlaylist, diff --git a/server/tests/api/videos/video-nsfw.ts b/server/tests/api/videos/video-nsfw.ts index b25dcda20..0a9e5ce3f 100644 --- a/server/tests/api/videos/video-nsfw.ts +++ b/server/tests/api/videos/video-nsfw.ts @@ -19,8 +19,10 @@ describe('Test video NSFW policy', function () { async function getVideosFunctions (token?: string, query: { nsfw?: BooleanBothQuery } = {}) { const user = await server.users.getMyInfo() - const videoChannelName = user.videoChannels[0].name + + const channelName = user.videoChannels[0].name const accountName = user.account.name + '@' + user.account.host + const hasQuery = Object.keys(query).length !== 0 let promises: Promise>[] @@ -28,8 +30,8 @@ describe('Test video NSFW policy', function () { promises = [ server.search.advancedVideoSearch({ token, search: { search: 'n', sort: '-publishedAt', ...query } }), server.videos.listWithToken({ token, ...query }), - server.videos.listByAccount({ token, accountName, ...query }), - server.videos.listByChannel({ token, videoChannelName, ...query }) + server.videos.listByAccount({ token, handle: channelName, ...query }), + server.videos.listByChannel({ token, handle: accountName, ...query }) ] // Overviews do not support video filters @@ -45,8 +47,8 @@ describe('Test video NSFW policy', function () { promises = [ server.search.searchVideos({ search: 'n', sort: '-publishedAt' }), server.videos.list(), - server.videos.listByAccount({ accountName }), - server.videos.listByChannel({ videoChannelName }) + server.videos.listByAccount({ handle: channelName }), + server.videos.listByChannel({ handle: accountName }) ] // Overviews do not support video filters diff --git a/server/tests/api/videos/video-playlists.ts b/server/tests/api/videos/video-playlists.ts index 71ca3e63a..9a28a421a 100644 --- a/server/tests/api/videos/video-playlists.ts +++ b/server/tests/api/videos/video-playlists.ts @@ -2,7 +2,7 @@ import 'mocha' import * as chai from 'chai' -import { HttpStatusCode } from '@shared/core-utils' +import { HttpStatusCode } from '@shared/models' import { checkPlaylistFilesWereRemoved, cleanupTests, diff --git a/server/tests/api/videos/video-privacy.ts b/server/tests/api/videos/video-privacy.ts index 5ec626155..06011082d 100644 --- a/server/tests/api/videos/video-privacy.ts +++ b/server/tests/api/videos/video-privacy.ts @@ -2,7 +2,7 @@ import 'mocha' import * as chai from 'chai' -import { HttpStatusCode } from '@shared/core-utils' +import { HttpStatusCode } from '@shared/models' import { cleanupTests, doubleFollow, createSingleServer, PeerTubeServer, setAccessTokensToServers, waitJobs } from '@shared/extra-utils' import { VideoCreateResult, VideoPrivacy } from '@shared/models' diff --git a/server/tests/api/videos/video-transcoder.ts b/server/tests/api/videos/video-transcoder.ts index 2465d2d89..7510472e3 100644 --- a/server/tests/api/videos/video-transcoder.ts +++ b/server/tests/api/videos/video-transcoder.ts @@ -4,7 +4,7 @@ import 'mocha' import * as chai from 'chai' import { omit } from 'lodash' import { join } from 'path' -import { HttpStatusCode } from '@shared/core-utils' +import { HttpStatusCode } from '@shared/models' import { buildAbsoluteFixturePath, cleanupTests, @@ -384,8 +384,8 @@ describe('Test video transcoding', function () { expect(videoDetails.files).to.have.lengthOf(1) - await makeGetRequest({ url: server.url, path: videoDetails.thumbnailPath, statusCodeExpected: HttpStatusCode.OK_200 }) - await makeGetRequest({ url: server.url, path: videoDetails.previewPath, statusCodeExpected: HttpStatusCode.OK_200 }) + await makeGetRequest({ url: server.url, path: videoDetails.thumbnailPath, expectedStatus: HttpStatusCode.OK_200 }) + await makeGetRequest({ url: server.url, path: videoDetails.previewPath, expectedStatus: HttpStatusCode.OK_200 }) const magnetUri = videoDetails.files[0].magnetUri expect(magnetUri).to.contain('.mp4') @@ -408,8 +408,8 @@ describe('Test video transcoding', function () { expect(videoDetails.files).to.have.lengthOf(1) - await makeGetRequest({ url: server.url, path: videoDetails.thumbnailPath, statusCodeExpected: HttpStatusCode.OK_200 }) - await makeGetRequest({ url: server.url, path: videoDetails.previewPath, statusCodeExpected: HttpStatusCode.OK_200 }) + await makeGetRequest({ url: server.url, path: videoDetails.thumbnailPath, expectedStatus: HttpStatusCode.OK_200 }) + await makeGetRequest({ url: server.url, path: videoDetails.previewPath, expectedStatus: HttpStatusCode.OK_200 }) const magnetUri = videoDetails.files[0].magnetUri expect(magnetUri).to.contain('.mp4') diff --git a/server/tests/api/videos/videos-filter.ts b/server/tests/api/videos/videos-filter.ts index db9150655..88dff3e7f 100644 --- a/server/tests/api/videos/videos-filter.ts +++ b/server/tests/api/videos/videos-filter.ts @@ -2,7 +2,7 @@ import 'mocha' import { expect } from 'chai' -import { HttpStatusCode } from '@shared/core-utils' +import { HttpStatusCode } from '@shared/models' import { cleanupTests, doubleFollow, @@ -13,7 +13,7 @@ import { } from '@shared/extra-utils' import { UserRole, Video, VideoPrivacy } from '@shared/models' -async function getVideosNames (server: PeerTubeServer, token: string, filter: string, statusCodeExpected = HttpStatusCode.OK_200) { +async function getVideosNames (server: PeerTubeServer, token: string, filter: string, expectedStatus = HttpStatusCode.OK_200) { const paths = [ '/api/v1/video-channels/root_channel/videos', '/api/v1/accounts/root/videos', @@ -32,7 +32,7 @@ async function getVideosNames (server: PeerTubeServer, token: string, filter: st sort: 'createdAt', filter }, - statusCodeExpected + expectedStatus }) videosResults.push(res.body.data.map(v => v.name)) diff --git a/server/tests/api/videos/videos-history.ts b/server/tests/api/videos/videos-history.ts index 55e53cb94..acb9d1a46 100644 --- a/server/tests/api/videos/videos-history.ts +++ b/server/tests/api/videos/videos-history.ts @@ -2,7 +2,7 @@ import 'mocha' import * as chai from 'chai' -import { HttpStatusCode } from '@shared/core-utils' +import { HttpStatusCode } from '@shared/models' import { cleanupTests, createSingleServer, -- 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/activitypub/cleaner.ts | 2 +- server/tests/api/activitypub/client.ts | 5 ++--- server/tests/api/activitypub/fetch.ts | 2 +- server/tests/api/activitypub/refresher.ts | 5 ++--- 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 +- server/tests/api/live/live-constraints.ts | 2 +- server/tests/api/live/live-permanent.ts | 2 +- server/tests/api/live/live-save-replay.ts | 5 ++--- server/tests/api/live/live-socket-messages.ts | 2 +- server/tests/api/live/live-views.ts | 2 +- server/tests/api/live/live.ts | 15 +++++++++++---- server/tests/api/moderation/blocklist-notification.ts | 2 +- server/tests/api/moderation/blocklist.ts | 2 +- server/tests/api/notifications/admin-notifications.ts | 2 +- server/tests/api/notifications/comments-notifications.ts | 2 +- .../tests/api/notifications/moderation-notifications.ts | 2 +- server/tests/api/notifications/notifications-api.ts | 2 +- server/tests/api/redundancy/manage-redundancy.ts | 4 ++-- server/tests/api/redundancy/redundancy-constraints.ts | 9 +-------- server/tests/api/redundancy/redundancy.ts | 7 +++---- .../tests/api/search/search-activitypub-video-channels.ts | 2 +- .../api/search/search-activitypub-video-playlists.ts | 2 +- server/tests/api/search/search-activitypub-videos.ts | 2 +- server/tests/api/search/search-channels.ts | 2 +- server/tests/api/search/search-index.ts | 2 +- server/tests/api/search/search-playlists.ts | 2 +- server/tests/api/search/search-videos.ts | 2 +- server/tests/api/server/bulk.ts | 2 +- server/tests/api/server/config.ts | 3 +-- server/tests/api/server/contact-form.ts | 2 +- server/tests/api/server/email.ts | 2 +- server/tests/api/server/follow-constraints.ts | 13 ++++++------- server/tests/api/server/follows.ts | 2 +- server/tests/api/server/handle-down.ts | 3 +-- server/tests/api/server/homepage.ts | 2 +- server/tests/api/server/jobs.ts | 2 +- server/tests/api/server/plugins.ts | 5 ++--- server/tests/api/server/reverse-proxy.ts | 2 +- server/tests/api/server/stats.ts | 2 +- server/tests/api/users/user-subscriptions.ts | 5 +++-- server/tests/api/users/users-multiple-servers.ts | 2 +- server/tests/api/users/users-verification.ts | 2 +- server/tests/api/users/users.ts | 3 +-- server/tests/api/videos/audio-only.ts | 2 +- server/tests/api/videos/multiple-servers.ts | 5 ++--- server/tests/api/videos/resumable-upload.ts | 3 +-- server/tests/api/videos/video-captions.ts | 2 +- server/tests/api/videos/video-change-ownership.ts | 5 ++--- server/tests/api/videos/video-channels.ts | 2 +- server/tests/api/videos/video-comments.ts | 2 +- server/tests/api/videos/video-description.ts | 2 +- server/tests/api/videos/video-hls.ts | 5 ++--- server/tests/api/videos/video-nsfw.ts | 9 +++++---- server/tests/api/videos/video-playlist-thumbnails.ts | 2 +- server/tests/api/videos/video-playlists.ts | 6 +++--- server/tests/api/videos/video-privacy.ts | 7 +++---- server/tests/api/videos/video-schedule-update.ts | 2 +- server/tests/api/videos/video-transcoder.ts | 5 ++--- server/tests/api/videos/videos-filter.ts | 5 ++--- server/tests/api/videos/videos-history.ts | 3 +-- server/tests/api/videos/videos-views-cleaner.ts | 2 +- 78 files changed, 119 insertions(+), 147 deletions(-) (limited to 'server/tests/api') diff --git a/server/tests/api/activitypub/cleaner.ts b/server/tests/api/activitypub/cleaner.ts index a5ce449f3..51cf6e599 100644 --- a/server/tests/api/activitypub/cleaner.ts +++ b/server/tests/api/activitypub/cleaner.ts @@ -4,8 +4,8 @@ import 'mocha' import * as chai from 'chai' import { cleanupTests, - doubleFollow, createMultipleServers, + doubleFollow, PeerTubeServer, setAccessTokensToServers, wait, diff --git a/server/tests/api/activitypub/client.ts b/server/tests/api/activitypub/client.ts index 53cc40663..c3e4b7f74 100644 --- a/server/tests/api/activitypub/client.ts +++ b/server/tests/api/activitypub/client.ts @@ -2,17 +2,16 @@ import 'mocha' import * as chai from 'chai' -import { HttpStatusCode } from '@shared/models' import { cleanupTests, - doubleFollow, createMultipleServers, + doubleFollow, makeActivityPubGetRequest, PeerTubeServer, setAccessTokensToServers, setDefaultVideoChannel } from '@shared/extra-utils' -import { VideoPlaylistPrivacy } from '@shared/models' +import { HttpStatusCode, VideoPlaylistPrivacy } from '@shared/models' const expect = chai.expect diff --git a/server/tests/api/activitypub/fetch.ts b/server/tests/api/activitypub/fetch.ts index ddfe6cfe0..422a75d6e 100644 --- a/server/tests/api/activitypub/fetch.ts +++ b/server/tests/api/activitypub/fetch.ts @@ -2,7 +2,7 @@ import 'mocha' import * as chai from 'chai' -import { cleanupTests, doubleFollow, createMultipleServers, PeerTubeServer, setAccessTokensToServers, waitJobs } from '@shared/extra-utils' +import { cleanupTests, createMultipleServers, doubleFollow, PeerTubeServer, setAccessTokensToServers, waitJobs } from '@shared/extra-utils' const expect = chai.expect diff --git a/server/tests/api/activitypub/refresher.ts b/server/tests/api/activitypub/refresher.ts index a0b72c7e6..81fee0044 100644 --- a/server/tests/api/activitypub/refresher.ts +++ b/server/tests/api/activitypub/refresher.ts @@ -1,11 +1,10 @@ /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */ import 'mocha' -import { HttpStatusCode } from '@shared/models' import { cleanupTests, - doubleFollow, createMultipleServers, + doubleFollow, killallServers, PeerTubeServer, setAccessTokensToServers, @@ -13,7 +12,7 @@ import { wait, waitJobs } from '@shared/extra-utils' -import { VideoPlaylistPrivacy } from '@shared/models' +import { HttpStatusCode, VideoPlaylistPrivacy } from '@shared/models' describe('Test AP refresher', function () { let servers: PeerTubeServer[] = [] 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' diff --git a/server/tests/api/live/live-constraints.ts b/server/tests/api/live/live-constraints.ts index a00833569..20346113d 100644 --- a/server/tests/api/live/live-constraints.ts +++ b/server/tests/api/live/live-constraints.ts @@ -7,8 +7,8 @@ import { checkLiveCleanup, cleanupTests, ConfigCommand, - doubleFollow, createMultipleServers, + doubleFollow, PeerTubeServer, setAccessTokensToServers, setDefaultVideoChannel, diff --git a/server/tests/api/live/live-permanent.ts b/server/tests/api/live/live-permanent.ts index 30d499e20..f07d4cfec 100644 --- a/server/tests/api/live/live-permanent.ts +++ b/server/tests/api/live/live-permanent.ts @@ -6,8 +6,8 @@ import { LiveVideoCreate, VideoPrivacy, VideoState } from '@shared/models' import { cleanupTests, ConfigCommand, - doubleFollow, createMultipleServers, + doubleFollow, PeerTubeServer, setAccessTokensToServers, setDefaultVideoChannel, diff --git a/server/tests/api/live/live-save-replay.ts b/server/tests/api/live/live-save-replay.ts index 095c51b97..bd15396ec 100644 --- a/server/tests/api/live/live-save-replay.ts +++ b/server/tests/api/live/live-save-replay.ts @@ -3,13 +3,12 @@ import 'mocha' import * as chai from 'chai' import { FfmpegCommand } from 'fluent-ffmpeg' -import { HttpStatusCode } from '@shared/models' import { checkLiveCleanup, cleanupTests, ConfigCommand, - doubleFollow, createMultipleServers, + doubleFollow, PeerTubeServer, setAccessTokensToServers, setDefaultVideoChannel, @@ -18,7 +17,7 @@ import { wait, waitJobs } from '@shared/extra-utils' -import { LiveVideoCreate, VideoPrivacy, VideoState } from '@shared/models' +import { HttpStatusCode, LiveVideoCreate, VideoPrivacy, VideoState } from '@shared/models' const expect = chai.expect diff --git a/server/tests/api/live/live-socket-messages.ts b/server/tests/api/live/live-socket-messages.ts index 3808964d1..2a1f9f108 100644 --- a/server/tests/api/live/live-socket-messages.ts +++ b/server/tests/api/live/live-socket-messages.ts @@ -5,8 +5,8 @@ import * as chai from 'chai' import { VideoPrivacy, VideoState } from '@shared/models' import { cleanupTests, - doubleFollow, createMultipleServers, + doubleFollow, PeerTubeServer, setAccessTokensToServers, setDefaultVideoChannel, diff --git a/server/tests/api/live/live-views.ts b/server/tests/api/live/live-views.ts index 4a137b185..5e3a79c64 100644 --- a/server/tests/api/live/live-views.ts +++ b/server/tests/api/live/live-views.ts @@ -6,8 +6,8 @@ import { FfmpegCommand } from 'fluent-ffmpeg' import { VideoPrivacy } from '@shared/models' import { cleanupTests, - doubleFollow, createMultipleServers, + doubleFollow, PeerTubeServer, setAccessTokensToServers, setDefaultVideoChannel, diff --git a/server/tests/api/live/live.ts b/server/tests/api/live/live.ts index 88995910c..4676a840a 100644 --- a/server/tests/api/live/live.ts +++ b/server/tests/api/live/live.ts @@ -4,19 +4,18 @@ import 'mocha' import * as chai from 'chai' import { join } from 'path' import { ffprobePromise, getVideoStreamFromFile } from '@server/helpers/ffprobe-utils' -import { HttpStatusCode } from '@shared/models' import { checkLiveCleanup, checkLiveSegmentHash, checkResolutionsInMasterPlaylist, cleanupTests, - doubleFollow, createMultipleServers, + doubleFollow, killallServers, LiveCommand, makeRawRequest, - sendRTMPStream, PeerTubeServer, + sendRTMPStream, setAccessTokensToServers, setDefaultVideoChannel, stopFfmpeg, @@ -26,7 +25,15 @@ import { waitJobs, waitUntilLivePublishedOnAllServers } from '@shared/extra-utils' -import { LiveVideo, LiveVideoCreate, VideoDetails, VideoPrivacy, VideoState, VideoStreamingPlaylistType } from '@shared/models' +import { + HttpStatusCode, + LiveVideo, + LiveVideoCreate, + VideoDetails, + VideoPrivacy, + VideoState, + VideoStreamingPlaylistType +} from '@shared/models' const expect = chai.expect diff --git a/server/tests/api/moderation/blocklist-notification.ts b/server/tests/api/moderation/blocklist-notification.ts index fdfbcbced..75b15c298 100644 --- a/server/tests/api/moderation/blocklist-notification.ts +++ b/server/tests/api/moderation/blocklist-notification.ts @@ -2,7 +2,7 @@ import 'mocha' import * as chai from 'chai' -import { cleanupTests, doubleFollow, createMultipleServers, PeerTubeServer, setAccessTokensToServers, waitJobs } from '@shared/extra-utils' +import { cleanupTests, createMultipleServers, doubleFollow, PeerTubeServer, setAccessTokensToServers, waitJobs } from '@shared/extra-utils' import { UserNotificationType } from '@shared/models' const expect = chai.expect diff --git a/server/tests/api/moderation/blocklist.ts b/server/tests/api/moderation/blocklist.ts index 593291e87..8ed5ad9e5 100644 --- a/server/tests/api/moderation/blocklist.ts +++ b/server/tests/api/moderation/blocklist.ts @@ -6,8 +6,8 @@ import { BlocklistCommand, cleanupTests, CommentsCommand, - doubleFollow, createMultipleServers, + doubleFollow, PeerTubeServer, setAccessTokensToServers, waitJobs diff --git a/server/tests/api/notifications/admin-notifications.ts b/server/tests/api/notifications/admin-notifications.ts index d65551f0a..b36ba11a9 100644 --- a/server/tests/api/notifications/admin-notifications.ts +++ b/server/tests/api/notifications/admin-notifications.ts @@ -9,8 +9,8 @@ import { cleanupTests, MockJoinPeerTubeVersions, MockSmtpServer, - prepareNotificationsTest, PeerTubeServer, + prepareNotificationsTest, wait } from '@shared/extra-utils' import { PluginType, UserNotification, UserNotificationType } from '@shared/models' diff --git a/server/tests/api/notifications/comments-notifications.ts b/server/tests/api/notifications/comments-notifications.ts index d54819aaa..cbb46e510 100644 --- a/server/tests/api/notifications/comments-notifications.ts +++ b/server/tests/api/notifications/comments-notifications.ts @@ -8,8 +8,8 @@ import { checkNewCommentOnMyVideo, cleanupTests, MockSmtpServer, - prepareNotificationsTest, PeerTubeServer, + prepareNotificationsTest, waitJobs } from '@shared/extra-utils' import { UserNotification } from '@shared/models' diff --git a/server/tests/api/notifications/moderation-notifications.ts b/server/tests/api/notifications/moderation-notifications.ts index 3a294192b..6e8f8a2b4 100644 --- a/server/tests/api/notifications/moderation-notifications.ts +++ b/server/tests/api/notifications/moderation-notifications.ts @@ -19,8 +19,8 @@ import { cleanupTests, MockInstancesIndex, MockSmtpServer, - prepareNotificationsTest, PeerTubeServer, + prepareNotificationsTest, wait, waitJobs } from '@shared/extra-utils' diff --git a/server/tests/api/notifications/notifications-api.ts b/server/tests/api/notifications/notifications-api.ts index 178b20687..fa4b53db6 100644 --- a/server/tests/api/notifications/notifications-api.ts +++ b/server/tests/api/notifications/notifications-api.ts @@ -8,8 +8,8 @@ import { cleanupTests, getAllNotificationsSettings, MockSmtpServer, - prepareNotificationsTest, PeerTubeServer, + prepareNotificationsTest, waitJobs } from '@shared/extra-utils' import { UserNotification, UserNotificationSettingValue } from '@shared/models' diff --git a/server/tests/api/redundancy/manage-redundancy.ts b/server/tests/api/redundancy/manage-redundancy.ts index aff64e2eb..5fd464ded 100644 --- a/server/tests/api/redundancy/manage-redundancy.ts +++ b/server/tests/api/redundancy/manage-redundancy.ts @@ -4,10 +4,10 @@ import 'mocha' import * as chai from 'chai' import { cleanupTests, - doubleFollow, createMultipleServers, - RedundancyCommand, + doubleFollow, PeerTubeServer, + RedundancyCommand, setAccessTokensToServers, waitJobs } from '@shared/extra-utils' diff --git a/server/tests/api/redundancy/redundancy-constraints.ts b/server/tests/api/redundancy/redundancy-constraints.ts index 71b93901e..25cd11658 100644 --- a/server/tests/api/redundancy/redundancy-constraints.ts +++ b/server/tests/api/redundancy/redundancy-constraints.ts @@ -2,14 +2,7 @@ import 'mocha' import { expect } from 'chai' -import { - cleanupTests, - createSingleServer, - killallServers, - PeerTubeServer, - setAccessTokensToServers, - waitJobs -} from '@shared/extra-utils' +import { cleanupTests, createSingleServer, killallServers, PeerTubeServer, setAccessTokensToServers, waitJobs } from '@shared/extra-utils' import { VideoPrivacy } from '@shared/models' describe('Test redundancy constraints', function () { diff --git a/server/tests/api/redundancy/redundancy.ts b/server/tests/api/redundancy/redundancy.ts index 921a48856..a6559d304 100644 --- a/server/tests/api/redundancy/redundancy.ts +++ b/server/tests/api/redundancy/redundancy.ts @@ -5,22 +5,21 @@ import * as chai from 'chai' import { readdir } from 'fs-extra' import * as magnetUtil from 'magnet-uri' import { join } from 'path' -import { HttpStatusCode } from '@shared/models' import { checkSegmentHash, checkVideoFilesWereRemoved, cleanupTests, - doubleFollow, createMultipleServers, + doubleFollow, killallServers, makeGetRequest, - root, PeerTubeServer, + root, setAccessTokensToServers, wait, waitJobs } from '@shared/extra-utils' -import { VideoPrivacy, VideoRedundancyStrategy, VideoRedundancyStrategyWithManual } from '@shared/models' +import { HttpStatusCode, VideoPrivacy, VideoRedundancyStrategy, VideoRedundancyStrategyWithManual } from '@shared/models' const expect = chai.expect diff --git a/server/tests/api/search/search-activitypub-video-channels.ts b/server/tests/api/search/search-activitypub-video-channels.ts index b33f28266..426cbc8e1 100644 --- a/server/tests/api/search/search-activitypub-video-channels.ts +++ b/server/tests/api/search/search-activitypub-video-channels.ts @@ -5,8 +5,8 @@ import * as chai from 'chai' import { cleanupTests, createMultipleServers, - SearchCommand, PeerTubeServer, + SearchCommand, setAccessTokensToServers, wait, waitJobs diff --git a/server/tests/api/search/search-activitypub-video-playlists.ts b/server/tests/api/search/search-activitypub-video-playlists.ts index ada2d3d6c..33ca7be12 100644 --- a/server/tests/api/search/search-activitypub-video-playlists.ts +++ b/server/tests/api/search/search-activitypub-video-playlists.ts @@ -5,8 +5,8 @@ import * as chai from 'chai' import { cleanupTests, createMultipleServers, - SearchCommand, PeerTubeServer, + SearchCommand, setAccessTokensToServers, setDefaultVideoChannel, wait, diff --git a/server/tests/api/search/search-activitypub-videos.ts b/server/tests/api/search/search-activitypub-videos.ts index a015b72a7..b3cfcacca 100644 --- a/server/tests/api/search/search-activitypub-videos.ts +++ b/server/tests/api/search/search-activitypub-videos.ts @@ -5,8 +5,8 @@ import * as chai from 'chai' import { cleanupTests, createMultipleServers, - SearchCommand, PeerTubeServer, + SearchCommand, setAccessTokensToServers, wait, waitJobs diff --git a/server/tests/api/search/search-channels.ts b/server/tests/api/search/search-channels.ts index 07e00a214..4da2d0ece 100644 --- a/server/tests/api/search/search-channels.ts +++ b/server/tests/api/search/search-channels.ts @@ -2,7 +2,7 @@ import 'mocha' import * as chai from 'chai' -import { cleanupTests, createSingleServer, SearchCommand, PeerTubeServer, setAccessTokensToServers } from '@shared/extra-utils' +import { cleanupTests, createSingleServer, PeerTubeServer, SearchCommand, setAccessTokensToServers } from '@shared/extra-utils' import { VideoChannel } from '@shared/models' const expect = chai.expect diff --git a/server/tests/api/search/search-index.ts b/server/tests/api/search/search-index.ts index 38edcf7c6..feb35411f 100644 --- a/server/tests/api/search/search-index.ts +++ b/server/tests/api/search/search-index.ts @@ -2,7 +2,7 @@ import 'mocha' import * as chai from 'chai' -import { cleanupTests, createSingleServer, SearchCommand, PeerTubeServer, setAccessTokensToServers } from '@shared/extra-utils' +import { cleanupTests, createSingleServer, PeerTubeServer, SearchCommand, setAccessTokensToServers } from '@shared/extra-utils' import { BooleanBothQuery, VideoPlaylistPrivacy, VideoPlaylistType, VideosSearchQuery } from '@shared/models' const expect = chai.expect diff --git a/server/tests/api/search/search-playlists.ts b/server/tests/api/search/search-playlists.ts index b29c2d127..22e9b8fca 100644 --- a/server/tests/api/search/search-playlists.ts +++ b/server/tests/api/search/search-playlists.ts @@ -5,8 +5,8 @@ import * as chai from 'chai' import { cleanupTests, createSingleServer, - SearchCommand, PeerTubeServer, + SearchCommand, setAccessTokensToServers, setDefaultVideoChannel } from '@shared/extra-utils' diff --git a/server/tests/api/search/search-videos.ts b/server/tests/api/search/search-videos.ts index a9b0a4fcd..f834c7f36 100644 --- a/server/tests/api/search/search-videos.ts +++ b/server/tests/api/search/search-videos.ts @@ -5,8 +5,8 @@ import * as chai from 'chai' import { cleanupTests, createSingleServer, - SearchCommand, PeerTubeServer, + SearchCommand, setAccessTokensToServers, setDefaultVideoChannel, stopFfmpeg, diff --git a/server/tests/api/server/bulk.ts b/server/tests/api/server/bulk.ts index 5d8c87983..16cbcd5c3 100644 --- a/server/tests/api/server/bulk.ts +++ b/server/tests/api/server/bulk.ts @@ -5,8 +5,8 @@ import * as chai from 'chai' import { BulkCommand, cleanupTests, - doubleFollow, createMultipleServers, + doubleFollow, PeerTubeServer, setAccessTokensToServers, waitJobs diff --git a/server/tests/api/server/config.ts b/server/tests/api/server/config.ts index a1c2f0f39..fd61e95df 100644 --- a/server/tests/api/server/config.ts +++ b/server/tests/api/server/config.ts @@ -2,7 +2,6 @@ import 'mocha' import * as chai from 'chai' -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' const expect = chai.expect diff --git a/server/tests/api/server/contact-form.ts b/server/tests/api/server/contact-form.ts index fc5d0ad6a..c555661ad 100644 --- a/server/tests/api/server/contact-form.ts +++ b/server/tests/api/server/contact-form.ts @@ -2,7 +2,6 @@ import 'mocha' import * as chai from 'chai' -import { HttpStatusCode } from '@shared/models' import { cleanupTests, ContactFormCommand, @@ -13,6 +12,7 @@ import { wait, waitJobs } from '@shared/extra-utils' +import { HttpStatusCode } from '@shared/models' const expect = chai.expect diff --git a/server/tests/api/server/email.ts b/server/tests/api/server/email.ts index 4c5b296ee..ae86b380f 100644 --- a/server/tests/api/server/email.ts +++ b/server/tests/api/server/email.ts @@ -2,8 +2,8 @@ import 'mocha' import * as chai from 'chai' -import { HttpStatusCode } from '@shared/models' import { cleanupTests, createSingleServer, MockSmtpServer, PeerTubeServer, setAccessTokensToServers, waitJobs } from '@shared/extra-utils' +import { HttpStatusCode } from '@shared/models' const expect = chai.expect diff --git a/server/tests/api/server/follow-constraints.ts b/server/tests/api/server/follow-constraints.ts index bd7b215db..471f5d8d0 100644 --- a/server/tests/api/server/follow-constraints.ts +++ b/server/tests/api/server/follow-constraints.ts @@ -2,9 +2,8 @@ import 'mocha' import * as chai from 'chai' -import { HttpStatusCode } from '@shared/models' -import { cleanupTests, doubleFollow, createMultipleServers, PeerTubeServer, setAccessTokensToServers } from '@shared/extra-utils' -import { PeerTubeProblemDocument, ServerErrorCode } from '@shared/models' +import { cleanupTests, createMultipleServers, doubleFollow, PeerTubeServer, setAccessTokensToServers } from '@shared/extra-utils' +import { HttpStatusCode, PeerTubeProblemDocument, ServerErrorCode } from '@shared/models' const expect = chai.expect @@ -157,7 +156,7 @@ describe('Test follow constraints', function () { it('Should list local account videos', async function () { const { total, data } = await servers[0].videos.listByAccount({ - token: undefined, + token: null, handle: 'root@localhost:' + servers[0].port }) @@ -167,7 +166,7 @@ describe('Test follow constraints', function () { it('Should not list remote account videos', async function () { const { total, data } = await servers[0].videos.listByAccount({ - token: undefined, + token: null, handle: 'root@localhost:' + servers[1].port }) @@ -177,7 +176,7 @@ describe('Test follow constraints', function () { it('Should list local channel videos', async function () { const handle = 'root_channel@localhost:' + servers[0].port - const { total, data } = await servers[0].videos.listByChannel({ token: undefined, handle }) + const { total, data } = await servers[0].videos.listByChannel({ token: null, handle }) expect(total).to.equal(1) expect(data).to.have.lengthOf(1) @@ -185,7 +184,7 @@ describe('Test follow constraints', function () { it('Should not list remote channel videos', async function () { const handle = 'root_channel@localhost:' + servers[1].port - const { total, data } = await servers[0].videos.listByChannel({ token: undefined, handle }) + const { total, data } = await servers[0].videos.listByChannel({ token: null, handle }) expect(total).to.equal(0) expect(data).to.have.lengthOf(0) diff --git a/server/tests/api/server/follows.ts b/server/tests/api/server/follows.ts index 8856177b8..ff8f880a6 100644 --- a/server/tests/api/server/follows.ts +++ b/server/tests/api/server/follows.ts @@ -5,9 +5,9 @@ import * as chai from 'chai' import { cleanupTests, completeVideoCheck, + createMultipleServers, dateIsValid, expectAccountFollows, - createMultipleServers, FollowsCommand, PeerTubeServer, setAccessTokensToServers, diff --git a/server/tests/api/server/handle-down.ts b/server/tests/api/server/handle-down.ts index d22e843e0..1f751c957 100644 --- a/server/tests/api/server/handle-down.ts +++ b/server/tests/api/server/handle-down.ts @@ -2,7 +2,6 @@ import 'mocha' import * as chai from 'chai' -import { HttpStatusCode } from '@shared/models' import { cleanupTests, CommentsCommand, @@ -14,7 +13,7 @@ import { wait, waitJobs } from '@shared/extra-utils' -import { JobState, VideoCreateResult, VideoPrivacy } from '@shared/models' +import { HttpStatusCode, JobState, VideoCreateResult, VideoPrivacy } from '@shared/models' const expect = chai.expect diff --git a/server/tests/api/server/homepage.ts b/server/tests/api/server/homepage.ts index 7eae3df20..cb3ba5677 100644 --- a/server/tests/api/server/homepage.ts +++ b/server/tests/api/server/homepage.ts @@ -5,8 +5,8 @@ import * as chai from 'chai' import { HttpStatusCode } from '@shared/models' import { cleanupTests, - CustomPagesCommand, createSingleServer, + CustomPagesCommand, killallServers, PeerTubeServer, setAccessTokensToServers diff --git a/server/tests/api/server/jobs.ts b/server/tests/api/server/jobs.ts index 376cd10d0..c10c154c2 100644 --- a/server/tests/api/server/jobs.ts +++ b/server/tests/api/server/jobs.ts @@ -4,9 +4,9 @@ import 'mocha' import * as chai from 'chai' import { cleanupTests, + createMultipleServers, dateIsValid, doubleFollow, - createMultipleServers, PeerTubeServer, setAccessTokensToServers, waitJobs diff --git a/server/tests/api/server/plugins.ts b/server/tests/api/server/plugins.ts index 334adfe9d..5f9f4ffdd 100644 --- a/server/tests/api/server/plugins.ts +++ b/server/tests/api/server/plugins.ts @@ -2,18 +2,17 @@ import 'mocha' import * as chai from 'chai' -import { HttpStatusCode } from '@shared/models' import { cleanupTests, createSingleServer, killallServers, - PluginsCommand, PeerTubeServer, + PluginsCommand, setAccessTokensToServers, testHelloWorldRegisteredSettings, wait } from '@shared/extra-utils' -import { PluginType } from '@shared/models' +import { HttpStatusCode, PluginType } from '@shared/models' const expect = chai.expect diff --git a/server/tests/api/server/reverse-proxy.ts b/server/tests/api/server/reverse-proxy.ts index 13b22bc0e..484f88d67 100644 --- a/server/tests/api/server/reverse-proxy.ts +++ b/server/tests/api/server/reverse-proxy.ts @@ -1,8 +1,8 @@ /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */ import { expect } from 'chai' -import { HttpStatusCode } from '@shared/models' import { cleanupTests, createSingleServer, PeerTubeServer, setAccessTokensToServers, wait } from '@shared/extra-utils' +import { HttpStatusCode } from '@shared/models' describe('Test application behind a reverse proxy', function () { let server: PeerTubeServer diff --git a/server/tests/api/server/stats.ts b/server/tests/api/server/stats.ts index f07d0fd39..942602b70 100644 --- a/server/tests/api/server/stats.ts +++ b/server/tests/api/server/stats.ts @@ -4,8 +4,8 @@ import 'mocha' import * as chai from 'chai' import { cleanupTests, - doubleFollow, createMultipleServers, + doubleFollow, PeerTubeServer, setAccessTokensToServers, wait, diff --git a/server/tests/api/users/user-subscriptions.ts b/server/tests/api/users/user-subscriptions.ts index d2bb9c387..565b4bd77 100644 --- a/server/tests/api/users/user-subscriptions.ts +++ b/server/tests/api/users/user-subscriptions.ts @@ -4,8 +4,8 @@ import 'mocha' import * as chai from 'chai' import { cleanupTests, - doubleFollow, createMultipleServers, + doubleFollow, PeerTubeServer, setAccessTokensToServers, SubscriptionsCommand, @@ -67,7 +67,8 @@ describe('Test users subscriptions', function () { await waitJobs(servers) - const { uuid } = await servers[2].videos.upload({ attributes: { name: 'video server 3 added after follow' } }) + const attributes = { name: 'video server 3 added after follow' } + const { uuid } = await servers[2].videos.upload({ token: users[2].accessToken, attributes }) video3UUID = uuid await waitJobs(servers) diff --git a/server/tests/api/users/users-multiple-servers.ts b/server/tests/api/users/users-multiple-servers.ts index e304e5d67..225145957 100644 --- a/server/tests/api/users/users-multiple-servers.ts +++ b/server/tests/api/users/users-multiple-servers.ts @@ -7,8 +7,8 @@ import { checkTmpIsEmpty, checkVideoFilesWereRemoved, cleanupTests, - doubleFollow, createMultipleServers, + doubleFollow, PeerTubeServer, setAccessTokensToServers, testImage, diff --git a/server/tests/api/users/users-verification.ts b/server/tests/api/users/users-verification.ts index 56fc25048..f54463359 100644 --- a/server/tests/api/users/users-verification.ts +++ b/server/tests/api/users/users-verification.ts @@ -2,8 +2,8 @@ import 'mocha' import * as chai from 'chai' -import { HttpStatusCode } from '@shared/models' import { cleanupTests, createSingleServer, MockSmtpServer, PeerTubeServer, setAccessTokensToServers, waitJobs } from '@shared/extra-utils' +import { HttpStatusCode } from '@shared/models' const expect = chai.expect diff --git a/server/tests/api/users/users.ts b/server/tests/api/users/users.ts index be80c2616..066da88ee 100644 --- a/server/tests/api/users/users.ts +++ b/server/tests/api/users/users.ts @@ -2,7 +2,6 @@ import 'mocha' import * as chai from 'chai' -import { HttpStatusCode } from '@shared/models' import { cleanupTests, createSingleServer, @@ -13,7 +12,7 @@ import { testImage, waitJobs } from '@shared/extra-utils' -import { AbuseState, OAuth2ErrorCode, UserAdminFlag, UserRole, Video, VideoPlaylistType } from '@shared/models' +import { AbuseState, HttpStatusCode, OAuth2ErrorCode, UserAdminFlag, UserRole, Video, VideoPlaylistType } from '@shared/models' const expect = chai.expect diff --git a/server/tests/api/videos/audio-only.ts b/server/tests/api/videos/audio-only.ts index b9bf96650..15c3ae6d6 100644 --- a/server/tests/api/videos/audio-only.ts +++ b/server/tests/api/videos/audio-only.ts @@ -4,7 +4,7 @@ import 'mocha' import * as chai from 'chai' import { join } from 'path' import { getAudioStream, getVideoStreamSize } from '@server/helpers/ffprobe-utils' -import { cleanupTests, doubleFollow, createMultipleServers, PeerTubeServer, setAccessTokensToServers, waitJobs } from '@shared/extra-utils' +import { cleanupTests, createMultipleServers, doubleFollow, PeerTubeServer, setAccessTokensToServers, waitJobs } from '@shared/extra-utils' const expect = chai.expect diff --git a/server/tests/api/videos/multiple-servers.ts b/server/tests/api/videos/multiple-servers.ts index edf2773cd..d916abb09 100644 --- a/server/tests/api/videos/multiple-servers.ts +++ b/server/tests/api/videos/multiple-servers.ts @@ -3,16 +3,15 @@ import 'mocha' import * as chai from 'chai' import * as request from 'supertest' -import { HttpStatusCode } from '@shared/models' import { buildAbsoluteFixturePath, checkTmpIsEmpty, checkVideoFilesWereRemoved, cleanupTests, completeVideoCheck, + createMultipleServers, dateIsValid, doubleFollow, - createMultipleServers, PeerTubeServer, setAccessTokensToServers, testImage, @@ -20,7 +19,7 @@ import { waitJobs, webtorrentAdd } from '@shared/extra-utils' -import { VideoCommentThreadTree, VideoPrivacy } from '@shared/models' +import { HttpStatusCode, VideoCommentThreadTree, VideoPrivacy } from '@shared/models' const expect = chai.expect diff --git a/server/tests/api/videos/resumable-upload.ts b/server/tests/api/videos/resumable-upload.ts index 0e62972c2..13e47c85e 100644 --- a/server/tests/api/videos/resumable-upload.ts +++ b/server/tests/api/videos/resumable-upload.ts @@ -4,7 +4,6 @@ import 'mocha' import * as chai from 'chai' import { pathExists, readdir, stat } from 'fs-extra' import { join } from 'path' -import { HttpStatusCode } from '@shared/models' import { buildAbsoluteFixturePath, cleanupTests, @@ -13,7 +12,7 @@ import { setAccessTokensToServers, setDefaultVideoChannel } from '@shared/extra-utils' -import { VideoPrivacy } from '@shared/models' +import { HttpStatusCode, VideoPrivacy } from '@shared/models' const expect = chai.expect diff --git a/server/tests/api/videos/video-captions.ts b/server/tests/api/videos/video-captions.ts index 6caba6aa6..e3d46e619 100644 --- a/server/tests/api/videos/video-captions.ts +++ b/server/tests/api/videos/video-captions.ts @@ -5,8 +5,8 @@ import * as chai from 'chai' import { checkVideoFilesWereRemoved, cleanupTests, - doubleFollow, createMultipleServers, + doubleFollow, PeerTubeServer, setAccessTokensToServers, testCaptionFile, diff --git a/server/tests/api/videos/video-change-ownership.ts b/server/tests/api/videos/video-change-ownership.ts index 792550101..6ae6d3004 100644 --- a/server/tests/api/videos/video-change-ownership.ts +++ b/server/tests/api/videos/video-change-ownership.ts @@ -2,19 +2,18 @@ import 'mocha' import * as chai from 'chai' -import { HttpStatusCode } from '@shared/models' import { ChangeOwnershipCommand, cleanupTests, - doubleFollow, createMultipleServers, createSingleServer, + doubleFollow, PeerTubeServer, setAccessTokensToServers, setDefaultVideoChannel, waitJobs } from '@shared/extra-utils' -import { VideoPrivacy } from '@shared/models' +import { HttpStatusCode, VideoPrivacy } from '@shared/models' const expect = chai.expect diff --git a/server/tests/api/videos/video-channels.ts b/server/tests/api/videos/video-channels.ts index eeaec5ad2..c25754eb6 100644 --- a/server/tests/api/videos/video-channels.ts +++ b/server/tests/api/videos/video-channels.ts @@ -6,8 +6,8 @@ import { basename } from 'path' import { ACTOR_IMAGES_SIZE } from '@server/initializers/constants' import { cleanupTests, - doubleFollow, createMultipleServers, + doubleFollow, PeerTubeServer, setAccessTokensToServers, setDefaultVideoChannel, diff --git a/server/tests/api/videos/video-comments.ts b/server/tests/api/videos/video-comments.ts index 9709e0628..61ee54540 100644 --- a/server/tests/api/videos/video-comments.ts +++ b/server/tests/api/videos/video-comments.ts @@ -5,8 +5,8 @@ import * as chai from 'chai' import { cleanupTests, CommentsCommand, - dateIsValid, createSingleServer, + dateIsValid, PeerTubeServer, setAccessTokensToServers, testImage diff --git a/server/tests/api/videos/video-description.ts b/server/tests/api/videos/video-description.ts index ce45eac80..d22b4ed96 100644 --- a/server/tests/api/videos/video-description.ts +++ b/server/tests/api/videos/video-description.ts @@ -2,7 +2,7 @@ import 'mocha' import * as chai from 'chai' -import { cleanupTests, doubleFollow, createMultipleServers, PeerTubeServer, setAccessTokensToServers, waitJobs } from '@shared/extra-utils' +import { cleanupTests, createMultipleServers, doubleFollow, PeerTubeServer, setAccessTokensToServers, waitJobs } from '@shared/extra-utils' const expect = chai.expect diff --git a/server/tests/api/videos/video-hls.ts b/server/tests/api/videos/video-hls.ts index df030110b..7845f7334 100644 --- a/server/tests/api/videos/video-hls.ts +++ b/server/tests/api/videos/video-hls.ts @@ -3,22 +3,21 @@ import 'mocha' import * as chai from 'chai' import { join } from 'path' -import { HttpStatusCode } from '@shared/models' import { checkDirectoryIsEmpty, checkResolutionsInMasterPlaylist, checkSegmentHash, checkTmpIsEmpty, cleanupTests, - doubleFollow, createMultipleServers, + doubleFollow, makeRawRequest, PeerTubeServer, setAccessTokensToServers, waitJobs, webtorrentAdd } from '@shared/extra-utils' -import { VideoStreamingPlaylistType } from '@shared/models' +import { HttpStatusCode, VideoStreamingPlaylistType } from '@shared/models' import { DEFAULT_AUDIO_RESOLUTION } from '../../../initializers/constants' const expect = chai.expect diff --git a/server/tests/api/videos/video-nsfw.ts b/server/tests/api/videos/video-nsfw.ts index 0a9e5ce3f..b5d183d62 100644 --- a/server/tests/api/videos/video-nsfw.ts +++ b/server/tests/api/videos/video-nsfw.ts @@ -30,8 +30,8 @@ describe('Test video NSFW policy', function () { promises = [ server.search.advancedVideoSearch({ token, search: { search: 'n', sort: '-publishedAt', ...query } }), server.videos.listWithToken({ token, ...query }), - server.videos.listByAccount({ token, handle: channelName, ...query }), - server.videos.listByChannel({ token, handle: accountName, ...query }) + server.videos.listByAccount({ token, handle: accountName, ...query }), + server.videos.listByChannel({ token, handle: channelName, ...query }) ] // Overviews do not support video filters @@ -47,8 +47,8 @@ describe('Test video NSFW policy', function () { promises = [ server.search.searchVideos({ search: 'n', sort: '-publishedAt' }), server.videos.list(), - server.videos.listByAccount({ handle: channelName }), - server.videos.listByChannel({ handle: accountName }) + server.videos.listByAccount({ token: null, handle: accountName }), + server.videos.listByChannel({ token: null, handle: channelName }) ] // Overviews do not support video filters @@ -82,6 +82,7 @@ describe('Test video NSFW policy', function () { }) describe('Instance default NSFW policy', function () { + it('Should display NSFW videos with display default NSFW policy', async function () { const serverConfig = await server.config.getConfig() expect(serverConfig.instance.defaultNSFWPolicy).to.equal('display') diff --git a/server/tests/api/videos/video-playlist-thumbnails.ts b/server/tests/api/videos/video-playlist-thumbnails.ts index 9a682c12b..f0b2ca169 100644 --- a/server/tests/api/videos/video-playlist-thumbnails.ts +++ b/server/tests/api/videos/video-playlist-thumbnails.ts @@ -4,8 +4,8 @@ import 'mocha' import * as chai from 'chai' import { cleanupTests, - doubleFollow, createMultipleServers, + doubleFollow, PeerTubeServer, setAccessTokensToServers, setDefaultVideoChannel, diff --git a/server/tests/api/videos/video-playlists.ts b/server/tests/api/videos/video-playlists.ts index 9a28a421a..f42aee2ff 100644 --- a/server/tests/api/videos/video-playlists.ts +++ b/server/tests/api/videos/video-playlists.ts @@ -2,14 +2,13 @@ import 'mocha' import * as chai from 'chai' -import { HttpStatusCode } from '@shared/models' import { checkPlaylistFilesWereRemoved, cleanupTests, - doubleFollow, createMultipleServers, - PlaylistsCommand, + doubleFollow, PeerTubeServer, + PlaylistsCommand, setAccessTokensToServers, setDefaultVideoChannel, testImage, @@ -17,6 +16,7 @@ import { waitJobs } from '@shared/extra-utils' import { + HttpStatusCode, VideoPlaylist, VideoPlaylistCreateResult, VideoPlaylistElementType, diff --git a/server/tests/api/videos/video-privacy.ts b/server/tests/api/videos/video-privacy.ts index 06011082d..b51b3bcdd 100644 --- a/server/tests/api/videos/video-privacy.ts +++ b/server/tests/api/videos/video-privacy.ts @@ -2,9 +2,8 @@ import 'mocha' import * as chai from 'chai' -import { HttpStatusCode } from '@shared/models' -import { cleanupTests, doubleFollow, createSingleServer, PeerTubeServer, setAccessTokensToServers, waitJobs } from '@shared/extra-utils' -import { VideoCreateResult, VideoPrivacy } from '@shared/models' +import { cleanupTests, createSingleServer, doubleFollow, PeerTubeServer, setAccessTokensToServers, waitJobs } from '@shared/extra-utils' +import { HttpStatusCode, VideoCreateResult, VideoPrivacy } from '@shared/models' const expect = chai.expect @@ -162,7 +161,7 @@ describe('Test video privacy', function () { }) it('Should not be able to get this unlisted video using its id', async function () { - await servers[1].videos.get({ id: unlistedVideo.id, expectedStatus: HttpStatusCode.BAD_REQUEST_400 }) + await servers[1].videos.get({ id: unlistedVideo.id, expectedStatus: HttpStatusCode.NOT_FOUND_404 }) }) it('Should be able to get this unlisted video using its uuid/shortUUID', async function () { diff --git a/server/tests/api/videos/video-schedule-update.ts b/server/tests/api/videos/video-schedule-update.ts index 22b5cf1c2..3f7738784 100644 --- a/server/tests/api/videos/video-schedule-update.ts +++ b/server/tests/api/videos/video-schedule-update.ts @@ -4,8 +4,8 @@ import 'mocha' import * as chai from 'chai' import { cleanupTests, - doubleFollow, createMultipleServers, + doubleFollow, PeerTubeServer, setAccessTokensToServers, wait, diff --git a/server/tests/api/videos/video-transcoder.ts b/server/tests/api/videos/video-transcoder.ts index 7510472e3..e4892bb24 100644 --- a/server/tests/api/videos/video-transcoder.ts +++ b/server/tests/api/videos/video-transcoder.ts @@ -4,12 +4,11 @@ import 'mocha' import * as chai from 'chai' import { omit } from 'lodash' import { join } from 'path' -import { HttpStatusCode } from '@shared/models' import { buildAbsoluteFixturePath, cleanupTests, - doubleFollow, createMultipleServers, + doubleFollow, generateHighBitrateVideo, generateVideoWithFramerate, makeGetRequest, @@ -18,7 +17,7 @@ import { waitJobs, webtorrentAdd } from '@shared/extra-utils' -import { getMaxBitrate, VideoResolution, VideoState } from '@shared/models' +import { getMaxBitrate, HttpStatusCode, VideoResolution, VideoState } from '@shared/models' import { VIDEO_TRANSCODING_FPS } from '../../../../server/initializers/constants' import { canDoQuickTranscode, diff --git a/server/tests/api/videos/videos-filter.ts b/server/tests/api/videos/videos-filter.ts index 88dff3e7f..2306807bf 100644 --- a/server/tests/api/videos/videos-filter.ts +++ b/server/tests/api/videos/videos-filter.ts @@ -2,16 +2,15 @@ import 'mocha' import { expect } from 'chai' -import { HttpStatusCode } from '@shared/models' import { cleanupTests, - doubleFollow, createMultipleServers, + doubleFollow, makeGetRequest, PeerTubeServer, setAccessTokensToServers } from '@shared/extra-utils' -import { UserRole, Video, VideoPrivacy } from '@shared/models' +import { HttpStatusCode, UserRole, Video, VideoPrivacy } from '@shared/models' async function getVideosNames (server: PeerTubeServer, token: string, filter: string, expectedStatus = HttpStatusCode.OK_200) { const paths = [ diff --git a/server/tests/api/videos/videos-history.ts b/server/tests/api/videos/videos-history.ts index acb9d1a46..e4bc0bb3a 100644 --- a/server/tests/api/videos/videos-history.ts +++ b/server/tests/api/videos/videos-history.ts @@ -2,7 +2,6 @@ import 'mocha' import * as chai from 'chai' -import { HttpStatusCode } from '@shared/models' import { cleanupTests, createSingleServer, @@ -12,7 +11,7 @@ import { setAccessTokensToServers, wait } from '@shared/extra-utils' -import { Video } from '@shared/models' +import { HttpStatusCode, Video } from '@shared/models' const expect = chai.expect diff --git a/server/tests/api/videos/videos-views-cleaner.ts b/server/tests/api/videos/videos-views-cleaner.ts index 0be03ddd2..82268b1be 100644 --- a/server/tests/api/videos/videos-views-cleaner.ts +++ b/server/tests/api/videos/videos-views-cleaner.ts @@ -4,8 +4,8 @@ import 'mocha' import * as chai from 'chai' import { cleanupTests, - doubleFollow, createMultipleServers, + doubleFollow, killallServers, PeerTubeServer, setAccessTokensToServers, -- 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 +- server/tests/api/moderation/blocklist.ts | 4 +- .../api/notifications/moderation-notifications.ts | 4 +- .../tests/api/redundancy/redundancy-constraints.ts | 4 +- server/tests/api/server/auto-follows.ts | 2 +- server/tests/api/server/follows-moderation.ts | 10 +- server/tests/api/server/follows.ts | 595 ++++++++++++--------- server/tests/api/server/handle-down.ts | 6 +- server/tests/api/server/stats.ts | 2 +- server/tests/api/users/user-subscriptions.ts | 2 +- server/tests/api/users/users.ts | 2 +- 11 files changed, 369 insertions(+), 298 deletions(-) (limited to 'server/tests/api') 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 }) diff --git a/server/tests/api/moderation/blocklist.ts b/server/tests/api/moderation/blocklist.ts index 8ed5ad9e5..089af8b15 100644 --- a/server/tests/api/moderation/blocklist.ts +++ b/server/tests/api/moderation/blocklist.ts @@ -690,7 +690,7 @@ describe('Test blocklist', function () { const now = new Date() await servers[1].follows.unfollow({ target: servers[0] }) await waitJobs(servers) - await servers[1].follows.follow({ targets: [ servers[0].host ] }) + await servers[1].follows.follow({ hosts: [ servers[0].host ] }) await waitJobs(servers) @@ -751,7 +751,7 @@ describe('Test blocklist', function () { const now = new Date() await servers[1].follows.unfollow({ target: servers[0] }) await waitJobs(servers) - await servers[1].follows.follow({ targets: [ servers[0].host ] }) + await servers[1].follows.follow({ hosts: [ servers[0].host ] }) await waitJobs(servers) diff --git a/server/tests/api/notifications/moderation-notifications.ts b/server/tests/api/notifications/moderation-notifications.ts index 6e8f8a2b4..6f74709b3 100644 --- a/server/tests/api/notifications/moderation-notifications.ts +++ b/server/tests/api/notifications/moderation-notifications.ts @@ -368,7 +368,7 @@ describe('Test moderation notifications', function () { it('Should send a notification only to admin when there is a new instance follower', async function () { this.timeout(20000) - await servers[2].follows.follow({ targets: [ servers[0].url ] }) + await servers[2].follows.follow({ hosts: [ servers[0].url ] }) await waitJobs(servers) @@ -393,7 +393,7 @@ describe('Test moderation notifications', function () { } await servers[0].config.updateCustomSubConfig({ newConfig: config }) - await servers[2].follows.follow({ targets: [ servers[0].url ] }) + await servers[2].follows.follow({ hosts: [ servers[0].url ] }) await waitJobs(servers) diff --git a/server/tests/api/redundancy/redundancy-constraints.ts b/server/tests/api/redundancy/redundancy-constraints.ts index 25cd11658..933a2c776 100644 --- a/server/tests/api/redundancy/redundancy-constraints.ts +++ b/server/tests/api/redundancy/redundancy-constraints.ts @@ -75,7 +75,7 @@ describe('Test redundancy constraints', function () { await waitJobs(servers) // Server 1 and server 2 follow each other - await remoteServer.follows.follow({ targets: [ localServer.url ] }) + await remoteServer.follows.follow({ hosts: [ localServer.url ] }) await waitJobs(servers) await remoteServer.redundancy.updateRedundancy({ host: localServer.host, redundancyAllowed: true }) @@ -161,7 +161,7 @@ describe('Test redundancy constraints', function () { it('Should have redundancy on server 1 and on server 2 with followings filter now server 2 follows server 1', async function () { this.timeout(120000) - await localServer.follows.follow({ targets: [ remoteServer.url ] }) + await localServer.follows.follow({ hosts: [ remoteServer.url ] }) await waitJobs(servers) await uploadWrapper('video 4 server 2') diff --git a/server/tests/api/server/auto-follows.ts b/server/tests/api/server/auto-follows.ts index 8dca2e5e5..ce7b51925 100644 --- a/server/tests/api/server/auto-follows.ts +++ b/server/tests/api/server/auto-follows.ts @@ -33,7 +33,7 @@ async function checkFollow (follower: PeerTubeServer, following: PeerTubeServer, } async function server1Follows2 (servers: PeerTubeServer[]) { - await servers[0].follows.follow({ targets: [ servers[1].host ] }) + await servers[0].follows.follow({ hosts: [ servers[1].host ] }) await waitJobs(servers) } diff --git a/server/tests/api/server/follows-moderation.ts b/server/tests/api/server/follows-moderation.ts index 0aa328c5a..921f51043 100644 --- a/server/tests/api/server/follows-moderation.ts +++ b/server/tests/api/server/follows-moderation.ts @@ -60,7 +60,7 @@ describe('Test follows moderation', function () { it('Should have server 1 following server 2', async function () { this.timeout(30000) - await commands[0].follow({ targets: [ servers[1].url ] }) + await commands[0].follow({ hosts: [ servers[1].url ] }) await waitJobs(servers) }) @@ -95,7 +95,7 @@ describe('Test follows moderation', function () { await servers[1].config.updateCustomSubConfig({ newConfig: subConfig }) - await commands[0].follow({ targets: [ servers[1].url ] }) + await commands[0].follow({ hosts: [ servers[1].url ] }) await waitJobs(servers) await checkNoFollowers(servers) @@ -115,7 +115,7 @@ describe('Test follows moderation', function () { await servers[1].config.updateCustomSubConfig({ newConfig: subConfig }) - await commands[0].follow({ targets: [ servers[1].url ] }) + await commands[0].follow({ hosts: [ servers[1].url ] }) await waitJobs(servers) await checkServer1And2HasFollowers(servers) @@ -139,7 +139,7 @@ describe('Test follows moderation', function () { await servers[1].config.updateCustomSubConfig({ newConfig: subConfig }) await servers[2].config.updateCustomSubConfig({ newConfig: subConfig }) - await commands[0].follow({ targets: [ servers[1].url ] }) + await commands[0].follow({ hosts: [ servers[1].url ] }) await waitJobs(servers) await checkServer1And2HasFollowers(servers, 'pending') @@ -157,7 +157,7 @@ describe('Test follows moderation', function () { it('Should reject another follower', async function () { this.timeout(20000) - await commands[0].follow({ targets: [ servers[2].url ] }) + await commands[0].follow({ hosts: [ servers[2].url ] }) await waitJobs(servers) { diff --git a/server/tests/api/server/follows.ts b/server/tests/api/server/follows.ts index ff8f880a6..a616edcff 100644 --- a/server/tests/api/server/follows.ts +++ b/server/tests/api/server/follows.ts @@ -8,308 +8,369 @@ import { createMultipleServers, dateIsValid, expectAccountFollows, - FollowsCommand, + expectChannelsFollows, PeerTubeServer, setAccessTokensToServers, testCaptionFile, waitJobs } from '@shared/extra-utils' -import { Video, VideoPrivacy } from '@shared/models' +import { VideoCreateResult, VideoPrivacy } from '@shared/models' const expect = chai.expect describe('Test follows', function () { let servers: PeerTubeServer[] = [] - let followsCommands: FollowsCommand[] before(async function () { this.timeout(30000) servers = await createMultipleServers(3) - followsCommands = servers.map(s => s.follows) // Get the access tokens await setAccessTokensToServers(servers) }) - it('Should not have followers', async function () { - for (const server of servers) { - const body = await server.follows.getFollowers({ start: 0, count: 5, sort: 'createdAt' }) - expect(body.total).to.equal(0) - - const follows = body.data - expect(follows).to.be.an('array') - expect(follows.length).to.equal(0) - } - }) + describe('Data propagation after follow', function () { - it('Should not have following', async function () { - for (const server of servers) { - const body = await server.follows.getFollowings({ start: 0, count: 5, sort: 'createdAt' }) - expect(body.total).to.equal(0) + it('Should not have followers/followings', async function () { + for (const server of servers) { + const bodies = await Promise.all([ + server.follows.getFollowers({ start: 0, count: 5, sort: 'createdAt' }), + server.follows.getFollowings({ start: 0, count: 5, sort: 'createdAt' }) + ]) - const follows = body.data - expect(follows).to.be.an('array') - expect(follows.length).to.equal(0) - } - }) + for (const body of bodies) { + expect(body.total).to.equal(0) - it('Should have server 1 following server 2 and 3', async function () { - this.timeout(30000) + const follows = body.data + expect(follows).to.be.an('array') + expect(follows).to.have.lengthOf(0) + } + } + }) - await followsCommands[0].follow({ targets: [ servers[1].url, servers[2].url ] }) + it('Should have server 1 following root account of server 2 and server 3', async function () { + this.timeout(30000) - await waitJobs(servers) - }) + await servers[0].follows.follow({ + hosts: [ servers[2].url ], + handles: [ 'root@' + servers[1].host ] + }) - it('Should have 2 followings on server 1', async function () { - const body = await followsCommands[0].getFollowings({ start: 0, count: 1, sort: 'createdAt' }) - expect(body.total).to.equal(2) + await waitJobs(servers) + }) - let follows = body.data - expect(follows).to.be.an('array') - expect(follows.length).to.equal(1) + it('Should have 2 followings on server 1', async function () { + const body = await servers[0].follows.getFollowings({ start: 0, count: 1, sort: 'createdAt' }) + expect(body.total).to.equal(2) - const body2 = await followsCommands[0].getFollowings({ start: 1, count: 1, sort: 'createdAt' }) - follows = follows.concat(body2.data) + let follows = body.data + expect(follows).to.be.an('array') + expect(follows).to.have.lengthOf(1) - const server2Follow = follows.find(f => f.following.host === 'localhost:' + servers[1].port) - const server3Follow = follows.find(f => f.following.host === 'localhost:' + servers[2].port) + const body2 = await servers[0].follows.getFollowings({ start: 1, count: 1, sort: 'createdAt' }) + follows = follows.concat(body2.data) - expect(server2Follow).to.not.be.undefined - expect(server3Follow).to.not.be.undefined - expect(server2Follow.state).to.equal('accepted') - expect(server3Follow.state).to.equal('accepted') - }) + const server2Follow = follows.find(f => f.following.host === servers[1].host) + const server3Follow = follows.find(f => f.following.host === servers[2].host) - it('Should search/filter followings on server 1', async function () { - const sort = 'createdAt' - const start = 0 - const count = 1 + expect(server2Follow).to.not.be.undefined + expect(server2Follow.following.name).to.equal('root') + expect(server2Follow.state).to.equal('accepted') - { - const search = ':' + servers[1].port + expect(server3Follow).to.not.be.undefined + expect(server3Follow.following.name).to.equal('peertube') + expect(server3Follow.state).to.equal('accepted') + }) - { - const body = await followsCommands[0].getFollowings({ start, count, sort, search }) - expect(body.total).to.equal(1) + it('Should have 0 followings on server 2 and 3', async function () { + for (const server of [ servers[1], servers[2] ]) { + const body = await server.follows.getFollowings({ start: 0, count: 5, sort: 'createdAt' }) + expect(body.total).to.equal(0) const follows = body.data - expect(follows.length).to.equal(1) - expect(follows[0].following.host).to.equal('localhost:' + servers[1].port) + expect(follows).to.be.an('array') + expect(follows).to.have.lengthOf(0) } + }) - { - const body = await followsCommands[0].getFollowings({ start, count, sort, search, state: 'accepted' }) - expect(body.total).to.equal(1) - expect(body.data).to.have.lengthOf(1) + it('Should have 1 followers on server 3', async function () { + const body = await servers[2].follows.getFollowers({ start: 0, count: 1, sort: 'createdAt' }) + expect(body.total).to.equal(1) + + const follows = body.data + expect(follows).to.be.an('array') + expect(follows).to.have.lengthOf(1) + expect(follows[0].follower.host).to.equal('localhost:' + servers[0].port) + }) + + it('Should have 0 followers on server 1 and 2', async function () { + for (const server of [ servers[0], servers[1] ]) { + const body = await server.follows.getFollowers({ start: 0, count: 5, sort: 'createdAt' }) + expect(body.total).to.equal(0) + + const follows = body.data + expect(follows).to.be.an('array') + expect(follows).to.have.lengthOf(0) } + }) + + it('Should search/filter followings on server 1', async function () { + const sort = 'createdAt' + const start = 0 + const count = 1 { - const body = await followsCommands[0].getFollowings({ start, count, sort, search, state: 'accepted', actorType: 'Person' }) - expect(body.total).to.equal(0) - expect(body.data).to.have.lengthOf(0) + const search = ':' + servers[1].port + + { + const body = await servers[0].follows.getFollowings({ start, count, sort, search }) + expect(body.total).to.equal(1) + + const follows = body.data + expect(follows).to.have.lengthOf(1) + expect(follows[0].following.host).to.equal(servers[1].host) + } + + { + const body = await servers[0].follows.getFollowings({ start, count, sort, search, state: 'accepted' }) + expect(body.total).to.equal(1) + expect(body.data).to.have.lengthOf(1) + } + + { + const body = await servers[0].follows.getFollowings({ start, count, sort, search, state: 'accepted', actorType: 'Person' }) + expect(body.total).to.equal(1) + expect(body.data).to.have.lengthOf(1) + } + + { + const body = await servers[0].follows.getFollowings({ + start, + count, + sort, + search, + state: 'accepted', + actorType: 'Application' + }) + expect(body.total).to.equal(0) + expect(body.data).to.have.lengthOf(0) + } + + { + const body = await servers[0].follows.getFollowings({ start, count, sort, search, state: 'pending' }) + expect(body.total).to.equal(0) + expect(body.data).to.have.lengthOf(0) + } } { - const body = await followsCommands[0].getFollowings({ - start, - count, - sort, - search, - state: 'accepted', - actorType: 'Application' - }) + const body = await servers[0].follows.getFollowings({ start, count, sort, search: 'root' }) expect(body.total).to.equal(1) expect(body.data).to.have.lengthOf(1) } { - const body = await followsCommands[0].getFollowings({ start, count, sort, search, state: 'pending' }) + const body = await servers[0].follows.getFollowings({ start, count, sort, search: 'bla' }) expect(body.total).to.equal(0) + expect(body.data).to.have.lengthOf(0) } - } + }) - { - const body = await followsCommands[0].getFollowings({ start, count, sort, search: 'bla' }) - expect(body.total).to.equal(0) + it('Should search/filter followers on server 2', async function () { + const start = 0 + const count = 5 + const sort = 'createdAt' - expect(body.data.length).to.equal(0) - } - }) + { + const search = servers[0].port + '' - it('Should have 0 followings on server 2 and 3', async function () { - for (const server of [ servers[1], servers[2] ]) { - const body = await server.follows.getFollowings({ start: 0, count: 5, sort: 'createdAt' }) - expect(body.total).to.equal(0) + { + const body = await servers[2].follows.getFollowers({ start, count, sort, search }) + expect(body.total).to.equal(1) - const follows = body.data - expect(follows).to.be.an('array') - expect(follows.length).to.equal(0) - } - }) + const follows = body.data + expect(follows).to.have.lengthOf(1) + expect(follows[0].following.host).to.equal(servers[2].host) + } - it('Should have 1 followers on server 2 and 3', async function () { - for (const server of [ servers[1], servers[2] ]) { - const body = await server.follows.getFollowers({ start: 0, count: 1, sort: 'createdAt' }) - expect(body.total).to.equal(1) + { + const body = await servers[2].follows.getFollowers({ start, count, sort, search, state: 'accepted' }) + expect(body.total).to.equal(1) + expect(body.data).to.have.lengthOf(1) + } - const follows = body.data - expect(follows).to.be.an('array') - expect(follows.length).to.equal(1) - expect(follows[0].follower.host).to.equal('localhost:' + servers[0].port) - } - }) + { + const body = await servers[2].follows.getFollowers({ start, count, sort, search, state: 'accepted', actorType: 'Person' }) + expect(body.total).to.equal(0) + expect(body.data).to.have.lengthOf(0) + } - it('Should search/filter followers on server 2', async function () { - const start = 0 - const count = 5 - const sort = 'createdAt' + { + const body = await servers[2].follows.getFollowers({ + start, + count, + sort, + search, + state: 'accepted', + actorType: 'Application' + }) + expect(body.total).to.equal(1) + expect(body.data).to.have.lengthOf(1) + } - { - const search = servers[0].port + '' + { + const body = await servers[2].follows.getFollowers({ start, count, sort, search, state: 'pending' }) + expect(body.total).to.equal(0) + expect(body.data).to.have.lengthOf(0) + } + } { - const body = await followsCommands[2].getFollowers({ start, count, sort, search }) - expect(body.total).to.equal(1) + const body = await servers[2].follows.getFollowers({ start, count, sort, search: 'bla' }) + expect(body.total).to.equal(0) const follows = body.data - expect(follows.length).to.equal(1) - expect(follows[0].following.host).to.equal('localhost:' + servers[2].port) + expect(follows).to.have.lengthOf(0) } + }) - { - const body = await followsCommands[2].getFollowers({ start, count, sort, search, state: 'accepted' }) - expect(body.total).to.equal(1) - expect(body.data).to.have.lengthOf(1) - } + it('Should have the correct follows counts', async function () { + await expectAccountFollows({ server: servers[0], handle: 'peertube@' + servers[0].host, followers: 0, following: 2 }) + await expectAccountFollows({ server: servers[0], handle: 'root@' + servers[1].host, followers: 1, following: 0 }) + await expectAccountFollows({ server: servers[0], handle: 'peertube@' + servers[2].host, followers: 1, following: 0 }) - { - const body = await followsCommands[2].getFollowers({ start, count, sort, search, state: 'accepted', actorType: 'Person' }) - expect(body.total).to.equal(0) - expect(body.data).to.have.lengthOf(0) - } + // Server 2 and 3 does not know server 1 follow another server (there was not a refresh) + await expectAccountFollows({ server: servers[1], handle: 'peertube@' + servers[0].host, followers: 0, following: 1 }) + await expectAccountFollows({ server: servers[1], handle: 'root@' + servers[1].host, followers: 1, following: 0 }) + await expectAccountFollows({ server: servers[1], handle: 'peertube@' + servers[1].host, followers: 0, following: 0 }) - { - const body = await followsCommands[2].getFollowers({ - start, - count, - sort, - search, - state: 'accepted', - actorType: 'Application' - }) - expect(body.total).to.equal(1) - expect(body.data).to.have.lengthOf(1) - } + await expectAccountFollows({ server: servers[2], handle: 'peertube@' + servers[0].host, followers: 0, following: 1 }) + await expectAccountFollows({ server: servers[2], handle: 'peertube@' + servers[2].host, followers: 1, following: 0 }) + }) - { - const body = await followsCommands[2].getFollowers({ start, count, sort, search, state: 'pending' }) - expect(body.total).to.equal(0) - expect(body.data).to.have.lengthOf(0) - } - } + it('Should unfollow server 3 on server 1', async function () { + this.timeout(15000) - { - const body = await followsCommands[2].getFollowers({ start, count, sort, search: 'bla' }) - expect(body.total).to.equal(0) + await servers[0].follows.unfollow({ target: servers[2] }) + + await waitJobs(servers) + }) + + it('Should not follow server 3 on server 1 anymore', async function () { + const body = await servers[0].follows.getFollowings({ start: 0, count: 2, sort: 'createdAt' }) + expect(body.total).to.equal(1) const follows = body.data - expect(follows.length).to.equal(0) - } - }) + expect(follows).to.be.an('array') + expect(follows).to.have.lengthOf(1) - it('Should have 0 followers on server 1', async function () { - const body = await followsCommands[0].getFollowers({ start: 0, count: 5, sort: 'createdAt' }) - expect(body.total).to.equal(0) + expect(follows[0].following.host).to.equal(servers[1].host) + }) - const follows = body.data - expect(follows).to.be.an('array') - expect(follows.length).to.equal(0) - }) + it('Should not have server 1 as follower on server 3 anymore', async function () { + const body = await servers[2].follows.getFollowers({ start: 0, count: 1, sort: 'createdAt' }) + expect(body.total).to.equal(0) - it('Should have the correct follows counts', async function () { - await expectAccountFollows({ server: servers[0], handle: 'peertube@localhost:' + servers[0].port, followers: 0, following: 2 }) - await expectAccountFollows({ server: servers[0], handle: 'peertube@localhost:' + servers[1].port, followers: 1, following: 0 }) - await expectAccountFollows({ server: servers[0], handle: 'peertube@localhost:' + servers[2].port, followers: 1, following: 0 }) + const follows = body.data + expect(follows).to.be.an('array') + expect(follows).to.have.lengthOf(0) + }) - // Server 2 and 3 does not know server 1 follow another server (there was not a refresh) - await expectAccountFollows({ server: servers[1], handle: 'peertube@localhost:' + servers[0].port, followers: 0, following: 1 }) - await expectAccountFollows({ server: servers[1], handle: 'peertube@localhost:' + servers[1].port, followers: 1, following: 0 }) + it('Should have the correct follows counts after the unfollow', async function () { + await expectAccountFollows({ server: servers[0], handle: 'peertube@' + servers[0].host, followers: 0, following: 1 }) + await expectAccountFollows({ server: servers[0], handle: 'root@' + servers[1].host, followers: 1, following: 0 }) + await expectAccountFollows({ server: servers[0], handle: 'peertube@' + servers[2].host, followers: 0, following: 0 }) - await expectAccountFollows({ server: servers[2], handle: 'peertube@localhost:' + servers[0].port, followers: 0, following: 1 }) - await expectAccountFollows({ server: servers[2], handle: 'peertube@localhost:' + servers[2].port, followers: 1, following: 0 }) - }) + await expectAccountFollows({ server: servers[1], handle: 'peertube@' + servers[0].host, followers: 0, following: 1 }) + await expectAccountFollows({ server: servers[1], handle: 'root@' + servers[1].host, followers: 1, following: 0 }) + await expectAccountFollows({ server: servers[1], handle: 'peertube@' + servers[1].host, followers: 0, following: 0 }) - it('Should unfollow server 3 on server 1', async function () { - this.timeout(5000) + await expectAccountFollows({ server: servers[2], handle: 'peertube@' + servers[0].host, followers: 0, following: 0 }) + await expectAccountFollows({ server: servers[2], handle: 'peertube@' + servers[2].host, followers: 0, following: 0 }) + }) - await followsCommands[0].unfollow({ target: servers[2] }) + it('Should upload a video on server 2 and 3 and propagate only the video of server 2', async function () { + this.timeout(60000) - await waitJobs(servers) - }) + await servers[1].videos.upload({ attributes: { name: 'server2' } }) + await servers[2].videos.upload({ attributes: { name: 'server3' } }) - it('Should not follow server 3 on server 1 anymore', async function () { - const body = await followsCommands[0].getFollowings({ start: 0, count: 2, sort: 'createdAt' }) - expect(body.total).to.equal(1) + await waitJobs(servers) - const follows = body.data - expect(follows).to.be.an('array') - expect(follows.length).to.equal(1) + { + const { total, data } = await servers[0].videos.list() + expect(total).to.equal(1) + expect(data[0].name).to.equal('server2') + } - expect(follows[0].following.host).to.equal('localhost:' + servers[1].port) - }) + { + const { total, data } = await servers[1].videos.list() + expect(total).to.equal(1) + expect(data[0].name).to.equal('server2') + } - it('Should not have server 1 as follower on server 3 anymore', async function () { - const body = await followsCommands[2].getFollowers({ start: 0, count: 1, sort: 'createdAt' }) - expect(body.total).to.equal(0) + { + const { total, data } = await servers[2].videos.list() + expect(total).to.equal(1) + expect(data[0].name).to.equal('server3') + } + }) - const follows = body.data - expect(follows).to.be.an('array') - expect(follows.length).to.equal(0) - }) + it('Should remove account follow', async function () { + this.timeout(15000) - it('Should have the correct follows counts 2', async function () { - await expectAccountFollows({ server: servers[0], handle: 'peertube@localhost:' + servers[0].port, followers: 0, following: 1 }) - await expectAccountFollows({ server: servers[0], handle: 'peertube@localhost:' + servers[1].port, followers: 1, following: 0 }) + await servers[0].follows.unfollow({ target: 'root@' + servers[1].host }) - await expectAccountFollows({ server: servers[1], handle: 'peertube@localhost:' + servers[0].port, followers: 0, following: 1 }) - await expectAccountFollows({ server: servers[1], handle: 'peertube@localhost:' + servers[1].port, followers: 1, following: 0 }) + await waitJobs(servers) + }) - await expectAccountFollows({ server: servers[2], handle: 'peertube@localhost:' + servers[0].port, followers: 0, following: 0 }) - await expectAccountFollows({ server: servers[2], handle: 'peertube@localhost:' + servers[2].port, followers: 0, following: 0 }) - }) + it('Should have removed the account follow', async function () { + await expectAccountFollows({ server: servers[0], handle: 'root@' + servers[1].host, followers: 0, following: 0 }) + await expectAccountFollows({ server: servers[1], handle: 'root@' + servers[1].host, followers: 0, following: 0 }) - it('Should upload a video on server 2 and 3 and propagate only the video of server 2', async function () { - this.timeout(60000) + { + const { total, data } = await servers[0].follows.getFollowings() + expect(total).to.equal(0) + expect(data).to.have.lengthOf(0) + } - await servers[1].videos.upload({ attributes: { name: 'server2' } }) - await servers[2].videos.upload({ attributes: { name: 'server3' } }) + { + const { total, data } = await servers[0].videos.list() + expect(total).to.equal(0) + expect(data).to.have.lengthOf(0) + } + }) - await waitJobs(servers) + it('Should follow a channel', async function () { + this.timeout(15000) - { - const { total, data } = await servers[0].videos.list() - expect(total).to.equal(1) - expect(data[0].name).to.equal('server2') - } + await servers[0].follows.follow({ + handles: [ 'root_channel@' + servers[1].host ] + }) - { - const { total, data } = await servers[1].videos.list() - expect(total).to.equal(1) - expect(data[0].name).to.equal('server2') - } + await waitJobs(servers) - { - const { total, data } = await servers[2].videos.list() - expect(total).to.equal(1) - expect(data[0].name).to.equal('server3') - } + await expectChannelsFollows({ server: servers[0], handle: 'root_channel@' + servers[1].host, followers: 1, following: 0 }) + await expectChannelsFollows({ server: servers[1], handle: 'root_channel@' + servers[1].host, followers: 1, following: 0 }) + + { + const { total, data } = await servers[0].follows.getFollowings() + expect(total).to.equal(1) + expect(data).to.have.lengthOf(1) + } + + { + const { total, data } = await servers[0].videos.list() + expect(total).to.equal(1) + expect(data).to.have.lengthOf(1) + } + }) }) - describe('Should propagate data on a new following', function () { - let video4: Video + describe('Should propagate data on a new server follow', function () { + let video4: VideoCreateResult before(async function () { this.timeout(50000) @@ -324,83 +385,64 @@ describe('Test follows', function () { await servers[2].videos.upload({ attributes: { name: 'server3-2' } }) await servers[2].videos.upload({ attributes: { name: 'server3-3' } }) - await servers[2].videos.upload({ attributes: video4Attributes }) + video4 = await servers[2].videos.upload({ attributes: video4Attributes }) await servers[2].videos.upload({ attributes: { name: 'server3-5' } }) await servers[2].videos.upload({ attributes: { name: 'server3-6' } }) { const userAccessToken = await servers[2].users.generateUserAndToken('captain') - const { data } = await servers[2].videos.list() - video4 = data.find(v => v.name === 'server3-4') - - { - await servers[2].videos.rate({ id: video4.id, rating: 'like' }) - await servers[2].videos.rate({ token: userAccessToken, id: video4.id, rating: 'dislike' }) - } - - { - { - const text = 'my super first comment' - const created = await servers[2].comments.createThread({ videoId: video4.id, text }) - const threadId = created.id - - const text1 = 'my super answer to thread 1' - const childComment = await servers[2].comments.addReply({ videoId: video4.id, toCommentId: threadId, text: text1 }) - - const text2 = 'my super answer to answer of thread 1' - await servers[2].comments.addReply({ videoId: video4.id, toCommentId: childComment.id, text: text2 }) - - const text3 = 'my second answer to thread 1' - await servers[2].comments.addReply({ videoId: video4.id, toCommentId: threadId, text: text3 }) - } + await servers[2].videos.rate({ id: video4.id, rating: 'like' }) + await servers[2].videos.rate({ token: userAccessToken, id: video4.id, rating: 'dislike' }) + } - { - const text = 'will be deleted' - const created = await servers[2].comments.createThread({ videoId: video4.id, text }) - const threadId = created.id + { + await servers[2].comments.createThread({ videoId: video4.id, text: 'my super first comment' }) - const text1 = 'answer to deleted' - await servers[2].comments.addReply({ videoId: video4.id, toCommentId: threadId, text: text1 }) + await servers[2].comments.addReplyToLastThread({ text: 'my super answer to thread 1' }) + await servers[2].comments.addReplyToLastReply({ text: 'my super answer to answer of thread 1' }) + await servers[2].comments.addReplyToLastThread({ text: 'my second answer to thread 1' }) + } - const text2 = 'will also be deleted' - const childComment = await servers[2].comments.addReply({ videoId: video4.id, toCommentId: threadId, text: text2 }) + { + const { id: threadId } = await servers[2].comments.createThread({ videoId: video4.id, text: 'will be deleted' }) + await servers[2].comments.addReplyToLastThread({ text: 'answer to deleted' }) - const text3 = 'my second answer to deleted' - await servers[2].comments.addReply({ videoId: video4.id, toCommentId: childComment.id, text: text3 }) + const { id: replyId } = await servers[2].comments.addReplyToLastThread({ text: 'will also be deleted' }) - await servers[2].comments.delete({ videoId: video4.id, commentId: threadId }) - await servers[2].comments.delete({ videoId: video4.id, commentId: childComment.id }) - } - } + await servers[2].comments.addReplyToLastReply({ text: 'my second answer to deleted' }) - { - await servers[2].captions.createVideoCaption({ - language: 'ar', - videoId: video4.id, - fixture: 'subtitle-good2.vtt' - }) - } + await servers[2].comments.delete({ videoId: video4.id, commentId: threadId }) + await servers[2].comments.delete({ videoId: video4.id, commentId: replyId }) } + await servers[2].captions.createVideoCaption({ + language: 'ar', + videoId: video4.id, + fixture: 'subtitle-good2.vtt' + }) + await waitJobs(servers) // Server 1 follows server 3 - await followsCommands[0].follow({ targets: [ servers[2].url ] }) + await servers[0].follows.follow({ hosts: [ servers[2].url ] }) await waitJobs(servers) }) - it('Should have the correct follows counts 3', async function () { - await expectAccountFollows({ server: servers[0], handle: 'peertube@localhost:' + servers[0].port, followers: 0, following: 2 }) - await expectAccountFollows({ server: servers[0], handle: 'peertube@localhost:' + servers[1].port, followers: 1, following: 0 }) - await expectAccountFollows({ server: servers[0], handle: 'peertube@localhost:' + servers[2].port, followers: 1, following: 0 }) + it('Should have the correct follows counts', async function () { + await expectAccountFollows({ server: servers[0], handle: 'peertube@' + servers[0].host, followers: 0, following: 2 }) + await expectAccountFollows({ server: servers[0], handle: 'root@' + servers[1].host, followers: 0, following: 0 }) + await expectChannelsFollows({ server: servers[0], handle: 'root_channel@' + servers[1].host, followers: 1, following: 0 }) + await expectAccountFollows({ server: servers[0], handle: 'peertube@' + servers[2].host, followers: 1, following: 0 }) - await expectAccountFollows({ server: servers[1], handle: 'peertube@localhost:' + servers[0].port, followers: 0, following: 1 }) - await expectAccountFollows({ server: servers[1], handle: 'peertube@localhost:' + servers[1].port, followers: 1, following: 0 }) + await expectAccountFollows({ server: servers[1], handle: 'peertube@' + servers[0].host, followers: 0, following: 1 }) + await expectAccountFollows({ server: servers[1], handle: 'peertube@' + servers[1].host, followers: 0, following: 0 }) + await expectAccountFollows({ server: servers[1], handle: 'root@' + servers[1].host, followers: 0, following: 0 }) + await expectChannelsFollows({ server: servers[1], handle: 'root_channel@' + servers[1].host, followers: 1, following: 0 }) - await expectAccountFollows({ server: servers[2], handle: 'peertube@localhost:' + servers[0].port, followers: 0, following: 1 }) - await expectAccountFollows({ server: servers[2], handle: 'peertube@localhost:' + servers[2].port, followers: 1, following: 0 }) + await expectAccountFollows({ server: servers[2], handle: 'peertube@' + servers[0].host, followers: 0, following: 1 }) + await expectAccountFollows({ server: servers[2], handle: 'peertube@' + servers[2].host, followers: 1, following: 0 }) }) it('Should have propagated videos', async function () { @@ -426,7 +468,7 @@ describe('Test follows', function () { support: 'my super support text', account: { name: 'root', - host: 'localhost:' + servers[2].port + host: servers[2].host }, isLocal, commentsEnabled: true, @@ -467,7 +509,7 @@ describe('Test follows', function () { expect(comment.videoId).to.equal(video4.id) expect(comment.id).to.equal(comment.threadId) expect(comment.account.name).to.equal('root') - expect(comment.account.host).to.equal('localhost:' + servers[2].port) + expect(comment.account.host).to.equal(servers[2].host) expect(comment.totalReplies).to.equal(3) expect(dateIsValid(comment.createdAt as string)).to.be.true expect(dateIsValid(comment.updatedAt as string)).to.be.true @@ -541,14 +583,39 @@ describe('Test follows', function () { it('Should unfollow server 3 on server 1 and does not list server 3 videos', async function () { this.timeout(5000) - await followsCommands[0].unfollow({ target: servers[2] }) + await servers[0].follows.unfollow({ target: servers[2] }) await waitJobs(servers) const { total } = await servers[0].videos.list() expect(total).to.equal(1) }) + }) + + describe('Should propagate data on a new channel follow', function () { + + before(async function () { + this.timeout(60000) + await servers[2].videos.upload({ attributes: { name: 'server3-7' } }) + + await waitJobs(servers) + + const video = await servers[0].videos.find({ name: 'server3-7' }) + expect(video).to.not.exist + }) + + it('Should have propagated channel video', async function () { + this.timeout(60000) + + await servers[0].follows.follow({ handles: [ 'root_channel@' + servers[2].host ] }) + + await waitJobs(servers) + + const video = await servers[0].videos.find({ name: 'server3-7' }) + + expect(video).to.exist + }) }) after(async function () { diff --git a/server/tests/api/server/handle-down.ts b/server/tests/api/server/handle-down.ts index 1f751c957..2f3950354 100644 --- a/server/tests/api/server/handle-down.ts +++ b/server/tests/api/server/handle-down.ts @@ -97,8 +97,8 @@ describe('Test handle downs', function () { this.timeout(240000) // Server 2 and 3 follow server 1 - await servers[1].follows.follow({ targets: [ servers[0].url ] }) - await servers[2].follows.follow({ targets: [ servers[0].url ] }) + await servers[1].follows.follow({ hosts: [ servers[0].url ] }) + await servers[2].follows.follow({ hosts: [ servers[0].url ] }) await waitJobs(servers) @@ -180,7 +180,7 @@ describe('Test handle downs', function () { await servers[1].follows.unfollow({ target: servers[0] }) await waitJobs(servers) - await servers[1].follows.follow({ targets: [ servers[0].url ] }) + await servers[1].follows.follow({ hosts: [ servers[0].url ] }) await waitJobs(servers) diff --git a/server/tests/api/server/stats.ts b/server/tests/api/server/stats.ts index 942602b70..5ec771429 100644 --- a/server/tests/api/server/stats.ts +++ b/server/tests/api/server/stats.ts @@ -43,7 +43,7 @@ describe('Test stats (excluding redundancy)', function () { // Wait the video views repeatable job await wait(8000) - await servers[2].follows.follow({ targets: [ servers[0].url ] }) + await servers[2].follows.follow({ hosts: [ servers[0].url ] }) await waitJobs(servers) }) diff --git a/server/tests/api/users/user-subscriptions.ts b/server/tests/api/users/user-subscriptions.ts index 565b4bd77..77b99886d 100644 --- a/server/tests/api/users/user-subscriptions.ts +++ b/server/tests/api/users/user-subscriptions.ts @@ -224,7 +224,7 @@ describe('Test users subscriptions', function () { it('Should have server 1 follow server 3 and display server 3 videos', async function () { this.timeout(60000) - await servers[0].follows.follow({ targets: [ servers[2].url ] }) + await servers[0].follows.follow({ hosts: [ servers[2].url ] }) await waitJobs(servers) diff --git a/server/tests/api/users/users.ts b/server/tests/api/users/users.ts index 066da88ee..1419ae820 100644 --- a/server/tests/api/users/users.ts +++ b/server/tests/api/users/users.ts @@ -103,7 +103,7 @@ describe('Test users', function () { token = 'my_super_token' await server.follows.follow({ - targets: [ 'http://example.com' ], + hosts: [ 'http://example.com' ], token, expectedStatus: HttpStatusCode.UNAUTHORIZED_401 }) -- 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 +- server/tests/api/search/search-videos.ts | 4 ++-- server/tests/api/server/follows.ts | 4 ++-- server/tests/api/videos/video-captions.ts | 20 ++++++++++---------- server/tests/api/videos/video-imports.ts | 6 +++--- 5 files changed, 18 insertions(+), 18 deletions(-) (limited to 'server/tests/api') 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', diff --git a/server/tests/api/search/search-videos.ts b/server/tests/api/search/search-videos.ts index f834c7f36..965766742 100644 --- a/server/tests/api/search/search-videos.ts +++ b/server/tests/api/search/search-videos.ts @@ -50,14 +50,14 @@ describe('Test videos search', function () { const { id, uuid } = await server.videos.upload({ attributes: attributes3 }) videoUUID = uuid - await server.captions.createVideoCaption({ + await server.captions.add({ language: 'en', videoId: id, fixture: 'subtitle-good2.vtt', mimeType: 'application/octet-stream' }) - await server.captions.createVideoCaption({ + await server.captions.add({ language: 'aa', videoId: id, fixture: 'subtitle-good2.vtt', diff --git a/server/tests/api/server/follows.ts b/server/tests/api/server/follows.ts index a616edcff..832ba561a 100644 --- a/server/tests/api/server/follows.ts +++ b/server/tests/api/server/follows.ts @@ -416,7 +416,7 @@ describe('Test follows', function () { await servers[2].comments.delete({ videoId: video4.id, commentId: replyId }) } - await servers[2].captions.createVideoCaption({ + await servers[2].captions.add({ language: 'ar', videoId: video4.id, fixture: 'subtitle-good2.vtt' @@ -569,7 +569,7 @@ describe('Test follows', function () { }) it('Should have propagated captions', async function () { - const body = await servers[0].captions.listVideoCaptions({ videoId: video4.id }) + const body = await servers[0].captions.list({ videoId: video4.id }) expect(body.total).to.equal(1) expect(body.data).to.have.lengthOf(1) diff --git a/server/tests/api/videos/video-captions.ts b/server/tests/api/videos/video-captions.ts index e3d46e619..4c8e28adf 100644 --- a/server/tests/api/videos/video-captions.ts +++ b/server/tests/api/videos/video-captions.ts @@ -40,7 +40,7 @@ describe('Test video captions', function () { it('Should list the captions and return an empty list', async function () { for (const server of servers) { - const body = await server.captions.listVideoCaptions({ videoId: videoUUID }) + const body = await server.captions.list({ videoId: videoUUID }) expect(body.total).to.equal(0) expect(body.data).to.have.lengthOf(0) } @@ -49,13 +49,13 @@ describe('Test video captions', function () { it('Should create two new captions', async function () { this.timeout(30000) - await servers[0].captions.createVideoCaption({ + await servers[0].captions.add({ language: 'ar', videoId: videoUUID, fixture: 'subtitle-good1.vtt' }) - await servers[0].captions.createVideoCaption({ + await servers[0].captions.add({ language: 'zh', videoId: videoUUID, fixture: 'subtitle-good2.vtt', @@ -67,7 +67,7 @@ describe('Test video captions', function () { it('Should list these uploaded captions', async function () { for (const server of servers) { - const body = await server.captions.listVideoCaptions({ videoId: videoUUID }) + const body = await server.captions.list({ videoId: videoUUID }) expect(body.total).to.equal(2) expect(body.data).to.have.lengthOf(2) @@ -88,7 +88,7 @@ describe('Test video captions', function () { it('Should replace an existing caption', async function () { this.timeout(30000) - await servers[0].captions.createVideoCaption({ + await servers[0].captions.add({ language: 'ar', videoId: videoUUID, fixture: 'subtitle-good2.vtt' @@ -99,7 +99,7 @@ describe('Test video captions', function () { it('Should have this caption updated', async function () { for (const server of servers) { - const body = await server.captions.listVideoCaptions({ videoId: videoUUID }) + const body = await server.captions.list({ videoId: videoUUID }) expect(body.total).to.equal(2) expect(body.data).to.have.lengthOf(2) @@ -114,7 +114,7 @@ describe('Test video captions', function () { it('Should replace an existing caption with a srt file and convert it', async function () { this.timeout(30000) - await servers[0].captions.createVideoCaption({ + await servers[0].captions.add({ language: 'ar', videoId: videoUUID, fixture: 'subtitle-good.srt' @@ -128,7 +128,7 @@ describe('Test video captions', function () { it('Should have this caption updated and converted', async function () { for (const server of servers) { - const body = await server.captions.listVideoCaptions({ videoId: videoUUID }) + const body = await server.captions.list({ videoId: videoUUID }) expect(body.total).to.equal(2) expect(body.data).to.have.lengthOf(2) @@ -157,14 +157,14 @@ describe('Test video captions', function () { it('Should remove one caption', async function () { this.timeout(30000) - await servers[0].captions.deleteVideoCaption({ videoId: videoUUID, language: 'ar' }) + await servers[0].captions.delete({ videoId: videoUUID, language: 'ar' }) await waitJobs(servers) }) it('Should only list the caption that was not deleted', async function () { for (const server of servers) { - const body = await server.captions.listVideoCaptions({ videoId: videoUUID }) + const body = await server.captions.list({ videoId: videoUUID }) expect(body.total).to.equal(1) expect(body.data).to.have.lengthOf(1) diff --git a/server/tests/api/videos/video-imports.ts b/server/tests/api/videos/video-imports.ts index 192f5232e..2eac130d2 100644 --- a/server/tests/api/videos/video-imports.ts +++ b/server/tests/api/videos/video-imports.ts @@ -59,7 +59,7 @@ describe('Test video imports', function () { expect(videoTorrent.name).to.contain('你好 世界 720p.mp4') expect(videoMagnet.name).to.contain('super peertube2 video') - const bodyCaptions = await server.captions.listVideoCaptions({ videoId: idHttp }) + const bodyCaptions = await server.captions.list({ videoId: idHttp }) expect(bodyCaptions.total).to.equal(2) } @@ -76,7 +76,7 @@ describe('Test video imports', function () { expect(video.files).to.have.lengthOf(1) - const bodyCaptions = await server.captions.listVideoCaptions({ videoId: id }) + const bodyCaptions = await server.captions.list({ videoId: id }) expect(bodyCaptions.total).to.equal(2) } @@ -120,7 +120,7 @@ describe('Test video imports', function () { await testImage(servers[0].url, 'video_import_thumbnail', video.thumbnailPath) await testImage(servers[0].url, 'video_import_preview', video.previewPath) - const bodyCaptions = await servers[0].captions.listVideoCaptions({ videoId: video.id }) + const bodyCaptions = await servers[0].captions.list({ videoId: video.id }) const videoCaptions = bodyCaptions.data expect(videoCaptions).to.have.lengthOf(2) -- cgit v1.2.3