diff --git a/internal/entities/pagination.go b/internal/entities/pagination.go index bfa7b3bb8..d8d63ae04 100644 --- a/internal/entities/pagination.go +++ b/internal/entities/pagination.go @@ -2,8 +2,8 @@ package entities type PaginationLinks struct { Self string `json:"self"` - Prev string `json:"next"` - Next string `json:"prev"` + Prev string `json:"prev"` + Next string `json:"next"` } type Pagination struct { diff --git a/internal/entities/pagination_test.go b/internal/entities/pagination_test.go new file mode 100644 index 000000000..c1a263ee8 --- /dev/null +++ b/internal/entities/pagination_test.go @@ -0,0 +1,34 @@ +package entities + +import ( + "encoding/json" + "testing" +) + +func TestPaginationLinks_JSONTagsMatchFieldNames(t *testing.T) { + links := PaginationLinks{ + Self: "self-url", + Prev: "prev-url", + Next: "next-url", + } + + raw, err := json.Marshal(links) + if err != nil { + t.Fatalf("marshal: %v", err) + } + + var decoded map[string]string + if err := json.Unmarshal(raw, &decoded); err != nil { + t.Fatalf("unmarshal: %v", err) + } + + if got := decoded["prev"]; got != "prev-url" { + t.Errorf(`json key "prev" = %q, want "prev-url"`, got) + } + if got := decoded["next"]; got != "next-url" { + t.Errorf(`json key "next" = %q, want "next-url"`, got) + } + if got := decoded["self"]; got != "self-url" { + t.Errorf(`json key "self" = %q, want "self-url"`, got) + } +}