-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
VEGA-2501 : Manual Status Change #minor (#264)
* VEGA-2501 : Initial changes to update the status * VEGA-2501 : New file to update the status * VEGA-2501 : Updates to handle the status change update * VEGA-2501 : Corrected the error field type * VEGA-2501 : Reverted the port number for apigw service * VEGA-2501 : Update the change type
- Loading branch information
Showing
6 changed files
with
163 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
{ | ||
"type": "OPG_STATUS_CHANGE", | ||
"changes": [ | ||
{ | ||
"key": "/status", | ||
"new": "cannot-register", | ||
"old": "in-progress" | ||
} | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
package main | ||
|
||
import ( | ||
"github.com/ministryofjustice/opg-data-lpa-store/internal/shared" | ||
"github.com/ministryofjustice/opg-data-lpa-store/internal/validate" | ||
"github.com/ministryofjustice/opg-data-lpa-store/lambda/update/parse" | ||
) | ||
|
||
type OpgChangeStatus struct { | ||
Status shared.LpaStatus | ||
} | ||
|
||
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 lpa.Status == shared.LpaStatusRegistered { | ||
return []shared.FieldError{{Source: "/status", Detail: "Lpa status cannot be registered"}} | ||
} | ||
|
||
if lpa.Status == shared.LpaStatusCancelled { | ||
return []shared.FieldError{{Source: "/status", Detail: "Lpa status cannot be cancelled"}} | ||
} | ||
|
||
lpa.Status = r.Status | ||
|
||
return nil | ||
} | ||
|
||
func validateOpgChangeStatus(changes []shared.Change, lpa *shared.Lpa) (OpgChangeStatus, []shared.FieldError) { | ||
|
||
var data OpgChangeStatus | ||
|
||
data.Status = lpa.Status | ||
|
||
errors := parse.Changes(changes). | ||
Field("/status", &data.Status, parse.Validate(func() []shared.FieldError { | ||
return validate.IsValid("", data.Status) | ||
})). | ||
Consumed() | ||
|
||
return data, errors | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
package main | ||
|
||
import ( | ||
"encoding/json" | ||
"github.com/ministryofjustice/opg-data-lpa-store/internal/shared" | ||
"github.com/stretchr/testify/assert" | ||
"testing" | ||
) | ||
|
||
func TestOpgChangeStatusApply(t *testing.T) { | ||
lpa := &shared.Lpa{ | ||
Status: shared.LpaStatusInProgress, | ||
} | ||
c := OpgChangeStatus{ | ||
Status: shared.LpaStatusCannotRegister, | ||
} | ||
|
||
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, | ||
} | ||
c := OpgChangeStatus{ | ||
Status: shared.LpaStatusWithdrawn, | ||
} | ||
|
||
errors := c.Apply(lpa) | ||
assert.Equal(t, errors, []shared.FieldError{{Source: "/status", Detail: "Status to be updated should be cannot register"}}) | ||
} | ||
|
||
func TestOpgChangeStatusIncorrectExistingStatus(t *testing.T) { | ||
lpa := &shared.Lpa{ | ||
Status: shared.LpaStatusRegistered, | ||
} | ||
c := OpgChangeStatus{ | ||
Status: shared.LpaStatusCannotRegister, | ||
} | ||
|
||
errors := c.Apply(lpa) | ||
assert.Equal(t, errors, []shared.FieldError{{Source: "/status", Detail: "Lpa status cannot be registered"}}) | ||
} | ||
|
||
func TestValidateUpdateOPGChangeStatus(t *testing.T) { | ||
testcases := map[string]struct { | ||
update shared.Update | ||
lpa *shared.Lpa | ||
errors []shared.FieldError | ||
}{ | ||
"valid - with previous values": { | ||
update: shared.Update{ | ||
Type: "OPG_STATUS_CHANGE", | ||
Changes: []shared.Change{ | ||
{ | ||
Key: "/status", | ||
New: json.RawMessage(`"cannot-register"`), | ||
Old: json.RawMessage(`"in-progress"`), | ||
}, | ||
}, | ||
}, | ||
lpa: &shared.Lpa{ | ||
Status: shared.LpaStatusInProgress, | ||
}, | ||
}, | ||
"invalid status": { | ||
update: shared.Update{ | ||
Type: "OPG_STATUS_CHANGE", | ||
Changes: []shared.Change{ | ||
{ | ||
Key: "/status", | ||
New: json.RawMessage(`"never-register"`), | ||
Old: json.RawMessage(`"in-progress"`), | ||
}, | ||
}, | ||
}, | ||
lpa: &shared.Lpa{ | ||
Status: shared.LpaStatusInProgress, | ||
}, | ||
errors: []shared.FieldError{ | ||
{Source: "/changes/0/new", Detail: "invalid value"}, | ||
}, | ||
}, | ||
} | ||
|
||
for name, tc := range testcases { | ||
t.Run(name, func(t *testing.T) { | ||
_, errors := validateUpdate(tc.update, tc.lpa) | ||
assert.ElementsMatch(t, tc.errors, errors) | ||
}) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters