ActivityPub-federated video streaming platform using P2P directly in your web browser
Introduce server commands
Chocobozzz6c5065a011b0
diff --git a/server/tests/api/activitypub/helpers.ts b/server/tests/api/activitypub/helpers.tsindex 66d7631b72..57b1cab23c 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.tsindex 9549070ef1..291de93ea8 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.tsindex d851d258dc..3949672855 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.tsindex d372221d05..8509b8ac5b 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.tsindex 4a2fc1197d..7973c112f1 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.tsindex 26d4423f93..913eca3669 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.tsindex bffe29bcec..fda7e9640c 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: '[email protected]'- })+ }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: '[email protected]' })+ const fields = { ...baseCorrectParams, email: '[email protected]' }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: '[email protected]', role: UserRole.USER })+ const fields = { ...baseCorrectParams, username: 'a4656', email: '[email protected]', 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.tsindex d29346dc3f..3b72d37969 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.tsindex ea473191ed..2cc124cc1a 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.tsindex 1c507a047e..3799e73b6d 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.tsindex 4d7a9a23bb..6549063b1d 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 = baseCorrectAttachesawait 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 = baseCorrectAttachesawait 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 = baseCorrectAttachesawait 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 = baseCorrectAttachesawait 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 = baseCorrectAttachesawait 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 = baseCorrectAttachesawait 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 = baseCorrectAttachesawait 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 = baseCorrectAttachesawait 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 = baseCorrectAttachesawait 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 = baseCorrectAttachesawait 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 = baseCorrectAttachesawait 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 = baseCorrectAttachesawait 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 = baseCorrectAttachesawait 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 = baseCorrectAttachesawait 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 = baseCorrectAttachesconst 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 PeerTubeProblemDocumentdiff --git a/server/tests/api/live/live.ts b/server/tests/api/live/live.tsindex f9a162df6b..999a490513 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.tsindex 229f78811d..99b4346068 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 = falseawait 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 expectedautoBlacklistTestsCustomConfig.transcoding.enabled = truediff --git a/server/tests/api/notifications/notifications-api.ts b/server/tests/api/notifications/notifications-api.tsindex 447492c5f3..e5864f1c22 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.tsindex 363e4cbfeb..03857f5126 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.tsindex 82d952471c..a31278de7c 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.tsindex 56a2af395d..00a5e86ccb 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, addif (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.tsindex e4c5f5796e..306f84c3a9 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.tsindex 513538917c..66f5f3182d 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.idvideoUUID = 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.tsindex dd06acb5e9..d45c3ae8a7 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: anylet 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 tokensawait setAccessTokensToServers(servers)diff --git a/server/tests/api/server/logs.ts b/server/tests/api/server/logs.tsindex 365f6cc2b1..096d63e21c 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.tsindex d4a43276f8..a81ac961a6 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.tsindex 47056be785..7b650cb8fd 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.tsindex 7ddbd5cd9c..9b516af81c 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.tsindex 1b6f0f48aa..1905aac837 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.tsindex 6c01c7e78f..5845efc865 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.lengthdiff --git a/server/tests/api/videos/single-server.ts b/server/tests/api/videos/single-server.tsindex 1058a1e9c4..af1703e027 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.tsindex 83ee809b88..d4a5385ab6 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.tsindex 4f9ecbe8ed..f6ae8cab14 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.tsindex e74fb5bef4..f16b22bae6 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/constantsimport { 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.bodyexpect(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 propertiesdiff --git a/server/tests/cli/optimize-old-videos.ts b/server/tests/cli/optimize-old-videos.tsindex bd15012fe1..e369a33058 100644--- a/server/tests/cli/optimize-old-videos.ts+++ b/server/tests/cli/optimize-old-videos.ts@@ -4,7 +4,6 @@ import 'mocha'import * as chai from 'chai'import { join } from 'path'import {- buildServerDirectory,cleanupTests,doubleFollow,flushAndRunMultipleServers,@@ -96,7 +95,7 @@ describe('Test optimize old videos', function () {expect(file.size).to.be.below(8000000)- const path = buildServerDirectory(servers[0], join('videos', video.uuid + '-' + file.resolution.id + '.mp4'))+ const path = servers[0].serversCommand.buildDirectory(join('videos', video.uuid + '-' + file.resolution.id + '.mp4'))const bitrate = await getVideoFileBitrate(path)const fps = await getVideoFileFPS(path)const resolution = await getVideoFileResolution(path)diff --git a/server/tests/cli/prune-storage.ts b/server/tests/cli/prune-storage.tsindex d4dbee682e..68a59a41d0 100644--- a/server/tests/cli/prune-storage.ts+++ b/server/tests/cli/prune-storage.ts@@ -7,7 +7,6 @@ import { join } from 'path'import { buildUUID } from '@server/helpers/uuid'import { HttpStatusCode } from '@shared/core-utils'import {- buildServerDirectory,cleanupTests,CLICommand,doubleFollow,@@ -26,14 +25,14 @@ import { VideoPlaylistPrivacy } from '@shared/models'const expect = chai.expect-async function countFiles (internalServerNumber: number, directory: string) {- const files = await readdir(buildServerDirectory({ internalServerNumber }, directory))+async function countFiles (server: ServerInfo, directory: string) {+ const files = await readdir(server.serversCommand.buildDirectory(directory))return files.length}-async function assertNotExists (internalServerNumber: number, directory: string, substring: string) {- const files = await readdir(buildServerDirectory({ internalServerNumber }, directory))+async function assertNotExists (server: ServerInfo, directory: string, substring: string) {+ const files = await readdir(server.serversCommand.buildDirectory(directory))for (const f of files) {expect(f).to.not.contain(substring)@@ -42,19 +41,19 @@ async function assertNotExists (internalServerNumber: number, directory: string,async function assertCountAreOkay (servers: ServerInfo[]) {for (const server of servers) {- const videosCount = await countFiles(server.internalServerNumber, 'videos')+ const videosCount = await countFiles(server, 'videos')expect(videosCount).to.equal(8)- const torrentsCount = await countFiles(server.internalServerNumber, 'torrents')+ const torrentsCount = await countFiles(server, 'torrents')expect(torrentsCount).to.equal(16)- const previewsCount = await countFiles(server.internalServerNumber, 'previews')+ const previewsCount = await countFiles(server, 'previews')expect(previewsCount).to.equal(2)- const thumbnailsCount = await countFiles(server.internalServerNumber, 'thumbnails')+ const thumbnailsCount = await countFiles(server, 'thumbnails')expect(thumbnailsCount).to.equal(6)- const avatarsCount = await countFiles(server.internalServerNumber, 'avatars')+ const avatarsCount = await countFiles(server, 'avatars')expect(avatarsCount).to.equal(2)}}@@ -122,7 +121,7 @@ describe('Test prune storage scripts', function () {it('Should create some dirty files', async function () {for (let i = 0; i < 2; i++) {{- const base = buildServerDirectory(servers[0], 'videos')+ const base = servers[0].serversCommand.buildDirectory('videos')const n1 = buildUUID() + '.mp4'const n2 = buildUUID() + '.webm'@@ -134,7 +133,7 @@ describe('Test prune storage scripts', function () {}{- const base = buildServerDirectory(servers[0], 'torrents')+ const base = servers[0].serversCommand.buildDirectory('torrents')const n1 = buildUUID() + '-240.torrent'const n2 = buildUUID() + '-480.torrent'@@ -146,7 +145,7 @@ describe('Test prune storage scripts', function () {}{- const base = buildServerDirectory(servers[0], 'thumbnails')+ const base = servers[0].serversCommand.buildDirectory('thumbnails')const n1 = buildUUID() + '.jpg'const n2 = buildUUID() + '.jpg'@@ -158,7 +157,7 @@ describe('Test prune storage scripts', function () {}{- const base = buildServerDirectory(servers[0], 'previews')+ const base = servers[0].serversCommand.buildDirectory('previews')const n1 = buildUUID() + '.jpg'const n2 = buildUUID() + '.jpg'@@ -170,7 +169,7 @@ describe('Test prune storage scripts', function () {}{- const base = buildServerDirectory(servers[0], 'avatars')+ const base = servers[0].serversCommand.buildDirectory('avatars')const n1 = buildUUID() + '.png'const n2 = buildUUID() + '.jpg'@@ -195,7 +194,7 @@ describe('Test prune storage scripts', function () {for (const directory of Object.keys(badNames)) {for (const name of badNames[directory]) {- await assertNotExists(servers[0].internalServerNumber, directory, name)+ await assertNotExists(servers[0], directory, name)}}})diff --git a/server/tests/cli/regenerate-thumbnails.ts b/server/tests/cli/regenerate-thumbnails.tsindex 1b460e9c02..68a4711b6f 100644--- a/server/tests/cli/regenerate-thumbnails.ts+++ b/server/tests/cli/regenerate-thumbnails.ts@@ -4,7 +4,6 @@ import { writeFile } from 'fs-extra'import { basename, join } from 'path'import { Video, VideoDetails } from '@shared/models'import {- buildServerDirectory,cleanupTests,doubleFollow,flushAndRunMultipleServers,@@ -50,7 +49,7 @@ describe('Test regenerate thumbnails script', function () {const videoUUID1 = (await uploadVideoAndGetId({ server: servers[0], videoName: 'video 1' })).uuidvideo1 = await (getVideo(servers[0].url, videoUUID1).then(res => res.body))- thumbnail1Path = join(buildServerDirectory(servers[0], 'thumbnails'), basename(video1.thumbnailPath))+ thumbnail1Path = join(servers[0].serversCommand.buildDirectory('thumbnails'), basename(video1.thumbnailPath))const videoUUID2 = (await uploadVideoAndGetId({ server: servers[0], videoName: 'video 2' })).uuidvideo2 = await (getVideo(servers[0].url, videoUUID2).then(res => res.body))@@ -62,7 +61,7 @@ describe('Test regenerate thumbnails script', function () {remoteVideo = await (getVideo(servers[0].url, videoUUID).then(res => res.body))- thumbnailRemotePath = join(buildServerDirectory(servers[0], 'thumbnails'), basename(remoteVideo.thumbnailPath))+ thumbnailRemotePath = join(servers[0].serversCommand.buildDirectory('thumbnails'), basename(remoteVideo.thumbnailPath))}await writeFile(thumbnail1Path, '')diff --git a/server/tests/plugins/action-hooks.ts b/server/tests/plugins/action-hooks.tsindex bcf773854b..cf81e44b74 100644--- a/server/tests/plugins/action-hooks.ts+++ b/server/tests/plugins/action-hooks.ts@@ -22,8 +22,7 @@ import {flushAndRunMultipleServers,killallServers,reRunServer,- ServerInfo,- waitUntilLog+ ServerInfo} from '../../../shared/extra-utils/server/servers'describe('Test plugin action hooks', function () {@@ -32,7 +31,7 @@ describe('Test plugin action hooks', function () {let threadId: numberfunction checkHook (hook: ServerHookName) {- return waitUntilLog(servers[0], 'Run hook ' + hook)+ return servers[0].serversCommand.waitUntilLog('Run hook ' + hook)}before(async function () {diff --git a/server/tests/plugins/external-auth.ts b/server/tests/plugins/external-auth.tsindex 09a107ca2e..f7cee588ab 100644--- a/server/tests/plugins/external-auth.ts+++ b/server/tests/plugins/external-auth.ts@@ -17,8 +17,7 @@ import {setAccessTokensToServers,updateMyUser,userLogin,- wait,- waitUntilLog+ wait} from '@shared/extra-utils'import { User, UserRole } from '@shared/models'@@ -127,7 +126,7 @@ describe('Test external auth plugins', function () {await loginUsingExternalToken(server, 'cyan', externalAuthToken, HttpStatusCode.BAD_REQUEST_400)- await waitUntilLog(server, 'expired external auth token', 2)+ await server.serversCommand.waitUntilLog('expired external auth token', 2)})it('Should auto login Cyan, create the user and use the token', async function () {@@ -217,7 +216,7 @@ describe('Test external auth plugins', function () {})it('Should have logged out Cyan', async function () {- await waitUntilLog(server, 'On logout cyan')+ await server.serversCommand.waitUntilLog('On logout cyan')await getMyUserInformation(server.url, cyanAccessToken, HttpStatusCode.UNAUTHORIZED_401)})diff --git a/server/tests/plugins/filter-hooks.ts b/server/tests/plugins/filter-hooks.tsindex c235508e80..b5e29d2985 100644--- a/server/tests/plugins/filter-hooks.ts+++ b/server/tests/plugins/filter-hooks.ts@@ -24,8 +24,7 @@ import {updateVideo,uploadVideo,uploadVideoAndGetId,- waitJobs,- waitUntilLog+ waitJobs} from '@shared/extra-utils'import { VideoDetails, VideoImportState, VideoPlaylist, VideoPlaylistPrivacy, VideoPrivacy } from '@shared/models'@@ -475,8 +474,8 @@ describe('Test plugin filter hooks', function () {}})- await waitUntilLog(servers[0], 'Run hook filter:api.search.videos.local.list.params', 1)- await waitUntilLog(servers[0], 'Run hook filter:api.search.videos.local.list.result', 1)+ await servers[0].serversCommand.waitUntilLog('Run hook filter:api.search.videos.local.list.params', 1)+ await servers[0].serversCommand.waitUntilLog('Run hook filter:api.search.videos.local.list.result', 1)})it('Should run filter:api.search.videos.index.list.{params,result}', async function () {@@ -487,10 +486,10 @@ describe('Test plugin filter hooks', function () {}})- await waitUntilLog(servers[0], 'Run hook filter:api.search.videos.local.list.params', 1)- await waitUntilLog(servers[0], 'Run hook filter:api.search.videos.local.list.result', 1)- await waitUntilLog(servers[0], 'Run hook filter:api.search.videos.index.list.params', 1)- await waitUntilLog(servers[0], 'Run hook filter:api.search.videos.index.list.result', 1)+ await servers[0].serversCommand.waitUntilLog('Run hook filter:api.search.videos.local.list.params', 1)+ await servers[0].serversCommand.waitUntilLog('Run hook filter:api.search.videos.local.list.result', 1)+ await servers[0].serversCommand.waitUntilLog('Run hook filter:api.search.videos.index.list.params', 1)+ await servers[0].serversCommand.waitUntilLog('Run hook filter:api.search.videos.index.list.result', 1)})it('Should run filter:api.search.video-channels.local.list.{params,result}', async function () {@@ -500,8 +499,8 @@ describe('Test plugin filter hooks', function () {}})- await waitUntilLog(servers[0], 'Run hook filter:api.search.video-channels.local.list.params', 1)- await waitUntilLog(servers[0], 'Run hook filter:api.search.video-channels.local.list.result', 1)+ await servers[0].serversCommand.waitUntilLog('Run hook filter:api.search.video-channels.local.list.params', 1)+ await servers[0].serversCommand.waitUntilLog('Run hook filter:api.search.video-channels.local.list.result', 1)})it('Should run filter:api.search.video-channels.index.list.{params,result}', async function () {@@ -512,10 +511,10 @@ describe('Test plugin filter hooks', function () {}})- await waitUntilLog(servers[0], 'Run hook filter:api.search.video-channels.local.list.params', 1)- await waitUntilLog(servers[0], 'Run hook filter:api.search.video-channels.local.list.result', 1)- await waitUntilLog(servers[0], 'Run hook filter:api.search.video-channels.index.list.params', 1)- await waitUntilLog(servers[0], 'Run hook filter:api.search.video-channels.index.list.result', 1)+ await servers[0].serversCommand.waitUntilLog('Run hook filter:api.search.video-channels.local.list.params', 1)+ await servers[0].serversCommand.waitUntilLog('Run hook filter:api.search.video-channels.local.list.result', 1)+ await servers[0].serversCommand.waitUntilLog('Run hook filter:api.search.video-channels.index.list.params', 1)+ await servers[0].serversCommand.waitUntilLog('Run hook filter:api.search.video-channels.index.list.result', 1)})it('Should run filter:api.search.video-playlists.local.list.{params,result}', async function () {@@ -525,8 +524,8 @@ describe('Test plugin filter hooks', function () {}})- await waitUntilLog(servers[0], 'Run hook filter:api.search.video-playlists.local.list.params', 1)- await waitUntilLog(servers[0], 'Run hook filter:api.search.video-playlists.local.list.result', 1)+ await servers[0].serversCommand.waitUntilLog('Run hook filter:api.search.video-playlists.local.list.params', 1)+ await servers[0].serversCommand.waitUntilLog('Run hook filter:api.search.video-playlists.local.list.result', 1)})it('Should run filter:api.search.video-playlists.index.list.{params,result}', async function () {@@ -537,10 +536,10 @@ describe('Test plugin filter hooks', function () {}})- await waitUntilLog(servers[0], 'Run hook filter:api.search.video-playlists.local.list.params', 1)- await waitUntilLog(servers[0], 'Run hook filter:api.search.video-playlists.local.list.result', 1)- await waitUntilLog(servers[0], 'Run hook filter:api.search.video-playlists.index.list.params', 1)- await waitUntilLog(servers[0], 'Run hook filter:api.search.video-playlists.index.list.result', 1)+ await servers[0].serversCommand.waitUntilLog('Run hook filter:api.search.video-playlists.local.list.params', 1)+ await servers[0].serversCommand.waitUntilLog('Run hook filter:api.search.video-playlists.local.list.result', 1)+ await servers[0].serversCommand.waitUntilLog('Run hook filter:api.search.video-playlists.index.list.params', 1)+ await servers[0].serversCommand.waitUntilLog('Run hook filter:api.search.video-playlists.index.list.result', 1)})})diff --git a/server/tests/plugins/id-and-pass-auth.ts b/server/tests/plugins/id-and-pass-auth.tsindex 99de28d3f8..a0b31bc1f7 100644--- a/server/tests/plugins/id-and-pass-auth.ts+++ b/server/tests/plugins/id-and-pass-auth.ts@@ -15,8 +15,7 @@ import {setAccessTokensToServers,updateMyUser,userLogin,- wait,- waitUntilLog+ wait} from '@shared/extra-utils'import { User, UserRole } from '@shared/models'@@ -137,7 +136,7 @@ describe('Test id and pass auth plugins', function () {})it('Should have logged out Crash', async function () {- await waitUntilLog(server, 'On logout for auth 1 - 2')+ await server.serversCommand.waitUntilLog('On logout for auth 1 - 2')await getMyUserInformation(server.url, crashAccessToken, 401)})@@ -164,16 +163,16 @@ describe('Test id and pass auth plugins', function () {it('Should reject an invalid username, email, role or display name', async function () {await userLogin(server, { username: 'ward', password: 'ward password' }, 400)- await waitUntilLog(server, 'valid username')+ await server.serversCommand.waitUntilLog('valid username')await userLogin(server, { username: 'kiros', password: 'kiros password' }, 400)- await waitUntilLog(server, 'valid display name')+ await server.serversCommand.waitUntilLog('valid display name')await userLogin(server, { username: 'raine', password: 'raine password' }, 400)- await waitUntilLog(server, 'valid role')+ await server.serversCommand.waitUntilLog('valid role')await userLogin(server, { username: 'ellone', password: 'elonne password' }, 400)- await waitUntilLog(server, 'valid email')+ await server.serversCommand.waitUntilLog('valid email')})it('Should unregister spyro-auth and do not login existing Spyro', async function () {diff --git a/server/tests/plugins/plugin-helpers.ts b/server/tests/plugins/plugin-helpers.tsindex 0e0f616385..cbb6887ebb 100644--- a/server/tests/plugins/plugin-helpers.ts+++ b/server/tests/plugins/plugin-helpers.ts@@ -17,8 +17,7 @@ import {setAccessTokensToServers,uploadVideoAndGetId,viewVideo,- waitJobs,- waitUntilLog+ waitJobs} from '@shared/extra-utils'function postCommand (server: ServerInfo, command: string, bodyArg?: object) {@@ -50,22 +49,22 @@ describe('Test plugin helpers', function () {describe('Logger', function () {it('Should have logged things', async function () {- await waitUntilLog(servers[0], 'localhost:' + servers[0].port + ' peertube-plugin-test-four', 1, false)- await waitUntilLog(servers[0], 'Hello world from plugin four', 1)+ await servers[0].serversCommand.waitUntilLog('localhost:' + servers[0].port + ' peertube-plugin-test-four', 1, false)+ await servers[0].serversCommand.waitUntilLog('Hello world from plugin four', 1)})})describe('Database', function () {it('Should have made a query', async function () {- await waitUntilLog(servers[0], `root email is admin${servers[0].internalServerNumber}@example.com`)+ await servers[0].serversCommand.waitUntilLog(`root email is admin${servers[0].internalServerNumber}@example.com`)})})describe('Config', function () {it('Should have the correct webserver url', async function () {- await waitUntilLog(servers[0], `server url is http://localhost:${servers[0].port}`)+ await servers[0].serversCommand.waitUntilLog(`server url is http://localhost:${servers[0].port}`)})it('Should have the correct config', async function () {@@ -83,7 +82,7 @@ describe('Test plugin helpers', function () {describe('Server', function () {it('Should get the server actor', async function () {- await waitUntilLog(servers[0], 'server actor name is peertube')+ await servers[0].serversCommand.waitUntilLog('server actor name is peertube')})})@@ -248,7 +247,7 @@ describe('Test plugin helpers', function () {// Should delete the videoawait viewVideo(servers[0].url, videoUUID)- await waitUntilLog(servers[0], 'Video deleted by plugin four.')+ await servers[0].serversCommand.waitUntilLog('Video deleted by plugin four.')try {// Should throw because the video should have been deleted@@ -258,11 +257,11 @@ describe('Test plugin helpers', function () {if (err.message.includes('exists')) throw err}- await checkVideoFilesWereRemoved(videoUUID, servers[0].internalServerNumber)+ await checkVideoFilesWereRemoved(videoUUID, servers[0])})it('Should have fetched the video by URL', async function () {- await waitUntilLog(servers[0], `video from DB uuid is ${videoUUID}`)+ await servers[0].serversCommand.waitUntilLog(`video from DB uuid is ${videoUUID}`)})})diff --git a/server/tests/plugins/plugin-storage.ts b/server/tests/plugins/plugin-storage.tsindex 4c65463f26..9babfc83e0 100644--- a/server/tests/plugins/plugin-storage.ts+++ b/server/tests/plugins/plugin-storage.ts@@ -5,16 +5,7 @@ import { expect } from 'chai'import { pathExists, readdir, readFile } from 'fs-extra'import { join } from 'path'import { HttpStatusCode } from '@shared/core-utils'-import {- buildServerDirectory,- cleanupTests,- flushAndRunServer,- makeGetRequest,- PluginsCommand,- ServerInfo,- setAccessTokensToServers,- waitUntilLog-} from '@shared/extra-utils'+import { cleanupTests, flushAndRunServer, makeGetRequest, PluginsCommand, ServerInfo, setAccessTokensToServers } from '@shared/extra-utils'describe('Test plugin storage', function () {let server: ServerInfo@@ -31,7 +22,7 @@ describe('Test plugin storage', function () {describe('DB storage', function () {it('Should correctly store a subkey', async function () {- await waitUntilLog(server, 'superkey stored value is toto')+ await server.serversCommand.waitUntilLog('superkey stored value is toto')})})@@ -47,12 +38,12 @@ describe('Test plugin storage', function () {}before(function () {- dataPath = buildServerDirectory(server, 'plugins/data')+ dataPath = server.serversCommand.buildDirectory('plugins/data')pluginDataPath = join(dataPath, 'peertube-plugin-test-six')})it('Should have created the directory on install', async function () {- const dataPath = buildServerDirectory(server, 'plugins/data')+ const dataPath = server.serversCommand.buildDirectory('plugins/data')const pluginDataPath = join(dataPath, 'peertube-plugin-test-six')expect(await pathExists(dataPath)).to.be.truediff --git a/server/tests/plugins/plugin-transcoding.ts b/server/tests/plugins/plugin-transcoding.tsindex ca4d9f962e..4839e87928 100644--- a/server/tests/plugins/plugin-transcoding.ts+++ b/server/tests/plugins/plugin-transcoding.ts@@ -5,7 +5,6 @@ import { expect } from 'chai'import { join } from 'path'import { getAudioStream, getVideoFileFPS, getVideoStreamFromFile } from '@server/helpers/ffprobe-utils'import {- buildServerDirectory,cleanupTests,flushAndRunServer,getVideo,@@ -247,7 +246,7 @@ describe('Test transcoding plugins', function () {const videoUUID = (await uploadVideoAndGetId({ server, videoName: 'video', fixture: 'video_short_240p.mp4' })).uuidawait waitJobs([ server ])- const path = buildServerDirectory(server, join('videos', videoUUID + '-240.mp4'))+ const path = server.serversCommand.buildDirectory(join('videos', videoUUID + '-240.mp4'))const audioProbe = await getAudioStream(path)expect(audioProbe.audioStream.codec_name).to.equal('opus')diff --git a/shared/extra-utils/miscs/checks.ts b/shared/extra-utils/miscs/checks.tsnew file mode 100644index 0000000000..86b861cd2b--- /dev/null+++ b/shared/extra-utils/miscs/checks.ts@@ -0,0 +1,46 @@+/* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/no-floating-promises */++import { expect } from 'chai'+import { pathExists, readFile } from 'fs-extra'+import { join } from 'path'+import { root } from '@server/helpers/core-utils'+import { HttpStatusCode } from '@shared/core-utils'+import { makeGetRequest } from '../requests'+import { ServerInfo } from '../server'++// Default interval -> 5 minutes+function dateIsValid (dateString: string, interval = 300000) {+ const dateToCheck = new Date(dateString)+ const now = new Date()++ return Math.abs(now.getTime() - dateToCheck.getTime()) <= interval+}++async function testImage (url: string, imageName: string, imagePath: string, extension = '.jpg') {+ const res = await makeGetRequest({+ url,+ path: imagePath,+ statusCodeExpected: HttpStatusCode.OK_200+ })++ const body = res.body++ const data = await readFile(join(root(), 'server', 'tests', 'fixtures', imageName + extension))+ const minLength = body.length - ((30 * body.length) / 100)+ const maxLength = body.length + ((30 * body.length) / 100)++ expect(data.length).to.be.above(minLength, 'the generated image is way smaller than the recorded fixture')+ expect(data.length).to.be.below(maxLength, 'the generated image is way larger than the recorded fixture')+}++async function testFileExistsOrNot (server: ServerInfo, directory: string, filePath: string, exist: boolean) {+ const base = server.serversCommand.buildDirectory(directory)++ expect(await pathExists(join(base, filePath))).to.equal(exist)+}++export {+ dateIsValid,+ testImage,+ testFileExistsOrNot+}diff --git a/shared/extra-utils/miscs/generate.ts b/shared/extra-utils/miscs/generate.tsnew file mode 100644index 0000000000..4e70ab853c--- /dev/null+++ b/shared/extra-utils/miscs/generate.ts@@ -0,0 +1,61 @@+import { ensureDir, pathExists } from 'fs-extra'+import { dirname } from 'path'+import { buildAbsoluteFixturePath } from './tests'+import * as ffmpeg from 'fluent-ffmpeg'++async function generateHighBitrateVideo () {+ const tempFixturePath = buildAbsoluteFixturePath('video_high_bitrate_1080p.mp4', true)++ await ensureDir(dirname(tempFixturePath))++ const exists = await pathExists(tempFixturePath)+ if (!exists) {+ console.log('Generating high bitrate video.')++ // Generate a random, high bitrate video on the fly, so we don't have to include+ // a large file in the repo. The video needs to have a certain minimum length so+ // that FFmpeg properly applies bitrate limits.+ // https://stackoverflow.com/a/15795112+ return new Promise<string>((res, rej) => {+ ffmpeg()+ .outputOptions([ '-f rawvideo', '-video_size 1920x1080', '-i /dev/urandom' ])+ .outputOptions([ '-ac 2', '-f s16le', '-i /dev/urandom', '-t 10' ])+ .outputOptions([ '-maxrate 10M', '-bufsize 10M' ])+ .output(tempFixturePath)+ .on('error', rej)+ .on('end', () => res(tempFixturePath))+ .run()+ })+ }++ return tempFixturePath+}++async function generateVideoWithFramerate (fps = 60) {+ const tempFixturePath = buildAbsoluteFixturePath(`video_${fps}fps.mp4`, true)++ await ensureDir(dirname(tempFixturePath))++ const exists = await pathExists(tempFixturePath)+ if (!exists) {+ console.log('Generating video with framerate %d.', fps)++ return new Promise<string>((res, rej) => {+ ffmpeg()+ .outputOptions([ '-f rawvideo', '-video_size 1280x720', '-i /dev/urandom' ])+ .outputOptions([ '-ac 2', '-f s16le', '-i /dev/urandom', '-t 10' ])+ .outputOptions([ `-r ${fps}` ])+ .output(tempFixturePath)+ .on('error', rej)+ .on('end', () => res(tempFixturePath))+ .run()+ })+ }++ return tempFixturePath+}++export {+ generateHighBitrateVideo,+ generateVideoWithFramerate+}diff --git a/shared/extra-utils/miscs/index.ts b/shared/extra-utils/miscs/index.tsindex 7e236c3299..4474661de8 100644--- a/shared/extra-utils/miscs/index.ts+++ b/shared/extra-utils/miscs/index.ts@@ -1,3 +1,5 @@-export * from './miscs'+export * from './checks'+export * from './generate'export * from './sql-command'-export * from './stubs'+export * from './tests'+export * from './webtorrent'diff --git a/shared/extra-utils/miscs/miscs.ts b/shared/extra-utils/miscs/miscs.tsdeleted file mode 100644index 462b914d41..0000000000--- a/shared/extra-utils/miscs/miscs.ts+++ /dev/null@@ -1,170 +0,0 @@-/* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */--import * as chai from 'chai'-import * as ffmpeg from 'fluent-ffmpeg'-import { ensureDir, pathExists, readFile, stat } from 'fs-extra'-import { basename, dirname, isAbsolute, join, resolve } from 'path'-import * as request from 'supertest'-import * as WebTorrent from 'webtorrent'-import { HttpStatusCode } from '../../../shared/core-utils/miscs/http-error-codes'--const expect = chai.expect-let webtorrent: WebTorrent.Instance--function immutableAssign<T, U> (target: T, source: U) {- return Object.assign<{}, T, U>({}, target, source)-}--// Default interval -> 5 minutes-function dateIsValid (dateString: string, interval = 300000) {- const dateToCheck = new Date(dateString)- const now = new Date()-- return Math.abs(now.getTime() - dateToCheck.getTime()) <= interval-}--function wait (milliseconds: number) {- return new Promise(resolve => setTimeout(resolve, milliseconds))-}--function webtorrentAdd (torrent: string, refreshWebTorrent = false) {- const WebTorrent = require('webtorrent')-- if (!webtorrent) webtorrent = new WebTorrent()- if (refreshWebTorrent === true) webtorrent = new WebTorrent()-- return new Promise<WebTorrent.Torrent>(res => webtorrent.add(torrent, res))-}--function root () {- // We are in /miscs- let root = join(__dirname, '..', '..', '..')-- if (basename(root) === 'dist') root = resolve(root, '..')-- return root-}--function buildServerDirectory (server: { internalServerNumber: number }, directory: string) {- return join(root(), 'test' + server.internalServerNumber, directory)-}--async function testImage (url: string, imageName: string, imagePath: string, extension = '.jpg') {- const res = await request(url)- .get(imagePath)- .expect(HttpStatusCode.OK_200)-- const body = res.body-- const data = await readFile(join(root(), 'server', 'tests', 'fixtures', imageName + extension))- const minLength = body.length - ((30 * body.length) / 100)- const maxLength = body.length + ((30 * body.length) / 100)-- expect(data.length).to.be.above(minLength, 'the generated image is way smaller than the recorded fixture')- expect(data.length).to.be.below(maxLength, 'the generated image is way larger than the recorded fixture')-}--async function testFileExistsOrNot (server: { internalServerNumber: number }, directory: string, filePath: string, exist: boolean) {- const base = buildServerDirectory(server, directory)-- expect(await pathExists(join(base, filePath))).to.equal(exist)-}--function isGithubCI () {- return !!process.env.GITHUB_WORKSPACE-}--function buildAbsoluteFixturePath (path: string, customCIPath = false) {- if (isAbsolute(path)) return path-- if (customCIPath && process.env.GITHUB_WORKSPACE) {- return join(process.env.GITHUB_WORKSPACE, 'fixtures', path)- }-- return join(root(), 'server', 'tests', 'fixtures', path)-}--function areHttpImportTestsDisabled () {- const disabled = process.env.DISABLE_HTTP_IMPORT_TESTS === 'true'-- if (disabled) console.log('Import tests are disabled')-- return disabled-}--async function generateHighBitrateVideo () {- const tempFixturePath = buildAbsoluteFixturePath('video_high_bitrate_1080p.mp4', true)-- await ensureDir(dirname(tempFixturePath))-- const exists = await pathExists(tempFixturePath)- if (!exists) {- console.log('Generating high bitrate video.')-- // Generate a random, high bitrate video on the fly, so we don't have to include- // a large file in the repo. The video needs to have a certain minimum length so- // that FFmpeg properly applies bitrate limits.- // https://stackoverflow.com/a/15795112- return new Promise<string>((res, rej) => {- ffmpeg()- .outputOptions([ '-f rawvideo', '-video_size 1920x1080', '-i /dev/urandom' ])- .outputOptions([ '-ac 2', '-f s16le', '-i /dev/urandom', '-t 10' ])- .outputOptions([ '-maxrate 10M', '-bufsize 10M' ])- .output(tempFixturePath)- .on('error', rej)- .on('end', () => res(tempFixturePath))- .run()- })- }-- return tempFixturePath-}--async function generateVideoWithFramerate (fps = 60) {- const tempFixturePath = buildAbsoluteFixturePath(`video_${fps}fps.mp4`, true)-- await ensureDir(dirname(tempFixturePath))-- const exists = await pathExists(tempFixturePath)- if (!exists) {- console.log('Generating video with framerate %d.', fps)-- return new Promise<string>((res, rej) => {- ffmpeg()- .outputOptions([ '-f rawvideo', '-video_size 1280x720', '-i /dev/urandom' ])- .outputOptions([ '-ac 2', '-f s16le', '-i /dev/urandom', '-t 10' ])- .outputOptions([ `-r ${fps}` ])- .output(tempFixturePath)- .on('error', rej)- .on('end', () => res(tempFixturePath))- .run()- })- }-- return tempFixturePath-}--async function getFileSize (path: string) {- const stats = await stat(path)-- return stats.size-}--// -----------------------------------------------------------------------------export {- dateIsValid,- wait,- areHttpImportTestsDisabled,- buildServerDirectory,- webtorrentAdd,- getFileSize,- immutableAssign,- testImage,- isGithubCI,- buildAbsoluteFixturePath,- testFileExistsOrNot,- root,- generateHighBitrateVideo,- generateVideoWithFramerate-}diff --git a/shared/extra-utils/miscs/sql-command.ts b/shared/extra-utils/miscs/sql-command.tsindex 2a3e9e607a..80c8cd2715 100644--- a/shared/extra-utils/miscs/sql-command.ts+++ b/shared/extra-utils/miscs/sql-command.ts@@ -1,5 +1,5 @@import { QueryTypes, Sequelize } from 'sequelize'-import { AbstractCommand } from '../shared'+import { AbstractCommand } from '../shared/abstract-command'export class SQLCommand extends AbstractCommand {private sequelize: Sequelizediff --git a/shared/extra-utils/miscs/stubs.ts b/shared/extra-utils/miscs/stubs.tsdeleted file mode 100644index 940e4bf299..0000000000--- a/shared/extra-utils/miscs/stubs.ts+++ /dev/null@@ -1,7 +0,0 @@-function buildRequestStub (): any {- return { }-}--export {- buildRequestStub-}diff --git a/shared/extra-utils/miscs/tests.ts b/shared/extra-utils/miscs/tests.tsnew file mode 100644index 0000000000..8f7a2f92b4--- /dev/null+++ b/shared/extra-utils/miscs/tests.ts@@ -0,0 +1,62 @@+import { stat } from 'fs-extra'+import { basename, isAbsolute, join, resolve } from 'path'++function parallelTests () {+ return process.env.MOCHA_PARALLEL === 'true'+}++function isGithubCI () {+ return !!process.env.GITHUB_WORKSPACE+}++function areHttpImportTestsDisabled () {+ const disabled = process.env.DISABLE_HTTP_IMPORT_TESTS === 'true'++ if (disabled) console.log('Import tests are disabled')++ return disabled+}++function buildAbsoluteFixturePath (path: string, customCIPath = false) {+ if (isAbsolute(path)) return path++ if (customCIPath && process.env.GITHUB_WORKSPACE) {+ return join(process.env.GITHUB_WORKSPACE, 'fixtures', path)+ }++ return join(root(), 'server', 'tests', 'fixtures', path)+}++function root () {+ // We are in /miscs+ let root = join(__dirname, '..', '..', '..')++ if (basename(root) === 'dist') root = resolve(root, '..')++ return root+}++function wait (milliseconds: number) {+ return new Promise(resolve => setTimeout(resolve, milliseconds))+}++async function getFileSize (path: string) {+ const stats = await stat(path)++ return stats.size+}++function buildRequestStub (): any {+ return { }+}++export {+ parallelTests,+ isGithubCI,+ areHttpImportTestsDisabled,+ buildAbsoluteFixturePath,+ getFileSize,+ buildRequestStub,+ wait,+ root+}diff --git a/shared/extra-utils/miscs/webtorrent.ts b/shared/extra-utils/miscs/webtorrent.tsnew file mode 100644index 0000000000..82548946d9--- /dev/null+++ b/shared/extra-utils/miscs/webtorrent.ts@@ -0,0 +1,16 @@+import * as WebTorrent from 'webtorrent'++let webtorrent: WebTorrent.Instance++function webtorrentAdd (torrent: string, refreshWebTorrent = false) {+ const WebTorrent = require('webtorrent')++ if (!webtorrent) webtorrent = new WebTorrent()+ if (refreshWebTorrent === true) webtorrent = new WebTorrent()++ return new Promise<WebTorrent.Torrent>(res => webtorrent.add(torrent, res))+}++export {+ webtorrentAdd+}diff --git a/shared/extra-utils/mock-servers/mock-email.ts b/shared/extra-utils/mock-servers/mock-email.tsindex 9fc9a5ad03..ffd62e3253 100644--- a/shared/extra-utils/mock-servers/mock-email.ts+++ b/shared/extra-utils/mock-servers/mock-email.ts@@ -1,6 +1,6 @@import { ChildProcess } from 'child_process'-import { randomInt } from '../../core-utils/miscs/miscs'-import { parallelTests } from '../server/servers'+import { randomInt } from '@shared/core-utils'+import { parallelTests } from '../miscs'const MailDev = require('maildev')diff --git a/shared/extra-utils/requests/check-api-params.ts b/shared/extra-utils/requests/check-api-params.tsindex 7f5ff775cf..7df63b0044 100644--- a/shared/extra-utils/requests/check-api-params.ts+++ b/shared/extra-utils/requests/check-api-params.ts@@ -1,13 +1,12 @@+import { HttpStatusCode } from '@shared/core-utils'import { makeGetRequest } from './requests'-import { immutableAssign } from '../miscs/miscs'-import { HttpStatusCode } from '../../../shared/core-utils/miscs/http-error-codes'function checkBadStartPagination (url: string, path: string, token?: string, query = {}) {return makeGetRequest({url,path,token,- query: immutableAssign(query, { start: 'hello' }),+ query: { ...query, start: 'hello' },statusCodeExpected: HttpStatusCode.BAD_REQUEST_400})}@@ -17,7 +16,7 @@ async function checkBadCountPagination (url: string, path: string, token?: strinurl,path,token,- query: immutableAssign(query, { count: 'hello' }),+ query: { ...query, count: 'hello' },statusCodeExpected: HttpStatusCode.BAD_REQUEST_400})@@ -25,7 +24,7 @@ async function checkBadCountPagination (url: string, path: string, token?: strinurl,path,token,- query: immutableAssign(query, { count: 2000 }),+ query: { ...query, count: 2000 },statusCodeExpected: HttpStatusCode.BAD_REQUEST_400})}@@ -35,7 +34,7 @@ function checkBadSortPagination (url: string, path: string, token?: string, querurl,path,token,- query: immutableAssign(query, { sort: 'hello' }),+ query: { ...query, sort: 'hello' },statusCodeExpected: HttpStatusCode.BAD_REQUEST_400})}diff --git a/shared/extra-utils/requests/requests.ts b/shared/extra-utils/requests/requests.tsindex 3fbaa31d61..f9d112acad 100644--- a/shared/extra-utils/requests/requests.ts+++ b/shared/extra-utils/requests/requests.ts@@ -4,8 +4,8 @@ import { isAbsolute, join } from 'path'import { decode } from 'querystring'import * as request from 'supertest'import { URL } from 'url'-import { HttpStatusCode } from '../../../shared/core-utils/miscs/http-error-codes'-import { buildAbsoluteFixturePath, root } from '../miscs/miscs'+import { HttpStatusCode } from '@shared/core-utils'+import { buildAbsoluteFixturePath, root } from '../miscs/tests'function get4KFileUrl () {return 'https://download.cpy.re/peertube/4k_file.txt'diff --git a/shared/extra-utils/server/directories.ts b/shared/extra-utils/server/directories.tsnew file mode 100644index 0000000000..3cd38a5619--- /dev/null+++ b/shared/extra-utils/server/directories.ts@@ -0,0 +1,34 @@+/* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */++import { expect } from 'chai'+import { pathExists, readdir } from 'fs-extra'+import { join } from 'path'+import { root } from '@server/helpers/core-utils'+import { ServerInfo } from './servers'++async function checkTmpIsEmpty (server: ServerInfo) {+ await checkDirectoryIsEmpty(server, 'tmp', [ 'plugins-global.css', 'hls', 'resumable-uploads' ])++ if (await pathExists(join('test' + server.internalServerNumber, 'tmp', 'hls'))) {+ await checkDirectoryIsEmpty(server, 'tmp/hls')+ }+}++async function checkDirectoryIsEmpty (server: ServerInfo, directory: string, exceptions: string[] = []) {+ const testDirectory = 'test' + server.internalServerNumber++ const directoryPath = join(root(), testDirectory, directory)++ const directoryExists = await pathExists(directoryPath)+ expect(directoryExists).to.be.true++ const files = await readdir(directoryPath)+ const filtered = files.filter(f => exceptions.includes(f) === false)++ expect(filtered).to.have.lengthOf(0)+}++export {+ checkTmpIsEmpty,+ checkDirectoryIsEmpty+}diff --git a/shared/extra-utils/server/index.ts b/shared/extra-utils/server/index.tsindex 03c3b0123b..669b004cd3 100644--- a/shared/extra-utils/server/index.ts+++ b/shared/extra-utils/server/index.ts@@ -1,6 +1,7 @@export * from './config-command'export * from './contact-form-command'export * from './debug-command'+export * from './directories'export * from './follows-command'export * from './follows'export * from './jobs'@@ -8,5 +9,6 @@ export * from './jobs-command'export * from './plugins-command'export * from './plugins'export * from './redundancy-command'+export * from './servers-command'export * from './servers'export * from './stats-command'diff --git a/shared/extra-utils/server/jobs.ts b/shared/extra-utils/server/jobs.tsindex b4b3d52e76..36ef882b39 100644--- a/shared/extra-utils/server/jobs.ts+++ b/shared/extra-utils/server/jobs.ts@@ -1,6 +1,6 @@import { JobState } from '../../models'-import { wait } from '../miscs/miscs'+import { wait } from '../miscs'import { ServerInfo } from './servers'async function waitJobs (serversArg: ServerInfo[] | ServerInfo) {diff --git a/shared/extra-utils/server/plugins-command.ts b/shared/extra-utils/server/plugins-command.tsindex ff49d58c49..5bed51d1a2 100644--- a/shared/extra-utils/server/plugins-command.ts+++ b/shared/extra-utils/server/plugins-command.ts@@ -15,7 +15,6 @@ import {RegisteredServerSettings,ResultList} from '@shared/models'-import { buildServerDirectory } from '../miscs'import { AbstractCommand, OverrideCommandOptions } from '../shared'export class PluginsCommand extends AbstractCommand {@@ -252,6 +251,6 @@ export class PluginsCommand extends AbstractCommand {}private getPackageJSONPath (npmName: string) {- return buildServerDirectory(this.server, join('plugins', 'node_modules', npmName, 'package.json'))+ return this.server.serversCommand.buildDirectory(join('plugins', 'node_modules', npmName, 'package.json'))}}diff --git a/shared/extra-utils/server/servers-command.ts b/shared/extra-utils/server/servers-command.tsnew file mode 100644index 0000000000..9ef68fede6--- /dev/null+++ b/shared/extra-utils/server/servers-command.ts@@ -0,0 +1,81 @@+import { exec } from 'child_process'+import { copy, ensureDir, readFile, remove } from 'fs-extra'+import { join } from 'path'+import { root } from '@server/helpers/core-utils'+import { HttpStatusCode } from '@shared/core-utils'+import { getFileSize } from '@uploadx/core'+import { isGithubCI, wait } from '../miscs'+import { AbstractCommand, OverrideCommandOptions } from '../shared'++export class ServersCommand extends AbstractCommand {++ static flushTests (internalServerNumber: number) {+ return new Promise<void>((res, rej) => {+ const suffix = ` -- ${internalServerNumber}`++ return exec('npm run clean:server:test' + suffix, (err, _stdout, stderr) => {+ if (err || stderr) return rej(err || new Error(stderr))++ return res()+ })+ })+ }++ ping (options: OverrideCommandOptions = {}) {+ return this.getRequestBody({+ ...options,++ path: '/api/v1/ping',+ implicitToken: false,+ defaultExpectedStatus: HttpStatusCode.OK_200+ })+ }++ async cleanupTests () {+ const p: Promise<any>[] = []++ if (isGithubCI()) {+ await ensureDir('artifacts')++ const origin = this.server.serversCommand.buildDirectory('logs/peertube.log')+ const destname = `peertube-${this.server.internalServerNumber}.log`+ console.log('Saving logs %s.', destname)++ await copy(origin, join('artifacts', destname))+ }++ if (this.server.parallel) {+ p.push(ServersCommand.flushTests(this.server.internalServerNumber))+ }++ if (this.server.customConfigFile) {+ p.push(remove(this.server.customConfigFile))+ }++ return p+ }++ async waitUntilLog (str: string, count = 1, strictCount = true) {+ const logfile = this.server.serversCommand.buildDirectory('logs/peertube.log')++ while (true) {+ const buf = await readFile(logfile)++ const matches = buf.toString().match(new RegExp(str, 'g'))+ if (matches && matches.length === count) return+ if (matches && strictCount === false && matches.length >= count) return++ await wait(1000)+ }+ }++ buildDirectory (directory: string) {+ return join(root(), 'test' + this.server.internalServerNumber, directory)+ }++ async getServerFileSize (subPath: string) {+ const path = this.server.serversCommand.buildDirectory(subPath)++ return getFileSize(path)+ }+}diff --git a/shared/extra-utils/server/servers.ts b/shared/extra-utils/server/servers.tsindex e0e49d2c4b..f5dc0326ff 100644--- a/shared/extra-utils/server/servers.ts+++ b/shared/extra-utils/server/servers.ts@@ -1,9 +1,9 @@/* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/no-floating-promises */-import { expect } from 'chai'-import { ChildProcess, exec, fork } from 'child_process'-import { copy, ensureDir, pathExists, readdir, readFile, remove } from 'fs-extra'+import { ChildProcess, fork } from 'child_process'+import { copy, ensureDir } from 'fs-extra'import { join } from 'path'+import { root } from '@server/helpers/core-utils'import { randomInt } from '../../core-utils/miscs/miscs'import { VideoChannel } from '../../models/videos'import { BulkCommand } from '../bulk'@@ -11,11 +11,9 @@ import { CLICommand } from '../cli'import { CustomPagesCommand } from '../custom-pages'import { FeedCommand } from '../feeds'import { LogsCommand } from '../logs'-import { SQLCommand } from '../miscs'-import { buildServerDirectory, getFileSize, isGithubCI, root, wait } from '../miscs/miscs'+import { isGithubCI, parallelTests, SQLCommand } from '../miscs'import { AbusesCommand } from '../moderation'import { OverviewsCommand } from '../overviews'-import { makeGetRequest } from '../requests/requests'import { SearchCommand } from '../search'import { SocketIOCommand } from '../socket'import { AccountsCommand, BlocklistCommand, NotificationsCommand, SubscriptionsCommand } from '../users'@@ -39,6 +37,7 @@ import { FollowsCommand } from './follows-command'import { JobsCommand } from './jobs-command'import { PluginsCommand } from './plugins-command'import { RedundancyCommand } from './redundancy-command'+import { ServersCommand } from './servers-command'import { StatsCommand } from './stats-command'interface ServerInfo {@@ -126,10 +125,7 @@ interface ServerInfo {commentsCommand?: CommentsCommandsqlCommand?: SQLCommandnotificationsCommand?: NotificationsCommand-}--function parallelTests () {- return process.env.MOCHA_PARALLEL === 'true'+ serversCommand?: ServersCommand}function flushAndRunMultipleServers (totalServers: number, configOverride?: Object) {@@ -151,18 +147,6 @@ function flushAndRunMultipleServers (totalServers: number, configOverride?: Obje})}-function flushTests (serverNumber?: number) {- return new Promise<void>((res, rej) => {- const suffix = serverNumber ? ` -- ${serverNumber}` : ''-- return exec('npm run clean:server:test' + suffix, (err, _stdout, stderr) => {- if (err || stderr) return rej(err || new Error(stderr))-- return res()- })- })-}-function randomServer () {const low = 10const high = 10000@@ -189,7 +173,7 @@ async function flushAndRunServer (serverNumber: number, configOverride?: Object,const rtmpPort = parallel ? randomRTMP() : 1936const port = 9000 + internalServerNumber- await flushTests(internalServerNumber)+ await ServersCommand.flushTests(internalServerNumber)const server: ServerInfo = {app: null,@@ -372,6 +356,7 @@ function assignCommands (server: ServerInfo) {server.commentsCommand = new CommentsCommand(server)server.sqlCommand = new SQLCommand(server)server.notificationsCommand = new NotificationsCommand(server)+ server.serversCommand = new ServersCommand(server)}async function reRunServer (server: ServerInfo, configOverride?: any) {@@ -381,28 +366,6 @@ async function reRunServer (server: ServerInfo, configOverride?: any) {return server}-async function checkTmpIsEmpty (server: ServerInfo) {- await checkDirectoryIsEmpty(server, 'tmp', [ 'plugins-global.css', 'hls', 'resumable-uploads' ])-- if (await pathExists(join('test' + server.internalServerNumber, 'tmp', 'hls'))) {- await checkDirectoryIsEmpty(server, 'tmp/hls')- }-}--async function checkDirectoryIsEmpty (server: ServerInfo, directory: string, exceptions: string[] = []) {- const testDirectory = 'test' + server.internalServerNumber-- const directoryPath = join(root(), testDirectory, directory)-- const directoryExists = await pathExists(directoryPath)- expect(directoryExists).to.be.true-- const files = await readdir(directoryPath)- const filtered = files.filter(f => exceptions.includes(f) === false)-- expect(filtered).to.have.lengthOf(0)-}-async function killallServers (servers: ServerInfo[]) {for (const server of servers) {if (!server.app) continue@@ -422,71 +385,22 @@ async function cleanupTests (servers: ServerInfo[]) {await ensureDir('artifacts')}- const p: Promise<any>[] = []+ let p: Promise<any>[] = []for (const server of servers) {- if (isGithubCI()) {- const origin = await buildServerDirectory(server, 'logs/peertube.log')- const destname = `peertube-${server.internalServerNumber}.log`- console.log('Saving logs %s.', destname)-- await copy(origin, join('artifacts', destname))- }-- if (server.parallel) {- p.push(flushTests(server.internalServerNumber))- }-- if (server.customConfigFile) {- p.push(remove(server.customConfigFile))- }+ p = p.concat(server.serversCommand.cleanupTests())}return Promise.all(p)}-async function waitUntilLog (server: ServerInfo, str: string, count = 1, strictCount = true) {- const logfile = buildServerDirectory(server, 'logs/peertube.log')-- while (true) {- const buf = await readFile(logfile)-- const matches = buf.toString().match(new RegExp(str, 'g'))- if (matches && matches.length === count) return- if (matches && strictCount === false && matches.length >= count) return-- await wait(1000)- }-}--async function getServerFileSize (server: ServerInfo, subPath: string) {- const path = buildServerDirectory(server, subPath)-- return getFileSize(path)-}--function makePingRequest (server: ServerInfo) {- return makeGetRequest({- url: server.url,- path: '/api/v1/ping',- statusCodeExpected: 200- })-}-// ---------------------------------------------------------------------------export {- checkDirectoryIsEmpty,- checkTmpIsEmpty,- getServerFileSize,ServerInfo,- parallelTests,cleanupTests,flushAndRunMultipleServers,- flushTests,- makePingRequest,flushAndRunServer,killallServers,reRunServer,- assignCommands,- waitUntilLog+ assignCommands}diff --git a/shared/extra-utils/shared/abstract-command.ts b/shared/extra-utils/shared/abstract-command.tsindex fd2deb57e6..4e61554a29 100644--- a/shared/extra-utils/shared/abstract-command.ts+++ b/shared/extra-utils/shared/abstract-command.ts@@ -1,6 +1,6 @@import { isAbsolute, join } from 'path'import { HttpStatusCode } from '@shared/core-utils'-import { root } from '../miscs/miscs'+import { root } from '../miscs/tests'import {makeDeleteRequest,makeGetRequest,diff --git a/shared/extra-utils/videos/captions-command.ts b/shared/extra-utils/videos/captions-command.tsindex 908b6dae6b..ac3bde7a91 100644--- a/shared/extra-utils/videos/captions-command.ts+++ b/shared/extra-utils/videos/captions-command.ts@@ -1,6 +1,6 @@+import { HttpStatusCode } from '@shared/core-utils'import { ResultList, VideoCaption } from '@shared/models'-import { HttpStatusCode } from '../../core-utils/miscs/http-error-codes'-import { buildAbsoluteFixturePath } from '../miscs/miscs'+import { buildAbsoluteFixturePath } from '../miscs'import { AbstractCommand, OverrideCommandOptions } from '../shared'export class CaptionsCommand extends AbstractCommand {diff --git a/shared/extra-utils/videos/live-command.ts b/shared/extra-utils/videos/live-command.tsindex 4f03c91278..a494e60fa3 100644--- a/shared/extra-utils/videos/live-command.ts+++ b/shared/extra-utils/videos/live-command.ts@@ -5,9 +5,8 @@ import { omit } from 'lodash'import { join } from 'path'import { LiveVideo, LiveVideoCreate, LiveVideoUpdate, VideoCreateResult, VideoDetails, VideoState } from '@shared/models'import { HttpStatusCode } from '../../core-utils/miscs/http-error-codes'-import { buildServerDirectory, wait } from '../miscs/miscs'+import { wait } from '../miscs'import { unwrapBody } from '../requests'-import { waitUntilLog } from '../server/servers'import { AbstractCommand, OverrideCommandOptions } from '../shared'import { sendRTMPStream, testFfmpegStreamError } from './live'import { getVideoWithToken } from './videos'@@ -116,7 +115,7 @@ export class LiveCommand extends AbstractCommand {const { resolution, segment, videoUUID } = optionsconst segmentName = `${resolution}-00000${segment}.ts`- return waitUntilLog(this.server, `${videoUUID}/${segmentName}`, 2, false)+ return this.server.serversCommand.waitUntilLog(`${videoUUID}/${segmentName}`, 2, false)}async waitUntilSaved (options: OverrideCommandOptions & {@@ -135,7 +134,7 @@ export class LiveCommand extends AbstractCommand {async countPlaylists (options: OverrideCommandOptions & {videoUUID: string}) {- const basePath = buildServerDirectory(this.server, 'streaming-playlists')+ const basePath = this.server.serversCommand.buildDirectory('streaming-playlists')const hlsPath = join(basePath, 'hls', options.videoUUID)const files = await readdir(hlsPath)diff --git a/shared/extra-utils/videos/live.ts b/shared/extra-utils/videos/live.tsindex 92cb9104c4..0efcc28831 100644--- a/shared/extra-utils/videos/live.ts+++ b/shared/extra-utils/videos/live.ts@@ -4,7 +4,7 @@ import { expect } from 'chai'import * as ffmpeg from 'fluent-ffmpeg'import { pathExists, readdir } from 'fs-extra'import { join } from 'path'-import { buildAbsoluteFixturePath, buildServerDirectory, wait } from '../miscs/miscs'+import { buildAbsoluteFixturePath, wait } from '../miscs'import { ServerInfo } from '../server/servers'function sendRTMPStream (rtmpBaseUrl: string, streamKey: string, fixtureName = 'video_short.mp4') {@@ -77,7 +77,7 @@ async function waitUntilLivePublishedOnAllServers (servers: ServerInfo[], videoI}async function checkLiveCleanup (server: ServerInfo, videoUUID: string, resolutions: number[] = []) {- const basePath = buildServerDirectory(server, 'streaming-playlists')+ const basePath = server.serversCommand.buildDirectory('streaming-playlists')const hlsPath = join(basePath, 'hls', videoUUID)if (resolutions.length === 0) {diff --git a/shared/extra-utils/videos/playlists.ts b/shared/extra-utils/videos/playlists.tsindex 023333c87f..3dde52bb94 100644--- a/shared/extra-utils/videos/playlists.ts+++ b/shared/extra-utils/videos/playlists.ts@@ -1,7 +1,7 @@import { expect } from 'chai'import { readdir } from 'fs-extra'import { join } from 'path'-import { root } from '../'+import { root } from '../miscs'async function checkPlaylistFilesWereRemoved (playlistUUID: string,diff --git a/shared/extra-utils/videos/videos.ts b/shared/extra-utils/videos/videos.tsindex 920c930727..5dd71ce8bf 100644--- a/shared/extra-utils/videos/videos.ts+++ b/shared/extra-utils/videos/videos.ts@@ -13,15 +13,7 @@ import { HttpStatusCode } from '@shared/core-utils'import { BooleanBothQuery, VideosCommonQuery } from '@shared/models'import { loadLanguages, VIDEO_CATEGORIES, VIDEO_LANGUAGES, VIDEO_LICENCES, VIDEO_PRIVACIES } from '../../../server/initializers/constants'import { VideoDetails, VideoPrivacy } from '../../models/videos'-import {- buildAbsoluteFixturePath,- buildServerDirectory,- dateIsValid,- immutableAssign,- testImage,- wait,- webtorrentAdd-} from '../miscs/miscs'+import { buildAbsoluteFixturePath, dateIsValid, testImage, wait, webtorrentAdd } from '../miscs'import { makeGetRequest, makePutBodyRequest, makeRawRequest, makeUploadRequest } from '../requests/requests'import { waitJobs } from '../server/jobs'import { ServerInfo } from '../server/servers'@@ -165,7 +157,7 @@ function getVideosListWithToken (url: string, token: string, query: { nsfw?: Booreturn request(url).get(path).set('Authorization', 'Bearer ' + token)- .query(immutableAssign(query, { sort: 'name' }))+ .query({ sort: 'name', ...query }).set('Accept', 'application/json').expect(HttpStatusCode.OK_200).expect('Content-Type', /json/)@@ -228,11 +220,7 @@ function getAccountVideos (return makeGetRequest({url,path,- query: immutableAssign(query, {- start,- count,- sort- }),+ query: { ...query, start, count, sort },token: accessToken,statusCodeExpected: HttpStatusCode.OK_200})@@ -252,11 +240,7 @@ function getVideoChannelVideos (return makeGetRequest({url,path,- query: immutableAssign(query, {- start,- count,- sort- }),+ query: { ...query, start, count, sort },token: accessToken,statusCodeExpected: HttpStatusCode.OK_200})@@ -320,7 +304,7 @@ async function removeAllVideos (server: ServerInfo) {async function checkVideoFilesWereRemoved (videoUUID: string,- serverNumber: number,+ server: ServerInfo,directories = ['redundancy','videos',@@ -333,7 +317,7 @@ async function checkVideoFilesWereRemoved (]) {for (const directory of directories) {- const directoryPath = buildServerDirectory({ internalServerNumber: serverNumber }, directory)+ const directoryPath = server.serversCommand.buildDirectory(directory)const directoryExists = await pathExists(directoryPath)if (directoryExists === false) continue@@ -607,7 +591,7 @@ function rateVideo (url: string, accessToken: string, id: number | string, ratinfunction parseTorrentVideo (server: ServerInfo, videoUUID: string, resolution: number) {return new Promise<any>((res, rej) => {const torrentName = videoUUID + '-' + resolution + '.torrent'- const torrentPath = buildServerDirectory(server, join('torrents', torrentName))+ const torrentPath = server.serversCommand.buildDirectory(join('torrents', torrentName))readFile(torrentPath, (err, data) => {if (err) return rej(err)