import { test } from 'node:test'; import assert from 'node:assert/strict'; import { nextAttribution, attributionSuffix, ATTR_TTL_MS } from '../src/lib/attribution.ts'; const NOW = 1_800_000_000_000; const H = 'infinith.webforai.kr'; test('utm 기록과 꼬리', () => { const a = nextAttribution(null, '?utm_source=naver_blog&utm_medium=organic&utm_campaign=2611_h', '', H, H + '/', NOW); assert.equal(attributionSuffix(a, NOW), ' | utm:naver_blog/organic/2611_h | land:infinith.webforai.kr/'); }); test('webforai.kr 에서 넘어온 것은 같은 사이트', () => { assert.equal(nextAttribution(null, '', 'https://webforai.kr/', H, H + '/', NOW), null); }); test('외부 유입은 살아 있는 utm 을 덮지 않고, 없으면 ref', () => { const u = nextAttribution(null, '?utm_source=facebook', '', H, H + '/', NOW); assert.equal(nextAttribution(u, '', 'https://blog.naver.com/x', H, H + '/', NOW + 1), null); const r = nextAttribution(null, '', 'https://blog.naver.com/x', H, H + '/', NOW); assert.equal(attributionSuffix(r, NOW), ' | ref:blog.naver.com | land:infinith.webforai.kr/'); assert.equal(attributionSuffix(r, NOW + ATTR_TTL_MS), ''); });