aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/tests/api/videos/video-abuse.ts
diff options
context:
space:
mode:
authorChocobozzz <me@florianbigard.com>2018-08-10 16:54:01 +0200
committerChocobozzz <me@florianbigard.com>2018-08-10 16:54:01 +0200
commit268eebed921ac13a9ce0f4717f4923aa24190657 (patch)
tree52f8436968c8dcc686663ef5db8dffd7ed191d34 /server/tests/api/videos/video-abuse.ts
parent904a463c7792837f0a468a522a28448323e48593 (diff)
downloadPeerTube-268eebed921ac13a9ce0f4717f4923aa24190657.tar.gz
PeerTube-268eebed921ac13a9ce0f4717f4923aa24190657.tar.zst
PeerTube-268eebed921ac13a9ce0f4717f4923aa24190657.zip
Add state and moderationComment for abuses on server side
Diffstat (limited to 'server/tests/api/videos/video-abuse.ts')
-rw-r--r--server/tests/api/videos/video-abuse.ts50
1 files changed, 44 insertions, 6 deletions
diff --git a/server/tests/api/videos/video-abuse.ts b/server/tests/api/videos/video-abuse.ts
index dde309b96..a17f3c8de 100644
--- a/server/tests/api/videos/video-abuse.ts
+++ b/server/tests/api/videos/video-abuse.ts
@@ -2,8 +2,9 @@
2 2
3import * as chai from 'chai' 3import * as chai from 'chai'
4import 'mocha' 4import 'mocha'
5import { VideoAbuse } from '../../../../shared/models/videos' 5import { VideoAbuse, VideoAbuseState } from '../../../../shared/models/videos'
6import { 6import {
7 deleteVideoAbuse,
7 flushAndRunMultipleServers, 8 flushAndRunMultipleServers,
8 getVideoAbusesList, 9 getVideoAbusesList,
9 getVideosList, 10 getVideosList,
@@ -11,6 +12,7 @@ import {
11 reportVideoAbuse, 12 reportVideoAbuse,
12 ServerInfo, 13 ServerInfo,
13 setAccessTokensToServers, 14 setAccessTokensToServers,
15 updateVideoAbuse,
14 uploadVideo 16 uploadVideo
15} from '../../utils/index' 17} from '../../utils/index'
16import { doubleFollow } from '../../utils/server/follows' 18import { doubleFollow } from '../../utils/server/follows'
@@ -20,6 +22,7 @@ const expect = chai.expect
20 22
21describe('Test video abuses', function () { 23describe('Test video abuses', function () {
22 let servers: ServerInfo[] = [] 24 let servers: ServerInfo[] = []
25 let abuseServer2: VideoAbuse
23 26
24 before(async function () { 27 before(async function () {
25 this.timeout(50000) 28 this.timeout(50000)
@@ -105,7 +108,7 @@ describe('Test video abuses', function () {
105 await waitJobs(servers) 108 await waitJobs(servers)
106 }) 109 })
107 110
108 it('Should have 2 video abuse on server 1 and 1 on server 2', async function () { 111 it('Should have 2 video abuses on server 1 and 1 on server 2', async function () {
109 const res1 = await getVideoAbusesList(servers[0].url, servers[0].accessToken) 112 const res1 = await getVideoAbusesList(servers[0].url, servers[0].accessToken)
110 expect(res1.body.total).to.equal(2) 113 expect(res1.body.total).to.equal(2)
111 expect(res1.body.data).to.be.an('array') 114 expect(res1.body.data).to.be.an('array')
@@ -116,22 +119,57 @@ describe('Test video abuses', function () {
116 expect(abuse1.reporterAccount.name).to.equal('root') 119 expect(abuse1.reporterAccount.name).to.equal('root')
117 expect(abuse1.reporterAccount.host).to.equal('localhost:9001') 120 expect(abuse1.reporterAccount.host).to.equal('localhost:9001')
118 expect(abuse1.video.id).to.equal(servers[0].video.id) 121 expect(abuse1.video.id).to.equal(servers[0].video.id)
122 expect(abuse1.state.id).to.equal(VideoAbuseState.PENDING)
123 expect(abuse1.state.label).to.equal('Pending')
124 expect(abuse1.moderationComment).to.be.null
119 125
120 const abuse2: VideoAbuse = res1.body.data[1] 126 const abuse2: VideoAbuse = res1.body.data[1]
121 expect(abuse2.reason).to.equal('my super bad reason 2') 127 expect(abuse2.reason).to.equal('my super bad reason 2')
122 expect(abuse2.reporterAccount.name).to.equal('root') 128 expect(abuse2.reporterAccount.name).to.equal('root')
123 expect(abuse2.reporterAccount.host).to.equal('localhost:9001') 129 expect(abuse2.reporterAccount.host).to.equal('localhost:9001')
124 expect(abuse2.video.id).to.equal(servers[1].video.id) 130 expect(abuse2.video.id).to.equal(servers[1].video.id)
131 expect(abuse2.state.id).to.equal(VideoAbuseState.PENDING)
132 expect(abuse2.state.label).to.equal('Pending')
133 expect(abuse2.moderationComment).to.be.null
125 134
126 const res2 = await getVideoAbusesList(servers[1].url, servers[1].accessToken) 135 const res2 = await getVideoAbusesList(servers[1].url, servers[1].accessToken)
127 expect(res2.body.total).to.equal(1) 136 expect(res2.body.total).to.equal(1)
128 expect(res2.body.data).to.be.an('array') 137 expect(res2.body.data).to.be.an('array')
129 expect(res2.body.data.length).to.equal(1) 138 expect(res2.body.data.length).to.equal(1)
130 139
131 const abuse3: VideoAbuse = res2.body.data[0] 140 abuseServer2 = res2.body.data[0]
132 expect(abuse3.reason).to.equal('my super bad reason 2') 141 expect(abuseServer2.reason).to.equal('my super bad reason 2')
133 expect(abuse3.reporterAccount.name).to.equal('root') 142 expect(abuseServer2.reporterAccount.name).to.equal('root')
134 expect(abuse3.reporterAccount.host).to.equal('localhost:9001') 143 expect(abuseServer2.reporterAccount.host).to.equal('localhost:9001')
144 expect(abuseServer2.state.id).to.equal(VideoAbuseState.PENDING)
145 expect(abuseServer2.state.label).to.equal('Pending')
146 expect(abuseServer2.moderationComment).to.be.null
147 })
148
149 it('Should update the state of a video abuse', async function () {
150 const body = { state: VideoAbuseState.REJECTED }
151 await updateVideoAbuse(servers[1].url, servers[1].accessToken, abuseServer2.video.uuid, abuseServer2.id, body)
152
153 const res = await getVideoAbusesList(servers[1].url, servers[1].accessToken)
154 expect(res.body.data[0].state.id).to.equal(VideoAbuseState.REJECTED)
155 })
156
157 it('Should add a moderation comment', async function () {
158 const body = { state: VideoAbuseState.ACCEPTED, moderationComment: 'It is valid' }
159 await updateVideoAbuse(servers[1].url, servers[1].accessToken, abuseServer2.video.uuid, abuseServer2.id, body)
160
161 const res = await getVideoAbusesList(servers[1].url, servers[1].accessToken)
162 expect(res.body.data[0].state.id).to.equal(VideoAbuseState.ACCEPTED)
163 expect(res.body.data[0].moderationComment).to.equal('It is valid')
164 })
165
166 it('Should delete the video abuse', async function () {
167 await deleteVideoAbuse(servers[1].url, servers[1].accessToken, abuseServer2.video.uuid, abuseServer2.id)
168
169 const res = await getVideoAbusesList(servers[1].url, servers[1].accessToken)
170 expect(res.body.total).to.equal(0)
171 expect(res.body.data).to.be.an('array')
172 expect(res.body.data.length).to.equal(0)
135 }) 173 })
136 174
137 after(async function () { 175 after(async function () {