|
| 1 | +import { describe, expect, it } from 'vitest'; |
| 2 | +import { __test__ } from './item.js'; |
| 3 | + |
| 4 | +describe('1688 item normalization', () => { |
| 5 | + it('normalizes public item payload into contract fields', () => { |
| 6 | + const result = __test__.normalizeItemPayload({ |
| 7 | + href: 'https://detail.1688.com/offer/887904326744.html', |
| 8 | + title: '法式春季长袖开衫连衣裙女新款大码女装碎花吊带裙套装142077 - 阿里巴巴', |
| 9 | + bodyText: ` |
| 10 | + 青岛沁澜衣品服装有限公司 |
| 11 | + 入驻13年 |
| 12 | + 主营:大码女装 |
| 13 | + 店铺回头率 |
| 14 | + 87% |
| 15 | + 山东青岛 |
| 16 | + 3套起批 |
| 17 | + 已售1600+套 |
| 18 | + 支持定制logo |
| 19 | + `, |
| 20 | + offerTitle: '法式春季长袖开衫连衣裙女新款大码女装碎花吊带裙套装142077', |
| 21 | + offerId: 887904326744, |
| 22 | + seller: { |
| 23 | + companyName: '青岛沁澜衣品服装有限公司', |
| 24 | + memberId: 'b2b-1641351767', |
| 25 | + winportUrl: 'https://yinuoweierfushi.1688.com/page/index.html?spm=a1', |
| 26 | + }, |
| 27 | + trade: { |
| 28 | + beginAmount: 3, |
| 29 | + priceDisplay: '96.00-98.00', |
| 30 | + unit: '套', |
| 31 | + saleCount: 1655, |
| 32 | + offerIDatacenterSellInfo: { |
| 33 | + 面料名称: '莫代尔', |
| 34 | + 主面料成分: '莫代尔纤维', |
| 35 | + sellPointModel: '{"ignore":true}', |
| 36 | + }, |
| 37 | + offerPriceModel: { |
| 38 | + currentPrices: [ |
| 39 | + { beginAmount: 3, price: '98.00' }, |
| 40 | + { beginAmount: 50, price: '97.00' }, |
| 41 | + ], |
| 42 | + }, |
| 43 | + }, |
| 44 | + gallery: { |
| 45 | + mainImage: ['https://example.com/1.jpg'], |
| 46 | + offerImgList: ['https://example.com/2.jpg'], |
| 47 | + wlImageInfos: [{ fullPathImageURI: 'https://example.com/3.jpg' }], |
| 48 | + }, |
| 49 | + services: [ |
| 50 | + { serviceName: '延期必赔', agreeDeliveryHours: 360 }, |
| 51 | + { serviceName: '品质保障' }, |
| 52 | + ], |
| 53 | + }); |
| 54 | + |
| 55 | + expect(result.offer_id).toBe('887904326744'); |
| 56 | + expect(result.member_id).toBe('b2b-1641351767'); |
| 57 | + expect(result.shop_id).toBe('yinuoweierfushi'); |
| 58 | + expect(result.seller_url).toBe('https://yinuoweierfushi.1688.com'); |
| 59 | + expect(result.price_text).toBe('¥96.00-98.00'); |
| 60 | + expect(result.moq_text).toBe('3套起批'); |
| 61 | + expect(result.origin_place).toBe('山东青岛'); |
| 62 | + expect(result.delivery_days_text).toBe('360小时内发货'); |
| 63 | + expect(result.private_label_text).toBe('支持定制logo'); |
| 64 | + expect(result.visible_attributes).toEqual([ |
| 65 | + { key: '面料名称', value: '莫代尔' }, |
| 66 | + { key: '主面料成分', value: '莫代尔纤维' }, |
| 67 | + ]); |
| 68 | + }); |
| 69 | +}); |
0 commit comments