-
Notifications
You must be signed in to change notification settings - Fork 9
/
plugin.test.js
72 lines (60 loc) · 1.81 KB
/
plugin.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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
const axios = require('axios').default;
const path = require('path');
const gateway = require('express-gateway');
const express = require('express');
let Application = undefined;
let axiosInstance = undefined;
beforeAll((done) => {
axiosInstance = axios.create({
baseURL: 'http://localhost:8080/',
validateStatus: (status) => status < 400
});
const app = express();
const hello = (req, res) => res.status(200).send('Hello!');
app.get('/status/:code', (req, res) => res.sendStatus(req.params.code));
app.get('/src/js/*', hello);
app.get('/api/v1/*', hello)
Application = app.listen(8081, done);
});
afterAll((done) => {
Application.close(done);
})
describe('Route path', () => {
it('should receive a redirect response', () => {
return axiosInstance
.get('/tina/318', { maxRedirects: 0 })
.then((response) => {
expect(response.status).toBe(301);
expect(response.headers).toHaveProperty('location', '/status/318');
});
});
it('should redirect to the correct resource', () => {
return axiosInstance
.get('/tina/318')
.then((response) => {
expect(response.status).toBe(318);
});
});
it('should receive a redirect response', () => {
return axiosInstance
.get('/api/users/nick', { maxRedirects: 0 })
.then((response) => {
expect(response.status).toBe(200);
});
});
});
describe('RegExp path', () => {
it('should redirect to the correct resource', () => {
return axiosInstance
.get('/js/resource.js')
.then((response) => {
expect(response.status).toBe(200);
});
});
});
describe('Non existing path', () => {
it('should preserve the not found status code', () => {
expect.assertions(1);
return expect(axiosInstance.get('/css/resource.css')).rejects.toBeDefined();
});
});