mirror of
https://github.com/Cockatrice/Cockatrice.git
synced 2026-06-12 00:54:53 -07:00
refactor typescript wiring
This commit is contained in:
parent
cea9ae62d8
commit
c62c336a11
286 changed files with 2999 additions and 3053 deletions
|
|
@ -32,7 +32,10 @@ vi.mock('../../persistence', () => ({
|
|||
},
|
||||
}));
|
||||
|
||||
import { create } from '@bufbuild/protobuf';
|
||||
import { Data } from '@app/types';
|
||||
import { GamePersistence } from '../../persistence';
|
||||
|
||||
import { attachCard } from './attachCard';
|
||||
import { changeZoneProperties } from './changeZoneProperties';
|
||||
import { createArrow } from './createArrow';
|
||||
|
|
@ -63,14 +66,12 @@ import { setCardCounter } from './setCardCounter';
|
|||
import { setCounter } from './setCounter';
|
||||
import { shuffle } from './shuffle';
|
||||
|
||||
beforeEach(() => vi.clearAllMocks());
|
||||
|
||||
const meta = { gameId: 5, playerId: 2, context: null, secondsElapsed: 0, forcedByJudge: 0 };
|
||||
|
||||
describe('joinGame event', () => {
|
||||
it('delegates to GamePersistence.playerJoined with gameId from meta', () => {
|
||||
const playerProperties = { playerId: 1 };
|
||||
const data = { playerProperties } as any;
|
||||
const playerProperties = create(Data.ServerInfo_PlayerPropertiesSchema, { playerId: 1 });
|
||||
const data = { playerProperties };
|
||||
joinGame(data, meta);
|
||||
expect(GamePersistence.playerJoined).toHaveBeenCalledWith(5, playerProperties);
|
||||
});
|
||||
|
|
@ -107,7 +108,7 @@ describe('kicked event', () => {
|
|||
|
||||
describe('gameStateChanged event', () => {
|
||||
it('delegates to GamePersistence.gameStateChanged with gameId and full data', () => {
|
||||
const data = { playerList: [] } as any;
|
||||
const data = create(Data.Event_GameStateChangedSchema, { playerList: [] });
|
||||
gameStateChanged(data, meta);
|
||||
expect(GamePersistence.gameStateChanged).toHaveBeenCalledWith(5, data);
|
||||
});
|
||||
|
|
@ -115,8 +116,8 @@ describe('gameStateChanged event', () => {
|
|||
|
||||
describe('playerPropertiesChanged event', () => {
|
||||
it('delegates to GamePersistence.playerPropertiesChanged with gameId, playerId, properties', () => {
|
||||
const playerProperties = { playerId: 2 } as any;
|
||||
const data = { playerProperties } as any;
|
||||
const playerProperties = create(Data.ServerInfo_PlayerPropertiesSchema, { playerId: 2 });
|
||||
const data = { playerProperties };
|
||||
playerPropertiesChanged(data, meta);
|
||||
expect(GamePersistence.playerPropertiesChanged).toHaveBeenCalledWith(5, 2, playerProperties);
|
||||
});
|
||||
|
|
@ -124,7 +125,7 @@ describe('playerPropertiesChanged event', () => {
|
|||
|
||||
describe('gameSay event', () => {
|
||||
it('delegates to GamePersistence.gameSay with gameId, playerId, message', () => {
|
||||
const data = { message: 'gg' } as any;
|
||||
const data = create(Data.Event_GameSaySchema, { message: 'gg' });
|
||||
gameSay(data, meta);
|
||||
expect(GamePersistence.gameSay).toHaveBeenCalledWith(5, 2, 'gg');
|
||||
});
|
||||
|
|
@ -132,7 +133,7 @@ describe('gameSay event', () => {
|
|||
|
||||
describe('moveCard event', () => {
|
||||
it('delegates to GamePersistence.cardMoved with gameId, playerId and data', () => {
|
||||
const data = { cardId: 3 } as any;
|
||||
const data = create(Data.Event_MoveCardSchema, { cardId: 3 });
|
||||
moveCard(data, meta);
|
||||
expect(GamePersistence.cardMoved).toHaveBeenCalledWith(5, 2, data);
|
||||
});
|
||||
|
|
@ -140,7 +141,7 @@ describe('moveCard event', () => {
|
|||
|
||||
describe('flipCard event', () => {
|
||||
it('delegates to GamePersistence.cardFlipped with gameId, playerId and data', () => {
|
||||
const data = { cardId: 3 } as any;
|
||||
const data = create(Data.Event_FlipCardSchema, { cardId: 3 });
|
||||
flipCard(data, meta);
|
||||
expect(GamePersistence.cardFlipped).toHaveBeenCalledWith(5, 2, data);
|
||||
});
|
||||
|
|
@ -148,7 +149,7 @@ describe('flipCard event', () => {
|
|||
|
||||
describe('destroyCard event', () => {
|
||||
it('delegates to GamePersistence.cardDestroyed with gameId, playerId and data', () => {
|
||||
const data = { cardId: 3 } as any;
|
||||
const data = create(Data.Event_DestroyCardSchema, { cardId: 3 });
|
||||
destroyCard(data, meta);
|
||||
expect(GamePersistence.cardDestroyed).toHaveBeenCalledWith(5, 2, data);
|
||||
});
|
||||
|
|
@ -156,7 +157,7 @@ describe('destroyCard event', () => {
|
|||
|
||||
describe('attachCard event', () => {
|
||||
it('delegates to GamePersistence.cardAttached with gameId, playerId and data', () => {
|
||||
const data = { cardId: 3 } as any;
|
||||
const data = create(Data.Event_AttachCardSchema, { cardId: 3 });
|
||||
attachCard(data, meta);
|
||||
expect(GamePersistence.cardAttached).toHaveBeenCalledWith(5, 2, data);
|
||||
});
|
||||
|
|
@ -164,7 +165,7 @@ describe('attachCard event', () => {
|
|||
|
||||
describe('createToken event', () => {
|
||||
it('delegates to GamePersistence.tokenCreated with gameId, playerId and data', () => {
|
||||
const data = { cardId: 3 } as any;
|
||||
const data = create(Data.Event_CreateTokenSchema, { cardId: 3 });
|
||||
createToken(data, meta);
|
||||
expect(GamePersistence.tokenCreated).toHaveBeenCalledWith(5, 2, data);
|
||||
});
|
||||
|
|
@ -172,7 +173,7 @@ describe('createToken event', () => {
|
|||
|
||||
describe('setCardAttr event', () => {
|
||||
it('delegates to GamePersistence.cardAttrChanged with gameId, playerId and data', () => {
|
||||
const data = { cardId: 3 } as any;
|
||||
const data = create(Data.Event_SetCardAttrSchema, { cardId: 3 });
|
||||
setCardAttr(data, meta);
|
||||
expect(GamePersistence.cardAttrChanged).toHaveBeenCalledWith(5, 2, data);
|
||||
});
|
||||
|
|
@ -180,7 +181,7 @@ describe('setCardAttr event', () => {
|
|||
|
||||
describe('setCardCounter event', () => {
|
||||
it('delegates to GamePersistence.cardCounterChanged with gameId, playerId and data', () => {
|
||||
const data = { cardId: 3 } as any;
|
||||
const data = create(Data.Event_SetCardCounterSchema, { cardId: 3 });
|
||||
setCardCounter(data, meta);
|
||||
expect(GamePersistence.cardCounterChanged).toHaveBeenCalledWith(5, 2, data);
|
||||
});
|
||||
|
|
@ -188,7 +189,7 @@ describe('setCardCounter event', () => {
|
|||
|
||||
describe('createArrow event', () => {
|
||||
it('delegates to GamePersistence.arrowCreated with gameId, playerId and data', () => {
|
||||
const data = { arrowInfo: {} } as any;
|
||||
const data = create(Data.Event_CreateArrowSchema, {});
|
||||
createArrow(data, meta);
|
||||
expect(GamePersistence.arrowCreated).toHaveBeenCalledWith(5, 2, data);
|
||||
});
|
||||
|
|
@ -196,7 +197,7 @@ describe('createArrow event', () => {
|
|||
|
||||
describe('deleteArrow event', () => {
|
||||
it('delegates to GamePersistence.arrowDeleted with gameId, playerId and data', () => {
|
||||
const data = { arrowId: 9 } as any;
|
||||
const data = create(Data.Event_DeleteArrowSchema, { arrowId: 9 });
|
||||
deleteArrow(data, meta);
|
||||
expect(GamePersistence.arrowDeleted).toHaveBeenCalledWith(5, 2, data);
|
||||
});
|
||||
|
|
@ -204,7 +205,7 @@ describe('deleteArrow event', () => {
|
|||
|
||||
describe('createCounter event', () => {
|
||||
it('delegates to GamePersistence.counterCreated with gameId, playerId and data', () => {
|
||||
const data = { counterInfo: {} } as any;
|
||||
const data = create(Data.Event_CreateCounterSchema, {});
|
||||
createCounter(data, meta);
|
||||
expect(GamePersistence.counterCreated).toHaveBeenCalledWith(5, 2, data);
|
||||
});
|
||||
|
|
@ -212,7 +213,7 @@ describe('createCounter event', () => {
|
|||
|
||||
describe('setCounter event', () => {
|
||||
it('delegates to GamePersistence.counterSet with gameId, playerId and data', () => {
|
||||
const data = { counterId: 1, value: 20 } as any;
|
||||
const data = create(Data.Event_SetCounterSchema, { counterId: 1, value: 20 });
|
||||
setCounter(data, meta);
|
||||
expect(GamePersistence.counterSet).toHaveBeenCalledWith(5, 2, data);
|
||||
});
|
||||
|
|
@ -220,7 +221,7 @@ describe('setCounter event', () => {
|
|||
|
||||
describe('delCounter event', () => {
|
||||
it('delegates to GamePersistence.counterDeleted with gameId, playerId and data', () => {
|
||||
const data = { counterId: 1 } as any;
|
||||
const data = create(Data.Event_DelCounterSchema, { counterId: 1 });
|
||||
delCounter(data, meta);
|
||||
expect(GamePersistence.counterDeleted).toHaveBeenCalledWith(5, 2, data);
|
||||
});
|
||||
|
|
@ -228,7 +229,7 @@ describe('delCounter event', () => {
|
|||
|
||||
describe('drawCards event', () => {
|
||||
it('delegates to GamePersistence.cardsDrawn with gameId, playerId and data', () => {
|
||||
const data = { number: 2, cards: [] } as any;
|
||||
const data = create(Data.Event_DrawCardsSchema, { number: 2, cards: [] });
|
||||
drawCards(data, meta);
|
||||
expect(GamePersistence.cardsDrawn).toHaveBeenCalledWith(5, 2, data);
|
||||
});
|
||||
|
|
@ -236,7 +237,7 @@ describe('drawCards event', () => {
|
|||
|
||||
describe('revealCards event', () => {
|
||||
it('delegates to GamePersistence.cardsRevealed with gameId, playerId and data', () => {
|
||||
const data = { zoneName: 'hand', cards: [] } as any;
|
||||
const data = create(Data.Event_RevealCardsSchema, { zoneName: 'hand', cards: [] });
|
||||
revealCards(data, meta);
|
||||
expect(GamePersistence.cardsRevealed).toHaveBeenCalledWith(5, 2, data);
|
||||
});
|
||||
|
|
@ -244,7 +245,7 @@ describe('revealCards event', () => {
|
|||
|
||||
describe('shuffle event', () => {
|
||||
it('delegates to GamePersistence.zoneShuffled with gameId, playerId and data', () => {
|
||||
const data = { zoneName: 'deck' } as any;
|
||||
const data = create(Data.Event_ShuffleSchema, { zoneName: 'deck' });
|
||||
shuffle(data, meta);
|
||||
expect(GamePersistence.zoneShuffled).toHaveBeenCalledWith(5, 2, data);
|
||||
});
|
||||
|
|
@ -252,7 +253,7 @@ describe('shuffle event', () => {
|
|||
|
||||
describe('rollDie event', () => {
|
||||
it('delegates to GamePersistence.dieRolled with gameId, playerId and data', () => {
|
||||
const data = { die: 6, result: 4 } as any;
|
||||
const data = create(Data.Event_RollDieSchema, { die: 6, result: 4 });
|
||||
rollDie(data, meta);
|
||||
expect(GamePersistence.dieRolled).toHaveBeenCalledWith(5, 2, data);
|
||||
});
|
||||
|
|
@ -260,7 +261,7 @@ describe('rollDie event', () => {
|
|||
|
||||
describe('setActivePlayer event', () => {
|
||||
it('delegates to GamePersistence.activePlayerSet with gameId and activePlayerId', () => {
|
||||
const data = { activePlayerId: 3 } as any;
|
||||
const data = create(Data.Event_SetActivePlayerSchema, { activePlayerId: 3 });
|
||||
setActivePlayer(data, meta);
|
||||
expect(GamePersistence.activePlayerSet).toHaveBeenCalledWith(5, 3);
|
||||
});
|
||||
|
|
@ -268,7 +269,7 @@ describe('setActivePlayer event', () => {
|
|||
|
||||
describe('setActivePhase event', () => {
|
||||
it('delegates to GamePersistence.activePhaseSet with gameId and phase', () => {
|
||||
const data = { phase: 4 } as any;
|
||||
const data = create(Data.Event_SetActivePhaseSchema, { phase: 4 });
|
||||
setActivePhase(data, meta);
|
||||
expect(GamePersistence.activePhaseSet).toHaveBeenCalledWith(5, 4);
|
||||
});
|
||||
|
|
@ -276,7 +277,7 @@ describe('setActivePhase event', () => {
|
|||
|
||||
describe('reverseTurn event', () => {
|
||||
it('delegates to GamePersistence.turnReversed with gameId and reversed', () => {
|
||||
const data = { reversed: true } as any;
|
||||
const data = create(Data.Event_ReverseTurnSchema, { reversed: true });
|
||||
reverseTurn(data, meta);
|
||||
expect(GamePersistence.turnReversed).toHaveBeenCalledWith(5, true);
|
||||
});
|
||||
|
|
@ -284,7 +285,7 @@ describe('reverseTurn event', () => {
|
|||
|
||||
describe('dumpZone event', () => {
|
||||
it('delegates to GamePersistence.zoneDumped with gameId, playerId and data', () => {
|
||||
const data = { zoneName: 'hand' } as any;
|
||||
const data = create(Data.Event_DumpZoneSchema, { zoneName: 'hand' });
|
||||
dumpZone(data, meta);
|
||||
expect(GamePersistence.zoneDumped).toHaveBeenCalledWith(5, 2, data);
|
||||
});
|
||||
|
|
@ -292,7 +293,7 @@ describe('dumpZone event', () => {
|
|||
|
||||
describe('changeZoneProperties event', () => {
|
||||
it('delegates to GamePersistence.zonePropertiesChanged with gameId, playerId and data', () => {
|
||||
const data = { zoneName: 'hand', alwaysRevealTopCard: true } as any;
|
||||
const data = create(Data.Event_ChangeZonePropertiesSchema, { zoneName: 'hand', alwaysRevealTopCard: true });
|
||||
changeZoneProperties(data, meta);
|
||||
expect(GamePersistence.zonePropertiesChanged).toHaveBeenCalledWith(5, 2, data);
|
||||
});
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue