Skip to content

Commit

Permalink
Adjusted test text and url values
Browse files Browse the repository at this point in the history
  • Loading branch information
eltinMeli committed Feb 14, 2024
1 parent 69c6931 commit f0b2b41
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 32 deletions.
15 changes: 7 additions & 8 deletions pkg/customercard/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,8 @@ import (
)

const (
urlBase = "https://api.mercadopago.com/v1/customers/{customer_id}"
urlCards = urlBase + "/cards"
urlCardsWithID = urlCards + "/{card_id}"
urlBase = "https://api.mercadopago.com/v1/customers/{customer_id}/cards"
urlWithID = urlBase + "/{card_id}"
)

// Client contains the methods to interact with the Customer Cards API.
Expand Down Expand Up @@ -58,7 +57,7 @@ func (c *client) Create(ctx context.Context, customerID string, request Request)
"customer_id": customerID,
}

res, err := httpclient.Post[Response](ctx, c.config, urlCards, request, httpclient.WithPathParams(params))
res, err := httpclient.Post[Response](ctx, c.config, urlBase, request, httpclient.WithPathParams(params))
if err != nil {
return nil, err
}
Expand All @@ -72,7 +71,7 @@ func (c *client) Get(ctx context.Context, customerID, cardID string) (*Response,
"card_id": cardID,
}

res, err := httpclient.Get[Response](ctx, c.config, urlCardsWithID, httpclient.WithPathParams(params))
res, err := httpclient.Get[Response](ctx, c.config, urlWithID, httpclient.WithPathParams(params))
if err != nil {
return nil, err
}
Expand All @@ -86,7 +85,7 @@ func (c *client) Update(ctx context.Context, customerID, cardID string, request
"card_id": cardID,
}

res, err := httpclient.Put[Response](ctx, c.config, urlCardsWithID, request, httpclient.WithPathParams(params))
res, err := httpclient.Put[Response](ctx, c.config, urlWithID, request, httpclient.WithPathParams(params))
if err != nil {
return nil, err
}
Expand All @@ -100,7 +99,7 @@ func (c *client) Delete(ctx context.Context, customerID, cardID string) (*Respon
"card_id": cardID,
}

res, err := httpclient.Delete[Response](ctx, c.config, urlCardsWithID, nil, httpclient.WithPathParams(params))
res, err := httpclient.Delete[Response](ctx, c.config, urlWithID, nil, httpclient.WithPathParams(params))
if err != nil {
return nil, err
}
Expand All @@ -113,7 +112,7 @@ func (c *client) List(ctx context.Context, customerID string) ([]Response, error
"customer_id": customerID,
}

res, err := httpclient.Get[[]Response](ctx, c.config, urlCards, httpclient.WithPathParams(params))
res, err := httpclient.Get[[]Response](ctx, c.config, urlBase, httpclient.WithPathParams(params))
if err != nil {
return nil, err
}
Expand Down
16 changes: 8 additions & 8 deletions pkg/customercard/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -248,10 +248,10 @@ func TestUpdate(t *testing.T) {
}

if gotErr != tt.wantErr {
t.Errorf("client.Create() error = %v, wantErr %v", err, tt.wantErr)
t.Errorf("client.Update() error = %v, wantErr %v", err, tt.wantErr)
}
if !reflect.DeepEqual(got, tt.want) {
t.Errorf("client.Create() = %v, want %v", got, tt.want)
t.Errorf("client.Update() = %v, want %v", got, tt.want)
}
})
}
Expand Down Expand Up @@ -363,10 +363,10 @@ func TestGet(t *testing.T) {
}

if gotErr != tt.wantErr {
t.Errorf("client.Create() error = %v, wantErr %v", err, tt.wantErr)
t.Errorf("client.Get() error = %v, wantErr %v", err, tt.wantErr)
}
if !reflect.DeepEqual(got, tt.want) {
t.Errorf("client.Create() = %v, want %v", got, tt.want)
t.Errorf("client.Get() = %v, want %v", got, tt.want)
}
})
}
Expand Down Expand Up @@ -478,10 +478,10 @@ func TestDelete(t *testing.T) {
}

if gotErr != tt.wantErr {
t.Errorf("client.Create() error = %v, wantErr %v", err, tt.wantErr)
t.Errorf("client.Delete() error = %v, wantErr %v", err, tt.wantErr)
}
if !reflect.DeepEqual(got, tt.want) {
t.Errorf("client.Create() = %v, want %v", got, tt.want)
t.Errorf("client.Delete() = %v, want %v", got, tt.want)
}
})
}
Expand Down Expand Up @@ -593,10 +593,10 @@ func TestList(t *testing.T) {
}

if gotErr != tt.wantErr {
t.Errorf("client.Create() error = %v, wantErr %v", err, tt.wantErr)
t.Errorf("client.List() error = %v, wantErr %v", err, tt.wantErr)
}
if !reflect.DeepEqual(got, tt.want) {
t.Errorf("client.Create() = %v, want %v", got, tt.want)
t.Errorf("client.List() = %v, want %v", got, tt.want)
}
})
}
Expand Down
32 changes: 16 additions & 16 deletions pkg/customercard/response.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,23 +4,23 @@ import "time"

// Response represents a customer card.
type Response struct {
ID string `json:"id"`
CustomerID string `json:"customer_id"`
UserID string `json:"user_id"`
CardNumberID string `json:"card_number_id"`
FirstSixDigits string `json:"first_six_digits"`
LastFourDigits string `json:"last_four_digits"`
ExpirationMonth int `json:"expiration_month"`
ExpirationYear int `json:"expiration_year"`
LiveMode bool `json:"live_mode"`
DateCreated *time.Time `json:"date_created"`
DateLastUpdated *time.Time `json:"date_last_updated"`
ID string `json:"id"`
CustomerID string `json:"customer_id"`
UserID string `json:"user_id"`
CardNumberID string `json:"card_number_id"`
FirstSixDigits string `json:"first_six_digits"`
LastFourDigits string `json:"last_four_digits"`
ExpirationMonth int `json:"expiration_month"`
ExpirationYear int `json:"expiration_year"`
LiveMode bool `json:"live_mode"`

Issuer IssuerResponse `json:"issuer"`
Cardholder CardholderResponse `json:"cardholder"`
AdditionalInfo AdditionalInfoResponse `json:"additional_info"`
PaymentMethod PaymentMethodResponse `json:"payment_method"`
SecurityCode SecurityCode `json:"security_code"`
DateCreated *time.Time `json:"date_created"`
DateLastUpdated *time.Time `json:"date_last_updated"`
Issuer IssuerResponse `json:"issuer"`
Cardholder CardholderResponse `json:"cardholder"`
AdditionalInfo AdditionalInfoResponse `json:"additional_info"`
PaymentMethod PaymentMethodResponse `json:"payment_method"`
SecurityCode SecurityCode `json:"security_code"`
}

// AdditionalInfoResponse represents additional customer card information.
Expand Down

0 comments on commit f0b2b41

Please sign in to comment.