Skip to content

Commit

Permalink
MLPAB-2088: Conditionally send Channel and Email for TRUST_CORPORATIO…
Browse files Browse the repository at this point in the history
…N_SIGN (#1210)
  • Loading branch information
acsauk authored May 2, 2024
1 parent a6d1c26 commit 012cd40
Show file tree
Hide file tree
Showing 16 changed files with 189 additions and 28 deletions.
2 changes: 0 additions & 2 deletions cypress/e2e/donor/enter-replacement-trust-corporation.cy.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,10 @@ describe('Enter replacement trust corporation', () => {
cy.get('.govuk-error-summary').within(() => {
cy.contains('Enter company name');
cy.contains('Enter company number');
cy.contains('Enter company email address');
});

cy.contains('[for=f-name] + .govuk-error-message', 'Enter company name');
cy.contains('[for=f-company-number] + div + .govuk-error-message', 'Enter company number');
cy.contains('[for=f-email] + div + .govuk-error-message', 'Enter company email address');
});

it('errors when invalid email', () => {
Expand Down
2 changes: 0 additions & 2 deletions cypress/e2e/donor/enter-trust-corporation.cy.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,10 @@ describe('Enter trust corporation', () => {
cy.get('.govuk-error-summary').within(() => {
cy.contains('Enter company name');
cy.contains('Enter company number');
cy.contains('Enter company email address');
});

cy.contains('[for=f-name] + .govuk-error-message', 'Enter company name');
cy.contains('[for=f-company-number] + div + .govuk-error-message', 'Enter company number');
cy.contains('[for=f-email] + div + .govuk-error-message', 'Enter company email address');
});

it('errors when invalid email', () => {
Expand Down
8 changes: 8 additions & 0 deletions internal/actor/attorney.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,14 @@ type TrustCorporation struct {
Address place.Address
}

func (tc TrustCorporation) Channel() Channel {
if tc.Email != "" {
return ChannelOnline
}

return ChannelPaper
}

type Attorneys struct {
TrustCorporation TrustCorporation
Attorneys []Attorney
Expand Down
5 changes: 5 additions & 0 deletions internal/actor/attorney_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -243,3 +243,8 @@ func TestAttorneysNames(t *testing.T) {
})
}
}

func TestTrustCorporationChannel(t *testing.T) {
assert.Equal(t, ChannelOnline, TrustCorporation{Email: "[email protected]"}.Channel())
assert.Equal(t, ChannelPaper, TrustCorporation{}.Channel())
}
140 changes: 133 additions & 7 deletions internal/lpastore/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,22 @@ func TestClientServiceContract(t *testing.T) {
"postcode": matchers.String("A1 1FF"),
"country": matchers.String("GB"),
}),
"channel": matchers.Regex("online", "online|post"),
"channel": matchers.Regex("online", "online|paper"),
"status": matchers.Regex("active", "active|replacement"),
}, 1),
"trustCorporations": matchers.EachLike(map[string]any{
"uid": matchers.UUID(),
"name": matchers.String("Trust us Corp."),
"companyNumber": matchers.String("66654321"),
"address": matchers.Like(map[string]any{
"line1": matchers.String("tc-line-1"),
"line2": matchers.String("tc-line-2"),
"line3": matchers.String("tc-line-3"),
"town": matchers.String("tc-town"),
"postcode": matchers.String("TC1 1FF"),
"country": matchers.String("GB"),
}),
"channel": matchers.Regex("paper", "online|paper"),
"status": matchers.Regex("active", "active|replacement"),
}, 1),
"certificateProvider": matchers.Like(map[string]any{
Expand All @@ -127,17 +142,18 @@ func TestClientServiceContract(t *testing.T) {
"email": matchers.String("[email protected]"),
"phone": matchers.String("0700009000"),
"address": matchers.Like(map[string]any{
"line1": matchers.String("a-line-1"),
"line2": matchers.String("a-line-2"),
"line3": matchers.String("a-line-3"),
"town": matchers.String("a-town"),
"postcode": matchers.String("A1 1FF"),
"line1": matchers.String("cp-line-1"),
"line2": matchers.String("cp-line-2"),
"line3": matchers.String("cp-line-3"),
"town": matchers.String("cp-town"),
"postcode": matchers.String("CP1 1FF"),
"country": matchers.String("GB"),
}),
"channel": matchers.Regex("online", "online|post"),
"channel": matchers.Regex("online", "online|paper"),
}),
"restrictionsAndConditions": matchers.String("hmm"),
"signedAt": matchers.Regex("2000-01-02T12:13:14.00000Z", `\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}(.\d+)?Z`),
"howAttorneysMakeDecisions": matchers.Regex("jointly", "jointly|jointly-and-severally|jointly-for-some-severally-for-others"),
})
}).
WillRespondWith(http.StatusCreated, func(b *consumer.V2ResponseBuilder) {
Expand Down Expand Up @@ -182,7 +198,14 @@ func TestClientServiceContract(t *testing.T) {
Email: "[email protected]",
Address: address,
}},
TrustCorporation: actor.TrustCorporation{
UID: actoruid.New(),
Name: "Trust us Corp.",
CompanyNumber: "66654321",
Address: address,
},
},
AttorneyDecisions: actor.AttorneyDecisions{How: actor.Jointly},
ReplacementAttorneys: actor.Attorneys{
Attorneys: []actor.Attorney{{
UID: actoruid.New(),
Expand Down Expand Up @@ -447,6 +470,109 @@ func TestClientServiceContract(t *testing.T) {
}))
})

