Browse Source

PROD-1221: More XML serialization/parser test cases for event

Blake Schneider 5 years ago
parent
commit
32a7e52c99

+ 5 - 5
__tests__/unit/processes/event.spec.js

@@ -6,8 +6,8 @@ const sinon = require('sinon');
 const rewire = require('rewire');
 
 const {
-  requestEvent1,
-  createdEvent1,
+  requestEventMax,
+  createdEventMax,
   createdEventInvalidEventId1,
 } = require('../xml/event/js-requests');
 
@@ -51,13 +51,13 @@ describe('Event', function() {
 
   describe('retrieveEvents', function() {
     it('translates nantum event to oadr event', async () => {
-      const venId = requestEvent1.venId;
+      const venId = requestEventMax.venId;
       const commonName = v4()
         .replace(/-/g, '')
         .substring(0, 12);
 
       const events = await rewired.retrieveEvents(
-        requestEvent1,
+        requestEventMax,
         commonName,
         venId,
       );
@@ -97,7 +97,7 @@ describe('Event', function() {
       );
       expect(pollResponse1.events.length).to.eql(1);
 
-      await rewired.updateOptType(createdEvent1, commonName, venId);
+      await rewired.updateOptType(createdEventMax, commonName, venId);
       const pollResponse2 = await rewired.pollForEvents(
         oadrPoll1,
         commonName,

File diff suppressed because it is too large
+ 37 - 18
__tests__/unit/xml/event/created-event.spec.js


File diff suppressed because it is too large
+ 45 - 29
__tests__/unit/xml/event/distribute-event.spec.js


+ 37 - 4
__tests__/unit/xml/event/js-requests.js

@@ -1,13 +1,43 @@
 'use strict';
 
-const requestEvent1 = {
+const requestEventMin = {
+  _type: 'oadrRequestEvent',
+  requestId: '2233',
+  venId: 'D8:1D:4B:20:5A:65:4C:50:32:FA',
+};
+
+const requestEventMax = {
   _type: 'oadrRequestEvent',
   requestId: '2233',
   venId: 'D8:1D:4B:20:5A:65:4C:50:32:FA',
   replyLimit: '2',
 };
 
-const createdEvent1 = {
+const createdEventMin1 = {
+  _type: 'oadrCreatedEvent',
+  responseCode: '200',
+  responseRequestId: '336f7e47b92eefe985ec',
+  venId: 'D8:1D:4B:20:5A:65:4C:50:32:FA',
+  eventResponses: [],
+};
+
+const createdEventMin2 = {
+  _type: 'oadrCreatedEvent',
+  responseCode: '200',
+  responseRequestId: '336f7e47b92eefe985ec',
+  venId: 'D8:1D:4B:20:5A:65:4C:50:32:FA',
+  eventResponses: [
+    {
+      responseCode: '200',
+      responseRequestId: '336f7e47b92eefe985ec',
+      optType: 'optIn',
+      eventId: 'a2fa542eca8d4e829ff5c0f0c8e68710',
+      modificationNumber: 2,
+    },
+  ],
+};
+
+const createdEventMax = {
   _type: 'oadrCreatedEvent',
   responseCode: '200',
   responseDescription: 'OK',
@@ -62,8 +92,11 @@ const createdEventOldModificationNumber1 = {
 };
 
 module.exports = {
-  createdEvent1,
+  createdEventMin1,
+  createdEventMin2,
+  createdEventMax,
   createdEventInvalidEventId1,
   createdEventOldModificationNumber1,
-  requestEvent1,
+  requestEventMin,
+  requestEventMax,
 };

+ 16 - 16
__tests__/unit/xml/event/js-responses.js

@@ -1,9 +1,15 @@
 'use strict';
 
-const generatedEvent1 = {
+const distributeEventMin1 = {
+  _type: 'oadrDistributeEvent',
+  requestId: '81dc20dfea7df7a2bb9e',
+  vtnId: 'NANTUM_VTN',
+  events: [],
+};
+
+const distributeEventMin2 = {
   _type: 'oadrDistributeEvent',
   responseCode: '200',
-  responseDescription: 'OK',
   responseRequestId: '9383fc5946cb0e14ef5a',
   requestId: '81dc20dfea7df7a2bb9e',
   vtnId: 'NANTUM_VTN',
@@ -16,17 +22,10 @@ const generatedEvent1 = {
         createdDateTime: '2020-04-14T16:06:39.000Z',
         eventStatus: 'far',
         testEvent: false,
-        modificationReason: '',
-        priority: 0,
-        vtnComment: '',
       },
       activePeriod: {
-        startDate: '2020-04-18T16:21:00.000Z',
+        startDate: '2020-04-14T16:21:00.000Z',
         duration: 'PT60M',
-        toleranceTolerateStartAfter: 'PT5M',
-        notificationDuration: 'PT5M',
-        rampUpDuration: 'PT10M',
-        recoveryDuration: 'PT12M',
       },
       signals: {
         event: [
@@ -34,7 +33,7 @@ const generatedEvent1 = {
             intervals: [
               {
                 signalPayloads: [50],
-                duration: 'PT60M',
+                duration: 'PT10M',
                 uid: '1',
               },
             ],
@@ -52,7 +51,7 @@ const generatedEvent1 = {
   ],
 };
 
-const generatedEvent2 = {
+const distributeEventMax = {
   _type: 'oadrDistributeEvent',
   responseCode: '200',
   responseDescription: 'OK',
@@ -265,7 +264,7 @@ const generatedEvent2 = {
   ],
 };
 
-const epriEvent1 = {
+const distributeEventEpri1 = {
   _type: 'oadrDistributeEvent',
   responseCode: '200',
   responseDescription: 'OK',
@@ -530,8 +529,9 @@ const generatedFromNantumEvent1 = {
 };
 
 module.exports = {
-  generatedEvent1,
-  generatedEvent2,
+  distributeEventMin1,
+  distributeEventMin2,
+  distributeEventMax,
+  distributeEventEpri1,
   generatedFromNantumEvent1,
-  epriEvent1,
 };

File diff suppressed because it is too large
+ 28 - 16
__tests__/unit/xml/event/request-event.spec.js


File diff suppressed because it is too large
+ 97 - 6
__tests__/unit/xml/event/xml-requests.js


File diff suppressed because it is too large
+ 454 - 2
__tests__/unit/xml/event/xml-responses.js


+ 10 - 5
xml/event/created-event.js

@@ -18,12 +18,11 @@ function parseEiResponse(response) {
 }
 
 function parseEventResponse(eventResponse) {
-  return {
+  const result = {
     responseCode: required(
       childAttr(eventResponse, 'responseCode'),
       'responseCode',
     ),
-    responseDescription: childAttr(eventResponse, 'responseDescription'),
     responseRequestId: required(
       childAttr(eventResponse, 'requestID'),
       'requestID',
@@ -43,9 +42,16 @@ function parseEventResponse(eventResponse) {
       'qualifiedEventID.modificationNumber',
     ),
   };
+  const responseDescription = childAttr(eventResponse, 'responseDescription');
+  if (responseDescription != null)
+    result.responseDescription = responseDescription;
+  return result;
 }
 
 function parseEventResponses(eventResponses) {
+  if (eventResponses['$$'] == null) {
+    return [];
+  }
   const unwrappedEventResponses = eventResponses['$$']['eventResponse'];
   return unwrappedEventResponses.map(x => parseEventResponse(x['$$']));
 }
@@ -58,12 +64,11 @@ function parseEiCreatedEvent(eiCreatedEvent) {
   const result = {
     _type: 'oadrCreatedEvent',
     responseCode: code,
-    responseDescription: description,
     responseRequestId: requestId,
+    venId: required(childAttr(eiCreatedEvent, 'venID'), 'venID'),
   };
 
-  const venId = childAttr(eiCreatedEvent, 'venID');
-  if (venId != null) result.venId = venId;
+  if (description != null) result.responseDescription = description;
 
   const eventResponses = childAttr(eiCreatedEvent, 'eventResponses');
   if (eventResponses != null)

+ 11 - 11
xml/event/distribute-event.js

@@ -857,26 +857,26 @@ async function parse(input) {
       'oadrDistributeEvent'
     ][0]['$$'];
 
-  const { code, description, requestId: responseRequestId } = parseEiResponse(
-    o['eiResponse'][0]['$$'],
-  );
-
   const result = {
     _type: 'oadrDistributeEvent',
-    responseCode: code,
-    responseDescription: description,
-    responseRequestId: responseRequestId,
   };
 
-  if (code < 200 || code >= 300) {
-    return result;
+  if (o['eiResponse']) {
+    const { code, description, requestId } = parseEiResponse(
+      o['eiResponse'][0]['$$'],
+    );
+    result.responseCode = code;
+    result.responseRequestId = requestId;
+    if (description != null) result.responseDescription = description;
+    if (code < 200 || code >= 300) {
+      return result;
+    }
   }
 
   const payloadRequestId = childAttr(o, 'requestID');
   if (payloadRequestId != null) result.requestId = payloadRequestId;
 
-  const vtnId = childAttr(o, 'vtnID');
-  if (vtnId != null) result.vtnId = vtnId;
+  result.vtnId = required(childAttr(o, 'vtnID'), 'vtnID');
 
   const events = parseEvents(o['oadrEvent'] || []);