From f914af0ced5c70e13c9ac5780dbb1661efd2a6b8 Mon Sep 17 00:00:00 2001 From: Joshua Hawxwell Date: Thu, 25 Jul 2024 09:56:00 +0100 Subject: [PATCH] Extract some packages from actor --- .mockery.yaml | 2 + internal/actor/attorney_provided.go | 73 +- internal/actor/enum_identitytask.go | 96 -- internal/actor/enum_paymenttask.go | 114 --- internal/actor/share_code_data.go | 24 +- internal/actor/task_state.go | 56 +- internal/actor/type.go | 81 +- internal/app/app.go | 3 +- internal/app/attorney_store.go | 93 +- internal/app/dashboard_store.go | 23 +- internal/appcontext/session_data.go | 32 + .../attorneydata/mock_DynamoClient_test.go | 877 ++++++++++++++++++ internal/attorney/attorneydata/mock_test.go | 100 ++ internal/attorney/attorneydata/provided.go | 80 ++ internal/attorney/attorneydata/store.go | 120 +++ .../attorneydata/store_test.go} | 92 +- .../confirm_dont_want_to_be_attorney.go | 63 ++ .../confirm_dont_want_to_be_attorney_test.go | 2 +- .../attorneypage/mock_AttorneyStore_test.go | 251 +++++ .../attorneypage/mock_Handler_test.go | 89 ++ .../attorneypage/mock_Localizer_test.go | 534 +++++++++++ .../mock_LpaStoreResolvingService_test.go | 95 ++ .../attorneypage/mock_NotifyClient_test.go | 86 ++ .../attorneypage/mock_Template_test.go | 83 ++ internal/attorney/attorneypage/mock_test.go | 52 ++ internal/attorney/attorneypage/register.go | 57 ++ .../confirm_dont_want_to_be_attorney.go | 60 +- .../page/attorney/mock_AttorneyStore_test.go | 52 +- .../page/attorney/mock_DashboardStore_test.go | 21 +- internal/page/attorney/mock_Localizer_test.go | 168 ++-- .../page/attorney/mock_LpaStoreClient_test.go | 65 +- .../page/attorney/mock_ShareCodeStore_test.go | 53 +- internal/page/attorney/register.go | 3 +- .../mock_CertificateProviderStore_test.go | 18 +- .../mock_DashboardStore_test.go | 21 +- .../certificateprovider/mock_Handler_test.go | 89 ++ .../mock_ShareCodeStore_test.go | 53 +- internal/page/data.go | 34 +- .../page/donor/mock_DashboardStore_test.go | 21 +- internal/page/donor/mock_DonorStore_test.go | 14 +- .../page/donor/mock_ShareCodeStore_test.go | 27 +- internal/page/fixtures/donor.go | 3 +- internal/page/mock_DashboardStore_test.go | 19 +- internal/page/mock_ShareCodeStore_test.go | 41 +- .../page/supporter/mock_DonorStore_test.go | 14 +- .../supporter/mock_ShareCodeStore_test.go | 41 +- internal/sharecode/data.go | 27 + internal/task/enum_identitystate.go | 96 ++ internal/task/enum_paymentstate.go | 114 +++ internal/task/state.go | 49 + internal/temporary/actor_type.go | 72 ++ internal/temporary/lpa_link.go | 30 + 52 files changed, 3397 insertions(+), 986 deletions(-) delete mode 100644 internal/actor/enum_identitytask.go delete mode 100644 internal/actor/enum_paymenttask.go create mode 100644 internal/appcontext/session_data.go create mode 100644 internal/attorney/attorneydata/mock_DynamoClient_test.go create mode 100644 internal/attorney/attorneydata/mock_test.go create mode 100644 internal/attorney/attorneydata/provided.go create mode 100644 internal/attorney/attorneydata/store.go rename internal/{app/attorney_store_test.go => attorney/attorneydata/store_test.go} (63%) create mode 100644 internal/attorney/attorneypage/confirm_dont_want_to_be_attorney.go rename internal/{page/attorney => attorney/attorneypage}/confirm_dont_want_to_be_attorney_test.go (99%) create mode 100644 internal/attorney/attorneypage/mock_AttorneyStore_test.go create mode 100644 internal/attorney/attorneypage/mock_Handler_test.go create mode 100644 internal/attorney/attorneypage/mock_Localizer_test.go create mode 100644 internal/attorney/attorneypage/mock_LpaStoreResolvingService_test.go create mode 100644 internal/attorney/attorneypage/mock_NotifyClient_test.go create mode 100644 internal/attorney/attorneypage/mock_Template_test.go create mode 100644 internal/attorney/attorneypage/mock_test.go create mode 100644 internal/attorney/attorneypage/register.go create mode 100644 internal/page/certificateprovider/mock_Handler_test.go create mode 100644 internal/sharecode/data.go create mode 100644 internal/task/enum_identitystate.go create mode 100644 internal/task/enum_paymentstate.go create mode 100644 internal/task/state.go create mode 100644 internal/temporary/actor_type.go create mode 100644 internal/temporary/lpa_link.go diff --git a/.mockery.yaml b/.mockery.yaml index fd5d43fb4e..6ae2a6573e 100644 --- a/.mockery.yaml +++ b/.mockery.yaml @@ -8,6 +8,8 @@ all: true packages: github.com/ministryofjustice/opg-modernising-lpa/cmd/event-received: github.com/ministryofjustice/opg-modernising-lpa/internal/app: + github.com/ministryofjustice/opg-modernising-lpa/internal/attorney/attorneydata: + github.com/ministryofjustice/opg-modernising-lpa/internal/attorney/attorneypage: github.com/ministryofjustice/opg-modernising-lpa/internal/dynamo: github.com/ministryofjustice/opg-modernising-lpa/internal/event: github.com/ministryofjustice/opg-modernising-lpa/internal/lambda: diff --git a/internal/actor/attorney_provided.go b/internal/actor/attorney_provided.go index 524ea26d93..13e02b76df 100644 --- a/internal/actor/attorney_provided.go +++ b/internal/actor/attorney_provided.go @@ -1,79 +1,14 @@ package actor import ( - "time" - - "github.com/ministryofjustice/opg-modernising-lpa/internal/actor/actoruid" - "github.com/ministryofjustice/opg-modernising-lpa/internal/dynamo" - "github.com/ministryofjustice/opg-modernising-lpa/internal/form" - "github.com/ministryofjustice/opg-modernising-lpa/internal/localize" + "github.com/ministryofjustice/opg-modernising-lpa/internal/attorney/attorneydata" ) // AttorneyProvidedDetails contains details about an attorney or replacement // attorney, provided by the attorney or replacement attorney -type AttorneyProvidedDetails struct { - PK dynamo.LpaKeyType - SK dynamo.AttorneyKeyType - // The identifier of the attorney or replacement attorney being edited - UID actoruid.UID - // The identifier of the LPA the attorney or replacement attorney is named in - LpaID string - // Tracking when AttorneyProvidedDetails is updated - UpdatedAt time.Time - // IsReplacement is true when the details relate to an attorney appointed as a - // replacement - IsReplacement bool - // IsTrustCorporation is true when the details relate to a trust corporation - IsTrustCorporation bool - // Mobile number of the attorney or replacement attorney - Mobile string - // SignedAt is when the attorney or replacement attorney submitted their - // signature - SignedAt time.Time - // WouldLikeSecondSignatory captures whether two signatories will be used for - // a trust corporation - WouldLikeSecondSignatory form.YesNo - // AuthorisedSignatories captures the details of the person who signed on - // behalf of a trust corporation, if one is acting as an attorney - AuthorisedSignatories [2]TrustCorporationSignatory - // Used to show attorney task list - Tasks AttorneyTasks - // ContactLanguagePreference is the language the attorney or replacement - // attorney prefers to receive notifications in - ContactLanguagePreference localize.Lang - // Email is the email address returned from OneLogin when the attorney logged in - Email string -} - -// Signed checks whether the attorney has confirmed and if that confirmation is -// still valid by checking that it was made for the donor's current signature. -func (d AttorneyProvidedDetails) Signed() bool { - if d.IsTrustCorporation { - switch d.WouldLikeSecondSignatory { - case form.Yes: - return !d.AuthorisedSignatories[0].SignedAt.IsZero() && - !d.AuthorisedSignatories[1].SignedAt.IsZero() - case form.No: - return !d.AuthorisedSignatories[0].SignedAt.IsZero() - default: - return false - } - } - - return !d.SignedAt.IsZero() -} +type AttorneyProvidedDetails = attorneydata.Provided -type AttorneyTasks struct { - ConfirmYourDetails TaskState - ReadTheLpa TaskState - SignTheLpa TaskState - SignTheLpaSecond TaskState -} +type AttorneyTasks = attorneydata.Tasks // TrustCorporationSignatory contains the details of a person who signed the LPA on behalf of a trust corporation -type TrustCorporationSignatory struct { - FirstNames string - LastName string - ProfessionalTitle string - SignedAt time.Time -} +type TrustCorporationSignatory = attorneydata.TrustCorporationSignatory diff --git a/internal/actor/enum_identitytask.go b/internal/actor/enum_identitytask.go deleted file mode 100644 index 1fd1f596ef..0000000000 --- a/internal/actor/enum_identitytask.go +++ /dev/null @@ -1,96 +0,0 @@ -// Code generated by "enumerator -type IdentityTask -trimprefix"; DO NOT EDIT. -package actor - -import ( - "fmt" - "strconv" -) - -func _() { - // An "invalid array index" compiler error signifies that the constant values have changed. - // Re-run the stringer command to generate them again. - var x [1]struct{} - _ = x[IdentityTaskNotStarted-0] - _ = x[IdentityTaskInProgress-1] - _ = x[IdentityTaskPending-2] - _ = x[IdentityTaskProblem-3] - _ = x[IdentityTaskCompleted-4] -} - -const _IdentityTask_name = "NotStartedInProgressPendingProblemCompleted" - -var _IdentityTask_index = [...]uint8{0, 10, 20, 27, 34, 43} - -func (i IdentityTask) String() string { - if i >= IdentityTask(len(_IdentityTask_index)-1) { - return "IdentityTask(" + strconv.FormatInt(int64(i), 10) + ")" - } - return _IdentityTask_name[_IdentityTask_index[i]:_IdentityTask_index[i+1]] -} - -func (i IdentityTask) MarshalText() ([]byte, error) { - return []byte(i.String()), nil -} - -func (i *IdentityTask) UnmarshalText(text []byte) error { - val, err := ParseIdentityTask(string(text)) - if err != nil { - return err - } - - *i = val - return nil -} - -func (i IdentityTask) IsNotStarted() bool { - return i == IdentityTaskNotStarted -} - -func (i IdentityTask) IsInProgress() bool { - return i == IdentityTaskInProgress -} - -func (i IdentityTask) IsPending() bool { - return i == IdentityTaskPending -} - -func (i IdentityTask) IsProblem() bool { - return i == IdentityTaskProblem -} - -func (i IdentityTask) IsCompleted() bool { - return i == IdentityTaskCompleted -} - -func ParseIdentityTask(s string) (IdentityTask, error) { - switch s { - case "NotStarted": - return IdentityTaskNotStarted, nil - case "InProgress": - return IdentityTaskInProgress, nil - case "Pending": - return IdentityTaskPending, nil - case "Problem": - return IdentityTaskProblem, nil - case "Completed": - return IdentityTaskCompleted, nil - default: - return IdentityTask(0), fmt.Errorf("invalid IdentityTask '%s'", s) - } -} - -type IdentityTaskOptions struct { - NotStarted IdentityTask - InProgress IdentityTask - Pending IdentityTask - Problem IdentityTask - Completed IdentityTask -} - -var IdentityTaskValues = IdentityTaskOptions{ - NotStarted: IdentityTaskNotStarted, - InProgress: IdentityTaskInProgress, - Pending: IdentityTaskPending, - Problem: IdentityTaskProblem, - Completed: IdentityTaskCompleted, -} diff --git a/internal/actor/enum_paymenttask.go b/internal/actor/enum_paymenttask.go deleted file mode 100644 index e55efd28ea..0000000000 --- a/internal/actor/enum_paymenttask.go +++ /dev/null @@ -1,114 +0,0 @@ -// Code generated by "enumerator -type PaymentTask -trimprefix"; DO NOT EDIT. -package actor - -import ( - "fmt" - "strconv" -) - -func _() { - // An "invalid array index" compiler error signifies that the constant values have changed. - // Re-run the stringer command to generate them again. - var x [1]struct{} - _ = x[PaymentTaskNotStarted-0] - _ = x[PaymentTaskInProgress-1] - _ = x[PaymentTaskPending-2] - _ = x[PaymentTaskApproved-3] - _ = x[PaymentTaskDenied-4] - _ = x[PaymentTaskMoreEvidenceRequired-5] - _ = x[PaymentTaskCompleted-6] -} - -const _PaymentTask_name = "NotStartedInProgressPendingApprovedDeniedMoreEvidenceRequiredCompleted" - -var _PaymentTask_index = [...]uint8{0, 10, 20, 27, 35, 41, 61, 70} - -func (i PaymentTask) String() string { - if i >= PaymentTask(len(_PaymentTask_index)-1) { - return "PaymentTask(" + strconv.FormatInt(int64(i), 10) + ")" - } - return _PaymentTask_name[_PaymentTask_index[i]:_PaymentTask_index[i+1]] -} - -func (i PaymentTask) MarshalText() ([]byte, error) { - return []byte(i.String()), nil -} - -func (i *PaymentTask) UnmarshalText(text []byte) error { - val, err := ParsePaymentTask(string(text)) - if err != nil { - return err - } - - *i = val - return nil -} - -func (i PaymentTask) IsNotStarted() bool { - return i == PaymentTaskNotStarted -} - -func (i PaymentTask) IsInProgress() bool { - return i == PaymentTaskInProgress -} - -func (i PaymentTask) IsPending() bool { - return i == PaymentTaskPending -} - -func (i PaymentTask) IsApproved() bool { - return i == PaymentTaskApproved -} - -func (i PaymentTask) IsDenied() bool { - return i == PaymentTaskDenied -} - -func (i PaymentTask) IsMoreEvidenceRequired() bool { - return i == PaymentTaskMoreEvidenceRequired -} - -func (i PaymentTask) IsCompleted() bool { - return i == PaymentTaskCompleted -} - -func ParsePaymentTask(s string) (PaymentTask, error) { - switch s { - case "NotStarted": - return PaymentTaskNotStarted, nil - case "InProgress": - return PaymentTaskInProgress, nil - case "Pending": - return PaymentTaskPending, nil - case "Approved": - return PaymentTaskApproved, nil - case "Denied": - return PaymentTaskDenied, nil - case "MoreEvidenceRequired": - return PaymentTaskMoreEvidenceRequired, nil - case "Completed": - return PaymentTaskCompleted, nil - default: - return PaymentTask(0), fmt.Errorf("invalid PaymentTask '%s'", s) - } -} - -type PaymentTaskOptions struct { - NotStarted PaymentTask - InProgress PaymentTask - Pending PaymentTask - Approved PaymentTask - Denied PaymentTask - MoreEvidenceRequired PaymentTask - Completed PaymentTask -} - -var PaymentTaskValues = PaymentTaskOptions{ - NotStarted: PaymentTaskNotStarted, - InProgress: PaymentTaskInProgress, - Pending: PaymentTaskPending, - Approved: PaymentTaskApproved, - Denied: PaymentTaskDenied, - MoreEvidenceRequired: PaymentTaskMoreEvidenceRequired, - Completed: PaymentTaskCompleted, -} diff --git a/internal/actor/share_code_data.go b/internal/actor/share_code_data.go index 491d105857..96f0a56347 100644 --- a/internal/actor/share_code_data.go +++ b/internal/actor/share_code_data.go @@ -1,27 +1,7 @@ package actor import ( - "time" - - "github.com/ministryofjustice/opg-modernising-lpa/internal/actor/actoruid" - "github.com/ministryofjustice/opg-modernising-lpa/internal/dynamo" + "github.com/ministryofjustice/opg-modernising-lpa/internal/sharecode" ) -type ShareCodeData struct { - PK dynamo.ShareKeyType - SK dynamo.ShareSortKeyType - UpdatedAt time.Time - LpaKey dynamo.LpaKeyType - LpaOwnerKey dynamo.LpaOwnerKeyType - ActorUID actoruid.UID - IsReplacementAttorney bool - IsTrustCorporation bool - - // InviteSentTo is the email address the supporter sent the invite to - InviteSentTo string - // LpaLinkedAt is the time the donor entered the access code - LpaLinkedAt time.Time - // LpaLinkedTo is set to the email address the donor used to sign-in when - // using the code - LpaLinkedTo string -} +type ShareCodeData = sharecode.ShareCodeData diff --git a/internal/actor/task_state.go b/internal/actor/task_state.go index b6a2d44933..a9b88a1e60 100644 --- a/internal/actor/task_state.go +++ b/internal/actor/task_state.go @@ -1,49 +1,33 @@ package actor -type TaskState uint8 +import "github.com/ministryofjustice/opg-modernising-lpa/internal/task" + +type TaskState = task.State const ( - TaskNotStarted TaskState = iota - TaskInProgress - TaskCompleted + TaskNotStarted = task.NotStarted + TaskInProgress = task.InProgress + TaskCompleted = task.Completed ) -func (t TaskState) NotStarted() bool { return t == TaskNotStarted } -func (t TaskState) InProgress() bool { return t == TaskInProgress } -func (t TaskState) Completed() bool { return t == TaskCompleted } - -func (t TaskState) String() string { - switch t { - case TaskNotStarted: - return "notStarted" - case TaskInProgress: - return "inProgress" - case TaskCompleted: - return "completed" - } - return "" -} - -//go:generate enumerator -type PaymentTask -trimprefix -type PaymentTask uint8 +type PaymentTask = task.PaymentState const ( - PaymentTaskNotStarted PaymentTask = iota - PaymentTaskInProgress - PaymentTaskPending - PaymentTaskApproved - PaymentTaskDenied - PaymentTaskMoreEvidenceRequired - PaymentTaskCompleted + PaymentTaskNotStarted = task.PaymentStateNotStarted + PaymentTaskInProgress = task.PaymentStateInProgress + PaymentTaskPending = task.PaymentStatePending + PaymentTaskApproved = task.PaymentStateApproved + PaymentTaskDenied = task.PaymentStateDenied + PaymentTaskMoreEvidenceRequired = task.PaymentStateMoreEvidenceRequired + PaymentTaskCompleted = task.PaymentStateCompleted ) -//go:generate enumerator -type IdentityTask -trimprefix -type IdentityTask uint8 +type IdentityTask = task.IdentityState const ( - IdentityTaskNotStarted IdentityTask = iota - IdentityTaskInProgress - IdentityTaskPending - IdentityTaskProblem - IdentityTaskCompleted + IdentityTaskNotStarted = task.IdentityStateNotStarted + IdentityTaskInProgress = task.IdentityStateInProgress + IdentityTaskPending = task.IdentityStatePending + IdentityTaskProblem = task.IdentityStateProblem + IdentityTaskCompleted = task.IdentityStateCompleted ) diff --git a/internal/actor/type.go b/internal/actor/type.go index 35b9449e21..c1b03fd7d2 100644 --- a/internal/actor/type.go +++ b/internal/actor/type.go @@ -1,72 +1,23 @@ package actor -type Type uint8 +import "github.com/ministryofjustice/opg-modernising-lpa/internal/temporary" + +type Type = temporary.ActorType const ( - TypeNone Type = iota - TypeDonor - TypeAttorney - TypeReplacementAttorney - TypeCertificateProvider - TypePersonToNotify - TypeAuthorisedSignatory - TypeIndependentWitness - TypeTrustCorporation - TypeReplacementTrustCorporation - TypeVoucher + TypeNone = temporary.ActorTypeNone + TypeDonor = temporary.ActorTypeDonor + TypeAttorney = temporary.ActorTypeAttorney + TypeReplacementAttorney = temporary.ActorTypeReplacementAttorney + TypeCertificateProvider = temporary.ActorTypeCertificateProvider + TypePersonToNotify = temporary.ActorTypePersonToNotify + TypeAuthorisedSignatory = temporary.ActorTypeAuthorisedSignatory + TypeIndependentWitness = temporary.ActorTypeIndependentWitness + TypeTrustCorporation = temporary.ActorTypeTrustCorporation + TypeReplacementTrustCorporation = temporary.ActorTypeReplacementTrustCorporation + TypeVoucher = temporary.ActorTypeVoucher ) -func (t Type) String() string { - switch t { - case TypeDonor: - return "donor" - case TypeAttorney: - return "attorney" - case TypeReplacementAttorney: - return "replacementAttorney" - case TypeCertificateProvider: - return "certificateProvider" - case TypePersonToNotify: - return "personToNotify" - case TypeAuthorisedSignatory: - return "signatory" - case TypeIndependentWitness: - return "independentWitness" - case TypeTrustCorporation: - return "trustCorporation" - case TypeReplacementTrustCorporation: - return "replacementTrustCorporation" - case TypeVoucher: - return "voucher" - default: - return "" - } -} - -type Types struct { - None Type - Donor Type - Attorney Type - ReplacementAttorney Type - TrustCorporation Type - ReplacementTrustCorporation Type - CertificateProvider Type - PersonToNotify Type - AuthorisedSignatory Type - IndependentWitness Type - Voucher Type -} +type Types = temporary.Types -var ActorTypes = Types{ - None: TypeNone, - Donor: TypeDonor, - Attorney: TypeAttorney, - ReplacementAttorney: TypeReplacementAttorney, - TrustCorporation: TypeTrustCorporation, - ReplacementTrustCorporation: TypeReplacementTrustCorporation, - CertificateProvider: TypeCertificateProvider, - PersonToNotify: TypePersonToNotify, - AuthorisedSignatory: TypeAuthorisedSignatory, - IndependentWitness: TypeIndependentWitness, - Voucher: TypeVoucher, -} +var ActorTypes = temporary.ActorTypes diff --git a/internal/app/app.go b/internal/app/app.go index 53987bf905..faf6556ce8 100644 --- a/internal/app/app.go +++ b/internal/app/app.go @@ -11,6 +11,7 @@ import ( "github.com/google/uuid" "github.com/ministryofjustice/opg-go-common/template" "github.com/ministryofjustice/opg-modernising-lpa/internal/actor/actoruid" + "github.com/ministryofjustice/opg-modernising-lpa/internal/attorney/attorneydata" "github.com/ministryofjustice/opg-modernising-lpa/internal/dynamo" "github.com/ministryofjustice/opg-modernising-lpa/internal/event" "github.com/ministryofjustice/opg-modernising-lpa/internal/localize" @@ -99,7 +100,7 @@ func App( searchClient: searchClient, } certificateProviderStore := &certificateProviderStore{dynamoClient: lpaDynamoClient, now: time.Now} - attorneyStore := &attorneyStore{dynamoClient: lpaDynamoClient, now: time.Now} + attorneyStore := attorneydata.NewStore(lpaDynamoClient, time.Now) shareCodeStore := &shareCodeStore{dynamoClient: lpaDynamoClient, now: time.Now} dashboardStore := &dashboardStore{dynamoClient: lpaDynamoClient, lpaStoreResolvingService: lpastore.NewResolvingService(donorStore, lpaStoreClient)} evidenceReceivedStore := &evidenceReceivedStore{dynamoClient: lpaDynamoClient} diff --git a/internal/app/attorney_store.go b/internal/app/attorney_store.go index 9708d8c0c4..15973460d7 100644 --- a/internal/app/attorney_store.go +++ b/internal/app/attorney_store.go @@ -1,94 +1,5 @@ package app -import ( - "context" - "errors" - "fmt" - "time" +import "github.com/ministryofjustice/opg-modernising-lpa/internal/attorney/attorneydata" - "github.com/ministryofjustice/opg-modernising-lpa/internal/actor" - "github.com/ministryofjustice/opg-modernising-lpa/internal/dynamo" - "github.com/ministryofjustice/opg-modernising-lpa/internal/page" -) - -type attorneyStore struct { - dynamoClient DynamoClient - now func() time.Time -} - -func (s *attorneyStore) Create(ctx context.Context, shareCode actor.ShareCodeData, email string) (*actor.AttorneyProvidedDetails, error) { - data, err := page.SessionDataFromContext(ctx) - if err != nil { - return nil, err - } - - if data.LpaID == "" || data.SessionID == "" { - return nil, errors.New("attorneyStore.Create requires LpaID and SessionID") - } - - attorney := &actor.AttorneyProvidedDetails{ - PK: dynamo.LpaKey(data.LpaID), - SK: dynamo.AttorneyKey(data.SessionID), - UID: shareCode.ActorUID, - LpaID: data.LpaID, - UpdatedAt: s.now(), - IsReplacement: shareCode.IsReplacementAttorney, - IsTrustCorporation: shareCode.IsTrustCorporation, - Email: email, - } - - transaction := dynamo.NewTransaction(). - Create(attorney). - Create(lpaLink{ - PK: dynamo.LpaKey(data.LpaID), - SK: dynamo.SubKey(data.SessionID), - DonorKey: shareCode.LpaOwnerKey, - ActorType: actor.TypeAttorney, - UpdatedAt: s.now(), - }). - Delete(dynamo.Keys{PK: shareCode.PK, SK: shareCode.SK}) - - if err := s.dynamoClient.WriteTransaction(ctx, transaction); err != nil { - return nil, err - } - - return attorney, err -} - -func (s *attorneyStore) Get(ctx context.Context) (*actor.AttorneyProvidedDetails, error) { - data, err := page.SessionDataFromContext(ctx) - if err != nil { - return nil, err - } - - if data.LpaID == "" || data.SessionID == "" { - return nil, errors.New("attorneyStore.Get requires LpaID and SessionID") - } - - var attorney actor.AttorneyProvidedDetails - err = s.dynamoClient.One(ctx, dynamo.LpaKey(data.LpaID), dynamo.AttorneyKey(data.SessionID), &attorney) - - return &attorney, err -} - -func (s *attorneyStore) Put(ctx context.Context, attorney *actor.AttorneyProvidedDetails) error { - attorney.UpdatedAt = s.now() - return s.dynamoClient.Put(ctx, attorney) -} - -func (s *attorneyStore) Delete(ctx context.Context) error { - data, err := page.SessionDataFromContext(ctx) - if err != nil { - return err - } - - if data.LpaID == "" || data.SessionID == "" { - return errors.New("attorneyStore.Delete requires LpaID and SessionID") - } - - if err := s.dynamoClient.DeleteOne(ctx, dynamo.LpaKey(data.LpaID), dynamo.AttorneyKey(data.SessionID)); err != nil { - return fmt.Errorf("error deleting attorney: %w", err) - } - - return nil -} +type attorneyStore = attorneydata.Store diff --git a/internal/app/dashboard_store.go b/internal/app/dashboard_store.go index 53873e677d..db93319978 100644 --- a/internal/app/dashboard_store.go +++ b/internal/app/dashboard_store.go @@ -5,13 +5,13 @@ import ( "errors" "slices" "strings" - "time" "github.com/aws/aws-sdk-go-v2/feature/dynamodb/attributevalue" "github.com/ministryofjustice/opg-modernising-lpa/internal/actor" "github.com/ministryofjustice/opg-modernising-lpa/internal/dynamo" "github.com/ministryofjustice/opg-modernising-lpa/internal/lpastore" "github.com/ministryofjustice/opg-modernising-lpa/internal/page" + "github.com/ministryofjustice/opg-modernising-lpa/internal/temporary" ) type LpaStoreResolvingService interface { @@ -19,26 +19,7 @@ type LpaStoreResolvingService interface { } // An lpaLink is used to join an actor to an LPA. -type lpaLink struct { - // PK is the same as the PK for the LPA - PK dynamo.LpaKeyType - // SK is the subKey for the current user - SK dynamo.SubKeyType - // DonorKey is the donorKey for the donor - DonorKey dynamo.LpaOwnerKeyType - // ActorType is the type for the current user - ActorType actor.Type - // UpdatedAt is set to allow this data to be queried from SKUpdatedAtIndex - UpdatedAt time.Time -} - -func (l lpaLink) UserSub() string { - if l.SK == "" { - return "" - } - - return strings.Split(l.SK.SK(), dynamo.SubKey("").SK())[1] -} +type lpaLink = temporary.LpaLink type dashboardStore struct { dynamoClient DynamoClient diff --git a/internal/appcontext/session_data.go b/internal/appcontext/session_data.go new file mode 100644 index 0000000000..86f86d7ed8 --- /dev/null +++ b/internal/appcontext/session_data.go @@ -0,0 +1,32 @@ +package appcontext + +import "context" + +type SessionData struct { + SessionID string + LpaID string + + // if a supporter + Email string + OrganisationID string +} + +type SessionMissingError struct{} + +func (s SessionMissingError) Error() string { + return "Session data not set" +} + +func SessionDataFromContext(ctx context.Context) (*SessionData, error) { + data, ok := ctx.Value((*SessionData)(nil)).(*SessionData) + + if !ok { + return nil, SessionMissingError{} + } + + return data, nil +} + +func ContextWithSessionData(ctx context.Context, data *SessionData) context.Context { + return context.WithValue(ctx, (*SessionData)(nil), data) +} diff --git a/internal/attorney/attorneydata/mock_DynamoClient_test.go b/internal/attorney/attorneydata/mock_DynamoClient_test.go new file mode 100644 index 0000000000..f3344ed43d --- /dev/null +++ b/internal/attorney/attorneydata/mock_DynamoClient_test.go @@ -0,0 +1,877 @@ +// Code generated by mockery v2.42.2. DO NOT EDIT. + +package attorneydata + +import ( + context "context" + + dynamo "github.com/ministryofjustice/opg-modernising-lpa/internal/dynamo" + mock "github.com/stretchr/testify/mock" + + types "github.com/aws/aws-sdk-go-v2/service/dynamodb/types" +) + +// mockDynamoClient is an autogenerated mock type for the DynamoClient type +type mockDynamoClient struct { + mock.Mock +} + +type mockDynamoClient_Expecter struct { + mock *mock.Mock +} + +func (_m *mockDynamoClient) EXPECT() *mockDynamoClient_Expecter { + return &mockDynamoClient_Expecter{mock: &_m.Mock} +} + +// AllByKeys provides a mock function with given fields: ctx, keys +func (_m *mockDynamoClient) AllByKeys(ctx context.Context, keys []dynamo.Keys) ([]map[string]types.AttributeValue, error) { + ret := _m.Called(ctx, keys) + + if len(ret) == 0 { + panic("no return value specified for AllByKeys") + } + + var r0 []map[string]types.AttributeValue + var r1 error + if rf, ok := ret.Get(0).(func(context.Context, []dynamo.Keys) ([]map[string]types.AttributeValue, error)); ok { + return rf(ctx, keys) + } + if rf, ok := ret.Get(0).(func(context.Context, []dynamo.Keys) []map[string]types.AttributeValue); ok { + r0 = rf(ctx, keys) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).([]map[string]types.AttributeValue) + } + } + + if rf, ok := ret.Get(1).(func(context.Context, []dynamo.Keys) error); ok { + r1 = rf(ctx, keys) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// mockDynamoClient_AllByKeys_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'AllByKeys' +type mockDynamoClient_AllByKeys_Call struct { + *mock.Call +} + +// AllByKeys is a helper method to define mock.On call +// - ctx context.Context +// - keys []dynamo.Keys +func (_e *mockDynamoClient_Expecter) AllByKeys(ctx interface{}, keys interface{}) *mockDynamoClient_AllByKeys_Call { + return &mockDynamoClient_AllByKeys_Call{Call: _e.mock.On("AllByKeys", ctx, keys)} +} + +func (_c *mockDynamoClient_AllByKeys_Call) Run(run func(ctx context.Context, keys []dynamo.Keys)) *mockDynamoClient_AllByKeys_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context), args[1].([]dynamo.Keys)) + }) + return _c +} + +func (_c *mockDynamoClient_AllByKeys_Call) Return(_a0 []map[string]types.AttributeValue, _a1 error) *mockDynamoClient_AllByKeys_Call { + _c.Call.Return(_a0, _a1) + return _c +} + +func (_c *mockDynamoClient_AllByKeys_Call) RunAndReturn(run func(context.Context, []dynamo.Keys) ([]map[string]types.AttributeValue, error)) *mockDynamoClient_AllByKeys_Call { + _c.Call.Return(run) + return _c +} + +// AllByPartialSK provides a mock function with given fields: ctx, pk, partialSK, v +func (_m *mockDynamoClient) AllByPartialSK(ctx context.Context, pk dynamo.PK, partialSK dynamo.SK, v interface{}) error { + ret := _m.Called(ctx, pk, partialSK, v) + + if len(ret) == 0 { + panic("no return value specified for AllByPartialSK") + } + + var r0 error + if rf, ok := ret.Get(0).(func(context.Context, dynamo.PK, dynamo.SK, interface{}) error); ok { + r0 = rf(ctx, pk, partialSK, v) + } else { + r0 = ret.Error(0) + } + + return r0 +} + +// mockDynamoClient_AllByPartialSK_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'AllByPartialSK' +type mockDynamoClient_AllByPartialSK_Call struct { + *mock.Call +} + +// AllByPartialSK is a helper method to define mock.On call +// - ctx context.Context +// - pk dynamo.PK +// - partialSK dynamo.SK +// - v interface{} +func (_e *mockDynamoClient_Expecter) AllByPartialSK(ctx interface{}, pk interface{}, partialSK interface{}, v interface{}) *mockDynamoClient_AllByPartialSK_Call { + return &mockDynamoClient_AllByPartialSK_Call{Call: _e.mock.On("AllByPartialSK", ctx, pk, partialSK, v)} +} + +func (_c *mockDynamoClient_AllByPartialSK_Call) Run(run func(ctx context.Context, pk dynamo.PK, partialSK dynamo.SK, v interface{})) *mockDynamoClient_AllByPartialSK_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context), args[1].(dynamo.PK), args[2].(dynamo.SK), args[3].(interface{})) + }) + return _c +} + +func (_c *mockDynamoClient_AllByPartialSK_Call) Return(_a0 error) *mockDynamoClient_AllByPartialSK_Call { + _c.Call.Return(_a0) + return _c +} + +func (_c *mockDynamoClient_AllByPartialSK_Call) RunAndReturn(run func(context.Context, dynamo.PK, dynamo.SK, interface{}) error) *mockDynamoClient_AllByPartialSK_Call { + _c.Call.Return(run) + return _c +} + +// AllBySK provides a mock function with given fields: ctx, sk, v +func (_m *mockDynamoClient) AllBySK(ctx context.Context, sk dynamo.SK, v interface{}) error { + ret := _m.Called(ctx, sk, v) + + if len(ret) == 0 { + panic("no return value specified for AllBySK") + } + + var r0 error + if rf, ok := ret.Get(0).(func(context.Context, dynamo.SK, interface{}) error); ok { + r0 = rf(ctx, sk, v) + } else { + r0 = ret.Error(0) + } + + return r0 +} + +// mockDynamoClient_AllBySK_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'AllBySK' +type mockDynamoClient_AllBySK_Call struct { + *mock.Call +} + +// AllBySK is a helper method to define mock.On call +// - ctx context.Context +// - sk dynamo.SK +// - v interface{} +func (_e *mockDynamoClient_Expecter) AllBySK(ctx interface{}, sk interface{}, v interface{}) *mockDynamoClient_AllBySK_Call { + return &mockDynamoClient_AllBySK_Call{Call: _e.mock.On("AllBySK", ctx, sk, v)} +} + +func (_c *mockDynamoClient_AllBySK_Call) Run(run func(ctx context.Context, sk dynamo.SK, v interface{})) *mockDynamoClient_AllBySK_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context), args[1].(dynamo.SK), args[2].(interface{})) + }) + return _c +} + +func (_c *mockDynamoClient_AllBySK_Call) Return(_a0 error) *mockDynamoClient_AllBySK_Call { + _c.Call.Return(_a0) + return _c +} + +func (_c *mockDynamoClient_AllBySK_Call) RunAndReturn(run func(context.Context, dynamo.SK, interface{}) error) *mockDynamoClient_AllBySK_Call { + _c.Call.Return(run) + return _c +} + +// AllKeysByPK provides a mock function with given fields: ctx, pk +func (_m *mockDynamoClient) AllKeysByPK(ctx context.Context, pk dynamo.PK) ([]dynamo.Keys, error) { + ret := _m.Called(ctx, pk) + + if len(ret) == 0 { + panic("no return value specified for AllKeysByPK") + } + + var r0 []dynamo.Keys + var r1 error + if rf, ok := ret.Get(0).(func(context.Context, dynamo.PK) ([]dynamo.Keys, error)); ok { + return rf(ctx, pk) + } + if rf, ok := ret.Get(0).(func(context.Context, dynamo.PK) []dynamo.Keys); ok { + r0 = rf(ctx, pk) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).([]dynamo.Keys) + } + } + + if rf, ok := ret.Get(1).(func(context.Context, dynamo.PK) error); ok { + r1 = rf(ctx, pk) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// mockDynamoClient_AllKeysByPK_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'AllKeysByPK' +type mockDynamoClient_AllKeysByPK_Call struct { + *mock.Call +} + +// AllKeysByPK is a helper method to define mock.On call +// - ctx context.Context +// - pk dynamo.PK +func (_e *mockDynamoClient_Expecter) AllKeysByPK(ctx interface{}, pk interface{}) *mockDynamoClient_AllKeysByPK_Call { + return &mockDynamoClient_AllKeysByPK_Call{Call: _e.mock.On("AllKeysByPK", ctx, pk)} +} + +func (_c *mockDynamoClient_AllKeysByPK_Call) Run(run func(ctx context.Context, pk dynamo.PK)) *mockDynamoClient_AllKeysByPK_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context), args[1].(dynamo.PK)) + }) + return _c +} + +func (_c *mockDynamoClient_AllKeysByPK_Call) Return(_a0 []dynamo.Keys, _a1 error) *mockDynamoClient_AllKeysByPK_Call { + _c.Call.Return(_a0, _a1) + return _c +} + +func (_c *mockDynamoClient_AllKeysByPK_Call) RunAndReturn(run func(context.Context, dynamo.PK) ([]dynamo.Keys, error)) *mockDynamoClient_AllKeysByPK_Call { + _c.Call.Return(run) + return _c +} + +// BatchPut provides a mock function with given fields: ctx, items +func (_m *mockDynamoClient) BatchPut(ctx context.Context, items []interface{}) error { + ret := _m.Called(ctx, items) + + if len(ret) == 0 { + panic("no return value specified for BatchPut") + } + + var r0 error + if rf, ok := ret.Get(0).(func(context.Context, []interface{}) error); ok { + r0 = rf(ctx, items) + } else { + r0 = ret.Error(0) + } + + return r0 +} + +// mockDynamoClient_BatchPut_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'BatchPut' +type mockDynamoClient_BatchPut_Call struct { + *mock.Call +} + +// BatchPut is a helper method to define mock.On call +// - ctx context.Context +// - items []interface{} +func (_e *mockDynamoClient_Expecter) BatchPut(ctx interface{}, items interface{}) *mockDynamoClient_BatchPut_Call { + return &mockDynamoClient_BatchPut_Call{Call: _e.mock.On("BatchPut", ctx, items)} +} + +func (_c *mockDynamoClient_BatchPut_Call) Run(run func(ctx context.Context, items []interface{})) *mockDynamoClient_BatchPut_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context), args[1].([]interface{})) + }) + return _c +} + +func (_c *mockDynamoClient_BatchPut_Call) Return(_a0 error) *mockDynamoClient_BatchPut_Call { + _c.Call.Return(_a0) + return _c +} + +func (_c *mockDynamoClient_BatchPut_Call) RunAndReturn(run func(context.Context, []interface{}) error) *mockDynamoClient_BatchPut_Call { + _c.Call.Return(run) + return _c +} + +// Create provides a mock function with given fields: ctx, v +func (_m *mockDynamoClient) Create(ctx context.Context, v interface{}) error { + ret := _m.Called(ctx, v) + + if len(ret) == 0 { + panic("no return value specified for Create") + } + + var r0 error + if rf, ok := ret.Get(0).(func(context.Context, interface{}) error); ok { + r0 = rf(ctx, v) + } else { + r0 = ret.Error(0) + } + + return r0 +} + +// mockDynamoClient_Create_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'Create' +type mockDynamoClient_Create_Call struct { + *mock.Call +} + +// Create is a helper method to define mock.On call +// - ctx context.Context +// - v interface{} +func (_e *mockDynamoClient_Expecter) Create(ctx interface{}, v interface{}) *mockDynamoClient_Create_Call { + return &mockDynamoClient_Create_Call{Call: _e.mock.On("Create", ctx, v)} +} + +func (_c *mockDynamoClient_Create_Call) Run(run func(ctx context.Context, v interface{})) *mockDynamoClient_Create_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context), args[1].(interface{})) + }) + return _c +} + +func (_c *mockDynamoClient_Create_Call) Return(_a0 error) *mockDynamoClient_Create_Call { + _c.Call.Return(_a0) + return _c +} + +func (_c *mockDynamoClient_Create_Call) RunAndReturn(run func(context.Context, interface{}) error) *mockDynamoClient_Create_Call { + _c.Call.Return(run) + return _c +} + +// DeleteKeys provides a mock function with given fields: ctx, keys +func (_m *mockDynamoClient) DeleteKeys(ctx context.Context, keys []dynamo.Keys) error { + ret := _m.Called(ctx, keys) + + if len(ret) == 0 { + panic("no return value specified for DeleteKeys") + } + + var r0 error + if rf, ok := ret.Get(0).(func(context.Context, []dynamo.Keys) error); ok { + r0 = rf(ctx, keys) + } else { + r0 = ret.Error(0) + } + + return r0 +} + +// mockDynamoClient_DeleteKeys_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'DeleteKeys' +type mockDynamoClient_DeleteKeys_Call struct { + *mock.Call +} + +// DeleteKeys is a helper method to define mock.On call +// - ctx context.Context +// - keys []dynamo.Keys +func (_e *mockDynamoClient_Expecter) DeleteKeys(ctx interface{}, keys interface{}) *mockDynamoClient_DeleteKeys_Call { + return &mockDynamoClient_DeleteKeys_Call{Call: _e.mock.On("DeleteKeys", ctx, keys)} +} + +func (_c *mockDynamoClient_DeleteKeys_Call) Run(run func(ctx context.Context, keys []dynamo.Keys)) *mockDynamoClient_DeleteKeys_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context), args[1].([]dynamo.Keys)) + }) + return _c +} + +func (_c *mockDynamoClient_DeleteKeys_Call) Return(_a0 error) *mockDynamoClient_DeleteKeys_Call { + _c.Call.Return(_a0) + return _c +} + +func (_c *mockDynamoClient_DeleteKeys_Call) RunAndReturn(run func(context.Context, []dynamo.Keys) error) *mockDynamoClient_DeleteKeys_Call { + _c.Call.Return(run) + return _c +} + +// DeleteOne provides a mock function with given fields: ctx, pk, sk +func (_m *mockDynamoClient) DeleteOne(ctx context.Context, pk dynamo.PK, sk dynamo.SK) error { + ret := _m.Called(ctx, pk, sk) + + if len(ret) == 0 { + panic("no return value specified for DeleteOne") + } + + var r0 error + if rf, ok := ret.Get(0).(func(context.Context, dynamo.PK, dynamo.SK) error); ok { + r0 = rf(ctx, pk, sk) + } else { + r0 = ret.Error(0) + } + + return r0 +} + +// mockDynamoClient_DeleteOne_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'DeleteOne' +type mockDynamoClient_DeleteOne_Call struct { + *mock.Call +} + +// DeleteOne is a helper method to define mock.On call +// - ctx context.Context +// - pk dynamo.PK +// - sk dynamo.SK +func (_e *mockDynamoClient_Expecter) DeleteOne(ctx interface{}, pk interface{}, sk interface{}) *mockDynamoClient_DeleteOne_Call { + return &mockDynamoClient_DeleteOne_Call{Call: _e.mock.On("DeleteOne", ctx, pk, sk)} +} + +func (_c *mockDynamoClient_DeleteOne_Call) Run(run func(ctx context.Context, pk dynamo.PK, sk dynamo.SK)) *mockDynamoClient_DeleteOne_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context), args[1].(dynamo.PK), args[2].(dynamo.SK)) + }) + return _c +} + +func (_c *mockDynamoClient_DeleteOne_Call) Return(_a0 error) *mockDynamoClient_DeleteOne_Call { + _c.Call.Return(_a0) + return _c +} + +func (_c *mockDynamoClient_DeleteOne_Call) RunAndReturn(run func(context.Context, dynamo.PK, dynamo.SK) error) *mockDynamoClient_DeleteOne_Call { + _c.Call.Return(run) + return _c +} + +// LatestForActor provides a mock function with given fields: ctx, sk, v +func (_m *mockDynamoClient) LatestForActor(ctx context.Context, sk dynamo.SK, v interface{}) error { + ret := _m.Called(ctx, sk, v) + + if len(ret) == 0 { + panic("no return value specified for LatestForActor") + } + + var r0 error + if rf, ok := ret.Get(0).(func(context.Context, dynamo.SK, interface{}) error); ok { + r0 = rf(ctx, sk, v) + } else { + r0 = ret.Error(0) + } + + return r0 +} + +// mockDynamoClient_LatestForActor_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'LatestForActor' +type mockDynamoClient_LatestForActor_Call struct { + *mock.Call +} + +// LatestForActor is a helper method to define mock.On call +// - ctx context.Context +// - sk dynamo.SK +// - v interface{} +func (_e *mockDynamoClient_Expecter) LatestForActor(ctx interface{}, sk interface{}, v interface{}) *mockDynamoClient_LatestForActor_Call { + return &mockDynamoClient_LatestForActor_Call{Call: _e.mock.On("LatestForActor", ctx, sk, v)} +} + +func (_c *mockDynamoClient_LatestForActor_Call) Run(run func(ctx context.Context, sk dynamo.SK, v interface{})) *mockDynamoClient_LatestForActor_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context), args[1].(dynamo.SK), args[2].(interface{})) + }) + return _c +} + +func (_c *mockDynamoClient_LatestForActor_Call) Return(_a0 error) *mockDynamoClient_LatestForActor_Call { + _c.Call.Return(_a0) + return _c +} + +func (_c *mockDynamoClient_LatestForActor_Call) RunAndReturn(run func(context.Context, dynamo.SK, interface{}) error) *mockDynamoClient_LatestForActor_Call { + _c.Call.Return(run) + return _c +} + +// One provides a mock function with given fields: ctx, pk, sk, v +func (_m *mockDynamoClient) One(ctx context.Context, pk dynamo.PK, sk dynamo.SK, v interface{}) error { + ret := _m.Called(ctx, pk, sk, v) + + if len(ret) == 0 { + panic("no return value specified for One") + } + + var r0 error + if rf, ok := ret.Get(0).(func(context.Context, dynamo.PK, dynamo.SK, interface{}) error); ok { + r0 = rf(ctx, pk, sk, v) + } else { + r0 = ret.Error(0) + } + + return r0 +} + +// mockDynamoClient_One_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'One' +type mockDynamoClient_One_Call struct { + *mock.Call +} + +// One is a helper method to define mock.On call +// - ctx context.Context +// - pk dynamo.PK +// - sk dynamo.SK +// - v interface{} +func (_e *mockDynamoClient_Expecter) One(ctx interface{}, pk interface{}, sk interface{}, v interface{}) *mockDynamoClient_One_Call { + return &mockDynamoClient_One_Call{Call: _e.mock.On("One", ctx, pk, sk, v)} +} + +func (_c *mockDynamoClient_One_Call) Run(run func(ctx context.Context, pk dynamo.PK, sk dynamo.SK, v interface{})) *mockDynamoClient_One_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context), args[1].(dynamo.PK), args[2].(dynamo.SK), args[3].(interface{})) + }) + return _c +} + +func (_c *mockDynamoClient_One_Call) Return(_a0 error) *mockDynamoClient_One_Call { + _c.Call.Return(_a0) + return _c +} + +func (_c *mockDynamoClient_One_Call) RunAndReturn(run func(context.Context, dynamo.PK, dynamo.SK, interface{}) error) *mockDynamoClient_One_Call { + _c.Call.Return(run) + return _c +} + +// OneByPK provides a mock function with given fields: ctx, pk, v +func (_m *mockDynamoClient) OneByPK(ctx context.Context, pk dynamo.PK, v interface{}) error { + ret := _m.Called(ctx, pk, v) + + if len(ret) == 0 { + panic("no return value specified for OneByPK") + } + + var r0 error + if rf, ok := ret.Get(0).(func(context.Context, dynamo.PK, interface{}) error); ok { + r0 = rf(ctx, pk, v) + } else { + r0 = ret.Error(0) + } + + return r0 +} + +// mockDynamoClient_OneByPK_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'OneByPK' +type mockDynamoClient_OneByPK_Call struct { + *mock.Call +} + +// OneByPK is a helper method to define mock.On call +// - ctx context.Context +// - pk dynamo.PK +// - v interface{} +func (_e *mockDynamoClient_Expecter) OneByPK(ctx interface{}, pk interface{}, v interface{}) *mockDynamoClient_OneByPK_Call { + return &mockDynamoClient_OneByPK_Call{Call: _e.mock.On("OneByPK", ctx, pk, v)} +} + +func (_c *mockDynamoClient_OneByPK_Call) Run(run func(ctx context.Context, pk dynamo.PK, v interface{})) *mockDynamoClient_OneByPK_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context), args[1].(dynamo.PK), args[2].(interface{})) + }) + return _c +} + +func (_c *mockDynamoClient_OneByPK_Call) Return(_a0 error) *mockDynamoClient_OneByPK_Call { + _c.Call.Return(_a0) + return _c +} + +func (_c *mockDynamoClient_OneByPK_Call) RunAndReturn(run func(context.Context, dynamo.PK, interface{}) error) *mockDynamoClient_OneByPK_Call { + _c.Call.Return(run) + return _c +} + +// OneByPartialSK provides a mock function with given fields: ctx, pk, partialSK, v +func (_m *mockDynamoClient) OneByPartialSK(ctx context.Context, pk dynamo.PK, partialSK dynamo.SK, v interface{}) error { + ret := _m.Called(ctx, pk, partialSK, v) + + if len(ret) == 0 { + panic("no return value specified for OneByPartialSK") + } + + var r0 error + if rf, ok := ret.Get(0).(func(context.Context, dynamo.PK, dynamo.SK, interface{}) error); ok { + r0 = rf(ctx, pk, partialSK, v) + } else { + r0 = ret.Error(0) + } + + return r0 +} + +// mockDynamoClient_OneByPartialSK_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'OneByPartialSK' +type mockDynamoClient_OneByPartialSK_Call struct { + *mock.Call +} + +// OneByPartialSK is a helper method to define mock.On call +// - ctx context.Context +// - pk dynamo.PK +// - partialSK dynamo.SK +// - v interface{} +func (_e *mockDynamoClient_Expecter) OneByPartialSK(ctx interface{}, pk interface{}, partialSK interface{}, v interface{}) *mockDynamoClient_OneByPartialSK_Call { + return &mockDynamoClient_OneByPartialSK_Call{Call: _e.mock.On("OneByPartialSK", ctx, pk, partialSK, v)} +} + +func (_c *mockDynamoClient_OneByPartialSK_Call) Run(run func(ctx context.Context, pk dynamo.PK, partialSK dynamo.SK, v interface{})) *mockDynamoClient_OneByPartialSK_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context), args[1].(dynamo.PK), args[2].(dynamo.SK), args[3].(interface{})) + }) + return _c +} + +func (_c *mockDynamoClient_OneByPartialSK_Call) Return(_a0 error) *mockDynamoClient_OneByPartialSK_Call { + _c.Call.Return(_a0) + return _c +} + +func (_c *mockDynamoClient_OneByPartialSK_Call) RunAndReturn(run func(context.Context, dynamo.PK, dynamo.SK, interface{}) error) *mockDynamoClient_OneByPartialSK_Call { + _c.Call.Return(run) + return _c +} + +// OneBySK provides a mock function with given fields: ctx, sk, v +func (_m *mockDynamoClient) OneBySK(ctx context.Context, sk dynamo.SK, v interface{}) error { + ret := _m.Called(ctx, sk, v) + + if len(ret) == 0 { + panic("no return value specified for OneBySK") + } + + var r0 error + if rf, ok := ret.Get(0).(func(context.Context, dynamo.SK, interface{}) error); ok { + r0 = rf(ctx, sk, v) + } else { + r0 = ret.Error(0) + } + + return r0 +} + +// mockDynamoClient_OneBySK_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'OneBySK' +type mockDynamoClient_OneBySK_Call struct { + *mock.Call +} + +// OneBySK is a helper method to define mock.On call +// - ctx context.Context +// - sk dynamo.SK +// - v interface{} +func (_e *mockDynamoClient_Expecter) OneBySK(ctx interface{}, sk interface{}, v interface{}) *mockDynamoClient_OneBySK_Call { + return &mockDynamoClient_OneBySK_Call{Call: _e.mock.On("OneBySK", ctx, sk, v)} +} + +func (_c *mockDynamoClient_OneBySK_Call) Run(run func(ctx context.Context, sk dynamo.SK, v interface{})) *mockDynamoClient_OneBySK_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context), args[1].(dynamo.SK), args[2].(interface{})) + }) + return _c +} + +func (_c *mockDynamoClient_OneBySK_Call) Return(_a0 error) *mockDynamoClient_OneBySK_Call { + _c.Call.Return(_a0) + return _c +} + +func (_c *mockDynamoClient_OneBySK_Call) RunAndReturn(run func(context.Context, dynamo.SK, interface{}) error) *mockDynamoClient_OneBySK_Call { + _c.Call.Return(run) + return _c +} + +// OneByUID provides a mock function with given fields: ctx, uid, v +func (_m *mockDynamoClient) OneByUID(ctx context.Context, uid string, v interface{}) error { + ret := _m.Called(ctx, uid, v) + + if len(ret) == 0 { + panic("no return value specified for OneByUID") + } + + var r0 error + if rf, ok := ret.Get(0).(func(context.Context, string, interface{}) error); ok { + r0 = rf(ctx, uid, v) + } else { + r0 = ret.Error(0) + } + + return r0 +} + +// mockDynamoClient_OneByUID_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'OneByUID' +type mockDynamoClient_OneByUID_Call struct { + *mock.Call +} + +// OneByUID is a helper method to define mock.On call +// - ctx context.Context +// - uid string +// - v interface{} +func (_e *mockDynamoClient_Expecter) OneByUID(ctx interface{}, uid interface{}, v interface{}) *mockDynamoClient_OneByUID_Call { + return &mockDynamoClient_OneByUID_Call{Call: _e.mock.On("OneByUID", ctx, uid, v)} +} + +func (_c *mockDynamoClient_OneByUID_Call) Run(run func(ctx context.Context, uid string, v interface{})) *mockDynamoClient_OneByUID_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context), args[1].(string), args[2].(interface{})) + }) + return _c +} + +func (_c *mockDynamoClient_OneByUID_Call) Return(_a0 error) *mockDynamoClient_OneByUID_Call { + _c.Call.Return(_a0) + return _c +} + +func (_c *mockDynamoClient_OneByUID_Call) RunAndReturn(run func(context.Context, string, interface{}) error) *mockDynamoClient_OneByUID_Call { + _c.Call.Return(run) + return _c +} + +// Put provides a mock function with given fields: ctx, v +func (_m *mockDynamoClient) Put(ctx context.Context, v interface{}) error { + ret := _m.Called(ctx, v) + + if len(ret) == 0 { + panic("no return value specified for Put") + } + + var r0 error + if rf, ok := ret.Get(0).(func(context.Context, interface{}) error); ok { + r0 = rf(ctx, v) + } else { + r0 = ret.Error(0) + } + + return r0 +} + +// mockDynamoClient_Put_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'Put' +type mockDynamoClient_Put_Call struct { + *mock.Call +} + +// Put is a helper method to define mock.On call +// - ctx context.Context +// - v interface{} +func (_e *mockDynamoClient_Expecter) Put(ctx interface{}, v interface{}) *mockDynamoClient_Put_Call { + return &mockDynamoClient_Put_Call{Call: _e.mock.On("Put", ctx, v)} +} + +func (_c *mockDynamoClient_Put_Call) Run(run func(ctx context.Context, v interface{})) *mockDynamoClient_Put_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context), args[1].(interface{})) + }) + return _c +} + +func (_c *mockDynamoClient_Put_Call) Return(_a0 error) *mockDynamoClient_Put_Call { + _c.Call.Return(_a0) + return _c +} + +func (_c *mockDynamoClient_Put_Call) RunAndReturn(run func(context.Context, interface{}) error) *mockDynamoClient_Put_Call { + _c.Call.Return(run) + return _c +} + +// Update provides a mock function with given fields: ctx, pk, sk, values, expression +func (_m *mockDynamoClient) Update(ctx context.Context, pk dynamo.PK, sk dynamo.SK, values map[string]types.AttributeValue, expression string) error { + ret := _m.Called(ctx, pk, sk, values, expression) + + if len(ret) == 0 { + panic("no return value specified for Update") + } + + var r0 error + if rf, ok := ret.Get(0).(func(context.Context, dynamo.PK, dynamo.SK, map[string]types.AttributeValue, string) error); ok { + r0 = rf(ctx, pk, sk, values, expression) + } else { + r0 = ret.Error(0) + } + + return r0 +} + +// mockDynamoClient_Update_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'Update' +type mockDynamoClient_Update_Call struct { + *mock.Call +} + +// Update is a helper method to define mock.On call +// - ctx context.Context +// - pk dynamo.PK +// - sk dynamo.SK +// - values map[string]types.AttributeValue +// - expression string +func (_e *mockDynamoClient_Expecter) Update(ctx interface{}, pk interface{}, sk interface{}, values interface{}, expression interface{}) *mockDynamoClient_Update_Call { + return &mockDynamoClient_Update_Call{Call: _e.mock.On("Update", ctx, pk, sk, values, expression)} +} + +func (_c *mockDynamoClient_Update_Call) Run(run func(ctx context.Context, pk dynamo.PK, sk dynamo.SK, values map[string]types.AttributeValue, expression string)) *mockDynamoClient_Update_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context), args[1].(dynamo.PK), args[2].(dynamo.SK), args[3].(map[string]types.AttributeValue), args[4].(string)) + }) + return _c +} + +func (_c *mockDynamoClient_Update_Call) Return(_a0 error) *mockDynamoClient_Update_Call { + _c.Call.Return(_a0) + return _c +} + +func (_c *mockDynamoClient_Update_Call) RunAndReturn(run func(context.Context, dynamo.PK, dynamo.SK, map[string]types.AttributeValue, string) error) *mockDynamoClient_Update_Call { + _c.Call.Return(run) + return _c +} + +// WriteTransaction provides a mock function with given fields: ctx, transaction +func (_m *mockDynamoClient) WriteTransaction(ctx context.Context, transaction *dynamo.Transaction) error { + ret := _m.Called(ctx, transaction) + + if len(ret) == 0 { + panic("no return value specified for WriteTransaction") + } + + var r0 error + if rf, ok := ret.Get(0).(func(context.Context, *dynamo.Transaction) error); ok { + r0 = rf(ctx, transaction) + } else { + r0 = ret.Error(0) + } + + return r0 +} + +// mockDynamoClient_WriteTransaction_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'WriteTransaction' +type mockDynamoClient_WriteTransaction_Call struct { + *mock.Call +} + +// WriteTransaction is a helper method to define mock.On call +// - ctx context.Context +// - transaction *dynamo.Transaction +func (_e *mockDynamoClient_Expecter) WriteTransaction(ctx interface{}, transaction interface{}) *mockDynamoClient_WriteTransaction_Call { + return &mockDynamoClient_WriteTransaction_Call{Call: _e.mock.On("WriteTransaction", ctx, transaction)} +} + +func (_c *mockDynamoClient_WriteTransaction_Call) Run(run func(ctx context.Context, transaction *dynamo.Transaction)) *mockDynamoClient_WriteTransaction_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context), args[1].(*dynamo.Transaction)) + }) + return _c +} + +func (_c *mockDynamoClient_WriteTransaction_Call) Return(_a0 error) *mockDynamoClient_WriteTransaction_Call { + _c.Call.Return(_a0) + return _c +} + +func (_c *mockDynamoClient_WriteTransaction_Call) RunAndReturn(run func(context.Context, *dynamo.Transaction) error) *mockDynamoClient_WriteTransaction_Call { + _c.Call.Return(run) + return _c +} + +// newMockDynamoClient creates a new instance of mockDynamoClient. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations. +// The first argument is typically a *testing.T value. +func newMockDynamoClient(t interface { + mock.TestingT + Cleanup(func()) +}) *mockDynamoClient { + mock := &mockDynamoClient{} + mock.Mock.Test(t) + + t.Cleanup(func() { mock.AssertExpectations(t) }) + + return mock +} diff --git a/internal/attorney/attorneydata/mock_test.go b/internal/attorney/attorneydata/mock_test.go new file mode 100644 index 0000000000..8e8edbe2b7 --- /dev/null +++ b/internal/attorney/attorneydata/mock_test.go @@ -0,0 +1,100 @@ +package attorneydata + +import ( + context "context" + "encoding/json" + "errors" + "time" + + types "github.com/aws/aws-sdk-go-v2/service/dynamodb/types" + "github.com/ministryofjustice/opg-modernising-lpa/internal/actor/actoruid" + dynamo "github.com/ministryofjustice/opg-modernising-lpa/internal/dynamo" + mock "github.com/stretchr/testify/mock" +) + +var ( + ctx = context.Background() + 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) { + m. + On("One", ctx, pk, sk, mock.Anything). + Return(func(ctx context.Context, pk dynamo.PK, partialSk dynamo.SK, v interface{}) error { + b, _ := json.Marshal(data) + json.Unmarshal(b, v) + return err + }). + Once() +} + +func (m *mockDynamoClient) ExpectOneByPK(ctx, pk, data interface{}, err error) { + m. + On("OneByPK", ctx, pk, mock.Anything). + Return(func(ctx context.Context, pk dynamo.PK, v interface{}) error { + b, _ := json.Marshal(data) + json.Unmarshal(b, v) + return err + }). + Once() +} + +func (m *mockDynamoClient) ExpectOneByPartialSK(ctx, pk, partialSk, data interface{}, err error) { + m. + On("OneByPartialSK", ctx, pk, partialSk, mock.Anything). + Return(func(ctx context.Context, pk dynamo.PK, partialSk dynamo.SK, v interface{}) error { + b, _ := json.Marshal(data) + json.Unmarshal(b, v) + return err + }) +} + +func (m *mockDynamoClient) ExpectAllByPartialSK(ctx, pk, partialSk, data interface{}, err error) { + m. + On("AllByPartialSK", ctx, pk, partialSk, mock.Anything). + Return(func(ctx context.Context, pk dynamo.PK, partialSk dynamo.SK, v interface{}) error { + b, _ := json.Marshal(data) + json.Unmarshal(b, v) + return err + }) +} + +func (m *mockDynamoClient) ExpectAllBySK(ctx, sk, data interface{}, err error) { + m. + On("AllBySK", ctx, sk, mock.Anything). + Return(func(ctx context.Context, sk dynamo.SK, v interface{}) error { + b, _ := json.Marshal(data) + json.Unmarshal(b, v) + return err + }) +} + +func (m *mockDynamoClient) ExpectLatestForActor(ctx, sk, data interface{}, err error) { + m. + On("LatestForActor", ctx, sk, mock.Anything). + Return(func(ctx context.Context, sk dynamo.SK, v interface{}) error { + b, _ := json.Marshal(data) + json.Unmarshal(b, v) + return err + }) +} + +func (m *mockDynamoClient) ExpectAllByKeys(ctx context.Context, keys []dynamo.Keys, data []map[string]types.AttributeValue, err error) { + m.EXPECT(). + AllByKeys(ctx, keys). + Return(data, err) +} + +func (m *mockDynamoClient) ExpectOneBySK(ctx, sk, data interface{}, err error) { + m. + On("OneBySK", ctx, sk, mock.Anything). + Return(func(ctx context.Context, sk dynamo.SK, v interface{}) error { + b, _ := json.Marshal(data) + json.Unmarshal(b, v) + return err + }) +} diff --git a/internal/attorney/attorneydata/provided.go b/internal/attorney/attorneydata/provided.go new file mode 100644 index 0000000000..9528430eaf --- /dev/null +++ b/internal/attorney/attorneydata/provided.go @@ -0,0 +1,80 @@ +package attorneydata + +import ( + "time" + + "github.com/ministryofjustice/opg-modernising-lpa/internal/actor/actoruid" + "github.com/ministryofjustice/opg-modernising-lpa/internal/dynamo" + "github.com/ministryofjustice/opg-modernising-lpa/internal/form" + "github.com/ministryofjustice/opg-modernising-lpa/internal/localize" + "github.com/ministryofjustice/opg-modernising-lpa/internal/task" +) + +// Provided contains details about an attorney or replacement +// attorney, provided by the attorney or replacement attorney +type Provided struct { + PK dynamo.LpaKeyType + SK dynamo.AttorneyKeyType + // The identifier of the attorney or replacement attorney being edited + UID actoruid.UID + // The identifier of the LPA the attorney or replacement attorney is named in + LpaID string + // Tracking when AttorneyProvidedDetails is updated + UpdatedAt time.Time + // IsReplacement is true when the details relate to an attorney appointed as a + // replacement + IsReplacement bool + // IsTrustCorporation is true when the details relate to a trust corporation + IsTrustCorporation bool + // Mobile number of the attorney or replacement attorney + Mobile string + // SignedAt is when the attorney or replacement attorney submitted their + // signature + SignedAt time.Time + // WouldLikeSecondSignatory captures whether two signatories will be used for + // a trust corporation + WouldLikeSecondSignatory form.YesNo + // AuthorisedSignatories captures the details of the person who signed on + // behalf of a trust corporation, if one is acting as an attorney + AuthorisedSignatories [2]TrustCorporationSignatory + // Used to show attorney task list + Tasks Tasks + // ContactLanguagePreference is the language the attorney or replacement + // attorney prefers to receive notifications in + ContactLanguagePreference localize.Lang + // Email is the email address returned from OneLogin when the attorney logged in + Email string +} + +// Signed checks whether the attorney has confirmed and if that confirmation is +// still valid by checking that it was made for the donor's current signature. +func (d Provided) Signed() bool { + if d.IsTrustCorporation { + switch d.WouldLikeSecondSignatory { + case form.Yes: + return !d.AuthorisedSignatories[0].SignedAt.IsZero() && + !d.AuthorisedSignatories[1].SignedAt.IsZero() + case form.No: + return !d.AuthorisedSignatories[0].SignedAt.IsZero() + default: + return false + } + } + + return !d.SignedAt.IsZero() +} + +type Tasks struct { + ConfirmYourDetails task.State + ReadTheLpa task.State + SignTheLpa task.State + SignTheLpaSecond task.State +} + +// TrustCorporationSignatory contains the details of a person who signed the LPA on behalf of a trust corporation +type TrustCorporationSignatory struct { + FirstNames string + LastName string + ProfessionalTitle string + SignedAt time.Time +} diff --git a/internal/attorney/attorneydata/store.go b/internal/attorney/attorneydata/store.go new file mode 100644 index 0000000000..d9d23b4be0 --- /dev/null +++ b/internal/attorney/attorneydata/store.go @@ -0,0 +1,120 @@ +package attorneydata + +import ( + "context" + "errors" + "fmt" + "time" + + dynamodbtypes "github.com/aws/aws-sdk-go-v2/service/dynamodb/types" + "github.com/ministryofjustice/opg-modernising-lpa/internal/appcontext" + "github.com/ministryofjustice/opg-modernising-lpa/internal/dynamo" + "github.com/ministryofjustice/opg-modernising-lpa/internal/sharecode" + "github.com/ministryofjustice/opg-modernising-lpa/internal/temporary" +) + +type DynamoClient interface { + One(ctx context.Context, pk dynamo.PK, sk dynamo.SK, v interface{}) error + OneByPK(ctx context.Context, pk dynamo.PK, v interface{}) error + OneByPartialSK(ctx context.Context, pk dynamo.PK, partialSK dynamo.SK, v interface{}) error + AllByPartialSK(ctx context.Context, pk dynamo.PK, partialSK dynamo.SK, v interface{}) error + LatestForActor(ctx context.Context, sk dynamo.SK, v interface{}) error + AllBySK(ctx context.Context, sk dynamo.SK, v interface{}) error + AllByKeys(ctx context.Context, keys []dynamo.Keys) ([]map[string]dynamodbtypes.AttributeValue, error) + AllKeysByPK(ctx context.Context, pk dynamo.PK) ([]dynamo.Keys, error) + Put(ctx context.Context, v interface{}) error + Create(ctx context.Context, v interface{}) error + DeleteKeys(ctx context.Context, keys []dynamo.Keys) error + DeleteOne(ctx context.Context, pk dynamo.PK, sk dynamo.SK) error + Update(ctx context.Context, pk dynamo.PK, sk dynamo.SK, values map[string]dynamodbtypes.AttributeValue, expression string) error + BatchPut(ctx context.Context, items []interface{}) error + OneBySK(ctx context.Context, sk dynamo.SK, v interface{}) error + OneByUID(ctx context.Context, uid string, v interface{}) error + WriteTransaction(ctx context.Context, transaction *dynamo.Transaction) error +} + +type Store struct { + dynamoClient DynamoClient + now func() time.Time +} + +func NewStore(dynamoClient DynamoClient, now func() time.Time) *Store { + return &Store{dynamoClient: dynamoClient, now: now} +} + +func (s *Store) Create(ctx context.Context, shareCode sharecode.ShareCodeData, email string) (*Provided, error) { + data, err := appcontext.SessionDataFromContext(ctx) + if err != nil { + return nil, err + } + + if data.LpaID == "" || data.SessionID == "" { + return nil, errors.New("attorneyStore.Create requires LpaID and SessionID") + } + + attorney := &Provided{ + PK: dynamo.LpaKey(data.LpaID), + SK: dynamo.AttorneyKey(data.SessionID), + UID: shareCode.ActorUID, + LpaID: data.LpaID, + UpdatedAt: s.now(), + IsReplacement: shareCode.IsReplacementAttorney, + IsTrustCorporation: shareCode.IsTrustCorporation, + Email: email, + } + + transaction := dynamo.NewTransaction(). + Create(attorney). + Create(temporary.LpaLink{ + PK: dynamo.LpaKey(data.LpaID), + SK: dynamo.SubKey(data.SessionID), + DonorKey: shareCode.LpaOwnerKey, + ActorType: temporary.ActorTypeAttorney, + UpdatedAt: s.now(), + }). + Delete(dynamo.Keys{PK: shareCode.PK, SK: shareCode.SK}) + + if err := s.dynamoClient.WriteTransaction(ctx, transaction); err != nil { + return nil, err + } + + return attorney, err +} + +func (s *Store) Get(ctx context.Context) (*Provided, error) { + data, err := appcontext.SessionDataFromContext(ctx) + if err != nil { + return nil, err + } + + if data.LpaID == "" || data.SessionID == "" { + return nil, errors.New("attorneyStore.Get requires LpaID and SessionID") + } + + var attorney Provided + err = s.dynamoClient.One(ctx, dynamo.LpaKey(data.LpaID), dynamo.AttorneyKey(data.SessionID), &attorney) + + return &attorney, err +} + +func (s *Store) Put(ctx context.Context, attorney *Provided) error { + attorney.UpdatedAt = s.now() + return s.dynamoClient.Put(ctx, attorney) +} + +func (s *Store) Delete(ctx context.Context) error { + data, err := appcontext.SessionDataFromContext(ctx) + if err != nil { + return err + } + + if data.LpaID == "" || data.SessionID == "" { + return errors.New("attorneyStore.Delete requires LpaID and SessionID") + } + + if err := s.dynamoClient.DeleteOne(ctx, dynamo.LpaKey(data.LpaID), dynamo.AttorneyKey(data.SessionID)); err != nil { + return fmt.Errorf("error deleting attorney: %w", err) + } + + return nil +} diff --git a/internal/app/attorney_store_test.go b/internal/attorney/attorneydata/store_test.go similarity index 63% rename from internal/app/attorney_store_test.go rename to internal/attorney/attorneydata/store_test.go index b0cb4e1151..f2213274c1 100644 --- a/internal/app/attorney_store_test.go +++ b/internal/attorney/attorneydata/store_test.go @@ -1,4 +1,4 @@ -package app +package attorneydata import ( "context" @@ -7,10 +7,11 @@ import ( "testing" "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/appcontext" "github.com/ministryofjustice/opg-modernising-lpa/internal/dynamo" - "github.com/ministryofjustice/opg-modernising-lpa/internal/page" + "github.com/ministryofjustice/opg-modernising-lpa/internal/sharecode" + "github.com/ministryofjustice/opg-modernising-lpa/internal/temporary" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/mock" ) @@ -28,10 +29,10 @@ func TestAttorneyStoreCreate(t *testing.T) { for name, tc := range testcases { t.Run(name, func(t *testing.T) { - ctx := page.ContextWithSessionData(context.Background(), &page.SessionData{LpaID: "123", SessionID: "456"}) + ctx := appcontext.ContextWithSessionData(context.Background(), &appcontext.SessionData{LpaID: "123", SessionID: "456"}) now := time.Now() uid := actoruid.New() - details := &actor.AttorneyProvidedDetails{ + details := &Provided{ PK: dynamo.LpaKey("123"), SK: dynamo.AttorneyKey("456"), UID: uid, @@ -42,7 +43,7 @@ func TestAttorneyStoreCreate(t *testing.T) { Email: "a@example.com", } - shareCode := actor.ShareCodeData{ + shareCode := sharecode.ShareCodeData{ PK: dynamo.ShareKey(dynamo.AttorneyShareKey("123")), SK: dynamo.ShareSortKey(dynamo.MetadataKey("123")), ActorUID: uid, @@ -55,11 +56,11 @@ func TestAttorneyStoreCreate(t *testing.T) { expectedTransaction := &dynamo.Transaction{ Creates: []any{ details, - lpaLink{ + temporary.LpaLink{ PK: dynamo.LpaKey("123"), SK: dynamo.SubKey("456"), DonorKey: dynamo.LpaOwnerKey(dynamo.DonorKey("donor")), - ActorType: actor.TypeAttorney, + ActorType: temporary.ActorTypeAttorney, UpdatedAt: now, }, }, @@ -76,7 +77,7 @@ func TestAttorneyStoreCreate(t *testing.T) { WriteTransaction(ctx, expectedTransaction). Return(nil) - attorneyStore := &attorneyStore{dynamoClient: dynamoClient, now: func() time.Time { return now }} + attorneyStore := &Store{dynamoClient: dynamoClient, now: func() time.Time { return now }} attorney, err := attorneyStore.Create(ctx, shareCode, "a@example.com") assert.Nil(t, err) @@ -88,32 +89,32 @@ func TestAttorneyStoreCreate(t *testing.T) { func TestAttorneyStoreCreateWhenSessionMissing(t *testing.T) { ctx := context.Background() - attorneyStore := &attorneyStore{dynamoClient: nil, now: nil} + attorneyStore := &Store{dynamoClient: nil, now: nil} - _, err := attorneyStore.Create(ctx, actor.ShareCodeData{}, "") - assert.Equal(t, page.SessionMissingError{}, err) + _, err := attorneyStore.Create(ctx, sharecode.ShareCodeData{}, "") + assert.Equal(t, appcontext.SessionMissingError{}, err) } func TestAttorneyStoreCreateWhenSessionDataMissing(t *testing.T) { - testcases := map[string]*page.SessionData{ + testcases := map[string]*appcontext.SessionData{ "LpaID": {SessionID: "456"}, "SessionID": {LpaID: "123"}, } for name, sessionData := range testcases { t.Run(name, func(t *testing.T) { - ctx := page.ContextWithSessionData(context.Background(), sessionData) + ctx := appcontext.ContextWithSessionData(context.Background(), sessionData) - attorneyStore := &attorneyStore{} + attorneyStore := &Store{} - _, err := attorneyStore.Create(ctx, actor.ShareCodeData{}, "") + _, err := attorneyStore.Create(ctx, sharecode.ShareCodeData{}, "") assert.NotNil(t, err) }) } } func TestAttorneyStoreCreateWhenWriteTransactionError(t *testing.T) { - ctx := page.ContextWithSessionData(context.Background(), &page.SessionData{LpaID: "123", SessionID: "456"}) + ctx := appcontext.ContextWithSessionData(context.Background(), &appcontext.SessionData{LpaID: "123", SessionID: "456"}) now := time.Now() dynamoClient := newMockDynamoClient(t) @@ -121,67 +122,66 @@ func TestAttorneyStoreCreateWhenWriteTransactionError(t *testing.T) { WriteTransaction(mock.Anything, mock.Anything). Return(expectedError) - attorneyStore := &attorneyStore{dynamoClient: dynamoClient, now: func() time.Time { return now }} + attorneyStore := &Store{dynamoClient: dynamoClient, now: func() time.Time { return now }} - _, err := attorneyStore.Create(ctx, actor.ShareCodeData{ + _, err := attorneyStore.Create(ctx, sharecode.ShareCodeData{ PK: dynamo.ShareKey(dynamo.AttorneyShareKey("123")), SK: dynamo.ShareSortKey(dynamo.MetadataKey("123")), }, "") assert.Equal(t, expectedError, err) - } func TestAttorneyStoreGet(t *testing.T) { - ctx := page.ContextWithSessionData(context.Background(), &page.SessionData{LpaID: "123", SessionID: "456"}) + ctx := appcontext.ContextWithSessionData(context.Background(), &appcontext.SessionData{LpaID: "123", SessionID: "456"}) dynamoClient := newMockDynamoClient(t) dynamoClient. ExpectOne(ctx, dynamo.LpaKey("123"), dynamo.AttorneyKey("456"), - &actor.AttorneyProvidedDetails{LpaID: "123"}, nil) + &Provided{LpaID: "123"}, nil) - attorneyStore := &attorneyStore{dynamoClient: dynamoClient, now: nil} + attorneyStore := &Store{dynamoClient: dynamoClient, now: nil} attorney, err := attorneyStore.Get(ctx) assert.Nil(t, err) - assert.Equal(t, &actor.AttorneyProvidedDetails{LpaID: "123"}, attorney) + assert.Equal(t, &Provided{LpaID: "123"}, attorney) } func TestAttorneyStoreGetWhenSessionMissing(t *testing.T) { ctx := context.Background() - attorneyStore := &attorneyStore{dynamoClient: nil, now: nil} + attorneyStore := &Store{dynamoClient: nil, now: nil} _, err := attorneyStore.Get(ctx) - assert.Equal(t, page.SessionMissingError{}, err) + assert.Equal(t, appcontext.SessionMissingError{}, err) } func TestAttorneyStoreGetMissingLpaIDInSessionData(t *testing.T) { - ctx := page.ContextWithSessionData(context.Background(), &page.SessionData{SessionID: "456"}) + ctx := appcontext.ContextWithSessionData(context.Background(), &appcontext.SessionData{SessionID: "456"}) - attorneyStore := &attorneyStore{} + attorneyStore := &Store{} _, err := attorneyStore.Get(ctx) assert.Equal(t, errors.New("attorneyStore.Get requires LpaID and SessionID"), err) } func TestAttorneyStoreGetMissingSessionIDInSessionData(t *testing.T) { - ctx := page.ContextWithSessionData(context.Background(), &page.SessionData{LpaID: "123"}) + ctx := appcontext.ContextWithSessionData(context.Background(), &appcontext.SessionData{LpaID: "123"}) - attorneyStore := &attorneyStore{} + attorneyStore := &Store{} _, err := attorneyStore.Get(ctx) assert.Equal(t, errors.New("attorneyStore.Get requires LpaID and SessionID"), err) } func TestAttorneyStoreGetOnError(t *testing.T) { - ctx := page.ContextWithSessionData(context.Background(), &page.SessionData{LpaID: "123", SessionID: "456"}) + ctx := appcontext.ContextWithSessionData(context.Background(), &appcontext.SessionData{LpaID: "123", SessionID: "456"}) dynamoClient := newMockDynamoClient(t) dynamoClient. ExpectOne(ctx, dynamo.LpaKey("123"), dynamo.AttorneyKey("456"), - &actor.AttorneyProvidedDetails{LpaID: "123"}, expectedError) + &Provided{LpaID: "123"}, expectedError) - attorneyStore := &attorneyStore{dynamoClient: dynamoClient, now: nil} + attorneyStore := &Store{dynamoClient: dynamoClient, now: nil} _, err := attorneyStore.Get(ctx) assert.Equal(t, expectedError, err) @@ -193,15 +193,15 @@ func TestAttorneyStorePut(t *testing.T) { dynamoClient := newMockDynamoClient(t) dynamoClient.EXPECT(). - Put(ctx, &actor.AttorneyProvidedDetails{PK: dynamo.LpaKey("123"), SK: dynamo.AttorneyKey("456"), LpaID: "123", UpdatedAt: now}). + Put(ctx, &Provided{PK: dynamo.LpaKey("123"), SK: dynamo.AttorneyKey("456"), LpaID: "123", UpdatedAt: now}). Return(nil) - attorneyStore := &attorneyStore{ + attorneyStore := &Store{ dynamoClient: dynamoClient, now: func() time.Time { return now }, } - err := attorneyStore.Put(ctx, &actor.AttorneyProvidedDetails{PK: dynamo.LpaKey("123"), SK: dynamo.AttorneyKey("456"), LpaID: "123"}) + err := attorneyStore.Put(ctx, &Provided{PK: dynamo.LpaKey("123"), SK: dynamo.AttorneyKey("456"), LpaID: "123"}) assert.Nil(t, err) } @@ -211,34 +211,34 @@ func TestAttorneyStorePutOnError(t *testing.T) { dynamoClient := newMockDynamoClient(t) dynamoClient.EXPECT(). - Put(ctx, &actor.AttorneyProvidedDetails{PK: dynamo.LpaKey("123"), SK: dynamo.AttorneyKey("456"), LpaID: "123", UpdatedAt: now}). + Put(ctx, &Provided{PK: dynamo.LpaKey("123"), SK: dynamo.AttorneyKey("456"), LpaID: "123", UpdatedAt: now}). Return(expectedError) - attorneyStore := &attorneyStore{ + attorneyStore := &Store{ dynamoClient: dynamoClient, now: func() time.Time { return now }, } - err := attorneyStore.Put(ctx, &actor.AttorneyProvidedDetails{PK: dynamo.LpaKey("123"), SK: dynamo.AttorneyKey("456"), LpaID: "123"}) + err := attorneyStore.Put(ctx, &Provided{PK: dynamo.LpaKey("123"), SK: dynamo.AttorneyKey("456"), LpaID: "123"}) assert.Equal(t, expectedError, err) } func TestAttorneyStoreDelete(t *testing.T) { - ctx := page.ContextWithSessionData(context.Background(), &page.SessionData{LpaID: "123", SessionID: "456"}) + ctx := appcontext.ContextWithSessionData(context.Background(), &appcontext.SessionData{LpaID: "123", SessionID: "456"}) dynamoClient := newMockDynamoClient(t) dynamoClient.EXPECT(). DeleteOne(ctx, dynamo.LpaKey("123"), dynamo.AttorneyKey("456")). Return(nil) - attorneyStore := &attorneyStore{dynamoClient: dynamoClient} + attorneyStore := &Store{dynamoClient: dynamoClient} err := attorneyStore.Delete(ctx) assert.Nil(t, err) } func TestAttorneyStoreDeleteWhenSessionDataErrors(t *testing.T) { - attorneyStore := &attorneyStore{} + attorneyStore := &Store{} err := attorneyStore.Delete(ctx) assert.Error(t, err) @@ -259,9 +259,9 @@ func TestAttorneyStoreDeleteWhenMissingSessionValues(t *testing.T) { for name, tc := range testcases { t.Run(name, func(t *testing.T) { - ctx := page.ContextWithSessionData(context.Background(), &page.SessionData{LpaID: tc.lpaID, SessionID: tc.sessionID}) + ctx := appcontext.ContextWithSessionData(context.Background(), &appcontext.SessionData{LpaID: tc.lpaID, SessionID: tc.sessionID}) - attorneyStore := &attorneyStore{} + attorneyStore := &Store{} err := attorneyStore.Delete(ctx) assert.Error(t, err) @@ -270,14 +270,14 @@ func TestAttorneyStoreDeleteWhenMissingSessionValues(t *testing.T) { } func TestAttorneyStoreDeleteWhenDynamoClientError(t *testing.T) { - ctx := page.ContextWithSessionData(context.Background(), &page.SessionData{LpaID: "123", SessionID: "456"}) + ctx := appcontext.ContextWithSessionData(context.Background(), &appcontext.SessionData{LpaID: "123", SessionID: "456"}) dynamoClient := newMockDynamoClient(t) dynamoClient.EXPECT(). DeleteOne(mock.Anything, mock.Anything, mock.Anything). Return(expectedError) - attorneyStore := &attorneyStore{dynamoClient: dynamoClient} + attorneyStore := &Store{dynamoClient: dynamoClient} err := attorneyStore.Delete(ctx) assert.Equal(t, fmt.Errorf("error deleting attorney: %w", expectedError), err) diff --git a/internal/attorney/attorneypage/confirm_dont_want_to_be_attorney.go b/internal/attorney/attorneypage/confirm_dont_want_to_be_attorney.go new file mode 100644 index 0000000000..e1cc4cd192 --- /dev/null +++ b/internal/attorney/attorneypage/confirm_dont_want_to_be_attorney.go @@ -0,0 +1,63 @@ +package attorneypage + +import ( + "net/http" + "net/url" + + "github.com/ministryofjustice/opg-go-common/template" + "github.com/ministryofjustice/opg-modernising-lpa/internal/actor" + "github.com/ministryofjustice/opg-modernising-lpa/internal/lpastore" + "github.com/ministryofjustice/opg-modernising-lpa/internal/notify" + "github.com/ministryofjustice/opg-modernising-lpa/internal/page" + "github.com/ministryofjustice/opg-modernising-lpa/internal/validation" +) + +type confirmDontWantToBeAttorneyData struct { + App page.AppData + Errors validation.List + Lpa *lpastore.Lpa +} + +func ConfirmDontWantToBeAttorney(tmpl template.Template, lpaStoreResolvingService LpaStoreResolvingService, attorneyStore AttorneyStore, notifyClient NotifyClient, appPublicURL string) Handler { + return func(appData page.AppData, w http.ResponseWriter, r *http.Request, attorneyProvidedDetails *actor.AttorneyProvidedDetails) error { + lpa, err := lpaStoreResolvingService.Get(r.Context()) + if err != nil { + return err + } + + data := &confirmDontWantToBeAttorneyData{ + App: appData, + Lpa: lpa, + } + + if r.Method == http.MethodPost { + attorneyFullName, err := findAttorneyFullName(lpa, attorneyProvidedDetails.UID, attorneyProvidedDetails.IsTrustCorporation, attorneyProvidedDetails.IsReplacement) + if err != nil { + return err + } + + email := notify.AttorneyOptedOutEmail{ + AttorneyFullName: attorneyFullName, + DonorFullName: lpa.Donor.FullName(), + LpaType: appData.Localizer.T(lpa.Type.String()), + LpaUID: lpa.LpaUID, + DonorStartPageURL: appPublicURL + page.Paths.Start.Format(), + } + + if err := attorneyStore.Delete(r.Context()); err != nil { + return err + } + + if err := notifyClient.SendActorEmail(r.Context(), lpa.Donor.Email, lpa.LpaUID, email); err != nil { + return err + } + + return page.Paths.Attorney.YouHaveDecidedNotToBeAttorney.RedirectQuery(w, r, appData, url.Values{ + "donorFullName": {lpa.Donor.FullName()}, + "donorFirstNames": {lpa.Donor.FirstNames}, + }) + } + + return tmpl(w, data) + } +} diff --git a/internal/page/attorney/confirm_dont_want_to_be_attorney_test.go b/internal/attorney/attorneypage/confirm_dont_want_to_be_attorney_test.go similarity index 99% rename from internal/page/attorney/confirm_dont_want_to_be_attorney_test.go rename to internal/attorney/attorneypage/confirm_dont_want_to_be_attorney_test.go index e2b2668970..c160f7701a 100644 --- a/internal/page/attorney/confirm_dont_want_to_be_attorney_test.go +++ b/internal/attorney/attorneypage/confirm_dont_want_to_be_attorney_test.go @@ -1,4 +1,4 @@ -package attorney +package attorneypage import ( "context" diff --git a/internal/attorney/attorneypage/mock_AttorneyStore_test.go b/internal/attorney/attorneypage/mock_AttorneyStore_test.go new file mode 100644 index 0000000000..681effdd41 --- /dev/null +++ b/internal/attorney/attorneypage/mock_AttorneyStore_test.go @@ -0,0 +1,251 @@ +// Code generated by mockery v2.42.2. DO NOT EDIT. + +package attorneypage + +import ( + context "context" + + attorneydata "github.com/ministryofjustice/opg-modernising-lpa/internal/attorney/attorneydata" + + mock "github.com/stretchr/testify/mock" + + sharecode "github.com/ministryofjustice/opg-modernising-lpa/internal/sharecode" +) + +// mockAttorneyStore is an autogenerated mock type for the AttorneyStore type +type mockAttorneyStore struct { + mock.Mock +} + +type mockAttorneyStore_Expecter struct { + mock *mock.Mock +} + +func (_m *mockAttorneyStore) EXPECT() *mockAttorneyStore_Expecter { + return &mockAttorneyStore_Expecter{mock: &_m.Mock} +} + +// Create provides a mock function with given fields: ctx, shareCode, email +func (_m *mockAttorneyStore) Create(ctx context.Context, shareCode sharecode.ShareCodeData, email string) (*attorneydata.Provided, error) { + ret := _m.Called(ctx, shareCode, email) + + if len(ret) == 0 { + panic("no return value specified for Create") + } + + var r0 *attorneydata.Provided + var r1 error + if rf, ok := ret.Get(0).(func(context.Context, sharecode.ShareCodeData, string) (*attorneydata.Provided, error)); ok { + return rf(ctx, shareCode, email) + } + if rf, ok := ret.Get(0).(func(context.Context, sharecode.ShareCodeData, string) *attorneydata.Provided); ok { + r0 = rf(ctx, shareCode, email) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(*attorneydata.Provided) + } + } + + if rf, ok := ret.Get(1).(func(context.Context, sharecode.ShareCodeData, string) error); ok { + r1 = rf(ctx, shareCode, email) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// mockAttorneyStore_Create_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'Create' +type mockAttorneyStore_Create_Call struct { + *mock.Call +} + +// Create is a helper method to define mock.On call +// - ctx context.Context +// - shareCode sharecode.ShareCodeData +// - email string +func (_e *mockAttorneyStore_Expecter) Create(ctx interface{}, shareCode interface{}, email interface{}) *mockAttorneyStore_Create_Call { + return &mockAttorneyStore_Create_Call{Call: _e.mock.On("Create", ctx, shareCode, email)} +} + +func (_c *mockAttorneyStore_Create_Call) Run(run func(ctx context.Context, shareCode sharecode.ShareCodeData, email string)) *mockAttorneyStore_Create_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context), args[1].(sharecode.ShareCodeData), args[2].(string)) + }) + return _c +} + +func (_c *mockAttorneyStore_Create_Call) Return(_a0 *attorneydata.Provided, _a1 error) *mockAttorneyStore_Create_Call { + _c.Call.Return(_a0, _a1) + return _c +} + +func (_c *mockAttorneyStore_Create_Call) RunAndReturn(run func(context.Context, sharecode.ShareCodeData, string) (*attorneydata.Provided, error)) *mockAttorneyStore_Create_Call { + _c.Call.Return(run) + return _c +} + +// Delete provides a mock function with given fields: ctx +func (_m *mockAttorneyStore) Delete(ctx context.Context) error { + ret := _m.Called(ctx) + + if len(ret) == 0 { + panic("no return value specified for Delete") + } + + var r0 error + if rf, ok := ret.Get(0).(func(context.Context) error); ok { + r0 = rf(ctx) + } else { + r0 = ret.Error(0) + } + + return r0 +} + +// mockAttorneyStore_Delete_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'Delete' +type mockAttorneyStore_Delete_Call struct { + *mock.Call +} + +// Delete is a helper method to define mock.On call +// - ctx context.Context +func (_e *mockAttorneyStore_Expecter) Delete(ctx interface{}) *mockAttorneyStore_Delete_Call { + return &mockAttorneyStore_Delete_Call{Call: _e.mock.On("Delete", ctx)} +} + +func (_c *mockAttorneyStore_Delete_Call) Run(run func(ctx context.Context)) *mockAttorneyStore_Delete_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context)) + }) + return _c +} + +func (_c *mockAttorneyStore_Delete_Call) Return(_a0 error) *mockAttorneyStore_Delete_Call { + _c.Call.Return(_a0) + return _c +} + +func (_c *mockAttorneyStore_Delete_Call) RunAndReturn(run func(context.Context) error) *mockAttorneyStore_Delete_Call { + _c.Call.Return(run) + return _c +} + +// Get provides a mock function with given fields: ctx +func (_m *mockAttorneyStore) Get(ctx context.Context) (*attorneydata.Provided, error) { + ret := _m.Called(ctx) + + if len(ret) == 0 { + panic("no return value specified for Get") + } + + var r0 *attorneydata.Provided + var r1 error + if rf, ok := ret.Get(0).(func(context.Context) (*attorneydata.Provided, error)); ok { + return rf(ctx) + } + if rf, ok := ret.Get(0).(func(context.Context) *attorneydata.Provided); ok { + r0 = rf(ctx) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(*attorneydata.Provided) + } + } + + if rf, ok := ret.Get(1).(func(context.Context) error); ok { + r1 = rf(ctx) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// mockAttorneyStore_Get_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'Get' +type mockAttorneyStore_Get_Call struct { + *mock.Call +} + +// Get is a helper method to define mock.On call +// - 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(ctx context.Context)) *mockAttorneyStore_Get_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context)) + }) + return _c +} + +func (_c *mockAttorneyStore_Get_Call) Return(_a0 *attorneydata.Provided, _a1 error) *mockAttorneyStore_Get_Call { + _c.Call.Return(_a0, _a1) + return _c +} + +func (_c *mockAttorneyStore_Get_Call) RunAndReturn(run func(context.Context) (*attorneydata.Provided, error)) *mockAttorneyStore_Get_Call { + _c.Call.Return(run) + return _c +} + +// Put provides a mock function with given fields: ctx, attorney +func (_m *mockAttorneyStore) Put(ctx context.Context, attorney *attorneydata.Provided) error { + ret := _m.Called(ctx, attorney) + + if len(ret) == 0 { + panic("no return value specified for Put") + } + + var r0 error + if rf, ok := ret.Get(0).(func(context.Context, *attorneydata.Provided) error); ok { + r0 = rf(ctx, attorney) + } else { + r0 = ret.Error(0) + } + + return r0 +} + +// mockAttorneyStore_Put_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'Put' +type mockAttorneyStore_Put_Call struct { + *mock.Call +} + +// Put is a helper method to define mock.On call +// - ctx context.Context +// - attorney *attorneydata.Provided +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(ctx context.Context, attorney *attorneydata.Provided)) *mockAttorneyStore_Put_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context), args[1].(*attorneydata.Provided)) + }) + return _c +} + +func (_c *mockAttorneyStore_Put_Call) Return(_a0 error) *mockAttorneyStore_Put_Call { + _c.Call.Return(_a0) + return _c +} + +func (_c *mockAttorneyStore_Put_Call) RunAndReturn(run func(context.Context, *attorneydata.Provided) error) *mockAttorneyStore_Put_Call { + _c.Call.Return(run) + return _c +} + +// newMockAttorneyStore creates a new instance of mockAttorneyStore. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations. +// The first argument is typically a *testing.T value. +func newMockAttorneyStore(t interface { + mock.TestingT + Cleanup(func()) +}) *mockAttorneyStore { + mock := &mockAttorneyStore{} + mock.Mock.Test(t) + + t.Cleanup(func() { mock.AssertExpectations(t) }) + + return mock +} diff --git a/internal/attorney/attorneypage/mock_Handler_test.go b/internal/attorney/attorneypage/mock_Handler_test.go new file mode 100644 index 0000000000..ebbea22527 --- /dev/null +++ b/internal/attorney/attorneypage/mock_Handler_test.go @@ -0,0 +1,89 @@ +// Code generated by mockery v2.42.2. DO NOT EDIT. + +package attorneypage + +import ( + http "net/http" + + attorneydata "github.com/ministryofjustice/opg-modernising-lpa/internal/attorney/attorneydata" + + mock "github.com/stretchr/testify/mock" + + page "github.com/ministryofjustice/opg-modernising-lpa/internal/page" +) + +// mockHandler is an autogenerated mock type for the Handler type +type mockHandler struct { + mock.Mock +} + +type mockHandler_Expecter struct { + mock *mock.Mock +} + +func (_m *mockHandler) EXPECT() *mockHandler_Expecter { + return &mockHandler_Expecter{mock: &_m.Mock} +} + +// Execute provides a mock function with given fields: data, w, r, details +func (_m *mockHandler) Execute(data page.AppData, w http.ResponseWriter, r *http.Request, details *attorneydata.Provided) error { + ret := _m.Called(data, w, r, details) + + if len(ret) == 0 { + panic("no return value specified for Execute") + } + + var r0 error + if rf, ok := ret.Get(0).(func(page.AppData, http.ResponseWriter, *http.Request, *attorneydata.Provided) error); ok { + r0 = rf(data, w, r, details) + } else { + r0 = ret.Error(0) + } + + return r0 +} + +// mockHandler_Execute_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'Execute' +type mockHandler_Execute_Call struct { + *mock.Call +} + +// Execute is a helper method to define mock.On call +// - data page.AppData +// - w http.ResponseWriter +// - r *http.Request +// - details *attorneydata.Provided +func (_e *mockHandler_Expecter) Execute(data interface{}, w interface{}, r interface{}, details interface{}) *mockHandler_Execute_Call { + return &mockHandler_Execute_Call{Call: _e.mock.On("Execute", data, w, r, details)} +} + +func (_c *mockHandler_Execute_Call) Run(run func(data page.AppData, w http.ResponseWriter, r *http.Request, details *attorneydata.Provided)) *mockHandler_Execute_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(page.AppData), args[1].(http.ResponseWriter), args[2].(*http.Request), args[3].(*attorneydata.Provided)) + }) + return _c +} + +func (_c *mockHandler_Execute_Call) Return(_a0 error) *mockHandler_Execute_Call { + _c.Call.Return(_a0) + return _c +} + +func (_c *mockHandler_Execute_Call) RunAndReturn(run func(page.AppData, http.ResponseWriter, *http.Request, *attorneydata.Provided) error) *mockHandler_Execute_Call { + _c.Call.Return(run) + return _c +} + +// newMockHandler creates a new instance of mockHandler. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations. +// The first argument is typically a *testing.T value. +func newMockHandler(t interface { + mock.TestingT + Cleanup(func()) +}) *mockHandler { + mock := &mockHandler{} + mock.Mock.Test(t) + + t.Cleanup(func() { mock.AssertExpectations(t) }) + + return mock +} diff --git a/internal/attorney/attorneypage/mock_Localizer_test.go b/internal/attorney/attorneypage/mock_Localizer_test.go new file mode 100644 index 0000000000..68400f9ef7 --- /dev/null +++ b/internal/attorney/attorneypage/mock_Localizer_test.go @@ -0,0 +1,534 @@ +// Code generated by mockery v2.42.2. DO NOT EDIT. + +package attorneypage + +import ( + date "github.com/ministryofjustice/opg-modernising-lpa/internal/date" + mock "github.com/stretchr/testify/mock" + + time "time" +) + +// mockLocalizer is an autogenerated mock type for the Localizer type +type mockLocalizer struct { + mock.Mock +} + +type mockLocalizer_Expecter struct { + mock *mock.Mock +} + +func (_m *mockLocalizer) EXPECT() *mockLocalizer_Expecter { + return &mockLocalizer_Expecter{mock: &_m.Mock} +} + +// Concat provides a mock function with given fields: list, joiner +func (_m *mockLocalizer) Concat(list []string, joiner string) string { + ret := _m.Called(list, joiner) + + if len(ret) == 0 { + panic("no return value specified for Concat") + } + + var r0 string + if rf, ok := ret.Get(0).(func([]string, string) string); ok { + r0 = rf(list, joiner) + } else { + r0 = ret.Get(0).(string) + } + + return r0 +} + +// mockLocalizer_Concat_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'Concat' +type mockLocalizer_Concat_Call struct { + *mock.Call +} + +// Concat is a helper method to define mock.On call +// - list []string +// - joiner string +func (_e *mockLocalizer_Expecter) Concat(list interface{}, joiner interface{}) *mockLocalizer_Concat_Call { + return &mockLocalizer_Concat_Call{Call: _e.mock.On("Concat", list, joiner)} +} + +func (_c *mockLocalizer_Concat_Call) Run(run func(list []string, joiner string)) *mockLocalizer_Concat_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].([]string), args[1].(string)) + }) + return _c +} + +func (_c *mockLocalizer_Concat_Call) Return(_a0 string) *mockLocalizer_Concat_Call { + _c.Call.Return(_a0) + return _c +} + +func (_c *mockLocalizer_Concat_Call) RunAndReturn(run func([]string, string) string) *mockLocalizer_Concat_Call { + _c.Call.Return(run) + return _c +} + +// Count provides a mock function with given fields: messageID, count +func (_m *mockLocalizer) Count(messageID string, count int) string { + ret := _m.Called(messageID, count) + + if len(ret) == 0 { + panic("no return value specified for Count") + } + + var r0 string + if rf, ok := ret.Get(0).(func(string, int) string); ok { + r0 = rf(messageID, count) + } else { + r0 = ret.Get(0).(string) + } + + return r0 +} + +// mockLocalizer_Count_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'Count' +type mockLocalizer_Count_Call struct { + *mock.Call +} + +// Count is a helper method to define mock.On call +// - messageID string +// - count int +func (_e *mockLocalizer_Expecter) Count(messageID interface{}, count interface{}) *mockLocalizer_Count_Call { + return &mockLocalizer_Count_Call{Call: _e.mock.On("Count", messageID, count)} +} + +func (_c *mockLocalizer_Count_Call) Run(run func(messageID string, count int)) *mockLocalizer_Count_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(string), args[1].(int)) + }) + return _c +} + +func (_c *mockLocalizer_Count_Call) Return(_a0 string) *mockLocalizer_Count_Call { + _c.Call.Return(_a0) + return _c +} + +func (_c *mockLocalizer_Count_Call) RunAndReturn(run func(string, int) string) *mockLocalizer_Count_Call { + _c.Call.Return(run) + return _c +} + +// Format provides a mock function with given fields: messageID, data +func (_m *mockLocalizer) Format(messageID string, data map[string]interface{}) string { + ret := _m.Called(messageID, data) + + if len(ret) == 0 { + panic("no return value specified for Format") + } + + var r0 string + if rf, ok := ret.Get(0).(func(string, map[string]interface{}) string); ok { + r0 = rf(messageID, data) + } else { + r0 = ret.Get(0).(string) + } + + return r0 +} + +// mockLocalizer_Format_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'Format' +type mockLocalizer_Format_Call struct { + *mock.Call +} + +// Format is a helper method to define mock.On call +// - messageID string +// - data map[string]interface{} +func (_e *mockLocalizer_Expecter) Format(messageID interface{}, data interface{}) *mockLocalizer_Format_Call { + return &mockLocalizer_Format_Call{Call: _e.mock.On("Format", messageID, data)} +} + +func (_c *mockLocalizer_Format_Call) Run(run func(messageID string, data map[string]interface{})) *mockLocalizer_Format_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(string), args[1].(map[string]interface{})) + }) + return _c +} + +func (_c *mockLocalizer_Format_Call) Return(_a0 string) *mockLocalizer_Format_Call { + _c.Call.Return(_a0) + return _c +} + +func (_c *mockLocalizer_Format_Call) RunAndReturn(run func(string, map[string]interface{}) string) *mockLocalizer_Format_Call { + _c.Call.Return(run) + return _c +} + +// FormatCount provides a mock function with given fields: messageID, count, data +func (_m *mockLocalizer) FormatCount(messageID string, count int, data map[string]interface{}) string { + ret := _m.Called(messageID, count, data) + + if len(ret) == 0 { + panic("no return value specified for FormatCount") + } + + var r0 string + if rf, ok := ret.Get(0).(func(string, int, map[string]interface{}) string); ok { + r0 = rf(messageID, count, data) + } else { + r0 = ret.Get(0).(string) + } + + return r0 +} + +// mockLocalizer_FormatCount_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'FormatCount' +type mockLocalizer_FormatCount_Call struct { + *mock.Call +} + +// FormatCount is a helper method to define mock.On call +// - messageID string +// - count int +// - data map[string]interface{} +func (_e *mockLocalizer_Expecter) FormatCount(messageID interface{}, count interface{}, data interface{}) *mockLocalizer_FormatCount_Call { + return &mockLocalizer_FormatCount_Call{Call: _e.mock.On("FormatCount", messageID, count, data)} +} + +func (_c *mockLocalizer_FormatCount_Call) Run(run func(messageID string, count int, data map[string]interface{})) *mockLocalizer_FormatCount_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(string), args[1].(int), args[2].(map[string]interface{})) + }) + return _c +} + +func (_c *mockLocalizer_FormatCount_Call) Return(_a0 string) *mockLocalizer_FormatCount_Call { + _c.Call.Return(_a0) + return _c +} + +func (_c *mockLocalizer_FormatCount_Call) RunAndReturn(run func(string, int, map[string]interface{}) string) *mockLocalizer_FormatCount_Call { + _c.Call.Return(run) + return _c +} + +// FormatDate provides a mock function with given fields: t +func (_m *mockLocalizer) FormatDate(t date.TimeOrDate) string { + ret := _m.Called(t) + + if len(ret) == 0 { + panic("no return value specified for FormatDate") + } + + var r0 string + if rf, ok := ret.Get(0).(func(date.TimeOrDate) string); ok { + r0 = rf(t) + } else { + r0 = ret.Get(0).(string) + } + + return r0 +} + +// mockLocalizer_FormatDate_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'FormatDate' +type mockLocalizer_FormatDate_Call struct { + *mock.Call +} + +// FormatDate is a helper method to define mock.On call +// - t date.TimeOrDate +func (_e *mockLocalizer_Expecter) FormatDate(t interface{}) *mockLocalizer_FormatDate_Call { + return &mockLocalizer_FormatDate_Call{Call: _e.mock.On("FormatDate", t)} +} + +func (_c *mockLocalizer_FormatDate_Call) Run(run func(t date.TimeOrDate)) *mockLocalizer_FormatDate_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(date.TimeOrDate)) + }) + return _c +} + +func (_c *mockLocalizer_FormatDate_Call) Return(_a0 string) *mockLocalizer_FormatDate_Call { + _c.Call.Return(_a0) + return _c +} + +func (_c *mockLocalizer_FormatDate_Call) RunAndReturn(run func(date.TimeOrDate) string) *mockLocalizer_FormatDate_Call { + _c.Call.Return(run) + return _c +} + +// FormatDateTime provides a mock function with given fields: t +func (_m *mockLocalizer) FormatDateTime(t time.Time) string { + ret := _m.Called(t) + + if len(ret) == 0 { + panic("no return value specified for FormatDateTime") + } + + var r0 string + if rf, ok := ret.Get(0).(func(time.Time) string); ok { + r0 = rf(t) + } else { + r0 = ret.Get(0).(string) + } + + return r0 +} + +// mockLocalizer_FormatDateTime_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'FormatDateTime' +type mockLocalizer_FormatDateTime_Call struct { + *mock.Call +} + +// FormatDateTime is a helper method to define mock.On call +// - t time.Time +func (_e *mockLocalizer_Expecter) FormatDateTime(t interface{}) *mockLocalizer_FormatDateTime_Call { + return &mockLocalizer_FormatDateTime_Call{Call: _e.mock.On("FormatDateTime", t)} +} + +func (_c *mockLocalizer_FormatDateTime_Call) Run(run func(t time.Time)) *mockLocalizer_FormatDateTime_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(time.Time)) + }) + return _c +} + +func (_c *mockLocalizer_FormatDateTime_Call) Return(_a0 string) *mockLocalizer_FormatDateTime_Call { + _c.Call.Return(_a0) + return _c +} + +func (_c *mockLocalizer_FormatDateTime_Call) RunAndReturn(run func(time.Time) string) *mockLocalizer_FormatDateTime_Call { + _c.Call.Return(run) + return _c +} + +// FormatTime provides a mock function with given fields: t +func (_m *mockLocalizer) FormatTime(t time.Time) string { + ret := _m.Called(t) + + if len(ret) == 0 { + panic("no return value specified for FormatTime") + } + + var r0 string + if rf, ok := ret.Get(0).(func(time.Time) string); ok { + r0 = rf(t) + } else { + r0 = ret.Get(0).(string) + } + + return r0 +} + +// mockLocalizer_FormatTime_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'FormatTime' +type mockLocalizer_FormatTime_Call struct { + *mock.Call +} + +// FormatTime is a helper method to define mock.On call +// - t time.Time +func (_e *mockLocalizer_Expecter) FormatTime(t interface{}) *mockLocalizer_FormatTime_Call { + return &mockLocalizer_FormatTime_Call{Call: _e.mock.On("FormatTime", t)} +} + +func (_c *mockLocalizer_FormatTime_Call) Run(run func(t time.Time)) *mockLocalizer_FormatTime_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(time.Time)) + }) + return _c +} + +func (_c *mockLocalizer_FormatTime_Call) Return(_a0 string) *mockLocalizer_FormatTime_Call { + _c.Call.Return(_a0) + return _c +} + +func (_c *mockLocalizer_FormatTime_Call) RunAndReturn(run func(time.Time) string) *mockLocalizer_FormatTime_Call { + _c.Call.Return(run) + return _c +} + +// Possessive provides a mock function with given fields: s +func (_m *mockLocalizer) Possessive(s string) string { + ret := _m.Called(s) + + if len(ret) == 0 { + panic("no return value specified for Possessive") + } + + var r0 string + if rf, ok := ret.Get(0).(func(string) string); ok { + r0 = rf(s) + } else { + r0 = ret.Get(0).(string) + } + + return r0 +} + +// mockLocalizer_Possessive_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'Possessive' +type mockLocalizer_Possessive_Call struct { + *mock.Call +} + +// Possessive is a helper method to define mock.On call +// - s string +func (_e *mockLocalizer_Expecter) Possessive(s interface{}) *mockLocalizer_Possessive_Call { + return &mockLocalizer_Possessive_Call{Call: _e.mock.On("Possessive", s)} +} + +func (_c *mockLocalizer_Possessive_Call) Run(run func(s string)) *mockLocalizer_Possessive_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(string)) + }) + return _c +} + +func (_c *mockLocalizer_Possessive_Call) Return(_a0 string) *mockLocalizer_Possessive_Call { + _c.Call.Return(_a0) + return _c +} + +func (_c *mockLocalizer_Possessive_Call) RunAndReturn(run func(string) string) *mockLocalizer_Possessive_Call { + _c.Call.Return(run) + return _c +} + +// SetShowTranslationKeys provides a mock function with given fields: s +func (_m *mockLocalizer) SetShowTranslationKeys(s bool) { + _m.Called(s) +} + +// mockLocalizer_SetShowTranslationKeys_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'SetShowTranslationKeys' +type mockLocalizer_SetShowTranslationKeys_Call struct { + *mock.Call +} + +// SetShowTranslationKeys is a helper method to define mock.On call +// - s bool +func (_e *mockLocalizer_Expecter) SetShowTranslationKeys(s interface{}) *mockLocalizer_SetShowTranslationKeys_Call { + return &mockLocalizer_SetShowTranslationKeys_Call{Call: _e.mock.On("SetShowTranslationKeys", s)} +} + +func (_c *mockLocalizer_SetShowTranslationKeys_Call) Run(run func(s bool)) *mockLocalizer_SetShowTranslationKeys_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(bool)) + }) + return _c +} + +func (_c *mockLocalizer_SetShowTranslationKeys_Call) Return() *mockLocalizer_SetShowTranslationKeys_Call { + _c.Call.Return() + return _c +} + +func (_c *mockLocalizer_SetShowTranslationKeys_Call) RunAndReturn(run func(bool)) *mockLocalizer_SetShowTranslationKeys_Call { + _c.Call.Return(run) + return _c +} + +// ShowTranslationKeys provides a mock function with given fields: +func (_m *mockLocalizer) ShowTranslationKeys() bool { + ret := _m.Called() + + if len(ret) == 0 { + panic("no return value specified for ShowTranslationKeys") + } + + var r0 bool + if rf, ok := ret.Get(0).(func() bool); ok { + r0 = rf() + } else { + r0 = ret.Get(0).(bool) + } + + return r0 +} + +// mockLocalizer_ShowTranslationKeys_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'ShowTranslationKeys' +type mockLocalizer_ShowTranslationKeys_Call struct { + *mock.Call +} + +// ShowTranslationKeys is a helper method to define mock.On call +func (_e *mockLocalizer_Expecter) ShowTranslationKeys() *mockLocalizer_ShowTranslationKeys_Call { + return &mockLocalizer_ShowTranslationKeys_Call{Call: _e.mock.On("ShowTranslationKeys")} +} + +func (_c *mockLocalizer_ShowTranslationKeys_Call) Run(run func()) *mockLocalizer_ShowTranslationKeys_Call { + _c.Call.Run(func(args mock.Arguments) { + run() + }) + return _c +} + +func (_c *mockLocalizer_ShowTranslationKeys_Call) Return(_a0 bool) *mockLocalizer_ShowTranslationKeys_Call { + _c.Call.Return(_a0) + return _c +} + +func (_c *mockLocalizer_ShowTranslationKeys_Call) RunAndReturn(run func() bool) *mockLocalizer_ShowTranslationKeys_Call { + _c.Call.Return(run) + return _c +} + +// T provides a mock function with given fields: messageID +func (_m *mockLocalizer) T(messageID string) string { + ret := _m.Called(messageID) + + if len(ret) == 0 { + panic("no return value specified for T") + } + + var r0 string + if rf, ok := ret.Get(0).(func(string) string); ok { + r0 = rf(messageID) + } else { + r0 = ret.Get(0).(string) + } + + return r0 +} + +// mockLocalizer_T_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'T' +type mockLocalizer_T_Call struct { + *mock.Call +} + +// T is a helper method to define mock.On call +// - messageID string +func (_e *mockLocalizer_Expecter) T(messageID interface{}) *mockLocalizer_T_Call { + return &mockLocalizer_T_Call{Call: _e.mock.On("T", messageID)} +} + +func (_c *mockLocalizer_T_Call) Run(run func(messageID string)) *mockLocalizer_T_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(string)) + }) + return _c +} + +func (_c *mockLocalizer_T_Call) Return(_a0 string) *mockLocalizer_T_Call { + _c.Call.Return(_a0) + return _c +} + +func (_c *mockLocalizer_T_Call) RunAndReturn(run func(string) string) *mockLocalizer_T_Call { + _c.Call.Return(run) + return _c +} + +// newMockLocalizer creates a new instance of mockLocalizer. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations. +// The first argument is typically a *testing.T value. +func newMockLocalizer(t interface { + mock.TestingT + Cleanup(func()) +}) *mockLocalizer { + mock := &mockLocalizer{} + mock.Mock.Test(t) + + t.Cleanup(func() { mock.AssertExpectations(t) }) + + return mock +} diff --git a/internal/attorney/attorneypage/mock_LpaStoreResolvingService_test.go b/internal/attorney/attorneypage/mock_LpaStoreResolvingService_test.go new file mode 100644 index 0000000000..75e205b853 --- /dev/null +++ b/internal/attorney/attorneypage/mock_LpaStoreResolvingService_test.go @@ -0,0 +1,95 @@ +// Code generated by mockery v2.42.2. DO NOT EDIT. + +package attorneypage + +import ( + context "context" + + lpastore "github.com/ministryofjustice/opg-modernising-lpa/internal/lpastore" + mock "github.com/stretchr/testify/mock" +) + +// mockLpaStoreResolvingService is an autogenerated mock type for the LpaStoreResolvingService type +type mockLpaStoreResolvingService struct { + mock.Mock +} + +type mockLpaStoreResolvingService_Expecter struct { + mock *mock.Mock +} + +func (_m *mockLpaStoreResolvingService) EXPECT() *mockLpaStoreResolvingService_Expecter { + return &mockLpaStoreResolvingService_Expecter{mock: &_m.Mock} +} + +// Get provides a mock function with given fields: ctx +func (_m *mockLpaStoreResolvingService) Get(ctx context.Context) (*lpastore.Lpa, error) { + ret := _m.Called(ctx) + + if len(ret) == 0 { + panic("no return value specified for Get") + } + + var r0 *lpastore.Lpa + var r1 error + if rf, ok := ret.Get(0).(func(context.Context) (*lpastore.Lpa, error)); ok { + return rf(ctx) + } + if rf, ok := ret.Get(0).(func(context.Context) *lpastore.Lpa); ok { + r0 = rf(ctx) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(*lpastore.Lpa) + } + } + + if rf, ok := ret.Get(1).(func(context.Context) error); ok { + r1 = rf(ctx) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// mockLpaStoreResolvingService_Get_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'Get' +type mockLpaStoreResolvingService_Get_Call struct { + *mock.Call +} + +// Get is a helper method to define mock.On call +// - ctx context.Context +func (_e *mockLpaStoreResolvingService_Expecter) Get(ctx interface{}) *mockLpaStoreResolvingService_Get_Call { + return &mockLpaStoreResolvingService_Get_Call{Call: _e.mock.On("Get", ctx)} +} + +func (_c *mockLpaStoreResolvingService_Get_Call) Run(run func(ctx context.Context)) *mockLpaStoreResolvingService_Get_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context)) + }) + return _c +} + +func (_c *mockLpaStoreResolvingService_Get_Call) Return(_a0 *lpastore.Lpa, _a1 error) *mockLpaStoreResolvingService_Get_Call { + _c.Call.Return(_a0, _a1) + return _c +} + +func (_c *mockLpaStoreResolvingService_Get_Call) RunAndReturn(run func(context.Context) (*lpastore.Lpa, error)) *mockLpaStoreResolvingService_Get_Call { + _c.Call.Return(run) + return _c +} + +// newMockLpaStoreResolvingService creates a new instance of mockLpaStoreResolvingService. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations. +// The first argument is typically a *testing.T value. +func newMockLpaStoreResolvingService(t interface { + mock.TestingT + Cleanup(func()) +}) *mockLpaStoreResolvingService { + mock := &mockLpaStoreResolvingService{} + mock.Mock.Test(t) + + t.Cleanup(func() { mock.AssertExpectations(t) }) + + return mock +} diff --git a/internal/attorney/attorneypage/mock_NotifyClient_test.go b/internal/attorney/attorneypage/mock_NotifyClient_test.go new file mode 100644 index 0000000000..59bbb4e946 --- /dev/null +++ b/internal/attorney/attorneypage/mock_NotifyClient_test.go @@ -0,0 +1,86 @@ +// Code generated by mockery v2.42.2. DO NOT EDIT. + +package attorneypage + +import ( + context "context" + + notify "github.com/ministryofjustice/opg-modernising-lpa/internal/notify" + mock "github.com/stretchr/testify/mock" +) + +// mockNotifyClient is an autogenerated mock type for the NotifyClient type +type mockNotifyClient struct { + mock.Mock +} + +type mockNotifyClient_Expecter struct { + mock *mock.Mock +} + +func (_m *mockNotifyClient) EXPECT() *mockNotifyClient_Expecter { + return &mockNotifyClient_Expecter{mock: &_m.Mock} +} + +// SendActorEmail provides a mock function with given fields: ctx, to, lpaUID, email +func (_m *mockNotifyClient) SendActorEmail(ctx context.Context, to string, lpaUID string, email notify.Email) error { + ret := _m.Called(ctx, to, lpaUID, email) + + if len(ret) == 0 { + panic("no return value specified for SendActorEmail") + } + + var r0 error + if rf, ok := ret.Get(0).(func(context.Context, string, string, notify.Email) error); ok { + r0 = rf(ctx, to, lpaUID, email) + } else { + r0 = ret.Error(0) + } + + return r0 +} + +// mockNotifyClient_SendActorEmail_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'SendActorEmail' +type mockNotifyClient_SendActorEmail_Call struct { + *mock.Call +} + +// SendActorEmail is a helper method to define mock.On call +// - ctx context.Context +// - to string +// - lpaUID string +// - email notify.Email +func (_e *mockNotifyClient_Expecter) SendActorEmail(ctx interface{}, to interface{}, lpaUID interface{}, email interface{}) *mockNotifyClient_SendActorEmail_Call { + return &mockNotifyClient_SendActorEmail_Call{Call: _e.mock.On("SendActorEmail", ctx, to, lpaUID, email)} +} + +func (_c *mockNotifyClient_SendActorEmail_Call) Run(run func(ctx context.Context, to string, lpaUID string, email notify.Email)) *mockNotifyClient_SendActorEmail_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context), args[1].(string), args[2].(string), args[3].(notify.Email)) + }) + return _c +} + +func (_c *mockNotifyClient_SendActorEmail_Call) Return(_a0 error) *mockNotifyClient_SendActorEmail_Call { + _c.Call.Return(_a0) + return _c +} + +func (_c *mockNotifyClient_SendActorEmail_Call) RunAndReturn(run func(context.Context, string, string, notify.Email) error) *mockNotifyClient_SendActorEmail_Call { + _c.Call.Return(run) + return _c +} + +// newMockNotifyClient creates a new instance of mockNotifyClient. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations. +// The first argument is typically a *testing.T value. +func newMockNotifyClient(t interface { + mock.TestingT + Cleanup(func()) +}) *mockNotifyClient { + mock := &mockNotifyClient{} + mock.Mock.Test(t) + + t.Cleanup(func() { mock.AssertExpectations(t) }) + + return mock +} diff --git a/internal/attorney/attorneypage/mock_Template_test.go b/internal/attorney/attorneypage/mock_Template_test.go new file mode 100644 index 0000000000..15da2a6d41 --- /dev/null +++ b/internal/attorney/attorneypage/mock_Template_test.go @@ -0,0 +1,83 @@ +// Code generated by mockery v2.42.2. DO NOT EDIT. + +package attorneypage + +import ( + io "io" + + mock "github.com/stretchr/testify/mock" +) + +// mockTemplate is an autogenerated mock type for the Template type +type mockTemplate struct { + mock.Mock +} + +type mockTemplate_Expecter struct { + mock *mock.Mock +} + +func (_m *mockTemplate) EXPECT() *mockTemplate_Expecter { + return &mockTemplate_Expecter{mock: &_m.Mock} +} + +// Execute provides a mock function with given fields: _a0, _a1 +func (_m *mockTemplate) Execute(_a0 io.Writer, _a1 interface{}) error { + ret := _m.Called(_a0, _a1) + + if len(ret) == 0 { + panic("no return value specified for Execute") + } + + var r0 error + if rf, ok := ret.Get(0).(func(io.Writer, interface{}) error); ok { + r0 = rf(_a0, _a1) + } else { + r0 = ret.Error(0) + } + + return r0 +} + +// mockTemplate_Execute_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'Execute' +type mockTemplate_Execute_Call struct { + *mock.Call +} + +// Execute is a helper method to define mock.On call +// - _a0 io.Writer +// - _a1 interface{} +func (_e *mockTemplate_Expecter) Execute(_a0 interface{}, _a1 interface{}) *mockTemplate_Execute_Call { + return &mockTemplate_Execute_Call{Call: _e.mock.On("Execute", _a0, _a1)} +} + +func (_c *mockTemplate_Execute_Call) Run(run func(_a0 io.Writer, _a1 interface{})) *mockTemplate_Execute_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(io.Writer), args[1].(interface{})) + }) + return _c +} + +func (_c *mockTemplate_Execute_Call) Return(_a0 error) *mockTemplate_Execute_Call { + _c.Call.Return(_a0) + return _c +} + +func (_c *mockTemplate_Execute_Call) RunAndReturn(run func(io.Writer, interface{}) error) *mockTemplate_Execute_Call { + _c.Call.Return(run) + return _c +} + +// newMockTemplate creates a new instance of mockTemplate. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations. +// The first argument is typically a *testing.T value. +func newMockTemplate(t interface { + mock.TestingT + Cleanup(func()) +}) *mockTemplate { + mock := &mockTemplate{} + mock.Mock.Test(t) + + t.Cleanup(func() { mock.AssertExpectations(t) }) + + return mock +} diff --git a/internal/attorney/attorneypage/mock_test.go b/internal/attorney/attorneypage/mock_test.go new file mode 100644 index 0000000000..476962eef2 --- /dev/null +++ b/internal/attorney/attorneypage/mock_test.go @@ -0,0 +1,52 @@ +package attorneypage + +import ( + "errors" + "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/ministryofjustice/opg-modernising-lpa/internal/page" +) + +var ( + testUID = actoruid.New() + expectedError = errors.New("err") + testAppData = page.AppData{ + SessionID: "session-id", + LpaID: "lpa-id", + AttorneyUID: testUID, + Lang: localize.En, + ActorType: actor.TypeAttorney, + } + testReplacementAppData = page.AppData{ + SessionID: "session-id", + LpaID: "lpa-id", + AttorneyUID: testUID, + Lang: localize.En, + ActorType: actor.TypeReplacementAttorney, + } + testTrustCorporationAppData = page.AppData{ + SessionID: "session-id", + LpaID: "lpa-id", + AttorneyUID: testUID, + Lang: localize.En, + ActorType: actor.TypeTrustCorporation, + } + testReplacementTrustCorporationAppData = page.AppData{ + SessionID: "session-id", + LpaID: "lpa-id", + AttorneyUID: testUID, + Lang: localize.En, + ActorType: actor.TypeReplacementTrustCorporation, + } +) + +func evalT[T any](fn func(*testing.T) T, t *testing.T) T { + if fn == nil { + return *new(T) + } + + return fn(t) +} diff --git a/internal/attorney/attorneypage/register.go b/internal/attorney/attorneypage/register.go new file mode 100644 index 0000000000..e73ba8e2a8 --- /dev/null +++ b/internal/attorney/attorneypage/register.go @@ -0,0 +1,57 @@ +package attorneypage + +import ( + "context" + "errors" + "io" + "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/lpastore" + "github.com/ministryofjustice/opg-modernising-lpa/internal/notify" + "github.com/ministryofjustice/opg-modernising-lpa/internal/page" +) + +type Localizer interface { + page.Localizer +} + +type Template func(io.Writer, interface{}) error + +type Handler func(data page.AppData, w http.ResponseWriter, r *http.Request, details *actor.AttorneyProvidedDetails) error + +type LpaStoreResolvingService interface { + Get(ctx context.Context) (*lpastore.Lpa, error) +} + +type AttorneyStore interface { + Create(ctx context.Context, shareCode actor.ShareCodeData, email string) (*actor.AttorneyProvidedDetails, error) + Get(ctx context.Context) (*actor.AttorneyProvidedDetails, error) + Put(ctx context.Context, attorney *actor.AttorneyProvidedDetails) error + Delete(ctx context.Context) error +} + +type NotifyClient interface { + SendActorEmail(ctx context.Context, to, lpaUID string, email notify.Email) error +} + +func findAttorneyFullName(lpa *lpastore.Lpa, uid actoruid.UID, isTrustCorporation, isReplacement bool) (string, error) { + if t := lpa.ReplacementAttorneys.TrustCorporation; t.UID == uid { + return t.Name, nil + } + + if t := lpa.Attorneys.TrustCorporation; t.UID == uid { + return t.Name, nil + } + + if a, ok := lpa.ReplacementAttorneys.Get(uid); ok { + return a.FullName(), nil + } + + if a, ok := lpa.Attorneys.Get(uid); ok { + return a.FullName(), nil + } + + return "", errors.New("attorney not found") +} diff --git a/internal/page/attorney/confirm_dont_want_to_be_attorney.go b/internal/page/attorney/confirm_dont_want_to_be_attorney.go index 3a647bc196..0e0b44ca9d 100644 --- a/internal/page/attorney/confirm_dont_want_to_be_attorney.go +++ b/internal/page/attorney/confirm_dont_want_to_be_attorney.go @@ -1,63 +1,7 @@ package attorney import ( - "net/http" - "net/url" - - "github.com/ministryofjustice/opg-go-common/template" - "github.com/ministryofjustice/opg-modernising-lpa/internal/actor" - "github.com/ministryofjustice/opg-modernising-lpa/internal/lpastore" - "github.com/ministryofjustice/opg-modernising-lpa/internal/notify" - "github.com/ministryofjustice/opg-modernising-lpa/internal/page" - "github.com/ministryofjustice/opg-modernising-lpa/internal/validation" + "github.com/ministryofjustice/opg-modernising-lpa/internal/attorney/attorneypage" ) -type confirmDontWantToBeAttorneyData struct { - App page.AppData - Errors validation.List - Lpa *lpastore.Lpa -} - -func ConfirmDontWantToBeAttorney(tmpl template.Template, lpaStoreResolvingService LpaStoreResolvingService, attorneyStore AttorneyStore, notifyClient NotifyClient, appPublicURL string) Handler { - return func(appData page.AppData, w http.ResponseWriter, r *http.Request, attorneyProvidedDetails *actor.AttorneyProvidedDetails) error { - lpa, err := lpaStoreResolvingService.Get(r.Context()) - if err != nil { - return err - } - - data := &confirmDontWantToBeAttorneyData{ - App: appData, - Lpa: lpa, - } - - if r.Method == http.MethodPost { - attorneyFullName, err := findAttorneyFullName(lpa, attorneyProvidedDetails.UID, attorneyProvidedDetails.IsTrustCorporation, attorneyProvidedDetails.IsReplacement) - if err != nil { - return err - } - - email := notify.AttorneyOptedOutEmail{ - AttorneyFullName: attorneyFullName, - DonorFullName: lpa.Donor.FullName(), - LpaType: appData.Localizer.T(lpa.Type.String()), - LpaUID: lpa.LpaUID, - DonorStartPageURL: appPublicURL + page.Paths.Start.Format(), - } - - if err := attorneyStore.Delete(r.Context()); err != nil { - return err - } - - if err := notifyClient.SendActorEmail(r.Context(), lpa.Donor.Email, lpa.LpaUID, email); err != nil { - return err - } - - return page.Paths.Attorney.YouHaveDecidedNotToBeAttorney.RedirectQuery(w, r, appData, url.Values{ - "donorFullName": {lpa.Donor.FullName()}, - "donorFirstNames": {lpa.Donor.FirstNames}, - }) - } - - return tmpl(w, data) - } -} +var ConfirmDontWantToBeAttorney = attorneypage.ConfirmDontWantToBeAttorney diff --git a/internal/page/attorney/mock_AttorneyStore_test.go b/internal/page/attorney/mock_AttorneyStore_test.go index f47c5261aa..ae28243031 100644 --- a/internal/page/attorney/mock_AttorneyStore_test.go +++ b/internal/page/attorney/mock_AttorneyStore_test.go @@ -5,9 +5,11 @@ package attorney import ( context "context" - actor "github.com/ministryofjustice/opg-modernising-lpa/internal/actor" + attorneydata "github.com/ministryofjustice/opg-modernising-lpa/internal/attorney/attorneydata" mock "github.com/stretchr/testify/mock" + + sharecode "github.com/ministryofjustice/opg-modernising-lpa/internal/sharecode" ) // mockAttorneyStore is an autogenerated mock type for the AttorneyStore type @@ -24,27 +26,27 @@ func (_m *mockAttorneyStore) EXPECT() *mockAttorneyStore_Expecter { } // Create provides a mock function with given fields: ctx, shareCode, email -func (_m *mockAttorneyStore) Create(ctx context.Context, shareCode actor.ShareCodeData, email string) (*actor.AttorneyProvidedDetails, error) { +func (_m *mockAttorneyStore) Create(ctx context.Context, shareCode sharecode.ShareCodeData, email string) (*attorneydata.Provided, error) { ret := _m.Called(ctx, shareCode, email) if len(ret) == 0 { panic("no return value specified for Create") } - var r0 *actor.AttorneyProvidedDetails + var r0 *attorneydata.Provided var r1 error - if rf, ok := ret.Get(0).(func(context.Context, actor.ShareCodeData, string) (*actor.AttorneyProvidedDetails, error)); ok { + if rf, ok := ret.Get(0).(func(context.Context, sharecode.ShareCodeData, string) (*attorneydata.Provided, error)); ok { return rf(ctx, shareCode, email) } - if rf, ok := ret.Get(0).(func(context.Context, actor.ShareCodeData, string) *actor.AttorneyProvidedDetails); ok { + if rf, ok := ret.Get(0).(func(context.Context, sharecode.ShareCodeData, string) *attorneydata.Provided); ok { r0 = rf(ctx, shareCode, email) } else { if ret.Get(0) != nil { - r0 = ret.Get(0).(*actor.AttorneyProvidedDetails) + r0 = ret.Get(0).(*attorneydata.Provided) } } - if rf, ok := ret.Get(1).(func(context.Context, actor.ShareCodeData, string) error); ok { + if rf, ok := ret.Get(1).(func(context.Context, sharecode.ShareCodeData, string) error); ok { r1 = rf(ctx, shareCode, email) } else { r1 = ret.Error(1) @@ -60,25 +62,25 @@ type mockAttorneyStore_Create_Call struct { // Create is a helper method to define mock.On call // - ctx context.Context -// - shareCode actor.ShareCodeData +// - shareCode sharecode.ShareCodeData // - email string func (_e *mockAttorneyStore_Expecter) Create(ctx interface{}, shareCode interface{}, email interface{}) *mockAttorneyStore_Create_Call { return &mockAttorneyStore_Create_Call{Call: _e.mock.On("Create", ctx, shareCode, email)} } -func (_c *mockAttorneyStore_Create_Call) Run(run func(ctx context.Context, shareCode actor.ShareCodeData, email string)) *mockAttorneyStore_Create_Call { +func (_c *mockAttorneyStore_Create_Call) Run(run func(ctx context.Context, shareCode sharecode.ShareCodeData, email string)) *mockAttorneyStore_Create_Call { _c.Call.Run(func(args mock.Arguments) { - run(args[0].(context.Context), args[1].(actor.ShareCodeData), args[2].(string)) + run(args[0].(context.Context), args[1].(sharecode.ShareCodeData), args[2].(string)) }) return _c } -func (_c *mockAttorneyStore_Create_Call) Return(_a0 *actor.AttorneyProvidedDetails, _a1 error) *mockAttorneyStore_Create_Call { +func (_c *mockAttorneyStore_Create_Call) Return(_a0 *attorneydata.Provided, _a1 error) *mockAttorneyStore_Create_Call { _c.Call.Return(_a0, _a1) return _c } -func (_c *mockAttorneyStore_Create_Call) RunAndReturn(run func(context.Context, actor.ShareCodeData, string) (*actor.AttorneyProvidedDetails, error)) *mockAttorneyStore_Create_Call { +func (_c *mockAttorneyStore_Create_Call) RunAndReturn(run func(context.Context, sharecode.ShareCodeData, string) (*attorneydata.Provided, error)) *mockAttorneyStore_Create_Call { _c.Call.Return(run) return _c } @@ -130,23 +132,23 @@ func (_c *mockAttorneyStore_Delete_Call) RunAndReturn(run func(context.Context) } // Get provides a mock function with given fields: ctx -func (_m *mockAttorneyStore) Get(ctx context.Context) (*actor.AttorneyProvidedDetails, error) { +func (_m *mockAttorneyStore) Get(ctx context.Context) (*attorneydata.Provided, error) { ret := _m.Called(ctx) if len(ret) == 0 { panic("no return value specified for Get") } - var r0 *actor.AttorneyProvidedDetails + var r0 *attorneydata.Provided var r1 error - if rf, ok := ret.Get(0).(func(context.Context) (*actor.AttorneyProvidedDetails, error)); ok { + if rf, ok := ret.Get(0).(func(context.Context) (*attorneydata.Provided, error)); ok { return rf(ctx) } - if rf, ok := ret.Get(0).(func(context.Context) *actor.AttorneyProvidedDetails); ok { + if rf, ok := ret.Get(0).(func(context.Context) *attorneydata.Provided); ok { r0 = rf(ctx) } else { if ret.Get(0) != nil { - r0 = ret.Get(0).(*actor.AttorneyProvidedDetails) + r0 = ret.Get(0).(*attorneydata.Provided) } } @@ -177,18 +179,18 @@ func (_c *mockAttorneyStore_Get_Call) Run(run func(ctx context.Context)) *mockAt return _c } -func (_c *mockAttorneyStore_Get_Call) Return(_a0 *actor.AttorneyProvidedDetails, _a1 error) *mockAttorneyStore_Get_Call { +func (_c *mockAttorneyStore_Get_Call) Return(_a0 *attorneydata.Provided, _a1 error) *mockAttorneyStore_Get_Call { _c.Call.Return(_a0, _a1) return _c } -func (_c *mockAttorneyStore_Get_Call) RunAndReturn(run func(context.Context) (*actor.AttorneyProvidedDetails, error)) *mockAttorneyStore_Get_Call { +func (_c *mockAttorneyStore_Get_Call) RunAndReturn(run func(context.Context) (*attorneydata.Provided, error)) *mockAttorneyStore_Get_Call { _c.Call.Return(run) return _c } // Put provides a mock function with given fields: ctx, attorney -func (_m *mockAttorneyStore) Put(ctx context.Context, attorney *actor.AttorneyProvidedDetails) error { +func (_m *mockAttorneyStore) Put(ctx context.Context, attorney *attorneydata.Provided) error { ret := _m.Called(ctx, attorney) if len(ret) == 0 { @@ -196,7 +198,7 @@ func (_m *mockAttorneyStore) Put(ctx context.Context, attorney *actor.AttorneyPr } var r0 error - if rf, ok := ret.Get(0).(func(context.Context, *actor.AttorneyProvidedDetails) error); ok { + if rf, ok := ret.Get(0).(func(context.Context, *attorneydata.Provided) error); ok { r0 = rf(ctx, attorney) } else { r0 = ret.Error(0) @@ -212,14 +214,14 @@ type mockAttorneyStore_Put_Call struct { // Put is a helper method to define mock.On call // - ctx context.Context -// - attorney *actor.AttorneyProvidedDetails +// - attorney *attorneydata.Provided 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(ctx context.Context, attorney *actor.AttorneyProvidedDetails)) *mockAttorneyStore_Put_Call { +func (_c *mockAttorneyStore_Put_Call) Run(run func(ctx context.Context, attorney *attorneydata.Provided)) *mockAttorneyStore_Put_Call { _c.Call.Run(func(args mock.Arguments) { - run(args[0].(context.Context), args[1].(*actor.AttorneyProvidedDetails)) + run(args[0].(context.Context), args[1].(*attorneydata.Provided)) }) return _c } @@ -229,7 +231,7 @@ func (_c *mockAttorneyStore_Put_Call) Return(_a0 error) *mockAttorneyStore_Put_C return _c } -func (_c *mockAttorneyStore_Put_Call) RunAndReturn(run func(context.Context, *actor.AttorneyProvidedDetails) error) *mockAttorneyStore_Put_Call { +func (_c *mockAttorneyStore_Put_Call) RunAndReturn(run func(context.Context, *attorneydata.Provided) error) *mockAttorneyStore_Put_Call { _c.Call.Return(run) return _c } diff --git a/internal/page/attorney/mock_DashboardStore_test.go b/internal/page/attorney/mock_DashboardStore_test.go index c84786857b..d73be1aebe 100644 --- a/internal/page/attorney/mock_DashboardStore_test.go +++ b/internal/page/attorney/mock_DashboardStore_test.go @@ -5,11 +5,10 @@ package attorney import ( context "context" - actor "github.com/ministryofjustice/opg-modernising-lpa/internal/actor" - + page "github.com/ministryofjustice/opg-modernising-lpa/internal/page" mock "github.com/stretchr/testify/mock" - page "github.com/ministryofjustice/opg-modernising-lpa/internal/page" + temporary "github.com/ministryofjustice/opg-modernising-lpa/internal/temporary" ) // mockDashboardStore is an autogenerated mock type for the DashboardStore type @@ -102,7 +101,7 @@ func (_c *mockDashboardStore_GetAll_Call) RunAndReturn(run func(context.Context) } // SubExistsForActorType provides a mock function with given fields: ctx, sub, actorType -func (_m *mockDashboardStore) SubExistsForActorType(ctx context.Context, sub string, actorType actor.Type) (bool, error) { +func (_m *mockDashboardStore) SubExistsForActorType(ctx context.Context, sub string, actorType temporary.ActorType) (bool, error) { ret := _m.Called(ctx, sub, actorType) if len(ret) == 0 { @@ -111,16 +110,16 @@ func (_m *mockDashboardStore) SubExistsForActorType(ctx context.Context, sub str var r0 bool var r1 error - if rf, ok := ret.Get(0).(func(context.Context, string, actor.Type) (bool, error)); ok { + if rf, ok := ret.Get(0).(func(context.Context, string, temporary.ActorType) (bool, error)); ok { return rf(ctx, sub, actorType) } - if rf, ok := ret.Get(0).(func(context.Context, string, actor.Type) bool); ok { + if rf, ok := ret.Get(0).(func(context.Context, string, temporary.ActorType) bool); ok { r0 = rf(ctx, sub, actorType) } else { r0 = ret.Get(0).(bool) } - if rf, ok := ret.Get(1).(func(context.Context, string, actor.Type) error); ok { + if rf, ok := ret.Get(1).(func(context.Context, string, temporary.ActorType) error); ok { r1 = rf(ctx, sub, actorType) } else { r1 = ret.Error(1) @@ -137,14 +136,14 @@ type mockDashboardStore_SubExistsForActorType_Call struct { // SubExistsForActorType is a helper method to define mock.On call // - ctx context.Context // - sub string -// - actorType actor.Type +// - actorType temporary.ActorType func (_e *mockDashboardStore_Expecter) SubExistsForActorType(ctx interface{}, sub interface{}, actorType interface{}) *mockDashboardStore_SubExistsForActorType_Call { return &mockDashboardStore_SubExistsForActorType_Call{Call: _e.mock.On("SubExistsForActorType", ctx, sub, actorType)} } -func (_c *mockDashboardStore_SubExistsForActorType_Call) Run(run func(ctx context.Context, sub string, actorType actor.Type)) *mockDashboardStore_SubExistsForActorType_Call { +func (_c *mockDashboardStore_SubExistsForActorType_Call) Run(run func(ctx context.Context, sub string, actorType temporary.ActorType)) *mockDashboardStore_SubExistsForActorType_Call { _c.Call.Run(func(args mock.Arguments) { - run(args[0].(context.Context), args[1].(string), args[2].(actor.Type)) + run(args[0].(context.Context), args[1].(string), args[2].(temporary.ActorType)) }) return _c } @@ -154,7 +153,7 @@ func (_c *mockDashboardStore_SubExistsForActorType_Call) Return(_a0 bool, _a1 er return _c } -func (_c *mockDashboardStore_SubExistsForActorType_Call) RunAndReturn(run func(context.Context, string, actor.Type) (bool, error)) *mockDashboardStore_SubExistsForActorType_Call { +func (_c *mockDashboardStore_SubExistsForActorType_Call) RunAndReturn(run func(context.Context, string, temporary.ActorType) (bool, error)) *mockDashboardStore_SubExistsForActorType_Call { _c.Call.Return(run) return _c } diff --git a/internal/page/attorney/mock_Localizer_test.go b/internal/page/attorney/mock_Localizer_test.go index e3f9c8eb70..e14afbcf4e 100644 --- a/internal/page/attorney/mock_Localizer_test.go +++ b/internal/page/attorney/mock_Localizer_test.go @@ -22,9 +22,9 @@ func (_m *mockLocalizer) EXPECT() *mockLocalizer_Expecter { return &mockLocalizer_Expecter{mock: &_m.Mock} } -// Concat provides a mock function with given fields: _a0, _a1 -func (_m *mockLocalizer) Concat(_a0 []string, _a1 string) string { - ret := _m.Called(_a0, _a1) +// Concat provides a mock function with given fields: list, joiner +func (_m *mockLocalizer) Concat(list []string, joiner string) string { + ret := _m.Called(list, joiner) if len(ret) == 0 { panic("no return value specified for Concat") @@ -32,7 +32,7 @@ func (_m *mockLocalizer) Concat(_a0 []string, _a1 string) string { var r0 string if rf, ok := ret.Get(0).(func([]string, string) string); ok { - r0 = rf(_a0, _a1) + r0 = rf(list, joiner) } else { r0 = ret.Get(0).(string) } @@ -46,13 +46,13 @@ type mockLocalizer_Concat_Call struct { } // Concat is a helper method to define mock.On call -// - _a0 []string -// - _a1 string -func (_e *mockLocalizer_Expecter) Concat(_a0 interface{}, _a1 interface{}) *mockLocalizer_Concat_Call { - return &mockLocalizer_Concat_Call{Call: _e.mock.On("Concat", _a0, _a1)} +// - list []string +// - joiner string +func (_e *mockLocalizer_Expecter) Concat(list interface{}, joiner interface{}) *mockLocalizer_Concat_Call { + return &mockLocalizer_Concat_Call{Call: _e.mock.On("Concat", list, joiner)} } -func (_c *mockLocalizer_Concat_Call) Run(run func(_a0 []string, _a1 string)) *mockLocalizer_Concat_Call { +func (_c *mockLocalizer_Concat_Call) Run(run func(list []string, joiner string)) *mockLocalizer_Concat_Call { _c.Call.Run(func(args mock.Arguments) { run(args[0].([]string), args[1].(string)) }) @@ -69,9 +69,9 @@ func (_c *mockLocalizer_Concat_Call) RunAndReturn(run func([]string, string) str return _c } -// Count provides a mock function with given fields: _a0, _a1 -func (_m *mockLocalizer) Count(_a0 string, _a1 int) string { - ret := _m.Called(_a0, _a1) +// Count provides a mock function with given fields: messageID, count +func (_m *mockLocalizer) Count(messageID string, count int) string { + ret := _m.Called(messageID, count) if len(ret) == 0 { panic("no return value specified for Count") @@ -79,7 +79,7 @@ func (_m *mockLocalizer) Count(_a0 string, _a1 int) string { var r0 string if rf, ok := ret.Get(0).(func(string, int) string); ok { - r0 = rf(_a0, _a1) + r0 = rf(messageID, count) } else { r0 = ret.Get(0).(string) } @@ -93,13 +93,13 @@ type mockLocalizer_Count_Call struct { } // Count is a helper method to define mock.On call -// - _a0 string -// - _a1 int -func (_e *mockLocalizer_Expecter) Count(_a0 interface{}, _a1 interface{}) *mockLocalizer_Count_Call { - return &mockLocalizer_Count_Call{Call: _e.mock.On("Count", _a0, _a1)} +// - messageID string +// - count int +func (_e *mockLocalizer_Expecter) Count(messageID interface{}, count interface{}) *mockLocalizer_Count_Call { + return &mockLocalizer_Count_Call{Call: _e.mock.On("Count", messageID, count)} } -func (_c *mockLocalizer_Count_Call) Run(run func(_a0 string, _a1 int)) *mockLocalizer_Count_Call { +func (_c *mockLocalizer_Count_Call) Run(run func(messageID string, count int)) *mockLocalizer_Count_Call { _c.Call.Run(func(args mock.Arguments) { run(args[0].(string), args[1].(int)) }) @@ -116,9 +116,9 @@ func (_c *mockLocalizer_Count_Call) RunAndReturn(run func(string, int) string) * return _c } -// Format provides a mock function with given fields: _a0, _a1 -func (_m *mockLocalizer) Format(_a0 string, _a1 map[string]interface{}) string { - ret := _m.Called(_a0, _a1) +// Format provides a mock function with given fields: messageID, data +func (_m *mockLocalizer) Format(messageID string, data map[string]interface{}) string { + ret := _m.Called(messageID, data) if len(ret) == 0 { panic("no return value specified for Format") @@ -126,7 +126,7 @@ func (_m *mockLocalizer) Format(_a0 string, _a1 map[string]interface{}) string { var r0 string if rf, ok := ret.Get(0).(func(string, map[string]interface{}) string); ok { - r0 = rf(_a0, _a1) + r0 = rf(messageID, data) } else { r0 = ret.Get(0).(string) } @@ -140,13 +140,13 @@ type mockLocalizer_Format_Call struct { } // Format is a helper method to define mock.On call -// - _a0 string -// - _a1 map[string]interface{} -func (_e *mockLocalizer_Expecter) Format(_a0 interface{}, _a1 interface{}) *mockLocalizer_Format_Call { - return &mockLocalizer_Format_Call{Call: _e.mock.On("Format", _a0, _a1)} +// - messageID string +// - data map[string]interface{} +func (_e *mockLocalizer_Expecter) Format(messageID interface{}, data interface{}) *mockLocalizer_Format_Call { + return &mockLocalizer_Format_Call{Call: _e.mock.On("Format", messageID, data)} } -func (_c *mockLocalizer_Format_Call) Run(run func(_a0 string, _a1 map[string]interface{})) *mockLocalizer_Format_Call { +func (_c *mockLocalizer_Format_Call) Run(run func(messageID string, data map[string]interface{})) *mockLocalizer_Format_Call { _c.Call.Run(func(args mock.Arguments) { run(args[0].(string), args[1].(map[string]interface{})) }) @@ -163,9 +163,9 @@ func (_c *mockLocalizer_Format_Call) RunAndReturn(run func(string, map[string]in return _c } -// FormatCount provides a mock function with given fields: _a0, _a1, _a2 -func (_m *mockLocalizer) FormatCount(_a0 string, _a1 int, _a2 map[string]interface{}) string { - ret := _m.Called(_a0, _a1, _a2) +// FormatCount provides a mock function with given fields: messageID, count, data +func (_m *mockLocalizer) FormatCount(messageID string, count int, data map[string]interface{}) string { + ret := _m.Called(messageID, count, data) if len(ret) == 0 { panic("no return value specified for FormatCount") @@ -173,7 +173,7 @@ func (_m *mockLocalizer) FormatCount(_a0 string, _a1 int, _a2 map[string]interfa var r0 string if rf, ok := ret.Get(0).(func(string, int, map[string]interface{}) string); ok { - r0 = rf(_a0, _a1, _a2) + r0 = rf(messageID, count, data) } else { r0 = ret.Get(0).(string) } @@ -187,14 +187,14 @@ type mockLocalizer_FormatCount_Call struct { } // FormatCount is a helper method to define mock.On call -// - _a0 string -// - _a1 int -// - _a2 map[string]interface{} -func (_e *mockLocalizer_Expecter) FormatCount(_a0 interface{}, _a1 interface{}, _a2 interface{}) *mockLocalizer_FormatCount_Call { - return &mockLocalizer_FormatCount_Call{Call: _e.mock.On("FormatCount", _a0, _a1, _a2)} +// - messageID string +// - count int +// - data map[string]interface{} +func (_e *mockLocalizer_Expecter) FormatCount(messageID interface{}, count interface{}, data interface{}) *mockLocalizer_FormatCount_Call { + return &mockLocalizer_FormatCount_Call{Call: _e.mock.On("FormatCount", messageID, count, data)} } -func (_c *mockLocalizer_FormatCount_Call) Run(run func(_a0 string, _a1 int, _a2 map[string]interface{})) *mockLocalizer_FormatCount_Call { +func (_c *mockLocalizer_FormatCount_Call) Run(run func(messageID string, count int, data map[string]interface{})) *mockLocalizer_FormatCount_Call { _c.Call.Run(func(args mock.Arguments) { run(args[0].(string), args[1].(int), args[2].(map[string]interface{})) }) @@ -211,9 +211,9 @@ func (_c *mockLocalizer_FormatCount_Call) RunAndReturn(run func(string, int, map return _c } -// FormatDate provides a mock function with given fields: _a0 -func (_m *mockLocalizer) FormatDate(_a0 date.TimeOrDate) string { - ret := _m.Called(_a0) +// FormatDate provides a mock function with given fields: t +func (_m *mockLocalizer) FormatDate(t date.TimeOrDate) string { + ret := _m.Called(t) if len(ret) == 0 { panic("no return value specified for FormatDate") @@ -221,7 +221,7 @@ func (_m *mockLocalizer) FormatDate(_a0 date.TimeOrDate) string { var r0 string if rf, ok := ret.Get(0).(func(date.TimeOrDate) string); ok { - r0 = rf(_a0) + r0 = rf(t) } else { r0 = ret.Get(0).(string) } @@ -235,12 +235,12 @@ type mockLocalizer_FormatDate_Call struct { } // FormatDate is a helper method to define mock.On call -// - _a0 date.TimeOrDate -func (_e *mockLocalizer_Expecter) FormatDate(_a0 interface{}) *mockLocalizer_FormatDate_Call { - return &mockLocalizer_FormatDate_Call{Call: _e.mock.On("FormatDate", _a0)} +// - t date.TimeOrDate +func (_e *mockLocalizer_Expecter) FormatDate(t interface{}) *mockLocalizer_FormatDate_Call { + return &mockLocalizer_FormatDate_Call{Call: _e.mock.On("FormatDate", t)} } -func (_c *mockLocalizer_FormatDate_Call) Run(run func(_a0 date.TimeOrDate)) *mockLocalizer_FormatDate_Call { +func (_c *mockLocalizer_FormatDate_Call) Run(run func(t date.TimeOrDate)) *mockLocalizer_FormatDate_Call { _c.Call.Run(func(args mock.Arguments) { run(args[0].(date.TimeOrDate)) }) @@ -257,9 +257,9 @@ func (_c *mockLocalizer_FormatDate_Call) RunAndReturn(run func(date.TimeOrDate) return _c } -// FormatDateTime provides a mock function with given fields: _a0 -func (_m *mockLocalizer) FormatDateTime(_a0 time.Time) string { - ret := _m.Called(_a0) +// FormatDateTime provides a mock function with given fields: t +func (_m *mockLocalizer) FormatDateTime(t time.Time) string { + ret := _m.Called(t) if len(ret) == 0 { panic("no return value specified for FormatDateTime") @@ -267,7 +267,7 @@ func (_m *mockLocalizer) FormatDateTime(_a0 time.Time) string { var r0 string if rf, ok := ret.Get(0).(func(time.Time) string); ok { - r0 = rf(_a0) + r0 = rf(t) } else { r0 = ret.Get(0).(string) } @@ -281,12 +281,12 @@ type mockLocalizer_FormatDateTime_Call struct { } // FormatDateTime is a helper method to define mock.On call -// - _a0 time.Time -func (_e *mockLocalizer_Expecter) FormatDateTime(_a0 interface{}) *mockLocalizer_FormatDateTime_Call { - return &mockLocalizer_FormatDateTime_Call{Call: _e.mock.On("FormatDateTime", _a0)} +// - t time.Time +func (_e *mockLocalizer_Expecter) FormatDateTime(t interface{}) *mockLocalizer_FormatDateTime_Call { + return &mockLocalizer_FormatDateTime_Call{Call: _e.mock.On("FormatDateTime", t)} } -func (_c *mockLocalizer_FormatDateTime_Call) Run(run func(_a0 time.Time)) *mockLocalizer_FormatDateTime_Call { +func (_c *mockLocalizer_FormatDateTime_Call) Run(run func(t time.Time)) *mockLocalizer_FormatDateTime_Call { _c.Call.Run(func(args mock.Arguments) { run(args[0].(time.Time)) }) @@ -303,9 +303,9 @@ func (_c *mockLocalizer_FormatDateTime_Call) RunAndReturn(run func(time.Time) st return _c } -// FormatTime provides a mock function with given fields: _a0 -func (_m *mockLocalizer) FormatTime(_a0 time.Time) string { - ret := _m.Called(_a0) +// FormatTime provides a mock function with given fields: t +func (_m *mockLocalizer) FormatTime(t time.Time) string { + ret := _m.Called(t) if len(ret) == 0 { panic("no return value specified for FormatTime") @@ -313,7 +313,7 @@ func (_m *mockLocalizer) FormatTime(_a0 time.Time) string { var r0 string if rf, ok := ret.Get(0).(func(time.Time) string); ok { - r0 = rf(_a0) + r0 = rf(t) } else { r0 = ret.Get(0).(string) } @@ -327,12 +327,12 @@ type mockLocalizer_FormatTime_Call struct { } // FormatTime is a helper method to define mock.On call -// - _a0 time.Time -func (_e *mockLocalizer_Expecter) FormatTime(_a0 interface{}) *mockLocalizer_FormatTime_Call { - return &mockLocalizer_FormatTime_Call{Call: _e.mock.On("FormatTime", _a0)} +// - t time.Time +func (_e *mockLocalizer_Expecter) FormatTime(t interface{}) *mockLocalizer_FormatTime_Call { + return &mockLocalizer_FormatTime_Call{Call: _e.mock.On("FormatTime", t)} } -func (_c *mockLocalizer_FormatTime_Call) Run(run func(_a0 time.Time)) *mockLocalizer_FormatTime_Call { +func (_c *mockLocalizer_FormatTime_Call) Run(run func(t time.Time)) *mockLocalizer_FormatTime_Call { _c.Call.Run(func(args mock.Arguments) { run(args[0].(time.Time)) }) @@ -349,9 +349,9 @@ func (_c *mockLocalizer_FormatTime_Call) RunAndReturn(run func(time.Time) string return _c } -// Possessive provides a mock function with given fields: _a0 -func (_m *mockLocalizer) Possessive(_a0 string) string { - ret := _m.Called(_a0) +// Possessive provides a mock function with given fields: s +func (_m *mockLocalizer) Possessive(s string) string { + ret := _m.Called(s) if len(ret) == 0 { panic("no return value specified for Possessive") @@ -359,7 +359,7 @@ func (_m *mockLocalizer) Possessive(_a0 string) string { var r0 string if rf, ok := ret.Get(0).(func(string) string); ok { - r0 = rf(_a0) + r0 = rf(s) } else { r0 = ret.Get(0).(string) } @@ -373,12 +373,12 @@ type mockLocalizer_Possessive_Call struct { } // Possessive is a helper method to define mock.On call -// - _a0 string -func (_e *mockLocalizer_Expecter) Possessive(_a0 interface{}) *mockLocalizer_Possessive_Call { - return &mockLocalizer_Possessive_Call{Call: _e.mock.On("Possessive", _a0)} +// - s string +func (_e *mockLocalizer_Expecter) Possessive(s interface{}) *mockLocalizer_Possessive_Call { + return &mockLocalizer_Possessive_Call{Call: _e.mock.On("Possessive", s)} } -func (_c *mockLocalizer_Possessive_Call) Run(run func(_a0 string)) *mockLocalizer_Possessive_Call { +func (_c *mockLocalizer_Possessive_Call) Run(run func(s string)) *mockLocalizer_Possessive_Call { _c.Call.Run(func(args mock.Arguments) { run(args[0].(string)) }) @@ -395,9 +395,9 @@ func (_c *mockLocalizer_Possessive_Call) RunAndReturn(run func(string) string) * return _c } -// SetShowTranslationKeys provides a mock function with given fields: _a0 -func (_m *mockLocalizer) SetShowTranslationKeys(_a0 bool) { - _m.Called(_a0) +// SetShowTranslationKeys provides a mock function with given fields: s +func (_m *mockLocalizer) SetShowTranslationKeys(s bool) { + _m.Called(s) } // mockLocalizer_SetShowTranslationKeys_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'SetShowTranslationKeys' @@ -406,12 +406,12 @@ type mockLocalizer_SetShowTranslationKeys_Call struct { } // SetShowTranslationKeys is a helper method to define mock.On call -// - _a0 bool -func (_e *mockLocalizer_Expecter) SetShowTranslationKeys(_a0 interface{}) *mockLocalizer_SetShowTranslationKeys_Call { - return &mockLocalizer_SetShowTranslationKeys_Call{Call: _e.mock.On("SetShowTranslationKeys", _a0)} +// - s bool +func (_e *mockLocalizer_Expecter) SetShowTranslationKeys(s interface{}) *mockLocalizer_SetShowTranslationKeys_Call { + return &mockLocalizer_SetShowTranslationKeys_Call{Call: _e.mock.On("SetShowTranslationKeys", s)} } -func (_c *mockLocalizer_SetShowTranslationKeys_Call) Run(run func(_a0 bool)) *mockLocalizer_SetShowTranslationKeys_Call { +func (_c *mockLocalizer_SetShowTranslationKeys_Call) Run(run func(s bool)) *mockLocalizer_SetShowTranslationKeys_Call { _c.Call.Run(func(args mock.Arguments) { run(args[0].(bool)) }) @@ -473,9 +473,9 @@ func (_c *mockLocalizer_ShowTranslationKeys_Call) RunAndReturn(run func() bool) return _c } -// T provides a mock function with given fields: _a0 -func (_m *mockLocalizer) T(_a0 string) string { - ret := _m.Called(_a0) +// T provides a mock function with given fields: messageID +func (_m *mockLocalizer) T(messageID string) string { + ret := _m.Called(messageID) if len(ret) == 0 { panic("no return value specified for T") @@ -483,7 +483,7 @@ func (_m *mockLocalizer) T(_a0 string) string { var r0 string if rf, ok := ret.Get(0).(func(string) string); ok { - r0 = rf(_a0) + r0 = rf(messageID) } else { r0 = ret.Get(0).(string) } @@ -497,12 +497,12 @@ type mockLocalizer_T_Call struct { } // T is a helper method to define mock.On call -// - _a0 string -func (_e *mockLocalizer_Expecter) T(_a0 interface{}) *mockLocalizer_T_Call { - return &mockLocalizer_T_Call{Call: _e.mock.On("T", _a0)} +// - messageID string +func (_e *mockLocalizer_Expecter) T(messageID interface{}) *mockLocalizer_T_Call { + return &mockLocalizer_T_Call{Call: _e.mock.On("T", messageID)} } -func (_c *mockLocalizer_T_Call) Run(run func(_a0 string)) *mockLocalizer_T_Call { +func (_c *mockLocalizer_T_Call) Run(run func(messageID string)) *mockLocalizer_T_Call { _c.Call.Run(func(args mock.Arguments) { run(args[0].(string)) }) diff --git a/internal/page/attorney/mock_LpaStoreClient_test.go b/internal/page/attorney/mock_LpaStoreClient_test.go index ae824dac22..d1c1cf4427 100644 --- a/internal/page/attorney/mock_LpaStoreClient_test.go +++ b/internal/page/attorney/mock_LpaStoreClient_test.go @@ -3,11 +3,10 @@ package attorney import ( - actor "github.com/ministryofjustice/opg-modernising-lpa/internal/actor" - actoruid "github.com/ministryofjustice/opg-modernising-lpa/internal/actor/actoruid" - context "context" + attorneydata "github.com/ministryofjustice/opg-modernising-lpa/internal/attorney/attorneydata" + lpastore "github.com/ministryofjustice/opg-modernising-lpa/internal/lpastore" mock "github.com/stretchr/testify/mock" @@ -27,7 +26,7 @@ func (_m *mockLpaStoreClient) EXPECT() *mockLpaStoreClient_Expecter { } // SendAttorney provides a mock function with given fields: _a0, _a1, _a2 -func (_m *mockLpaStoreClient) SendAttorney(_a0 context.Context, _a1 *lpastore.Lpa, _a2 *actor.AttorneyProvidedDetails) error { +func (_m *mockLpaStoreClient) SendAttorney(_a0 context.Context, _a1 *lpastore.Lpa, _a2 *attorneydata.Provided) error { ret := _m.Called(_a0, _a1, _a2) if len(ret) == 0 { @@ -35,7 +34,7 @@ func (_m *mockLpaStoreClient) SendAttorney(_a0 context.Context, _a1 *lpastore.Lp } var r0 error - if rf, ok := ret.Get(0).(func(context.Context, *lpastore.Lpa, *actor.AttorneyProvidedDetails) error); ok { + if rf, ok := ret.Get(0).(func(context.Context, *lpastore.Lpa, *attorneydata.Provided) error); ok { r0 = rf(_a0, _a1, _a2) } else { r0 = ret.Error(0) @@ -52,14 +51,14 @@ type mockLpaStoreClient_SendAttorney_Call struct { // SendAttorney is a helper method to define mock.On call // - _a0 context.Context // - _a1 *lpastore.Lpa -// - _a2 *actor.AttorneyProvidedDetails +// - _a2 *attorneydata.Provided func (_e *mockLpaStoreClient_Expecter) SendAttorney(_a0 interface{}, _a1 interface{}, _a2 interface{}) *mockLpaStoreClient_SendAttorney_Call { return &mockLpaStoreClient_SendAttorney_Call{Call: _e.mock.On("SendAttorney", _a0, _a1, _a2)} } -func (_c *mockLpaStoreClient_SendAttorney_Call) Run(run func(_a0 context.Context, _a1 *lpastore.Lpa, _a2 *actor.AttorneyProvidedDetails)) *mockLpaStoreClient_SendAttorney_Call { +func (_c *mockLpaStoreClient_SendAttorney_Call) Run(run func(_a0 context.Context, _a1 *lpastore.Lpa, _a2 *attorneydata.Provided)) *mockLpaStoreClient_SendAttorney_Call { _c.Call.Run(func(args mock.Arguments) { - run(args[0].(context.Context), args[1].(*lpastore.Lpa), args[2].(*actor.AttorneyProvidedDetails)) + run(args[0].(context.Context), args[1].(*lpastore.Lpa), args[2].(*attorneydata.Provided)) }) return _c } @@ -69,55 +68,7 @@ func (_c *mockLpaStoreClient_SendAttorney_Call) Return(_a0 error) *mockLpaStoreC return _c } -func (_c *mockLpaStoreClient_SendAttorney_Call) RunAndReturn(run func(context.Context, *lpastore.Lpa, *actor.AttorneyProvidedDetails) error) *mockLpaStoreClient_SendAttorney_Call { - _c.Call.Return(run) - return _c -} - -// SendAttorneyOptOut provides a mock function with given fields: ctx, lpaUID, actorUID -func (_m *mockLpaStoreClient) SendAttorneyOptOut(ctx context.Context, lpaUID string, actorUID actoruid.UID) error { - ret := _m.Called(ctx, lpaUID, actorUID) - - if len(ret) == 0 { - panic("no return value specified for SendAttorneyOptOut") - } - - var r0 error - if rf, ok := ret.Get(0).(func(context.Context, string, actoruid.UID) error); ok { - r0 = rf(ctx, lpaUID, actorUID) - } else { - r0 = ret.Error(0) - } - - return r0 -} - -// mockLpaStoreClient_SendAttorneyOptOut_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'SendAttorneyOptOut' -type mockLpaStoreClient_SendAttorneyOptOut_Call struct { - *mock.Call -} - -// SendAttorneyOptOut is a helper method to define mock.On call -// - ctx context.Context -// - lpaUID string -// - actorUID actoruid.UID -func (_e *mockLpaStoreClient_Expecter) SendAttorneyOptOut(ctx interface{}, lpaUID interface{}, actorUID interface{}) *mockLpaStoreClient_SendAttorneyOptOut_Call { - return &mockLpaStoreClient_SendAttorneyOptOut_Call{Call: _e.mock.On("SendAttorneyOptOut", ctx, lpaUID, actorUID)} -} - -func (_c *mockLpaStoreClient_SendAttorneyOptOut_Call) Run(run func(ctx context.Context, lpaUID string, actorUID actoruid.UID)) *mockLpaStoreClient_SendAttorneyOptOut_Call { - _c.Call.Run(func(args mock.Arguments) { - run(args[0].(context.Context), args[1].(string), args[2].(actoruid.UID)) - }) - return _c -} - -func (_c *mockLpaStoreClient_SendAttorneyOptOut_Call) Return(_a0 error) *mockLpaStoreClient_SendAttorneyOptOut_Call { - _c.Call.Return(_a0) - return _c -} - -func (_c *mockLpaStoreClient_SendAttorneyOptOut_Call) RunAndReturn(run func(context.Context, string, actoruid.UID) error) *mockLpaStoreClient_SendAttorneyOptOut_Call { +func (_c *mockLpaStoreClient_SendAttorney_Call) RunAndReturn(run func(context.Context, *lpastore.Lpa, *attorneydata.Provided) error) *mockLpaStoreClient_SendAttorney_Call { _c.Call.Return(run) return _c } diff --git a/internal/page/attorney/mock_ShareCodeStore_test.go b/internal/page/attorney/mock_ShareCodeStore_test.go index 0b8797f397..f5472801e2 100644 --- a/internal/page/attorney/mock_ShareCodeStore_test.go +++ b/internal/page/attorney/mock_ShareCodeStore_test.go @@ -5,9 +5,10 @@ package attorney import ( context "context" - actor "github.com/ministryofjustice/opg-modernising-lpa/internal/actor" - + sharecode "github.com/ministryofjustice/opg-modernising-lpa/internal/sharecode" mock "github.com/stretchr/testify/mock" + + temporary "github.com/ministryofjustice/opg-modernising-lpa/internal/temporary" ) // mockShareCodeStore is an autogenerated mock type for the ShareCodeStore type @@ -24,7 +25,7 @@ func (_m *mockShareCodeStore) EXPECT() *mockShareCodeStore_Expecter { } // Delete provides a mock function with given fields: ctx, shareCode -func (_m *mockShareCodeStore) Delete(ctx context.Context, shareCode actor.ShareCodeData) error { +func (_m *mockShareCodeStore) Delete(ctx context.Context, shareCode sharecode.ShareCodeData) error { ret := _m.Called(ctx, shareCode) if len(ret) == 0 { @@ -32,7 +33,7 @@ func (_m *mockShareCodeStore) Delete(ctx context.Context, shareCode actor.ShareC } var r0 error - if rf, ok := ret.Get(0).(func(context.Context, actor.ShareCodeData) error); ok { + if rf, ok := ret.Get(0).(func(context.Context, sharecode.ShareCodeData) error); ok { r0 = rf(ctx, shareCode) } else { r0 = ret.Error(0) @@ -48,14 +49,14 @@ type mockShareCodeStore_Delete_Call struct { // Delete is a helper method to define mock.On call // - ctx context.Context -// - shareCode actor.ShareCodeData +// - shareCode sharecode.ShareCodeData func (_e *mockShareCodeStore_Expecter) Delete(ctx interface{}, shareCode interface{}) *mockShareCodeStore_Delete_Call { return &mockShareCodeStore_Delete_Call{Call: _e.mock.On("Delete", ctx, shareCode)} } -func (_c *mockShareCodeStore_Delete_Call) Run(run func(ctx context.Context, shareCode actor.ShareCodeData)) *mockShareCodeStore_Delete_Call { +func (_c *mockShareCodeStore_Delete_Call) Run(run func(ctx context.Context, shareCode sharecode.ShareCodeData)) *mockShareCodeStore_Delete_Call { _c.Call.Run(func(args mock.Arguments) { - run(args[0].(context.Context), args[1].(actor.ShareCodeData)) + run(args[0].(context.Context), args[1].(sharecode.ShareCodeData)) }) return _c } @@ -65,31 +66,31 @@ func (_c *mockShareCodeStore_Delete_Call) Return(_a0 error) *mockShareCodeStore_ return _c } -func (_c *mockShareCodeStore_Delete_Call) RunAndReturn(run func(context.Context, actor.ShareCodeData) error) *mockShareCodeStore_Delete_Call { +func (_c *mockShareCodeStore_Delete_Call) RunAndReturn(run func(context.Context, sharecode.ShareCodeData) error) *mockShareCodeStore_Delete_Call { _c.Call.Return(run) return _c } // Get provides a mock function with given fields: ctx, actorType, shareCode -func (_m *mockShareCodeStore) Get(ctx context.Context, actorType actor.Type, shareCode string) (actor.ShareCodeData, error) { +func (_m *mockShareCodeStore) Get(ctx context.Context, actorType temporary.ActorType, shareCode string) (sharecode.ShareCodeData, error) { ret := _m.Called(ctx, actorType, shareCode) if len(ret) == 0 { panic("no return value specified for Get") } - var r0 actor.ShareCodeData + var r0 sharecode.ShareCodeData var r1 error - if rf, ok := ret.Get(0).(func(context.Context, actor.Type, string) (actor.ShareCodeData, error)); ok { + if rf, ok := ret.Get(0).(func(context.Context, temporary.ActorType, string) (sharecode.ShareCodeData, error)); ok { return rf(ctx, actorType, shareCode) } - if rf, ok := ret.Get(0).(func(context.Context, actor.Type, string) actor.ShareCodeData); ok { + if rf, ok := ret.Get(0).(func(context.Context, temporary.ActorType, string) sharecode.ShareCodeData); ok { r0 = rf(ctx, actorType, shareCode) } else { - r0 = ret.Get(0).(actor.ShareCodeData) + r0 = ret.Get(0).(sharecode.ShareCodeData) } - if rf, ok := ret.Get(1).(func(context.Context, actor.Type, string) error); ok { + if rf, ok := ret.Get(1).(func(context.Context, temporary.ActorType, string) error); ok { r1 = rf(ctx, actorType, shareCode) } else { r1 = ret.Error(1) @@ -105,31 +106,31 @@ type mockShareCodeStore_Get_Call struct { // Get is a helper method to define mock.On call // - ctx context.Context -// - actorType actor.Type +// - actorType temporary.ActorType // - shareCode string func (_e *mockShareCodeStore_Expecter) Get(ctx interface{}, actorType interface{}, shareCode interface{}) *mockShareCodeStore_Get_Call { return &mockShareCodeStore_Get_Call{Call: _e.mock.On("Get", ctx, actorType, shareCode)} } -func (_c *mockShareCodeStore_Get_Call) Run(run func(ctx context.Context, actorType actor.Type, shareCode string)) *mockShareCodeStore_Get_Call { +func (_c *mockShareCodeStore_Get_Call) Run(run func(ctx context.Context, actorType temporary.ActorType, shareCode string)) *mockShareCodeStore_Get_Call { _c.Call.Run(func(args mock.Arguments) { - run(args[0].(context.Context), args[1].(actor.Type), args[2].(string)) + run(args[0].(context.Context), args[1].(temporary.ActorType), args[2].(string)) }) return _c } -func (_c *mockShareCodeStore_Get_Call) Return(_a0 actor.ShareCodeData, _a1 error) *mockShareCodeStore_Get_Call { +func (_c *mockShareCodeStore_Get_Call) Return(_a0 sharecode.ShareCodeData, _a1 error) *mockShareCodeStore_Get_Call { _c.Call.Return(_a0, _a1) return _c } -func (_c *mockShareCodeStore_Get_Call) RunAndReturn(run func(context.Context, actor.Type, string) (actor.ShareCodeData, error)) *mockShareCodeStore_Get_Call { +func (_c *mockShareCodeStore_Get_Call) RunAndReturn(run func(context.Context, temporary.ActorType, string) (sharecode.ShareCodeData, error)) *mockShareCodeStore_Get_Call { _c.Call.Return(run) return _c } // Put provides a mock function with given fields: ctx, actorType, shareCode, data -func (_m *mockShareCodeStore) Put(ctx context.Context, actorType actor.Type, shareCode string, data actor.ShareCodeData) error { +func (_m *mockShareCodeStore) Put(ctx context.Context, actorType temporary.ActorType, shareCode string, data sharecode.ShareCodeData) error { ret := _m.Called(ctx, actorType, shareCode, data) if len(ret) == 0 { @@ -137,7 +138,7 @@ func (_m *mockShareCodeStore) Put(ctx context.Context, actorType actor.Type, sha } var r0 error - if rf, ok := ret.Get(0).(func(context.Context, actor.Type, string, actor.ShareCodeData) error); ok { + if rf, ok := ret.Get(0).(func(context.Context, temporary.ActorType, string, sharecode.ShareCodeData) error); ok { r0 = rf(ctx, actorType, shareCode, data) } else { r0 = ret.Error(0) @@ -153,16 +154,16 @@ type mockShareCodeStore_Put_Call struct { // Put is a helper method to define mock.On call // - ctx context.Context -// - actorType actor.Type +// - actorType temporary.ActorType // - shareCode string -// - data actor.ShareCodeData +// - data sharecode.ShareCodeData func (_e *mockShareCodeStore_Expecter) Put(ctx interface{}, actorType interface{}, shareCode interface{}, data interface{}) *mockShareCodeStore_Put_Call { return &mockShareCodeStore_Put_Call{Call: _e.mock.On("Put", ctx, actorType, shareCode, data)} } -func (_c *mockShareCodeStore_Put_Call) Run(run func(ctx context.Context, actorType actor.Type, shareCode string, data actor.ShareCodeData)) *mockShareCodeStore_Put_Call { +func (_c *mockShareCodeStore_Put_Call) Run(run func(ctx context.Context, actorType temporary.ActorType, shareCode string, data sharecode.ShareCodeData)) *mockShareCodeStore_Put_Call { _c.Call.Run(func(args mock.Arguments) { - run(args[0].(context.Context), args[1].(actor.Type), args[2].(string), args[3].(actor.ShareCodeData)) + run(args[0].(context.Context), args[1].(temporary.ActorType), args[2].(string), args[3].(sharecode.ShareCodeData)) }) return _c } @@ -172,7 +173,7 @@ func (_c *mockShareCodeStore_Put_Call) Return(_a0 error) *mockShareCodeStore_Put return _c } -func (_c *mockShareCodeStore_Put_Call) RunAndReturn(run func(context.Context, actor.Type, string, actor.ShareCodeData) error) *mockShareCodeStore_Put_Call { +func (_c *mockShareCodeStore_Put_Call) RunAndReturn(run func(context.Context, temporary.ActorType, string, sharecode.ShareCodeData) error) *mockShareCodeStore_Put_Call { _c.Call.Return(run) return _c } diff --git a/internal/page/attorney/register.go b/internal/page/attorney/register.go index eca50e8c7f..b229a0ded1 100644 --- a/internal/page/attorney/register.go +++ b/internal/page/attorney/register.go @@ -8,6 +8,7 @@ import ( "github.com/ministryofjustice/opg-go-common/template" "github.com/ministryofjustice/opg-modernising-lpa/internal/actor" + "github.com/ministryofjustice/opg-modernising-lpa/internal/attorney/attorneypage" "github.com/ministryofjustice/opg-modernising-lpa/internal/lpastore" "github.com/ministryofjustice/opg-modernising-lpa/internal/notify" "github.com/ministryofjustice/opg-modernising-lpa/internal/onelogin" @@ -25,7 +26,7 @@ type LpaStoreResolvingService interface { Get(ctx context.Context) (*lpastore.Lpa, error) } -type Handler func(data page.AppData, w http.ResponseWriter, r *http.Request, details *actor.AttorneyProvidedDetails) error +type Handler = attorneypage.Handler type Template func(io.Writer, interface{}) error diff --git a/internal/page/certificateprovider/mock_CertificateProviderStore_test.go b/internal/page/certificateprovider/mock_CertificateProviderStore_test.go index ae0fab616c..04913c17f4 100644 --- a/internal/page/certificateprovider/mock_CertificateProviderStore_test.go +++ b/internal/page/certificateprovider/mock_CertificateProviderStore_test.go @@ -8,6 +8,8 @@ import ( actor "github.com/ministryofjustice/opg-modernising-lpa/internal/actor" mock "github.com/stretchr/testify/mock" + + sharecode "github.com/ministryofjustice/opg-modernising-lpa/internal/sharecode" ) // mockCertificateProviderStore is an autogenerated mock type for the CertificateProviderStore type @@ -24,7 +26,7 @@ func (_m *mockCertificateProviderStore) EXPECT() *mockCertificateProviderStore_E } // Create provides a mock function with given fields: ctx, shareCode, email -func (_m *mockCertificateProviderStore) Create(ctx context.Context, shareCode actor.ShareCodeData, email string) (*actor.CertificateProviderProvidedDetails, error) { +func (_m *mockCertificateProviderStore) Create(ctx context.Context, shareCode sharecode.ShareCodeData, email string) (*actor.CertificateProviderProvidedDetails, error) { ret := _m.Called(ctx, shareCode, email) if len(ret) == 0 { @@ -33,10 +35,10 @@ func (_m *mockCertificateProviderStore) Create(ctx context.Context, shareCode ac var r0 *actor.CertificateProviderProvidedDetails var r1 error - if rf, ok := ret.Get(0).(func(context.Context, actor.ShareCodeData, string) (*actor.CertificateProviderProvidedDetails, error)); ok { + if rf, ok := ret.Get(0).(func(context.Context, sharecode.ShareCodeData, string) (*actor.CertificateProviderProvidedDetails, error)); ok { return rf(ctx, shareCode, email) } - if rf, ok := ret.Get(0).(func(context.Context, actor.ShareCodeData, string) *actor.CertificateProviderProvidedDetails); ok { + if rf, ok := ret.Get(0).(func(context.Context, sharecode.ShareCodeData, string) *actor.CertificateProviderProvidedDetails); ok { r0 = rf(ctx, shareCode, email) } else { if ret.Get(0) != nil { @@ -44,7 +46,7 @@ func (_m *mockCertificateProviderStore) Create(ctx context.Context, shareCode ac } } - if rf, ok := ret.Get(1).(func(context.Context, actor.ShareCodeData, string) error); ok { + if rf, ok := ret.Get(1).(func(context.Context, sharecode.ShareCodeData, string) error); ok { r1 = rf(ctx, shareCode, email) } else { r1 = ret.Error(1) @@ -60,15 +62,15 @@ type mockCertificateProviderStore_Create_Call struct { // Create is a helper method to define mock.On call // - ctx context.Context -// - shareCode actor.ShareCodeData +// - shareCode sharecode.ShareCodeData // - email string func (_e *mockCertificateProviderStore_Expecter) Create(ctx interface{}, shareCode interface{}, email interface{}) *mockCertificateProviderStore_Create_Call { return &mockCertificateProviderStore_Create_Call{Call: _e.mock.On("Create", ctx, shareCode, email)} } -func (_c *mockCertificateProviderStore_Create_Call) Run(run func(ctx context.Context, shareCode actor.ShareCodeData, email string)) *mockCertificateProviderStore_Create_Call { +func (_c *mockCertificateProviderStore_Create_Call) Run(run func(ctx context.Context, shareCode sharecode.ShareCodeData, email string)) *mockCertificateProviderStore_Create_Call { _c.Call.Run(func(args mock.Arguments) { - run(args[0].(context.Context), args[1].(actor.ShareCodeData), args[2].(string)) + run(args[0].(context.Context), args[1].(sharecode.ShareCodeData), args[2].(string)) }) return _c } @@ -78,7 +80,7 @@ func (_c *mockCertificateProviderStore_Create_Call) Return(_a0 *actor.Certificat return _c } -func (_c *mockCertificateProviderStore_Create_Call) RunAndReturn(run func(context.Context, actor.ShareCodeData, string) (*actor.CertificateProviderProvidedDetails, error)) *mockCertificateProviderStore_Create_Call { +func (_c *mockCertificateProviderStore_Create_Call) RunAndReturn(run func(context.Context, sharecode.ShareCodeData, string) (*actor.CertificateProviderProvidedDetails, error)) *mockCertificateProviderStore_Create_Call { _c.Call.Return(run) return _c } diff --git a/internal/page/certificateprovider/mock_DashboardStore_test.go b/internal/page/certificateprovider/mock_DashboardStore_test.go index c09f05dc16..4a074d5406 100644 --- a/internal/page/certificateprovider/mock_DashboardStore_test.go +++ b/internal/page/certificateprovider/mock_DashboardStore_test.go @@ -5,11 +5,10 @@ package certificateprovider import ( context "context" - actor "github.com/ministryofjustice/opg-modernising-lpa/internal/actor" - + page "github.com/ministryofjustice/opg-modernising-lpa/internal/page" mock "github.com/stretchr/testify/mock" - page "github.com/ministryofjustice/opg-modernising-lpa/internal/page" + temporary "github.com/ministryofjustice/opg-modernising-lpa/internal/temporary" ) // mockDashboardStore is an autogenerated mock type for the DashboardStore type @@ -102,7 +101,7 @@ func (_c *mockDashboardStore_GetAll_Call) RunAndReturn(run func(context.Context) } // SubExistsForActorType provides a mock function with given fields: ctx, sub, actorType -func (_m *mockDashboardStore) SubExistsForActorType(ctx context.Context, sub string, actorType actor.Type) (bool, error) { +func (_m *mockDashboardStore) SubExistsForActorType(ctx context.Context, sub string, actorType temporary.ActorType) (bool, error) { ret := _m.Called(ctx, sub, actorType) if len(ret) == 0 { @@ -111,16 +110,16 @@ func (_m *mockDashboardStore) SubExistsForActorType(ctx context.Context, sub str var r0 bool var r1 error - if rf, ok := ret.Get(0).(func(context.Context, string, actor.Type) (bool, error)); ok { + if rf, ok := ret.Get(0).(func(context.Context, string, temporary.ActorType) (bool, error)); ok { return rf(ctx, sub, actorType) } - if rf, ok := ret.Get(0).(func(context.Context, string, actor.Type) bool); ok { + if rf, ok := ret.Get(0).(func(context.Context, string, temporary.ActorType) bool); ok { r0 = rf(ctx, sub, actorType) } else { r0 = ret.Get(0).(bool) } - if rf, ok := ret.Get(1).(func(context.Context, string, actor.Type) error); ok { + if rf, ok := ret.Get(1).(func(context.Context, string, temporary.ActorType) error); ok { r1 = rf(ctx, sub, actorType) } else { r1 = ret.Error(1) @@ -137,14 +136,14 @@ type mockDashboardStore_SubExistsForActorType_Call struct { // SubExistsForActorType is a helper method to define mock.On call // - ctx context.Context // - sub string -// - actorType actor.Type +// - actorType temporary.ActorType func (_e *mockDashboardStore_Expecter) SubExistsForActorType(ctx interface{}, sub interface{}, actorType interface{}) *mockDashboardStore_SubExistsForActorType_Call { return &mockDashboardStore_SubExistsForActorType_Call{Call: _e.mock.On("SubExistsForActorType", ctx, sub, actorType)} } -func (_c *mockDashboardStore_SubExistsForActorType_Call) Run(run func(ctx context.Context, sub string, actorType actor.Type)) *mockDashboardStore_SubExistsForActorType_Call { +func (_c *mockDashboardStore_SubExistsForActorType_Call) Run(run func(ctx context.Context, sub string, actorType temporary.ActorType)) *mockDashboardStore_SubExistsForActorType_Call { _c.Call.Run(func(args mock.Arguments) { - run(args[0].(context.Context), args[1].(string), args[2].(actor.Type)) + run(args[0].(context.Context), args[1].(string), args[2].(temporary.ActorType)) }) return _c } @@ -154,7 +153,7 @@ func (_c *mockDashboardStore_SubExistsForActorType_Call) Return(_a0 bool, _a1 er return _c } -func (_c *mockDashboardStore_SubExistsForActorType_Call) RunAndReturn(run func(context.Context, string, actor.Type) (bool, error)) *mockDashboardStore_SubExistsForActorType_Call { +func (_c *mockDashboardStore_SubExistsForActorType_Call) RunAndReturn(run func(context.Context, string, temporary.ActorType) (bool, error)) *mockDashboardStore_SubExistsForActorType_Call { _c.Call.Return(run) return _c } diff --git a/internal/page/certificateprovider/mock_Handler_test.go b/internal/page/certificateprovider/mock_Handler_test.go new file mode 100644 index 0000000000..688312da1e --- /dev/null +++ b/internal/page/certificateprovider/mock_Handler_test.go @@ -0,0 +1,89 @@ +// Code generated by mockery v2.42.2. DO NOT EDIT. + +package certificateprovider + +import ( + http "net/http" + + actor "github.com/ministryofjustice/opg-modernising-lpa/internal/actor" + + mock "github.com/stretchr/testify/mock" + + page "github.com/ministryofjustice/opg-modernising-lpa/internal/page" +) + +// mockHandler is an autogenerated mock type for the Handler type +type mockHandler struct { + mock.Mock +} + +type mockHandler_Expecter struct { + mock *mock.Mock +} + +func (_m *mockHandler) EXPECT() *mockHandler_Expecter { + return &mockHandler_Expecter{mock: &_m.Mock} +} + +// Execute provides a mock function with given fields: data, w, r, details +func (_m *mockHandler) Execute(data page.AppData, w http.ResponseWriter, r *http.Request, details *actor.CertificateProviderProvidedDetails) error { + ret := _m.Called(data, w, r, details) + + if len(ret) == 0 { + panic("no return value specified for Execute") + } + + var r0 error + if rf, ok := ret.Get(0).(func(page.AppData, http.ResponseWriter, *http.Request, *actor.CertificateProviderProvidedDetails) error); ok { + r0 = rf(data, w, r, details) + } else { + r0 = ret.Error(0) + } + + return r0 +} + +// mockHandler_Execute_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'Execute' +type mockHandler_Execute_Call struct { + *mock.Call +} + +// Execute is a helper method to define mock.On call +// - data page.AppData +// - w http.ResponseWriter +// - r *http.Request +// - details *actor.CertificateProviderProvidedDetails +func (_e *mockHandler_Expecter) Execute(data interface{}, w interface{}, r interface{}, details interface{}) *mockHandler_Execute_Call { + return &mockHandler_Execute_Call{Call: _e.mock.On("Execute", data, w, r, details)} +} + +func (_c *mockHandler_Execute_Call) Run(run func(data page.AppData, w http.ResponseWriter, r *http.Request, details *actor.CertificateProviderProvidedDetails)) *mockHandler_Execute_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(page.AppData), args[1].(http.ResponseWriter), args[2].(*http.Request), args[3].(*actor.CertificateProviderProvidedDetails)) + }) + return _c +} + +func (_c *mockHandler_Execute_Call) Return(_a0 error) *mockHandler_Execute_Call { + _c.Call.Return(_a0) + return _c +} + +func (_c *mockHandler_Execute_Call) RunAndReturn(run func(page.AppData, http.ResponseWriter, *http.Request, *actor.CertificateProviderProvidedDetails) error) *mockHandler_Execute_Call { + _c.Call.Return(run) + return _c +} + +// newMockHandler creates a new instance of mockHandler. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations. +// The first argument is typically a *testing.T value. +func newMockHandler(t interface { + mock.TestingT + Cleanup(func()) +}) *mockHandler { + mock := &mockHandler{} + mock.Mock.Test(t) + + t.Cleanup(func() { mock.AssertExpectations(t) }) + + return mock +} diff --git a/internal/page/certificateprovider/mock_ShareCodeStore_test.go b/internal/page/certificateprovider/mock_ShareCodeStore_test.go index 59a489800e..f337cfe00d 100644 --- a/internal/page/certificateprovider/mock_ShareCodeStore_test.go +++ b/internal/page/certificateprovider/mock_ShareCodeStore_test.go @@ -5,9 +5,10 @@ package certificateprovider import ( context "context" - actor "github.com/ministryofjustice/opg-modernising-lpa/internal/actor" - + sharecode "github.com/ministryofjustice/opg-modernising-lpa/internal/sharecode" mock "github.com/stretchr/testify/mock" + + temporary "github.com/ministryofjustice/opg-modernising-lpa/internal/temporary" ) // mockShareCodeStore is an autogenerated mock type for the ShareCodeStore type @@ -24,7 +25,7 @@ func (_m *mockShareCodeStore) EXPECT() *mockShareCodeStore_Expecter { } // Delete provides a mock function with given fields: ctx, shareCode -func (_m *mockShareCodeStore) Delete(ctx context.Context, shareCode actor.ShareCodeData) error { +func (_m *mockShareCodeStore) Delete(ctx context.Context, shareCode sharecode.ShareCodeData) error { ret := _m.Called(ctx, shareCode) if len(ret) == 0 { @@ -32,7 +33,7 @@ func (_m *mockShareCodeStore) Delete(ctx context.Context, shareCode actor.ShareC } var r0 error - if rf, ok := ret.Get(0).(func(context.Context, actor.ShareCodeData) error); ok { + if rf, ok := ret.Get(0).(func(context.Context, sharecode.ShareCodeData) error); ok { r0 = rf(ctx, shareCode) } else { r0 = ret.Error(0) @@ -48,14 +49,14 @@ type mockShareCodeStore_Delete_Call struct { // Delete is a helper method to define mock.On call // - ctx context.Context -// - shareCode actor.ShareCodeData +// - shareCode sharecode.ShareCodeData func (_e *mockShareCodeStore_Expecter) Delete(ctx interface{}, shareCode interface{}) *mockShareCodeStore_Delete_Call { return &mockShareCodeStore_Delete_Call{Call: _e.mock.On("Delete", ctx, shareCode)} } -func (_c *mockShareCodeStore_Delete_Call) Run(run func(ctx context.Context, shareCode actor.ShareCodeData)) *mockShareCodeStore_Delete_Call { +func (_c *mockShareCodeStore_Delete_Call) Run(run func(ctx context.Context, shareCode sharecode.ShareCodeData)) *mockShareCodeStore_Delete_Call { _c.Call.Run(func(args mock.Arguments) { - run(args[0].(context.Context), args[1].(actor.ShareCodeData)) + run(args[0].(context.Context), args[1].(sharecode.ShareCodeData)) }) return _c } @@ -65,31 +66,31 @@ func (_c *mockShareCodeStore_Delete_Call) Return(_a0 error) *mockShareCodeStore_ return _c } -func (_c *mockShareCodeStore_Delete_Call) RunAndReturn(run func(context.Context, actor.ShareCodeData) error) *mockShareCodeStore_Delete_Call { +func (_c *mockShareCodeStore_Delete_Call) RunAndReturn(run func(context.Context, sharecode.ShareCodeData) error) *mockShareCodeStore_Delete_Call { _c.Call.Return(run) return _c } // Get provides a mock function with given fields: ctx, actorType, shareCode -func (_m *mockShareCodeStore) Get(ctx context.Context, actorType actor.Type, shareCode string) (actor.ShareCodeData, error) { +func (_m *mockShareCodeStore) Get(ctx context.Context, actorType temporary.ActorType, shareCode string) (sharecode.ShareCodeData, error) { ret := _m.Called(ctx, actorType, shareCode) if len(ret) == 0 { panic("no return value specified for Get") } - var r0 actor.ShareCodeData + var r0 sharecode.ShareCodeData var r1 error - if rf, ok := ret.Get(0).(func(context.Context, actor.Type, string) (actor.ShareCodeData, error)); ok { + if rf, ok := ret.Get(0).(func(context.Context, temporary.ActorType, string) (sharecode.ShareCodeData, error)); ok { return rf(ctx, actorType, shareCode) } - if rf, ok := ret.Get(0).(func(context.Context, actor.Type, string) actor.ShareCodeData); ok { + if rf, ok := ret.Get(0).(func(context.Context, temporary.ActorType, string) sharecode.ShareCodeData); ok { r0 = rf(ctx, actorType, shareCode) } else { - r0 = ret.Get(0).(actor.ShareCodeData) + r0 = ret.Get(0).(sharecode.ShareCodeData) } - if rf, ok := ret.Get(1).(func(context.Context, actor.Type, string) error); ok { + if rf, ok := ret.Get(1).(func(context.Context, temporary.ActorType, string) error); ok { r1 = rf(ctx, actorType, shareCode) } else { r1 = ret.Error(1) @@ -105,31 +106,31 @@ type mockShareCodeStore_Get_Call struct { // Get is a helper method to define mock.On call // - ctx context.Context -// - actorType actor.Type +// - actorType temporary.ActorType // - shareCode string func (_e *mockShareCodeStore_Expecter) Get(ctx interface{}, actorType interface{}, shareCode interface{}) *mockShareCodeStore_Get_Call { return &mockShareCodeStore_Get_Call{Call: _e.mock.On("Get", ctx, actorType, shareCode)} } -func (_c *mockShareCodeStore_Get_Call) Run(run func(ctx context.Context, actorType actor.Type, shareCode string)) *mockShareCodeStore_Get_Call { +func (_c *mockShareCodeStore_Get_Call) Run(run func(ctx context.Context, actorType temporary.ActorType, shareCode string)) *mockShareCodeStore_Get_Call { _c.Call.Run(func(args mock.Arguments) { - run(args[0].(context.Context), args[1].(actor.Type), args[2].(string)) + run(args[0].(context.Context), args[1].(temporary.ActorType), args[2].(string)) }) return _c } -func (_c *mockShareCodeStore_Get_Call) Return(_a0 actor.ShareCodeData, _a1 error) *mockShareCodeStore_Get_Call { +func (_c *mockShareCodeStore_Get_Call) Return(_a0 sharecode.ShareCodeData, _a1 error) *mockShareCodeStore_Get_Call { _c.Call.Return(_a0, _a1) return _c } -func (_c *mockShareCodeStore_Get_Call) RunAndReturn(run func(context.Context, actor.Type, string) (actor.ShareCodeData, error)) *mockShareCodeStore_Get_Call { +func (_c *mockShareCodeStore_Get_Call) RunAndReturn(run func(context.Context, temporary.ActorType, string) (sharecode.ShareCodeData, error)) *mockShareCodeStore_Get_Call { _c.Call.Return(run) return _c } // Put provides a mock function with given fields: ctx, actorType, shareCode, shareCodeData -func (_m *mockShareCodeStore) Put(ctx context.Context, actorType actor.Type, shareCode string, shareCodeData actor.ShareCodeData) error { +func (_m *mockShareCodeStore) Put(ctx context.Context, actorType temporary.ActorType, shareCode string, shareCodeData sharecode.ShareCodeData) error { ret := _m.Called(ctx, actorType, shareCode, shareCodeData) if len(ret) == 0 { @@ -137,7 +138,7 @@ func (_m *mockShareCodeStore) Put(ctx context.Context, actorType actor.Type, sha } var r0 error - if rf, ok := ret.Get(0).(func(context.Context, actor.Type, string, actor.ShareCodeData) error); ok { + if rf, ok := ret.Get(0).(func(context.Context, temporary.ActorType, string, sharecode.ShareCodeData) error); ok { r0 = rf(ctx, actorType, shareCode, shareCodeData) } else { r0 = ret.Error(0) @@ -153,16 +154,16 @@ type mockShareCodeStore_Put_Call struct { // Put is a helper method to define mock.On call // - ctx context.Context -// - actorType actor.Type +// - actorType temporary.ActorType // - shareCode string -// - shareCodeData actor.ShareCodeData +// - shareCodeData sharecode.ShareCodeData func (_e *mockShareCodeStore_Expecter) Put(ctx interface{}, actorType interface{}, shareCode interface{}, shareCodeData interface{}) *mockShareCodeStore_Put_Call { return &mockShareCodeStore_Put_Call{Call: _e.mock.On("Put", ctx, actorType, shareCode, shareCodeData)} } -func (_c *mockShareCodeStore_Put_Call) Run(run func(ctx context.Context, actorType actor.Type, shareCode string, shareCodeData actor.ShareCodeData)) *mockShareCodeStore_Put_Call { +func (_c *mockShareCodeStore_Put_Call) Run(run func(ctx context.Context, actorType temporary.ActorType, shareCode string, shareCodeData sharecode.ShareCodeData)) *mockShareCodeStore_Put_Call { _c.Call.Run(func(args mock.Arguments) { - run(args[0].(context.Context), args[1].(actor.Type), args[2].(string), args[3].(actor.ShareCodeData)) + run(args[0].(context.Context), args[1].(temporary.ActorType), args[2].(string), args[3].(sharecode.ShareCodeData)) }) return _c } @@ -172,7 +173,7 @@ func (_c *mockShareCodeStore_Put_Call) Return(_a0 error) *mockShareCodeStore_Put return _c } -func (_c *mockShareCodeStore_Put_Call) RunAndReturn(run func(context.Context, actor.Type, string, actor.ShareCodeData) error) *mockShareCodeStore_Put_Call { +func (_c *mockShareCodeStore_Put_Call) RunAndReturn(run func(context.Context, temporary.ActorType, string, sharecode.ShareCodeData) error) *mockShareCodeStore_Put_Call { _c.Call.Return(run) return _c } diff --git a/internal/page/data.go b/internal/page/data.go index e76062c83e..61706e3301 100644 --- a/internal/page/data.go +++ b/internal/page/data.go @@ -12,40 +12,16 @@ package page import ( - "context" - "github.com/ministryofjustice/opg-modernising-lpa/internal/actor" + "github.com/ministryofjustice/opg-modernising-lpa/internal/appcontext" "github.com/ministryofjustice/opg-modernising-lpa/internal/form" ) -type SessionData struct { - SessionID string - LpaID string - - // if a supporter - Email string - OrganisationID string -} - -type SessionMissingError struct{} - -func (s SessionMissingError) Error() string { - return "Session data not set" -} - -func SessionDataFromContext(ctx context.Context) (*SessionData, error) { - data, ok := ctx.Value((*SessionData)(nil)).(*SessionData) - - if !ok { - return nil, SessionMissingError{} - } - - return data, nil -} +type SessionData = appcontext.SessionData +type SessionMissingError = appcontext.SessionMissingError -func ContextWithSessionData(ctx context.Context, data *SessionData) context.Context { - return context.WithValue(ctx, (*SessionData)(nil), data) -} +var SessionDataFromContext = appcontext.SessionDataFromContext +var ContextWithSessionData = appcontext.ContextWithSessionData func ChooseAttorneysState(attorneys actor.Attorneys, decisions actor.AttorneyDecisions) actor.TaskState { if attorneys.Len() == 0 { diff --git a/internal/page/donor/mock_DashboardStore_test.go b/internal/page/donor/mock_DashboardStore_test.go index d3008ff21c..f029e29ff2 100644 --- a/internal/page/donor/mock_DashboardStore_test.go +++ b/internal/page/donor/mock_DashboardStore_test.go @@ -5,11 +5,10 @@ package donor import ( context "context" - actor "github.com/ministryofjustice/opg-modernising-lpa/internal/actor" - + page "github.com/ministryofjustice/opg-modernising-lpa/internal/page" mock "github.com/stretchr/testify/mock" - page "github.com/ministryofjustice/opg-modernising-lpa/internal/page" + temporary "github.com/ministryofjustice/opg-modernising-lpa/internal/temporary" ) // mockDashboardStore is an autogenerated mock type for the DashboardStore type @@ -102,7 +101,7 @@ func (_c *mockDashboardStore_GetAll_Call) RunAndReturn(run func(context.Context) } // SubExistsForActorType provides a mock function with given fields: ctx, sub, actorType -func (_m *mockDashboardStore) SubExistsForActorType(ctx context.Context, sub string, actorType actor.Type) (bool, error) { +func (_m *mockDashboardStore) SubExistsForActorType(ctx context.Context, sub string, actorType temporary.ActorType) (bool, error) { ret := _m.Called(ctx, sub, actorType) if len(ret) == 0 { @@ -111,16 +110,16 @@ func (_m *mockDashboardStore) SubExistsForActorType(ctx context.Context, sub str var r0 bool var r1 error - if rf, ok := ret.Get(0).(func(context.Context, string, actor.Type) (bool, error)); ok { + if rf, ok := ret.Get(0).(func(context.Context, string, temporary.ActorType) (bool, error)); ok { return rf(ctx, sub, actorType) } - if rf, ok := ret.Get(0).(func(context.Context, string, actor.Type) bool); ok { + if rf, ok := ret.Get(0).(func(context.Context, string, temporary.ActorType) bool); ok { r0 = rf(ctx, sub, actorType) } else { r0 = ret.Get(0).(bool) } - if rf, ok := ret.Get(1).(func(context.Context, string, actor.Type) error); ok { + if rf, ok := ret.Get(1).(func(context.Context, string, temporary.ActorType) error); ok { r1 = rf(ctx, sub, actorType) } else { r1 = ret.Error(1) @@ -137,14 +136,14 @@ type mockDashboardStore_SubExistsForActorType_Call struct { // SubExistsForActorType is a helper method to define mock.On call // - ctx context.Context // - sub string -// - actorType actor.Type +// - actorType temporary.ActorType func (_e *mockDashboardStore_Expecter) SubExistsForActorType(ctx interface{}, sub interface{}, actorType interface{}) *mockDashboardStore_SubExistsForActorType_Call { return &mockDashboardStore_SubExistsForActorType_Call{Call: _e.mock.On("SubExistsForActorType", ctx, sub, actorType)} } -func (_c *mockDashboardStore_SubExistsForActorType_Call) Run(run func(ctx context.Context, sub string, actorType actor.Type)) *mockDashboardStore_SubExistsForActorType_Call { +func (_c *mockDashboardStore_SubExistsForActorType_Call) Run(run func(ctx context.Context, sub string, actorType temporary.ActorType)) *mockDashboardStore_SubExistsForActorType_Call { _c.Call.Run(func(args mock.Arguments) { - run(args[0].(context.Context), args[1].(string), args[2].(actor.Type)) + run(args[0].(context.Context), args[1].(string), args[2].(temporary.ActorType)) }) return _c } @@ -154,7 +153,7 @@ func (_c *mockDashboardStore_SubExistsForActorType_Call) Return(_a0 bool, _a1 er return _c } -func (_c *mockDashboardStore_SubExistsForActorType_Call) RunAndReturn(run func(context.Context, string, actor.Type) (bool, error)) *mockDashboardStore_SubExistsForActorType_Call { +func (_c *mockDashboardStore_SubExistsForActorType_Call) RunAndReturn(run func(context.Context, string, temporary.ActorType) (bool, error)) *mockDashboardStore_SubExistsForActorType_Call { _c.Call.Return(run) return _c } diff --git a/internal/page/donor/mock_DonorStore_test.go b/internal/page/donor/mock_DonorStore_test.go index 7f01a935a9..d68d2d6e47 100644 --- a/internal/page/donor/mock_DonorStore_test.go +++ b/internal/page/donor/mock_DonorStore_test.go @@ -8,6 +8,8 @@ import ( actor "github.com/ministryofjustice/opg-modernising-lpa/internal/actor" mock "github.com/stretchr/testify/mock" + + sharecode "github.com/ministryofjustice/opg-modernising-lpa/internal/sharecode" ) // mockDonorStore is an autogenerated mock type for the DonorStore type @@ -186,7 +188,7 @@ func (_c *mockDonorStore_Latest_Call) RunAndReturn(run func(context.Context) (*a } // Link provides a mock function with given fields: ctx, data, donorEmail -func (_m *mockDonorStore) Link(ctx context.Context, data actor.ShareCodeData, donorEmail string) error { +func (_m *mockDonorStore) Link(ctx context.Context, data sharecode.ShareCodeData, donorEmail string) error { ret := _m.Called(ctx, data, donorEmail) if len(ret) == 0 { @@ -194,7 +196,7 @@ func (_m *mockDonorStore) Link(ctx context.Context, data actor.ShareCodeData, do } var r0 error - if rf, ok := ret.Get(0).(func(context.Context, actor.ShareCodeData, string) error); ok { + if rf, ok := ret.Get(0).(func(context.Context, sharecode.ShareCodeData, string) error); ok { r0 = rf(ctx, data, donorEmail) } else { r0 = ret.Error(0) @@ -210,15 +212,15 @@ type mockDonorStore_Link_Call struct { // Link is a helper method to define mock.On call // - ctx context.Context -// - data actor.ShareCodeData +// - data sharecode.ShareCodeData // - donorEmail string func (_e *mockDonorStore_Expecter) Link(ctx interface{}, data interface{}, donorEmail interface{}) *mockDonorStore_Link_Call { return &mockDonorStore_Link_Call{Call: _e.mock.On("Link", ctx, data, donorEmail)} } -func (_c *mockDonorStore_Link_Call) Run(run func(ctx context.Context, data actor.ShareCodeData, donorEmail string)) *mockDonorStore_Link_Call { +func (_c *mockDonorStore_Link_Call) Run(run func(ctx context.Context, data sharecode.ShareCodeData, donorEmail string)) *mockDonorStore_Link_Call { _c.Call.Run(func(args mock.Arguments) { - run(args[0].(context.Context), args[1].(actor.ShareCodeData), args[2].(string)) + run(args[0].(context.Context), args[1].(sharecode.ShareCodeData), args[2].(string)) }) return _c } @@ -228,7 +230,7 @@ func (_c *mockDonorStore_Link_Call) Return(_a0 error) *mockDonorStore_Link_Call return _c } -func (_c *mockDonorStore_Link_Call) RunAndReturn(run func(context.Context, actor.ShareCodeData, string) error) *mockDonorStore_Link_Call { +func (_c *mockDonorStore_Link_Call) RunAndReturn(run func(context.Context, sharecode.ShareCodeData, string) error) *mockDonorStore_Link_Call { _c.Call.Return(run) return _c } diff --git a/internal/page/donor/mock_ShareCodeStore_test.go b/internal/page/donor/mock_ShareCodeStore_test.go index faa1a3d514..ed1c35b5ac 100644 --- a/internal/page/donor/mock_ShareCodeStore_test.go +++ b/internal/page/donor/mock_ShareCodeStore_test.go @@ -5,9 +5,10 @@ package donor import ( context "context" - actor "github.com/ministryofjustice/opg-modernising-lpa/internal/actor" - + sharecode "github.com/ministryofjustice/opg-modernising-lpa/internal/sharecode" mock "github.com/stretchr/testify/mock" + + temporary "github.com/ministryofjustice/opg-modernising-lpa/internal/temporary" ) // mockShareCodeStore is an autogenerated mock type for the ShareCodeStore type @@ -24,25 +25,25 @@ func (_m *mockShareCodeStore) EXPECT() *mockShareCodeStore_Expecter { } // Get provides a mock function with given fields: ctx, actorType, code -func (_m *mockShareCodeStore) Get(ctx context.Context, actorType actor.Type, code string) (actor.ShareCodeData, error) { +func (_m *mockShareCodeStore) Get(ctx context.Context, actorType temporary.ActorType, code string) (sharecode.ShareCodeData, error) { ret := _m.Called(ctx, actorType, code) if len(ret) == 0 { panic("no return value specified for Get") } - var r0 actor.ShareCodeData + var r0 sharecode.ShareCodeData var r1 error - if rf, ok := ret.Get(0).(func(context.Context, actor.Type, string) (actor.ShareCodeData, error)); ok { + if rf, ok := ret.Get(0).(func(context.Context, temporary.ActorType, string) (sharecode.ShareCodeData, error)); ok { return rf(ctx, actorType, code) } - if rf, ok := ret.Get(0).(func(context.Context, actor.Type, string) actor.ShareCodeData); ok { + if rf, ok := ret.Get(0).(func(context.Context, temporary.ActorType, string) sharecode.ShareCodeData); ok { r0 = rf(ctx, actorType, code) } else { - r0 = ret.Get(0).(actor.ShareCodeData) + r0 = ret.Get(0).(sharecode.ShareCodeData) } - if rf, ok := ret.Get(1).(func(context.Context, actor.Type, string) error); ok { + if rf, ok := ret.Get(1).(func(context.Context, temporary.ActorType, string) error); ok { r1 = rf(ctx, actorType, code) } else { r1 = ret.Error(1) @@ -58,25 +59,25 @@ type mockShareCodeStore_Get_Call struct { // Get is a helper method to define mock.On call // - ctx context.Context -// - actorType actor.Type +// - actorType temporary.ActorType // - code string func (_e *mockShareCodeStore_Expecter) Get(ctx interface{}, actorType interface{}, code interface{}) *mockShareCodeStore_Get_Call { return &mockShareCodeStore_Get_Call{Call: _e.mock.On("Get", ctx, actorType, code)} } -func (_c *mockShareCodeStore_Get_Call) Run(run func(ctx context.Context, actorType actor.Type, code string)) *mockShareCodeStore_Get_Call { +func (_c *mockShareCodeStore_Get_Call) Run(run func(ctx context.Context, actorType temporary.ActorType, code string)) *mockShareCodeStore_Get_Call { _c.Call.Run(func(args mock.Arguments) { - run(args[0].(context.Context), args[1].(actor.Type), args[2].(string)) + run(args[0].(context.Context), args[1].(temporary.ActorType), args[2].(string)) }) return _c } -func (_c *mockShareCodeStore_Get_Call) Return(_a0 actor.ShareCodeData, _a1 error) *mockShareCodeStore_Get_Call { +func (_c *mockShareCodeStore_Get_Call) Return(_a0 sharecode.ShareCodeData, _a1 error) *mockShareCodeStore_Get_Call { _c.Call.Return(_a0, _a1) return _c } -func (_c *mockShareCodeStore_Get_Call) RunAndReturn(run func(context.Context, actor.Type, string) (actor.ShareCodeData, error)) *mockShareCodeStore_Get_Call { +func (_c *mockShareCodeStore_Get_Call) RunAndReturn(run func(context.Context, temporary.ActorType, string) (sharecode.ShareCodeData, error)) *mockShareCodeStore_Get_Call { _c.Call.Return(run) return _c } diff --git a/internal/page/fixtures/donor.go b/internal/page/fixtures/donor.go index f471244f2c..8c677b1b2c 100644 --- a/internal/page/fixtures/donor.go +++ b/internal/page/fixtures/donor.go @@ -22,6 +22,7 @@ import ( "github.com/ministryofjustice/opg-modernising-lpa/internal/place" "github.com/ministryofjustice/opg-modernising-lpa/internal/random" "github.com/ministryofjustice/opg-modernising-lpa/internal/sesh" + "github.com/ministryofjustice/opg-modernising-lpa/internal/task" "github.com/ministryofjustice/opg-modernising-lpa/internal/uid" ) @@ -387,7 +388,7 @@ func updateLPAProgress( donorDetails.Tasks.PayForLpa = actor.PaymentTaskCompleted if data.PaymentTaskProgress != "" { - taskState, err := actor.ParsePaymentTask(data.PaymentTaskProgress) + taskState, err := task.ParsePaymentState(data.PaymentTaskProgress) if err != nil { return nil, nil, err } diff --git a/internal/page/mock_DashboardStore_test.go b/internal/page/mock_DashboardStore_test.go index 915c28ba4a..285e427607 100644 --- a/internal/page/mock_DashboardStore_test.go +++ b/internal/page/mock_DashboardStore_test.go @@ -5,8 +5,7 @@ package page import ( context "context" - actor "github.com/ministryofjustice/opg-modernising-lpa/internal/actor" - + temporary "github.com/ministryofjustice/opg-modernising-lpa/internal/temporary" mock "github.com/stretchr/testify/mock" ) @@ -100,7 +99,7 @@ func (_c *mockDashboardStore_GetAll_Call) RunAndReturn(run func(context.Context) } // SubExistsForActorType provides a mock function with given fields: ctx, sub, actorType -func (_m *mockDashboardStore) SubExistsForActorType(ctx context.Context, sub string, actorType actor.Type) (bool, error) { +func (_m *mockDashboardStore) SubExistsForActorType(ctx context.Context, sub string, actorType temporary.ActorType) (bool, error) { ret := _m.Called(ctx, sub, actorType) if len(ret) == 0 { @@ -109,16 +108,16 @@ func (_m *mockDashboardStore) SubExistsForActorType(ctx context.Context, sub str var r0 bool var r1 error - if rf, ok := ret.Get(0).(func(context.Context, string, actor.Type) (bool, error)); ok { + if rf, ok := ret.Get(0).(func(context.Context, string, temporary.ActorType) (bool, error)); ok { return rf(ctx, sub, actorType) } - if rf, ok := ret.Get(0).(func(context.Context, string, actor.Type) bool); ok { + if rf, ok := ret.Get(0).(func(context.Context, string, temporary.ActorType) bool); ok { r0 = rf(ctx, sub, actorType) } else { r0 = ret.Get(0).(bool) } - if rf, ok := ret.Get(1).(func(context.Context, string, actor.Type) error); ok { + if rf, ok := ret.Get(1).(func(context.Context, string, temporary.ActorType) error); ok { r1 = rf(ctx, sub, actorType) } else { r1 = ret.Error(1) @@ -135,14 +134,14 @@ type mockDashboardStore_SubExistsForActorType_Call struct { // SubExistsForActorType is a helper method to define mock.On call // - ctx context.Context // - sub string -// - actorType actor.Type +// - actorType temporary.ActorType func (_e *mockDashboardStore_Expecter) SubExistsForActorType(ctx interface{}, sub interface{}, actorType interface{}) *mockDashboardStore_SubExistsForActorType_Call { return &mockDashboardStore_SubExistsForActorType_Call{Call: _e.mock.On("SubExistsForActorType", ctx, sub, actorType)} } -func (_c *mockDashboardStore_SubExistsForActorType_Call) Run(run func(ctx context.Context, sub string, actorType actor.Type)) *mockDashboardStore_SubExistsForActorType_Call { +func (_c *mockDashboardStore_SubExistsForActorType_Call) Run(run func(ctx context.Context, sub string, actorType temporary.ActorType)) *mockDashboardStore_SubExistsForActorType_Call { _c.Call.Run(func(args mock.Arguments) { - run(args[0].(context.Context), args[1].(string), args[2].(actor.Type)) + run(args[0].(context.Context), args[1].(string), args[2].(temporary.ActorType)) }) return _c } @@ -152,7 +151,7 @@ func (_c *mockDashboardStore_SubExistsForActorType_Call) Return(_a0 bool, _a1 er return _c } -func (_c *mockDashboardStore_SubExistsForActorType_Call) RunAndReturn(run func(context.Context, string, actor.Type) (bool, error)) *mockDashboardStore_SubExistsForActorType_Call { +func (_c *mockDashboardStore_SubExistsForActorType_Call) RunAndReturn(run func(context.Context, string, temporary.ActorType) (bool, error)) *mockDashboardStore_SubExistsForActorType_Call { _c.Call.Return(run) return _c } diff --git a/internal/page/mock_ShareCodeStore_test.go b/internal/page/mock_ShareCodeStore_test.go index edc22fefd0..97c1b8110b 100644 --- a/internal/page/mock_ShareCodeStore_test.go +++ b/internal/page/mock_ShareCodeStore_test.go @@ -5,9 +5,10 @@ package page import ( context "context" - actor "github.com/ministryofjustice/opg-modernising-lpa/internal/actor" - + sharecode "github.com/ministryofjustice/opg-modernising-lpa/internal/sharecode" mock "github.com/stretchr/testify/mock" + + temporary "github.com/ministryofjustice/opg-modernising-lpa/internal/temporary" ) // mockShareCodeStore is an autogenerated mock type for the ShareCodeStore type @@ -24,25 +25,25 @@ func (_m *mockShareCodeStore) EXPECT() *mockShareCodeStore_Expecter { } // Get provides a mock function with given fields: ctx, actorType, shareCode -func (_m *mockShareCodeStore) Get(ctx context.Context, actorType actor.Type, shareCode string) (actor.ShareCodeData, error) { +func (_m *mockShareCodeStore) Get(ctx context.Context, actorType temporary.ActorType, shareCode string) (sharecode.ShareCodeData, error) { ret := _m.Called(ctx, actorType, shareCode) if len(ret) == 0 { panic("no return value specified for Get") } - var r0 actor.ShareCodeData + var r0 sharecode.ShareCodeData var r1 error - if rf, ok := ret.Get(0).(func(context.Context, actor.Type, string) (actor.ShareCodeData, error)); ok { + if rf, ok := ret.Get(0).(func(context.Context, temporary.ActorType, string) (sharecode.ShareCodeData, error)); ok { return rf(ctx, actorType, shareCode) } - if rf, ok := ret.Get(0).(func(context.Context, actor.Type, string) actor.ShareCodeData); ok { + if rf, ok := ret.Get(0).(func(context.Context, temporary.ActorType, string) sharecode.ShareCodeData); ok { r0 = rf(ctx, actorType, shareCode) } else { - r0 = ret.Get(0).(actor.ShareCodeData) + r0 = ret.Get(0).(sharecode.ShareCodeData) } - if rf, ok := ret.Get(1).(func(context.Context, actor.Type, string) error); ok { + if rf, ok := ret.Get(1).(func(context.Context, temporary.ActorType, string) error); ok { r1 = rf(ctx, actorType, shareCode) } else { r1 = ret.Error(1) @@ -58,31 +59,31 @@ type mockShareCodeStore_Get_Call struct { // Get is a helper method to define mock.On call // - ctx context.Context -// - actorType actor.Type +// - actorType temporary.ActorType // - shareCode string func (_e *mockShareCodeStore_Expecter) Get(ctx interface{}, actorType interface{}, shareCode interface{}) *mockShareCodeStore_Get_Call { return &mockShareCodeStore_Get_Call{Call: _e.mock.On("Get", ctx, actorType, shareCode)} } -func (_c *mockShareCodeStore_Get_Call) Run(run func(ctx context.Context, actorType actor.Type, shareCode string)) *mockShareCodeStore_Get_Call { +func (_c *mockShareCodeStore_Get_Call) Run(run func(ctx context.Context, actorType temporary.ActorType, shareCode string)) *mockShareCodeStore_Get_Call { _c.Call.Run(func(args mock.Arguments) { - run(args[0].(context.Context), args[1].(actor.Type), args[2].(string)) + run(args[0].(context.Context), args[1].(temporary.ActorType), args[2].(string)) }) return _c } -func (_c *mockShareCodeStore_Get_Call) Return(_a0 actor.ShareCodeData, _a1 error) *mockShareCodeStore_Get_Call { +func (_c *mockShareCodeStore_Get_Call) Return(_a0 sharecode.ShareCodeData, _a1 error) *mockShareCodeStore_Get_Call { _c.Call.Return(_a0, _a1) return _c } -func (_c *mockShareCodeStore_Get_Call) RunAndReturn(run func(context.Context, actor.Type, string) (actor.ShareCodeData, error)) *mockShareCodeStore_Get_Call { +func (_c *mockShareCodeStore_Get_Call) RunAndReturn(run func(context.Context, temporary.ActorType, string) (sharecode.ShareCodeData, error)) *mockShareCodeStore_Get_Call { _c.Call.Return(run) return _c } // Put provides a mock function with given fields: ctx, actorType, shareCode, data -func (_m *mockShareCodeStore) Put(ctx context.Context, actorType actor.Type, shareCode string, data actor.ShareCodeData) error { +func (_m *mockShareCodeStore) Put(ctx context.Context, actorType temporary.ActorType, shareCode string, data sharecode.ShareCodeData) error { ret := _m.Called(ctx, actorType, shareCode, data) if len(ret) == 0 { @@ -90,7 +91,7 @@ func (_m *mockShareCodeStore) Put(ctx context.Context, actorType actor.Type, sha } var r0 error - if rf, ok := ret.Get(0).(func(context.Context, actor.Type, string, actor.ShareCodeData) error); ok { + if rf, ok := ret.Get(0).(func(context.Context, temporary.ActorType, string, sharecode.ShareCodeData) error); ok { r0 = rf(ctx, actorType, shareCode, data) } else { r0 = ret.Error(0) @@ -106,16 +107,16 @@ type mockShareCodeStore_Put_Call struct { // Put is a helper method to define mock.On call // - ctx context.Context -// - actorType actor.Type +// - actorType temporary.ActorType // - shareCode string -// - data actor.ShareCodeData +// - data sharecode.ShareCodeData func (_e *mockShareCodeStore_Expecter) Put(ctx interface{}, actorType interface{}, shareCode interface{}, data interface{}) *mockShareCodeStore_Put_Call { return &mockShareCodeStore_Put_Call{Call: _e.mock.On("Put", ctx, actorType, shareCode, data)} } -func (_c *mockShareCodeStore_Put_Call) Run(run func(ctx context.Context, actorType actor.Type, shareCode string, data actor.ShareCodeData)) *mockShareCodeStore_Put_Call { +func (_c *mockShareCodeStore_Put_Call) Run(run func(ctx context.Context, actorType temporary.ActorType, shareCode string, data sharecode.ShareCodeData)) *mockShareCodeStore_Put_Call { _c.Call.Run(func(args mock.Arguments) { - run(args[0].(context.Context), args[1].(actor.Type), args[2].(string), args[3].(actor.ShareCodeData)) + run(args[0].(context.Context), args[1].(temporary.ActorType), args[2].(string), args[3].(sharecode.ShareCodeData)) }) return _c } @@ -125,7 +126,7 @@ func (_c *mockShareCodeStore_Put_Call) Return(_a0 error) *mockShareCodeStore_Put return _c } -func (_c *mockShareCodeStore_Put_Call) RunAndReturn(run func(context.Context, actor.Type, string, actor.ShareCodeData) error) *mockShareCodeStore_Put_Call { +func (_c *mockShareCodeStore_Put_Call) RunAndReturn(run func(context.Context, temporary.ActorType, string, sharecode.ShareCodeData) error) *mockShareCodeStore_Put_Call { _c.Call.Return(run) return _c } diff --git a/internal/page/supporter/mock_DonorStore_test.go b/internal/page/supporter/mock_DonorStore_test.go index c56222335e..53dffd3255 100644 --- a/internal/page/supporter/mock_DonorStore_test.go +++ b/internal/page/supporter/mock_DonorStore_test.go @@ -10,6 +10,8 @@ import ( dynamo "github.com/ministryofjustice/opg-modernising-lpa/internal/dynamo" mock "github.com/stretchr/testify/mock" + + sharecode "github.com/ministryofjustice/opg-modernising-lpa/internal/sharecode" ) // mockDonorStore is an autogenerated mock type for the DonorStore type @@ -26,7 +28,7 @@ func (_m *mockDonorStore) EXPECT() *mockDonorStore_Expecter { } // DeleteDonorAccess provides a mock function with given fields: ctx, shareCodeData -func (_m *mockDonorStore) DeleteDonorAccess(ctx context.Context, shareCodeData actor.ShareCodeData) error { +func (_m *mockDonorStore) DeleteDonorAccess(ctx context.Context, shareCodeData sharecode.ShareCodeData) error { ret := _m.Called(ctx, shareCodeData) if len(ret) == 0 { @@ -34,7 +36,7 @@ func (_m *mockDonorStore) DeleteDonorAccess(ctx context.Context, shareCodeData a } var r0 error - if rf, ok := ret.Get(0).(func(context.Context, actor.ShareCodeData) error); ok { + if rf, ok := ret.Get(0).(func(context.Context, sharecode.ShareCodeData) error); ok { r0 = rf(ctx, shareCodeData) } else { r0 = ret.Error(0) @@ -50,14 +52,14 @@ type mockDonorStore_DeleteDonorAccess_Call struct { // DeleteDonorAccess is a helper method to define mock.On call // - ctx context.Context -// - shareCodeData actor.ShareCodeData +// - shareCodeData sharecode.ShareCodeData func (_e *mockDonorStore_Expecter) DeleteDonorAccess(ctx interface{}, shareCodeData interface{}) *mockDonorStore_DeleteDonorAccess_Call { return &mockDonorStore_DeleteDonorAccess_Call{Call: _e.mock.On("DeleteDonorAccess", ctx, shareCodeData)} } -func (_c *mockDonorStore_DeleteDonorAccess_Call) Run(run func(ctx context.Context, shareCodeData actor.ShareCodeData)) *mockDonorStore_DeleteDonorAccess_Call { +func (_c *mockDonorStore_DeleteDonorAccess_Call) Run(run func(ctx context.Context, shareCodeData sharecode.ShareCodeData)) *mockDonorStore_DeleteDonorAccess_Call { _c.Call.Run(func(args mock.Arguments) { - run(args[0].(context.Context), args[1].(actor.ShareCodeData)) + run(args[0].(context.Context), args[1].(sharecode.ShareCodeData)) }) return _c } @@ -67,7 +69,7 @@ func (_c *mockDonorStore_DeleteDonorAccess_Call) Return(_a0 error) *mockDonorSto return _c } -func (_c *mockDonorStore_DeleteDonorAccess_Call) RunAndReturn(run func(context.Context, actor.ShareCodeData) error) *mockDonorStore_DeleteDonorAccess_Call { +func (_c *mockDonorStore_DeleteDonorAccess_Call) RunAndReturn(run func(context.Context, sharecode.ShareCodeData) error) *mockDonorStore_DeleteDonorAccess_Call { _c.Call.Return(run) return _c } diff --git a/internal/page/supporter/mock_ShareCodeStore_test.go b/internal/page/supporter/mock_ShareCodeStore_test.go index 56041d701d..4dc4eb057d 100644 --- a/internal/page/supporter/mock_ShareCodeStore_test.go +++ b/internal/page/supporter/mock_ShareCodeStore_test.go @@ -5,8 +5,7 @@ package supporter import ( context "context" - actor "github.com/ministryofjustice/opg-modernising-lpa/internal/actor" - + sharecode "github.com/ministryofjustice/opg-modernising-lpa/internal/sharecode" mock "github.com/stretchr/testify/mock" ) @@ -24,7 +23,7 @@ func (_m *mockShareCodeStore) EXPECT() *mockShareCodeStore_Expecter { } // Delete provides a mock function with given fields: ctx, data -func (_m *mockShareCodeStore) Delete(ctx context.Context, data actor.ShareCodeData) error { +func (_m *mockShareCodeStore) Delete(ctx context.Context, data sharecode.ShareCodeData) error { ret := _m.Called(ctx, data) if len(ret) == 0 { @@ -32,7 +31,7 @@ func (_m *mockShareCodeStore) Delete(ctx context.Context, data actor.ShareCodeDa } var r0 error - if rf, ok := ret.Get(0).(func(context.Context, actor.ShareCodeData) error); ok { + if rf, ok := ret.Get(0).(func(context.Context, sharecode.ShareCodeData) error); ok { r0 = rf(ctx, data) } else { r0 = ret.Error(0) @@ -48,14 +47,14 @@ type mockShareCodeStore_Delete_Call struct { // Delete is a helper method to define mock.On call // - ctx context.Context -// - data actor.ShareCodeData +// - data sharecode.ShareCodeData func (_e *mockShareCodeStore_Expecter) Delete(ctx interface{}, data interface{}) *mockShareCodeStore_Delete_Call { return &mockShareCodeStore_Delete_Call{Call: _e.mock.On("Delete", ctx, data)} } -func (_c *mockShareCodeStore_Delete_Call) Run(run func(ctx context.Context, data actor.ShareCodeData)) *mockShareCodeStore_Delete_Call { +func (_c *mockShareCodeStore_Delete_Call) Run(run func(ctx context.Context, data sharecode.ShareCodeData)) *mockShareCodeStore_Delete_Call { _c.Call.Run(func(args mock.Arguments) { - run(args[0].(context.Context), args[1].(actor.ShareCodeData)) + run(args[0].(context.Context), args[1].(sharecode.ShareCodeData)) }) return _c } @@ -65,28 +64,28 @@ func (_c *mockShareCodeStore_Delete_Call) Return(_a0 error) *mockShareCodeStore_ return _c } -func (_c *mockShareCodeStore_Delete_Call) RunAndReturn(run func(context.Context, actor.ShareCodeData) error) *mockShareCodeStore_Delete_Call { +func (_c *mockShareCodeStore_Delete_Call) RunAndReturn(run func(context.Context, sharecode.ShareCodeData) error) *mockShareCodeStore_Delete_Call { _c.Call.Return(run) return _c } // GetDonor provides a mock function with given fields: ctx -func (_m *mockShareCodeStore) GetDonor(ctx context.Context) (actor.ShareCodeData, error) { +func (_m *mockShareCodeStore) GetDonor(ctx context.Context) (sharecode.ShareCodeData, error) { ret := _m.Called(ctx) if len(ret) == 0 { panic("no return value specified for GetDonor") } - var r0 actor.ShareCodeData + var r0 sharecode.ShareCodeData var r1 error - if rf, ok := ret.Get(0).(func(context.Context) (actor.ShareCodeData, error)); ok { + if rf, ok := ret.Get(0).(func(context.Context) (sharecode.ShareCodeData, error)); ok { return rf(ctx) } - if rf, ok := ret.Get(0).(func(context.Context) actor.ShareCodeData); ok { + if rf, ok := ret.Get(0).(func(context.Context) sharecode.ShareCodeData); ok { r0 = rf(ctx) } else { - r0 = ret.Get(0).(actor.ShareCodeData) + r0 = ret.Get(0).(sharecode.ShareCodeData) } if rf, ok := ret.Get(1).(func(context.Context) error); ok { @@ -116,18 +115,18 @@ func (_c *mockShareCodeStore_GetDonor_Call) Run(run func(ctx context.Context)) * return _c } -func (_c *mockShareCodeStore_GetDonor_Call) Return(_a0 actor.ShareCodeData, _a1 error) *mockShareCodeStore_GetDonor_Call { +func (_c *mockShareCodeStore_GetDonor_Call) Return(_a0 sharecode.ShareCodeData, _a1 error) *mockShareCodeStore_GetDonor_Call { _c.Call.Return(_a0, _a1) return _c } -func (_c *mockShareCodeStore_GetDonor_Call) RunAndReturn(run func(context.Context) (actor.ShareCodeData, error)) *mockShareCodeStore_GetDonor_Call { +func (_c *mockShareCodeStore_GetDonor_Call) RunAndReturn(run func(context.Context) (sharecode.ShareCodeData, error)) *mockShareCodeStore_GetDonor_Call { _c.Call.Return(run) return _c } // PutDonor provides a mock function with given fields: ctx, shareCode, data -func (_m *mockShareCodeStore) PutDonor(ctx context.Context, shareCode string, data actor.ShareCodeData) error { +func (_m *mockShareCodeStore) PutDonor(ctx context.Context, shareCode string, data sharecode.ShareCodeData) error { ret := _m.Called(ctx, shareCode, data) if len(ret) == 0 { @@ -135,7 +134,7 @@ func (_m *mockShareCodeStore) PutDonor(ctx context.Context, shareCode string, da } var r0 error - if rf, ok := ret.Get(0).(func(context.Context, string, actor.ShareCodeData) error); ok { + if rf, ok := ret.Get(0).(func(context.Context, string, sharecode.ShareCodeData) error); ok { r0 = rf(ctx, shareCode, data) } else { r0 = ret.Error(0) @@ -152,14 +151,14 @@ type mockShareCodeStore_PutDonor_Call struct { // PutDonor is a helper method to define mock.On call // - ctx context.Context // - shareCode string -// - data actor.ShareCodeData +// - data sharecode.ShareCodeData func (_e *mockShareCodeStore_Expecter) PutDonor(ctx interface{}, shareCode interface{}, data interface{}) *mockShareCodeStore_PutDonor_Call { return &mockShareCodeStore_PutDonor_Call{Call: _e.mock.On("PutDonor", ctx, shareCode, data)} } -func (_c *mockShareCodeStore_PutDonor_Call) Run(run func(ctx context.Context, shareCode string, data actor.ShareCodeData)) *mockShareCodeStore_PutDonor_Call { +func (_c *mockShareCodeStore_PutDonor_Call) Run(run func(ctx context.Context, shareCode string, data sharecode.ShareCodeData)) *mockShareCodeStore_PutDonor_Call { _c.Call.Run(func(args mock.Arguments) { - run(args[0].(context.Context), args[1].(string), args[2].(actor.ShareCodeData)) + run(args[0].(context.Context), args[1].(string), args[2].(sharecode.ShareCodeData)) }) return _c } @@ -169,7 +168,7 @@ func (_c *mockShareCodeStore_PutDonor_Call) Return(_a0 error) *mockShareCodeStor return _c } -func (_c *mockShareCodeStore_PutDonor_Call) RunAndReturn(run func(context.Context, string, actor.ShareCodeData) error) *mockShareCodeStore_PutDonor_Call { +func (_c *mockShareCodeStore_PutDonor_Call) RunAndReturn(run func(context.Context, string, sharecode.ShareCodeData) error) *mockShareCodeStore_PutDonor_Call { _c.Call.Return(run) return _c } diff --git a/internal/sharecode/data.go b/internal/sharecode/data.go new file mode 100644 index 0000000000..5873ecbc8a --- /dev/null +++ b/internal/sharecode/data.go @@ -0,0 +1,27 @@ +package sharecode + +import ( + "time" + + "github.com/ministryofjustice/opg-modernising-lpa/internal/actor/actoruid" + "github.com/ministryofjustice/opg-modernising-lpa/internal/dynamo" +) + +type ShareCodeData struct { + PK dynamo.ShareKeyType + SK dynamo.ShareSortKeyType + UpdatedAt time.Time + LpaKey dynamo.LpaKeyType + LpaOwnerKey dynamo.LpaOwnerKeyType + ActorUID actoruid.UID + IsReplacementAttorney bool + IsTrustCorporation bool + + // InviteSentTo is the email address the supporter sent the invite to + InviteSentTo string + // LpaLinkedAt is the time the donor entered the access code + LpaLinkedAt time.Time + // LpaLinkedTo is set to the email address the donor used to sign-in when + // using the code + LpaLinkedTo string +} diff --git a/internal/task/enum_identitystate.go b/internal/task/enum_identitystate.go new file mode 100644 index 0000000000..83599d3ff8 --- /dev/null +++ b/internal/task/enum_identitystate.go @@ -0,0 +1,96 @@ +// Code generated by "enumerator -type IdentityState -trimprefix"; DO NOT EDIT. +package task + +import ( + "fmt" + "strconv" +) + +func _() { + // An "invalid array index" compiler error signifies that the constant values have changed. + // Re-run the stringer command to generate them again. + var x [1]struct{} + _ = x[IdentityStateNotStarted-0] + _ = x[IdentityStateInProgress-1] + _ = x[IdentityStatePending-2] + _ = x[IdentityStateProblem-3] + _ = x[IdentityStateCompleted-4] +} + +const _IdentityState_name = "NotStartedInProgressPendingProblemCompleted" + +var _IdentityState_index = [...]uint8{0, 10, 20, 27, 34, 43} + +func (i IdentityState) String() string { + if i >= IdentityState(len(_IdentityState_index)-1) { + return "IdentityState(" + strconv.FormatInt(int64(i), 10) + ")" + } + return _IdentityState_name[_IdentityState_index[i]:_IdentityState_index[i+1]] +} + +func (i IdentityState) MarshalText() ([]byte, error) { + return []byte(i.String()), nil +} + +func (i *IdentityState) UnmarshalText(text []byte) error { + val, err := ParseIdentityState(string(text)) + if err != nil { + return err + } + + *i = val + return nil +} + +func (i IdentityState) IsNotStarted() bool { + return i == IdentityStateNotStarted +} + +func (i IdentityState) IsInProgress() bool { + return i == IdentityStateInProgress +} + +func (i IdentityState) IsPending() bool { + return i == IdentityStatePending +} + +func (i IdentityState) IsProblem() bool { + return i == IdentityStateProblem +} + +func (i IdentityState) IsCompleted() bool { + return i == IdentityStateCompleted +} + +func ParseIdentityState(s string) (IdentityState, error) { + switch s { + case "NotStarted": + return IdentityStateNotStarted, nil + case "InProgress": + return IdentityStateInProgress, nil + case "Pending": + return IdentityStatePending, nil + case "Problem": + return IdentityStateProblem, nil + case "Completed": + return IdentityStateCompleted, nil + default: + return IdentityState(0), fmt.Errorf("invalid IdentityState '%s'", s) + } +} + +type IdentityStateOptions struct { + NotStarted IdentityState + InProgress IdentityState + Pending IdentityState + Problem IdentityState + Completed IdentityState +} + +var IdentityStateValues = IdentityStateOptions{ + NotStarted: IdentityStateNotStarted, + InProgress: IdentityStateInProgress, + Pending: IdentityStatePending, + Problem: IdentityStateProblem, + Completed: IdentityStateCompleted, +} diff --git a/internal/task/enum_paymentstate.go b/internal/task/enum_paymentstate.go new file mode 100644 index 0000000000..75b920115d --- /dev/null +++ b/internal/task/enum_paymentstate.go @@ -0,0 +1,114 @@ +// Code generated by "enumerator -type PaymentState -trimprefix"; DO NOT EDIT. +package task + +import ( + "fmt" + "strconv" +) + +func _() { + // An "invalid array index" compiler error signifies that the constant values have changed. + // Re-run the stringer command to generate them again. + var x [1]struct{} + _ = x[PaymentStateNotStarted-0] + _ = x[PaymentStateInProgress-1] + _ = x[PaymentStatePending-2] + _ = x[PaymentStateApproved-3] + _ = x[PaymentStateDenied-4] + _ = x[PaymentStateMoreEvidenceRequired-5] + _ = x[PaymentStateCompleted-6] +} + +const _PaymentState_name = "NotStartedInProgressPendingApprovedDeniedMoreEvidenceRequiredCompleted" + +var _PaymentState_index = [...]uint8{0, 10, 20, 27, 35, 41, 61, 70} + +func (i PaymentState) String() string { + if i >= PaymentState(len(_PaymentState_index)-1) { + return "PaymentState(" + strconv.FormatInt(int64(i), 10) + ")" + } + return _PaymentState_name[_PaymentState_index[i]:_PaymentState_index[i+1]] +} + +func (i PaymentState) MarshalText() ([]byte, error) { + return []byte(i.String()), nil +} + +func (i *PaymentState) UnmarshalText(text []byte) error { + val, err := ParsePaymentState(string(text)) + if err != nil { + return err + } + + *i = val + return nil +} + +func (i PaymentState) IsNotStarted() bool { + return i == PaymentStateNotStarted +} + +func (i PaymentState) IsInProgress() bool { + return i == PaymentStateInProgress +} + +func (i PaymentState) IsPending() bool { + return i == PaymentStatePending +} + +func (i PaymentState) IsApproved() bool { + return i == PaymentStateApproved +} + +func (i PaymentState) IsDenied() bool { + return i == PaymentStateDenied +} + +func (i PaymentState) IsMoreEvidenceRequired() bool { + return i == PaymentStateMoreEvidenceRequired +} + +func (i PaymentState) IsCompleted() bool { + return i == PaymentStateCompleted +} + +func ParsePaymentState(s string) (PaymentState, error) { + switch s { + case "NotStarted": + return PaymentStateNotStarted, nil + case "InProgress": + return PaymentStateInProgress, nil + case "Pending": + return PaymentStatePending, nil + case "Approved": + return PaymentStateApproved, nil + case "Denied": + return PaymentStateDenied, nil + case "MoreEvidenceRequired": + return PaymentStateMoreEvidenceRequired, nil + case "Completed": + return PaymentStateCompleted, nil + default: + return PaymentState(0), fmt.Errorf("invalid PaymentState '%s'", s) + } +} + +type PaymentStateOptions struct { + NotStarted PaymentState + InProgress PaymentState + Pending PaymentState + Approved PaymentState + Denied PaymentState + MoreEvidenceRequired PaymentState + Completed PaymentState +} + +var PaymentStateValues = PaymentStateOptions{ + NotStarted: PaymentStateNotStarted, + InProgress: PaymentStateInProgress, + Pending: PaymentStatePending, + Approved: PaymentStateApproved, + Denied: PaymentStateDenied, + MoreEvidenceRequired: PaymentStateMoreEvidenceRequired, + Completed: PaymentStateCompleted, +} diff --git a/internal/task/state.go b/internal/task/state.go new file mode 100644 index 0000000000..d26a2c7474 --- /dev/null +++ b/internal/task/state.go @@ -0,0 +1,49 @@ +package task + +type State uint8 + +const ( + NotStarted State = iota + InProgress + Completed +) + +func (t State) NotStarted() bool { return t == NotStarted } +func (t State) InProgress() bool { return t == InProgress } +func (t State) Completed() bool { return t == Completed } + +func (t State) String() string { + switch t { + case NotStarted: + return "notStarted" + case InProgress: + return "inProgress" + case Completed: + return "completed" + } + return "" +} + +//go:generate enumerator -type PaymentState -trimprefix +type PaymentState uint8 + +const ( + PaymentStateNotStarted PaymentState = iota + PaymentStateInProgress + PaymentStatePending + PaymentStateApproved + PaymentStateDenied + PaymentStateMoreEvidenceRequired + PaymentStateCompleted +) + +//go:generate enumerator -type IdentityState -trimprefix +type IdentityState uint8 + +const ( + IdentityStateNotStarted IdentityState = iota + IdentityStateInProgress + IdentityStatePending + IdentityStateProblem + IdentityStateCompleted +) diff --git a/internal/temporary/actor_type.go b/internal/temporary/actor_type.go new file mode 100644 index 0000000000..9629350954 --- /dev/null +++ b/internal/temporary/actor_type.go @@ -0,0 +1,72 @@ +package temporary + +type ActorType uint8 + +const ( + ActorTypeNone ActorType = iota + ActorTypeDonor + ActorTypeAttorney + ActorTypeReplacementAttorney + ActorTypeCertificateProvider + ActorTypePersonToNotify + ActorTypeAuthorisedSignatory + ActorTypeIndependentWitness + ActorTypeTrustCorporation + ActorTypeReplacementTrustCorporation + ActorTypeVoucher +) + +func (t ActorType) String() string { + switch t { + case ActorTypeDonor: + return "donor" + case ActorTypeAttorney: + return "attorney" + case ActorTypeReplacementAttorney: + return "replacementAttorney" + case ActorTypeCertificateProvider: + return "certificateProvider" + case ActorTypePersonToNotify: + return "personToNotify" + case ActorTypeAuthorisedSignatory: + return "signatory" + case ActorTypeIndependentWitness: + return "independentWitness" + case ActorTypeTrustCorporation: + return "trustCorporation" + case ActorTypeReplacementTrustCorporation: + return "replacementTrustCorporation" + case ActorTypeVoucher: + return "voucher" + default: + return "" + } +} + +type Types struct { + None ActorType + Donor ActorType + Attorney ActorType + ReplacementAttorney ActorType + TrustCorporation ActorType + ReplacementTrustCorporation ActorType + CertificateProvider ActorType + PersonToNotify ActorType + AuthorisedSignatory ActorType + IndependentWitness ActorType + Voucher ActorType +} + +var ActorTypes = Types{ + None: ActorTypeNone, + Donor: ActorTypeDonor, + Attorney: ActorTypeAttorney, + ReplacementAttorney: ActorTypeReplacementAttorney, + TrustCorporation: ActorTypeTrustCorporation, + ReplacementTrustCorporation: ActorTypeReplacementTrustCorporation, + CertificateProvider: ActorTypeCertificateProvider, + PersonToNotify: ActorTypePersonToNotify, + AuthorisedSignatory: ActorTypeAuthorisedSignatory, + IndependentWitness: ActorTypeIndependentWitness, + Voucher: ActorTypeVoucher, +} diff --git a/internal/temporary/lpa_link.go b/internal/temporary/lpa_link.go new file mode 100644 index 0000000000..7295396fcf --- /dev/null +++ b/internal/temporary/lpa_link.go @@ -0,0 +1,30 @@ +package temporary + +import ( + "strings" + "time" + + "github.com/ministryofjustice/opg-modernising-lpa/internal/dynamo" +) + +// An LpaLink is used to join an actor to an LPA. +type LpaLink struct { + // PK is the same as the PK for the LPA + PK dynamo.LpaKeyType + // SK is the subKey for the current user + SK dynamo.SubKeyType + // DonorKey is the donorKey for the donor + DonorKey dynamo.LpaOwnerKeyType + // ActorType is the type for the current user + ActorType ActorType + // UpdatedAt is set to allow this data to be queried from SKUpdatedAtIndex + UpdatedAt time.Time +} + +func (l LpaLink) UserSub() string { + if l.SK == "" { + return "" + } + + return strings.Split(l.SK.SK(), dynamo.SubKey("").SK())[1] +}