1 /* tslint:disable:no-unused-expression */
3 import * as chai from 'chai'
5 import { askResetPassword, createUser, reportVideoAbuse, resetPassword, runServer, uploadVideo, userLogin, wait } from '../../utils'
6 import { flushTests, killallServers, ServerInfo, setAccessTokensToServers } from '../../utils/index'
7 import { mockSmtpServer } from '../../utils/miscs/email'
9 const expect = chai.expect
11 describe('Test emails', function () {
12 let server: ServerInfo
15 let verificationString: string
16 const emails: object[] = []
19 password: 'super_password'
22 before(async function () {
25 await mockSmtpServer(emails)
29 const overrideConfig = {
34 server = await runServer(1, overrideConfig)
37 await setAccessTokensToServers([ server ])
40 const res = await createUser(server.url, server.accessToken, user.username, user.password)
41 userId = res.body.user.id
48 const res = await uploadVideo(server.url, server.accessToken, attributes)
49 videoUUID = res.body.video.uuid
53 describe('When resetting user password', function () {
55 it('Should ask to reset the password', async function () {
58 await askResetPassword(server.url, 'user_1@example.com')
61 expect(emails).to.have.lengthOf(1)
63 const email = emails[0]
65 expect(email['from'][0]['address']).equal('test-admin@localhost')
66 expect(email['to'][0]['address']).equal('user_1@example.com')
67 expect(email['subject']).contains('password')
69 const verificationStringMatches = /verificationString=([a-z0-9]+)/.exec(email['text'])
70 expect(verificationStringMatches).not.to.be.null
72 verificationString = verificationStringMatches[1]
73 expect(verificationString).to.have.length.above(2)
75 const userIdMatches = /userId=([0-9]+)/.exec(email['text'])
76 expect(userIdMatches).not.to.be.null
78 userId = parseInt(userIdMatches[1], 10)
79 expect(verificationString).to.not.be.undefined
82 it('Should not reset the password with an invalid verification string', async function () {
83 await resetPassword(server.url, userId, verificationString + 'b', 'super_password2', 403)
86 it('Should reset the password', async function () {
87 await resetPassword(server.url, userId, verificationString, 'super_password2')
90 it('Should login with this new password', async function () {
91 user.password = 'super_password2'
93 await userLogin(server, user)
97 describe('When creating a video abuse', function () {
98 it('Should send the notification email', async function () {
101 const reason = 'my super bad reason'
102 await reportVideoAbuse(server.url, server.accessToken, videoUUID, reason)
105 expect(emails).to.have.lengthOf(2)
107 const email = emails[1]
109 expect(email['from'][0]['address']).equal('test-admin@localhost')
110 expect(email['to'][0]['address']).equal('admin1@example.com')
111 expect(email['subject']).contains('abuse')
112 expect(email['text']).contains(videoUUID)
116 after(async function () {
117 killallServers([ server ])
119 // Keep the logs if the test failed