forked from ucfopen/Obojobo
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathprofile.test.js
More file actions
53 lines (48 loc) · 1.47 KB
/
Copy pathprofile.test.js
File metadata and controls
53 lines (48 loc) · 1.47 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
jest.unmock('express') // we'll use supertest + express for this
// override requireCurrentUser to provide our own
const mockCurrentUser = { username: 'GUEST' }
const mockResetCurrentUser = jest.fn()
jest.mock('../../server/express_current_user', () => (req, res, next) => {
req.getCurrentUser = () => {
req.currentUser = mockCurrentUser
return Promise.resolve(mockCurrentUser)
}
req.resetCurrentUser = mockResetCurrentUser
next()
})
// setup express server
const request = require('supertest')
const express = require('express')
const app = express()
app.use(oboRequire('server/express_current_user'))
app.use('/', oboRequire('server/routes/profile'))
describe('profile routes', () => {
test('view profile renders current user', () => {
expect.hasAssertions()
return request(app)
.get('/')
.then(response => {
expect(response.header['content-type']).toContain('text/html')
expect(response.statusCode).toBe(200)
expect(response.text).toBe('Hello GUEST!')
})
})
test('logout... logs out', () => {
expect.hasAssertions()
return request(app)
.get('/logout')
.then(() => {
expect(mockResetCurrentUser).toHaveBeenCalledTimes(1)
})
})
test('logout redirects', () => {
expect.hasAssertions()
return request(app)
.get('/logout')
.then(response => {
expect(response.header['content-type']).toContain('text/plain; charset=utf-8')
expect(response.statusCode).toBe(302)
expect(response.text).toBe('Found. Redirecting to /')
})
})
})