|
1 | 1 | 'use strict';
|
2 | 2 |
|
3 |
| -const Promise = require('bluebird') // Promise library |
4 | 3 | const expect = require('chai').expect // Assertion library
|
5 | 4 |
|
6 | 5 | // Init API instance
|
@@ -57,74 +56,46 @@ api.get('/attachment/null-string', function(req,res) {
|
57 | 56 |
|
58 | 57 | describe('Attachment Tests:', function() {
|
59 | 58 |
|
60 |
| - it('Simple attachment', function() { |
| 59 | + it('Simple attachment', async function() { |
61 | 60 | 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 }) |
68 | 63 | }) // end it
|
69 | 64 |
|
70 |
| - it('PDF attachment w/ path', function() { |
| 65 | + it('PDF attachment w/ path', async function() { |
71 | 66 | 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 }) |
78 | 69 | }) // end it
|
79 | 70 |
|
80 |
| - it('PNG attachment w/ path', function() { |
| 71 | + it('PNG attachment w/ path', async function() { |
81 | 72 | 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 }) |
88 | 75 | }) // end it
|
89 | 76 |
|
90 |
| - it('CSV attachment w/ path', function() { |
| 77 | + it('CSV attachment w/ path', async function() { |
91 | 78 | 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 }) |
98 | 81 | }) // end it
|
99 | 82 |
|
100 |
| - it('Custom MIME type attachment w/ path', function() { |
| 83 | + it('Custom MIME type attachment w/ path', async function() { |
101 | 84 | 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 }) |
108 | 87 | }) // end it
|
109 | 88 |
|
110 |
| - it('Empty string', function() { |
| 89 | + it('Empty string', async function() { |
111 | 90 | 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 }) |
118 | 93 | }) // end it
|
119 | 94 |
|
120 |
| - it('Null string', function() { |
| 95 | + it('Null string', async function() { |
121 | 96 | 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 }) |
128 | 99 | }) // end it
|
129 | 100 |
|
130 | 101 | }) // end HEADER tests
|
0 commit comments