t.Run("SendAttorney when trust corporation", func(t *testing.T) {
uid := actoruid.New()

mockProvider.
AddInteraction().
Given("An LPA with UID M-0000-1111-2222 exists").
UponReceiving("A request to send the trust corporation data").
WithRequest(http.MethodPost, "/lpas/M-0000-1111-2222/updates", func(b *consumer.V2RequestBuilder) {
b.
// Header("Content-Type", matchers.String("application/json")).
// Header("Authorization", matchers.Regex("AWS4-HMAC-SHA256 Credential=abc/20000102/eu-west-1/execute-api/aws4_request, SignedHeaders=content-length;content-type;host;x-amz-date;x-jwt-authorization, Signature=3fe9cd4a65c746d7531c3f3d9ae4479eec81886f5b6863680fcf7cf804aa4d6b", "AWS4-HMAC-SHA256 .*")).
// Header("X-Amz-Date", matchers.String("20000102T000000Z")).
// Header("X-Jwt-Authorization", matchers.Regex("Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJvcGcucG9hcy5tYWtlcmVnaXN0ZXIiLCJzdWIiOiJ0b2RvIiwiaWF0Ijo5NDY3NzEyMDB9.teh381oIhucqUD3EhBTaaBTLFI1O2FOWGe-44Ftk0LY", "Bearer .+")).
JSONBody(matchers.Map{
"type": matchers.Like("TRUST_CORPORATION_SIGN"),
"changes": matchers.Like([]map[string]any{{
"key": matchers.Like("/trustCorporations/0/mobile"),
"old": matchers.Like(nil),
"new": matchers.Like("07777777"),
}, {
"key": matchers.Like("/trustCorporations/0/contactLanguagePreference"),
"old": matchers.Like(nil),
"new": matchers.Like("cy"),
}, {
"key": matchers.Like("/trustCorporations/0/email"),
"old": matchers.Like("[email protected]"),
"new": matchers.Like("[email protected]"),
}, {
"key": matchers.Like("/trustCorporations/0/channel"),
"old": matchers.Like("paper"),
"new": matchers.Like("online"),
}, {
"key": matchers.Like("/trustCorporations/0/signatories/0/firstNames"),
"old": matchers.Like(nil),
"new": matchers.Like("John"),
}, {
"key": matchers.Like("/trustCorporations/0/signatories/0/lastName"),
"old": matchers.Like(nil),
"new": matchers.Like("Smith"),
}, {
"key": matchers.Like("/trustCorporations/0/signatories/0/professionalTitle"),
"old": matchers.Like(nil),
"new": matchers.Like("Director"),
}, {
"key": matchers.Like("/trustCorporations/0/signatories/0/signedAt"),
"old": matchers.Like(nil),
"new": matchers.Like("2020-01-01T12:13:14Z"),
}}),
})
}).
WillRespondWith(http.StatusCreated, func(b *consumer.V2ResponseBuilder) {
// b.Header("Content-Type", matchers.String("application/json"))
b.JSONBody(matchers.Map{})
})

assert.Nil(t, mockProvider.ExecuteTest(t, func(config consumer.MockServerConfig) error {
baseURL := fmt.Sprintf("http://%s:%d", config.Host, config.Port)

secretsClient := newMockSecretsClient(t)
secretsClient.EXPECT().
Secret(mock.Anything, mock.Anything).
Return("secret", nil)

client := &Client{
baseURL: baseURL,
secretsClient: secretsClient,
doer: lambda.New(cfg, v4.NewSigner(), http.DefaultClient, now),
now: now,
}

err := client.SendAttorney(context.Background(),
&Lpa{
LpaUID: "M-0000-1111-2222",
Attorneys: Attorneys{
TrustCorporation: TrustCorporation{
UID: uid,
Name: "Trust us Corp.",
CompanyNumber: "66654321",
Email: "[email protected]",
Channel: actor.ChannelPaper,
},
},
},
&actor.AttorneyProvidedDetails{
UID: uid,
Mobile: "07777777",
ContactLanguagePreference: localize.Cy,
AuthorisedSignatories: [2]actor.TrustCorporationSignatory{
{
FirstNames: "John",
LastName: "Smith",
ProfessionalTitle: "Director",
Confirmed: time.Date(2020, time.January, 1, 12, 13, 14, 0, time.UTC),
},
},
IsTrustCorporation: true,
Email: "[email protected]",
})
assert.Nil(t, err)
return nil
}))
})

