feat: Add testing framework and initial test cases for various tools and database operations
This commit is contained in:
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