From de2233f998b12c1ddfa111e88c1861038a24b804 Mon Sep 17 00:00:00 2001
From: Julia Friesel <julia.friesel@gmail.com>
Date: Fri, 13 Jul 2018 09:09:45 +0200
Subject: [PATCH] Fix assert for bleeding value === null

---
 lib/sympto/index.js | 22 ++++++++++++----------
 1 file changed, 12 insertions(+), 10 deletions(-)

diff --git a/lib/sympto/index.js b/lib/sympto/index.js
index 2005f323..01509391 100644
--- a/lib/sympto/index.js
+++ b/lib/sympto/index.js
@@ -5,7 +5,7 @@ import { LocalDate } from 'js-joda'
 import assert from 'assert'
 
 export default function getSymptoThermalStatus({ cycle, previousCycles = [] }) {
-  throwIfArgsAreNotInRequiredFormat(cycle, previousCycles)
+  throwIfArgsAreNotInRequiredFormat([cycle, ...previousCycles])
 
   const status = {
     assumeFertility: true,
@@ -14,12 +14,14 @@ export default function getSymptoThermalStatus({ cycle, previousCycles = [] }) {
 
   // if there was no first higher measurement in the previous cycle,
   // no infertile pre-ovulatory phase may be assumed
-  const lastCycle = previousCycles[previousCycles.length - 1]
-  if (lastCycle && getSymptoThermalStatus({cycle: lastCycle}).temperatureShift) {
-    status.phases.preOvulatory = getPreOvulatoryPhase(cycle, previousCycles)
-    if (status.phases.preOvulatory.cycleDays.length === cycle.length) {
-      status.assumeFertility = false
-      return status
+  if (previousCycles) {
+    const lastCycle = previousCycles[previousCycles.length - 1]
+    if (lastCycle && getSymptoThermalStatus({ cycle: lastCycle }).temperatureShift) {
+      status.phases.preOvulatory = getPreOvulatoryPhase(cycle, previousCycles)
+      if (status.phases.preOvulatory.cycleDays.length === cycle.length) {
+        status.assumeFertility = false
+        return status
+      }
     }
   }
 
@@ -71,11 +73,11 @@ export default function getSymptoThermalStatus({ cycle, previousCycles = [] }) {
   return status
 }
 
-function throwIfArgsAreNotInRequiredFormat(cycle, previousCycles) {
-  [cycle, ...previousCycles].forEach(cycle => {
+function throwIfArgsAreNotInRequiredFormat(cycles) {
+  cycles.forEach(cycle => {
     assert.ok(Array.isArray(cycle))
-    // TODO handle case of no previous cycles
     assert.ok(cycle.length > 0)
+    assert.ok(cycle[0].bleeding !== null)
     assert.equal(typeof cycle[0].bleeding, 'object')
     assert.equal(typeof cycle[0].bleeding.value, 'number')
     cycle.forEach(day => {
-- 
GitLab