Permalink
Browse files

close #29 by upgrading all tests to async/await

  • Loading branch information...
jeremydaly committed Apr 24, 2018
1 parent 4391d9e commit 8496285b0c6a296727234eb916eba969324e3522
Showing with 578 additions and 1,039 deletions.
  1. +21 −50 test/attachments.js
  2. +9 −23 test/basePath.js
  3. +124 −197 test/cookies.js
  4. +95 −143 test/download.js
  5. +15 −35 test/errorHandling.js
  6. +6 −15 test/finally.js
  7. +73 −110 test/headers.js
  8. +9 −21 test/middleware.js
  9. +12 −28 test/modules.js
  10. +6 −17 test/namespaces.js
  11. +48 −115 test/register.js
  12. +45 −107 test/responses.js
  13. +115 −177 test/sendFile.js
  14. +0 −1 test/utils.js
@@ -1,6 +1,5 @@
'use strict';

const Promise = require('bluebird') // Promise library
const expect = require('chai').expect // Assertion library

// Init API instance
@@ -57,74 +56,46 @@ api.get('/attachment/null-string', function(req,res) {

describe('Attachment Tests:', function() {

it('Simple attachment', function() {
it('Simple attachment', async function() {
let _event = Object.assign({},event,{ path: '/attachment' })

return new Promise((resolve,reject) => {
api.run(_event,{},function(err,res) { resolve(res) })
}).then((result) => {
expect(result).to.deep.equal({ headers: { 'content-disposition': 'attachment', 'content-type': 'application/json' }, statusCode: 200, body: '{"status":"ok"}', isBase64Encoded: false })
})
let result = await new Promise(r => api.run(_event,{},(e,res) => { r(res) }))
expect(result).to.deep.equal({ headers: { 'content-disposition': 'attachment', 'content-type': 'application/json' }, statusCode: 200, body: '{"status":"ok"}', isBase64Encoded: false })
}) // end it

it('PDF attachment w/ path', function() {
it('PDF attachment w/ path', async function() {
let _event = Object.assign({},event,{ path: '/attachment/pdf' })

return new Promise((resolve,reject) => {
api.run(_event,{},function(err,res) { resolve(res) })
}).then((result) => {
expect(result).to.deep.equal({ headers: { 'content-disposition': 'attachment; filename=\"foo.pdf\"', 'content-type': 'application/pdf' }, statusCode: 200, body: 'filedata', isBase64Encoded: false })
})
let result = await new Promise(r => api.run(_event,{},(e,res) => { r(res) }))
expect(result).to.deep.equal({ headers: { 'content-disposition': 'attachment; filename=\"foo.pdf\"', 'content-type': 'application/pdf' }, statusCode: 200, body: 'filedata', isBase64Encoded: false })
}) // end it

it('PNG attachment w/ path', function() {
it('PNG attachment w/ path', async function() {
let _event = Object.assign({},event,{ path: '/attachment/png' })

return new Promise((resolve,reject) => {
api.run(_event,{},function(err,res) { resolve(res) })
}).then((result) => {
expect(result).to.deep.equal({ headers: { 'content-disposition': 'attachment; filename=\"foo.png\"', 'content-type': 'image/png' }, statusCode: 200, body: 'filedata', isBase64Encoded: false })
})
let result = await new Promise(r => api.run(_event,{},(e,res) => { r(res) }))
expect(result).to.deep.equal({ headers: { 'content-disposition': 'attachment; filename=\"foo.png\"', 'content-type': 'image/png' }, statusCode: 200, body: 'filedata', isBase64Encoded: false })
}) // end it

it('CSV attachment w/ path', function() {
it('CSV attachment w/ path', async function() {
let _event = Object.assign({},event,{ path: '/attachment/csv' })

return new Promise((resolve,reject) => {
api.run(_event,{},function(err,res) { resolve(res) })
}).then((result) => {
expect(result).to.deep.equal({ headers: { 'content-disposition': 'attachment; filename=\"foo.csv\"', 'content-type': 'text/csv' }, statusCode: 200, body: 'filedata', isBase64Encoded: false })
})
let result = await new Promise(r => api.run(_event,{},(e,res) => { r(res) }))
expect(result).to.deep.equal({ headers: { 'content-disposition': 'attachment; filename=\"foo.csv\"', 'content-type': 'text/csv' }, statusCode: 200, body: 'filedata', isBase64Encoded: false })
}) // end it

it('Custom MIME type attachment w/ path', function() {
it('Custom MIME type attachment w/ path', async function() {
let _event = Object.assign({},event,{ path: '/attachment/custom' })

return new Promise((resolve,reject) => {
api.run(_event,{},function(err,res) { resolve(res) })
}).then((result) => {
expect(result).to.deep.equal({ headers: { 'content-disposition': 'attachment; filename=\"foo.test\"', 'content-type': 'text/test' }, statusCode: 200, body: 'filedata', isBase64Encoded: false })
})
let result = await new Promise(r => api.run(_event,{},(e,res) => { r(res) }))
expect(result).to.deep.equal({ headers: { 'content-disposition': 'attachment; filename=\"foo.test\"', 'content-type': 'text/test' }, statusCode: 200, body: 'filedata', isBase64Encoded: false })
}) // end it

it('Empty string', function() {
it('Empty string', async function() {
let _event = Object.assign({},event,{ path: '/attachment/empty-string' })

return new Promise((resolve,reject) => {
api.run(_event,{},function(err,res) { resolve(res) })
}).then((result) => {
expect(result).to.deep.equal({ headers: { 'content-disposition': 'attachment', 'content-type': 'application/json' }, statusCode: 200, body: 'filedata', isBase64Encoded: false })
})
let result = await new Promise(r => api.run(_event,{},(e,res) => { r(res) }))
expect(result).to.deep.equal({ headers: { 'content-disposition': 'attachment', 'content-type': 'application/json' }, statusCode: 200, body: 'filedata', isBase64Encoded: false })
}) // end it

it('Null string', function() {
it('Null string', async function() {
let _event = Object.assign({},event,{ path: '/attachment/empty-string' })

return new Promise((resolve,reject) => {
api.run(_event,{},function(err,res) { resolve(res) })
}).then((result) => {
expect(result).to.deep.equal({ headers: { 'content-disposition': 'attachment', 'content-type': 'application/json' }, statusCode: 200, body: 'filedata', isBase64Encoded: false })
})
let result = await new Promise(r => api.run(_event,{},(e,res) => { r(res) }))
expect(result).to.deep.equal({ headers: { 'content-disposition': 'attachment', 'content-type': 'application/json' }, statusCode: 200, body: 'filedata', isBase64Encoded: false })
}) // end it

}) // end HEADER tests
@@ -1,6 +1,5 @@
'use strict';

const Promise = require('bluebird') // Promise library
const expect = require('chai').expect // Assertion library

// Init API instance
@@ -41,35 +40,22 @@ api.get('/test/test2/test3', function(req,res) {

describe('Base Path Tests:', function() {

it('Simple path with base: /v1/test', function() {
it('Simple path with base: /v1/test', async function() {
let _event = Object.assign({},event,{ path: '/v1/test' })

return new Promise((resolve,reject) => {
api.run(_event,{},function(err,res) { resolve(res) })
}).then((result) => {
expect(result).to.deep.equal({ headers: { 'content-type': 'application/json' }, statusCode: 200, body: '{"method":"get","status":"ok"}', isBase64Encoded: false })
})
let result = await new Promise(r => api.run(_event,{},(e,res) => { r(res) }))
expect(result).to.deep.equal({ headers: { 'content-type': 'application/json' }, statusCode: 200, body: '{"method":"get","status":"ok"}', isBase64Encoded: false })
}) // end it

it('Path with base and parameter: /v1/test/123', function() {
it('Path with base and parameter: /v1/test/123', async function() {
let _event = Object.assign({},event,{ path: '/v1/test/123' })

return new Promise((resolve,reject) => {
api.run(_event,{},function(err,res) { resolve(res) })
}).then((result) => {
expect(result).to.deep.equal({ headers: { 'content-type': 'application/json' }, statusCode: 200, body: '{"method":"get","status":"ok","param":"123"}', isBase64Encoded: false })
})
let result = await new Promise(r => api.run(_event,{},(e,res) => { r(res) }))
expect(result).to.deep.equal({ headers: { 'content-type': 'application/json' }, statusCode: 200, body: '{"method":"get","status":"ok","param":"123"}', isBase64Encoded: false })
}) // end it

it('Nested path with base: /v1/test/test2/test3', function() {
it('Nested path with base: /v1/test/test2/test3', async function() {
let _event = Object.assign({},event,{ path: '/v1/test/test2/test3' })

return new Promise((resolve,reject) => {
api.run(_event,{},function(err,res) { resolve(res) })
}).then((result) => {
// console.log(JSON.stringify(JSON.parse(result.body),null,2));
expect(result).to.deep.equal({ headers: { 'content-type': 'application/json' }, statusCode: 200, body: '{"path":"/v1/test/test2/test3","method":"get","status":"ok"}', isBase64Encoded: false })
})
let result = await new Promise(r => api.run(_event,{},(e,res) => { r(res) }))
expect(result).to.deep.equal({ headers: { 'content-type': 'application/json' }, statusCode: 200, body: '{"path":"/v1/test/test2/test3","method":"get","status":"ok"}', isBase64Encoded: false })
}) // end it

}) // end BASEPATH tests
Oops, something went wrong.

0 comments on commit 8496285

Please sign in to comment.