games_app/backend/dist-test-faq/tests/marketingService.test.js

180 lines
9.6 KiB
JavaScript

"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const node_test_1 = require("node:test");
const strict_1 = __importDefault(require("node:assert/strict"));
const marketingRepository_1 = require("../repositories/marketingRepository");
const marketingService_1 = require("../services/marketingService");
const defaultSettings = {
enabled: true,
realActiveThreshold: 200,
displayActiveTarget: 250,
displayActiveSpread: 40,
};
const personas = [
{ public_id: '7a***k2' },
{ public_id: '9c***m1' },
{ public_id: '3f***p8' },
{ public_id: 'b2***q4' },
{ public_id: 'e8***t6' },
{ public_id: '1d***w9' },
{ public_id: '5h***n3' },
{ public_id: 'c4***r7' },
{ public_id: '8j***v5' },
{ public_id: '2m***x0' },
{ public_id: '6p***y1' },
{ public_id: '0s***z8' },
];
(0, node_test_1.describe)('marketingService helpers', () => {
(0, node_test_1.test)('daily stats include main bonus and test stake kinds', () => {
strict_1.default.deepEqual([...marketingRepository_1.MARKETING_STAKE_KINDS], ['main', 'bonus', 'test']);
});
(0, node_test_1.test)('utcDayBounds uses UTC midnight', () => {
const { dayStart, dayEnd, day } = (0, marketingRepository_1.utcDayBounds)(new Date('2026-10-17T15:30:00.000Z'));
strict_1.default.equal(day, '2026-10-17');
strict_1.default.equal(dayStart.toISOString(), '2026-10-17T00:00:00.000Z');
strict_1.default.equal(dayEnd.toISOString(), '2026-10-18T00:00:00.000Z');
});
(0, node_test_1.test)('maskPublicId anonymizes uuids', () => {
const masked = (0, marketingService_1.maskPublicId)('abcdef12-3456-7890-abcd-ef1234567890');
strict_1.default.match(masked, /^[a-z0-9]{2}\*\*\*[a-z0-9]{2}$/i);
strict_1.default.equal((0, marketingService_1.maskPublicId)('ab'), 'ab***');
});
(0, node_test_1.test)('formatAmountRaw converts micro-units', () => {
strict_1.default.equal((0, marketingService_1.formatAmountRaw)('1000000'), '1.00');
strict_1.default.equal((0, marketingService_1.formatAmountRaw)('50000000'), '50.00');
});
(0, node_test_1.test)('formatAmountRaw keeps decimals for real withdrawals', () => {
strict_1.default.equal((0, marketingService_1.formatAmountRaw)('3200000'), '3.20');
strict_1.default.equal((0, marketingService_1.formatAmountRaw)('120000000'), '120.00');
});
(0, node_test_1.test)('synthetic withdrawals accept decimal amounts', () => {
const items = (0, marketingService_1.buildSyntheticWithdrawalsFromPersonas)(personas, 3, [3.2, 20.5, 100], 0);
strict_1.default.equal(items.length, 3);
strict_1.default.ok(items.some((i) => i.amountLabel.includes('.')));
});
(0, node_test_1.test)('blendAndRotateFeedItems mixes real and synthetic without sticky real-first', () => {
const real = [
{ id: 'r1', publicId: 'aa***11' },
{ id: 'r2', publicId: 'bb***22' },
];
const synthetic = [
{ id: 's1', publicId: 'cc***33' },
{ id: 's2', publicId: 'dd***44' },
{ id: 's3', publicId: 'ee***55' },
];
// slotIndex = floor(now/10_000); pick times that shift start by 1 in a pool of 5.
const a = (0, marketingService_1.blendAndRotateFeedItems)(real, synthetic, 4, 0);
const b = (0, marketingService_1.blendAndRotateFeedItems)(real, synthetic, 4, 10000);
strict_1.default.equal(a.length, 4);
strict_1.default.equal(b.length, 4);
strict_1.default.deepEqual(a.map((x) => x.id), ['r1', 'r2', 's1', 's2']);
strict_1.default.deepEqual(b.map((x) => x.id), ['r2', 's1', 's2', 's3']);
});
(0, node_test_1.test)('mergeFeedItems keeps real first then pads synthetic', () => {
const real = [
{ id: 'r1', publicId: 'aa***11' },
{ id: 'r2', publicId: 'bb***22' },
];
const synthetic = [
{ id: 's1', publicId: 'cc***33' },
{ id: 's2', publicId: 'dd***44' },
{ id: 's3', publicId: 'ee***55' },
];
const merged = (0, marketingService_1.mergeFeedItems)(real, synthetic, 4);
strict_1.default.deepEqual(merged.map((x) => x.id), ['r1', 'r2', 's1', 's2']);
});
(0, node_test_1.test)('shouldUseSynthetic: 50 and 199 use fictifs when enabled', () => {
strict_1.default.equal((0, marketingService_1.shouldUseSynthetic)(50, defaultSettings), true);
strict_1.default.equal((0, marketingService_1.shouldUseSynthetic)(199, defaultSettings), true);
});
(0, node_test_1.test)('shouldUseSynthetic: 200 and above use real only', () => {
strict_1.default.equal((0, marketingService_1.shouldUseSynthetic)(200, defaultSettings), false);
strict_1.default.equal((0, marketingService_1.shouldUseSynthetic)(250, defaultSettings), false);
});
(0, node_test_1.test)('shouldUseSynthetic: disabled never uses fictifs', () => {
const disabled = { ...defaultSettings, enabled: false };
strict_1.default.equal((0, marketingService_1.shouldUseSynthetic)(50, disabled), false);
strict_1.default.equal((0, marketingService_1.shouldUseSynthetic)(199, disabled), false);
});
(0, node_test_1.test)('shouldUseSynthetic respects custom threshold', () => {
const low = { ...defaultSettings, realActiveThreshold: 100 };
strict_1.default.equal((0, marketingService_1.shouldUseSynthetic)(50, low), true);
strict_1.default.equal((0, marketingService_1.shouldUseSynthetic)(100, low), false);
});
(0, node_test_1.test)('computeActivePlayersCount varies in band below display target', () => {
const a = (0, marketingService_1.computeActivePlayersCount)(50, defaultSettings, 1700000000000);
const b = (0, marketingService_1.computeActivePlayersCount)(50, defaultSettings, 1700000050000);
strict_1.default.ok(a >= 210 && a <= 250);
strict_1.default.ok(b >= 210 && b <= 250);
strict_1.default.notEqual(a, b);
});
(0, node_test_1.test)('computeActivePlayersCount returns real when at/above threshold or disabled', () => {
strict_1.default.equal((0, marketingService_1.computeActivePlayersCount)(200, defaultSettings), 200);
strict_1.default.equal((0, marketingService_1.computeActivePlayersCount)(50, { ...defaultSettings, enabled: false }), 50);
});
(0, node_test_1.test)('clearMarketingCache is callable after settings-style changes', () => {
(0, marketingService_1.clearMarketingCache)();
strict_1.default.equal((0, marketingService_1.shouldUseSynthetic)(50, { ...defaultSettings, enabled: false }), false);
strict_1.default.equal((0, marketingService_1.shouldUseSynthetic)(50, { ...defaultSettings, realActiveThreshold: 40 }), false);
const n = (0, marketingService_1.computeActivePlayersCount)(10, {
...defaultSettings,
displayActiveTarget: 80,
displayActiveSpread: 0,
});
strict_1.default.equal(n, 80);
});
(0, node_test_1.test)('synthetic activity is Playing-only with unique handles from personas', () => {
const items = (0, marketingService_1.buildSyntheticActivityFromPersonas)(personas, 12, 1700000000000);
strict_1.default.equal(items.length, 12);
strict_1.default.ok(items.every((i) => i.synthetic));
strict_1.default.ok(items.every((i) => i.statusLabel === 'Playing'));
strict_1.default.ok(items.every((i) => i.kind === 'bet'));
strict_1.default.equal(new Set(items.map((i) => i.publicId)).size, items.length);
});
(0, node_test_1.test)('synthetic withdrawals pad feed from personas with configurable amounts', () => {
const amounts = [20, 50, 100];
const items = (0, marketingService_1.buildSyntheticWithdrawalsFromPersonas)(personas, 6, amounts, 1700000000000);
strict_1.default.equal(items.length, 6);
strict_1.default.ok(items.every((i) => i.statusLabel === 'Completed'));
strict_1.default.ok(items.every((i) => amounts.includes(Number(i.amountLabel))));
});
(0, node_test_1.test)('synthetic withdrawals respect zero plafond and empty amounts', () => {
strict_1.default.deepEqual((0, marketingService_1.buildSyntheticWithdrawalsFromPersonas)(personas, 0, [20, 50], 1700000000000), []);
strict_1.default.deepEqual((0, marketingService_1.buildSyntheticWithdrawalsFromPersonas)(personas, 5, [], 1700000000000), []);
});
(0, node_test_1.test)('merge with empty real still fills from synthetic', () => {
const synthetic = (0, marketingService_1.buildSyntheticActivityFromPersonas)(personas, 12, 1700000000000);
const merged = (0, marketingService_1.mergeFeedItems)([], synthetic, 12);
strict_1.default.equal(merged.length, 12);
});
(0, node_test_1.test)('seed handles include legacy marketing_fallback set', () => {
const seed = [
'7a***k2',
'9c***m1',
'3f***p8',
'b2***q4',
'e8***t6',
'1d***w9',
'5h***n3',
'c4***r7',
'8j***v5',
'2m***x0',
'6p***y1',
'0s***z8',
'4n***a3',
'd7***b5',
'f1***c9',
'a9***d2',
'g3***e4',
'h6***f7',
'i2***g1',
'j8***h6',
];
strict_1.default.equal(seed.length, 20);
strict_1.default.ok(seed.every((h) => /^[a-zA-Z0-9]{2}\*\*\*[a-zA-Z0-9]{2}$/.test(h)));
});
});
//# sourceMappingURL=marketingService.test.js.map