@@ -41,7 +41,6 @@ var _ = Describe("Config", func() {
4141 },
4242 "urgentLow": {
4343 "enabled": false,
44- "repeat": 30,
4544 "threshold": {
4645 "units": "mg/dL",
4746 "value": 47.5
@@ -58,12 +57,10 @@ var _ = Describe("Config", func() {
5857 },
5958 "notLooping": {
6059 "enabled": true,
61- "repeat": 32,
6260 "delay": 4
6361 },
6462 "noCommunication": {
6563 "enabled": true,
66- "repeat": 33,
6764 "delay": 6
6865 }
6966}` , mockUserID1 , mockUserID2 )
@@ -83,14 +80,11 @@ var _ = Describe("Config", func() {
8380 Expect (conf .Low .Threshold .Value ).To (Equal (80.0 ))
8481 Expect (conf .Low .Threshold .Units ).To (Equal (glucose .MgdL ))
8582 Expect (conf .UrgentLow .Enabled ).To (Equal (false ))
86- Expect (conf .UrgentLow .Repeat ).To (Equal (DurationMinutes (30 * time .Minute )))
8783 Expect (conf .UrgentLow .Threshold .Value ).To (Equal (47.5 ))
8884 Expect (conf .UrgentLow .Threshold .Units ).To (Equal (glucose .MgdL ))
8985 Expect (conf .NotLooping .Enabled ).To (Equal (true ))
90- Expect (conf .NotLooping .Repeat ).To (Equal (DurationMinutes (32 * time .Minute )))
9186 Expect (conf .NotLooping .Delay ).To (Equal (DurationMinutes (4 * time .Minute )))
9287 Expect (conf .NoCommunication .Enabled ).To (Equal (true ))
93- Expect (conf .NoCommunication .Repeat ).To (Equal (DurationMinutes (33 * time .Minute )))
9488 Expect (conf .NoCommunication .Delay ).To (Equal (DurationMinutes (6 * time .Minute )))
9589 })
9690
@@ -285,32 +279,41 @@ var _ = Describe("Config", func() {
285279 })
286280
287281 Context ("repeat" , func () {
282+ var defaultAlert = LowAlert {
283+ Threshold : Threshold {Value : 11 , Units : glucose .MmolL },
284+ }
285+
288286 It ("accepts values of 0 (indicating disabled)" , func () {
289287 val := validator .New ()
290- b := Base {Repeat : 0 }
291- b .Validate (val )
288+ l := defaultAlert
289+ l .Repeat = 0
290+ l .Validate (val )
292291 Expect (val .Error ()).To (Succeed ())
293292 })
294293
295294 It ("accepts values of 15 minutes to 4 hours (inclusive)" , func () {
296295 val := validator .New ()
297- b := Base {Repeat : DurationMinutes (15 * time .Minute )}
298- b .Validate (val )
296+ l := defaultAlert
297+ l .Repeat = DurationMinutes (15 * time .Minute )
298+ l .Validate (val )
299299 Expect (val .Error ()).To (Succeed ())
300300
301301 val = validator .New ()
302- b = Base {Repeat : DurationMinutes (4 * time .Hour )}
303- b .Validate (val )
302+ l = defaultAlert
303+ l .Repeat = DurationMinutes (4 * time .Hour )
304+ l .Validate (val )
304305 Expect (val .Error ()).To (Succeed ())
305306
306307 val = validator .New ()
307- b = Base {Repeat : DurationMinutes (4 * time .Hour + 1 )}
308- b .Validate (val )
308+ l = defaultAlert
309+ l .Repeat = DurationMinutes (4 * time .Hour + 1 )
310+ l .Validate (val )
309311 Expect (val .Error ()).NotTo (Succeed ())
310312
311313 val = validator .New ()
312- b = Base {Repeat : DurationMinutes (15 * time .Minute - 1 )}
313- b .Validate (val )
314+ l = defaultAlert
315+ l .Repeat = DurationMinutes (15 * time .Minute - 1 )
316+ l .Validate (val )
314317 Expect (val .Error ()).NotTo (Succeed ())
315318 })
316319 })
@@ -322,65 +325,65 @@ var _ = Describe("Config", func() {
322325 err := request .DecodeObject (nil , buf , threshold )
323326 Expect (err ).To (MatchError ("json is malformed" ))
324327 })
325- It ("validates repeat minutes (negative)" , func () {
328+ })
329+
330+ Context ("low" , func () {
331+ It ("accepts a blank repeat" , func () {
326332 buf := buff (`{
327333 "userId": "%s",
328334 "followedUserId": "%s",
329- "urgentLow ": {
330- "enabled": false ,
331- "repeat ": -11 ,
335+ "low ": {
336+ "enabled": true ,
337+ "delay ": 10 ,
332338 "threshold": {
333- "units": "%s ",
334- "value": 47.5
339+ "units": "mg/dL ",
340+ "value": 80
335341 }
336342 }
337- }` , mockUserID1 , mockUserID2 , glucose .MgdL )
338- cfg := & Config {}
339- err := request .DecodeObject (nil , buf , cfg )
340- Expect (err ).To (MatchError ("value -11m0s is not greater than or equal to 15m0s" ))
343+ }` , mockUserID1 , mockUserID2 )
344+ conf := & Config {}
345+ err := request .DecodeObject (nil , buf , conf )
346+ Expect (err ).To (Succeed ())
347+ Expect (conf .Low .Repeat ).To (Equal (DurationMinutes (0 )))
341348 })
342- It ("validates repeat minutes (string)" , func () {
343- buf := buff (`{
349+ })
350+ It ("validates repeat minutes (negative)" , func () {
351+ buf := buff (`{
344352 "userId": "%s",
345353 "followedUserId": "%s",
346- "urgentLow ": {
354+ "low ": {
347355 "enabled": false,
348- "repeat": "a" ,
356+ "repeat": -11 ,
349357 "threshold": {
350358 "units": "%s",
351- "value": 1
359+ "value": 47.5
352360 }
353361 }
354362}` , mockUserID1 , mockUserID2 , glucose .MgdL )
355- cfg := & Config {}
356- err := request .DecodeObject (nil , buf , cfg )
357- Expect (err ).To (MatchError ("json is malformed" ))
358- })
363+ cfg := & Config {}
364+ err := request .DecodeObject (nil , buf , cfg )
365+ Expect (err ).To (MatchError ("value -11m0s is not greater than or equal to 15m0s" ))
359366 })
360-
361- Context ("low" , func () {
362- It ("accepts a blank repeat" , func () {
363- buf := buff (`{
367+ It ("validates repeat minutes (string)" , func () {
368+ buf := buff (`{
364369 "userId": "%s",
365370 "followedUserId": "%s",
366371 "low": {
367- "enabled": true ,
368- "delay ": 10 ,
372+ "enabled": false ,
373+ "repeat ": "a" ,
369374 "threshold": {
370- "units": "mg/dL ",
371- "value": 80
375+ "units": "%s ",
376+ "value": 1
372377 }
373378 }
374- }` , mockUserID1 , mockUserID2 )
375- conf := & Config {}
376- err := request .DecodeObject (nil , buf , conf )
377- Expect (err ).To (Succeed ())
378- Expect (conf .Low .Repeat ).To (Equal (DurationMinutes (0 )))
379- })
379+ }` , mockUserID1 , mockUserID2 , glucose .MgdL )
380+ cfg := & Config {}
381+ err := request .DecodeObject (nil , buf , cfg )
382+ Expect (err ).To (MatchError ("json is malformed" ))
380383 })
381384})
382385
383- var _ = Describe ("Duration " , func () {
386+ var _ = Describe ("DurationMinutes " , func () {
384387 It ("parses 42" , func () {
385388 d := DurationMinutes (0 )
386389 err := d .UnmarshalJSON ([]byte (`42` ))
0 commit comments