| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149 |
- 'use strict';
- const { readFileSync } = require('fs');
- const path = require('path');
- const { expect } = require('chai');
- const sinon = require('sinon');
- const { Ven } = require('../../client/ven');
- const app = require('../../server');
- const { sequelize, Ven: VenDb } = require('../../db');
- const { port } = require('../../config');
- describe('VEN registration', function() {
- describe('successful registration and event retrieval', async function() {
- let clock;
- after(async () => {
- clock.restore();
- });
- let ven;
- before(async () => {
- clock = sinon.useFakeTimers(new Date('2020-04-26T01:00:00.000Z').getTime());
- await sequelize.sync();
- await VenDb.destroy({ truncate : true});
- await app.start();
- const clientCrtPem = readFileSync(path.join(__dirname, 'integration-client.crt'), 'utf-8');
- ven = new Ven(`http://127.0.0.1:${port}`, clientCrtPem, 'aabbccddeeff', '17:32:59:FD:0E:B5:99:31:27:9C', 'ven.js1');
- });
- it('should successfully return a vtnId from queryRegistration', async () => {
- const queryResponse = await ven.queryRegistration();
- expect(queryResponse.vtnId).to.be.a('string');
- });
- it('should successfully register and receive a vtnId and registrationId', async () => {
- const registrationResponse = await ven.register();
- expect(registrationResponse.vtnId).to.be.a('string');
- expect(registrationResponse.registrationId).to.be.a('string');
- });
- it('should successfully return a registrationId and venId from queryRegistration', async () => {
- const queryResponse = await ven.queryRegistration();
- expect(queryResponse.vtnId).to.be.a('string');
- expect(queryResponse.registrationId).to.be.a('string');
- expect(queryResponse.venId).to.be.a('string');
- });
- it('should return an event from requestEvents', async () => {
- const eventResponse = await ven.requestEvents();
- expect(eventResponse.events.length).to.eql(1);
- expect(eventResponse.vtnId).to.be.a('string');
- });
- it('should successfully cancel that registration', async () => {
- const cancelResponse = await ven.cancelRegistration();
- expect(cancelResponse.registrationId).to.be.a('string');
- expect(cancelResponse.venId).to.be.a('string');
- });
- after(async () => {
- await app.stop();
- });
- });
- describe('successful poll', async function() {
- let ven;
- let clock;
- after(async () => {
- clock.restore();
- });
- before(async () => {
- clock = sinon.useFakeTimers(new Date('2020-04-26T01:00:00.000Z').getTime());
- await sequelize.sync();
- await VenDb.destroy({ truncate : true});
- await app.start();
- const clientCrtPem = readFileSync(path.join(__dirname, 'integration-client.crt'), 'utf-8');
- ven = new Ven(`http://127.0.0.1:${port}`, clientCrtPem, 'aabbccddeeff', '17:32:59:FD:0E:B5:99:31:27:9C', 'ven.js1');
- await ven.register();
- });
- it('should successfully poll for events', async () => {
- const pollResponse = await ven.poll();
- expect(pollResponse._type).to.eql('oadrDistributeEvent');
- expect(pollResponse.events.length).to.eql(1);
- });
- after(async () => {
- await app.stop();
- });
- });
- describe('successful optIn', async function() {
- let clock;
- after(async () => {
- clock.restore();
- });
- let ven, events, pollResponse;
- before(async () => {
- clock = sinon.useFakeTimers(new Date('2020-04-26T01:00:00.000Z').getTime());
- await sequelize.sync();
- await VenDb.destroy({ truncate : true});
- await app.start();
- const clientCrtPem = readFileSync(path.join(__dirname, 'integration-client.crt'), 'utf-8');
- ven = new Ven(`http://127.0.0.1:${port}`, clientCrtPem, 'aabbccddeeff', '17:32:59:FD:0E:B5:99:31:27:9C', 'ven.js1');
- await ven.register();
- pollResponse = await ven.poll();
- events = pollResponse.events;
- });
- it('should successfully poll for events', async () => {
- expect(pollResponse._type).to.eql('oadrDistributeEvent');
- expect(pollResponse.events.length).to.eql(1);
- });
- it('should return same events if not opted', async () => {
- const pollResponse = await ven.poll();
- expect(pollResponse._type).to.eql('oadrDistributeEvent');
- expect(pollResponse.events.length).to.eql(1);
- });
- it('should return no events if opted', async () => {
- const eventId = events[0].eventDescriptor.eventId;
- const modificationNumber = events[0].eventDescriptor.modificationNumber;
- await ven.opt('optIn', eventId, modificationNumber);
- const pollResponse = await ven.poll();
- expect(pollResponse._type).to.eql('oadrResponse');
- });
- after(async () => {
- await app.stop();
- });
- });
- });
|