test(publisher): BIT-25574 add wp-categories unit tests for mappedCategoryId
ai-news-writer-ci / test (pull_request) Failing after 29s

Covers slug lookup, missing/null map, non-positive IDs, and case-folding.
This commit is contained in:
Xika committed 2026-06-18 16:22:35 +00:00
1 parent 3027361259
commit 547498ab41
1 file changed
+33
+33
View File
@@ -0,0 +1,33 @@
'use strict';
const assert = require('node:assert/strict');
const test = require('node:test');
const { mappedCategoryId } = require('./wp-categories');
test('mappedCategoryId returns id from exact slug match', () => {
const site = { category_map: { nacional: 1, internacional: 2 } };
assert.equal(mappedCategoryId(site, 'nacional'), 1);
assert.equal(mappedCategoryId(site, 'internacional'), 2);
});
test('mappedCategoryId returns null for missing slug', () => {
const site = { category_map: { nacional: 1 } };
assert.equal(mappedCategoryId(site, 'selecao'), null);
});
test('mappedCategoryId returns null when category_map is absent', () => {
assert.equal(mappedCategoryId({}, 'nacional'), null);
assert.equal(mappedCategoryId(null, 'nacional'), null);
});
test('mappedCategoryId rejects non-positive values', () => {
const site = { category_map: { bad: 0, alsobad: -5, fine: 3 } };
assert.equal(mappedCategoryId(site, 'bad'), null);
assert.equal(mappedCategoryId(site, 'alsobad'), null);
assert.equal(mappedCategoryId(site, 'fine'), 3);
});
test('mappedCategoryId falls back to lowercase key lookup', () => {
const site = { category_map: { selecao: 3 } };
assert.equal(mappedCategoryId(site, 'SELECAO'), 3);
});