mirror of
https://github.com/Cockatrice/Cockatrice.git
synced 2026-04-27 07:48:01 -07:00
add missing requests/responses
This commit is contained in:
parent
f0c3581d26
commit
4b5f66d497
27 changed files with 382 additions and 10 deletions
|
|
@ -73,6 +73,8 @@ export function makeSessionPersistenceMock() {
|
|||
replayAdded: vi.fn(),
|
||||
replayModifyMatch: vi.fn(),
|
||||
replayDeleteMatch: vi.fn(),
|
||||
downloadServerDeck: vi.fn(),
|
||||
replayDownloaded: vi.fn(),
|
||||
resetPasswordChallenge: vi.fn(),
|
||||
resetPassword: vi.fn(),
|
||||
resetPasswordFailed: vi.fn(),
|
||||
|
|
|
|||
|
|
@ -34,6 +34,7 @@ import { nextTurn } from './nextTurn';
|
|||
import { readyStart } from './readyStart';
|
||||
import { revealCards } from './revealCards';
|
||||
import { reverseTurn } from './reverseTurn';
|
||||
import { rollDie } from './rollDie';
|
||||
import { setActivePhase } from './setActivePhase';
|
||||
import { setCardAttr } from './setCardAttr';
|
||||
import { setCardCounter } from './setCardCounter';
|
||||
|
|
@ -262,6 +263,13 @@ describe('Game commands — delegate to WebClient.instance.protobuf.sendGameComm
|
|||
expect(WebClient.instance.protobuf.sendGameCommand).toHaveBeenCalledWith(gameId, Data.Command_Unconcede_ext, expect.any(Object));
|
||||
});
|
||||
|
||||
it('rollDie sends Command_RollDie', () => {
|
||||
rollDie(gameId, { sides: 6, count: 2 });
|
||||
expect(WebClient.instance.protobuf.sendGameCommand).toHaveBeenCalledWith(
|
||||
gameId, Data.Command_RollDie_ext, expect.objectContaining({ sides: 6, count: 2 })
|
||||
);
|
||||
});
|
||||
|
||||
it('judge sends Command_Judge with targetId and wrapped gameCommand array', () => {
|
||||
const targetId = 3;
|
||||
const innerCmd = create(Data.GameCommandSchema);
|
||||
|
|
|
|||
|
|
@ -31,3 +31,4 @@ export { deckSelect } from './deckSelect';
|
|||
export { setSideboardPlan } from './setSideboardPlan';
|
||||
export { setSideboardLock } from './setSideboardLock';
|
||||
export { mulligan } from './mulligan';
|
||||
export { rollDie } from './rollDie';
|
||||
|
|
|
|||
8
webclient/src/websocket/commands/game/rollDie.ts
Normal file
8
webclient/src/websocket/commands/game/rollDie.ts
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
import { create } from '@bufbuild/protobuf';
|
||||
import { WebClient } from '../../WebClient';
|
||||
|
||||
import { Data } from '@app/types';
|
||||
|
||||
export function rollDie(gameId: number, params: Data.RollDieParams): void {
|
||||
WebClient.instance.protobuf.sendGameCommand(gameId, Data.Command_RollDie_ext, create(Data.Command_RollDieSchema, params));
|
||||
}
|
||||
17
webclient/src/websocket/commands/session/deckDownload.ts
Normal file
17
webclient/src/websocket/commands/session/deckDownload.ts
Normal file
|
|
@ -0,0 +1,17 @@
|
|||
import { create } from '@bufbuild/protobuf';
|
||||
import { WebClient } from '../../WebClient';
|
||||
|
||||
import { Data } from '@app/types';
|
||||
|
||||
export function deckDownload(deckId: number): void {
|
||||
WebClient.instance.protobuf.sendSessionCommand(
|
||||
Data.Command_DeckDownload_ext,
|
||||
create(Data.Command_DeckDownloadSchema, { deckId }),
|
||||
{
|
||||
responseExt: Data.Response_DeckDownload_ext,
|
||||
onSuccess: (response) => {
|
||||
WebClient.instance.response.session.downloadServerDeck(deckId, response);
|
||||
},
|
||||
}
|
||||
);
|
||||
}
|
||||
|
|
@ -6,6 +6,7 @@ export * from './addToList';
|
|||
export * from './connect';
|
||||
export * from './deckDel';
|
||||
export * from './deckDelDir';
|
||||
export * from './deckDownload';
|
||||
export * from './deckList';
|
||||
export * from './deckNewDir';
|
||||
export * from './deckUpload';
|
||||
|
|
@ -24,6 +25,7 @@ export * from './ping';
|
|||
export * from './register';
|
||||
export * from './removeFromList';
|
||||
export * from './replayDeleteMatch';
|
||||
export * from './replayDownload';
|
||||
export * from './replayGetCode';
|
||||
export * from './replayList';
|
||||
export * from './replayModifyMatch';
|
||||
|
|
|
|||
17
webclient/src/websocket/commands/session/replayDownload.ts
Normal file
17
webclient/src/websocket/commands/session/replayDownload.ts
Normal file
|
|
@ -0,0 +1,17 @@
|
|||
import { create } from '@bufbuild/protobuf';
|
||||
import { WebClient } from '../../WebClient';
|
||||
|
||||
import { Data } from '@app/types';
|
||||
|
||||
export function replayDownload(replayId: number): void {
|
||||
WebClient.instance.protobuf.sendSessionCommand(
|
||||
Data.Command_ReplayDownload_ext,
|
||||
create(Data.Command_ReplayDownloadSchema, { replayId }),
|
||||
{
|
||||
responseExt: Data.Response_ReplayDownload_ext,
|
||||
onSuccess: (response) => {
|
||||
WebClient.instance.response.session.replayDownloaded(replayId, response);
|
||||
},
|
||||
}
|
||||
);
|
||||
}
|
||||
|
|
@ -27,6 +27,7 @@ import { accountImage } from './accountImage';
|
|||
import { accountPassword } from './accountPassword';
|
||||
import { deckDel } from './deckDel';
|
||||
import { deckDelDir } from './deckDelDir';
|
||||
import { deckDownload } from './deckDownload';
|
||||
import { deckList } from './deckList';
|
||||
import { deckNewDir } from './deckNewDir';
|
||||
import { deckUpload } from './deckUpload';
|
||||
|
|
@ -39,6 +40,7 @@ import { listUsers } from './listUsers';
|
|||
import { message } from './message';
|
||||
import { ping } from './ping';
|
||||
import { replayDeleteMatch } from './replayDeleteMatch';
|
||||
import { replayDownload } from './replayDownload';
|
||||
import { replayList } from './replayList';
|
||||
import { replayModifyMatch } from './replayModifyMatch';
|
||||
import { addToList, addToBuddyList, addToIgnoreList } from './addToList';
|
||||
|
|
@ -450,3 +452,39 @@ describe('replaySubmitCode', () => {
|
|||
expect(onError).toHaveBeenCalledWith(404);
|
||||
});
|
||||
});
|
||||
|
||||
describe('deckDownload', () => {
|
||||
it('sends Command_DeckDownload', () => {
|
||||
deckDownload(42);
|
||||
expect(WebClient.instance.protobuf.sendSessionCommand).toHaveBeenCalledWith(
|
||||
Data.Command_DeckDownload_ext,
|
||||
expect.objectContaining({ deckId: 42 }),
|
||||
expect.objectContaining({ responseExt: Data.Response_DeckDownload_ext })
|
||||
);
|
||||
});
|
||||
|
||||
it('calls downloadServerDeck on success', () => {
|
||||
deckDownload(42);
|
||||
const resp = { deck: 'deck-content' };
|
||||
invokeOnSuccess(resp, { responseCode: 0 });
|
||||
expect(WebClient.instance.response.session.downloadServerDeck).toHaveBeenCalledWith(42, resp);
|
||||
});
|
||||
});
|
||||
|
||||
describe('replayDownload', () => {
|
||||
it('sends Command_ReplayDownload', () => {
|
||||
replayDownload(99);
|
||||
expect(WebClient.instance.protobuf.sendSessionCommand).toHaveBeenCalledWith(
|
||||
Data.Command_ReplayDownload_ext,
|
||||
expect.objectContaining({ replayId: 99 }),
|
||||
expect.objectContaining({ responseExt: Data.Response_ReplayDownload_ext })
|
||||
);
|
||||
});
|
||||
|
||||
it('calls replayDownloaded on success', () => {
|
||||
replayDownload(99);
|
||||
const resp = { replayData: new Uint8Array([1, 2, 3]) };
|
||||
invokeOnSuccess(resp, { responseCode: 0 });
|
||||
expect(WebClient.instance.response.session.replayDownloaded).toHaveBeenCalledWith(99, resp);
|
||||
});
|
||||
});
|
||||
|
|
|
|||
|
|
@ -22,6 +22,8 @@ export interface ISessionRequest {
|
|||
sendDirectMessage(userName: string, message: string): void;
|
||||
getUserInfo(userName: string): void;
|
||||
getUserGames(userName: string): void;
|
||||
deckDownload(deckId: number): void;
|
||||
replayDownload(replayId: number): void;
|
||||
}
|
||||
|
||||
export interface IRoomsRequest {
|
||||
|
|
@ -54,10 +56,48 @@ export interface IModeratorRequest {
|
|||
warnUser(userName: string, reason: string, clientid?: string, removeMessages?: number): void;
|
||||
}
|
||||
|
||||
export interface IGameRequest {
|
||||
leaveGame(gameId: number): void;
|
||||
kickFromGame(gameId: number, params: Data.KickFromGameParams): void;
|
||||
gameSay(gameId: number, params: Data.GameSayParams): void;
|
||||
readyStart(gameId: number, params: Data.ReadyStartParams): void;
|
||||
concede(gameId: number): void;
|
||||
unconcede(gameId: number): void;
|
||||
judge(gameId: number, targetId: number, innerGameCommand: Data.GameCommand): void;
|
||||
nextTurn(gameId: number): void;
|
||||
setActivePhase(gameId: number, params: Data.SetActivePhaseParams): void;
|
||||
reverseTurn(gameId: number): void;
|
||||
moveCard(gameId: number, params: Data.MoveCardParams): void;
|
||||
flipCard(gameId: number, params: Data.FlipCardParams): void;
|
||||
attachCard(gameId: number, params: Data.AttachCardParams): void;
|
||||
createToken(gameId: number, params: Data.CreateTokenParams): void;
|
||||
setCardAttr(gameId: number, params: Data.SetCardAttrParams): void;
|
||||
setCardCounter(gameId: number, params: Data.SetCardCounterParams): void;
|
||||
incCardCounter(gameId: number, params: Data.IncCardCounterParams): void;
|
||||
drawCards(gameId: number, params: Data.DrawCardsParams): void;
|
||||
undoDraw(gameId: number): void;
|
||||
createArrow(gameId: number, params: Data.CreateArrowParams): void;
|
||||
deleteArrow(gameId: number, params: Data.DeleteArrowParams): void;
|
||||
createCounter(gameId: number, params: Data.CreateCounterParams): void;
|
||||
setCounter(gameId: number, params: Data.SetCounterParams): void;
|
||||
incCounter(gameId: number, params: Data.IncCounterParams): void;
|
||||
delCounter(gameId: number, params: Data.DelCounterParams): void;
|
||||
shuffle(gameId: number, params: Data.ShuffleParams): void;
|
||||
dumpZone(gameId: number, params: Data.DumpZoneParams): void;
|
||||
revealCards(gameId: number, params: Data.RevealCardsParams): void;
|
||||
changeZoneProperties(gameId: number, params: Data.ChangeZonePropertiesParams): void;
|
||||
deckSelect(gameId: number, params: Data.DeckSelectParams): void;
|
||||
setSideboardPlan(gameId: number, params: Data.SetSideboardPlanParams): void;
|
||||
setSideboardLock(gameId: number, params: Data.SetSideboardLockParams): void;
|
||||
mulligan(gameId: number, params: Data.MulliganParams): void;
|
||||
rollDie(gameId: number, params: Data.RollDieParams): void;
|
||||
}
|
||||
|
||||
export interface IWebClientRequest {
|
||||
authentication: IAuthenticationRequest;
|
||||
session: ISessionRequest;
|
||||
rooms: IRoomsRequest;
|
||||
game: IGameRequest;
|
||||
admin: IAdminRequest;
|
||||
moderator: IModeratorRequest;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -50,12 +50,14 @@ export interface ISessionResponse {
|
|||
deleteServerDeck(deckId: number): void;
|
||||
updateServerDecks(deckList: Data.Response_DeckList): void;
|
||||
uploadServerDeck(path: string, treeItem: Data.ServerInfo_DeckStorage_TreeItem): void;
|
||||
downloadServerDeck(deckId: number, response: Data.Response_DeckDownload): void;
|
||||
createServerDeckDir(path: string, dirName: string): void;
|
||||
deleteServerDeckDir(path: string): void;
|
||||
replayList(matchList: Data.ServerInfo_ReplayMatch[]): void;
|
||||
replayAdded(matchInfo: Data.ServerInfo_ReplayMatch): void;
|
||||
replayModifyMatch(gameId: number, doNotHide: boolean): void;
|
||||
replayDeleteMatch(gameId: number): void;
|
||||
replayDownloaded(replayId: number, response: Data.Response_ReplayDownload): void;
|
||||
}
|
||||
|
||||
export interface IRoomResponse {
|
||||
|
|
|
|||
|
|
@ -11,6 +11,7 @@ export type {
|
|||
IAuthenticationRequest,
|
||||
ISessionRequest,
|
||||
IRoomsRequest,
|
||||
IGameRequest,
|
||||
IAdminRequest,
|
||||
IModeratorRequest,
|
||||
IWebClientRequest,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue