Skip to content

Commit

Permalink
VEGA-2638 : Handle Do Not Register status update #minor (#273)
Browse files Browse the repository at this point in the history
* VEGA-2638 : Handle Do Not Register status update

* VEGA-2638 : Corrected the test case
  • Loading branch information
ndasmoj authored Nov 6, 2024
1 parent be3acef commit 6d39560
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 @@ -59,8 +59,9 @@ const (
LpaStatusCannotRegister = LpaStatus("cannot-register")
LpaStatusWithdrawn = LpaStatus("withdrawn")
LpaStatusCancelled = LpaStatus("cancelled")
LpaStatusDoNotRegister = LpaStatus("do-not-register")
)

func (l LpaStatus) IsValid() bool {
return l == LpaStatusInProgress || l == LpaStatusStatutoryWaitingPeriod || l == LpaStatusRegistered || l == LpaStatusCannotRegister || l == LpaStatusWithdrawn || l == LpaStatusCancelled
return l == LpaStatusInProgress || l == LpaStatusStatutoryWaitingPeriod || l == LpaStatusRegistered || l == LpaStatusCannotRegister || l == LpaStatusWithdrawn || l == LpaStatusCancelled || l == LpaStatusDoNotRegister
}
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 {
return []shared.FieldError{{Source: "/status", Detail: "Status to be updated should be cannot register or cancelled"}}
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 && lpa.Status == shared.LpaStatusRegistered {
Expand All @@ -28,6 +28,10 @@ func (r OpgChangeStatus) Apply(lpa *shared.Lpa) []shared.FieldError {
return []shared.FieldError{{Source: "/status", Detail: "Lpa status has to be registered while changing to cancelled"}}
}

if r.Status == shared.LpaStatusDoNotRegister && lpa.Status != shared.LpaStatusStatutoryWaitingPeriod {
return []shared.FieldError{{Source: "/status", Detail: "Lpa status has to be statutory waiting period while changing to do not register"}}
}

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 @@ -33,6 +33,19 @@ func TestOpgChangeStatusToCancelledApply(t *testing.T) {
assert.Equal(t, c.Status, lpa.Status)
}

func TestOpgChangeStatusToDoNotRegisterApply(t *testing.T) {
lpa := &shared.Lpa{
Status: shared.LpaStatusStatutoryWaitingPeriod,
}
c := OpgChangeStatus{
Status: shared.LpaStatusDoNotRegister,
}

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 @@ -42,7 +55,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 or cancelled"}})
assert.Equal(t, errors, []shared.FieldError{{Source: "/status", Detail: "Status to be updated should be cannot register, cancelled or do not register"}})
}

func TestOpgChangeStatusToCannotRegisterIncorrectExistingStatus(t *testing.T) {
Expand All @@ -69,6 +82,18 @@ func TestOpgChangeStatusToCancelledIncorrectExistingStatus(t *testing.T) {
assert.Equal(t, errors, []shared.FieldError{{Source: "/status", Detail: "Lpa status has to be registered while changing to cancelled"}})
}

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

errors := c.Apply(lpa)
assert.Equal(t, errors, []shared.FieldError{{Source: "/status", Detail: "Lpa status has to be statutory waiting period while changing to do not register"}})
}

func TestValidateUpdateOPGChangeStatus(t *testing.T) {
testcases := map[string]struct {
update shared.Update
Expand Down

0 comments on commit 6d39560

Please sign in to comment.