Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SCC-4407 - EDD Form Prepopulate Patron Email #422

Open
wants to merge 5 commits into
base: hold-pages
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Added fetchPatronEligibility server function that requests a patron's hold request eligibility status from Discovery API (SCC-3762)
- Added patron ineligibility error messaging to HoldRequestErrorBanner component (SCC-3762)
- Added eligibility checks to EDD and on-site request hold pages and API routes (SCC-3762)
- Added email address field prepopulation on EDD Request form (SCC-4407)

### Updated

Expand Down
21 changes: 21 additions & 0 deletions __test__/pages/hold/eddRequestPage.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import userEvent from "@testing-library/user-event"
import EDDRequestPage, {
getServerSideProps,
} from "../../../pages/hold/request/[id]/edd"
import { getPatronData } from "../../../pages/api/account/[id]"

import initializePatronTokenAuth, {
doRedirectBasedOnNyplAccountRedirects,
Expand All @@ -27,6 +28,7 @@ jest.mock("../../../src/server/auth")
jest.mock("../../../src/server/api/bib")
jest.mock("../../../src/server/sierraClient")
jest.mock("../../../src/server/api/hold")
jest.mock("../../../pages/api/account/[id]")

jest.mock("next/router", () => jest.requireActual("next-router-mock"))

Expand Down Expand Up @@ -76,6 +78,9 @@ describe("EDD Request page", () => {
discoveryBibResult: bibWithItems.resource,
status: 200,
})
;(getPatronData as jest.Mock).mockResolvedValue({
patron: { emails: ["[email protected]"] },
})
;(fetchDeliveryLocations as jest.Mock).mockResolvedValue({
eddRequestable: true,
status: 200,
Expand Down Expand Up @@ -205,6 +210,22 @@ describe("EDD Request page", () => {
expect(screen.getByTestId("edd-request-form")).toBeInTheDocument()
})
})
describe("EDD Request prepopulated form fields", () => {
beforeEach(() => {
render(
<EDDRequestPage
discoveryBibResult={bibWithItems.resource}
discoveryItemResult={bibWithItems.resource.items[2]}
patronId="123"
patronEmail="[email protected]"
isAuthenticated={true}
/>
)
})
it("prepopulates the email field with the patron's email address if present", () => {
expect(screen.getByDisplayValue("[email protected]")).toBeInTheDocument()
})
})
describe("EDD Request form validation", () => {
beforeEach(async () => {
render(
Expand Down
12 changes: 10 additions & 2 deletions pages/hold/request/[id]/edd.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import { SITE_NAME, BASE_URL, PATHS } from "../../../../src/config/constants"
import useLoading from "../../../../src/hooks/useLoading"

import { fetchBib } from "../../../../src/server/api/bib"
import { getPatronData } from "../../../../pages/api/account/[id]"
import {
fetchDeliveryLocations,
fetchPatronEligibility,
Expand Down Expand Up @@ -43,6 +44,7 @@ interface EDDRequestPropsType {
discoveryBibResult: DiscoveryBibResult
discoveryItemResult: DiscoveryItemResult
patronId: string
patronEmail?: string
isAuthenticated?: boolean
errorStatus?: HoldErrorStatus
patronEligibilityStatus?: PatronEligibilityStatus
Expand All @@ -55,12 +57,12 @@ export default function EDDRequestPage({
discoveryBibResult,
discoveryItemResult,
patronId,
patronEmail,
isAuthenticated,
errorStatus: defaultErrorStatus,
patronEligibilityStatus: defaultEligibilityStatus,
}: EDDRequestPropsType) {
const metadataTitle = `Electronic Delivery Request | ${SITE_NAME}`

const bib = new Bib(discoveryBibResult)
const item = new Item(discoveryItemResult, bib)

Expand All @@ -71,8 +73,9 @@ export default function EDDRequestPage({
defaultEligibilityStatus
)

const [eddFormState, setEddFormState] = useState({
const [eddFormState, setEddFormState] = useState<EDDRequestParams>({
...initialEDDFormState,
emailAddress: patronEmail,
patronId,
source: item.source,
})
Expand Down Expand Up @@ -250,6 +253,10 @@ export async function getServerSideProps({ params, req, res }) {

const patronEligibilityStatus = await fetchPatronEligibility(patronId)

// fetch patron's email to pre-populate the edd form if available
const patronData = await getPatronData(patronId)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is fetching a lot of patron data, though it doesn't appear to be taking a very long time. I still think that instead of using getPatronData, which builds out a whole my account dataset including checkouts and holds and fines, maybe you can use the MyAccount model's getPatron

const patronEmail = patronData?.patron?.emails?.[0]

const locationOrEligibilityFetchFailed =
locationStatus !== 200 ||
![200, 401].includes(patronEligibilityStatus?.status)
Expand All @@ -259,6 +266,7 @@ export async function getServerSideProps({ params, req, res }) {
discoveryBibResult,
discoveryItemResult,
patronId,
patronEmail,
isAuthenticated,
patronEligibilityStatus,
errorStatus: locationOrEligibilityFetchFailed
Expand Down
Loading