| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051 |
- 'use strict';
- const { expect } = require('chai');
- const { parse, serialize } = require('../../../../xml/poll/oadr-response');
- const {
- responseMinXml,
- responseMaxXml,
- responseMissingRequiredXml,
- } = require('./xml-responses');
- const { responseMin, responseMax } = require('./js-responses');
- describe('Response', function() {
- describe('parse', function() {
- it('successfully parses min xml', async function() {
- const parsedResponse = await parse(responseMinXml);
- expect(parsedResponse).to.eql(responseMin);
- });
- it('successfully parses max xml', async function() {
- const parsedResponse = await parse(responseMaxXml);
- expect(parsedResponse).to.eql(responseMax);
- });
- it('successfully parses serialized value', async function() {
- const serialized = serialize(responseMax);
- const parsedResponse = await parse(serialized);
- expect(parsedResponse).to.eql(responseMax);
- });
- it('throws Error on missing required field', async function() {
- let lastError;
- try {
- await parse(responseMissingRequiredXml);
- } catch (e) {
- lastError = e;
- }
- expect(lastError).to.be.an('error');
- });
- });
- describe('serialize', function() {
- it('successfully serializes valid object', async function() {
- const serializedResponse = await serialize(responseMax);
- expect(serializedResponse).to.eql(
- '<oadr2b:oadrPayload xmlns:oadr2b="http://openadr.org/oadr-2.0b/2012/07"><oadr2b:oadrSignedObject><oadr2b:oadrResponse xmlns:ei="http://docs.oasis-open.org/ns/energyinterop/201110" ei:schemaVersion="2.0b"><ei:eiResponse xmlns:ei="http://docs.oasis-open.org/ns/energyinterop/201110"><ei:responseCode>200</ei:responseCode><ei:responseDescription>OK</ei:responseDescription><pyld:requestID xmlns:pyld="http://docs.oasis-open.org/ns/energyinterop/201110/payloads">9383fc5946cb0e14ef5a</pyld:requestID></ei:eiResponse><ei:venID xmlns:ei="http://docs.oasis-open.org/ns/energyinterop/201110">D8:1D:4B:20:5A:65:4C:50:32:FA</ei:venID></oadr2b:oadrResponse></oadr2b:oadrSignedObject></oadr2b:oadrPayload>',
- );
- });
- });
- });
|