diff --git a/lib/sympto/index.js b/lib/sympto/index.js index 2d2f244..e32f8a2 100644 --- a/lib/sympto/index.js +++ b/lib/sympto/index.js @@ -7,23 +7,25 @@ export default function ({ cycle, previousCycle }) { // TODO check for basic stuff, throw if nonexistent const status = { assumeFertility: true, - phases: { - periOvulatory: { - start: { - date: null - }, - cycleDays: null - } - } + phases: {} } // if there was no first higher measurement in the previous cycle, // no infertile pre-ovulatory phase may be assumed if (getTemperatureShift(previousCycle).detected && !cycle[0].mucus) { status.phases.preOvulatory = getPreOvulatoryPhase(cycle) + if (status.phases.preOvulatory.cycleDays.length === cycle.length) { + status.assumeFertility = false + return status + } } + status.phases.periOvulatory = { + start: { date: null }, + cycleDays: [] + } const periPhase = status.phases.periOvulatory + if (status.phases.preOvulatory) { const prePhase = status.phases.preOvulatory periPhase.start.date = LocalDate.parse(prePhase.end.date).plusDays(1).toString() diff --git a/test/sympto/fixtures.js b/test/sympto/fixtures.js index 14d1eb2..159c055 100644 --- a/test/sympto/fixtures.js +++ b/test/sympto/fixtures.js @@ -83,10 +83,19 @@ const cycleWithoutAnyShifts = [ { temperature: 36.45, mucus: 1 } ].map(convertToSymptoFormat) +const fiveDayCycle = [ + { temperature: 36.6, bleeding: 2 }, + { temperature: 36.65 }, + { temperature: 36.5 }, + { temperature: 36.6 }, + { temperature: 36.55 } +].map(convertToSymptoFormat) + export { cycleWithoutTempShift, cycleWithTempAndMucusShift, cycleWithTempAndNoMucusShift, cycleWithTempShift, - cycleWithoutAnyShifts + cycleWithoutAnyShifts, + fiveDayCycle } \ No newline at end of file diff --git a/test/sympto/index.spec.js b/test/sympto/index.spec.js index e3cd067..b223629 100644 --- a/test/sympto/index.spec.js +++ b/test/sympto/index.spec.js @@ -1,7 +1,7 @@ import chai from 'chai' import getSensiplanStatus from '../../lib/sympto' import { - cycleWithoutTempShift, cycleWithTempAndMucusShift, cycleWithTempAndNoMucusShift, cycleWithTempShift, cycleWithoutAnyShifts + cycleWithoutTempShift, cycleWithTempAndMucusShift, cycleWithTempAndNoMucusShift, cycleWithTempShift, cycleWithoutAnyShifts, fiveDayCycle } from './fixtures' const expect = chai.expect @@ -52,6 +52,23 @@ describe('sympto', () => { }) }) describe('with previous higher measurement', () => { + describe('with no shifts detects pre-ovulatory phase', function () { + it('according to 5-day-rule', function () { + const status = getSensiplanStatus({ + cycle: fiveDayCycle, + previousCycle: cycleWithTempShift + }) + + expect(Object.keys(status.phases).length).to.eql(1) + expect(status.assumeFertility).to.be.false() + expect(status.phases.preOvulatory).to.eql({ + cycleDays: fiveDayCycle, + start: { date: '2018-06-01' }, + end: { date: '2018-06-05' } + }) + }) + + }) describe('with no shifts detects pre- and peri-ovulatory phase', function () { it('according to 5-day-rule', function () { const status = getSensiplanStatus({