server: include HTTP test for balance endpoint
@@ -254,6 +254,58 @@ func TestFiles__validateFileEndpoint(t *testing.T) {
}
}
+func TestFilesErr__balanceFileEndpoint(t *testing.T) {
+ repo := NewRepositoryInMemory(testTTLDuration, nil)
+ svc := NewService(repo)
+
+ resp, err := balanceFileEndpoint(svc, repo, nil)(context.TODO(), nil)
+ r, ok := resp.(balanceFileResponse)
+ if !ok {
+ t.Errorf("got %#v", resp)
+ }
+ if err == nil || r.Err == nil {
+ t.Errorf("expected error: err=%v resp.Err=%v", err, r.Err)
+ }
+}
+
+func TestFiles__balanceFileEndpoint(t *testing.T) {
+ logger := log.NewNopLogger()
+ repo := NewRepositoryInMemory(testTTLDuration, logger)
+ svc := NewService(repo)
+ router := MakeHTTPHandler(svc, repo, logger)
+
+ // write an ACH file into the repository
+ fd, err := os.Open(filepath.Join("..", "test", "testdata", "ppd-mixedDebitCredit-valid.json"))
+ if err != nil {
+ t.Fatalf("empty ACH file: %v", err)
+ }
+ defer fd.Close()
+
+ bs, _ := ioutil.ReadAll(fd)
+ file, _ := ach.FileFromJSON(bs)
+ repo.StoreFile(file)
+
+ w := httptest.NewRecorder()
+ body := strings.NewReader(`{"routingNumber": "987654320", "accountNumber": "216112", "accountType": "checking", "description": "OFFSET"}`)
+ req := httptest.NewRequest("POST", fmt.Sprintf("/files/%s/balance", file.ID), body)
+ req.Header.Set("X-Request-ID", base.ID())
+
+ router.ServeHTTP(w, req)
+ w.Flush()
+
+ if w.Code != http.StatusOK {
+ t.Errorf("bogus HTTP status: %d", w.Code)
+ }
+
+ var resp balanceFileResponse
+ if err := json.NewDecoder(w.Body).Decode(&resp); err != nil {
+ t.Fatal(err)
+ }
+ if resp.FileID == "" {
+ t.Error("empty FileID")
+ }
+}
+
// TestFilesError__segmentFileEndpoint test an error returned from segmentFileEndpoint
func TestFilesError__segmentFileEndpoint(t *testing.T) {
repo := NewRepositoryInMemory(testTTLDuration, nil)
@@ -267,7 +319,6 @@ func TestFilesError__segmentFileEndpoint(t *testing.T) {
if err == nil || r.Err == nil {
t.Errorf("expected error: err=%v resp.Err=%v", err, r.Err)
}
-
}
// TestFiles__segmentFileEndpoint tests segmentFileEndpoints
