Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Image comparison: use source url #129

Open
wants to merge 1 commit into
base: entities
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
114 changes: 114 additions & 0 deletions entity_diff_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand Down
28 changes: 28 additions & 0 deletions entity_healthcare_professional.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
}
22 changes: 22 additions & 0 deletions entity_location.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ package yext

import (
"encoding/json"
"log"
)

const ENTITYTYPE_LOCATION EntityType = "location"
Expand Down Expand Up @@ -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 {
Expand All @@ -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)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

mean to leave this in here?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, it follows the model of the other Equal implementations in yext-go

panic(r)
}
}()

if a.SourceUrl != nil {
a.Url = a.SourceUrl
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

mutating the source seems wacky - can we compare the source URL directly?

Copy link
Contributor Author

@cdworak cdworak May 20, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sure but i wanted to make sure it was only the source url and url that is different, i don't have a great way of doing that other than porting reflection here (the diff) or writing code to compare attribute to attribute, which if we add an attribute we'd have to remember to update this code too, so that seems dangerous

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm uncomfortable with the idea of the equal function modifying the receiver that it's called on? could we copy it instead and then call genericdiff on the copy?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sure!

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"`
Expand Down