2020-01-31 15:56:52 +00:00
|
|
|
/* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
|
2018-01-03 15:38:50 +00:00
|
|
|
|
|
|
|
import 'mocha'
|
2021-07-07 11:38:26 +00:00
|
|
|
import * as chai from 'chai'
|
2018-02-15 13:46:26 +00:00
|
|
|
import {
|
2021-07-07 11:38:26 +00:00
|
|
|
checkActorFilesWereRemoved,
|
2019-03-19 09:53:53 +00:00
|
|
|
checkTmpIsEmpty,
|
2019-05-31 12:02:26 +00:00
|
|
|
checkVideoFilesWereRemoved,
|
|
|
|
cleanupTests,
|
2018-04-25 08:21:38 +00:00
|
|
|
doubleFollow,
|
|
|
|
flushAndRunMultipleServers,
|
2021-07-07 11:38:26 +00:00
|
|
|
ServerInfo,
|
|
|
|
setAccessTokensToServers,
|
|
|
|
testImage,
|
|
|
|
waitJobs
|
|
|
|
} from '@shared/extra-utils'
|
2021-07-09 09:21:30 +00:00
|
|
|
import { User } from '@shared/models'
|
2018-01-03 15:38:50 +00:00
|
|
|
|
|
|
|
const expect = chai.expect
|
|
|
|
|
|
|
|
describe('Test users with multiple servers', function () {
|
|
|
|
let servers: ServerInfo[] = []
|
2018-04-25 08:21:38 +00:00
|
|
|
let user: User
|
|
|
|
let userId: number
|
|
|
|
let videoUUID: string
|
|
|
|
let userAccessToken: string
|
2019-05-31 12:02:26 +00:00
|
|
|
let userAvatarFilename: string
|
2018-01-03 15:38:50 +00:00
|
|
|
|
|
|
|
before(async function () {
|
2021-01-19 12:43:33 +00:00
|
|
|
this.timeout(120_000)
|
2018-01-03 15:38:50 +00:00
|
|
|
|
|
|
|
servers = await flushAndRunMultipleServers(3)
|
|
|
|
|
|
|
|
// Get the access tokens
|
|
|
|
await setAccessTokensToServers(servers)
|
|
|
|
|
|
|
|
// 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 07:04:35 +00:00
|
|
|
await servers[0].videos.upload()
|
2018-01-03 15:38:50 +00:00
|
|
|
|
2018-04-25 08:21:38 +00:00
|
|
|
{
|
|
|
|
const user = {
|
|
|
|
username: 'user1',
|
|
|
|
password: 'password'
|
|
|
|
}
|
2021-07-16 07:04:35 +00:00
|
|
|
const created = await servers[0].users.create(user)
|
2021-07-13 12:23:01 +00:00
|
|
|
userId = created.id
|
2021-07-16 07:04:35 +00:00
|
|
|
userAccessToken = await servers[0].login.getAccessToken(user)
|
2018-04-25 08:21:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
{
|
2021-07-16 07:04:35 +00:00
|
|
|
const { uuid } = await servers[0].videos.upload({ token: userAccessToken })
|
2021-07-15 08:02:54 +00:00
|
|
|
videoUUID = uuid
|
2018-04-25 08:21:38 +00:00
|
|
|
}
|
2018-01-18 09:53:54 +00:00
|
|
|
|
2018-06-13 08:06:50 +00:00
|
|
|
await waitJobs(servers)
|
2018-01-03 15:38:50 +00:00
|
|
|
})
|
|
|
|
|
2018-04-26 08:03:40 +00:00
|
|
|
it('Should be able to update my display name', async function () {
|
|
|
|
this.timeout(10000)
|
|
|
|
|
2021-07-16 07:04:35 +00:00
|
|
|
await servers[0].users.updateMe({ displayName: 'my super display name' })
|
2019-05-31 12:02:26 +00:00
|
|
|
|
2021-07-16 07:04:35 +00:00
|
|
|
user = await servers[0].users.getMyInfo()
|
2018-04-26 08:03:40 +00:00
|
|
|
expect(user.account.displayName).to.equal('my super display name')
|
|
|
|
|
2018-06-13 08:06:50 +00:00
|
|
|
await waitJobs(servers)
|
2018-04-26 08:03:40 +00:00
|
|
|
})
|
|
|
|
|
2018-02-15 13:46:26 +00:00
|
|
|
it('Should be able to update my description', async function () {
|
2021-01-19 12:43:33 +00:00
|
|
|
this.timeout(10_000)
|
2018-02-15 13:46:26 +00:00
|
|
|
|
2021-07-16 07:04:35 +00:00
|
|
|
await servers[0].users.updateMe({ description: 'my super description updated' })
|
2018-02-15 13:46:26 +00:00
|
|
|
|
2021-07-16 07:04:35 +00:00
|
|
|
user = await servers[0].users.getMyInfo()
|
2018-04-26 08:03:40 +00:00
|
|
|
expect(user.account.displayName).to.equal('my super display name')
|
2018-02-15 13:46:26 +00:00
|
|
|
expect(user.account.description).to.equal('my super description updated')
|
|
|
|
|
2018-06-13 08:06:50 +00:00
|
|
|
await waitJobs(servers)
|
2018-02-15 13:46:26 +00:00
|
|
|
})
|
|
|
|
|
2018-01-03 15:38:50 +00:00
|
|
|
it('Should be able to update my avatar', async function () {
|
2021-01-19 12:43:33 +00:00
|
|
|
this.timeout(10_000)
|
2018-01-03 15:38:50 +00:00
|
|
|
|
|
|
|
const fixture = 'avatar2.png'
|
|
|
|
|
2021-07-16 07:04:35 +00:00
|
|
|
await servers[0].users.updateMyAvatar({ fixture })
|
2018-01-03 15:38:50 +00:00
|
|
|
|
2021-07-16 07:04:35 +00:00
|
|
|
user = await servers[0].users.getMyInfo()
|
2019-05-31 12:02:26 +00:00
|
|
|
userAvatarFilename = user.account.avatar.path
|
|
|
|
|
|
|
|
await testImage(servers[0].url, 'avatar2-resized', userAvatarFilename, '.png')
|
2018-01-03 15:38:50 +00:00
|
|
|
|
2018-06-13 08:06:50 +00:00
|
|
|
await waitJobs(servers)
|
2018-01-03 15:38:50 +00:00
|
|
|
})
|
|
|
|
|
2018-04-26 08:03:40 +00:00
|
|
|
it('Should have updated my profile on other servers too', async function () {
|
2021-05-07 06:59:59 +00:00
|
|
|
let createdAt: string | Date
|
|
|
|
|
2018-01-03 15:38:50 +00:00
|
|
|
for (const server of servers) {
|
2021-07-16 07:04:35 +00:00
|
|
|
const body = await server.accounts.list({ sort: '-createdAt' })
|
2018-01-03 15:38:50 +00:00
|
|
|
|
2021-07-07 11:38:26 +00:00
|
|
|
const resList = body.data.find(a => a.name === 'root' && a.host === 'localhost:' + servers[0].port)
|
2021-05-07 06:59:59 +00:00
|
|
|
expect(resList).not.to.be.undefined
|
|
|
|
|
2021-07-16 07:04:35 +00:00
|
|
|
const account = await server.accounts.get({ accountName: resList.name + '@' + resList.host })
|
2021-05-07 06:59:59 +00:00
|
|
|
|
|
|
|
if (!createdAt) createdAt = account.createdAt
|
2018-01-03 15:38:50 +00:00
|
|
|
|
2021-05-07 06:59:59 +00:00
|
|
|
expect(account.name).to.equal('root')
|
|
|
|
expect(account.host).to.equal('localhost:' + servers[0].port)
|
|
|
|
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 15:38:50 +00:00
|
|
|
|
2018-10-05 14:56:14 +00:00
|
|
|
if (server.serverNumber === 1) {
|
2021-05-07 06:59:59 +00:00
|
|
|
expect(account.userId).to.be.a('number')
|
2018-10-05 14:56:14 +00:00
|
|
|
} else {
|
2021-05-07 06:59:59 +00:00
|
|
|
expect(account.userId).to.be.undefined
|
2018-10-05 14:56:14 +00:00
|
|
|
}
|
|
|
|
|
2021-05-07 06:59:59 +00:00
|
|
|
await testImage(server.url, 'avatar2-resized', account.avatar.path, '.png')
|
2018-01-03 15:38:50 +00:00
|
|
|
}
|
|
|
|
})
|
|
|
|
|
2018-04-25 08:21:38 +00:00
|
|
|
it('Should list account videos', async function () {
|
|
|
|
for (const server of servers) {
|
2021-07-16 07:04:35 +00:00
|
|
|
const { total, data } = await server.videos.listByAccount({ accountName: 'user1@localhost:' + servers[0].port })
|
2018-04-25 08:21:38 +00:00
|
|
|
|
2021-07-15 08:02:54 +00: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 08:21:38 +00:00
|
|
|
}
|
|
|
|
})
|
|
|
|
|
2021-01-19 12:43:33 +00:00
|
|
|
it('Should search through account videos', async function () {
|
|
|
|
this.timeout(10_000)
|
|
|
|
|
2021-07-16 07:04:35 +00:00
|
|
|
const created = await servers[0].videos.upload({ token: userAccessToken, attributes: { name: 'Kami no chikara' } })
|
2021-01-19 12:43:33 +00:00
|
|
|
|
|
|
|
await waitJobs(servers)
|
|
|
|
|
|
|
|
for (const server of servers) {
|
2021-07-16 07:04:35 +00:00
|
|
|
const { total, data } = await server.videos.listByAccount({ accountName: 'user1@localhost:' + servers[0].port, search: 'Kami' })
|
2021-07-15 08:02:54 +00: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)
|
2021-01-19 12:43:33 +00:00
|
|
|
}
|
|
|
|
})
|
|
|
|
|
2018-01-18 09:53:54 +00:00
|
|
|
it('Should remove the user', async function () {
|
2021-01-19 12:43:33 +00:00
|
|
|
this.timeout(10_000)
|
2018-01-18 09:53:54 +00:00
|
|
|
|
|
|
|
for (const server of servers) {
|
2021-07-16 07:04:35 +00:00
|
|
|
const body = await server.accounts.list({ sort: '-createdAt' })
|
2018-01-18 09:53:54 +00:00
|
|
|
|
2021-07-07 11:38:26 +00:00
|
|
|
const accountDeleted = body.data.find(a => a.name === 'user1' && a.host === 'localhost:' + servers[0].port)
|
2018-04-25 08:21:38 +00:00
|
|
|
expect(accountDeleted).not.to.be.undefined
|
|
|
|
|
2021-07-16 07:04:35 +00:00
|
|
|
const { data } = await server.channels.list()
|
2021-07-09 09:21:30 +00:00
|
|
|
const videoChannelDeleted = data.find(a => a.displayName === 'Main user1 channel' && a.host === 'localhost:' + servers[0].port)
|
2018-04-25 08:21:38 +00:00
|
|
|
expect(videoChannelDeleted).not.to.be.undefined
|
2018-01-18 09:53:54 +00:00
|
|
|
}
|
|
|
|
|
2021-07-16 07:04:35 +00:00
|
|
|
await servers[0].users.remove({ userId })
|
2018-01-18 09:53:54 +00:00
|
|
|
|
2018-06-13 08:06:50 +00:00
|
|
|
await waitJobs(servers)
|
2018-01-18 09:53:54 +00:00
|
|
|
|
|
|
|
for (const server of servers) {
|
2021-07-16 07:04:35 +00:00
|
|
|
const body = await server.accounts.list({ sort: '-createdAt' })
|
2018-01-18 09:53:54 +00:00
|
|
|
|
2021-07-07 11:38:26 +00:00
|
|
|
const accountDeleted = body.data.find(a => a.name === 'user1' && a.host === 'localhost:' + servers[0].port)
|
2018-04-25 08:21:38 +00:00
|
|
|
expect(accountDeleted).to.be.undefined
|
|
|
|
|
2021-07-16 07:04:35 +00:00
|
|
|
const { data } = await server.channels.list()
|
2021-07-09 09:21:30 +00:00
|
|
|
const videoChannelDeleted = data.find(a => a.name === 'Main user1 channel' && a.host === 'localhost:' + servers[0].port)
|
2018-04-25 08:21:38 +00:00
|
|
|
expect(videoChannelDeleted).to.be.undefined
|
2018-01-18 09:53:54 +00:00
|
|
|
}
|
|
|
|
})
|
|
|
|
|
|
|
|
it('Should not have actor files', async () => {
|
|
|
|
for (const server of servers) {
|
2019-05-31 12:02:26 +00:00
|
|
|
await checkActorFilesWereRemoved(userAvatarFilename, server.internalServerNumber)
|
2018-01-18 09:53:54 +00:00
|
|
|
}
|
|
|
|
})
|
|
|
|
|
|
|
|
it('Should not have video files', async () => {
|
|
|
|
for (const server of servers) {
|
2021-07-13 07:43:59 +00:00
|
|
|
await checkVideoFilesWereRemoved(videoUUID, server)
|
2018-01-18 09:53:54 +00:00
|
|
|
}
|
|
|
|
})
|
|
|
|
|
2019-03-19 09:53:53 +00:00
|
|
|
it('Should have an empty tmp directory', async function () {
|
|
|
|
for (const server of servers) {
|
|
|
|
await checkTmpIsEmpty(server)
|
|
|
|
}
|
|
|
|
})
|
|
|
|
|
2019-04-24 13:10:37 +00:00
|
|
|
after(async function () {
|
|
|
|
await cleanupTests(servers)
|
2018-01-03 15:38:50 +00:00
|
|
|
})
|
|
|
|
})
|