Skip to content

Commit 43b65c2

Browse files
committed
Move test models to models_test.go
1 parent 6bdf239 commit 43b65c2

File tree

2 files changed

+26
-26
lines changed

2 files changed

+26
-26
lines changed

models_test.go

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -212,3 +212,27 @@ type CustomAttributeTypes struct {
212212
Float CustomFloatType `jsonapi:"attr,float"`
213213
String CustomStringType `jsonapi:"attr,string"`
214214
}
215+
216+
type Image struct {
217+
ID string `jsonapi:"primary,images"`
218+
Src string `jsonapi:"attr,src"`
219+
}
220+
221+
type Video struct {
222+
ID string `jsonapi:"primary,videos"`
223+
Captions string `jsonapi:"attr,captions"`
224+
}
225+
226+
type OneOfMedia struct {
227+
Image *Image
228+
random int
229+
Video *Video
230+
RandomStuff *string
231+
}
232+
233+
type BlogPostWithPoly struct {
234+
ID string `jsonapi:"primary,blogs"`
235+
Title string `jsonapi:"attr,title"`
236+
Hero *OneOfMedia `jsonapi:"polyrelation,hero-media,omitempty"`
237+
Media []*OneOfMedia `jsonapi:"polyrelation,media,omitempty"`
238+
}

request_test.go

Lines changed: 2 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -607,31 +607,7 @@ func TestUnmarshalRelationships(t *testing.T) {
607607
}
608608
}
609609

610-
type Image struct {
611-
ID int `jsonapi:"primary,images"`
612-
Src string `jsonapi:"attr,src"`
613-
}
614-
615-
type Video struct {
616-
ID int `jsonapi:"primary,videos"`
617-
Captions string `jsonapi:"attr,captions"`
618-
}
619-
620-
type OneOfMedia struct {
621-
Image *Image
622-
random int
623-
Video *Video
624-
RandomStuff *string
625-
}
626-
627610
func Test_UnmarshalPayload_polymorphicRelations(t *testing.T) {
628-
type pointerToOne struct {
629-
ID int `jsonapi:"primary,blogs"`
630-
Title string `jsonapi:"attr,title"`
631-
Hero *OneOfMedia `jsonapi:"polyrelation,hero-media,omitempty"`
632-
Media []*OneOfMedia `jsonapi:"polyrelation,media,omitempty"`
633-
}
634-
635611
in := bytes.NewReader([]byte(`{
636612
"data": {
637613
"type": "blogs",
@@ -684,7 +660,7 @@ func Test_UnmarshalPayload_polymorphicRelations(t *testing.T) {
684660
}
685661
]
686662
}`))
687-
out := new(pointerToOne)
663+
out := new(BlogPostWithPoly)
688664

689665
if err := UnmarshalPayload(in, out); err != nil {
690666
t.Fatal(err)
@@ -714,7 +690,7 @@ func Test_UnmarshalPayload_polymorphicRelations(t *testing.T) {
714690

715691
func Test_UnmarshalPayload_polymorphicRelations_no_choice(t *testing.T) {
716692
type pointerToOne struct {
717-
ID int `jsonapi:"primary,blogs"`
693+
ID string `jsonapi:"primary,blogs"`
718694
Title string `jsonapi:"attr,title"`
719695
Hero *OneOfMedia `jsonapi:"polyrelation,hero-media,omitempty"`
720696
}

0 commit comments

Comments
 (0)