Skip to content
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

Fix Amount struct for correct url query encoding. #412

Closed
Closed
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
10 changes: 9 additions & 1 deletion .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,15 @@
"editor.fontFamily": "'Fira Code', Menlo, Monaco, 'Courier New', monospace",
"editor.fontLigatures": true,
"files.insertFinalNewline": true,
"files.trimFinalNewlines": true
"files.trimFinalNewlines": true,
"cSpell.ignorePaths": [
".devcontainer/*",
"mollie/*_test.go",
"testdata/*",
".git/objects",
".vscode",
".github"
]
}
}
},
Expand Down
21 changes: 10 additions & 11 deletions .github/workflows/documentation-links.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,13 @@ jobs:
id: lychee
uses: lycheeverse/lychee-action@7da8ec1fc4e01b5a12062ac6c589c10a4ce70d67

- name: Create Issue From File
if: env.lychee_exit_code != 0
uses: peter-evans/create-issue-from-file@e8ef132d6df98ed982188e460ebb3b5d4ef3a9cd
with:
title: Link Checker Report
content-filepath: ./lychee/out.md
labels: |
report
automated-issue
help-wanted
assignees: VictorAvelar
# - name: Create Issue From File
# if: ${{ env.lychee_exit_code != 0 }}
# uses: peter-evans/create-issue-from-file@e8ef132d6df98ed982188e460ebb3b5d4ef3a9cd
# with:
# title: Link Checker Report
# content-filepath: ./lychee/out.md
# labels: |
# report
# automated-issue
# assignees: VictorAvelar
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())
})
}
}
24 changes: 0 additions & 24 deletions mollie/custom_types_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,30 +73,6 @@ func TestContextValues_UnmarshalJSON(t *testing.T) {
}
}

func TestAmount_URLEncodingSimple(t *testing.T) {
tests := []struct {
name string
a Amount
want string
}{
{
name: "Test URL encoding simple.",
a: Amount{
Value: "10.00",
Currency: "EUR",
},
want: "currency=EUR&value=10.00",
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
v, err := query.Values(tt.a)
assert.Nil(t, err)
assert.Equal(t, tt.want, v.Encode())
})
}
}

func TestAmount_URLEncodingNested(t *testing.T) {
tests := []struct {
name string
Expand Down
Loading