diff --git a/internal/actor/actoruid/uid.go b/internal/actor/actoruid/uid.go new file mode 100644 index 0000000000..70213f5f38 --- /dev/null +++ b/internal/actor/actoruid/uid.go @@ -0,0 +1,64 @@ +package actoruid + +import ( + "errors" + "strings" + + "github.com/aws/aws-sdk-go-v2/feature/dynamodb/attributevalue" + "github.com/aws/aws-sdk-go-v2/service/dynamodb/types" + "github.com/google/uuid" +) + +const prefix = "urn:opg:poas:makeregister:users:" + +type UID struct{ value string } + +func New() UID { + return UID{value: uuid.NewString()} +} + +func FromRequest(r interface{ FormValue(string) string }) UID { + return UID{value: r.FormValue("id")} +} + +func (u UID) IsZero() bool { + return len(u.value) == 0 +} + +func (u UID) String() string { + return u.value +} + +func (u UID) PrefixedString() string { + return prefix + u.value +} + +func (u UID) MarshalJSON() ([]byte, error) { + if u.value == "" { + return []byte("null"), nil + } + + return []byte(`"` + u.PrefixedString() + `"`), nil +} + +func (u *UID) UnmarshalText(text []byte) error { + if len(text) == 0 { + return nil + } + + uid, found := strings.CutPrefix(string(text), prefix) + if !found { + return errors.New("invalid uid prefix") + } + + u.value = uid + return nil +} + +func (u UID) MarshalDynamoDBAttributeValue() (types.AttributeValue, error) { + return attributevalue.Marshal(u.value) +} + +func (u *UID) UnmarshalDynamoDBAttributeValue(av types.AttributeValue) error { + return attributevalue.Unmarshal(av, &u.value) +} diff --git a/internal/actor/actoruid/uid_test.go b/internal/actor/actoruid/uid_test.go new file mode 100644 index 0000000000..e5a537a1c0 --- /dev/null +++ b/internal/actor/actoruid/uid_test.go @@ -0,0 +1,71 @@ +package actoruid + +import ( + "encoding/json" + "net/http" + "testing" + + "github.com/aws/aws-sdk-go-v2/feature/dynamodb/attributevalue" + "github.com/aws/aws-sdk-go-v2/service/dynamodb/types" + "github.com/stretchr/testify/assert" +) + +func TestUID(t *testing.T) { + uid := UID{value: "abc"} + + assert.Equal(t, "abc", uid.String()) + assert.Equal(t, prefix+"abc", uid.PrefixedString()) +} + +func TestUIDFromRequest(t *testing.T) { + r, _ := http.NewRequest(http.MethodGet, "/?id=abc", nil) + + assert.Equal(t, UID{value: "abc"}, FromRequest(r)) +} + +func TestUIDZero(t *testing.T) { + assert.True(t, UID{}.IsZero()) + assert.False(t, New().IsZero()) +} + +func TestUIDJSON(t *testing.T) { + uid := UID{value: "abc"} + + jsonData, _ := json.Marshal(uid) + assert.Equal(t, `"urn:opg:poas:makeregister:users:abc"`, string(jsonData)) + + var a UID + err := json.Unmarshal([]byte(`"urn:opg:poas:makeregister:users:abc"`), &a) + assert.Nil(t, err) + assert.Equal(t, a, uid) + + emptyData, _ := json.Marshal(UID{}) + assert.Equal(t, `null`, string(emptyData)) + + var b UID + err = json.Unmarshal([]byte(`null`), &b) + assert.Nil(t, err) + assert.True(t, b.IsZero()) + + var c UID + err = json.Unmarshal([]byte(`""`), &c) + assert.Nil(t, err) + assert.True(t, c.IsZero()) +} + +func TestUIDJSONInvalidPrefix(t *testing.T) { + var v UID + err := json.Unmarshal([]byte(`"urn:opg:poas:makeregister:users2:abc"`), &v) + assert.ErrorContains(t, err, "invalid uid prefix") +} + +func TestUIDAttributeValue(t *testing.T) { + uid := UID{value: "abc"} + + avData, _ := attributevalue.Marshal(uid) + assert.Equal(t, &types.AttributeValueMemberS{Value: "abc"}, avData) + + var b UID + _ = attributevalue.Unmarshal(&types.AttributeValueMemberS{Value: "abc"}, &b) + assert.Equal(t, b, uid) +} diff --git a/internal/actor/attorney.go b/internal/actor/attorney.go index 87ac945f49..28825103a4 100644 --- a/internal/actor/attorney.go +++ b/internal/actor/attorney.go @@ -4,14 +4,15 @@ import ( "fmt" "slices" + "github.com/ministryofjustice/opg-modernising-lpa/internal/actor/actoruid" "github.com/ministryofjustice/opg-modernising-lpa/internal/date" "github.com/ministryofjustice/opg-modernising-lpa/internal/place" ) // Attorney contains details about an attorney or replacement attorney, provided by the applicant type Attorney struct { - // Identifies the attorney being edited - ID string + // UID for the actor + UID actoruid.UID // First names of the attorney FirstNames string // Last name of the attorney @@ -30,6 +31,8 @@ func (a Attorney) FullName() string { // TrustCorporation contains details about a trust corporation, provided by the applicant type TrustCorporation struct { + // UID for the actor + UID actoruid.UID // Name of the company Name string // CompanyNumber as registered by Companies House @@ -83,8 +86,8 @@ func (as Attorneys) Addresses() []place.Address { return addresses } -func (as Attorneys) Get(id string) (Attorney, bool) { - idx := as.Index(id) +func (as Attorneys) Get(uid actoruid.UID) (Attorney, bool) { + idx := as.Index(uid) if idx == -1 { return Attorney{}, false } @@ -93,7 +96,7 @@ func (as Attorneys) Get(id string) (Attorney, bool) { } func (as *Attorneys) Put(attorney Attorney) { - idx := as.Index(attorney.ID) + idx := as.Index(attorney.UID) if idx == -1 { as.Attorneys = append(as.Attorneys, attorney) } else { @@ -102,7 +105,7 @@ func (as *Attorneys) Put(attorney Attorney) { } func (as *Attorneys) Delete(attorney Attorney) bool { - idx := as.Index(attorney.ID) + idx := as.Index(attorney.UID) if idx == -1 { return false } @@ -111,8 +114,8 @@ func (as *Attorneys) Delete(attorney Attorney) bool { return true } -func (as *Attorneys) Index(id string) int { - return slices.IndexFunc(as.Attorneys, func(a Attorney) bool { return a.ID == id }) +func (as *Attorneys) Index(uid actoruid.UID) int { + return slices.IndexFunc(as.Attorneys, func(a Attorney) bool { return a.UID == uid }) } func (as Attorneys) FullNames() []string { diff --git a/internal/actor/attorney_provided.go b/internal/actor/attorney_provided.go index 7eeaf2697c..3acdfa9bd2 100644 --- a/internal/actor/attorney_provided.go +++ b/internal/actor/attorney_provided.go @@ -3,6 +3,7 @@ package actor import ( "time" + "github.com/ministryofjustice/opg-modernising-lpa/internal/actor/actoruid" "github.com/ministryofjustice/opg-modernising-lpa/internal/form" "github.com/ministryofjustice/opg-modernising-lpa/internal/localize" ) @@ -12,7 +13,7 @@ import ( type AttorneyProvidedDetails struct { PK, SK string // The identifier of the attorney or replacement attorney being edited - ID string + UID actoruid.UID // The identifier of the LPA the attorney or replacement attorney is named in LpaID string // Tracking when AttorneyProvidedDetails is updated diff --git a/internal/actor/attorney_test.go b/internal/actor/attorney_test.go index dda9c38ab3..86aa3841ac 100644 --- a/internal/actor/attorney_test.go +++ b/internal/actor/attorney_test.go @@ -3,6 +3,7 @@ package actor import ( "testing" + "github.com/ministryofjustice/opg-modernising-lpa/internal/actor/actoruid" "github.com/ministryofjustice/opg-modernising-lpa/internal/place" "github.com/stretchr/testify/assert" ) @@ -94,29 +95,32 @@ func TestAttorneysAddresses(t *testing.T) { } func TestAttorneysGet(t *testing.T) { + uid1 := actoruid.New() + uid2 := actoruid.New() + testCases := map[string]struct { attorneys Attorneys expectedAttorney Attorney - id string + uid actoruid.UID expectedFound bool }{ "attorney exists": { - attorneys: Attorneys{Attorneys: []Attorney{{ID: "1", FirstNames: "Bob"}, {ID: "2"}}}, - expectedAttorney: Attorney{ID: "1", FirstNames: "Bob"}, - id: "1", + attorneys: Attorneys{Attorneys: []Attorney{{UID: uid1, FirstNames: "Bob"}, {UID: uid2}}}, + expectedAttorney: Attorney{UID: uid1, FirstNames: "Bob"}, + uid: uid1, expectedFound: true, }, "attorney does not exist": { - attorneys: Attorneys{Attorneys: []Attorney{{ID: "1", FirstNames: "Bob"}, {ID: "2"}}}, + attorneys: Attorneys{Attorneys: []Attorney{{UID: uid1, FirstNames: "Bob"}, {UID: uid2}}}, expectedAttorney: Attorney{}, - id: "4", + uid: actoruid.New(), expectedFound: false, }, } for name, tc := range testCases { t.Run(name, func(t *testing.T) { - a, found := tc.attorneys.Get(tc.id) + a, found := tc.attorneys.Get(tc.uid) assert.Equal(t, tc.expectedFound, found) assert.Equal(t, tc.expectedAttorney, a) @@ -125,20 +129,25 @@ func TestAttorneysGet(t *testing.T) { } func TestAttorneysPut(t *testing.T) { + uid1 := actoruid.New() + uid2 := actoruid.New() + + newAttorney := Attorney{UID: actoruid.New(), FirstNames: "Bob"} + testCases := map[string]struct { attorneys Attorneys expectedAttorneys Attorneys updatedAttorney Attorney }{ "attorney exists": { - attorneys: Attorneys{Attorneys: []Attorney{{ID: "1"}, {ID: "2"}}}, - expectedAttorneys: Attorneys{Attorneys: []Attorney{{ID: "1", FirstNames: "Bob"}, {ID: "2"}}}, - updatedAttorney: Attorney{ID: "1", FirstNames: "Bob"}, + attorneys: Attorneys{Attorneys: []Attorney{{UID: uid1}, {UID: uid2}}}, + expectedAttorneys: Attorneys{Attorneys: []Attorney{{UID: uid1, FirstNames: "Bob"}, {UID: uid2}}}, + updatedAttorney: Attorney{UID: uid1, FirstNames: "Bob"}, }, "attorney does not exist": { - attorneys: Attorneys{Attorneys: []Attorney{{ID: "1"}, {ID: "2"}}}, - expectedAttorneys: Attorneys{Attorneys: []Attorney{{ID: "1"}, {ID: "2"}, {ID: "3", FirstNames: "Bob"}}}, - updatedAttorney: Attorney{ID: "3", FirstNames: "Bob"}, + attorneys: Attorneys{Attorneys: []Attorney{{UID: uid1}, {UID: uid2}}}, + expectedAttorneys: Attorneys{Attorneys: []Attorney{{UID: uid1}, {UID: uid2}, newAttorney}}, + updatedAttorney: newAttorney, }, } @@ -152,6 +161,9 @@ func TestAttorneysPut(t *testing.T) { } func TestAttorneysDelete(t *testing.T) { + uid1 := actoruid.New() + uid2 := actoruid.New() + testCases := map[string]struct { attorneys Attorneys expectedAttorneys Attorneys @@ -159,15 +171,15 @@ func TestAttorneysDelete(t *testing.T) { expectedDeleted bool }{ "attorney exists": { - attorneys: Attorneys{Attorneys: []Attorney{{ID: "1"}, {ID: "2"}}}, - expectedAttorneys: Attorneys{Attorneys: []Attorney{{ID: "1"}}}, - attorneyToDelete: Attorney{ID: "2"}, + attorneys: Attorneys{Attorneys: []Attorney{{UID: uid1}, {UID: uid2}}}, + expectedAttorneys: Attorneys{Attorneys: []Attorney{{UID: uid1}}}, + attorneyToDelete: Attorney{UID: uid2}, expectedDeleted: true, }, "attorney does not exist": { - attorneys: Attorneys{Attorneys: []Attorney{{ID: "1"}, {ID: "2"}}}, - expectedAttorneys: Attorneys{Attorneys: []Attorney{{ID: "1"}, {ID: "2"}}}, - attorneyToDelete: Attorney{ID: "3"}, + attorneys: Attorneys{Attorneys: []Attorney{{UID: uid1}, {UID: uid2}}}, + expectedAttorneys: Attorneys{Attorneys: []Attorney{{UID: uid1}, {UID: uid2}}}, + attorneyToDelete: Attorney{UID: actoruid.New()}, expectedDeleted: false, }, } diff --git a/internal/actor/certificate_provider.go b/internal/actor/certificate_provider.go index 3ee84268a9..93f8c38c40 100644 --- a/internal/actor/certificate_provider.go +++ b/internal/actor/certificate_provider.go @@ -3,6 +3,7 @@ package actor import ( "fmt" + "github.com/ministryofjustice/opg-modernising-lpa/internal/actor/actoruid" "github.com/ministryofjustice/opg-modernising-lpa/internal/place" ) @@ -33,6 +34,8 @@ const ( // CertificateProvider contains details about the certificate provider, provided by the applicant type CertificateProvider struct { + // UID for the actor + UID actoruid.UID // First names of the certificate provider FirstNames string // Last name of the certificate provider diff --git a/internal/actor/donor.go b/internal/actor/donor.go index e7c82d9b70..8bf90bd90c 100644 --- a/internal/actor/donor.go +++ b/internal/actor/donor.go @@ -3,6 +3,7 @@ package actor import ( "fmt" + "github.com/ministryofjustice/opg-modernising-lpa/internal/actor/actoruid" "github.com/ministryofjustice/opg-modernising-lpa/internal/date" "github.com/ministryofjustice/opg-modernising-lpa/internal/form" "github.com/ministryofjustice/opg-modernising-lpa/internal/place" @@ -10,6 +11,8 @@ import ( // Donor contains details about the donor, provided by the applicant type Donor struct { + // UID for the actor + UID actoruid.UID // First names of the donor FirstNames string // Last name of the donor diff --git a/internal/actor/donor_provided.go b/internal/actor/donor_provided.go index af2484c5e4..f9b54fabe9 100644 --- a/internal/actor/donor_provided.go +++ b/internal/actor/donor_provided.go @@ -5,6 +5,7 @@ import ( "strings" "time" + "github.com/ministryofjustice/opg-modernising-lpa/internal/actor/actoruid" "github.com/ministryofjustice/opg-modernising-lpa/internal/date" "github.com/ministryofjustice/opg-modernising-lpa/internal/form" "github.com/ministryofjustice/opg-modernising-lpa/internal/identity" @@ -152,7 +153,7 @@ func (l *DonorProvidedDetails) AttorneysAndCpSigningDeadline() time.Time { type Under18ActorDetails struct { FullName string DateOfBirth date.Date - ID string + UID actoruid.UID Type Type } @@ -165,7 +166,7 @@ func (l *DonorProvidedDetails) Under18ActorDetails() []Under18ActorDetails { data = append(data, Under18ActorDetails{ FullName: a.FullName(), DateOfBirth: a.DateOfBirth, - ID: a.ID, + UID: a.UID, Type: TypeAttorney, }) } @@ -176,7 +177,7 @@ func (l *DonorProvidedDetails) Under18ActorDetails() []Under18ActorDetails { data = append(data, Under18ActorDetails{ FullName: ra.FullName(), DateOfBirth: ra.DateOfBirth, - ID: ra.ID, + UID: ra.UID, Type: TypeReplacementAttorney, }) } @@ -248,8 +249,8 @@ func (l *DonorProvidedDetails) AllAttorneysSigned(attorneys []*AttorneyProvidedD } var ( - attorneysSigned = map[string]struct{}{} - replacementAttorneysSigned = map[string]struct{}{} + attorneysSigned = map[actoruid.UID]struct{}{} + replacementAttorneysSigned = map[actoruid.UID]struct{}{} trustCorporationSigned = false replacementTrustCorporationSigned = false ) @@ -262,11 +263,11 @@ func (l *DonorProvidedDetails) AllAttorneysSigned(attorneys []*AttorneyProvidedD if a.IsReplacement && a.IsTrustCorporation { replacementTrustCorporationSigned = true } else if a.IsReplacement { - replacementAttorneysSigned[a.ID] = struct{}{} + replacementAttorneysSigned[a.UID] = struct{}{} } else if a.IsTrustCorporation { trustCorporationSigned = true } else { - attorneysSigned[a.ID] = struct{}{} + attorneysSigned[a.UID] = struct{}{} } } @@ -275,7 +276,7 @@ func (l *DonorProvidedDetails) AllAttorneysSigned(attorneys []*AttorneyProvidedD } for _, a := range l.ReplacementAttorneys.Attorneys { - if _, ok := replacementAttorneysSigned[a.ID]; !ok { + if _, ok := replacementAttorneysSigned[a.UID]; !ok { return false } } @@ -285,7 +286,7 @@ func (l *DonorProvidedDetails) AllAttorneysSigned(attorneys []*AttorneyProvidedD } for _, a := range l.Attorneys.Attorneys { - if _, ok := attorneysSigned[a.ID]; !ok { + if _, ok := attorneysSigned[a.UID]; !ok { return false } } diff --git a/internal/actor/donor_provided_test.go b/internal/actor/donor_provided_test.go index 83197e88f7..36b22f6b7a 100644 --- a/internal/actor/donor_provided_test.go +++ b/internal/actor/donor_provided_test.go @@ -4,6 +4,7 @@ import ( "testing" "time" + "github.com/ministryofjustice/opg-modernising-lpa/internal/actor/actoruid" "github.com/ministryofjustice/opg-modernising-lpa/internal/date" "github.com/ministryofjustice/opg-modernising-lpa/internal/form" "github.com/ministryofjustice/opg-modernising-lpa/internal/identity" @@ -27,12 +28,12 @@ func TestGenerateHash(t *testing.T) { }} hash, err := donor.GenerateHash() assert.Nil(t, err) - assert.Equal(t, uint64(0xdf80e0da44d7fafd), hash) + assert.Equal(t, uint64(0x1c746864bd23d82e), hash) donor.Attorneys.Attorneys[0].DateOfBirth = date.New("2001", "1", "2") hash, err = donor.GenerateHash() assert.Nil(t, err) - assert.Equal(t, uint64(0x1e06941b4d5e138e), hash) + assert.Equal(t, uint64(0x80d2d4728e9a797a), hash) } func TestIdentityConfirmed(t *testing.T) { @@ -83,24 +84,28 @@ func TestAttorneysSigningDeadline(t *testing.T) { func TestUnder18ActorDetails(t *testing.T) { under18 := date.Today().AddDate(0, 0, -1) over18 := date.Today().AddDate(-18, 0, -1) + uid1 := actoruid.New() + uid2 := actoruid.New() + uid3 := actoruid.New() + uid4 := actoruid.New() donor := DonorProvidedDetails{ LpaID: "lpa-id", Attorneys: Attorneys{Attorneys: []Attorney{ - {FirstNames: "a", LastName: "b", DateOfBirth: under18, ID: "1"}, - {FirstNames: "c", LastName: "d", DateOfBirth: over18, ID: "2"}, + {FirstNames: "a", LastName: "b", DateOfBirth: under18, UID: uid1}, + {FirstNames: "c", LastName: "d", DateOfBirth: over18, UID: uid2}, }}, ReplacementAttorneys: Attorneys{Attorneys: []Attorney{ - {FirstNames: "e", LastName: "f", DateOfBirth: under18, ID: "3"}, - {FirstNames: "g", LastName: "h", DateOfBirth: over18, ID: "4"}, + {FirstNames: "e", LastName: "f", DateOfBirth: under18, UID: uid3}, + {FirstNames: "g", LastName: "h", DateOfBirth: over18, UID: uid4}, }}, } actors := donor.Under18ActorDetails() assert.Equal(t, []Under18ActorDetails{ - {FullName: "a b", DateOfBirth: under18, ID: "1", Type: TypeAttorney}, - {FullName: "e f", DateOfBirth: under18, ID: "3", Type: TypeReplacementAttorney}, + {FullName: "a b", DateOfBirth: under18, UID: uid1, Type: TypeAttorney}, + {FullName: "e f", DateOfBirth: under18, UID: uid3, Type: TypeReplacementAttorney}, }, actors) } @@ -109,6 +114,12 @@ func TestAllAttorneysSigned(t *testing.T) { otherLpaSignedAt := lpaSignedAt.Add(time.Minute) attorneySigned := lpaSignedAt.Add(time.Second) + uid1 := actoruid.New() + uid2 := actoruid.New() + uid3 := actoruid.New() + uid4 := actoruid.New() + uid5 := actoruid.New() + testcases := map[string]struct { lpa *DonorProvidedDetails attorneys []*AttorneyProvidedDetails @@ -120,62 +131,62 @@ func TestAllAttorneysSigned(t *testing.T) { "need attorney to sign": { lpa: &DonorProvidedDetails{ SignedAt: lpaSignedAt, - Attorneys: Attorneys{Attorneys: []Attorney{{ID: "a1"}, {ID: "a2"}}}, - ReplacementAttorneys: Attorneys{Attorneys: []Attorney{{ID: "r1"}}}, + Attorneys: Attorneys{Attorneys: []Attorney{{UID: uid1}, {UID: uid2}}}, + ReplacementAttorneys: Attorneys{Attorneys: []Attorney{{UID: uid3}}}, }, attorneys: []*AttorneyProvidedDetails{ - {ID: "a1", LpaSignedAt: lpaSignedAt, Confirmed: attorneySigned}, - {ID: "a3", LpaSignedAt: otherLpaSignedAt, Confirmed: attorneySigned}, - {ID: "r1", IsReplacement: true, LpaSignedAt: lpaSignedAt, Confirmed: attorneySigned}, + {UID: uid1, LpaSignedAt: lpaSignedAt, Confirmed: attorneySigned}, + {UID: uid4, LpaSignedAt: otherLpaSignedAt, Confirmed: attorneySigned}, + {UID: uid3, IsReplacement: true, LpaSignedAt: lpaSignedAt, Confirmed: attorneySigned}, }, expected: false, }, "need replacement attorney to sign": { lpa: &DonorProvidedDetails{ SignedAt: lpaSignedAt, - Attorneys: Attorneys{Attorneys: []Attorney{{ID: "a1"}}}, - ReplacementAttorneys: Attorneys{Attorneys: []Attorney{{ID: "r1"}, {ID: "r2"}}}, + Attorneys: Attorneys{Attorneys: []Attorney{{UID: uid1}}}, + ReplacementAttorneys: Attorneys{Attorneys: []Attorney{{UID: uid3}, {UID: uid5}}}, }, attorneys: []*AttorneyProvidedDetails{ - {ID: "a1", LpaSignedAt: lpaSignedAt, Confirmed: attorneySigned}, - {ID: "r1", IsReplacement: true}, - {ID: "r2", IsReplacement: true, LpaSignedAt: lpaSignedAt, Confirmed: attorneySigned}, + {UID: uid1, LpaSignedAt: lpaSignedAt, Confirmed: attorneySigned}, + {UID: uid3, IsReplacement: true}, + {UID: uid5, IsReplacement: true, LpaSignedAt: lpaSignedAt, Confirmed: attorneySigned}, }, expected: false, }, "all attorneys signed": { lpa: &DonorProvidedDetails{ SignedAt: lpaSignedAt, - Attorneys: Attorneys{Attorneys: []Attorney{{ID: "a1"}, {ID: "a2"}}}, - ReplacementAttorneys: Attorneys{Attorneys: []Attorney{{ID: "r1"}}}, + Attorneys: Attorneys{Attorneys: []Attorney{{UID: uid1}, {UID: uid2}}}, + ReplacementAttorneys: Attorneys{Attorneys: []Attorney{{UID: uid3}}}, }, attorneys: []*AttorneyProvidedDetails{ - {ID: "a1", LpaSignedAt: lpaSignedAt, Confirmed: attorneySigned}, - {ID: "a2", LpaSignedAt: lpaSignedAt, Confirmed: attorneySigned}, - {ID: "r1", IsReplacement: true, LpaSignedAt: lpaSignedAt, Confirmed: attorneySigned}, + {UID: uid1, LpaSignedAt: lpaSignedAt, Confirmed: attorneySigned}, + {UID: uid2, LpaSignedAt: lpaSignedAt, Confirmed: attorneySigned}, + {UID: uid3, IsReplacement: true, LpaSignedAt: lpaSignedAt, Confirmed: attorneySigned}, }, expected: true, }, "more attorneys signed": { lpa: &DonorProvidedDetails{ SignedAt: lpaSignedAt, - Attorneys: Attorneys{Attorneys: []Attorney{{ID: "a1"}, {ID: "a2"}}}, + Attorneys: Attorneys{Attorneys: []Attorney{{UID: uid1}, {UID: uid2}}}, }, attorneys: []*AttorneyProvidedDetails{ - {ID: "a1", LpaSignedAt: lpaSignedAt, Confirmed: attorneySigned}, - {ID: "a2", LpaSignedAt: lpaSignedAt, Confirmed: attorneySigned}, - {ID: "a3", LpaSignedAt: otherLpaSignedAt, Confirmed: attorneySigned}, + {UID: uid1, LpaSignedAt: lpaSignedAt, Confirmed: attorneySigned}, + {UID: uid2, LpaSignedAt: lpaSignedAt, Confirmed: attorneySigned}, + {UID: uid4, LpaSignedAt: otherLpaSignedAt, Confirmed: attorneySigned}, }, expected: true, }, "waiting for attorney to re-sign": { lpa: &DonorProvidedDetails{ SignedAt: lpaSignedAt, - Attorneys: Attorneys{Attorneys: []Attorney{{ID: "a1"}, {ID: "a2"}}}, + Attorneys: Attorneys{Attorneys: []Attorney{{UID: uid1}, {UID: uid2}}}, }, attorneys: []*AttorneyProvidedDetails{ - {ID: "a1", LpaSignedAt: otherLpaSignedAt, Confirmed: attorneySigned}, - {ID: "a2", LpaSignedAt: lpaSignedAt, Confirmed: attorneySigned}, + {UID: uid1, LpaSignedAt: otherLpaSignedAt, Confirmed: attorneySigned}, + {UID: uid2, LpaSignedAt: lpaSignedAt, Confirmed: attorneySigned}, }, expected: false, }, diff --git a/internal/actor/person_to_notify.go b/internal/actor/person_to_notify.go index 88aad232f2..7bef29c702 100644 --- a/internal/actor/person_to_notify.go +++ b/internal/actor/person_to_notify.go @@ -3,19 +3,19 @@ package actor import ( "slices" + "github.com/ministryofjustice/opg-modernising-lpa/internal/actor/actoruid" "github.com/ministryofjustice/opg-modernising-lpa/internal/place" ) // PersonToNotify contains details about a person to notify, provided by the applicant type PersonToNotify struct { + UID actoruid.UID // First names of the person to notify FirstNames string // Last name of the person to notify LastName string // Address of the person to notify Address place.Address - // Identifies the person to notify being edited - ID string } func (p PersonToNotify) FullName() string { @@ -24,8 +24,8 @@ func (p PersonToNotify) FullName() string { type PeopleToNotify []PersonToNotify -func (ps PeopleToNotify) Get(id string) (PersonToNotify, bool) { - idx := slices.IndexFunc(ps, func(p PersonToNotify) bool { return p.ID == id }) +func (ps PeopleToNotify) Get(uid actoruid.UID) (PersonToNotify, bool) { + idx := slices.IndexFunc(ps, func(p PersonToNotify) bool { return p.UID == uid }) if idx == -1 { return PersonToNotify{}, false } @@ -34,7 +34,7 @@ func (ps PeopleToNotify) Get(id string) (PersonToNotify, bool) { } func (ps PeopleToNotify) Put(person PersonToNotify) bool { - idx := slices.IndexFunc(ps, func(p PersonToNotify) bool { return p.ID == person.ID }) + idx := slices.IndexFunc(ps, func(p PersonToNotify) bool { return p.UID == person.UID }) if idx == -1 { return false } @@ -44,7 +44,7 @@ func (ps PeopleToNotify) Put(person PersonToNotify) bool { } func (ps *PeopleToNotify) Delete(personToNotify PersonToNotify) bool { - idx := slices.IndexFunc(*ps, func(p PersonToNotify) bool { return p.ID == personToNotify.ID }) + idx := slices.IndexFunc(*ps, func(p PersonToNotify) bool { return p.UID == personToNotify.UID }) if idx == -1 { return false } diff --git a/internal/actor/person_to_notify_test.go b/internal/actor/person_to_notify_test.go index d34750a56c..c0f6301529 100644 --- a/internal/actor/person_to_notify_test.go +++ b/internal/actor/person_to_notify_test.go @@ -3,6 +3,7 @@ package actor import ( "testing" + "github.com/ministryofjustice/opg-modernising-lpa/internal/actor/actoruid" "github.com/stretchr/testify/assert" ) @@ -11,22 +12,25 @@ func TestPersonToNotifyFullName(t *testing.T) { } func TestPeopleToNotifyGet(t *testing.T) { + uid1 := actoruid.New() + uid2 := actoruid.New() + testCases := map[string]struct { peopleToNotify PeopleToNotify expectedPersonToNotify PersonToNotify - id string + id actoruid.UID expectedFound bool }{ "personToNotify exists": { - peopleToNotify: PeopleToNotify{{ID: "1", FirstNames: "Bob"}, {ID: "2"}}, - expectedPersonToNotify: PersonToNotify{ID: "1", FirstNames: "Bob"}, - id: "1", + peopleToNotify: PeopleToNotify{{UID: uid1, FirstNames: "Bob"}, {UID: uid2}}, + expectedPersonToNotify: PersonToNotify{UID: uid1, FirstNames: "Bob"}, + id: uid1, expectedFound: true, }, "personToNotify does not exist": { - peopleToNotify: PeopleToNotify{{ID: "1", FirstNames: "Bob"}, {ID: "2"}}, + peopleToNotify: PeopleToNotify{{UID: uid1, FirstNames: "Bob"}, {UID: uid2}}, expectedPersonToNotify: PersonToNotify{}, - id: "4", + id: actoruid.New(), expectedFound: false, }, } @@ -42,6 +46,10 @@ func TestPeopleToNotifyGet(t *testing.T) { } func TestPeopleToNotifyPut(t *testing.T) { + uid1 := actoruid.New() + uid2 := actoruid.New() + uid3 := actoruid.New() + testCases := map[string]struct { peopleToNotify PeopleToNotify expectedPeopleToNotify PeopleToNotify @@ -49,15 +57,15 @@ func TestPeopleToNotifyPut(t *testing.T) { expectedUpdated bool }{ "personToNotify exists": { - peopleToNotify: PeopleToNotify{{ID: "1"}, {ID: "2"}}, - expectedPeopleToNotify: PeopleToNotify{{ID: "1", FirstNames: "Bob"}, {ID: "2"}}, - updatedPersonToNotify: PersonToNotify{ID: "1", FirstNames: "Bob"}, + peopleToNotify: PeopleToNotify{{UID: uid1}, {UID: uid2}}, + expectedPeopleToNotify: PeopleToNotify{{UID: uid1, FirstNames: "Bob"}, {UID: uid2}}, + updatedPersonToNotify: PersonToNotify{UID: uid1, FirstNames: "Bob"}, expectedUpdated: true, }, "personToNotify does not exist": { - peopleToNotify: PeopleToNotify{{ID: "1"}, {ID: "2"}}, - expectedPeopleToNotify: PeopleToNotify{{ID: "1"}, {ID: "2"}}, - updatedPersonToNotify: PersonToNotify{ID: "3", FirstNames: "Bob"}, + peopleToNotify: PeopleToNotify{{UID: uid1}, {UID: uid2}}, + expectedPeopleToNotify: PeopleToNotify{{UID: uid1}, {UID: uid2}}, + updatedPersonToNotify: PersonToNotify{UID: uid3, FirstNames: "Bob"}, expectedUpdated: false, }, } @@ -73,6 +81,10 @@ func TestPeopleToNotifyPut(t *testing.T) { } func TestPeopleToNotifyDelete(t *testing.T) { + uid1 := actoruid.New() + uid2 := actoruid.New() + uid3 := actoruid.New() + testCases := map[string]struct { peopleToNotify PeopleToNotify expectedPeopleToNotify PeopleToNotify @@ -80,15 +92,15 @@ func TestPeopleToNotifyDelete(t *testing.T) { expectedDeleted bool }{ "personToNotify exists": { - peopleToNotify: PeopleToNotify{{ID: "1"}, {ID: "2"}}, - expectedPeopleToNotify: PeopleToNotify{{ID: "1"}}, - personToNotifyToDelete: PersonToNotify{ID: "2"}, + peopleToNotify: PeopleToNotify{{UID: uid1}, {UID: uid2}}, + expectedPeopleToNotify: PeopleToNotify{{UID: uid1}}, + personToNotifyToDelete: PersonToNotify{UID: uid2}, expectedDeleted: true, }, "personToNotify does not exist": { - peopleToNotify: PeopleToNotify{{ID: "1"}, {ID: "2"}}, - expectedPeopleToNotify: PeopleToNotify{{ID: "1"}, {ID: "2"}}, - personToNotifyToDelete: PersonToNotify{ID: "3"}, + peopleToNotify: PeopleToNotify{{UID: uid1}, {UID: uid2}}, + expectedPeopleToNotify: PeopleToNotify{{UID: uid1}, {UID: uid2}}, + personToNotifyToDelete: PersonToNotify{UID: uid3}, expectedDeleted: false, }, } diff --git a/internal/actor/share_code_data.go b/internal/actor/share_code_data.go index aab8d7eb20..c04b6cec26 100644 --- a/internal/actor/share_code_data.go +++ b/internal/actor/share_code_data.go @@ -1,10 +1,12 @@ package actor +import "github.com/ministryofjustice/opg-modernising-lpa/internal/actor/actoruid" + type ShareCodeData struct { PK, SK string SessionID string LpaID string - AttorneyID string + AttorneyUID actoruid.UID IsReplacementAttorney bool IsTrustCorporation bool DonorFullname string diff --git a/internal/actor/type.go b/internal/actor/type.go index df3357a18e..1dc0b1c628 100644 --- a/internal/actor/type.go +++ b/internal/actor/type.go @@ -1,6 +1,6 @@ package actor -type Type int +type Type uint8 const ( TypeNone Type = iota @@ -11,6 +11,8 @@ const ( TypePersonToNotify TypeAuthorisedSignatory TypeIndependentWitness + TypeTrustCorporation + TypeReplacementTrustCorporation ) func (t Type) String() string { @@ -29,29 +31,35 @@ func (t Type) String() string { return "signatory" case TypeIndependentWitness: return "independentWitness" + case TypeTrustCorporation: + return "trustCorporation" default: return "" } } type Types struct { - None Type - Donor Type - Attorney Type - ReplacementAttorney Type - CertificateProvider Type - PersonToNotify Type - AuthorisedSignatory Type - IndependentWitness Type + None Type + Donor Type + Attorney Type + ReplacementAttorney Type + TrustCorporation Type + ReplacementTrustCorporation Type + CertificateProvider Type + PersonToNotify Type + AuthorisedSignatory Type + IndependentWitness Type } var ActorTypes = Types{ - None: TypeNone, - Donor: TypeDonor, - Attorney: TypeAttorney, - ReplacementAttorney: TypeReplacementAttorney, - CertificateProvider: TypeCertificateProvider, - PersonToNotify: TypePersonToNotify, - AuthorisedSignatory: TypeAuthorisedSignatory, - IndependentWitness: TypeIndependentWitness, + None: TypeNone, + Donor: TypeDonor, + Attorney: TypeAttorney, + ReplacementAttorney: TypeReplacementAttorney, + TrustCorporation: TypeTrustCorporation, + ReplacementTrustCorporation: TypeReplacementTrustCorporation, + CertificateProvider: TypeCertificateProvider, + PersonToNotify: TypePersonToNotify, + AuthorisedSignatory: TypeAuthorisedSignatory, + IndependentWitness: TypeIndependentWitness, } diff --git a/internal/app/app.go b/internal/app/app.go index 53e6f02ebd..e5bc647465 100644 --- a/internal/app/app.go +++ b/internal/app/app.go @@ -12,6 +12,7 @@ import ( "github.com/gorilla/sessions" "github.com/ministryofjustice/opg-go-common/logging" "github.com/ministryofjustice/opg-go-common/template" + "github.com/ministryofjustice/opg-modernising-lpa/internal/actor/actoruid" "github.com/ministryofjustice/opg-modernising-lpa/internal/dynamo" "github.com/ministryofjustice/opg-modernising-lpa/internal/event" "github.com/ministryofjustice/opg-modernising-lpa/internal/localize" @@ -89,6 +90,7 @@ func App( eventClient: eventClient, logger: logger, uuidString: uuid.NewString, + newUID: actoruid.New, now: time.Now, documentStore: documentStore, } diff --git a/internal/app/attorney_store.go b/internal/app/attorney_store.go index 439a801b2f..74305601f3 100644 --- a/internal/app/attorney_store.go +++ b/internal/app/attorney_store.go @@ -6,6 +6,7 @@ import ( "time" "github.com/ministryofjustice/opg-modernising-lpa/internal/actor" + "github.com/ministryofjustice/opg-modernising-lpa/internal/actor/actoruid" "github.com/ministryofjustice/opg-modernising-lpa/internal/page" ) @@ -14,7 +15,7 @@ type attorneyStore struct { now func() time.Time } -func (s *attorneyStore) Create(ctx context.Context, donorSessionID, attorneyID string, isReplacement, isTrustCorporation bool) (*actor.AttorneyProvidedDetails, error) { +func (s *attorneyStore) Create(ctx context.Context, donorSessionID string, attorneyUID actoruid.UID, isReplacement, isTrustCorporation bool) (*actor.AttorneyProvidedDetails, error) { data, err := page.SessionDataFromContext(ctx) if err != nil { return nil, err @@ -27,7 +28,7 @@ func (s *attorneyStore) Create(ctx context.Context, donorSessionID, attorneyID s attorney := &actor.AttorneyProvidedDetails{ PK: lpaKey(data.LpaID), SK: attorneyKey(data.SessionID), - ID: attorneyID, + UID: attorneyUID, LpaID: data.LpaID, UpdatedAt: s.now(), IsReplacement: isReplacement, diff --git a/internal/app/attorney_store_test.go b/internal/app/attorney_store_test.go index 0136739c59..6ee738dce2 100644 --- a/internal/app/attorney_store_test.go +++ b/internal/app/attorney_store_test.go @@ -7,6 +7,7 @@ import ( "time" "github.com/ministryofjustice/opg-modernising-lpa/internal/actor" + "github.com/ministryofjustice/opg-modernising-lpa/internal/actor/actoruid" "github.com/ministryofjustice/opg-modernising-lpa/internal/page" "github.com/stretchr/testify/assert" mock "github.com/stretchr/testify/mock" @@ -27,7 +28,8 @@ func TestAttorneyStoreCreate(t *testing.T) { t.Run(name, func(t *testing.T) { ctx := page.ContextWithSessionData(context.Background(), &page.SessionData{LpaID: "123", SessionID: "456"}) now := time.Now() - details := &actor.AttorneyProvidedDetails{PK: "LPA#123", SK: "#ATTORNEY#456", ID: "attorney-id", LpaID: "123", UpdatedAt: now, IsReplacement: tc.replacement, IsTrustCorporation: tc.trustCorporation} + uid := actoruid.New() + details := &actor.AttorneyProvidedDetails{PK: "LPA#123", SK: "#ATTORNEY#456", UID: uid, LpaID: "123", UpdatedAt: now, IsReplacement: tc.replacement, IsTrustCorporation: tc.trustCorporation} dynamoClient := newMockDynamoClient(t) dynamoClient.EXPECT(). @@ -39,7 +41,7 @@ func TestAttorneyStoreCreate(t *testing.T) { attorneyStore := &attorneyStore{dynamoClient: dynamoClient, now: func() time.Time { return now }} - attorney, err := attorneyStore.Create(ctx, "session-id", "attorney-id", tc.replacement, tc.trustCorporation) + attorney, err := attorneyStore.Create(ctx, "session-id", uid, tc.replacement, tc.trustCorporation) assert.Nil(t, err) assert.Equal(t, details, attorney) }) @@ -51,7 +53,7 @@ func TestAttorneyStoreCreateWhenSessionMissing(t *testing.T) { attorneyStore := &attorneyStore{dynamoClient: nil, now: nil} - _, err := attorneyStore.Create(ctx, "session-id", "attorney-id", false, false) + _, err := attorneyStore.Create(ctx, "session-id", actoruid.New(), false, false) assert.Equal(t, page.SessionMissingError{}, err) } @@ -67,7 +69,7 @@ func TestAttorneyStoreCreateWhenSessionDataMissing(t *testing.T) { attorneyStore := &attorneyStore{} - _, err := attorneyStore.Create(ctx, "session-id", "attorney-id", false, false) + _, err := attorneyStore.Create(ctx, "session-id", actoruid.New(), false, false) assert.NotNil(t, err) }) } @@ -106,7 +108,7 @@ func TestAttorneyStoreCreateWhenCreateError(t *testing.T) { attorneyStore := &attorneyStore{dynamoClient: dynamoClient, now: func() time.Time { return now }} - _, err := attorneyStore.Create(ctx, "session-id", "attorney-id", false, false) + _, err := attorneyStore.Create(ctx, "session-id", actoruid.New(), false, false) assert.Equal(t, expectedError, err) }) } diff --git a/internal/app/donor_store.go b/internal/app/donor_store.go index cdaa384c8c..18cb6438c9 100644 --- a/internal/app/donor_store.go +++ b/internal/app/donor_store.go @@ -7,6 +7,7 @@ import ( "github.com/aws/aws-sdk-go-v2/service/s3" "github.com/ministryofjustice/opg-modernising-lpa/internal/actor" + "github.com/ministryofjustice/opg-modernising-lpa/internal/actor/actoruid" "github.com/ministryofjustice/opg-modernising-lpa/internal/event" "github.com/ministryofjustice/opg-modernising-lpa/internal/page" "github.com/ministryofjustice/opg-modernising-lpa/internal/uid" @@ -34,6 +35,7 @@ type donorStore struct { eventClient EventClient logger Logger uuidString func() string + newUID func() actoruid.UID now func() time.Time s3Client *s3.Client documentStore DocumentStore @@ -50,6 +52,7 @@ func (s *donorStore) Create(ctx context.Context) (*actor.DonorProvidedDetails, e } lpaID := s.uuidString() + donorUID := s.newUID() donor := &actor.DonorProvidedDetails{ PK: lpaKey(lpaID), @@ -57,6 +60,9 @@ func (s *donorStore) Create(ctx context.Context) (*actor.DonorProvidedDetails, e LpaID: lpaID, CreatedAt: s.now(), Version: 1, + Donor: actor.Donor{ + UID: donorUID, + }, } latest, err := s.Latest(ctx) diff --git a/internal/app/donor_store_test.go b/internal/app/donor_store_test.go index 4724cb0e82..84829fc975 100644 --- a/internal/app/donor_store_test.go +++ b/internal/app/donor_store_test.go @@ -8,6 +8,7 @@ import ( "time" "github.com/ministryofjustice/opg-modernising-lpa/internal/actor" + "github.com/ministryofjustice/opg-modernising-lpa/internal/actor/actoruid" "github.com/ministryofjustice/opg-modernising-lpa/internal/date" "github.com/ministryofjustice/opg-modernising-lpa/internal/dynamo" "github.com/ministryofjustice/opg-modernising-lpa/internal/event" @@ -23,6 +24,8 @@ var ( expectedError = errors.New("err") testNow = time.Date(2023, time.April, 2, 3, 4, 5, 6, time.UTC) testNowFn = func() time.Time { return testNow } + testUID = actoruid.New() + testUIDFn = func() actoruid.UID { return testUID } ) func (m *mockDynamoClient) ExpectOne(ctx, pk, sk, data interface{}, err error) { @@ -487,12 +490,15 @@ func TestDonorStorePutWhenPreviousApplicationLinkedWhenError(t *testing.T) { func TestDonorStoreCreate(t *testing.T) { testCases := map[string]actor.DonorProvidedDetails{ - "with previous details": {Donor: actor.Donor{ - FirstNames: "a", - LastName: "b", - OtherNames: "c", - DateOfBirth: date.New("2000", "01", "02"), - Address: place.Address{Line1: "d"}}, + "with previous details": { + Donor: actor.Donor{ + UID: actoruid.New(), + FirstNames: "a", + LastName: "b", + OtherNames: "c", + DateOfBirth: date.New("2000", "01", "02"), + Address: place.Address{Line1: "d"}, + }, }, "no previous details": {}, } @@ -507,6 +513,7 @@ func TestDonorStoreCreate(t *testing.T) { CreatedAt: testNow, Version: 1, Donor: actor.Donor{ + UID: testUID, FirstNames: previousDetails.Donor.FirstNames, LastName: previousDetails.Donor.LastName, OtherNames: previousDetails.Donor.OtherNames, @@ -526,7 +533,7 @@ func TestDonorStoreCreate(t *testing.T) { Create(ctx, lpaLink{PK: "LPA#10100000", SK: "#SUB#an-id", DonorKey: "#DONOR#an-id", ActorType: actor.TypeDonor, UpdatedAt: testNow}). Return(nil) - donorStore := &donorStore{dynamoClient: dynamoClient, uuidString: func() string { return "10100000" }, now: testNowFn} + donorStore := &donorStore{dynamoClient: dynamoClient, uuidString: func() string { return "10100000" }, now: testNowFn, newUID: testUIDFn} result, err := donorStore.Create(ctx) assert.Nil(t, err) @@ -589,6 +596,7 @@ func TestDonorStoreCreateWhenError(t *testing.T) { dynamoClient: dynamoClient, uuidString: func() string { return "10100000" }, now: testNowFn, + newUID: testUIDFn, } _, err := donorStore.Create(ctx) diff --git a/internal/lpastore/client.go b/internal/lpastore/client.go index 18523aadfd..063e144167 100644 --- a/internal/lpastore/client.go +++ b/internal/lpastore/client.go @@ -11,6 +11,7 @@ import ( "github.com/golang-jwt/jwt/v5" "github.com/ministryofjustice/opg-modernising-lpa/internal/actor" + "github.com/ministryofjustice/opg-modernising-lpa/internal/actor/actoruid" "github.com/ministryofjustice/opg-modernising-lpa/internal/date" "github.com/ministryofjustice/opg-modernising-lpa/internal/place" "github.com/ministryofjustice/opg-modernising-lpa/internal/secrets" @@ -71,6 +72,7 @@ type lpaRequest struct { } type lpaRequestDonor struct { + UID actoruid.UID `json:"uid"` FirstNames string `json:"firstNames"` LastName string `json:"lastName"` DateOfBirth date.Date `json:"dateOfBirth"` @@ -80,6 +82,7 @@ type lpaRequestDonor struct { } type lpaRequestAttorney struct { + UID actoruid.UID `json:"uid"` FirstNames string `json:"firstNames"` LastName string `json:"lastName"` DateOfBirth date.Date `json:"dateOfBirth"` @@ -89,6 +92,7 @@ type lpaRequestAttorney struct { } type lpaRequestTrustCorporation struct { + UID actoruid.UID `json:"uid"` Name string `json:"name"` CompanyNumber string `json:"companyNumber"` Email string `json:"email"` @@ -97,6 +101,7 @@ type lpaRequestTrustCorporation struct { } type lpaRequestCertificateProvider struct { + UID actoruid.UID `json:"uid"` FirstNames string `json:"firstNames"` LastName string `json:"lastName"` Email string `json:"email,omitempty"` @@ -105,6 +110,7 @@ type lpaRequestCertificateProvider struct { } type lpaRequestPersonToNotify struct { + UID actoruid.UID `json:"uid"` FirstNames string `json:"firstNames"` LastName string `json:"lastName"` Address place.Address `json:"address"` @@ -114,6 +120,7 @@ func (c *Client) SendLpa(ctx context.Context, donor *actor.DonorProvidedDetails) body := lpaRequest{ LpaType: donor.Type, Donor: lpaRequestDonor{ + UID: donor.Donor.UID, FirstNames: donor.Donor.FirstNames, LastName: donor.Donor.LastName, DateOfBirth: donor.Donor.DateOfBirth, @@ -122,6 +129,7 @@ func (c *Client) SendLpa(ctx context.Context, donor *actor.DonorProvidedDetails) OtherNamesKnownBy: donor.Donor.OtherNames, }, CertificateProvider: lpaRequestCertificateProvider{ + UID: donor.CertificateProvider.UID, FirstNames: donor.CertificateProvider.FirstNames, LastName: donor.CertificateProvider.LastName, Email: donor.CertificateProvider.Email, @@ -160,6 +168,7 @@ func (c *Client) SendLpa(ctx context.Context, donor *actor.DonorProvidedDetails) for _, attorney := range donor.Attorneys.Attorneys { body.Attorneys = append(body.Attorneys, lpaRequestAttorney{ + UID: attorney.UID, FirstNames: attorney.FirstNames, LastName: attorney.LastName, DateOfBirth: attorney.DateOfBirth, @@ -171,6 +180,7 @@ func (c *Client) SendLpa(ctx context.Context, donor *actor.DonorProvidedDetails) if trustCorporation := donor.Attorneys.TrustCorporation; trustCorporation.Name != "" { body.TrustCorporations = append(body.TrustCorporations, lpaRequestTrustCorporation{ + UID: trustCorporation.UID, Name: trustCorporation.Name, CompanyNumber: trustCorporation.CompanyNumber, Email: trustCorporation.Email, @@ -181,6 +191,7 @@ func (c *Client) SendLpa(ctx context.Context, donor *actor.DonorProvidedDetails) for _, attorney := range donor.ReplacementAttorneys.Attorneys { body.Attorneys = append(body.Attorneys, lpaRequestAttorney{ + UID: attorney.UID, FirstNames: attorney.FirstNames, LastName: attorney.LastName, DateOfBirth: attorney.DateOfBirth, @@ -192,6 +203,7 @@ func (c *Client) SendLpa(ctx context.Context, donor *actor.DonorProvidedDetails) if trustCorporation := donor.ReplacementAttorneys.TrustCorporation; trustCorporation.Name != "" { body.TrustCorporations = append(body.TrustCorporations, lpaRequestTrustCorporation{ + UID: trustCorporation.UID, Name: trustCorporation.Name, CompanyNumber: trustCorporation.CompanyNumber, Email: trustCorporation.Email, @@ -202,6 +214,7 @@ func (c *Client) SendLpa(ctx context.Context, donor *actor.DonorProvidedDetails) for _, person := range donor.PeopleToNotify { body.PeopleToNotify = append(body.PeopleToNotify, lpaRequestPersonToNotify{ + UID: person.UID, FirstNames: person.FirstNames, LastName: person.LastName, Address: person.Address, @@ -275,9 +288,9 @@ func (c *Client) SendAttorney(ctx context.Context, donor *actor.DonorProvidedDet } else if attorney.IsTrustCorporation { attorneyKey = "/trustCorporations/0" } else if attorney.IsReplacement { - attorneyKey = fmt.Sprintf("/attorneys/%d", len(donor.Attorneys.Attorneys)+donor.ReplacementAttorneys.Index(attorney.ID)) + attorneyKey = fmt.Sprintf("/attorneys/%d", len(donor.Attorneys.Attorneys)+donor.ReplacementAttorneys.Index(attorney.UID)) } else { - attorneyKey = fmt.Sprintf("/attorneys/%d", donor.Attorneys.Index(attorney.ID)) + attorneyKey = fmt.Sprintf("/attorneys/%d", donor.Attorneys.Index(attorney.UID)) } body := updateRequest{ diff --git a/internal/lpastore/client_test.go b/internal/lpastore/client_test.go index 9964dc3c6d..7327d41c0a 100644 --- a/internal/lpastore/client_test.go +++ b/internal/lpastore/client_test.go @@ -15,6 +15,7 @@ import ( "github.com/aws/aws-sdk-go-v2/aws" v4 "github.com/aws/aws-sdk-go-v2/aws/signer/v4" "github.com/ministryofjustice/opg-modernising-lpa/internal/actor" + "github.com/ministryofjustice/opg-modernising-lpa/internal/actor/actoruid" "github.com/ministryofjustice/opg-modernising-lpa/internal/date" "github.com/ministryofjustice/opg-modernising-lpa/internal/lambda" "github.com/ministryofjustice/opg-modernising-lpa/internal/localize" @@ -41,6 +42,10 @@ func (m *mockCredentialsProvider) IsExpired() bool { return false } +func ActorUID() matchers.Matcher { + return matchers.Regex("urn:opg:poas:makeregister:users:123e4567-e89b-12d3-a456-426655440000", "urn:opg:poas:makeregister:users:[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}") +} + func TestResponseError(t *testing.T) { err := responseError{name: "name", body: 5} assert.Equal(t, "name", err.Error()) @@ -49,6 +54,16 @@ func TestResponseError(t *testing.T) { } func TestClientSendLpa(t *testing.T) { + donorUID := actoruid.New() + trustCorporationUID := actoruid.New() + attorneyUID := actoruid.New() + attorney2UID := actoruid.New() + replacementTrustCorporationUID := actoruid.New() + replacementAttorneyUID := actoruid.New() + replacementAttorney2UID := actoruid.New() + certificateProviderUID := actoruid.New() + personToNotifyUID := actoruid.New() + testcases := map[string]struct { donor *actor.DonorProvidedDetails json string @@ -58,6 +73,7 @@ func TestClientSendLpa(t *testing.T) { LpaUID: "M-0000-1111-2222", Type: actor.LpaTypePropertyAndAffairs, Donor: actor.Donor{ + UID: donorUID, FirstNames: "John Johnson", LastName: "Smith", DateOfBirth: date.New("2000", "1", "2"), @@ -71,6 +87,7 @@ func TestClientSendLpa(t *testing.T) { }, Attorneys: actor.Attorneys{ Attorneys: []actor.Attorney{{ + UID: attorneyUID, FirstNames: "Adam", LastName: "Attorney", DateOfBirth: date.New("1999", "1", "2"), @@ -85,6 +102,7 @@ func TestClientSendLpa(t *testing.T) { ReplacementAttorneys: actor.Attorneys{}, WhenCanTheLpaBeUsed: actor.CanBeUsedWhenCapacityLost, CertificateProvider: actor.CertificateProvider{ + UID: certificateProviderUID, FirstNames: "Carol", LastName: "Cert", Address: place.Address{ @@ -96,13 +114,22 @@ func TestClientSendLpa(t *testing.T) { }, SignedAt: time.Date(2000, time.January, 2, 3, 4, 5, 6, time.UTC), }, - json: `{"lpaType":"property-and-affairs","donor":{"firstNames":"John Johnson","lastName":"Smith","dateOfBirth":"2000-01-02","email":"john@example.com","address":{"line1":"line-1","line2":"","line3":"","town":"town","postcode":"","country":"GB"},"otherNamesKnownBy":"JJ"},"attorneys":[{"firstNames":"Adam","lastName":"Attorney","dateOfBirth":"1999-01-02","email":"adam@example.com","address":{"line1":"a-line-1","line2":"","line3":"","town":"a-town","postcode":"","country":"GB"},"status":"active"}],"certificateProvider":{"firstNames":"Carol","lastName":"Cert","address":{"line1":"c-line-1","line2":"","line3":"","town":"c-town","postcode":"","country":"GB"},"channel":"paper"},"restrictionsAndConditions":"","whenTheLpaCanBeUsed":"when-capacity-lost","signedAt":"2000-01-02T03:04:05.000000006Z"}`, + json: `{ +"lpaType":"property-and-affairs", +"donor":{"uid":"` + donorUID.PrefixedString() + `","firstNames":"John Johnson","lastName":"Smith","dateOfBirth":"2000-01-02","email":"john@example.com","address":{"line1":"line-1","line2":"","line3":"","town":"town","postcode":"","country":"GB"},"otherNamesKnownBy":"JJ"}, +"attorneys":[{"uid":"` + attorneyUID.PrefixedString() + `","firstNames":"Adam","lastName":"Attorney","dateOfBirth":"1999-01-02","email":"adam@example.com","address":{"line1":"a-line-1","line2":"","line3":"","town":"a-town","postcode":"","country":"GB"},"status":"active"}], +"certificateProvider":{"uid":"` + certificateProviderUID.PrefixedString() + `","firstNames":"Carol","lastName":"Cert","address":{"line1":"c-line-1","line2":"","line3":"","town":"c-town","postcode":"","country":"GB"},"channel":"paper"}, +"restrictionsAndConditions":"", +"whenTheLpaCanBeUsed":"when-capacity-lost", +"signedAt":"2000-01-02T03:04:05.000000006Z" +}`, }, "everything": { donor: &actor.DonorProvidedDetails{ LpaUID: "M-0000-1111-2222", Type: actor.LpaTypePersonalWelfare, Donor: actor.Donor{ + UID: donorUID, FirstNames: "John Johnson", LastName: "Smith", DateOfBirth: date.New("2000", "1", "2"), @@ -119,6 +146,7 @@ func TestClientSendLpa(t *testing.T) { }, Attorneys: actor.Attorneys{ TrustCorporation: actor.TrustCorporation{ + UID: trustCorporationUID, Name: "Trusty", CompanyNumber: "55555", Email: "trusty@example.com", @@ -132,6 +160,7 @@ func TestClientSendLpa(t *testing.T) { }, }, Attorneys: []actor.Attorney{{ + UID: attorneyUID, FirstNames: "Adam", LastName: "Attorney", DateOfBirth: date.New("1999", "1", "2"), @@ -145,6 +174,7 @@ func TestClientSendLpa(t *testing.T) { Country: "GB", }, }, { + UID: attorney2UID, FirstNames: "Alice", LastName: "Attorney", DateOfBirth: date.New("1998", "1", "2"), @@ -164,6 +194,7 @@ func TestClientSendLpa(t *testing.T) { }, ReplacementAttorneys: actor.Attorneys{ TrustCorporation: actor.TrustCorporation{ + UID: replacementTrustCorporationUID, Name: "UnTrusty", CompanyNumber: "65555", Email: "untrusty@example.com", @@ -177,6 +208,7 @@ func TestClientSendLpa(t *testing.T) { }, }, Attorneys: []actor.Attorney{{ + UID: replacementAttorneyUID, FirstNames: "Richard", LastName: "Attorney", DateOfBirth: date.New("1999", "11", "12"), @@ -190,6 +222,7 @@ func TestClientSendLpa(t *testing.T) { Country: "GB", }, }, { + UID: replacementAttorney2UID, FirstNames: "Rachel", LastName: "Attorney", DateOfBirth: date.New("1998", "11", "12"), @@ -212,6 +245,7 @@ func TestClientSendLpa(t *testing.T) { LifeSustainingTreatmentOption: actor.LifeSustainingTreatmentOptionA, Restrictions: "do not do this", CertificateProvider: actor.CertificateProvider{ + UID: certificateProviderUID, FirstNames: "Carol", LastName: "Cert", Email: "carol@example.com", @@ -226,6 +260,7 @@ func TestClientSendLpa(t *testing.T) { CarryOutBy: actor.Online, }, PeopleToNotify: actor.PeopleToNotify{{ + UID: personToNotifyUID, FirstNames: "Peter", LastName: "Notify", Address: place.Address{ @@ -240,7 +275,29 @@ func TestClientSendLpa(t *testing.T) { SignedAt: time.Date(2000, time.January, 2, 3, 4, 5, 6, time.UTC), CertificateProviderNotRelatedConfirmedAt: time.Date(2001, time.February, 3, 4, 5, 6, 7, time.UTC), }, - json: `{"lpaType":"personal-welfare","donor":{"firstNames":"John Johnson","lastName":"Smith","dateOfBirth":"2000-01-02","email":"john@example.com","address":{"line1":"line-1","line2":"line-2","line3":"line-3","town":"town","postcode":"F1 1FF","country":"GB"},"otherNamesKnownBy":"JJ"},"attorneys":[{"firstNames":"Adam","lastName":"Attorney","dateOfBirth":"1999-01-02","email":"adam@example.com","address":{"line1":"a-line-1","line2":"a-line-2","line3":"a-line-3","town":"a-town","postcode":"A1 1FF","country":"GB"},"status":"active"},{"firstNames":"Alice","lastName":"Attorney","dateOfBirth":"1998-01-02","email":"alice@example.com","address":{"line1":"aa-line-1","line2":"aa-line-2","line3":"aa-line-3","town":"aa-town","postcode":"A1 1AF","country":"GB"},"status":"active"},{"firstNames":"Richard","lastName":"Attorney","dateOfBirth":"1999-11-12","email":"richard@example.com","address":{"line1":"r-line-1","line2":"r-line-2","line3":"r-line-3","town":"r-town","postcode":"R1 1FF","country":"GB"},"status":"replacement"},{"firstNames":"Rachel","lastName":"Attorney","dateOfBirth":"1998-11-12","email":"rachel@example.com","address":{"line1":"rr-line-1","line2":"rr-line-2","line3":"rr-line-3","town":"rr-town","postcode":"R1 1RF","country":"GB"},"status":"replacement"}],"trustCorporations":[{"name":"Trusty","companyNumber":"55555","email":"trusty@example.com","address":{"line1":"a-line-1","line2":"a-line-2","line3":"a-line-3","town":"a-town","postcode":"A1 1FF","country":"GB"},"status":"active"},{"name":"UnTrusty","companyNumber":"65555","email":"untrusty@example.com","address":{"line1":"a-line-1","line2":"a-line-2","line3":"a-line-3","town":"a-town","postcode":"A1 1FF","country":"GB"},"status":"replacement"}],"certificateProvider":{"firstNames":"Carol","lastName":"Cert","email":"carol@example.com","address":{"line1":"c-line-1","line2":"c-line-2","line3":"c-line-3","town":"c-town","postcode":"C1 1FF","country":"GB"},"channel":"online"},"peopleToNotify":[{"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"}}],"howAttorneysMakeDecisions":"jointly","howReplacementAttorneysMakeDecisions":"jointly-for-some-severally-for-others","howReplacementAttorneysMakeDecisionsDetails":"umm","restrictionsAndConditions":"do not do this","lifeSustainingTreatmentOption":"option-a","signedAt":"2000-01-02T03:04:05.000000006Z","certificateProviderNotRelatedConfirmedAt":"2001-02-03T04:05:06.000000007Z"}`, + json: `{ +"lpaType":"personal-welfare", +"donor":{"uid":"` + donorUID.PrefixedString() + `","firstNames":"John Johnson","lastName":"Smith","dateOfBirth":"2000-01-02","email":"john@example.com","address":{"line1":"line-1","line2":"line-2","line3":"line-3","town":"town","postcode":"F1 1FF","country":"GB"},"otherNamesKnownBy":"JJ"}, +"attorneys":[ +{"uid":"` + attorneyUID.PrefixedString() + `","firstNames":"Adam","lastName":"Attorney","dateOfBirth":"1999-01-02","email":"adam@example.com","address":{"line1":"a-line-1","line2":"a-line-2","line3":"a-line-3","town":"a-town","postcode":"A1 1FF","country":"GB"},"status":"active"}, +{"uid":"` + attorney2UID.PrefixedString() + `","firstNames":"Alice","lastName":"Attorney","dateOfBirth":"1998-01-02","email":"alice@example.com","address":{"line1":"aa-line-1","line2":"aa-line-2","line3":"aa-line-3","town":"aa-town","postcode":"A1 1AF","country":"GB"},"status":"active"}, +{"uid":"` + replacementAttorneyUID.PrefixedString() + `","firstNames":"Richard","lastName":"Attorney","dateOfBirth":"1999-11-12","email":"richard@example.com","address":{"line1":"r-line-1","line2":"r-line-2","line3":"r-line-3","town":"r-town","postcode":"R1 1FF","country":"GB"},"status":"replacement"}, +{"uid":"` + replacementAttorney2UID.PrefixedString() + `","firstNames":"Rachel","lastName":"Attorney","dateOfBirth":"1998-11-12","email":"rachel@example.com","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.PrefixedString() + `","name":"Trusty","companyNumber":"55555","email":"trusty@example.com","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.PrefixedString() + `","name":"UnTrusty","companyNumber":"65555","email":"untrusty@example.com","address":{"line1":"a-line-1","line2":"a-line-2","line3":"a-line-3","town":"a-town","postcode":"A1 1FF","country":"GB"},"status":"replacement"} +], +"certificateProvider":{"uid":"` + certificateProviderUID.PrefixedString() + `","firstNames":"Carol","lastName":"Cert","email":"carol@example.com","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.PrefixedString() + `","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"}}], +"howAttorneysMakeDecisions":"jointly", +"howReplacementAttorneysMakeDecisions":"jointly-for-some-severally-for-others", +"howReplacementAttorneysMakeDecisionsDetails":"umm", +"restrictionsAndConditions":"do not do this", +"lifeSustainingTreatmentOption":"option-a", +"signedAt":"2000-01-02T03:04:05.000000006Z", +"certificateProviderNotRelatedConfirmedAt":"2001-02-03T04:05:06.000000007Z"} +`, }, } @@ -387,6 +444,9 @@ func TestClientSendCertificateProvider(t *testing.T) { } func TestClientSendAttorney(t *testing.T) { + uid1 := actoruid.New() + uid2 := actoruid.New() + testcases := map[string]struct { attorney *actor.AttorneyProvidedDetails donor *actor.DonorProvidedDetails @@ -394,7 +454,7 @@ func TestClientSendAttorney(t *testing.T) { }{ "attorney": { attorney: &actor.AttorneyProvidedDetails{ - ID: "xyz", + UID: uid2, Mobile: "07777", Confirmed: time.Date(2000, time.January, 2, 3, 4, 5, 6, time.UTC), ContactLanguagePreference: localize.Cy, @@ -403,7 +463,7 @@ func TestClientSendAttorney(t *testing.T) { LpaUID: "lpa-uid", Attorneys: actor.Attorneys{ Attorneys: []actor.Attorney{ - {ID: "abc"}, {ID: "xyz"}, + {UID: uid1}, {UID: uid2}, }, }, }, @@ -411,7 +471,7 @@ func TestClientSendAttorney(t *testing.T) { }, "replacement attorney": { attorney: &actor.AttorneyProvidedDetails{ - ID: "xyz", + UID: uid2, IsReplacement: true, Mobile: "07777", Confirmed: time.Date(2000, time.January, 2, 3, 4, 5, 6, time.UTC), @@ -421,12 +481,12 @@ func TestClientSendAttorney(t *testing.T) { LpaUID: "lpa-uid", Attorneys: actor.Attorneys{ Attorneys: []actor.Attorney{ - {ID: "abc"}, {ID: "xyz"}, + {UID: uid1}, {UID: uid2}, }, }, ReplacementAttorneys: actor.Attorneys{ Attorneys: []actor.Attorney{ - {ID: "abc"}, {ID: "xyz"}, + {UID: uid1}, {UID: uid2}, }, }, }, @@ -434,7 +494,7 @@ func TestClientSendAttorney(t *testing.T) { }, "trust corporation": { attorney: &actor.AttorneyProvidedDetails{ - ID: "xyz", + UID: uid2, IsTrustCorporation: true, Mobile: "07777", AuthorisedSignatories: [2]actor.TrustCorporationSignatory{{ @@ -457,7 +517,7 @@ func TestClientSendAttorney(t *testing.T) { }, "replacement trust corporation": { attorney: &actor.AttorneyProvidedDetails{ - ID: "xyz", + UID: uid2, IsTrustCorporation: true, IsReplacement: true, Mobile: "07777", @@ -476,7 +536,7 @@ func TestClientSendAttorney(t *testing.T) { }, "replacement trust corporation when also attorney trust corporation": { attorney: &actor.AttorneyProvidedDetails{ - ID: "xyz", + UID: uid2, IsTrustCorporation: true, IsReplacement: true, Mobile: "07777", @@ -571,6 +631,7 @@ func TestClientServiceContract(t *testing.T) { "lpaType": matchers.Regex("personal-welfare", "personal-welfare|property-and-affairs"), "lifeSustainingTreatmentOption": matchers.Regex("option-a", "option-a|option-b"), "donor": matchers.Like(map[string]any{ + "uid": ActorUID(), "firstNames": matchers.String("John Johnson"), "lastName": matchers.String("Smith"), "dateOfBirth": matchers.Regex("2000-01-02", "\\d{4}-\\d{2}-\\d{2}"), @@ -585,6 +646,7 @@ func TestClientServiceContract(t *testing.T) { }), }), "attorneys": matchers.EachLike(map[string]any{ + "uid": ActorUID(), "firstNames": matchers.String("Adam"), "lastName": matchers.String("Attorney"), "dateOfBirth": matchers.Regex("1999-01-02", "\\d{4}-\\d{2}-\\d{2}"), @@ -600,6 +662,7 @@ func TestClientServiceContract(t *testing.T) { "status": matchers.Regex("active", "active|replacement"), }, 1), "certificateProvider": matchers.Like(map[string]any{ + "uid": ActorUID(), "firstNames": matchers.String("Charles"), "lastName": matchers.String("Certificate"), "email": matchers.String("charles@example.com"), @@ -642,6 +705,7 @@ func TestClientServiceContract(t *testing.T) { Type: actor.LpaTypePersonalWelfare, LifeSustainingTreatmentOption: actor.LifeSustainingTreatmentOptionA, Donor: actor.Donor{ + UID: actoruid.New(), FirstNames: "John Johnson", LastName: "Smith", DateOfBirth: date.New("2000", "1", "2"), @@ -650,6 +714,7 @@ func TestClientServiceContract(t *testing.T) { }, Attorneys: actor.Attorneys{ Attorneys: []actor.Attorney{{ + UID: actoruid.New(), FirstNames: "Alice", LastName: "Attorney", DateOfBirth: date.New("1998", "1", "2"), @@ -659,6 +724,7 @@ func TestClientServiceContract(t *testing.T) { }, ReplacementAttorneys: actor.Attorneys{ Attorneys: []actor.Attorney{{ + UID: actoruid.New(), FirstNames: "Richard", LastName: "Attorney", DateOfBirth: date.New("1999", "11", "12"), @@ -667,6 +733,7 @@ func TestClientServiceContract(t *testing.T) { }}, }, CertificateProvider: actor.CertificateProvider{ + UID: actoruid.New(), FirstNames: "Charles", LastName: "Certificate", Email: "charles@example.com", @@ -696,6 +763,7 @@ func TestClientServiceContract(t *testing.T) { JSONBody(matchers.Map{ "lpaType": matchers.Regex("personal-welfare", "personal-welfare|property-and-affairs"), "donor": matchers.Like(map[string]any{ + "uid": ActorUID(), "firstNames": matchers.String("John Johnson"), "lastName": matchers.String("Smith"), "dateOfBirth": matchers.Regex("2000-01-02", "\\d{4}-\\d{2}-\\d{2}"), @@ -711,6 +779,7 @@ func TestClientServiceContract(t *testing.T) { "otherNamesKnownBy": matchers.String("JJ"), }), "attorneys": matchers.EachLike(map[string]any{ + "uid": ActorUID(), "firstNames": matchers.String("Adam"), "lastName": matchers.String("Attorney"), "dateOfBirth": matchers.Regex("1999-01-02", "\\d{4}-\\d{2}-\\d{2}"), @@ -726,6 +795,7 @@ func TestClientServiceContract(t *testing.T) { "status": matchers.Regex("active", "active|replacement"), }, 1), "certificateProvider": matchers.Like(map[string]any{ + "uid": ActorUID(), "firstNames": matchers.String("Charles"), "lastName": matchers.String("Certificate"), "email": matchers.String("charles@example.com"), @@ -740,6 +810,7 @@ func TestClientServiceContract(t *testing.T) { "channel": matchers.Regex("online", "online|post"), }), "peopleToNotify": matchers.EachLike(map[string]any{ + "uid": ActorUID(), "firstNames": matchers.String("Peter"), "lastName": matchers.String("Person"), "address": matchers.Like(map[string]any{ @@ -782,6 +853,7 @@ func TestClientServiceContract(t *testing.T) { LpaUID: "M-0000-1111-2222", Type: actor.LpaTypePersonalWelfare, Donor: actor.Donor{ + UID: actoruid.New(), FirstNames: "John Johnson", LastName: "Smith", DateOfBirth: date.New("2000", "1", "2"), @@ -791,6 +863,7 @@ func TestClientServiceContract(t *testing.T) { }, Attorneys: actor.Attorneys{ Attorneys: []actor.Attorney{{ + UID: actoruid.New(), FirstNames: "Alice", LastName: "Attorney", DateOfBirth: date.New("1998", "1", "2"), @@ -800,6 +873,7 @@ func TestClientServiceContract(t *testing.T) { }, ReplacementAttorneys: actor.Attorneys{ Attorneys: []actor.Attorney{{ + UID: actoruid.New(), FirstNames: "Richard", LastName: "Attorney", DateOfBirth: date.New("1999", "11", "12"), @@ -808,6 +882,7 @@ func TestClientServiceContract(t *testing.T) { }}, }, CertificateProvider: actor.CertificateProvider{ + UID: actoruid.New(), FirstNames: "Charles", LastName: "Certificate", Email: "charles@example.com", @@ -815,6 +890,7 @@ func TestClientServiceContract(t *testing.T) { CarryOutBy: actor.Online, }, PeopleToNotify: actor.PeopleToNotify{{ + UID: actoruid.New(), FirstNames: "Peter", LastName: "Person", Address: address, @@ -829,6 +905,8 @@ func TestClientServiceContract(t *testing.T) { }) t.Run("SendAttorney", func(t *testing.T) { + uid := actoruid.New() + mockProvider. AddInteraction(). Given("An LPA with UID M-0000-1111-2222 exists"). @@ -880,11 +958,11 @@ func TestClientServiceContract(t *testing.T) { &actor.DonorProvidedDetails{ LpaUID: "M-0000-1111-2222", Attorneys: actor.Attorneys{ - Attorneys: []actor.Attorney{{ID: "abcde"}}, + Attorneys: []actor.Attorney{{UID: uid}}, }, }, &actor.AttorneyProvidedDetails{ - ID: "abcde", + UID: uid, Mobile: "07777777", Confirmed: time.Date(2020, time.January, 1, 12, 13, 14, 0, time.UTC), ContactLanguagePreference: localize.Cy, diff --git a/internal/page/app_data.go b/internal/page/app_data.go index 6ff71815f0..0c0cc37217 100644 --- a/internal/page/app_data.go +++ b/internal/page/app_data.go @@ -5,6 +5,7 @@ import ( "net/http" "github.com/ministryofjustice/opg-modernising-lpa/internal/actor" + "github.com/ministryofjustice/opg-modernising-lpa/internal/actor/actoruid" "github.com/ministryofjustice/opg-modernising-lpa/internal/localize" ) @@ -20,7 +21,7 @@ type AppData struct { LpaID string CsrfToken string ActorType actor.Type - AttorneyID string + AttorneyUID actoruid.UID IsSupporter bool OrganisationName string IsManageOrganisation bool @@ -54,5 +55,5 @@ func (d AppData) IsReplacementAttorney() bool { } func (d AppData) IsTrustCorporation() bool { - return (d.ActorType == actor.TypeAttorney || d.ActorType == actor.TypeReplacementAttorney) && d.AttorneyID == "" + return d.ActorType == actor.TypeTrustCorporation || d.ActorType == actor.TypeReplacementTrustCorporation } diff --git a/internal/page/app_data_test.go b/internal/page/app_data_test.go index a52f3ed906..a5e9c2ee6a 100644 --- a/internal/page/app_data_test.go +++ b/internal/page/app_data_test.go @@ -7,6 +7,7 @@ import ( "testing" "github.com/ministryofjustice/opg-modernising-lpa/internal/actor" + "github.com/ministryofjustice/opg-modernising-lpa/internal/actor/actoruid" "github.com/ministryofjustice/opg-modernising-lpa/internal/localize" "github.com/stretchr/testify/assert" ) @@ -64,9 +65,9 @@ func TestIsReplacementAttorney(t *testing.T) { } func TestIsTrustCorporation(t *testing.T) { - assert.True(t, AppData{ActorType: actor.TypeAttorney}.IsTrustCorporation()) - assert.True(t, AppData{ActorType: actor.TypeReplacementAttorney}.IsTrustCorporation()) + assert.True(t, AppData{ActorType: actor.TypeTrustCorporation, AttorneyUID: actoruid.New()}.IsTrustCorporation()) + assert.True(t, AppData{ActorType: actor.TypeReplacementTrustCorporation, AttorneyUID: actoruid.New()}.IsTrustCorporation()) - assert.False(t, AppData{ActorType: actor.TypeAttorney, AttorneyID: "1"}.IsTrustCorporation()) - assert.False(t, AppData{ActorType: actor.TypeReplacementAttorney, AttorneyID: "1"}.IsTrustCorporation()) + assert.False(t, AppData{ActorType: actor.TypeAttorney, AttorneyUID: actoruid.New()}.IsTrustCorporation()) + assert.False(t, AppData{ActorType: actor.TypeReplacementAttorney, AttorneyUID: actoruid.New()}.IsTrustCorporation()) } diff --git a/internal/page/attorney/confirm_your_details.go b/internal/page/attorney/confirm_your_details.go index 45aac01b63..99496864b0 100644 --- a/internal/page/attorney/confirm_your_details.go +++ b/internal/page/attorney/confirm_your_details.go @@ -49,7 +49,7 @@ func ConfirmYourDetails(tmpl template.Template, attorneyStore AttorneyStore, don if appData.IsTrustCorporation() { data.TrustCorporation = attorneys.TrustCorporation } else { - data.Attorney, _ = attorneys.Get(attorneyProvidedDetails.ID) + data.Attorney, _ = attorneys.Get(attorneyProvidedDetails.UID) } return tmpl(w, data) diff --git a/internal/page/attorney/confirm_your_details_test.go b/internal/page/attorney/confirm_your_details_test.go index cf166557d2..c08e95ce62 100644 --- a/internal/page/attorney/confirm_your_details_test.go +++ b/internal/page/attorney/confirm_your_details_test.go @@ -6,13 +6,15 @@ import ( "testing" "github.com/ministryofjustice/opg-modernising-lpa/internal/actor" + "github.com/ministryofjustice/opg-modernising-lpa/internal/actor/actoruid" "github.com/ministryofjustice/opg-modernising-lpa/internal/page" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/mock" ) func TestGetConfirmYourDetails(t *testing.T) { - attorneyProvidedDetails := &actor.AttorneyProvidedDetails{ID: "123"} + uid := actoruid.New() + attorneyProvidedDetails := &actor.AttorneyProvidedDetails{UID: uid} testcases := map[string]struct { appData page.AppData @@ -22,14 +24,14 @@ func TestGetConfirmYourDetails(t *testing.T) { "attorney": { appData: testAppData, donor: &actor.DonorProvidedDetails{ - Attorneys: actor.Attorneys{Attorneys: []actor.Attorney{{ID: "123", FirstNames: "John"}}}, + Attorneys: actor.Attorneys{Attorneys: []actor.Attorney{{UID: uid, FirstNames: "John"}}}, }, data: &confirmYourDetailsData{ App: testAppData, Donor: &actor.DonorProvidedDetails{ - Attorneys: actor.Attorneys{Attorneys: []actor.Attorney{{ID: "123", FirstNames: "John"}}}, + Attorneys: actor.Attorneys{Attorneys: []actor.Attorney{{UID: uid, FirstNames: "John"}}}, }, - Attorney: actor.Attorney{ID: "123", FirstNames: "John"}, + Attorney: actor.Attorney{UID: uid, FirstNames: "John"}, AttorneyProvidedDetails: attorneyProvidedDetails, }, }, @@ -109,19 +111,20 @@ func TestGetConfirmYourDetailsWhenTemplateErrors(t *testing.T) { } func TestPostConfirmYourDetails(t *testing.T) { + uid := actoruid.New() w := httptest.NewRecorder() r, _ := http.NewRequest(http.MethodPost, "/", nil) attorneyStore := newMockAttorneyStore(t) attorneyStore.EXPECT(). Put(r.Context(), &actor.AttorneyProvidedDetails{ - ID: "123", + UID: uid, LpaID: "lpa-id", Tasks: actor.AttorneyTasks{ConfirmYourDetails: actor.TaskCompleted}, }). Return(nil) - err := ConfirmYourDetails(nil, attorneyStore, nil)(testAppData, w, r, &actor.AttorneyProvidedDetails{ID: "123", LpaID: "lpa-id"}) + err := ConfirmYourDetails(nil, attorneyStore, nil)(testAppData, w, r, &actor.AttorneyProvidedDetails{UID: uid, LpaID: "lpa-id"}) resp := w.Result() assert.Nil(t, err) @@ -138,6 +141,6 @@ func TestPostConfirmYourDetailsWhenStoreErrors(t *testing.T) { Put(r.Context(), mock.Anything). Return(expectedError) - err := ConfirmYourDetails(nil, attorneyStore, nil)(testAppData, w, r, &actor.AttorneyProvidedDetails{ID: "123", LpaID: "lpa-id"}) + err := ConfirmYourDetails(nil, attorneyStore, nil)(testAppData, w, r, &actor.AttorneyProvidedDetails{UID: actoruid.New(), LpaID: "lpa-id"}) assert.Equal(t, expectedError, err) } diff --git a/internal/page/attorney/enter_reference_number.go b/internal/page/attorney/enter_reference_number.go index b5e270ebc1..78b22ea7b1 100644 --- a/internal/page/attorney/enter_reference_number.go +++ b/internal/page/attorney/enter_reference_number.go @@ -54,7 +54,7 @@ func EnterReferenceNumber(tmpl template.Template, shareCodeStore ShareCodeStore, LpaID: shareCode.LpaID, }) - if _, err := attorneyStore.Create(ctx, shareCode.SessionID, shareCode.AttorneyID, shareCode.IsReplacementAttorney, shareCode.IsTrustCorporation); err != nil { + if _, err := attorneyStore.Create(ctx, shareCode.SessionID, shareCode.AttorneyUID, shareCode.IsReplacementAttorney, shareCode.IsTrustCorporation); err != nil { var ccf *types.ConditionalCheckFailedException if !errors.As(err, &ccf) { return err diff --git a/internal/page/attorney/enter_reference_number_test.go b/internal/page/attorney/enter_reference_number_test.go index c9726b8872..a9770056bc 100644 --- a/internal/page/attorney/enter_reference_number_test.go +++ b/internal/page/attorney/enter_reference_number_test.go @@ -85,21 +85,21 @@ func TestPostEnterReferenceNumber(t *testing.T) { isTrustCorporation bool }{ "attorney": { - shareCode: actor.ShareCodeData{LpaID: "lpa-id", SessionID: "aGV5", AttorneyID: "attorney-id"}, + shareCode: actor.ShareCodeData{LpaID: "lpa-id", SessionID: "aGV5", AttorneyUID: testUID}, session: &sesh.LoginSession{Sub: "hey"}, }, "replacement": { - shareCode: actor.ShareCodeData{LpaID: "lpa-id", SessionID: "aGV5", AttorneyID: "attorney-id", IsReplacementAttorney: true}, + shareCode: actor.ShareCodeData{LpaID: "lpa-id", SessionID: "aGV5", AttorneyUID: testUID, IsReplacementAttorney: true}, session: &sesh.LoginSession{Sub: "hey"}, isReplacement: true, }, "trust corporation": { - shareCode: actor.ShareCodeData{LpaID: "lpa-id", SessionID: "aGV5", AttorneyID: "attorney-id", IsTrustCorporation: true}, + shareCode: actor.ShareCodeData{LpaID: "lpa-id", SessionID: "aGV5", AttorneyUID: testUID, IsTrustCorporation: true}, session: &sesh.LoginSession{Sub: "hey"}, isTrustCorporation: true, }, "replacement trust corporation": { - shareCode: actor.ShareCodeData{LpaID: "lpa-id", SessionID: "aGV5", AttorneyID: "attorney-id", IsReplacementAttorney: true, IsTrustCorporation: true}, + shareCode: actor.ShareCodeData{LpaID: "lpa-id", SessionID: "aGV5", AttorneyUID: testUID, IsReplacementAttorney: true, IsTrustCorporation: true}, session: &sesh.LoginSession{Sub: "hey"}, isReplacement: true, isTrustCorporation: true, @@ -130,7 +130,7 @@ func TestPostEnterReferenceNumber(t *testing.T) { session, _ := page.SessionDataFromContext(ctx) return assert.Equal(t, &page.SessionData{SessionID: "aGV5", LpaID: "lpa-id"}, session) - }), "aGV5", "attorney-id", tc.isReplacement, tc.isTrustCorporation). + }), "aGV5", testUID, tc.isReplacement, tc.isTrustCorporation). Return(&actor.AttorneyProvidedDetails{}, nil) sessionStore := newMockSessionStore(t) diff --git a/internal/page/attorney/mock_AttorneyStore_test.go b/internal/page/attorney/mock_AttorneyStore_test.go index d8e2066935..7a4672f0ce 100644 --- a/internal/page/attorney/mock_AttorneyStore_test.go +++ b/internal/page/attorney/mock_AttorneyStore_test.go @@ -3,9 +3,10 @@ package attorney import ( - context "context" - actor "github.com/ministryofjustice/opg-modernising-lpa/internal/actor" + actoruid "github.com/ministryofjustice/opg-modernising-lpa/internal/actor/actoruid" + + context "context" mock "github.com/stretchr/testify/mock" ) @@ -23,9 +24,9 @@ func (_m *mockAttorneyStore) EXPECT() *mockAttorneyStore_Expecter { return &mockAttorneyStore_Expecter{mock: &_m.Mock} } -// Create provides a mock function with given fields: _a0, _a1, _a2, _a3, _a4 -func (_m *mockAttorneyStore) Create(_a0 context.Context, _a1 string, _a2 string, _a3 bool, _a4 bool) (*actor.AttorneyProvidedDetails, error) { - ret := _m.Called(_a0, _a1, _a2, _a3, _a4) +// Create provides a mock function with given fields: ctx, sessionID, attorneyUID, isReplacement, isTrustCorporation +func (_m *mockAttorneyStore) Create(ctx context.Context, sessionID string, attorneyUID actoruid.UID, isReplacement bool, isTrustCorporation bool) (*actor.AttorneyProvidedDetails, error) { + ret := _m.Called(ctx, sessionID, attorneyUID, isReplacement, isTrustCorporation) if len(ret) == 0 { panic("no return value specified for Create") @@ -33,19 +34,19 @@ func (_m *mockAttorneyStore) Create(_a0 context.Context, _a1 string, _a2 string, var r0 *actor.AttorneyProvidedDetails var r1 error - if rf, ok := ret.Get(0).(func(context.Context, string, string, bool, bool) (*actor.AttorneyProvidedDetails, error)); ok { - return rf(_a0, _a1, _a2, _a3, _a4) + if rf, ok := ret.Get(0).(func(context.Context, string, actoruid.UID, bool, bool) (*actor.AttorneyProvidedDetails, error)); ok { + return rf(ctx, sessionID, attorneyUID, isReplacement, isTrustCorporation) } - if rf, ok := ret.Get(0).(func(context.Context, string, string, bool, bool) *actor.AttorneyProvidedDetails); ok { - r0 = rf(_a0, _a1, _a2, _a3, _a4) + if rf, ok := ret.Get(0).(func(context.Context, string, actoruid.UID, bool, bool) *actor.AttorneyProvidedDetails); ok { + r0 = rf(ctx, sessionID, attorneyUID, isReplacement, isTrustCorporation) } else { if ret.Get(0) != nil { r0 = ret.Get(0).(*actor.AttorneyProvidedDetails) } } - if rf, ok := ret.Get(1).(func(context.Context, string, string, bool, bool) error); ok { - r1 = rf(_a0, _a1, _a2, _a3, _a4) + if rf, ok := ret.Get(1).(func(context.Context, string, actoruid.UID, bool, bool) error); ok { + r1 = rf(ctx, sessionID, attorneyUID, isReplacement, isTrustCorporation) } else { r1 = ret.Error(1) } @@ -59,18 +60,18 @@ type mockAttorneyStore_Create_Call struct { } // Create is a helper method to define mock.On call -// - _a0 context.Context -// - _a1 string -// - _a2 string -// - _a3 bool -// - _a4 bool -func (_e *mockAttorneyStore_Expecter) Create(_a0 interface{}, _a1 interface{}, _a2 interface{}, _a3 interface{}, _a4 interface{}) *mockAttorneyStore_Create_Call { - return &mockAttorneyStore_Create_Call{Call: _e.mock.On("Create", _a0, _a1, _a2, _a3, _a4)} +// - ctx context.Context +// - sessionID string +// - attorneyUID actoruid.UID +// - isReplacement bool +// - isTrustCorporation bool +func (_e *mockAttorneyStore_Expecter) Create(ctx interface{}, sessionID interface{}, attorneyUID interface{}, isReplacement interface{}, isTrustCorporation interface{}) *mockAttorneyStore_Create_Call { + return &mockAttorneyStore_Create_Call{Call: _e.mock.On("Create", ctx, sessionID, attorneyUID, isReplacement, isTrustCorporation)} } -func (_c *mockAttorneyStore_Create_Call) Run(run func(_a0 context.Context, _a1 string, _a2 string, _a3 bool, _a4 bool)) *mockAttorneyStore_Create_Call { +func (_c *mockAttorneyStore_Create_Call) Run(run func(ctx context.Context, sessionID string, attorneyUID actoruid.UID, isReplacement bool, isTrustCorporation bool)) *mockAttorneyStore_Create_Call { _c.Call.Run(func(args mock.Arguments) { - run(args[0].(context.Context), args[1].(string), args[2].(string), args[3].(bool), args[4].(bool)) + run(args[0].(context.Context), args[1].(string), args[2].(actoruid.UID), args[3].(bool), args[4].(bool)) }) return _c } @@ -80,14 +81,14 @@ func (_c *mockAttorneyStore_Create_Call) Return(_a0 *actor.AttorneyProvidedDetai return _c } -func (_c *mockAttorneyStore_Create_Call) RunAndReturn(run func(context.Context, string, string, bool, bool) (*actor.AttorneyProvidedDetails, error)) *mockAttorneyStore_Create_Call { +func (_c *mockAttorneyStore_Create_Call) RunAndReturn(run func(context.Context, string, actoruid.UID, bool, bool) (*actor.AttorneyProvidedDetails, error)) *mockAttorneyStore_Create_Call { _c.Call.Return(run) return _c } -// Get provides a mock function with given fields: _a0 -func (_m *mockAttorneyStore) Get(_a0 context.Context) (*actor.AttorneyProvidedDetails, error) { - ret := _m.Called(_a0) +// Get provides a mock function with given fields: ctx +func (_m *mockAttorneyStore) Get(ctx context.Context) (*actor.AttorneyProvidedDetails, error) { + ret := _m.Called(ctx) if len(ret) == 0 { panic("no return value specified for Get") @@ -96,10 +97,10 @@ func (_m *mockAttorneyStore) Get(_a0 context.Context) (*actor.AttorneyProvidedDe var r0 *actor.AttorneyProvidedDetails var r1 error if rf, ok := ret.Get(0).(func(context.Context) (*actor.AttorneyProvidedDetails, error)); ok { - return rf(_a0) + return rf(ctx) } if rf, ok := ret.Get(0).(func(context.Context) *actor.AttorneyProvidedDetails); ok { - r0 = rf(_a0) + r0 = rf(ctx) } else { if ret.Get(0) != nil { r0 = ret.Get(0).(*actor.AttorneyProvidedDetails) @@ -107,7 +108,7 @@ func (_m *mockAttorneyStore) Get(_a0 context.Context) (*actor.AttorneyProvidedDe } if rf, ok := ret.Get(1).(func(context.Context) error); ok { - r1 = rf(_a0) + r1 = rf(ctx) } else { r1 = ret.Error(1) } @@ -121,12 +122,12 @@ type mockAttorneyStore_Get_Call struct { } // Get is a helper method to define mock.On call -// - _a0 context.Context -func (_e *mockAttorneyStore_Expecter) Get(_a0 interface{}) *mockAttorneyStore_Get_Call { - return &mockAttorneyStore_Get_Call{Call: _e.mock.On("Get", _a0)} +// - ctx context.Context +func (_e *mockAttorneyStore_Expecter) Get(ctx interface{}) *mockAttorneyStore_Get_Call { + return &mockAttorneyStore_Get_Call{Call: _e.mock.On("Get", ctx)} } -func (_c *mockAttorneyStore_Get_Call) Run(run func(_a0 context.Context)) *mockAttorneyStore_Get_Call { +func (_c *mockAttorneyStore_Get_Call) Run(run func(ctx context.Context)) *mockAttorneyStore_Get_Call { _c.Call.Run(func(args mock.Arguments) { run(args[0].(context.Context)) }) @@ -143,9 +144,9 @@ func (_c *mockAttorneyStore_Get_Call) RunAndReturn(run func(context.Context) (*a return _c } -// GetAny provides a mock function with given fields: _a0 -func (_m *mockAttorneyStore) GetAny(_a0 context.Context) ([]*actor.AttorneyProvidedDetails, error) { - ret := _m.Called(_a0) +// GetAny provides a mock function with given fields: ctx +func (_m *mockAttorneyStore) GetAny(ctx context.Context) ([]*actor.AttorneyProvidedDetails, error) { + ret := _m.Called(ctx) if len(ret) == 0 { panic("no return value specified for GetAny") @@ -154,10 +155,10 @@ func (_m *mockAttorneyStore) GetAny(_a0 context.Context) ([]*actor.AttorneyProvi var r0 []*actor.AttorneyProvidedDetails var r1 error if rf, ok := ret.Get(0).(func(context.Context) ([]*actor.AttorneyProvidedDetails, error)); ok { - return rf(_a0) + return rf(ctx) } if rf, ok := ret.Get(0).(func(context.Context) []*actor.AttorneyProvidedDetails); ok { - r0 = rf(_a0) + r0 = rf(ctx) } else { if ret.Get(0) != nil { r0 = ret.Get(0).([]*actor.AttorneyProvidedDetails) @@ -165,7 +166,7 @@ func (_m *mockAttorneyStore) GetAny(_a0 context.Context) ([]*actor.AttorneyProvi } if rf, ok := ret.Get(1).(func(context.Context) error); ok { - r1 = rf(_a0) + r1 = rf(ctx) } else { r1 = ret.Error(1) } @@ -179,12 +180,12 @@ type mockAttorneyStore_GetAny_Call struct { } // GetAny is a helper method to define mock.On call -// - _a0 context.Context -func (_e *mockAttorneyStore_Expecter) GetAny(_a0 interface{}) *mockAttorneyStore_GetAny_Call { - return &mockAttorneyStore_GetAny_Call{Call: _e.mock.On("GetAny", _a0)} +// - ctx context.Context +func (_e *mockAttorneyStore_Expecter) GetAny(ctx interface{}) *mockAttorneyStore_GetAny_Call { + return &mockAttorneyStore_GetAny_Call{Call: _e.mock.On("GetAny", ctx)} } -func (_c *mockAttorneyStore_GetAny_Call) Run(run func(_a0 context.Context)) *mockAttorneyStore_GetAny_Call { +func (_c *mockAttorneyStore_GetAny_Call) Run(run func(ctx context.Context)) *mockAttorneyStore_GetAny_Call { _c.Call.Run(func(args mock.Arguments) { run(args[0].(context.Context)) }) @@ -201,9 +202,9 @@ func (_c *mockAttorneyStore_GetAny_Call) RunAndReturn(run func(context.Context) return _c } -// Put provides a mock function with given fields: _a0, _a1 -func (_m *mockAttorneyStore) Put(_a0 context.Context, _a1 *actor.AttorneyProvidedDetails) error { - ret := _m.Called(_a0, _a1) +// Put provides a mock function with given fields: ctx, attorney +func (_m *mockAttorneyStore) Put(ctx context.Context, attorney *actor.AttorneyProvidedDetails) error { + ret := _m.Called(ctx, attorney) if len(ret) == 0 { panic("no return value specified for Put") @@ -211,7 +212,7 @@ func (_m *mockAttorneyStore) Put(_a0 context.Context, _a1 *actor.AttorneyProvide var r0 error if rf, ok := ret.Get(0).(func(context.Context, *actor.AttorneyProvidedDetails) error); ok { - r0 = rf(_a0, _a1) + r0 = rf(ctx, attorney) } else { r0 = ret.Error(0) } @@ -225,13 +226,13 @@ type mockAttorneyStore_Put_Call struct { } // Put is a helper method to define mock.On call -// - _a0 context.Context -// - _a1 *actor.AttorneyProvidedDetails -func (_e *mockAttorneyStore_Expecter) Put(_a0 interface{}, _a1 interface{}) *mockAttorneyStore_Put_Call { - return &mockAttorneyStore_Put_Call{Call: _e.mock.On("Put", _a0, _a1)} +// - ctx context.Context +// - attorney *actor.AttorneyProvidedDetails +func (_e *mockAttorneyStore_Expecter) Put(ctx interface{}, attorney interface{}) *mockAttorneyStore_Put_Call { + return &mockAttorneyStore_Put_Call{Call: _e.mock.On("Put", ctx, attorney)} } -func (_c *mockAttorneyStore_Put_Call) Run(run func(_a0 context.Context, _a1 *actor.AttorneyProvidedDetails)) *mockAttorneyStore_Put_Call { +func (_c *mockAttorneyStore_Put_Call) Run(run func(ctx context.Context, attorney *actor.AttorneyProvidedDetails)) *mockAttorneyStore_Put_Call { _c.Call.Run(func(args mock.Arguments) { run(args[0].(context.Context), args[1].(*actor.AttorneyProvidedDetails)) }) diff --git a/internal/page/attorney/mock_test.go b/internal/page/attorney/mock_test.go index 0ebaf64498..e46b515152 100644 --- a/internal/page/attorney/mock_test.go +++ b/internal/page/attorney/mock_test.go @@ -4,36 +4,40 @@ import ( "errors" "github.com/ministryofjustice/opg-modernising-lpa/internal/actor" + "github.com/ministryofjustice/opg-modernising-lpa/internal/actor/actoruid" "github.com/ministryofjustice/opg-modernising-lpa/internal/localize" "github.com/ministryofjustice/opg-modernising-lpa/internal/page" ) var ( + testUID = actoruid.New() expectedError = errors.New("err") testAppData = page.AppData{ - SessionID: "session-id", - LpaID: "lpa-id", - AttorneyID: "attorney-id", - Lang: localize.En, - ActorType: actor.TypeAttorney, + SessionID: "session-id", + LpaID: "lpa-id", + AttorneyUID: testUID, + Lang: localize.En, + ActorType: actor.TypeAttorney, } testReplacementAppData = page.AppData{ - SessionID: "session-id", - LpaID: "lpa-id", - AttorneyID: "attorney-id", - Lang: localize.En, - ActorType: actor.TypeReplacementAttorney, + SessionID: "session-id", + LpaID: "lpa-id", + AttorneyUID: testUID, + Lang: localize.En, + ActorType: actor.TypeReplacementAttorney, } testTrustCorporationAppData = page.AppData{ - SessionID: "session-id", - LpaID: "lpa-id", - Lang: localize.En, - ActorType: actor.TypeAttorney, + SessionID: "session-id", + LpaID: "lpa-id", + AttorneyUID: testUID, + Lang: localize.En, + ActorType: actor.TypeTrustCorporation, } testReplacementTrustCorporationAppData = page.AppData{ - SessionID: "session-id", - LpaID: "lpa-id", - Lang: localize.En, - ActorType: actor.TypeReplacementAttorney, + SessionID: "session-id", + LpaID: "lpa-id", + AttorneyUID: testUID, + Lang: localize.En, + ActorType: actor.TypeReplacementTrustCorporation, } ) diff --git a/internal/page/attorney/read_the_lpa_test.go b/internal/page/attorney/read_the_lpa_test.go index bb2e38c51b..fb9322f09f 100644 --- a/internal/page/attorney/read_the_lpa_test.go +++ b/internal/page/attorney/read_the_lpa_test.go @@ -6,24 +6,26 @@ import ( "testing" "github.com/ministryofjustice/opg-modernising-lpa/internal/actor" + "github.com/ministryofjustice/opg-modernising-lpa/internal/actor/actoruid" "github.com/ministryofjustice/opg-modernising-lpa/internal/page" "github.com/stretchr/testify/assert" ) func TestGetReadTheLpaWithAttorney(t *testing.T) { + uid := actoruid.New() w := httptest.NewRecorder() r, _ := http.NewRequest(http.MethodGet, "/", nil) donorStore := newMockDonorStore(t) donorStore.EXPECT(). GetAny(r.Context()). - Return(&actor.DonorProvidedDetails{Attorneys: actor.Attorneys{Attorneys: []actor.Attorney{{ID: "attorney-id"}}}}, nil) + Return(&actor.DonorProvidedDetails{Attorneys: actor.Attorneys{Attorneys: []actor.Attorney{{UID: uid}}}}, nil) template := newMockTemplate(t) template.EXPECT(). Execute(w, &readTheLpaData{ App: testAppData, - Donor: &actor.DonorProvidedDetails{Attorneys: actor.Attorneys{Attorneys: []actor.Attorney{{ID: "attorney-id"}}}}, + Donor: &actor.DonorProvidedDetails{Attorneys: actor.Attorneys{Attorneys: []actor.Attorney{{UID: uid}}}}, }). Return(nil) @@ -35,19 +37,20 @@ func TestGetReadTheLpaWithAttorney(t *testing.T) { } func TestGetReadTheLpaWithReplacementAttorney(t *testing.T) { + uid := actoruid.New() w := httptest.NewRecorder() r, _ := http.NewRequest(http.MethodGet, "/", nil) donorStore := newMockDonorStore(t) donorStore.EXPECT(). GetAny(r.Context()). - Return(&actor.DonorProvidedDetails{ReplacementAttorneys: actor.Attorneys{Attorneys: []actor.Attorney{{ID: "attorney-id"}}}}, nil) + Return(&actor.DonorProvidedDetails{ReplacementAttorneys: actor.Attorneys{Attorneys: []actor.Attorney{{UID: uid}}}}, nil) template := newMockTemplate(t) template.EXPECT(). Execute(w, &readTheLpaData{ App: testReplacementAppData, - Donor: &actor.DonorProvidedDetails{ReplacementAttorneys: actor.Attorneys{Attorneys: []actor.Attorney{{ID: "attorney-id"}}}}, + Donor: &actor.DonorProvidedDetails{ReplacementAttorneys: actor.Attorneys{Attorneys: []actor.Attorney{{UID: uid}}}}, }). Return(nil) @@ -59,13 +62,14 @@ func TestGetReadTheLpaWithReplacementAttorney(t *testing.T) { } func TestGetReadTheLpaWithAttorneyWhenDonorStoreErrors(t *testing.T) { + uid := actoruid.New() w := httptest.NewRecorder() r, _ := http.NewRequest(http.MethodGet, "/", nil) donorStore := newMockDonorStore(t) donorStore.EXPECT(). GetAny(r.Context()). - Return(&actor.DonorProvidedDetails{Attorneys: actor.Attorneys{Attorneys: []actor.Attorney{{ID: "attorney-id"}}}}, expectedError) + Return(&actor.DonorProvidedDetails{Attorneys: actor.Attorneys{Attorneys: []actor.Attorney{{UID: uid}}}}, expectedError) err := ReadTheLpa(nil, donorStore, nil)(testAppData, w, r, nil) resp := w.Result() @@ -75,19 +79,20 @@ func TestGetReadTheLpaWithAttorneyWhenDonorStoreErrors(t *testing.T) { } func TestGetReadTheLpaWhenTemplateError(t *testing.T) { + uid := actoruid.New() w := httptest.NewRecorder() r, _ := http.NewRequest(http.MethodGet, "/", nil) donorStore := newMockDonorStore(t) donorStore.EXPECT(). GetAny(r.Context()). - Return(&actor.DonorProvidedDetails{Attorneys: actor.Attorneys{Attorneys: []actor.Attorney{{ID: "attorney-id"}}}}, nil) + Return(&actor.DonorProvidedDetails{Attorneys: actor.Attorneys{Attorneys: []actor.Attorney{{UID: uid}}}}, nil) template := newMockTemplate(t) template.EXPECT(). Execute(w, &readTheLpaData{ App: testAppData, - Donor: &actor.DonorProvidedDetails{Attorneys: actor.Attorneys{Attorneys: []actor.Attorney{{ID: "attorney-id"}}}}, + Donor: &actor.DonorProvidedDetails{Attorneys: actor.Attorneys{Attorneys: []actor.Attorney{{UID: uid}}}}, }). Return(expectedError) diff --git a/internal/page/attorney/register.go b/internal/page/attorney/register.go index 8c3017cb14..dd5a03f42b 100644 --- a/internal/page/attorney/register.go +++ b/internal/page/attorney/register.go @@ -9,6 +9,7 @@ import ( "github.com/gorilla/sessions" "github.com/ministryofjustice/opg-go-common/template" "github.com/ministryofjustice/opg-modernising-lpa/internal/actor" + "github.com/ministryofjustice/opg-modernising-lpa/internal/actor/actoruid" "github.com/ministryofjustice/opg-modernising-lpa/internal/onelogin" "github.com/ministryofjustice/opg-modernising-lpa/internal/page" "github.com/ministryofjustice/opg-modernising-lpa/internal/place" @@ -51,10 +52,10 @@ type CertificateProviderStore interface { } type AttorneyStore interface { - Create(context.Context, string, string, bool, bool) (*actor.AttorneyProvidedDetails, error) - Get(context.Context) (*actor.AttorneyProvidedDetails, error) - GetAny(context.Context) ([]*actor.AttorneyProvidedDetails, error) - Put(context.Context, *actor.AttorneyProvidedDetails) error + Create(ctx context.Context, sessionID string, attorneyUID actoruid.UID, isReplacement, isTrustCorporation bool) (*actor.AttorneyProvidedDetails, error) + Get(ctx context.Context) (*actor.AttorneyProvidedDetails, error) + GetAny(ctx context.Context) ([]*actor.AttorneyProvidedDetails, error) + Put(ctx context.Context, attorney *actor.AttorneyProvidedDetails) error } type AddressClient interface { @@ -195,8 +196,12 @@ func makeAttorneyHandle(mux *http.ServeMux, store sesh.Store, errorHandler page. } appData.Page = path.Format(appData.LpaID) - appData.AttorneyID = attorney.ID - if attorney.IsReplacement { + appData.AttorneyUID = attorney.UID + if attorney.IsTrustCorporation && attorney.IsReplacement { + appData.ActorType = actor.TypeReplacementTrustCorporation + } else if attorney.IsTrustCorporation { + appData.ActorType = actor.TypeTrustCorporation + } else if attorney.IsReplacement { appData.ActorType = actor.TypeReplacementAttorney } else { appData.ActorType = actor.TypeAttorney diff --git a/internal/page/attorney/register_test.go b/internal/page/attorney/register_test.go index a29a0a1c67..9b953fbb1f 100644 --- a/internal/page/attorney/register_test.go +++ b/internal/page/attorney/register_test.go @@ -9,6 +9,7 @@ import ( "github.com/gorilla/sessions" "github.com/ministryofjustice/opg-go-common/template" "github.com/ministryofjustice/opg-modernising-lpa/internal/actor" + "github.com/ministryofjustice/opg-modernising-lpa/internal/actor/actoruid" "github.com/ministryofjustice/opg-modernising-lpa/internal/lpastore" "github.com/ministryofjustice/opg-modernising-lpa/internal/page" "github.com/ministryofjustice/opg-modernising-lpa/internal/sesh" @@ -192,9 +193,10 @@ func TestMakeHandleNoSessionRequired(t *testing.T) { func TestMakeAttorneyHandleExistingSessionData(t *testing.T) { ctx := page.ContextWithSessionData(context.Background(), &page.SessionData{LpaID: "lpa-id", SessionID: "ignored-session-id"}) + uid := actoruid.New() w := httptest.NewRecorder() r, _ := http.NewRequestWithContext(ctx, http.MethodGet, "/path?a=b", nil) - expectedDetails := &actor.AttorneyProvidedDetails{ID: "123"} + expectedDetails := &actor.AttorneyProvidedDetails{UID: uid} sessionStore := newMockSessionStore(t) sessionStore.EXPECT(). @@ -212,12 +214,12 @@ func TestMakeAttorneyHandleExistingSessionData(t *testing.T) { assert.Equal(t, expectedDetails, details) assert.Equal(t, page.AppData{ - Page: "/attorney/lpa-id/path", - CanGoBack: true, - SessionID: "cmFuZG9t", - LpaID: "lpa-id", - ActorType: actor.TypeAttorney, - AttorneyID: "123", + Page: "/attorney/lpa-id/path", + CanGoBack: true, + SessionID: "cmFuZG9t", + LpaID: "lpa-id", + ActorType: actor.TypeAttorney, + AttorneyUID: uid, }, appData) assert.Equal(t, w, hw) @@ -235,18 +237,27 @@ func TestMakeAttorneyHandleExistingSessionData(t *testing.T) { } func TestMakeAttorneyHandleExistingLpaData(t *testing.T) { + uid := actoruid.New() testCases := map[string]struct { details *actor.AttorneyProvidedDetails actorType actor.Type }{ "attorney": { - details: &actor.AttorneyProvidedDetails{ID: "attorney-id"}, + details: &actor.AttorneyProvidedDetails{UID: uid}, actorType: actor.TypeAttorney, }, "replacement attorney": { - details: &actor.AttorneyProvidedDetails{ID: "attorney-id", IsReplacement: true}, + details: &actor.AttorneyProvidedDetails{UID: uid, IsReplacement: true}, actorType: actor.TypeReplacementAttorney, }, + "trust corporation": { + details: &actor.AttorneyProvidedDetails{UID: uid, IsTrustCorporation: true}, + actorType: actor.TypeTrustCorporation, + }, + "replacement trust corporation": { + details: &actor.AttorneyProvidedDetails{UID: uid, IsReplacement: true, IsTrustCorporation: true}, + actorType: actor.TypeReplacementTrustCorporation, + }, } for name, tc := range testCases { @@ -270,12 +281,12 @@ func TestMakeAttorneyHandleExistingLpaData(t *testing.T) { handle("/path", CanGoBack, func(appData page.AppData, hw http.ResponseWriter, hr *http.Request, details *actor.AttorneyProvidedDetails) error { assert.Equal(t, tc.details, details) assert.Equal(t, page.AppData{ - Page: "/attorney/lpa-id/path", - CanGoBack: true, - LpaID: "lpa-id", - SessionID: "cmFuZG9t", - AttorneyID: "attorney-id", - ActorType: tc.actorType, + Page: "/attorney/lpa-id/path", + CanGoBack: true, + LpaID: "lpa-id", + SessionID: "cmFuZG9t", + AttorneyUID: uid, + ActorType: tc.actorType, }, appData) assert.Equal(t, w, hw) diff --git a/internal/page/attorney/sign.go b/internal/page/attorney/sign.go index 79370de7b4..8113407982 100644 --- a/internal/page/attorney/sign.go +++ b/internal/page/attorney/sign.go @@ -95,7 +95,7 @@ func Sign( attorneys = lpa.ReplacementAttorneys } - attorney, ok := attorneys.Get(appData.AttorneyID) + attorney, ok := attorneys.Get(appData.AttorneyUID) if !ok { return page.Paths.Attorney.Start.Redirect(w, r, appData) } diff --git a/internal/page/attorney/sign_test.go b/internal/page/attorney/sign_test.go index 5123df0313..8b33b7aa7b 100644 --- a/internal/page/attorney/sign_test.go +++ b/internal/page/attorney/sign_test.go @@ -9,6 +9,7 @@ import ( "time" "github.com/ministryofjustice/opg-modernising-lpa/internal/actor" + "github.com/ministryofjustice/opg-modernising-lpa/internal/actor/actoruid" "github.com/ministryofjustice/opg-modernising-lpa/internal/page" "github.com/ministryofjustice/opg-modernising-lpa/internal/validation" "github.com/stretchr/testify/assert" @@ -27,14 +28,14 @@ func TestGetSign(t *testing.T) { SignedAt: time.Now(), WhenCanTheLpaBeUsed: actor.CanBeUsedWhenHasCapacity, Attorneys: actor.Attorneys{Attorneys: []actor.Attorney{ - {ID: "attorney-id", FirstNames: "Bob", LastName: "Smith"}, - {ID: "other", FirstNames: "Dave", LastName: "Smith"}, + {UID: testUID, FirstNames: "Bob", LastName: "Smith"}, + {UID: actoruid.New(), FirstNames: "Dave", LastName: "Smith"}, }}, }, data: &signData{ App: testAppData, Form: &signForm{}, - Attorney: actor.Attorney{ID: "attorney-id", FirstNames: "Bob", LastName: "Smith"}, + Attorney: actor.Attorney{UID: testUID, FirstNames: "Bob", LastName: "Smith"}, LpaCanBeUsedWhenHasCapacity: true, }, }, @@ -44,14 +45,14 @@ func TestGetSign(t *testing.T) { SignedAt: time.Now(), WhenCanTheLpaBeUsed: actor.CanBeUsedWhenCapacityLost, Attorneys: actor.Attorneys{Attorneys: []actor.Attorney{ - {ID: "attorney-id", FirstNames: "Bob", LastName: "Smith"}, - {ID: "other", FirstNames: "Dave", LastName: "Smith"}, + {UID: testUID, FirstNames: "Bob", LastName: "Smith"}, + {UID: actoruid.New(), FirstNames: "Dave", LastName: "Smith"}, }}, }, data: &signData{ App: testAppData, Form: &signForm{}, - Attorney: actor.Attorney{ID: "attorney-id", FirstNames: "Bob", LastName: "Smith"}, + Attorney: actor.Attorney{UID: testUID, FirstNames: "Bob", LastName: "Smith"}, }, }, "replacement attorney use when registered": { @@ -60,14 +61,14 @@ func TestGetSign(t *testing.T) { SignedAt: time.Now(), WhenCanTheLpaBeUsed: actor.CanBeUsedWhenHasCapacity, ReplacementAttorneys: actor.Attorneys{Attorneys: []actor.Attorney{ - {ID: "attorney-id", FirstNames: "Bob", LastName: "Smith"}, - {ID: "other", FirstNames: "Dave", LastName: "Smith"}, + {UID: testUID, FirstNames: "Bob", LastName: "Smith"}, + {UID: actoruid.New(), FirstNames: "Dave", LastName: "Smith"}, }}, }, data: &signData{ App: testReplacementAppData, Form: &signForm{}, - Attorney: actor.Attorney{ID: "attorney-id", FirstNames: "Bob", LastName: "Smith"}, + Attorney: actor.Attorney{UID: testUID, FirstNames: "Bob", LastName: "Smith"}, IsReplacement: true, LpaCanBeUsedWhenHasCapacity: true, }, @@ -78,14 +79,14 @@ func TestGetSign(t *testing.T) { SignedAt: time.Now(), WhenCanTheLpaBeUsed: actor.CanBeUsedWhenCapacityLost, ReplacementAttorneys: actor.Attorneys{Attorneys: []actor.Attorney{ - {ID: "attorney-id", FirstNames: "Bob", LastName: "Smith"}, - {ID: "other", FirstNames: "Dave", LastName: "Smith"}, + {UID: testUID, FirstNames: "Bob", LastName: "Smith"}, + {UID: actoruid.New(), FirstNames: "Dave", LastName: "Smith"}, }}, }, data: &signData{ App: testReplacementAppData, Form: &signForm{}, - Attorney: actor.Attorney{ID: "attorney-id", FirstNames: "Bob", LastName: "Smith"}, + Attorney: actor.Attorney{UID: testUID, FirstNames: "Bob", LastName: "Smith"}, IsReplacement: true, }, }, @@ -139,6 +140,8 @@ func TestGetSign(t *testing.T) { } func TestGetSignCantSignYet(t *testing.T) { + uid := actoruid.New() + testcases := map[string]struct { appData page.AppData donor *actor.DonorProvidedDetails @@ -149,8 +152,8 @@ func TestGetSignCantSignYet(t *testing.T) { donor: &actor.DonorProvidedDetails{ SignedAt: time.Now(), Attorneys: actor.Attorneys{Attorneys: []actor.Attorney{ - {ID: "attorney-id", FirstNames: "Bob", LastName: "Smith"}, - {ID: "other", FirstNames: "Dave", LastName: "Smith"}, + {UID: uid, FirstNames: "Bob", LastName: "Smith"}, + {UID: actoruid.New(), FirstNames: "Dave", LastName: "Smith"}, }}, }, certificateProvider: &actor.CertificateProviderProvidedDetails{}, @@ -160,8 +163,8 @@ func TestGetSignCantSignYet(t *testing.T) { donor: &actor.DonorProvidedDetails{ WhenCanTheLpaBeUsed: actor.CanBeUsedWhenCapacityLost, Attorneys: actor.Attorneys{Attorneys: []actor.Attorney{ - {ID: "attorney-id", FirstNames: "Bob", LastName: "Smith"}, - {ID: "other", FirstNames: "Dave", LastName: "Smith"}, + {UID: uid, FirstNames: "Bob", LastName: "Smith"}, + {UID: actoruid.New(), FirstNames: "Dave", LastName: "Smith"}, }}, }, certificateProvider: &actor.CertificateProviderProvidedDetails{ @@ -196,6 +199,8 @@ func TestGetSignCantSignYet(t *testing.T) { } func TestGetSignWhenAttorneyDoesNotExist(t *testing.T) { + uid := actoruid.New() + testcases := map[string]struct { appData page.AppData donor *actor.DonorProvidedDetails @@ -205,7 +210,7 @@ func TestGetSignWhenAttorneyDoesNotExist(t *testing.T) { donor: &actor.DonorProvidedDetails{ SignedAt: time.Now(), ReplacementAttorneys: actor.Attorneys{Attorneys: []actor.Attorney{ - {ID: "attorney-id", FirstNames: "Bob", LastName: "Smith"}, + {UID: uid, FirstNames: "Bob", LastName: "Smith"}, }}, }, }, @@ -214,7 +219,7 @@ func TestGetSignWhenAttorneyDoesNotExist(t *testing.T) { donor: &actor.DonorProvidedDetails{ SignedAt: time.Now(), Attorneys: actor.Attorneys{Attorneys: []actor.Attorney{ - {ID: "attorney-id", FirstNames: "Bob", LastName: "Smith"}, + {UID: uid, FirstNames: "Bob", LastName: "Smith"}, }}, }, }, @@ -279,7 +284,7 @@ func TestGetSignOnTemplateError(t *testing.T) { GetAny(r.Context()). Return(&actor.DonorProvidedDetails{ SignedAt: time.Now(), - Attorneys: actor.Attorneys{Attorneys: []actor.Attorney{{ID: "attorney-id"}}}, + Attorneys: actor.Attorneys{Attorneys: []actor.Attorney{{UID: testUID}}}, }, nil) certificateProviderStore := newMockCertificateProviderStore(t) @@ -312,7 +317,7 @@ func TestPostSign(t *testing.T) { form: url.Values{"confirm": {"1"}}, donor: &actor.DonorProvidedDetails{ SignedAt: lpaSignedAt, - Attorneys: actor.Attorneys{Attorneys: []actor.Attorney{{ID: "attorney-id", FirstNames: "Bob", LastName: "Smith"}}}, + Attorneys: actor.Attorneys{Attorneys: []actor.Attorney{{UID: testUID, FirstNames: "Bob", LastName: "Smith"}}}, }, updatedAttorney: &actor.AttorneyProvidedDetails{ LpaID: "lpa-id", @@ -326,7 +331,7 @@ func TestPostSign(t *testing.T) { form: url.Values{"confirm": {"1"}}, donor: &actor.DonorProvidedDetails{ SignedAt: lpaSignedAt, - ReplacementAttorneys: actor.Attorneys{Attorneys: []actor.Attorney{{ID: "attorney-id", FirstNames: "Bob", LastName: "Smith"}}}, + ReplacementAttorneys: actor.Attorneys{Attorneys: []actor.Attorney{{UID: testUID, FirstNames: "Bob", LastName: "Smith"}}}, }, updatedAttorney: &actor.AttorneyProvidedDetails{ LpaID: "lpa-id", @@ -524,17 +529,16 @@ func TestPostSignWhenWantSecondSignatory(t *testing.T) { func TestPostSignWhenLpaStoreClientErrors(t *testing.T) { form := url.Values{"confirm": {"1"}} + w := httptest.NewRecorder() r, _ := http.NewRequest(http.MethodPost, "", strings.NewReader(form.Encode())) r.Header.Add("Content-Type", page.FormUrlEncoded) - w := httptest.NewRecorder() - donorStore := newMockDonorStore(t) donorStore.EXPECT(). GetAny(r.Context()). Return(&actor.DonorProvidedDetails{ SignedAt: time.Now(), - Attorneys: actor.Attorneys{Attorneys: []actor.Attorney{{ID: "attorney-id", FirstNames: "Bob", LastName: "Smith"}}}, + Attorneys: actor.Attorneys{Attorneys: []actor.Attorney{{UID: testUID, FirstNames: "Bob", LastName: "Smith"}}}, }, nil) attorneyStore := newMockAttorneyStore(t) @@ -563,17 +567,16 @@ func TestPostSignWhenStoreError(t *testing.T) { "confirm": {"1"}, } + w := httptest.NewRecorder() r, _ := http.NewRequest(http.MethodPost, "/", strings.NewReader(form.Encode())) r.Header.Add("Content-Type", page.FormUrlEncoded) - w := httptest.NewRecorder() - donorStore := newMockDonorStore(t) donorStore.EXPECT(). GetAny(r.Context()). Return(&actor.DonorProvidedDetails{ SignedAt: time.Now(), - Attorneys: actor.Attorneys{Attorneys: []actor.Attorney{{ID: "attorney-id", FirstNames: "Bob", LastName: "Smith"}}}, + Attorneys: actor.Attorneys{Attorneys: []actor.Attorney{{UID: testUID, FirstNames: "Bob", LastName: "Smith"}}}, }, nil) certificateProviderStore := newMockCertificateProviderStore(t) @@ -598,17 +601,16 @@ func TestPostSignWhenStoreError(t *testing.T) { func TestPostSignOnValidationError(t *testing.T) { form := url.Values{} + w := httptest.NewRecorder() r, _ := http.NewRequest(http.MethodPost, "/", strings.NewReader(form.Encode())) r.Header.Add("Content-Type", page.FormUrlEncoded) - w := httptest.NewRecorder() - donorStore := newMockDonorStore(t) donorStore.EXPECT(). GetAny(r.Context()). Return(&actor.DonorProvidedDetails{ SignedAt: time.Now(), - Attorneys: actor.Attorneys{Attorneys: []actor.Attorney{{ID: "attorney-id", FirstNames: "Bob", LastName: "Smith"}}}, + Attorneys: actor.Attorneys{Attorneys: []actor.Attorney{{UID: testUID, FirstNames: "Bob", LastName: "Smith"}}}, }, nil) certificateProviderStore := newMockCertificateProviderStore(t) @@ -623,7 +625,7 @@ func TestPostSignOnValidationError(t *testing.T) { Execute(w, &signData{ App: testAppData, Form: &signForm{}, - Attorney: actor.Attorney{ID: "attorney-id", FirstNames: "Bob", LastName: "Smith"}, + Attorney: actor.Attorney{UID: testUID, FirstNames: "Bob", LastName: "Smith"}, Errors: validation.With("confirm", validation.CustomError{Label: "youMustSelectTheBoxToSignAttorney"}), }). Return(nil) diff --git a/internal/page/data_test.go b/internal/page/data_test.go index f2ee22f116..4c10e8a6d8 100644 --- a/internal/page/data_test.go +++ b/internal/page/data_test.go @@ -5,6 +5,7 @@ import ( "time" "github.com/ministryofjustice/opg-modernising-lpa/internal/actor" + "github.com/ministryofjustice/opg-modernising-lpa/internal/actor/actoruid" "github.com/ministryofjustice/opg-modernising-lpa/internal/form" "github.com/ministryofjustice/opg-modernising-lpa/internal/pay" "github.com/ministryofjustice/opg-modernising-lpa/internal/place" @@ -142,6 +143,8 @@ func TestCanGoTo(t *testing.T) { func TestLpaProgress(t *testing.T) { lpaSignedAt := time.Now() + uid1 := actoruid.New() + uid2 := actoruid.New() testCases := map[string]struct { donor *actor.DonorProvidedDetails @@ -188,12 +191,12 @@ func TestLpaProgress(t *testing.T) { "attorneys signed": { donor: &actor.DonorProvidedDetails{ SignedAt: lpaSignedAt, - Attorneys: actor.Attorneys{Attorneys: []actor.Attorney{{ID: "a1"}, {ID: "a2"}}}, + Attorneys: actor.Attorneys{Attorneys: []actor.Attorney{{UID: uid1}, {UID: uid2}}}, }, certificateProvider: &actor.CertificateProviderProvidedDetails{Certificate: actor.Certificate{Agreed: lpaSignedAt.Add(time.Second)}}, attorneys: []*actor.AttorneyProvidedDetails{ - {ID: "a1", LpaSignedAt: lpaSignedAt, Confirmed: lpaSignedAt.Add(time.Minute)}, - {ID: "a2", LpaSignedAt: lpaSignedAt, Confirmed: lpaSignedAt.Add(time.Minute)}, + {UID: uid1, LpaSignedAt: lpaSignedAt, Confirmed: lpaSignedAt.Add(time.Minute)}, + {UID: uid2, LpaSignedAt: lpaSignedAt, Confirmed: lpaSignedAt.Add(time.Minute)}, }, expectedProgress: actor.Progress{ DonorSigned: actor.TaskCompleted, @@ -208,12 +211,12 @@ func TestLpaProgress(t *testing.T) { donor: &actor.DonorProvidedDetails{ SignedAt: lpaSignedAt, SubmittedAt: lpaSignedAt.Add(time.Hour), - Attorneys: actor.Attorneys{Attorneys: []actor.Attorney{{ID: "a1"}, {ID: "a2"}}}, + Attorneys: actor.Attorneys{Attorneys: []actor.Attorney{{UID: uid1}, {UID: uid2}}}, }, certificateProvider: &actor.CertificateProviderProvidedDetails{Certificate: actor.Certificate{Agreed: lpaSignedAt.Add(time.Second)}}, attorneys: []*actor.AttorneyProvidedDetails{ - {ID: "a1", LpaSignedAt: lpaSignedAt, Confirmed: lpaSignedAt.Add(time.Minute)}, - {ID: "a2", LpaSignedAt: lpaSignedAt, Confirmed: lpaSignedAt.Add(time.Minute)}, + {UID: uid1, LpaSignedAt: lpaSignedAt, Confirmed: lpaSignedAt.Add(time.Minute)}, + {UID: uid2, LpaSignedAt: lpaSignedAt, Confirmed: lpaSignedAt.Add(time.Minute)}, }, expectedProgress: actor.Progress{ DonorSigned: actor.TaskCompleted, @@ -229,12 +232,12 @@ func TestLpaProgress(t *testing.T) { SignedAt: lpaSignedAt, SubmittedAt: lpaSignedAt.Add(time.Hour), RegisteredAt: lpaSignedAt.Add(2 * time.Hour), - Attorneys: actor.Attorneys{Attorneys: []actor.Attorney{{ID: "a1"}, {ID: "a2"}}}, + Attorneys: actor.Attorneys{Attorneys: []actor.Attorney{{UID: uid1}, {UID: uid2}}}, }, certificateProvider: &actor.CertificateProviderProvidedDetails{Certificate: actor.Certificate{Agreed: lpaSignedAt.Add(time.Second)}}, attorneys: []*actor.AttorneyProvidedDetails{ - {ID: "a1", LpaSignedAt: lpaSignedAt, Confirmed: lpaSignedAt.Add(time.Minute)}, - {ID: "a2", LpaSignedAt: lpaSignedAt, Confirmed: lpaSignedAt.Add(time.Minute)}, + {UID: uid1, LpaSignedAt: lpaSignedAt, Confirmed: lpaSignedAt.Add(time.Minute)}, + {UID: uid2, LpaSignedAt: lpaSignedAt, Confirmed: lpaSignedAt.Add(time.Minute)}, }, expectedProgress: actor.Progress{ DonorSigned: actor.TaskCompleted, diff --git a/internal/page/donor/certificate_provider_address.go b/internal/page/donor/certificate_provider_address.go index a39d18cbd2..c537ada620 100644 --- a/internal/page/donor/certificate_provider_address.go +++ b/internal/page/donor/certificate_provider_address.go @@ -16,7 +16,7 @@ func CertificateProviderAddress(logger Logger, tmpl template.Template, addressCl appData, "certificateProvider", donor.CertificateProvider.FullName(), - "", + donor.CertificateProvider.UID, false, ) diff --git a/internal/page/donor/certificate_provider_details.go b/internal/page/donor/certificate_provider_details.go index 4ef72ad761..b5ec19d2b4 100644 --- a/internal/page/donor/certificate_provider_details.go +++ b/internal/page/donor/certificate_provider_details.go @@ -6,6 +6,7 @@ import ( "github.com/ministryofjustice/opg-go-common/template" "github.com/ministryofjustice/opg-modernising-lpa/internal/actor" + "github.com/ministryofjustice/opg-modernising-lpa/internal/actor/actoruid" "github.com/ministryofjustice/opg-modernising-lpa/internal/page" "github.com/ministryofjustice/opg-modernising-lpa/internal/validation" ) @@ -17,7 +18,7 @@ type certificateProviderDetailsData struct { NameWarning *actor.SameNameWarning } -func CertificateProviderDetails(tmpl template.Template, donorStore DonorStore) Handler { +func CertificateProviderDetails(tmpl template.Template, donorStore DonorStore, newUID func() actoruid.UID) Handler { return func(appData page.AppData, w http.ResponseWriter, r *http.Request, donor *actor.DonorProvidedDetails) error { data := &certificateProviderDetailsData{ App: appData, @@ -50,9 +51,14 @@ func CertificateProviderDetails(tmpl template.Template, donorStore DonorStore) H } if data.Errors.None() && data.NameWarning == nil { + if donor.CertificateProvider.UID.IsZero() { + donor.CertificateProvider.UID = newUID() + } + donor.CertificateProvider.FirstNames = data.Form.FirstNames donor.CertificateProvider.LastName = data.Form.LastName donor.CertificateProvider.HasNonUKMobile = data.Form.HasNonUKMobile + if data.Form.HasNonUKMobile { donor.CertificateProvider.Mobile = data.Form.NonUKMobile } else { diff --git a/internal/page/donor/certificate_provider_details_test.go b/internal/page/donor/certificate_provider_details_test.go index ada268c0fb..8e54cea092 100644 --- a/internal/page/donor/certificate_provider_details_test.go +++ b/internal/page/donor/certificate_provider_details_test.go @@ -26,7 +26,7 @@ func TestGetCertificateProviderDetails(t *testing.T) { }). Return(nil) - err := CertificateProviderDetails(template.Execute, nil)(testAppData, w, r, &actor.DonorProvidedDetails{}) + err := CertificateProviderDetails(template.Execute, nil, testUIDFn)(testAppData, w, r, &actor.DonorProvidedDetails{}) resp := w.Result() assert.Nil(t, err) @@ -79,7 +79,7 @@ func TestGetCertificateProviderDetailsFromStore(t *testing.T) { }). Return(nil) - err := CertificateProviderDetails(template.Execute, nil)(testAppData, w, r, tc.donor) + err := CertificateProviderDetails(template.Execute, nil, testUIDFn)(testAppData, w, r, tc.donor) resp := w.Result() assert.Nil(t, err) @@ -100,7 +100,7 @@ func TestGetCertificateProviderDetailsWhenTemplateErrors(t *testing.T) { }). Return(expectedError) - err := CertificateProviderDetails(template.Execute, nil)(testAppData, w, r, &actor.DonorProvidedDetails{}) + err := CertificateProviderDetails(template.Execute, nil, testUIDFn)(testAppData, w, r, &actor.DonorProvidedDetails{}) resp := w.Result() assert.Equal(t, expectedError, err) @@ -119,6 +119,7 @@ func TestPostCertificateProviderDetails(t *testing.T) { "mobile": {"07535111111"}, }, certificateProviderDetails: actor.CertificateProvider{ + UID: testUID, FirstNames: "John", LastName: "Rey", Mobile: "07535111111", @@ -132,6 +133,7 @@ func TestPostCertificateProviderDetails(t *testing.T) { "non-uk-mobile": {"+337575757"}, }, certificateProviderDetails: actor.CertificateProvider{ + UID: testUID, FirstNames: "John", LastName: "Rey", Mobile: "+337575757", @@ -146,6 +148,7 @@ func TestPostCertificateProviderDetails(t *testing.T) { "ignore-name-warning": {actor.NewSameNameWarning(actor.TypeCertificateProvider, actor.TypeDonor, "Jane", "Doe").String()}, }, certificateProviderDetails: actor.CertificateProvider{ + UID: testUID, FirstNames: "Jane", LastName: "Doe", Mobile: "07535111111", @@ -159,6 +162,7 @@ func TestPostCertificateProviderDetails(t *testing.T) { "ignore-similar-name-warning": {"yes"}, }, certificateProviderDetails: actor.CertificateProvider{ + UID: testUID, FirstNames: "Joyce", LastName: "Doe", Mobile: "07535111111", @@ -185,7 +189,7 @@ func TestPostCertificateProviderDetails(t *testing.T) { }). Return(nil) - err := CertificateProviderDetails(nil, donorStore)(testAppData, w, r, &actor.DonorProvidedDetails{ + err := CertificateProviderDetails(nil, donorStore, testUIDFn)(testAppData, w, r, &actor.DonorProvidedDetails{ LpaID: "lpa-id", Donor: actor.Donor{ FirstNames: "Jane", @@ -221,6 +225,7 @@ func TestPostCertificateProviderDetailsWhenAmendingDetailsAfterStateComplete(t * LastName: "Doe", }, CertificateProvider: actor.CertificateProvider{ + UID: testUID, FirstNames: "John", LastName: "Rey", Mobile: "07535111111", @@ -229,7 +234,7 @@ func TestPostCertificateProviderDetailsWhenAmendingDetailsAfterStateComplete(t * }). Return(nil) - err := CertificateProviderDetails(nil, donorStore)(testAppData, w, r, &actor.DonorProvidedDetails{ + err := CertificateProviderDetails(nil, donorStore, testUIDFn)(testAppData, w, r, &actor.DonorProvidedDetails{ LpaID: "lpa-id", Donor: actor.Donor{ FirstNames: "Jane", @@ -324,7 +329,7 @@ func TestPostCertificateProviderDetailsWhenInputRequired(t *testing.T) { })). Return(nil) - err := CertificateProviderDetails(template.Execute, nil)(testAppData, w, r, tc.existingDonor) + err := CertificateProviderDetails(template.Execute, nil, testUIDFn)(testAppData, w, r, tc.existingDonor) resp := w.Result() assert.Nil(t, err) @@ -349,7 +354,7 @@ func TestPostCertificateProviderDetailsWhenStoreErrors(t *testing.T) { Put(r.Context(), mock.Anything). Return(expectedError) - err := CertificateProviderDetails(nil, donorStore)(testAppData, w, r, &actor.DonorProvidedDetails{}) + err := CertificateProviderDetails(nil, donorStore, testUIDFn)(testAppData, w, r, &actor.DonorProvidedDetails{}) assert.Equal(t, expectedError, err) } diff --git a/internal/page/donor/choose_address.go b/internal/page/donor/choose_address.go index d075e5b1f0..dc68d674e3 100644 --- a/internal/page/donor/choose_address.go +++ b/internal/page/donor/choose_address.go @@ -4,18 +4,19 @@ import ( "context" "errors" + "github.com/ministryofjustice/opg-modernising-lpa/internal/actor/actoruid" "github.com/ministryofjustice/opg-modernising-lpa/internal/form" "github.com/ministryofjustice/opg-modernising-lpa/internal/page" "github.com/ministryofjustice/opg-modernising-lpa/internal/place" "github.com/ministryofjustice/opg-modernising-lpa/internal/validation" ) -func newChooseAddressData(appData page.AppData, actorLabel, fullName, ID string, canSkip bool) *chooseAddressData { +func newChooseAddressData(appData page.AppData, actorLabel, fullName string, UID actoruid.UID, canSkip bool) *chooseAddressData { return &chooseAddressData{ App: appData, ActorLabel: actorLabel, FullName: fullName, - ID: ID, + UID: UID, CanSkip: canSkip, Form: form.NewAddressForm(), TitleKeys: titleKeys{ @@ -33,7 +34,7 @@ type chooseAddressData struct { Errors validation.List ActorLabel string FullName string - ID string + UID actoruid.UID CanSkip bool Addresses []place.Address Form *form.AddressForm diff --git a/internal/page/donor/choose_address_test.go b/internal/page/donor/choose_address_test.go index 9c793d6a2f..acc6b85048 100644 --- a/internal/page/donor/choose_address_test.go +++ b/internal/page/donor/choose_address_test.go @@ -3,6 +3,7 @@ package donor import ( "testing" + "github.com/ministryofjustice/opg-modernising-lpa/internal/actor/actoruid" "github.com/ministryofjustice/opg-modernising-lpa/internal/form" "github.com/stretchr/testify/assert" ) @@ -16,19 +17,22 @@ var testTitleKeys = titleKeys{ } func TestNewChooseAddressData(t *testing.T) { + uid := actoruid.New() + assert.Equal(t, &chooseAddressData{ Form: &form.AddressForm{FieldNames: form.FieldNames.Address}, TitleKeys: testTitleKeys, App: testAppData, ActorLabel: "a", FullName: "b", - ID: "c", + UID: uid, CanSkip: true, - }, newChooseAddressData(testAppData, "a", "b", "c", true)) + }, newChooseAddressData(testAppData, "a", "b", uid, true)) } func TestOverrideProfessionalCertificateProviderKeys(t *testing.T) { - data := newChooseAddressData(testAppData, "1", "2", "3", true) + uid := actoruid.New() + data := newChooseAddressData(testAppData, "1", "2", uid, true) data.overrideTitleKeys(titleKeys{ Manual: "a", @@ -50,7 +54,7 @@ func TestOverrideProfessionalCertificateProviderKeys(t *testing.T) { App: testAppData, ActorLabel: "1", FullName: "2", - ID: "3", + UID: uid, CanSkip: true, }, data) } diff --git a/internal/page/donor/choose_attorneys.go b/internal/page/donor/choose_attorneys.go index 34923be30b..6918118375 100644 --- a/internal/page/donor/choose_attorneys.go +++ b/internal/page/donor/choose_attorneys.go @@ -7,6 +7,7 @@ import ( "github.com/ministryofjustice/opg-go-common/template" "github.com/ministryofjustice/opg-modernising-lpa/internal/actor" + "github.com/ministryofjustice/opg-modernising-lpa/internal/actor/actoruid" "github.com/ministryofjustice/opg-modernising-lpa/internal/date" "github.com/ministryofjustice/opg-modernising-lpa/internal/page" "github.com/ministryofjustice/opg-modernising-lpa/internal/validation" @@ -22,10 +23,10 @@ type chooseAttorneysData struct { NameWarning *actor.SameNameWarning } -func ChooseAttorneys(tmpl template.Template, donorStore DonorStore, uuidString func() string) Handler { +func ChooseAttorneys(tmpl template.Template, donorStore DonorStore, newUID func() actoruid.UID) Handler { return func(appData page.AppData, w http.ResponseWriter, r *http.Request, donor *actor.DonorProvidedDetails) error { addAnother := r.FormValue("addAnother") == "1" - attorney, attorneyFound := donor.Attorneys.Get(r.URL.Query().Get("id")) + attorney, attorneyFound := donor.Attorneys.Get(actoruid.FromRequest(r)) if r.Method == http.MethodGet && len(donor.Attorneys.Attorneys) > 0 && !attorneyFound && !addAnother { return page.Paths.ChooseAttorneysSummary.Redirect(w, r, appData, donor) @@ -50,7 +51,7 @@ func ChooseAttorneys(tmpl template.Template, donorStore DonorStore, uuidString f nameWarning := actor.NewSameNameWarning( actor.TypeAttorney, - attorneyMatches(donor, attorney.ID, data.Form.FirstNames, data.Form.LastName), + attorneyMatches(donor, attorney.UID, data.Form.FirstNames, data.Form.LastName), data.Form.FirstNames, data.Form.LastName, ) @@ -65,7 +66,7 @@ func ChooseAttorneys(tmpl template.Template, donorStore DonorStore, uuidString f if data.Errors.None() && data.DobWarning == "" && data.NameWarning == nil { if attorneyFound == false { - attorney = actor.Attorney{ID: uuidString()} + attorney = actor.Attorney{UID: newUID()} } attorney.FirstNames = data.Form.FirstNames @@ -82,7 +83,7 @@ func ChooseAttorneys(tmpl template.Template, donorStore DonorStore, uuidString f return err } - return page.Paths.ChooseAttorneysAddress.RedirectQuery(w, r, appData, donor, url.Values{"id": {attorney.ID}}) + return page.Paths.ChooseAttorneysAddress.RedirectQuery(w, r, appData, donor, url.Values{"id": {attorney.UID.String()}}) } } @@ -160,7 +161,7 @@ func (f *chooseAttorneysForm) DobWarning() string { return "" } -func attorneyMatches(donor *actor.DonorProvidedDetails, id, firstNames, lastName string) actor.Type { +func attorneyMatches(donor *actor.DonorProvidedDetails, uid actoruid.UID, firstNames, lastName string) actor.Type { if firstNames == "" && lastName == "" { return actor.TypeNone } @@ -170,7 +171,7 @@ func attorneyMatches(donor *actor.DonorProvidedDetails, id, firstNames, lastName } for _, attorney := range donor.Attorneys.Attorneys { - if attorney.ID != id && strings.EqualFold(attorney.FirstNames, firstNames) && strings.EqualFold(attorney.LastName, lastName) { + if attorney.UID != uid && strings.EqualFold(attorney.FirstNames, firstNames) && strings.EqualFold(attorney.LastName, lastName) { return actor.TypeAttorney } } diff --git a/internal/page/donor/choose_attorneys_address.go b/internal/page/donor/choose_attorneys_address.go index 4a8dacda59..5e0d83dcc7 100644 --- a/internal/page/donor/choose_attorneys_address.go +++ b/internal/page/donor/choose_attorneys_address.go @@ -5,6 +5,7 @@ import ( "github.com/ministryofjustice/opg-go-common/template" "github.com/ministryofjustice/opg-modernising-lpa/internal/actor" + "github.com/ministryofjustice/opg-modernising-lpa/internal/actor/actoruid" "github.com/ministryofjustice/opg-modernising-lpa/internal/form" "github.com/ministryofjustice/opg-modernising-lpa/internal/page" "github.com/ministryofjustice/opg-modernising-lpa/internal/place" @@ -12,8 +13,7 @@ import ( func ChooseAttorneysAddress(logger Logger, tmpl template.Template, addressClient AddressClient, donorStore DonorStore) Handler { return func(appData page.AppData, w http.ResponseWriter, r *http.Request, donor *actor.DonorProvidedDetails) error { - attorneyId := r.FormValue("id") - attorney, found := donor.Attorneys.Get(attorneyId) + attorney, found := donor.Attorneys.Get(actoruid.FromRequest(r)) if found == false { return page.Paths.ChooseAttorneys.Redirect(w, r, appData, donor) @@ -23,13 +23,13 @@ func ChooseAttorneysAddress(logger Logger, tmpl template.Template, addressClient appData, "attorney", attorney.FullName(), - attorney.ID, + attorney.UID, true, ) data.ActorLabel = "attorney" data.FullName = attorney.FullName() - data.ID = attorney.ID + data.UID = attorney.UID data.CanSkip = true if attorney.Address.Line1 != "" { diff --git a/internal/page/donor/choose_attorneys_address_test.go b/internal/page/donor/choose_attorneys_address_test.go index 30f8aa4c8e..844ad053b6 100644 --- a/internal/page/donor/choose_attorneys_address_test.go +++ b/internal/page/donor/choose_attorneys_address_test.go @@ -8,6 +8,7 @@ import ( "testing" "github.com/ministryofjustice/opg-modernising-lpa/internal/actor" + "github.com/ministryofjustice/opg-modernising-lpa/internal/actor/actoruid" "github.com/ministryofjustice/opg-modernising-lpa/internal/form" "github.com/ministryofjustice/opg-modernising-lpa/internal/page" "github.com/ministryofjustice/opg-modernising-lpa/internal/place" @@ -17,15 +18,16 @@ import ( ) func TestGetChooseAttorneysAddress(t *testing.T) { + uid := actoruid.New() w := httptest.NewRecorder() - r, _ := http.NewRequest(http.MethodGet, "/?id=123", nil) + r, _ := http.NewRequest(http.MethodGet, "/?id="+uid.String(), nil) template := newMockTemplate(t) template.EXPECT(). Execute(w, &chooseAddressData{ App: testAppData, Form: form.NewAddressForm(), - ID: "123", + UID: uid, FullName: "John Smith", CanSkip: true, ActorLabel: "attorney", @@ -35,7 +37,7 @@ func TestGetChooseAttorneysAddress(t *testing.T) { err := ChooseAttorneysAddress(nil, template.Execute, nil, nil)(testAppData, w, r, &actor.DonorProvidedDetails{ Attorneys: actor.Attorneys{Attorneys: []actor.Attorney{{ - ID: "123", + UID: uid, FirstNames: "John", LastName: "Smith", Address: place.Address{}, @@ -48,11 +50,12 @@ func TestGetChooseAttorneysAddress(t *testing.T) { } func TestGetChooseAttorneysAddressFromStore(t *testing.T) { + uid := actoruid.New() w := httptest.NewRecorder() - r, _ := http.NewRequest(http.MethodGet, "/?id=123", nil) + r, _ := http.NewRequest(http.MethodGet, "/?id="+uid.String(), nil) attorney := actor.Attorney{ - ID: "123", + UID: uid, Address: testAddress, } @@ -65,7 +68,7 @@ func TestGetChooseAttorneysAddressFromStore(t *testing.T) { Address: &testAddress, FieldNames: form.FieldNames.Address, }, - ID: "123", + UID: uid, FullName: " ", CanSkip: true, ActorLabel: "attorney", @@ -83,8 +86,9 @@ func TestGetChooseAttorneysAddressFromStore(t *testing.T) { } func TestGetChooseAttorneysAddressManual(t *testing.T) { + uid := actoruid.New() w := httptest.NewRecorder() - r, _ := http.NewRequest(http.MethodGet, "/?action=manual&id=123", nil) + r, _ := http.NewRequest(http.MethodGet, "/?action=manual&id="+uid.String(), nil) template := newMockTemplate(t) template.EXPECT(). @@ -95,7 +99,7 @@ func TestGetChooseAttorneysAddressManual(t *testing.T) { Address: &place.Address{}, FieldNames: form.FieldNames.Address, }, - ID: "123", + UID: uid, FullName: " ", CanSkip: true, ActorLabel: "attorney", @@ -104,7 +108,7 @@ func TestGetChooseAttorneysAddressManual(t *testing.T) { Return(nil) err := ChooseAttorneysAddress(nil, template.Execute, nil, nil)(testAppData, w, r, &actor.DonorProvidedDetails{ - Attorneys: actor.Attorneys{Attorneys: []actor.Attorney{{ID: "123"}}}, + Attorneys: actor.Attorneys{Attorneys: []actor.Attorney{{UID: uid}}}, }) resp := w.Result() @@ -113,15 +117,16 @@ func TestGetChooseAttorneysAddressManual(t *testing.T) { } func TestGetChooseAttorneysAddressWhenTemplateErrors(t *testing.T) { + uid := actoruid.New() w := httptest.NewRecorder() - r, _ := http.NewRequest(http.MethodGet, "/?id=123", nil) + r, _ := http.NewRequest(http.MethodGet, "/?id="+uid.String(), nil) template := newMockTemplate(t) template.EXPECT(). Execute(w, &chooseAddressData{ App: testAppData, Form: form.NewAddressForm(), - ID: "123", + UID: uid, FullName: " ", CanSkip: true, ActorLabel: "attorney", @@ -130,7 +135,7 @@ func TestGetChooseAttorneysAddressWhenTemplateErrors(t *testing.T) { Return(expectedError) err := ChooseAttorneysAddress(nil, template.Execute, nil, nil)(testAppData, w, r, &actor.DonorProvidedDetails{ - Attorneys: actor.Attorneys{Attorneys: []actor.Attorney{{ID: "123"}}}, + Attorneys: actor.Attorneys{Attorneys: []actor.Attorney{{UID: uid}}}, }) resp := w.Result() @@ -148,15 +153,16 @@ func TestPostChooseAttorneysAddressSkip(t *testing.T) { form.FieldNames.Address.Postcode: {"e"}, } + uid := actoruid.New() w := httptest.NewRecorder() - r, _ := http.NewRequest(http.MethodPost, "/?id=123", strings.NewReader(f.Encode())) + r, _ := http.NewRequest(http.MethodPost, "/?id="+uid.String(), strings.NewReader(f.Encode())) r.Header.Add("Content-Type", page.FormUrlEncoded) donorStore := newMockDonorStore(t) donorStore.EXPECT(). Put(r.Context(), &actor.DonorProvidedDetails{ LpaID: "lpa-id", - Attorneys: actor.Attorneys{Attorneys: []actor.Attorney{{ID: "123", FirstNames: "a", Email: "a"}}}, + Attorneys: actor.Attorneys{Attorneys: []actor.Attorney{{UID: uid, FirstNames: "a", Email: "a"}}}, Tasks: actor.DonorTasks{ChooseAttorneys: actor.TaskCompleted}, }). Return(nil) @@ -164,7 +170,7 @@ func TestPostChooseAttorneysAddressSkip(t *testing.T) { err := ChooseAttorneysAddress(nil, nil, nil, donorStore)(testAppData, w, r, &actor.DonorProvidedDetails{ LpaID: "lpa-id", Attorneys: actor.Attorneys{Attorneys: []actor.Attorney{{ - ID: "123", + UID: uid, FirstNames: "a", Email: "a", Address: place.Address{Line1: "abc"}, @@ -187,8 +193,9 @@ func TestPostChooseAttorneysAddressSkipWhenStoreErrors(t *testing.T) { form.FieldNames.Address.Postcode: {"e"}, } + uid := actoruid.New() w := httptest.NewRecorder() - r, _ := http.NewRequest(http.MethodPost, "/?id=123", strings.NewReader(f.Encode())) + r, _ := http.NewRequest(http.MethodPost, "/?id="+uid.String(), strings.NewReader(f.Encode())) r.Header.Add("Content-Type", page.FormUrlEncoded) donorStore := newMockDonorStore(t) @@ -198,7 +205,7 @@ func TestPostChooseAttorneysAddressSkipWhenStoreErrors(t *testing.T) { err := ChooseAttorneysAddress(nil, nil, nil, donorStore)(testAppData, w, r, &actor.DonorProvidedDetails{ Attorneys: actor.Attorneys{Attorneys: []actor.Attorney{{ - ID: "123", + UID: uid, Address: place.Address{Line1: "abc"}, }}}, }) @@ -216,8 +223,9 @@ func TestPostChooseAttorneysAddressManual(t *testing.T) { form.FieldNames.Address.Postcode: {"e"}, } + uid := actoruid.New() w := httptest.NewRecorder() - r, _ := http.NewRequest(http.MethodPost, "/?id=123", strings.NewReader(f.Encode())) + r, _ := http.NewRequest(http.MethodPost, "/?id="+uid.String(), strings.NewReader(f.Encode())) r.Header.Add("Content-Type", page.FormUrlEncoded) donorStore := newMockDonorStore(t) @@ -226,7 +234,7 @@ func TestPostChooseAttorneysAddressManual(t *testing.T) { LpaID: "lpa-id", Tasks: actor.DonorTasks{ChooseAttorneys: actor.TaskCompleted}, Attorneys: actor.Attorneys{Attorneys: []actor.Attorney{{ - ID: "123", + UID: uid, FirstNames: "a", Address: testAddress, }}}, @@ -236,7 +244,7 @@ func TestPostChooseAttorneysAddressManual(t *testing.T) { err := ChooseAttorneysAddress(nil, nil, nil, donorStore)(testAppData, w, r, &actor.DonorProvidedDetails{ LpaID: "lpa-id", Attorneys: actor.Attorneys{Attorneys: []actor.Attorney{{ - ID: "123", + UID: uid, FirstNames: "a", Address: place.Address{}, }}}, @@ -258,8 +266,9 @@ func TestPostChooseAttorneysAddressManualWhenStoreErrors(t *testing.T) { form.FieldNames.Address.Postcode: {"e"}, } + uid := actoruid.New() w := httptest.NewRecorder() - r, _ := http.NewRequest(http.MethodPost, "/?id=123", strings.NewReader(f.Encode())) + r, _ := http.NewRequest(http.MethodPost, "/?id="+uid.String(), strings.NewReader(f.Encode())) r.Header.Add("Content-Type", page.FormUrlEncoded) donorStore := newMockDonorStore(t) @@ -269,7 +278,7 @@ func TestPostChooseAttorneysAddressManualWhenStoreErrors(t *testing.T) { err := ChooseAttorneysAddress(nil, nil, nil, donorStore)(testAppData, w, r, &actor.DonorProvidedDetails{ Attorneys: actor.Attorneys{Attorneys: []actor.Attorney{{ - ID: "123", + UID: uid, Address: place.Address{}, }}}, }) @@ -287,8 +296,9 @@ func TestPostChooseAttorneysAddressManualFromStore(t *testing.T) { form.FieldNames.Address.Postcode: {"e"}, } + uid := actoruid.New() w := httptest.NewRecorder() - r, _ := http.NewRequest(http.MethodPost, "/?id=123", strings.NewReader(f.Encode())) + r, _ := http.NewRequest(http.MethodPost, "/?id="+uid.String(), strings.NewReader(f.Encode())) r.Header.Add("Content-Type", page.FormUrlEncoded) donorStore := newMockDonorStore(t) @@ -297,7 +307,7 @@ func TestPostChooseAttorneysAddressManualFromStore(t *testing.T) { LpaID: "lpa-id", Tasks: actor.DonorTasks{ChooseAttorneys: actor.TaskCompleted}, Attorneys: actor.Attorneys{Attorneys: []actor.Attorney{{ - ID: "123", + UID: uid, FirstNames: "John", Address: testAddress, }}}, @@ -307,7 +317,7 @@ func TestPostChooseAttorneysAddressManualFromStore(t *testing.T) { err := ChooseAttorneysAddress(nil, nil, nil, donorStore)(testAppData, w, r, &actor.DonorProvidedDetails{ LpaID: "lpa-id", Attorneys: actor.Attorneys{Attorneys: []actor.Attorney{{ - ID: "123", + UID: uid, FirstNames: "John", Address: place.Address{Line1: "abc"}, }}}, @@ -327,12 +337,13 @@ func TestPostChooseAttorneysAddressManualWhenValidationError(t *testing.T) { form.FieldNames.Address.Postcode: {"d"}, } + uid := actoruid.New() w := httptest.NewRecorder() - r, _ := http.NewRequest(http.MethodPost, "/?id=123", strings.NewReader(f.Encode())) + r, _ := http.NewRequest(http.MethodPost, "/?id="+uid.String(), strings.NewReader(f.Encode())) r.Header.Add("Content-Type", page.FormUrlEncoded) attorney := actor.Attorney{ - ID: "123", + UID: uid, Address: place.Address{}, } @@ -353,7 +364,7 @@ func TestPostChooseAttorneysAddressManualWhenValidationError(t *testing.T) { FieldNames: form.FieldNames.Address, }, Errors: validation.With(form.FieldNames.Address.Line1, validation.EnterError{Label: "addressLine1"}), - ID: "123", + UID: uid, FullName: " ", CanSkip: true, ActorLabel: "attorney", @@ -377,8 +388,9 @@ func TestPostChooseAttorneysAddressPostcodeSelect(t *testing.T) { "select-address": {testAddress.Encode()}, } + uid := actoruid.New() w := httptest.NewRecorder() - r, _ := http.NewRequest(http.MethodPost, "/?id=123", strings.NewReader(f.Encode())) + r, _ := http.NewRequest(http.MethodPost, "/?id="+uid.String(), strings.NewReader(f.Encode())) r.Header.Add("Content-Type", page.FormUrlEncoded) template := newMockTemplate(t) @@ -391,7 +403,7 @@ func TestPostChooseAttorneysAddressPostcodeSelect(t *testing.T) { Address: &testAddress, FieldNames: form.FieldNames.Address, }, - ID: "123", + UID: uid, FullName: " ", CanSkip: true, ActorLabel: "attorney", @@ -400,7 +412,7 @@ func TestPostChooseAttorneysAddressPostcodeSelect(t *testing.T) { Return(nil) err := ChooseAttorneysAddress(nil, template.Execute, nil, nil)(testAppData, w, r, &actor.DonorProvidedDetails{ - Attorneys: actor.Attorneys{Attorneys: []actor.Attorney{{ID: "123"}}}, + Attorneys: actor.Attorneys{Attorneys: []actor.Attorney{{UID: uid}}}, }) resp := w.Result() @@ -414,8 +426,9 @@ func TestPostChooseAttorneysAddressPostcodeSelectWhenValidationError(t *testing. "lookup-postcode": {"NG1"}, } + uid := actoruid.New() w := httptest.NewRecorder() - r, _ := http.NewRequest(http.MethodPost, "/?id=123", strings.NewReader(f.Encode())) + r, _ := http.NewRequest(http.MethodPost, "/?id="+uid.String(), strings.NewReader(f.Encode())) r.Header.Add("Content-Type", page.FormUrlEncoded) addresses := []place.Address{ @@ -438,7 +451,7 @@ func TestPostChooseAttorneysAddressPostcodeSelectWhenValidationError(t *testing. }, Addresses: addresses, Errors: validation.With("select-address", validation.SelectError{Label: "anAddressFromTheList"}), - ID: "123", + UID: uid, FullName: " ", CanSkip: true, ActorLabel: "attorney", @@ -447,7 +460,7 @@ func TestPostChooseAttorneysAddressPostcodeSelectWhenValidationError(t *testing. Return(nil) err := ChooseAttorneysAddress(nil, template.Execute, addressClient, nil)(testAppData, w, r, &actor.DonorProvidedDetails{ - Attorneys: actor.Attorneys{Attorneys: []actor.Attorney{{ID: "123"}}}, + Attorneys: actor.Attorneys{Attorneys: []actor.Attorney{{UID: uid}}}, }) resp := w.Result() @@ -461,8 +474,9 @@ func TestPostChooseAttorneysPostcodeLookup(t *testing.T) { "lookup-postcode": {"NG1"}, } + uid := actoruid.New() w := httptest.NewRecorder() - r, _ := http.NewRequest(http.MethodPost, "/?id=123", strings.NewReader(f.Encode())) + r, _ := http.NewRequest(http.MethodPost, "/?id="+uid.String(), strings.NewReader(f.Encode())) r.Header.Add("Content-Type", page.FormUrlEncoded) addresses := []place.Address{ @@ -484,7 +498,7 @@ func TestPostChooseAttorneysPostcodeLookup(t *testing.T) { FieldNames: form.FieldNames.Address, }, Addresses: addresses, - ID: "123", + UID: uid, FullName: " ", CanSkip: true, ActorLabel: "attorney", @@ -493,7 +507,7 @@ func TestPostChooseAttorneysPostcodeLookup(t *testing.T) { Return(nil) err := ChooseAttorneysAddress(nil, template.Execute, addressClient, nil)(testAppData, w, r, &actor.DonorProvidedDetails{ - Attorneys: actor.Attorneys{Attorneys: []actor.Attorney{{ID: "123"}}}, + Attorneys: actor.Attorneys{Attorneys: []actor.Attorney{{UID: uid}}}, }) resp := w.Result() @@ -507,8 +521,9 @@ func TestPostChooseAttorneysPostcodeLookupError(t *testing.T) { "lookup-postcode": {"NG1"}, } + uid := actoruid.New() w := httptest.NewRecorder() - r, _ := http.NewRequest(http.MethodPost, "/?id=123", strings.NewReader(f.Encode())) + r, _ := http.NewRequest(http.MethodPost, "/?id="+uid.String(), strings.NewReader(f.Encode())) r.Header.Add("Content-Type", page.FormUrlEncoded) logger := newMockLogger(t) @@ -531,7 +546,7 @@ func TestPostChooseAttorneysPostcodeLookupError(t *testing.T) { }, Addresses: []place.Address{}, Errors: validation.With("lookup-postcode", validation.CustomError{Label: "couldNotLookupPostcode"}), - ID: "123", + UID: uid, FullName: " ", CanSkip: true, ActorLabel: "attorney", @@ -540,7 +555,7 @@ func TestPostChooseAttorneysPostcodeLookupError(t *testing.T) { Return(nil) err := ChooseAttorneysAddress(logger, template.Execute, addressClient, nil)(testAppData, w, r, &actor.DonorProvidedDetails{ - Attorneys: actor.Attorneys{Attorneys: []actor.Attorney{{ID: "123"}}}, + Attorneys: actor.Attorneys{Attorneys: []actor.Attorney{{UID: uid}}}, }) resp := w.Result() @@ -560,7 +575,8 @@ func TestPostChooseAttorneysPostcodeLookupInvalidPostcodeError(t *testing.T) { "lookup-postcode": {"XYZ"}, } - r, _ := http.NewRequest(http.MethodPost, "/?id=123", strings.NewReader(f.Encode())) + uid := actoruid.New() + r, _ := http.NewRequest(http.MethodPost, "/?id="+uid.String(), strings.NewReader(f.Encode())) r.Header.Add("Content-Type", page.FormUrlEncoded) logger := newMockLogger(t) @@ -583,7 +599,7 @@ func TestPostChooseAttorneysPostcodeLookupInvalidPostcodeError(t *testing.T) { }, Addresses: []place.Address{}, Errors: validation.With("lookup-postcode", validation.EnterError{Label: "invalidPostcode"}), - ID: "123", + UID: uid, FullName: " ", CanSkip: true, ActorLabel: "attorney", @@ -592,7 +608,7 @@ func TestPostChooseAttorneysPostcodeLookupInvalidPostcodeError(t *testing.T) { Return(nil) err := ChooseAttorneysAddress(logger, template.Execute, addressClient, nil)(testAppData, w, r, &actor.DonorProvidedDetails{ - Attorneys: actor.Attorneys{Attorneys: []actor.Attorney{{ID: "123"}}}, + Attorneys: actor.Attorneys{Attorneys: []actor.Attorney{{UID: uid}}}, }) resp := w.Result() @@ -608,7 +624,8 @@ func TestPostChooseAttorneysPostcodeLookupValidPostcodeNoAddresses(t *testing.T) "lookup-postcode": {"XYZ"}, } - r, _ := http.NewRequest(http.MethodPost, "/?id=123", strings.NewReader(f.Encode())) + uid := actoruid.New() + r, _ := http.NewRequest(http.MethodPost, "/?id="+uid.String(), strings.NewReader(f.Encode())) r.Header.Add("Content-Type", page.FormUrlEncoded) addressClient := newMockAddressClient(t) @@ -627,7 +644,7 @@ func TestPostChooseAttorneysPostcodeLookupValidPostcodeNoAddresses(t *testing.T) }, Addresses: []place.Address{}, Errors: validation.With("lookup-postcode", validation.CustomError{Label: "noAddressesFound"}), - ID: "123", + UID: uid, FullName: " ", CanSkip: true, ActorLabel: "attorney", @@ -636,7 +653,7 @@ func TestPostChooseAttorneysPostcodeLookupValidPostcodeNoAddresses(t *testing.T) Return(nil) err := ChooseAttorneysAddress(nil, template.Execute, addressClient, nil)(testAppData, w, r, &actor.DonorProvidedDetails{ - Attorneys: actor.Attorneys{Attorneys: []actor.Attorney{{ID: "123"}}}, + Attorneys: actor.Attorneys{Attorneys: []actor.Attorney{{UID: uid}}}, }) resp := w.Result() @@ -649,8 +666,9 @@ func TestPostChooseAttorneysPostcodeLookupWhenValidationError(t *testing.T) { form.FieldNames.Address.Action: {"postcode-lookup"}, } + uid := actoruid.New() w := httptest.NewRecorder() - r, _ := http.NewRequest(http.MethodPost, "/?id=123", strings.NewReader(f.Encode())) + r, _ := http.NewRequest(http.MethodPost, "/?id="+uid.String(), strings.NewReader(f.Encode())) r.Header.Add("Content-Type", page.FormUrlEncoded) template := newMockTemplate(t) @@ -662,7 +680,7 @@ func TestPostChooseAttorneysPostcodeLookupWhenValidationError(t *testing.T) { FieldNames: form.FieldNames.Address, }, Errors: validation.With("lookup-postcode", validation.EnterError{Label: "aPostcode"}), - ID: "123", + UID: uid, FullName: " ", CanSkip: true, ActorLabel: "attorney", @@ -671,7 +689,7 @@ func TestPostChooseAttorneysPostcodeLookupWhenValidationError(t *testing.T) { Return(nil) err := ChooseAttorneysAddress(nil, template.Execute, nil, nil)(testAppData, w, r, &actor.DonorProvidedDetails{ - Attorneys: actor.Attorneys{Attorneys: []actor.Attorney{{ID: "123"}}}, + Attorneys: actor.Attorneys{Attorneys: []actor.Attorney{{UID: uid}}}, }) resp := w.Result() @@ -684,8 +702,9 @@ func TestPostChooseAttorneysAddressReuse(t *testing.T) { form.FieldNames.Address.Action: {"reuse"}, } + uid := actoruid.New() w := httptest.NewRecorder() - r, _ := http.NewRequest(http.MethodPost, "/?id=123", strings.NewReader(f.Encode())) + r, _ := http.NewRequest(http.MethodPost, "/?id="+uid.String(), strings.NewReader(f.Encode())) r.Header.Add("Content-Type", page.FormUrlEncoded) template := newMockTemplate(t) @@ -696,7 +715,7 @@ func TestPostChooseAttorneysAddressReuse(t *testing.T) { Action: "reuse", FieldNames: form.FieldNames.Address, }, - ID: "123", + UID: uid, FullName: " ", CanSkip: true, ActorLabel: "attorney", @@ -707,7 +726,7 @@ func TestPostChooseAttorneysAddressReuse(t *testing.T) { err := ChooseAttorneysAddress(nil, template.Execute, nil, nil)(testAppData, w, r, &actor.DonorProvidedDetails{ Donor: actor.Donor{Address: place.Address{Line1: "donor lane"}}, - Attorneys: actor.Attorneys{Attorneys: []actor.Attorney{{ID: "123"}}}, + Attorneys: actor.Attorneys{Attorneys: []actor.Attorney{{UID: uid}}}, }) resp := w.Result() @@ -721,12 +740,13 @@ func TestPostChooseAttorneysAddressReuseSelect(t *testing.T) { "select-address": {testAddress.Encode()}, } + uid := actoruid.New() w := httptest.NewRecorder() - r, _ := http.NewRequest(http.MethodPost, "/?id=123", strings.NewReader(f.Encode())) + r, _ := http.NewRequest(http.MethodPost, "/?id="+uid.String(), strings.NewReader(f.Encode())) r.Header.Add("Content-Type", page.FormUrlEncoded) updatedAttorney := actor.Attorney{ - ID: "123", + UID: uid, Address: place.Address{ Line1: "a", Line2: "b", @@ -748,7 +768,7 @@ func TestPostChooseAttorneysAddressReuseSelect(t *testing.T) { err := ChooseAttorneysAddress(nil, nil, nil, donorStore)(testAppData, w, r, &actor.DonorProvidedDetails{ LpaID: "lpa-id", - Attorneys: actor.Attorneys{Attorneys: []actor.Attorney{{ID: "123"}}}, + Attorneys: actor.Attorneys{Attorneys: []actor.Attorney{{UID: uid}}}, }) resp := w.Result() @@ -762,8 +782,9 @@ func TestPostChooseAttorneysAddressReuseSelectWhenValidationError(t *testing.T) form.FieldNames.Address.Action: {"reuse-select"}, } + uid := actoruid.New() w := httptest.NewRecorder() - r, _ := http.NewRequest(http.MethodPost, "/?id=123", strings.NewReader(f.Encode())) + r, _ := http.NewRequest(http.MethodPost, "/?id="+uid.String(), strings.NewReader(f.Encode())) r.Header.Add("Content-Type", page.FormUrlEncoded) template := newMockTemplate(t) @@ -776,7 +797,7 @@ func TestPostChooseAttorneysAddressReuseSelectWhenValidationError(t *testing.T) }, Addresses: []place.Address{{Line1: "donor lane"}}, Errors: validation.With("select-address", validation.SelectError{Label: "anAddressFromTheList"}), - ID: "123", + UID: uid, FullName: " ", CanSkip: true, ActorLabel: "attorney", @@ -786,7 +807,7 @@ func TestPostChooseAttorneysAddressReuseSelectWhenValidationError(t *testing.T) err := ChooseAttorneysAddress(nil, template.Execute, nil, nil)(testAppData, w, r, &actor.DonorProvidedDetails{ Donor: actor.Donor{Address: place.Address{Line1: "donor lane"}}, - Attorneys: actor.Attorneys{Attorneys: []actor.Attorney{{ID: "123"}}}, + Attorneys: actor.Attorneys{Attorneys: []actor.Attorney{{UID: uid}}}, }) resp := w.Result() @@ -795,20 +816,22 @@ func TestPostChooseAttorneysAddressReuseSelectWhenValidationError(t *testing.T) } func TestPostChooseAttorneysManuallyFromAnotherPage(t *testing.T) { + uid := actoruid.New() + testcases := map[string]struct { requestUrl string expectedNextUrl string }{ "with from value": { - "/?from=/test&id=123", + "/?from=/test&id=" + uid.String(), "/test", }, "without from value": { - "/?from=&id=123", + "/?from=&id=" + uid.String(), page.Paths.ChooseAttorneysSummary.Format("lpa-id"), }, "missing from key": { - "/?id=123", + "/?id=" + uid.String(), page.Paths.ChooseAttorneysSummary.Format("lpa-id"), }, } @@ -830,7 +853,7 @@ func TestPostChooseAttorneysManuallyFromAnotherPage(t *testing.T) { LpaID: "lpa-id", Attorneys: actor.Attorneys{Attorneys: []actor.Attorney{ { - ID: "123", + UID: uid, Address: place.Address{ Line1: "a", TownOrCity: "b", diff --git a/internal/page/donor/choose_attorneys_summary_test.go b/internal/page/donor/choose_attorneys_summary_test.go index c7f5c54383..c4b309a084 100644 --- a/internal/page/donor/choose_attorneys_summary_test.go +++ b/internal/page/donor/choose_attorneys_summary_test.go @@ -8,6 +8,7 @@ import ( "testing" "github.com/ministryofjustice/opg-modernising-lpa/internal/actor" + "github.com/ministryofjustice/opg-modernising-lpa/internal/actor/actoruid" "github.com/ministryofjustice/opg-modernising-lpa/internal/form" "github.com/ministryofjustice/opg-modernising-lpa/internal/page" "github.com/ministryofjustice/opg-modernising-lpa/internal/validation" @@ -74,12 +75,12 @@ func TestPostChooseAttorneysSummaryAddAttorney(t *testing.T) { "do not add attorney - with single attorney": { addMoreFormValue: form.No, expectedUrl: page.Paths.TaskList.Format("lpa-id"), - Attorneys: actor.Attorneys{Attorneys: []actor.Attorney{{ID: "123"}}}, + Attorneys: actor.Attorneys{Attorneys: []actor.Attorney{{UID: actoruid.New()}}}, }, "do not add attorney - with multiple attorneys": { addMoreFormValue: form.No, expectedUrl: page.Paths.HowShouldAttorneysMakeDecisions.Format("lpa-id"), - Attorneys: actor.Attorneys{Attorneys: []actor.Attorney{{ID: "123"}, {ID: "456"}}}, + Attorneys: actor.Attorneys{Attorneys: []actor.Attorney{{UID: actoruid.New()}, {UID: actoruid.New()}}}, }, } diff --git a/internal/page/donor/choose_attorneys_test.go b/internal/page/donor/choose_attorneys_test.go index c27502b341..08c04b8620 100644 --- a/internal/page/donor/choose_attorneys_test.go +++ b/internal/page/donor/choose_attorneys_test.go @@ -10,6 +10,7 @@ import ( "time" "github.com/ministryofjustice/opg-modernising-lpa/internal/actor" + "github.com/ministryofjustice/opg-modernising-lpa/internal/actor/actoruid" "github.com/ministryofjustice/opg-modernising-lpa/internal/date" "github.com/ministryofjustice/opg-modernising-lpa/internal/page" "github.com/ministryofjustice/opg-modernising-lpa/internal/place" @@ -32,7 +33,7 @@ func TestGetChooseAttorneys(t *testing.T) { }). Return(nil) - err := ChooseAttorneys(template.Execute, nil, mockUuidString)(testAppData, w, r, &actor.DonorProvidedDetails{}) + err := ChooseAttorneys(template.Execute, nil, testUIDFn)(testAppData, w, r, &actor.DonorProvidedDetails{}) resp := w.Result() assert.Nil(t, err) @@ -43,10 +44,10 @@ func TestGetChooseAttorneysFromStore(t *testing.T) { w := httptest.NewRecorder() r, _ := http.NewRequest(http.MethodGet, "/", nil) - err := ChooseAttorneys(nil, nil, mockUuidString)(testAppData, w, r, &actor.DonorProvidedDetails{ + err := ChooseAttorneys(nil, nil, testUIDFn)(testAppData, w, r, &actor.DonorProvidedDetails{ LpaID: "lpa-id", Attorneys: actor.Attorneys{Attorneys: []actor.Attorney{ - {FirstNames: "John", ID: "1"}, + {FirstNames: "John", UID: actoruid.New()}, }}, }) resp := w.Result() @@ -57,8 +58,9 @@ func TestGetChooseAttorneysFromStore(t *testing.T) { } func TestGetChooseAttorneysDobWarningIsAlwaysShown(t *testing.T) { + uid := actoruid.New() w := httptest.NewRecorder() - r, _ := http.NewRequest(http.MethodGet, "/?id=1", nil) + r, _ := http.NewRequest(http.MethodGet, "/?id="+uid.String(), nil) template := newMockTemplate(t) template.EXPECT(). @@ -66,7 +68,7 @@ func TestGetChooseAttorneysDobWarningIsAlwaysShown(t *testing.T) { App: testAppData, Donor: &actor.DonorProvidedDetails{ Attorneys: actor.Attorneys{Attorneys: []actor.Attorney{ - {ID: "1", DateOfBirth: date.New("1900", "1", "2")}, + {UID: uid, DateOfBirth: date.New("1900", "1", "2")}, }}, }, Form: &chooseAttorneysForm{ @@ -77,10 +79,10 @@ func TestGetChooseAttorneysDobWarningIsAlwaysShown(t *testing.T) { }). Return(nil) - err := ChooseAttorneys(template.Execute, nil, mockUuidString)(testAppData, w, r, &actor.DonorProvidedDetails{ + err := ChooseAttorneys(template.Execute, nil, testUIDFn)(testAppData, w, r, &actor.DonorProvidedDetails{ Donor: actor.Donor{}, Attorneys: actor.Attorneys{Attorneys: []actor.Attorney{ - {ID: "1", DateOfBirth: date.New("1900", "1", "2")}, + {UID: uid, DateOfBirth: date.New("1900", "1", "2")}, }}, }) resp := w.Result() @@ -98,7 +100,7 @@ func TestGetChooseAttorneysWhenTemplateErrors(t *testing.T) { Execute(w, mock.Anything). Return(expectedError) - err := ChooseAttorneys(template.Execute, nil, mockUuidString)(testAppData, w, r, &actor.DonorProvidedDetails{}) + err := ChooseAttorneys(template.Execute, nil, testUIDFn)(testAppData, w, r, &actor.DonorProvidedDetails{}) resp := w.Result() assert.Equal(t, expectedError, err) @@ -126,7 +128,7 @@ func TestPostChooseAttorneysAttorneyDoesNotExist(t *testing.T) { LastName: "Doe", Email: "john@example.com", DateOfBirth: date.New(validBirthYear, "1", "2"), - ID: "123", + UID: testUID, }, }, "dob warning ignored": { @@ -144,7 +146,7 @@ func TestPostChooseAttorneysAttorneyDoesNotExist(t *testing.T) { LastName: "Doe", Email: "john@example.com", DateOfBirth: date.New("1900", "1", "2"), - ID: "123", + UID: testUID, }, }, "name warning ignored": { @@ -162,7 +164,7 @@ func TestPostChooseAttorneysAttorneyDoesNotExist(t *testing.T) { LastName: "Doe", Email: "john@example.com", DateOfBirth: date.New(validBirthYear, "1", "2"), - ID: "123", + UID: testUID, }, }, } @@ -186,7 +188,7 @@ func TestPostChooseAttorneysAttorneyDoesNotExist(t *testing.T) { }). Return(nil) - err := ChooseAttorneys(nil, donorStore, mockUuidString)(testAppData, w, r, &actor.DonorProvidedDetails{ + err := ChooseAttorneys(nil, donorStore, testUIDFn)(testAppData, w, r, &actor.DonorProvidedDetails{ LpaID: "lpa-id", Donor: actor.Donor{ FirstNames: "Jane", @@ -197,12 +199,13 @@ func TestPostChooseAttorneysAttorneyDoesNotExist(t *testing.T) { assert.Nil(t, err) assert.Equal(t, http.StatusFound, resp.StatusCode) - assert.Equal(t, page.Paths.ChooseAttorneysAddress.Format("lpa-id")+"?id=123", resp.Header.Get("Location")) + assert.Equal(t, page.Paths.ChooseAttorneysAddress.Format("lpa-id")+"?id="+testUID.String(), resp.Header.Get("Location")) }) } } func TestPostChooseAttorneysAttorneyExists(t *testing.T) { + uid := actoruid.New() validBirthYear := strconv.Itoa(time.Now().Year() - 40) testCases := map[string]struct { @@ -224,7 +227,7 @@ func TestPostChooseAttorneysAttorneyExists(t *testing.T) { Email: "john@example.com", DateOfBirth: date.New(validBirthYear, "1", "2"), Address: place.Address{Line1: "abc"}, - ID: "123", + UID: uid, }, }, "dob warning ignored": { @@ -243,7 +246,7 @@ func TestPostChooseAttorneysAttorneyExists(t *testing.T) { Email: "john@example.com", DateOfBirth: date.New("1900", "1", "2"), Address: place.Address{Line1: "abc"}, - ID: "123", + UID: uid, }, }, "name warning ignored": { @@ -262,7 +265,7 @@ func TestPostChooseAttorneysAttorneyExists(t *testing.T) { Email: "john@example.com", DateOfBirth: date.New(validBirthYear, "1", "2"), Address: place.Address{Line1: "abc"}, - ID: "123", + UID: uid, }, }, } @@ -270,7 +273,7 @@ func TestPostChooseAttorneysAttorneyExists(t *testing.T) { for name, tc := range testCases { t.Run(name, func(t *testing.T) { w := httptest.NewRecorder() - r, _ := http.NewRequest(http.MethodPost, "/?id=123", strings.NewReader(tc.form.Encode())) + r, _ := http.NewRequest(http.MethodPost, "/?id="+uid.String(), strings.NewReader(tc.form.Encode())) r.Header.Add("Content-Type", page.FormUrlEncoded) donorStore := newMockDonorStore(t) @@ -283,13 +286,13 @@ func TestPostChooseAttorneysAttorneyExists(t *testing.T) { }). Return(nil) - err := ChooseAttorneys(nil, donorStore, mockUuidString)(testAppData, w, r, &actor.DonorProvidedDetails{ + err := ChooseAttorneys(nil, donorStore, testUIDFn)(testAppData, w, r, &actor.DonorProvidedDetails{ LpaID: "lpa-id", Donor: actor.Donor{FirstNames: "Jane", LastName: "Doe"}, Attorneys: actor.Attorneys{Attorneys: []actor.Attorney{ { FirstNames: "John", - ID: "123", + UID: uid, Address: place.Address{Line1: "abc"}, }, }}, @@ -298,7 +301,7 @@ func TestPostChooseAttorneysAttorneyExists(t *testing.T) { assert.Nil(t, err) assert.Equal(t, http.StatusFound, resp.StatusCode) - assert.Equal(t, page.Paths.ChooseAttorneysAddress.Format("lpa-id")+"?id=123", resp.Header.Get("Location")) + assert.Equal(t, page.Paths.ChooseAttorneysAddress.Format("lpa-id")+"?id="+uid.String(), resp.Header.Get("Location")) }) } } @@ -312,8 +315,9 @@ func TestPostChooseAttorneysNameWarningOnlyShownWhenAttorneyAndFormNamesAreDiffe "date-of-birth-year": {"2000"}, } + uid := actoruid.New() w := httptest.NewRecorder() - r, _ := http.NewRequest(http.MethodPost, "/?id=123", strings.NewReader(form.Encode())) + r, _ := http.NewRequest(http.MethodPost, "/?id="+uid.String(), strings.NewReader(form.Encode())) r.Header.Add("Content-Type", page.FormUrlEncoded) donorStore := newMockDonorStore(t) @@ -325,7 +329,7 @@ func TestPostChooseAttorneysNameWarningOnlyShownWhenAttorneyAndFormNamesAreDiffe { FirstNames: "Jane", LastName: "Doe", - ID: "123", + UID: uid, Address: place.Address{Line1: "abc"}, DateOfBirth: date.New("2000", "1", "2"), }, @@ -334,18 +338,18 @@ func TestPostChooseAttorneysNameWarningOnlyShownWhenAttorneyAndFormNamesAreDiffe }). Return(nil) - err := ChooseAttorneys(nil, donorStore, mockUuidString)(testAppData, w, r, &actor.DonorProvidedDetails{ + err := ChooseAttorneys(nil, donorStore, testUIDFn)(testAppData, w, r, &actor.DonorProvidedDetails{ LpaID: "lpa-id", Donor: actor.Donor{FirstNames: "Jane", LastName: "Doe"}, Attorneys: actor.Attorneys{Attorneys: []actor.Attorney{ - {FirstNames: "Jane", LastName: "Doe", ID: "123", Address: place.Address{Line1: "abc"}}, + {FirstNames: "Jane", LastName: "Doe", UID: uid, Address: place.Address{Line1: "abc"}}, }}, }) resp := w.Result() assert.Nil(t, err) assert.Equal(t, http.StatusFound, resp.StatusCode) - assert.Equal(t, page.Paths.ChooseAttorneysAddress.Format("lpa-id")+"?id=123", resp.Header.Get("Location")) + assert.Equal(t, page.Paths.ChooseAttorneysAddress.Format("lpa-id")+"?id="+uid.String(), resp.Header.Get("Location")) } func TestPostChooseAttorneysWhenInputRequired(t *testing.T) { @@ -473,7 +477,7 @@ func TestPostChooseAttorneysWhenInputRequired(t *testing.T) { })). Return(nil) - err := ChooseAttorneys(template.Execute, nil, mockUuidString)(testAppData, w, r, &actor.DonorProvidedDetails{ + err := ChooseAttorneys(template.Execute, nil, testUIDFn)(testAppData, w, r, &actor.DonorProvidedDetails{ Donor: actor.Donor{FirstNames: "Jane", LastName: "Doe"}, }) resp := w.Result() @@ -503,7 +507,7 @@ func TestPostChooseAttorneysWhenStoreErrors(t *testing.T) { Put(r.Context(), mock.Anything). Return(expectedError) - err := ChooseAttorneys(nil, donorStore, mockUuidString)(testAppData, w, r, &actor.DonorProvidedDetails{}) + err := ChooseAttorneys(nil, donorStore, testUIDFn)(testAppData, w, r, &actor.DonorProvidedDetails{}) assert.Equal(t, expectedError, err) } @@ -662,11 +666,13 @@ func TestChooseAttorneysFormDobWarning(t *testing.T) { } func TestAttorneyMatches(t *testing.T) { + uid := actoruid.New() + donor := &actor.DonorProvidedDetails{ Donor: actor.Donor{FirstNames: "a", LastName: "b"}, Attorneys: actor.Attorneys{Attorneys: []actor.Attorney{ {FirstNames: "c", LastName: "d"}, - {ID: "123", FirstNames: "e", LastName: "f"}, + {UID: uid, FirstNames: "e", LastName: "f"}, }}, ReplacementAttorneys: actor.Attorneys{Attorneys: []actor.Attorney{ {FirstNames: "g", LastName: "h"}, @@ -681,24 +687,26 @@ func TestAttorneyMatches(t *testing.T) { IndependentWitness: actor.IndependentWitness{FirstNames: "i", LastName: "w"}, } - assert.Equal(t, actor.TypeNone, attorneyMatches(donor, "123", "x", "y")) - assert.Equal(t, actor.TypeDonor, attorneyMatches(donor, "123", "a", "b")) - assert.Equal(t, actor.TypeAttorney, attorneyMatches(donor, "123", "c", "d")) - assert.Equal(t, actor.TypeNone, attorneyMatches(donor, "123", "e", "f")) - assert.Equal(t, actor.TypeReplacementAttorney, attorneyMatches(donor, "123", "g", "h")) - assert.Equal(t, actor.TypeReplacementAttorney, attorneyMatches(donor, "123", "I", "J")) - assert.Equal(t, actor.TypeCertificateProvider, attorneyMatches(donor, "123", "k", "l")) - assert.Equal(t, actor.TypePersonToNotify, attorneyMatches(donor, "123", "M", "N")) - assert.Equal(t, actor.TypePersonToNotify, attorneyMatches(donor, "123", "o", "p")) - assert.Equal(t, actor.TypeAuthorisedSignatory, attorneyMatches(donor, "123", "a", "s")) - assert.Equal(t, actor.TypeIndependentWitness, attorneyMatches(donor, "123", "i", "w")) + assert.Equal(t, actor.TypeNone, attorneyMatches(donor, uid, "x", "y")) + assert.Equal(t, actor.TypeDonor, attorneyMatches(donor, uid, "a", "b")) + assert.Equal(t, actor.TypeAttorney, attorneyMatches(donor, uid, "c", "d")) + assert.Equal(t, actor.TypeNone, attorneyMatches(donor, uid, "e", "f")) + assert.Equal(t, actor.TypeReplacementAttorney, attorneyMatches(donor, uid, "g", "h")) + assert.Equal(t, actor.TypeReplacementAttorney, attorneyMatches(donor, uid, "I", "J")) + assert.Equal(t, actor.TypeCertificateProvider, attorneyMatches(donor, uid, "k", "l")) + assert.Equal(t, actor.TypePersonToNotify, attorneyMatches(donor, uid, "M", "N")) + assert.Equal(t, actor.TypePersonToNotify, attorneyMatches(donor, uid, "o", "p")) + assert.Equal(t, actor.TypeAuthorisedSignatory, attorneyMatches(donor, uid, "a", "s")) + assert.Equal(t, actor.TypeIndependentWitness, attorneyMatches(donor, uid, "i", "w")) } func TestAttorneyMatchesEmptyNamesIgnored(t *testing.T) { + uid := actoruid.New() + donor := &actor.DonorProvidedDetails{ Donor: actor.Donor{FirstNames: "", LastName: ""}, Attorneys: actor.Attorneys{Attorneys: []actor.Attorney{ - {ID: "123", FirstNames: "", LastName: ""}, + {UID: uid, FirstNames: "", LastName: ""}, {FirstNames: "", LastName: ""}, }}, ReplacementAttorneys: actor.Attorneys{Attorneys: []actor.Attorney{ @@ -710,5 +718,5 @@ func TestAttorneyMatchesEmptyNamesIgnored(t *testing.T) { }, } - assert.Equal(t, actor.TypeNone, attorneyMatches(donor, "123", "", "")) + assert.Equal(t, actor.TypeNone, attorneyMatches(donor, uid, "", "")) } diff --git a/internal/page/donor/choose_people_to_notify.go b/internal/page/donor/choose_people_to_notify.go index ddb99625ab..83c6a19620 100644 --- a/internal/page/donor/choose_people_to_notify.go +++ b/internal/page/donor/choose_people_to_notify.go @@ -7,6 +7,7 @@ import ( "github.com/ministryofjustice/opg-go-common/template" "github.com/ministryofjustice/opg-modernising-lpa/internal/actor" + "github.com/ministryofjustice/opg-modernising-lpa/internal/actor/actoruid" "github.com/ministryofjustice/opg-modernising-lpa/internal/page" "github.com/ministryofjustice/opg-modernising-lpa/internal/validation" ) @@ -18,14 +19,14 @@ type choosePeopleToNotifyData struct { NameWarning *actor.SameNameWarning } -func ChoosePeopleToNotify(tmpl template.Template, donorStore DonorStore, uuidString func() string) Handler { +func ChoosePeopleToNotify(tmpl template.Template, donorStore DonorStore, newUID func() actoruid.UID) Handler { return func(appData page.AppData, w http.ResponseWriter, r *http.Request, donor *actor.DonorProvidedDetails) error { if len(donor.PeopleToNotify) > 4 { return page.Paths.ChoosePeopleToNotifySummary.Redirect(w, r, appData, donor) } addAnother := r.FormValue("addAnother") == "1" - personToNotify, personFound := donor.PeopleToNotify.Get(r.URL.Query().Get("id")) + personToNotify, personFound := donor.PeopleToNotify.Get(actoruid.FromRequest(r)) if r.Method == http.MethodGet && len(donor.PeopleToNotify) > 0 && personFound == false && addAnother == false { return page.Paths.ChoosePeopleToNotifySummary.Redirect(w, r, appData, donor) @@ -45,7 +46,7 @@ func ChoosePeopleToNotify(tmpl template.Template, donorStore DonorStore, uuidStr nameWarning := actor.NewSameNameWarning( actor.TypePersonToNotify, - personToNotifyMatches(donor, personToNotify.ID, data.Form.FirstNames, data.Form.LastName), + personToNotifyMatches(donor, personToNotify.UID, data.Form.FirstNames, data.Form.LastName), data.Form.FirstNames, data.Form.LastName, ) @@ -57,9 +58,9 @@ func ChoosePeopleToNotify(tmpl template.Template, donorStore DonorStore, uuidStr if data.Errors.None() && data.NameWarning == nil { if personFound == false { personToNotify = actor.PersonToNotify{ + UID: newUID(), FirstNames: data.Form.FirstNames, LastName: data.Form.LastName, - ID: uuidString(), } donor.PeopleToNotify = append(donor.PeopleToNotify, personToNotify) @@ -78,7 +79,7 @@ func ChoosePeopleToNotify(tmpl template.Template, donorStore DonorStore, uuidStr return err } - return page.Paths.ChoosePeopleToNotifyAddress.RedirectQuery(w, r, appData, donor, url.Values{"id": {personToNotify.ID}}) + return page.Paths.ChoosePeopleToNotifyAddress.RedirectQuery(w, r, appData, donor, url.Values{"id": {personToNotify.UID.String()}}) } } @@ -114,7 +115,7 @@ func (f *choosePeopleToNotifyForm) Validate() validation.List { return errors } -func personToNotifyMatches(donor *actor.DonorProvidedDetails, id, firstNames, lastName string) actor.Type { +func personToNotifyMatches(donor *actor.DonorProvidedDetails, uid actoruid.UID, firstNames, lastName string) actor.Type { if firstNames == "" && lastName == "" { return actor.TypeNone } @@ -136,7 +137,7 @@ func personToNotifyMatches(donor *actor.DonorProvidedDetails, id, firstNames, la } for _, person := range donor.PeopleToNotify { - if person.ID != id && strings.EqualFold(person.FirstNames, firstNames) && strings.EqualFold(person.LastName, lastName) { + if person.UID != uid && strings.EqualFold(person.FirstNames, firstNames) && strings.EqualFold(person.LastName, lastName) { return actor.TypePersonToNotify } } diff --git a/internal/page/donor/choose_people_to_notify_address.go b/internal/page/donor/choose_people_to_notify_address.go index 78decde238..1620bcaed6 100644 --- a/internal/page/donor/choose_people_to_notify_address.go +++ b/internal/page/donor/choose_people_to_notify_address.go @@ -5,6 +5,7 @@ import ( "github.com/ministryofjustice/opg-go-common/template" "github.com/ministryofjustice/opg-modernising-lpa/internal/actor" + "github.com/ministryofjustice/opg-modernising-lpa/internal/actor/actoruid" "github.com/ministryofjustice/opg-modernising-lpa/internal/form" "github.com/ministryofjustice/opg-modernising-lpa/internal/page" "github.com/ministryofjustice/opg-modernising-lpa/internal/place" @@ -12,8 +13,7 @@ import ( func ChoosePeopleToNotifyAddress(logger Logger, tmpl template.Template, addressClient AddressClient, donorStore DonorStore) Handler { return func(appData page.AppData, w http.ResponseWriter, r *http.Request, donor *actor.DonorProvidedDetails) error { - personId := r.FormValue("id") - personToNotify, found := donor.PeopleToNotify.Get(personId) + personToNotify, found := donor.PeopleToNotify.Get(actoruid.FromRequest(r)) if found == false { return page.Paths.ChoosePeopleToNotify.Redirect(w, r, appData, donor) @@ -23,7 +23,7 @@ func ChoosePeopleToNotifyAddress(logger Logger, tmpl template.Template, addressC appData, "personToNotify", personToNotify.FullName(), - personToNotify.ID, + personToNotify.UID, false, ) diff --git a/internal/page/donor/choose_people_to_notify_address_test.go b/internal/page/donor/choose_people_to_notify_address_test.go index b61d537f31..d0a179b874 100644 --- a/internal/page/donor/choose_people_to_notify_address_test.go +++ b/internal/page/donor/choose_people_to_notify_address_test.go @@ -8,6 +8,7 @@ import ( "testing" "github.com/ministryofjustice/opg-modernising-lpa/internal/actor" + "github.com/ministryofjustice/opg-modernising-lpa/internal/actor/actoruid" "github.com/ministryofjustice/opg-modernising-lpa/internal/form" "github.com/ministryofjustice/opg-modernising-lpa/internal/page" "github.com/ministryofjustice/opg-modernising-lpa/internal/place" @@ -17,11 +18,12 @@ import ( ) func TestGetChoosePeopleToNotifyAddress(t *testing.T) { + uid := actoruid.New() w := httptest.NewRecorder() - r, _ := http.NewRequest(http.MethodGet, "/?id=123", nil) + r, _ := http.NewRequest(http.MethodGet, "/?id="+uid.String(), nil) personToNotify := actor.PersonToNotify{ - ID: "123", + UID: uid, FirstNames: "John", LastName: "Smith", Address: place.Address{}, @@ -32,7 +34,7 @@ func TestGetChoosePeopleToNotifyAddress(t *testing.T) { Execute(w, &chooseAddressData{ App: testAppData, Form: form.NewAddressForm(), - ID: "123", + UID: uid, FullName: "John Smith", ActorLabel: "personToNotify", TitleKeys: testTitleKeys, @@ -47,8 +49,9 @@ func TestGetChoosePeopleToNotifyAddress(t *testing.T) { } func TestGetChoosePeopleToNotifyAddressFromStore(t *testing.T) { + uid := actoruid.New() w := httptest.NewRecorder() - r, _ := http.NewRequest(http.MethodGet, "/?id=123", nil) + r, _ := http.NewRequest(http.MethodGet, "/?id="+uid.String(), nil) template := newMockTemplate(t) template.EXPECT(). @@ -59,7 +62,7 @@ func TestGetChoosePeopleToNotifyAddressFromStore(t *testing.T) { Address: &testAddress, FieldNames: form.FieldNames.Address, }, - ID: "123", + UID: uid, FullName: " ", ActorLabel: "personToNotify", TitleKeys: testTitleKeys, @@ -67,7 +70,7 @@ func TestGetChoosePeopleToNotifyAddressFromStore(t *testing.T) { Return(nil) err := ChoosePeopleToNotifyAddress(nil, template.Execute, nil, nil)(testAppData, w, r, &actor.DonorProvidedDetails{ - PeopleToNotify: actor.PeopleToNotify{{ID: "123", Address: testAddress}}, + PeopleToNotify: actor.PeopleToNotify{{UID: uid, Address: testAddress}}, }) resp := w.Result() @@ -76,8 +79,9 @@ func TestGetChoosePeopleToNotifyAddressFromStore(t *testing.T) { } func TestGetChoosePeopleToNotifyAddressManual(t *testing.T) { + uid := actoruid.New() w := httptest.NewRecorder() - r, _ := http.NewRequest(http.MethodGet, "/?action=manual&id=123", nil) + r, _ := http.NewRequest(http.MethodGet, "/?action=manual&id="+uid.String(), nil) template := newMockTemplate(t) template.EXPECT(). @@ -88,14 +92,14 @@ func TestGetChoosePeopleToNotifyAddressManual(t *testing.T) { Address: &place.Address{}, FieldNames: form.FieldNames.Address, }, - ID: "123", + UID: uid, FullName: " ", ActorLabel: "personToNotify", TitleKeys: testTitleKeys, }). Return(nil) - err := ChoosePeopleToNotifyAddress(nil, template.Execute, nil, nil)(testAppData, w, r, &actor.DonorProvidedDetails{PeopleToNotify: actor.PeopleToNotify{{ID: "123", Address: testAddress}}}) + err := ChoosePeopleToNotifyAddress(nil, template.Execute, nil, nil)(testAppData, w, r, &actor.DonorProvidedDetails{PeopleToNotify: actor.PeopleToNotify{{UID: uid, Address: testAddress}}}) resp := w.Result() assert.Nil(t, err) @@ -103,11 +107,12 @@ func TestGetChoosePeopleToNotifyAddressManual(t *testing.T) { } func TestGetChoosePeopleToNotifyAddressWhenTemplateErrors(t *testing.T) { + uid := actoruid.New() w := httptest.NewRecorder() - r, _ := http.NewRequest(http.MethodGet, "/?id=123", nil) + r, _ := http.NewRequest(http.MethodGet, "/?id="+uid.String(), nil) personToNotify := actor.PersonToNotify{ - ID: "123", + UID: uid, Address: place.Address{}, } @@ -116,7 +121,7 @@ func TestGetChoosePeopleToNotifyAddressWhenTemplateErrors(t *testing.T) { Execute(w, &chooseAddressData{ App: testAppData, Form: form.NewAddressForm(), - ID: "123", + UID: uid, FullName: " ", ActorLabel: "personToNotify", TitleKeys: testTitleKeys, @@ -140,22 +145,23 @@ func TestPostChoosePeopleToNotifyAddressManual(t *testing.T) { form.FieldNames.Address.Postcode: {"e"}, } + uid := actoruid.New() w := httptest.NewRecorder() - r, _ := http.NewRequest(http.MethodPost, "/?id=123", strings.NewReader(f.Encode())) + r, _ := http.NewRequest(http.MethodPost, "/?id="+uid.String(), strings.NewReader(f.Encode())) r.Header.Add("Content-Type", page.FormUrlEncoded) donorStore := newMockDonorStore(t) donorStore.EXPECT(). Put(r.Context(), &actor.DonorProvidedDetails{ LpaID: "lpa-id", - PeopleToNotify: actor.PeopleToNotify{{ID: "123", Address: testAddress}}, + PeopleToNotify: actor.PeopleToNotify{{UID: uid, Address: testAddress}}, Tasks: actor.DonorTasks{PeopleToNotify: actor.TaskCompleted}, }). Return(nil) err := ChoosePeopleToNotifyAddress(nil, nil, nil, donorStore)(testAppData, w, r, &actor.DonorProvidedDetails{ LpaID: "lpa-id", - PeopleToNotify: actor.PeopleToNotify{{ID: "123"}}, + PeopleToNotify: actor.PeopleToNotify{{UID: uid}}, Tasks: actor.DonorTasks{PeopleToNotify: actor.TaskInProgress}, }) resp := w.Result() @@ -175,19 +181,20 @@ func TestPostChoosePeopleToNotifyAddressManualWhenStoreErrors(t *testing.T) { form.FieldNames.Address.Postcode: {"e"}, } + uid := actoruid.New() w := httptest.NewRecorder() - r, _ := http.NewRequest(http.MethodPost, "/?id=123", strings.NewReader(f.Encode())) + r, _ := http.NewRequest(http.MethodPost, "/?id="+uid.String(), strings.NewReader(f.Encode())) r.Header.Add("Content-Type", page.FormUrlEncoded) donorStore := newMockDonorStore(t) donorStore.EXPECT(). Put(r.Context(), &actor.DonorProvidedDetails{ - PeopleToNotify: actor.PeopleToNotify{{ID: "123", Address: testAddress}}, + PeopleToNotify: actor.PeopleToNotify{{UID: uid, Address: testAddress}}, Tasks: actor.DonorTasks{PeopleToNotify: actor.TaskCompleted}, }). Return(expectedError) - err := ChoosePeopleToNotifyAddress(nil, nil, nil, donorStore)(testAppData, w, r, &actor.DonorProvidedDetails{PeopleToNotify: actor.PeopleToNotify{{ID: "123"}}}) + err := ChoosePeopleToNotifyAddress(nil, nil, nil, donorStore)(testAppData, w, r, &actor.DonorProvidedDetails{PeopleToNotify: actor.PeopleToNotify{{UID: uid}}}) assert.Equal(t, expectedError, err) } @@ -202,8 +209,9 @@ func TestPostChoosePeopleToNotifyAddressManualFromStore(t *testing.T) { form.FieldNames.Address.Postcode: {"e"}, } + uid := actoruid.New() w := httptest.NewRecorder() - r, _ := http.NewRequest(http.MethodPost, "/?id=123", strings.NewReader(f.Encode())) + r, _ := http.NewRequest(http.MethodPost, "/?id="+uid.String(), strings.NewReader(f.Encode())) r.Header.Add("Content-Type", page.FormUrlEncoded) donorStore := newMockDonorStore(t) @@ -212,7 +220,7 @@ func TestPostChoosePeopleToNotifyAddressManualFromStore(t *testing.T) { Put(r.Context(), &actor.DonorProvidedDetails{ LpaID: "lpa-id", PeopleToNotify: actor.PeopleToNotify{actor.PersonToNotify{ - ID: "123", + UID: uid, FirstNames: "John", Address: testAddress, }}, @@ -223,7 +231,7 @@ func TestPostChoosePeopleToNotifyAddressManualFromStore(t *testing.T) { err := ChoosePeopleToNotifyAddress(nil, nil, nil, donorStore)(testAppData, w, r, &actor.DonorProvidedDetails{ LpaID: "lpa-id", PeopleToNotify: actor.PeopleToNotify{actor.PersonToNotify{ - ID: "123", + UID: uid, FirstNames: "John", Address: place.Address{Line1: "line1"}, }}, @@ -244,8 +252,9 @@ func TestPostChoosePeopleToNotifyPostcodeSelect(t *testing.T) { "select-address": {testAddress.Encode()}, } + uid := actoruid.New() w := httptest.NewRecorder() - r, _ := http.NewRequest(http.MethodPost, "/?id=123", strings.NewReader(f.Encode())) + r, _ := http.NewRequest(http.MethodPost, "/?id="+uid.String(), strings.NewReader(f.Encode())) r.Header.Add("Content-Type", page.FormUrlEncoded) template := newMockTemplate(t) @@ -258,7 +267,7 @@ func TestPostChoosePeopleToNotifyPostcodeSelect(t *testing.T) { Address: &testAddress, FieldNames: form.FieldNames.Address, }, - ID: "123", + UID: uid, FullName: "John ", ActorLabel: "personToNotify", TitleKeys: testTitleKeys, @@ -267,7 +276,7 @@ func TestPostChoosePeopleToNotifyPostcodeSelect(t *testing.T) { err := ChoosePeopleToNotifyAddress(nil, template.Execute, nil, nil)(testAppData, w, r, &actor.DonorProvidedDetails{ PeopleToNotify: actor.PeopleToNotify{{ - ID: "123", + UID: uid, FirstNames: "John", Address: place.Address{Line1: "abc"}, }}, @@ -284,8 +293,9 @@ func TestPostChoosePeopleToNotifyPostcodeSelectWhenValidationError(t *testing.T) "lookup-postcode": {"NG1"}, } + uid := actoruid.New() w := httptest.NewRecorder() - r, _ := http.NewRequest(http.MethodPost, "/?id=123", strings.NewReader(f.Encode())) + r, _ := http.NewRequest(http.MethodPost, "/?id="+uid.String(), strings.NewReader(f.Encode())) r.Header.Add("Content-Type", page.FormUrlEncoded) addresses := []place.Address{ @@ -306,7 +316,7 @@ func TestPostChoosePeopleToNotifyPostcodeSelectWhenValidationError(t *testing.T) LookupPostcode: "NG1", FieldNames: form.FieldNames.Address, }, - ID: "123", + UID: uid, FullName: " ", ActorLabel: "personToNotify", Addresses: addresses, @@ -315,7 +325,7 @@ func TestPostChoosePeopleToNotifyPostcodeSelectWhenValidationError(t *testing.T) }). Return(nil) - err := ChoosePeopleToNotifyAddress(nil, template.Execute, addressClient, nil)(testAppData, w, r, &actor.DonorProvidedDetails{PeopleToNotify: actor.PeopleToNotify{{ID: "123"}}}) + err := ChoosePeopleToNotifyAddress(nil, template.Execute, addressClient, nil)(testAppData, w, r, &actor.DonorProvidedDetails{PeopleToNotify: actor.PeopleToNotify{{UID: uid}}}) resp := w.Result() assert.Nil(t, err) @@ -328,8 +338,9 @@ func TestPostChoosePeopleToNotifyPostcodeLookup(t *testing.T) { "lookup-postcode": {"NG1"}, } + uid := actoruid.New() w := httptest.NewRecorder() - r, _ := http.NewRequest(http.MethodPost, "/?id=123", strings.NewReader(f.Encode())) + r, _ := http.NewRequest(http.MethodPost, "/?id="+uid.String(), strings.NewReader(f.Encode())) r.Header.Add("Content-Type", page.FormUrlEncoded) addresses := []place.Address{ @@ -350,7 +361,7 @@ func TestPostChoosePeopleToNotifyPostcodeLookup(t *testing.T) { LookupPostcode: "NG1", FieldNames: form.FieldNames.Address, }, - ID: "123", + UID: uid, FullName: "John ", ActorLabel: "personToNotify", Addresses: addresses, @@ -358,7 +369,7 @@ func TestPostChoosePeopleToNotifyPostcodeLookup(t *testing.T) { }). Return(nil) - err := ChoosePeopleToNotifyAddress(nil, template.Execute, addressClient, nil)(testAppData, w, r, &actor.DonorProvidedDetails{PeopleToNotify: actor.PeopleToNotify{{ID: "123", FirstNames: "John"}}}) + err := ChoosePeopleToNotifyAddress(nil, template.Execute, addressClient, nil)(testAppData, w, r, &actor.DonorProvidedDetails{PeopleToNotify: actor.PeopleToNotify{{UID: uid, FirstNames: "John"}}}) resp := w.Result() assert.Nil(t, err) @@ -371,8 +382,9 @@ func TestPostChoosePeopleToNotifyPostcodeLookupError(t *testing.T) { "lookup-postcode": {"NG1"}, } + uid := actoruid.New() w := httptest.NewRecorder() - r, _ := http.NewRequest(http.MethodPost, "/?id=123", strings.NewReader(f.Encode())) + r, _ := http.NewRequest(http.MethodPost, "/?id="+uid.String(), strings.NewReader(f.Encode())) r.Header.Add("Content-Type", page.FormUrlEncoded) logger := newMockLogger(t) @@ -393,7 +405,7 @@ func TestPostChoosePeopleToNotifyPostcodeLookupError(t *testing.T) { LookupPostcode: "NG1", FieldNames: form.FieldNames.Address, }, - ID: "123", + UID: uid, FullName: " ", ActorLabel: "personToNotify", Addresses: []place.Address{}, @@ -402,7 +414,7 @@ func TestPostChoosePeopleToNotifyPostcodeLookupError(t *testing.T) { }). Return(nil) - err := ChoosePeopleToNotifyAddress(logger, template.Execute, addressClient, nil)(testAppData, w, r, &actor.DonorProvidedDetails{PeopleToNotify: actor.PeopleToNotify{{ID: "123"}}}) + err := ChoosePeopleToNotifyAddress(logger, template.Execute, addressClient, nil)(testAppData, w, r, &actor.DonorProvidedDetails{PeopleToNotify: actor.PeopleToNotify{{UID: uid}}}) resp := w.Result() assert.Nil(t, err) @@ -421,7 +433,8 @@ func TestPostChoosePeopleToNotifyPostcodeLookupInvalidPostcodeError(t *testing.T "lookup-postcode": {"XYZ"}, } - r, _ := http.NewRequest(http.MethodPost, "/?id=123", strings.NewReader(f.Encode())) + uid := actoruid.New() + r, _ := http.NewRequest(http.MethodPost, "/?id="+uid.String(), strings.NewReader(f.Encode())) r.Header.Add("Content-Type", page.FormUrlEncoded) logger := newMockLogger(t) @@ -442,7 +455,7 @@ func TestPostChoosePeopleToNotifyPostcodeLookupInvalidPostcodeError(t *testing.T LookupPostcode: "XYZ", FieldNames: form.FieldNames.Address, }, - ID: "123", + UID: uid, FullName: " ", ActorLabel: "personToNotify", Addresses: []place.Address{}, @@ -451,7 +464,7 @@ func TestPostChoosePeopleToNotifyPostcodeLookupInvalidPostcodeError(t *testing.T }). Return(nil) - err := ChoosePeopleToNotifyAddress(logger, template.Execute, addressClient, nil)(testAppData, w, r, &actor.DonorProvidedDetails{PeopleToNotify: actor.PeopleToNotify{{ID: "123"}}}) + err := ChoosePeopleToNotifyAddress(logger, template.Execute, addressClient, nil)(testAppData, w, r, &actor.DonorProvidedDetails{PeopleToNotify: actor.PeopleToNotify{{UID: uid}}}) resp := w.Result() assert.Nil(t, err) @@ -466,7 +479,8 @@ func TestPostChoosePeopleToNotifyPostcodeLookupValidPostcodeNoAddresses(t *testi "lookup-postcode": {"XYZ"}, } - r, _ := http.NewRequest(http.MethodPost, "/?id=123", strings.NewReader(f.Encode())) + uid := actoruid.New() + r, _ := http.NewRequest(http.MethodPost, "/?id="+uid.String(), strings.NewReader(f.Encode())) r.Header.Add("Content-Type", page.FormUrlEncoded) logger := newMockLogger(t) @@ -485,7 +499,7 @@ func TestPostChoosePeopleToNotifyPostcodeLookupValidPostcodeNoAddresses(t *testi LookupPostcode: "XYZ", FieldNames: form.FieldNames.Address, }, - ID: "123", + UID: uid, FullName: " ", ActorLabel: "personToNotify", Addresses: []place.Address{}, @@ -494,7 +508,7 @@ func TestPostChoosePeopleToNotifyPostcodeLookupValidPostcodeNoAddresses(t *testi }). Return(nil) - err := ChoosePeopleToNotifyAddress(logger, template.Execute, addressClient, nil)(testAppData, w, r, &actor.DonorProvidedDetails{PeopleToNotify: actor.PeopleToNotify{{ID: "123"}}}) + err := ChoosePeopleToNotifyAddress(logger, template.Execute, addressClient, nil)(testAppData, w, r, &actor.DonorProvidedDetails{PeopleToNotify: actor.PeopleToNotify{{UID: uid}}}) resp := w.Result() assert.Nil(t, err) @@ -506,12 +520,13 @@ func TestPostChoosePeopleToNotifyPostcodeLookupWhenValidationError(t *testing.T) form.FieldNames.Address.Action: {"postcode-lookup"}, } + uid := actoruid.New() w := httptest.NewRecorder() - r, _ := http.NewRequest(http.MethodPost, "/?id=123", strings.NewReader(f.Encode())) + r, _ := http.NewRequest(http.MethodPost, "/?id="+uid.String(), strings.NewReader(f.Encode())) r.Header.Add("Content-Type", page.FormUrlEncoded) personToNotify := actor.PersonToNotify{ - ID: "123", + UID: uid, Address: place.Address{}, } @@ -523,7 +538,7 @@ func TestPostChoosePeopleToNotifyPostcodeLookupWhenValidationError(t *testing.T) Action: "postcode", FieldNames: form.FieldNames.Address, }, - ID: "123", + UID: uid, FullName: " ", ActorLabel: "personToNotify", Errors: validation.With("lookup-postcode", validation.EnterError{Label: "aPostcode"}), @@ -543,8 +558,9 @@ func TestPostChoosePeopleToNotifyAddressReuse(t *testing.T) { form.FieldNames.Address.Action: {"reuse"}, } + uid := actoruid.New() w := httptest.NewRecorder() - r, _ := http.NewRequest(http.MethodPost, "/?id=123", strings.NewReader(f.Encode())) + r, _ := http.NewRequest(http.MethodPost, "/?id="+uid.String(), strings.NewReader(f.Encode())) r.Header.Add("Content-Type", page.FormUrlEncoded) template := newMockTemplate(t) @@ -555,7 +571,7 @@ func TestPostChoosePeopleToNotifyAddressReuse(t *testing.T) { Action: "reuse", FieldNames: form.FieldNames.Address, }, - ID: "123", + UID: uid, FullName: " ", ActorLabel: "personToNotify", Addresses: []place.Address{{Line1: "donor lane"}}, @@ -565,7 +581,7 @@ func TestPostChoosePeopleToNotifyAddressReuse(t *testing.T) { err := ChoosePeopleToNotifyAddress(nil, template.Execute, nil, nil)(testAppData, w, r, &actor.DonorProvidedDetails{ Donor: actor.Donor{Address: place.Address{Line1: "donor lane"}}, - PeopleToNotify: actor.PeopleToNotify{{ID: "123"}}, + PeopleToNotify: actor.PeopleToNotify{{UID: uid}}, }) resp := w.Result() @@ -579,8 +595,9 @@ func TestPostChoosePeopleToNotifyAddressReuseSelect(t *testing.T) { "select-address": {testAddress.Encode()}, } + uid := actoruid.New() w := httptest.NewRecorder() - r, _ := http.NewRequest(http.MethodPost, "/?id=123", strings.NewReader(f.Encode())) + r, _ := http.NewRequest(http.MethodPost, "/?id="+uid.String(), strings.NewReader(f.Encode())) r.Header.Add("Content-Type", page.FormUrlEncoded) donorStore := newMockDonorStore(t) @@ -588,7 +605,7 @@ func TestPostChoosePeopleToNotifyAddressReuseSelect(t *testing.T) { Put(r.Context(), &actor.DonorProvidedDetails{ LpaID: "lpa-id", PeopleToNotify: actor.PeopleToNotify{{ - ID: "123", + UID: uid, Address: place.Address{ Line1: "a", Line2: "b", @@ -602,7 +619,7 @@ func TestPostChoosePeopleToNotifyAddressReuseSelect(t *testing.T) { }). Return(nil) - err := ChoosePeopleToNotifyAddress(nil, nil, nil, donorStore)(testAppData, w, r, &actor.DonorProvidedDetails{LpaID: "lpa-id", PeopleToNotify: actor.PeopleToNotify{{ID: "123"}}}) + err := ChoosePeopleToNotifyAddress(nil, nil, nil, donorStore)(testAppData, w, r, &actor.DonorProvidedDetails{LpaID: "lpa-id", PeopleToNotify: actor.PeopleToNotify{{UID: uid}}}) resp := w.Result() assert.Nil(t, err) @@ -615,8 +632,9 @@ func TestPostChoosePeopleToNotifyAddressReuseSelectWhenValidationError(t *testin form.FieldNames.Address.Action: {"reuse-select"}, } + uid := actoruid.New() w := httptest.NewRecorder() - r, _ := http.NewRequest(http.MethodPost, "/?id=123", strings.NewReader(f.Encode())) + r, _ := http.NewRequest(http.MethodPost, "/?id="+uid.String(), strings.NewReader(f.Encode())) r.Header.Add("Content-Type", page.FormUrlEncoded) template := newMockTemplate(t) @@ -629,7 +647,7 @@ func TestPostChoosePeopleToNotifyAddressReuseSelectWhenValidationError(t *testin }, Addresses: []place.Address{{Line1: "donor lane"}}, Errors: validation.With("select-address", validation.SelectError{Label: "anAddressFromTheList"}), - ID: "123", + UID: uid, FullName: " ", ActorLabel: "personToNotify", TitleKeys: testTitleKeys, @@ -638,7 +656,7 @@ func TestPostChoosePeopleToNotifyAddressReuseSelectWhenValidationError(t *testin err := ChoosePeopleToNotifyAddress(nil, template.Execute, nil, nil)(testAppData, w, r, &actor.DonorProvidedDetails{ Donor: actor.Donor{Address: place.Address{Line1: "donor lane"}}, - PeopleToNotify: actor.PeopleToNotify{{ID: "123"}}, + PeopleToNotify: actor.PeopleToNotify{{UID: uid}}, }) resp := w.Result() diff --git a/internal/page/donor/choose_people_to_notify_summary_test.go b/internal/page/donor/choose_people_to_notify_summary_test.go index f5003c0ac6..feb0002eef 100644 --- a/internal/page/donor/choose_people_to_notify_summary_test.go +++ b/internal/page/donor/choose_people_to_notify_summary_test.go @@ -8,6 +8,7 @@ import ( "testing" "github.com/ministryofjustice/opg-modernising-lpa/internal/actor" + "github.com/ministryofjustice/opg-modernising-lpa/internal/actor/actoruid" "github.com/ministryofjustice/opg-modernising-lpa/internal/form" "github.com/ministryofjustice/opg-modernising-lpa/internal/page" "github.com/ministryofjustice/opg-modernising-lpa/internal/validation" @@ -69,7 +70,7 @@ func TestPostChoosePeopleToNotifySummaryAddPersonToNotify(t *testing.T) { r, _ := http.NewRequest(http.MethodPost, "/", strings.NewReader(f.Encode())) r.Header.Add("Content-Type", page.FormUrlEncoded) - err := ChoosePeopleToNotifySummary(nil)(testAppData, w, r, &actor.DonorProvidedDetails{LpaID: "lpa-id", PeopleToNotify: actor.PeopleToNotify{{ID: "123"}}}) + err := ChoosePeopleToNotifySummary(nil)(testAppData, w, r, &actor.DonorProvidedDetails{LpaID: "lpa-id", PeopleToNotify: actor.PeopleToNotify{{UID: actoruid.New()}}}) resp := w.Result() assert.Nil(t, err) @@ -88,7 +89,7 @@ func TestPostChoosePeopleToNotifySummaryNoFurtherPeopleToNotify(t *testing.T) { err := ChoosePeopleToNotifySummary(nil)(testAppData, w, r, &actor.DonorProvidedDetails{ LpaID: "lpa-id", - PeopleToNotify: actor.PeopleToNotify{{ID: "123"}}, + PeopleToNotify: actor.PeopleToNotify{{UID: actoruid.New()}}, Tasks: actor.DonorTasks{ YourDetails: actor.TaskCompleted, ChooseAttorneys: actor.TaskCompleted, diff --git a/internal/page/donor/choose_people_to_notify_test.go b/internal/page/donor/choose_people_to_notify_test.go index e6734f27a5..5b128ea03b 100644 --- a/internal/page/donor/choose_people_to_notify_test.go +++ b/internal/page/donor/choose_people_to_notify_test.go @@ -8,6 +8,7 @@ import ( "testing" "github.com/ministryofjustice/opg-modernising-lpa/internal/actor" + "github.com/ministryofjustice/opg-modernising-lpa/internal/actor/actoruid" "github.com/ministryofjustice/opg-modernising-lpa/internal/page" "github.com/ministryofjustice/opg-modernising-lpa/internal/validation" "github.com/stretchr/testify/assert" @@ -26,7 +27,7 @@ func TestGetChoosePeopleToNotify(t *testing.T) { }). Return(nil) - err := ChoosePeopleToNotify(template.Execute, nil, mockUuidString)(testAppData, w, r, &actor.DonorProvidedDetails{}) + err := ChoosePeopleToNotify(template.Execute, nil, testUIDFn)(testAppData, w, r, &actor.DonorProvidedDetails{}) resp := w.Result() assert.Nil(t, err) @@ -39,11 +40,11 @@ func TestGetChoosePeopleToNotifyFromStore(t *testing.T) { template := newMockTemplate(t) - err := ChoosePeopleToNotify(template.Execute, nil, mockUuidString)(testAppData, w, r, &actor.DonorProvidedDetails{ + err := ChoosePeopleToNotify(template.Execute, nil, testUIDFn)(testAppData, w, r, &actor.DonorProvidedDetails{ LpaID: "lpa-id", PeopleToNotify: actor.PeopleToNotify{ { - ID: "123", + UID: actoruid.New(), Address: testAddress, FirstNames: "Johnny", LastName: "Jones", @@ -69,7 +70,7 @@ func TestGetChoosePeopleToNotifyWhenTemplateErrors(t *testing.T) { }). Return(expectedError) - err := ChoosePeopleToNotify(template.Execute, nil, mockUuidString)(testAppData, w, r, &actor.DonorProvidedDetails{}) + err := ChoosePeopleToNotify(template.Execute, nil, testUIDFn)(testAppData, w, r, &actor.DonorProvidedDetails{}) resp := w.Result() assert.Equal(t, expectedError, err) @@ -80,7 +81,7 @@ func TestGetChoosePeopleToNotifyPeopleLimitReached(t *testing.T) { personToNotify := actor.PersonToNotify{ FirstNames: "John", LastName: "Doe", - ID: "123", + UID: actoruid.New(), } testcases := map[string]struct { @@ -115,7 +116,7 @@ func TestGetChoosePeopleToNotifyPeopleLimitReached(t *testing.T) { w := httptest.NewRecorder() r, _ := http.NewRequest(http.MethodGet, "/", nil) - err := ChoosePeopleToNotify(nil, nil, mockUuidString)(testAppData, w, r, &actor.DonorProvidedDetails{ + err := ChoosePeopleToNotify(nil, nil, testUIDFn)(testAppData, w, r, &actor.DonorProvidedDetails{ LpaID: "lpa-id", PeopleToNotify: tc.addedPeople, }) @@ -141,7 +142,7 @@ func TestPostChoosePeopleToNotifyPersonDoesNotExists(t *testing.T) { personToNotify: actor.PersonToNotify{ FirstNames: "John", LastName: "Doe", - ID: "123", + UID: testUID, }, }, "name warning ignored": { @@ -153,7 +154,7 @@ func TestPostChoosePeopleToNotifyPersonDoesNotExists(t *testing.T) { personToNotify: actor.PersonToNotify{ FirstNames: "Jane", LastName: "Doe", - ID: "123", + UID: testUID, }, }, } @@ -174,7 +175,7 @@ func TestPostChoosePeopleToNotifyPersonDoesNotExists(t *testing.T) { }). Return(nil) - err := ChoosePeopleToNotify(nil, donorStore, mockUuidString)(testAppData, w, r, &actor.DonorProvidedDetails{ + err := ChoosePeopleToNotify(nil, donorStore, testUIDFn)(testAppData, w, r, &actor.DonorProvidedDetails{ LpaID: "lpa-id", Donor: actor.Donor{FirstNames: "Jane", LastName: "Doe"}, }) @@ -182,7 +183,7 @@ func TestPostChoosePeopleToNotifyPersonDoesNotExists(t *testing.T) { assert.Nil(t, err) assert.Equal(t, http.StatusFound, resp.StatusCode) - assert.Equal(t, page.Paths.ChoosePeopleToNotifyAddress.Format("lpa-id")+"?id=123", resp.Header.Get("Location")) + assert.Equal(t, page.Paths.ChoosePeopleToNotifyAddress.Format("lpa-id")+"?id="+testUID.String(), resp.Header.Get("Location")) }) } } @@ -193,8 +194,9 @@ func TestPostChoosePeopleToNotifyPersonExists(t *testing.T) { "last-name": {"Dear"}, } + uid := actoruid.New() w := httptest.NewRecorder() - r, _ := http.NewRequest(http.MethodPost, "/?id=123", strings.NewReader(form.Encode())) + r, _ := http.NewRequest(http.MethodPost, "/?id="+uid.String(), strings.NewReader(form.Encode())) r.Header.Add("Content-Type", page.FormUrlEncoded) donorStore := newMockDonorStore(t) @@ -204,25 +206,25 @@ func TestPostChoosePeopleToNotifyPersonExists(t *testing.T) { PeopleToNotify: actor.PeopleToNotify{{ FirstNames: "Johnny", LastName: "Dear", - ID: "123", + UID: uid, }}, Tasks: actor.DonorTasks{PeopleToNotify: actor.TaskInProgress}, }). Return(nil) - err := ChoosePeopleToNotify(nil, donorStore, mockUuidString)(testAppData, w, r, &actor.DonorProvidedDetails{ + err := ChoosePeopleToNotify(nil, donorStore, testUIDFn)(testAppData, w, r, &actor.DonorProvidedDetails{ LpaID: "lpa-id", PeopleToNotify: actor.PeopleToNotify{{ FirstNames: "John", LastName: "Doe", - ID: "123", + UID: uid, }}, }) resp := w.Result() assert.Nil(t, err) assert.Equal(t, http.StatusFound, resp.StatusCode) - assert.Equal(t, page.Paths.ChoosePeopleToNotifyAddress.Format("lpa-id")+"?id=123", resp.Header.Get("Location")) + assert.Equal(t, page.Paths.ChoosePeopleToNotifyAddress.Format("lpa-id")+"?id="+uid.String(), resp.Header.Get("Location")) } func TestPostChoosePeopleToNotifyWhenInputRequired(t *testing.T) { @@ -275,7 +277,7 @@ func TestPostChoosePeopleToNotifyWhenInputRequired(t *testing.T) { })). Return(nil) - err := ChoosePeopleToNotify(template.Execute, nil, mockUuidString)(testAppData, w, r, &actor.DonorProvidedDetails{ + err := ChoosePeopleToNotify(template.Execute, nil, testUIDFn)(testAppData, w, r, &actor.DonorProvidedDetails{ Donor: actor.Donor{FirstNames: "Jane", LastName: "Doe"}, }) resp := w.Result() @@ -301,7 +303,7 @@ func TestPostChoosePeopleToNotifyWhenStoreErrors(t *testing.T) { Put(r.Context(), mock.Anything). Return(expectedError) - err := ChoosePeopleToNotify(nil, donorStore, mockUuidString)(testAppData, w, r, &actor.DonorProvidedDetails{}) + err := ChoosePeopleToNotify(nil, donorStore, testUIDFn)(testAppData, w, r, &actor.DonorProvidedDetails{}) assert.Equal(t, expectedError, err) } @@ -365,6 +367,7 @@ func TestChoosePeopleToNotifyFormValidate(t *testing.T) { } func TestPersonToNotifyMatches(t *testing.T) { + uid := actoruid.New() donor := &actor.DonorProvidedDetails{ Donor: actor.Donor{FirstNames: "a", LastName: "b"}, Attorneys: actor.Attorneys{Attorneys: []actor.Attorney{ @@ -378,22 +381,23 @@ func TestPersonToNotifyMatches(t *testing.T) { CertificateProvider: actor.CertificateProvider{FirstNames: "k", LastName: "l"}, PeopleToNotify: actor.PeopleToNotify{ {FirstNames: "m", LastName: "n"}, - {ID: "123", FirstNames: "o", LastName: "p"}, + {UID: uid, FirstNames: "o", LastName: "p"}, }, } - assert.Equal(t, actor.TypeNone, personToNotifyMatches(donor, "123", "x", "y")) - assert.Equal(t, actor.TypeDonor, personToNotifyMatches(donor, "123", "a", "b")) - assert.Equal(t, actor.TypeAttorney, personToNotifyMatches(donor, "123", "C", "D")) - assert.Equal(t, actor.TypeAttorney, personToNotifyMatches(donor, "123", "e", "f")) - assert.Equal(t, actor.TypeReplacementAttorney, personToNotifyMatches(donor, "123", "G", "H")) - assert.Equal(t, actor.TypeReplacementAttorney, personToNotifyMatches(donor, "123", "i", "j")) - assert.Equal(t, actor.TypeNone, personToNotifyMatches(donor, "123", "k", "L")) - assert.Equal(t, actor.TypePersonToNotify, personToNotifyMatches(donor, "123", "m", "n")) - assert.Equal(t, actor.TypeNone, personToNotifyMatches(donor, "123", "o", "p")) + assert.Equal(t, actor.TypeNone, personToNotifyMatches(donor, uid, "x", "y")) + assert.Equal(t, actor.TypeDonor, personToNotifyMatches(donor, uid, "a", "b")) + assert.Equal(t, actor.TypeAttorney, personToNotifyMatches(donor, uid, "C", "D")) + assert.Equal(t, actor.TypeAttorney, personToNotifyMatches(donor, uid, "e", "f")) + assert.Equal(t, actor.TypeReplacementAttorney, personToNotifyMatches(donor, uid, "G", "H")) + assert.Equal(t, actor.TypeReplacementAttorney, personToNotifyMatches(donor, uid, "i", "j")) + assert.Equal(t, actor.TypeNone, personToNotifyMatches(donor, uid, "k", "L")) + assert.Equal(t, actor.TypePersonToNotify, personToNotifyMatches(donor, uid, "m", "n")) + assert.Equal(t, actor.TypeNone, personToNotifyMatches(donor, uid, "o", "p")) } func TestPersonToNotifyMatchesEmptyNamesIgnored(t *testing.T) { + uid := actoruid.New() donor := &actor.DonorProvidedDetails{ Donor: actor.Donor{FirstNames: "", LastName: ""}, Attorneys: actor.Attorneys{Attorneys: []actor.Attorney{ @@ -405,9 +409,9 @@ func TestPersonToNotifyMatchesEmptyNamesIgnored(t *testing.T) { CertificateProvider: actor.CertificateProvider{FirstNames: "", LastName: ""}, PeopleToNotify: actor.PeopleToNotify{ {FirstNames: "", LastName: ""}, - {ID: "123", FirstNames: "", LastName: ""}, + {UID: uid, FirstNames: "", LastName: ""}, }, } - assert.Equal(t, actor.TypeNone, personToNotifyMatches(donor, "123", "", "")) + assert.Equal(t, actor.TypeNone, personToNotifyMatches(donor, uid, "", "")) } diff --git a/internal/page/donor/choose_replacement_attorneys.go b/internal/page/donor/choose_replacement_attorneys.go index ff3fb22fad..812ba25443 100644 --- a/internal/page/donor/choose_replacement_attorneys.go +++ b/internal/page/donor/choose_replacement_attorneys.go @@ -7,6 +7,7 @@ import ( "github.com/ministryofjustice/opg-go-common/template" "github.com/ministryofjustice/opg-modernising-lpa/internal/actor" + "github.com/ministryofjustice/opg-modernising-lpa/internal/actor/actoruid" "github.com/ministryofjustice/opg-modernising-lpa/internal/page" "github.com/ministryofjustice/opg-modernising-lpa/internal/validation" ) @@ -20,10 +21,10 @@ type chooseReplacementAttorneysData struct { NameWarning *actor.SameNameWarning } -func ChooseReplacementAttorneys(tmpl template.Template, donorStore DonorStore, uuidString func() string) Handler { +func ChooseReplacementAttorneys(tmpl template.Template, donorStore DonorStore, newUID func() actoruid.UID) Handler { return func(appData page.AppData, w http.ResponseWriter, r *http.Request, donor *actor.DonorProvidedDetails) error { addAnother := r.FormValue("addAnother") == "1" - attorney, attorneyFound := donor.ReplacementAttorneys.Get(r.URL.Query().Get("id")) + attorney, attorneyFound := donor.ReplacementAttorneys.Get(actoruid.FromRequest(r)) if r.Method == http.MethodGet && donor.ReplacementAttorneys.Len() > 0 && !attorneyFound && !addAnother { return page.Paths.ChooseReplacementAttorneysSummary.Redirect(w, r, appData, donor) @@ -47,7 +48,7 @@ func ChooseReplacementAttorneys(tmpl template.Template, donorStore DonorStore, u nameWarning := actor.NewSameNameWarning( actor.TypeReplacementAttorney, - replacementAttorneyMatches(donor, attorney.ID, data.Form.FirstNames, data.Form.LastName), + replacementAttorneyMatches(donor, attorney.UID, data.Form.FirstNames, data.Form.LastName), data.Form.FirstNames, data.Form.LastName, ) @@ -62,7 +63,7 @@ func ChooseReplacementAttorneys(tmpl template.Template, donorStore DonorStore, u if data.Errors.None() && data.DobWarning == "" && data.NameWarning == nil { if attorneyFound == false { - attorney = actor.Attorney{ID: uuidString()} + attorney = actor.Attorney{UID: newUID()} } attorney.FirstNames = data.Form.FirstNames @@ -78,7 +79,7 @@ func ChooseReplacementAttorneys(tmpl template.Template, donorStore DonorStore, u return err } - return page.Paths.ChooseReplacementAttorneysAddress.RedirectQuery(w, r, appData, donor, url.Values{"id": {attorney.ID}}) + return page.Paths.ChooseReplacementAttorneysAddress.RedirectQuery(w, r, appData, donor, url.Values{"id": {attorney.UID.String()}}) } } @@ -90,7 +91,7 @@ func ChooseReplacementAttorneys(tmpl template.Template, donorStore DonorStore, u } } -func replacementAttorneyMatches(donor *actor.DonorProvidedDetails, id, firstNames, lastName string) actor.Type { +func replacementAttorneyMatches(donor *actor.DonorProvidedDetails, uid actoruid.UID, firstNames, lastName string) actor.Type { if firstNames == "" && lastName == "" { return actor.TypeNone } @@ -106,7 +107,7 @@ func replacementAttorneyMatches(donor *actor.DonorProvidedDetails, id, firstName } for _, attorney := range donor.ReplacementAttorneys.Attorneys { - if attorney.ID != id && strings.EqualFold(attorney.FirstNames, firstNames) && strings.EqualFold(attorney.LastName, lastName) { + if attorney.UID != uid && strings.EqualFold(attorney.FirstNames, firstNames) && strings.EqualFold(attorney.LastName, lastName) { return actor.TypeReplacementAttorney } } diff --git a/internal/page/donor/choose_replacement_attorneys_address.go b/internal/page/donor/choose_replacement_attorneys_address.go index df2397e128..ecac1d61c8 100644 --- a/internal/page/donor/choose_replacement_attorneys_address.go +++ b/internal/page/donor/choose_replacement_attorneys_address.go @@ -5,6 +5,7 @@ import ( "github.com/ministryofjustice/opg-go-common/template" "github.com/ministryofjustice/opg-modernising-lpa/internal/actor" + "github.com/ministryofjustice/opg-modernising-lpa/internal/actor/actoruid" "github.com/ministryofjustice/opg-modernising-lpa/internal/form" "github.com/ministryofjustice/opg-modernising-lpa/internal/page" "github.com/ministryofjustice/opg-modernising-lpa/internal/place" @@ -12,14 +13,13 @@ import ( func ChooseReplacementAttorneysAddress(logger Logger, tmpl template.Template, addressClient AddressClient, donorStore DonorStore) Handler { return func(appData page.AppData, w http.ResponseWriter, r *http.Request, donor *actor.DonorProvidedDetails) error { - attorneyId := r.FormValue("id") - attorney, _ := donor.ReplacementAttorneys.Get(attorneyId) + attorney, _ := donor.ReplacementAttorneys.Get(actoruid.FromRequest(r)) data := newChooseAddressData( appData, "replacementAttorney", attorney.FullName(), - attorney.ID, + attorney.UID, true, ) diff --git a/internal/page/donor/choose_replacement_attorneys_address_test.go b/internal/page/donor/choose_replacement_attorneys_address_test.go index 710a0b4820..59ccd2d4af 100644 --- a/internal/page/donor/choose_replacement_attorneys_address_test.go +++ b/internal/page/donor/choose_replacement_attorneys_address_test.go @@ -8,6 +8,7 @@ import ( "testing" "github.com/ministryofjustice/opg-modernising-lpa/internal/actor" + "github.com/ministryofjustice/opg-modernising-lpa/internal/actor/actoruid" "github.com/ministryofjustice/opg-modernising-lpa/internal/form" "github.com/ministryofjustice/opg-modernising-lpa/internal/page" "github.com/ministryofjustice/opg-modernising-lpa/internal/place" @@ -17,11 +18,12 @@ import ( ) func TestGetChooseReplacementAttorneysAddress(t *testing.T) { + uid := actoruid.New() w := httptest.NewRecorder() - r, _ := http.NewRequest(http.MethodGet, "/?id=123", nil) + r, _ := http.NewRequest(http.MethodGet, "/?id="+uid.String(), nil) ra := actor.Attorney{ - ID: "123", + UID: uid, FirstNames: "John", LastName: "Smith", Address: place.Address{}, @@ -32,7 +34,7 @@ func TestGetChooseReplacementAttorneysAddress(t *testing.T) { Execute(w, &chooseAddressData{ App: testAppData, Form: form.NewAddressForm(), - ID: "123", + UID: uid, FullName: "John Smith", CanSkip: true, ActorLabel: "replacementAttorney", @@ -48,11 +50,12 @@ func TestGetChooseReplacementAttorneysAddress(t *testing.T) { } func TestGetChooseReplacementAttorneysAddressFromStore(t *testing.T) { + uid := actoruid.New() w := httptest.NewRecorder() - r, _ := http.NewRequest(http.MethodGet, "/?id=123", nil) + r, _ := http.NewRequest(http.MethodGet, "/?id="+uid.String(), nil) ra := actor.Attorney{ - ID: "123", + UID: uid, Address: testAddress, } @@ -65,7 +68,7 @@ func TestGetChooseReplacementAttorneysAddressFromStore(t *testing.T) { Address: &testAddress, FieldNames: form.FieldNames.Address, }, - ID: "123", + UID: uid, FullName: " ", CanSkip: true, ActorLabel: "replacementAttorney", @@ -81,11 +84,12 @@ func TestGetChooseReplacementAttorneysAddressFromStore(t *testing.T) { } func TestGetChooseReplacementAttorneysAddressManual(t *testing.T) { + uid := actoruid.New() w := httptest.NewRecorder() - r, _ := http.NewRequest(http.MethodGet, "/?action=manual&id=123", nil) + r, _ := http.NewRequest(http.MethodGet, "/?action=manual&id="+uid.String(), nil) ra := actor.Attorney{ - ID: "123", + UID: uid, Address: testAddress, } @@ -98,7 +102,7 @@ func TestGetChooseReplacementAttorneysAddressManual(t *testing.T) { Address: &place.Address{}, FieldNames: form.FieldNames.Address, }, - ID: "123", + UID: uid, FullName: " ", CanSkip: true, ActorLabel: "replacementAttorney", @@ -114,11 +118,12 @@ func TestGetChooseReplacementAttorneysAddressManual(t *testing.T) { } func TestGetChooseReplacementAttorneysAddressWhenTemplateErrors(t *testing.T) { + uid := actoruid.New() w := httptest.NewRecorder() - r, _ := http.NewRequest(http.MethodGet, "/?id=123", nil) + r, _ := http.NewRequest(http.MethodGet, "/?id="+uid.String(), nil) ra := actor.Attorney{ - ID: "123", + UID: uid, Address: place.Address{}, } @@ -127,7 +132,7 @@ func TestGetChooseReplacementAttorneysAddressWhenTemplateErrors(t *testing.T) { Execute(w, &chooseAddressData{ App: testAppData, Form: form.NewAddressForm(), - ID: "123", + UID: uid, FullName: " ", CanSkip: true, ActorLabel: "replacementAttorney", @@ -152,15 +157,16 @@ func TestPostChooseReplacementAttorneysAddressSkip(t *testing.T) { form.FieldNames.Address.Postcode: {"e"}, } + uid := actoruid.New() w := httptest.NewRecorder() - r, _ := http.NewRequest(http.MethodPost, "/?id=123", strings.NewReader(f.Encode())) + r, _ := http.NewRequest(http.MethodPost, "/?id="+uid.String(), strings.NewReader(f.Encode())) r.Header.Add("Content-Type", page.FormUrlEncoded) donorStore := newMockDonorStore(t) donorStore.EXPECT(). Put(r.Context(), &actor.DonorProvidedDetails{ LpaID: "lpa-id", - ReplacementAttorneys: actor.Attorneys{Attorneys: []actor.Attorney{{ID: "123", FirstNames: "a", Email: "a"}}}, + ReplacementAttorneys: actor.Attorneys{Attorneys: []actor.Attorney{{UID: uid, FirstNames: "a", Email: "a"}}}, Tasks: actor.DonorTasks{ChooseReplacementAttorneys: actor.TaskCompleted}, }). Return(nil) @@ -168,7 +174,7 @@ func TestPostChooseReplacementAttorneysAddressSkip(t *testing.T) { err := ChooseReplacementAttorneysAddress(nil, nil, nil, donorStore)(testAppData, w, r, &actor.DonorProvidedDetails{ LpaID: "lpa-id", ReplacementAttorneys: actor.Attorneys{Attorneys: []actor.Attorney{{ - ID: "123", + UID: uid, FirstNames: "a", Email: "a", Address: place.Address{Line1: "abc"}, @@ -191,8 +197,9 @@ func TestPostChooseReplacementAttorneysAddressManual(t *testing.T) { form.FieldNames.Address.Postcode: {"e"}, } + uid := actoruid.New() w := httptest.NewRecorder() - r, _ := http.NewRequest(http.MethodPost, "/?id=123", strings.NewReader(f.Encode())) + r, _ := http.NewRequest(http.MethodPost, "/?id="+uid.String(), strings.NewReader(f.Encode())) r.Header.Add("Content-Type", page.FormUrlEncoded) donorStore := newMockDonorStore(t) @@ -200,7 +207,7 @@ func TestPostChooseReplacementAttorneysAddressManual(t *testing.T) { Put(r.Context(), &actor.DonorProvidedDetails{ LpaID: "lpa-id", ReplacementAttorneys: actor.Attorneys{Attorneys: []actor.Attorney{{ - ID: "123", + UID: uid, FirstNames: "a", Address: testAddress, }}}, @@ -210,7 +217,7 @@ func TestPostChooseReplacementAttorneysAddressManual(t *testing.T) { err := ChooseReplacementAttorneysAddress(nil, nil, nil, donorStore)(testAppData, w, r, &actor.DonorProvidedDetails{ LpaID: "lpa-id", - ReplacementAttorneys: actor.Attorneys{Attorneys: []actor.Attorney{{ID: "123", FirstNames: "a"}}}, + ReplacementAttorneys: actor.Attorneys{Attorneys: []actor.Attorney{{UID: uid, FirstNames: "a"}}}, }) resp := w.Result() @@ -229,8 +236,9 @@ func TestPostChooseReplacementAttorneysAddressManualWhenStoreErrors(t *testing.T form.FieldNames.Address.Postcode: {"e"}, } + uid := actoruid.New() w := httptest.NewRecorder() - r, _ := http.NewRequest(http.MethodPost, "/?id=123", strings.NewReader(f.Encode())) + r, _ := http.NewRequest(http.MethodPost, "/?id="+uid.String(), strings.NewReader(f.Encode())) r.Header.Add("Content-Type", page.FormUrlEncoded) donorStore := newMockDonorStore(t) @@ -238,7 +246,7 @@ func TestPostChooseReplacementAttorneysAddressManualWhenStoreErrors(t *testing.T Put(r.Context(), mock.Anything). Return(expectedError) - err := ChooseReplacementAttorneysAddress(nil, nil, nil, donorStore)(testAppData, w, r, &actor.DonorProvidedDetails{ReplacementAttorneys: actor.Attorneys{Attorneys: []actor.Attorney{{ID: "123"}}}}) + err := ChooseReplacementAttorneysAddress(nil, nil, nil, donorStore)(testAppData, w, r, &actor.DonorProvidedDetails{ReplacementAttorneys: actor.Attorneys{Attorneys: []actor.Attorney{{UID: uid}}}}) assert.Equal(t, expectedError, err) } @@ -253,8 +261,9 @@ func TestPostChooseReplacementAttorneysAddressManualFromStore(t *testing.T) { form.FieldNames.Address.Postcode: {"e"}, } + uid := actoruid.New() w := httptest.NewRecorder() - r, _ := http.NewRequest(http.MethodPost, "/?id=123", strings.NewReader(f.Encode())) + r, _ := http.NewRequest(http.MethodPost, "/?id="+uid.String(), strings.NewReader(f.Encode())) r.Header.Add("Content-Type", page.FormUrlEncoded) donorStore := newMockDonorStore(t) @@ -262,7 +271,7 @@ func TestPostChooseReplacementAttorneysAddressManualFromStore(t *testing.T) { Put(r.Context(), &actor.DonorProvidedDetails{ LpaID: "lpa-id", ReplacementAttorneys: actor.Attorneys{Attorneys: []actor.Attorney{{ - ID: "123", + UID: uid, FirstNames: "John", Address: testAddress, }}}, @@ -273,7 +282,7 @@ func TestPostChooseReplacementAttorneysAddressManualFromStore(t *testing.T) { err := ChooseReplacementAttorneysAddress(nil, nil, nil, donorStore)(testAppData, w, r, &actor.DonorProvidedDetails{ LpaID: "lpa-id", ReplacementAttorneys: actor.Attorneys{Attorneys: []actor.Attorney{{ - ID: "123", + UID: uid, FirstNames: "John", Address: place.Address{Line1: "abc"}, }}}, @@ -293,8 +302,9 @@ func TestPostChooseReplacementAttorneysAddressManualWhenValidationError(t *testi form.FieldNames.Address.Postcode: {"d"}, } + uid := actoruid.New() w := httptest.NewRecorder() - r, _ := http.NewRequest(http.MethodPost, "/?id=123", strings.NewReader(f.Encode())) + r, _ := http.NewRequest(http.MethodPost, "/?id="+uid.String(), strings.NewReader(f.Encode())) r.Header.Add("Content-Type", page.FormUrlEncoded) invalidAddress := &place.Address{ @@ -314,7 +324,7 @@ func TestPostChooseReplacementAttorneysAddressManualWhenValidationError(t *testi FieldNames: form.FieldNames.Address, }, Errors: validation.With(form.FieldNames.Address.Line1, validation.EnterError{Label: "addressLine1"}), - ID: "123", + UID: uid, FullName: " ", CanSkip: true, ActorLabel: "replacementAttorney", @@ -322,7 +332,7 @@ func TestPostChooseReplacementAttorneysAddressManualWhenValidationError(t *testi }). Return(nil) - err := ChooseReplacementAttorneysAddress(nil, template.Execute, nil, nil)(testAppData, w, r, &actor.DonorProvidedDetails{ReplacementAttorneys: actor.Attorneys{Attorneys: []actor.Attorney{{ID: "123"}}}}) + err := ChooseReplacementAttorneysAddress(nil, template.Execute, nil, nil)(testAppData, w, r, &actor.DonorProvidedDetails{ReplacementAttorneys: actor.Attorneys{Attorneys: []actor.Attorney{{UID: uid}}}}) resp := w.Result() assert.Nil(t, err) @@ -336,8 +346,9 @@ func TestPostChooseReplacementAttorneysPostcodeSelect(t *testing.T) { "select-address": {testAddress.Encode()}, } + uid := actoruid.New() w := httptest.NewRecorder() - r, _ := http.NewRequest(http.MethodPost, "/?id=123", strings.NewReader(f.Encode())) + r, _ := http.NewRequest(http.MethodPost, "/?id="+uid.String(), strings.NewReader(f.Encode())) r.Header.Add("Content-Type", page.FormUrlEncoded) template := newMockTemplate(t) @@ -350,7 +361,7 @@ func TestPostChooseReplacementAttorneysPostcodeSelect(t *testing.T) { Address: &testAddress, FieldNames: form.FieldNames.Address, }, - ID: "123", + UID: uid, FullName: " ", CanSkip: true, ActorLabel: "replacementAttorney", @@ -358,7 +369,7 @@ func TestPostChooseReplacementAttorneysPostcodeSelect(t *testing.T) { }). Return(nil) - err := ChooseReplacementAttorneysAddress(nil, template.Execute, nil, nil)(testAppData, w, r, &actor.DonorProvidedDetails{ReplacementAttorneys: actor.Attorneys{Attorneys: []actor.Attorney{{ID: "123"}}}}) + err := ChooseReplacementAttorneysAddress(nil, template.Execute, nil, nil)(testAppData, w, r, &actor.DonorProvidedDetails{ReplacementAttorneys: actor.Attorneys{Attorneys: []actor.Attorney{{UID: uid}}}}) resp := w.Result() assert.Nil(t, err) @@ -371,8 +382,9 @@ func TestPostChooseReplacementAttorneysPostcodeSelectWhenValidationError(t *test "lookup-postcode": {"NG1"}, } + uid := actoruid.New() w := httptest.NewRecorder() - r, _ := http.NewRequest(http.MethodPost, "/?id=123", strings.NewReader(f.Encode())) + r, _ := http.NewRequest(http.MethodPost, "/?id="+uid.String(), strings.NewReader(f.Encode())) r.Header.Add("Content-Type", page.FormUrlEncoded) addresses := []place.Address{ @@ -395,7 +407,7 @@ func TestPostChooseReplacementAttorneysPostcodeSelectWhenValidationError(t *test }, Addresses: addresses, Errors: validation.With("select-address", validation.SelectError{Label: "anAddressFromTheList"}), - ID: "123", + UID: uid, FullName: " ", CanSkip: true, ActorLabel: "replacementAttorney", @@ -403,7 +415,7 @@ func TestPostChooseReplacementAttorneysPostcodeSelectWhenValidationError(t *test }). Return(nil) - err := ChooseReplacementAttorneysAddress(nil, template.Execute, addressClient, nil)(testAppData, w, r, &actor.DonorProvidedDetails{ReplacementAttorneys: actor.Attorneys{Attorneys: []actor.Attorney{{ID: "123"}}}}) + err := ChooseReplacementAttorneysAddress(nil, template.Execute, addressClient, nil)(testAppData, w, r, &actor.DonorProvidedDetails{ReplacementAttorneys: actor.Attorneys{Attorneys: []actor.Attorney{{UID: uid}}}}) resp := w.Result() assert.Nil(t, err) @@ -416,8 +428,9 @@ func TestPostChooseReplacementAttorneysPostcodeLookup(t *testing.T) { "lookup-postcode": {"NG1"}, } + uid := actoruid.New() w := httptest.NewRecorder() - r, _ := http.NewRequest(http.MethodPost, "/?id=123", strings.NewReader(f.Encode())) + r, _ := http.NewRequest(http.MethodPost, "/?id="+uid.String(), strings.NewReader(f.Encode())) r.Header.Add("Content-Type", page.FormUrlEncoded) addresses := []place.Address{ @@ -439,7 +452,7 @@ func TestPostChooseReplacementAttorneysPostcodeLookup(t *testing.T) { FieldNames: form.FieldNames.Address, }, Addresses: addresses, - ID: "123", + UID: uid, FullName: " ", CanSkip: true, ActorLabel: "replacementAttorney", @@ -447,7 +460,7 @@ func TestPostChooseReplacementAttorneysPostcodeLookup(t *testing.T) { }). Return(nil) - err := ChooseReplacementAttorneysAddress(nil, template.Execute, addressClient, nil)(testAppData, w, r, &actor.DonorProvidedDetails{ReplacementAttorneys: actor.Attorneys{Attorneys: []actor.Attorney{{ID: "123"}}}}) + err := ChooseReplacementAttorneysAddress(nil, template.Execute, addressClient, nil)(testAppData, w, r, &actor.DonorProvidedDetails{ReplacementAttorneys: actor.Attorneys{Attorneys: []actor.Attorney{{UID: uid}}}}) resp := w.Result() assert.Nil(t, err) @@ -460,8 +473,9 @@ func TestPostChooseReplacementAttorneysPostcodeLookupError(t *testing.T) { "lookup-postcode": {"NG1"}, } + uid := actoruid.New() w := httptest.NewRecorder() - r, _ := http.NewRequest(http.MethodPost, "/?id=123", strings.NewReader(f.Encode())) + r, _ := http.NewRequest(http.MethodPost, "/?id="+uid.String(), strings.NewReader(f.Encode())) r.Header.Add("Content-Type", page.FormUrlEncoded) logger := newMockLogger(t) @@ -484,7 +498,7 @@ func TestPostChooseReplacementAttorneysPostcodeLookupError(t *testing.T) { }, Addresses: []place.Address{}, Errors: validation.With("lookup-postcode", validation.CustomError{Label: "couldNotLookupPostcode"}), - ID: "123", + UID: uid, FullName: " ", CanSkip: true, ActorLabel: "replacementAttorney", @@ -492,7 +506,7 @@ func TestPostChooseReplacementAttorneysPostcodeLookupError(t *testing.T) { }). Return(nil) - err := ChooseReplacementAttorneysAddress(logger, template.Execute, addressClient, nil)(testAppData, w, r, &actor.DonorProvidedDetails{ReplacementAttorneys: actor.Attorneys{Attorneys: []actor.Attorney{{ID: "123"}}}}) + err := ChooseReplacementAttorneysAddress(logger, template.Execute, addressClient, nil)(testAppData, w, r, &actor.DonorProvidedDetails{ReplacementAttorneys: actor.Attorneys{Attorneys: []actor.Attorney{{UID: uid}}}}) resp := w.Result() assert.Nil(t, err) @@ -500,6 +514,7 @@ func TestPostChooseReplacementAttorneysPostcodeLookupError(t *testing.T) { } func TestPostChooseReplacementAttorneysPostcodeLookupInvalidPostcodeError(t *testing.T) { + uid := actoruid.New() w := httptest.NewRecorder() invalidPostcodeErr := place.BadRequestError{ Statuscode: 400, @@ -511,7 +526,7 @@ func TestPostChooseReplacementAttorneysPostcodeLookupInvalidPostcodeError(t *tes "lookup-postcode": {"XYZ"}, } - r, _ := http.NewRequest(http.MethodPost, "/?id=123", strings.NewReader(f.Encode())) + r, _ := http.NewRequest(http.MethodPost, "/?id="+uid.String(), strings.NewReader(f.Encode())) r.Header.Add("Content-Type", page.FormUrlEncoded) logger := newMockLogger(t) @@ -534,7 +549,7 @@ func TestPostChooseReplacementAttorneysPostcodeLookupInvalidPostcodeError(t *tes }, Addresses: []place.Address{}, Errors: validation.With("lookup-postcode", validation.EnterError{Label: "invalidPostcode"}), - ID: "123", + UID: uid, FullName: " ", CanSkip: true, ActorLabel: "replacementAttorney", @@ -543,7 +558,7 @@ func TestPostChooseReplacementAttorneysPostcodeLookupInvalidPostcodeError(t *tes Return(nil) err := ChooseReplacementAttorneysAddress(logger, template.Execute, addressClient, nil)(testAppData, w, r, &actor.DonorProvidedDetails{ - ReplacementAttorneys: actor.Attorneys{Attorneys: []actor.Attorney{{ID: "123"}}}, + ReplacementAttorneys: actor.Attorneys{Attorneys: []actor.Attorney{{UID: uid}}}, }) resp := w.Result() @@ -552,6 +567,7 @@ func TestPostChooseReplacementAttorneysPostcodeLookupInvalidPostcodeError(t *tes } func TestPostChooseReplacementAttorneysPostcodeLookupValidPostcodeNoAddresses(t *testing.T) { + uid := actoruid.New() w := httptest.NewRecorder() f := url.Values{ @@ -559,7 +575,7 @@ func TestPostChooseReplacementAttorneysPostcodeLookupValidPostcodeNoAddresses(t "lookup-postcode": {"XYZ"}, } - r, _ := http.NewRequest(http.MethodPost, "/?id=123", strings.NewReader(f.Encode())) + r, _ := http.NewRequest(http.MethodPost, "/?id="+uid.String(), strings.NewReader(f.Encode())) r.Header.Add("Content-Type", page.FormUrlEncoded) logger := newMockLogger(t) @@ -580,7 +596,7 @@ func TestPostChooseReplacementAttorneysPostcodeLookupValidPostcodeNoAddresses(t }, Addresses: []place.Address{}, Errors: validation.With("lookup-postcode", validation.CustomError{Label: "noAddressesFound"}), - ID: "123", + UID: uid, FullName: " ", CanSkip: true, ActorLabel: "replacementAttorney", @@ -589,7 +605,7 @@ func TestPostChooseReplacementAttorneysPostcodeLookupValidPostcodeNoAddresses(t Return(nil) err := ChooseReplacementAttorneysAddress(logger, template.Execute, addressClient, nil)(testAppData, w, r, &actor.DonorProvidedDetails{ - ReplacementAttorneys: actor.Attorneys{Attorneys: []actor.Attorney{{ID: "123"}}}, + ReplacementAttorneys: actor.Attorneys{Attorneys: []actor.Attorney{{UID: uid}}}, }) resp := w.Result() @@ -602,8 +618,9 @@ func TestPostChooseReplacementAttorneysPostcodeLookupWhenValidationError(t *test form.FieldNames.Address.Action: {"postcode-lookup"}, } + uid := actoruid.New() w := httptest.NewRecorder() - r, _ := http.NewRequest(http.MethodPost, "/?id=123", strings.NewReader(f.Encode())) + r, _ := http.NewRequest(http.MethodPost, "/?id="+uid.String(), strings.NewReader(f.Encode())) r.Header.Add("Content-Type", page.FormUrlEncoded) template := newMockTemplate(t) @@ -615,7 +632,7 @@ func TestPostChooseReplacementAttorneysPostcodeLookupWhenValidationError(t *test FieldNames: form.FieldNames.Address, }, Errors: validation.With("lookup-postcode", validation.EnterError{Label: "aPostcode"}), - ID: "123", + UID: uid, FullName: " ", CanSkip: true, ActorLabel: "replacementAttorney", @@ -623,7 +640,7 @@ func TestPostChooseReplacementAttorneysPostcodeLookupWhenValidationError(t *test }). Return(nil) - err := ChooseReplacementAttorneysAddress(nil, template.Execute, nil, nil)(testAppData, w, r, &actor.DonorProvidedDetails{ReplacementAttorneys: actor.Attorneys{Attorneys: []actor.Attorney{{ID: "123"}}}}) + err := ChooseReplacementAttorneysAddress(nil, template.Execute, nil, nil)(testAppData, w, r, &actor.DonorProvidedDetails{ReplacementAttorneys: actor.Attorneys{Attorneys: []actor.Attorney{{UID: uid}}}}) resp := w.Result() assert.Nil(t, err) @@ -635,8 +652,9 @@ func TestPostChooseReplacementAttorneysAddressReuse(t *testing.T) { form.FieldNames.Address.Action: {"reuse"}, } + uid := actoruid.New() w := httptest.NewRecorder() - r, _ := http.NewRequest(http.MethodPost, "/?id=123", strings.NewReader(f.Encode())) + r, _ := http.NewRequest(http.MethodPost, "/?id="+uid.String(), strings.NewReader(f.Encode())) r.Header.Add("Content-Type", page.FormUrlEncoded) template := newMockTemplate(t) @@ -647,7 +665,7 @@ func TestPostChooseReplacementAttorneysAddressReuse(t *testing.T) { Action: "reuse", FieldNames: form.FieldNames.Address, }, - ID: "123", + UID: uid, FullName: " ", CanSkip: true, ActorLabel: "replacementAttorney", @@ -658,7 +676,7 @@ func TestPostChooseReplacementAttorneysAddressReuse(t *testing.T) { err := ChooseReplacementAttorneysAddress(nil, template.Execute, nil, nil)(testAppData, w, r, &actor.DonorProvidedDetails{ Donor: actor.Donor{Address: place.Address{Line1: "donor lane"}}, - ReplacementAttorneys: actor.Attorneys{Attorneys: []actor.Attorney{{ID: "123"}}}, + ReplacementAttorneys: actor.Attorneys{Attorneys: []actor.Attorney{{UID: uid}}}, }) resp := w.Result() @@ -672,12 +690,13 @@ func TestPostChooseReplacementAttorneysAddressReuseSelect(t *testing.T) { "select-address": {testAddress.Encode()}, } + uid := actoruid.New() w := httptest.NewRecorder() - r, _ := http.NewRequest(http.MethodPost, "/?id=123", strings.NewReader(f.Encode())) + r, _ := http.NewRequest(http.MethodPost, "/?id="+uid.String(), strings.NewReader(f.Encode())) r.Header.Add("Content-Type", page.FormUrlEncoded) updatedAttorney := actor.Attorney{ - ID: "123", + UID: uid, Address: place.Address{ Line1: "a", Line2: "b", @@ -699,7 +718,7 @@ func TestPostChooseReplacementAttorneysAddressReuseSelect(t *testing.T) { err := ChooseReplacementAttorneysAddress(nil, nil, nil, donorStore)(testAppData, w, r, &actor.DonorProvidedDetails{ LpaID: "lpa-id", - ReplacementAttorneys: actor.Attorneys{Attorneys: []actor.Attorney{{ID: "123"}}}, + ReplacementAttorneys: actor.Attorneys{Attorneys: []actor.Attorney{{UID: uid}}}, }) resp := w.Result() @@ -713,8 +732,9 @@ func TestPostChooseReplacementAttorneysAddressReuseSelectWhenValidationError(t * form.FieldNames.Address.Action: {"reuse-select"}, } + uid := actoruid.New() w := httptest.NewRecorder() - r, _ := http.NewRequest(http.MethodPost, "/?id=123", strings.NewReader(f.Encode())) + r, _ := http.NewRequest(http.MethodPost, "/?id="+uid.String(), strings.NewReader(f.Encode())) r.Header.Add("Content-Type", page.FormUrlEncoded) template := newMockTemplate(t) @@ -727,7 +747,7 @@ func TestPostChooseReplacementAttorneysAddressReuseSelectWhenValidationError(t * }, Addresses: []place.Address{{Line1: "donor lane"}}, Errors: validation.With("select-address", validation.SelectError{Label: "anAddressFromTheList"}), - ID: "123", + UID: uid, FullName: " ", CanSkip: true, ActorLabel: "replacementAttorney", @@ -737,7 +757,7 @@ func TestPostChooseReplacementAttorneysAddressReuseSelectWhenValidationError(t * err := ChooseReplacementAttorneysAddress(nil, template.Execute, nil, nil)(testAppData, w, r, &actor.DonorProvidedDetails{ Donor: actor.Donor{Address: place.Address{Line1: "donor lane"}}, - ReplacementAttorneys: actor.Attorneys{Attorneys: []actor.Attorney{{ID: "123"}}}, + ReplacementAttorneys: actor.Attorneys{Attorneys: []actor.Attorney{{UID: uid}}}, }) resp := w.Result() diff --git a/internal/page/donor/choose_replacement_attorneys_test.go b/internal/page/donor/choose_replacement_attorneys_test.go index d9c42118ea..f3158d5b87 100644 --- a/internal/page/donor/choose_replacement_attorneys_test.go +++ b/internal/page/donor/choose_replacement_attorneys_test.go @@ -10,6 +10,7 @@ import ( "time" "github.com/ministryofjustice/opg-modernising-lpa/internal/actor" + "github.com/ministryofjustice/opg-modernising-lpa/internal/actor/actoruid" "github.com/ministryofjustice/opg-modernising-lpa/internal/date" "github.com/ministryofjustice/opg-modernising-lpa/internal/page" "github.com/ministryofjustice/opg-modernising-lpa/internal/place" @@ -31,7 +32,7 @@ func TestGetChooseReplacementAttorneys(t *testing.T) { }). Return(nil) - err := ChooseReplacementAttorneys(template.Execute, nil, mockUuidString)(testAppData, w, r, &actor.DonorProvidedDetails{}) + err := ChooseReplacementAttorneys(template.Execute, nil, testUIDFn)(testAppData, w, r, &actor.DonorProvidedDetails{}) resp := w.Result() assert.Nil(t, err) @@ -42,7 +43,7 @@ func TestGetChooseReplacementAttorneysFromStore(t *testing.T) { w := httptest.NewRecorder() r, _ := http.NewRequest(http.MethodGet, "/", nil) - err := ChooseReplacementAttorneys(nil, nil, mockUuidString)(testAppData, w, r, &actor.DonorProvidedDetails{LpaID: "lpa-id", ReplacementAttorneys: actor.Attorneys{Attorneys: []actor.Attorney{{FirstNames: "John", ID: "1"}}}}) + err := ChooseReplacementAttorneys(nil, nil, testUIDFn)(testAppData, w, r, &actor.DonorProvidedDetails{LpaID: "lpa-id", ReplacementAttorneys: actor.Attorneys{Attorneys: []actor.Attorney{{FirstNames: "John", UID: actoruid.New()}}}}) resp := w.Result() assert.Nil(t, err) @@ -51,8 +52,9 @@ func TestGetChooseReplacementAttorneysFromStore(t *testing.T) { } func TestGetChooseReplacementAttorneysDobWarningIsAlwaysShown(t *testing.T) { + uid := actoruid.New() w := httptest.NewRecorder() - r, _ := http.NewRequest(http.MethodGet, "/?id=1", nil) + r, _ := http.NewRequest(http.MethodGet, "/?id="+uid.String(), nil) template := newMockTemplate(t) template.EXPECT(). @@ -60,7 +62,7 @@ func TestGetChooseReplacementAttorneysDobWarningIsAlwaysShown(t *testing.T) { App: testAppData, Donor: &actor.DonorProvidedDetails{ ReplacementAttorneys: actor.Attorneys{Attorneys: []actor.Attorney{ - {ID: "1", DateOfBirth: date.New("1900", "1", "2")}, + {UID: uid, DateOfBirth: date.New("1900", "1", "2")}, }}, }, Form: &chooseAttorneysForm{ @@ -70,10 +72,10 @@ func TestGetChooseReplacementAttorneysDobWarningIsAlwaysShown(t *testing.T) { }). Return(nil) - err := ChooseReplacementAttorneys(template.Execute, nil, mockUuidString)(testAppData, w, r, &actor.DonorProvidedDetails{ + err := ChooseReplacementAttorneys(template.Execute, nil, testUIDFn)(testAppData, w, r, &actor.DonorProvidedDetails{ Donor: actor.Donor{}, ReplacementAttorneys: actor.Attorneys{Attorneys: []actor.Attorney{ - {ID: "1", DateOfBirth: date.New("1900", "1", "2")}, + {UID: uid, DateOfBirth: date.New("1900", "1", "2")}, }}, }) resp := w.Result() @@ -91,7 +93,7 @@ func TestGetChooseReplacementAttorneysWhenTemplateErrors(t *testing.T) { Execute(w, mock.Anything). Return(expectedError) - err := ChooseReplacementAttorneys(template.Execute, nil, mockUuidString)(testAppData, w, r, &actor.DonorProvidedDetails{}) + err := ChooseReplacementAttorneys(template.Execute, nil, testUIDFn)(testAppData, w, r, &actor.DonorProvidedDetails{}) resp := w.Result() assert.Equal(t, expectedError, err) @@ -119,7 +121,7 @@ func TestPostChooseReplacementAttorneysAttorneyDoesNotExists(t *testing.T) { LastName: "Doe", Email: "john@example.com", DateOfBirth: date.New(validBirthYear, "1", "2"), - ID: "123", + UID: testUID, }, }, "dob warning ignored": { @@ -137,7 +139,7 @@ func TestPostChooseReplacementAttorneysAttorneyDoesNotExists(t *testing.T) { LastName: "Doe", Email: "john@example.com", DateOfBirth: date.New("1900", "1", "2"), - ID: "123", + UID: testUID, }, }, "name warning ignored": { @@ -155,7 +157,7 @@ func TestPostChooseReplacementAttorneysAttorneyDoesNotExists(t *testing.T) { LastName: "Doe", Email: "john@example.com", DateOfBirth: date.New(validBirthYear, "1", "2"), - ID: "123", + UID: testUID, }, }, } @@ -176,17 +178,18 @@ func TestPostChooseReplacementAttorneysAttorneyDoesNotExists(t *testing.T) { }). Return(nil) - err := ChooseReplacementAttorneys(nil, donorStore, mockUuidString)(testAppData, w, r, &actor.DonorProvidedDetails{LpaID: "lpa-id", Donor: actor.Donor{FirstNames: "Jane", LastName: "Doe"}}) + err := ChooseReplacementAttorneys(nil, donorStore, testUIDFn)(testAppData, w, r, &actor.DonorProvidedDetails{LpaID: "lpa-id", Donor: actor.Donor{FirstNames: "Jane", LastName: "Doe"}}) resp := w.Result() assert.Nil(t, err) assert.Equal(t, http.StatusFound, resp.StatusCode) - assert.Equal(t, page.Paths.ChooseReplacementAttorneysAddress.Format("lpa-id")+"?id=123", resp.Header.Get("Location")) + assert.Equal(t, page.Paths.ChooseReplacementAttorneysAddress.Format("lpa-id")+"?id="+testUID.String(), resp.Header.Get("Location")) }) } } func TestPostChooseReplacementAttorneysAttorneyExists(t *testing.T) { + uid := actoruid.New() validBirthYear := strconv.Itoa(time.Now().Year() - 40) testCases := map[string]struct { @@ -208,7 +211,7 @@ func TestPostChooseReplacementAttorneysAttorneyExists(t *testing.T) { Email: "john@example.com", DateOfBirth: date.New(validBirthYear, "1", "2"), Address: place.Address{Line1: "abc"}, - ID: "123", + UID: uid, }, }, "dob warning ignored": { @@ -227,7 +230,7 @@ func TestPostChooseReplacementAttorneysAttorneyExists(t *testing.T) { Email: "john@example.com", DateOfBirth: date.New("1900", "1", "2"), Address: place.Address{Line1: "abc"}, - ID: "123", + UID: uid, }, }, "name warning ignored": { @@ -246,7 +249,7 @@ func TestPostChooseReplacementAttorneysAttorneyExists(t *testing.T) { Email: "john@example.com", DateOfBirth: date.New(validBirthYear, "1", "2"), Address: place.Address{Line1: "abc"}, - ID: "123", + UID: uid, }, }, } @@ -254,7 +257,7 @@ func TestPostChooseReplacementAttorneysAttorneyExists(t *testing.T) { for name, tc := range testCases { t.Run(name, func(t *testing.T) { w := httptest.NewRecorder() - r, _ := http.NewRequest(http.MethodPost, "/?id=123", strings.NewReader(tc.form.Encode())) + r, _ := http.NewRequest(http.MethodPost, "/?id="+uid.String(), strings.NewReader(tc.form.Encode())) r.Header.Add("Content-Type", page.FormUrlEncoded) donorStore := newMockDonorStore(t) @@ -267,13 +270,13 @@ func TestPostChooseReplacementAttorneysAttorneyExists(t *testing.T) { }). Return(nil) - err := ChooseReplacementAttorneys(nil, donorStore, mockUuidString)(testAppData, w, r, &actor.DonorProvidedDetails{ + err := ChooseReplacementAttorneys(nil, donorStore, testUIDFn)(testAppData, w, r, &actor.DonorProvidedDetails{ LpaID: "lpa-id", Donor: actor.Donor{FirstNames: "Jane", LastName: "Doe"}, ReplacementAttorneys: actor.Attorneys{Attorneys: []actor.Attorney{ { FirstNames: "John", - ID: "123", + UID: uid, Address: place.Address{Line1: "abc"}, }, }}, @@ -282,7 +285,7 @@ func TestPostChooseReplacementAttorneysAttorneyExists(t *testing.T) { assert.Nil(t, err) assert.Equal(t, http.StatusFound, resp.StatusCode) - assert.Equal(t, page.Paths.ChooseReplacementAttorneysAddress.Format("lpa-id")+"?id=123", resp.Header.Get("Location")) + assert.Equal(t, page.Paths.ChooseReplacementAttorneysAddress.Format("lpa-id")+"?id="+uid.String(), resp.Header.Get("Location")) }) } } @@ -296,8 +299,9 @@ func TestPostChooseReplacementAttorneysNameWarningOnlyShownWhenAttorneyAndFormNa "date-of-birth-year": {"2000"}, } + uid := actoruid.New() w := httptest.NewRecorder() - r, _ := http.NewRequest(http.MethodPost, "/?id=123", strings.NewReader(form.Encode())) + r, _ := http.NewRequest(http.MethodPost, "/?id="+uid.String(), strings.NewReader(form.Encode())) r.Header.Add("Content-Type", page.FormUrlEncoded) donorStore := newMockDonorStore(t) @@ -309,7 +313,7 @@ func TestPostChooseReplacementAttorneysNameWarningOnlyShownWhenAttorneyAndFormNa { FirstNames: "Jane", LastName: "Doe", - ID: "123", + UID: uid, Address: place.Address{Line1: "abc"}, DateOfBirth: date.New("2000", "1", "2"), }, @@ -318,18 +322,18 @@ func TestPostChooseReplacementAttorneysNameWarningOnlyShownWhenAttorneyAndFormNa }). Return(nil) - err := ChooseReplacementAttorneys(nil, donorStore, mockUuidString)(testAppData, w, r, &actor.DonorProvidedDetails{ + err := ChooseReplacementAttorneys(nil, donorStore, testUIDFn)(testAppData, w, r, &actor.DonorProvidedDetails{ LpaID: "lpa-id", Donor: actor.Donor{FirstNames: "Jane", LastName: "Doe"}, ReplacementAttorneys: actor.Attorneys{Attorneys: []actor.Attorney{ - {FirstNames: "Jane", LastName: "Doe", ID: "123", Address: place.Address{Line1: "abc"}}, + {FirstNames: "Jane", LastName: "Doe", UID: uid, Address: place.Address{Line1: "abc"}}, }}, }) resp := w.Result() assert.Nil(t, err) assert.Equal(t, http.StatusFound, resp.StatusCode) - assert.Equal(t, page.Paths.ChooseReplacementAttorneysAddress.Format("lpa-id")+"?id=123", resp.Header.Get("Location")) + assert.Equal(t, page.Paths.ChooseReplacementAttorneysAddress.Format("lpa-id")+"?id="+uid.String(), resp.Header.Get("Location")) } func TestPostChooseReplacementAttorneysWhenInputRequired(t *testing.T) { @@ -451,7 +455,7 @@ func TestPostChooseReplacementAttorneysWhenInputRequired(t *testing.T) { })). Return(nil) - err := ChooseReplacementAttorneys(template.Execute, nil, mockUuidString)(testAppData, w, r, &actor.DonorProvidedDetails{Donor: actor.Donor{FirstNames: "Jane", LastName: "Doe"}}) + err := ChooseReplacementAttorneys(template.Execute, nil, testUIDFn)(testAppData, w, r, &actor.DonorProvidedDetails{Donor: actor.Donor{FirstNames: "Jane", LastName: "Doe"}}) resp := w.Result() assert.Nil(t, err) @@ -479,12 +483,13 @@ func TestPostChooseReplacementAttorneysWhenStoreErrors(t *testing.T) { Put(r.Context(), mock.Anything). Return(expectedError) - err := ChooseReplacementAttorneys(nil, donorStore, mockUuidString)(testAppData, w, r, &actor.DonorProvidedDetails{}) + err := ChooseReplacementAttorneys(nil, donorStore, testUIDFn)(testAppData, w, r, &actor.DonorProvidedDetails{}) assert.Equal(t, expectedError, err) } func TestReplacementAttorneyMatches(t *testing.T) { + uid := actoruid.New() donor := &actor.DonorProvidedDetails{ Donor: actor.Donor{FirstNames: "a", LastName: "b"}, Attorneys: actor.Attorneys{Attorneys: []actor.Attorney{ @@ -493,7 +498,7 @@ func TestReplacementAttorneyMatches(t *testing.T) { }}, ReplacementAttorneys: actor.Attorneys{Attorneys: []actor.Attorney{ {FirstNames: "g", LastName: "h"}, - {ID: "123", FirstNames: "i", LastName: "j"}, + {UID: uid, FirstNames: "i", LastName: "j"}, }}, CertificateProvider: actor.CertificateProvider{FirstNames: "k", LastName: "l"}, PeopleToNotify: actor.PeopleToNotify{ @@ -504,20 +509,21 @@ func TestReplacementAttorneyMatches(t *testing.T) { IndependentWitness: actor.IndependentWitness{FirstNames: "i", LastName: "w"}, } - assert.Equal(t, actor.TypeNone, replacementAttorneyMatches(donor, "123", "x", "y")) - assert.Equal(t, actor.TypeDonor, replacementAttorneyMatches(donor, "123", "a", "b")) - assert.Equal(t, actor.TypeAttorney, replacementAttorneyMatches(donor, "123", "C", "D")) - assert.Equal(t, actor.TypeAttorney, replacementAttorneyMatches(donor, "123", "e", "f")) - assert.Equal(t, actor.TypeReplacementAttorney, replacementAttorneyMatches(donor, "123", "g", "h")) - assert.Equal(t, actor.TypeNone, replacementAttorneyMatches(donor, "123", "i", "j")) - assert.Equal(t, actor.TypeCertificateProvider, replacementAttorneyMatches(donor, "123", "K", "l")) - assert.Equal(t, actor.TypePersonToNotify, replacementAttorneyMatches(donor, "123", "m", "n")) - assert.Equal(t, actor.TypePersonToNotify, replacementAttorneyMatches(donor, "123", "O", "P")) - assert.Equal(t, actor.TypeAuthorisedSignatory, replacementAttorneyMatches(donor, "123", "a", "s")) - assert.Equal(t, actor.TypeIndependentWitness, replacementAttorneyMatches(donor, "123", "i", "w")) + assert.Equal(t, actor.TypeNone, replacementAttorneyMatches(donor, uid, "x", "y")) + assert.Equal(t, actor.TypeDonor, replacementAttorneyMatches(donor, uid, "a", "b")) + assert.Equal(t, actor.TypeAttorney, replacementAttorneyMatches(donor, uid, "C", "D")) + assert.Equal(t, actor.TypeAttorney, replacementAttorneyMatches(donor, uid, "e", "f")) + assert.Equal(t, actor.TypeReplacementAttorney, replacementAttorneyMatches(donor, uid, "g", "h")) + assert.Equal(t, actor.TypeNone, replacementAttorneyMatches(donor, uid, "i", "j")) + assert.Equal(t, actor.TypeCertificateProvider, replacementAttorneyMatches(donor, uid, "K", "l")) + assert.Equal(t, actor.TypePersonToNotify, replacementAttorneyMatches(donor, uid, "m", "n")) + assert.Equal(t, actor.TypePersonToNotify, replacementAttorneyMatches(donor, uid, "O", "P")) + assert.Equal(t, actor.TypeAuthorisedSignatory, replacementAttorneyMatches(donor, uid, "a", "s")) + assert.Equal(t, actor.TypeIndependentWitness, replacementAttorneyMatches(donor, uid, "i", "w")) } func TestReplacementAttorneyMatchesEmptyNamesIgnored(t *testing.T) { + uid := actoruid.New() donor := &actor.DonorProvidedDetails{ Donor: actor.Donor{FirstNames: "", LastName: ""}, Attorneys: actor.Attorneys{Attorneys: []actor.Attorney{ @@ -525,7 +531,7 @@ func TestReplacementAttorneyMatchesEmptyNamesIgnored(t *testing.T) { }}, ReplacementAttorneys: actor.Attorneys{Attorneys: []actor.Attorney{ {FirstNames: "", LastName: ""}, - {ID: "123", FirstNames: "", LastName: ""}, + {UID: uid, FirstNames: "", LastName: ""}, }}, CertificateProvider: actor.CertificateProvider{FirstNames: "", LastName: ""}, PeopleToNotify: actor.PeopleToNotify{ @@ -533,5 +539,5 @@ func TestReplacementAttorneyMatchesEmptyNamesIgnored(t *testing.T) { }, } - assert.Equal(t, actor.TypeNone, replacementAttorneyMatches(donor, "123", "", "")) + assert.Equal(t, actor.TypeNone, replacementAttorneyMatches(donor, uid, "", "")) } diff --git a/internal/page/donor/do_you_want_to_notify_people_test.go b/internal/page/donor/do_you_want_to_notify_people_test.go index 531b35ca2d..13ebeba931 100644 --- a/internal/page/donor/do_you_want_to_notify_people_test.go +++ b/internal/page/donor/do_you_want_to_notify_people_test.go @@ -8,6 +8,7 @@ import ( "testing" "github.com/ministryofjustice/opg-modernising-lpa/internal/actor" + "github.com/ministryofjustice/opg-modernising-lpa/internal/actor/actoruid" "github.com/ministryofjustice/opg-modernising-lpa/internal/form" "github.com/ministryofjustice/opg-modernising-lpa/internal/page" "github.com/ministryofjustice/opg-modernising-lpa/internal/validation" @@ -117,7 +118,7 @@ func TestGetDoYouWantToNotifyPeopleFromStoreWithPeople(t *testing.T) { err := DoYouWantToNotifyPeople(template.Execute, nil)(testAppData, w, r, &actor.DonorProvidedDetails{ LpaID: "lpa-id", PeopleToNotify: actor.PeopleToNotify{ - {ID: "123"}, + {UID: actoruid.New()}, }, }) resp := w.Result() diff --git a/internal/page/donor/enter_replacement_trust_corporation_address.go b/internal/page/donor/enter_replacement_trust_corporation_address.go index d40a849862..1629fe8075 100644 --- a/internal/page/donor/enter_replacement_trust_corporation_address.go +++ b/internal/page/donor/enter_replacement_trust_corporation_address.go @@ -18,7 +18,7 @@ func EnterReplacementTrustCorporationAddress(logger Logger, tmpl template.Templa appData, "theTrustCorporation", "", - "", + trustCorporation.UID, false, ) diff --git a/internal/page/donor/enter_trust_corporation_address.go b/internal/page/donor/enter_trust_corporation_address.go index cc93c4e0cb..de2d6189c3 100644 --- a/internal/page/donor/enter_trust_corporation_address.go +++ b/internal/page/donor/enter_trust_corporation_address.go @@ -18,7 +18,7 @@ func EnterTrustCorporationAddress(logger Logger, tmpl template.Template, address appData, "theTrustCorporation", "", - "", + trustCorporation.UID, false, ) diff --git a/internal/page/donor/how_should_replacement_attorneys_step_in_test.go b/internal/page/donor/how_should_replacement_attorneys_step_in_test.go index c3e3c74a96..fc3a94ab22 100644 --- a/internal/page/donor/how_should_replacement_attorneys_step_in_test.go +++ b/internal/page/donor/how_should_replacement_attorneys_step_in_test.go @@ -8,6 +8,7 @@ import ( "testing" "github.com/ministryofjustice/opg-modernising-lpa/internal/actor" + "github.com/ministryofjustice/opg-modernising-lpa/internal/actor/actoruid" "github.com/ministryofjustice/opg-modernising-lpa/internal/page" "github.com/ministryofjustice/opg-modernising-lpa/internal/validation" "github.com/stretchr/testify/assert" @@ -102,12 +103,12 @@ func TestPostHowShouldReplacementAttorneysStepInRedirects(t *testing.T) { }{ "multiple attorneys acting jointly and severally replacements step in when none left": { Attorneys: actor.Attorneys{Attorneys: []actor.Attorney{ - {ID: "123"}, - {ID: "123"}, + {UID: actoruid.New()}, + {UID: actoruid.New()}, }}, ReplacementAttorneys: actor.Attorneys{Attorneys: []actor.Attorney{ - {ID: "123"}, - {ID: "123"}, + {UID: actoruid.New()}, + {UID: actoruid.New()}, }}, HowAttorneysMakeDecisions: actor.JointlyAndSeverally, HowShouldReplacementAttorneysStepIn: actor.ReplacementAttorneysStepInWhenAllCanNoLongerAct, @@ -116,8 +117,8 @@ func TestPostHowShouldReplacementAttorneysStepInRedirects(t *testing.T) { }, "multiple attorneys acting jointly": { ReplacementAttorneys: actor.Attorneys{Attorneys: []actor.Attorney{ - {ID: "123"}, - {ID: "123"}, + {UID: actoruid.New()}, + {UID: actoruid.New()}, }}, HowAttorneysMakeDecisions: actor.Jointly, HowShouldReplacementAttorneysStepIn: actor.ReplacementAttorneysStepInWhenOneCanNoLongerAct, @@ -127,8 +128,8 @@ func TestPostHowShouldReplacementAttorneysStepInRedirects(t *testing.T) { }, "multiple attorneys acting jointly and severally replacements step in when one loses capacity": { Attorneys: actor.Attorneys{Attorneys: []actor.Attorney{ - {ID: "123"}, - {ID: "123"}, + {UID: actoruid.New()}, + {UID: actoruid.New()}, }}, HowAttorneysMakeDecisions: actor.JointlyAndSeverally, HowShouldReplacementAttorneysStepIn: actor.ReplacementAttorneysStepInWhenOneCanNoLongerAct, @@ -137,12 +138,12 @@ func TestPostHowShouldReplacementAttorneysStepInRedirects(t *testing.T) { }, "multiple attorneys acting jointly and severally": { Attorneys: actor.Attorneys{Attorneys: []actor.Attorney{ - {ID: "123"}, - {ID: "123"}, + {UID: actoruid.New()}, + {UID: actoruid.New()}, }}, ReplacementAttorneys: actor.Attorneys{Attorneys: []actor.Attorney{ - {ID: "123"}, - {ID: "123"}, + {UID: actoruid.New()}, + {UID: actoruid.New()}, }}, HowAttorneysMakeDecisions: actor.JointlyAndSeverally, HowShouldReplacementAttorneysStepIn: actor.ReplacementAttorneysStepInWhenOneCanNoLongerAct, diff --git a/internal/page/donor/mock_test.go b/internal/page/donor/mock_test.go index 4125f33c9c..7491232469 100644 --- a/internal/page/donor/mock_test.go +++ b/internal/page/donor/mock_test.go @@ -8,6 +8,7 @@ import ( "github.com/gorilla/sessions" "github.com/ministryofjustice/opg-modernising-lpa/internal/actor" + "github.com/ministryofjustice/opg-modernising-lpa/internal/actor/actoruid" "github.com/ministryofjustice/opg-modernising-lpa/internal/localize" "github.com/ministryofjustice/opg-modernising-lpa/internal/page" "github.com/ministryofjustice/opg-modernising-lpa/internal/place" @@ -33,6 +34,8 @@ var ( } testNow = time.Date(2023, time.July, 3, 4, 5, 6, 1, time.UTC) testNowFn = func() time.Time { return testNow } + testUID = actoruid.New() + testUIDFn = func() actoruid.UID { return testUID } ) func (m *mockDonorStore) withCompletedPaymentLpaData(r *http.Request, paymentId, paymentReference string, paymentAmount int) *mockDonorStore { diff --git a/internal/page/donor/register.go b/internal/page/donor/register.go index ab67cf0cd2..e4d7a295ec 100644 --- a/internal/page/donor/register.go +++ b/internal/page/donor/register.go @@ -11,6 +11,7 @@ import ( "github.com/gorilla/sessions" "github.com/ministryofjustice/opg-go-common/template" "github.com/ministryofjustice/opg-modernising-lpa/internal/actor" + "github.com/ministryofjustice/opg-modernising-lpa/internal/actor/actoruid" "github.com/ministryofjustice/opg-modernising-lpa/internal/date" "github.com/ministryofjustice/opg-modernising-lpa/internal/event" "github.com/ministryofjustice/opg-modernising-lpa/internal/identity" @@ -224,7 +225,7 @@ func Register( handleWithDonor(page.Paths.ChooseAttorneysGuidance, page.None, Guidance(tmpls.Get("choose_attorneys_guidance.gohtml"))) handleWithDonor(page.Paths.ChooseAttorneys, page.CanGoBack, - ChooseAttorneys(tmpls.Get("choose_attorneys.gohtml"), donorStore, random.UuidString)) + ChooseAttorneys(tmpls.Get("choose_attorneys.gohtml"), donorStore, actoruid.New)) handleWithDonor(page.Paths.ChooseAttorneysAddress, page.CanGoBack, ChooseAttorneysAddress(logger, tmpls.Get("choose_address.gohtml"), addressClient, donorStore)) handleWithDonor(page.Paths.EnterTrustCorporation, page.CanGoBack, @@ -243,7 +244,7 @@ func Register( handleWithDonor(page.Paths.DoYouWantReplacementAttorneys, page.None, WantReplacementAttorneys(tmpls.Get("do_you_want_replacement_attorneys.gohtml"), donorStore)) handleWithDonor(page.Paths.ChooseReplacementAttorneys, page.CanGoBack, - ChooseReplacementAttorneys(tmpls.Get("choose_replacement_attorneys.gohtml"), donorStore, random.UuidString)) + ChooseReplacementAttorneys(tmpls.Get("choose_replacement_attorneys.gohtml"), donorStore, actoruid.New)) handleWithDonor(page.Paths.ChooseReplacementAttorneysAddress, page.CanGoBack, ChooseReplacementAttorneysAddress(logger, tmpls.Get("choose_address.gohtml"), addressClient, donorStore)) handleWithDonor(page.Paths.EnterReplacementTrustCorporation, page.CanGoBack, @@ -275,7 +276,7 @@ func Register( handleWithDonor(page.Paths.ChooseNewCertificateProvider, page.None, ChooseNewCertificateProvider(tmpls.Get("choose_new_certificate_provider.gohtml"), donorStore)) handleWithDonor(page.Paths.CertificateProviderDetails, page.CanGoBack, - CertificateProviderDetails(tmpls.Get("certificate_provider_details.gohtml"), donorStore)) + CertificateProviderDetails(tmpls.Get("certificate_provider_details.gohtml"), donorStore, actoruid.New)) handleWithDonor(page.Paths.HowWouldCertificateProviderPreferToCarryOutTheirRole, page.CanGoBack, HowWouldCertificateProviderPreferToCarryOutTheirRole(tmpls.Get("how_would_certificate_provider_prefer_to_carry_out_their_role.gohtml"), donorStore)) handleWithDonor(page.Paths.CertificateProviderAddress, page.CanGoBack, @@ -288,7 +289,7 @@ func Register( handleWithDonor(page.Paths.DoYouWantToNotifyPeople, page.CanGoBack, DoYouWantToNotifyPeople(tmpls.Get("do_you_want_to_notify_people.gohtml"), donorStore)) handleWithDonor(page.Paths.ChoosePeopleToNotify, page.CanGoBack, - ChoosePeopleToNotify(tmpls.Get("choose_people_to_notify.gohtml"), donorStore, random.UuidString)) + ChoosePeopleToNotify(tmpls.Get("choose_people_to_notify.gohtml"), donorStore, actoruid.New)) handleWithDonor(page.Paths.ChoosePeopleToNotifyAddress, page.CanGoBack, ChoosePeopleToNotifyAddress(logger, tmpls.Get("choose_address.gohtml"), addressClient, donorStore)) handleWithDonor(page.Paths.ChoosePeopleToNotifySummary, page.CanGoBack, diff --git a/internal/page/donor/remove_attorney.go b/internal/page/donor/remove_attorney.go index e8e9ac2254..edafe082ac 100644 --- a/internal/page/donor/remove_attorney.go +++ b/internal/page/donor/remove_attorney.go @@ -6,6 +6,7 @@ import ( "github.com/ministryofjustice/opg-go-common/template" "github.com/ministryofjustice/opg-modernising-lpa/internal/actor" + "github.com/ministryofjustice/opg-modernising-lpa/internal/actor/actoruid" "github.com/ministryofjustice/opg-modernising-lpa/internal/form" "github.com/ministryofjustice/opg-modernising-lpa/internal/page" "github.com/ministryofjustice/opg-modernising-lpa/internal/validation" @@ -21,8 +22,7 @@ type removeAttorneyData struct { func RemoveAttorney(logger Logger, tmpl template.Template, donorStore DonorStore) Handler { return func(appData page.AppData, w http.ResponseWriter, r *http.Request, donor *actor.DonorProvidedDetails) error { - id := r.FormValue("id") - attorney, found := donor.Attorneys.Get(id) + attorney, found := donor.Attorneys.Get(actoruid.FromRequest(r)) if found == false { return page.Paths.ChooseAttorneysSummary.Redirect(w, r, appData, donor) diff --git a/internal/page/donor/remove_attorney_test.go b/internal/page/donor/remove_attorney_test.go index 8e520638dd..c5d9678ec4 100644 --- a/internal/page/donor/remove_attorney_test.go +++ b/internal/page/donor/remove_attorney_test.go @@ -8,6 +8,7 @@ import ( "testing" "github.com/ministryofjustice/opg-modernising-lpa/internal/actor" + "github.com/ministryofjustice/opg-modernising-lpa/internal/actor/actoruid" "github.com/ministryofjustice/opg-modernising-lpa/internal/form" "github.com/ministryofjustice/opg-modernising-lpa/internal/page" "github.com/ministryofjustice/opg-modernising-lpa/internal/place" @@ -17,13 +18,14 @@ import ( ) func TestGetRemoveAttorney(t *testing.T) { + uid := actoruid.New() w := httptest.NewRecorder() - r, _ := http.NewRequest(http.MethodGet, "/?id=123", nil) + r, _ := http.NewRequest(http.MethodGet, "/?id="+uid.String(), nil) logger := newMockLogger(t) attorney := actor.Attorney{ - ID: "123", + UID: uid, FirstNames: "John", LastName: "Smith", Address: place.Address{ @@ -58,7 +60,7 @@ func TestGetRemoveAttorneyAttorneyDoesNotExist(t *testing.T) { template := newMockTemplate(t) attorney := actor.Attorney{ - ID: "123", + UID: actoruid.New(), Address: place.Address{ Line1: "1 Road way", }, @@ -74,9 +76,9 @@ func TestGetRemoveAttorneyAttorneyDoesNotExist(t *testing.T) { } func TestPostRemoveAttorney(t *testing.T) { - attorneyWithEmail := actor.Attorney{ID: "with-email", Email: "a"} - attorneyWithAddress := actor.Attorney{ID: "with-address", Address: place.Address{Line1: "1 Road way"}} - attorneyWithoutAddress := actor.Attorney{ID: "without-address"} + attorneyWithEmail := actor.Attorney{UID: actoruid.New(), Email: "a"} + attorneyWithAddress := actor.Attorney{UID: actoruid.New(), Address: place.Address{Line1: "1 Road way"}} + attorneyWithoutAddress := actor.Attorney{UID: actoruid.New()} testcases := map[string]struct { donor *actor.DonorProvidedDetails @@ -127,7 +129,7 @@ func TestPostRemoveAttorney(t *testing.T) { } w := httptest.NewRecorder() - r, _ := http.NewRequest(http.MethodPost, "/?id=without-address", strings.NewReader(f.Encode())) + r, _ := http.NewRequest(http.MethodPost, "/?id="+attorneyWithoutAddress.UID.String(), strings.NewReader(f.Encode())) r.Header.Add("Content-Type", page.FormUrlEncoded) logger := newMockLogger(t) @@ -154,25 +156,25 @@ func TestPostRemoveAttorneyWithFormValueNo(t *testing.T) { form.FieldNames.YesNo: {form.No.String()}, } - w := httptest.NewRecorder() - r, _ := http.NewRequest(http.MethodPost, "/?id=without-address", strings.NewReader(f.Encode())) - r.Header.Add("Content-Type", page.FormUrlEncoded) - - logger := newMockLogger(t) - template := newMockTemplate(t) - attorneyWithAddress := actor.Attorney{ - ID: "with-address", + UID: actoruid.New(), Address: place.Address{ Line1: "1 Road way", }, } attorneyWithoutAddress := actor.Attorney{ - ID: "without-address", + UID: actoruid.New(), Address: place.Address{}, } + w := httptest.NewRecorder() + r, _ := http.NewRequest(http.MethodPost, "/?id="+attorneyWithoutAddress.UID.String(), strings.NewReader(f.Encode())) + r.Header.Add("Content-Type", page.FormUrlEncoded) + + logger := newMockLogger(t) + template := newMockTemplate(t) + err := RemoveAttorney(logger, template.Execute, nil)(testAppData, w, r, &actor.DonorProvidedDetails{LpaID: "lpa-id", Attorneys: actor.Attorneys{Attorneys: []actor.Attorney{attorneyWithoutAddress, attorneyWithAddress}}}) resp := w.Result() @@ -187,29 +189,29 @@ func TestPostRemoveAttorneyErrorOnPutStore(t *testing.T) { form.FieldNames.YesNo: {form.Yes.String()}, } - w := httptest.NewRecorder() - r, _ := http.NewRequest(http.MethodPost, "/?id=without-address", strings.NewReader(f.Encode())) - r.Header.Add("Content-Type", page.FormUrlEncoded) - - template := newMockTemplate(t) - - logger := newMockLogger(t) - logger.EXPECT(). - Print("error removing Attorney from LPA: err"). - Return() - attorneyWithAddress := actor.Attorney{ - ID: "with-address", + UID: actoruid.New(), Address: place.Address{ Line1: "1 Road way", }, } attorneyWithoutAddress := actor.Attorney{ - ID: "without-address", + UID: actoruid.New(), Address: place.Address{}, } + w := httptest.NewRecorder() + r, _ := http.NewRequest(http.MethodPost, "/?id="+attorneyWithoutAddress.UID.String(), strings.NewReader(f.Encode())) + r.Header.Add("Content-Type", page.FormUrlEncoded) + + template := newMockTemplate(t) + + logger := newMockLogger(t) + logger.EXPECT(). + Print("error removing Attorney from LPA: err"). + Return() + donorStore := newMockDonorStore(t) donorStore.EXPECT(). Put(r.Context(), mock.Anything). @@ -228,15 +230,11 @@ func TestRemoveAttorneyFormValidation(t *testing.T) { form.FieldNames.YesNo: {""}, } + uid := actoruid.New() w := httptest.NewRecorder() - r, _ := http.NewRequest(http.MethodPost, "/?id=without-address", strings.NewReader(f.Encode())) + r, _ := http.NewRequest(http.MethodPost, "/?id="+uid.String(), strings.NewReader(f.Encode())) r.Header.Add("Content-Type", page.FormUrlEncoded) - attorneyWithoutAddress := actor.Attorney{ - ID: "without-address", - Address: place.Address{}, - } - validationError := validation.With(form.FieldNames.YesNo, validation.SelectError{Label: "yesToRemoveAttorney"}) template := newMockTemplate(t) @@ -246,7 +244,14 @@ func TestRemoveAttorneyFormValidation(t *testing.T) { })). Return(nil) - err := RemoveAttorney(nil, template.Execute, nil)(testAppData, w, r, &actor.DonorProvidedDetails{Attorneys: actor.Attorneys{Attorneys: []actor.Attorney{attorneyWithoutAddress}}}) + err := RemoveAttorney(nil, template.Execute, nil)(testAppData, w, r, &actor.DonorProvidedDetails{ + Attorneys: actor.Attorneys{ + Attorneys: []actor.Attorney{{ + UID: uid, + Address: place.Address{}, + }}, + }, + }) resp := w.Result() assert.Nil(t, err) diff --git a/internal/page/donor/remove_person_to_notify.go b/internal/page/donor/remove_person_to_notify.go index 5713f9553a..1881b2d544 100644 --- a/internal/page/donor/remove_person_to_notify.go +++ b/internal/page/donor/remove_person_to_notify.go @@ -6,6 +6,7 @@ import ( "github.com/ministryofjustice/opg-go-common/template" "github.com/ministryofjustice/opg-modernising-lpa/internal/actor" + "github.com/ministryofjustice/opg-modernising-lpa/internal/actor/actoruid" "github.com/ministryofjustice/opg-modernising-lpa/internal/form" "github.com/ministryofjustice/opg-modernising-lpa/internal/page" "github.com/ministryofjustice/opg-modernising-lpa/internal/validation" @@ -20,8 +21,7 @@ type removePersonToNotifyData struct { func RemovePersonToNotify(logger Logger, tmpl template.Template, donorStore DonorStore) Handler { return func(appData page.AppData, w http.ResponseWriter, r *http.Request, donor *actor.DonorProvidedDetails) error { - id := r.FormValue("id") - person, found := donor.PeopleToNotify.Get(id) + person, found := donor.PeopleToNotify.Get(actoruid.FromRequest(r)) if found == false { return page.Paths.ChoosePeopleToNotifySummary.Redirect(w, r, appData, donor) diff --git a/internal/page/donor/remove_person_to_notify_test.go b/internal/page/donor/remove_person_to_notify_test.go index 78839fe177..9c51182b8b 100644 --- a/internal/page/donor/remove_person_to_notify_test.go +++ b/internal/page/donor/remove_person_to_notify_test.go @@ -8,6 +8,7 @@ import ( "testing" "github.com/ministryofjustice/opg-modernising-lpa/internal/actor" + "github.com/ministryofjustice/opg-modernising-lpa/internal/actor/actoruid" "github.com/ministryofjustice/opg-modernising-lpa/internal/form" "github.com/ministryofjustice/opg-modernising-lpa/internal/page" "github.com/ministryofjustice/opg-modernising-lpa/internal/place" @@ -17,13 +18,14 @@ import ( ) func TestGetRemovePersonToNotify(t *testing.T) { + uid := actoruid.New() w := httptest.NewRecorder() - r, _ := http.NewRequest(http.MethodGet, "/?id=123", nil) + r, _ := http.NewRequest(http.MethodGet, "/?id="+uid.String(), nil) logger := newMockLogger(t) personToNotify := actor.PersonToNotify{ - ID: "123", + UID: uid, Address: place.Address{ Line1: "1 Road way", }, @@ -56,7 +58,7 @@ func TestGetRemovePersonToNotifyAttorneyDoesNotExist(t *testing.T) { template := newMockTemplate(t) personToNotify := actor.PersonToNotify{ - ID: "123", + UID: actoruid.New(), Address: place.Address{ Line1: "1 Road way", }, @@ -76,22 +78,23 @@ func TestPostRemovePersonToNotify(t *testing.T) { form.FieldNames.YesNo: {form.Yes.String()}, } + uid := actoruid.New() w := httptest.NewRecorder() - r, _ := http.NewRequest(http.MethodPost, "/?id=without-address", strings.NewReader(f.Encode())) + r, _ := http.NewRequest(http.MethodPost, "/?id="+uid.String(), strings.NewReader(f.Encode())) r.Header.Add("Content-Type", page.FormUrlEncoded) logger := newMockLogger(t) template := newMockTemplate(t) personToNotifyWithAddress := actor.PersonToNotify{ - ID: "with-address", + UID: actoruid.New(), Address: place.Address{ Line1: "1 Road way", }, } personToNotifyWithoutAddress := actor.PersonToNotify{ - ID: "without-address", + UID: uid, Address: place.Address{}, } @@ -114,22 +117,23 @@ func TestPostRemovePersonToNotifyWithFormValueNo(t *testing.T) { form.FieldNames.YesNo: {form.No.String()}, } + uid := actoruid.New() w := httptest.NewRecorder() - r, _ := http.NewRequest(http.MethodPost, "/?id=without-address", strings.NewReader(f.Encode())) + r, _ := http.NewRequest(http.MethodPost, "/?id="+uid.String(), strings.NewReader(f.Encode())) r.Header.Add("Content-Type", page.FormUrlEncoded) logger := newMockLogger(t) template := newMockTemplate(t) personToNotifyWithAddress := actor.PersonToNotify{ - ID: "with-address", + UID: actoruid.New(), Address: place.Address{ Line1: "1 Road way", }, } personToNotifyWithoutAddress := actor.PersonToNotify{ - ID: "without-address", + UID: uid, Address: place.Address{}, } @@ -147,8 +151,9 @@ func TestPostRemovePersonToNotifyErrorOnPutStore(t *testing.T) { form.FieldNames.YesNo: {form.Yes.String()}, } + uid := actoruid.New() w := httptest.NewRecorder() - r, _ := http.NewRequest(http.MethodPost, "/?id=without-address", strings.NewReader(f.Encode())) + r, _ := http.NewRequest(http.MethodPost, "/?id="+uid.String(), strings.NewReader(f.Encode())) r.Header.Add("Content-Type", page.FormUrlEncoded) template := newMockTemplate(t) @@ -159,14 +164,14 @@ func TestPostRemovePersonToNotifyErrorOnPutStore(t *testing.T) { Return() personToNotifyWithAddress := actor.PersonToNotify{ - ID: "with-address", + UID: actoruid.New(), Address: place.Address{ Line1: "1 Road way", }, } personToNotifyWithoutAddress := actor.PersonToNotify{ - ID: "without-address", + UID: uid, Address: place.Address{}, } @@ -188,12 +193,13 @@ func TestRemovePersonToNotifyFormValidation(t *testing.T) { form.FieldNames.YesNo: {""}, } + uid := actoruid.New() w := httptest.NewRecorder() - r, _ := http.NewRequest(http.MethodPost, "/?id=without-address", strings.NewReader(f.Encode())) + r, _ := http.NewRequest(http.MethodPost, "/?id="+uid.String(), strings.NewReader(f.Encode())) r.Header.Add("Content-Type", page.FormUrlEncoded) personToNotifyWithoutAddress := actor.PersonToNotify{ - ID: "without-address", + UID: uid, Address: place.Address{}, } @@ -218,15 +224,16 @@ func TestRemovePersonToNotifyRemoveLastPerson(t *testing.T) { form.FieldNames.YesNo: {form.Yes.String()}, } + uid := actoruid.New() w := httptest.NewRecorder() - r, _ := http.NewRequest(http.MethodPost, "/?id=without-address", strings.NewReader(f.Encode())) + r, _ := http.NewRequest(http.MethodPost, "/?id="+uid.String(), strings.NewReader(f.Encode())) r.Header.Add("Content-Type", page.FormUrlEncoded) logger := newMockLogger(t) template := newMockTemplate(t) personToNotifyWithoutAddress := actor.PersonToNotify{ - ID: "without-address", + UID: uid, Address: place.Address{}, } diff --git a/internal/page/donor/remove_replacement_attorney.go b/internal/page/donor/remove_replacement_attorney.go index fc3b872c90..9bd9af31de 100644 --- a/internal/page/donor/remove_replacement_attorney.go +++ b/internal/page/donor/remove_replacement_attorney.go @@ -6,14 +6,14 @@ import ( "github.com/ministryofjustice/opg-go-common/template" "github.com/ministryofjustice/opg-modernising-lpa/internal/actor" + "github.com/ministryofjustice/opg-modernising-lpa/internal/actor/actoruid" "github.com/ministryofjustice/opg-modernising-lpa/internal/form" "github.com/ministryofjustice/opg-modernising-lpa/internal/page" ) func RemoveReplacementAttorney(logger Logger, tmpl template.Template, donorStore DonorStore) Handler { return func(appData page.AppData, w http.ResponseWriter, r *http.Request, donor *actor.DonorProvidedDetails) error { - id := r.FormValue("id") - attorney, found := donor.ReplacementAttorneys.Get(id) + attorney, found := donor.ReplacementAttorneys.Get(actoruid.FromRequest(r)) if found == false { return page.Paths.ChooseReplacementAttorneysSummary.Redirect(w, r, appData, donor) diff --git a/internal/page/donor/remove_replacement_attorney_test.go b/internal/page/donor/remove_replacement_attorney_test.go index 29adc5d9f2..73a28461a0 100644 --- a/internal/page/donor/remove_replacement_attorney_test.go +++ b/internal/page/donor/remove_replacement_attorney_test.go @@ -8,6 +8,7 @@ import ( "testing" "github.com/ministryofjustice/opg-modernising-lpa/internal/actor" + "github.com/ministryofjustice/opg-modernising-lpa/internal/actor/actoruid" "github.com/ministryofjustice/opg-modernising-lpa/internal/form" "github.com/ministryofjustice/opg-modernising-lpa/internal/page" "github.com/ministryofjustice/opg-modernising-lpa/internal/place" @@ -17,13 +18,14 @@ import ( ) func TestGetRemoveReplacementAttorney(t *testing.T) { + uid := actoruid.New() w := httptest.NewRecorder() - r, _ := http.NewRequest(http.MethodGet, "/?id=123", nil) + r, _ := http.NewRequest(http.MethodGet, "/?id="+uid.String(), nil) logger := newMockLogger(t) attorney := actor.Attorney{ - ID: "123", + UID: uid, FirstNames: "John", LastName: "Smith", Address: place.Address{ @@ -57,7 +59,7 @@ func TestGetRemoveReplacementAttorneyAttorneyDoesNotExist(t *testing.T) { template := newMockTemplate(t) attorney := actor.Attorney{ - ID: "123", + UID: actoruid.New(), Address: place.Address{ Line1: "1 Road way", }, @@ -73,9 +75,9 @@ func TestGetRemoveReplacementAttorneyAttorneyDoesNotExist(t *testing.T) { } func TestPostRemoveReplacementAttorney(t *testing.T) { - attorneyWithEmail := actor.Attorney{ID: "with-email", Email: "a"} - attorneyWithAddress := actor.Attorney{ID: "with-address", Address: place.Address{Line1: "1 Road way"}} - attorneyWithoutAddress := actor.Attorney{ID: "without-address"} + attorneyWithEmail := actor.Attorney{UID: actoruid.New(), Email: "a"} + attorneyWithAddress := actor.Attorney{UID: actoruid.New(), Address: place.Address{Line1: "1 Road way"}} + attorneyWithoutAddress := actor.Attorney{UID: actoruid.New()} testcases := map[string]struct { donor *actor.DonorProvidedDetails @@ -127,7 +129,7 @@ func TestPostRemoveReplacementAttorney(t *testing.T) { } w := httptest.NewRecorder() - r, _ := http.NewRequest(http.MethodPost, "/?id=without-address", strings.NewReader(f.Encode())) + r, _ := http.NewRequest(http.MethodPost, "/?id="+attorneyWithoutAddress.UID.String(), strings.NewReader(f.Encode())) r.Header.Add("Content-Type", page.FormUrlEncoded) logger := newMockLogger(t) @@ -154,22 +156,23 @@ func TestPostRemoveReplacementAttorneyWithFormValueNo(t *testing.T) { form.FieldNames.YesNo: {form.No.String()}, } + uid := actoruid.New() w := httptest.NewRecorder() - r, _ := http.NewRequest(http.MethodPost, "/?id=without-address", strings.NewReader(f.Encode())) + r, _ := http.NewRequest(http.MethodPost, "/?id="+uid.String(), strings.NewReader(f.Encode())) r.Header.Add("Content-Type", page.FormUrlEncoded) logger := newMockLogger(t) template := newMockTemplate(t) attorneyWithAddress := actor.Attorney{ - ID: "with-address", + UID: actoruid.New(), Address: place.Address{ Line1: "1 Road way", }, } attorneyWithoutAddress := actor.Attorney{ - ID: "without-address", + UID: uid, Address: place.Address{}, } @@ -187,8 +190,9 @@ func TestPostRemoveReplacementAttorneyErrorOnPutStore(t *testing.T) { form.FieldNames.YesNo: {form.Yes.String()}, } + uid := actoruid.New() w := httptest.NewRecorder() - r, _ := http.NewRequest(http.MethodPost, "/?id=without-address", strings.NewReader(f.Encode())) + r, _ := http.NewRequest(http.MethodPost, "/?id="+uid.String(), strings.NewReader(f.Encode())) r.Header.Add("Content-Type", page.FormUrlEncoded) template := newMockTemplate(t) @@ -199,14 +203,14 @@ func TestPostRemoveReplacementAttorneyErrorOnPutStore(t *testing.T) { Return() attorneyWithAddress := actor.Attorney{ - ID: "with-address", + UID: actoruid.New(), Address: place.Address{ Line1: "1 Road way", }, } attorneyWithoutAddress := actor.Attorney{ - ID: "without-address", + UID: uid, Address: place.Address{}, } @@ -231,12 +235,13 @@ func TestRemoveReplacementAttorneyFormValidation(t *testing.T) { form.FieldNames.YesNo: {""}, } + uid := actoruid.New() w := httptest.NewRecorder() - r, _ := http.NewRequest(http.MethodPost, "/?id=without-address", strings.NewReader(f.Encode())) + r, _ := http.NewRequest(http.MethodPost, "/?id="+uid.String(), strings.NewReader(f.Encode())) r.Header.Add("Content-Type", page.FormUrlEncoded) attorneyWithoutAddress := actor.Attorney{ - ID: "without-address", + UID: uid, Address: place.Address{}, } diff --git a/internal/page/donor/remove_trust_corporation_test.go b/internal/page/donor/remove_trust_corporation_test.go index 765b90e393..9fc07e1eec 100644 --- a/internal/page/donor/remove_trust_corporation_test.go +++ b/internal/page/donor/remove_trust_corporation_test.go @@ -8,6 +8,7 @@ import ( "testing" "github.com/ministryofjustice/opg-modernising-lpa/internal/actor" + "github.com/ministryofjustice/opg-modernising-lpa/internal/actor/actoruid" "github.com/ministryofjustice/opg-modernising-lpa/internal/form" "github.com/ministryofjustice/opg-modernising-lpa/internal/page" "github.com/ministryofjustice/opg-modernising-lpa/internal/place" @@ -61,7 +62,7 @@ func TestGetRemoveTrustCorporation(t *testing.T) { } func TestPostRemoveTrustCorporation(t *testing.T) { - attorney := actor.Attorney{ID: "with-email", Email: "a"} + attorney := actor.Attorney{UID: actoruid.New(), Email: "a"} trustCorporation := actor.TrustCorporation{Name: "a"} testcases := map[string]struct { @@ -178,21 +179,22 @@ func TestPostRemoveTrustCorporationWithFormValueNo(t *testing.T) { form.FieldNames.YesNo: {form.No.String()}, } + uid := actoruid.New() w := httptest.NewRecorder() - r, _ := http.NewRequest(http.MethodPost, "/?id=without-address", strings.NewReader(f.Encode())) + r, _ := http.NewRequest(http.MethodPost, "/?id="+uid.String(), strings.NewReader(f.Encode())) r.Header.Add("Content-Type", page.FormUrlEncoded) template := newMockTemplate(t) attorneyWithAddress := actor.Attorney{ - ID: "with-address", + UID: actoruid.New(), Address: place.Address{ Line1: "1 Road way", }, } attorneyWithoutAddress := actor.Attorney{ - ID: "without-address", + UID: uid, Address: place.Address{}, } @@ -210,21 +212,22 @@ func TestPostRemoveTrustCorporationErrorOnPutStore(t *testing.T) { form.FieldNames.YesNo: {form.Yes.String()}, } + uid := actoruid.New() w := httptest.NewRecorder() - r, _ := http.NewRequest(http.MethodPost, "/?id=without-address", strings.NewReader(f.Encode())) + r, _ := http.NewRequest(http.MethodPost, "/?id="+uid.String(), strings.NewReader(f.Encode())) r.Header.Add("Content-Type", page.FormUrlEncoded) template := newMockTemplate(t) attorneyWithAddress := actor.Attorney{ - ID: "with-address", + UID: actoruid.New(), Address: place.Address{ Line1: "1 Road way", }, } attorneyWithoutAddress := actor.Attorney{ - ID: "without-address", + UID: uid, Address: place.Address{}, } @@ -246,12 +249,13 @@ func TestRemoveTrustCorporationFormValidation(t *testing.T) { form.FieldNames.YesNo: {""}, } + uid := actoruid.New() w := httptest.NewRecorder() - r, _ := http.NewRequest(http.MethodPost, "/?id=without-address", strings.NewReader(f.Encode())) + r, _ := http.NewRequest(http.MethodPost, "/?id="+uid.String(), strings.NewReader(f.Encode())) r.Header.Add("Content-Type", page.FormUrlEncoded) attorneyWithoutAddress := actor.Attorney{ - ID: "without-address", + UID: uid, Address: place.Address{}, } diff --git a/internal/page/donor/want_replacement_attorneys_test.go b/internal/page/donor/want_replacement_attorneys_test.go index 6976c4969f..e9598e927d 100644 --- a/internal/page/donor/want_replacement_attorneys_test.go +++ b/internal/page/donor/want_replacement_attorneys_test.go @@ -8,6 +8,7 @@ import ( "testing" "github.com/ministryofjustice/opg-modernising-lpa/internal/actor" + "github.com/ministryofjustice/opg-modernising-lpa/internal/actor/actoruid" "github.com/ministryofjustice/opg-modernising-lpa/internal/form" "github.com/ministryofjustice/opg-modernising-lpa/internal/page" "github.com/ministryofjustice/opg-modernising-lpa/internal/validation" @@ -86,6 +87,8 @@ func TestGetWantReplacementAttorneysWhenTemplateErrors(t *testing.T) { } func TestPostWantReplacementAttorneys(t *testing.T) { + uid := actoruid.New() + testCases := map[string]struct { yesNo form.YesNo existingReplacementAttorneys actor.Attorneys @@ -95,16 +98,16 @@ func TestPostWantReplacementAttorneys(t *testing.T) { }{ "yes": { yesNo: form.Yes, - existingReplacementAttorneys: actor.Attorneys{Attorneys: []actor.Attorney{{ID: "123"}}}, - expectedReplacementAttorneys: actor.Attorneys{Attorneys: []actor.Attorney{{ID: "123"}}}, + existingReplacementAttorneys: actor.Attorneys{Attorneys: []actor.Attorney{{UID: uid}}}, + expectedReplacementAttorneys: actor.Attorneys{Attorneys: []actor.Attorney{{UID: uid}}}, taskState: actor.TaskInProgress, redirect: page.Paths.ChooseReplacementAttorneys, }, "no": { yesNo: form.No, existingReplacementAttorneys: actor.Attorneys{Attorneys: []actor.Attorney{ - {ID: "123"}, - {ID: "345"}, + {UID: uid}, + {UID: actoruid.New()}, }}, expectedReplacementAttorneys: actor.Attorneys{}, taskState: actor.TaskCompleted, diff --git a/internal/page/donor/your_address.go b/internal/page/donor/your_address.go index 41763de5b5..20ff915b6d 100644 --- a/internal/page/donor/your_address.go +++ b/internal/page/donor/your_address.go @@ -17,7 +17,7 @@ func YourAddress(logger Logger, tmpl template.Template, addressClient AddressCli appData, "", "", - "", + donor.Donor.UID, false, ) diff --git a/internal/page/donor/your_details_test.go b/internal/page/donor/your_details_test.go index 49f68e90cf..d9c4d8a250 100644 --- a/internal/page/donor/your_details_test.go +++ b/internal/page/donor/your_details_test.go @@ -11,6 +11,7 @@ import ( "github.com/gorilla/sessions" "github.com/ministryofjustice/opg-modernising-lpa/internal/actor" + "github.com/ministryofjustice/opg-modernising-lpa/internal/actor/actoruid" "github.com/ministryofjustice/opg-modernising-lpa/internal/date" "github.com/ministryofjustice/opg-modernising-lpa/internal/form" "github.com/ministryofjustice/opg-modernising-lpa/internal/page" @@ -449,6 +450,7 @@ func TestPostYourDetailsNameWarningOnlyShownWhenDonorAndFormNamesAreDifferent(t "can-sign": {actor.Yes.String()}, } + uid := actoruid.New() w := httptest.NewRecorder() r, _ := http.NewRequest(http.MethodPost, "/", strings.NewReader(f.Encode())) r.Header.Add("Content-Type", page.FormUrlEncoded) @@ -467,7 +469,7 @@ func TestPostYourDetailsNameWarningOnlyShownWhenDonorAndFormNamesAreDifferent(t }, Tasks: actor.DonorTasks{YourDetails: actor.TaskInProgress}, ReplacementAttorneys: actor.Attorneys{Attorneys: []actor.Attorney{ - {FirstNames: "Jane", LastName: "Doe", ID: "123", Address: place.Address{Line1: "abc"}}, + {FirstNames: "Jane", LastName: "Doe", UID: uid, Address: place.Address{Line1: "abc"}}, }}, }). Return(nil) @@ -481,7 +483,7 @@ func TestPostYourDetailsNameWarningOnlyShownWhenDonorAndFormNamesAreDifferent(t LpaID: "lpa-id", Donor: actor.Donor{FirstNames: "Jane", LastName: "Doe"}, ReplacementAttorneys: actor.Attorneys{Attorneys: []actor.Attorney{ - {FirstNames: "Jane", LastName: "Doe", ID: "123", Address: place.Address{Line1: "abc"}}, + {FirstNames: "Jane", LastName: "Doe", UID: uid, Address: place.Address{Line1: "abc"}}, }}, }) resp := w.Result() diff --git a/internal/page/donor/your_independent_witness_address.go b/internal/page/donor/your_independent_witness_address.go index 416db58bad..459d8b56f9 100644 --- a/internal/page/donor/your_independent_witness_address.go +++ b/internal/page/donor/your_independent_witness_address.go @@ -5,6 +5,7 @@ import ( "github.com/ministryofjustice/opg-go-common/template" "github.com/ministryofjustice/opg-modernising-lpa/internal/actor" + "github.com/ministryofjustice/opg-modernising-lpa/internal/actor/actoruid" "github.com/ministryofjustice/opg-modernising-lpa/internal/form" "github.com/ministryofjustice/opg-modernising-lpa/internal/page" "github.com/ministryofjustice/opg-modernising-lpa/internal/place" @@ -16,7 +17,7 @@ func YourIndependentWitnessAddress(logger Logger, tmpl template.Template, addres appData, "independentWitness", donor.IndependentWitness.FullName(), - "", + actoruid.UID{}, false, ) diff --git a/internal/page/fixtures/attorney.go b/internal/page/fixtures/attorney.go index 4ef88def56..d785f8e53b 100644 --- a/internal/page/fixtures/attorney.go +++ b/internal/page/fixtures/attorney.go @@ -10,6 +10,7 @@ import ( "github.com/ministryofjustice/opg-go-common/template" "github.com/ministryofjustice/opg-modernising-lpa/internal/actor" + "github.com/ministryofjustice/opg-modernising-lpa/internal/actor/actoruid" "github.com/ministryofjustice/opg-modernising-lpa/internal/date" "github.com/ministryofjustice/opg-modernising-lpa/internal/form" "github.com/ministryofjustice/opg-modernising-lpa/internal/localize" @@ -31,7 +32,7 @@ type CertificateProviderStore interface { } type AttorneyStore interface { - Create(context.Context, string, string, bool, bool) (*actor.AttorneyProvidedDetails, error) + Create(context.Context, string, actoruid.UID, bool, bool) (*actor.AttorneyProvidedDetails, error) Put(context.Context, *actor.AttorneyProvidedDetails) error } @@ -151,13 +152,15 @@ func Attorney( } } - var attorneyID string - if !isTrustCorporation { - if isReplacement { - attorneyID = donor.ReplacementAttorneys.Attorneys[0].ID - } else { - attorneyID = donor.Attorneys.Attorneys[0].ID - } + var attorneyUID actoruid.UID + if isTrustCorporation && isReplacement { + attorneyUID = donor.ReplacementAttorneys.TrustCorporation.UID + } else if isTrustCorporation { + attorneyUID = donor.Attorneys.TrustCorporation.UID + } else if isReplacement { + attorneyUID = donor.ReplacementAttorneys.Attorneys[0].UID + } else { + attorneyUID = donor.Attorneys.Attorneys[0].UID } donor.AttorneyDecisions = actor.AttorneyDecisions{How: actor.JointlyAndSeverally} @@ -168,7 +171,7 @@ func Attorney( return err } - attorney, err := attorneyStore.Create(attorneyCtx, donorSessionID, attorneyID, isReplacement, isTrustCorporation) + attorney, err := attorneyStore.Create(attorneyCtx, donorSessionID, attorneyUID, isReplacement, isTrustCorporation) if err != nil { return err } @@ -205,7 +208,7 @@ func Attorney( for _, a := range list.Attorneys { ctx := page.ContextWithSessionData(r.Context(), &page.SessionData{SessionID: random.String(16), LpaID: donor.LpaID}) - attorney, err := attorneyStore.Create(ctx, donorSessionID, a.ID, isReplacement, false) + attorney, err := attorneyStore.Create(ctx, donorSessionID, a.UID, isReplacement, false) if err != nil { return err } @@ -225,7 +228,7 @@ func Attorney( if list.TrustCorporation.Name != "" { ctx := page.ContextWithSessionData(r.Context(), &page.SessionData{SessionID: random.String(16), LpaID: donor.LpaID}) - attorney, err := attorneyStore.Create(ctx, donorSessionID, "", isReplacement, true) + attorney, err := attorneyStore.Create(ctx, donorSessionID, list.TrustCorporation.UID, isReplacement, true) if err != nil { return err } diff --git a/internal/page/fixtures/dashboard.go b/internal/page/fixtures/dashboard.go index 1d708c99f6..fe8ae63d6a 100644 --- a/internal/page/fixtures/dashboard.go +++ b/internal/page/fixtures/dashboard.go @@ -109,7 +109,7 @@ func Dashboard( attorneyCtx := page.ContextWithSessionData(r.Context(), &page.SessionData{SessionID: meSessionID, LpaID: donor.LpaID}) - attorney, err := attorneyStore.Create(attorneyCtx, donorSessionID, donor.Attorneys.Attorneys[0].ID, false, false) + attorney, err := attorneyStore.Create(attorneyCtx, donorSessionID, donor.Attorneys.Attorneys[0].UID, false, false) if err != nil { return err } diff --git a/internal/page/fixtures/donor.go b/internal/page/fixtures/donor.go index 0d675e1f81..f7b44ca82f 100644 --- a/internal/page/fixtures/donor.go +++ b/internal/page/fixtures/donor.go @@ -3,6 +3,7 @@ package fixtures import ( "context" "encoding/base64" + "encoding/json" "log" "net/http" "slices" @@ -10,6 +11,7 @@ import ( "github.com/ministryofjustice/opg-go-common/template" "github.com/ministryofjustice/opg-modernising-lpa/internal/actor" + "github.com/ministryofjustice/opg-modernising-lpa/internal/actor/actoruid" "github.com/ministryofjustice/opg-modernising-lpa/internal/event" "github.com/ministryofjustice/opg-modernising-lpa/internal/form" "github.com/ministryofjustice/opg-modernising-lpa/internal/identity" @@ -144,13 +146,16 @@ func Donor( donorDetails.Tasks.YourDetails = actor.TaskCompleted } + var withoutAddressUID actoruid.UID + json.Unmarshal([]byte(`"urn:opg:poas:makeregister:users:without-address"`), &withoutAddressUID) + if progress >= slices.Index(progressValues, "chooseYourAttorneys") { donorDetails.Attorneys.Attorneys = []actor.Attorney{makeAttorney(attorneyNames[0]), makeAttorney(attorneyNames[1])} donorDetails.AttorneyDecisions.How = actor.JointlyAndSeverally switch attorneys { case "without-address": - donorDetails.Attorneys.Attorneys[1].ID = "without-address" + donorDetails.Attorneys.Attorneys[1].UID = withoutAddressUID donorDetails.Attorneys.Attorneys[1].Address = place.Address{} case "trust-corporation-without-address": donorDetails.Attorneys.TrustCorporation = makeTrustCorporation("First Choice Trust Corporation Ltd.") @@ -176,7 +181,7 @@ func Donor( switch replacementAttorneys { case "without-address": - donorDetails.ReplacementAttorneys.Attorneys[1].ID = "without-address" + donorDetails.ReplacementAttorneys.Attorneys[1].UID = withoutAddressUID donorDetails.ReplacementAttorneys.Attorneys[1].Address = place.Address{} case "trust-corporation-without-address": donorDetails.ReplacementAttorneys.TrustCorporation = makeTrustCorporation("First Choice Trust Corporation Ltd.") @@ -228,7 +233,7 @@ func Donor( donorDetails.PeopleToNotify = []actor.PersonToNotify{makePersonToNotify(peopleToNotifyNames[0]), makePersonToNotify(peopleToNotifyNames[1])} switch peopleToNotify { case "without-address": - donorDetails.PeopleToNotify[0].ID = "without-address" + donorDetails.PeopleToNotify[0].UID = withoutAddressUID donorDetails.PeopleToNotify[0].Address = place.Address{} case "max": donorDetails.PeopleToNotify = append(donorDetails.PeopleToNotify, makePersonToNotify(peopleToNotifyNames[2]), makePersonToNotify(peopleToNotifyNames[3]), makePersonToNotify(peopleToNotifyNames[4])) @@ -348,7 +353,7 @@ func Donor( for _, a := range list.Attorneys { ctx := page.ContextWithSessionData(r.Context(), &page.SessionData{SessionID: random.String(16), LpaID: donorDetails.LpaID}) - attorney, err := attorneyStore.Create(ctx, donorSessionID, a.ID, isReplacement, false) + attorney, err := attorneyStore.Create(ctx, donorSessionID, a.UID, isReplacement, false) if err != nil { return err } @@ -368,7 +373,7 @@ func Donor( if list.TrustCorporation.Name != "" { ctx := page.ContextWithSessionData(r.Context(), &page.SessionData{SessionID: random.String(16), LpaID: donorDetails.LpaID}) - attorney, err := attorneyStore.Create(ctx, donorSessionID, "", isReplacement, true) + attorney, err := attorneyStore.Create(ctx, donorSessionID, list.TrustCorporation.UID, isReplacement, true) if err != nil { return err } diff --git a/internal/page/fixtures/fixtures.go b/internal/page/fixtures/fixtures.go index fde6481dcc..eba55dacc0 100644 --- a/internal/page/fixtures/fixtures.go +++ b/internal/page/fixtures/fixtures.go @@ -5,6 +5,7 @@ import ( "strings" "github.com/ministryofjustice/opg-modernising-lpa/internal/actor" + "github.com/ministryofjustice/opg-modernising-lpa/internal/actor/actoruid" "github.com/ministryofjustice/opg-modernising-lpa/internal/date" "github.com/ministryofjustice/opg-modernising-lpa/internal/form" "github.com/ministryofjustice/opg-modernising-lpa/internal/page" @@ -60,7 +61,7 @@ var ( func makeAttorney(name Name) actor.Attorney { return actor.Attorney{ - ID: name.Firstnames + name.Lastname, + UID: actoruid.New(), FirstNames: name.Firstnames, LastName: name.Lastname, Email: testEmail, @@ -78,6 +79,7 @@ func makeAttorney(name Name) actor.Attorney { func makeTrustCorporation(name string) actor.TrustCorporation { return actor.TrustCorporation{ + UID: actoruid.New(), Name: name, CompanyNumber: "555555555", Email: testEmail, @@ -94,6 +96,7 @@ func makeTrustCorporation(name string) actor.TrustCorporation { func makeDonor() actor.Donor { return actor.Donor{ + UID: actoruid.New(), FirstNames: "Sam", LastName: "Smith", Address: place.Address{ @@ -113,6 +116,7 @@ func makeDonor() actor.Donor { func makeCertificateProvider() actor.CertificateProvider { return actor.CertificateProvider{ + UID: actoruid.New(), FirstNames: "Charlie", LastName: "Cooper", Email: testEmail, @@ -133,7 +137,7 @@ func makeCertificateProvider() actor.CertificateProvider { func makePersonToNotify(name Name) actor.PersonToNotify { return actor.PersonToNotify{ - ID: name.Firstnames + name.Lastname, + UID: actoruid.New(), FirstNames: name.Firstnames, LastName: name.Lastname, Address: place.Address{ diff --git a/internal/page/share_code.go b/internal/page/share_code.go index a4bfc46de1..ed7994a835 100644 --- a/internal/page/share_code.go +++ b/internal/page/share_code.go @@ -126,9 +126,9 @@ func (s *ShareCodeSender) sendOriginalAttorney(ctx context.Context, appData AppD AttorneyStartPageURL: fmt.Sprintf("%s%s", s.appPublicURL, Paths.Attorney.Start), }, actor.ShareCodeData{ - SessionID: appData.SessionID, - LpaID: appData.LpaID, - AttorneyID: attorney.ID, + SessionID: appData.SessionID, + LpaID: appData.LpaID, + AttorneyUID: attorney.UID, }, donor) } @@ -148,7 +148,7 @@ func (s *ShareCodeSender) sendReplacementAttorney(ctx context.Context, appData A }, actor.ShareCodeData{ SessionID: appData.SessionID, LpaID: appData.LpaID, - AttorneyID: attorney.ID, + AttorneyUID: attorney.UID, IsReplacementAttorney: true, }, donor) } diff --git a/internal/page/share_code_test.go b/internal/page/share_code_test.go index 4b82280ffd..fca72e7b89 100644 --- a/internal/page/share_code_test.go +++ b/internal/page/share_code_test.go @@ -7,6 +7,7 @@ import ( "testing" "github.com/ministryofjustice/opg-modernising-lpa/internal/actor" + "github.com/ministryofjustice/opg-modernising-lpa/internal/actor/actoruid" "github.com/ministryofjustice/opg-modernising-lpa/internal/event" "github.com/ministryofjustice/opg-modernising-lpa/internal/notify" "github.com/stretchr/testify/assert" @@ -512,6 +513,12 @@ func TestShareCodeSenderSendCertificateProviderPromptWhenShareCodeStoreErrors(t } func TestShareCodeSenderSendAttorneys(t *testing.T) { + uid1 := actoruid.New() + uid2 := actoruid.New() + uid3 := actoruid.New() + uid4 := actoruid.New() + uid5 := actoruid.New() + donor := &actor.DonorProvidedDetails{ Attorneys: actor.Attorneys{ TrustCorporation: actor.TrustCorporation{ @@ -520,19 +527,19 @@ func TestShareCodeSenderSendAttorneys(t *testing.T) { }, Attorneys: []actor.Attorney{ { - ID: "1", + UID: uid1, FirstNames: "Joanna", LastName: "Jones", Email: "name@example.org", }, { - ID: "2", + UID: uid2, FirstNames: "John", LastName: "Jones", Email: "name2@example.org", }, { - ID: "3", + UID: uid3, FirstNames: "Nope", LastName: "Jones", }, @@ -545,13 +552,13 @@ func TestShareCodeSenderSendAttorneys(t *testing.T) { }, Attorneys: []actor.Attorney{ { - ID: "4", + UID: uid4, FirstNames: "Dave", LastName: "Davis", Email: "dave@example.com", }, { - ID: "5", + UID: uid5, FirstNames: "Donny", LastName: "Davis", }, @@ -585,13 +592,13 @@ func TestShareCodeSenderSendAttorneys(t *testing.T) { Put(ctx, actor.TypeAttorney, RandomString, actor.ShareCodeData{SessionID: "session-id", LpaID: "lpa-id", IsTrustCorporation: true, IsReplacementAttorney: true}). Return(nil) shareCodeStore.EXPECT(). - Put(ctx, actor.TypeAttorney, RandomString, actor.ShareCodeData{SessionID: "session-id", LpaID: "lpa-id", AttorneyID: "1"}). + Put(ctx, actor.TypeAttorney, RandomString, actor.ShareCodeData{SessionID: "session-id", LpaID: "lpa-id", AttorneyUID: uid1}). Return(nil) shareCodeStore.EXPECT(). - Put(ctx, actor.TypeAttorney, RandomString, actor.ShareCodeData{SessionID: "session-id", LpaID: "lpa-id", AttorneyID: "2"}). + Put(ctx, actor.TypeAttorney, RandomString, actor.ShareCodeData{SessionID: "session-id", LpaID: "lpa-id", AttorneyUID: uid2}). Return(nil) shareCodeStore.EXPECT(). - Put(ctx, actor.TypeAttorney, RandomString, actor.ShareCodeData{SessionID: "session-id", LpaID: "lpa-id", AttorneyID: "4", IsReplacementAttorney: true}). + Put(ctx, actor.TypeAttorney, RandomString, actor.ShareCodeData{SessionID: "session-id", LpaID: "lpa-id", AttorneyUID: uid4, IsReplacementAttorney: true}). Return(nil) notifyClient := newMockNotifyClient(t) diff --git a/internal/templatefn/fn_test.go b/internal/templatefn/fn_test.go index 91b8ffe3b7..aa705a2faf 100644 --- a/internal/templatefn/fn_test.go +++ b/internal/templatefn/fn_test.go @@ -6,6 +6,7 @@ import ( "time" "github.com/ministryofjustice/opg-modernising-lpa/internal/actor" + "github.com/ministryofjustice/opg-modernising-lpa/internal/actor/actoruid" "github.com/ministryofjustice/opg-modernising-lpa/internal/date" "github.com/ministryofjustice/opg-modernising-lpa/internal/localize" "github.com/ministryofjustice/opg-modernising-lpa/internal/page" @@ -276,8 +277,8 @@ func TestFormatPhone(t *testing.T) { func TestListAttorneysWithAttorneys(t *testing.T) { trustCorporation := actor.TrustCorporation{Name: "a"} attorneys := []actor.Attorney{ - {ID: "123"}, - {ID: "123"}, + {UID: actoruid.New()}, + {UID: actoruid.New()}, } app := page.AppData{SessionID: "abc", Page: "/here", ActorType: actor.TypeDonor} @@ -308,8 +309,8 @@ func TestListAttorneysWithAttorneys(t *testing.T) { func TestListAttorneysWithReplacementAttorneys(t *testing.T) { trustCorporation := actor.TrustCorporation{Name: "a"} attorneys := []actor.Attorney{ - {ID: "123"}, - {ID: "123"}, + {UID: actoruid.New()}, + {UID: actoruid.New()}, } app := page.AppData{SessionID: "abc", Page: "/here"} diff --git a/web/template/donor/choose_address.gohtml b/web/template/donor/choose_address.gohtml index 7bcd5842d2..6ee9250e7a 100644 --- a/web/template/donor/choose_address.gohtml +++ b/web/template/donor/choose_address.gohtml @@ -79,7 +79,7 @@

- + {{ tr .App "cantFindTheirAddressInList" }}

@@ -119,7 +119,7 @@

- + {{ tr .App "enterAddressManually" }}

diff --git a/web/template/donor/you_cannot_sign_your_lpa_yet.gohtml b/web/template/donor/you_cannot_sign_your_lpa_yet.gohtml index 0a0f78e9d1..7478b14ae4 100644 --- a/web/template/donor/you_cannot_sign_your_lpa_yet.gohtml +++ b/web/template/donor/you_cannot_sign_your_lpa_yet.gohtml @@ -16,9 +16,9 @@
{{range $i, $actor := $actorsData }} - {{ $changeLink := printf "%s?id=%s" (link $.App (global.Paths.ChooseReplacementAttorneys.Format $.App.LpaID)) $actor.ID }} + {{ $changeLink := printf "%s?id=%s" (link $.App (global.Paths.ChooseReplacementAttorneys.Format $.App.LpaID)) $actor.UID }} {{ if eq global.ActorTypes.Attorney $actor.Type }} - {{ $changeLink = printf "%s?id=%s" (link $.App (global.Paths.ChooseAttorneys.Format $.App.LpaID)) $actor.ID }} + {{ $changeLink = printf "%s?id=%s" (link $.App (global.Paths.ChooseAttorneys.Format $.App.LpaID)) $actor.UID }} {{ end }}
diff --git a/web/template/layout/attorney-summary.gohtml b/web/template/layout/attorney-summary.gohtml index 5373d2a3b8..2ebc6bc09f 100644 --- a/web/template/layout/attorney-summary.gohtml +++ b/web/template/layout/attorney-summary.gohtml @@ -82,7 +82,7 @@ {{ if $.CanChange }} {{ end }} @@ -94,7 +94,7 @@
{{ .FullName }}
{{ if $.CanChange }}
- + {{ trFormatHtml $.App "changeNameLinkText" "FirstNames" .FirstNames "LastName" .LastName }}
@@ -105,7 +105,7 @@
{{ formatDate $.App .DateOfBirth }}
{{ if $.CanChange }}
- + {{ trFormatHtml $.App "changeDOBLinkText" "FirstNames" .FirstNames "LastName" .LastName }}
@@ -117,7 +117,7 @@
{{ .Email }}
{{ if $.CanChange }}
- + {{ trFormatHtml $.App "changeEmailLinkText" "FirstNames" .FirstNames "LastName" .LastName }}
@@ -129,7 +129,7 @@
{{ template "address-lines" .Address }}
{{ if $.CanChange }}
- + {{ trFormatHtml $.App "changeAddressLink" "FirstNames" .FirstNames "LastName" .LastName }}
diff --git a/web/template/layout/people-to-notify-summary.gohtml b/web/template/layout/people-to-notify-summary.gohtml index 5e9fc08456..6f64dae4a3 100644 --- a/web/template/layout/people-to-notify-summary.gohtml +++ b/web/template/layout/people-to-notify-summary.gohtml @@ -2,9 +2,9 @@ {{ $canChange := and (not $.Donor.Tasks.ConfirmYourIdentityAndSign.Completed) $.App.IsDonor }} {{ range .Donor.PeopleToNotify }} - {{ $detailsLink := printf "%s?from=%s&id=%s" (link $.App (global.Paths.ChoosePeopleToNotify.Format $.App.LpaID)) $.App.Page .ID }} - {{ $addressLink := printf "%s?from=%s&id=%s" (link $.App (global.Paths.ChoosePeopleToNotifyAddress.Format $.App.LpaID)) $.App.Page .ID }} - {{ $removeLink := printf "%s?from=%s&id=%s" (link $.App (global.Paths.RemovePersonToNotify.Format $.App.LpaID)) $.App.Page .ID }} + {{ $detailsLink := printf "%s?from=%s&id=%s" (link $.App (global.Paths.ChoosePeopleToNotify.Format $.App.LpaID)) $.App.Page .UID }} + {{ $addressLink := printf "%s?from=%s&id=%s" (link $.App (global.Paths.ChoosePeopleToNotifyAddress.Format $.App.LpaID)) $.App.Page .UID }} + {{ $removeLink := printf "%s?from=%s&id=%s" (link $.App (global.Paths.RemovePersonToNotify.Format $.App.LpaID)) $.App.Page .UID }}