From ea458b955b73bbf39374e616c7e30ceb44d05c06 Mon Sep 17 00:00:00 2001 From: Mark Polak Date: Fri, 7 Apr 2017 14:00:49 +0200 Subject: [PATCH] Add test for filtering periods and correct stream error --- src/main/period/period-service.js | 4 ++-- src/test/specs/period/period-service_spec.js | 7 ++++++- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/src/main/period/period-service.js b/src/main/period/period-service.js index e8c525a..23f556c 100644 --- a/src/main/period/period-service.js +++ b/src/main/period/period-service.js @@ -14,7 +14,7 @@ function periodService(dataStore, rx, $rootScope) { return rx.Observable.fromPromise(dataStore.getPeriodSettings()) .map(onlyPeriodsForWorkflow(workflow)) .map(periodSettingsToArray) - .filter(onlyOpenPeriods) + .map(onlyOpenPeriods) .map(onlyNameAndIdProperties) .safeApply($rootScope); } @@ -40,7 +40,7 @@ function periodService(dataStore, rx, $rootScope) { var start = Date.parse(startDate); var end = Date.parse(endDate); var now = Date.now(); - + if (isNumber(start) && isNumber(end)) { return (start < now) && (now < end); } diff --git a/src/test/specs/period/period-service_spec.js b/src/test/specs/period/period-service_spec.js index 63c41d7..60c91bf 100644 --- a/src/test/specs/period/period-service_spec.js +++ b/src/test/specs/period/period-service_spec.js @@ -10,6 +10,11 @@ describe('Period service', function () { periodSettingMock = sinon.stub() .returns($q.when({ "MER Results": { // Id of dataApprovalWorkflow + "2016Q2": { + "name": "April - June 2016", + "start": "Mar 3 2017 21:00:00 GMT+0200", + "end": "Mar 4 2017 21:00:00 GMT+0200" + }, "2017Q1": { "name": "January - March 2017", "start": 'Fri Mar 31 2017 21:00:00 GMT+0200', @@ -63,7 +68,7 @@ describe('Period service', function () { expect(periodsForWorkflow$.subscribe).to.be.a('function'); }); - it('should return the periods for just the workflow', function (done) { + it('should return the open periods for the workflow', function (done) { var periodsForWorkflow$ = service.getPeriodsForWorkflow({ id: 'QeGps9iWl1i', name: 'MER Results' }); periodsForWorkflow$.subscribe(