From ce5b69ad0b31fa994e904bd17ed6429949d77547 Mon Sep 17 00:00:00 2001 From: ndasmoj <146009864+ndasmoj@users.noreply.github.com> Date: Fri, 25 Oct 2024 13:14:24 +0100 Subject: [PATCH] VEGA-2500 : Handle manual change to cancelled status (#271) --- lambda/update/opg_change_status.go | 16 +++++++----- lambda/update/opg_change_status_test.go | 33 ++++++++++++++++++++++--- 2 files changed, 39 insertions(+), 10 deletions(-) diff --git a/lambda/update/opg_change_status.go b/lambda/update/opg_change_status.go index 130082bc..917b4ee3 100644 --- a/lambda/update/opg_change_status.go +++ b/lambda/update/opg_change_status.go @@ -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 diff --git a/lambda/update/opg_change_status_test.go b/lambda/update/opg_change_status_test.go index ef83796a..cba1bf5f 100644 --- a/lambda/update/opg_change_status_test.go +++ b/lambda/update/opg_change_status_test.go @@ -7,7 +7,7 @@ import ( "testing" ) -func TestOpgChangeStatusApply(t *testing.T) { +func TestOpgChangeStatusToCannotRegisterApply(t *testing.T) { lpa := &shared.Lpa{ Status: shared.LpaStatusInProgress, } @@ -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, @@ -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, } @@ -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) {