Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix parser constructor error when passing payload #812

Merged
merged 1 commit into from
Dec 11, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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: 'inbound@inbound.example.com',
from: 'Test User <test@example.com>',
subject: 'Test Subject',
},
};

const parse = new Parse(config, request);
const keyValues = parse.keyValues();
const expectedValues = {
to: 'inbound@inbound.example.com',
from: 'Test User <test@example.com>',
};

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

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