Skip to content

Commit

Permalink
join param for /operation (#1560)
Browse files Browse the repository at this point in the history
  • Loading branch information
poliha authored Aug 6, 2019
1 parent 5357697 commit df86d1f
Show file tree
Hide file tree
Showing 6 changed files with 33 additions and 8 deletions.
5 changes: 5 additions & 0 deletions clients/horizonclient/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,11 @@
All notable changes to this project will be documented in this
file. This project adheres to [Semantic Versioning](http://semver.org/).

## Unreleased

- Add support for querying operation endpoint with `join` parameter [#1521](https://github.com/stellar/go/issues/1521).


## [v1.3.0](https://github.com/stellar/go/releases/tag/horizonclient-v1.3.0) - 2019-07-08

- Transaction information returned by methods now contain new fields: `FeeCharged` and `MaxFee`. `FeePaid` is deprecated and will be removed in later versions.
Expand Down
4 changes: 4 additions & 0 deletions clients/horizonclient/internal.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,10 @@ func addQueryParams(params ...interface{}) string {
if param {
query.Add("include_failed", "true")
}
case join:
if param != "" {
query.Add("join", string(param))
}
case map[string]string:
for key, value := range param {
if value != "" {
Expand Down
4 changes: 4 additions & 0 deletions clients/horizonclient/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,9 @@ type includeFailed bool
// AssetType represents `asset_type` param in queries
type AssetType string

// join represents `join` param in queries
type join string

const (
// OrderAsc represents an ascending order parameter
OrderAsc Order = "asc"
Expand Down Expand Up @@ -271,6 +274,7 @@ type OperationRequest struct {
Cursor string
Limit uint
IncludeFailed bool
Join string
endpoint string
}

Expand Down
6 changes: 3 additions & 3 deletions clients/horizonclient/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -733,12 +733,12 @@ func TestOperationsRequest(t *testing.T) {
HTTP: hmock,
}

operationRequest := OperationRequest{}
operationRequest := OperationRequest{Join: "transactions"}

// all operations
hmock.On(
"GET",
"https://localhost/operations",
"https://localhost/operations?join=transactions",
).ReturnString(200, multipleOpsResponse)

ops, err := client.Operations(operationRequest)
Expand Down Expand Up @@ -768,7 +768,7 @@ func TestOperationsRequest(t *testing.T) {
// all payments
hmock.On(
"GET",
"https://localhost/payments",
"https://localhost/payments?join=transactions",
).ReturnString(200, paymentsResponse)

ops, err = client.Payments(operationRequest)
Expand Down
2 changes: 1 addition & 1 deletion clients/horizonclient/operation_request.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ func (op OperationRequest) BuildURL() (endpoint string, err error) {
}

queryParams := addQueryParams(cursor(op.Cursor), limit(op.Limit), op.Order,
includeFailed(op.IncludeFailed))
includeFailed(op.IncludeFailed), join(op.Join))
if queryParams != "" {
endpoint = fmt.Sprintf("%s?%s", endpoint, queryParams)
}
Expand Down
20 changes: 16 additions & 4 deletions clients/horizonclient/operation_request_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,17 +56,29 @@ func TestOperationRequestBuildUrl(t *testing.T) {
assert.Contains(t, err.Error(), "invalid request: too many parameters")
}

op = OperationRequest{Cursor: "123456", Limit: 30, Order: OrderAsc, endpoint: "operations"}
op = OperationRequest{Cursor: "123456", Limit: 30, Order: OrderAsc, endpoint: "operations", Join: "transactions"}
endpoint, err = op.BuildURL()
// It should return valid all operations endpoint with query params and no errors
require.NoError(t, err)
assert.Equal(t, "operations?cursor=123456&limit=30&order=asc", endpoint)
assert.Equal(t, "operations?cursor=123456&join=transactions&limit=30&order=asc", endpoint)

op = OperationRequest{Cursor: "123456", Limit: 30, Order: OrderAsc, endpoint: "payments"}
op = OperationRequest{Cursor: "123456", Limit: 30, Order: OrderAsc, endpoint: "payments", Join: "transactions"}
endpoint, err = op.BuildURL()
// It should return valid all operations endpoint with query params and no errors
require.NoError(t, err)
assert.Equal(t, "payments?cursor=123456&limit=30&order=asc", endpoint)
assert.Equal(t, "payments?cursor=123456&join=transactions&limit=30&order=asc", endpoint)

op = OperationRequest{ForAccount: "GCLWGQPMKXQSPF776IU33AH4PZNOOWNAWGGKVTBQMIC5IMKUNP3E6NVU", endpoint: "payments", Join: "transactions"}
endpoint, err = op.BuildURL()
// It should return valid all operations endpoint with query params and no errors
require.NoError(t, err)
assert.Equal(t, "accounts/GCLWGQPMKXQSPF776IU33AH4PZNOOWNAWGGKVTBQMIC5IMKUNP3E6NVU/payments?join=transactions", endpoint)

op = OperationRequest{forOperationID: "1234", endpoint: "payments", Join: "transactions"}
endpoint, err = op.BuildURL()
// It should return valid all operations endpoint with query params and no errors
require.NoError(t, err)
assert.Equal(t, "operations/1234?join=transactions", endpoint)
}

func ExampleClient_StreamOperations() {
Expand Down

0 comments on commit df86d1f

Please sign in to comment.