mirror of
https://github.com/tiennm99/miti99bot.git
synced 2026-04-17 19:22:09 +00:00
feat: add fake trading module with crypto, stocks, forex and gold
Paper trading system with 5 commands (trade_topup, trade_buy, trade_sell, trade_convert, trade_stats). Supports VN stocks via TCBS, crypto via CoinGecko, forex via ER-API, and gold via PAX Gold proxy. Per-user portfolio stored in KV with 60s price caching. 54 new tests.
This commit is contained in:
46
tests/modules/trading/symbols.test.js
Normal file
46
tests/modules/trading/symbols.test.js
Normal file
@@ -0,0 +1,46 @@
|
||||
import { describe, expect, it } from "vitest";
|
||||
import {
|
||||
CURRENCIES,
|
||||
SYMBOLS,
|
||||
getSymbol,
|
||||
listSymbols,
|
||||
} from "../../../src/modules/trading/symbols.js";
|
||||
|
||||
describe("trading/symbols", () => {
|
||||
it("SYMBOLS has 9 entries across 3 categories", () => {
|
||||
expect(Object.keys(SYMBOLS)).toHaveLength(9);
|
||||
const cats = new Set(Object.values(SYMBOLS).map((s) => s.category));
|
||||
expect(cats).toEqual(new Set(["crypto", "stock", "others"]));
|
||||
});
|
||||
|
||||
it("getSymbol is case-insensitive", () => {
|
||||
const btc = getSymbol("btc");
|
||||
expect(btc).toBeDefined();
|
||||
expect(btc.symbol).toBe("BTC");
|
||||
expect(btc.category).toBe("crypto");
|
||||
|
||||
expect(getSymbol("Tcb").symbol).toBe("TCB");
|
||||
});
|
||||
|
||||
it("getSymbol returns undefined for unknown symbols", () => {
|
||||
expect(getSymbol("NOPE")).toBeUndefined();
|
||||
expect(getSymbol("")).toBeUndefined();
|
||||
expect(getSymbol(null)).toBeUndefined();
|
||||
});
|
||||
|
||||
it("CURRENCIES contains VND and USD", () => {
|
||||
expect(CURRENCIES.has("VND")).toBe(true);
|
||||
expect(CURRENCIES.has("USD")).toBe(true);
|
||||
expect(CURRENCIES.has("EUR")).toBe(false);
|
||||
});
|
||||
|
||||
it("listSymbols returns grouped output", () => {
|
||||
const out = listSymbols();
|
||||
expect(out).toContain("Crypto:");
|
||||
expect(out).toContain("BTC — Bitcoin");
|
||||
expect(out).toContain("Stocks:");
|
||||
expect(out).toContain("TCB — Techcombank");
|
||||
expect(out).toContain("Others:");
|
||||
expect(out).toContain("GOLD — Gold");
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user