Skip to content

Pass clientMode when creating a relationship marshaler #50

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

Merged
Merged
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
1 change: 1 addition & 0 deletions marshal.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ func (m *Marshaler) relationshipMarshaler(link *Link) *Marshaler {

rm.memberNameValidationMode = m.memberNameValidationMode
rm.link = link
rm.clientMode = m.clientMode
return rm
}

Expand Down
15 changes: 15 additions & 0 deletions marshal_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -650,6 +650,8 @@ func TestMarshalRelationships(t *testing.T) {
func TestMarshalClientMode(t *testing.T) {
t.Parallel()

articleNoIDRelatedComplexBody := `{"data":{"type":"articles","attributes":{"title":"Bazel 101"},"relationships":{"author":{"data":{"id":"1","type":"author"},"links":{"self":"http://example.com/articles//relationships/author","related":"http://example.com/articles//author"}},"comments":{"data":[{"type":"comments"},{"type":"comments"},{"type":"comments"}],"links":{"self":"http://example.com/articles//relationships/comments","related":"http://example.com/articles//comments"}}}}}`

tests := []struct {
description string
given any
Expand All @@ -660,6 +662,19 @@ func TestMarshalClientMode(t *testing.T) {
given: &Article{ID: "", Title: "A"},
expect: articleANoIDBody,
},
{
description: "empty primary field with relationships",
given: &ArticleRelated{
Title: "Bazel 101",
Author: &authorA,
Comments: []*Comment{
{Body: "Why is Bazel so slow on my computerr?", Archived: true, Author: &authorBWithMeta},
{Body: "Why is Bazel so slow on my computer?", Author: &authorBWithMeta},
{Body: "Just use an Apple M1", Author: &authorA},
},
},
expect: articleNoIDRelatedComplexBody,
},
}

for i, tc := range tests {
Expand Down