Skip to content

Commit

Permalink
Merge pull request #209 from moov-io/trim-ach-suffix-on-cancel
Browse files Browse the repository at this point in the history
incoming/web: normalize fileID when canceling
  • Loading branch information
adamdecaf authored Oct 20, 2023
2 parents 87cf86e + 03744a0 commit bceef1c
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
4 changes: 4 additions & 0 deletions internal/incoming/web/api_files.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import (
"fmt"
"io"
"net/http"
"strings"

"github.com/moov-io/ach"
"github.com/moov-io/achgateway/internal/incoming"
Expand Down Expand Up @@ -164,6 +165,9 @@ func (c *FilesController) CancelFileHandler(w http.ResponseWriter, r *http.Reque
}

func (c *FilesController) cancelFile(shardKey, fileID string) error {
// Remove .ach suffix if the request added it
fileID = strings.TrimSuffix(fileID, ".ach")

bs, err := compliance.Protect(c.cfg.Transform, models.Event{
Event: incoming.CancelACHFile{
FileID: fileID,
Expand Down
4 changes: 2 additions & 2 deletions internal/incoming/web/api_files_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ func TestCancelFileHandler(t *testing.T) {
controller.AppendRoutes(r)

// Cancel our file
req := httptest.NewRequest("DELETE", "/shards/s2/files/f2", nil)
req := httptest.NewRequest("DELETE", "/shards/s2/files/f2.ach", nil)

w := httptest.NewRecorder()
r.ServeHTTP(w, req)
Expand All @@ -102,6 +102,6 @@ func TestCancelFileHandler(t *testing.T) {
var file incoming.CancelACHFile
require.NoError(t, models.ReadEvent(msg.Body, &file))

require.Equal(t, "f2", file.FileID)
require.Equal(t, "f2", file.FileID) // make sure .ach suffix is trimmed
require.Equal(t, "s2", file.ShardKey)
}

0 comments on commit bceef1c

Please sign in to comment.