Skip to content

Commit 8496285

Browse files
committed
close #29 by upgrading all tests to async/await
1 parent 4391d9e commit 8496285

14 files changed

+578
-1039
lines changed

test/attachments.js

Lines changed: 21 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
'use strict';
22

3-
const Promise = require('bluebird') // Promise library
43
const expect = require('chai').expect // Assertion library
54

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

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

60-
it('Simple attachment', function() {
59+
it('Simple attachment', async function() {
6160
let _event = Object.assign({},event,{ path: '/attachment' })
62-
63-
return new Promise((resolve,reject) => {
64-
api.run(_event,{},function(err,res) { resolve(res) })
65-
}).then((result) => {
66-
expect(result).to.deep.equal({ headers: { 'content-disposition': 'attachment', 'content-type': 'application/json' }, statusCode: 200, body: '{"status":"ok"}', isBase64Encoded: false })
67-
})
61+
let result = await new Promise(r => api.run(_event,{},(e,res) => { r(res) }))
62+
expect(result).to.deep.equal({ headers: { 'content-disposition': 'attachment', 'content-type': 'application/json' }, statusCode: 200, body: '{"status":"ok"}', isBase64Encoded: false })
6863
}) // end it
6964

70-
it('PDF attachment w/ path', function() {
65+
it('PDF attachment w/ path', async function() {
7166
let _event = Object.assign({},event,{ path: '/attachment/pdf' })
72-
73-
return new Promise((resolve,reject) => {
74-
api.run(_event,{},function(err,res) { resolve(res) })
75-
}).then((result) => {
76-
expect(result).to.deep.equal({ headers: { 'content-disposition': 'attachment; filename=\"foo.pdf\"', 'content-type': 'application/pdf' }, statusCode: 200, body: 'filedata', isBase64Encoded: false })
77-
})
67+
let result = await new Promise(r => api.run(_event,{},(e,res) => { r(res) }))
68+
expect(result).to.deep.equal({ headers: { 'content-disposition': 'attachment; filename=\"foo.pdf\"', 'content-type': 'application/pdf' }, statusCode: 200, body: 'filedata', isBase64Encoded: false })
7869
}) // end it
7970

80-
it('PNG attachment w/ path', function() {
71+
it('PNG attachment w/ path', async function() {
8172
let _event = Object.assign({},event,{ path: '/attachment/png' })
82-
83-
return new Promise((resolve,reject) => {
84-
api.run(_event,{},function(err,res) { resolve(res) })
85-
}).then((result) => {
86-
expect(result).to.deep.equal({ headers: { 'content-disposition': 'attachment; filename=\"foo.png\"', 'content-type': 'image/png' }, statusCode: 200, body: 'filedata', isBase64Encoded: false })
87-
})
73+
let result = await new Promise(r => api.run(_event,{},(e,res) => { r(res) }))
74+
expect(result).to.deep.equal({ headers: { 'content-disposition': 'attachment; filename=\"foo.png\"', 'content-type': 'image/png' }, statusCode: 200, body: 'filedata', isBase64Encoded: false })
8875
}) // end it
8976

90-
it('CSV attachment w/ path', function() {
77+
it('CSV attachment w/ path', async function() {
9178
let _event = Object.assign({},event,{ path: '/attachment/csv' })
92-
93-
return new Promise((resolve,reject) => {
94-
api.run(_event,{},function(err,res) { resolve(res) })
95-
}).then((result) => {
96-
expect(result).to.deep.equal({ headers: { 'content-disposition': 'attachment; filename=\"foo.csv\"', 'content-type': 'text/csv' }, statusCode: 200, body: 'filedata', isBase64Encoded: false })
97-
})
79+
let result = await new Promise(r => api.run(_event,{},(e,res) => { r(res) }))
80+
expect(result).to.deep.equal({ headers: { 'content-disposition': 'attachment; filename=\"foo.csv\"', 'content-type': 'text/csv' }, statusCode: 200, body: 'filedata', isBase64Encoded: false })
9881
}) // end it
9982

100-
it('Custom MIME type attachment w/ path', function() {
83+
it('Custom MIME type attachment w/ path', async function() {
10184
let _event = Object.assign({},event,{ path: '/attachment/custom' })
102-
103-
return new Promise((resolve,reject) => {
104-
api.run(_event,{},function(err,res) { resolve(res) })
105-
}).then((result) => {
106-
expect(result).to.deep.equal({ headers: { 'content-disposition': 'attachment; filename=\"foo.test\"', 'content-type': 'text/test' }, statusCode: 200, body: 'filedata', isBase64Encoded: false })
107-
})
85+
let result = await new Promise(r => api.run(_event,{},(e,res) => { r(res) }))
86+
expect(result).to.deep.equal({ headers: { 'content-disposition': 'attachment; filename=\"foo.test\"', 'content-type': 'text/test' }, statusCode: 200, body: 'filedata', isBase64Encoded: false })
10887
}) // end it
10988

110-
it('Empty string', function() {
89+
it('Empty string', async function() {
11190
let _event = Object.assign({},event,{ path: '/attachment/empty-string' })
112-
113-
return new Promise((resolve,reject) => {
114-
api.run(_event,{},function(err,res) { resolve(res) })
115-
}).then((result) => {
116-
expect(result).to.deep.equal({ headers: { 'content-disposition': 'attachment', 'content-type': 'application/json' }, statusCode: 200, body: 'filedata', isBase64Encoded: false })
117-
})
91+
let result = await new Promise(r => api.run(_event,{},(e,res) => { r(res) }))
92+
expect(result).to.deep.equal({ headers: { 'content-disposition': 'attachment', 'content-type': 'application/json' }, statusCode: 200, body: 'filedata', isBase64Encoded: false })
11893
}) // end it
11994

120-
it('Null string', function() {
95+
it('Null string', async function() {
12196
let _event = Object.assign({},event,{ path: '/attachment/empty-string' })
122-
123-
return new Promise((resolve,reject) => {
124-
api.run(_event,{},function(err,res) { resolve(res) })
125-
}).then((result) => {
126-
expect(result).to.deep.equal({ headers: { 'content-disposition': 'attachment', 'content-type': 'application/json' }, statusCode: 200, body: 'filedata', isBase64Encoded: false })
127-
})
97+
let result = await new Promise(r => api.run(_event,{},(e,res) => { r(res) }))
98+
expect(result).to.deep.equal({ headers: { 'content-disposition': 'attachment', 'content-type': 'application/json' }, statusCode: 200, body: 'filedata', isBase64Encoded: false })
12899
}) // end it
129100

130101
}) // end HEADER tests

test/basePath.js

Lines changed: 9 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
'use strict';
22

3-
const Promise = require('bluebird') // Promise library
43
const expect = require('chai').expect // Assertion library
54

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

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

44-
it('Simple path with base: /v1/test', function() {
43+
it('Simple path with base: /v1/test', async function() {
4544
let _event = Object.assign({},event,{ path: '/v1/test' })
46-
47-
return new Promise((resolve,reject) => {
48-
api.run(_event,{},function(err,res) { resolve(res) })
49-
}).then((result) => {
50-
expect(result).to.deep.equal({ headers: { 'content-type': 'application/json' }, statusCode: 200, body: '{"method":"get","status":"ok"}', isBase64Encoded: false })
51-
})
45+
let result = await new Promise(r => api.run(_event,{},(e,res) => { r(res) }))
46+
expect(result).to.deep.equal({ headers: { 'content-type': 'application/json' }, statusCode: 200, body: '{"method":"get","status":"ok"}', isBase64Encoded: false })
5247
}) // end it
5348

54-
it('Path with base and parameter: /v1/test/123', function() {
49+
it('Path with base and parameter: /v1/test/123', async function() {
5550
let _event = Object.assign({},event,{ path: '/v1/test/123' })
56-
57-
return new Promise((resolve,reject) => {
58-
api.run(_event,{},function(err,res) { resolve(res) })
59-
}).then((result) => {
60-
expect(result).to.deep.equal({ headers: { 'content-type': 'application/json' }, statusCode: 200, body: '{"method":"get","status":"ok","param":"123"}', isBase64Encoded: false })
61-
})
51+
let result = await new Promise(r => api.run(_event,{},(e,res) => { r(res) }))
52+
expect(result).to.deep.equal({ headers: { 'content-type': 'application/json' }, statusCode: 200, body: '{"method":"get","status":"ok","param":"123"}', isBase64Encoded: false })
6253
}) // end it
6354

64-
it('Nested path with base: /v1/test/test2/test3', function() {
55+
it('Nested path with base: /v1/test/test2/test3', async function() {
6556
let _event = Object.assign({},event,{ path: '/v1/test/test2/test3' })
66-
67-
return new Promise((resolve,reject) => {
68-
api.run(_event,{},function(err,res) { resolve(res) })
69-
}).then((result) => {
70-
// console.log(JSON.stringify(JSON.parse(result.body),null,2));
71-
expect(result).to.deep.equal({ headers: { 'content-type': 'application/json' }, statusCode: 200, body: '{"path":"/v1/test/test2/test3","method":"get","status":"ok"}', isBase64Encoded: false })
72-
})
57+
let result = await new Promise(r => api.run(_event,{},(e,res) => { r(res) }))
58+
expect(result).to.deep.equal({ headers: { 'content-type': 'application/json' }, statusCode: 200, body: '{"path":"/v1/test/test2/test3","method":"get","status":"ok"}', isBase64Encoded: false })
7359
}) // end it
7460

7561
}) // end BASEPATH tests

0 commit comments

Comments
 (0)