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
a1306cd7
Commit
a1306cd7
authored
6 years ago
by
Julia Friesel
Browse files
Options
Downloads
Patches
Plain Diff
Use assert for args check
parent
60c61894
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
lib/sympto/index.js
+12
-18
12 additions, 18 deletions
lib/sympto/index.js
test/sympto/index.spec.js
+7
-6
7 additions, 6 deletions
test/sympto/index.spec.js
with
19 additions
and
24 deletions
lib/sympto/index.js
+
12
−
18
View file @
a1306cd7
...
...
@@ -2,6 +2,7 @@ import getTemperatureShift from './temperature'
import
getMucusShift
from
'
./mucus
'
import
getPreOvulatoryPhase
from
'
./pre-ovulatory
'
import
{
LocalDate
}
from
'
js-joda
'
import
assert
from
'
assert
'
export
default
function
({
cycle
,
previousCycle
})
{
throwIfArgsAreNotInRequiredFormat
(
cycle
,
previousCycle
)
...
...
@@ -70,23 +71,16 @@ export default function ({ cycle, previousCycle }) {
}
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
[
cycle
,
previousCycle
].
forEach
(
cycle
=>
{
assert
.
ok
(
Array
.
isArray
(
cycle
))
assert
.
ok
(
cycle
.
length
>
0
)
assert
.
equal
(
typeof
cycle
[
0
].
bleeding
,
'
object
'
)
assert
.
equal
(
typeof
cycle
[
0
].
bleeding
.
value
,
'
number
'
)
cycle
.
forEach
(
day
=>
{
assert
.
equal
(
typeof
day
.
date
,
'
string
'
)
assert
.
doesNotThrow
(()
=>
LocalDate
.
parse
(
day
.
date
))
if
(
day
.
temperature
)
assert
.
equal
(
typeof
day
.
temperature
.
value
,
'
number
'
)
if
(
day
.
mucus
)
assert
.
equal
(
typeof
day
.
mucus
.
value
,
'
number
'
)
})
})
)
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/index.spec.js
+
7
−
6
View file @
a1306cd7
import
chai
from
'
chai
'
import
getSensiplanStatus
from
'
../../lib/sympto
'
import
{
AssertionError
}
from
'
assert
'
import
{
cycleWithoutTempShift
,
cycleWithTempAndMucusShift
,
...
...
@@ -141,10 +142,10 @@ 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
'
)
expect
(()
=>
getSensiplanStatus
(
wrongObject
)).
to
.
throw
(
AssertionError
)
})
it
(
'
throws if cycle array is empty
'
,
()
=>
{
expect
(()
=>
getSensiplanStatus
({
cycle
:
[]})).
to
.
throw
(
'
cycle days as array
'
)
expect
(()
=>
getSensiplanStatus
({
cycle
:
[]})).
to
.
throw
(
AssertionError
)
})
it
(
'
throws if cycle days are not in right format
'
,
()
=>
{
expect
(()
=>
getSensiplanStatus
({
...
...
@@ -156,7 +157,7 @@ describe('sympto', () => {
date
:
'
1992-09-09
'
,
bleeding
:
{
value
:
0
}
}]
})).
to
.
throw
(
'
correct format
'
)
})).
to
.
throw
(
AssertionError
)
expect
(()
=>
getSensiplanStatus
({
cycle
:
[{
date
:
'
2018-04-13
'
,
...
...
@@ -167,7 +168,7 @@ describe('sympto', () => {
date
:
'
1992-09-09
'
,
bleeding
:
{
value
:
0
}
}]
})).
to
.
throw
(
'
correct format
'
)
})).
to
.
throw
(
AssertionError
)
expect
(()
=>
getSensiplanStatus
({
cycle
:
[{
date
:
'
09-14-2017
'
,
...
...
@@ -177,7 +178,7 @@ describe('sympto', () => {
date
:
'
1992-09-09
'
,
bleeding
:
{
value
:
0
}
}]
})).
to
.
throw
(
'
ISO
'
)
})).
to
.
throw
(
AssertionError
)
})
it
(
'
throws if first cycle day does not have bleeding value
'
,
()
=>
{
expect
(()
=>
getSensiplanStatus
({
...
...
@@ -192,7 +193,7 @@ describe('sympto', () => {
date
:
'
2017-09-23
'
,
}
]
})).
to
.
throw
(
'
start with bleeding
'
)
})).
to
.
throw
(
AssertionError
)
})
})
})
\ 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