From b1ca97aa190edf6a9554ec15de38f882c82c6c69 Mon Sep 17 00:00:00 2001 From: Felipe Valtl de Mello Date: Thu, 18 Oct 2018 13:37:51 -0300 Subject: [PATCH] Fix parser constructor error when passing payload --- packages/inbound-mail-parser/src/parser.d.ts | 1 + packages/inbound-mail-parser/src/parser.js | 2 +- .../inbound-mail-parser/src/parser.spec.js | 25 ++++++++++++++++++- 3 files changed, 26 insertions(+), 2 deletions(-) diff --git a/packages/inbound-mail-parser/src/parser.d.ts b/packages/inbound-mail-parser/src/parser.d.ts index 1379e3a51..97f08a71a 100644 --- a/packages/inbound-mail-parser/src/parser.d.ts +++ b/packages/inbound-mail-parser/src/parser.d.ts @@ -6,6 +6,7 @@ declare interface ParseConfig { declare interface ParseRequest { body?: {}; + payload?: {}; files?: any[]; } diff --git a/packages/inbound-mail-parser/src/parser.js b/packages/inbound-mail-parser/src/parser.js index d5f7d5663..1d6f63619 100644 --- a/packages/inbound-mail-parser/src/parser.js +++ b/packages/inbound-mail-parser/src/parser.js @@ -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 || []; } diff --git a/packages/inbound-mail-parser/src/parser.spec.js b/packages/inbound-mail-parser/src/parser.spec.js index 293d41080..863f98c09 100644 --- a/packages/inbound-mail-parser/src/parser.spec.js +++ b/packages/inbound-mail-parser/src/parser.spec.js @@ -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'], }; @@ -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 ', + subject: 'Test Subject', + }, + }; + + const parse = new Parse(config, request); + const keyValues = parse.keyValues(); + const expectedValues = { + to: 'inbound@inbound.example.com', + from: 'Test User ', + }; + + expect(keyValues).to.be.an('object'); + expect(keyValues).to.deep.equal(expectedValues); + }); }); describe('test_parse_get_raw_email', () => {