import * as chai from 'chai'
import {
cleanupTests,
+ createMultipleServers,
doubleFollow,
- flushAndRunMultipleServers,
- getVideosList,
- ServerInfo,
+ PeerTubeServer,
setAccessTokensToServers,
SubscriptionsCommand,
- updateVideo,
- uploadVideo,
waitJobs
} from '@shared/extra-utils'
const expect = chai.expect
describe('Test users subscriptions', function () {
- let servers: ServerInfo[] = []
+ let servers: PeerTubeServer[] = []
const users: { accessToken: string }[] = []
let video3UUID: string
before(async function () {
this.timeout(120000)
- servers = await flushAndRunMultipleServers(3)
+ servers = await createMultipleServers(3)
// Get the access tokens
await setAccessTokensToServers(servers)
{
for (const server of servers) {
const user = { username: 'user' + server.serverNumber, password: 'password' }
- await server.usersCommand.create({ username: user.username, password: user.password })
+ await server.users.create({ username: user.username, password: user.password })
- const accessToken = await server.loginCommand.getAccessToken(user)
+ const accessToken = await server.login.getAccessToken(user)
users.push({ accessToken })
const videoName1 = 'video 1-' + server.serverNumber
- await uploadVideo(server.url, accessToken, { name: videoName1 })
+ await server.videos.upload({ token: accessToken, attributes: { name: videoName1 } })
const videoName2 = 'video 2-' + server.serverNumber
- await uploadVideo(server.url, accessToken, { name: videoName2 })
+ await server.videos.upload({ token: accessToken, attributes: { name: videoName2 } })
}
}
await waitJobs(servers)
- command = servers[0].subscriptionsCommand
+ command = servers[0].subscriptions
})
it('Should display videos of server 2 on server 1', async function () {
- const res = await getVideosList(servers[0].url)
+ const { total } = await servers[0].videos.list()
- expect(res.body.total).to.equal(4)
+ expect(total).to.equal(4)
})
it('User of server 1 should follow user of server 3 and root of server 1', async function () {
await waitJobs(servers)
- const res = await uploadVideo(servers[2].url, users[2].accessToken, { name: 'video server 3 added after follow' })
- video3UUID = res.body.video.uuid
+ const attributes = { name: 'video server 3 added after follow' }
+ const { uuid } = await servers[2].videos.upload({ token: users[2].accessToken, attributes })
+ video3UUID = uuid
await waitJobs(servers)
})
it('Should not display videos of server 3 on server 1', async function () {
- const res = await getVideosList(servers[0].url)
+ const { total, data } = await servers[0].videos.list()
+ expect(total).to.equal(4)
- expect(res.body.total).to.equal(4)
- for (const video of res.body.data) {
+ for (const video of data) {
expect(video.name).to.not.contain('1-3')
expect(video.name).to.not.contain('2-3')
expect(video.name).to.not.contain('video server 3 added after follow')
this.timeout(60000)
const videoName = 'video server 1 added after follow'
- await uploadVideo(servers[0].url, servers[0].accessToken, { name: videoName })
+ await servers[0].videos.upload({ attributes: { name: videoName } })
await waitJobs(servers)
}
{
- const res = await getVideosList(servers[0].url)
+ const { data, total } = await servers[0].videos.list()
+ expect(total).to.equal(5)
- expect(res.body.total).to.equal(5)
- for (const video of res.body.data) {
+ for (const video of data) {
expect(video.name).to.not.contain('1-3')
expect(video.name).to.not.contain('2-3')
expect(video.name).to.not.contain('video server 3 added after follow')
it('Should have server 1 follow server 3 and display server 3 videos', async function () {
this.timeout(60000)
- await servers[0].followsCommand.follow({ targets: [ servers[2].url ] })
+ await servers[0].follows.follow({ hosts: [ servers[2].url ] })
await waitJobs(servers)
- const res = await getVideosList(servers[0].url)
-
- expect(res.body.total).to.equal(8)
+ const { data, total } = await servers[0].videos.list()
+ expect(total).to.equal(8)
const names = [ '1-3', '2-3', 'video server 3 added after follow' ]
for (const name of names) {
- const video = res.body.data.find(v => v.name.indexOf(name) === -1)
+ const video = data.find(v => v.name.includes(name))
expect(video).to.not.be.undefined
}
})
it('Should remove follow server 1 -> server 3 and hide server 3 videos', async function () {
this.timeout(60000)
- await servers[0].followsCommand.unfollow({ target: servers[2] })
+ await servers[0].follows.unfollow({ target: servers[2] })
await waitJobs(servers)
- const res = await getVideosList(servers[0].url)
+ const { total, data } = await servers[0].videos.list()
+ expect(total).to.equal(5)
- expect(res.body.total).to.equal(5)
- for (const video of res.body.data) {
+ for (const video of data) {
expect(video.name).to.not.contain('1-3')
expect(video.name).to.not.contain('2-3')
expect(video.name).to.not.contain('video server 3 added after follow')
it('Should update a video of server 3 and see the updated video on server 1', async function () {
this.timeout(30000)
- await updateVideo(servers[2].url, users[2].accessToken, video3UUID, { name: 'video server 3 added after follow updated' })
+ await servers[2].videos.update({ id: video3UUID, attributes: { name: 'video server 3 added after follow updated' } })
await waitJobs(servers)
})
it('Should correctly display public videos on server 1', async function () {
- const res = await getVideosList(servers[0].url)
+ const { total, data } = await servers[0].videos.list()
+ expect(total).to.equal(5)
- expect(res.body.total).to.equal(5)
- for (const video of res.body.data) {
+ for (const video of data) {
expect(video.name).to.not.contain('1-3')
expect(video.name).to.not.contain('2-3')
expect(video.name).to.not.contain('video server 3 added after follow updated')
}
{
- const res = await getVideosList(servers[0].url)
+ const { total, data } = await servers[0].videos.list()
+ expect(total).to.equal(5)
- expect(res.body.total).to.equal(5)
- for (const video of res.body.data) {
+ for (const video of data) {
expect(video.name).to.not.contain('1-3')
expect(video.name).to.not.contain('2-3')
expect(video.name).to.not.contain('video server 3 added after follow updated')