Skip to content

Commit

Permalink
review fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
jasonbornsteinMOOV committed Aug 1, 2023
1 parent 12a2152 commit 07554d7
Show file tree
Hide file tree
Showing 6 changed files with 31 additions and 17 deletions.
12 changes: 11 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,17 @@ match:
routingNumber: <string> # Exact match of ABA routing number (RDFIIdentification and CheckDigit)
traceNumber: <string> # Exact match of TraceNumber
entryType: <string> # Checks TransactionCode. Accepted values: credit, debit or prenote.
# at most, one `copy` action and one other action will be returned
# Matching will find at most 2 Actions: 1 Copy Action and 1 Return/Correction Action.
# If the Return/Correction Action as no Delay, the Copy Action will be excluded.
# Valid combinations include:
# 1. Copy
# 2. Return/Correction w/ Delay
# 3. Return/Correction w/o Delay
# 4. Copy and Return/Correction w/ Delay
# 5. Nothing
# Invalid combinations are:
# 1. Copy + Return/Correction w/o Delay
# 2. Copy w/ Delay (validated when reading configuration)
action:
# How long into the future should we wait before making the correction/return available?
delay: <duration>
Expand Down
6 changes: 3 additions & 3 deletions pkg/response/match/matcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,9 @@ func (m Matcher) FindAction(ed *ach.EntryDetail) (copyAction *service.Action, pr
* Valid combinations include:
* 1. Copy
* 2. Return/Correction w/ Delay
* 2. Return/Correction w/o Delay
* 3. Copy and Return/Correction w/ Delay
* 4. Nothing
* 3. Return/Correction w/o Delay
* 4. Copy and Return/Correction w/ Delay
* 5. Nothing
*
* Invalid combinations are:
* 1. Copy + Return/Correction w/o Delay
Expand Down
2 changes: 2 additions & 0 deletions pkg/service/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,5 @@ func Test_ConfigLoading(t *testing.T) {
err := ConfigService.Load(gc)
require.Nil(t, err)
}

// TODO JB: tests
5 changes: 2 additions & 3 deletions pkg/service/environment.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
package service

import (
"errors"
ftp "goftp.io/server/core"

"github.com/gorilla/mux"
Expand Down Expand Up @@ -61,8 +60,8 @@ func LoadConfig(logger log.Logger) (*Config, error) {
if err := configService.Load(global); err != nil {
return nil, err
}
if !global.Validate() {
return nil, errors.New("invalid config")
if err := global.Validate(); err != nil {
return nil, err
}

cfg := &global.ACHTestHarness
Expand Down
21 changes: 11 additions & 10 deletions pkg/service/model_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
package service

import (
"errors"
"fmt"
"time"

Expand All @@ -13,7 +14,7 @@ type GlobalConfig struct {
ACHTestHarness Config
}

func (gc *GlobalConfig) Validate() bool {
func (gc *GlobalConfig) Validate() error {
return gc.ACHTestHarness.Validate()
}

Expand All @@ -25,14 +26,14 @@ type Config struct {
Responses []Response
}

func (cfg *Config) Validate() bool {
func (cfg *Config) Validate() error {
for i := range cfg.Responses {
if !cfg.Responses[i].Validate() {
return false
if err := cfg.Responses[i].Validate(); err != nil {
return err
}
}

return true
return nil
}

func (cfg *Config) responsePaths() []string {
Expand Down Expand Up @@ -93,7 +94,7 @@ type Response struct {
Action Action
}

func (r *Response) Validate() bool {
func (r *Response) Validate() error {
return r.Action.Validate()
}

Expand Down Expand Up @@ -141,10 +142,10 @@ type Action struct {
Return *Return
}

func (a *Action) Validate() bool {
func (a *Action) Validate() error {
// Delay is only valid for Return and Correction
if a.Delay != nil && a.Copy != nil {
return false
return errors.New("Delay and Copy are not valid together in an Action")
}

// only allowed 1 of Copy, Return, Correction to be configured
Expand All @@ -159,10 +160,10 @@ func (a *Action) Validate() bool {
count++
}
if count > 1 {
return false
return errors.New("only 1 of Copy, Return, Correction can be configured in an Action")
}

return true
return nil
}

type Copy struct {
Expand Down
2 changes: 2 additions & 0 deletions pkg/service/model_config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,3 +31,5 @@ func TestConfig__Return(t *testing.T) {
r.Code = "R99"
require.Error(t, r.Validate())
}

// TODO JB: tests

0 comments on commit 07554d7

Please sign in to comment.