Skip to content

Commit

Permalink
MLPAB-1390 MLPAB-1435 Send us your evidence and what happens next pag…
Browse files Browse the repository at this point in the history
…es (#815)
  • Loading branch information
hawx authored Nov 2, 2023
1 parent eb7e9b4 commit c438826
Show file tree
Hide file tree
Showing 31 changed files with 453 additions and 315 deletions.
9 changes: 5 additions & 4 deletions internal/app/donor_store_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
"github.com/ministryofjustice/opg-modernising-lpa/internal/date"
"github.com/ministryofjustice/opg-modernising-lpa/internal/dynamo"
"github.com/ministryofjustice/opg-modernising-lpa/internal/page"
"github.com/ministryofjustice/opg-modernising-lpa/internal/pay"
"github.com/ministryofjustice/opg-modernising-lpa/internal/place"
"github.com/ministryofjustice/opg-modernising-lpa/internal/uid"
"github.com/stretchr/testify/assert"
Expand Down Expand Up @@ -476,7 +477,7 @@ func TestDonorStorePutWhenReducedFeeRequestedAndUnsentDocuments(t *testing.T) {
ID: "5",
UID: "M-1111",
UpdatedAt: now,
FeeType: page.HalfFee,
FeeType: pay.HalfFee,
Tasks: page.Tasks{PayForLpa: actor.PaymentTaskPending},
HasSentApplicationUpdatedEvent: true,
}).
Expand Down Expand Up @@ -508,7 +509,7 @@ func TestDonorStorePutWhenReducedFeeRequestedAndUnsentDocuments(t *testing.T) {
SK: "#DONOR#an-id",
ID: "5",
UID: "M-1111",
FeeType: page.HalfFee,
FeeType: pay.HalfFee,
Tasks: page.Tasks{PayForLpa: actor.PaymentTaskPending},
HasSentApplicationUpdatedEvent: true,
})
Expand Down Expand Up @@ -614,7 +615,7 @@ func TestDonorStorePutWhenReducedFeeRequestedAndUnsentDocumentsWhenEventClientSe
SK: "#DONOR#an-id",
ID: "5",
UID: "M-1111",
FeeType: page.HalfFee,
FeeType: pay.HalfFee,
Tasks: page.Tasks{PayForLpa: actor.PaymentTaskPending},
HasSentApplicationUpdatedEvent: true,
})
Expand Down Expand Up @@ -661,7 +662,7 @@ func TestDonorStorePutWhenReducedFeeRequestedAndUnsentDocumentsWhenDocumentStore
SK: "#DONOR#an-id",
ID: "5",
UID: "M-1111",
FeeType: page.HalfFee,
FeeType: pay.HalfFee,
Tasks: page.Tasks{PayForLpa: actor.PaymentTaskPending},
HasSentApplicationUpdatedEvent: true,
})
Expand Down
46 changes: 6 additions & 40 deletions internal/page/data.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import (
"github.com/ministryofjustice/opg-modernising-lpa/internal/actor"
"github.com/ministryofjustice/opg-modernising-lpa/internal/form"
"github.com/ministryofjustice/opg-modernising-lpa/internal/identity"
"github.com/ministryofjustice/opg-modernising-lpa/internal/pay"
"github.com/ministryofjustice/opg-modernising-lpa/internal/place"
"golang.org/x/exp/slices"
)
Expand Down Expand Up @@ -66,27 +67,6 @@ const (
ReplacementAttorneysStepInAnotherWay // other
)

//go:generate enumerator -type FeeType
type FeeType uint8

const (
FullFee FeeType = iota
HalfFee
NoFee
HardshipFee
RepeatApplicationFee
)

//go:generate enumerator -type PreviousFee -empty
type PreviousFee uint8

const (
PreviousFeeFull PreviousFee = iota + 1
PreviousFeeHalf
PreviousFeeExemption
PreviousFeeHardship
)

