Skip to content

Commit

Permalink
Merge in hold pages
Browse files Browse the repository at this point in the history
  • Loading branch information
dgcohen committed Dec 12, 2024
2 parents e7cc403 + 8afc6fe commit a94fe3d
Show file tree
Hide file tree
Showing 12 changed files with 435 additions and 38 deletions.
7 changes: 6 additions & 1 deletion CHANGELOG
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,12 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## Unreleased
## Prerelease

### Added

- Added and integrated hold confirmation details fetcher function (SCC-3762)
- Added server-side auth redirect to hold confirmation page (SCC-3762)

### Updated

Expand Down
226 changes: 219 additions & 7 deletions __test__/pages/hold/confirmation.test.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,141 @@
import HoldConfirmationPage from "../../../pages/hold/confirmation/[id]"
import HoldConfirmationPage, {
getServerSideProps,
} from "../../../pages/hold/confirmation/[id]"
import { render, screen } from "../../../src/utils/testUtils"
import { bibWithItems } from "../../fixtures/bibFixtures"

import initializePatronTokenAuth, {
doRedirectBasedOnNyplAccountRedirects,
} from "../../../src/server/auth"

import { fetchBib } from "../../../src/server/api/bib"
import {
fetchHoldDetails,
fetchDeliveryLocations,
} from "../../../src/server/api/hold"

jest.mock("../../../src/server/auth")
jest.mock("../../../src/server/api/bib")
jest.mock("../../../src/server/sierraClient")
jest.mock("../../../src/server/api/hold")

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

const mockRes = {
setHeader: jest.fn(),
}
const id = "b15080796-i39333697"
const mockReq = {
headers: {
host: "local.nypl.org:8080",
},
url: `/hold/confirmation/${id}`,
cookies: {
nyplIdentityPatron: '{"access_token":123}',
},
}

