add missing requests/responses

This commit is contained in:
seavor 2026-04-16 01:28:42 -05:00
parent f0c3581d26
commit 4b5f66d497
27 changed files with 382 additions and 10 deletions

View file

@ -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);

View file

@ -31,3 +31,4 @@ export { deckSelect } from './deckSelect';
export { setSideboardPlan } from './setSideboardPlan';
export { setSideboardLock } from './setSideboardLock';
export { mulligan } from './mulligan';
export { rollDie } from './rollDie';

View 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));
}

View 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);
},
}
);
}

View file

@ -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';

View 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);
},
}
);
}

View file

@ -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);
});
});