Skip to content

Commit

Permalink
check terminals resource against api reference (#352)
Browse files Browse the repository at this point in the history
  • Loading branch information
VictorAvelar authored Mar 16, 2024
1 parent ea1f38c commit 5c00b3e
Show file tree
Hide file tree
Showing 4 changed files with 72 additions and 52 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -40,4 +40,4 @@ jobs:
- uses: actions/setup-go@0c52d547c9bc32b1aa3301fd7a9cb496313a4491
with:
go-version: ${{ matrix.go }}
- run: go test -v -failfast ./...
- run: go test -failfast ./...
50 changes: 25 additions & 25 deletions docs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,7 @@ REST also implies a nice and clean structure for URLs or endpoints. This means y
- [type ListPaymentOptions](<#ListPaymentOptions>)
- [type ListSettlementsOptions](<#ListSettlementsOptions>)
- [type ListSubscriptionsOptions](<#ListSubscriptionsOptions>)
- [type ListTerminalsOptions](<#ListTerminalsOptions>)
- [type Locale](<#Locale>)
- [type Mandate](<#Mandate>)
- [type MandateDetails](<#MandateDetails>)
Expand Down Expand Up @@ -367,11 +368,10 @@ REST also implies a nice and clean structure for URLs or endpoints. This means y
- [type Subtotal](<#Subtotal>)
- [type Terminal](<#Terminal>)
- [type TerminalList](<#TerminalList>)
- [type TerminalListOptions](<#TerminalListOptions>)
- [type TerminalStatus](<#TerminalStatus>)
- [type TerminalsService](<#TerminalsService>)
- [func \(ts \*TerminalsService\) Get\(ctx context.Context, id string\) \(res \*Response, t \*Terminal, err error\)](<#TerminalsService.Get>)
- [func \(ts \*TerminalsService\) List\(ctx context.Context, options \*TerminalListOptions\) \(res \*Response, tl \*TerminalList, err error\)](<#TerminalsService.List>)
- [func \(ts \*TerminalsService\) List\(ctx context.Context, options \*ListTerminalsOptions\) \(res \*Response, tl \*TerminalList, err error\)](<#TerminalsService.List>)
- [type TransactionType](<#TransactionType>)
- [type TransferDestination](<#TransferDestination>)
- [type TransferFrequency](<#TransferFrequency>)
Expand Down Expand Up @@ -2799,6 +2799,22 @@ type ListSubscriptionsOptions struct {
}
```

<a name="ListTerminalsOptions"></a>
## type [ListTerminalsOptions](<https://github.com/VictorAvelar/mollie-api-go/blob/master/mollie/terminals.go#L39-L44>)

ListTerminalsOptions holds query string parameters valid for terminals lists.

ProfileID and TestMode are valid only when using access tokens.

```go
type ListTerminalsOptions struct {
Testmode bool `url:"testMode,omitempty"`
Limit int `url:"limit,omitempty"`
From string `url:"from,omitempty"`
ProfileID string `url:"profileID,omitempty"`
}
```

<a name="Locale"></a>
## type [Locale](<https://github.com/VictorAvelar/mollie-api-go/blob/master/mollie/common_types.go#L89>)

Expand Down Expand Up @@ -5714,7 +5730,7 @@ type Subtotal struct {
```

<a name="Terminal"></a>
## type [Terminal](<https://github.com/VictorAvelar/mollie-api-go/blob/master/mollie/terminals.go#L24-L37>)
## type [Terminal](<https://github.com/VictorAvelar/mollie-api-go/blob/master/mollie/terminals.go#L21-L34>)

Terminal symbolizes a physical device to receive payments.

Expand All @@ -5723,20 +5739,20 @@ type Terminal struct {
ID string `json:"id,omitempty"`
Resource string `json:"resource,omitempty"`
ProfileID string `json:"profileID,omitempty"`
Status TerminalStatus `json:"status,omitempty"`
Brand string `json:"brand,omitempty"`
Model string `json:"model,omitempty"`
SerialNumber string `json:"serialNumber,omitempty"`
Currency string `json:"currency,omitempty"`
Description string `json:"description,omitempty"`
CreatedAt *time.Time `json:"createdAt,omitempty"`
UpdatedAt *time.Time `json:"updatedAt,omitempty"`
Status TerminalStatus `json:"status,omitempty"`
Links PaginationLinks `json:"_links,omitempty"`
}
```

<a name="TerminalList"></a>
## type [TerminalList](<https://github.com/VictorAvelar/mollie-api-go/blob/master/mollie/terminals.go#L64-L70>)
## type [TerminalList](<https://github.com/VictorAvelar/mollie-api-go/blob/master/mollie/terminals.go#L47-L53>)

TerminalList describes the response for terminals list endpoints.

Expand All @@ -5750,24 +5766,8 @@ type TerminalList struct {
}
```

<a name="TerminalListOptions"></a>
## type [TerminalListOptions](<https://github.com/VictorAvelar/mollie-api-go/blob/master/mollie/terminals.go#L56-L61>)

TerminalListOptions holds query string parameters valid for terminals lists.

ProfileID and TestMode are valid only when using access tokens.

```go
type TerminalListOptions struct {
From string `url:"from,omitempty"`
Limit int `url:"limit,omitempty"`
ProfileID string `url:"profileID,omitempty"`
TestMode bool `url:"testMode,omitempty"`
}
```

<a name="TerminalStatus"></a>
## type [TerminalStatus](<https://github.com/VictorAvelar/mollie-api-go/blob/master/mollie/terminals.go#L14>)
## type [TerminalStatus](<https://github.com/VictorAvelar/mollie-api-go/blob/master/mollie/terminals.go#L11>)

TerminalStatus is the status of the terminal, which is a read\-only value determined by Mollie.

Expand All @@ -5786,7 +5786,7 @@ const (
```

<a name="TerminalsService"></a>
## type [TerminalsService](<https://github.com/VictorAvelar/mollie-api-go/blob/master/mollie/terminals.go#L11>)
## type [TerminalsService](<https://github.com/VictorAvelar/mollie-api-go/blob/master/mollie/terminals.go#L56>)

TerminalsService operates over terminals resource.

Expand All @@ -5795,7 +5795,7 @@ type TerminalsService service
```

<a name="TerminalsService.Get"></a>
### func \(\*TerminalsService\) [Get](<https://github.com/VictorAvelar/mollie-api-go/blob/master/mollie/terminals.go#L40>)
### func \(\*TerminalsService\) [Get](<https://github.com/VictorAvelar/mollie-api-go/blob/master/mollie/terminals.go#L59>)

```go
func (ts *TerminalsService) Get(ctx context.Context, id string) (res *Response, t *Terminal, err error)
Expand All @@ -5807,7 +5807,7 @@ Get terminal retrieves a single terminal object by its terminal ID.
### func \(\*TerminalsService\) [List](<https://github.com/VictorAvelar/mollie-api-go/blob/master/mollie/terminals.go#L73-L77>)

```go
func (ts *TerminalsService) List(ctx context.Context, options *TerminalListOptions) (res *Response, tl *TerminalList, err error)
func (ts *TerminalsService) List(ctx context.Context, options *ListTerminalsOptions) (res *Response, tl *TerminalList, err error)
```

List retrieves a list of terminals symbolizing the physical devices to receive payments.
Expand Down
48 changes: 24 additions & 24 deletions mollie/terminals.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,6 @@ import (
"time"
)

// TerminalsService operates over terminals resource.
type TerminalsService service

// TerminalStatus is the status of the terminal, which is a read-only value determined by Mollie.
type TerminalStatus string

Expand All @@ -25,39 +22,25 @@ type Terminal struct {
ID string `json:"id,omitempty"`
Resource string `json:"resource,omitempty"`
ProfileID string `json:"profileID,omitempty"`
Status TerminalStatus `json:"status,omitempty"`
Brand string `json:"brand,omitempty"`
Model string `json:"model,omitempty"`
SerialNumber string `json:"serialNumber,omitempty"`
Currency string `json:"currency,omitempty"`
Description string `json:"description,omitempty"`
CreatedAt *time.Time `json:"createdAt,omitempty"`
UpdatedAt *time.Time `json:"updatedAt,omitempty"`
Status TerminalStatus `json:"status,omitempty"`
Links PaginationLinks `json:"_links,omitempty"`
}

// Get terminal retrieves a single terminal object by its terminal ID.
func (ts *TerminalsService) Get(ctx context.Context, id string) (res *Response, t *Terminal, err error) {
res, err = ts.client.get(ctx, fmt.Sprintf("v2/terminals/%s", id), nil)
if err != nil {
return
}

if err = json.Unmarshal(res.content, &t); err != nil {
return
}

return
}

// TerminalListOptions holds query string parameters valid for terminals lists.
// ListTerminalsOptions holds query string parameters valid for terminals lists.
//
// ProfileID and TestMode are valid only when using access tokens.
type TerminalListOptions struct {
From string `url:"from,omitempty"`
type ListTerminalsOptions struct {
Testmode bool `url:"testMode,omitempty"`
Limit int `url:"limit,omitempty"`
From string `url:"from,omitempty"`
ProfileID string `url:"profileID,omitempty"`
TestMode bool `url:"testMode,omitempty"`
}

// TerminalList describes the response for terminals list endpoints.
Expand All @@ -69,14 +52,31 @@ type TerminalList struct {
Links PaginationLinks `json:"_links,omitempty"`
}

// TerminalsService operates over terminals resource.
type TerminalsService service

// Get terminal retrieves a single terminal object by its terminal ID.
func (ts *TerminalsService) Get(ctx context.Context, id string) (res *Response, t *Terminal, err error) {
res, err = ts.client.get(ctx, fmt.Sprintf("v2/terminals/%s", id), nil)
if err != nil {
return
}

if err = json.Unmarshal(res.content, &t); err != nil {
return
}

return
}

// List retrieves a list of terminals symbolizing the physical devices to receive payments.
func (ts *TerminalsService) List(ctx context.Context, options *TerminalListOptions) (
func (ts *TerminalsService) List(ctx context.Context, options *ListTerminalsOptions) (
res *Response,
tl *TerminalList,
err error,
) {
if ts.client.HasAccessToken() && ts.client.config.testing {
options.TestMode = true
options.Testmode = true
}

res, err = ts.client.get(ctx, "v2/terminals", options)
Expand Down
24 changes: 22 additions & 2 deletions mollie/terminals_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ func TestTerminalsService_List(t *testing.T) {

type args struct {
ctx context.Context
options *TerminalListOptions
options *ListTerminalsOptions
}

cases := []struct {
Expand All @@ -129,7 +129,7 @@ func TestTerminalsService_List(t *testing.T) {
"list terminals correctly",
args{
context.Background(),
&TerminalListOptions{},
&ListTerminalsOptions{},
},
false,
nil,
Expand All @@ -145,6 +145,26 @@ func TestTerminalsService_List(t *testing.T) {
_, _ = w.Write([]byte(testdata.ListTerminalsResponse))
},
},
{
"list terminals correctly with an access token",
args{
context.Background(),
&ListTerminalsOptions{},
},
false,
nil,
testdata.GetTerminalResponse,
setAccessToken,
func(w http.ResponseWriter, r *http.Request) {
testHeader(t, r, AuthHeader, "Bearer access_token_test")
testMethod(t, r, "GET")

if _, ok := r.Header[AuthHeader]; !ok {
w.WriteHeader(http.StatusUnauthorized)
}
_, _ = w.Write([]byte(testdata.ListTerminalsResponse))
},
},
{
"get terminals list, an error is returned from the server",
args{
Expand Down

0 comments on commit 5c00b3e

Please sign in to comment.