From 9c1780bd2b7648184804d373020ba4314d6b0005 Mon Sep 17 00:00:00 2001 From: Niladri Das Date: Thu, 7 Nov 2024 10:18:56 +0000 Subject: [PATCH] VEGA-2661 : Handle manual update of Expired status --- internal/shared/lpa.go | 3 ++- lambda/update/opg_change_status.go | 8 ++++++-- lambda/update/opg_change_status_test.go | 27 ++++++++++++++++++++++++- 3 files changed, 34 insertions(+), 4 deletions(-) diff --git a/internal/shared/lpa.go b/internal/shared/lpa.go index 0343a4b7..6069f63c 100644 --- a/internal/shared/lpa.go +++ b/internal/shared/lpa.go @@ -60,8 +60,9 @@ const ( LpaStatusWithdrawn = LpaStatus("withdrawn") LpaStatusCancelled = LpaStatus("cancelled") LpaStatusDoNotRegister = LpaStatus("do-not-register") + LpaStatusExpired = LpaStatus("expired") ) func (l LpaStatus) IsValid() bool { - return l == LpaStatusInProgress || l == LpaStatusStatutoryWaitingPeriod || l == LpaStatusRegistered || l == LpaStatusCannotRegister || l == LpaStatusWithdrawn || l == LpaStatusCancelled || l == LpaStatusDoNotRegister + return l == LpaStatusInProgress || l == LpaStatusStatutoryWaitingPeriod || l == LpaStatusRegistered || l == LpaStatusCannotRegister || l == LpaStatusWithdrawn || l == LpaStatusCancelled || l == LpaStatusDoNotRegister || l == LpaStatusExpired } diff --git a/lambda/update/opg_change_status.go b/lambda/update/opg_change_status.go index 9fc04f2c..16fd5c3b 100644 --- a/lambda/update/opg_change_status.go +++ b/lambda/update/opg_change_status.go @@ -12,8 +12,8 @@ type OpgChangeStatus struct { func (r OpgChangeStatus) Apply(lpa *shared.Lpa) []shared.FieldError { - if r.Status != shared.LpaStatusCannotRegister && r.Status != shared.LpaStatusCancelled && r.Status != shared.LpaStatusDoNotRegister { - return []shared.FieldError{{Source: "/status", Detail: "Status to be updated should be cannot register, cancelled or do not register"}} + if r.Status != shared.LpaStatusCannotRegister && r.Status != shared.LpaStatusCancelled && r.Status != shared.LpaStatusDoNotRegister && r.Status != shared.LpaStatusExpired { + return []shared.FieldError{{Source: "/status", Detail: "Status to be updated should be cannot register, cancelled, do not register or expired"}} } if r.Status == shared.LpaStatusCannotRegister && lpa.Status == shared.LpaStatusRegistered { @@ -32,6 +32,10 @@ func (r OpgChangeStatus) Apply(lpa *shared.Lpa) []shared.FieldError { return []shared.FieldError{{Source: "/status", Detail: "Lpa status has to be statutory waiting period while changing to do not register"}} } + if r.Status == shared.LpaStatusExpired && lpa.Status != shared.LpaStatusInProgress && lpa.Status != shared.LpaStatusStatutoryWaitingPeriod && lpa.Status != shared.LpaStatusDoNotRegister { + return []shared.FieldError{{Source: "/status", Detail: "Lpa status has to be in progress, statutory waiting period or do not register while changing to expired"}} + } + lpa.Status = r.Status return nil diff --git a/lambda/update/opg_change_status_test.go b/lambda/update/opg_change_status_test.go index ecf2f542..0907d5a4 100644 --- a/lambda/update/opg_change_status_test.go +++ b/lambda/update/opg_change_status_test.go @@ -46,6 +46,19 @@ func TestOpgChangeStatusToDoNotRegisterApply(t *testing.T) { assert.Equal(t, c.Status, lpa.Status) } +func TestOpgChangeStatusToExpiredApply(t *testing.T) { + lpa := &shared.Lpa{ + Status: shared.LpaStatusStatutoryWaitingPeriod, + } + c := OpgChangeStatus{ + Status: shared.LpaStatusExpired, + } + + 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, @@ -55,7 +68,7 @@ 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, cancelled or do not register"}}) + assert.Equal(t, errors, []shared.FieldError{{Source: "/status", Detail: "Status to be updated should be cannot register, cancelled, do not register or expired"}}) } func TestOpgChangeStatusToCannotRegisterIncorrectExistingStatus(t *testing.T) { @@ -94,6 +107,18 @@ func TestOpgChangeStatusToDoNotRegisterIncorrectExistingStatus(t *testing.T) { assert.Equal(t, errors, []shared.FieldError{{Source: "/status", Detail: "Lpa status has to be statutory waiting period while changing to do not register"}}) } +func TestOpgChangeStatusToExpiredIncorrectExistingStatus(t *testing.T) { + lpa := &shared.Lpa{ + Status: shared.LpaStatusRegistered, + } + c := OpgChangeStatus{ + Status: shared.LpaStatusExpired, + } + + errors := c.Apply(lpa) + assert.Equal(t, errors, []shared.FieldError{{Source: "/status", Detail: "Lpa status has to be in progress, statutory waiting period or do not register while changing to expired"}}) +} + func TestValidateUpdateOPGChangeStatus(t *testing.T) { testcases := map[string]struct { update shared.Update