Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MLPAB-1552: Attorney moving from paper to online #179

Merged
merged 7 commits into from
Apr 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -23,18 +23,29 @@ test-api:
$(eval LPA_UID := "$(shell ./api-test/tester UID)")
$(eval TMPFILE := "$(shell mktemp)")

# JWT required
JWT_SECRET_KEY=bad ./api-test/tester -expectedStatus=401 REQUEST PUT $(URL)/lpas/$(LPA_UID) '{"version":"1"}'
JWT_SECRET_KEY=bad ./api-test/tester -expectedStatus=401 REQUEST POST $(URL)/lpas/$(LPA_UID)/updates '{"type":"BUMP_VERSION","changes":[{"key":"/version","old":"1","new":"2"}]}'
JWT_SECRET_KEY=bad ./api-test/tester -expectedStatus=401 REQUEST GET $(URL)/lpas/$(LPA_UID) ''

# create
cat ./docs/example-lpa.json | ./api-test/tester -expectedStatus=201 REQUEST PUT $(URL)/lpas/$(LPA_UID) "`xargs -0`"
./api-test/tester -expectedStatus=200 -write REQUEST GET $(URL)/lpas/$(LPA_UID) '' > $(TMPFILE)

# missing fields
diff <(jq --sort-keys 'del(.status,.uid,.updatedAt)' < $(TMPFILE)) <(jq --sort-keys . < docs/example-lpa.json)
./api-test/tester -expectedStatus=400 REQUEST PUT $(URL)/lpas/$(LPA_UID) '{"version":"2"}'

# certificate provider sign
cat ./docs/certificate-provider-change.json | ./api-test/tester -expectedStatus=201 REQUEST POST $(URL)/lpas/$(LPA_UID)/updates "`xargs -0`"

# attorney sign
cat ./docs/attorney-change.json | ./api-test/tester -expectedStatus=201 REQUEST POST $(URL)/lpas/$(LPA_UID)/updates "`xargs -0`"

# get lpa
./api-test/tester -expectedStatus=200 REQUEST GET $(URL)/lpas/$(LPA_UID) ''

# get lpas
./api-test/tester -expectedStatus=200 REQUEST POST $(URL)/lpas '{"uids": [$(LPA_UID)]}'
.PHONY: test-api

Expand Down
30 changes: 30 additions & 0 deletions docs/attorney-change.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
{
"type": "ATTORNEY_SIGN",
"changes": [
{
"key": "/attorneys/0/mobile",
"new": "07700900000",
"old": null
},
{
"key": "/attorneys/0/signedAt",
"new": "2024-01-13T22:00:00Z",
"old": null
},
{
"key": "/attorneys/0/contactLanguagePreference",
"new": "en",
"old": null
},
{
"key": "/attorneys/0/channel",
"new": "online",
"old": "paper"
},
{
"key": "/attorneys/0/email",
"new": "[email protected]",
"old": "[email protected]"
}
]
}
5 changes: 3 additions & 2 deletions docs/example-lpa.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,9 @@
"country": "GB"
},
"dateOfBirth": "1982-07-24",
"email": "[email protected]",
"status": "active"
"email": "[email protected]",
"status": "active",
"channel": "paper"
}
],
"certificateProvider": {
Expand Down
6 changes: 5 additions & 1 deletion docs/schemas/2024-04/donor-details.json
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@
}
],
"type": "object",
"required": ["dateOfBirth", "email", "status"],
"required": ["dateOfBirth", "status"],
"properties": {
"dateOfBirth": {
"type": "string",
Expand All @@ -225,6 +225,10 @@
"status": {
"type": "string",
"enum": ["active", "replacement", "removed"]
},
"channel": {
"type": "string",
"enum": ["paper", "online"]
}
}
},
Expand Down
1 change: 1 addition & 0 deletions internal/shared/person.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ type Attorney struct {
Mobile string `json:"mobile,omitempty"`
SignedAt *time.Time `json:"signedAt,omitempty"`
ContactLanguagePreference Lang `json:"contactLanguagePreference,omitempty"`
Channel Channel `json:"channel"`
}

