-
Notifications
You must be signed in to change notification settings - Fork 23
/
Copy pathapp.test.js
58 lines (50 loc) · 1.52 KB
/
app.test.js
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
const request = require('supertest')
const express = require('express')
jest.mock('./env')
jest.mock('passport')
const { enableKeycloakOauth, getRole } = require('./app')
describe('test app', () => {
let app
const baseUriPath = 'http://localhost:4242'
beforeEach(() => {
app = express()
const config = { server: { baseUriPath } }
const services = {
userService: {
loginUserSSO: jest.fn()
},
accessService: {
setUserRootRole: jest.fn()
}
}
enableKeycloakOauth(app, config, services)
app.get('/api/admin/projects', (req, res) => {
res.sendStatus(200)
})
app.get('/api/client/features', (req, res) => {
res.sendStatus(200)
})
})
it('should return 401 without admin access token', async () => {
const response = await request(app).get('/api/admin/projects')
expect(response.statusCode).toBe(401)
})
it('should return 401 without client access token', async () => {
const response = await request(app).get('/api/client/features')
expect(response.statusCode).toBe(401)
})
it('should redirect to base after auth', async () => {
const response = await request(app).get('/api/auth/callback')
expect(response.statusCode).toBe(302)
expect(response.headers.location).toBe(`${baseUriPath}/`)
})
})
describe('test getRole', () => {
it.each([
[['admin'], 'Admin'],
[['editor'], 'Editor'],
[['viewer'], 'Viewer']
])('getRole(%p) to return %s', (input, expected) => {
expect(getRole(input)).toBe(expected)
})
})