describe("Hold Confirmation page", () => {
describe("Hold Confirmation page UI", () => {
describe("logout redirect handling", () => {
beforeEach(() => {
;(initializePatronTokenAuth as jest.Mock).mockResolvedValue({
isTokenValid: true,
errorCode: null,
decodedPatron: { sub: "123" },
})
;(fetchHoldDetails as jest.Mock).mockResolvedValue({
patronId: "123",
pickupLocation: "mal17",
status: 200,
})
;(fetchBib as jest.Mock).mockResolvedValue({
discoveryBibResult: bibWithItems.resource,
status: 200,
})
;(fetchDeliveryLocations as jest.Mock).mockResolvedValue({
eddRequestable: true,
status: 200,
})
})

it("redirects if cookie count is less than 3", async () => {
;(doRedirectBasedOnNyplAccountRedirects as jest.Mock).mockReturnValue(
true
)
;(initializePatronTokenAuth as jest.Mock).mockResolvedValue({
isTokenValid: false,
})

const responseWithZeroRedirects = await getServerSideProps({
params: { id },
req: mockReq,
res: mockRes,
query: {},
})
expect(responseWithZeroRedirects.redirect).toBeDefined()
const responseWithTwoRedirects = await getServerSideProps({
params: { id: "123-456" },
req: { ...mockReq, cookies: { nyplAccountRedirects: 2 } },
res: mockRes,
query: {},
})
expect(responseWithTwoRedirects.redirect).toBeDefined()
})
it("does not redirect if doRedirect method returns false", async () => {
;(doRedirectBasedOnNyplAccountRedirects as jest.Mock).mockReturnValue(
false
)
;(initializePatronTokenAuth as jest.Mock).mockResolvedValue({
decodedPatron: { sub: "123" },
isTokenValid: false,
})

const responseWithoutRedirect = await getServerSideProps({
params: { id },
req: mockReq,
res: mockRes,
query: {},
})
expect(responseWithoutRedirect.redirect).not.toBeDefined()
})
it("does not redirect if patron is authenticated", async () => {
const response = await getServerSideProps({
params: { id },
req: mockReq,
res: mockRes,
query: {},
})
expect(response.redirect).toBeUndefined()
})
it("updates the nyplAccountRedirectsCookie upon redirecting", async () => {
;(doRedirectBasedOnNyplAccountRedirects as jest.Mock).mockReturnValue(
true
)
;(initializePatronTokenAuth as jest.Mock).mockResolvedValue({
decodedPatron: { sub: "123" },
isTokenValid: false,
})
await getServerSideProps({
params: { id },
res: mockRes,
req: mockReq,
query: {},
})
expect(mockRes.setHeader.mock.calls[0]).toStrictEqual([
"Set-Cookie",
"nyplAccountRedirects=1; Max-Age=10; path=/; domain=.nypl.org;",
])
})
})

describe("On-site Confirmation page UI", () => {
beforeEach(() => {
render(<HoldConfirmationPage />)
render(
<HoldConfirmationPage
discoveryBibResult={bibWithItems.resource}
pickupLocationLabel="Schwarzman Building"
/>
)
})

it("renders an H2", () => {
Expand All @@ -13,14 +144,95 @@ describe("Hold Confirmation page", () => {
)
})

it("renders a success banner", () => {
it("renders a success banner with a link to the requested item's bib", () => {
expect(screen.getAllByRole("heading", { level: 2 })[1]).toHaveTextContent(
"Request successful"
)
expect(
screen.queryByText(
"You're all set! We have received your request for",
{
exact: false,
}
)
).toBeInTheDocument()

const bibLink = screen.getByText("Urban spaghetti.")
expect(bibLink).toHaveAttribute(
"href",
"/research/research-catalog/bib/b15080796"
)
})
it("renders an item details table with a pickup location for on-site holds", () => {
expect(screen.getByTestId("pickup-location")).toHaveTextContent(
"Schwarzman Building"
)
expect(screen.getByTestId("call-number")).toHaveTextContent(
"JFK 01-374 no. 4 (2001)"
)
expect(screen.getByTestId("barcode")).toHaveTextContent("33433130221975")
})
it("renders an on-site specific faq accordion", () => {
expect(screen.getByTestId("on-site-confirmation-faq")).toBeInTheDocument()
})
it("renders a back to search link", () => {
const searchLink = screen.getByText("Start a new search")
expect(searchLink).toHaveAttribute(
"href",
"/research/research-catalog/search"
)
})
})
describe("Electronic Delivery Confirmation page UI", () => {
beforeEach(() => {
render(
<HoldConfirmationPage
discoveryBibResult={bibWithItems.resource}
isEDD
/>
)
})

it("renders an H2", () => {
expect(screen.getAllByRole("heading", { level: 2 })[0]).toHaveTextContent(
"Request scan"
)
})

it("renders a success banner with a link to the requested item's bib", () => {
expect(screen.getAllByRole("heading", { level: 2 })[1]).toHaveTextContent(
"Request successful"
)
expect(
screen.queryByText(
"You're all set! We have received your scan request for",
{
exact: false,
}
)
).toBeInTheDocument()

const bibLink = screen.getByText("Urban spaghetti.")
expect(bibLink).toHaveAttribute(
"href",
"/research/research-catalog/bib/b15080796"
)
})
it("renders an item details table without a pickup location for EDD holds", () => {
expect(screen.queryByTestId("pickup-location")).not.toBeInTheDocument()
expect(screen.getByTestId("call-number")).toHaveTextContent(
"JFK 01-374 no. 4 (2001)"
)
expect(screen.getByTestId("barcode")).toHaveTextContent("33433130221975")
})
it("renders an edd-specific faq accordion", () => {
expect(screen.getByTestId("edd-confirmation-faq")).toBeInTheDocument()
})
it("renders a faq accordion", () => {
expect(screen.getByRole("heading", { level: 3 })).toHaveTextContent(
"Frequently asked questions"
it("renders a back to search link", () => {
const searchLink = screen.getByText("Start a new search")
expect(searchLink).toHaveAttribute(
"href",
"/research/research-catalog/search"
)
})
})
Expand Down
Loading

0 comments on commit a94fe3d

Please sign in to comment.