/ clis / 1688 / download.test.js
download.test.js
 1  import { describe, expect, it } from 'vitest';
 2  import { __test__ } from './download.js';
 3  describe('1688 download helpers', () => {
 4      it('builds stable filenames for grouped assets', () => {
 5          const items = __test__.toDownloadItems('887904326744', {
 6              offer_id: '887904326744',
 7              title: '测试商品',
 8              item_url: 'https://detail.1688.com/offer/887904326744.html',
 9              main_images: ['https://img.example.com/a.jpg'],
10              sku_images: ['https://img.example.com/b.png'],
11              detail_images: ['https://img.example.com/c.webp'],
12              videos: ['https://video.example.com/d.mp4'],
13              other_images: [],
14              raw_assets: [],
15              source: [],
16              main_count: 1,
17              sku_count: 1,
18              detail_count: 1,
19              video_count: 1,
20              source_url: 'https://detail.1688.com/offer/887904326744.html',
21              fetched_at: new Date().toISOString(),
22              strategy: 'cookie',
23          });
24          expect(items.map((item) => item.filename)).toEqual([
25              '887904326744_main_01.jpg',
26              '887904326744_sku_01.png',
27              '887904326744_detail_01.webp',
28              '887904326744_video_01.mp4',
29          ]);
30      });
31  });