Fix assert for bleeding value === null
This commit is contained in:
+12
-10
@@ -5,7 +5,7 @@ import { LocalDate } from 'js-joda'
|
|||||||
import assert from 'assert'
|
import assert from 'assert'
|
||||||
|
|
||||||
export default function getSymptoThermalStatus({ cycle, previousCycles = [] }) {
|
export default function getSymptoThermalStatus({ cycle, previousCycles = [] }) {
|
||||||
throwIfArgsAreNotInRequiredFormat(cycle, previousCycles)
|
throwIfArgsAreNotInRequiredFormat([cycle, ...previousCycles])
|
||||||
|
|
||||||
const status = {
|
const status = {
|
||||||
assumeFertility: true,
|
assumeFertility: true,
|
||||||
@@ -14,12 +14,14 @@ export default function getSymptoThermalStatus({ cycle, previousCycles = [] }) {
|
|||||||
|
|
||||||
// if there was no first higher measurement in the previous cycle,
|
// if there was no first higher measurement in the previous cycle,
|
||||||
// no infertile pre-ovulatory phase may be assumed
|
// no infertile pre-ovulatory phase may be assumed
|
||||||
const lastCycle = previousCycles[previousCycles.length - 1]
|
if (previousCycles) {
|
||||||
if (lastCycle && getSymptoThermalStatus({cycle: lastCycle}).temperatureShift) {
|
const lastCycle = previousCycles[previousCycles.length - 1]
|
||||||
status.phases.preOvulatory = getPreOvulatoryPhase(cycle, previousCycles)
|
if (lastCycle && getSymptoThermalStatus({ cycle: lastCycle }).temperatureShift) {
|
||||||
if (status.phases.preOvulatory.cycleDays.length === cycle.length) {
|
status.phases.preOvulatory = getPreOvulatoryPhase(cycle, previousCycles)
|
||||||
status.assumeFertility = false
|
if (status.phases.preOvulatory.cycleDays.length === cycle.length) {
|
||||||
return status
|
status.assumeFertility = false
|
||||||
|
return status
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -71,11 +73,11 @@ export default function getSymptoThermalStatus({ cycle, previousCycles = [] }) {
|
|||||||
return status
|
return status
|
||||||
}
|
}
|
||||||
|
|
||||||
function throwIfArgsAreNotInRequiredFormat(cycle, previousCycles) {
|
function throwIfArgsAreNotInRequiredFormat(cycles) {
|
||||||
[cycle, ...previousCycles].forEach(cycle => {
|
cycles.forEach(cycle => {
|
||||||
assert.ok(Array.isArray(cycle))
|
assert.ok(Array.isArray(cycle))
|
||||||
// TODO handle case of no previous cycles
|
|
||||||
assert.ok(cycle.length > 0)
|
assert.ok(cycle.length > 0)
|
||||||
|
assert.ok(cycle[0].bleeding !== null)
|
||||||
assert.equal(typeof cycle[0].bleeding, 'object')
|
assert.equal(typeof cycle[0].bleeding, 'object')
|
||||||
assert.equal(typeof cycle[0].bleeding.value, 'number')
|
assert.equal(typeof cycle[0].bleeding.value, 'number')
|
||||||
cycle.forEach(day => {
|
cycle.forEach(day => {
|
||||||
|
|||||||
Reference in New Issue
Block a user