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/videos/video-change-ownership.ts | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) (limited to 'server/tests/api/videos/video-change-ownership.ts') diff --git a/server/tests/api/videos/video-change-ownership.ts b/server/tests/api/videos/video-change-ownership.ts index a3384851b..89dba14b1 100644 --- a/server/tests/api/videos/video-change-ownership.ts +++ b/server/tests/api/videos/video-change-ownership.ts @@ -20,7 +20,6 @@ import { ServerInfo, setAccessTokensToServers, setDefaultVideoChannel, - updateCustomSubConfig, uploadVideo, userLogin } from '../../../../shared/extra-utils' @@ -58,12 +57,14 @@ describe('Test video change ownership - nominal', function () { await setAccessTokensToServers(servers) await setDefaultVideoChannel(servers) - await updateCustomSubConfig(servers[0].url, servers[0].accessToken, { - transcoding: { - enabled: false - }, - live: { - enabled: true + await servers[0].configCommand.updateCustomSubConfig({ + newConfig: { + transcoding: { + enabled: false + }, + live: { + enabled: true + } } }) -- cgit v1.2.3 From 4f2199144e428c16460750305f737b890c1ac322 Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Thu, 8 Jul 2021 10:18:40 +0200 Subject: Introduce live command --- server/tests/api/videos/video-change-ownership.ts | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) (limited to 'server/tests/api/videos/video-change-ownership.ts') diff --git a/server/tests/api/videos/video-change-ownership.ts b/server/tests/api/videos/video-change-ownership.ts index 89dba14b1..88e4d51a2 100644 --- a/server/tests/api/videos/video-change-ownership.ts +++ b/server/tests/api/videos/video-change-ownership.ts @@ -7,7 +7,6 @@ import { acceptChangeOwnership, changeVideoOwnership, cleanupTests, - createLive, createUser, doubleFollow, flushAndRunMultipleServers, @@ -112,9 +111,9 @@ describe('Test video change ownership - nominal', function () { { const attributes = { name: 'live', channelId: firstUserChannelId, privacy: VideoPrivacy.PUBLIC } - const res = await createLive(servers[0].url, firstUserAccessToken, attributes) + const video = await servers[0].liveCommand.createLive({ token: firstUserAccessToken, fields: attributes }) - liveId = res.body.video.id + liveId = video.id } await doubleFollow(servers[0], servers[1]) -- cgit v1.2.3 From 04aed76711909507e74905bde3a7fa024d3585c9 Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Thu, 8 Jul 2021 10:25:50 +0200 Subject: Shorter live methods --- server/tests/api/videos/video-change-ownership.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'server/tests/api/videos/video-change-ownership.ts') diff --git a/server/tests/api/videos/video-change-ownership.ts b/server/tests/api/videos/video-change-ownership.ts index 88e4d51a2..3c33cf015 100644 --- a/server/tests/api/videos/video-change-ownership.ts +++ b/server/tests/api/videos/video-change-ownership.ts @@ -111,7 +111,7 @@ describe('Test video change ownership - nominal', function () { { const attributes = { name: 'live', channelId: firstUserChannelId, privacy: VideoPrivacy.PUBLIC } - const video = await servers[0].liveCommand.createLive({ token: firstUserAccessToken, fields: attributes }) + const video = await servers[0].liveCommand.create({ token: firstUserAccessToken, fields: attributes }) liveId = video.id } -- cgit v1.2.3 From 72cbfc5695ec5ebdb9721d3648218f63feeaeac5 Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Thu, 8 Jul 2021 13:56:04 +0200 Subject: Introduce change ownership command --- server/tests/api/videos/video-change-ownership.ts | 185 ++++++++++++---------- 1 file changed, 100 insertions(+), 85 deletions(-) (limited to 'server/tests/api/videos/video-change-ownership.ts') diff --git a/server/tests/api/videos/video-change-ownership.ts b/server/tests/api/videos/video-change-ownership.ts index 3c33cf015..1b81fe047 100644 --- a/server/tests/api/videos/video-change-ownership.ts +++ b/server/tests/api/videos/video-change-ownership.ts @@ -4,8 +4,7 @@ import 'mocha' import * as chai from 'chai' import { HttpStatusCode } from '../../../../shared/core-utils/miscs/http-error-codes' import { - acceptChangeOwnership, - changeVideoOwnership, + ChangeOwnershipCommand, cleanupTests, createUser, doubleFollow, @@ -13,9 +12,7 @@ import { flushAndRunServer, getMyUserInformation, getVideo, - getVideoChangeOwnershipList, getVideosList, - refuseChangeOwnership, ServerInfo, setAccessTokensToServers, setDefaultVideoChannel, @@ -39,16 +36,18 @@ describe('Test video change ownership - nominal', function () { password: 'My other password' } - let firstUserAccessToken = '' + let firstUserToken = '' let firstUserChannelId: number - let secondUserAccessToken = '' + let secondUserToken = '' let secondUserChannelId: number - let lastRequestChangeOwnershipId = '' + let lastRequestId: number let liveId: number + let command: ChangeOwnershipCommand + before(async function () { this.timeout(50000) @@ -83,17 +82,17 @@ describe('Test video change ownership - nominal', function () { videoQuota: videoQuota }) - firstUserAccessToken = await userLogin(servers[0], firstUser) - secondUserAccessToken = await userLogin(servers[0], secondUser) + firstUserToken = await userLogin(servers[0], firstUser) + secondUserToken = await userLogin(servers[0], secondUser) { - const res = await getMyUserInformation(servers[0].url, firstUserAccessToken) + const res = await getMyUserInformation(servers[0].url, firstUserToken) const firstUserInformation: User = res.body firstUserChannelId = firstUserInformation.videoChannels[0].id } { - const res = await getMyUserInformation(servers[0].url, secondUserAccessToken) + const res = await getMyUserInformation(servers[0].url, secondUserToken) const secondUserInformation: User = res.body secondUserChannelId = secondUserInformation.videoChannels[0].id } @@ -103,7 +102,7 @@ describe('Test video change ownership - nominal', function () { name: 'my super name', description: 'my super description' } - const res = await uploadVideo(servers[0].url, firstUserAccessToken, videoAttributes) + const res = await uploadVideo(servers[0].url, firstUserToken, videoAttributes) const resVideo = await getVideo(servers[0].url, res.body.video.id) servers[0].video = resVideo.body @@ -111,116 +110,129 @@ describe('Test video change ownership - nominal', function () { { const attributes = { name: 'live', channelId: firstUserChannelId, privacy: VideoPrivacy.PUBLIC } - const video = await servers[0].liveCommand.create({ token: firstUserAccessToken, fields: attributes }) + const video = await servers[0].liveCommand.create({ token: firstUserToken, fields: attributes }) liveId = video.id } + command = servers[0].changeOwnershipCommand + await doubleFollow(servers[0], servers[1]) }) it('Should not have video change ownership', async function () { - const resFirstUser = await getVideoChangeOwnershipList(servers[0].url, firstUserAccessToken) + { + const body = await command.list({ token: firstUserToken }) - expect(resFirstUser.body.total).to.equal(0) - expect(resFirstUser.body.data).to.be.an('array') - expect(resFirstUser.body.data.length).to.equal(0) + expect(body.total).to.equal(0) + expect(body.data).to.be.an('array') + expect(body.data.length).to.equal(0) + } - const resSecondUser = await getVideoChangeOwnershipList(servers[0].url, secondUserAccessToken) + { + const body = await command.list({ token: secondUserToken }) - expect(resSecondUser.body.total).to.equal(0) - expect(resSecondUser.body.data).to.be.an('array') - expect(resSecondUser.body.data.length).to.equal(0) + expect(body.total).to.equal(0) + expect(body.data).to.be.an('array') + expect(body.data.length).to.equal(0) + } }) it('Should send a request to change ownership of a video', async function () { this.timeout(15000) - await changeVideoOwnership(servers[0].url, firstUserAccessToken, servers[0].video.id, secondUser.username) + await command.create({ token: firstUserToken, videoId: servers[0].video.id, username: secondUser.username }) }) it('Should only return a request to change ownership for the second user', async function () { - const resFirstUser = await getVideoChangeOwnershipList(servers[0].url, firstUserAccessToken) + { + const body = await command.list({ token: firstUserToken }) - expect(resFirstUser.body.total).to.equal(0) - expect(resFirstUser.body.data).to.be.an('array') - expect(resFirstUser.body.data.length).to.equal(0) + expect(body.total).to.equal(0) + expect(body.data).to.be.an('array') + expect(body.data.length).to.equal(0) + } - const resSecondUser = await getVideoChangeOwnershipList(servers[0].url, secondUserAccessToken) + { + const body = await command.list({ token: secondUserToken }) - expect(resSecondUser.body.total).to.equal(1) - expect(resSecondUser.body.data).to.be.an('array') - expect(resSecondUser.body.data.length).to.equal(1) + expect(body.total).to.equal(1) + expect(body.data).to.be.an('array') + expect(body.data.length).to.equal(1) - lastRequestChangeOwnershipId = resSecondUser.body.data[0].id + lastRequestId = body.data[0].id + } }) it('Should accept the same change ownership request without crashing', async function () { this.timeout(10000) - await changeVideoOwnership(servers[0].url, firstUserAccessToken, servers[0].video.id, secondUser.username) + await command.create({ token: firstUserToken, videoId: servers[0].video.id, username: secondUser.username }) }) it('Should not create multiple change ownership requests while one is waiting', async function () { this.timeout(10000) - const resSecondUser = await getVideoChangeOwnershipList(servers[0].url, secondUserAccessToken) + const body = await command.list({ token: secondUserToken }) - expect(resSecondUser.body.total).to.equal(1) - expect(resSecondUser.body.data).to.be.an('array') - expect(resSecondUser.body.data.length).to.equal(1) + expect(body.total).to.equal(1) + expect(body.data).to.be.an('array') + expect(body.data.length).to.equal(1) }) it('Should not be possible to refuse the change of ownership from first user', async function () { this.timeout(10000) - await refuseChangeOwnership(servers[0].url, firstUserAccessToken, lastRequestChangeOwnershipId, HttpStatusCode.FORBIDDEN_403) + await command.refuse({ token: firstUserToken, ownershipId: lastRequestId, expectedStatus: HttpStatusCode.FORBIDDEN_403 }) }) it('Should be possible to refuse the change of ownership from second user', async function () { this.timeout(10000) - await refuseChangeOwnership(servers[0].url, secondUserAccessToken, lastRequestChangeOwnershipId) + await command.refuse({ token: secondUserToken, ownershipId: lastRequestId }) }) it('Should send a new request to change ownership of a video', async function () { this.timeout(15000) - await changeVideoOwnership(servers[0].url, firstUserAccessToken, servers[0].video.id, secondUser.username) + await command.create({ token: firstUserToken, videoId: servers[0].video.id, username: secondUser.username }) }) it('Should return two requests to change ownership for the second user', async function () { - const resFirstUser = await getVideoChangeOwnershipList(servers[0].url, firstUserAccessToken) + { + const body = await command.list({ token: firstUserToken }) - expect(resFirstUser.body.total).to.equal(0) - expect(resFirstUser.body.data).to.be.an('array') - expect(resFirstUser.body.data.length).to.equal(0) + expect(body.total).to.equal(0) + expect(body.data).to.be.an('array') + expect(body.data.length).to.equal(0) + } - const resSecondUser = await getVideoChangeOwnershipList(servers[0].url, secondUserAccessToken) + { + const body = await command.list({ token: secondUserToken }) - expect(resSecondUser.body.total).to.equal(2) - expect(resSecondUser.body.data).to.be.an('array') - expect(resSecondUser.body.data.length).to.equal(2) + expect(body.total).to.equal(2) + expect(body.data).to.be.an('array') + expect(body.data.length).to.equal(2) - lastRequestChangeOwnershipId = resSecondUser.body.data[0].id + lastRequestId = body.data[0].id + } }) it('Should not be possible to accept the change of ownership from first user', async function () { this.timeout(10000) - await acceptChangeOwnership( - servers[0].url, - firstUserAccessToken, - lastRequestChangeOwnershipId, - secondUserChannelId, - HttpStatusCode.FORBIDDEN_403 - ) + await command.accept({ + token: firstUserToken, + ownershipId: lastRequestId, + channelId: secondUserChannelId, + expectedStatus: HttpStatusCode.FORBIDDEN_403 + }) }) it('Should be possible to accept the change of ownership from second user', async function () { this.timeout(10000) - await acceptChangeOwnership(servers[0].url, secondUserAccessToken, lastRequestChangeOwnershipId, secondUserChannelId) + await command.accept({ token: secondUserToken, ownershipId: lastRequestId, channelId: secondUserChannelId }) await waitJobs(servers) }) @@ -240,20 +252,20 @@ describe('Test video change ownership - nominal', function () { it('Should send a request to change ownership of a live', async function () { this.timeout(15000) - await changeVideoOwnership(servers[0].url, firstUserAccessToken, liveId, secondUser.username) + await command.create({ token: firstUserToken, videoId: liveId, username: secondUser.username }) - const resSecondUser = await getVideoChangeOwnershipList(servers[0].url, secondUserAccessToken) + const body = await command.list({ token: secondUserToken }) - expect(resSecondUser.body.total).to.equal(3) - expect(resSecondUser.body.data.length).to.equal(3) + expect(body.total).to.equal(3) + expect(body.data.length).to.equal(3) - lastRequestChangeOwnershipId = resSecondUser.body.data[0].id + lastRequestId = body.data[0].id }) it('Should accept a live ownership change', async function () { this.timeout(20000) - await acceptChangeOwnership(servers[0].url, secondUserAccessToken, lastRequestChangeOwnershipId, secondUserChannelId) + await command.accept({ token: secondUserToken, ownershipId: lastRequestId, channelId: secondUserChannelId }) await waitJobs(servers) @@ -283,9 +295,9 @@ describe('Test video change ownership - quota too small', function () { username: 'second', password: 'My other password' } - let firstUserAccessToken = '' - let secondUserAccessToken = '' - let lastRequestChangeOwnershipId = '' + let firstUserToken = '' + let secondUserToken = '' + let lastRequestId: number before(async function () { this.timeout(50000) @@ -311,15 +323,15 @@ describe('Test video change ownership - quota too small', function () { videoQuota: limitedVideoQuota }) - firstUserAccessToken = await userLogin(server, firstUser) - secondUserAccessToken = await userLogin(server, secondUser) + firstUserToken = await userLogin(server, firstUser) + secondUserToken = await userLogin(server, secondUser) // Upload some videos on the server const video1Attributes = { name: 'my super name', description: 'my super description' } - await uploadVideo(server.url, firstUserAccessToken, video1Attributes) + await uploadVideo(server.url, firstUserToken, video1Attributes) await waitJobs(server) @@ -334,39 +346,42 @@ describe('Test video change ownership - quota too small', function () { it('Should send a request to change ownership of a video', async function () { this.timeout(15000) - await changeVideoOwnership(server.url, firstUserAccessToken, server.video.id, secondUser.username) + await server.changeOwnershipCommand.create({ token: firstUserToken, videoId: server.video.id, username: secondUser.username }) }) it('Should only return a request to change ownership for the second user', async function () { - const resFirstUser = await getVideoChangeOwnershipList(server.url, firstUserAccessToken) + { + const body = await server.changeOwnershipCommand.list({ token: firstUserToken }) - expect(resFirstUser.body.total).to.equal(0) - expect(resFirstUser.body.data).to.be.an('array') - expect(resFirstUser.body.data.length).to.equal(0) + expect(body.total).to.equal(0) + expect(body.data).to.be.an('array') + expect(body.data.length).to.equal(0) + } - const resSecondUser = await getVideoChangeOwnershipList(server.url, secondUserAccessToken) + { + const body = await server.changeOwnershipCommand.list({ token: secondUserToken }) - expect(resSecondUser.body.total).to.equal(1) - expect(resSecondUser.body.data).to.be.an('array') - expect(resSecondUser.body.data.length).to.equal(1) + expect(body.total).to.equal(1) + expect(body.data).to.be.an('array') + expect(body.data.length).to.equal(1) - lastRequestChangeOwnershipId = resSecondUser.body.data[0].id + lastRequestId = body.data[0].id + } }) it('Should not be possible to accept the change of ownership from second user because of exceeded quota', async function () { this.timeout(10000) - const secondUserInformationResponse = await getMyUserInformation(server.url, secondUserAccessToken) + const secondUserInformationResponse = await getMyUserInformation(server.url, secondUserToken) const secondUserInformation: User = secondUserInformationResponse.body const channelId = secondUserInformation.videoChannels[0].id - await acceptChangeOwnership( - server.url, - secondUserAccessToken, - lastRequestChangeOwnershipId, + await server.changeOwnershipCommand.accept({ + token: secondUserToken, + ownershipId: lastRequestId, channelId, - HttpStatusCode.PAYLOAD_TOO_LARGE_413 - ) + expectedStatus: HttpStatusCode.PAYLOAD_TOO_LARGE_413 + }) }) after(async function () { -- cgit v1.2.3 From 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/videos/video-change-ownership.ts | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) (limited to 'server/tests/api/videos/video-change-ownership.ts') diff --git a/server/tests/api/videos/video-change-ownership.ts b/server/tests/api/videos/video-change-ownership.ts index 1b81fe047..17c738e6f 100644 --- a/server/tests/api/videos/video-change-ownership.ts +++ b/server/tests/api/videos/video-change-ownership.ts @@ -16,8 +16,7 @@ import { ServerInfo, setAccessTokensToServers, setDefaultVideoChannel, - uploadVideo, - userLogin + uploadVideo } from '../../../../shared/extra-utils' import { waitJobs } from '../../../../shared/extra-utils/server/jobs' import { User } from '../../../../shared/models/users' @@ -82,8 +81,8 @@ describe('Test video change ownership - nominal', function () { videoQuota: videoQuota }) - firstUserToken = await userLogin(servers[0], firstUser) - secondUserToken = await userLogin(servers[0], secondUser) + firstUserToken = await servers[0].loginCommand.getAccessToken(firstUser) + secondUserToken = await servers[0].loginCommand.getAccessToken(secondUser) { const res = await getMyUserInformation(servers[0].url, firstUserToken) @@ -323,8 +322,8 @@ describe('Test video change ownership - quota too small', function () { videoQuota: limitedVideoQuota }) - firstUserToken = await userLogin(server, firstUser) - secondUserToken = await userLogin(server, secondUser) + firstUserToken = await server.loginCommand.getAccessToken(firstUser) + secondUserToken = await server.loginCommand.getAccessToken(secondUser) // Upload some videos on the server const video1Attributes = { -- 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/videos/video-change-ownership.ts | 89 ++++++----------------- 1 file changed, 21 insertions(+), 68 deletions(-) (limited to 'server/tests/api/videos/video-change-ownership.ts') diff --git a/server/tests/api/videos/video-change-ownership.ts b/server/tests/api/videos/video-change-ownership.ts index 17c738e6f..b0bbd5a0d 100644 --- a/server/tests/api/videos/video-change-ownership.ts +++ b/server/tests/api/videos/video-change-ownership.ts @@ -6,11 +6,9 @@ import { HttpStatusCode } from '../../../../shared/core-utils/miscs/http-error-c import { ChangeOwnershipCommand, cleanupTests, - createUser, doubleFollow, flushAndRunMultipleServers, flushAndRunServer, - getMyUserInformation, getVideo, getVideosList, ServerInfo, @@ -19,21 +17,15 @@ import { uploadVideo } from '../../../../shared/extra-utils' import { waitJobs } from '../../../../shared/extra-utils/server/jobs' -import { User } from '../../../../shared/models/users' import { VideoDetails, VideoPrivacy } from '../../../../shared/models/videos' const expect = chai.expect describe('Test video change ownership - nominal', function () { let servers: ServerInfo[] = [] - const firstUser = { - username: 'first', - password: 'My great password' - } - const secondUser = { - username: 'second', - password: 'My other password' - } + + const firstUser = 'first' + const secondUser = 'second' let firstUserToken = '' let firstUserChannelId: number @@ -65,35 +57,17 @@ describe('Test video change ownership - nominal', function () { } }) - const videoQuota = 42000000 - await createUser({ - url: servers[0].url, - accessToken: servers[0].accessToken, - username: firstUser.username, - password: firstUser.password, - videoQuota: videoQuota - }) - await createUser({ - url: servers[0].url, - accessToken: servers[0].accessToken, - username: secondUser.username, - password: secondUser.password, - videoQuota: videoQuota - }) - - firstUserToken = await servers[0].loginCommand.getAccessToken(firstUser) - secondUserToken = await servers[0].loginCommand.getAccessToken(secondUser) + firstUserToken = await servers[0].usersCommand.generateUserAndToken(firstUser) + secondUserToken = await servers[0].usersCommand.generateUserAndToken(secondUser) { - const res = await getMyUserInformation(servers[0].url, firstUserToken) - const firstUserInformation: User = res.body - firstUserChannelId = firstUserInformation.videoChannels[0].id + const { videoChannels } = await servers[0].usersCommand.getMyInfo({ token: firstUserToken }) + firstUserChannelId = videoChannels[0].id } { - const res = await getMyUserInformation(servers[0].url, secondUserToken) - const secondUserInformation: User = res.body - secondUserChannelId = secondUserInformation.videoChannels[0].id + const { videoChannels } = await servers[0].usersCommand.getMyInfo({ token: secondUserToken }) + secondUserChannelId = videoChannels[0].id } { @@ -140,7 +114,7 @@ describe('Test video change ownership - nominal', function () { it('Should send a request to change ownership of a video', async function () { this.timeout(15000) - await command.create({ token: firstUserToken, videoId: servers[0].video.id, username: secondUser.username }) + await command.create({ token: firstUserToken, videoId: servers[0].video.id, username: secondUser }) }) it('Should only return a request to change ownership for the second user', async function () { @@ -166,7 +140,7 @@ describe('Test video change ownership - nominal', function () { it('Should accept the same change ownership request without crashing', async function () { this.timeout(10000) - await command.create({ token: firstUserToken, videoId: servers[0].video.id, username: secondUser.username }) + await command.create({ token: firstUserToken, videoId: servers[0].video.id, username: secondUser }) }) it('Should not create multiple change ownership requests while one is waiting', async function () { @@ -194,7 +168,7 @@ describe('Test video change ownership - nominal', function () { it('Should send a new request to change ownership of a video', async function () { this.timeout(15000) - await command.create({ token: firstUserToken, videoId: servers[0].video.id, username: secondUser.username }) + await command.create({ token: firstUserToken, videoId: servers[0].video.id, username: secondUser }) }) it('Should return two requests to change ownership for the second user', async function () { @@ -251,7 +225,7 @@ describe('Test video change ownership - nominal', function () { it('Should send a request to change ownership of a live', async function () { this.timeout(15000) - await command.create({ token: firstUserToken, videoId: liveId, username: secondUser.username }) + await command.create({ token: firstUserToken, videoId: liveId, username: secondUser }) const body = await command.list({ token: secondUserToken }) @@ -286,14 +260,9 @@ describe('Test video change ownership - nominal', function () { describe('Test video change ownership - quota too small', function () { let server: ServerInfo - const firstUser = { - username: 'first', - password: 'My great password' - } - const secondUser = { - username: 'second', - password: 'My other password' - } + const firstUser = 'first' + const secondUser = 'second' + let firstUserToken = '' let secondUserToken = '' let lastRequestId: number @@ -305,24 +274,9 @@ describe('Test video change ownership - quota too small', function () { server = await flushAndRunServer(1) await setAccessTokensToServers([ server ]) - const videoQuota = 42000000 - const limitedVideoQuota = 10 - await createUser({ - url: server.url, - accessToken: server.accessToken, - username: firstUser.username, - password: firstUser.password, - videoQuota: videoQuota - }) - await createUser({ - url: server.url, - accessToken: server.accessToken, - username: secondUser.username, - password: secondUser.password, - videoQuota: limitedVideoQuota - }) + await server.usersCommand.create({ username: secondUser, videoQuota: 10 }) - firstUserToken = await server.loginCommand.getAccessToken(firstUser) + firstUserToken = await server.usersCommand.generateUserAndToken(firstUser) secondUserToken = await server.loginCommand.getAccessToken(secondUser) // Upload some videos on the server @@ -345,7 +299,7 @@ describe('Test video change ownership - quota too small', function () { it('Should send a request to change ownership of a video', async function () { this.timeout(15000) - await server.changeOwnershipCommand.create({ token: firstUserToken, videoId: server.video.id, username: secondUser.username }) + await server.changeOwnershipCommand.create({ token: firstUserToken, videoId: server.video.id, username: secondUser }) }) it('Should only return a request to change ownership for the second user', async function () { @@ -371,9 +325,8 @@ describe('Test video change ownership - quota too small', function () { it('Should not be possible to accept the change of ownership from second user because of exceeded quota', async function () { this.timeout(10000) - const secondUserInformationResponse = await getMyUserInformation(server.url, secondUserToken) - const secondUserInformation: User = secondUserInformationResponse.body - const channelId = secondUserInformation.videoChannels[0].id + const { videoChannels } = await server.usersCommand.getMyInfo({ token: secondUserToken }) + const channelId = videoChannels[0].id await server.changeOwnershipCommand.accept({ token: secondUserToken, -- cgit v1.2.3 From d23dd9fbfc4d26026352c10f81d2795ceaf2908a Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Thu, 15 Jul 2021 10:02:54 +0200 Subject: Introduce videos command --- server/tests/api/videos/video-change-ownership.ts | 38 +++++++++-------------- 1 file changed, 14 insertions(+), 24 deletions(-) (limited to 'server/tests/api/videos/video-change-ownership.ts') diff --git a/server/tests/api/videos/video-change-ownership.ts b/server/tests/api/videos/video-change-ownership.ts index b0bbd5a0d..b85edd920 100644 --- a/server/tests/api/videos/video-change-ownership.ts +++ b/server/tests/api/videos/video-change-ownership.ts @@ -2,22 +2,19 @@ import 'mocha' import * as chai from 'chai' -import { HttpStatusCode } from '../../../../shared/core-utils/miscs/http-error-codes' +import { HttpStatusCode } from '@shared/core-utils' import { ChangeOwnershipCommand, cleanupTests, doubleFollow, flushAndRunMultipleServers, flushAndRunServer, - getVideo, - getVideosList, ServerInfo, setAccessTokensToServers, setDefaultVideoChannel, - uploadVideo -} from '../../../../shared/extra-utils' -import { waitJobs } from '../../../../shared/extra-utils/server/jobs' -import { VideoDetails, VideoPrivacy } from '../../../../shared/models/videos' + waitJobs +} from '@shared/extra-utils' +import { VideoPrivacy } from '@shared/models' const expect = chai.expect @@ -71,14 +68,13 @@ describe('Test video change ownership - nominal', function () { } { - const videoAttributes = { + const attributes = { name: 'my super name', description: 'my super description' } - const res = await uploadVideo(servers[0].url, firstUserToken, videoAttributes) + const { id } = await servers[0].videosCommand.upload({ token: firstUserToken, attributes }) - const resVideo = await getVideo(servers[0].url, res.body.video.id) - servers[0].video = resVideo.body + servers[0].video = await servers[0].videosCommand.get({ id }) } { @@ -212,9 +208,7 @@ describe('Test video change ownership - nominal', function () { it('Should have the channel of the video updated', async function () { for (const server of servers) { - const res = await getVideo(server.url, servers[0].video.uuid) - - const video: VideoDetails = res.body + const video = await server.videosCommand.get({ id: servers[0].video.uuid }) expect(video.name).to.equal('my super name') expect(video.channel.displayName).to.equal('Main second channel') @@ -243,9 +237,7 @@ describe('Test video change ownership - nominal', function () { await waitJobs(servers) for (const server of servers) { - const res = await getVideo(server.url, servers[0].video.uuid) - - const video: VideoDetails = res.body + const video = await server.videosCommand.get({ id: servers[0].video.uuid }) expect(video.name).to.equal('my super name') expect(video.channel.displayName).to.equal('Main second channel') @@ -280,20 +272,18 @@ describe('Test video change ownership - quota too small', function () { secondUserToken = await server.loginCommand.getAccessToken(secondUser) // Upload some videos on the server - const video1Attributes = { + const attributes = { name: 'my super name', description: 'my super description' } - await uploadVideo(server.url, firstUserToken, video1Attributes) + await server.videosCommand.upload({ token: firstUserToken, attributes }) await waitJobs(server) - const res = await getVideosList(server.url) - const videos = res.body.data - - expect(videos.length).to.equal(1) + const { data } = await server.videosCommand.list() + expect(data.length).to.equal(1) - server.video = videos.find(video => video.name === 'my super name') + server.video = data.find(video => video.name === 'my super name') }) it('Should send a request to change ownership of a video', async function () { -- 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/videos/video-change-ownership.ts | 50 +++++++++++------------ 1 file changed, 25 insertions(+), 25 deletions(-) (limited to 'server/tests/api/videos/video-change-ownership.ts') diff --git a/server/tests/api/videos/video-change-ownership.ts b/server/tests/api/videos/video-change-ownership.ts index b85edd920..352eb5ea3 100644 --- a/server/tests/api/videos/video-change-ownership.ts +++ b/server/tests/api/videos/video-change-ownership.ts @@ -43,7 +43,7 @@ describe('Test video change ownership - nominal', function () { await setAccessTokensToServers(servers) await setDefaultVideoChannel(servers) - await servers[0].configCommand.updateCustomSubConfig({ + await servers[0].config.updateCustomSubConfig({ newConfig: { transcoding: { enabled: false @@ -54,16 +54,16 @@ describe('Test video change ownership - nominal', function () { } }) - firstUserToken = await servers[0].usersCommand.generateUserAndToken(firstUser) - secondUserToken = await servers[0].usersCommand.generateUserAndToken(secondUser) + firstUserToken = await servers[0].users.generateUserAndToken(firstUser) + secondUserToken = await servers[0].users.generateUserAndToken(secondUser) { - const { videoChannels } = await servers[0].usersCommand.getMyInfo({ token: firstUserToken }) + const { videoChannels } = await servers[0].users.getMyInfo({ token: firstUserToken }) firstUserChannelId = videoChannels[0].id } { - const { videoChannels } = await servers[0].usersCommand.getMyInfo({ token: secondUserToken }) + const { videoChannels } = await servers[0].users.getMyInfo({ token: secondUserToken }) secondUserChannelId = videoChannels[0].id } @@ -72,19 +72,19 @@ describe('Test video change ownership - nominal', function () { name: 'my super name', description: 'my super description' } - const { id } = await servers[0].videosCommand.upload({ token: firstUserToken, attributes }) + const { id } = await servers[0].videos.upload({ token: firstUserToken, attributes }) - servers[0].video = await servers[0].videosCommand.get({ id }) + servers[0].store.video = await servers[0].videos.get({ id }) } { const attributes = { name: 'live', channelId: firstUserChannelId, privacy: VideoPrivacy.PUBLIC } - const video = await servers[0].liveCommand.create({ token: firstUserToken, fields: attributes }) + const video = await servers[0].live.create({ token: firstUserToken, fields: attributes }) liveId = video.id } - command = servers[0].changeOwnershipCommand + command = servers[0].changeOwnership await doubleFollow(servers[0], servers[1]) }) @@ -110,7 +110,7 @@ describe('Test video change ownership - nominal', function () { it('Should send a request to change ownership of a video', async function () { this.timeout(15000) - await command.create({ token: firstUserToken, videoId: servers[0].video.id, username: secondUser }) + await command.create({ token: firstUserToken, videoId: servers[0].store.video.id, username: secondUser }) }) it('Should only return a request to change ownership for the second user', async function () { @@ -136,7 +136,7 @@ describe('Test video change ownership - nominal', function () { it('Should accept the same change ownership request without crashing', async function () { this.timeout(10000) - await command.create({ token: firstUserToken, videoId: servers[0].video.id, username: secondUser }) + await command.create({ token: firstUserToken, videoId: servers[0].store.video.id, username: secondUser }) }) it('Should not create multiple change ownership requests while one is waiting', async function () { @@ -164,7 +164,7 @@ describe('Test video change ownership - nominal', function () { it('Should send a new request to change ownership of a video', async function () { this.timeout(15000) - await command.create({ token: firstUserToken, videoId: servers[0].video.id, username: secondUser }) + await command.create({ token: firstUserToken, videoId: servers[0].store.video.id, username: secondUser }) }) it('Should return two requests to change ownership for the second user', async function () { @@ -208,7 +208,7 @@ describe('Test video change ownership - nominal', function () { it('Should have the channel of the video updated', async function () { for (const server of servers) { - const video = await server.videosCommand.get({ id: servers[0].video.uuid }) + const video = await server.videos.get({ id: servers[0].store.video.uuid }) expect(video.name).to.equal('my super name') expect(video.channel.displayName).to.equal('Main second channel') @@ -237,7 +237,7 @@ describe('Test video change ownership - nominal', function () { await waitJobs(servers) for (const server of servers) { - const video = await server.videosCommand.get({ id: servers[0].video.uuid }) + const video = await server.videos.get({ id: servers[0].store.video.uuid }) expect(video.name).to.equal('my super name') expect(video.channel.displayName).to.equal('Main second channel') @@ -266,35 +266,35 @@ describe('Test video change ownership - quota too small', function () { server = await flushAndRunServer(1) await setAccessTokensToServers([ server ]) - await server.usersCommand.create({ username: secondUser, videoQuota: 10 }) + await server.users.create({ username: secondUser, videoQuota: 10 }) - firstUserToken = await server.usersCommand.generateUserAndToken(firstUser) - secondUserToken = await server.loginCommand.getAccessToken(secondUser) + firstUserToken = await server.users.generateUserAndToken(firstUser) + secondUserToken = await server.login.getAccessToken(secondUser) // Upload some videos on the server const attributes = { name: 'my super name', description: 'my super description' } - await server.videosCommand.upload({ token: firstUserToken, attributes }) + await server.videos.upload({ token: firstUserToken, attributes }) await waitJobs(server) - const { data } = await server.videosCommand.list() + const { data } = await server.videos.list() expect(data.length).to.equal(1) - server.video = data.find(video => video.name === 'my super name') + server.store.video = data.find(video => video.name === 'my super name') }) it('Should send a request to change ownership of a video', async function () { this.timeout(15000) - await server.changeOwnershipCommand.create({ token: firstUserToken, videoId: server.video.id, username: secondUser }) + await server.changeOwnership.create({ token: firstUserToken, videoId: server.store.video.id, username: secondUser }) }) it('Should only return a request to change ownership for the second user', async function () { { - const body = await server.changeOwnershipCommand.list({ token: firstUserToken }) + const body = await server.changeOwnership.list({ token: firstUserToken }) expect(body.total).to.equal(0) expect(body.data).to.be.an('array') @@ -302,7 +302,7 @@ describe('Test video change ownership - quota too small', function () { } { - const body = await server.changeOwnershipCommand.list({ token: secondUserToken }) + const body = await server.changeOwnership.list({ token: secondUserToken }) expect(body.total).to.equal(1) expect(body.data).to.be.an('array') @@ -315,10 +315,10 @@ describe('Test video change ownership - quota too small', function () { it('Should not be possible to accept the change of ownership from second user because of exceeded quota', async function () { this.timeout(10000) - const { videoChannels } = await server.usersCommand.getMyInfo({ token: secondUserToken }) + const { videoChannels } = await server.users.getMyInfo({ token: secondUserToken }) const channelId = videoChannels[0].id - await server.changeOwnershipCommand.accept({ + await server.changeOwnership.accept({ token: secondUserToken, ownershipId: lastRequestId, channelId, -- 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/videos/video-change-ownership.ts | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) (limited to 'server/tests/api/videos/video-change-ownership.ts') diff --git a/server/tests/api/videos/video-change-ownership.ts b/server/tests/api/videos/video-change-ownership.ts index 352eb5ea3..cefddb68e 100644 --- a/server/tests/api/videos/video-change-ownership.ts +++ b/server/tests/api/videos/video-change-ownership.ts @@ -7,9 +7,9 @@ import { ChangeOwnershipCommand, cleanupTests, doubleFollow, - flushAndRunMultipleServers, - flushAndRunServer, - ServerInfo, + createMultipleServers, + createSingleServer, + PeerTubeServer, setAccessTokensToServers, setDefaultVideoChannel, waitJobs @@ -19,7 +19,7 @@ import { VideoPrivacy } from '@shared/models' const expect = chai.expect describe('Test video change ownership - nominal', function () { - let servers: ServerInfo[] = [] + let servers: PeerTubeServer[] = [] const firstUser = 'first' const secondUser = 'second' @@ -39,7 +39,7 @@ describe('Test video change ownership - nominal', function () { before(async function () { this.timeout(50000) - servers = await flushAndRunMultipleServers(2) + servers = await createMultipleServers(2) await setAccessTokensToServers(servers) await setDefaultVideoChannel(servers) @@ -251,7 +251,7 @@ describe('Test video change ownership - nominal', function () { }) describe('Test video change ownership - quota too small', function () { - let server: ServerInfo + let server: PeerTubeServer const firstUser = 'first' const secondUser = 'second' @@ -263,7 +263,7 @@ describe('Test video change ownership - quota too small', function () { this.timeout(50000) // Run one server - server = await flushAndRunServer(1) + server = await createSingleServer(1) await setAccessTokensToServers([ server ]) await server.users.create({ username: secondUser, videoQuota: 10 }) -- 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/videos/video-change-ownership.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'server/tests/api/videos/video-change-ownership.ts') diff --git a/server/tests/api/videos/video-change-ownership.ts b/server/tests/api/videos/video-change-ownership.ts index cefddb68e..792550101 100644 --- a/server/tests/api/videos/video-change-ownership.ts +++ b/server/tests/api/videos/video-change-ownership.ts @@ -2,7 +2,7 @@ import 'mocha' import * as chai from 'chai' -import { HttpStatusCode } from '@shared/core-utils' +import { HttpStatusCode } from '@shared/models' import { ChangeOwnershipCommand, cleanupTests, -- 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/videos/video-change-ownership.ts | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) (limited to 'server/tests/api/videos/video-change-ownership.ts') diff --git a/server/tests/api/videos/video-change-ownership.ts b/server/tests/api/videos/video-change-ownership.ts index 792550101..6ae6d3004 100644 --- a/server/tests/api/videos/video-change-ownership.ts +++ b/server/tests/api/videos/video-change-ownership.ts @@ -2,19 +2,18 @@ import 'mocha' import * as chai from 'chai' -import { HttpStatusCode } from '@shared/models' import { ChangeOwnershipCommand, cleanupTests, - doubleFollow, createMultipleServers, createSingleServer, + doubleFollow, PeerTubeServer, setAccessTokensToServers, setDefaultVideoChannel, waitJobs } from '@shared/extra-utils' -import { VideoPrivacy } from '@shared/models' +import { HttpStatusCode, VideoPrivacy } from '@shared/models' const expect = chai.expect -- cgit v1.2.3