'use strict'; const { expect } = require('chai'); const { parse, serialize } = require('../../../../xml/event/distribute-event'); const { distributeEventMin1Xml, distributeEventMin2Xml, distributeEventMaxXml, distributeEventEpri1Xml, distributeEventMissingRequiredXml, } = require('./xml-responses'); const { distributeEventMin1, distributeEventMin2, distributeEventMax, distributeEventEpri1, } = require('./js-responses'); describe('Distribute Event', function() { describe('parse', function() { it('successfully parses min 1 xml', async function() { const parsedResponse = await parse(distributeEventMin1Xml); expect(parsedResponse).to.eql(distributeEventMin1); }); it('successfully parses min 2 xml', async function() { const parsedResponse = await parse(distributeEventMin2Xml); expect(parsedResponse).to.eql(distributeEventMin2); }); it('successfully parses max xml', async function() { const parsedResponse = await parse(distributeEventMaxXml); expect(parsedResponse).to.eql(distributeEventMax); }); it('successfully parses epri xml', async function() { const parsedResponse = await parse(distributeEventEpri1Xml); expect(parsedResponse).to.eql(distributeEventEpri1); }); it('successfully parses serialized value', async function() { const serialized = serialize(distributeEventMax); const parsedResponse = await parse(serialized); expect(parsedResponse).to.eql(distributeEventMax); }); it('throws Error on missing required field', async function() { let lastError; try { await parse(distributeEventMissingRequiredXml); } catch (e) { lastError = e; } expect(lastError).to.be.an('error'); }); }); describe('serialize', function() { it('successfully serializes valid object', async function() { const serializedResponse = await serialize(distributeEventMax); expect(serializedResponse).to.eql( '200OK9383fc5946cb0e14ef5aNANTUM_VTN81dc20dfea7df7a2bb9e41836407d027a0aabcb30http://MarketContext12020-04-14T16:06:39.000Zfarfalse02020-04-14T16:21:00.000ZPT60MPT5MPT5MPT10MPT12MPT10M150PT15M255PT25M360PT10M46564ba02508ab099d6eae6LOAD_CONTROLx-loadControlCapacityEnergy_Management_System0PT60M05.55a5d7f2c75a526386fa41ELECTRICITY_PRICEprice072233284678ff05139f4some baselinePT10M2020-04-14T16:50:00.000ZPT30M150PT30M260currencyPerKWhUSDnoneTest TargetD8:1D:4B:20:5A:65:4C:50:32:FAalwaysb6c955285eb2006232ea0http://MarketContext12020-04-10T19:38:00.000Zcompletedfalse02020-04-10T19:08:00.000ZPT30MPT0MPT0MPT0MPT0M38e550909d77bc37310dBID_LOADlevel0RealPowerWnone60120truePT30M05.594a93415888d31b6d84eELECTRICITY_PRICEprice5.5D8:1D:4B:20:5A:65:4C:50:32:FAalways16b3c052f1b636ede15e0http://MarketContext12020-04-10T20:54:00.000Zcompletedfalse02020-04-10T20:34:00.000ZPT20MPT0MPT0MPT0MPT0MPT20M050e6e7b114b6298cd9d055ENERGY_PRICEprice50D8:1D:4B:20:5A:65:4C:50:32:FAalways', ); }); }); });