1
0
Fork 0
peertube/server/tests/api/server/follow-constraints.ts

246 lines
8.8 KiB
TypeScript
Raw Normal View History

2020-01-31 15:56:52 +00:00
/* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
import 'mocha'
2021-07-07 07:16:40 +00:00
import * as chai from 'chai'
import { HttpStatusCode } from '@shared/core-utils'
import { PeerTubeProblemDocument, ServerErrorCode } from '@shared/models'
2018-11-20 07:03:52 +00:00
import {
cleanupTests,
2018-11-20 07:03:52 +00:00
doubleFollow,
flushAndRunMultipleServers,
2018-11-20 07:03:52 +00:00
getAccountVideos,
getVideo,
getVideoChannelVideos,
getVideoWithToken,
ServerInfo,
setAccessTokensToServers,
2021-07-13 09:05:15 +00:00
uploadVideo
} from '../../../../shared/extra-utils'
const expect = chai.expect
describe('Test follow constraints', function () {
let servers: ServerInfo[] = []
let video1UUID: string
let video2UUID: string
let userAccessToken: string
before(async function () {
2021-05-10 11:56:26 +00:00
this.timeout(90000)
servers = await flushAndRunMultipleServers(2)
// Get the access tokens
await setAccessTokensToServers(servers)
{
2020-01-31 15:56:52 +00:00
const res = await uploadVideo(servers[0].url, servers[0].accessToken, { name: 'video server 1' })
video1UUID = res.body.video.uuid
}
{
2020-01-31 15:56:52 +00:00
const res = await uploadVideo(servers[1].url, servers[1].accessToken, { name: 'video server 2' })
video2UUID = res.body.video.uuid
}
const user = {
username: 'user1',
password: 'super_password'
}
2021-07-13 12:23:01 +00:00
await servers[0].usersCommand.create({ username: user.username, password: user.password })
2021-07-13 09:05:15 +00:00
userAccessToken = await servers[0].loginCommand.getAccessToken(user)
await doubleFollow(servers[0], servers[1])
})
describe('With a followed instance', function () {
describe('With an unlogged user', function () {
it('Should get the local video', async function () {
await getVideo(servers[0].url, video1UUID, HttpStatusCode.OK_200)
})
it('Should get the remote video', async function () {
await getVideo(servers[0].url, video2UUID, HttpStatusCode.OK_200)
})
it('Should list local account videos', async function () {
const res = await getAccountVideos(servers[0].url, undefined, 'root@localhost:' + servers[0].port, 0, 5)
expect(res.body.total).to.equal(1)
expect(res.body.data).to.have.lengthOf(1)
})
it('Should list remote account videos', async function () {
const res = await getAccountVideos(servers[0].url, undefined, 'root@localhost:' + servers[1].port, 0, 5)
expect(res.body.total).to.equal(1)
expect(res.body.data).to.have.lengthOf(1)
})
it('Should list local channel videos', async function () {
const videoChannelName = 'root_channel@localhost:' + servers[0].port
const res = await getVideoChannelVideos(servers[0].url, undefined, videoChannelName, 0, 5)
expect(res.body.total).to.equal(1)
expect(res.body.data).to.have.lengthOf(1)
})
it('Should list remote channel videos', async function () {
const videoChannelName = 'root_channel@localhost:' + servers[1].port
const res = await getVideoChannelVideos(servers[0].url, undefined, videoChannelName, 0, 5)
expect(res.body.total).to.equal(1)
expect(res.body.data).to.have.lengthOf(1)
})
})
describe('With a logged user', function () {
it('Should get the local video', async function () {
await getVideoWithToken(servers[0].url, userAccessToken, video1UUID, HttpStatusCode.OK_200)
})
it('Should get the remote video', async function () {
await getVideoWithToken(servers[0].url, userAccessToken, video2UUID, HttpStatusCode.OK_200)
})
it('Should list local account videos', async function () {
const res = await getAccountVideos(servers[0].url, userAccessToken, 'root@localhost:' + servers[0].port, 0, 5)
expect(res.body.total).to.equal(1)
expect(res.body.data).to.have.lengthOf(1)
})
it('Should list remote account videos', async function () {
const res = await getAccountVideos(servers[0].url, userAccessToken, 'root@localhost:' + servers[1].port, 0, 5)
expect(res.body.total).to.equal(1)
expect(res.body.data).to.have.lengthOf(1)
})
it('Should list local channel videos', async function () {
const videoChannelName = 'root_channel@localhost:' + servers[0].port
const res = await getVideoChannelVideos(servers[0].url, userAccessToken, videoChannelName, 0, 5)
expect(res.body.total).to.equal(1)
expect(res.body.data).to.have.lengthOf(1)
})
it('Should list remote channel videos', async function () {
const videoChannelName = 'root_channel@localhost:' + servers[1].port
const res = await getVideoChannelVideos(servers[0].url, userAccessToken, videoChannelName, 0, 5)
expect(res.body.total).to.equal(1)
expect(res.body.data).to.have.lengthOf(1)
})
})
})
describe('With a non followed instance', function () {
before(async function () {
this.timeout(30000)
2021-07-07 07:16:40 +00:00
await servers[0].followsCommand.unfollow({ target: servers[1] })
})
describe('With an unlogged user', function () {
it('Should get the local video', async function () {
await getVideo(servers[0].url, video1UUID, HttpStatusCode.OK_200)
})
it('Should not get the remote video', async function () {
2021-06-02 16:15:41 +00:00
const res = await getVideo(servers[0].url, video2UUID, HttpStatusCode.FORBIDDEN_403)
const error = res.body as PeerTubeProblemDocument
const doc = 'https://docs.joinpeertube.org/api-rest-reference.html#section/Errors/does_not_respect_follow_constraints'
expect(error.type).to.equal(doc)
expect(error.code).to.equal(ServerErrorCode.DOES_NOT_RESPECT_FOLLOW_CONSTRAINTS)
expect(error.detail).to.equal('Cannot get this video regarding follow constraints')
expect(error.error).to.equal(error.detail)
expect(error.status).to.equal(HttpStatusCode.FORBIDDEN_403)
expect(error.originUrl).to.contains(servers[1].url)
})
it('Should list local account videos', async function () {
const res = await getAccountVideos(servers[0].url, undefined, 'root@localhost:' + servers[0].port, 0, 5)
expect(res.body.total).to.equal(1)
expect(res.body.data).to.have.lengthOf(1)
})
it('Should not list remote account videos', async function () {
const res = await getAccountVideos(servers[0].url, undefined, 'root@localhost:' + servers[1].port, 0, 5)
expect(res.body.total).to.equal(0)
expect(res.body.data).to.have.lengthOf(0)
})
it('Should list local channel videos', async function () {
const videoChannelName = 'root_channel@localhost:' + servers[0].port
const res = await getVideoChannelVideos(servers[0].url, undefined, videoChannelName, 0, 5)
expect(res.body.total).to.equal(1)
expect(res.body.data).to.have.lengthOf(1)
})
it('Should not list remote channel videos', async function () {
const videoChannelName = 'root_channel@localhost:' + servers[1].port
const res = await getVideoChannelVideos(servers[0].url, undefined, videoChannelName, 0, 5)
expect(res.body.total).to.equal(0)
expect(res.body.data).to.have.lengthOf(0)
})
})
describe('With a logged user', function () {
it('Should get the local video', async function () {
await getVideoWithToken(servers[0].url, userAccessToken, video1UUID, HttpStatusCode.OK_200)
})
it('Should get the remote video', async function () {
await getVideoWithToken(servers[0].url, userAccessToken, video2UUID, HttpStatusCode.OK_200)
})
it('Should list local account videos', async function () {
const res = await getAccountVideos(servers[0].url, userAccessToken, 'root@localhost:' + servers[0].port, 0, 5)
expect(res.body.total).to.equal(1)
expect(res.body.data).to.have.lengthOf(1)
})
it('Should list remote account videos', async function () {
const res = await getAccountVideos(servers[0].url, userAccessToken, 'root@localhost:' + servers[1].port, 0, 5)
expect(res.body.total).to.equal(1)
expect(res.body.data).to.have.lengthOf(1)
})
it('Should list local channel videos', async function () {
const videoChannelName = 'root_channel@localhost:' + servers[0].port
const res = await getVideoChannelVideos(servers[0].url, userAccessToken, videoChannelName, 0, 5)
expect(res.body.total).to.equal(1)
expect(res.body.data).to.have.lengthOf(1)
})
it('Should list remote channel videos', async function () {
const videoChannelName = 'root_channel@localhost:' + servers[1].port
const res = await getVideoChannelVideos(servers[0].url, userAccessToken, videoChannelName, 0, 5)
expect(res.body.total).to.equal(1)
expect(res.body.data).to.have.lengthOf(1)
})
})
})
2019-04-24 13:10:37 +00:00
after(async function () {
await cleanupTests(servers)
})
})