grim/paytreon
Clone
Summary
Browse
Changes
Graph
Add all the v2 types
draft
2019-04-10, Gary Kramlich
8b3c6c709f2b
Add all the v2 types
package
paytreon
import
(
"reflect"
"strings"
"testing"
"github.com/google/jsonapi"
)
func
TestAddressUnmarshal
(
t
*
testing
.
T
)
{
data
:=
`{"data": {
"attributes": {
"addressee": "somebody",
"city": "somecity",
"country": "somecountry",
"line_1": "someline1",
"line_2": "someline2",
"phone_number": null,
"postal_code": "somepostalcode",
"state": "somestate"
},
"id": "someid",
"type": "address"
}}`
exp
:=
Address
{
ID
:
"someid"
,
Addressee
:
"somebody"
,
City
:
"somecity"
,
Country
:
"somecountry"
,
Line1
:
"someline1"
,
Line2
:
"someline2"
,
PhoneNumber
:
""
,
PostalCode
:
"somepostalcode"
,
State
:
"somestate"
,
}
var
address
Address
err
:=
jsonapi
.
UnmarshalPayload
(
strings
.
NewReader
(
data
),
&
address
)
if
err
!=
nil
{
t
.
Errorf
(
"unexpected error: %s"
,
err
)
}
if
!
reflect
.
DeepEqual
(
address
,
exp
)
{
t
.
Errorf
(
"value mismatch\n%#v\nis not equal to\n%#v"
,
address
,
exp
)
}
}
func
TestRewardUnmarshal
(
t
*
testing
.
T
)
{
data
:=
`{"data": {
"attributes": {
"amount": 100,
"amount_cents": 50,
"created_at": "2018-05-23T21:27:59.077755+00:00",
"deleted_at": null,
"edited_at": "2018-05-23T21:27:59.077755+00:00",
"description": "somedescription",
"image_url": "http://some.img",
"patron_count": 100,
"post_count": 50,
"published": true,
"published_at": "2018-05-23T21:27:59.077755+00:00",
"requires_shipping": true,
"title": "sometitle",
"unpublished_at": null,
"url": "http://some.reward"
},
"id": "someid",
"type": "reward"
}}`
expDate
:=
"2018-05-23T21:27:59.077755+00:00"
exp
:=
Reward
{
ID
:
"someid"
,
Amount
:
100
,
AmountCents
:
50
,
CreatedAt
:
expDate
,
EditedAt
:
expDate
,
Description
:
"somedescription"
,
ImageURL
:
"http://some.img"
,
PatronCount
:
100
,
PostCount
:
50
,
Published
:
true
,
PublishedAt
:
expDate
,
RequiresShipping
:
true
,
Title
:
"sometitle"
,
URL
:
"http://some.reward"
,
}
var
act
Reward
err
:=
jsonapi
.
UnmarshalPayload
(
strings
.
NewReader
(
data
),
&
act
)
if
err
!=
nil
{
t
.
Errorf
(
"unexpected error: %s"
,
err
)
}
if
!
reflect
.
DeepEqual
(
act
,
exp
)
{
t
.
Errorf
(
"value mismatch\n%#v\nis not equal to\n%#v"
,
act
,
exp
)
}
}
func
TestGoalUnmarshal
(
t
*
testing
.
T
)
{
data
:=
`{"data": {
"attributes": {
"amount": 100,
"amount_cents": 50,
"completed_percentage": 75,
"created_at": "2018-05-23T21:27:59.077755+00:00",
"reached_at": null,
"title": "sometitle",
"description": "somedescription"
},
"id": "someid",
"type": "goal"
}}`
expDate
:=
"2018-05-23T21:27:59.077755+00:00"
exp
:=
Goal
{
ID
:
"someid"
,
Amount
:
100
,
AmountCents
:
50
,
CompletedPercentage
:
75
,
CreatedAt
:
expDate
,
ReachedAt
:
""
,
Title
:
"sometitle"
,
Description
:
"somedescription"
,
}
var
act
Goal
err
:=
jsonapi
.
UnmarshalPayload
(
strings
.
NewReader
(
data
),
&
act
)
if
err
!=
nil
{
t
.
Errorf
(
"unexpected error: %s"
,
err
)
}
if
!
reflect
.
DeepEqual
(
act
,
exp
)
{
t
.
Errorf
(
"value mismatch\n%#v\nis not equal to\n%#v"
,
act
,
exp
)
}
}