Skip to content

Commit

Permalink
resolve comments
Browse files Browse the repository at this point in the history
  • Loading branch information
AlBaraa-mohamed committed Jan 5, 2024
1 parent 656ddf4 commit bfeff43
Show file tree
Hide file tree
Showing 4 changed files with 76 additions and 74 deletions.
6 changes: 3 additions & 3 deletions order_risk.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,9 @@ type OrderRiskListOptions struct {

// OrderRisk represents a Shopify order risk
type OrderRisk struct {
ID int64 `json:"id,omitempty"`
CheckoutID int64 `json:"checkout_id,omitempty"`
OrderID int64 `json:"order_id,omitempty"`
Id int64 `json:"id,omitempty"`
CheckoutId int64 `json:"checkout_id,omitempty"`
OrderId int64 `json:"order_id,omitempty"`
CauseCancel bool `json:"cause_cancel,omitempty"`
Display bool `json:"display,omitempty"`
MerchantMessage string `json:"merchant_message,omitempty"`
Expand Down
57 changes: 29 additions & 28 deletions order_risk_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,12 @@ package goshopify
import (
"errors"
"fmt"
"github.com/jarcoal/httpmock"
"net/http"
"reflect"
"runtime"
"testing"

"github.com/jarcoal/httpmock"
)

func TestOrderRiskListError(t *testing.T) {
Expand Down Expand Up @@ -52,7 +53,7 @@ func TestOrderRiskListWithPagination(t *testing.T) {
{
`{"risks": [{"id":1},{"id":2}]}`,
"",
[]OrderRisk{{ID: 1}, {ID: 2}},
[]OrderRisk{{Id: 1}, {Id: 2}},
new(Pagination),
nil,
},
Expand Down Expand Up @@ -96,7 +97,7 @@ func TestOrderRiskListWithPagination(t *testing.T) {
{
`{"risks": [{"id":1}]}`,
`<http://valid.url?page_info=foo&limit=2>; rel="next"`,
[]OrderRisk{{ID: 1}},
[]OrderRisk{{Id: 1}},
&Pagination{
NextPageOptions: &ListOptions{PageInfo: "foo", Limit: 2},
},
Expand All @@ -105,7 +106,7 @@ func TestOrderRiskListWithPagination(t *testing.T) {
{
`{"risks": [{"id":2}]}`,
`<http://valid.url?page_info=foo>; rel="next", <http://valid.url?page_info=bar>; rel="previous"`,
[]OrderRisk{{ID: 2}},
[]OrderRisk{{Id: 2}},
&Pagination{
NextPageOptions: &ListOptions{PageInfo: "foo"},
PreviousPageOptions: &ListOptions{PageInfo: "bar"},
Expand Down Expand Up @@ -163,9 +164,9 @@ func TestOrderRiskList(t *testing.T) {

expected := []OrderRisk{
{
ID: 284138680,
CheckoutID: 0,
OrderID: 450789469,
Id: 284138680,
CheckoutId: 0,
OrderId: 450789469,
CauseCancel: true,
Display: true,
MerchantMessage: "This order was placed from a proxy IP",
Expand All @@ -175,9 +176,9 @@ func TestOrderRiskList(t *testing.T) {
Recommendation: OrderRecommendationCancel,
},
{
ID: 1029151489,
CheckoutID: 901414060,
OrderID: 450789469,
Id: 1029151489,
CheckoutId: 901414060,
OrderId: 450789469,
CauseCancel: true,
Display: true,
MerchantMessage: "This order came from an anonymous proxy",
Expand Down Expand Up @@ -221,9 +222,9 @@ func TestOrderRiskListOptions(t *testing.T) {
}
expected := []OrderRisk{
{
ID: 284138680,
CheckoutID: 0,
OrderID: 450789469,
Id: 284138680,
CheckoutId: 0,
OrderId: 450789469,
CauseCancel: true,
Display: true,
MerchantMessage: "This order was placed from a proxy IP",
Expand All @@ -233,9 +234,9 @@ func TestOrderRiskListOptions(t *testing.T) {
Recommendation: OrderRecommendationCancel,
},
{
ID: 1029151489,
CheckoutID: 901414060,
OrderID: 450789469,
Id: 1029151489,
CheckoutId: 901414060,
OrderId: 450789469,
CauseCancel: true,
Display: true,
MerchantMessage: "This order came from an anonymous proxy",
Expand Down Expand Up @@ -263,9 +264,9 @@ func TestOrderRiskGet(t *testing.T) {
t.Errorf("OrderRisk.List returned error: %v", err)
}
expected := &OrderRisk{
ID: 284138680,
CheckoutID: 0,
OrderID: 450789469,
Id: 284138680,
CheckoutId: 0,
OrderId: 450789469,
CauseCancel: true,
Display: true,
MerchantMessage: "This order was placed from a proxy IP",
Expand All @@ -287,17 +288,17 @@ func TestOrderRiskCreate(t *testing.T) {
httpmock.NewStringResponder(201, `{"risk":{"id": 1}}`))

orderRisk := OrderRisk{
ID: 1,
Id: 1,
}

o, err := client.OrderRisk.Create(450789469, orderRisk)
if err != nil {
t.Errorf("OrderRisk.Create returned error: %v", err)
}

expected := Order{ID: 1}
if o.ID != expected.ID {
t.Errorf("OrderRisk.Create returned id %d, expected %d", o.ID, expected.ID)
expected := OrderRisk{Id: 1}
if o.Id != expected.Id {
t.Errorf("OrderRisk.Create returned id %d, expected %d", o.Id, expected.Id)
}
}

Expand All @@ -309,8 +310,8 @@ func TestOrderRiskUpdate(t *testing.T) {
httpmock.NewStringResponder(201, `{"risk":{"id": 1,"order_id": 2}}`))

orderRisk := OrderRisk{
ID: 1,
OrderID: 2,
Id: 1,
OrderId: 2,
Recommendation: OrderRecommendationAccept,
}

Expand All @@ -319,9 +320,9 @@ func TestOrderRiskUpdate(t *testing.T) {
t.Errorf("Order.Update returned error: %v", err)
}

expected := OrderRisk{ID: 1, OrderID: 2, Recommendation: OrderRecommendationAccept}
if o.ID != expected.ID && o.OrderID != expected.OrderID && o.Recommendation == expected.Recommendation {
t.Errorf("Order.Update returned id %d, expected %d, expected %d", o.ID, expected.ID, expected.OrderID)
expected := OrderRisk{Id: 1, OrderId: 2, Recommendation: OrderRecommendationAccept}
if o.Id != expected.Id && o.OrderId != expected.OrderId && o.Recommendation == expected.Recommendation {
t.Errorf("Order.Update returned id %d, expected %d, expected %d", o.Id, expected.Id, expected.OrderId)
}
}

Expand Down
10 changes: 5 additions & 5 deletions payments_transactions.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,19 +37,19 @@ type PaymentsTransactionsListOptions struct {

// PaymentsTransactions represents a Shopify Transactions
type PaymentsTransactions struct {
ID int64 `json:"id,omitempty"`
Id int64 `json:"id,omitempty"`
Type PaymentsTransactionsTypes `json:"type,omitempty"`
Test bool `json:"test,omitempty"`
PayoutID int `json:"payout_id,omitempty"`
PayoutId int `json:"payout_id,omitempty"`
PayoutStatus PayoutStatus `json:"payout_status,omitempty"`
Currency string `json:"currency,omitempty"`
Amount string `json:"amount,omitempty"`
Fee string `json:"fee,omitempty"`
Net string `json:"net,omitempty"`
SourceID int `json:"source_id,omitempty"`
SourceId int `json:"source_id,omitempty"`
SourceType string `json:"source_type,omitempty"`
SourceOrderTransactionID int `json:"source_order_transaction_id,omitempty"`
SourceOrderID int `json:"source_order_id,omitempty"`
SourceOrderTransactionId int `json:"source_order_transaction_id,omitempty"`
SourceOrderId int `json:"source_order_id,omitempty"`
ProcessedAt OnlyDate `json:"processed_at,omitempty"`
}

Expand Down
77 changes: 39 additions & 38 deletions payments_transactions_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,12 @@ package goshopify
import (
"errors"
"fmt"
"github.com/jarcoal/httpmock"
"net/http"
"reflect"
"testing"
"time"

"github.com/jarcoal/httpmock"
)

func TestPaymentsTransactionsList(t *testing.T) {
Expand All @@ -24,51 +25,51 @@ func TestPaymentsTransactionsList(t *testing.T) {

expected := []PaymentsTransactions{
{
ID: 699519475,
Id: 699519475,
Type: PaymentsTransactionsDebit,
Test: false,
PayoutID: 623721858,
PayoutId: 623721858,
PayoutStatus: PayoutStatusPaid,
Currency: "USD",
Amount: "-50.00",
Fee: "0.00",
Net: "-50.00",
SourceID: 460709370,
SourceId: 460709370,
SourceType: "adjustment",
SourceOrderID: 0,
SourceOrderTransactionID: 0,
SourceOrderId: 0,
SourceOrderTransactionId: 0,
ProcessedAt: date1,
},
{
ID: 77412310,
Id: 77412310,
Type: PaymentsTransactionsCredit,
Test: false,
PayoutID: 623721858,
PayoutId: 623721858,
PayoutStatus: PayoutStatusPaid,
Currency: "USD",
Amount: "50.00",
Fee: "0.00",
Net: "50.00",
SourceID: 374511569,
SourceId: 374511569,
SourceType: "Payments::Balance::AdjustmentReversal",
SourceOrderID: 0,
SourceOrderTransactionID: 0,
SourceOrderId: 0,
SourceOrderTransactionId: 0,
ProcessedAt: date1,
},
{
ID: 1006917261,
Id: 1006917261,
Type: PaymentsTransactionsRefund,
Test: false,
PayoutID: 623721858,
PayoutId: 623721858,
PayoutStatus: PayoutStatusPaid,
Currency: "USD",
Amount: "-3.45",
Fee: "0.00",
Net: "-3.45",
SourceID: 1006917261,
SourceId: 1006917261,
SourceType: "Payments::Refund",
SourceOrderID: 217130470,
SourceOrderTransactionID: 1006917261,
SourceOrderId: 217130470,
SourceOrderTransactionId: 1006917261,
ProcessedAt: date1,
},
}
Expand Down Expand Up @@ -130,51 +131,51 @@ func TestPaymentsTransactionsListWithPagination(t *testing.T) {
"",
[]PaymentsTransactions{
{
ID: 699519475,
Id: 699519475,
Type: PaymentsTransactionsDebit,
Test: false,
PayoutID: 623721858,
PayoutId: 623721858,
PayoutStatus: PayoutStatusPaid,
Currency: "USD",
Amount: "-50.00",
Fee: "0.00",
Net: "-50.00",
SourceID: 460709370,
SourceId: 460709370,
SourceType: "adjustment",
SourceOrderID: 0,
SourceOrderTransactionID: 0,
SourceOrderId: 0,
SourceOrderTransactionId: 0,
ProcessedAt: date1,
},
{
ID: 77412310,
Id: 77412310,
Type: PaymentsTransactionsCredit,
Test: false,
PayoutID: 623721858,
PayoutId: 623721858,
PayoutStatus: PayoutStatusPaid,
Currency: "USD",
Amount: "50.00",
Fee: "0.00",
Net: "50.00",
SourceID: 374511569,
SourceId: 374511569,
SourceType: "Payments::Balance::AdjustmentReversal",
SourceOrderID: 0,
SourceOrderTransactionID: 0,
SourceOrderId: 0,
SourceOrderTransactionId: 0,
ProcessedAt: date1,
},
{
ID: 1006917261,
Id: 1006917261,
Type: PaymentsTransactionsRefund,
Test: false,
PayoutID: 623721858,
PayoutId: 623721858,
PayoutStatus: PayoutStatusPaid,
Currency: "USD",
Amount: "-3.45",
Fee: "0.00",
Net: "-3.45",
SourceID: 1006917261,
SourceId: 1006917261,
SourceType: "Payments::Refund",
SourceOrderID: 217130470,
SourceOrderTransactionID: 1006917261,
SourceOrderId: 217130470,
SourceOrderTransactionId: 1006917261,
ProcessedAt: date1,
},
},
Expand Down Expand Up @@ -221,7 +222,7 @@ func TestPaymentsTransactionsListWithPagination(t *testing.T) {
{
`{"transactions": [{"id":1}]}`,
`<http://valid.url?page_info=foo&limit=2>; rel="next"`,
[]PaymentsTransactions{{ID: 1}},
[]PaymentsTransactions{{Id: 1}},
&Pagination{
NextPageOptions: &ListOptions{PageInfo: "foo", Limit: 2},
},
Expand All @@ -230,7 +231,7 @@ func TestPaymentsTransactionsListWithPagination(t *testing.T) {
{
`{"transactions": [{"id":2}]}`,
`<http://valid.url?page_info=foo>; rel="next", <http://valid.url?page_info=bar>; rel="previous"`,
[]PaymentsTransactions{{ID: 2}},
[]PaymentsTransactions{{Id: 2}},
&Pagination{
NextPageOptions: &ListOptions{PageInfo: "foo"},
PreviousPageOptions: &ListOptions{PageInfo: "bar"},
Expand Down Expand Up @@ -288,19 +289,19 @@ func TestPaymentsTransactionsGet(t *testing.T) {
date1 := OnlyDate{time.Date(2013, 11, 01, 0, 0, 0, 0, time.UTC)}

expected := &PaymentsTransactions{
ID: 699519475,
Id: 699519475,
Type: PaymentsTransactionsDebit,
Test: false,
PayoutID: 623721858,
PayoutId: 623721858,
PayoutStatus: PayoutStatusPaid,
Currency: "USD",
Amount: "-50.00",
Fee: "0.00",
Net: "-50.00",
SourceID: 460709370,
SourceId: 460709370,
SourceType: "adjustment",
SourceOrderID: 0,
SourceOrderTransactionID: 0,
SourceOrderId: 0,
SourceOrderTransactionId: 0,
ProcessedAt: date1,
}
if !reflect.DeepEqual(paymentsTransactions, expected) {
Expand Down

0 comments on commit bfeff43

Please sign in to comment.