UNPKG

gtfs-alerts-utils

Version:
90 lines (70 loc) 2.84 kB
'use strict'; const { FeedEntity, Alert, TimeRange } = require('gtfs-realtime-bindings-transit').transit_realtime; const GtfsAlertsUtils = require('../GtfsAlertsUtils'); const expect = require('chai').expect; describe('GtfsAlertsUtils time ranges', () => { let entity; beforeEach(() => { entity = FeedEntity.create(); entity.alert = Alert.create(); }); it('should return undefined with no time range', () => { expect(GtfsAlertsUtils.getEarliestStartDate(entity)).to.equal(undefined); expect(GtfsAlertsUtils.getLatestEndDate(entity)).to.equal(undefined); }); it('should return single value with single time range', () => { entity.alert.activePeriod.push(TimeRange.create({ start: 100, end: 100, })); expect(GtfsAlertsUtils.getEarliestStartDate(entity)).to.equal(100); expect(GtfsAlertsUtils.getLatestEndDate(entity)).to.equal(100); }); it('should return single value with single time range with only start', () => { entity.alert.activePeriod.push(TimeRange.create({ start: 100, })); expect(GtfsAlertsUtils.getEarliestStartDate(entity)).to.equal(100); expect(GtfsAlertsUtils.getLatestEndDate(entity)).to.equal(undefined); }); it('should return single value with single time range with only end', () => { entity.alert.activePeriod.push(TimeRange.create({ end: 100, })); expect(GtfsAlertsUtils.getEarliestStartDate(entity)).to.equal(undefined); expect(GtfsAlertsUtils.getLatestEndDate(entity)).to.equal(100); }); it('should return single value with two time range with only end/start each', () => { entity.alert.activePeriod.push(TimeRange.create({ end: 100, })); entity.alert.activePeriod.push(TimeRange.create({ start: 100, })); expect(GtfsAlertsUtils.getEarliestStartDate(entity)).to.equal(undefined); expect(GtfsAlertsUtils.getLatestEndDate(entity)).to.equal(undefined); }); it('should return single value with two time range with only end/start each but with one complete', () => { entity.alert.activePeriod.push(TimeRange.create({ start: 110, end: 120, })); entity.alert.activePeriod.push(TimeRange.create({ start: 100, })); expect(GtfsAlertsUtils.getEarliestStartDate(entity)).to.equal(100); expect(GtfsAlertsUtils.getLatestEndDate(entity)).to.equal(undefined); }); it('should return single value with two time range with only end/start each but with one complete', () => { entity.alert.activePeriod.push(TimeRange.create({ start: 110, end: 120, })); entity.alert.activePeriod.push(TimeRange.create({ start: 100, end: 200 })); expect(GtfsAlertsUtils.getEarliestStartDate(entity)).to.equal(100); expect(GtfsAlertsUtils.getLatestEndDate(entity)).to.equal(200); }); });