From 12a2dd7858a5f28e562df6d3bf3e10ca5e903964 Mon Sep 17 00:00:00 2001 From: cdworak Date: Mon, 20 May 2019 11:42:13 -0400 Subject: [PATCH] Image comparison: use source url --- entity_diff_test.go | 114 ++++++++++++++++++++++++++++++ entity_healthcare_professional.go | 28 ++++++++ entity_location.go | 22 ++++++ 3 files changed, 164 insertions(+) diff --git a/entity_diff_test.go b/entity_diff_test.go index b74e4bd..33049b2 100644 --- a/entity_diff_test.go +++ b/entity_diff_test.go @@ -2059,6 +2059,120 @@ func TestEntityDiffComplex(t *testing.T) { }, isDiff: false, }, + { + name: "Photo", + base: &CustomLocationEntity{ + CustomEntity: CustomEntity{ + CFPhoto: NullablePhoto(&Photo{ + Image: &Image{ + Url: String("https://s3.amazonaws.com/devk-photos/photos/18123037_retina.jpg"), + }, + }), + }, + }, + new: &CustomLocationEntity{ + CustomEntity: CustomEntity{ + CFPhoto: NullablePhoto(&Photo{ + Image: &Image{ + Url: String("https://s3.amazonaws.com/devk-photos/photos/18123037_retina.jpg"), + }, + }), + }, + }, + isDiff: false, + }, + { + name: "Photo with Base from Yext API", + base: &CustomLocationEntity{ + CustomEntity: CustomEntity{ + CFPhoto: NullablePhoto(&Photo{ + Image: &Image{ + Url: String("http://a.mktgcdn.com/p/AVreuCLGkLDSRJpj1RgHhrPF7LPaC3iDAjz6WWXMxwk/206x309.jpg"), + SourceUrl: String("https://s3.amazonaws.com/devk-photos/photos/18123037_retina.jpg"), + }, + }), + }, + }, + new: &CustomLocationEntity{ + CustomEntity: CustomEntity{ + CFPhoto: NullablePhoto(&Photo{ + Image: &Image{ + Url: String("https://s3.amazonaws.com/devk-photos/photos/18123037_retina.jpg"), + }, + }), + }, + }, + isDiff: false, + }, + { + name: "Photo with Base from Yext API", + base: &CustomLocationEntity{ + CustomEntity: CustomEntity{ + CFPhoto: NullablePhoto(&Photo{ + Image: &Image{ + Url: String("http://a.mktgcdn.com/p/AVreuCLGkLDSRJpj1RgHhrPF7LPaC3iDAjz6WWXMxwk/206x309.jpg"), + SourceUrl: String("https://not-the-same.jpg"), + }, + }), + }, + }, + new: &CustomLocationEntity{ + CustomEntity: CustomEntity{ + CFPhoto: NullablePhoto(&Photo{ + Image: &Image{ + Url: String("https://s3.amazonaws.com/devk-photos/photos/18123037_retina.jpg"), + }, + }), + }, + }, + isDiff: true, + delta: &CustomLocationEntity{ + CustomEntity: CustomEntity{ + CFPhoto: NullablePhoto(&Photo{ + Image: &Image{ + Url: String("https://s3.amazonaws.com/devk-photos/photos/18123037_retina.jpg"), + }, + }), + }, + }, + }, + // Ideally, the below test would just return the Alternate Text in the delta, and not the Url + // But ensuring that happens would require a much larger code change + { + name: "Photo with Base from Yext API", + base: &CustomLocationEntity{ + CustomEntity: CustomEntity{ + CFPhoto: NullablePhoto(&Photo{ + Image: &Image{ + Url: String("http://a.mktgcdn.com/p/AVreuCLGkLDSRJpj1RgHhrPF7LPaC3iDAjz6WWXMxwk/206x309.jpg"), + SourceUrl: String("https://s3.amazonaws.com/devk-photos/photos/18123037_retina.jpg"), + AlternateText: String("Old Alternate Text"), + }, + }), + }, + }, + new: &CustomLocationEntity{ + CustomEntity: CustomEntity{ + CFPhoto: NullablePhoto(&Photo{ + Image: &Image{ + Url: String("https://s3.amazonaws.com/devk-photos/photos/18123037_retina.jpg"), + AlternateText: String("New Alternate Text"), + }, + }), + }, + }, + isDiff: true, + delta: &CustomLocationEntity{ + CustomEntity: CustomEntity{ + CFPhoto: NullablePhoto(&Photo{ + Image: &Image{ + Url: String("https://s3.amazonaws.com/devk-photos/photos/18123037_retina.jpg"), + AlternateText: String("New Alternate Text"), + }, + }), + }, + }, + }, { name: "MultiLine", base: &CustomLocationEntity{ diff --git a/entity_healthcare_professional.go b/entity_healthcare_professional.go index e8064eb..29a355c 100644 --- a/entity_healthcare_professional.go +++ b/entity_healthcare_professional.go @@ -174,6 +174,13 @@ func (y HealthcareProfessionalEntity) GetId() string { return "" } +func (y HealthcareProfessionalEntity) GetCategoryIds() (v []string) { + if y.CategoryIds != nil { + v = *y.CategoryIds + } + return v +} + func (y HealthcareProfessionalEntity) GetName() string { if y.Name != nil { return GetString(y.Name) @@ -516,6 +523,27 @@ func (y HealthcareProfessionalEntity) GetNPI() string { return "" } +func (y HealthcareProfessionalEntity) GetAdmittingHospitals() (v []string) { + if y.AdmittingHospitals != nil { + v = *y.AdmittingHospitals + } + return v +} + +func (y HealthcareProfessionalEntity) GetConditionsTreated() (v []string) { + if y.ConditionsTreated != nil { + v = *y.ConditionsTreated + } + return v +} + +func (y HealthcareProfessionalEntity) GetInsuranceAccepted() (v []string) { + if y.InsuranceAccepted != nil { + v = *y.InsuranceAccepted + } + return v +} + func (y HealthcareProfessionalEntity) IsClosed() bool { return GetNullableBool(y.Closed) } diff --git a/entity_location.go b/entity_location.go index a21e136..a98b4fc 100644 --- a/entity_location.go +++ b/entity_location.go @@ -7,6 +7,7 @@ package yext import ( "encoding/json" + "log" ) const ENTITYTYPE_LOCATION EntityType = "location" @@ -208,6 +209,7 @@ type Photo struct { type Image struct { Url *string `json:"url,omitempty"` AlternateText *string `json:"alternateText,omitempty"` + SourceUrl *string `json:"sourceUrl,omitempty"` } func NullableImage(i *Image) **Image { @@ -226,6 +228,26 @@ func NullImage() **Image { return &i } +// If source URL is filled in, Image came from Yext API and source URL should be +// used for comparison as URL is the mktg cdn generated URL +func (a *Image) Equal(b Comparable) bool { + defer func() { + if r := recover(); r != nil { + log.Printf("Value of A: %+v, Value of B:%+v, Type Of A: %T, Type Of B: %T\n", a, b, a, b) + panic(r) + } + }() + + if a.SourceUrl != nil { + a.Url = a.SourceUrl + a.SourceUrl = nil + _, isDiff := GenericDiff(a, b, false, false) + return !isDiff + } + _, isDiff := GenericDiff(a, b, false, false) + return !isDiff +} + type Address struct { Line1 *string `json:"line1,omitempty"` Line2 *string `json:"line2,omitempty"`