// Lpa contains all the data related to the LPA application
type Lpa struct {
PK, SK string
Expand Down Expand Up @@ -167,11 +147,13 @@ type Lpa struct {
WitnessCodeLimiter *Limiter

// FeeType is the type of fee the user is applying for
FeeType FeeType
FeeType pay.FeeType
// EvidenceDelivery is the method by which the user wants to send evidence
EvidenceDelivery pay.EvidenceDelivery
// PreviousApplicationNumber if the application is related to an existing application
PreviousApplicationNumber string
// PreviousFee is the fee previously paid for an LPA
PreviousFee PreviousFee
PreviousFee pay.PreviousFee

HasSentApplicationUpdatedEvent bool
HasSentPreviousApplicationLinkedEvent bool
Expand Down Expand Up @@ -477,23 +459,7 @@ func (l *Lpa) Cost() int {
return 8200
}

switch l.FeeType {
case FullFee:
return 8200
case HalfFee:
return 4100
case RepeatApplicationFee:
switch l.PreviousFee {
case PreviousFeeFull:
return 4100
case PreviousFeeHalf:
return 2050
default:
return 0
}
default:
return 0
}
return pay.Cost(l.FeeType, l.PreviousFee)
}

func (l *Lpa) FeeAmount() int {
Expand Down
69 changes: 13 additions & 56 deletions internal/page/data_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"github.com/ministryofjustice/opg-modernising-lpa/internal/actor"
"github.com/ministryofjustice/opg-modernising-lpa/internal/form"
"github.com/ministryofjustice/opg-modernising-lpa/internal/identity"
"github.com/ministryofjustice/opg-modernising-lpa/internal/pay"
"github.com/ministryofjustice/opg-modernising-lpa/internal/place"
"github.com/stretchr/testify/assert"
)
Expand Down Expand Up @@ -1036,38 +1037,14 @@ func TestLpaCost(t *testing.T) {
lpa *Lpa
expected int
}{
"full": {
lpa: &Lpa{FeeType: FullFee},
"denied": {
lpa: &Lpa{FeeType: pay.HalfFee, Tasks: Tasks{PayForLpa: actor.PaymentTaskDenied}},
expected: 8200,
},
"half": {
lpa: &Lpa{FeeType: HalfFee},
lpa: &Lpa{FeeType: pay.HalfFee},
expected: 4100,
},
"no fee": {
lpa: &Lpa{FeeType: NoFee},
expected: 0,
},
"hardship": {
lpa: &Lpa{FeeType: HardshipFee},
expected: 0,
},
"repeat full": {
lpa: &Lpa{FeeType: RepeatApplicationFee, PreviousFee: PreviousFeeFull},
expected: 4100,
},
"repeat half": {
lpa: &Lpa{FeeType: RepeatApplicationFee, PreviousFee: PreviousFeeHalf},
expected: 2050,
},
"repeat exemption": {
lpa: &Lpa{FeeType: RepeatApplicationFee, PreviousFee: PreviousFeeExemption},
expected: 0,
},
"repeat hardship": {
lpa: &Lpa{FeeType: RepeatApplicationFee, PreviousFee: PreviousFeeHardship},
expected: 0,
},
}

for name, tc := range testCases {
Expand All @@ -1082,41 +1059,21 @@ func TestFeeAmount(t *testing.T) {
Lpa *Lpa
ExpectedCost int
}{
"full fee - not paid": {
Lpa: &Lpa{FeeType: FullFee},
ExpectedCost: 8200,
},
"half fee - not paid": {
Lpa: &Lpa{FeeType: HalfFee},
"not paid": {
Lpa: &Lpa{FeeType: pay.HalfFee},
ExpectedCost: 4100,
},
"no fee": {
Lpa: &Lpa{FeeType: NoFee},
"fully paid": {
Lpa: &Lpa{FeeType: pay.HalfFee, PaymentDetails: []Payment{{Amount: 4100}}},
ExpectedCost: 0,
},
"hardship fee": {
Lpa: &Lpa{FeeType: HardshipFee},
ExpectedCost: 0,
},
"full fee - paid": {
Lpa: &Lpa{FeeType: FullFee, PaymentDetails: []Payment{{Amount: 8200}}},
ExpectedCost: 0,
},
"half fee - paid": {
Lpa: &Lpa{FeeType: HalfFee, PaymentDetails: []Payment{{Amount: 4100}}},
ExpectedCost: 0,
},
"half fee - paid, denied": {
Lpa: &Lpa{FeeType: HalfFee, PaymentDetails: []Payment{{Amount: 4100}}, Tasks: Tasks{PayForLpa: actor.PaymentTaskDenied}},
"denied partially paid": {
Lpa: &Lpa{FeeType: pay.HalfFee, PaymentDetails: []Payment{{Amount: 4100}}, Tasks: Tasks{PayForLpa: actor.PaymentTaskDenied}},
ExpectedCost: 4100,
},
"no fee - paid, denied": {
Lpa: &Lpa{FeeType: NoFee, Tasks: Tasks{PayForLpa: actor.PaymentTaskDenied}},
ExpectedCost: 8200,
},
"hardship fee - paid, denied": {
Lpa: &Lpa{FeeType: HardshipFee, Tasks: Tasks{PayForLpa: actor.PaymentTaskDenied}},
ExpectedCost: 8200,
"denied fully paid": {
Lpa: &Lpa{FeeType: pay.HalfFee, PaymentDetails: []Payment{{Amount: 4100}, {Amount: 4100}}, Tasks: Tasks{PayForLpa: actor.PaymentTaskDenied}},
ExpectedCost: 0,
},
}

Expand Down
29 changes: 14 additions & 15 deletions internal/page/donor/how_would_you_like_to_send_evidence.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,39 +6,38 @@ import (
"github.com/ministryofjustice/opg-go-common/template"
"github.com/ministryofjustice/opg-modernising-lpa/internal/form"
"github.com/ministryofjustice/opg-modernising-lpa/internal/page"
"github.com/ministryofjustice/opg-modernising-lpa/internal/pay"
"github.com/ministryofjustice/opg-modernising-lpa/internal/validation"
)

//go:generate enumerator -type EvidenceDelivery -linecomment -empty
type EvidenceDelivery uint8

const (
Upload EvidenceDelivery = iota + 1 // upload
Post // post
)

type howWouldYouLikeToSendEvidenceData struct {
App page.AppData
Errors validation.List
Options EvidenceDeliveryOptions
Options pay.EvidenceDeliveryOptions
}

func HowWouldYouLikeToSendEvidence(tmpl template.Template) Handler {
func HowWouldYouLikeToSendEvidence(tmpl template.Template, donorStore DonorStore) Handler {
return func(appData page.AppData, w http.ResponseWriter, r *http.Request, lpa *page.Lpa) error {
data := &howWouldYouLikeToSendEvidenceData{
App: appData,
Options: EvidenceDeliveryValues,
Options: pay.EvidenceDeliveryValues,
}

if r.Method == http.MethodPost {
form := readHowWouldYouLikeToSendEvidenceForm(r)
data.Errors = form.Validate()

if data.Errors.None() {
if form.EvidenceDelivery.IsUpload() {
lpa.EvidenceDelivery = form.EvidenceDelivery

if err := donorStore.Put(r.Context(), lpa); err != nil {
return err
}

if lpa.EvidenceDelivery.IsUpload() {
return appData.Redirect(w, r, lpa, page.Paths.UploadEvidence.Format(lpa.ID))
} else {
return appData.Redirect(w, r, lpa, page.Paths.HowToEmailOrPostEvidence.Format(lpa.ID))
return appData.Redirect(w, r, lpa, page.Paths.SendUsYourEvidenceByPost.Format(lpa.ID))
}
}
}
Expand All @@ -48,7 +47,7 @@ func HowWouldYouLikeToSendEvidence(tmpl template.Template) Handler {
}

type evidenceDeliveryForm struct {
EvidenceDelivery EvidenceDelivery
EvidenceDelivery pay.EvidenceDelivery
Error error
ErrorLabel string
}
Expand All @@ -63,7 +62,7 @@ func (f *evidenceDeliveryForm) Validate() validation.List {
}

func readHowWouldYouLikeToSendEvidenceForm(r *http.Request) *evidenceDeliveryForm {
evidenceDelivery, err := ParseEvidenceDelivery(form.PostFormString(r, "evidence-delivery"))
evidenceDelivery, err := pay.ParseEvidenceDelivery(form.PostFormString(r, "evidence-delivery"))

return &evidenceDeliveryForm{
EvidenceDelivery: evidenceDelivery,
Expand Down
44 changes: 34 additions & 10 deletions internal/page/donor/how_would_you_like_to_send_evidence_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"testing"

"github.com/ministryofjustice/opg-modernising-lpa/internal/page"
"github.com/ministryofjustice/opg-modernising-lpa/internal/pay"
"github.com/ministryofjustice/opg-modernising-lpa/internal/validation"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/mock"
Expand All @@ -21,11 +22,11 @@ func TestGetHowWouldYouLikeToSendEvidence(t *testing.T) {
template.
On("Execute", w, &howWouldYouLikeToSendEvidenceData{
App: testAppData,
Options: EvidenceDeliveryValues,
Options: pay.EvidenceDeliveryValues,
}).
Return(nil)

err := HowWouldYouLikeToSendEvidence(template.Execute)(testAppData, w, r, &page.Lpa{})
err := HowWouldYouLikeToSendEvidence(template.Execute, nil)(testAppData, w, r, &page.Lpa{})
resp := w.Result()

assert.Nil(t, err)
Expand All @@ -40,11 +41,11 @@ func TestGetHowWouldYouLikeToSendEvidenceFromStore(t *testing.T) {
template.
On("Execute", w, &howWouldYouLikeToSendEvidenceData{
App: testAppData,
Options: EvidenceDeliveryValues,
Options: pay.EvidenceDeliveryValues,
}).
Return(nil)

err := HowWouldYouLikeToSendEvidence(template.Execute)(testAppData, w, r, &page.Lpa{})
err := HowWouldYouLikeToSendEvidence(template.Execute, nil)(testAppData, w, r, &page.Lpa{})
resp := w.Result()

assert.Nil(t, err)
Expand All @@ -60,17 +61,17 @@ func TestGetHowWouldYouLikeToSendEvidenceWhenTemplateErrors(t *testing.T) {
On("Execute", w, mock.Anything).
Return(expectedError)

err := HowWouldYouLikeToSendEvidence(template.Execute)(testAppData, w, r, &page.Lpa{})
err := HowWouldYouLikeToSendEvidence(template.Execute, nil)(testAppData, w, r, &page.Lpa{})
resp := w.Result()

assert.Equal(t, expectedError, err)
assert.Equal(t, http.StatusOK, resp.StatusCode)
}

func TestPostHowWouldYouLikeToSendEvidence(t *testing.T) {
testcases := map[EvidenceDelivery]page.LpaPath{
Upload: page.Paths.UploadEvidence,
Post: page.Paths.HowToEmailOrPostEvidence,
testcases := map[pay.EvidenceDelivery]page.LpaPath{
pay.Upload: page.Paths.UploadEvidence,
pay.Post: page.Paths.SendUsYourEvidenceByPost,
}

for evidenceDelivery, redirect := range testcases {
Expand All @@ -83,7 +84,12 @@ func TestPostHowWouldYouLikeToSendEvidence(t *testing.T) {
r, _ := http.NewRequest(http.MethodPost, "/", strings.NewReader(form.Encode()))
r.Header.Add("Content-Type", page.FormUrlEncoded)

err := HowWouldYouLikeToSendEvidence(nil)(testAppData, w, r, &page.Lpa{ID: "lpa-id"})
donorStore := newMockDonorStore(t)
donorStore.
On("Put", r.Context(), &page.Lpa{ID: "lpa-id", EvidenceDelivery: evidenceDelivery}).
Return(nil)

err := HowWouldYouLikeToSendEvidence(nil, donorStore)(testAppData, w, r, &page.Lpa{ID: "lpa-id"})
resp := w.Result()

assert.Nil(t, err)
Expand All @@ -93,6 +99,24 @@ func TestPostHowWouldYouLikeToSendEvidence(t *testing.T) {
}
}

func TestPostHowWouldYouLikeToSendEvidenceWhenStoreErrors(t *testing.T) {
form := url.Values{
"evidence-delivery": {pay.Upload.String()},
}

w := httptest.NewRecorder()
r, _ := http.NewRequest(http.MethodPost, "/", strings.NewReader(form.Encode()))
r.Header.Add("Content-Type", page.FormUrlEncoded)

donorStore := newMockDonorStore(t)
donorStore.
On("Put", r.Context(), mock.Anything).
Return(expectedError)

err := HowWouldYouLikeToSendEvidence(nil, donorStore)(testAppData, w, r, &page.Lpa{ID: "lpa-id"})
assert.Equal(t, expectedError, err)
}

func TestPostHowWouldYouLikeToSendEvidenceWhenValidationErrors(t *testing.T) {
w := httptest.NewRecorder()
r, _ := http.NewRequest(http.MethodPost, "/", strings.NewReader(""))
Expand All @@ -105,7 +129,7 @@ func TestPostHowWouldYouLikeToSendEvidenceWhenValidationErrors(t *testing.T) {
})).
Return(nil)

err := HowWouldYouLikeToSendEvidence(template.Execute)(testAppData, w, r, &page.Lpa{})
err := HowWouldYouLikeToSendEvidence(template.Execute, nil)(testAppData, w, r, &page.Lpa{})
resp := w.Result()

assert.Nil(t, err)
Expand Down
Loading

0 comments on commit c438826

Please sign in to comment.