text: import FixParser from '../src/FixParser';
  import dic from "../src/FixDic.json";
  
  describe("FixParser", () => {
      it("parses a simple message", () => {
          const message = `8=FIX.4.1|9=154|35=6|49=BRKR|56=INVMGR|34=236|52=19980604-07:58:48|23=115685|28=N|55=SPMI.MI|54=2|27=200000|44=10100.000000|25=H|10=159|`;
          const expected = [{"fields": [{"tag": "8", "tag_name": "BeginString", "value": undefined, "value_raw": "FIX.4.1"}, {"tag": "9", "tag_name": "BodyLength", "value": undefined, "value_raw": "154"}, {"tag": "35", "tag_name": "MsgType", "value": "INDICATION_OF_INTEREST", "value_raw": "6"}, {"tag": "49", "tag_name": "SenderCompID", "value": undefined, "value_raw": "BRKR"}, {"tag": "56", "tag_name": "TargetCompID", "value": undefined, "value_raw": "INVMGR"}, {"tag": "34", "tag_name": "MsgSeqNum", "value": undefined, "value_raw": "236"}, {"tag": "52", "tag_name": "SendingTime", "value": undefined, "value_raw": "19980604-07:58:48"}, {"tag": "23", "tag_name": "IOIID", "value": undefined, "value_raw": "115685"}, {"tag": "28", "tag_name": "IOITransType", "value": "NEW", "value_raw": "N"}, {"tag": "55", "tag_name": "Symbol", "value": undefined, "value_raw": "SPMI.MI"}, {"tag": "54", "tag_name": "Side", "value": "SELL", "value_raw": "2"}, {"tag": "27", "tag_name": "IOIQty", "value": undefined, "value_raw": "200000"}, {"tag": "44", "tag_name": "Price", "value": undefined, "value_raw": "10100.000000"}, {"tag": "25", "tag_name": "IOIQltyInd", "value": "HIGH", "value_raw": "H"}, {"tag": "10", "tag_name": "CheckSum", "value": undefined, "value_raw": "159"}], "prefix": "", "raw": "8=FIX.4.1|9=154|35=6|49=BRKR|56=INVMGR|34=236|52=19980604-07:58:48|23=115685|28=N|55=SPMI.MI|54=2|27=200000|44=10100.000000|25=H|10=159|"}];
          const parser = new FixParser(dic);
          const result = parser.parseFixMsg(message);
          expect(result).toEqual(expected);
      });
  
      it("parses a message with space separators", () => {
          const message = `8=FIX.4.2 9=406 35=8 128=AAA 129=AAA 34=2242 49=FFF 56=ABCTTT 43=N 52=20170131-01:34:48.172 1=M1 37=00010223877ORTO1 21=3 47=A 55=fff 48=fff 22=2 207=T 38=500000 6=140.989033 60=20170131-01:34:48 44=141 40=2 59=0 54=1 151=0 15=JPY 120=JPY 14=93282 150=4 39=4 425=93282 426=140.989033 11=fff 378=2 58=Financial creation has failed for more than 10 times 17=0900061788 20=0 32=0 31=0.000000 10=245`;
          const expected = [{"fields": [{"tag": "8", "tag_name": "BeginString", "value": undefined, "value_raw": "FIX.4.2"}, {"tag": "9", "tag_name": "BodyLength", "value": undefined, "value_raw": "406"}, {"tag": "35", "tag_name": "MsgType", "value": "EXECUTION_REPORT", "value_raw": "8"}, {"tag": "128", "tag_name": "DeliverToCompID", "value": undefined, "value_raw": "AAA"}, {"tag": "129", "tag_name": "DeliverToSubID", "value": undefined, "value_raw": "AAA"}, {"tag": "34", "tag_name": "MsgSeqNum", "value": undefined, "value_raw": "2242"}, {"tag": "49", "tag_name": "SenderCompID", "value": undefined, "value_raw": "FFF"}, {"tag": "56", "tag_name": "TargetCompID", "value": undefined, "value_raw": "ABCTTT"}, {"tag": "43", "tag_name": "PossDupFlag", "value": "NO", "value_raw": "N"}, {"tag": "52", "tag_name": "SendingTime", "value": undefined, "value_raw": "20170131-01:34:48.172"}, {"tag": "1", "tag_name": "Account", "value": undefined, "value_raw": "M1"}, {"tag": "37", "tag_name": "OrderID", "value": undefined, "value_raw": "00010223877ORTO1"}, {"tag": "21", "tag_name": "HandlInst", "value": "MANUAL_ORDER_BEST_EXECUTION", "value_raw": "3"}, {"tag": "47", "tag_name": undefined, "value": undefined, "value_raw": "A"}, {"tag": "55", "tag_name": "Symbol", "value": undefined, "value_raw": "fff"}, {"tag": "48", "tag_name": "SecurityID", "value": undefined, "value_raw": "fff"}, {"tag": "22", "tag_name": "SecurityIDSource", "value": "SEDOL", "value_raw": "2"}, {"tag": "207", "tag_name": "SecurityExchange", "value": undefined, "value_raw": "T"}, {"tag": "38", "tag_name": "OrderQty", "value": undefined, "value_raw": "500000"}, {"tag": "6", "tag_name": "AvgPx", "value": undefined, "value_raw": "140.989033"}, {"tag": "60", "tag_name": "TransactTime", "value": undefined, "value_raw": "20170131-01:34:48"}, {"tag": "44", "tag_name": "Price", "value": undefined, "value_raw": "141"}, {"tag": "40", "tag_name": "OrdType", "value": "LIMIT", "value_raw": "2"}, {"tag": "59", "tag_name": "TimeInForce", "value": "DAY", "value_raw": "0"}, {"tag": "54", "tag_name": "Side", "value": "BUY", "value_raw": "1"}, {"tag": "151", "tag_name": "LeavesQty", "value": undefined, "value_raw": "0"}, {"tag": "15", "tag_name": "Currency", "value": undefined, "value_raw": "JPY"}, {"tag": "120", "tag_name": "SettlCurrency", "value": undefined, "value_raw": "JPY"}, {"tag": "14", "tag_name": "CumQty", "value": undefined, "value_raw": "93282"}, {"tag": "150", "tag_name": "ExecType", "value": "CANCELED", "value_raw": "4"}, {"tag": "39", "tag_name": "OrdStatus", "value": "CANCELED", "value_raw": "4"}, {"tag": "425", "tag_name": "DayCumQty", "value": undefined, "value_raw": "93282"}, {"tag": "426", "tag_name": "DayAvgPx", "value": undefined, "value_raw": "140.989033"}, {"tag": "11", "tag_name": "ClOrdID", "value": undefined, "value_raw": "fff"}, {"tag": "378", "tag_name": "ExecRestatementReason", "value": "VERBAL_CHANGE", "value_raw": "2"}, {"tag": "58", "tag_name": "Text", "value": undefined, "value_raw": "Financial creation has failed for more than 10 times"}, {"tag": "17", "tag_name": "ExecID", "value": undefined, "value_raw": "0900061788"}, {"tag": "20", "tag_name": "ExecTransType", "value": "NEW", "value_raw": "0"}, {"tag": "32", "tag_name": "LastQty", "value": undefined, "value_raw": "0"}, {"tag": "31", "tag_name": "LastPx", "value": undefined, "value_raw": "0.000000"}, {"tag": "10", "tag_name": "CheckSum", "value": undefined, "value_raw": "245"}], "prefix": "", "raw": "8=FIX.4.2 9=406 35=8 128=AAA 129=AAA 34=2242 49=FFF 56=ABCTTT 43=N 52=20170131-01:34:48.172 1=M1 37=00010223877ORTO1 21=3 47=A 55=fff 48=fff 22=2 207=T 38=500000 6=140.989033 60=20170131-01:34:48 44=141 40=2 59=0 54=1 151=0 15=JPY 120=JPY 14=93282 150=4 39=4 425=93282 426=140.989033 11=fff 378=2 58=Financial creation has failed for more than 10 times 17=0900061788 20=0 32=0 31=0.000000 10=245"}];
          const parser = new FixParser(dic);
          const result = parser.parseFixMsg(message);
          expect(result).toEqual(expected);
      });
  
      it("parses multiple messages", () => {
          const message = `8=FIX.4.1|9=112|35=0|49=BRKR|56=INVMGR|34=235|52=19980604-07:58:28|112=19980604-07:58:28|10=157|
  8=FIX.4.1|9=90|35=0|49=INVMGR|56=BRKR|34=236|52=19980604-07:59:30|10=225|
          `;
          const expected = [{"fields": [{"tag": "8", "tag_name": "BeginString", "value": undefined, "value_raw": "FIX.4.1"}, {"tag": "9", "tag_name": "BodyLength", "value": undefined, "value_raw": "112"}, {"tag": "35", "tag_name": "MsgType", "value": "HEARTBEAT", "value_raw": "0"}, {"tag": "49", "tag_name": "SenderCompID", "value": undefined, "value_raw": "BRKR"}, {"tag": "56", "tag_name": "TargetCompID", "value": undefined, "value_raw": "INVMGR"}, {"tag": "34", "tag_name": "MsgSeqNum", "value": undefined, "value_raw": "235"}, {"tag": "52", "tag_name": "SendingTime", "value": undefined, "value_raw": "19980604-07:58:28"}, {"tag": "112", "tag_name": "TestReqID", "value": undefined, "value_raw": "19980604-07:58:28"}, {"tag": "10", "tag_name": "CheckSum", "value": undefined, "value_raw": "157"}], "prefix": "", "raw": "8=FIX.4.1|9=112|35=0|49=BRKR|56=INVMGR|34=235|52=19980604-07:58:28|112=19980604-07:58:28|10=157|"}, {"fields": [{"tag": "8", "tag_name": "BeginString", "value": undefined, "value_raw": "FIX.4.1"}, {"tag": "9", "tag_name": "BodyLength", "value": undefined, "value_raw": "90"}, {"tag": "35", "tag_name": "MsgType", "value": "HEARTBEAT", "value_raw": "0"}, {"tag": "49", "tag_name": "SenderCompID", "value": undefined, "value_raw": "INVMGR"}, {"tag": "56", "tag_name": "TargetCompID", "value": undefined, "value_raw": "BRKR"}, {"tag": "34", "tag_name": "MsgSeqNum", "value": undefined, "value_raw": "236"}, {"tag": "52", "tag_name": "SendingTime", "value": undefined, "value_raw": "19980604-07:59:30"}, {"tag": "10", "tag_name": "CheckSum", "value": undefined, "value_raw": "225"}], "prefix": "", "raw": "8=FIX.4.1|9=90|35=0|49=INVMGR|56=BRKR|34=236|52=19980604-07:59:30|10=225|"}];
          const parser = new FixParser(dic);
          const result = parser.parseFixMsg(message);
          expect(result).toEqual(expected);
      });
      
      it("parses a message with semicolon separaters", () => {
          const message = `8=FIX.4.4;9=61;35=A;49=BRKR;56=INVMGR;98=0;34=1;52=20000426-12:05:08;108=30;10=143;`;
          const expected = [{"fields": [{"tag": "8", "tag_name": "BeginString", "value": undefined, "value_raw": "FIX.4.4"}, {"tag": "9", "tag_name": "BodyLength", "value": undefined, "value_raw": "61"}, {"tag": "35", "tag_name": "MsgType", "value": "LOGON", "value_raw": "A"}, {"tag": "49", "tag_name": "SenderCompID", "value": undefined, "value_raw": "BRKR"}, {"tag": "56", "tag_name": "TargetCompID", "value": undefined, "value_raw": "INVMGR"}, {"tag": "98", "tag_name": "EncryptMethod", "value": "NONE", "value_raw": "0"}, {"tag": "34", "tag_name": "MsgSeqNum", "value": undefined, "value_raw": "1"}, {"tag": "52", "tag_name": "SendingTime", "value": undefined, "value_raw": "20000426-12:05:08"}, {"tag": "108", "tag_name": "HeartBtInt", "value": undefined, "value_raw": "30"}, {"tag": "10", "tag_name": "CheckSum", "value": undefined, "value_raw": "143"}], "prefix": "", "raw": "8=FIX.4.4;9=61;35=A;49=BRKR;56=INVMGR;98=0;34=1;52=20000426-12:05:08;108=30;10=143;"}];
          const parser = new FixParser(dic);
          const result = parser.parseFixMsg(message);
          expect(result).toEqual(expected);
      });
  
      it("parses messages with ^A separator", () => {
          const message = `20160707-10:02:51.041 SNT-000183:8=FIX.4.4^A9=296^A35=s^A34=183^A49=12328^A50=1234^A52=20160707-01:02:51.039^A56=1^A57=1,6,F^A142=H3B00^A347=Shift_JIS^A40=2^A44=917.0000^A55= 7201 ^A59=0^A60=20160707
              -01:02:51.012^A548=QqfQfVd9m5YAAAXT 1B1^A549=1^A550=0^A8045=0^A8046=0^A552=2^A54=1^A11=QqfQfaiCVcYAAAAD 1B1^A38=100^A528=A^A54=2^A11=AAAB5Vd9Kp0AACGs 1B1^A38=100^A528=P^A10=202^A
  20160707-10:02:51.214 RCV-000210:8=FIX.4.4^A9=276^A35=8^A34=210^A49=1^A50=1,6,F^A52=20160707-01:02:51.113^A56=12328^A57=1234^A97=N^A143=H3B00^A347=Shift_JIS^A6=0^A11=QqfQfaiCVcYAAAAD 1B1^A14=0^A17=5^A37=00QqfQfaiCVcYAAAAD 1B100000015^A38=100^A39=0^A44=917.0000^A54=1^A55= 7201 ^A150=0^A151=0^A528=A^A548=QqfQfVd9m5YAAAXT 1B1^A8026=100251^A8045=0^A10=104^A`;
          const expected = [{"fields": [{"tag": "8", "tag_name": "BeginString", "value": undefined, "value_raw": "FIX.4.4"}, {"tag": "9", "tag_name": "BodyLength", "value": undefined, "value_raw": "296"}, {"tag": "35", "tag_name": "MsgType", "value": "NEW_ORDER_s", "value_raw": "s"}, {"tag": "34", "tag_name": "MsgSeqNum", "value": undefined, "value_raw": "183"}, {"tag": "49", "tag_name": "SenderCompID", "value": undefined, "value_raw": "12328"}, {"tag": "50", "tag_name": "SenderSubID", "value": undefined, "value_raw": "1234"}, {"tag": "52", "tag_name": "SendingTime", "value": undefined, "value_raw": "20160707-01:02:51.039"}, {"tag": "56", "tag_name": "TargetCompID", "value": undefined, "value_raw": "1"}, {"tag": "57", "tag_name": "TargetSubID", "value": undefined, "value_raw": "1,6,F"}, {"tag": "142", "tag_name": "SenderLocationID", "value": undefined, "value_raw": "H3B00"}, {"tag": "347", "tag_name": "MessageEncoding", "value": "FOR_USING_SJIS", "value_raw": "Shift_JIS"}, {"tag": "40", "tag_name": "OrdType", "value": "LIMIT", "value_raw": "2"}, {"tag": "44", "tag_name": "Price", "value": undefined, "value_raw": "917.0000"}, {"tag": "55", "tag_name": "Symbol", "value": undefined, "value_raw": " 7201 "}, {"tag": "59", "tag_name": "TimeInForce", "value": "DAY", "value_raw": "0"}, {"tag": "60", "tag_name": "TransactTime", "value": undefined, "value_raw": "20160707            -01:02:51.012"}, {"tag": "548", "tag_name": "CrossID", "value": undefined, "value_raw": "QqfQfVd9m5YAAAXT 1B1"}, {"tag": "549", "tag_name": "CrossType", "value": "CROSS_TRADE_WHICH_IS_EXECUTED_COMPLETELY_OR_NOT_BOTH_SIDES_ARE_TREATED_IN_THE_SAME_MANNER_THIS_IS_EQUIVALENT_TO_AN_ALL_OR_NONE", "value_raw": "1"}, {"tag": "550", "tag_name": "CrossPrioritization", "value": "NONE", "value_raw": "0"}, {"tag": "8045", "tag_name": undefined, "value": undefined, "value_raw": "0"}, {"tag": "8046", "tag_name": undefined, "value": undefined, "value_raw": "0"}, {"tag": "552", "tag_name": "NoSides", "value": "BOTH_SIDES", "value_raw": "2"}, {"tag": "54", "tag_name": "Side", "value": "BUY", "value_raw": "1"}, {"tag": "11", "tag_name": "ClOrdID", "value": undefined, "value_raw": "QqfQfaiCVcYAAAAD 1B1"}, {"tag": "38", "tag_name": "OrderQty", "value": undefined, "value_raw": "100"}, {"tag": "528", "tag_name": "OrderCapacity", "value": "AGENCY", "value_raw": "A"}, {"tag": "54", "tag_name": "Side", "value": "SELL", "value_raw": "2"}, {"tag": "11", "tag_name": "ClOrdID", "value": undefined, "value_raw": "AAAB5Vd9Kp0AACGs 1B1"}, {"tag": "38", "tag_name": "OrderQty", "value": undefined, "value_raw": "100"}, {"tag": "528", "tag_name": "OrderCapacity", "value": "PRINCIPAL", "value_raw": "P"}, {"tag": "10", "tag_name": "CheckSum", "value": undefined, "value_raw": "202"}], "prefix": "20160707-10:02:51.041 SNT-000183:", "raw": "20160707-10:02:51.041 SNT-000183:8=FIX.4.4^A9=296^A35=s^A34=183^A49=12328^A50=1234^A52=20160707-01:02:51.039^A56=1^A57=1,6,F^A142=H3B00^A347=Shift_JIS^A40=2^A44=917.0000^A55= 7201 ^A59=0^A60=20160707            -01:02:51.012^A548=QqfQfVd9m5YAAAXT 1B1^A549=1^A550=0^A8045=0^A8046=0^A552=2^A54=1^A11=QqfQfaiCVcYAAAAD 1B1^A38=100^A528=A^A54=2^A11=AAAB5Vd9Kp0AACGs 1B1^A38=100^A528=P^A10=202^A"}, {"fields": [{"tag": "8", "tag_name": "BeginString", "value": undefined, "value_raw": "FIX.4.4"}, {"tag": "9", "tag_name": "BodyLength", "value": undefined, "value_raw": "276"}, {"tag": "35", "tag_name": "MsgType", "value": "EXECUTION_REPORT", "value_raw": "8"}, {"tag": "34", "tag_name": "MsgSeqNum", "value": undefined, "value_raw": "210"}, {"tag": "49", "tag_name": "SenderCompID", "value": undefined, "value_raw": "1"}, {"tag": "50", "tag_name": "SenderSubID", "value": undefined, "value_raw": "1,6,F"}, {"tag": "52", "tag_name": "SendingTime", "value": undefined, "value_raw": "20160707-01:02:51.113"}, {"tag": "56", "tag_name": "TargetCompID", "value": undefined, "value_raw": "12328"}, {"tag": "57", "tag_name": "TargetSubID", "value": undefined, "value_raw": "1234"}, {"tag": "97", "tag_name": "PossResend", "value": "NO", "value_raw": "N"}, {"tag": "143", "tag_name": "TargetLocationID", "value": undefined, "value_raw": "H3B00"}, {"tag": "347", "tag_name": "MessageEncoding", "value": "FOR_USING_SJIS", "value_raw": "Shift_JIS"}, {"tag": "6", "tag_name": "AvgPx", "value": undefined, "value_raw": "0"}, {"tag": "11", "tag_name": "ClOrdID", "value": undefined, "value_raw": "QqfQfaiCVcYAAAAD 1B1"}, {"tag": "14", "tag_name": "CumQty", "value": undefined, "value_raw": "0"}, {"tag": "17", "tag_name": "ExecID", "value": undefined, "value_raw": "5"}, {"tag": "37", "tag_name": "OrderID", "value": undefined, "value_raw": "00QqfQfaiCVcYAAAAD 1B100000015"}, {"tag": "38", "tag_name": "OrderQty", "value": undefined, "value_raw": "100"}, {"tag": "39", "tag_name": "OrdStatus", "value": "NEW", "value_raw": "0"}, {"tag": "44", "tag_name": "Price", "value": undefined, "value_raw": "917.0000"}, {"tag": "54", "tag_name": "Side", "value": "BUY", "value_raw": "1"}, {"tag": "55", "tag_name": "Symbol", "value": undefined, "value_raw": " 7201 "}, {"tag": "150", "tag_name": "ExecType", "value": "NEW", "value_raw": "0"}, {"tag": "151", "tag_name": "LeavesQty", "value": undefined, "value_raw": "0"}, {"tag": "528", "tag_name": "OrderCapacity", "value": "AGENCY", "value_raw": "A"}, {"tag": "548", "tag_name": "CrossID", "value": undefined, "value_raw": "QqfQfVd9m5YAAAXT 1B1"}, {"tag": "8026", "tag_name": undefined, "value": undefined, "value_raw": "100251"}, {"tag": "8045", "tag_name": undefined, "value": undefined, "value_raw": "0"}, {"tag": "10", "tag_name": "CheckSum", "value": undefined, "value_raw": "104"}], "prefix": "20160707-10:02:51.214 RCV-000210:", "raw": "20160707-10:02:51.214 RCV-000210:8=FIX.4.4^A9=276^A35=8^A34=210^A49=1^A50=1,6,F^A52=20160707-01:02:51.113^A56=12328^A57=1234^A97=N^A143=H3B00^A347=Shift_JIS^A6=0^A11=QqfQfaiCVcYAAAAD 1B1^A14=0^A17=5^A37=00QqfQfaiCVcYAAAAD 1B100000015^A38=100^A39=0^A44=917.0000^A54=1^A55= 7201 ^A150=0^A151=0^A528=A^A548=QqfQfVd9m5YAAAXT 1B1^A8026=100251^A8045=0^A10=104^A"}];
          const parser = new FixParser(dic);
          const result = parser.parseFixMsg(message);
          expect(result).toEqual(expected);
      });
  });
  