Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

VEGA-2500 : Handle manual change to cancelled status #minor #271

Merged
merged 1 commit into from
Oct 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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