| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111 |
- 'use strict';
- const { v4 } = require('uuid');
- const _ = require('lodash');
- class FakeNantumModule {
- constructor({ vens, events, venRegistrations, venReports, seenEvents } = {}) {
- this.vens = vens || [];
- this.venRegistrations = venRegistrations || [];
- this.venReports = venReports || [];
- this.events = events || [];
- this.seenEvents = seenEvents || [];
- this.eventResponses = [];
- this.reportReadings = [];
- }
- async getVenRegistration(clientCertificateFingerprint) {
- return _.find(this.venRegistrations, {
- client_certificate_fingerprint: clientCertificateFingerprint,
- });
- }
- async createVenRegistration(ven) {
- const venId = v4();
- const newVen = { ...ven, _id: venId };
- this.venRegistrations.push(newVen);
- }
- async deleteVenRegistration(venId) {
- const venIndex = _.findIndex(this.venRegistrations, { _id: venId });
- if (venIndex == null)
- throw new Error(`Could not find ven with _id: ${venId}`);
- this.venRegistrations = this.venRegistrations.filter(ven => ven._id !== venId);
- }
- async getEventResponse(ven, eventId, modificationNumber) {
- return _.find(this.eventResponses, {
- oadr_utility_ven_id: ven._id,
- oadr_utility_event_id: eventId,
- modification_number: modificationNumber,
- })[0];
- }
- async createEventResponse(eventResponse) {
- const eventResponseId = v4();
- const newEventResponse = { ...eventResponse, _id: eventResponseId };
- this.eventResponses.push(newEventResponse);
- }
- async updateEventResponse(id, newProperties) {
- const eventResponseIndex = _.findIndex(this.eventResponses, { _id: id });
- if (eventResponseIndex == null)
- throw new Error(`Could not find eventResponse with _id: ${id}`);
- this.eventResponses[eventResponseIndex] = {
- ...this.eventResponses[eventResponseIndex],
- ...newProperties,
- };
- }
- markEventAsSeen(oadrUtilityVenRegistrationId, eventId, modificationNumber) {
- const newSeenEvent = {
- _id: v4(),
- oadr_utility_ven_registration_id: oadrUtilityVenRegistrationId,
- oadr_utility_event_id: eventId,
- modification_number: modificationNumber
- };
- this.seenEvents.push(newSeenEvent);
- }
- async getSeenEvents(venRegistrationId) {
- return _.filter(this.seenEvents, {
- oadr_utility_ven_registration_id: venRegistrationId,
- });
- }
- async getVen(venRegistrationId) {
- return _.filter(this.seenEvents, {
- oadr_utility_ven_registration_id: venRegistrationId,
- })[0];
- }
- async getEvents() {
- return [...this.events];
- }
- async sendReportReadings(ven, readings) {
- this.reportReadings.push({ ven: ven._id, readings });
- }
- async getVenReports(venRegistrationId) {
- return _.find(this.venReports, {
- oadr_utility_ven_registration_id: venRegistrationId,
- });
- }
- async updateVenReports(venReportId, newReportList) {
- const venReportIndex = _.findIndex(this.venReports, { _id: venReportId });
- if (venReportIndex == null)
- throw new Error(`Could not find venReport with _id: ${venReportId}`);
- this.venReports[venReportIndex].reports = newReportList;
- }
- async createVenReports(venReports) {
- const venReportsId = v4();
- const newVenReport = { ...venReports, _id: venReportsId };
- this.venReports.push(newVenReport);
- }
- }
- module.exports = FakeNantumModule;
|