Skip to content

Commit

Permalink
Merge pull request #812 from valtlfelipe/fix-parser
Browse files Browse the repository at this point in the history
Fix parser constructor error when passing payload
  • Loading branch information
thinkingserious authored Dec 11, 2018
2 parents 2701787 + b1ca97a commit fc1cb69
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 2 deletions.
1 change: 1 addition & 0 deletions packages/inbound-mail-parser/src/parser.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ declare interface ParseConfig {

declare interface ParseRequest {
body?: {};
payload?: {};
files?: any[];
}

Expand Down
2 changes: 1 addition & 1 deletion packages/inbound-mail-parser/src/parser.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ class Parse {
constructor(config, request) {
this.keys = config.keys;
this.request = request;
this.payload = request.body || {};
this.payload = request.body || request.payload || {};
this.files = request.files || [];
}

Expand Down
25 changes: 24 additions & 1 deletion packages/inbound-mail-parser/src/parser.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ const Parse = require('./parser');

describe('test_parse', () => {
describe('test_parse_key_values', () => {
it('should return the key values specified in the config from the payload', () => {
it('should return the key values specified in the config from the body', () => {
const config = {
keys: ['to', 'from'],
};
Expand All @@ -24,6 +24,29 @@ describe('test_parse', () => {
expect(keyValues).to.be.an('object');
expect(keyValues).to.deep.equal(expectedValues);
});

it('should return the key values specified in the config from the payload', () => {
const config = {
keys: ['to', 'from'],
};
const request = {
payload: {
to: '[email protected]',
from: 'Test User <[email protected]>',
subject: 'Test Subject',
},
};

const parse = new Parse(config, request);
const keyValues = parse.keyValues();
const expectedValues = {
to: '[email protected]',
from: 'Test User <[email protected]>',
};

expect(keyValues).to.be.an('object');
expect(keyValues).to.deep.equal(expectedValues);
});
});

describe('test_parse_get_raw_email', () => {
Expand Down

0 comments on commit fc1cb69

Please sign in to comment.