type TrustCorporation struct {
Expand Down
1 change: 1 addition & 0 deletions lambda/create/validate_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -336,6 +336,7 @@ func TestValidateLpaValid(t *testing.T) {
},
DateOfBirth: newDate("1977-10-30"),
Status: shared.AttorneyStatusActive,
Channel: shared.ChannelOnline,
},
},
CertificateProvider: shared.CertificateProvider{
Expand Down
8 changes: 8 additions & 0 deletions lambda/update/attorney_sign.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ type AttorneySign struct {
Mobile string
SignedAt time.Time
ContactLanguagePreference shared.Lang
Channel shared.Channel
Email string
}

func (a AttorneySign) Apply(lpa *shared.Lpa) []shared.FieldError {
Expand All @@ -23,6 +25,8 @@ func (a AttorneySign) Apply(lpa *shared.Lpa) []shared.FieldError {
lpa.Attorneys[*a.Index].Mobile = a.Mobile
lpa.Attorneys[*a.Index].SignedAt = &a.SignedAt
lpa.Attorneys[*a.Index].ContactLanguagePreference = a.ContactLanguagePreference
lpa.Attorneys[*a.Index].Channel = a.Channel
lpa.Attorneys[*a.Index].Email = a.Email

return nil
}
Expand All @@ -47,6 +51,10 @@ func validateAttorneySign(changes []shared.Change) (AttorneySign, []shared.Field
Field("/contactLanguagePreference", &data.ContactLanguagePreference, parse.Validate(func() []shared.FieldError {
return validate.IsValid("", data.ContactLanguagePreference)
})).
Field("/channel", &data.Channel, parse.Validate(func() []shared.FieldError {
return validate.IsValid("", data.Channel)
}), parse.Optional()).
Field("/email", &data.Email, parse.Optional()).
Consumed()
}).
Consumed()
Expand Down
72 changes: 70 additions & 2 deletions lambda/update/attorney_sign_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,15 @@ func TestAttorneySignApply(t *testing.T) {
Mobile: "0777",
SignedAt: time.Now(),
ContactLanguagePreference: shared.LangCy,
Channel: shared.ChannelOnline,
}

errors := a.Apply(lpa)
assert.Empty(t, errors)
assert.Equal(t, a.Mobile, lpa.Attorneys[attorneyIndex].Mobile)
assert.Equal(t, a.SignedAt, *lpa.Attorneys[attorneyIndex].SignedAt)
assert.Equal(t, a.ContactLanguagePreference, lpa.Attorneys[attorneyIndex].ContactLanguagePreference)
assert.Equal(t, a.Channel, lpa.Attorneys[attorneyIndex].Channel)
}

func TestAttorneySignApplyWhenAlreadySigned(t *testing.T) {
Expand All @@ -43,11 +45,14 @@ func TestAttorneySignApplyWhenAlreadySigned(t *testing.T) {
}

func TestValidateUpdateAttorneySign(t *testing.T) {
now := time.Now()
yesterday := time.Now()

testcases := map[string]struct {
update shared.Update
errors []shared.FieldError
}{
"valid": {
"valid - no previous values": {
update: shared.Update{
Type: "ATTORNEY_SIGN",
Changes: []shared.Change{
Expand All @@ -66,6 +71,48 @@ func TestValidateUpdateAttorneySign(t *testing.T) {
New: json.RawMessage(`"cy"`),
Old: jsonNull,
},
{
Key: "/attorneys/1/channel",
New: json.RawMessage(`"online"`),
Old: jsonNull,
},
{
Key: "/attorneys/1/email",
New: json.RawMessage(`"[email protected]"`),
Old: jsonNull,
},
},
},
},
"valid - with previous values": {
update: shared.Update{
Type: "ATTORNEY_SIGN",
Changes: []shared.Change{
{
Key: "/attorneys/1/mobile",
New: json.RawMessage(`"07777"`),
Old: json.RawMessage(`"06666"`),
},
{
Key: "/attorneys/1/signedAt",
New: json.RawMessage(`"` + now.Format(time.RFC3339) + `"`),
Old: json.RawMessage(`"` + yesterday.Format(time.RFC3339) + `"`),
},
{
Key: "/attorneys/1/contactLanguagePreference",
New: json.RawMessage(`"cy"`),
Old: jsonNull,
},
{
Key: "/attorneys/1/channel",
New: json.RawMessage(`"online"`),
Old: json.RawMessage(`"paper"`),
},
{
Key: "/attorneys/1/email",
New: json.RawMessage(`"[email protected]"`),
Old: json.RawMessage(`"[email protected]"`),
},
},
},
},
Expand Down Expand Up @@ -104,14 +151,19 @@ func TestValidateUpdateAttorneySign(t *testing.T) {
New: json.RawMessage(`"John"`),
Old: jsonNull,
},
{
Key: "/attorneys/1/email",
New: json.RawMessage(`"[email protected]"`),
Old: jsonNull,
},
},
},
errors: []shared.FieldError{
{Source: "/changes/3", Detail: "unexpected change provided"},
{Source: "/changes/4", Detail: "unexpected change provided"},
},
},
"invalid contact language": {
"invalid contact language and channel": {
update: shared.Update{
Type: "ATTORNEY_SIGN",
Changes: []shared.Change{
Expand All @@ -130,10 +182,21 @@ func TestValidateUpdateAttorneySign(t *testing.T) {
New: json.RawMessage(`"xy"`),
Old: jsonNull,
},
{
Key: "/attorneys/1/channel",
New: json.RawMessage(`"digital"`),
Old: jsonNull,
},
{
Key: "/attorneys/1/email",
New: json.RawMessage(`"[email protected]"`),
Old: jsonNull,
},
},
},
errors: []shared.FieldError{
{Source: "/changes/2/new", Detail: "invalid value"},
{Source: "/changes/3/new", Detail: "invalid value"},
},
},
"multiple attorneys": {
Expand All @@ -155,6 +218,11 @@ func TestValidateUpdateAttorneySign(t *testing.T) {
New: json.RawMessage(`"` + shared.LangCy + `"`),
Old: jsonNull,
},
{
Key: "/attorneys/0/email",
New: json.RawMessage(`"[email protected]"`),
Old: jsonNull,
},
},
},
errors: []shared.FieldError{
Expand Down
3 changes: 2 additions & 1 deletion mock-apigw/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,8 @@ func handlePactState(r *http.Request) error {
"line1": "71 South Western Terrace",
"town": "Milton",
"country": "AU"
}
},
"channel": "paper"
}
],
"certificateProvider": {
Expand Down
Loading