forked from ucfopen/Obojobo
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdb.test.js
More file actions
45 lines (41 loc) · 1.52 KB
/
Copy pathdb.test.js
File metadata and controls
45 lines (41 loc) · 1.52 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
const mockPgPromise = jest.fn()
const mockPgPromiseInstance = jest.fn()
const mockBlueBirdConfig = jest.fn()
jest.mock('../server/config') // to allow us to alter db.useBluebird
jest.mock('bluebird', () => ({ config: mockBlueBirdConfig }))
jest.mock('pg-promise', () => mockPgPromise)
const mockDB = {}
let config
describe('db', () => {
beforeEach(() => {
jest.resetAllMocks()
jest.resetModules()
mockPgPromise.mockReturnValue(mockPgPromiseInstance)
mockPgPromiseInstance.mockReturnValue(mockDB)
config = require('../server/config')
})
test('db initializes with common expectations', () => {
const db = require('../server/db')
expect(db).toBe(mockDB)
expect(mockPgPromiseInstance).toHaveBeenCalledTimes(1)
expect(mockPgPromiseInstance).toHaveBeenCalledWith(config.db)
})
test('db initializes w/o bluebird', () => {
config.db.useBluebird = false
require('../server/db')
const pgPromise = require('pg-promise')
expect(pgPromise).toHaveBeenCalledTimes(1)
expect(pgPromise).toHaveBeenCalledWith({ noWarnings: true })
expect(mockBlueBirdConfig).not.toHaveBeenCalled()
})
test('db initializes with bluebird', () => {
config.db.useBluebird = true
require('../server/db')
const bluebird = require('bluebird')
const pgPromise = require('pg-promise')
expect(pgPromise).toHaveBeenCalledTimes(1)
expect(pgPromise).toHaveBeenCalledWith({ noWarnings: true, promiseLib: bluebird })
expect(mockPgPromiseInstance).toHaveBeenCalledTimes(1)
expect(mockBlueBirdConfig).toHaveBeenCalledWith({ longStackTraces: true })
})
})