From 65e6e2602c0d5521f3a6740f7469bb92830ecb53 Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Wed, 7 Jul 2021 11:51:09 +0200 Subject: Introduce config command --- server/tests/api/check-params/video-imports.ts | 53 +++++++++++++------------- 1 file changed, 27 insertions(+), 26 deletions(-) (limited to 'server/tests/api/check-params/video-imports.ts') diff --git a/server/tests/api/check-params/video-imports.ts b/server/tests/api/check-params/video-imports.ts index a27b624d0..dae3860ef 100644 --- a/server/tests/api/check-params/video-imports.ts +++ b/server/tests/api/check-params/video-imports.ts @@ -2,9 +2,12 @@ import 'mocha' import { omit } from 'lodash' -import { HttpStatusCode } from '../../../../shared/core-utils/miscs/http-error-codes' +import { HttpStatusCode } from '@shared/core-utils' import { buildAbsoluteFixturePath, + checkBadCountPagination, + checkBadSortPagination, + checkBadStartPagination, cleanupTests, createUser, flushAndRunServer, @@ -15,16 +18,10 @@ import { makeUploadRequest, ServerInfo, setAccessTokensToServers, - updateCustomSubConfig, userLogin -} from '../../../../shared/extra-utils' -import { - checkBadCountPagination, - checkBadSortPagination, - checkBadStartPagination -} from '../../../../shared/extra-utils/requests/check-api-params' -import { getGoodVideoUrl, getMagnetURI } from '../../../../shared/extra-utils/videos/video-imports' -import { VideoPrivacy } from '../../../../shared/models/videos/video-privacy.enum' +} from '@shared/extra-utils' +import { getGoodVideoUrl, getMagnetURI } from '@shared/extra-utils/videos/video-imports' +import { VideoPrivacy } from '@shared/models' describe('Test video imports API validator', function () { const path = '/api/v1/videos/imports' @@ -263,14 +260,16 @@ describe('Test video imports API validator', function () { }) it('Should forbid to import http videos', async function () { - await updateCustomSubConfig(server.url, server.accessToken, { - import: { - videos: { - http: { - enabled: false - }, - torrent: { - enabled: true + await server.configCommand.updateCustomSubConfig({ + newConfig: { + import: { + videos: { + http: { + enabled: false + }, + torrent: { + enabled: true + } } } } @@ -286,14 +285,16 @@ describe('Test video imports API validator', function () { }) it('Should forbid to import torrent videos', async function () { - await updateCustomSubConfig(server.url, server.accessToken, { - import: { - videos: { - http: { - enabled: true - }, - torrent: { - enabled: false + await server.configCommand.updateCustomSubConfig({ + newConfig: { + import: { + videos: { + http: { + enabled: true + }, + torrent: { + enabled: false + } } } } -- cgit v1.2.3 From 6910f20f114b5bd020258a3a9a3f2117819a60c2 Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Thu, 8 Jul 2021 16:49:51 +0200 Subject: Introduce import command --- server/tests/api/check-params/video-imports.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'server/tests/api/check-params/video-imports.ts') diff --git a/server/tests/api/check-params/video-imports.ts b/server/tests/api/check-params/video-imports.ts index dae3860ef..ea473191e 100644 --- a/server/tests/api/check-params/video-imports.ts +++ b/server/tests/api/check-params/video-imports.ts @@ -13,6 +13,7 @@ import { flushAndRunServer, getMyUserInformation, immutableAssign, + ImportsCommand, makeGetRequest, makePostBodyRequest, makeUploadRequest, @@ -20,7 +21,6 @@ import { setAccessTokensToServers, userLogin } from '@shared/extra-utils' -import { getGoodVideoUrl, getMagnetURI } from '@shared/extra-utils/videos/video-imports' import { VideoPrivacy } from '@shared/models' describe('Test video imports API validator', function () { @@ -74,7 +74,7 @@ describe('Test video imports API validator', function () { before(function () { baseCorrectParams = { - targetUrl: getGoodVideoUrl(), + targetUrl: ImportsCommand.getGoodVideoUrl(), name: 'my super name', category: 5, licence: 1, @@ -301,7 +301,7 @@ describe('Test video imports API validator', function () { }) let fields = omit(baseCorrectParams, 'targetUrl') - fields = immutableAssign(fields, { magnetUri: getMagnetURI() }) + fields = immutableAssign(fields, { magnetUri: ImportsCommand.getMagnetURI() }) await makePostBodyRequest({ url: server.url, -- cgit v1.2.3 From 6c5065a011b099618681a37bd77eaa7bd3db752e Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Tue, 13 Jul 2021 09:43:59 +0200 Subject: Introduce server commands --- server/tests/api/check-params/video-imports.ts | 29 +++++++++++++------------- 1 file changed, 14 insertions(+), 15 deletions(-) (limited to 'server/tests/api/check-params/video-imports.ts') diff --git a/server/tests/api/check-params/video-imports.ts b/server/tests/api/check-params/video-imports.ts index ea473191e..2cc124cc1 100644 --- a/server/tests/api/check-params/video-imports.ts +++ b/server/tests/api/check-params/video-imports.ts @@ -12,7 +12,6 @@ import { createUser, flushAndRunServer, getMyUserInformation, - immutableAssign, ImportsCommand, makeGetRequest, makePostBodyRequest, @@ -108,43 +107,43 @@ describe('Test video imports API validator', function () { }) it('Should fail with a bad target url', async function () { - const fields = immutableAssign(baseCorrectParams, { targetUrl: 'htt://hello' }) + const fields = { ...baseCorrectParams, targetUrl: 'htt://hello' } await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields }) }) it('Should fail with a long name', async function () { - const fields = immutableAssign(baseCorrectParams, { name: 'super'.repeat(65) }) + const fields = { ...baseCorrectParams, name: 'super'.repeat(65) } await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields }) }) it('Should fail with a bad category', async function () { - const fields = immutableAssign(baseCorrectParams, { category: 125 }) + const fields = { ...baseCorrectParams, category: 125 } await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields }) }) it('Should fail with a bad licence', async function () { - const fields = immutableAssign(baseCorrectParams, { licence: 125 }) + const fields = { ...baseCorrectParams, licence: 125 } await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields }) }) it('Should fail with a bad language', async function () { - const fields = immutableAssign(baseCorrectParams, { language: 'a'.repeat(15) }) + const fields = { ...baseCorrectParams, language: 'a'.repeat(15) } await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields }) }) it('Should fail with a long description', async function () { - const fields = immutableAssign(baseCorrectParams, { description: 'super'.repeat(2500) }) + const fields = { ...baseCorrectParams, description: 'super'.repeat(2500) } await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields }) }) it('Should fail with a long support text', async function () { - const fields = immutableAssign(baseCorrectParams, { support: 'super'.repeat(201) }) + const fields = { ...baseCorrectParams, support: 'super'.repeat(201) } await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields }) }) @@ -156,7 +155,7 @@ describe('Test video imports API validator', function () { }) it('Should fail with a bad channel', async function () { - const fields = immutableAssign(baseCorrectParams, { channelId: 545454 }) + const fields = { ...baseCorrectParams, channelId: 545454 } await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields }) }) @@ -172,25 +171,25 @@ describe('Test video imports API validator', function () { const res = await getMyUserInformation(server.url, accessTokenUser) const customChannelId = res.body.videoChannels[0].id - const fields = immutableAssign(baseCorrectParams, { channelId: customChannelId }) + const fields = { ...baseCorrectParams, channelId: customChannelId } await makePostBodyRequest({ url: server.url, path, token: userAccessToken, fields }) }) it('Should fail with too many tags', async function () { - const fields = immutableAssign(baseCorrectParams, { tags: [ 'tag1', 'tag2', 'tag3', 'tag4', 'tag5', 'tag6' ] }) + const fields = { ...baseCorrectParams, tags: [ 'tag1', 'tag2', 'tag3', 'tag4', 'tag5', 'tag6' ] } await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields }) }) it('Should fail with a tag length too low', async function () { - const fields = immutableAssign(baseCorrectParams, { tags: [ 'tag1', 't' ] }) + const fields = { ...baseCorrectParams, tags: [ 'tag1', 't' ] } await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields }) }) it('Should fail with a tag length too big', async function () { - const fields = immutableAssign(baseCorrectParams, { tags: [ 'tag1', 'my_super_tag_too_long_long_long_long_long_long' ] }) + const fields = { ...baseCorrectParams, tags: [ 'tag1', 'my_super_tag_too_long_long_long_long_long_long' ] } await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields }) }) @@ -242,7 +241,7 @@ describe('Test video imports API validator', function () { it('Should fail with an invalid magnet URI', async function () { let fields = omit(baseCorrectParams, 'targetUrl') - fields = immutableAssign(fields, { magnetUri: 'blabla' }) + fields = { ...fields, magnetUri: 'blabla' } await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields }) }) @@ -301,7 +300,7 @@ describe('Test video imports API validator', function () { }) let fields = omit(baseCorrectParams, 'targetUrl') - fields = immutableAssign(fields, { magnetUri: ImportsCommand.getMagnetURI() }) + fields = { ...fields, magnetUri: ImportsCommand.getMagnetURI() } await makePostBodyRequest({ url: server.url, -- cgit v1.2.3 From 41d1d075011174e73dccb74006181a92a618d7b4 Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Tue, 13 Jul 2021 11:05:15 +0200 Subject: Introduce login command --- server/tests/api/check-params/video-imports.ts | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) (limited to 'server/tests/api/check-params/video-imports.ts') diff --git a/server/tests/api/check-params/video-imports.ts b/server/tests/api/check-params/video-imports.ts index 2cc124cc1..51260affa 100644 --- a/server/tests/api/check-params/video-imports.ts +++ b/server/tests/api/check-params/video-imports.ts @@ -17,8 +17,7 @@ import { makePostBodyRequest, makeUploadRequest, ServerInfo, - setAccessTokensToServers, - userLogin + setAccessTokensToServers } from '@shared/extra-utils' import { VideoPrivacy } from '@shared/models' @@ -40,7 +39,7 @@ describe('Test video imports API validator', function () { const username = 'user1' const password = 'my super password' await createUser({ url: server.url, accessToken: server.accessToken, username: username, password: password }) - userAccessToken = await userLogin(server, { username, password }) + userAccessToken = await server.loginCommand.getAccessToken({ username, password }) { const res = await getMyUserInformation(server.url, server.accessToken) @@ -167,7 +166,7 @@ describe('Test video imports API validator', function () { } await createUser({ url: server.url, accessToken: server.accessToken, username: user.username, password: user.password }) - const accessTokenUser = await userLogin(server, user) + const accessTokenUser = await server.loginCommand.getAccessToken(user) const res = await getMyUserInformation(server.url, accessTokenUser) const customChannelId = res.body.videoChannels[0].id -- cgit v1.2.3 From 7926c5f9b3ffcabb1ffb0dcfa5e48b8e0b88fbc0 Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Tue, 13 Jul 2021 14:23:01 +0200 Subject: Introduce user command --- server/tests/api/check-params/video-imports.ts | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) (limited to 'server/tests/api/check-params/video-imports.ts') diff --git a/server/tests/api/check-params/video-imports.ts b/server/tests/api/check-params/video-imports.ts index 51260affa..d09e473de 100644 --- a/server/tests/api/check-params/video-imports.ts +++ b/server/tests/api/check-params/video-imports.ts @@ -9,9 +9,7 @@ import { checkBadSortPagination, checkBadStartPagination, cleanupTests, - createUser, flushAndRunServer, - getMyUserInformation, ImportsCommand, makeGetRequest, makePostBodyRequest, @@ -38,12 +36,12 @@ describe('Test video imports API validator', function () { const username = 'user1' const password = 'my super password' - await createUser({ url: server.url, accessToken: server.accessToken, username: username, password: password }) + await server.usersCommand.create({ username: username, password: password }) userAccessToken = await server.loginCommand.getAccessToken({ username, password }) { - const res = await getMyUserInformation(server.url, server.accessToken) - channelId = res.body.videoChannels[0].id + const { videoChannels } = await server.usersCommand.getMyInfo() + channelId = videoChannels[0].id } }) @@ -164,11 +162,11 @@ describe('Test video imports API validator', function () { username: 'fake', password: 'fake_password' } - await createUser({ url: server.url, accessToken: server.accessToken, username: user.username, password: user.password }) + await server.usersCommand.create({ username: user.username, password: user.password }) const accessTokenUser = await server.loginCommand.getAccessToken(user) - const res = await getMyUserInformation(server.url, accessTokenUser) - const customChannelId = res.body.videoChannels[0].id + const { videoChannels } = await server.usersCommand.getMyInfo({ token: accessTokenUser }) + const customChannelId = videoChannels[0].id const fields = { ...baseCorrectParams, channelId: customChannelId } -- cgit v1.2.3 From 89d241a79c262b9775c233b73cff080043ebb5e6 Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Fri, 16 Jul 2021 09:04:35 +0200 Subject: Shorter server command names --- server/tests/api/check-params/video-imports.ts | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) (limited to 'server/tests/api/check-params/video-imports.ts') diff --git a/server/tests/api/check-params/video-imports.ts b/server/tests/api/check-params/video-imports.ts index d09e473de..1a6b6075f 100644 --- a/server/tests/api/check-params/video-imports.ts +++ b/server/tests/api/check-params/video-imports.ts @@ -36,11 +36,11 @@ describe('Test video imports API validator', function () { const username = 'user1' const password = 'my super password' - await server.usersCommand.create({ username: username, password: password }) - userAccessToken = await server.loginCommand.getAccessToken({ username, password }) + await server.users.create({ username: username, password: password }) + userAccessToken = await server.login.getAccessToken({ username, password }) { - const { videoChannels } = await server.usersCommand.getMyInfo() + const { videoChannels } = await server.users.getMyInfo() channelId = videoChannels[0].id } }) @@ -162,10 +162,10 @@ describe('Test video imports API validator', function () { username: 'fake', password: 'fake_password' } - await server.usersCommand.create({ username: user.username, password: user.password }) + await server.users.create({ username: user.username, password: user.password }) - const accessTokenUser = await server.loginCommand.getAccessToken(user) - const { videoChannels } = await server.usersCommand.getMyInfo({ token: accessTokenUser }) + const accessTokenUser = await server.login.getAccessToken(user) + const { videoChannels } = await server.users.getMyInfo({ token: accessTokenUser }) const customChannelId = videoChannels[0].id const fields = { ...baseCorrectParams, channelId: customChannelId } @@ -256,7 +256,7 @@ describe('Test video imports API validator', function () { }) it('Should forbid to import http videos', async function () { - await server.configCommand.updateCustomSubConfig({ + await server.config.updateCustomSubConfig({ newConfig: { import: { videos: { @@ -281,7 +281,7 @@ describe('Test video imports API validator', function () { }) it('Should forbid to import torrent videos', async function () { - await server.configCommand.updateCustomSubConfig({ + await server.config.updateCustomSubConfig({ newConfig: { import: { videos: { -- cgit v1.2.3 From 254d3579f5338f5fd775c17d15cdfc37078bcfb4 Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Fri, 16 Jul 2021 09:47:51 +0200 Subject: Use an object to represent a server --- server/tests/api/check-params/video-imports.ts | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'server/tests/api/check-params/video-imports.ts') diff --git a/server/tests/api/check-params/video-imports.ts b/server/tests/api/check-params/video-imports.ts index 1a6b6075f..627f0c7ad 100644 --- a/server/tests/api/check-params/video-imports.ts +++ b/server/tests/api/check-params/video-imports.ts @@ -9,19 +9,19 @@ import { checkBadSortPagination, checkBadStartPagination, cleanupTests, - flushAndRunServer, + createSingleServer, ImportsCommand, makeGetRequest, makePostBodyRequest, makeUploadRequest, - ServerInfo, + PeerTubeServer, setAccessTokensToServers } from '@shared/extra-utils' import { VideoPrivacy } from '@shared/models' describe('Test video imports API validator', function () { const path = '/api/v1/videos/imports' - let server: ServerInfo + let server: PeerTubeServer let userAccessToken = '' let channelId: number @@ -30,7 +30,7 @@ describe('Test video imports API validator', function () { before(async function () { this.timeout(30000) - server = await flushAndRunServer(1) + server = await createSingleServer(1) await setAccessTokensToServers([ server ]) -- cgit v1.2.3 From 59bbcced37005dd511daca9bd58ae2998cb931b1 Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Fri, 16 Jul 2021 10:19:16 +0200 Subject: Centralize test URLs --- server/tests/api/check-params/video-imports.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'server/tests/api/check-params/video-imports.ts') diff --git a/server/tests/api/check-params/video-imports.ts b/server/tests/api/check-params/video-imports.ts index 627f0c7ad..0209275ac 100644 --- a/server/tests/api/check-params/video-imports.ts +++ b/server/tests/api/check-params/video-imports.ts @@ -10,7 +10,7 @@ import { checkBadStartPagination, cleanupTests, createSingleServer, - ImportsCommand, + FIXTURE_URLS, makeGetRequest, makePostBodyRequest, makeUploadRequest, @@ -70,7 +70,7 @@ describe('Test video imports API validator', function () { before(function () { baseCorrectParams = { - targetUrl: ImportsCommand.getGoodVideoUrl(), + targetUrl: FIXTURE_URLS.goodVideo, name: 'my super name', category: 5, licence: 1, @@ -297,7 +297,7 @@ describe('Test video imports API validator', function () { }) let fields = omit(baseCorrectParams, 'targetUrl') - fields = { ...fields, magnetUri: ImportsCommand.getMagnetURI() } + fields = { ...fields, magnetUri: FIXTURE_URLS.magnet } await makePostBodyRequest({ url: server.url, -- cgit v1.2.3 From c0e8b12e7fd554ba4d2ceb0c4900804c6a4c63ea Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Fri, 16 Jul 2021 10:42:24 +0200 Subject: Refactor requests --- server/tests/api/check-params/video-imports.ts | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) (limited to 'server/tests/api/check-params/video-imports.ts') diff --git a/server/tests/api/check-params/video-imports.ts b/server/tests/api/check-params/video-imports.ts index 0209275ac..957556c9b 100644 --- a/server/tests/api/check-params/video-imports.ts +++ b/server/tests/api/check-params/video-imports.ts @@ -2,7 +2,7 @@ import 'mocha' import { omit } from 'lodash' -import { HttpStatusCode } from '@shared/core-utils' +import { HttpStatusCode } from '@shared/models' import { buildAbsoluteFixturePath, checkBadCountPagination, @@ -61,7 +61,7 @@ describe('Test video imports API validator', function () { }) it('Should success with the correct parameters', async function () { - await makeGetRequest({ url: server.url, path: myPath, statusCodeExpected: HttpStatusCode.OK_200, token: server.accessToken }) + await makeGetRequest({ url: server.url, path: myPath, expectedStatus: HttpStatusCode.OK_200, token: server.accessToken }) }) }) @@ -99,7 +99,7 @@ describe('Test video imports API validator', function () { path, token: server.accessToken, fields, - statusCodeExpected: HttpStatusCode.BAD_REQUEST_400 + expectedStatus: HttpStatusCode.BAD_REQUEST_400 }) }) @@ -251,7 +251,7 @@ describe('Test video imports API validator', function () { path, token: server.accessToken, fields: baseCorrectParams, - statusCodeExpected: HttpStatusCode.OK_200 + expectedStatus: HttpStatusCode.OK_200 }) }) @@ -276,7 +276,7 @@ describe('Test video imports API validator', function () { path, token: server.accessToken, fields: baseCorrectParams, - statusCodeExpected: HttpStatusCode.CONFLICT_409 + expectedStatus: HttpStatusCode.CONFLICT_409 }) }) @@ -304,7 +304,7 @@ describe('Test video imports API validator', function () { path, token: server.accessToken, fields, - statusCodeExpected: HttpStatusCode.CONFLICT_409 + expectedStatus: HttpStatusCode.CONFLICT_409 }) fields = omit(fields, 'magnetUri') @@ -318,7 +318,7 @@ describe('Test video imports API validator', function () { token: server.accessToken, fields, attaches, - statusCodeExpected: HttpStatusCode.CONFLICT_409 + expectedStatus: HttpStatusCode.CONFLICT_409 }) }) }) -- cgit v1.2.3 From 4c7e60bc17ee5830399bac4aa273356903421b4c Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Fri, 16 Jul 2021 14:27:30 +0200 Subject: Reorganize imports --- server/tests/api/check-params/video-imports.ts | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'server/tests/api/check-params/video-imports.ts') diff --git a/server/tests/api/check-params/video-imports.ts b/server/tests/api/check-params/video-imports.ts index 957556c9b..d6d745488 100644 --- a/server/tests/api/check-params/video-imports.ts +++ b/server/tests/api/check-params/video-imports.ts @@ -2,7 +2,6 @@ import 'mocha' import { omit } from 'lodash' -import { HttpStatusCode } from '@shared/models' import { buildAbsoluteFixturePath, checkBadCountPagination, @@ -17,7 +16,7 @@ import { PeerTubeServer, setAccessTokensToServers } from '@shared/extra-utils' -import { VideoPrivacy } from '@shared/models' +import { HttpStatusCode, VideoPrivacy } from '@shared/models' describe('Test video imports API validator', function () { const path = '/api/v1/videos/imports' -- cgit v1.2.3