forked from solidcouch/simple-email-notifications
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathshowcase.spec.ts
71 lines (62 loc) · 1.9 KB
/
showcase.spec.ts
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
import { expect } from 'chai'
import fetch from 'cross-fetch'
import { describe } from 'mocha'
import { baseUrl } from '../config'
import type { GoodBody } from '../controllers/notification'
import { takeScreenshot, verifyEmail } from './helpers'
import {
authenticatedFetch,
authenticatedFetch3,
person,
person3,
} from './testSetup.spec'
const email = 'email@example.com'
/**
* Generate body for POST /notification
*/
const getBody = ({
from,
to,
message,
}: {
from: string
to: string
message: string
}): GoodBody => ({
'@context': 'https://www.w3.org/ns/activitystreams',
type: 'Create',
actor: { type: 'Person', id: from, name: 'PersonFromName' },
object: { type: 'Note', id: 'https://example', content: message },
target: { type: 'Person', id: to, name: 'PersonToName' },
})
describe('Generate screenshots of emails for visual testing', () => {
// empty the maildev inbox
beforeEach(async () => {
await fetch('http://0.0.0.0:1080/email/all', { method: 'DELETE' })
})
beforeEach(async () => {
// setup email for receiver
await verifyEmail({
email,
person: person3,
authenticatedFetch: authenticatedFetch3,
})
})
it('[everything ok] should generate screenshots of email verification and notification in ./screenshots/ folder', async () => {
const response = await authenticatedFetch(`${baseUrl}/notification`, {
method: 'post',
headers: { 'content-type': 'application/ld+json' },
body: JSON.stringify(
getBody({ from: person.webId, to: person3.webId, message: 'Hello!' }),
),
})
expect(response.status).to.equal(202)
const emailResponse = await fetch('http://0.0.0.0:1080/email')
const emails = await emailResponse.json()
// one verification email and one notification
expect(emails).to.have.length(2)
for (const i in emails) {
await takeScreenshot(emails[i], `email${i}`)
}
})
})