PeerTube/server/tests/api/users/users-multiple-servers.ts

217 lines
6.6 KiB
TypeScript
Raw Normal View History

2020-01-31 09:56:52 -06:00
/* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
2018-01-03 09:38:50 -06:00
2022-08-17 08:44:32 -05:00
import { expect } from 'chai'
import {
2021-07-07 06:38:26 -05:00
checkActorFilesWereRemoved,
2019-03-19 04:53:53 -05:00
checkTmpIsEmpty,
2019-05-31 07:02:26 -05:00
checkVideoFilesWereRemoved,
saveVideoInServers,
testImage
} from '@server/tests/shared'
import { MyUser } from '@shared/models'
import {
2019-05-31 07:02:26 -05:00
cleanupTests,
2021-07-16 02:47:51 -05:00
createMultipleServers,
2021-07-16 07:27:30 -05:00
doubleFollow,
2021-07-16 02:47:51 -05:00
PeerTubeServer,
2021-07-07 06:38:26 -05:00
setAccessTokensToServers,
setDefaultChannelAvatar,
2021-07-07 06:38:26 -05:00
waitJobs
} from '@shared/server-commands'
2018-01-03 09:38:50 -06:00
describe('Test users with multiple servers', function () {
2021-07-16 02:47:51 -05:00
let servers: PeerTubeServer[] = []
2021-07-22 07:28:03 -05:00
let user: MyUser
2018-04-25 03:21:38 -05:00
let userId: number
2021-07-22 07:28:03 -05:00
2018-04-25 03:21:38 -05:00
let videoUUID: string
let userAccessToken: string
let userAvatarFilenames: string[]
2018-01-03 09:38:50 -06:00
before(async function () {
this.timeout(120_000)
2018-01-03 09:38:50 -06:00
2021-07-16 02:47:51 -05:00
servers = await createMultipleServers(3)
2018-01-03 09:38:50 -06:00
// Get the access tokens
await setAccessTokensToServers(servers)
await setDefaultChannelAvatar(servers)
2018-01-03 09:38:50 -06:00
// Server 1 and server 2 follow each other
await doubleFollow(servers[0], servers[1])
// Server 1 and server 3 follow each other
await doubleFollow(servers[0], servers[2])
// Server 2 and server 3 follow each other
await doubleFollow(servers[1], servers[2])
// The root user of server 1 is propagated to servers 2 and 3
2021-07-16 02:04:35 -05:00
await servers[0].videos.upload()
2018-01-03 09:38:50 -06:00
2018-04-25 03:21:38 -05:00
{
2021-07-22 07:28:03 -05:00
const username = 'user1'
const created = await servers[0].users.create({ username })
2021-07-13 07:23:01 -05:00
userId = created.id
2021-07-22 07:28:03 -05:00
userAccessToken = await servers[0].login.getAccessToken(username)
2018-04-25 03:21:38 -05:00
}
{
2021-07-16 02:04:35 -05:00
const { uuid } = await servers[0].videos.upload({ token: userAccessToken })
2021-07-15 03:02:54 -05:00
videoUUID = uuid
2021-07-22 07:28:03 -05:00
2021-07-23 04:20:00 -05:00
await waitJobs(servers)
2021-07-22 07:28:03 -05:00
await saveVideoInServers(servers, videoUUID)
2018-04-25 03:21:38 -05:00
}
2018-01-03 09:38:50 -06:00
})
it('Should be able to update my display name', async function () {
2021-07-16 02:04:35 -05:00
await servers[0].users.updateMe({ displayName: 'my super display name' })
2019-05-31 07:02:26 -05:00
2021-07-16 02:04:35 -05:00
user = await servers[0].users.getMyInfo()
expect(user.account.displayName).to.equal('my super display name')
await waitJobs(servers)
})
it('Should be able to update my description', async function () {
this.timeout(10_000)
2021-07-16 02:04:35 -05:00
await servers[0].users.updateMe({ description: 'my super description updated' })
2021-07-16 02:04:35 -05:00
user = await servers[0].users.getMyInfo()
expect(user.account.displayName).to.equal('my super display name')
expect(user.account.description).to.equal('my super description updated')
await waitJobs(servers)
})
2018-01-03 09:38:50 -06:00
it('Should be able to update my avatar', async function () {
this.timeout(10_000)
2018-01-03 09:38:50 -06:00
const fixture = 'avatar2.png'
2021-07-16 02:04:35 -05:00
await servers[0].users.updateMyAvatar({ fixture })
2018-01-03 09:38:50 -06:00
2021-07-16 02:04:35 -05:00
user = await servers[0].users.getMyInfo()
userAvatarFilenames = user.account.avatars.map(({ path }) => path)
2019-05-31 07:02:26 -05:00
for (const avatar of user.account.avatars) {
await testImage(servers[0].url, `avatar2-resized-${avatar.width}x${avatar.width}`, avatar.path, '.png')
}
2018-01-03 09:38:50 -06:00
await waitJobs(servers)
2018-01-03 09:38:50 -06:00
})
it('Should have updated my profile on other servers too', async function () {
2021-05-07 01:59:59 -05:00
let createdAt: string | Date
2018-01-03 09:38:50 -06:00
for (const server of servers) {
2021-07-16 02:04:35 -05:00
const body = await server.accounts.list({ sort: '-createdAt' })
2018-01-03 09:38:50 -06:00
2022-12-09 04:14:47 -06:00
const resList = body.data.find(a => a.name === 'root' && a.host === servers[0].host)
2021-05-07 01:59:59 -05:00
expect(resList).not.to.be.undefined
2021-07-16 02:04:35 -05:00
const account = await server.accounts.get({ accountName: resList.name + '@' + resList.host })
2021-05-07 01:59:59 -05:00
if (!createdAt) createdAt = account.createdAt
2018-01-03 09:38:50 -06:00
2021-05-07 01:59:59 -05:00
expect(account.name).to.equal('root')
2022-12-09 04:14:47 -06:00
expect(account.host).to.equal(servers[0].host)
2021-05-07 01:59:59 -05:00
expect(account.displayName).to.equal('my super display name')
expect(account.description).to.equal('my super description updated')
expect(createdAt).to.equal(account.createdAt)
2018-01-03 09:38:50 -06:00
if (server.serverNumber === 1) {
2021-05-07 01:59:59 -05:00
expect(account.userId).to.be.a('number')
} else {
2021-05-07 01:59:59 -05:00
expect(account.userId).to.be.undefined
}
for (const avatar of account.avatars) {
await testImage(server.url, `avatar2-resized-${avatar.width}x${avatar.width}`, avatar.path, '.png')
}
2018-01-03 09:38:50 -06:00
}
})
2018-04-25 03:21:38 -05:00
it('Should list account videos', async function () {
for (const server of servers) {
2022-12-09 04:14:47 -06:00
const { total, data } = await server.videos.listByAccount({ handle: 'user1@' + servers[0].host })
2018-04-25 03:21:38 -05:00
2021-07-15 03:02:54 -05:00
expect(total).to.equal(1)
expect(data).to.be.an('array')
expect(data).to.have.lengthOf(1)
expect(data[0].uuid).to.equal(videoUUID)
2018-04-25 03:21:38 -05:00
}
})
it('Should search through account videos', async function () {
2021-07-16 02:04:35 -05:00
const created = await servers[0].videos.upload({ token: userAccessToken, attributes: { name: 'Kami no chikara' } })
await waitJobs(servers)
for (const server of servers) {
2022-12-09 04:14:47 -06:00
const { total, data } = await server.videos.listByAccount({ handle: 'user1@' + servers[0].host, search: 'Kami' })
2021-07-15 03:02:54 -05:00
expect(total).to.equal(1)
expect(data).to.be.an('array')
expect(data).to.have.lengthOf(1)
expect(data[0].uuid).to.equal(created.uuid)
}
})
it('Should remove the user', async function () {
this.timeout(10_000)
for (const server of servers) {
2021-07-16 02:04:35 -05:00
const body = await server.accounts.list({ sort: '-createdAt' })
2022-12-09 04:14:47 -06:00
const accountDeleted = body.data.find(a => a.name === 'user1' && a.host === servers[0].host)
2018-04-25 03:21:38 -05:00
expect(accountDeleted).not.to.be.undefined
2021-07-16 02:04:35 -05:00
const { data } = await server.channels.list()
2022-12-09 04:14:47 -06:00
const videoChannelDeleted = data.find(a => a.displayName === 'Main user1 channel' && a.host === servers[0].host)
2018-04-25 03:21:38 -05:00
expect(videoChannelDeleted).not.to.be.undefined
}
2021-07-16 02:04:35 -05:00
await servers[0].users.remove({ userId })
await waitJobs(servers)
for (const server of servers) {
2021-07-16 02:04:35 -05:00
const body = await server.accounts.list({ sort: '-createdAt' })
2022-12-09 04:14:47 -06:00
const accountDeleted = body.data.find(a => a.name === 'user1' && a.host === servers[0].host)
2018-04-25 03:21:38 -05:00
expect(accountDeleted).to.be.undefined
2021-07-16 02:04:35 -05:00
const { data } = await server.channels.list()
2022-12-09 04:14:47 -06:00
const videoChannelDeleted = data.find(a => a.name === 'Main user1 channel' && a.host === servers[0].host)
2018-04-25 03:21:38 -05:00
expect(videoChannelDeleted).to.be.undefined
}
})
it('Should not have actor files', async () => {
for (const server of servers) {
for (const userAvatarFilename of userAvatarFilenames) {
await checkActorFilesWereRemoved(userAvatarFilename, server)
}
}
})
it('Should not have video files', async () => {
for (const server of servers) {
2021-07-22 07:28:03 -05:00
await checkVideoFilesWereRemoved({ server, video: server.store.videoDetails })
}
})
2019-03-19 04:53:53 -05:00
it('Should have an empty tmp directory', async function () {
for (const server of servers) {
await checkTmpIsEmpty(server)
}
})
2019-04-24 08:10:37 -05:00
after(async function () {
await cleanupTests(servers)
2018-01-03 09:38:50 -06:00
})
})