From 4dee9487e2448d224477d1bdd44d28bf0039754f Mon Sep 17 00:00:00 2001 From: Darin Krauss Date: Tue, 13 Nov 2018 15:12:32 -0800 Subject: [PATCH] Fix Dexcom API v2 edge cases --- CHANGELOG.md | 1 + data/types/insulin/formulation_test.go | 16 ++++++++-------- data/types/insulin/simple.go | 3 --- data/types/insulin/simple_test.go | 5 ++--- dexcom/fetch/translate.go | 2 +- 5 files changed, 12 insertions(+), 15 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index a046cc16b..4191afbb0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,7 @@ ## v1.30.0 +* Fix Dexcom API v2 edge cases * Handle unexpected data from Dexcom API v2 * Update to Dexcom API v2 * Capture cgm settings for changed Dexcom API devices diff --git a/data/types/insulin/formulation_test.go b/data/types/insulin/formulation_test.go index 4d7cdf033..565d11822 100644 --- a/data/types/insulin/formulation_test.go +++ b/data/types/insulin/formulation_test.go @@ -64,9 +64,9 @@ var _ = Describe("Formulation", func() { func(datum *insulin.Formulation) { datum.Compounds = nil datum.Simple = testDataTypesInsulin.NewSimple() - datum.Simple.Concentration = nil + datum.Simple.ActingType = nil }, - testErrors.WithPointerSource(structureValidator.ErrorValueNotExists(), "/simple/concentration"), + testErrors.WithPointerSource(structureValidator.ErrorValueNotExists(), "/simple/actingType"), ), Entry("compounds missing; simple valid", func(datum *insulin.Formulation) { @@ -87,10 +87,10 @@ var _ = Describe("Formulation", func() { datum.Compounds = insulin.NewCompoundArray() *datum.Compounds = append(*datum.Compounds, nil) datum.Simple = testDataTypesInsulin.NewSimple() - datum.Simple.Concentration = nil + datum.Simple.ActingType = nil }, testErrors.WithPointerSource(structureValidator.ErrorValueExists(), "/compounds"), - testErrors.WithPointerSource(structureValidator.ErrorValueNotExists(), "/simple/concentration"), + testErrors.WithPointerSource(structureValidator.ErrorValueNotExists(), "/simple/actingType"), ), Entry("compounds invalid; simple valid", func(datum *insulin.Formulation) { @@ -110,10 +110,10 @@ var _ = Describe("Formulation", func() { func(datum *insulin.Formulation) { datum.Compounds = testDataTypesInsulin.NewCompoundArray(3) datum.Simple = testDataTypesInsulin.NewSimple() - datum.Simple.Concentration = nil + datum.Simple.ActingType = nil }, testErrors.WithPointerSource(structureValidator.ErrorValueExists(), "/compounds"), - testErrors.WithPointerSource(structureValidator.ErrorValueNotExists(), "/simple/concentration"), + testErrors.WithPointerSource(structureValidator.ErrorValueNotExists(), "/simple/actingType"), ), Entry("compounds valid; simple valid", func(datum *insulin.Formulation) { @@ -141,11 +141,11 @@ var _ = Describe("Formulation", func() { datum.Compounds = testDataTypesInsulin.NewCompoundArray(3) datum.Name = pointer.FromString("") datum.Simple = testDataTypesInsulin.NewSimple() - datum.Simple.Concentration = nil + datum.Simple.ActingType = nil }, testErrors.WithPointerSource(structureValidator.ErrorValueExists(), "/compounds"), testErrors.WithPointerSource(structureValidator.ErrorValueEmpty(), "/name"), - testErrors.WithPointerSource(structureValidator.ErrorValueNotExists(), "/simple/concentration"), + testErrors.WithPointerSource(structureValidator.ErrorValueNotExists(), "/simple/actingType"), ), ) }) diff --git a/data/types/insulin/simple.go b/data/types/insulin/simple.go index 569faf19a..898859337 100644 --- a/data/types/insulin/simple.go +++ b/data/types/insulin/simple.go @@ -3,7 +3,6 @@ package insulin import ( "github.com/tidepool-org/platform/data" "github.com/tidepool-org/platform/structure" - structureValidator "github.com/tidepool-org/platform/structure/validator" ) const ( @@ -54,8 +53,6 @@ func (s *Simple) Validate(validator structure.Validator) { validator.String("brand", s.Brand).NotEmpty().LengthLessThanOrEqualTo(SimpleBrandLengthMaximum) if s.Concentration != nil { s.Concentration.Validate(validator.WithReference("concentration")) - } else { - validator.WithReference("concentration").ReportError(structureValidator.ErrorValueNotExists()) } } diff --git a/data/types/insulin/simple_test.go b/data/types/insulin/simple_test.go index 1120bdf0e..ffce74e05 100644 --- a/data/types/insulin/simple_test.go +++ b/data/types/insulin/simple_test.go @@ -102,7 +102,6 @@ var _ = Describe("Simple", func() { ), Entry("concentration missing", func(datum *insulin.Simple) { datum.Concentration = nil }, - testErrors.WithPointerSource(structureValidator.ErrorValueNotExists(), "/concentration"), ), Entry("concentration invalid", func(datum *insulin.Simple) { datum.Concentration.Units = nil }, @@ -115,11 +114,11 @@ var _ = Describe("Simple", func() { func(datum *insulin.Simple) { datum.ActingType = nil datum.Brand = pointer.FromString("") - datum.Concentration = nil + datum.Concentration.Units = nil }, testErrors.WithPointerSource(structureValidator.ErrorValueNotExists(), "/actingType"), testErrors.WithPointerSource(structureValidator.ErrorValueEmpty(), "/brand"), - testErrors.WithPointerSource(structureValidator.ErrorValueNotExists(), "/concentration"), + testErrors.WithPointerSource(structureValidator.ErrorValueNotExists(), "/concentration/units"), ), ) }) diff --git a/dexcom/fetch/translate.go b/dexcom/fetch/translate.go index 67e1d5c08..739e93dd1 100644 --- a/dexcom/fetch/translate.go +++ b/dexcom/fetch/translate.go @@ -204,7 +204,7 @@ func translateAlertScheduleSettingsDaysOfWeekToScheduledAlertDays(daysOfWeek *[] if daysOfWeek == nil { return nil } - var days []string + days := []string{} for _, dayOfWeek := range *daysOfWeek { days = append(days, translateAlertScheduleSettingsDayOfWeekToScheduledAlertDay(dayOfWeek)) }