1 /* tslint:disable:no-unused-expression */
3 import * as chai from 'chai'
9 createUser, removeVideoFromBlacklist,
17 import { flushTests, killallServers, ServerInfo, setAccessTokensToServers } from '../../utils/index'
18 import { mockSmtpServer } from '../../utils/miscs/email'
19 import { waitJobs } from '../../utils/server/jobs'
21 const expect = chai.expect
23 describe('Test emails', function () {
24 let server: ServerInfo
26 let userAccessToken: string
28 let videoUserUUID: string
29 let verificationString: string
30 const emails: object[] = []
33 password: 'super_password'
36 before(async function () {
39 await mockSmtpServer(emails)
43 const overrideConfig = {
48 server = await runServer(1, overrideConfig)
49 await setAccessTokensToServers([ server ])
52 const res = await createUser(server.url, server.accessToken, user.username, user.password)
53 userId = res.body.user.id
55 userAccessToken = await userLogin(server, user)
60 name: 'my super user video'
62 const res = await uploadVideo(server.url, userAccessToken, attributes)
63 videoUserUUID = res.body.video.uuid
70 const res = await uploadVideo(server.url, server.accessToken, attributes)
71 videoUUID = res.body.video.uuid
75 describe('When resetting user password', function () {
77 it('Should ask to reset the password', async function () {
80 await askResetPassword(server.url, 'user_1@example.com')
82 await waitJobs(server)
83 expect(emails).to.have.lengthOf(1)
85 const email = emails[0]
87 expect(email['from'][0]['address']).equal('test-admin@localhost')
88 expect(email['to'][0]['address']).equal('user_1@example.com')
89 expect(email['subject']).contains('password')
91 const verificationStringMatches = /verificationString=([a-z0-9]+)/.exec(email['text'])
92 expect(verificationStringMatches).not.to.be.null
94 verificationString = verificationStringMatches[1]
95 expect(verificationString).to.have.length.above(2)
97 const userIdMatches = /userId=([0-9]+)/.exec(email['text'])
98 expect(userIdMatches).not.to.be.null
100 userId = parseInt(userIdMatches[1], 10)
101 expect(verificationString).to.not.be.undefined
104 it('Should not reset the password with an invalid verification string', async function () {
105 await resetPassword(server.url, userId, verificationString + 'b', 'super_password2', 403)
108 it('Should reset the password', async function () {
109 await resetPassword(server.url, userId, verificationString, 'super_password2')
112 it('Should login with this new password', async function () {
113 user.password = 'super_password2'
115 await userLogin(server, user)
119 describe('When creating a video abuse', function () {
120 it('Should send the notification email', async function () {
123 const reason = 'my super bad reason'
124 await reportVideoAbuse(server.url, server.accessToken, videoUUID, reason)
126 await waitJobs(server)
127 expect(emails).to.have.lengthOf(2)
129 const email = emails[1]
131 expect(email['from'][0]['address']).equal('test-admin@localhost')
132 expect(email['to'][0]['address']).equal('admin1@example.com')
133 expect(email['subject']).contains('abuse')
134 expect(email['text']).contains(videoUUID)
138 describe('When blocking/unblocking user', async function () {
139 it('Should send the notification email when blocking a user', async function () {
142 const reason = 'my super bad reason'
143 await blockUser(server.url, userId, server.accessToken, 204, reason)
145 await waitJobs(server)
146 expect(emails).to.have.lengthOf(3)
148 const email = emails[2]
150 expect(email['from'][0]['address']).equal('test-admin@localhost')
151 expect(email['to'][0]['address']).equal('user_1@example.com')
152 expect(email['subject']).contains(' blocked')
153 expect(email['text']).contains(' blocked')
154 expect(email['text']).contains(reason)
157 it('Should send the notification email when unblocking a user', async function () {
160 await unblockUser(server.url, userId, server.accessToken, 204)
162 await waitJobs(server)
163 expect(emails).to.have.lengthOf(4)
165 const email = emails[3]
167 expect(email['from'][0]['address']).equal('test-admin@localhost')
168 expect(email['to'][0]['address']).equal('user_1@example.com')
169 expect(email['subject']).contains(' unblocked')
170 expect(email['text']).contains(' unblocked')
174 describe('When blacklisting a video', function () {
175 it('Should send the notification email', async function () {
178 const reason = 'my super reason'
179 await addVideoToBlacklist(server.url, server.accessToken, videoUserUUID, reason)
181 await waitJobs(server)
182 expect(emails).to.have.lengthOf(5)
184 const email = emails[4]
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')
193 it('Should send the notification email', async function () {
196 await removeVideoFromBlacklist(server.url, server.accessToken, videoUserUUID)
198 await waitJobs(server)
199 expect(emails).to.have.lengthOf(6)
201 const email = emails[5]
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')
210 after(async function () {
211 killallServers([ server ])