Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
D
Drip
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Issue analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
backup
Drip
Commits
d027c6e9
Commit
d027c6e9
authored
6 years ago
by
Julia Friesel
Browse files
Options
Downloads
Patches
Plain Diff
Throw if args are wrong
parent
81b7b46b
No related branches found
No related tags found
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
lib/sympto/index.js
+24
-1
24 additions, 1 deletion
lib/sympto/index.js
test/sympto/fixtures.js
+2
-0
2 additions, 0 deletions
test/sympto/fixtures.js
test/sympto/index.spec.js
+92
-37
92 additions, 37 deletions
test/sympto/index.spec.js
with
118 additions
and
38 deletions
lib/sympto/index.js
+
24
−
1
View file @
d027c6e9
...
@@ -4,7 +4,8 @@ import getPreOvulatoryPhase from './pre-ovulatory'
...
@@ -4,7 +4,8 @@ import getPreOvulatoryPhase from './pre-ovulatory'
import
{
LocalDate
}
from
'
js-joda
'
import
{
LocalDate
}
from
'
js-joda
'
export
default
function
({
cycle
,
previousCycle
})
{
export
default
function
({
cycle
,
previousCycle
})
{
// TODO check for basic stuff, throw if nonexistent
throwIfArgsAreNotInRequiredFormat
(
cycle
,
previousCycle
)
const
status
=
{
const
status
=
{
assumeFertility
:
true
,
assumeFertility
:
true
,
phases
:
{}
phases
:
{}
...
@@ -66,4 +67,26 @@ export default function ({ cycle, previousCycle }) {
...
@@ -66,4 +67,26 @@ export default function ({ cycle, previousCycle }) {
status
.
assumeFertility
=
false
status
.
assumeFertility
=
false
return
status
return
status
}
function
throwIfArgsAreNotInRequiredFormat
(
cycle
,
previousCycle
)
{
if
(
!
Array
.
isArray
(
cycle
)
||
!
cycle
.
length
)
throw
new
Error
(
'
Please provide all cycle days as array
'
)
if
(
!
Array
.
isArray
(
previousCycle
)
||
!
previousCycle
.
length
)
throw
new
Error
(
'
Please provide previous cycle days as array
'
)
if
(
!
cycle
[
0
].
bleeding
||
typeof
cycle
[
0
].
bleeding
.
value
!=
'
number
'
||
!
previousCycle
[
0
].
bleeding
||
typeof
previousCycle
[
0
].
bleeding
.
value
!=
'
number
'
)
throw
new
Error
(
'
Cycle must start with bleeding
'
)
if
([
cycle
,
previousCycle
].
some
(
cycle
=>
{
return
cycle
.
some
(
day
=>
{
if
(
!
day
.
date
)
return
true
try
{
LocalDate
.
parse
(
day
.
date
)
}
catch
(
err
)
{
throw
new
Error
(
'
Please provide dates in ISO8601 format
'
)
}
if
(
day
.
temperature
&&
typeof
day
.
temperature
.
value
!=
'
number
'
)
return
true
if
(
day
.
mucus
&&
typeof
day
.
mucus
.
value
!=
'
number
'
)
return
true
})
}))
throw
new
Error
(
'
Cycle days are not in correct format
'
)
}
}
\ No newline at end of file
This diff is collapsed.
Click to expand it.
test/sympto/fixtures.js
+
2
−
0
View file @
d027c6e9
...
@@ -10,10 +10,12 @@ function convertToSymptoFormat(val) {
...
@@ -10,10 +10,12 @@ function convertToSymptoFormat(val) {
const
cycleWithTempShift
=
[
36.6
,
36.6
,
36.6
,
36.6
,
36.6
,
36.6
,
36.8
,
36.8
,
36.8
]
const
cycleWithTempShift
=
[
36.6
,
36.6
,
36.6
,
36.6
,
36.6
,
36.6
,
36.8
,
36.8
,
36.8
]
.
map
(
num
=>
({
date
:
'
2018-06-01
'
,
temperature
:
num
}))
.
map
(
num
=>
({
date
:
'
2018-06-01
'
,
temperature
:
num
}))
.
map
(
convertToSymptoFormat
)
.
map
(
convertToSymptoFormat
)
cycleWithTempShift
.
unshift
({
date
:
'
2018-05-30
'
,
bleeding
:
{
value
:
2
}})
const
cycleWithoutTempShift
=
[
36.6
,
36.6
,
36.6
,
36.6
,
36.6
,
36.6
,
36.8
,
36.8
]
const
cycleWithoutTempShift
=
[
36.6
,
36.6
,
36.6
,
36.6
,
36.6
,
36.6
,
36.8
,
36.8
]
.
map
(
num
=>
({
date
:
'
2018-06-01
'
,
temperature
:
num
}))
.
map
(
num
=>
({
date
:
'
2018-06-01
'
,
temperature
:
num
}))
.
map
(
convertToSymptoFormat
)
.
map
(
convertToSymptoFormat
)
cycleWithoutTempShift
.
unshift
({
date
:
'
2018-05-30
'
,
bleeding
:
{
value
:
2
}})
const
cycleWithTempAndMucusShift
=
[
const
cycleWithTempAndMucusShift
=
[
{
date
:
'
2018-06-01
'
,
temperature
:
36.6
,
bleeding
:
2
},
{
date
:
'
2018-06-01
'
,
temperature
:
36.6
,
bleeding
:
2
},
...
...
This diff is collapsed.
Click to expand it.
test/sympto/index.spec.js
+
92
−
37
View file @
d027c6e9
...
@@ -7,47 +7,45 @@ import {
...
@@ -7,47 +7,45 @@ import {
const
expect
=
chai
.
expect
const
expect
=
chai
.
expect
describe
(
'
sympto
'
,
()
=>
{
describe
(
'
sympto
'
,
()
=>
{
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
status
=
getSensiplanStatus
({
const
status
=
getSensiplanStatus
({
cycle
:
cycleWithoutAnyShifts
,
cycle
:
cycleWithoutAnyShifts
,
previousCycle
:
cycleWithoutTempShift
previousCycle
:
cycleWithoutTempShift
})
})
expect
(
status
).
to
.
eql
({
expect
(
status
).
to
.
eql
({
assumeFertility
:
true
,
assumeFertility
:
true
,
phases
:
{
phases
:
{
periOvulatory
:
{
periOvulatory
:
{
start
:
{
date
:
'
2018-06-01
'
},
start
:
{
date
:
'
2018-06-01
'
},
cycleDays
:
cycleWithoutAnyShifts
cycleDays
:
cycleWithoutAnyShifts
}
}
},
},
})
})
})
})
it
(
'
with shifts detects only peri-ovulatory and post-ovulatory
'
,
function
()
{
it
(
'
with shifts detects only peri-ovulatory and post-ovulatory
'
,
function
()
{
const
status
=
getSensiplanStatus
({
const
status
=
getSensiplanStatus
({
cycle
:
cycleWithTempAndMucusShift
,
cycle
:
cycleWithTempAndMucusShift
,
previousCycle
:
cycleWithoutTempShift
previousCycle
:
cycleWithoutTempShift
})
})
expect
(
status
.
temperatureShift
).
to
.
be
.
an
(
'
object
'
)
expect
(
status
.
temperatureShift
).
to
.
be
.
an
(
'
object
'
)
expect
(
status
.
mucusShift
).
to
.
be
.
an
(
'
object
'
)
expect
(
status
.
mucusShift
).
to
.
be
.
an
(
'
object
'
)
expect
(
status
.
assumeFertility
).
to
.
be
.
false
()
expect
(
status
.
assumeFertility
).
to
.
be
.
false
()
expect
(
Object
.
keys
(
status
.
phases
).
length
).
to
.
eql
(
2
)
expect
(
Object
.
keys
(
status
.
phases
).
length
).
to
.
eql
(
2
)
expect
(
status
.
phases
.
periOvulatory
).
to
.
eql
({
expect
(
status
.
phases
.
periOvulatory
).
to
.
eql
({
start
:
{
date
:
'
2018-06-01
'
},
start
:
{
date
:
'
2018-06-01
'
},
end
:
{
date
:
'
2018-06-21
'
,
time
:
'
18:00
'
},
end
:
{
date
:
'
2018-06-21
'
,
time
:
'
18:00
'
},
cycleDays
:
cycleWithTempAndMucusShift
.
filter
(({
date
})
=>
date
<=
'
2018-06-21
'
)
cycleDays
:
cycleWithTempAndMucusShift
.
filter
(({
date
})
=>
date
<=
'
2018-06-21
'
)
})
})
expect
(
status
.
phases
.
postOvulatory
).
to
.
eql
({
expect
(
status
.
phases
.
postOvulatory
).
to
.
eql
({
start
:
{
start
:
{
date
:
'
2018-06-21
'
,
date
:
'
2018-06-21
'
,
time
:
'
18:00
'
time
:
'
18:00
'
},
},
cycleDays
:
cycleWithTempAndMucusShift
.
filter
(({
date
})
=>
date
>=
'
2018-06-21
'
)
cycleDays
:
cycleWithTempAndMucusShift
.
filter
(({
date
})
=>
date
>=
'
2018-06-21
'
)
})
})
})
})
})
})
})
...
@@ -117,4 +115,61 @@ describe('sympto', () => {
...
@@ -117,4 +115,61 @@ describe('sympto', () => {
})
})
})
})
describe
(
'
when args are wrong
'
,
()
=>
{
it
(
'
throws when arg object is not in right format
'
,
()
=>
{
const
wrongObject
=
{
hello
:
'
world
'
}
expect
(()
=>
getSensiplanStatus
(
wrongObject
)).
to
.
throw
(
'
cycle days as array
'
)
})
it
(
'
throws if cycle array is empty
'
,
()
=>
{
expect
(()
=>
getSensiplanStatus
({
cycle
:
[]})).
to
.
throw
(
'
cycle days as array
'
)
})
it
(
'
throws if cycle days are not in right format
'
,
()
=>
{
expect
(()
=>
getSensiplanStatus
({
cycle
:
[{
hello
:
'
world
'
,
bleeding
:
{
value
:
0
}
}],
previousCycle
:
[{
date
:
'
1992-09-09
'
,
bleeding
:
{
value
:
0
}
}]
})).
to
.
throw
(
'
correct format
'
)
expect
(()
=>
getSensiplanStatus
({
cycle
:
[{
date
:
'
2018-04-13
'
,
temperature
:
{
value
:
'
35
'
},
bleeding
:
{
value
:
0
}
}],
previousCycle
:
[{
date
:
'
1992-09-09
'
,
bleeding
:
{
value
:
0
}
}]
})).
to
.
throw
(
'
correct format
'
)
expect
(()
=>
getSensiplanStatus
({
cycle
:
[{
date
:
'
09-14-2017
'
,
bleeding
:
{
value
:
0
}
}],
previousCycle
:
[{
date
:
'
1992-09-09
'
,
bleeding
:
{
value
:
0
}
}]
})).
to
.
throw
(
'
ISO
'
)
})
it
(
'
throws if first cycle day does not have bleeding value
'
,
()
=>
{
expect
(()
=>
getSensiplanStatus
({
cycle
:
[{
date
:
'
2017-01-01
'
,
bleeding
:
{
value
:
'
medium
'
}
}],
previousCycle
:
[
{
date
:
'
2017-09-23
'
,
}
]
})).
to
.
throw
(
'
start with bleeding
'
)
})
})
})
})
\ No newline at end of file
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment