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'
8 import { waitJobs } from '../../utils/server/jobs'
10 const expect = chai.expect
12 describe('Test emails', function () {
13 let server: ServerInfo
16 let verificationString: string
17 const emails: object[] = []
20 password: 'super_password'
23 before(async function () {
26 await mockSmtpServer(emails)
30 const overrideConfig = {
35 server = await runServer(1, overrideConfig)
36 await setAccessTokensToServers([ server ])
39 const res = await createUser(server.url, server.accessToken, user.username, user.password)
40 userId = res.body.user.id
47 const res = await uploadVideo(server.url, server.accessToken, attributes)
48 videoUUID = res.body.video.uuid
52 describe('When resetting user password', function () {
54 it('Should ask to reset the password', async function () {
57 await askResetPassword(server.url, 'user_1@example.com')
59 await waitJobs(server)
60 expect(emails).to.have.lengthOf(1)
62 const email = emails[0]
64 expect(email['from'][0]['address']).equal('test-admin@localhost')
65 expect(email['to'][0]['address']).equal('user_1@example.com')
66 expect(email['subject']).contains('password')
68 const verificationStringMatches = /verificationString=([a-z0-9]+)/.exec(email['text'])
69 expect(verificationStringMatches).not.to.be.null
71 verificationString = verificationStringMatches[1]
72 expect(verificationString).to.have.length.above(2)
74 const userIdMatches = /userId=([0-9]+)/.exec(email['text'])
75 expect(userIdMatches).not.to.be.null
77 userId = parseInt(userIdMatches[1], 10)
78 expect(verificationString).to.not.be.undefined
81 it('Should not reset the password with an invalid verification string', async function () {
82 await resetPassword(server.url, userId, verificationString + 'b', 'super_password2', 403)
85 it('Should reset the password', async function () {
86 await resetPassword(server.url, userId, verificationString, 'super_password2')
89 it('Should login with this new password', async function () {
90 user.password = 'super_password2'
92 await userLogin(server, user)
96 describe('When creating a video abuse', function () {
97 it('Should send the notification email', async function () {
100 const reason = 'my super bad reason'
101 await reportVideoAbuse(server.url, server.accessToken, videoUUID, reason)
103 await waitJobs(server)
104 expect(emails).to.have.lengthOf(2)
106 const email = emails[1]
108 expect(email['from'][0]['address']).equal('test-admin@localhost')
109 expect(email['to'][0]['address']).equal('admin1@example.com')
110 expect(email['subject']).contains('abuse')
111 expect(email['text']).contains(videoUUID)
115 after(async function () {
116 killallServers([ server ])