created-party-registration.spec.js 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. 'use strict';
  2. const { expect } = require('chai');
  3. const {
  4. parse,
  5. serialize,
  6. } = require('../../../../xml/register-party/created-party-registration');
  7. const {
  8. createdPartyRegistrationMinXml,
  9. createdPartyRegistrationMaxXml,
  10. createdPartyRegistrationMissingRequiredXml,
  11. } = require('./xml-responses');
  12. const {
  13. createdPartyRegistrationMin,
  14. createdPartyRegistrationMax,
  15. } = require('./js-responses');
  16. describe('Created Party Registration', function() {
  17. describe('parse', function() {
  18. it('successfully parses min xml', async function() {
  19. const parsedResponse = await parse(createdPartyRegistrationMinXml);
  20. expect(parsedResponse).to.eql(createdPartyRegistrationMin);
  21. });
  22. it('successfully parses max xml', async function() {
  23. const parsedResponse = await parse(createdPartyRegistrationMaxXml);
  24. expect(parsedResponse).to.eql(createdPartyRegistrationMax);
  25. });
  26. it('successfully parses serialized value', async function() {
  27. const serialized = serialize(createdPartyRegistrationMax);
  28. const parsedResponse = await parse(serialized);
  29. expect(parsedResponse).to.eql(createdPartyRegistrationMax);
  30. });
  31. it('throws Error on missing required field', async function() {
  32. let lastError;
  33. try {
  34. await parse(createdPartyRegistrationMissingRequiredXml);
  35. } catch (e) {
  36. lastError = e;
  37. }
  38. expect(lastError).to.be.an('error');
  39. });
  40. });
  41. describe('serialize', function() {
  42. it('successfully serializes valid object', async function() {
  43. const serializedResponse = await serialize(createdPartyRegistrationMax);
  44. expect(serializedResponse).to.eql(
  45. '<oadr2b:oadrPayload xmlns:oadr2b="http://openadr.org/oadr-2.0b/2012/07"><oadr2b:oadrSignedObject><oadr2b:oadrCreatedPartyRegistration 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">4323</pyld:requestID></ei:eiResponse><ei:registrationID xmlns:ei="http://docs.oasis-open.org/ns/energyinterop/201110">3bd3c02dc6965c8b9240</ei:registrationID><ei:venID xmlns:ei="http://docs.oasis-open.org/ns/energyinterop/201110">3f59d85fbdf3997dbeb1</ei:venID><ei:vtnID xmlns:ei="http://docs.oasis-open.org/ns/energyinterop/201110">VTN_ID1</ei:vtnID><oadr2b:oadrProfiles><oadr2b:oadrProfile><oadr2b:oadrProfileName>2.0b</oadr2b:oadrProfileName><oadr2b:oadrTransports><oadr2b:oadrTransport><oadr2b:oadrTransportName>simpleHttp</oadr2b:oadrTransportName></oadr2b:oadrTransport></oadr2b:oadrTransports></oadr2b:oadrProfile></oadr2b:oadrProfiles><oadr2b:oadrRequestedOadrPollFreq><cal:duration xmlns:cal="urn:ietf:params:xml:ns:icalendar-2.0">PT10S</cal:duration></oadr2b:oadrRequestedOadrPollFreq></oadr2b:oadrCreatedPartyRegistration></oadr2b:oadrSignedObject></oadr2b:oadrPayload>',
  46. );
  47. });
  48. });
  49. });