From f7b8e5176418b34c63804499431f6f0f0827766f Mon Sep 17 00:00:00 2001 From: bwhitn Date: Mon, 17 Dec 2018 22:48:15 -0500 Subject: [PATCH] working on test cases and dressing a bit of code --- src/core/operations/ParseIMF.mjs | 2 +- test/index.mjs | 1 + test/tests/operations/Mime.mjs | 23 +++++++++++++++++++++++ 3 files changed, 25 insertions(+), 1 deletion(-) create mode 100644 test/tests/operations/Mime.mjs diff --git a/src/core/operations/ParseIMF.mjs b/src/core/operations/ParseIMF.mjs index 9df69d31..0799ef83 100644 --- a/src/core/operations/ParseIMF.mjs +++ b/src/core/operations/ParseIMF.mjs @@ -61,7 +61,7 @@ class ParseIMF extends Operation { const dataObj = eml.extractData(fields); let subject = null; const retval = []; - if (dataObj.length >= 1) { + if (dataObj.length) { subject = dataObj[0].fields.subject; if (dataObj[0].header) { retval.push(new File([dataObj[0].header], "Header.txt", {type: "text/plain"})); diff --git a/test/index.mjs b/test/index.mjs index e40ad9d0..6f2e1128 100644 --- a/test/index.mjs +++ b/test/index.mjs @@ -75,6 +75,7 @@ import "./tests/operations/ToGeohash.mjs"; import "./tests/operations/TranslateDateTimeFormat"; import "./tests/operations/Magic"; import "./tests/operations/ParseTLV"; +import "./tests/operations/Mime"; let allTestsPassing = true; const testStatusCounts = { diff --git a/test/tests/operations/Mime.mjs b/test/tests/operations/Mime.mjs new file mode 100644 index 00000000..8fc8a885 --- /dev/null +++ b/test/tests/operations/Mime.mjs @@ -0,0 +1,23 @@ +/** + * Mime tests. + * + * @author bwhitn [brian.m.whitney@outlook.com] + * @copyright Crown Copyright 2018 + * @license Apache-2.0 + */ +import TestRegister from "../../TestRegister"; + +TestRegister.addTests([ + { + name: "Decode Mime Encoded Words", + input: "This is a GBK base64 encoded word: =?GBK?B?x/izx7ncvta52NPazfjC59Pfx+nQxc+i16g=?=.\nThis is a Cyrillic quoted word: =?utf-8?Q?=D0=A2=D0=B5=D1=81=D1=82_=D0=A2=D0=B5=D1=81=D1=82_=D0=A2=D0=B5=D1=81=D1=82?=.", + expectedOutput: ["This is a GBK base64 encoded word: 区城管局关于网络舆情信息专.", + "This is a Cyrillic quoted word: Тест Тест Тест."].join("\n"), + recipeConfig: [ + { + "op": "Decode Mime Encoded Words", + "args": [] + } + ] + }, +]);