Spaces:
Runtime error
Runtime error
refactor: update server to use ESM, refine product card availability UI, and improve test assertions.
eaf6f0e | import { describe, it, expect } from 'vitest'; | |
| import { | |
| validateAmazonAffiliateUrl, | |
| validateEbayAffiliateUrl, | |
| validateEtsyAffiliateUrl, | |
| validateAffiliateUrl, | |
| } from '../affiliate-url-validator'; | |
| describe('Affiliate URL Validator', () => { | |
| describe('validateAmazonAffiliateUrl', () => { | |
| it('should validate correct Amazon affiliate URL', () => { | |
| const url = 'https://www.amazon.com/dp/B08N5WRWNW?tag=vaultai-20'; | |
| const result = validateAmazonAffiliateUrl(url); | |
| expect(result.isValid).toBe(true); | |
| expect(result.error).toBeUndefined(); | |
| }); | |
| it('should reject Amazon URL without tag parameter', () => { | |
| const url = 'https://www.amazon.com/dp/B08N5WRWNW'; | |
| const result = validateAmazonAffiliateUrl(url); | |
| expect(result.isValid).toBe(false); | |
| expect(result.error).toBe('Missing affiliate tag parameter'); | |
| }); | |
| it('should reject Amazon URL with invalid tag format', () => { | |
| const url = 'https://www.amazon.com/dp/B08N5WRWNW?tag=invalid-tag'; | |
| const result = validateAmazonAffiliateUrl(url); | |
| expect(result.isValid).toBe(false); | |
| expect(result.error).toBe('Invalid Amazon tag format (must end with -20)'); | |
| }); | |
| it('should reject non-Amazon URLs', () => { | |
| const url = 'https://www.ebay.com/itm/123456789'; | |
| const result = validateAmazonAffiliateUrl(url); | |
| expect(result.isValid).toBe(false); | |
| expect(result.error).toBe('Not an Amazon URL'); | |
| }); | |
| it('should reject invalid URL format', () => { | |
| const url = 'not-a-url'; | |
| const result = validateAmazonAffiliateUrl(url); | |
| expect(result.isValid).toBe(false); | |
| expect(result.error).toBe('Invalid URL format'); | |
| }); | |
| }); | |
| describe('validateEbayAffiliateUrl', () => { | |
| it('should validate correct eBay affiliate URL', () => { | |
| const url = | |
| 'https://rover.ebay.com/rover/1/711-53200-19255-0/1?mpre=https://www.ebay.com/itm/123456789&campid=5338123456'; | |
| const result = validateEbayAffiliateUrl(url); | |
| expect(result.isValid).toBe(true); | |
| expect(result.error).toBeUndefined(); | |
| }); | |
| it('should reject eBay URL without campid parameter', () => { | |
| const url = | |
| 'https://rover.ebay.com/rover/1/711-53200-19255-0/1?mpre=https://www.ebay.com/itm/123456789'; | |
| const result = validateEbayAffiliateUrl(url); | |
| expect(result.isValid).toBe(false); | |
| expect(result.error).toBe('Missing campaign ID parameter'); | |
| }); | |
| it('should reject eBay URL with non-numeric campid', () => { | |
| const url = | |
| 'https://rover.ebay.com/rover/1/711-53200-19255-0/1?mpre=https://www.ebay.com/itm/123456789&campid=invalid'; | |
| const result = validateEbayAffiliateUrl(url); | |
| expect(result.isValid).toBe(false); | |
| expect(result.error).toBe('Invalid campaign ID format'); | |
| }); | |
| it('should reject non-eBay rover URLs', () => { | |
| const url = 'https://www.ebay.com/itm/123456789'; | |
| const result = validateEbayAffiliateUrl(url); | |
| expect(result.isValid).toBe(false); | |
| expect(result.error).toBe('Not an eBay Partner Network URL'); | |
| }); | |
| it('should reject invalid URL format', () => { | |
| const url = 'not-a-url'; | |
| const result = validateEbayAffiliateUrl(url); | |
| expect(result.isValid).toBe(false); | |
| expect(result.error).toBe('Invalid URL format'); | |
| }); | |
| }); | |
| describe('validateEtsyAffiliateUrl', () => { | |
| it('should validate correct Etsy affiliate URL', () => { | |
| const url = 'https://www.etsy.com/listing/123456789?ref=vaultai_affiliate'; | |
| const result = validateEtsyAffiliateUrl(url); | |
| expect(result.isValid).toBe(true); | |
| expect(result.error).toBeUndefined(); | |
| }); | |
| it('should reject Etsy URL without ref parameter', () => { | |
| const url = 'https://www.etsy.com/listing/123456789'; | |
| const result = validateEtsyAffiliateUrl(url); | |
| expect(result.isValid).toBe(false); | |
| expect(result.error).toBe('Missing affiliate ref parameter'); | |
| }); | |
| it('should reject non-Etsy URLs', () => { | |
| const url = 'https://www.amazon.com/dp/B08N5WRWNW'; | |
| const result = validateEtsyAffiliateUrl(url); | |
| expect(result.isValid).toBe(false); | |
| expect(result.error).toBe('Not an Etsy URL'); | |
| }); | |
| it('should reject invalid URL format', () => { | |
| const url = 'not-a-url'; | |
| const result = validateEtsyAffiliateUrl(url); | |
| expect(result.isValid).toBe(false); | |
| expect(result.error).toBe('Invalid URL format'); | |
| }); | |
| }); | |
| describe('validateAffiliateUrl', () => { | |
| it('should validate Amazon URLs correctly', () => { | |
| const url = 'https://www.amazon.com/dp/B08N5WRWNW?tag=vaultai-20'; | |
| const result = validateAffiliateUrl(url, 'amazon'); | |
| expect(result.isValid).toBe(true); | |
| }); | |
| it('should validate eBay URLs correctly', () => { | |
| const url = | |
| 'https://rover.ebay.com/rover/1/711-53200-19255-0/1?mpre=https://www.ebay.com/itm/123456789&campid=5338123456'; | |
| const result = validateAffiliateUrl(url, 'ebay'); | |
| expect(result.isValid).toBe(true); | |
| }); | |
| it('should validate Etsy URLs correctly', () => { | |
| const url = 'https://www.etsy.com/listing/123456789?ref=vaultai_affiliate'; | |
| const result = validateAffiliateUrl(url, 'etsy'); | |
| expect(result.isValid).toBe(true); | |
| }); | |
| it('should reject invalid marketplace type', () => { | |
| const url = 'https://www.amazon.com/dp/B08N5WRWNW?tag=vaultai-20'; | |
| const result = validateAffiliateUrl(url, 'invalid' as unknown as 'amazon'); | |
| expect(result.isValid).toBe(false); | |
| expect(result.error).toBe('Unknown marketplace type'); | |
| }); | |
| }); | |
| }); | |