@@ -43,7 +43,6 @@ var _ = Describe("Config", func() {
4343 },
4444 "urgentLow": {
4545 "enabled": false,
46- "repeat": 30,
4746 "threshold": {
4847 "units": "mg/dL",
4948 "value": 47.5
@@ -60,12 +59,10 @@ var _ = Describe("Config", func() {
6059 },
6160 "notLooping": {
6261 "enabled": true,
63- "repeat": 32,
6462 "delay": 4
6563 },
6664 "noCommunication": {
6765 "enabled": true,
68- "repeat": 33,
6966 "delay": 6
7067 }
7168}` , mockUserID1 , mockUserID2 , mockUploadID )
@@ -86,14 +83,11 @@ var _ = Describe("Config", func() {
8683 Expect (conf .Low .Threshold .Value ).To (Equal (80.0 ))
8784 Expect (conf .Low .Threshold .Units ).To (Equal (glucose .MgdL ))
8885 Expect (conf .UrgentLow .Enabled ).To (Equal (false ))
89- Expect (conf .UrgentLow .Repeat ).To (Equal (DurationMinutes (30 * time .Minute )))
9086 Expect (conf .UrgentLow .Threshold .Value ).To (Equal (47.5 ))
9187 Expect (conf .UrgentLow .Threshold .Units ).To (Equal (glucose .MgdL ))
9288 Expect (conf .NotLooping .Enabled ).To (Equal (true ))
93- Expect (conf .NotLooping .Repeat ).To (Equal (DurationMinutes (32 * time .Minute )))
9489 Expect (conf .NotLooping .Delay ).To (Equal (DurationMinutes (4 * time .Minute )))
9590 Expect (conf .NoCommunication .Enabled ).To (Equal (true ))
96- Expect (conf .NoCommunication .Repeat ).To (Equal (DurationMinutes (33 * time .Minute )))
9791 Expect (conf .NoCommunication .Delay ).To (Equal (DurationMinutes (6 * time .Minute )))
9892 })
9993
@@ -322,32 +316,41 @@ var _ = Describe("Config", func() {
322316 })
323317
324318 Context ("repeat" , func () {
319+ var defaultAlert = LowAlert {
320+ Threshold : Threshold {Value : 11 , Units : glucose .MmolL },
321+ }
322+
325323 It ("accepts values of 0 (indicating disabled)" , func () {
326324 val := validator .New ()
327- b := Base {Repeat : 0 }
328- b .Validate (val )
325+ l := defaultAlert
326+ l .Repeat = 0
327+ l .Validate (val )
329328 Expect (val .Error ()).To (Succeed ())
330329 })
331330
332331 It ("accepts values of 15 minutes to 4 hours (inclusive)" , func () {
333332 val := validator .New ()
334- b := Base {Repeat : DurationMinutes (15 * time .Minute )}
335- b .Validate (val )
333+ l := defaultAlert
334+ l .Repeat = DurationMinutes (15 * time .Minute )
335+ l .Validate (val )
336336 Expect (val .Error ()).To (Succeed ())
337337
338338 val = validator .New ()
339- b = Base {Repeat : DurationMinutes (4 * time .Hour )}
340- b .Validate (val )
339+ l = defaultAlert
340+ l .Repeat = DurationMinutes (4 * time .Hour )
341+ l .Validate (val )
341342 Expect (val .Error ()).To (Succeed ())
342343
343344 val = validator .New ()
344- b = Base {Repeat : DurationMinutes (4 * time .Hour + 1 )}
345- b .Validate (val )
345+ l = defaultAlert
346+ l .Repeat = DurationMinutes (4 * time .Hour + 1 )
347+ l .Validate (val )
346348 Expect (val .Error ()).NotTo (Succeed ())
347349
348350 val = validator .New ()
349- b = Base {Repeat : DurationMinutes (15 * time .Minute - 1 )}
350- b .Validate (val )
351+ l = defaultAlert
352+ l .Repeat = DurationMinutes (15 * time .Minute - 1 )
353+ l .Validate (val )
351354 Expect (val .Error ()).NotTo (Succeed ())
352355 })
353356 })
@@ -359,67 +362,68 @@ var _ = Describe("Config", func() {
359362 err := request .DecodeObject (nil , buf , threshold )
360363 Expect (err ).To (MatchError ("json is malformed" ))
361364 })
362- It ("validates repeat minutes (negative)" , func () {
365+ })
366+
367+ Context ("low" , func () {
368+ It ("accepts a blank repeat" , func () {
363369 buf := buff (`{
364370 "userId": "%s",
365371 "followedUserId": "%s",
366372 "uploadId": "%s",
367- "urgentLow ": {
368- "enabled": false ,
369- "repeat ": -11 ,
373+ "low ": {
374+ "enabled": true ,
375+ "delay ": 10 ,
370376 "threshold": {
371- "units": "%s ",
372- "value": 47.5
377+ "units": "mg/dL ",
378+ "value": 80
373379 }
374380 }
375- }` , mockUserID1 , mockUserID2 , mockUploadID , glucose .MgdL )
376- cfg := & Config {}
377- err := request .DecodeObject (nil , buf , cfg )
378- Expect (err ).To (MatchError ("value -11m0s is not greater than or equal to 15m0s" ))
381+ }` , mockUserID1 , mockUserID2 , mockUploadID )
382+ conf := & Config {}
383+ err := request .DecodeObject (nil , buf , conf )
384+ Expect (err ).To (Succeed ())
385+ Expect (conf .Low .Repeat ).To (Equal (DurationMinutes (0 )))
379386 })
380- It ("validates repeat minutes (string)" , func () {
381- buf := buff (`{
387+ })
388+ It ("validates repeat minutes (negative)" , func () {
389+ buf := buff (`{
382390 "userId": "%s",
383391 "followedUserId": "%s",
384- "urgentLow": {
392+ "uploadId": "%s",
393+ "low": {
385394 "enabled": false,
386- "repeat": "a" ,
395+ "repeat": -11 ,
387396 "threshold": {
388397 "units": "%s",
389- "value": 1
398+ "value": 47.5
390399 }
391400 }
392- }` , mockUserID1 , mockUserID2 , glucose .MgdL )
393- cfg := & Config {}
394- err := request .DecodeObject (nil , buf , cfg )
395- Expect (err ).To (MatchError ("json is malformed" ))
396- })
401+ }` , mockUserID1 , mockUserID2 , mockUploadID , glucose .MgdL )
402+ cfg := & Config {}
403+ err := request .DecodeObject (nil , buf , cfg )
404+ Expect (err ).To (MatchError ("value -11m0s is not greater than or equal to 15m0s" ))
397405 })
398-
399- Context ("low" , func () {
400- It ("accepts a blank repeat" , func () {
401- buf := buff (`{
406+ It ("validates repeat minutes (string)" , func () {
407+ buf := buff (`{
402408 "userId": "%s",
403409 "followedUserId": "%s",
404410 "uploadId": "%s",
405411 "low": {
406- "enabled": true ,
407- "delay ": 10 ,
412+ "enabled": false ,
413+ "repeat ": "a" ,
408414 "threshold": {
409- "units": "mg/dL ",
410- "value": 80
415+ "units": "%s ",
416+ "value": 1
411417 }
412418 }
413- }` , mockUserID1 , mockUserID2 , mockUploadID )
414- conf := & Config {}
415- err := request .DecodeObject (nil , buf , conf )
416- Expect (err ).To (Succeed ())
417- Expect (conf .Low .Repeat ).To (Equal (DurationMinutes (0 )))
418- })
419+ }` , mockUserID1 , mockUserID2 , mockUploadID , glucose .MgdL )
420+ cfg := & Config {}
421+ err := request .DecodeObject (nil , buf , cfg )
422+ Expect (err ).To (MatchError ("json is malformed" ))
419423 })
420424})
421425
422- var _ = Describe ("Duration " , func () {
426+ var _ = Describe ("DurationMinutes " , func () {
423427 It ("parses 42" , func () {
424428 d := DurationMinutes (0 )
425429 err := d .UnmarshalJSON ([]byte (`42` ))
0 commit comments