Skip to content

Commit

Permalink
Merge pull request #337 from moov-io/Adds-X-Total-Count-headers-for-t…
Browse files Browse the repository at this point in the history
…he-GetBatches-request

Adds X-Total-Count headers for the GetBatches request
  • Loading branch information
bkmoovio authored Nov 1, 2018
2 parents ff055d8 + dcab45a commit bcb2751
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 3 deletions.
2 changes: 2 additions & 0 deletions server/endpoints.go
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,8 @@ type getBatchesResponse struct {
Err error `json:"error"`
}

func (r getBatchesResponse) count() int { return len(r.Batches) }

func (r getBatchesResponse) error() error { return r.Err }

func MakeGetBatchEndpoint(s Service) endpoint.Endpoint {
Expand Down
32 changes: 29 additions & 3 deletions server/routing_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,11 @@ package server
import (
"context"
"encoding/json"
"github.com/moov-io/ach"
"net/http/httptest"
"strings"
"testing"

"github.com/moov-io/ach"

httptransport "github.com/go-kit/kit/transport/http"
)

Expand Down Expand Up @@ -49,7 +48,7 @@ func TestEncodeTextResponse(t *testing.T) {
}
}

func TestXTotalCountHeader(t *testing.T) {
func TestFilesXTotalCountHeader(t *testing.T) {
counter := getFilesResponse{
Files: []*ach.File{ach.NewFile()},
Err: nil,
Expand All @@ -67,6 +66,33 @@ func TestXTotalCountHeader(t *testing.T) {
}
}

func TestBatchesXTotalCountHeader(t *testing.T) {
bh := mockBatchHeaderWeb()
entry := mockWEBEntryDetail()
addenda := mockAddenda05()
entry.AddAddenda(addenda)
// build the batch
batch := ach.NewBatchWEB(bh)
batch.SetID(batch.Header.ID)
batch.AddEntry(entry)

counter := getBatchesResponse{
Batches: []ach.Batcher{batch},
Err: nil,
}

w := httptest.NewRecorder()
encodeResponse(context.Background(), w, counter)

actual, ok := w.Result().Header["X-Total-Count"]
if !ok {
t.Fatal("should have count")
}
if actual[0] != "1" {
t.Errorf("should be 1, got %v", actual[0])
}
}

func TestRouting__proxyCORSHeaders(t *testing.T) {
r := httptest.NewRequest("GET", "/ping", nil)
r.Header.Set("Access-Control-Allow-Origin", "origin")
Expand Down

0 comments on commit bcb2751

Please sign in to comment.