-import 'mocha'
-import * as chai from 'chai'
+import { expect } from 'chai'
+import { AbuseMessage, AbusePredefinedReasonsString, AbuseState, AdminAbuse, UserAbuse } from '@shared/models'
-} from '@shared/extra-utils'
-import { AbuseMessage, AbusePredefinedReasonsString, AbuseState, AdminAbuse, UserAbuse } from '@shared/models'
-
-const expect = chai.expect
+} from '@shared/server-commands'
let abuseServer1: AdminAbuse
let abuseServer2: AdminAbuse
let commands: AbusesCommand[]
let abuseServer1: AdminAbuse
let abuseServer2: AdminAbuse
let commands: AbusesCommand[]
// Server 1 and server 2 follow each other
await doubleFollow(servers[0], servers[1])
// Server 1 and server 2 follow each other
await doubleFollow(servers[0], servers[1])
- const video1Attributes = {
- name: 'my super name for server 1',
- description: 'my super description for server 1'
+ {
+ const attributes = {
+ name: 'my super name for server 1',
+ description: 'my super description for server 1'
+ }
+ await servers[0].videos.upload({ attributes })
- const video2Attributes = {
- name: 'my super name for server 2',
- description: 'my super description for server 2'
+ {
+ const attributes = {
+ name: 'my super name for server 2',
+ description: 'my super description for server 2'
+ }
+ await servers[1].videos.upload({ attributes })
- const res = await getVideosList(servers[0].url)
- const videos = res.body.data
-
- expect(videos.length).to.equal(2)
+ const { data } = await servers[0].videos.list()
+ expect(data.length).to.equal(2)
- servers[0].video = videos.find(video => video.name === 'my super name for server 1')
- servers[1].video = videos.find(video => video.name === 'my super name for server 2')
+ servers[0].store.videoCreated = data.find(video => video.name === 'my super name for server 1')
+ servers[1].store.videoCreated = data.find(video => video.name === 'my super name for server 2')
expect(abuse.reporterAccount.name).to.equal('root')
expect(abuse.reporterAccount.host).to.equal(servers[0].host)
expect(abuse.reporterAccount.name).to.equal('root')
expect(abuse.reporterAccount.host).to.equal(servers[0].host)
await commands[0].report({ videoId, reason })
// We wait requests propagation
await commands[0].report({ videoId, reason })
// We wait requests propagation
expect(abuse1.reporterAccount.name).to.equal('root')
expect(abuse1.reporterAccount.host).to.equal(servers[0].host)
expect(abuse1.reporterAccount.name).to.equal('root')
expect(abuse1.reporterAccount.host).to.equal(servers[0].host)
expect(abuse2.reporterAccount.name).to.equal('root')
expect(abuse2.reporterAccount.host).to.equal(servers[0].host)
expect(abuse2.reporterAccount.name).to.equal('root')
expect(abuse2.reporterAccount.host).to.equal(servers[0].host)
- expect(body.total).to.equal(2, "wrong number of videos returned")
- expect(body.data).to.have.lengthOf(2, "wrong number of videos returned")
+ expect(body.total).to.equal(2, 'wrong number of videos returned')
+ expect(body.data).to.have.lengthOf(2, 'wrong number of videos returned')
- expect(abuse.id).to.equal(abuseServer2.id, "wrong origin server id for first video")
- expect(abuse.video.id).to.equal(abuseServer2.video.id, "wrong video id")
+ expect(abuse.id).to.equal(abuseServer2.id, 'wrong origin server id for first video')
+ expect(abuse.video.id).to.equal(abuseServer2.video.id, 'wrong video id')
// register a second user to have two reporters/reportees
const user = { username: 'user2', password: 'password' }
// register a second user to have two reporters/reportees
const user = { username: 'user2', password: 'password' }
- await createUser({ url: servers[0].url, accessToken: servers[0].accessToken, ...user })
- const userAccessToken = await userLogin(servers[0], user)
+ await servers[0].users.create({ ...user })
+ const userAccessToken = await servers[0].login.getAccessToken(user)
name: 'my second super name for server 1',
description: 'my second super description for server 1'
}
name: 'my second super name for server 1',
description: 'my second super description for server 1'
}
- const resUpload = await uploadVideo(servers[0].url, userAccessToken, video3Attributes)
- const video3Id = resUpload.body.video.id
+ const { id } = await servers[0].videos.upload({ token: userAccessToken, attributes })
+ const video3Id = id
// resume with the test
const reason3 = 'my super bad reason 3'
await commands[0].report({ videoId: video3Id, reason: reason3 })
const reason4 = 'my super bad reason 4'
// resume with the test
const reason3 = 'my super bad reason 3'
await commands[0].report({ videoId: video3Id, reason: reason3 })
const reason4 = 'my super bad reason 4'
- await commands[0].report({ token: userAccessToken, videoId: servers[0].video.id, reason: reason4 })
+ await commands[0].report({ token: userAccessToken, videoId: servers[0].store.videoCreated.id, reason: reason4 })
const abuseVideo3 = body.data.find(a => a.video.id === video3Id)
expect(abuseVideo3).to.not.be.undefined
const abuseVideo3 = body.data.find(a => a.video.id === video3Id)
expect(abuseVideo3).to.not.be.undefined
- expect(abuseVideo3.video.countReports).to.equal(1, "wrong reports count for video 3")
- expect(abuseVideo3.video.nthReport).to.equal(1, "wrong report position in report list for video 3")
- expect(abuseVideo3.countReportsForReportee).to.equal(1, "wrong reports count for reporter on video 3 abuse")
- expect(abuseVideo3.countReportsForReporter).to.equal(3, "wrong reports count for reportee on video 3 abuse")
+ expect(abuseVideo3.video.countReports).to.equal(1, 'wrong reports count for video 3')
+ expect(abuseVideo3.video.nthReport).to.equal(1, 'wrong report position in report list for video 3')
+ expect(abuseVideo3.countReportsForReportee).to.equal(1, 'wrong reports count for reporter on video 3 abuse')
+ expect(abuseVideo3.countReportsForReporter).to.equal(3, 'wrong reports count for reportee on video 3 abuse')
- const abuseServer1 = abuses.find(a => a.video.id === servers[0].video.id)
- expect(abuseServer1.countReportsForReportee).to.equal(3, "wrong reports count for reporter on video 1 abuse")
+ const abuseServer1 = abuses.find(a => a.video.id === servers[0].store.videoCreated.id)
+ expect(abuseServer1.countReportsForReportee).to.equal(3, 'wrong reports count for reporter on video 1 abuse')
const reason5 = 'my super bad reason 5'
const predefinedReasons5: AbusePredefinedReasonsString[] = [ 'violentOrRepulsive', 'captions' ]
const createRes = await commands[0].report({
const reason5 = 'my super bad reason 5'
const predefinedReasons5: AbusePredefinedReasonsString[] = [ 'violentOrRepulsive', 'captions' ]
const createRes = await commands[0].report({
{
const abuse = body.data.find(a => a.id === createRes.abuse.id)
expect(abuse.reason).to.equals(reason5)
{
const abuse = body.data.find(a => a.id === createRes.abuse.id)
expect(abuse.reason).to.equals(reason5)
expect(abuse.video.startAt).to.equal(1, "starting timestamp doesn't match the one reported")
expect(abuse.video.endAt).to.equal(5, "ending timestamp doesn't match the one reported")
}
expect(abuse.video.startAt).to.equal(1, "starting timestamp doesn't match the one reported")
expect(abuse.video.endAt).to.equal(5, "ending timestamp doesn't match the one reported")
}
- servers[0].video = await uploadVideoAndGetId({ server: servers[0], videoName: 'server 1' })
- servers[1].video = await uploadVideoAndGetId({ server: servers[1], videoName: 'server 2' })
+ servers[0].store.videoCreated = await servers[0].videos.quickUpload({ name: 'server 1' })
+ servers[1].store.videoCreated = await servers[1].videos.quickUpload({ name: 'server 2' })
- await servers[0].commentsCommand.createThread({ videoId: servers[0].video.id, text: 'comment server 1' })
- await servers[1].commentsCommand.createThread({ videoId: servers[1].video.id, text: 'comment server 2' })
+ await servers[0].comments.createThread({ videoId: servers[0].store.videoCreated.id, text: 'comment server 1' })
+ await servers[1].comments.createThread({ videoId: servers[1].store.videoCreated.id, text: 'comment server 2' })
const reason = 'it is a bad comment'
await commands[0].report({ commentId: comment.id, reason })
const reason = 'it is a bad comment'
await commands[0].report({ commentId: comment.id, reason })
expect(abuse.comment.id).to.equal(comment.id)
expect(abuse.comment.text).to.equal(comment.text)
expect(abuse.comment.video.name).to.equal('server 1')
expect(abuse.comment.id).to.equal(comment.id)
expect(abuse.comment.text).to.equal(comment.text)
expect(abuse.comment.video.name).to.equal('server 1')
- expect(abuse.comment.video.id).to.equal(servers[0].video.id)
- expect(abuse.comment.video.uuid).to.equal(servers[0].video.uuid)
+ expect(abuse.comment.video.id).to.equal(servers[0].store.videoCreated.id)
+ expect(abuse.comment.video.uuid).to.equal(servers[0].store.videoCreated.uuid)
const reason = 'it is a really bad comment'
await commands[0].report({ commentId: comment.id, reason })
const reason = 'it is a really bad comment'
await commands[0].report({ commentId: comment.id, reason })
expect(abuse2.comment.id).to.equal(commentServer2.id)
expect(abuse2.comment.text).to.equal(commentServer2.text)
expect(abuse2.comment.video.name).to.equal('server 2')
expect(abuse2.comment.id).to.equal(commentServer2.id)
expect(abuse2.comment.text).to.equal(commentServer2.text)
expect(abuse2.comment.video.name).to.equal('server 2')
- function getAccountFromServer (server: ServerInfo, targetName: string, targetServer: ServerInfo) {
- return server.accountsCommand.get({ accountName: targetName + '@' + targetServer.host })
+ function getAccountFromServer (server: PeerTubeServer, targetName: string, targetServer: PeerTubeServer) {
+ return server.accounts.get({ accountName: targetName + '@' + targetServer.host })
- const token = await generateUserAccessToken(servers[1], 'user_2')
- await uploadVideo(servers[1].url, token, { name: 'super video' })
+ const token = await servers[1].users.generateUserAndToken('user_2')
+ await servers[1].videos.upload({ token, attributes: { name: 'super video' } })
- await commands[0].report({ token: userAccessToken, videoId: servers[0].video.id, reason: 'user reason 1' })
+ await commands[0].report({ token: userAccessToken, videoId: servers[0].store.videoCreated.id, reason: 'user reason 1' })
- const body = await commands[0].report({ token: userToken, videoId: servers[0].video.id, reason: 'user 43 reason 1' })
+ const body = await commands[0].report({ token: userToken, videoId: servers[0].store.videoCreated.id, reason: 'user 43 reason 1' })