aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/tests
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
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')
-rw-r--r--server/tests/api/check-params/video-abuses.ts115
-rw-r--r--server/tests/api/videos/video-abuse.ts50
-rw-r--r--server/tests/utils/videos/video-abuses.ts38
3 files changed, 177 insertions, 26 deletions
diff --git a/server/tests/api/check-params/video-abuses.ts b/server/tests/api/check-params/video-abuses.ts
index 68b965bbe..d2bed6a2a 100644
--- a/server/tests/api/check-params/video-abuses.ts
+++ b/server/tests/api/check-params/video-abuses.ts
@@ -3,14 +3,26 @@
3import 'mocha' 3import 'mocha'
4 4
5import { 5import {
6 createUser, flushTests, killallServers, makeGetRequest, makePostBodyRequest, runServer, ServerInfo, setAccessTokensToServers, 6 createUser,
7 uploadVideo, userLogin 7 deleteVideoAbuse,
8 flushTests,
9 killallServers,
10 makeGetRequest,
11 makePostBodyRequest,
12 runServer,
13 ServerInfo,
14 setAccessTokensToServers,
15 updateVideoAbuse,
16 uploadVideo,
17 userLogin
8} from '../../utils' 18} from '../../utils'
9import { checkBadCountPagination, checkBadSortPagination, checkBadStartPagination } from '../../utils/requests/check-api-params' 19import { checkBadCountPagination, checkBadSortPagination, checkBadStartPagination } from '../../utils/requests/check-api-params'
20import { VideoAbuseState } from '../../../../shared/models/videos'
10 21
11describe('Test video abuses API validators', function () { 22describe('Test video abuses API validators', function () {
12 let server: ServerInfo 23 let server: ServerInfo
13 let userAccessToken = '' 24 let userAccessToken = ''
25 let videoAbuseId: number
14 26
15 // --------------------------------------------------------------- 27 // ---------------------------------------------------------------
16 28
@@ -67,44 +79,111 @@ describe('Test video abuses API validators', function () {
67 79
68 describe('When reporting a video abuse', function () { 80 describe('When reporting a video abuse', function () {
69 const basePath = '/api/v1/videos/' 81 const basePath = '/api/v1/videos/'
82 let path: string
83
84 before(() => {
85 path = basePath + server.video.id + '/abuse'
86 })
70 87
71 it('Should fail with nothing', async function () { 88 it('Should fail with nothing', async function () {
72 const path = basePath + server.video.id + '/abuse'
73 const fields = {} 89 const fields = {}
74 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields }) 90 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields })
75 }) 91 })
76 92
77 it('Should fail with a wrong video', async function () { 93 it('Should fail with a wrong video', async function () {
78 const wrongPath = '/api/v1/videos/blabla/abuse' 94 const wrongPath = '/api/v1/videos/blabla/abuse'
79 const fields = { 95 const fields = { reason: 'my super reason' }
80 reason: 'my super reason' 96
81 }
82 await makePostBodyRequest({ url: server.url, path: wrongPath, token: server.accessToken, fields }) 97 await makePostBodyRequest({ url: server.url, path: wrongPath, token: server.accessToken, fields })
83 }) 98 })
84 99
85 it('Should fail with a non authenticated user', async function () { 100 it('Should fail with a non authenticated user', async function () {
86 const path = basePath + server.video.id + '/abuse' 101 const fields = { reason: 'my super reason' }
87 const fields = { 102
88 reason: 'my super reason'
89 }
90 await makePostBodyRequest({ url: server.url, path, token: 'hello', fields, statusCodeExpected: 401 }) 103 await makePostBodyRequest({ url: server.url, path, token: 'hello', fields, statusCodeExpected: 401 })
91 }) 104 })
92 105
93 it('Should fail with a reason too short', async function () { 106 it('Should fail with a reason too short', async function () {
94 const path = basePath + server.video.id + '/abuse' 107 const fields = { reason: 'h' }
95 const fields = { 108
96 reason: 'h'
97 }
98 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields }) 109 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields })
99 }) 110 })
100 111
101 it('Should fail with a reason too big', async function () { 112 it('Should fail with a reason too big', async function () {
102 const path = basePath + server.video.id + '/abuse' 113 const fields = { reason: 'super'.repeat(61) }
103 const fields = { 114
104 reason: 'super'.repeat(61)
105 }
106 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields }) 115 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields })
107 }) 116 })
117
118 it('Should succeed with the correct parameters', async function () {
119 const fields = { reason: 'super reason' }
120
121 const res = await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields, statusCodeExpected: 200 })
122 videoAbuseId = res.body.videoAbuse.id
123 })
124 })
125
126 describe('When updating a video abuse', function () {
127 const basePath = '/api/v1/videos/'
128 let path: string
129
130 before(() => {
131 path = basePath + server.video.id + '/abuse/' + videoAbuseId
132 })
133
134 it('Should fail with a non authenticated user', async function () {
135 await updateVideoAbuse(server.url, 'blabla', server.video.uuid, videoAbuseId, {}, 401)
136 })
137
138 it('Should fail with a non admin user', async function () {
139 await updateVideoAbuse(server.url, userAccessToken, server.video.uuid, videoAbuseId, {}, 403)
140 })
141
142 it('Should fail with a bad video id or bad video abuse id', async function () {
143 await updateVideoAbuse(server.url, server.accessToken, server.video.uuid, 45, {}, 404)
144 await updateVideoAbuse(server.url, server.accessToken, 52, videoAbuseId, {}, 404)
145 })
146
147 it('Should fail with a bad state', async function () {
148 const body = { state: 5 }
149 await updateVideoAbuse(server.url, server.accessToken, server.video.uuid, videoAbuseId, body, 400)
150 })
151
152 it('Should fail with a bad moderation comment', async function () {
153 const body = { moderationComment: 'b'.repeat(305) }
154 await updateVideoAbuse(server.url, server.accessToken, server.video.uuid, videoAbuseId, body, 400)
155 })
156
157 it('Should succeed with the correct params', async function () {
158 const body = { state: VideoAbuseState.ACCEPTED }
159 await updateVideoAbuse(server.url, server.accessToken, server.video.uuid, videoAbuseId, body)
160 })
161 })
162
163 describe('When deleting a video abuse', function () {
164 const basePath = '/api/v1/videos/'
165 let path: string
166
167 before(() => {
168 path = basePath + server.video.id + '/abuse/' + videoAbuseId
169 })
170
171 it('Should fail with a non authenticated user', async function () {
172 await deleteVideoAbuse(server.url, 'blabla', server.video.uuid, videoAbuseId, 401)
173 })
174
175 it('Should fail with a non admin user', async function () {
176 await deleteVideoAbuse(server.url, userAccessToken, server.video.uuid, videoAbuseId, 403)
177 })
178
179 it('Should fail with a bad video id or bad video abuse id', async function () {
180 await deleteVideoAbuse(server.url, server.accessToken, server.video.uuid, 45, 404)
181 await deleteVideoAbuse(server.url, server.accessToken, 52, videoAbuseId, 404)
182 })
183
184 it('Should succeed with the correct params', async function () {
185 await deleteVideoAbuse(server.url, server.accessToken, server.video.uuid, videoAbuseId)
186 })
108 }) 187 })
109 188
110 after(async function () { 189 after(async function () {
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 () {
diff --git a/server/tests/utils/videos/video-abuses.ts b/server/tests/utils/videos/video-abuses.ts
index 0d72bf457..5f138d6b3 100644
--- a/server/tests/utils/videos/video-abuses.ts
+++ b/server/tests/utils/videos/video-abuses.ts
@@ -1,6 +1,8 @@
1import * as request from 'supertest' 1import * as request from 'supertest'
2import { VideoAbuseUpdate } from '../../../../shared/models/videos/video-abuse-update.model'
3import { makeDeleteRequest, makePutBodyRequest } from '..'
2 4
3function reportVideoAbuse (url: string, token: string, videoId: number | string, reason: string, specialStatus = 204) { 5function reportVideoAbuse (url: string, token: string, videoId: number | string, reason: string, specialStatus = 200) {
4 const path = '/api/v1/videos/' + videoId + '/abuse' 6 const path = '/api/v1/videos/' + videoId + '/abuse'
5 7
6 return request(url) 8 return request(url)
@@ -23,9 +25,41 @@ function getVideoAbusesList (url: string, token: string) {
23 .expect('Content-Type', /json/) 25 .expect('Content-Type', /json/)
24} 26}
25 27
28function updateVideoAbuse (
29 url: string,
30 token: string,
31 videoId: string | number,
32 videoAbuseId: number,
33 body: VideoAbuseUpdate,
34 statusCodeExpected = 204
35) {
36 const path = '/api/v1/videos/' + videoId + '/abuse/' + videoAbuseId
37
38 return makePutBodyRequest({
39 url,
40 token,
41 path,
42 fields: body,
43 statusCodeExpected
44 })
45}
46
47function deleteVideoAbuse (url: string, token: string, videoId: string | number, videoAbuseId: number, statusCodeExpected = 204) {
48 const path = '/api/v1/videos/' + videoId + '/abuse/' + videoAbuseId
49
50 return makeDeleteRequest({
51 url,
52 token,
53 path,
54 statusCodeExpected
55 })
56}
57
26// --------------------------------------------------------------------------- 58// ---------------------------------------------------------------------------
27 59
28export { 60export {
29 reportVideoAbuse, 61 reportVideoAbuse,
30 getVideoAbusesList 62 getVideoAbusesList,
63 updateVideoAbuse,
64 deleteVideoAbuse
31} 65}