Skip to content

Commit

Permalink
MLPAB-1453 Send attorney share codes when donor executes (#782)
Browse files Browse the repository at this point in the history
  • Loading branch information
hawx authored Oct 19, 2023
1 parent b600e6f commit 45e8b8d
Show file tree
Hide file tree
Showing 2 changed files with 72 additions and 10 deletions.
4 changes: 4 additions & 0 deletions internal/page/donor/witnessing_as_certificate_provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,10 @@ func WitnessingAsCertificateProvider(tmpl template.Template, donorStore DonorSto
}
}

if err := shareCodeSender.SendAttorneys(r.Context(), appData, lpa); err != nil {
return err
}

return appData.Redirect(w, r, lpa, page.Paths.YouHaveSubmittedYourLpa.Format(lpa.ID))
}
}
Expand Down
78 changes: 68 additions & 10 deletions internal/page/donor/witnessing_as_certificate_provider_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -113,16 +113,23 @@ func TestPostWitnessingAsCertificateProvider(t *testing.T) {
r.Header.Add("Content-Type", page.FormUrlEncoded)
now := time.Now()

lpa := &page.Lpa{
ID: "lpa-id",
DonorIdentityUserData: identity.UserData{OK: true, Provider: identity.OneLogin},
CertificateProviderCodes: page.WitnessCodes{{Code: "1234", Created: now}},
CertificateProvider: actor.CertificateProvider{FirstNames: "Fred"},
WitnessedByCertificateProviderAt: now,
SignedAt: now,
}

shareCodeSender := newMockShareCodeSender(t)
shareCodeSender.
On("SendAttorneys", r.Context(), testAppData, lpa).
Return(nil)

donorStore := newMockDonorStore(t)
donorStore.
On("Put", r.Context(), &page.Lpa{
ID: "lpa-id",
DonorIdentityUserData: identity.UserData{OK: true, Provider: identity.OneLogin},
CertificateProviderCodes: page.WitnessCodes{{Code: "1234", Created: now}},
CertificateProvider: actor.CertificateProvider{FirstNames: "Fred"},
WitnessedByCertificateProviderAt: now,
SignedAt: now,
}).
On("Put", r.Context(), lpa).
Return(nil)

ctx := page.ContextWithSessionData(r.Context(), &page.SessionData{
Expand All @@ -135,7 +142,7 @@ func TestPostWitnessingAsCertificateProvider(t *testing.T) {
On("GetAny", ctx).
Return(tc.certificateProvider, tc.err)

err := WitnessingAsCertificateProvider(nil, donorStore, nil, func() time.Time { return now }, certificateProviderStore)(testAppData, w, r, &page.Lpa{
err := WitnessingAsCertificateProvider(nil, donorStore, shareCodeSender, func() time.Time { return now }, certificateProviderStore)(testAppData, w, r, &page.Lpa{
ID: "lpa-id",
DonorIdentityUserData: identity.UserData{OK: true, Provider: identity.OneLogin},
CertificateProviderCodes: page.WitnessCodes{{Code: "1234", Created: now}},
Expand Down Expand Up @@ -187,6 +194,9 @@ func TestPostWitnessingAsCertificateProviderWhenIdentityConfirmed(t *testing.T)
shareCodeSender.
On("SendCertificateProvider", r.Context(), notify.CertificateProviderReturnEmail, testAppData, false, lpa).
Return(nil)
shareCodeSender.
On("SendAttorneys", r.Context(), testAppData, lpa).
Return(nil)

err := WitnessingAsCertificateProvider(nil, donorStore, shareCodeSender, func() time.Time { return now }, certificateProviderStore)(testAppData, w, r, &page.Lpa{
ID: "lpa-id",
Expand All @@ -201,7 +211,55 @@ func TestPostWitnessingAsCertificateProviderWhenIdentityConfirmed(t *testing.T)
assert.Equal(t, page.Paths.YouHaveSubmittedYourLpa.Format("lpa-id"), resp.Header.Get("Location"))
}

func TestPostWitnessingAsCertificateProviderWhenShareCodeSendErrors(t *testing.T) {
func TestPostWitnessingAsCertificateProviderWhenShareCodeSendToAttorneysErrors(t *testing.T) {
form := url.Values{
"witness-code": {"1234"},
}

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

lpa := &page.Lpa{
ID: "lpa-id",
DonorIdentityUserData: identity.UserData{OK: true, Provider: identity.OneLogin},
CertificateProviderCodes: page.WitnessCodes{{Code: "1234", Created: now}},
CertificateProvider: actor.CertificateProvider{FirstNames: "Fred"},
WitnessedByCertificateProviderAt: now,
SignedAt: now,
}

shareCodeSender := newMockShareCodeSender(t)
shareCodeSender.
On("SendAttorneys", r.Context(), testAppData, lpa).
Return(expectedError)

donorStore := newMockDonorStore(t)
donorStore.
On("Put", r.Context(), lpa).
Return(nil)

ctx := page.ContextWithSessionData(r.Context(), &page.SessionData{
SessionID: "session-id",
LpaID: "lpa-id",
})

certificateProviderStore := newMockCertificateProviderStore(t)
certificateProviderStore.
On("GetAny", ctx).
Return(nil, dynamo.NotFoundError{})

err := WitnessingAsCertificateProvider(nil, donorStore, shareCodeSender, func() time.Time { return now }, certificateProviderStore)(testAppData, w, r, &page.Lpa{
ID: "lpa-id",
DonorIdentityUserData: identity.UserData{OK: true, Provider: identity.OneLogin},
CertificateProviderCodes: page.WitnessCodes{{Code: "1234", Created: now}},
CertificateProvider: actor.CertificateProvider{FirstNames: "Fred"},
})
assert.Equal(t, expectedError, err)
}

func TestPostWitnessingAsCertificateProviderWhenShareCodeSendToCertificateProviderErrors(t *testing.T) {
form := url.Values{
"witness-code": {"1234"},
}
Expand Down

0 comments on commit 45e8b8d

Please sign in to comment.