-
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.
- Loading branch information
Showing
2 changed files
with
76 additions
and
9 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
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 |
---|---|---|
|
@@ -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()}, | ||
|
@@ -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) { | ||
|