aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/tests
diff options
context:
space:
mode:
authorChocobozzz <me@florianbigard.com>2018-08-08 17:36:10 +0200
committerChocobozzz <me@florianbigard.com>2018-08-08 17:44:22 +0200
commiteacb25c4366bcc8fba20f98f93f004fabc6d5578 (patch)
treed006c6ef3358ec8c3e3deda643dc9b70068f2515 /server/tests
parenta6ce68673ace5b94a81eda3ba198f0a4170eb05e (diff)
downloadPeerTube-eacb25c4366bcc8fba20f98f93f004fabc6d5578.tar.gz
PeerTube-eacb25c4366bcc8fba20f98f93f004fabc6d5578.tar.zst
PeerTube-eacb25c4366bcc8fba20f98f93f004fabc6d5578.zip
Add reason when banning a user
Diffstat (limited to 'server/tests')
-rw-r--r--server/tests/api/server/email.ts48
-rw-r--r--server/tests/utils/users/users.ts5
2 files changed, 51 insertions, 2 deletions
diff --git a/server/tests/api/server/email.ts b/server/tests/api/server/email.ts
index 4be013c84..65d6a759f 100644
--- a/server/tests/api/server/email.ts
+++ b/server/tests/api/server/email.ts
@@ -2,7 +2,17 @@
2 2
3import * as chai from 'chai' 3import * as chai from 'chai'
4import 'mocha' 4import 'mocha'
5import { askResetPassword, createUser, reportVideoAbuse, resetPassword, runServer, uploadVideo, userLogin, wait } from '../../utils' 5import {
6 askResetPassword,
7 blockUser,
8 createUser,
9 reportVideoAbuse,
10 resetPassword,
11 runServer,
12 unblockUser,
13 uploadVideo,
14 userLogin
15} from '../../utils'
6import { flushTests, killallServers, ServerInfo, setAccessTokensToServers } from '../../utils/index' 16import { flushTests, killallServers, ServerInfo, setAccessTokensToServers } from '../../utils/index'
7import { mockSmtpServer } from '../../utils/miscs/email' 17import { mockSmtpServer } from '../../utils/miscs/email'
8import { waitJobs } from '../../utils/server/jobs' 18import { waitJobs } from '../../utils/server/jobs'
@@ -112,6 +122,42 @@ describe('Test emails', function () {
112 }) 122 })
113 }) 123 })
114 124
125 describe('When blocking/unblocking user', async function () {
126 it('Should send the notification email when blocking a user', async function () {
127 this.timeout(10000)
128
129 const reason = 'my super bad reason'
130 await blockUser(server.url, userId, server.accessToken, 204, reason)
131
132 await waitJobs(server)
133 expect(emails).to.have.lengthOf(3)
134
135 const email = emails[2]
136
137 expect(email['from'][0]['address']).equal('test-admin@localhost')
138 expect(email['to'][0]['address']).equal('user_1@example.com')
139 expect(email['subject']).contains(' blocked')
140 expect(email['text']).contains(' blocked')
141 expect(email['text']).contains(reason)
142 })
143
144 it('Should send the notification email when unblocking a user', async function () {
145 this.timeout(10000)
146
147 await unblockUser(server.url, userId, server.accessToken, 204)
148
149 await waitJobs(server)
150 expect(emails).to.have.lengthOf(4)
151
152 const email = emails[3]
153
154 expect(email['from'][0]['address']).equal('test-admin@localhost')
155 expect(email['to'][0]['address']).equal('user_1@example.com')
156 expect(email['subject']).contains(' unblocked')
157 expect(email['text']).contains(' unblocked')
158 })
159 })
160
115 after(async function () { 161 after(async function () {
116 killallServers([ server ]) 162 killallServers([ server ])
117 }) 163 })
diff --git a/server/tests/utils/users/users.ts b/server/tests/utils/users/users.ts
index 7e15fc86e..f786de6e3 100644
--- a/server/tests/utils/users/users.ts
+++ b/server/tests/utils/users/users.ts
@@ -134,11 +134,14 @@ function removeUser (url: string, userId: number | string, accessToken: string,
134 .expect(expectedStatus) 134 .expect(expectedStatus)
135} 135}
136 136
137function blockUser (url: string, userId: number | string, accessToken: string, expectedStatus = 204) { 137function blockUser (url: string, userId: number | string, accessToken: string, expectedStatus = 204, reason?: string) {
138 const path = '/api/v1/users' 138 const path = '/api/v1/users'
139 let body: any
140 if (reason) body = { reason }
139 141
140 return request(url) 142 return request(url)
141 .post(path + '/' + userId + '/block') 143 .post(path + '/' + userId + '/block')
144 .send(body)
142 .set('Accept', 'application/json') 145 .set('Accept', 'application/json')
143 .set('Authorization', 'Bearer ' + accessToken) 146 .set('Authorization', 'Bearer ' + accessToken)
144 .expect(expectedStatus) 147 .expect(expectedStatus)