| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869 |
- import assert from 'node:assert/strict';
- import test from 'node:test';
- import type { Queryable } from '../src/db/types.js';
- import { SnapshotService } from '../src/modules/domestic-voc/services/snapshot.service.js';
- test('snapshot returns the frontend DomesticDataset contract for an empty workspace', async () => {
- const database = {
- async query(text: string) {
- if (text.includes('FROM voc.workspace')) {
- return { rows: [{ id: '1', public_id: 'demashi', case_name: 'Demashi' }], rowCount: 1 };
- }
- return { rows: [], rowCount: 0 };
- },
- } as unknown as Queryable;
- const service = new SnapshotService(database, () => new Date('2026-07-23T00:00:00.000Z'));
- const snapshot = await service.getSnapshot('demashi', 'jd');
- assert.ok(snapshot);
- assert.equal(snapshot.schemaVersion, 1);
- assert.equal(snapshot.caseName, 'Demashi');
- assert.equal(snapshot.platform, 'jd');
- assert.deepEqual(snapshot.products, []);
- assert.deepEqual(snapshot.reviews, []);
- assert.deepEqual(snapshot.dailyTotals, []);
- assert.deepEqual(snapshot.source.dateRange, { start: '', end: '' });
- assert.equal(snapshot.summary.reviewCount, 0);
- });
- test('snapshot exposes relation groups without leaking relation stub products', async () => {
- const database = {
- async query(text: string) {
- if (text.includes('FROM voc.workspace')) {
- return { rows: [{ id: '1', public_id: 'demashi', case_name: 'Demashi' }], rowCount: 1 };
- }
- if (text.includes('FROM voc.product_relation')) {
- return {
- rows: [{
- relation_key: 'jd:own-1:competitor-1',
- own_internal_id: '10',
- own_product_id: 'own-1',
- own_product_key: 'jd:own-1',
- competitor_internal_id: '11',
- competitor_product_id: 'competitor-1',
- competitor_product_key: 'jd:competitor-1',
- competitor_brand: 'Competitor',
- own_model: 'DM-1',
- own_category_1: '',
- own_category_2: '',
- own_category_3: 'Kitchen',
- category: 'Kitchen',
- }],
- rowCount: 1,
- };
- }
- return { rows: [], rowCount: 0 };
- },
- } as unknown as Queryable;
- const service = new SnapshotService(database);
- const snapshot = await service.getSnapshot('demashi', 'jd');
- assert.ok(snapshot);
- assert.deepEqual(snapshot.products, []);
- assert.equal(snapshot.relations.length, 1);
- assert.equal(snapshot.mappingGroups.length, 1);
- assert.equal(snapshot.mappingGroups[0]?.model, 'DM-1');
- assert.equal(snapshot.summary.uniqueCompetitorProducts, 1);
- });
|