From 904fdf3de7d62be50ad26ba995f4f4e270eaa366 Mon Sep 17 00:00:00 2001 From: Victor Hugo Avelar Ossorio Date: Sat, 12 Oct 2024 12:09:05 +0000 Subject: [PATCH] fix(common_types): url encoding for Amount struct --- mollie/common_types.go | 4 ++-- mollie/common_types_test.go | 22 ++++++++++++++++++++++ 2 files changed, 24 insertions(+), 2 deletions(-) diff --git a/mollie/common_types.go b/mollie/common_types.go index 77e9956b..e395ab97 100644 --- a/mollie/common_types.go +++ b/mollie/common_types.go @@ -9,8 +9,8 @@ import ( // Amount represents a currency and value pair. type Amount struct { - Currency string `json:"currency,omitempty" url:"currency,omitempty"` - Value string `json:"value,omitempty" url:"value,omitempty"` + Currency string `json:"currency,omitempty" url:"amount[currency],omitempty"` + Value string `json:"value,omitempty" url:"amount[value],omitempty"` } // Address provides a human friendly representation of a geographical space. diff --git a/mollie/common_types_test.go b/mollie/common_types_test.go index ef15118f..1f5ebc5f 100644 --- a/mollie/common_types_test.go +++ b/mollie/common_types_test.go @@ -4,6 +4,7 @@ import ( "testing" "time" + "github.com/google/go-querystring/query" "github.com/stretchr/testify/assert" ) @@ -49,3 +50,24 @@ func TestShortDate_MarshalJSON(t *testing.T) { assert.Nil(t, err) }) } + +func TestURLQueryEncode(t *testing.T) { + cases := []struct { + name string + in any + expected string + }{ + { + "test amount encode", + &Amount{Currency: "EUR", Value: "10.00"}, + "amount%5Bcurrency%5D=EUR&amount%5Bvalue%5D=10.00", + }, + } + + for _, c := range cases { + t.Run(c.name, func(t *testing.T) { + v, _ := query.Values(c.in) + assert.Equal(t, c.expected, v.Encode()) + }) + } +}