Skip to content

Commit

Permalink
VEGA-2661 : Handle manual update of Expired status
Browse files Browse the repository at this point in the history
  • Loading branch information
ndasmoj committed Nov 7, 2024
1 parent 6d39560 commit 9c1780b
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 4 deletions.
3 changes: 2 additions & 1 deletion internal/shared/lpa.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
8 changes: 6 additions & 2 deletions lambda/update/opg_change_status.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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
Expand Down
27 changes: 26 additions & 1 deletion lambda/update/opg_change_status_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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) {
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 9c1780b

Please sign in to comment.