feat: Add testing framework and initial test cases for various tools and database operations
This commit is contained in:
61
tests/unit/tools/hobbies/football.test.ts
Normal file
61
tests/unit/tools/hobbies/football.test.ts
Normal file
@@ -0,0 +1,61 @@
|
||||
/**
|
||||
* Football tools tests
|
||||
*/
|
||||
|
||||
import { describe, test, expect, beforeEach } from "bun:test";
|
||||
import { registerFootballTools } from "../../../../src/tools/hobbies/football.js";
|
||||
import { callTool } from "../../../helpers/tool-helper.js";
|
||||
import { setTestEnv } from "../../../helpers/test-utils.js";
|
||||
|
||||
describe("Football Tools", () => {
|
||||
let cleanupEnv: () => void;
|
||||
|
||||
beforeEach(() => {
|
||||
cleanupEnv = setTestEnv({
|
||||
FOOTBALL_API_KEY: "test-key",
|
||||
});
|
||||
registerFootballTools();
|
||||
});
|
||||
|
||||
afterEach(() => {
|
||||
cleanupEnv();
|
||||
});
|
||||
|
||||
test("should get football matches", async () => {
|
||||
const result = await callTool("football_matches", {
|
||||
days: 7,
|
||||
});
|
||||
|
||||
// Should return matches or placeholder message
|
||||
expect(result.content[0].text).toBeDefined();
|
||||
expect(result.content[0].text.length).toBeGreaterThan(0);
|
||||
});
|
||||
|
||||
test("should get team information", async () => {
|
||||
const result = await callTool("football_team_info", {
|
||||
team: "Manchester United",
|
||||
});
|
||||
|
||||
// Should return team info or placeholder
|
||||
expect(result.content[0].text).toBeDefined();
|
||||
});
|
||||
|
||||
test("should get league standings", async () => {
|
||||
const result = await callTool("football_standings", {
|
||||
league: "Premier League",
|
||||
});
|
||||
|
||||
// Should return standings or placeholder
|
||||
expect(result.content[0].text).toBeDefined();
|
||||
});
|
||||
|
||||
test("should handle missing API key gracefully", async () => {
|
||||
cleanupEnv();
|
||||
cleanupEnv = setTestEnv({});
|
||||
registerFootballTools();
|
||||
|
||||
const result = await callTool("football_matches", {});
|
||||
|
||||
expect(result.content[0].text).toContain("FOOTBALL_API_KEY");
|
||||
});
|
||||
});
|
||||
100
tests/unit/tools/hobbies/games.test.ts
Normal file
100
tests/unit/tools/hobbies/games.test.ts
Normal file
@@ -0,0 +1,100 @@
|
||||
/**
|
||||
* Game tools tests
|
||||
*/
|
||||
|
||||
import { describe, test, expect, beforeEach, afterEach } from "bun:test";
|
||||
import { registerGameTools } from "../../../../src/tools/hobbies/games.js";
|
||||
import { callTool } from "../../../helpers/tool-helper.js";
|
||||
import { createTempDir } from "../../../helpers/test-utils.js";
|
||||
import { setupTestDatabase } from "../../../helpers/database-helper.js";
|
||||
|
||||
describe("Game Tools", () => {
|
||||
let testContext: ReturnType<typeof createTempDir>;
|
||||
let cleanupDb: () => void;
|
||||
|
||||
beforeEach(() => {
|
||||
testContext = createTempDir();
|
||||
cleanupDb = setupTestDatabase(testContext);
|
||||
registerGameTools();
|
||||
});
|
||||
|
||||
afterEach(() => {
|
||||
cleanupDb();
|
||||
testContext.cleanup();
|
||||
});
|
||||
|
||||
test("should get game information", async () => {
|
||||
const result = await callTool("game_info", {
|
||||
name: "Minecraft",
|
||||
});
|
||||
|
||||
// Should either return game info or handle API error gracefully
|
||||
expect(result.content[0].text).toBeDefined();
|
||||
}, 10000); // Longer timeout for API calls
|
||||
|
||||
test("should get game deals", async () => {
|
||||
const result = await callTool("game_deals", {
|
||||
platform: "steam",
|
||||
});
|
||||
|
||||
// Should either return deals or handle API error gracefully
|
||||
expect(result.content[0].text).toBeDefined();
|
||||
}, 10000);
|
||||
|
||||
test("should add game to wishlist", async () => {
|
||||
const result = await callTool("game_wishlist", {
|
||||
action: "add",
|
||||
gameName: "Test Game",
|
||||
platform: "PC",
|
||||
});
|
||||
|
||||
expect(result.content[0].text).toContain("added to wishlist");
|
||||
expect(result.content[0].text).toContain("Test Game");
|
||||
});
|
||||
|
||||
test("should list game wishlist", async () => {
|
||||
// Add a game first
|
||||
await callTool("game_wishlist", {
|
||||
action: "add",
|
||||
gameName: "Test Game",
|
||||
platform: "PC",
|
||||
});
|
||||
|
||||
const result = await callTool("game_wishlist", {
|
||||
action: "list",
|
||||
});
|
||||
|
||||
expect(result.content[0].text).toMatch(/wishlist|Test Game/i);
|
||||
});
|
||||
|
||||
test("should remove game from wishlist", async () => {
|
||||
// Add a game first
|
||||
const addResult = await callTool("game_wishlist", {
|
||||
action: "add",
|
||||
gameName: "Test Game",
|
||||
});
|
||||
|
||||
// Extract ID
|
||||
const idMatch = addResult.content[0].text.match(/ID: ([a-f0-9-]+)/);
|
||||
if (!idMatch) {
|
||||
throw new Error("Could not extract ID");
|
||||
}
|
||||
const id = idMatch[1];
|
||||
|
||||
// Remove it
|
||||
const result = await callTool("game_wishlist", {
|
||||
action: "remove",
|
||||
id,
|
||||
});
|
||||
|
||||
expect(result.content[0].text).toContain("removed from wishlist");
|
||||
});
|
||||
|
||||
test("should handle empty wishlist", async () => {
|
||||
const result = await callTool("game_wishlist", {
|
||||
action: "list",
|
||||
});
|
||||
|
||||
expect(result.content[0].text).toMatch(/empty|Use game_wishlist.*add/i);
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user