import assert from 'node:assert/strict';
import test from 'node:test';
import { createPlazaSeoService, seoInternals } from './plaza-seo.mjs';

test('normalizeUtm trims and caps length', () => {
  assert.equal(seoInternals.normalizeUtm('  plaza  '), 'plaza');
  assert.equal(seoInternals.normalizeUtm('x'.repeat(120)).length, 100);
});

test('normalizeEventType accepts landing and signup', () => {
  assert.equal(seoInternals.normalizeEventType('landing'), 'landing');
  assert.throws(
    () => seoInternals.normalizeEventType('click'),
    (error) => error.code === 'invalid_input',
  );
});

test('buildPostPublicUrl uses plaza path', () => {
  assert.equal(
    seoInternals.buildPostPublicUrl('abc-123', 'https://go.tkmind.cn'),
    'https://go.tkmind.cn/plaza/p/abc-123',
  );
});

test('pingBaidu skips when token missing', async () => {
  const service = createPlazaSeoService(null, { baiduToken: '' });
  const result = await service.pingBaidu(['https://go.tkmind.cn/plaza/p/1']);
  assert.equal(result.pushed, false);
});
