Skip to content

Commit

Permalink
Merge 5a3d6cc into 88e1ec7
Browse files Browse the repository at this point in the history
  • Loading branch information
acsauk authored Apr 10, 2024
2 parents 88e1ec7 + 5a3d6cc commit ec7459f
Show file tree
Hide file tree
Showing 2 changed files with 76 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,14 @@ type howWouldCertificateProviderPreferToCarryOutTheirRoleForm struct {
func readHowWouldCertificateProviderPreferToCarryOutTheirRole(r *http.Request) *howWouldCertificateProviderPreferToCarryOutTheirRoleForm {
carryOutBy, err := actor.ParseCertificateProviderCarryOutBy(page.PostFormString(r, "carry-out-by"))

email := page.PostFormString(r, "email")
if carryOutBy.IsPaper() {
email = ""
}

return &howWouldCertificateProviderPreferToCarryOutTheirRoleForm{
CarryOutBy: carryOutBy,
Email: page.PostFormString(r, "email"),
Email: email,
Error: err,
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,35 @@ func TestPostHowWouldCertificateProviderPreferToCarryOutTheirRole(t *testing.T)
}
}

func TestPostHowWouldCertificateProviderPreferToCarryOutTheirRoleChangingFromOnlineToPaper(t *testing.T) {
form := url.Values{
"carry-out-by": {actor.Paper.String()},
"email": {"[email protected]"},
}

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

donorStore := newMockDonorStore(t)
donorStore.EXPECT().
Put(r.Context(), &actor.DonorProvidedDetails{
LpaID: "lpa-id",
CertificateProvider: actor.CertificateProvider{CarryOutBy: actor.Paper, Email: ""},
}).
Return(nil)

err := HowWouldCertificateProviderPreferToCarryOutTheirRole(nil, donorStore)(testAppData, w, r, &actor.DonorProvidedDetails{
LpaID: "lpa-id",
CertificateProvider: actor.CertificateProvider{CarryOutBy: actor.Online, Email: "[email protected]"},
})
resp := w.Result()

assert.Nil(t, err)
assert.Equal(t, http.StatusFound, resp.StatusCode)
assert.Equal(t, page.Paths.CertificateProviderAddress.Format("lpa-id"), resp.Header.Get("Location"))
}

func TestPostHowWouldCertificateProviderPreferToCarryOutTheirRoleWhenStoreErrors(t *testing.T) {
form := url.Values{
"carry-out-by": {actor.Paper.String()},
Expand Down Expand Up @@ -159,18 +188,51 @@ func TestPostHowWouldCertificateProviderPreferToCarryOutTheirRoleWhenValidationE
}

func TestReadHowWouldCertificateProviderPreferToCarryOutTheirRoleForm(t *testing.T) {
form := url.Values{
"carry-out-by": {actor.Online.String()},
"email": {"[email protected]"},
testcases := map[string]struct {
carryOutBy actor.CertificateProviderCarryOutBy
email string
formValues url.Values
expectedForm *howWouldCertificateProviderPreferToCarryOutTheirRoleForm
}{
"online with email": {
formValues: url.Values{
"carry-out-by": {actor.Online.String()},
"email": {"[email protected]"},
},
expectedForm: &howWouldCertificateProviderPreferToCarryOutTheirRoleForm{
CarryOutBy: actor.Online,
Email: "[email protected]",
},
},
"paper": {
formValues: url.Values{
"carry-out-by": {actor.Paper.String()},
},
expectedForm: &howWouldCertificateProviderPreferToCarryOutTheirRoleForm{
CarryOutBy: actor.Paper,
},
},
"paper with email": {
formValues: url.Values{
"carry-out-by": {actor.Paper.String()},
"email": {"[email protected]"},
},
expectedForm: &howWouldCertificateProviderPreferToCarryOutTheirRoleForm{
CarryOutBy: actor.Paper,
},
},
}

r, _ := http.NewRequest(http.MethodPost, "/", strings.NewReader(form.Encode()))
r.Header.Add("Content-Type", page.FormUrlEncoded)
for name, tc := range testcases {
t.Run(name, func(t *testing.T) {
r, _ := http.NewRequest(http.MethodPost, "/", strings.NewReader(tc.formValues.Encode()))
r.Header.Add("Content-Type", page.FormUrlEncoded)

result := readHowWouldCertificateProviderPreferToCarryOutTheirRole(r)
result := readHowWouldCertificateProviderPreferToCarryOutTheirRole(r)

assert.Equal(t, actor.Online, result.CarryOutBy)
assert.Equal(t, "[email protected]", result.Email)
assert.Equal(t, tc.expectedForm, result)
})
}
}

func TestHowWouldCertificateProviderPreferToCarryOutTheirRoleFormValidate(t *testing.T) {
Expand Down

0 comments on commit ec7459f

Please sign in to comment.