forked from jeremydaly/lambda-api
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlastModified.js
More file actions
147 lines (123 loc) · 4.55 KB
/
Copy pathlastModified.js
File metadata and controls
147 lines (123 loc) · 4.55 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
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
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
'use strict';
const Promise = require('bluebird') // Promise library
const expect = require('chai').expect // Assertion library
// Init API instance
const api = require('../index')({ version: 'v1.0' })
// NOTE: Set test to true
api._test = true;
let event = {
httpMethod: 'get',
path: '/test',
body: {},
multiValueHeaders: {
'content-type': ['application/json']
}
}
/******************************************************************************/
/*** DEFINE TEST ROUTES ***/
/******************************************************************************/
api.get('/modified', function(req,res) {
res.modified().send('cache')
})
api.get('/modifiedTrue', function(req,res) {
res.modified(true).send('cache')
})
api.get('/modifiedFalse', function(req,res) {
res.modified(false).send('cache')
})
api.get('/modifiedDate', function(req,res) {
res.modified(new Date('2018-08-01')).send('cache')
})
api.get('/modifiedString', function(req,res) {
res.modified('2018-08-01').send('cache')
})
api.get('/modifiedBadString', function(req,res) {
res.modified('test').send('cache')
})
/******************************************************************************/
/*** BEGIN TESTS ***/
/******************************************************************************/
describe('modified Tests:', function() {
it('modified (no options)', async function() {
let _event = Object.assign({},event,{ path: '/modified' })
let result = await new Promise(r => api.run(_event,{},(e,res) => { r(res) }))
expect(result).to.deep.equal({
multiValueHeaders: {
'content-type': ['application/json'],
'last-modified': result.multiValueHeaders['last-modified']
},
statusCode: 200,
body: 'cache',
isBase64Encoded: false
})
expect(typeof result.multiValueHeaders['last-modified']).to.not.be.null
expect(typeof result.multiValueHeaders['last-modified']).to.not.be.empty
}) // end it
it('modified (true)', async function() {
let _event = Object.assign({},event,{ path: '/modifiedTrue' })
let result = await new Promise(r => api.run(_event,{},(e,res) => { r(res) }))
expect(result).to.deep.equal({
multiValueHeaders: {
'content-type': ['application/json'],
'last-modified': result.multiValueHeaders['last-modified']
},
statusCode: 200,
body: 'cache',
isBase64Encoded: false
})
expect(typeof result.multiValueHeaders['last-modified']).to.not.be.null
expect(typeof result.multiValueHeaders['last-modified']).to.not.be.empty
}) // end it
it('modified (false)', async function() {
let _event = Object.assign({},event,{ path: '/modifiedFalse' })
let result = await new Promise(r => api.run(_event,{},(e,res) => { r(res) }))
expect(result).to.deep.equal({
multiValueHeaders: {
'content-type': ['application/json']
},
statusCode: 200,
body: 'cache',
isBase64Encoded: false
})
}) // end it
it('modified (date)', async function() {
let _event = Object.assign({},event,{ path: '/modifiedDate' })
let result = await new Promise(r => api.run(_event,{},(e,res) => { r(res) }))
expect(result).to.deep.equal({
multiValueHeaders: {
'content-type': ['application/json'],
'last-modified': ['Wed, 01 Aug 2018 00:00:00 GMT']
},
statusCode: 200,
body: 'cache',
isBase64Encoded: false
})
}) // end it
it('modified (string)', async function() {
let _event = Object.assign({},event,{ path: '/modifiedString' })
let result = await new Promise(r => api.run(_event,{},(e,res) => { r(res) }))
expect(result).to.deep.equal({
multiValueHeaders: {
'content-type': ['application/json'],
'last-modified': ['Wed, 01 Aug 2018 00:00:00 GMT']
},
statusCode: 200,
body: 'cache',
isBase64Encoded: false
})
}) // end it
it('modified (invalid date)', async function() {
let _event = Object.assign({},event,{ path: '/modifiedBadString' })
let result = await new Promise(r => api.run(_event,{},(e,res) => { r(res) }))
expect(result).to.deep.equal({
multiValueHeaders: {
'content-type': ['application/json'],
'last-modified': result.multiValueHeaders['last-modified']
},
statusCode: 200,
body: 'cache',
isBase64Encoded: false
})
expect(new Date(result.multiValueHeaders['last-modified'])).to.be.above(new Date('2018-08-02'))
}) // end it
}) // end lastModified tests