Skip to content

Commit

Permalink
VEGA-2500 : Handle manual change to cancelled status (#271)
Browse files Browse the repository at this point in the history
  • Loading branch information
ndasmoj authored Oct 25, 2024
1 parent 5791938 commit ce5b69a
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 10 deletions.
16 changes: 10 additions & 6 deletions lambda/update/opg_change_status.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,20 @@ type OpgChangeStatus struct {

func (r OpgChangeStatus) Apply(lpa *shared.Lpa) []shared.FieldError {

if r.Status != shared.LpaStatusCannotRegister {
return []shared.FieldError{{Source: "/status", Detail: "Status to be updated should be cannot register"}}
if r.Status != shared.LpaStatusCannotRegister && r.Status != shared.LpaStatusCancelled {
return []shared.FieldError{{Source: "/status", Detail: "Status to be updated should be cannot register or cancelled"}}
}

if lpa.Status == shared.LpaStatusRegistered {
return []shared.FieldError{{Source: "/status", Detail: "Lpa status cannot be registered"}}
if r.Status == shared.LpaStatusCannotRegister && lpa.Status == shared.LpaStatusRegistered {
return []shared.FieldError{{Source: "/status", Detail: "Lpa status cannot be registered while changing to cannot register"}}
}

if lpa.Status == shared.LpaStatusCancelled {
return []shared.FieldError{{Source: "/status", Detail: "Lpa status cannot be cancelled"}}
if r.Status == shared.LpaStatusCannotRegister && lpa.Status == shared.LpaStatusCancelled {
return []shared.FieldError{{Source: "/status", Detail: "Lpa status cannot be cancelled while changing to cannot register"}}
}

if r.Status == shared.LpaStatusCancelled && lpa.Status != shared.LpaStatusRegistered {
return []shared.FieldError{{Source: "/status", Detail: "Lpa status has to be registered while changing to cancelled"}}
}

lpa.Status = r.Status
Expand Down
33 changes: 29 additions & 4 deletions lambda/update/opg_change_status_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
"testing"
)

func TestOpgChangeStatusApply(t *testing.T) {
func TestOpgChangeStatusToCannotRegisterApply(t *testing.T) {
lpa := &shared.Lpa{
Status: shared.LpaStatusInProgress,
}
Expand All @@ -20,6 +20,19 @@ func TestOpgChangeStatusApply(t *testing.T) {
assert.Equal(t, c.Status, lpa.Status)
}

func TestOpgChangeStatusToCancelledApply(t *testing.T) {
lpa := &shared.Lpa{
Status: shared.LpaStatusRegistered,
}
c := OpgChangeStatus{
Status: shared.LpaStatusCancelled,
}

errors := c.Apply(lpa)
assert.Empty(t, errors)
assert.Equal(t, c.Status, lpa.Status)
}

func TestOpgChangeStatusInvalidNewStatus(t *testing.T) {
lpa := &shared.Lpa{
Status: shared.LpaStatusInProgress,
Expand All @@ -29,10 +42,10 @@ func TestOpgChangeStatusInvalidNewStatus(t *testing.T) {
}

errors := c.Apply(lpa)
assert.Equal(t, errors, []shared.FieldError{{Source: "/status", Detail: "Status to be updated should be cannot register"}})
assert.Equal(t, errors, []shared.FieldError{{Source: "/status", Detail: "Status to be updated should be cannot register or cancelled"}})
}

func TestOpgChangeStatusIncorrectExistingStatus(t *testing.T) {
func TestOpgChangeStatusToCannotRegisterIncorrectExistingStatus(t *testing.T) {
lpa := &shared.Lpa{
Status: shared.LpaStatusRegistered,
}
Expand All @@ -41,7 +54,19 @@ func TestOpgChangeStatusIncorrectExistingStatus(t *testing.T) {
}

errors := c.Apply(lpa)
assert.Equal(t, errors, []shared.FieldError{{Source: "/status", Detail: "Lpa status cannot be registered"}})
assert.Equal(t, errors, []shared.FieldError{{Source: "/status", Detail: "Lpa status cannot be registered while changing to cannot register"}})
}

func TestOpgChangeStatusToCancelledIncorrectExistingStatus(t *testing.T) {
lpa := &shared.Lpa{
Status: shared.LpaStatusInProgress,
}
c := OpgChangeStatus{
Status: shared.LpaStatusCancelled,
}

errors := c.Apply(lpa)
assert.Equal(t, errors, []shared.FieldError{{Source: "/status", Detail: "Lpa status has to be registered while changing to cancelled"}})
}

func TestValidateUpdateOPGChangeStatus(t *testing.T) {
Expand Down

0 comments on commit ce5b69a

Please sign in to comment.