This repository was archived by the owner on Dec 28, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathlist.test.js
More file actions
76 lines (60 loc) · 1.73 KB
/
list.test.js
File metadata and controls
76 lines (60 loc) · 1.73 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
/* eslint-disable */
process.env.MAILGUN_API_KEY = "api_key"
process.env.MAILGUN_DOMAIN = "domain"
describe('usage', () => {
jest.mock('./logger')
jest.mock('mailgun-js')
const mailgun = require('mailgun-js')
const mockMailgun = {
lists: jest.fn(() => mockMailgun),
members: jest.fn(() => mockMailgun),
add: jest.fn(() => mockMailgun),
}
mailgun.mockReturnValue(mockMailgun)
const m = require('./list')('listname')
test('adds to correct list', () => {
m.add(['member'], true)
expect(mockMailgun.lists)
.toBeCalledWith(`listname@${process.env.MAILGUN_DOMAIN}`)
})
})
describe('error handling', () => {
jest.resetModules()
jest.mock('./logger')
const logger = require('./logger')
logger.error = jest.fn()
jest.mock('mailgun-js')
const mailgun = require('mailgun-js')
const mockMailgun = {
lists: jest.fn(() => mockMailgun),
members: jest.fn(() => mockMailgun),
add: jest.fn((_, cb) => cb('error', null)),
}
mailgun.mockReturnValue(mockMailgun)
const m = require('./list')('listname')
test('add failed', () => {
m.add(['member'], true)
expect(logger.error)
.toBeCalledWith('error')
})
})
describe('success handling', () => {
jest.resetModules()
jest.mock('./logger')
const logger = require('./logger')
logger.debug = jest.fn()
jest.mock('mailgun-js')
const mailgun = require('mailgun-js')
const mockMailgun = {
lists: jest.fn(() => mockMailgun),
members: jest.fn(() => mockMailgun),
add: jest.fn((_, cb) => cb(null, 'success')),
}
mailgun.mockReturnValue(mockMailgun)
const m = require('./list')('listname')
test('add failed', () => {
m.add(['member'], true)
expect(logger.debug)
.toBeCalledWith('success')
})
})