/ clis / amazon / offer.test.js
offer.test.js
 1  import { describe, expect, it } from 'vitest';
 2  import { __test__ } from './offer.js';
 3  describe('amazon offer normalization', () => {
 4      it('extracts sold-by and fulfillment facts from product offer text', () => {
 5          const result = __test__.normalizeOfferPayload({
 6              href: 'https://www.amazon.com/dp/B0FJS72893',
 7              price_text: '$15.99',
 8              merchant_info: '',
 9              sold_by: 'KUATUDIRECT',
10              ships_from_text: 'Ships from Amazon',
11              offer_link: null,
12              review_url: 'https://www.amazon.com/dp/B0FJS72893#customerReviews',
13              qa_url: null,
14          });
15          expect(result.asin).toBe('B0FJS72893');
16          expect(result.sold_by).toBe('KUATUDIRECT');
17          expect(result.ships_from).toBe('Amazon');
18          expect(result.is_amazon_sold).toBe(false);
19          expect(result.is_amazon_fulfilled).toBe(true);
20      });
21      it('parses merchant info fallback text', () => {
22          expect(__test__.extractSoldBy('Sold by Example Seller and Fulfilled by Amazon.')).toBe('Example Seller');
23          expect(__test__.extractShipsFrom('Ships from Amazon')).toBe('Amazon');
24      });
25      it('detects delivery-location blocking in the buy box text', () => {
26          expect(__test__.isDeliveryLocationBlocked('This item cannot be shipped to your selected delivery location. Similar items shipping to Hong Kong')).toBe(true);
27          expect(__test__.isDeliveryLocationBlocked('Ships from Amazon')).toBe(false);
28      });
29  });