t.Run("SendCertificateProvider", func(t *testing.T) {
mockProvider.
AddInteraction().
Expand Down
7 changes: 6 additions & 1 deletion internal/lpastore/lpa.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,9 +63,10 @@ type lpaRequestTrustCorporation struct {
UID actoruid.UID `json:"uid"`
Name string `json:"name"`
CompanyNumber string `json:"companyNumber"`
Email string `json:"email"`
Email string `json:"email,omitempty"`
Address place.Address `json:"address"`
Status string `json:"status"`
Channel actor.Channel `json:"channel"`
}

type lpaRequestCertificateProvider struct {
Expand Down Expand Up @@ -158,6 +159,7 @@ func (c *Client) SendLpa(ctx context.Context, donor *actor.DonorProvidedDetails)
Email: trustCorporation.Email,
Address: trustCorporation.Address,
Status: statusActive,
Channel: trustCorporation.Channel(),
})
}

Expand All @@ -182,6 +184,7 @@ func (c *Client) SendLpa(ctx context.Context, donor *actor.DonorProvidedDetails)
Email: trustCorporation.Email,
Address: trustCorporation.Address,
Status: statusReplacement,
Channel: trustCorporation.Channel(),
})
}

Expand Down Expand Up @@ -262,6 +265,7 @@ type TrustCorporation struct {
Mobile string
Signatories []TrustCorporationSignatory
ContactLanguagePreference localize.Lang
Channel actor.Channel
}

