fix(core): parse Kijiji StandardListing records

This commit is contained in:
2026-04-28 21:57:10 -04:00
parent 2a5701aeb9
commit 11dce39428
2 changed files with 180 additions and 8 deletions

View File

@@ -149,6 +149,48 @@ describe("HTML Parsing Integration", () => {
expect(results[0]?.name).toBe("iPhone 13 Pro");
});
test("should parse current StandardListing search records", () => {
const mockHtml = `
<html>
<script id="__NEXT_DATA__" type="application/json">
${JSON.stringify({
props: {
pageProps: {
__APOLLO_STATE__: {
ROOT_QUERY: { test: "value" },
"StandardListing:123": {
__typename: "StandardListing",
url: "https://www.kijiji.ca/v-cell-phone/city-of-toronto/iphone-13/123",
title: "iPhone 13",
},
"StandardListing:456": {
__typename: "StandardListing",
url: "/v-cell-phone/city-of-toronto/iphone-14/456",
title: "iPhone 14",
},
},
},
},
})}
</script>
</html>
`;
const results = parseSearch(mockHtml, "https://www.kijiji.ca");
expect(results).toEqual([
{
name: "iPhone 13",
listingLink:
"https://www.kijiji.ca/v-cell-phone/city-of-toronto/iphone-13/123",
},
{
name: "iPhone 14",
listingLink:
"https://www.kijiji.ca/v-cell-phone/city-of-toronto/iphone-14/456",
},
]);
});
test("should return empty array for invalid HTML", () => {
const results = parseSearch(
"<html><body>Invalid</body></html>",
@@ -303,6 +345,118 @@ describe("HTML Parsing Integration", () => {
expect(result).toBeNull();
});
test("should parse current StandardListing detail records", async () => {
const mockHtml = `
<html>
<script id="__NEXT_DATA__" type="application/json">
${JSON.stringify({
props: {
pageProps: {
__APOLLO_STATE__: {
"StandardListing:123": {
__typename: "StandardListing",
url: "https://www.kijiji.ca/v-cell-phone/city-of-toronto/iphone-13/123",
title: "iPhone 13",
description: "Lightly used iPhone 13",
price: {
__typename: "AmountPrice",
amount: 45000,
currency: "CAD",
type: "FIXED",
},
type: "OFFER",
status: "ACTIVE",
activationDate: "2026-04-20T10:00:00.000Z",
metrics: { views: "12" },
location: {
id: 1700273,
name: "City of Toronto",
address: "Toronto, ON",
coordinates: {
latitude: 43.6532,
longitude: -79.3832,
},
},
imageUrls: ["https://media.kijiji.ca/api/v1/image1.jpg"],
categoryId: 760,
adSource: "ORGANIC",
flags: {
topAd: false,
priceDrop: false,
},
posterInfo: {
posterId: "user123",
rating: 4.5,
},
attributes: {
__typename: "StandardListingAttributes",
all: [
{
__typename: "ListingAttributeV2",
canonicalName: "forsaleby",
canonicalValues: ["ownr"],
},
{
__typename: "ListingAttributeV2",
canonicalName: "phonebrand",
canonicalValues: ["apple"],
},
],
},
},
},
},
},
})}
</script>
</html>
`;
const result = await parseDetailedListing(
mockHtml,
"https://www.kijiji.ca",
);
expect(result).toEqual({
url: "https://www.kijiji.ca/v-cell-phone/city-of-toronto/iphone-13/123",
title: "iPhone 13",
description: "Lightly used iPhone 13",
listingPrice: {
amountFormatted: "$450.00",
cents: 45000,
currency: "CAD",
},
listingType: "OFFER",
listingStatus: "ACTIVE",
creationDate: "2026-04-20T10:00:00.000Z",
endDate: undefined,
numberOfViews: 12,
address: "Toronto, ON",
images: ["https://media.kijiji.ca/api/v1/image1.jpg"],
categoryId: 760,
adSource: "ORGANIC",
flags: {
topAd: false,
priceDrop: false,
},
attributes: {
forsaleby: ["ownr"],
phonebrand: ["apple"],
},
location: {
id: 1700273,
name: "City of Toronto",
coordinates: {
latitude: 43.6532,
longitude: -79.3832,
},
},
sellerInfo: {
posterId: "user123",
rating: 4.5,
},
});
});
test("should handle missing optional fields", async () => {
const mockHtml = `
<html>