-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
65e1dd6
commit 6528561
Showing
8 changed files
with
142 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
package clearbank | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
"net/http" | ||
) | ||
|
||
type StatementClient interface { | ||
RequestStatement(context.Context, StatementPayload) error | ||
RequestStatementFor(context.Context, string, StatementPayload) error | ||
} | ||
|
||
type StatementPayload struct { | ||
Year int `json:"year"` | ||
Month int `json:"month"` | ||
Format string `json:"format"` | ||
Currency string `json:"currency"` | ||
} | ||
|
||
func (c *client) RequestStatement(ctx context.Context, payload StatementPayload) error { | ||
req, err := c.newRequest(ctx, http.MethodPost, "/mccy/v1/StatementRequests", payload) | ||
if err != nil { | ||
return fmt.Errorf("failed to create request: %w", err) | ||
} | ||
|
||
req.ExpectStatus(http.StatusAccepted) | ||
return c.do(ctx, req) | ||
} | ||
|
||
func (c *client) RequestStatementFor(ctx context.Context, iban string, payload StatementPayload) error { | ||
req, err := c.newRequest(ctx, http.MethodPost, fmt.Sprintf("/mccy/v1/StatementRequests/account/%s", iban), payload) | ||
if err != nil { | ||
return fmt.Errorf("failed to create request: %w", err) | ||
} | ||
|
||
req.ExpectStatus(http.StatusAccepted) | ||
return c.do(ctx, req) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
package clearbank_test | ||
|
||
import ( | ||
"bytes" | ||
"context" | ||
_ "embed" | ||
"io" | ||
"net/http" | ||
"testing" | ||
|
||
"github.com/brokeyourbike/clearbank-api-client-go" | ||
"github.com/brokeyourbike/clearbank-api-client-go/signature" | ||
"github.com/stretchr/testify/assert" | ||
mock "github.com/stretchr/testify/mock" | ||
) | ||
|
||
func TestRequestStatement(t *testing.T) { | ||
mockSigner := signature.NewMockSigner(t) | ||
mockHttpClient := clearbank.NewMockHttpClient(t) | ||
client := clearbank.NewClient("token", mockSigner, clearbank.WithHTTPClient(mockHttpClient)) | ||
|
||
ctx := clearbank.RequestIdContext(context.TODO(), "123") | ||
mockSigner.On("Sign", ctx, mock.Anything).Return([]byte("signed"), nil).Once() | ||
|
||
resp := &http.Response{StatusCode: http.StatusAccepted, Body: io.NopCloser(bytes.NewReader(nil))} | ||
mockHttpClient.On("Do", mock.AnythingOfType("*http.Request")).Return(resp, nil).Once() | ||
|
||
assert.NoError(t, client.RequestStatement(ctx, clearbank.StatementPayload{})) | ||
} | ||
|
||
func TestRequestStatementFor(t *testing.T) { | ||
mockSigner := signature.NewMockSigner(t) | ||
mockHttpClient := clearbank.NewMockHttpClient(t) | ||
client := clearbank.NewClient("token", mockSigner, clearbank.WithHTTPClient(mockHttpClient)) | ||
|
||
ctx := clearbank.RequestIdContext(context.TODO(), "123") | ||
mockSigner.On("Sign", ctx, mock.Anything).Return([]byte("signed"), nil).Once() | ||
|
||
resp := &http.Response{StatusCode: http.StatusAccepted, Body: io.NopCloser(bytes.NewReader(nil))} | ||
mockHttpClient.On("Do", mock.AnythingOfType("*http.Request")).Return(resp, nil).Once() | ||
|
||
assert.NoError(t, client.RequestStatementFor(ctx, "IBAN12345", clearbank.StatementPayload{})) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
{ | ||
"type": "string", | ||
"title": "string", | ||
"status": 123, | ||
"detail": "string", | ||
"instance": "string", | ||
"property1": null, | ||
"property2": null | ||
} |