Repository: VictorAvelar/mollie-api-go
Pull request #352 (2024-03-16 07:19:11)

check terminals resource against api reference
<!--- Provide a general summary of your changes in the Title above -->

# Description

Ensures that the `terminals` resource delivers API parity. 

## Motivation and context

Ensures the library has full API parity.

## How has this been tested?

Please describe in detail how you tested your changes.

Include details of your testing environment, and the tests you ran to
see how your change affects other areas of the code, etc.

- [x] Unit tests added / updated
- [x] The tests run on docker (using `make test`)
- [x] The required `test data` has been added / updated

If you are running the tests locally, please specify:

- OS: macos
- Go version 1.22

## Types of changes

What types of changes does your code introduce? Put an `x` in all the boxes that apply:

- [ ] Bug fix (non-breaking change which fixes an issue)
- [x] New feature (non-breaking change which adds functionality)
- [x] Breaking change (fix or feature that would cause existing functionality to change)
- [ ] This change requires a documentation update

## Checklist

Go over all the following points, and put an `x` in all the boxes that apply.

Please, please, please, don't send your pull request until all of the boxes are ticked. Once your pull request is created, it will trigger a build on our continuous integration server to make sure your [tests and code style pass](https://help.github.com/articles/about-required-status-checks/).

- [x] I have read the **[CONTRIBUTING](CONTRIBUTING.md)** document.
- [x] My pull request addresses exactly one patch/feature.
- [x] I have created a branch for this patch/feature.
- [x] Each individual commit in the pull request is meaningful.
- [x] If my change requires a change to the documentation, I have updated it accordingly.

<!-- If you're unsure about any of these, don't hesitate to ask. We're here to help! -->



Patch:
diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml
index 4f9f157..1a7c6de 100644
--- a/.github/workflows/main.yml
+++ b/.github/workflows/main.yml
@@ -40,4 +40,4 @@ jobs:
       - uses: actions/setup-go@0c52d547c9bc32b1aa3301fd7a9cb496313a4491
         with:
           go-version: ${{ matrix.go }}
-      - run: go test -v -failfast ./...
+      - run: go test -failfast ./...
diff --git a/docs/README.md b/docs/README.md
index 3f2f07d..e59246d 100644
--- a/docs/README.md
+++ b/docs/README.md
@@ -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>)
@@ -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>)
@@ -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>)
 
@@ -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.
 
@@ -5723,7 +5739,6 @@ 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"`
@@ -5731,12 +5746,13 @@ type Terminal struct {
     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.
 
@@ -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.
 
@@ -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.
 
@@ -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)
@@ -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.
diff --git a/mollie/terminals.go b/mollie/terminals.go
index 27e89d1..41f0637 100644
--- a/mollie/terminals.go
+++ b/mollie/terminals.go
@@ -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
 
@@ -25,7 +22,6 @@ 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"`
@@ -33,31 +29,18 @@ type Terminal struct {
 	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.
@@ -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)


Test patch:
diff --git a/mollie/terminals_test.go b/mollie/terminals_test.go
index 3503f7d..8958805 100644
--- a/mollie/terminals_test.go
+++ b/mollie/terminals_test.go
@@ -113,7 +113,7 @@ func TestTerminalsService_List(t *testing.T) {
 
 	type args struct {
 		ctx     context.Context
-		options *TerminalListOptions
+		options *ListTerminalsOptions
 	}
 
 	cases := []struct {
@@ -129,7 +129,7 @@ func TestTerminalsService_List(t *testing.T) {
 			"list terminals correctly",
 			args{
 				context.Background(),
-				&TerminalListOptions{},
+				&ListTerminalsOptions{},
 			},
 			false,
 			nil,
@@ -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{