2020-01-31 09:56:52 -06:00
|
|
|
/* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
|
2018-11-14 09:32:12 -06:00
|
|
|
|
|
|
|
import 'mocha'
|
2021-07-09 08:37:43 -05:00
|
|
|
import * as chai from 'chai'
|
2018-11-14 09:32:12 -06:00
|
|
|
import {
|
2019-04-26 01:50:52 -05:00
|
|
|
cleanupTests,
|
2018-11-14 09:32:12 -06:00
|
|
|
createUser,
|
|
|
|
doubleFollow,
|
|
|
|
flushAndRunMultipleServers,
|
|
|
|
getVideosListSort,
|
|
|
|
ServerInfo,
|
|
|
|
setAccessTokensToServers,
|
|
|
|
uploadVideo,
|
2018-12-07 09:09:57 -06:00
|
|
|
userLogin,
|
|
|
|
waitJobs
|
2019-04-15 08:26:15 -05:00
|
|
|
} from '../../../../shared/extra-utils'
|
2018-11-14 09:32:12 -06:00
|
|
|
import { Video } from '../../../../shared/models/videos'
|
|
|
|
|
|
|
|
const expect = chai.expect
|
|
|
|
|
|
|
|
describe('Test ActivityPub fetcher', function () {
|
|
|
|
let servers: ServerInfo[]
|
|
|
|
|
|
|
|
// ---------------------------------------------------------------
|
|
|
|
|
|
|
|
before(async function () {
|
|
|
|
this.timeout(60000)
|
|
|
|
|
|
|
|
servers = await flushAndRunMultipleServers(3)
|
|
|
|
|
|
|
|
// Get the access tokens
|
|
|
|
await setAccessTokensToServers(servers)
|
|
|
|
|
|
|
|
const user = { username: 'user1', password: 'password' }
|
|
|
|
for (const server of servers) {
|
2019-04-15 03:49:46 -05:00
|
|
|
await createUser({ url: server.url, accessToken: server.accessToken, username: user.username, password: user.password })
|
2018-11-14 09:32:12 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
const userAccessToken = await userLogin(servers[0], user)
|
|
|
|
|
|
|
|
await uploadVideo(servers[0].url, servers[0].accessToken, { name: 'video root' })
|
|
|
|
const res = await uploadVideo(servers[0].url, servers[0].accessToken, { name: 'bad video root' })
|
|
|
|
const badVideoUUID = res.body.video.uuid
|
|
|
|
await uploadVideo(servers[0].url, userAccessToken, { name: 'video user' })
|
|
|
|
|
2019-04-26 01:50:52 -05:00
|
|
|
{
|
|
|
|
const to = 'http://localhost:' + servers[0].port + '/accounts/user1'
|
|
|
|
const value = 'http://localhost:' + servers[1].port + '/accounts/user1'
|
2021-07-09 08:37:43 -05:00
|
|
|
await servers[0].sqlCommand.setActorField(to, 'url', value)
|
2019-04-26 01:50:52 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
{
|
|
|
|
const value = 'http://localhost:' + servers[2].port + '/videos/watch/' + badVideoUUID
|
2021-07-09 08:37:43 -05:00
|
|
|
await servers[0].sqlCommand.setVideoField(badVideoUUID, 'url', value)
|
2019-04-26 01:50:52 -05:00
|
|
|
}
|
2018-11-14 09:32:12 -06:00
|
|
|
})
|
|
|
|
|
|
|
|
it('Should add only the video with a valid actor URL', async function () {
|
|
|
|
this.timeout(60000)
|
|
|
|
|
|
|
|
await doubleFollow(servers[0], servers[1])
|
|
|
|
await waitJobs(servers)
|
|
|
|
|
|
|
|
{
|
|
|
|
const res = await getVideosListSort(servers[0].url, 'createdAt')
|
|
|
|
expect(res.body.total).to.equal(3)
|
|
|
|
|
|
|
|
const data: Video[] = res.body.data
|
|
|
|
expect(data[0].name).to.equal('video root')
|
|
|
|
expect(data[1].name).to.equal('bad video root')
|
|
|
|
expect(data[2].name).to.equal('video user')
|
|
|
|
}
|
|
|
|
|
|
|
|
{
|
|
|
|
const res = await getVideosListSort(servers[1].url, 'createdAt')
|
|
|
|
expect(res.body.total).to.equal(1)
|
|
|
|
|
|
|
|
const data: Video[] = res.body.data
|
|
|
|
expect(data[0].name).to.equal('video root')
|
|
|
|
}
|
|
|
|
})
|
|
|
|
|
|
|
|
after(async function () {
|
2019-07-29 04:59:29 -05:00
|
|
|
this.timeout(20000)
|
2019-04-26 01:50:52 -05:00
|
|
|
|
|
|
|
await cleanupTests(servers)
|
2018-11-14 09:32:12 -06:00
|
|
|
})
|
|
|
|
})
|