summaryrefslogtreecommitdiffstats
path: root/public/src/app/rule-engine/action/papa.spec.ts
diff options
context:
space:
mode:
authorManor, Yanir (ym903w) <ym903w@intl.att.com>2018-09-20 14:18:38 +0300
committeryanir manor <ym903w@intl.att.com>2018-09-26 09:34:04 +0000
commit22eda038b6cb646d63bfaf617372fce2b5d98631 (patch)
tree0bb3ef9104e02c031305ecfb2ab0692a57b1ed73 /public/src/app/rule-engine/action/papa.spec.ts
parent40bb7dc4a104dc7b387b3586e610299b85f903a3 (diff)
update code to latest
update code to latest Change-Id: I6ed427434b0da47e0d33507a0992b09fe48f9c52 Issue-ID: DCAEGEN2-821 Signed-off-by: Manor, Yanir (ym903w) <ym903w@intl.att.com>
Diffstat (limited to 'public/src/app/rule-engine/action/papa.spec.ts')
-rw-r--r--public/src/app/rule-engine/action/papa.spec.ts84
1 files changed, 84 insertions, 0 deletions
diff --git a/public/src/app/rule-engine/action/papa.spec.ts b/public/src/app/rule-engine/action/papa.spec.ts
new file mode 100644
index 0000000..864d581
--- /dev/null
+++ b/public/src/app/rule-engine/action/papa.spec.ts
@@ -0,0 +1,84 @@
+import * as Papa from 'papaparse';
+
+describe('parse CSV to JSON', () => {
+ it('should have only 2 attribute key and value', () => {
+ const stringAsCSV = 'liav,GL';
+ Papa.parse(stringAsCSV, {
+ complete: result => {
+ if (result.data) {
+ const parser = result.data
+ .slice(0, 300)
+ .filter(item => item[0] !== undefined && item[1] !== undefined)
+ .map(item => {
+ return {
+ key: item[0].trim(),
+ value: item[1].trim()
+ };
+ });
+ expect(parser).toEqual([
+ {
+ key: 'liav',
+ value: 'GL'
+ }
+ ]);
+ }
+ }
+ });
+ });
+
+ it('should have 2 attribute ignore 1', () => {
+ const stringAsCSV = 'liav,GL,DCAE';
+ Papa.parse(stringAsCSV, {
+ complete: result => {
+ if (result.data) {
+ const parser = result.data
+ .slice(0, 300)
+ .filter(item => item[0] !== undefined && item[1] !== undefined)
+ .map(item => {
+ return {
+ key: item[0].trim(),
+ value: item[1].trim()
+ };
+ });
+ expect(parser).toEqual([
+ {
+ key: 'liav',
+ value: 'GL'
+ }
+ ]);
+ }
+ }
+ });
+ });
+
+ it('should have 4 attribute', () => {
+ const stringAsCSV = `liav,GL
+ Vosk,Dev`;
+
+ Papa.parse(stringAsCSV, {
+ complete: result => {
+ if (result.data) {
+ const parser = result.data
+ .slice(0, 300)
+ .filter(item => item[0] !== undefined && item[1] !== undefined)
+ .map(item => {
+ return {
+ key: item[0].trim(),
+ value: item[1].trim()
+ };
+ });
+ expect(parser).toEqual([
+ {
+ key: 'liav',
+ value: 'GL'
+ },
+ {
+ key: 'Vosk',
+ value: 'Dev'
+ }
+ ]);
+ }
+ }
+ });
+ });
+});