/
index.test.js
117 lines (112 loc) · 2.77 KB
/
index.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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
const app = require('./index');
const {mwsupertest} = require('middleware-supertest');
const { test, describe, expect } = require('@jest/globals');
const {toMatchImageSnapshot} = require('jest-image-snapshot');
expect.extend({
toMatchImageSnapshot,
});
describe('should only accept GET requests', () => {
test('rejects POST', async (done) => {
const res = await mwsupertest(app)
.post('/')
.send('')
.expect(405);
done();
});
test('rejects PUT', async (done) => {
const res = await mwsupertest(app)
.put('/')
.send('')
.expect(405);
done();
});
test('rejects DELETE', async (done) => {
const res = await mwsupertest(app)
.delete('/')
.send('')
.expect(405);
done();
});
test('does not 405 GET', async (done) => {
const res = await mwsupertest(app)
.get('/')
.send('');
expect(res.status).not.toEqual(405);
done();
});
});
describe('Rejects requests that do not specify a meme template', () => {
test('/', async (done) => {
const res = await mwsupertest(app)
.get('/')
.expect(400);
done();
});
test('/?t1=watermellons', async (done) => {
const res = await mwsupertest(app)
.get('/')
.query({
t1: 'watermellons',
})
.expect(400);
done();
});
test('/testmeme', async (done) => {
const res = await mwsupertest(app)
.get('/testmeme')
expect(res.status).not.toEqual(400);
done();
});
test('/testmeme?t1=watermellons', async (done) => {
const res = await mwsupertest(app)
.get('/testmeme?t1=watermellons')
.query({
t1: 'watermellons',
})
expect(res.status).not.toEqual(400);
done();
});
});
describe('Meme requests should have open CORS headers',() => {
test('/', async (done) => {
const res = await mwsupertest(app)
.get('/')
.expect('Access-Control-Allow-Origin', '*');
done();
});
test('/testmeme', async (done) => {
const res = await mwsupertest(app)
.get('/')
.expect('Access-Control-Allow-Origin', '*');
done();
});
});
test('404s a missing meme', async (done) => {
const res = await mwsupertest(app)
.get('/notFound?t1=watermellons')
.query({
t1: 'watermellons',
})
expect(res.status).toEqual(404);
done();
});
describe('regression testing', () => {
test('test-meme "cherries"', async (done) => {
const res = await mwsupertest(app)
.get('/test-meme')
.query({
t1: 'cherriess',
});
expect(res.body).toMatchImageSnapshot();
done();
});
test('test-meme "strawberry"', async (done) => {
const res = await mwsupertest(app)
.get('/test-meme')
.query({
t1: 'strawberrys',
});
expect(res.body).toMatchImageSnapshot();
done();
});
});