mirror of
https://github.com/primedigitaltech/azon_seeker.git
synced 2026-10-05 15:22:59 +08:00
82 lines
2.6 KiB
TypeScript
82 lines
2.6 KiB
TypeScript
import {
|
|
extractAmazonDetailAsin,
|
|
hasReachedAmazonDetailPage,
|
|
hasReachedAmazonNavigationTarget,
|
|
} from '../src/page-worker/page-navigation';
|
|
|
|
const assert = (condition: boolean, message: string) => {
|
|
if (!condition) throw new Error(message);
|
|
};
|
|
|
|
assert(
|
|
!hasReachedAmazonNavigationTarget(
|
|
'https://www.amazon.com/product-reviews/B08XM6S6ZL?reviewerType=all_reviews',
|
|
'https://www.amazon.com/product-reviews/B08XM6S6ZL?reviewerType=all_reviews&filterByStar=one_star',
|
|
),
|
|
'An unfiltered completed page must not satisfy a star-filter navigation.',
|
|
);
|
|
|
|
assert(
|
|
hasReachedAmazonNavigationTarget(
|
|
'https://www.amazon.com/product-reviews/B08XM6S6ZL/ref=cm_cr_arp_d_viewopt_sr?filterByStar=one_star&pageNumber=2',
|
|
'https://www.amazon.com/product-reviews/B08XM6S6ZL/ref=cm_cr_arp_d_paging_btm_next_2?filterByStar=one_star&pageNumber=2',
|
|
),
|
|
'Tracking ref rewrites must not prevent matching the requested review page.',
|
|
);
|
|
|
|
assert(
|
|
!hasReachedAmazonNavigationTarget(
|
|
'https://www.amazon.com/product-reviews/B08XM6S6ZL?filterByStar=one_star&pageNumber=1',
|
|
'https://www.amazon.com/product-reviews/B08XM6S6ZL?filterByStar=one_star&pageNumber=2',
|
|
),
|
|
'A previous review page must not satisfy the next-page navigation.',
|
|
);
|
|
|
|
assert(
|
|
hasReachedAmazonNavigationTarget(
|
|
'https://www.amazon.com/s?k=security+camera&page=17&ref=sr_pg_17',
|
|
'https://www.amazon.com/s?ref=sr_pg_17&page=17&k=security+camera',
|
|
),
|
|
'Search navigation should tolerate query ordering differences.',
|
|
);
|
|
|
|
assert(
|
|
hasReachedAmazonNavigationTarget(
|
|
'https://www.amazon.com/Product-Name/dp/B0DMNDL5NH/ref=sr_1_1',
|
|
'https://www.amazon.com/dp/B0DMNDL5NH',
|
|
),
|
|
'A canonical product slug must still match the requested detail ASIN.',
|
|
);
|
|
|
|
assert(
|
|
!hasReachedAmazonNavigationTarget(
|
|
'https://www.amazon.com/Product-Name/dp/B0DMNDL5NH',
|
|
'https://www.amazon.com/dp/B0BKPNRLC8',
|
|
),
|
|
'The previous detail ASIN must not satisfy the next-ASIN navigation.',
|
|
);
|
|
|
|
assert(
|
|
hasReachedAmazonDetailPage(
|
|
'https://www.amazon.com/Product-Name/dp/B0CCXB29LF?th=1',
|
|
'https://www.amazon.com/dp/B0D2MC2865',
|
|
),
|
|
'A canonical Amazon detail redirect must be accepted as a loaded detail page.',
|
|
);
|
|
|
|
assert(
|
|
!hasReachedAmazonDetailPage(
|
|
'https://www.amazon.com/',
|
|
'https://www.amazon.com/dp/B0D2MC2865',
|
|
),
|
|
'The Amazon home page must not be accepted as a detail redirect.',
|
|
);
|
|
|
|
assert(
|
|
extractAmazonDetailAsin('https://www.amazon.com/Product-Name/dp/B0CCXB29LF?th=1') ===
|
|
'B0CCXB29LF',
|
|
'The resolved ASIN must be extracted from canonical detail URLs.',
|
|
);
|
|
|
|
console.log('Amazon page navigation tests passed.');
|