forked from nodeSolidServer/node-solid-server
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathemail-welcome-test.js
More file actions
78 lines (62 loc) · 2.33 KB
/
email-welcome-test.js
File metadata and controls
78 lines (62 loc) · 2.33 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
'use strict'
const path = require('path')
const chai = require('chai')
const expect = chai.expect
const sinon = require('sinon')
const sinonChai = require('sinon-chai')
chai.use(sinonChai)
chai.should()
const SolidHost = require('../../lib/models/solid-host')
const AccountManager = require('../../lib/models/account-manager')
const EmailService = require('../../lib/models/email-service')
const templatePath = path.join(__dirname, '../../default-templates/emails')
var host, accountManager, emailService
beforeEach(() => {
host = SolidHost.from({ serverUri: 'https://example.com' })
let emailConfig = { auth: {}, sender: 'solid@example.com' }
emailService = new EmailService(templatePath, emailConfig)
let mgrConfig = {
host,
emailService,
authMethod: 'oidc',
multiuser: true
}
accountManager = AccountManager.from(mgrConfig)
})
describe('Account Creation Welcome Email', () => {
describe('accountManager.sendWelcomeEmail() (unit tests)', () => {
it('should resolve to null if email service not set up', () => {
accountManager.emailService = null
let userData = { name: 'Alice', username: 'alice', email: 'alice@alice.com' }
let newUser = accountManager.userAccountFrom(userData)
return accountManager.sendWelcomeEmail(newUser)
.then(result => {
expect(result).to.be.null
})
})
it('should resolve to null if a new user has no email', () => {
let userData = { name: 'Alice', username: 'alice' }
let newUser = accountManager.userAccountFrom(userData)
return accountManager.sendWelcomeEmail(newUser)
.then(result => {
expect(result).to.be.null
})
})
it('should send an email using the welcome template', () => {
let sendWithTemplate = sinon
.stub(accountManager.emailService, 'sendWithTemplate')
.returns(Promise.resolve())
let userData = { name: 'Alice', username: 'alice', email: 'alice@alice.com' }
let newUser = accountManager.userAccountFrom(userData)
let expectedEmailData = {
webid: 'https://alice.example.com/profile/card#me',
to: 'alice@alice.com',
name: 'Alice'
}
return accountManager.sendWelcomeEmail(newUser)
.then(result => {
expect(sendWithTemplate).to.be.calledWith('welcome', expectedEmailData)
})
})
})
})