Skip to content
Merged
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
19 changes: 19 additions & 0 deletions cinemas/dugdaleartscentre.co.uk/tests/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,4 +44,23 @@ describe(attributes.name, () => {
},
isRecording ? 240_000 : undefined,
);

it("transforms the venue's explicit empty state to no movies", async () => {
const movieListPage = `
<div class="whats-on-grid" id="whats_on_grid">
<div class="empty">
<h2>We don’t currently have any scheduled events that match your selection.</h2>
</div>
</div>`;

expect(await transform({ movieListPage, moviePages: {} }, {})).toEqual([]);
});

it("throws when no movies are found without the empty state", async () => {
const movieListPage = `<div class="whats-on-grid" id="whats_on_grid"></div>`;

await expect(
transform({ movieListPage, moviePages: {} }, {}),
).rejects.toThrow("No movies found - the page structure may have changed");
});
});
11 changes: 9 additions & 2 deletions cinemas/dugdaleartscentre.co.uk/transform.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ const getMatchingDescription = ($description) => {
return $clone.text().trim();
};

async function transform({ moviePages }, sourcedEvents) {
async function transform({ movieListPage, moviePages }, sourcedEvents) {
const movies = [];

for (const [moviePageUrl, { moviePage, booking, eventId }] of Object.entries(
Expand Down Expand Up @@ -87,7 +87,14 @@ async function transform({ moviePages }, sourcedEvents) {
}

if (movies.length === 0) {
throw new Error("No movies found - the page structure may have changed");
// When the venue has no films scheduled, the listing grid holds an
// explicit empty state ("We don't currently have any scheduled events
// that match your selection") instead of events. Without that marker, no
// movies means our parsing has broken.
const $ = cheerio.load(movieListPage);
if ($(".whats-on-grid .empty").length === 0) {
throw new Error("No movies found - the page structure may have changed");
}
}

const listOfSourcedEvents = Object.values(sourcedEvents).flatMap(
Expand Down
Loading