end-to-end.spec.js 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282
  1. 'use strict';
  2. const { expect } = require('chai');
  3. const sinon = require('sinon');
  4. const app = require('../../server');
  5. const { getVenClient } = require('../util/provision-ven');
  6. describe('VEN to VTN interactions', function() {
  7. describe('registration and event retrieval', async function() {
  8. let clock;
  9. after(async () => {
  10. clock.restore();
  11. });
  12. let ven;
  13. before(async function () {
  14. this.timeout(10000);
  15. clock = sinon.useFakeTimers(
  16. new Date('2020-04-26T01:00:00.000Z').getTime(),
  17. );
  18. await app.start();
  19. ven = await getVenClient();
  20. });
  21. it('should successfully return a vtnId from queryRegistration', async () => {
  22. const queryResponse = await ven.queryRegistration();
  23. expect(queryResponse.vtnId).to.be.a('string');
  24. });
  25. it('should successfully register and receive a vtnId and registrationId', async () => {
  26. const registrationResponse = await ven.register();
  27. expect(registrationResponse.vtnId).to.be.a('string');
  28. expect(registrationResponse.registrationId).to.be.a('string');
  29. });
  30. it('should successfully return a registrationId and venId from queryRegistration', async () => {
  31. const queryResponse = await ven.queryRegistration();
  32. expect(queryResponse.vtnId).to.be.a('string');
  33. expect(queryResponse.registrationId).to.be.a('string');
  34. expect(queryResponse.venId).to.be.a('string');
  35. });
  36. it('should return an event from requestEvents', async () => {
  37. const eventResponse = await ven.requestEvents();
  38. expect(eventResponse.events.length).to.eql(2);
  39. expect(eventResponse.vtnId).to.be.a('string');
  40. });
  41. it('should successfully cancel that registration', async () => {
  42. const cancelResponse = await ven.cancelRegistration();
  43. expect(cancelResponse.registrationId).to.be.a('string');
  44. expect(cancelResponse.venId).to.be.a('string');
  45. });
  46. after(async () => {
  47. await app.stop();
  48. });
  49. }).timeout(5000);
  50. describe('poll', async function() {
  51. let ven;
  52. let clock;
  53. after(async () => {
  54. clock.restore();
  55. });
  56. before(async function() {
  57. this.timeout(10000);
  58. clock = sinon.useFakeTimers(
  59. new Date('2020-04-26T01:00:00.000Z').getTime(),
  60. );
  61. await app.start();
  62. ven = await getVenClient();
  63. await ven.register();
  64. });
  65. it('should successfully poll for events', async () => {
  66. const pollResponse = await ven.poll();
  67. expect(pollResponse._type).to.eql('oadrDistributeEvent');
  68. expect(pollResponse.events.length).to.eql(2);
  69. }).timeout(10000);
  70. it('should not return the same event twice', async () => {
  71. const pollResponse = await ven.poll();
  72. expect(pollResponse._type).to.eql('oadrResponse');
  73. }).timeout(5000);
  74. after(async () => {
  75. await app.stop();
  76. });
  77. }).timeout(5000);
  78. describe('report', async function() {
  79. let ven;
  80. let clock;
  81. after(async () => {
  82. clock.restore();
  83. });
  84. before(async function() {
  85. this.timeout(10000);
  86. clock = sinon.useFakeTimers(
  87. new Date('2020-04-26T01:00:00.000Z').getTime(),
  88. );
  89. await app.start();
  90. ven = await getVenClient();
  91. await ven.register();
  92. await ven.poll(); // poll for any events that may be waiting
  93. });
  94. it('should successfully subscribe to reports and receive data', async () => {
  95. const reqs = [
  96. {
  97. reportRequestId: '31c5ce71a68a73ece370',
  98. reportSpecifierId: 'TELEMETRY_STATUS',
  99. createdDateTime: '2020-05-07T10:05:41.421-06:00',
  100. duration: 'PT1H',
  101. reportName: 'METADATA_TELEMETRY_STATUS',
  102. descriptions: [
  103. {
  104. reportId: 'TelemetryStatusReport',
  105. reportType: 'x-resourceStatus',
  106. readingType: 'x-notApplicable',
  107. samplingRate: {
  108. minPeriod: 'PT1M',
  109. maxPeriod: 'PT1H',
  110. onChange: false,
  111. },
  112. },
  113. ],
  114. },
  115. {
  116. reportRequestId: '3d92d98e0b65d94e60a7',
  117. reportSpecifierId: 'TELEMETRY_USAGE',
  118. createdDateTime: '2020-05-07T10:05:41.421-06:00',
  119. duration: 'PT1H',
  120. reportName: 'METADATA_TELEMETRY_USAGE',
  121. descriptions: [
  122. {
  123. reportId: 'TelemetryUsageReport',
  124. reportType: 'usage',
  125. readingType: 'Direct Read',
  126. samplingRate: {
  127. minPeriod: 'PT1M',
  128. maxPeriod: 'PT1H',
  129. onChange: false,
  130. },
  131. },
  132. ],
  133. },
  134. ];
  135. // register reports
  136. await ven.registerReports(reqs);
  137. const pollResponse = await ven.poll();
  138. // poll has a request to create reports
  139. expect(pollResponse._type).to.eql('oadrCreateReport');
  140. const createRequestId = pollResponse.reportRequestId;
  141. const [
  142. telemetryStatusReportRequestId,
  143. telemetryUsageReportRequestId,
  144. ] = pollResponse.requests.map(x => x.reportRequestId);
  145. // notify vtn that reports have been created
  146. await ven.notifyCreatedReports(createRequestId, [
  147. telemetryStatusReportRequestId,
  148. telemetryUsageReportRequestId,
  149. ]);
  150. // poll is empty, no reports to create
  151. const pollResponse2 = await ven.poll();
  152. expect(pollResponse2._type).to.eql('oadrResponse');
  153. // send report
  154. const reports = [
  155. {
  156. createdDateTime: '2020-05-08T21:27:49.591-06:00',
  157. duration: 'PT1M',
  158. intervals: [
  159. {
  160. duration: 'PT1M',
  161. reportPayloads: [
  162. {
  163. dataQuality: 'Quality Good - Non Specific',
  164. payloadFloat: 161.97970171999845,
  165. reportId: 'TelemetryUsageReport',
  166. },
  167. ],
  168. startDate: '2020-05-08T21:26:49.562-06:00',
  169. },
  170. ],
  171. reportName: 'TELEMETRY_USAGE',
  172. reportRequestId: telemetryUsageReportRequestId,
  173. reportSpecifierId: 'TELEMETRY_USAGE',
  174. startDate: '2020-05-08T21:26:49.562-06:00',
  175. },
  176. {
  177. createdDateTime: '2020-05-13T10:56:11.058-06:00',
  178. duration: 'PT1M',
  179. intervals: [
  180. {
  181. duration: 'PT1M',
  182. reportPayloads: [
  183. {
  184. dataQuality: 'Quality Good - Non Specific',
  185. payloadStatus: {
  186. online: true,
  187. manualOverride: false,
  188. loadControlState: {
  189. oadrLevelOffset: {
  190. oadrNormal: 40,
  191. oadrCurrent: 50,
  192. },
  193. },
  194. },
  195. reportId: 'TelemetryStatusReport',
  196. },
  197. ],
  198. startDate: '2020-05-13T10:56:11.058-06:00',
  199. },
  200. ],
  201. reportName: 'TELEMETRY_STATUS',
  202. reportRequestId: telemetryStatusReportRequestId,
  203. reportSpecifierId: 'TELEMETRY_STATUS',
  204. startDate: '2020-05-13T10:56:11.058-06:00',
  205. },
  206. ];
  207. await ven.sendReportData(reports);
  208. }).timeout(10000);
  209. after(async () => {
  210. await app.stop();
  211. });
  212. }).timeout(5000);
  213. describe('optIn', async function() {
  214. let clock;
  215. after(async () => {
  216. clock.restore();
  217. });
  218. let ven, events, pollResponse;
  219. before(async function() {
  220. this.timeout(10000);
  221. clock = sinon.useFakeTimers(
  222. new Date('2020-04-26T01:00:00.000Z').getTime(),
  223. );
  224. await app.start();
  225. ven = await getVenClient();
  226. await ven.register();
  227. pollResponse = await ven.poll();
  228. events = pollResponse.events;
  229. });
  230. it('should successfully opt in', async () => {
  231. const eventId = events[0].eventDescriptor.eventId;
  232. const modificationNumber = events[0].eventDescriptor.modificationNumber;
  233. await ven.opt('optIn', eventId, modificationNumber);
  234. }).timeout(5000);
  235. it('should be able to opt out after opting in', async () => {
  236. const eventId = events[0].eventDescriptor.eventId;
  237. const modificationNumber = events[0].eventDescriptor.modificationNumber;
  238. await ven.opt('optOut', eventId, modificationNumber);
  239. }).timeout(5000);
  240. after(async () => {
  241. await app.stop();
  242. });
  243. }).timeout(5000);
  244. });