From eacb25c4366bcc8fba20f98f93f004fabc6d5578 Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Wed, 8 Aug 2018 17:36:10 +0200 Subject: Add reason when banning a user --- server/tests/api/server/email.ts | 48 ++++++++++++++++++++++++++++++++++++++- server/tests/utils/users/users.ts | 5 +++- 2 files changed, 51 insertions(+), 2 deletions(-) (limited to 'server/tests') 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 @@ import * as chai from 'chai' import 'mocha' -import { askResetPassword, createUser, reportVideoAbuse, resetPassword, runServer, uploadVideo, userLogin, wait } from '../../utils' +import { + askResetPassword, + blockUser, + createUser, + reportVideoAbuse, + resetPassword, + runServer, + unblockUser, + uploadVideo, + userLogin +} from '../../utils' import { flushTests, killallServers, ServerInfo, setAccessTokensToServers } from '../../utils/index' import { mockSmtpServer } from '../../utils/miscs/email' import { waitJobs } from '../../utils/server/jobs' @@ -112,6 +122,42 @@ describe('Test emails', function () { }) }) + describe('When blocking/unblocking user', async function () { + it('Should send the notification email when blocking a user', async function () { + this.timeout(10000) + + const reason = 'my super bad reason' + await blockUser(server.url, userId, server.accessToken, 204, reason) + + await waitJobs(server) + expect(emails).to.have.lengthOf(3) + + const email = emails[2] + + expect(email['from'][0]['address']).equal('test-admin@localhost') + expect(email['to'][0]['address']).equal('user_1@example.com') + expect(email['subject']).contains(' blocked') + expect(email['text']).contains(' blocked') + expect(email['text']).contains(reason) + }) + + it('Should send the notification email when unblocking a user', async function () { + this.timeout(10000) + + await unblockUser(server.url, userId, server.accessToken, 204) + + await waitJobs(server) + expect(emails).to.have.lengthOf(4) + + const email = emails[3] + + expect(email['from'][0]['address']).equal('test-admin@localhost') + expect(email['to'][0]['address']).equal('user_1@example.com') + expect(email['subject']).contains(' unblocked') + expect(email['text']).contains(' unblocked') + }) + }) + after(async function () { killallServers([ server ]) }) 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, .expect(expectedStatus) } -function blockUser (url: string, userId: number | string, accessToken: string, expectedStatus = 204) { +function blockUser (url: string, userId: number | string, accessToken: string, expectedStatus = 204, reason?: string) { const path = '/api/v1/users' + let body: any + if (reason) body = { reason } return request(url) .post(path + '/' + userId + '/block') + .send(body) .set('Accept', 'application/json') .set('Authorization', 'Bearer ' + accessToken) .expect(expectedStatus) -- cgit v1.2.3