Extract fixtures

This commit is contained in:
Julia Friesel
2018-07-10 13:10:53 +02:00
parent 672235a475
commit 51bd75fb0f
2 changed files with 97 additions and 87 deletions
+92
View File
@@ -0,0 +1,92 @@
function convertToSymptoFormat(val, i) {
++i
const dayString = i < 10 ? `0${i}` : i
const sympto = { date: `2018-06-${dayString}` }
if (val.temperature) sympto.temperature = { value: val.temperature }
if (val.mucus) sympto.mucus = { value: val.mucus }
if (val.bleeding) sympto.bleeding = { value: val.bleeding }
return sympto
}
const cycleWithTempShift = [36.6, 36.6, 36.6, 36.6, 36.6, 36.6, 36.8, 36.8, 36.8]
.map(num => ({ temperature: num }))
.map(convertToSymptoFormat)
const cycleWithoutTempShift = [36.6, 36.6, 36.6, 36.6, 36.6, 36.6, 36.8, 36.8]
.map(num => ({ temperature: num }))
.map(convertToSymptoFormat)
const cycleWithTempAndMucusShift = [
{ temperature: 36.6, bleeding: 2 },
{ temperature: 36.65 },
{ temperature: 36.5 },
{ temperature: 36.6 },
{ temperature: 36.55 },
{ temperature: 36.7, mucus: 0 },
{ temperature: 36.75, mucus: 0 },
{ temperature: 36.45, mucus: 1 },
{ temperature: 36.5, mucus: 4 },
{ temperature: 36.4, mucus: 2 },
{ temperature: 36.5, mucus: 3 },
{ temperature: 36.55, mucus: 3 },
{ temperature: 36.45, mucus: 3 },
{ temperature: 36.5, mucus: 4 },
{ temperature: 36.55, mucus: 4 },
{ temperature: 36.7, mucus: 3 },
{ temperature: 36.65, mucus: 3 },
{ temperature: 36.75, mucus: 4 },
{ temperature: 36.8, mucus: 1 },
{ temperature: 36.85, mucus: 2 },
{ temperature: 36.8, mucus: 2 },
{ temperature: 36.9, mucus: 2 },
{ temperature: 36.9, mucus: 1 },
{ temperature: 36.85, mucus: 1 },
{ temperature: 36.9, mucus: 1 },
{ temperature: 36.8, mucus: 1 },
{ temperature: 36.9, mucus: 1 }
].map(convertToSymptoFormat)
const cycleWithTempAndNoMucusShift = [
{ temperature: 36.6, bleeding: 2 },
{ temperature: 36.65 },
{ temperature: 36.5 },
{ temperature: 36.6 },
{ temperature: 36.55 },
{ temperature: 36.7, mucus: 0 },
{ temperature: 36.75, mucus: 0 },
{ temperature: 36.45, mucus: 1 },
{ temperature: 36.5, mucus: 4 },
{ temperature: 36.4, mucus: 2 },
{ temperature: 36.5, mucus: 3 },
{ temperature: 36.55, mucus: 3 },
{ temperature: 36.45, mucus: 3 },
{ temperature: 36.5, mucus: 4 },
{ temperature: 36.55, mucus: 4 },
{ temperature: 36.7, mucus: 3 },
{ temperature: 36.65, mucus: 3 },
{ temperature: 36.75, mucus: 4 },
{ temperature: 36.8, mucus: 4 },
{ temperature: 36.85, mucus: 4 },
{ temperature: 36.8, mucus: 4 },
{ temperature: 36.9, mucus: 4 }
].map(convertToSymptoFormat)
const cycleWithoutAnyShifts = [
{ temperature: 36.6, bleeding: 2 },
{ temperature: 36.65 },
{ temperature: 36.5 },
{ temperature: 36.6 },
{ temperature: 36.55 },
{ temperature: 36.7, mucus: 0 },
{ temperature: 36.75, mucus: 0 },
{ temperature: 36.45, mucus: 1 }
].map(convertToSymptoFormat)
export {
cycleWithoutTempShift,
cycleWithTempAndMucusShift,
cycleWithTempAndNoMucusShift,
cycleWithTempShift,
cycleWithoutAnyShifts
}
+5 -87
View File
@@ -1,99 +1,17 @@
import chai from 'chai' import chai from 'chai'
import getSensiplanStatus from '../../lib/sympto' import getSensiplanStatus from '../../lib/sympto'
import {
cycleWithoutTempShift, cycleWithTempAndMucusShift, cycleWithTempAndNoMucusShift, cycleWithTempShift, cycleWithoutAnyShifts
} from './fixtures'
const expect = chai.expect const expect = chai.expect
function convertToSymptoFormat(val, i) {
++i
const dayString = i < 10 ? `0${i}` : i
const sympto = { date: `2018-06-${dayString}` }
if (val.temperature) sympto.temperature = { value: val.temperature }
if (val.mucus) sympto.mucus = { value: val.mucus }
if (val.bleeding) sympto.bleeding = { value: val.bleeding }
return sympto
}
const cycleWithTempShift = [36.6, 36.6, 36.6, 36.6, 36.6, 36.6, 36.8, 36.8, 36.8]
.map(num => ({ temperature: num }))
.map(convertToSymptoFormat)
const cycleWithoutTempShift = [36.6, 36.6, 36.6, 36.6, 36.6, 36.6, 36.8, 36.8]
.map(num => ({ temperature: num }))
.map(convertToSymptoFormat)
const cycleWithTempAndMucusShift = [
{ temperature: 36.6, bleeding: 2 },
{ temperature: 36.65 },
{ temperature: 36.5 },
{ temperature: 36.6 },
{ temperature: 36.55 },
{ temperature: 36.7, mucus: 0 },
{ temperature: 36.75, mucus: 0 },
{ temperature: 36.45, mucus: 1 },
{ temperature: 36.5, mucus: 4 },
{ temperature: 36.4, mucus: 2 },
{ temperature: 36.5, mucus: 3 },
{ temperature: 36.55, mucus: 3 },
{ temperature: 36.45, mucus: 3 },
{ temperature: 36.5, mucus: 4 },
{ temperature: 36.55, mucus: 4 },
{ temperature: 36.7, mucus: 3 },
{ temperature: 36.65, mucus: 3 },
{ temperature: 36.75, mucus: 4 },
{ temperature: 36.8, mucus: 1 },
{ temperature: 36.85, mucus: 2 },
{ temperature: 36.8, mucus: 2 },
{ temperature: 36.9, mucus: 2 },
{ temperature: 36.9, mucus: 1 },
{ temperature: 36.85, mucus: 1 },
{ temperature: 36.9, mucus: 1 },
{ temperature: 36.8, mucus: 1 },
{ temperature: 36.9, mucus: 1 }
].map(convertToSymptoFormat)
const cycleWithTempAndNoMucusShift = [
{ temperature: 36.6, bleeding: 2 },
{ temperature: 36.65 },
{ temperature: 36.5 },
{ temperature: 36.6 },
{ temperature: 36.55 },
{ temperature: 36.7, mucus: 0 },
{ temperature: 36.75, mucus: 0 },
{ temperature: 36.45, mucus: 1 },
{ temperature: 36.5, mucus: 4 },
{ temperature: 36.4, mucus: 2 },
{ temperature: 36.5, mucus: 3 },
{ temperature: 36.55, mucus: 3 },
{ temperature: 36.45, mucus: 3 },
{ temperature: 36.5, mucus: 4 },
{ temperature: 36.55, mucus: 4 },
{ temperature: 36.7, mucus: 3 },
{ temperature: 36.65, mucus: 3 },
{ temperature: 36.75, mucus: 4 },
{ temperature: 36.8, mucus: 4 },
{ temperature: 36.85, mucus: 4 },
{ temperature: 36.8, mucus: 4 },
{ temperature: 36.9, mucus: 4 }
].map(convertToSymptoFormat)
describe('sympto', () => { describe('sympto', () => {
describe('evaluating mucus and temperature shift together', () => { describe('evaluating mucus and temperature shift together', () => {
describe('with no previous higher measurement', () => { describe('with no previous higher measurement', () => {
it('with no shifts detects only peri-ovulatory', function () { it('with no shifts detects only peri-ovulatory', function () {
const values = [
{ temperature: 36.6, bleeding: 2 },
{ temperature: 36.65 },
{ temperature: 36.5 },
{ temperature: 36.6 },
{ temperature: 36.55 },
{ temperature: 36.7, mucus: 0 },
{ temperature: 36.75, mucus: 0 },
{ temperature: 36.45, mucus: 1 }
]
const cycle = values.map(convertToSymptoFormat)
const status = getSensiplanStatus({ const status = getSensiplanStatus({
cycle, cycle: cycleWithoutAnyShifts,
previousCycle: cycleWithoutTempShift previousCycle: cycleWithoutTempShift
}) })
@@ -102,7 +20,7 @@ describe('sympto', () => {
phases: { phases: {
periOvulatory: { periOvulatory: {
start: { date: '2018-06-01' }, start: { date: '2018-06-01' },
cycleDays: cycle cycleDays: cycleWithoutAnyShifts
} }
}, },
}) })