aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/tests/api
diff options
context:
space:
mode:
authorChocobozzz <me@florianbigard.com>2018-08-13 16:57:13 +0200
committerChocobozzz <me@florianbigard.com>2018-08-14 09:27:18 +0200
commit26b7305a232e547709f433a6edf700bf495935d8 (patch)
treeb5676090c61df72f864735bcc881d5ee256cffbd /server/tests/api
parentefc9e8450a8bbeeef9cd18e3ad6037abc0f815c3 (diff)
downloadPeerTube-26b7305a232e547709f433a6edf700bf495935d8.tar.gz
PeerTube-26b7305a232e547709f433a6edf700bf495935d8.tar.zst
PeerTube-26b7305a232e547709f433a6edf700bf495935d8.zip
Add blacklist reason field
Diffstat (limited to 'server/tests/api')
-rw-r--r--server/tests/api/check-params/video-blacklist.ts92
-rw-r--r--server/tests/api/server/email.ts51
-rw-r--r--server/tests/api/videos/video-blacklist-management.ts78
3 files changed, 189 insertions, 32 deletions
diff --git a/server/tests/api/check-params/video-blacklist.ts b/server/tests/api/check-params/video-blacklist.ts
index 6cd13d23f..415474718 100644
--- a/server/tests/api/check-params/video-blacklist.ts
+++ b/server/tests/api/check-params/video-blacklist.ts
@@ -3,13 +3,24 @@
3import 'mocha' 3import 'mocha'
4 4
5import { 5import {
6 createUser, flushTests, getBlacklistedVideosList, killallServers, makePostBodyRequest, removeVideoFromBlacklist, runServer, 6 createUser,
7 ServerInfo, setAccessTokensToServers, uploadVideo, userLogin 7 flushTests,
8 getBlacklistedVideosList,
9 killallServers,
10 makePostBodyRequest,
11 makePutBodyRequest,
12 removeVideoFromBlacklist,
13 runServer,
14 ServerInfo,
15 setAccessTokensToServers,
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'
10 20
11describe('Test video blacklist API validators', function () { 21describe('Test video blacklist API validators', function () {
12 let server: ServerInfo 22 let server: ServerInfo
23 let notBlacklistedVideoId: number
13 let userAccessToken = '' 24 let userAccessToken = ''
14 25
15 // --------------------------------------------------------------- 26 // ---------------------------------------------------------------
@@ -28,8 +39,15 @@ describe('Test video blacklist API validators', function () {
28 await createUser(server.url, server.accessToken, username, password) 39 await createUser(server.url, server.accessToken, username, password)
29 userAccessToken = await userLogin(server, { username, password }) 40 userAccessToken = await userLogin(server, { username, password })
30 41
31 const res = await uploadVideo(server.url, server.accessToken, {}) 42 {
32 server.video = res.body.video 43 const res = await uploadVideo(server.url, server.accessToken, {})
44 server.video = res.body.video
45 }
46
47 {
48 const res = await uploadVideo(server.url, server.accessToken, {})
49 notBlacklistedVideoId = res.body.video.uuid
50 }
33 }) 51 })
34 52
35 describe('When adding a video in blacklist', function () { 53 describe('When adding a video in blacklist', function () {
@@ -59,20 +77,70 @@ describe('Test video blacklist API validators', function () {
59 await makePostBodyRequest({ url: server.url, path, token: userAccessToken, fields, statusCodeExpected: 403 }) 77 await makePostBodyRequest({ url: server.url, path, token: userAccessToken, fields, statusCodeExpected: 403 })
60 }) 78 })
61 79
62 it('Should fail with a local video', async function () { 80 it('Should fail with an invalid reason', async function () {
63 const path = basePath + server.video.id + '/blacklist' 81 const path = basePath + server.video.uuid + '/blacklist'
82 const fields = { reason: 'a'.repeat(305) }
83
84 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields })
85 })
86
87 it('Should succeed with the correct params', async function () {
88 const path = basePath + server.video.uuid + '/blacklist'
89 const fields = { }
90
91 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields, statusCodeExpected: 204 })
92 })
93 })
94
95 describe('When updating a video in blacklist', function () {
96 const basePath = '/api/v1/videos/'
97
98 it('Should fail with a wrong video', async function () {
99 const wrongPath = '/api/v1/videos/blabla/blacklist'
100 const fields = {}
101 await makePutBodyRequest({ url: server.url, path: wrongPath, token: server.accessToken, fields })
102 })
103
104 it('Should fail with a video not blacklisted', async function () {
105 const path = '/api/v1/videos/' + notBlacklistedVideoId + '/blacklist'
64 const fields = {} 106 const fields = {}
65 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields, statusCodeExpected: 403 }) 107 await makePutBodyRequest({ url: server.url, path, token: server.accessToken, fields, statusCodeExpected: 404 })
108 })
109
110 it('Should fail with a non authenticated user', async function () {
111 const path = basePath + server.video + '/blacklist'
112 const fields = {}
113 await makePutBodyRequest({ url: server.url, path, token: 'hello', fields, statusCodeExpected: 401 })
114 })
115
116 it('Should fail with a non admin user', async function () {
117 const path = basePath + server.video + '/blacklist'
118 const fields = {}
119 await makePutBodyRequest({ url: server.url, path, token: userAccessToken, fields, statusCodeExpected: 403 })
120 })
121
122 it('Should fail with an invalid reason', async function () {
123 const path = basePath + server.video.uuid + '/blacklist'
124 const fields = { reason: 'a'.repeat(305) }
125
126 await makePutBodyRequest({ url: server.url, path, token: server.accessToken, fields })
127 })
128
129 it('Should succeed with the correct params', async function () {
130 const path = basePath + server.video.uuid + '/blacklist'
131 const fields = { reason: 'hello' }
132
133 await makePutBodyRequest({ url: server.url, path, token: server.accessToken, fields, statusCodeExpected: 204 })
66 }) 134 })
67 }) 135 })
68 136
69 describe('When removing a video in blacklist', function () { 137 describe('When removing a video in blacklist', function () {
70 it('Should fail with a non authenticated user', async function () { 138 it('Should fail with a non authenticated user', async function () {
71 await removeVideoFromBlacklist(server.url, 'fake token', server.video.id, 401) 139 await removeVideoFromBlacklist(server.url, 'fake token', server.video.uuid, 401)
72 }) 140 })
73 141
74 it('Should fail with a non admin user', async function () { 142 it('Should fail with a non admin user', async function () {
75 await removeVideoFromBlacklist(server.url, userAccessToken, server.video.id, 403) 143 await removeVideoFromBlacklist(server.url, userAccessToken, server.video.uuid, 403)
76 }) 144 })
77 145
78 it('Should fail with an incorrect id', async function () { 146 it('Should fail with an incorrect id', async function () {
@@ -81,7 +149,11 @@ describe('Test video blacklist API validators', function () {
81 149
82 it('Should fail with a not blacklisted video', async function () { 150 it('Should fail with a not blacklisted video', async function () {
83 // The video was not added to the blacklist so it should fail 151 // The video was not added to the blacklist so it should fail
84 await removeVideoFromBlacklist(server.url, server.accessToken, server.video.id, 404) 152 await removeVideoFromBlacklist(server.url, server.accessToken, notBlacklistedVideoId, 404)
153 })
154
155 it('Should succeed with the correct params', async function () {
156 await removeVideoFromBlacklist(server.url, server.accessToken, server.video.uuid, 204)
85 }) 157 })
86 }) 158 })
87 159
diff --git a/server/tests/api/server/email.ts b/server/tests/api/server/email.ts
index 65d6a759f..db937f288 100644
--- a/server/tests/api/server/email.ts
+++ b/server/tests/api/server/email.ts
@@ -3,9 +3,10 @@
3import * as chai from 'chai' 3import * as chai from 'chai'
4import 'mocha' 4import 'mocha'
5import { 5import {
6 addVideoToBlacklist,
6 askResetPassword, 7 askResetPassword,
7 blockUser, 8 blockUser,
8 createUser, 9 createUser, removeVideoFromBlacklist,
9 reportVideoAbuse, 10 reportVideoAbuse,
10 resetPassword, 11 resetPassword,
11 runServer, 12 runServer,
@@ -22,7 +23,9 @@ const expect = chai.expect
22describe('Test emails', function () { 23describe('Test emails', function () {
23 let server: ServerInfo 24 let server: ServerInfo
24 let userId: number 25 let userId: number
26 let userAccessToken: string
25 let videoUUID: string 27 let videoUUID: string
28 let videoUserUUID: string
26 let verificationString: string 29 let verificationString: string
27 const emails: object[] = [] 30 const emails: object[] = []
28 const user = { 31 const user = {
@@ -48,6 +51,16 @@ describe('Test emails', function () {
48 { 51 {
49 const res = await createUser(server.url, server.accessToken, user.username, user.password) 52 const res = await createUser(server.url, server.accessToken, user.username, user.password)
50 userId = res.body.user.id 53 userId = res.body.user.id
54
55 userAccessToken = await userLogin(server, user)
56 }
57
58 {
59 const attributes = {
60 name: 'my super user video'
61 }
62 const res = await uploadVideo(server.url, userAccessToken, attributes)
63 videoUserUUID = res.body.video.uuid
51 } 64 }
52 65
53 { 66 {
@@ -158,6 +171,42 @@ describe('Test emails', function () {
158 }) 171 })
159 }) 172 })
160 173
174 describe('When blacklisting a video', function () {
175 it('Should send the notification email', async function () {
176 this.timeout(10000)
177
178 const reason = 'my super reason'
179 await addVideoToBlacklist(server.url, server.accessToken, videoUserUUID, reason)
180
181 await waitJobs(server)
182 expect(emails).to.have.lengthOf(5)
183
184 const email = emails[4]
185
186 expect(email['from'][0]['address']).equal('test-admin@localhost')
187 expect(email['to'][0]['address']).equal('user_1@example.com')
188 expect(email['subject']).contains(' blacklisted')
189 expect(email['text']).contains('my super user video')
190 expect(email['text']).contains('my super reason')
191 })
192
193 it('Should send the notification email', async function () {
194 this.timeout(10000)
195
196 await removeVideoFromBlacklist(server.url, server.accessToken, videoUserUUID)
197
198 await waitJobs(server)
199 expect(emails).to.have.lengthOf(6)
200
201 const email = emails[5]
202
203 expect(email['from'][0]['address']).equal('test-admin@localhost')
204 expect(email['to'][0]['address']).equal('user_1@example.com')
205 expect(email['subject']).contains(' unblacklisted')
206 expect(email['text']).contains('my super user video')
207 })
208 })
209
161 after(async function () { 210 after(async function () {
162 killallServers([ server ]) 211 killallServers([ server ])
163 }) 212 })
diff --git a/server/tests/api/videos/video-blacklist-management.ts b/server/tests/api/videos/video-blacklist-management.ts
index 4d1a06436..7bf39dc99 100644
--- a/server/tests/api/videos/video-blacklist-management.ts
+++ b/server/tests/api/videos/video-blacklist-management.ts
@@ -1,4 +1,4 @@
1/* tslint:disable:no-unused-expressions */ 1/* tslint:disable:no-unused-expression */
2 2
3import * as chai from 'chai' 3import * as chai from 'chai'
4import * as lodash from 'lodash' 4import * as lodash from 'lodash'
@@ -7,29 +7,33 @@ import {
7 addVideoToBlacklist, 7 addVideoToBlacklist,
8 flushAndRunMultipleServers, 8 flushAndRunMultipleServers,
9 getBlacklistedVideosList, 9 getBlacklistedVideosList,
10 getMyVideos,
10 getSortedBlacklistedVideosList, 11 getSortedBlacklistedVideosList,
11 getVideosList, 12 getVideosList,
12 killallServers, 13 killallServers,
13 removeVideoFromBlacklist, 14 removeVideoFromBlacklist,
14 ServerInfo, 15 ServerInfo,
15 setAccessTokensToServers, 16 setAccessTokensToServers,
17 updateVideoBlacklist,
16 uploadVideo 18 uploadVideo
17} from '../../utils/index' 19} from '../../utils/index'
18import { doubleFollow } from '../../utils/server/follows' 20import { doubleFollow } from '../../utils/server/follows'
19import { waitJobs } from '../../utils/server/jobs' 21import { waitJobs } from '../../utils/server/jobs'
22import { VideoAbuse } from '../../../../shared/models/videos'
20 23
21const expect = chai.expect 24const expect = chai.expect
22const orderBy = lodash.orderBy 25const orderBy = lodash.orderBy
23 26
24describe('Test video blacklist management', function () { 27describe('Test video blacklist management', function () {
25 let servers: ServerInfo[] = [] 28 let servers: ServerInfo[] = []
29 let videoId: number
26 30
27 async function blacklistVideosOnServer (server: ServerInfo) { 31 async function blacklistVideosOnServer (server: ServerInfo) {
28 const res = await getVideosList(server.url) 32 const res = await getVideosList(server.url)
29 33
30 const videos = res.body.data 34 const videos = res.body.data
31 for (let video of videos) { 35 for (let video of videos) {
32 await addVideoToBlacklist(server.url, server.accessToken, video.id) 36 await addVideoToBlacklist(server.url, server.accessToken, video.id, 'super reason')
33 } 37 }
34 } 38 }
35 39
@@ -62,53 +66,85 @@ describe('Test video blacklist management', function () {
62 66
63 expect(res.body.total).to.equal(2) 67 expect(res.body.total).to.equal(2)
64 68
65 const videos = res.body.data 69 const blacklistedVideos = res.body.data
66 expect(videos).to.be.an('array') 70 expect(blacklistedVideos).to.be.an('array')
67 expect(videos.length).to.equal(2) 71 expect(blacklistedVideos.length).to.equal(2)
72
73 for (const blacklistedVideo of blacklistedVideos) {
74 expect(blacklistedVideo.reason).to.equal('super reason')
75 videoId = blacklistedVideo.video.id
76 }
68 }) 77 })
69 78
70 it('Should get the correct sort when sorting by descending id', async function () { 79 it('Should get the correct sort when sorting by descending id', async function () {
71 const res = await getSortedBlacklistedVideosList(servers[0].url, servers[0].accessToken, '-id') 80 const res = await getSortedBlacklistedVideosList(servers[0].url, servers[0].accessToken, '-id')
72 expect(res.body.total).to.equal(2) 81 expect(res.body.total).to.equal(2)
73 82
74 const videos = res.body.data 83 const blacklistedVideos = res.body.data
75 expect(videos).to.be.an('array') 84 expect(blacklistedVideos).to.be.an('array')
76 expect(videos.length).to.equal(2) 85 expect(blacklistedVideos.length).to.equal(2)
77 86
78 const result = orderBy(res.body.data, [ 'id' ], [ 'desc' ]) 87 const result = orderBy(res.body.data, [ 'id' ], [ 'desc' ])
79 88
80 expect(videos).to.deep.equal(result) 89 expect(blacklistedVideos).to.deep.equal(result)
81 }) 90 })
82 91
83 it('Should get the correct sort when sorting by descending video name', async function () { 92 it('Should get the correct sort when sorting by descending video name', async function () {
84 const res = await getSortedBlacklistedVideosList(servers[0].url, servers[0].accessToken, '-name') 93 const res = await getSortedBlacklistedVideosList(servers[0].url, servers[0].accessToken, '-name')
85 expect(res.body.total).to.equal(2) 94 expect(res.body.total).to.equal(2)
86 95
87 const videos = res.body.data 96 const blacklistedVideos = res.body.data
88 expect(videos).to.be.an('array') 97 expect(blacklistedVideos).to.be.an('array')
89 expect(videos.length).to.equal(2) 98 expect(blacklistedVideos.length).to.equal(2)
90 99
91 const result = orderBy(res.body.data, [ 'name' ], [ 'desc' ]) 100 const result = orderBy(res.body.data, [ 'name' ], [ 'desc' ])
92 101
93 expect(videos).to.deep.equal(result) 102 expect(blacklistedVideos).to.deep.equal(result)
94 }) 103 })
95 104
96 it('Should get the correct sort when sorting by ascending creation date', async function () { 105 it('Should get the correct sort when sorting by ascending creation date', async function () {
97 const res = await getSortedBlacklistedVideosList(servers[0].url, servers[0].accessToken, 'createdAt') 106 const res = await getSortedBlacklistedVideosList(servers[0].url, servers[0].accessToken, 'createdAt')
98 expect(res.body.total).to.equal(2) 107 expect(res.body.total).to.equal(2)
99 108
100 const videos = res.body.data 109 const blacklistedVideos = res.body.data
101 expect(videos).to.be.an('array') 110 expect(blacklistedVideos).to.be.an('array')
102 expect(videos.length).to.equal(2) 111 expect(blacklistedVideos.length).to.equal(2)
103 112
104 const result = orderBy(res.body.data, [ 'createdAt' ]) 113 const result = orderBy(res.body.data, [ 'createdAt' ])
105 114
106 expect(videos).to.deep.equal(result) 115 expect(blacklistedVideos).to.deep.equal(result)
116 })
117 })
118
119 describe('When updating blacklisted videos', function () {
120 it('Should change the reason', async function () {
121 await updateVideoBlacklist(servers[0].url, servers[0].accessToken, videoId, 'my super reason updated')
122
123 const res = await getSortedBlacklistedVideosList(servers[0].url, servers[0].accessToken, '-name')
124 const video = res.body.data.find(b => b.video.id === videoId)
125
126 expect(video.reason).to.equal('my super reason updated')
127 })
128 })
129
130 describe('When listing my videos', function () {
131 it('Should display blacklisted videos', async function () {
132 await blacklistVideosOnServer(servers[1])
133
134 const res = await getMyVideos(servers[1].url, servers[1].accessToken, 0, 5)
135
136 expect(res.body.total).to.equal(2)
137 expect(res.body.data).to.have.lengthOf(2)
138
139 for (const video of res.body.data) {
140 expect(video.blacklisted).to.be.true
141 expect(video.blacklistedReason).to.equal('super reason')
142 }
107 }) 143 })
108 }) 144 })
109 145
110 describe('When removing a blacklisted video', function () { 146 describe('When removing a blacklisted video', function () {
111 let videoToRemove 147 let videoToRemove: VideoAbuse
112 let blacklist = [] 148 let blacklist = []
113 149
114 it('Should not have any video in videos list on server 1', async function () { 150 it('Should not have any video in videos list on server 1', async function () {
@@ -125,7 +161,7 @@ describe('Test video blacklist management', function () {
125 blacklist = res.body.data.slice(1) 161 blacklist = res.body.data.slice(1)
126 162
127 // Remove it 163 // Remove it
128 await removeVideoFromBlacklist(servers[0].url, servers[0].accessToken, videoToRemove.videoId) 164 await removeVideoFromBlacklist(servers[0].url, servers[0].accessToken, videoToRemove.video.id)
129 }) 165 })
130 166
131 it('Should have the ex-blacklisted video in videos list on server 1', async function () { 167 it('Should have the ex-blacklisted video in videos list on server 1', async function () {
@@ -136,8 +172,8 @@ describe('Test video blacklist management', function () {
136 expect(videos).to.be.an('array') 172 expect(videos).to.be.an('array')
137 expect(videos.length).to.equal(1) 173 expect(videos.length).to.equal(1)
138 174
139 expect(videos[0].name).to.equal(videoToRemove.name) 175 expect(videos[0].name).to.equal(videoToRemove.video.name)
140 expect(videos[0].id).to.equal(videoToRemove.videoId) 176 expect(videos[0].id).to.equal(videoToRemove.video.id)
141 }) 177 })
142 178
143 it('Should not have the ex-blacklisted video in videos blacklist list on server 1', async function () { 179 it('Should not have the ex-blacklisted video in videos blacklist list on server 1', async function () {