-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1629 from ministryofjustice/MLPAB-2454-back-from-…
…the-post-office MLPAB-2454 Collect identity info when they have completed at post office
- Loading branch information
Showing
32 changed files
with
809 additions
and
60 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
42 changes: 42 additions & 0 deletions
42
...rnal/certificateprovider/certificateproviderpage/completing_your_identity_confirmation.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
package certificateproviderpage | ||
|
||
import ( | ||
"net/http" | ||
"time" | ||
|
||
"github.com/ministryofjustice/opg-go-common/template" | ||
"github.com/ministryofjustice/opg-modernising-lpa/internal/appcontext" | ||
"github.com/ministryofjustice/opg-modernising-lpa/internal/certificateprovider" | ||
"github.com/ministryofjustice/opg-modernising-lpa/internal/certificateprovider/certificateproviderdata" | ||
"github.com/ministryofjustice/opg-modernising-lpa/internal/validation" | ||
) | ||
|
||
type completingYourIdentityConfirmationData struct { | ||
App appcontext.Data | ||
Errors validation.List | ||
Form *howWillYouConfirmYourIdentityForm | ||
Options howYouWillConfirmYourIdentityOptions | ||
Deadline time.Time | ||
} | ||
|
||
func CompletingYourIdentityConfirmation(tmpl template.Template) Handler { | ||
return func(appData appcontext.Data, w http.ResponseWriter, r *http.Request, provided *certificateproviderdata.Provided) error { | ||
data := &completingYourIdentityConfirmationData{ | ||
App: appData, | ||
Form: &howWillYouConfirmYourIdentityForm{}, | ||
Options: howYouWillConfirmYourIdentityValues, | ||
Deadline: provided.IdentityDeadline(), | ||
} | ||
|
||
if r.Method == http.MethodPost { | ||
data.Form = readHowWillYouConfirmYourIdentityForm(r, "howYouWouldLikeToContinue") | ||
data.Errors = data.Form.Validate() | ||
|
||
if data.Errors.None() { | ||
return certificateprovider.PathIdentityWithOneLogin.Redirect(w, r, appData, provided.LpaID) | ||
} | ||
} | ||
|
||
return tmpl(w, data) | ||
} | ||
} |
106 changes: 106 additions & 0 deletions
106
...certificateprovider/certificateproviderpage/completing_your_identity_confirmation_test.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,106 @@ | ||
package certificateproviderpage | ||
|
||
import ( | ||
"net/http" | ||
"net/http/httptest" | ||
"net/url" | ||
"strings" | ||
"testing" | ||
|
||
"github.com/ministryofjustice/opg-modernising-lpa/internal/certificateprovider" | ||
"github.com/ministryofjustice/opg-modernising-lpa/internal/certificateprovider/certificateproviderdata" | ||
"github.com/ministryofjustice/opg-modernising-lpa/internal/page" | ||
"github.com/ministryofjustice/opg-modernising-lpa/internal/validation" | ||
"github.com/stretchr/testify/assert" | ||
"github.com/stretchr/testify/mock" | ||
) | ||
|
||
func TestGetCompletingYourIdentityConfirmation(t *testing.T) { | ||
w := httptest.NewRecorder() | ||
r, _ := http.NewRequest(http.MethodGet, "/", nil) | ||
|
||
template := newMockTemplate(t) | ||
template.EXPECT(). | ||
Execute(w, &completingYourIdentityConfirmationData{ | ||
App: testAppData, | ||
Form: &howWillYouConfirmYourIdentityForm{}, | ||
Options: howYouWillConfirmYourIdentityValues, | ||
}). | ||
Return(nil) | ||
|
||
err := CompletingYourIdentityConfirmation(template.Execute)(testAppData, w, r, &certificateproviderdata.Provided{}) | ||
resp := w.Result() | ||
|
||
assert.Nil(t, err) | ||
assert.Equal(t, http.StatusOK, resp.StatusCode) | ||
} | ||
|
||
func TestGetCompletingYourIdentityConfirmationWhenTemplateErrors(t *testing.T) { | ||
w := httptest.NewRecorder() | ||
r, _ := http.NewRequest(http.MethodGet, "/", nil) | ||
|
||
template := newMockTemplate(t) | ||
template.EXPECT(). | ||
Execute(w, mock.Anything). | ||
Return(expectedError) | ||
|
||
err := CompletingYourIdentityConfirmation(template.Execute)(testAppData, w, r, &certificateproviderdata.Provided{}) | ||
assert.Equal(t, expectedError, err) | ||
} | ||
|
||
func TestPostCompletingYourIdentityConfirmation(t *testing.T) { | ||
testCases := map[string]struct { | ||
how howYouWillConfirmYourIdentity | ||
provided *certificateproviderdata.Provided | ||
redirect certificateprovider.Path | ||
}{ | ||
"post office successful": { | ||
how: howYouWillConfirmYourIdentityPostOfficeSuccessfully, | ||
provided: &certificateproviderdata.Provided{LpaID: "lpa-id"}, | ||
redirect: certificateprovider.PathIdentityWithOneLogin, | ||
}, | ||
"one login": { | ||
how: howYouWillConfirmYourIdentityOneLogin, | ||
provided: &certificateproviderdata.Provided{LpaID: "lpa-id"}, | ||
redirect: certificateprovider.PathIdentityWithOneLogin, | ||
}, | ||
} | ||
|
||
for name, tc := range testCases { | ||
t.Run(name, func(t *testing.T) { | ||
form := url.Values{ | ||
"how": {tc.how.String()}, | ||
} | ||
|
||
w := httptest.NewRecorder() | ||
r, _ := http.NewRequest(http.MethodPost, "/", strings.NewReader(form.Encode())) | ||
r.Header.Add("Content-Type", page.FormUrlEncoded) | ||
|
||
err := CompletingYourIdentityConfirmation(nil)(testAppData, w, r, tc.provided) | ||
resp := w.Result() | ||
|
||
assert.Nil(t, err) | ||
assert.Equal(t, http.StatusFound, resp.StatusCode) | ||
assert.Equal(t, tc.redirect.Format("lpa-id"), resp.Header.Get("Location")) | ||
}) | ||
} | ||
} | ||
|
||
func TestPostCompletingYourIdentityConfirmationWhenValidationErrors(t *testing.T) { | ||
w := httptest.NewRecorder() | ||
r, _ := http.NewRequest(http.MethodPost, "/", strings.NewReader("")) | ||
r.Header.Add("Content-Type", page.FormUrlEncoded) | ||
|
||
template := newMockTemplate(t) | ||
template.EXPECT(). | ||
Execute(w, mock.MatchedBy(func(data *completingYourIdentityConfirmationData) bool { | ||
return assert.Equal(t, validation.With("how", validation.SelectError{Label: "howYouWouldLikeToContinue"}), data.Errors) | ||
})). | ||
Return(nil) | ||
|
||
err := CompletingYourIdentityConfirmation(template.Execute)(testAppData, w, r, &certificateproviderdata.Provided{}) | ||
resp := w.Result() | ||
|
||
assert.Nil(t, err) | ||
assert.Equal(t, http.StatusOK, resp.StatusCode) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
52 changes: 52 additions & 0 deletions
52
internal/donor/donorpage/completing_your_identity_confirmation.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
package donorpage | ||
|
||
import ( | ||
"net/http" | ||
"time" | ||
|
||
"github.com/ministryofjustice/opg-go-common/template" | ||
"github.com/ministryofjustice/opg-modernising-lpa/internal/appcontext" | ||
"github.com/ministryofjustice/opg-modernising-lpa/internal/donor" | ||
"github.com/ministryofjustice/opg-modernising-lpa/internal/donor/donordata" | ||
"github.com/ministryofjustice/opg-modernising-lpa/internal/validation" | ||
) | ||
|
||
type completingYourIdentityConfirmationData struct { | ||
App appcontext.Data | ||
Errors validation.List | ||
Form *howWillYouConfirmYourIdentityForm | ||
Options howYouWillConfirmYourIdentityOptions | ||
Deadline time.Time | ||
} | ||
|
||
func CompletingYourIdentityConfirmation(tmpl template.Template) Handler { | ||
return func(appData appcontext.Data, w http.ResponseWriter, r *http.Request, provided *donordata.Provided) error { | ||
data := &completingYourIdentityConfirmationData{ | ||
App: appData, | ||
Form: &howWillYouConfirmYourIdentityForm{}, | ||
Options: howYouWillConfirmYourIdentityValues, | ||
Deadline: provided.IdentityDeadline(), | ||
} | ||
|
||
if r.Method == http.MethodPost { | ||
data.Form = readHowWillYouConfirmYourIdentityForm(r, "howYouWouldLikeToContinue") | ||
data.Errors = data.Form.Validate() | ||
|
||
if data.Errors.None() { | ||
switch data.Form.How { | ||
case howYouWillConfirmYourIdentityWithdraw: | ||
if provided.WitnessedByCertificateProviderAt.IsZero() { | ||
return donor.PathDeleteThisLpa.Redirect(w, r, appData, provided) | ||
} | ||
|
||
return donor.PathWithdrawThisLpa.Redirect(w, r, appData, provided) | ||
|
||
default: | ||
return donor.PathIdentityWithOneLogin.Redirect(w, r, appData, provided) | ||
} | ||
} | ||
} | ||
|
||
return tmpl(w, data) | ||
} | ||
} |
Oops, something went wrong.