feat(items): add server field and improve item management
refactor(ai): enhance item structure generation with schema validation feat(ai): add token usage tracking and cost calculation fix(ui): improve item card number formatting with locale support docs(items): add documentation for item value separation test(items): add tests for value field validation
This commit is contained in:
1 parent
dc169f9eba
commit
d3704602fd
22 files changed
+1317
-95
No files matched your search
@@ -0,0 +1,62 @@
|
||||
import assert from "node:assert";
|
||||
import fs from "node:fs";
|
||||
import path from "node:path";
|
||||
|
||||
import { assertNoValueFieldsInMetadata } from "../lib/prisma/queries/items";
|
||||
|
||||
type TestCase = { name: string; fn: () => Promise<void> | void };
|
||||
const tests: TestCase[] = [];
|
||||
|
||||
function test(name: string, fn: () => Promise<void> | void) {
|
||||
tests.push({ name, fn });
|
||||
}
|
||||
|
||||
// Teste 1: criação sem valores (validação não lança)
|
||||
test("Validação permite metadata sem campos de valor", () => {
|
||||
const cleanMeta = {
|
||||
attributes: { protection_physical: 0, speed: 500 },
|
||||
servers: ["Antica"],
|
||||
tags: ["relic"],
|
||||
};
|
||||
assert.doesNotThrow(() => assertNoValueFieldsInMetadata(cleanMeta, "test1"));
|
||||
});
|
||||
|
||||
// Teste 2: rejeita tentativas de incluir valores
|
||||
test("Validação rejeita metadata com campos de preço/valor", () => {
|
||||
const badMeta = {
|
||||
attributes: { speed: 500 },
|
||||
price: 100000,
|
||||
};
|
||||
assert.throws(() => assertNoValueFieldsInMetadata(badMeta, "test2"));
|
||||
});
|
||||
|
||||
// Teste 3: Consistência do schema do Item (sem campos de valor)
|
||||
test("Schema Prisma do Item não possui campos de preço/valor", () => {
|
||||
const schemaPath = path.resolve(process.cwd(), "prisma", "schema.prisma");
|
||||
const content = fs.readFileSync(schemaPath, "utf8");
|
||||
const itemBlockMatch = content.match(/model\s+Item\s+\{[\s\S]*?\}/);
|
||||
assert.ok(itemBlockMatch, "Bloco model Item não encontrado no schema.prisma");
|
||||
const itemBlock = itemBlockMatch![0];
|
||||
const forbidden = [/price/i, /value/i, /sell_value/i, /buy_price/i];
|
||||
for (const re of forbidden) {
|
||||
assert.ok(!re.test(itemBlock), `Campo proibido detectado no Item: ${re}`);
|
||||
}
|
||||
});
|
||||
|
||||
async function run() {
|
||||
let passed = 0;
|
||||
for (const t of tests) {
|
||||
try {
|
||||
await t.fn();
|
||||
passed++;
|
||||
console.log(`✓ ${t.name}`);
|
||||
} catch (e) {
|
||||
console.error(`✗ ${t.name}`);
|
||||
console.error(e);
|
||||
process.exitCode = 1;
|
||||
}
|
||||
}
|
||||
console.log(`\n${passed}/${tests.length} testes passaram.`);
|
||||
}
|
||||
|
||||
run();
|
||||
Reference in new issue
Block a user