From 9e1393766ad8ffca5ffa89d2d1795966bba95fd0 Mon Sep 17 00:00:00 2001 From: emelko <ml.kochsiek@mailbox.org> Date: Mon, 30 Jul 2018 14:42:00 +0200 Subject: [PATCH] Split fixtures into temp & mucus and temp & cervix files Add first blueprint for temp&cervix tests --- test/sympto/index.spec.js | 660 ----------------- test/sympto/mucus-temp-fixtures.js | 8 - test/sympto/mucus-temp.spec.js | 1026 +++++++++++++-------------- test/sympto/mucus-temp.spec.js~HEAD | 661 +++++++++++++++++ 4 files changed, 1156 insertions(+), 1199 deletions(-) delete mode 100644 test/sympto/index.spec.js create mode 100644 test/sympto/mucus-temp.spec.js~HEAD diff --git a/test/sympto/index.spec.js b/test/sympto/index.spec.js deleted file mode 100644 index 88ada869..00000000 --- a/test/sympto/index.spec.js +++ /dev/null @@ -1,660 +0,0 @@ -import chai from 'chai' -import getSensiplanStatus from '../../lib/sympto' -import { AssertionError } from 'assert' -import { - cycleWithoutFhm, - longAndComplicatedCycle, - cycleWithTempAndNoMucusShift, - cycleWithFhm, - cycleWithoutAnyShifts, - fiveDayCycle, - cycleWithEarlyMucus, - cycleWithMucusOnFirstDay, - mucusPeakAndFhmOnSameDay, - fhmTwoDaysBeforeMucusPeak, - fhm5DaysAfterMucusPeak, - mucusPeak5DaysAfterFhm, - mucusPeakTwoDaysBeforeFhm, - fhmOnDay12, - fhmOnDay15, - mucusPeakSlightlyBeforeTempShift, - tempAndCervixEvalEndOnSameDay -} from './fixtures' - -const expect = chai.expect - -describe('sympto', () => { - describe('with no previous higher measurement', () => { - it('with no shifts detects only peri-ovulatory', function () { - const status = getSensiplanStatus({ - cycle: cycleWithoutAnyShifts, - previousCycle: cycleWithoutFhm - }) - - expect(status).to.eql({ - - phases: { - periOvulatory: { - start: { date: '2018-06-01' }, - cycleDays: cycleWithoutAnyShifts - } - }, - }) - }) - - it('with shifts detects only peri-ovulatory and post-ovulatory', () => { - const status = getSensiplanStatus({ - cycle: longAndComplicatedCycle, - previousCycle: cycleWithoutFhm - }) - - expect(status.temperatureShift).to.be.an('object') - expect(status.mucusShift).to.be.an('object') - - expect(Object.keys(status.phases).length).to.eql(2) - expect(status.phases.periOvulatory).to.eql({ - start: { date: '2018-06-01' }, - end: { date: '2018-06-21', time: '18:00' }, - cycleDays: longAndComplicatedCycle - .filter(({date}) => date <= '2018-06-21') - }) - expect(status.phases.postOvulatory).to.eql({ - start: { - date: '2018-06-21', - time: '18:00' - }, - cycleDays: longAndComplicatedCycle - .filter(({date}) => date >= '2018-06-21') - }) - }) - }) - 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: cycleWithFhm - }) - - expect(Object.keys(status.phases).length).to.eql(1) - - 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', () => { - it('according to 5-day-rule', function () { - const status = getSensiplanStatus({ - cycle: cycleWithTempAndNoMucusShift, - previousCycle: cycleWithFhm - }) - - expect(Object.keys(status.phases).length).to.eql(2) - - expect(status.phases.preOvulatory).to.eql({ - cycleDays: cycleWithTempAndNoMucusShift - .filter(({date}) => date <= '2018-06-05'), - start: { date: '2018-06-01' }, - end: { date: '2018-06-05' } - }) - expect(status.phases.periOvulatory).to.eql({ - cycleDays: cycleWithTempAndNoMucusShift - .filter(({date}) => date > '2018-06-05'), - start: { date: '2018-06-06' } - }) - }) - it('according to 5-day-rule with shortened pre-phase', function () { - const status = getSensiplanStatus({ - cycle: cycleWithEarlyMucus, - previousCycle: cycleWithFhm - }) - - expect(Object.keys(status.phases).length).to.eql(2) - - expect(status.phases.preOvulatory).to.eql({ - cycleDays: [cycleWithEarlyMucus[0]], - start: { date: '2018-06-01' }, - end: { date: '2018-06-01' } - }) - expect(status.phases.periOvulatory).to.eql({ - cycleDays: cycleWithEarlyMucus.slice(1), - start: { date: '2018-06-02' } - }) - }) - }) - describe('with shifts detects pre- and peri-ovulatory phase', function () { - it('according to 5-day-rule', function () { - const status = getSensiplanStatus({ - cycle: longAndComplicatedCycle, - previousCycle: cycleWithFhm - }) - - expect(Object.keys(status.phases).length).to.eql(3) - - expect(status.phases.preOvulatory).to.eql({ - cycleDays: longAndComplicatedCycle - .filter(({date}) => date <= '2018-06-05'), - start: { date: '2018-06-01' }, - end: { date: '2018-06-05' } - }) - expect(status.phases.periOvulatory).to.eql({ - cycleDays: longAndComplicatedCycle - .filter(({date}) => date > '2018-06-05' && date <= '2018-06-21'), - start: { date: '2018-06-06' }, - end: { date: '2018-06-21', time: '18:00'} - }) - expect(status.phases.postOvulatory).to.eql({ - cycleDays: longAndComplicatedCycle - .filter(({date}) => date >= '2018-06-21'), - start: { date: '2018-06-21', time: '18:00'} - }) - }) - - }) - }) - - describe('combining first higher measurment and mucus peak', () => { - it('with fhM + mucus peak on same day finds start of postovu phase', () => { - const status = getSensiplanStatus({ - cycle: mucusPeakAndFhmOnSameDay, - previousCycle: cycleWithFhm - }) - - expect(status.temperatureShift).to.be.an('object') - expect(status.mucusShift).to.be.an('object') - - expect(Object.keys(status.phases).length).to.eql(3) - expect(status.phases.preOvulatory).to.eql({ - start: { date: '2018-06-01' }, - end: { date: '2018-06-05' }, - cycleDays: mucusPeakAndFhmOnSameDay - .filter(({date}) => date <= '2018-06-05') - }) - expect(status.phases.periOvulatory).to.eql({ - start: { date: '2018-06-06' }, - end: { date: '2018-06-21', time: '18:00' }, - cycleDays: mucusPeakAndFhmOnSameDay - .filter(({date}) => { - return date > '2018-06-05' && date <= '2018-06-21' - }) - }) - expect(status.phases.postOvulatory).to.eql({ - start: { - date: '2018-06-21', - time: '18:00' - }, - cycleDays: mucusPeakAndFhmOnSameDay - .filter(({date}) => date >= '2018-06-21') - }) - }) - - it('with fhM 2 days before mucus peak waits for end of mucus eval', () => { - const status = getSensiplanStatus({ - cycle: fhmTwoDaysBeforeMucusPeak, - previousCycle: cycleWithFhm - }) - - expect(status.temperatureShift).to.be.an('object') - expect(status.mucusShift).to.be.an('object') - - expect(Object.keys(status.phases).length).to.eql(3) - expect(status.phases.preOvulatory).to.eql({ - start: { date: '2018-06-01' }, - end: { date: '2018-06-05' }, - cycleDays: fhmTwoDaysBeforeMucusPeak - .filter(({date}) => date <= '2018-06-05') - }) - expect(status.phases.periOvulatory).to.eql({ - start: { date: '2018-06-06' }, - end: { date: '2018-06-26', time: '18:00' }, - cycleDays: fhmTwoDaysBeforeMucusPeak - .filter(({date}) => { - return date > '2018-06-05' && date <= '2018-06-26' - }) - }) - expect(status.phases.postOvulatory).to.eql({ - start: { - date: '2018-06-26', - time: '18:00' - }, - cycleDays: fhmTwoDaysBeforeMucusPeak - .filter(({date}) => date >= '2018-06-26') - }) - }) - - it('another example for mucus peak before temp shift', () => { - const status = getSensiplanStatus({ - cycle: mucusPeakSlightlyBeforeTempShift, - previousCycle: cycleWithFhm - }) - - expect(status.temperatureShift).to.be.an('object') - expect(status.mucusShift).to.be.an('object') - - expect(Object.keys(status.phases).length).to.eql(3) - expect(status.phases.preOvulatory).to.eql({ - start: { date: '2018-06-01' }, - end: { date: '2018-06-05' }, - cycleDays: mucusPeakSlightlyBeforeTempShift - .filter(({date}) => date <= '2018-06-05') - }) - expect(status.phases.periOvulatory).to.eql({ - start: { date: '2018-06-06' }, - end: { date: '2018-06-17', time: '18:00' }, - cycleDays: mucusPeakSlightlyBeforeTempShift - .filter(({date}) => { - return date > '2018-06-05' && date <= '2018-06-17' - }) - }) - expect(status.phases.postOvulatory).to.eql({ - start: { - date: '2018-06-17', - time: '18:00' - }, - cycleDays: mucusPeakSlightlyBeforeTempShift - .filter(({date}) => date >= '2018-06-17') - }) - }) - - it('with another mucus peak 5 days after fHM ignores it', () => { - const status = getSensiplanStatus({ - cycle: mucusPeak5DaysAfterFhm, - previousCycle: cycleWithFhm - }) - - expect(status.temperatureShift).to.be.an('object') - expect(status.mucusShift).to.be.an('object') - - expect(Object.keys(status.phases).length).to.eql(3) - expect(status.phases.preOvulatory).to.eql({ - start: { date: '2018-06-01' }, - end: { date: '2018-06-01' }, - cycleDays: mucusPeak5DaysAfterFhm - .filter(({date}) => date <= '2018-06-01') - }) - expect(status.phases.periOvulatory).to.eql({ - start: { date: '2018-06-02' }, - end: { date: '2018-06-22', time: '18:00' }, - cycleDays: mucusPeak5DaysAfterFhm - .filter(({date}) => { - return date > '2018-06-01' && date <= '2018-06-22' - }) - }) - expect(status.phases.postOvulatory).to.eql({ - start: { - date: '2018-06-22', - time: '18:00' - }, - cycleDays: mucusPeak5DaysAfterFhm - .filter(({date}) => date >= '2018-06-22') - }) - }) - - it('with mucus peak 2 days before fhM waits for end of temp eval', () => { - const status = getSensiplanStatus({ - cycle: mucusPeakTwoDaysBeforeFhm, - previousCycle: cycleWithFhm - }) - - expect(status.temperatureShift).to.be.an('object') - expect(status.mucusShift).to.be.an('object') - - expect(Object.keys(status.phases).length).to.eql(3) - expect(status.phases.preOvulatory).to.eql({ - start: { date: '2018-06-01' }, - end: { date: '2018-06-04' }, - cycleDays: mucusPeakTwoDaysBeforeFhm - .filter(({date}) => date <= '2018-06-04') - }) - expect(status.phases.periOvulatory).to.eql({ - start: { date: '2018-06-05' }, - end: { date: '2018-07-03', time: '18:00' }, - cycleDays: mucusPeakTwoDaysBeforeFhm - .filter(({date}) => { - return date > '2018-06-04' && date <= '2018-07-03' - }) - }) - expect(status.phases.postOvulatory).to.eql({ - start: { - date: '2018-07-03', - time: '18:00' - }, - cycleDays: mucusPeakTwoDaysBeforeFhm - .filter(({date}) => date >= '2018-07-03') - }) - }) - - it('with mucus peak 5 days before fhM waits for end of temp eval', () => { - const status = getSensiplanStatus({ - cycle: fhm5DaysAfterMucusPeak, - previousCycle: cycleWithFhm - }) - - expect(status.temperatureShift).to.be.an('object') - expect(status.mucusShift).to.be.an('object') - - expect(Object.keys(status.phases).length).to.eql(3) - expect(status.phases.preOvulatory).to.eql({ - start: { date: '2018-06-01' }, - end: { date: '2018-06-05' }, - cycleDays: fhm5DaysAfterMucusPeak - .filter(({date}) => date <= '2018-06-05') - }) - expect(status.phases.periOvulatory).to.eql({ - start: { date: '2018-06-06' }, - end: { date: '2018-06-21', time: '18:00' }, - cycleDays: fhm5DaysAfterMucusPeak - .filter(({date}) => { - return date > '2018-06-05' && date <= '2018-06-21' - }) - }) - expect(status.phases.postOvulatory).to.eql({ - start: { - date: '2018-06-21', - time: '18:00' - }, - cycleDays: fhm5DaysAfterMucusPeak - .filter(({date}) => date >= '2018-06-21') - }) - }) - }) - - describe('combining temperature and cervix measurment', () => { - it('with evaluation of temperature and cervix end on same day', () => { - const status = getSensiplanStatus({ - cycle: tempAndCervixEvalEndOnSameDay, - previousCycle: cycleWithFhm, - secondarySymptom: 'cervix' - }) - expect(Object.keys(status.phases).length).to.eql(3) - expect(status.phases.preOvulatory).to.eql({ - start: { date: '2018-06-01' }, - end: { date: '2018-06-05' }, - cycleDays: tempAndCervixEvalEndOnSameDay - .filter(({date}) => date <= '2018-06-05') - }) - expect(status.phases.periOvulatory).to.eql({ - start: { date: '2018-06-06' }, - end: { date: '2018-06-17', time: '18:00' }, - cycleDays: tempAndCervixEvalEndOnSameDay - .filter(({date}) => { - return date > '2018-06-05' && date <= '2018-06-17' - }) - }) - expect(status.phases.postOvulatory).to.eql({ - start: { date: '2018-06-17', time: '18:00' }, - cycleDays: tempAndCervixEvalEndOnSameDay - .filter(({date}) => date >= '2018-06-17') - }) - expect(status.cervixShift.detected).to.be.true() - expect(status.cervixShift.cervixPeak.date).to.eql('2018-06-14') - expect(status.cervixShift.evaluationCompleteDay.date).to.eql('2018-06-17') - - }) - }) - - describe('applying the minus-8 rule', () => { - it('shortens the pre-ovu phase if there is a previous <13 fhm', () => { - const status = getSensiplanStatus({ - cycle: longAndComplicatedCycle, - previousCycle: fhmOnDay15, - earlierCycles: [fhmOnDay12, ...Array(10).fill(fhmOnDay15)] - }) - - expect(status.temperatureShift).to.be.an('object') - expect(status.mucusShift).to.be.an('object') - - expect(Object.keys(status.phases).length).to.eql(3) - expect(status.phases.preOvulatory).to.eql({ - start: { date: '2018-06-01' }, - end: { date: '2018-06-04' }, - cycleDays: longAndComplicatedCycle - .filter(({date}) => date <= '2018-06-04') - }) - expect(status.phases.periOvulatory).to.eql({ - start: { date: '2018-06-05' }, - end: { date: '2018-06-21', time: '18:00' }, - cycleDays: longAndComplicatedCycle - .filter(({date}) => { - return date > '2018-06-04' && date <= '2018-06-21' - }) - }) - expect(status.phases.postOvulatory).to.eql({ - start: { - date: '2018-06-21', - time: '18:00' - }, - cycleDays: longAndComplicatedCycle - .filter(({date}) => date >= '2018-06-21') - }) - }) - it('shortens pre-ovu phase with prev <13 fhm even with <12 cycles', () => { - const status = getSensiplanStatus({ - cycle: longAndComplicatedCycle, - previousCycle: fhmOnDay12, - earlierCycles: Array(10).fill(fhmOnDay12) - }) - - expect(status.temperatureShift).to.be.an('object') - expect(status.mucusShift).to.be.an('object') - - expect(Object.keys(status.phases).length).to.eql(3) - expect(status.phases.preOvulatory).to.eql({ - start: { date: '2018-06-01' }, - end: { date: '2018-06-04' }, - cycleDays: longAndComplicatedCycle - .filter(({date}) => date <= '2018-06-04') - }) - expect(status.phases.periOvulatory).to.eql({ - start: { date: '2018-06-05' }, - end: { date: '2018-06-21', time: '18:00' }, - cycleDays: longAndComplicatedCycle - .filter(({date}) => { - return date > '2018-06-04' && date <= '2018-06-21' - }) - }) - expect(status.phases.postOvulatory).to.eql({ - start: { - date: '2018-06-21', - time: '18:00' - }, - cycleDays: longAndComplicatedCycle - .filter(({date}) => date >= '2018-06-21') - }) - }) - it('shortens the pre-ovu phase if mucus occurs', () => { - const status = getSensiplanStatus({ - cycle: cycleWithEarlyMucus, - previousCycle: fhmOnDay12, - earlierCycles: Array(10).fill(fhmOnDay12) - }) - - - expect(Object.keys(status.phases).length).to.eql(2) - expect(status.phases.preOvulatory).to.eql({ - start: { date: '2018-06-01' }, - end: { date: '2018-06-01' }, - cycleDays: cycleWithEarlyMucus - .filter(({date}) => date <= '2018-06-01') - }) - expect(status.phases.periOvulatory).to.eql({ - start: { date: '2018-06-02' }, - cycleDays: cycleWithEarlyMucus - .filter(({date}) => { - return date > '2018-06-01' - }) - }) - }) - - it('shortens the pre-ovu phase if mucus occurs even on the first day', () => { - const status = getSensiplanStatus({ - cycle: cycleWithMucusOnFirstDay, - previousCycle: fhmOnDay12, - earlierCycles: Array(10).fill(fhmOnDay12) - }) - - - expect(Object.keys(status.phases).length).to.eql(1) - - expect(status.phases.periOvulatory).to.eql({ - start: { date: '2018-06-01' }, - cycleDays: cycleWithMucusOnFirstDay - }) - }) - - it('lengthens the pre-ovu phase if >= 12 cycles with fhm > 13', () => { - const status = getSensiplanStatus({ - cycle: longAndComplicatedCycle, - previousCycle: fhmOnDay15, - earlierCycles: Array(11).fill(fhmOnDay15) - }) - - - expect(Object.keys(status.phases).length).to.eql(3) - expect(status.phases.preOvulatory).to.eql({ - start: { date: '2018-06-01' }, - end: { date: '2018-06-07' }, - cycleDays: longAndComplicatedCycle - .filter(({date}) => date <= '2018-06-07') - }) - expect(status.phases.periOvulatory).to.eql({ - start: { date: '2018-06-08' }, - end: { date: '2018-06-21', time: '18:00' }, - cycleDays: longAndComplicatedCycle - .filter(({date}) => { - return date > '2018-06-07' && date <= '2018-06-21' - }) - }) - expect(status.phases.postOvulatory).to.eql({ - start: { - date: '2018-06-21', - time: '18:00' - }, - cycleDays: longAndComplicatedCycle - .filter(({date}) => date >= '2018-06-21') - }) - }) - - it('does not lengthen the pre-ovu phase if < 12 cycles', () => { - const status = getSensiplanStatus({ - cycle: longAndComplicatedCycle, - previousCycle: fhmOnDay15, - earlierCycles: Array(10).fill(fhmOnDay15) - }) - - - expect(Object.keys(status.phases).length).to.eql(3) - expect(status.phases.preOvulatory).to.eql({ - start: { date: '2018-06-01' }, - end: { date: '2018-06-05' }, - cycleDays: longAndComplicatedCycle - .filter(({date}) => date <= '2018-06-05') - }) - expect(status.phases.periOvulatory).to.eql({ - start: { date: '2018-06-06' }, - end: { date: '2018-06-21', time: '18:00' }, - cycleDays: longAndComplicatedCycle - .filter(({date}) => { - return date > '2018-06-05' && date <= '2018-06-21' - }) - }) - expect(status.phases.postOvulatory).to.eql({ - start: { - date: '2018-06-21', - time: '18:00' - }, - cycleDays: longAndComplicatedCycle - .filter(({date}) => date >= '2018-06-21') - }) - }) - - it('does not detect any pre-ovu phase if prev cycle had no fhm', () => { - const status = getSensiplanStatus({ - cycle: longAndComplicatedCycle, - previousCycle: cycleWithoutFhm, - earlierCycles: [...Array(12).fill(fhmOnDay15)] - }) - - - expect(Object.keys(status.phases).length).to.eql(2) - expect(status.phases.periOvulatory).to.eql({ - start: { date: '2018-06-01' }, - end: { date: '2018-06-21', time: '18:00' }, - cycleDays: longAndComplicatedCycle - .filter(({date}) => { - return date >= '2018-06-01' && date <= '2018-06-21' - }) - }) - expect(status.phases.postOvulatory).to.eql({ - start: { - date: '2018-06-21', - time: '18:00' - }, - cycleDays: longAndComplicatedCycle - .filter(({date}) => date >= '2018-06-21') - }) - }) - }) - - describe('when args are wrong', () => { - it('throws when arg object is not in right format', () => { - const wrongObject = { hello: 'world' } - expect(() => getSensiplanStatus(wrongObject)).to.throw(AssertionError) - }) - it('throws if cycle array is empty', () => { - expect(() => getSensiplanStatus({cycle: []})).to.throw(AssertionError) - }) - it('throws if cycle days are not in right format', () => { - expect(() => getSensiplanStatus({ - cycle: [{ - hello: 'world', - bleeding: { value: 0 } - }], - earlierCycles: [[{ - date: '1992-09-09', - bleeding: { value: 0 } - }]] - })).to.throw(AssertionError) - expect(() => getSensiplanStatus({ - cycle: [{ - date: '2018-04-13', - temperature: {value: '35'}, - bleeding: { value: 0 } - }], - earlierCycles: [[{ - date: '1992-09-09', - bleeding: { value: 0 } - }]] - })).to.throw(AssertionError) - expect(() => getSensiplanStatus({ - cycle: [{ - date: '09-14-2017', - bleeding: { value: 0 } - }], - earlierCycles: [[{ - date: '1992-09-09', - bleeding: { value: 0 } - }]] - })).to.throw(AssertionError) - }) - it('throws if first cycle day does not have bleeding value', () => { - expect(() => getSensiplanStatus({ - cycle: [{ - date: '2017-01-01', - bleeding: { - value: 'medium' - } - }], - earlierCycles: [[ - { - date: '2017-09-23', - } - ]] - })).to.throw(AssertionError) - }) - }) -}) \ No newline at end of file diff --git a/test/sympto/mucus-temp-fixtures.js b/test/sympto/mucus-temp-fixtures.js index 705e6dc5..c313629c 100644 --- a/test/sympto/mucus-temp-fixtures.js +++ b/test/sympto/mucus-temp-fixtures.js @@ -4,14 +4,6 @@ function convertToSymptoFormat(val) { if (val.temperature) sympto.temperature = { value: val.temperature } if (val.mucus) sympto.mucus = { value: val.mucus } if (val.bleeding) sympto.bleeding = { value: val.bleeding } - if (val.cervix) { - sympto.cervix = {} - if (val.cervix === 'firm & closed') { - sympto.cervix.firmAndClosed = true - } else { - sympto.cervix.firmAndClosed = false - } - } return sympto } diff --git a/test/sympto/mucus-temp.spec.js b/test/sympto/mucus-temp.spec.js index 92f346d8..c0f850a1 100644 --- a/test/sympto/mucus-temp.spec.js +++ b/test/sympto/mucus-temp.spec.js @@ -17,645 +17,609 @@ import { mucusPeakTwoDaysBeforeFhm, fhmOnDay12, fhmOnDay15, - mucusPeakSlightlyBeforeTempShift, - highestMucusQualityAfterEndOfEval + mucusPeakSlightlyBeforeTempShift } from './mucus-temp-fixtures' const expect = chai.expect describe('sympto', () => { - describe('combining temperature and mucus tracking', () => { - describe('with no previous higher temp measurement', () => { - - it('with no shifts detects only peri-ovulatory', function () { - const status = getSensiplanStatus({ - cycle: cycleWithoutAnyShifts, - previousCycle: cycleWithoutFhm - }) - expect(status.phases.periOvulatory).to.eql({ - start: { date: '2018-06-01' }, - cycleDays: cycleWithoutAnyShifts - }) + describe('with no previous higher measurement', () => { + it('with no shifts detects only peri-ovulatory', function () { + const status = getSensiplanStatus({ + cycle: cycleWithoutAnyShifts, + previousCycle: cycleWithoutFhm }) - it('with temp and mucus shifts detects only peri-ovulatory and post-ovulatory', () => { - const status = getSensiplanStatus({ - cycle: longAndComplicatedCycle, - previousCycle: cycleWithoutFhm - }) - expect(status.temperatureShift).to.be.an('object') - expect(status.mucusShift).to.be.an('object') - expect(Object.keys(status.phases).length).to.eql(2) - expect(status.phases.periOvulatory).to.eql({ - start: { date: '2018-06-01' }, - end: { date: '2018-06-21', time: '18:00' }, - cycleDays: longAndComplicatedCycle - .filter(({date}) => date <= '2018-06-21') - }) - expect(status.phases.postOvulatory).to.eql({ - start: { - date: '2018-06-21', - time: '18:00' - }, - cycleDays: longAndComplicatedCycle - .filter(({date}) => date >= '2018-06-21') - }) + expect(status).to.eql({ + phases: { + periOvulatory: { + start: { date: '2018-06-01' }, + cycleDays: cycleWithoutAnyShifts + } + }, }) }) - 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: cycleWithFhm - }) - - expect(Object.keys(status.phases).length).to.eql(1) - expect(status.phases.preOvulatory).to.eql({ - cycleDays: fiveDayCycle, - start: { date: '2018-06-01' }, - end: { date: '2018-06-05' } - }) - }) + it('with shifts detects only peri-ovulatory and post-ovulatory', () => { + const status = getSensiplanStatus({ + cycle: longAndComplicatedCycle, + previousCycle: cycleWithoutFhm }) - describe('with no shifts detects pre- and peri-ovulatory phase', () => { - it('according to 5-day-rule', function () { - const status = getSensiplanStatus({ - cycle: cycleWithTempAndNoMucusShift, - previousCycle: cycleWithFhm - }) - - expect(Object.keys(status.phases).length).to.eql(2) - expect(status.phases.preOvulatory).to.eql({ - cycleDays: cycleWithTempAndNoMucusShift - .filter(({date}) => date <= '2018-06-05'), - start: { date: '2018-06-01' }, - end: { date: '2018-06-05' } - }) - expect(status.phases.periOvulatory).to.eql({ - cycleDays: cycleWithTempAndNoMucusShift - .filter(({date}) => date > '2018-06-05'), - start: { date: '2018-06-06' } - }) - }) - it('according to 5-day-rule with shortened pre-phase', function () { - const status = getSensiplanStatus({ - cycle: cycleWithEarlyMucus, - previousCycle: cycleWithFhm - }) - - expect(Object.keys(status.phases).length).to.eql(2) + expect(status.temperatureShift).to.be.an('object') + expect(status.mucusShift).to.be.an('object') - expect(status.phases.preOvulatory).to.eql({ - cycleDays: [cycleWithEarlyMucus[0]], - start: { date: '2018-06-01' }, - end: { date: '2018-06-01' } - }) - expect(status.phases.periOvulatory).to.eql({ - cycleDays: cycleWithEarlyMucus.slice(1), - start: { date: '2018-06-02' } - }) - }) + expect(Object.keys(status.phases).length).to.eql(2) + expect(status.phases.periOvulatory).to.eql({ + start: { date: '2018-06-01' }, + end: { date: '2018-06-21', time: '18:00' }, + cycleDays: longAndComplicatedCycle + .filter(({date}) => date <= '2018-06-21') }) - describe('with shifts detects pre- and peri-ovulatory phase', function () { - it('according to 5-day-rule', function () { - const status = getSensiplanStatus({ - cycle: longAndComplicatedCycle, - previousCycle: cycleWithFhm - }) - - expect(Object.keys(status.phases).length).to.eql(3) - - expect(status.phases.preOvulatory).to.eql({ - cycleDays: longAndComplicatedCycle - .filter(({date}) => date <= '2018-06-05'), - start: { date: '2018-06-01' }, - end: { date: '2018-06-05' } - }) - expect(status.phases.periOvulatory).to.eql({ - cycleDays: longAndComplicatedCycle - .filter(({date}) => date > '2018-06-05' && date <= '2018-06-21'), - start: { date: '2018-06-06' }, - end: { date: '2018-06-21', time: '18:00'} - }) - expect(status.phases.postOvulatory).to.eql({ - cycleDays: longAndComplicatedCycle - .filter(({date}) => date >= '2018-06-21'), - start: { date: '2018-06-21', time: '18:00'} - }) - }) - + expect(status.phases.postOvulatory).to.eql({ + start: { + date: '2018-06-21', + time: '18:00' + }, + cycleDays: longAndComplicatedCycle + .filter(({date}) => date >= '2018-06-21') }) }) - - describe('combining first higher measurment and mucus peak', () => { - it('with fhM + mucus peak on same day finds start of postovu phase', () => { + }) + 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: mucusPeakAndFhmOnSameDay, + cycle: fiveDayCycle, previousCycle: cycleWithFhm }) - expect(status.temperatureShift).to.be.an('object') - expect(status.mucusShift).to.be.an('object') + expect(Object.keys(status.phases).length).to.eql(1) - expect(Object.keys(status.phases).length).to.eql(3) expect(status.phases.preOvulatory).to.eql({ + cycleDays: fiveDayCycle, start: { date: '2018-06-01' }, - end: { date: '2018-06-05' }, - cycleDays: mucusPeakAndFhmOnSameDay - .filter(({date}) => date <= '2018-06-05') - }) - expect(status.phases.periOvulatory).to.eql({ - start: { date: '2018-06-06' }, - end: { date: '2018-06-21', time: '18:00' }, - cycleDays: mucusPeakAndFhmOnSameDay - .filter(({date}) => { - return date > '2018-06-05' && date <= '2018-06-21' - }) - }) - expect(status.phases.postOvulatory).to.eql({ - start: { - date: '2018-06-21', - time: '18:00' - }, - cycleDays: mucusPeakAndFhmOnSameDay - .filter(({date}) => date >= '2018-06-21') + end: { date: '2018-06-05' } }) }) - it('with fhM 2 days before mucus peak waits for end of mucus eval', () => { + }) + describe('with no shifts detects pre- and peri-ovulatory phase', () => { + it('according to 5-day-rule', function () { const status = getSensiplanStatus({ - cycle: fhmTwoDaysBeforeMucusPeak, + cycle: cycleWithTempAndNoMucusShift, previousCycle: cycleWithFhm }) - expect(status.temperatureShift).to.be.an('object') - expect(status.mucusShift).to.be.an('object') + expect(Object.keys(status.phases).length).to.eql(2) - expect(Object.keys(status.phases).length).to.eql(3) expect(status.phases.preOvulatory).to.eql({ + cycleDays: cycleWithTempAndNoMucusShift + .filter(({date}) => date <= '2018-06-05'), start: { date: '2018-06-01' }, - end: { date: '2018-06-05' }, - cycleDays: fhmTwoDaysBeforeMucusPeak - .filter(({date}) => date <= '2018-06-05') + end: { date: '2018-06-05' } }) expect(status.phases.periOvulatory).to.eql({ - start: { date: '2018-06-06' }, - end: { date: '2018-06-26', time: '18:00' }, - cycleDays: fhmTwoDaysBeforeMucusPeak - .filter(({date}) => { - return date > '2018-06-05' && date <= '2018-06-26' - }) - }) - expect(status.phases.postOvulatory).to.eql({ - start: { - date: '2018-06-26', - time: '18:00' - }, - cycleDays: fhmTwoDaysBeforeMucusPeak - .filter(({date}) => date >= '2018-06-26') + cycleDays: cycleWithTempAndNoMucusShift + .filter(({date}) => date > '2018-06-05'), + start: { date: '2018-06-06' } }) }) - - it('another example for mucus peak before temp shift', () => { + it('according to 5-day-rule with shortened pre-phase', function () { const status = getSensiplanStatus({ - cycle: mucusPeakSlightlyBeforeTempShift, + cycle: cycleWithEarlyMucus, previousCycle: cycleWithFhm }) - expect(status.temperatureShift).to.be.an('object') - expect(status.mucusShift).to.be.an('object') + expect(Object.keys(status.phases).length).to.eql(2) - expect(Object.keys(status.phases).length).to.eql(3) expect(status.phases.preOvulatory).to.eql({ + cycleDays: [cycleWithEarlyMucus[0]], start: { date: '2018-06-01' }, - end: { date: '2018-06-05' }, - cycleDays: mucusPeakSlightlyBeforeTempShift - .filter(({date}) => date <= '2018-06-05') + end: { date: '2018-06-01' } }) expect(status.phases.periOvulatory).to.eql({ - start: { date: '2018-06-06' }, - end: { date: '2018-06-17', time: '18:00' }, - cycleDays: mucusPeakSlightlyBeforeTempShift - .filter(({date}) => { - return date > '2018-06-05' && date <= '2018-06-17' - }) - }) - expect(status.phases.postOvulatory).to.eql({ - start: { - date: '2018-06-17', - time: '18:00' - }, - cycleDays: mucusPeakSlightlyBeforeTempShift - .filter(({date}) => date >= '2018-06-17') + cycleDays: cycleWithEarlyMucus.slice(1), + start: { date: '2018-06-02' } }) }) - - it('with another mucus peak 5 days after fHM ignores it', () => { + }) + describe('with shifts detects pre- and peri-ovulatory phase', function () { + it('according to 5-day-rule', function () { const status = getSensiplanStatus({ - cycle: mucusPeak5DaysAfterFhm, + cycle: longAndComplicatedCycle, previousCycle: cycleWithFhm }) - expect(status.temperatureShift).to.be.an('object') - expect(status.mucusShift).to.be.an('object') - expect(Object.keys(status.phases).length).to.eql(3) + expect(status.phases.preOvulatory).to.eql({ + cycleDays: longAndComplicatedCycle + .filter(({date}) => date <= '2018-06-05'), start: { date: '2018-06-01' }, - end: { date: '2018-06-01' }, - cycleDays: mucusPeak5DaysAfterFhm - .filter(({date}) => date <= '2018-06-01') + end: { date: '2018-06-05' } }) expect(status.phases.periOvulatory).to.eql({ - start: { date: '2018-06-02' }, - end: { date: '2018-06-22', time: '18:00' }, - cycleDays: mucusPeak5DaysAfterFhm - .filter(({date}) => { - return date > '2018-06-01' && date <= '2018-06-22' - }) + cycleDays: longAndComplicatedCycle + .filter(({date}) => date > '2018-06-05' && date <= '2018-06-21'), + start: { date: '2018-06-06' }, + end: { date: '2018-06-21', time: '18:00'} }) expect(status.phases.postOvulatory).to.eql({ - start: { - date: '2018-06-22', - time: '18:00' - }, - cycleDays: mucusPeak5DaysAfterFhm - .filter(({date}) => date >= '2018-06-22') + cycleDays: longAndComplicatedCycle + .filter(({date}) => date >= '2018-06-21'), + start: { date: '2018-06-21', time: '18:00'} }) }) - it('with mucus peak 2 days before fhM waits for end of temp eval', () => { - const status = getSensiplanStatus({ - cycle: mucusPeakTwoDaysBeforeFhm, - previousCycle: cycleWithFhm - }) + }) + }) - expect(status.temperatureShift).to.be.an('object') - expect(status.mucusShift).to.be.an('object') + describe('combining first higher measurment and mucus peak', () => { + it('with fhM + mucus peak on same day finds start of postovu phase', () => { + const status = getSensiplanStatus({ + cycle: mucusPeakAndFhmOnSameDay, + previousCycle: cycleWithFhm + }) - expect(Object.keys(status.phases).length).to.eql(3) - expect(status.phases.preOvulatory).to.eql({ - start: { date: '2018-06-01' }, - end: { date: '2018-06-04' }, - cycleDays: mucusPeakTwoDaysBeforeFhm - .filter(({date}) => date <= '2018-06-04') - }) - expect(status.phases.periOvulatory).to.eql({ - start: { date: '2018-06-05' }, - end: { date: '2018-07-03', time: '18:00' }, - cycleDays: mucusPeakTwoDaysBeforeFhm - .filter(({date}) => { - return date > '2018-06-04' && date <= '2018-07-03' - }) - }) - expect(status.phases.postOvulatory).to.eql({ - start: { - date: '2018-07-03', - time: '18:00' - }, - cycleDays: mucusPeakTwoDaysBeforeFhm - .filter(({date}) => date >= '2018-07-03') - }) + expect(status.temperatureShift).to.be.an('object') + expect(status.mucusShift).to.be.an('object') + + expect(Object.keys(status.phases).length).to.eql(3) + expect(status.phases.preOvulatory).to.eql({ + start: { date: '2018-06-01' }, + end: { date: '2018-06-05' }, + cycleDays: mucusPeakAndFhmOnSameDay + .filter(({date}) => date <= '2018-06-05') + }) + expect(status.phases.periOvulatory).to.eql({ + start: { date: '2018-06-06' }, + end: { date: '2018-06-21', time: '18:00' }, + cycleDays: mucusPeakAndFhmOnSameDay + .filter(({date}) => { + return date > '2018-06-05' && date <= '2018-06-21' + }) + }) + expect(status.phases.postOvulatory).to.eql({ + start: { + date: '2018-06-21', + time: '18:00' + }, + cycleDays: mucusPeakAndFhmOnSameDay + .filter(({date}) => date >= '2018-06-21') }) + }) - it('with mucus peak 5 days before fhM waits for end of temp eval', () => { - const status = getSensiplanStatus({ - cycle: fhm5DaysAfterMucusPeak, - previousCycle: cycleWithFhm - }) + it('with fhM 2 days before mucus peak waits for end of mucus eval', () => { + const status = getSensiplanStatus({ + cycle: fhmTwoDaysBeforeMucusPeak, + previousCycle: cycleWithFhm + }) - expect(status.temperatureShift).to.be.an('object') - expect(status.mucusShift).to.be.an('object') + expect(status.temperatureShift).to.be.an('object') + expect(status.mucusShift).to.be.an('object') - expect(Object.keys(status.phases).length).to.eql(3) - expect(status.phases.preOvulatory).to.eql({ - start: { date: '2018-06-01' }, - end: { date: '2018-06-05' }, - cycleDays: fhm5DaysAfterMucusPeak - .filter(({date}) => date <= '2018-06-05') - }) - expect(status.phases.periOvulatory).to.eql({ - start: { date: '2018-06-06' }, - end: { date: '2018-06-21', time: '18:00' }, - cycleDays: fhm5DaysAfterMucusPeak - .filter(({date}) => { - return date > '2018-06-05' && date <= '2018-06-21' - }) - }) - expect(status.phases.postOvulatory).to.eql({ - start: { - date: '2018-06-21', - time: '18:00' - }, - cycleDays: fhm5DaysAfterMucusPeak - .filter(({date}) => date >= '2018-06-21') - }) + expect(Object.keys(status.phases).length).to.eql(3) + expect(status.phases.preOvulatory).to.eql({ + start: { date: '2018-06-01' }, + end: { date: '2018-06-05' }, + cycleDays: fhmTwoDaysBeforeMucusPeak + .filter(({date}) => date <= '2018-06-05') + }) + expect(status.phases.periOvulatory).to.eql({ + start: { date: '2018-06-06' }, + end: { date: '2018-06-26', time: '18:00' }, + cycleDays: fhmTwoDaysBeforeMucusPeak + .filter(({date}) => { + return date > '2018-06-05' && date <= '2018-06-26' + }) + }) + expect(status.phases.postOvulatory).to.eql({ + start: { + date: '2018-06-26', + time: '18:00' + }, + cycleDays: fhmTwoDaysBeforeMucusPeak + .filter(({date}) => date >= '2018-06-26') }) }) - describe('applying the minus-8 rule', () => { - it('shortens the pre-ovu phase if there is a previous <13 fhm', () => { - const status = getSensiplanStatus({ - cycle: longAndComplicatedCycle, - previousCycle: fhmOnDay15, - earlierCycles: [fhmOnDay12, ...Array(10).fill(fhmOnDay15)] - }) + it('another example for mucus peak before temp shift', () => { + const status = getSensiplanStatus({ + cycle: mucusPeakSlightlyBeforeTempShift, + previousCycle: cycleWithFhm + }) - expect(status.temperatureShift).to.be.an('object') - expect(status.mucusShift).to.be.an('object') + expect(status.temperatureShift).to.be.an('object') + expect(status.mucusShift).to.be.an('object') - expect(Object.keys(status.phases).length).to.eql(3) - expect(status.phases.preOvulatory).to.eql({ - start: { date: '2018-06-01' }, - end: { date: '2018-06-04' }, - cycleDays: longAndComplicatedCycle - .filter(({date}) => date <= '2018-06-04') - }) - expect(status.phases.periOvulatory).to.eql({ - start: { date: '2018-06-05' }, - end: { date: '2018-06-21', time: '18:00' }, - cycleDays: longAndComplicatedCycle - .filter(({date}) => { - return date > '2018-06-04' && date <= '2018-06-21' - }) - }) - expect(status.phases.postOvulatory).to.eql({ - start: { - date: '2018-06-21', - time: '18:00' - }, - cycleDays: longAndComplicatedCycle - .filter(({date}) => date >= '2018-06-21') - }) + expect(Object.keys(status.phases).length).to.eql(3) + expect(status.phases.preOvulatory).to.eql({ + start: { date: '2018-06-01' }, + end: { date: '2018-06-05' }, + cycleDays: mucusPeakSlightlyBeforeTempShift + .filter(({date}) => date <= '2018-06-05') }) - // #TODO - it.only('shortens pre-ovu phase with prev <13 fhm even with <12 cycles', () => { - const status = getSensiplanStatus({ - cycle: longAndComplicatedCycle, - previousCycle: fhmOnDay12, - earlierCycles: Array(10).fill(fhmOnDay12) - }) + expect(status.phases.periOvulatory).to.eql({ + start: { date: '2018-06-06' }, + end: { date: '2018-06-17', time: '18:00' }, + cycleDays: mucusPeakSlightlyBeforeTempShift + .filter(({date}) => { + return date > '2018-06-05' && date <= '2018-06-17' + }) + }) + expect(status.phases.postOvulatory).to.eql({ + start: { + date: '2018-06-17', + time: '18:00' + }, + cycleDays: mucusPeakSlightlyBeforeTempShift + .filter(({date}) => date >= '2018-06-17') + }) + }) - expect(status.temperatureShift).to.be.an('object') - expect(status.mucusShift).to.be.an('object') + it('with another mucus peak 5 days after fHM ignores it', () => { + const status = getSensiplanStatus({ + cycle: mucusPeak5DaysAfterFhm, + previousCycle: cycleWithFhm + }) - expect(Object.keys(status.phases).length).to.eql(3) - expect(status.phases.preOvulatory).to.eql({ - start: { date: '2018-06-01' }, - end: { date: '2018-06-05' }, - cycleDays: fhm5DaysAfterMucusPeak - .filter(({date}) => date <= '2018-06-05') - }) - expect(status.phases.periOvulatory).to.eql({ - start: { date: '2018-06-06' }, - end: { date: '2018-06-21', time: '18:00' }, - cycleDays: fhm5DaysAfterMucusPeak - .filter(({date}) => { - return date > '2018-06-05' && date <= '2018-06-21' - }) - }) - expect(status.phases.postOvulatory).to.eql({ - start: { - date: '2018-06-21', - time: '18:00' - }, - cycleDays: fhm5DaysAfterMucusPeak - .filter(({date}) => date >= '2018-06-21') - }) + expect(status.temperatureShift).to.be.an('object') + expect(status.mucusShift).to.be.an('object') + + expect(Object.keys(status.phases).length).to.eql(3) + expect(status.phases.preOvulatory).to.eql({ + start: { date: '2018-06-01' }, + end: { date: '2018-06-01' }, + cycleDays: mucusPeak5DaysAfterFhm + .filter(({date}) => date <= '2018-06-01') }) + expect(status.phases.periOvulatory).to.eql({ + start: { date: '2018-06-02' }, + end: { date: '2018-06-22', time: '18:00' }, + cycleDays: mucusPeak5DaysAfterFhm + .filter(({date}) => { + return date > '2018-06-01' && date <= '2018-06-22' + }) + }) + expect(status.phases.postOvulatory).to.eql({ + start: { + date: '2018-06-22', + time: '18:00' + }, + cycleDays: mucusPeak5DaysAfterFhm + .filter(({date}) => date >= '2018-06-22') + }) + }) - // #TODO - it('with highest quality after end of eval', () => { - const status = getSensiplanStatus({ - cycle: highestMucusQualityAfterEndOfEval, - previousCycle: cycleWithFhm - }) + it('with mucus peak 2 days before fhM waits for end of temp eval', () => { + const status = getSensiplanStatus({ + cycle: mucusPeakTwoDaysBeforeFhm, + previousCycle: cycleWithFhm + }) - expect(status.temperatureShift).to.be.an('object') - expect(status.mucusShift).to.be.an('object') + expect(status.temperatureShift).to.be.an('object') + expect(status.mucusShift).to.be.an('object') - expect(Object.keys(status.phases).length).to.eql(3) - expect(status.phases.preOvulatory).to.eql({ - start: { date: '2018-06-01' }, - end: { date: '2018-06-05' }, - cycleDays: highestMucusQualityAfterEndOfEval - .filter(({date}) => date <= '2018-06-05') - }) - expect(status.phases.periOvulatory).to.eql({ - start: { date: '2018-06-06' }, - end: { date: '2018-06-26', time: '18:00' }, - cycleDays: highestMucusQualityAfterEndOfEval - .filter(({date}) => { - return date > '2018-06-05' && date <= '2018-06-26' - }) - }) - expect(status.phases.postOvulatory).to.eql({ - start: { - date: '2018-06-26', - time: '18:00' - }, - cycleDays: highestMucusQualityAfterEndOfEval - .filter(({date}) => date >= '2018-06-26') - }) + expect(Object.keys(status.phases).length).to.eql(3) + expect(status.phases.preOvulatory).to.eql({ + start: { date: '2018-06-01' }, + end: { date: '2018-06-04' }, + cycleDays: mucusPeakTwoDaysBeforeFhm + .filter(({date}) => date <= '2018-06-04') + }) + expect(status.phases.periOvulatory).to.eql({ + start: { date: '2018-06-05' }, + end: { date: '2018-07-03', time: '18:00' }, + cycleDays: mucusPeakTwoDaysBeforeFhm + .filter(({date}) => { + return date > '2018-06-04' && date <= '2018-07-03' + }) + }) + expect(status.phases.postOvulatory).to.eql({ + start: { + date: '2018-07-03', + time: '18:00' + }, + cycleDays: mucusPeakTwoDaysBeforeFhm + .filter(({date}) => date >= '2018-07-03') }) }) - describe('something', () => { + it('with mucus peak 5 days before fhM waits for end of temp eval', () => { + const status = getSensiplanStatus({ + cycle: fhm5DaysAfterMucusPeak, + previousCycle: cycleWithFhm + }) - it('shortens the pre-ovu phase if mucus occurs', () => { - const status = getSensiplanStatus({ - cycle: cycleWithEarlyMucus, - previousCycle: fhmOnDay12, - earlierCycles: Array(10).fill(fhmOnDay12) - }) + expect(status.temperatureShift).to.be.an('object') + expect(status.mucusShift).to.be.an('object') + expect(Object.keys(status.phases).length).to.eql(3) + expect(status.phases.preOvulatory).to.eql({ + start: { date: '2018-06-01' }, + end: { date: '2018-06-05' }, + cycleDays: fhm5DaysAfterMucusPeak + .filter(({date}) => date <= '2018-06-05') + }) + expect(status.phases.periOvulatory).to.eql({ + start: { date: '2018-06-06' }, + end: { date: '2018-06-21', time: '18:00' }, + cycleDays: fhm5DaysAfterMucusPeak + .filter(({date}) => { + return date > '2018-06-05' && date <= '2018-06-21' + }) + }) + expect(status.phases.postOvulatory).to.eql({ + start: { + date: '2018-06-21', + time: '18:00' + }, + cycleDays: fhm5DaysAfterMucusPeak + .filter(({date}) => date >= '2018-06-21') + }) + }) + }) - expect(Object.keys(status.phases).length).to.eql(2) - expect(status.phases.preOvulatory).to.eql({ - start: { date: '2018-06-01' }, - end: { date: '2018-06-01' }, - cycleDays: cycleWithEarlyMucus - .filter(({date}) => date <= '2018-06-01') - }) - expect(status.phases.periOvulatory).to.eql({ - start: { date: '2018-06-02' }, - cycleDays: cycleWithEarlyMucus - .filter(({date}) => { - return date > '2018-06-01' - }) - }) + describe('applying the minus-8 rule', () => { + it('shortens the pre-ovu phase if there is a previous <13 fhm', () => { + const status = getSensiplanStatus({ + cycle: longAndComplicatedCycle, + previousCycle: fhmOnDay15, + earlierCycles: [fhmOnDay12, ...Array(10).fill(fhmOnDay15)] }) - it('shortens the pre-ovu phase if mucus occurs even on the first day', () => { - const status = getSensiplanStatus({ - cycle: cycleWithMucusOnFirstDay, - previousCycle: fhmOnDay12, - earlierCycles: Array(10).fill(fhmOnDay12) - }) + expect(status.temperatureShift).to.be.an('object') + expect(status.mucusShift).to.be.an('object') + expect(Object.keys(status.phases).length).to.eql(3) + expect(status.phases.preOvulatory).to.eql({ + start: { date: '2018-06-01' }, + end: { date: '2018-06-04' }, + cycleDays: longAndComplicatedCycle + .filter(({date}) => date <= '2018-06-04') + }) + expect(status.phases.periOvulatory).to.eql({ + start: { date: '2018-06-05' }, + end: { date: '2018-06-21', time: '18:00' }, + cycleDays: longAndComplicatedCycle + .filter(({date}) => { + return date > '2018-06-04' && date <= '2018-06-21' + }) + }) + expect(status.phases.postOvulatory).to.eql({ + start: { + date: '2018-06-21', + time: '18:00' + }, + cycleDays: longAndComplicatedCycle + .filter(({date}) => date >= '2018-06-21') + }) + }) + it('shortens pre-ovu phase with prev <13 fhm even with <12 cycles', () => { + const status = getSensiplanStatus({ + cycle: longAndComplicatedCycle, + previousCycle: fhmOnDay12, + earlierCycles: Array(10).fill(fhmOnDay12) + }) - expect(Object.keys(status.phases).length).to.eql(1) + expect(status.temperatureShift).to.be.an('object') + expect(status.mucusShift).to.be.an('object') - expect(status.phases.periOvulatory).to.eql({ - start: { date: '2018-06-01' }, - cycleDays: cycleWithMucusOnFirstDay - }) + expect(Object.keys(status.phases).length).to.eql(3) + expect(status.phases.preOvulatory).to.eql({ + start: { date: '2018-06-01' }, + end: { date: '2018-06-04' }, + cycleDays: longAndComplicatedCycle + .filter(({date}) => date <= '2018-06-04') + }) + expect(status.phases.periOvulatory).to.eql({ + start: { date: '2018-06-05' }, + end: { date: '2018-06-21', time: '18:00' }, + cycleDays: longAndComplicatedCycle + .filter(({date}) => { + return date > '2018-06-04' && date <= '2018-06-21' + }) + }) + expect(status.phases.postOvulatory).to.eql({ + start: { + date: '2018-06-21', + time: '18:00' + }, + cycleDays: longAndComplicatedCycle + .filter(({date}) => date >= '2018-06-21') + }) + }) + it('shortens the pre-ovu phase if mucus occurs', () => { + const status = getSensiplanStatus({ + cycle: cycleWithEarlyMucus, + previousCycle: fhmOnDay12, + earlierCycles: Array(10).fill(fhmOnDay12) }) - it('lengthens the pre-ovu phase if >= 12 cycles with fhm > 13', () => { - const status = getSensiplanStatus({ - cycle: longAndComplicatedCycle, - previousCycle: fhmOnDay15, - earlierCycles: Array(11).fill(fhmOnDay15) - }) + expect(Object.keys(status.phases).length).to.eql(2) + expect(status.phases.preOvulatory).to.eql({ + start: { date: '2018-06-01' }, + end: { date: '2018-06-01' }, + cycleDays: cycleWithEarlyMucus + .filter(({date}) => date <= '2018-06-01') + }) + expect(status.phases.periOvulatory).to.eql({ + start: { date: '2018-06-02' }, + cycleDays: cycleWithEarlyMucus + .filter(({date}) => { + return date > '2018-06-01' + }) + }) + }) - expect(Object.keys(status.phases).length).to.eql(3) - expect(status.phases.preOvulatory).to.eql({ - start: { date: '2018-06-01' }, - end: { date: '2018-06-07' }, - cycleDays: longAndComplicatedCycle - .filter(({date}) => date <= '2018-06-07') - }) - expect(status.phases.periOvulatory).to.eql({ - start: { date: '2018-06-08' }, - end: { date: '2018-06-21', time: '18:00' }, - cycleDays: longAndComplicatedCycle - .filter(({date}) => { - return date > '2018-06-07' && date <= '2018-06-21' - }) - }) - expect(status.phases.postOvulatory).to.eql({ - start: { - date: '2018-06-21', - time: '18:00' - }, - cycleDays: longAndComplicatedCycle - .filter(({date}) => date >= '2018-06-21') - }) + it('shortens the pre-ovu phase if mucus occurs even on the first day', () => { + const status = getSensiplanStatus({ + cycle: cycleWithMucusOnFirstDay, + previousCycle: fhmOnDay12, + earlierCycles: Array(10).fill(fhmOnDay12) }) - it('does not lengthen the pre-ovu phase if < 12 cycles', () => { - const status = getSensiplanStatus({ - cycle: longAndComplicatedCycle, - previousCycle: fhmOnDay15, - earlierCycles: Array(10).fill(fhmOnDay15) - }) + expect(Object.keys(status.phases).length).to.eql(1) - expect(Object.keys(status.phases).length).to.eql(3) - expect(status.phases.preOvulatory).to.eql({ - start: { date: '2018-06-01' }, - end: { date: '2018-06-05' }, - cycleDays: longAndComplicatedCycle - .filter(({date}) => date <= '2018-06-05') - }) - expect(status.phases.periOvulatory).to.eql({ - start: { date: '2018-06-06' }, - end: { date: '2018-06-21', time: '18:00' }, - cycleDays: longAndComplicatedCycle - .filter(({date}) => { - return date > '2018-06-05' && date <= '2018-06-21' - }) - }) - expect(status.phases.postOvulatory).to.eql({ - start: { - date: '2018-06-21', - time: '18:00' - }, - cycleDays: longAndComplicatedCycle - .filter(({date}) => date >= '2018-06-21') - }) + expect(status.phases.periOvulatory).to.eql({ + start: { date: '2018-06-01' }, + cycleDays: cycleWithMucusOnFirstDay }) + }) - it('does not detect any pre-ovu phase if prev cycle had no fhm', () => { - const status = getSensiplanStatus({ - cycle: longAndComplicatedCycle, - previousCycle: cycleWithoutFhm, - earlierCycles: [...Array(12).fill(fhmOnDay15)] - }) + it('lengthens the pre-ovu phase if >= 12 cycles with fhm > 13', () => { + const status = getSensiplanStatus({ + cycle: longAndComplicatedCycle, + previousCycle: fhmOnDay15, + earlierCycles: Array(11).fill(fhmOnDay15) + }) - expect(Object.keys(status.phases).length).to.eql(2) - expect(status.phases.periOvulatory).to.eql({ - start: { date: '2018-06-01' }, - end: { date: '2018-06-21', time: '18:00' }, - cycleDays: longAndComplicatedCycle - .filter(({date}) => { - return date >= '2018-06-01' && date <= '2018-06-21' - }) - }) - expect(status.phases.postOvulatory).to.eql({ - start: { - date: '2018-06-21', - time: '18:00' - }, - cycleDays: longAndComplicatedCycle - .filter(({date}) => date >= '2018-06-21') - }) + expect(Object.keys(status.phases).length).to.eql(3) + expect(status.phases.preOvulatory).to.eql({ + start: { date: '2018-06-01' }, + end: { date: '2018-06-07' }, + cycleDays: longAndComplicatedCycle + .filter(({date}) => date <= '2018-06-07') + }) + expect(status.phases.periOvulatory).to.eql({ + start: { date: '2018-06-08' }, + end: { date: '2018-06-21', time: '18:00' }, + cycleDays: longAndComplicatedCycle + .filter(({date}) => { + return date > '2018-06-07' && date <= '2018-06-21' + }) + }) + expect(status.phases.postOvulatory).to.eql({ + start: { + date: '2018-06-21', + time: '18:00' + }, + cycleDays: longAndComplicatedCycle + .filter(({date}) => date >= '2018-06-21') + }) + }) + + it('does not lengthen the pre-ovu phase if < 12 cycles', () => { + const status = getSensiplanStatus({ + cycle: longAndComplicatedCycle, + previousCycle: fhmOnDay15, + earlierCycles: Array(10).fill(fhmOnDay15) + }) + + + expect(Object.keys(status.phases).length).to.eql(3) + expect(status.phases.preOvulatory).to.eql({ + start: { date: '2018-06-01' }, + end: { date: '2018-06-05' }, + cycleDays: longAndComplicatedCycle + .filter(({date}) => date <= '2018-06-05') + }) + expect(status.phases.periOvulatory).to.eql({ + start: { date: '2018-06-06' }, + end: { date: '2018-06-21', time: '18:00' }, + cycleDays: longAndComplicatedCycle + .filter(({date}) => { + return date > '2018-06-05' && date <= '2018-06-21' + }) + }) + expect(status.phases.postOvulatory).to.eql({ + start: { + date: '2018-06-21', + time: '18:00' + }, + cycleDays: longAndComplicatedCycle + .filter(({date}) => date >= '2018-06-21') }) }) - describe('when args are wrong', () => { - it('throws when arg object is not in right format', () => { - const wrongObject = { hello: 'world' } - expect(() => getSensiplanStatus(wrongObject)).to.throw(AssertionError) - }) - it('throws if cycle array is empty', () => { - expect(() => getSensiplanStatus({cycle: []})).to.throw(AssertionError) - }) - it('throws if cycle days are not in right format', () => { - expect(() => getSensiplanStatus({ - cycle: [{ - hello: 'world', - bleeding: { value: 0 } - }], - earlierCycles: [[{ - date: '1992-09-09', - bleeding: { value: 0 } - }]] - })).to.throw(AssertionError) - expect(() => getSensiplanStatus({ - cycle: [{ - date: '2018-04-13', - temperature: {value: '35'}, - bleeding: { value: 0 } - }], - earlierCycles: [[{ - date: '1992-09-09', - bleeding: { value: 0 } - }]] - })).to.throw(AssertionError) - expect(() => getSensiplanStatus({ - cycle: [{ - date: '09-14-2017', - bleeding: { value: 0 } - }], - earlierCycles: [[{ - date: '1992-09-09', - bleeding: { value: 0 } - }]] - })).to.throw(AssertionError) - }) - it('throws if first cycle day does not have bleeding value', () => { - expect(() => getSensiplanStatus({ - cycle: [{ - date: '2017-01-01', - bleeding: { - value: 'medium' - } - }], - earlierCycles: [[ - { - date: '2017-09-23', - } - ]] - })).to.throw(AssertionError) + it('does not detect any pre-ovu phase if prev cycle had no fhm', () => { + const status = getSensiplanStatus({ + cycle: longAndComplicatedCycle, + previousCycle: cycleWithoutFhm, + earlierCycles: [...Array(12).fill(fhmOnDay15)] + }) + + + expect(Object.keys(status.phases).length).to.eql(2) + expect(status.phases.periOvulatory).to.eql({ + start: { date: '2018-06-01' }, + end: { date: '2018-06-21', time: '18:00' }, + cycleDays: longAndComplicatedCycle + .filter(({date}) => { + return date >= '2018-06-01' && date <= '2018-06-21' + }) + }) + expect(status.phases.postOvulatory).to.eql({ + start: { + date: '2018-06-21', + time: '18:00' + }, + cycleDays: longAndComplicatedCycle + .filter(({date}) => date >= '2018-06-21') }) }) }) + + describe('when args are wrong', () => { + it('throws when arg object is not in right format', () => { + const wrongObject = { hello: 'world' } + expect(() => getSensiplanStatus(wrongObject)).to.throw(AssertionError) + }) + it('throws if cycle array is empty', () => { + expect(() => getSensiplanStatus({cycle: []})).to.throw(AssertionError) + }) + it('throws if cycle days are not in right format', () => { + expect(() => getSensiplanStatus({ + cycle: [{ + hello: 'world', + bleeding: { value: 0 } + }], + earlierCycles: [[{ + date: '1992-09-09', + bleeding: { value: 0 } + }]] + })).to.throw(AssertionError) + expect(() => getSensiplanStatus({ + cycle: [{ + date: '2018-04-13', + temperature: {value: '35'}, + bleeding: { value: 0 } + }], + earlierCycles: [[{ + date: '1992-09-09', + bleeding: { value: 0 } + }]] + })).to.throw(AssertionError) + expect(() => getSensiplanStatus({ + cycle: [{ + date: '09-14-2017', + bleeding: { value: 0 } + }], + earlierCycles: [[{ + date: '1992-09-09', + bleeding: { value: 0 } + }]] + })).to.throw(AssertionError) + }) + it('throws if first cycle day does not have bleeding value', () => { + expect(() => getSensiplanStatus({ + cycle: [{ + date: '2017-01-01', + bleeding: { + value: 'medium' + } + }], + earlierCycles: [[ + { + date: '2017-09-23', + } + ]] + })).to.throw(AssertionError) + }) + }) }) diff --git a/test/sympto/mucus-temp.spec.js~HEAD b/test/sympto/mucus-temp.spec.js~HEAD new file mode 100644 index 00000000..92f346d8 --- /dev/null +++ b/test/sympto/mucus-temp.spec.js~HEAD @@ -0,0 +1,661 @@ +import chai from 'chai' +import getSensiplanStatus from '../../lib/sympto' +import { AssertionError } from 'assert' +import { + cycleWithoutFhm, + longAndComplicatedCycle, + cycleWithTempAndNoMucusShift, + cycleWithFhm, + cycleWithoutAnyShifts, + fiveDayCycle, + cycleWithEarlyMucus, + cycleWithMucusOnFirstDay, + mucusPeakAndFhmOnSameDay, + fhmTwoDaysBeforeMucusPeak, + fhm5DaysAfterMucusPeak, + mucusPeak5DaysAfterFhm, + mucusPeakTwoDaysBeforeFhm, + fhmOnDay12, + fhmOnDay15, + mucusPeakSlightlyBeforeTempShift, + highestMucusQualityAfterEndOfEval +} from './mucus-temp-fixtures' + +const expect = chai.expect + +describe('sympto', () => { + describe('combining temperature and mucus tracking', () => { + describe('with no previous higher temp measurement', () => { + + it('with no shifts detects only peri-ovulatory', function () { + const status = getSensiplanStatus({ + cycle: cycleWithoutAnyShifts, + previousCycle: cycleWithoutFhm + }) + expect(status.phases.periOvulatory).to.eql({ + start: { date: '2018-06-01' }, + cycleDays: cycleWithoutAnyShifts + }) + }) + + it('with temp and mucus shifts detects only peri-ovulatory and post-ovulatory', () => { + const status = getSensiplanStatus({ + cycle: longAndComplicatedCycle, + previousCycle: cycleWithoutFhm + }) + expect(status.temperatureShift).to.be.an('object') + expect(status.mucusShift).to.be.an('object') + expect(Object.keys(status.phases).length).to.eql(2) + expect(status.phases.periOvulatory).to.eql({ + start: { date: '2018-06-01' }, + end: { date: '2018-06-21', time: '18:00' }, + cycleDays: longAndComplicatedCycle + .filter(({date}) => date <= '2018-06-21') + }) + expect(status.phases.postOvulatory).to.eql({ + start: { + date: '2018-06-21', + time: '18:00' + }, + cycleDays: longAndComplicatedCycle + .filter(({date}) => date >= '2018-06-21') + }) + + }) + }) + + 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: cycleWithFhm + }) + + expect(Object.keys(status.phases).length).to.eql(1) + 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', () => { + it('according to 5-day-rule', function () { + const status = getSensiplanStatus({ + cycle: cycleWithTempAndNoMucusShift, + previousCycle: cycleWithFhm + }) + + expect(Object.keys(status.phases).length).to.eql(2) + + expect(status.phases.preOvulatory).to.eql({ + cycleDays: cycleWithTempAndNoMucusShift + .filter(({date}) => date <= '2018-06-05'), + start: { date: '2018-06-01' }, + end: { date: '2018-06-05' } + }) + expect(status.phases.periOvulatory).to.eql({ + cycleDays: cycleWithTempAndNoMucusShift + .filter(({date}) => date > '2018-06-05'), + start: { date: '2018-06-06' } + }) + }) + it('according to 5-day-rule with shortened pre-phase', function () { + const status = getSensiplanStatus({ + cycle: cycleWithEarlyMucus, + previousCycle: cycleWithFhm + }) + + expect(Object.keys(status.phases).length).to.eql(2) + + expect(status.phases.preOvulatory).to.eql({ + cycleDays: [cycleWithEarlyMucus[0]], + start: { date: '2018-06-01' }, + end: { date: '2018-06-01' } + }) + expect(status.phases.periOvulatory).to.eql({ + cycleDays: cycleWithEarlyMucus.slice(1), + start: { date: '2018-06-02' } + }) + }) + }) + describe('with shifts detects pre- and peri-ovulatory phase', function () { + it('according to 5-day-rule', function () { + const status = getSensiplanStatus({ + cycle: longAndComplicatedCycle, + previousCycle: cycleWithFhm + }) + + expect(Object.keys(status.phases).length).to.eql(3) + + expect(status.phases.preOvulatory).to.eql({ + cycleDays: longAndComplicatedCycle + .filter(({date}) => date <= '2018-06-05'), + start: { date: '2018-06-01' }, + end: { date: '2018-06-05' } + }) + expect(status.phases.periOvulatory).to.eql({ + cycleDays: longAndComplicatedCycle + .filter(({date}) => date > '2018-06-05' && date <= '2018-06-21'), + start: { date: '2018-06-06' }, + end: { date: '2018-06-21', time: '18:00'} + }) + expect(status.phases.postOvulatory).to.eql({ + cycleDays: longAndComplicatedCycle + .filter(({date}) => date >= '2018-06-21'), + start: { date: '2018-06-21', time: '18:00'} + }) + }) + + }) + }) + + describe('combining first higher measurment and mucus peak', () => { + it('with fhM + mucus peak on same day finds start of postovu phase', () => { + const status = getSensiplanStatus({ + cycle: mucusPeakAndFhmOnSameDay, + previousCycle: cycleWithFhm + }) + + expect(status.temperatureShift).to.be.an('object') + expect(status.mucusShift).to.be.an('object') + + expect(Object.keys(status.phases).length).to.eql(3) + expect(status.phases.preOvulatory).to.eql({ + start: { date: '2018-06-01' }, + end: { date: '2018-06-05' }, + cycleDays: mucusPeakAndFhmOnSameDay + .filter(({date}) => date <= '2018-06-05') + }) + expect(status.phases.periOvulatory).to.eql({ + start: { date: '2018-06-06' }, + end: { date: '2018-06-21', time: '18:00' }, + cycleDays: mucusPeakAndFhmOnSameDay + .filter(({date}) => { + return date > '2018-06-05' && date <= '2018-06-21' + }) + }) + expect(status.phases.postOvulatory).to.eql({ + start: { + date: '2018-06-21', + time: '18:00' + }, + cycleDays: mucusPeakAndFhmOnSameDay + .filter(({date}) => date >= '2018-06-21') + }) + }) + + it('with fhM 2 days before mucus peak waits for end of mucus eval', () => { + const status = getSensiplanStatus({ + cycle: fhmTwoDaysBeforeMucusPeak, + previousCycle: cycleWithFhm + }) + + expect(status.temperatureShift).to.be.an('object') + expect(status.mucusShift).to.be.an('object') + + expect(Object.keys(status.phases).length).to.eql(3) + expect(status.phases.preOvulatory).to.eql({ + start: { date: '2018-06-01' }, + end: { date: '2018-06-05' }, + cycleDays: fhmTwoDaysBeforeMucusPeak + .filter(({date}) => date <= '2018-06-05') + }) + expect(status.phases.periOvulatory).to.eql({ + start: { date: '2018-06-06' }, + end: { date: '2018-06-26', time: '18:00' }, + cycleDays: fhmTwoDaysBeforeMucusPeak + .filter(({date}) => { + return date > '2018-06-05' && date <= '2018-06-26' + }) + }) + expect(status.phases.postOvulatory).to.eql({ + start: { + date: '2018-06-26', + time: '18:00' + }, + cycleDays: fhmTwoDaysBeforeMucusPeak + .filter(({date}) => date >= '2018-06-26') + }) + }) + + it('another example for mucus peak before temp shift', () => { + const status = getSensiplanStatus({ + cycle: mucusPeakSlightlyBeforeTempShift, + previousCycle: cycleWithFhm + }) + + expect(status.temperatureShift).to.be.an('object') + expect(status.mucusShift).to.be.an('object') + + expect(Object.keys(status.phases).length).to.eql(3) + expect(status.phases.preOvulatory).to.eql({ + start: { date: '2018-06-01' }, + end: { date: '2018-06-05' }, + cycleDays: mucusPeakSlightlyBeforeTempShift + .filter(({date}) => date <= '2018-06-05') + }) + expect(status.phases.periOvulatory).to.eql({ + start: { date: '2018-06-06' }, + end: { date: '2018-06-17', time: '18:00' }, + cycleDays: mucusPeakSlightlyBeforeTempShift + .filter(({date}) => { + return date > '2018-06-05' && date <= '2018-06-17' + }) + }) + expect(status.phases.postOvulatory).to.eql({ + start: { + date: '2018-06-17', + time: '18:00' + }, + cycleDays: mucusPeakSlightlyBeforeTempShift + .filter(({date}) => date >= '2018-06-17') + }) + }) + + it('with another mucus peak 5 days after fHM ignores it', () => { + const status = getSensiplanStatus({ + cycle: mucusPeak5DaysAfterFhm, + previousCycle: cycleWithFhm + }) + + expect(status.temperatureShift).to.be.an('object') + expect(status.mucusShift).to.be.an('object') + + expect(Object.keys(status.phases).length).to.eql(3) + expect(status.phases.preOvulatory).to.eql({ + start: { date: '2018-06-01' }, + end: { date: '2018-06-01' }, + cycleDays: mucusPeak5DaysAfterFhm + .filter(({date}) => date <= '2018-06-01') + }) + expect(status.phases.periOvulatory).to.eql({ + start: { date: '2018-06-02' }, + end: { date: '2018-06-22', time: '18:00' }, + cycleDays: mucusPeak5DaysAfterFhm + .filter(({date}) => { + return date > '2018-06-01' && date <= '2018-06-22' + }) + }) + expect(status.phases.postOvulatory).to.eql({ + start: { + date: '2018-06-22', + time: '18:00' + }, + cycleDays: mucusPeak5DaysAfterFhm + .filter(({date}) => date >= '2018-06-22') + }) + }) + + it('with mucus peak 2 days before fhM waits for end of temp eval', () => { + const status = getSensiplanStatus({ + cycle: mucusPeakTwoDaysBeforeFhm, + previousCycle: cycleWithFhm + }) + + expect(status.temperatureShift).to.be.an('object') + expect(status.mucusShift).to.be.an('object') + + expect(Object.keys(status.phases).length).to.eql(3) + expect(status.phases.preOvulatory).to.eql({ + start: { date: '2018-06-01' }, + end: { date: '2018-06-04' }, + cycleDays: mucusPeakTwoDaysBeforeFhm + .filter(({date}) => date <= '2018-06-04') + }) + expect(status.phases.periOvulatory).to.eql({ + start: { date: '2018-06-05' }, + end: { date: '2018-07-03', time: '18:00' }, + cycleDays: mucusPeakTwoDaysBeforeFhm + .filter(({date}) => { + return date > '2018-06-04' && date <= '2018-07-03' + }) + }) + expect(status.phases.postOvulatory).to.eql({ + start: { + date: '2018-07-03', + time: '18:00' + }, + cycleDays: mucusPeakTwoDaysBeforeFhm + .filter(({date}) => date >= '2018-07-03') + }) + }) + + it('with mucus peak 5 days before fhM waits for end of temp eval', () => { + const status = getSensiplanStatus({ + cycle: fhm5DaysAfterMucusPeak, + previousCycle: cycleWithFhm + }) + + expect(status.temperatureShift).to.be.an('object') + expect(status.mucusShift).to.be.an('object') + + expect(Object.keys(status.phases).length).to.eql(3) + expect(status.phases.preOvulatory).to.eql({ + start: { date: '2018-06-01' }, + end: { date: '2018-06-05' }, + cycleDays: fhm5DaysAfterMucusPeak + .filter(({date}) => date <= '2018-06-05') + }) + expect(status.phases.periOvulatory).to.eql({ + start: { date: '2018-06-06' }, + end: { date: '2018-06-21', time: '18:00' }, + cycleDays: fhm5DaysAfterMucusPeak + .filter(({date}) => { + return date > '2018-06-05' && date <= '2018-06-21' + }) + }) + expect(status.phases.postOvulatory).to.eql({ + start: { + date: '2018-06-21', + time: '18:00' + }, + cycleDays: fhm5DaysAfterMucusPeak + .filter(({date}) => date >= '2018-06-21') + }) + }) + }) + + describe('applying the minus-8 rule', () => { + it('shortens the pre-ovu phase if there is a previous <13 fhm', () => { + const status = getSensiplanStatus({ + cycle: longAndComplicatedCycle, + previousCycle: fhmOnDay15, + earlierCycles: [fhmOnDay12, ...Array(10).fill(fhmOnDay15)] + }) + + expect(status.temperatureShift).to.be.an('object') + expect(status.mucusShift).to.be.an('object') + + expect(Object.keys(status.phases).length).to.eql(3) + expect(status.phases.preOvulatory).to.eql({ + start: { date: '2018-06-01' }, + end: { date: '2018-06-04' }, + cycleDays: longAndComplicatedCycle + .filter(({date}) => date <= '2018-06-04') + }) + expect(status.phases.periOvulatory).to.eql({ + start: { date: '2018-06-05' }, + end: { date: '2018-06-21', time: '18:00' }, + cycleDays: longAndComplicatedCycle + .filter(({date}) => { + return date > '2018-06-04' && date <= '2018-06-21' + }) + }) + expect(status.phases.postOvulatory).to.eql({ + start: { + date: '2018-06-21', + time: '18:00' + }, + cycleDays: longAndComplicatedCycle + .filter(({date}) => date >= '2018-06-21') + }) + }) + // #TODO + it.only('shortens pre-ovu phase with prev <13 fhm even with <12 cycles', () => { + const status = getSensiplanStatus({ + cycle: longAndComplicatedCycle, + previousCycle: fhmOnDay12, + earlierCycles: Array(10).fill(fhmOnDay12) + }) + + expect(status.temperatureShift).to.be.an('object') + expect(status.mucusShift).to.be.an('object') + + expect(Object.keys(status.phases).length).to.eql(3) + expect(status.phases.preOvulatory).to.eql({ + start: { date: '2018-06-01' }, + end: { date: '2018-06-05' }, + cycleDays: fhm5DaysAfterMucusPeak + .filter(({date}) => date <= '2018-06-05') + }) + expect(status.phases.periOvulatory).to.eql({ + start: { date: '2018-06-06' }, + end: { date: '2018-06-21', time: '18:00' }, + cycleDays: fhm5DaysAfterMucusPeak + .filter(({date}) => { + return date > '2018-06-05' && date <= '2018-06-21' + }) + }) + expect(status.phases.postOvulatory).to.eql({ + start: { + date: '2018-06-21', + time: '18:00' + }, + cycleDays: fhm5DaysAfterMucusPeak + .filter(({date}) => date >= '2018-06-21') + }) + }) + + // #TODO + it('with highest quality after end of eval', () => { + const status = getSensiplanStatus({ + cycle: highestMucusQualityAfterEndOfEval, + previousCycle: cycleWithFhm + }) + + expect(status.temperatureShift).to.be.an('object') + expect(status.mucusShift).to.be.an('object') + + expect(Object.keys(status.phases).length).to.eql(3) + expect(status.phases.preOvulatory).to.eql({ + start: { date: '2018-06-01' }, + end: { date: '2018-06-05' }, + cycleDays: highestMucusQualityAfterEndOfEval + .filter(({date}) => date <= '2018-06-05') + }) + expect(status.phases.periOvulatory).to.eql({ + start: { date: '2018-06-06' }, + end: { date: '2018-06-26', time: '18:00' }, + cycleDays: highestMucusQualityAfterEndOfEval + .filter(({date}) => { + return date > '2018-06-05' && date <= '2018-06-26' + }) + }) + expect(status.phases.postOvulatory).to.eql({ + start: { + date: '2018-06-26', + time: '18:00' + }, + cycleDays: highestMucusQualityAfterEndOfEval + .filter(({date}) => date >= '2018-06-26') + }) + }) + }) + + describe('something', () => { + + it('shortens the pre-ovu phase if mucus occurs', () => { + const status = getSensiplanStatus({ + cycle: cycleWithEarlyMucus, + previousCycle: fhmOnDay12, + earlierCycles: Array(10).fill(fhmOnDay12) + }) + + + expect(Object.keys(status.phases).length).to.eql(2) + expect(status.phases.preOvulatory).to.eql({ + start: { date: '2018-06-01' }, + end: { date: '2018-06-01' }, + cycleDays: cycleWithEarlyMucus + .filter(({date}) => date <= '2018-06-01') + }) + expect(status.phases.periOvulatory).to.eql({ + start: { date: '2018-06-02' }, + cycleDays: cycleWithEarlyMucus + .filter(({date}) => { + return date > '2018-06-01' + }) + }) + }) + + it('shortens the pre-ovu phase if mucus occurs even on the first day', () => { + const status = getSensiplanStatus({ + cycle: cycleWithMucusOnFirstDay, + previousCycle: fhmOnDay12, + earlierCycles: Array(10).fill(fhmOnDay12) + }) + + + expect(Object.keys(status.phases).length).to.eql(1) + + expect(status.phases.periOvulatory).to.eql({ + start: { date: '2018-06-01' }, + cycleDays: cycleWithMucusOnFirstDay + }) + }) + + it('lengthens the pre-ovu phase if >= 12 cycles with fhm > 13', () => { + const status = getSensiplanStatus({ + cycle: longAndComplicatedCycle, + previousCycle: fhmOnDay15, + earlierCycles: Array(11).fill(fhmOnDay15) + }) + + + expect(Object.keys(status.phases).length).to.eql(3) + expect(status.phases.preOvulatory).to.eql({ + start: { date: '2018-06-01' }, + end: { date: '2018-06-07' }, + cycleDays: longAndComplicatedCycle + .filter(({date}) => date <= '2018-06-07') + }) + expect(status.phases.periOvulatory).to.eql({ + start: { date: '2018-06-08' }, + end: { date: '2018-06-21', time: '18:00' }, + cycleDays: longAndComplicatedCycle + .filter(({date}) => { + return date > '2018-06-07' && date <= '2018-06-21' + }) + }) + expect(status.phases.postOvulatory).to.eql({ + start: { + date: '2018-06-21', + time: '18:00' + }, + cycleDays: longAndComplicatedCycle + .filter(({date}) => date >= '2018-06-21') + }) + }) + + it('does not lengthen the pre-ovu phase if < 12 cycles', () => { + const status = getSensiplanStatus({ + cycle: longAndComplicatedCycle, + previousCycle: fhmOnDay15, + earlierCycles: Array(10).fill(fhmOnDay15) + }) + + + expect(Object.keys(status.phases).length).to.eql(3) + expect(status.phases.preOvulatory).to.eql({ + start: { date: '2018-06-01' }, + end: { date: '2018-06-05' }, + cycleDays: longAndComplicatedCycle + .filter(({date}) => date <= '2018-06-05') + }) + expect(status.phases.periOvulatory).to.eql({ + start: { date: '2018-06-06' }, + end: { date: '2018-06-21', time: '18:00' }, + cycleDays: longAndComplicatedCycle + .filter(({date}) => { + return date > '2018-06-05' && date <= '2018-06-21' + }) + }) + expect(status.phases.postOvulatory).to.eql({ + start: { + date: '2018-06-21', + time: '18:00' + }, + cycleDays: longAndComplicatedCycle + .filter(({date}) => date >= '2018-06-21') + }) + }) + + it('does not detect any pre-ovu phase if prev cycle had no fhm', () => { + const status = getSensiplanStatus({ + cycle: longAndComplicatedCycle, + previousCycle: cycleWithoutFhm, + earlierCycles: [...Array(12).fill(fhmOnDay15)] + }) + + + expect(Object.keys(status.phases).length).to.eql(2) + expect(status.phases.periOvulatory).to.eql({ + start: { date: '2018-06-01' }, + end: { date: '2018-06-21', time: '18:00' }, + cycleDays: longAndComplicatedCycle + .filter(({date}) => { + return date >= '2018-06-01' && date <= '2018-06-21' + }) + }) + expect(status.phases.postOvulatory).to.eql({ + start: { + date: '2018-06-21', + time: '18:00' + }, + cycleDays: longAndComplicatedCycle + .filter(({date}) => date >= '2018-06-21') + }) + }) + }) + + describe('when args are wrong', () => { + it('throws when arg object is not in right format', () => { + const wrongObject = { hello: 'world' } + expect(() => getSensiplanStatus(wrongObject)).to.throw(AssertionError) + }) + it('throws if cycle array is empty', () => { + expect(() => getSensiplanStatus({cycle: []})).to.throw(AssertionError) + }) + it('throws if cycle days are not in right format', () => { + expect(() => getSensiplanStatus({ + cycle: [{ + hello: 'world', + bleeding: { value: 0 } + }], + earlierCycles: [[{ + date: '1992-09-09', + bleeding: { value: 0 } + }]] + })).to.throw(AssertionError) + expect(() => getSensiplanStatus({ + cycle: [{ + date: '2018-04-13', + temperature: {value: '35'}, + bleeding: { value: 0 } + }], + earlierCycles: [[{ + date: '1992-09-09', + bleeding: { value: 0 } + }]] + })).to.throw(AssertionError) + expect(() => getSensiplanStatus({ + cycle: [{ + date: '09-14-2017', + bleeding: { value: 0 } + }], + earlierCycles: [[{ + date: '1992-09-09', + bleeding: { value: 0 } + }]] + })).to.throw(AssertionError) + }) + it('throws if first cycle day does not have bleeding value', () => { + expect(() => getSensiplanStatus({ + cycle: [{ + date: '2017-01-01', + bleeding: { + value: 'medium' + } + }], + earlierCycles: [[ + { + date: '2017-09-23', + } + ]] + })).to.throw(AssertionError) + }) + }) + }) +}) -- GitLab