-
Notifications
You must be signed in to change notification settings - Fork 1k
/
Copy pathwithApiProxy.test.ts
65 lines (54 loc) · 1.47 KB
/
withApiProxy.test.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
import path from 'path'
import type { FastifyInstance } from 'fastify'
import withApiProxy from '../plugins/withApiProxy'
const FIXTURE_PATH = path.resolve(
__dirname,
'../../../../__fixtures__/example-todo-main'
)
// Mock the dist folder from fixtures,
// because its gitignored
jest.mock('@redwoodjs/internal', () => {
return {
...jest.requireActual('@redwoodjs/internal'),
}
})
jest.mock('../fastify', () => {
return {
...jest.requireActual('../fastify'),
loadFastifyConfig: jest.fn().mockReturnValue({
config: {},
configureFastify: jest.fn((fastify) => fastify),
}),
}
})
describe('Configures the ApiProxy', () => {
beforeAll(() => {
process.env.RWJS_CWD = FIXTURE_PATH
})
afterAll(() => {
delete process.env.RWJS_CWD
})
beforeEach(() => {
jest.clearAllMocks()
})
test('Checks that the fastify http-proxy plugin is configured correctly', async () => {
const mockedFastifyInstance = {
register: jest.fn(),
get: jest.fn(),
all: jest.fn(),
addContentTypeParser: jest.fn(),
log: console,
}
await withApiProxy(mockedFastifyInstance as unknown as FastifyInstance, {
apiUrl: 'http://localhost',
apiHost: 'my-api-host',
})
const mockedFastifyInstanceOptions =
mockedFastifyInstance.register.mock.calls[0][1]
expect(mockedFastifyInstanceOptions).toEqual({
disableCache: true,
prefix: 'http://localhost',
upstream: 'my-api-host',
})
})
})