1+ import { vi } from 'vitest'
12import { handleToolCall } from '../handlers/tool-handlers.js'
23import { listResources , readResource } from '../handlers/resource-handlers.js'
34import { listPrompts , getPrompt } from '../handlers/prompt-handlers.js'
5+ import * as httpClient from '../utils/http-client.js'
6+
7+ // Import the real constants from shared package
8+ import { GAME_TYPES , DIFFICULTIES , isSupportedGameType , DEFAULT_PLAYER_NAME , DEFAULT_AI_DIFFICULTY } from '@turn-based-mcp/shared'
49
510// Mock the web API calls for testing
6- jest . mock ( '../utils/http-client.js' , ( ) => ( {
7- httpGet : jest . fn ( ) ,
8- httpPost : jest . fn ( ) ,
9- getGameViaAPI : jest . fn ( ) ,
10- createGameViaAPI : jest . fn ( ) ,
11- submitMoveViaAPI : jest . fn ( ) ,
12- getGamesByType : jest . fn ( )
11+ vi . mock ( '../utils/http-client.js' , ( ) => ( {
12+ httpGet : vi . fn ( ) ,
13+ httpPost : vi . fn ( ) ,
14+ getGameViaAPI : vi . fn ( ) ,
15+ createGameViaAPI : vi . fn ( ) ,
16+ submitMoveViaAPI : vi . fn ( ) ,
17+ getGamesByType : vi . fn ( )
1318} ) )
1419
15- // Mock shared library
16- jest . mock ( '@turn-based-mcp/shared' , ( ) => ( {
17- TicTacToeGame : jest . fn ( ( ) => ( {
18- getValidMoves : jest . fn ( ( ) => [ { row : 0 , col : 0 } ] )
19- } ) ) ,
20- RockPaperScissorsGame : jest . fn ( ( ) => ( { } ) )
21- } ) )
20+ // Mock only the game classes from shared library
21+ vi . mock ( '@turn-based-mcp/shared' , async ( importOriginal ) => {
22+ const actual = await importOriginal ( ) as any
23+ return {
24+ ...actual ,
25+ TicTacToeGame : vi . fn ( ( ) => ( {
26+ getValidMoves : vi . fn ( ( ) => [ { row : 0 , col : 0 } ] )
27+ } ) ) ,
28+ RockPaperScissorsGame : vi . fn ( ( ) => ( { } ) )
29+ }
30+ } )
2231
2332// Mock AI modules
24- jest . mock ( '../ai/tic-tac-toe-ai.js' , ( ) => ( {
25- TicTacToeAI : jest . fn ( ( ) => ( {
26- makeMove : jest . fn ( ( ) => ( { row : 0 , col : 0 } ) )
33+ vi . mock ( '../ai/tic-tac-toe-ai.js' , ( ) => ( {
34+ TicTacToeAI : vi . fn ( ( ) => ( {
35+ makeMove : vi . fn ( ( ) => ( { row : 0 , col : 0 } ) )
2736 } ) )
2837} ) )
2938
30- jest . mock ( '../ai/rock-paper-scissors-ai.js' , ( ) => ( {
31- RockPaperScissorsAI : jest . fn ( ( ) => ( {
32- makeChoice : jest . fn ( ( ) => 'rock' )
39+ vi . mock ( '../ai/rock-paper-scissors-ai.js' , ( ) => ( {
40+ RockPaperScissorsAI : vi . fn ( ( ) => ( {
41+ makeChoice : vi . fn ( ( ) => 'rock' )
3342 } ) )
3443} ) )
3544
3645describe ( 'MCP Server Integration' , ( ) => {
3746 beforeEach ( ( ) => {
38- jest . clearAllMocks ( )
47+ vi . clearAllMocks ( )
3948 } )
4049
4150 describe ( 'Resource Handlers' , ( ) => {
4251 it ( 'should list resources correctly' , async ( ) => {
43- const mockGetGamesByType = require ( '../utils/http-client.js' ) . getGamesByType
52+ const mockGetGamesByType = vi . mocked ( httpClient . getGamesByType )
4453 mockGetGamesByType . mockResolvedValue ( [
4554 {
4655 gameState : {
@@ -70,7 +79,7 @@ describe('MCP Server Integration', () => {
7079 } )
7180
7281 it ( 'should read game type resource correctly' , async ( ) => {
73- const mockGetGamesByType = require ( '../utils/http-client.js' ) . getGamesByType
82+ const mockGetGamesByType = vi . mocked ( httpClient . getGamesByType )
7483 mockGetGamesByType . mockResolvedValue ( [
7584 {
7685 gameState : {
@@ -95,7 +104,7 @@ describe('MCP Server Integration', () => {
95104 } )
96105
97106 it ( 'should read individual game resource correctly' , async ( ) => {
98- const mockGetGameViaAPI = require ( '../utils/http-client.js' ) . getGameViaAPI
107+ const mockGetGameViaAPI = vi . mocked ( httpClient . getGameViaAPI )
99108 mockGetGameViaAPI . mockResolvedValue ( {
100109 gameState : {
101110 id : 'test-game-1' ,
@@ -118,7 +127,7 @@ describe('MCP Server Integration', () => {
118127
119128 describe ( 'Tool Handlers' , ( ) => {
120129 it ( 'should create tic-tac-toe game correctly' , async ( ) => {
121- const mockCreateGameViaAPI = require ( '../utils/http-client.js' ) . createGameViaAPI
130+ const mockCreateGameViaAPI = vi . mocked ( httpClient . createGameViaAPI )
122131 mockCreateGameViaAPI . mockResolvedValue ( {
123132 gameState : {
124133 id : 'new-game-id' ,
@@ -136,8 +145,8 @@ describe('MCP Server Integration', () => {
136145 } )
137146
138147 it ( 'should handle play moves correctly' , async ( ) => {
139- const mockGetGameViaAPI = require ( '../utils/http-client.js' ) . getGameViaAPI
140- const mockSubmitMoveViaAPI = require ( '../utils/http-client.js' ) . submitMoveViaAPI
148+ const mockGetGameViaAPI = vi . mocked ( httpClient . getGameViaAPI )
149+ const mockSubmitMoveViaAPI = vi . mocked ( httpClient . submitMoveViaAPI )
141150
142151 mockGetGameViaAPI . mockResolvedValue ( {
143152 gameState : {
0 commit comments