type TrustCorporationSignatory struct {
Expand Down Expand Up @@ -446,6 +450,7 @@ func lpaResponseToLpa(l lpaResponse) *Lpa {
Mobile: t.Mobile,
Signatories: t.Signatories,
ContactLanguagePreference: t.ContactLanguagePreference,
Channel: t.Channel,
}

if t.Status == "replacement" {
Expand Down
12 changes: 6 additions & 6 deletions internal/lpastore/lpa_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,6 @@ func TestClientSendLpa(t *testing.T) {
UID: replacementTrustCorporationUID,
Name: "UnTrusty",
CompanyNumber: "65555",
Email: "[email protected]",
Address: place.Address{
Line1: "a-line-1",
Line2: "a-line-2",
Expand Down Expand Up @@ -253,8 +252,8 @@ func TestClientSendLpa(t *testing.T) {
{"uid":"` + replacementAttorney2UID.String() + `","firstNames":"Rachel","lastName":"Attorney","dateOfBirth":"1998-11-12","email":"[email protected]","address":{"line1":"rr-line-1","line2":"rr-line-2","line3":"rr-line-3","town":"rr-town","postcode":"R1 1RF","country":"GB"},"status":"replacement","channel":"online"}
],
"trustCorporations":[
{"uid":"` + trustCorporationUID.String() + `","name":"Trusty","companyNumber":"55555","email":"[email protected]","address":{"line1":"a-line-1","line2":"a-line-2","line3":"a-line-3","town":"a-town","postcode":"A1 1FF","country":"GB"},"status":"active"},
{"uid":"` + replacementTrustCorporationUID.String() + `","name":"UnTrusty","companyNumber":"65555","email":"[email protected]","address":{"line1":"a-line-1","line2":"a-line-2","line3":"a-line-3","town":"a-town","postcode":"A1 1FF","country":"GB"},"status":"replacement"}
{"uid":"` + trustCorporationUID.String() + `","name":"Trusty","companyNumber":"55555","email":"[email protected]","address":{"line1":"a-line-1","line2":"a-line-2","line3":"a-line-3","town":"a-town","postcode":"A1 1FF","country":"GB"},"status":"active","channel":"online"},
{"uid":"` + replacementTrustCorporationUID.String() + `","name":"UnTrusty","companyNumber":"65555","address":{"line1":"a-line-1","line2":"a-line-2","line3":"a-line-3","town":"a-town","postcode":"A1 1FF","country":"GB"},"status":"replacement","channel":"paper"}
],
"certificateProvider":{"uid":"` + certificateProviderUID.String() + `","firstNames":"Carol","lastName":"Cert","email":"[email protected]","phone":"0700009000","address":{"line1":"c-line-1","line2":"c-line-2","line3":"c-line-3","town":"c-town","postcode":"C1 1FF","country":"GB"},"channel":"online"},
"peopleToNotify":[{"uid":"` + personToNotifyUID.String() + `","firstNames":"Peter","lastName":"Notify","address":{"line1":"p-line-1","line2":"p-line-2","line3":"p-line-3","town":"p-town","postcode":"P1 1FF","country":"GB"}}],
Expand Down Expand Up @@ -470,6 +469,7 @@ func TestClientLpa(t *testing.T) {
Postcode: "A1 1FF",
Country: "GB",
},
Channel: actor.ChannelOnline,
},
Attorneys: []Attorney{{
UID: attorneyUID,
Expand Down Expand Up @@ -509,7 +509,6 @@ func TestClientLpa(t *testing.T) {
UID: replacementTrustCorporationUID,
Name: "UnTrusty",
CompanyNumber: "65555",
Email: "[email protected]",
Address: place.Address{
Line1: "a-line-1",
Line2: "a-line-2",
Expand All @@ -518,6 +517,7 @@ func TestClientLpa(t *testing.T) {
Postcode: "A1 1FF",
Country: "GB",
},
Channel: actor.ChannelPaper,
},
Attorneys: []Attorney{{
UID: replacementAttorneyUID,
Expand Down Expand Up @@ -599,8 +599,8 @@ func TestClientLpa(t *testing.T) {
{"uid":"` + replacementAttorney2UID.String() + `","firstNames":"Rachel","lastName":"Attorney","dateOfBirth":"1998-11-12","email":"[email protected]","address":{"line1":"rr-line-1","line2":"rr-line-2","line3":"rr-line-3","town":"rr-town","postcode":"R1 1RF","country":"GB"},"status":"replacement"}
],
"trustCorporations":[
{"uid":"` + trustCorporationUID.String() + `","name":"Trusty","companyNumber":"55555","email":"[email protected]","address":{"line1":"a-line-1","line2":"a-line-2","line3":"a-line-3","town":"a-town","postcode":"A1 1FF","country":"GB"},"status":"active"},
{"uid":"` + replacementTrustCorporationUID.String() + `","name":"UnTrusty","companyNumber":"65555","email":"[email protected]","address":{"line1":"a-line-1","line2":"a-line-2","line3":"a-line-3","town":"a-town","postcode":"A1 1FF","country":"GB"},"status":"replacement"}
{"uid":"` + trustCorporationUID.String() + `","name":"Trusty","companyNumber":"55555","email":"[email protected]","address":{"line1":"a-line-1","line2":"a-line-2","line3":"a-line-3","town":"a-town","postcode":"A1 1FF","country":"GB"},"status":"active","channel":"online"},
{"uid":"` + replacementTrustCorporationUID.String() + `","name":"UnTrusty","companyNumber":"65555","address":{"line1":"a-line-1","line2":"a-line-2","line3":"a-line-3","town":"a-town","postcode":"A1 1FF","country":"GB"},"status":"replacement","channel":"paper"}
],
"certificateProvider":{"uid":"` + certificateProviderUID.String() + `","firstNames":"Carol","lastName":"Cert","email":"[email protected]","phone":"0700009000","address":{"line1":"c-line-1","line2":"c-line-2","line3":"c-line-3","town":"c-town","postcode":"C1 1FF","country":"GB"},"channel":"online"},
"peopleToNotify":[{"uid":"` + personToNotifyUID.String() + `","firstNames":"Peter","lastName":"Notify","address":{"line1":"p-line-1","line2":"p-line-2","line3":"p-line-3","town":"p-town","postcode":"P1 1FF","country":"GB"}}],
Expand Down
11 changes: 11 additions & 0 deletions internal/lpastore/update.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,11 +107,14 @@ func (c *Client) SendCertificateProvider(ctx context.Context, certificateProvide
func (c *Client) SendAttorney(ctx context.Context, lpa *Lpa, attorney *actor.AttorneyProvidedDetails) error {
var attorneyKey string
var lpaAttorney Attorney
var lpaTrustCorp TrustCorporation

if attorney.IsTrustCorporation && attorney.IsReplacement && lpa.Attorneys.TrustCorporation.Name != "" {
attorneyKey = "/trustCorporations/1"
lpaTrustCorp = lpa.ReplacementAttorneys.TrustCorporation
} else if attorney.IsTrustCorporation {
attorneyKey = "/trustCorporations/0"
lpaTrustCorp = lpa.Attorneys.TrustCorporation
} else if attorney.IsReplacement {
attorneyKey = fmt.Sprintf("/attorneys/%d", len(lpa.Attorneys.Attorneys)+lpa.ReplacementAttorneys.Index(attorney.UID))
lpaAttorney = lpa.ReplacementAttorneys.Attorneys[lpa.ReplacementAttorneys.Index(attorney.UID)]
Expand All @@ -131,6 +134,14 @@ func (c *Client) SendAttorney(ctx context.Context, lpa *Lpa, attorney *actor.Att
if attorney.IsTrustCorporation {
body.Type = "TRUST_CORPORATION_SIGN"

if lpaTrustCorp.Email != attorney.Email {
body.Changes = append(body.Changes, updateRequestChange{Key: attorneyKey + "/email", New: attorney.Email, Old: lpaTrustCorp.Email})
}

if lpaTrustCorp.Channel == actor.ChannelPaper {
body.Changes = append(body.Changes, updateRequestChange{Key: attorneyKey + "/channel", New: actor.ChannelOnline, Old: actor.ChannelPaper})
}

body.Changes = append(body.Changes,
updateRequestChange{Key: attorneyKey + "/signatories/0/firstNames", New: attorney.AuthorisedSignatories[0].FirstNames},
updateRequestChange{Key: attorneyKey + "/signatories/0/lastName", New: attorney.AuthorisedSignatories[0].LastName},
Expand Down
Loading

0 comments on commit 012cd40

Please sign in to comment.