Skip to content

Commit

Permalink
fix(common_types): url encoding for Amount struct
Browse files Browse the repository at this point in the history
  • Loading branch information
VictorAvelar committed Oct 12, 2024
1 parent a78acd0 commit 904fdf3
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 2 deletions.
4 changes: 2 additions & 2 deletions mollie/common_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
22 changes: 22 additions & 0 deletions mollie/common_types_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"testing"
"time"

"github.com/google/go-querystring/query"
"github.com/stretchr/testify/assert"
)

Expand Down Expand Up @@ -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())
})
}
}

0 comments on commit 904fdf3

Please sign in to comment.