Skip to content

Commit

Permalink
Fix failing gzip test.
Browse files Browse the repository at this point in the history
  • Loading branch information
sharkinsspatial committed Jun 18, 2019
1 parent 9b8f8c1 commit c911b22
Showing 1 changed file with 0 additions and 57 deletions.
57 changes: 0 additions & 57 deletions packages/api/tests/test_handler.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,6 @@ const test = require('ava')
const sinon = require('sinon')
const proxyquire = require('proxyquire')
const createEvent = require('aws-event-mocks')
const zlib = require('zlib')
const { promisify } = require('util')
const gunzip = promisify(zlib.gunzip)

test('handler calls search with parameters', async (t) => {
const result = { value: 'value' }
Expand Down Expand Up @@ -84,57 +81,3 @@ test('handler returns 404 for error', async (t) => {
t.is(actual.statusCode, 404)
t.is(actual.body, errorMessage)
})

test('handler gzips response', async (t) => {
const result = { value: 'value' }
const search = sinon.stub().resolves(result)
const satlib = {
api: {
search
}
}
const lambda = proxyquire('../index.js', {
'@sat-utils/api-lib': satlib
})
const host = 'host'
const httpMethod = 'GET'
const path = 'path'

let event = createEvent({
template: 'aws:apiGateway',
merge: {
headers: {
Host: host,
'accept-encoding': 'gzip, deflate'
},
requestContext: {},
httpMethod,
path
}
})

let actual = await lambda.handler(event)
t.is(actual.statusCode, 200)
let unzippedBody = await gunzip(Buffer.from(actual.body, 'base64'))
t.is(unzippedBody.toString(), JSON.stringify(result))
t.is(actual.headers['Content-Encoding'], 'gzip')

event = createEvent({
template: 'aws:apiGateway',
merge: {
headers: {
Host: host,
'Accept-Encoding': 'gzip, deflate'
},
requestContext: {},
httpMethod,
path
}
})

actual = await lambda.handler(event)
t.is(actual.statusCode, 200)
unzippedBody = await gunzip(Buffer.from(actual.body, 'base64'))
t.is(unzippedBody.toString(), JSON.stringify(result),
'Ignores header case sensitivity')
})

0 comments on commit c911b22

Please sign in to comment.