Skip to content

Commit 6adcc4c

Browse files
authored
Add test (#445)
1 parent b694d6b commit 6adcc4c

File tree

1 file changed

+34
-0
lines changed

1 file changed

+34
-0
lines changed

tests/model_payment_request_test.go

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package tests
22

33
import (
44
"encoding/json"
5+
"github.com/adyen/adyen-go-api-library/v21/src/common"
56
"testing"
67

78
"github.com/adyen/adyen-go-api-library/v21/src/checkout"
@@ -162,4 +163,37 @@ func TestPaymentRequest_UnmarshalJSON(t *testing.T) {
162163
err := json.Unmarshal([]byte(inputJson), &pm)
163164
require.ErrorContains(t, err, "data failed to match schemas in oneOf(CheckoutPaymentMethod)")
164165
})
166+
167+
// test serialization (Marshal)
168+
t.Run("Sessions", func(t *testing.T) {
169+
expected := `{"amount":{"currency":"EUR","value":1250},"channel":"Web","countryCode":"NL","merchantAccount":"merchantAccount","reference":"123456781235","returnUrl":"http://localhost:3000/redirect"}`
170+
171+
body := checkout.CreateCheckoutSessionRequest{
172+
Reference: "123456781235",
173+
Amount: checkout.Amount{
174+
Value: 1250,
175+
Currency: "EUR",
176+
},
177+
CountryCode: common.PtrString("NL"),
178+
MerchantAccount: "merchantAccount",
179+
Channel: common.PtrString("Web"),
180+
ReturnUrl: "http://localhost:3000/redirect",
181+
}
182+
183+
data, err := json.Marshal(body)
184+
require.NoError(t, err)
185+
186+
// Unmarshal expected JSON into map
187+
var expectedMap map[string]interface{}
188+
err = json.Unmarshal([]byte(expected), &expectedMap)
189+
require.NoError(t, err)
190+
191+
// Unmarshal actual JSON into map
192+
var actualMap map[string]interface{}
193+
err = json.Unmarshal(data, &actualMap)
194+
require.NoError(t, err)
195+
196+
// Compare maps
197+
assert.Equal(t, expectedMap, actualMap)
198+
})
165199
}

0 commit comments

Comments
 (0)