Files
yourpart3/backend/tools/testGiftCost.js

39 lines
1.4 KiB
JavaScript

import { fileURLToPath } from 'url';
import path from 'path';
import { readFileSync } from 'fs';
// Kleine Testhilfe: extrahiere getGiftCost aus service-file via eval (schneller Smoke-test ohne DB)
const svcPath = path.resolve(process.cwd(), 'services', 'falukantService.js');
const src = readFileSync(svcPath, 'utf8');
// Extrahiere die getGiftCost-Funktion via Regex (vereinfachte Annahme)
const re = /async getGiftCost\([\s\S]*?\n\s*}\n/;
const match = src.match(re);
if (!match) {
console.error('getGiftCost function not found');
process.exit(2);
}
const funcSrc = match[0];
// Wrappe in Async-Function und erzeuge getGiftCost im lokalen Scope
const wrapper = `(async () => { ${funcSrc}; return getGiftCost; })()`;
// eslint-disable-next-line no-eval
const getGiftCostPromise = eval(wrapper);
let getGiftCost;
getGiftCostPromise.then(f => { getGiftCost = f; runTests(); }).catch(e => { console.error('eval failed', e); process.exit(2); });
function runTests() {
const cases = [
{ value: 100, title: 3, lowest: 1 },
{ value: '200', title: '2', lowest: '1' },
{ value: null, title: null, lowest: null },
{ value: 'abc', title: 5, lowest: 1 }
];
for (const c of cases) {
getGiftCost(c.value, c.title, c.lowest).then(out => {
console.log(`in=${JSON.stringify(c)} -> cost=${out}`);
}).catch(err => console.error('error calling getGiftCost', err));
}
}
// Ende Patch