| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546 |
- import assert from 'node:assert/strict';
- import test from 'node:test';
- import {
- makeProductKey,
- makeRelationKey,
- makeReviewKey,
- makeSyncIdempotencyKey,
- } from '../src/modules/domestic-voc/domain/identity.js';
- test('domestic product and relation keys are stable', () => {
- assert.equal(makeProductKey('JD', ' 11266507445 '), 'jd:11266507445');
- assert.equal(makeRelationKey('JD', 'own-1', 'competitor-2'), 'jd:own-1:competitor-2');
- });
- test('review key uses source id when available and a stable hash otherwise', () => {
- const sourceKey = makeReviewKey({
- platform: 'jd',
- productId: '1',
- reviewId: 'review-10',
- content: 'content',
- });
- assert.equal(sourceKey, 'jd:1:review-10');
- const input = { platform: 'jd', productId: '1', content: 'same content', reviewDate: '2026-07-23' };
- assert.equal(makeReviewKey(input), makeReviewKey(input));
- assert.match(makeReviewKey(input), /^jd:1:sha256:[a-f0-9]{64}$/);
- });
- test('sync idempotency ignores input ordering', () => {
- const first = makeSyncIdempotencyKey({
- workspaceId: 'demashi',
- platform: 'jd',
- productIds: ['2', '1'],
- scopes: ['reviews', 'product'],
- bucket: '2026-07-23',
- });
- const second = makeSyncIdempotencyKey({
- workspaceId: 'demashi',
- platform: 'JD',
- productIds: ['1', '2', '1'],
- scopes: ['product', 'reviews'],
- bucket: '2026-07-23',
- });
- assert.equal(first, second);
- });
|