X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=server%2Ftests%2Fapi%2Fserver%2Ffollow-constraints.ts;h=e1ec2b069baefd4da052a863a4c1d6a42edc9980;hb=77239b425a8e00822a53c9907415832a473c3eb6;hp=4ed593b7674f6d93ed39e2870cf0ebc3610241e4;hpb=254d3579f5338f5fd775c17d15cdfc37078bcfb4;p=github%2FChocobozzz%2FPeerTube.git diff --git a/server/tests/api/server/follow-constraints.ts b/server/tests/api/server/follow-constraints.ts index 4ed593b76..e1ec2b069 100644 --- a/server/tests/api/server/follow-constraints.ts +++ b/server/tests/api/server/follow-constraints.ts @@ -1,12 +1,15 @@ /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */ -import 'mocha' -import * as chai from 'chai' -import { HttpStatusCode } from '@shared/core-utils' -import { cleanupTests, doubleFollow, createMultipleServers, PeerTubeServer, setAccessTokensToServers } from '@shared/extra-utils' -import { PeerTubeProblemDocument, ServerErrorCode } from '@shared/models' - -const expect = chai.expect +import { expect } from 'chai' +import { HttpStatusCode, PeerTubeProblemDocument, ServerErrorCode } from '@shared/models' +import { + cleanupTests, + createMultipleServers, + doubleFollow, + PeerTubeServer, + setAccessTokensToServers, + waitJobs +} from '@shared/server-commands' describe('Test follow constraints', function () { let servers: PeerTubeServer[] = [] @@ -15,7 +18,7 @@ describe('Test follow constraints', function () { let userToken: string before(async function () { - this.timeout(90000) + this.timeout(240000) servers = await createMultipleServers(2) @@ -54,30 +57,30 @@ describe('Test follow constraints', function () { }) it('Should list local account videos', async function () { - const { total, data } = await servers[0].videos.listByAccount({ accountName: 'root@localhost:' + servers[0].port }) + const { total, data } = await servers[0].videos.listByAccount({ handle: 'root@localhost:' + servers[0].port }) expect(total).to.equal(1) expect(data).to.have.lengthOf(1) }) it('Should list remote account videos', async function () { - const { total, data } = await servers[0].videos.listByAccount({ accountName: 'root@localhost:' + servers[1].port }) + const { total, data } = await servers[0].videos.listByAccount({ handle: 'root@localhost:' + servers[1].port }) expect(total).to.equal(1) expect(data).to.have.lengthOf(1) }) it('Should list local channel videos', async function () { - const videoChannelName = 'root_channel@localhost:' + servers[0].port - const { total, data } = await servers[0].videos.listByChannel({ videoChannelName }) + const handle = 'root_channel@localhost:' + servers[0].port + const { total, data } = await servers[0].videos.listByChannel({ handle }) expect(total).to.equal(1) expect(data).to.have.lengthOf(1) }) it('Should list remote channel videos', async function () { - const videoChannelName = 'root_channel@localhost:' + servers[1].port - const { total, data } = await servers[0].videos.listByChannel({ videoChannelName }) + const handle = 'root_channel@localhost:' + servers[1].port + const { total, data } = await servers[0].videos.listByChannel({ handle }) expect(total).to.equal(1) expect(data).to.have.lengthOf(1) @@ -94,30 +97,30 @@ describe('Test follow constraints', function () { }) it('Should list local account videos', async function () { - const { total, data } = await servers[0].videos.listByAccount({ token: userToken, accountName: 'root@localhost:' + servers[0].port }) + const { total, data } = await servers[0].videos.listByAccount({ token: userToken, handle: 'root@localhost:' + servers[0].port }) expect(total).to.equal(1) expect(data).to.have.lengthOf(1) }) it('Should list remote account videos', async function () { - const { total, data } = await servers[0].videos.listByAccount({ token: userToken, accountName: 'root@localhost:' + servers[1].port }) + const { total, data } = await servers[0].videos.listByAccount({ token: userToken, handle: 'root@localhost:' + servers[1].port }) expect(total).to.equal(1) expect(data).to.have.lengthOf(1) }) it('Should list local channel videos', async function () { - const videoChannelName = 'root_channel@localhost:' + servers[0].port - const { total, data } = await servers[0].videos.listByChannel({ token: userToken, videoChannelName }) + const handle = 'root_channel@localhost:' + servers[0].port + const { total, data } = await servers[0].videos.listByChannel({ token: userToken, handle }) expect(total).to.equal(1) expect(data).to.have.lengthOf(1) }) it('Should list remote channel videos', async function () { - const videoChannelName = 'root_channel@localhost:' + servers[1].port - const { total, data } = await servers[0].videos.listByChannel({ token: userToken, videoChannelName }) + const handle = 'root_channel@localhost:' + servers[1].port + const { total, data } = await servers[0].videos.listByChannel({ token: userToken, handle }) expect(total).to.equal(1) expect(data).to.have.lengthOf(1) @@ -157,8 +160,8 @@ describe('Test follow constraints', function () { it('Should list local account videos', async function () { const { total, data } = await servers[0].videos.listByAccount({ - token: undefined, - accountName: 'root@localhost:' + servers[0].port + token: null, + handle: 'root@localhost:' + servers[0].port }) expect(total).to.equal(1) @@ -167,8 +170,8 @@ describe('Test follow constraints', function () { it('Should not list remote account videos', async function () { const { total, data } = await servers[0].videos.listByAccount({ - token: undefined, - accountName: 'root@localhost:' + servers[1].port + token: null, + handle: 'root@localhost:' + servers[1].port }) expect(total).to.equal(0) @@ -176,16 +179,16 @@ describe('Test follow constraints', function () { }) it('Should list local channel videos', async function () { - const videoChannelName = 'root_channel@localhost:' + servers[0].port - const { total, data } = await servers[0].videos.listByChannel({ token: undefined, videoChannelName }) + const handle = 'root_channel@localhost:' + servers[0].port + const { total, data } = await servers[0].videos.listByChannel({ token: null, handle }) expect(total).to.equal(1) expect(data).to.have.lengthOf(1) }) it('Should not list remote channel videos', async function () { - const videoChannelName = 'root_channel@localhost:' + servers[1].port - const { total, data } = await servers[0].videos.listByChannel({ token: undefined, videoChannelName }) + const handle = 'root_channel@localhost:' + servers[1].port + const { total, data } = await servers[0].videos.listByChannel({ token: null, handle }) expect(total).to.equal(0) expect(data).to.have.lengthOf(0) @@ -193,6 +196,7 @@ describe('Test follow constraints', function () { }) describe('With a logged user', function () { + it('Should get the local video', async function () { await servers[0].videos.getWithToken({ token: userToken, id: video1UUID }) }) @@ -202,30 +206,30 @@ describe('Test follow constraints', function () { }) it('Should list local account videos', async function () { - const { total, data } = await servers[0].videos.listByAccount({ token: userToken, accountName: 'root@localhost:' + servers[0].port }) + const { total, data } = await servers[0].videos.listByAccount({ token: userToken, handle: 'root@localhost:' + servers[0].port }) expect(total).to.equal(1) expect(data).to.have.lengthOf(1) }) it('Should list remote account videos', async function () { - const { total, data } = await servers[0].videos.listByAccount({ token: userToken, accountName: 'root@localhost:' + servers[1].port }) + const { total, data } = await servers[0].videos.listByAccount({ token: userToken, handle: 'root@localhost:' + servers[1].port }) expect(total).to.equal(1) expect(data).to.have.lengthOf(1) }) it('Should list local channel videos', async function () { - const videoChannelName = 'root_channel@localhost:' + servers[0].port - const { total, data } = await servers[0].videos.listByChannel({ token: userToken, videoChannelName }) + const handle = 'root_channel@localhost:' + servers[0].port + const { total, data } = await servers[0].videos.listByChannel({ token: userToken, handle }) expect(total).to.equal(1) expect(data).to.have.lengthOf(1) }) it('Should list remote channel videos', async function () { - const videoChannelName = 'root_channel@localhost:' + servers[1].port - const { total, data } = await servers[0].videos.listByChannel({ token: userToken, videoChannelName }) + const handle = 'root_channel@localhost:' + servers[1].port + const { total, data } = await servers[0].videos.listByChannel({ token: userToken, handle }) expect(total).to.equal(1) expect(data).to.have.lengthOf(1) @@ -233,6 +237,84 @@ describe('Test follow constraints', function () { }) }) + describe('When following a remote account', function () { + + before(async function () { + this.timeout(60000) + + await servers[0].follows.follow({ handles: [ 'root@' + servers[1].host ] }) + await waitJobs(servers) + }) + + it('Should get the remote video with an unlogged user', async function () { + await servers[0].videos.get({ id: video2UUID }) + }) + + it('Should get the remote video with a logged in user', async function () { + await servers[0].videos.getWithToken({ token: userToken, id: video2UUID }) + }) + }) + + describe('When unfollowing a remote account', function () { + + before(async function () { + this.timeout(60000) + + await servers[0].follows.unfollow({ target: 'root@' + servers[1].host }) + await waitJobs(servers) + }) + + it('Should not get the remote video with an unlogged user', async function () { + const body = await servers[0].videos.get({ id: video2UUID, expectedStatus: HttpStatusCode.FORBIDDEN_403 }) + + const error = body as unknown as PeerTubeProblemDocument + expect(error.code).to.equal(ServerErrorCode.DOES_NOT_RESPECT_FOLLOW_CONSTRAINTS) + }) + + it('Should get the remote video with a logged in user', async function () { + await servers[0].videos.getWithToken({ token: userToken, id: video2UUID }) + }) + }) + + describe('When following a remote channel', function () { + + before(async function () { + this.timeout(60000) + + await servers[0].follows.follow({ handles: [ 'root_channel@' + servers[1].host ] }) + await waitJobs(servers) + }) + + it('Should get the remote video with an unlogged user', async function () { + await servers[0].videos.get({ id: video2UUID }) + }) + + it('Should get the remote video with a logged in user', async function () { + await servers[0].videos.getWithToken({ token: userToken, id: video2UUID }) + }) + }) + + describe('When unfollowing a remote channel', function () { + + before(async function () { + this.timeout(60000) + + await servers[0].follows.unfollow({ target: 'root_channel@' + servers[1].host }) + await waitJobs(servers) + }) + + it('Should not get the remote video with an unlogged user', async function () { + const body = await servers[0].videos.get({ id: video2UUID, expectedStatus: HttpStatusCode.FORBIDDEN_403 }) + + const error = body as unknown as PeerTubeProblemDocument + expect(error.code).to.equal(ServerErrorCode.DOES_NOT_RESPECT_FOLLOW_CONSTRAINTS) + }) + + it('Should get the remote video with a logged in user', async function () { + await servers[0].videos.getWithToken({ token: userToken, id: video2UUID }) + }) + }) + after(async function () { await cleanupTests(servers) })