mirror of
https://github.com/Cockatrice/Cockatrice.git
synced 2026-04-27 07:48:01 -07:00
refactor typescript wiring
This commit is contained in:
parent
cea9ae62d8
commit
c62c336a11
286 changed files with 2999 additions and 3053 deletions
|
|
@ -1,10 +1,10 @@
|
|||
const captured = vi.hoisted(() => ({
|
||||
wsOptions: null as any,
|
||||
pbOptions: null as any,
|
||||
wsOptions: null as WebSocketServiceConfig | null,
|
||||
pbOptions: null as SocketTransport | null,
|
||||
}));
|
||||
|
||||
vi.mock('./services/WebSocketService', () => ({
|
||||
WebSocketService: vi.fn().mockImplementation(function WebSocketServiceImpl(options: any) {
|
||||
WebSocketService: vi.fn().mockImplementation(function WebSocketServiceImpl(options: WebSocketServiceConfig) {
|
||||
captured.wsOptions = options;
|
||||
return {
|
||||
message$: { subscribe: vi.fn() },
|
||||
|
|
@ -18,7 +18,7 @@ vi.mock('./services/WebSocketService', () => ({
|
|||
}));
|
||||
|
||||
vi.mock('./services/ProtobufService', () => ({
|
||||
ProtobufService: vi.fn().mockImplementation(function ProtobufServiceImpl(options: any) {
|
||||
ProtobufService: vi.fn().mockImplementation(function ProtobufServiceImpl(options: SocketTransport) {
|
||||
captured.pbOptions = options;
|
||||
return {
|
||||
handleMessageEvent: vi.fn(),
|
||||
|
|
@ -32,7 +32,7 @@ vi.mock('./persistence', () => ({
|
|||
SessionPersistence: { clearStore: vi.fn(), initialized: vi.fn(), connectionAttempted: vi.fn() },
|
||||
}));
|
||||
|
||||
vi.mock('store', () => ({
|
||||
vi.mock('@app/store', () => ({
|
||||
GameDispatch: { clearStore: vi.fn() },
|
||||
}));
|
||||
|
||||
|
|
@ -45,17 +45,18 @@ import { WebSocketService } from './services/WebSocketService';
|
|||
import { ProtobufService } from './services/ProtobufService';
|
||||
import { RoomPersistence, SessionPersistence } from './persistence';
|
||||
import { ping } from './commands/session';
|
||||
import { StatusEnum } from 'types';
|
||||
import { App, Enriched } from '@app/types';
|
||||
import { Subject } from 'rxjs';
|
||||
import { Mock } from 'vitest';
|
||||
import { SocketTransport } from './services/ProtobufService';
|
||||
import { WebSocketServiceConfig } from './services/WebSocketService';
|
||||
|
||||
describe('WebClient', () => {
|
||||
let client: WebClient;
|
||||
let messageSubject: Subject<MessageEvent>;
|
||||
|
||||
beforeEach(() => {
|
||||
vi.clearAllMocks();
|
||||
(ProtobufService as Mock).mockImplementation(function ProtobufServiceImpl(options: any) {
|
||||
(ProtobufService as Mock).mockImplementation(function ProtobufServiceImpl(options: SocketTransport) {
|
||||
captured.pbOptions = options;
|
||||
return {
|
||||
handleMessageEvent: vi.fn(),
|
||||
|
|
@ -63,7 +64,7 @@ describe('WebClient', () => {
|
|||
};
|
||||
});
|
||||
messageSubject = new Subject<MessageEvent>();
|
||||
(WebSocketService as Mock).mockImplementation(function WebSocketServiceImpl(options: any) {
|
||||
(WebSocketService as Mock).mockImplementation(function WebSocketServiceImpl(options: WebSocketServiceConfig) {
|
||||
captured.wsOptions = options;
|
||||
return {
|
||||
message$: messageSubject,
|
||||
|
|
@ -97,13 +98,13 @@ describe('WebClient', () => {
|
|||
|
||||
describe('connect', () => {
|
||||
it('calls SessionPersistence.connectionAttempted', () => {
|
||||
const opts: any = { host: 'h', port: 1 };
|
||||
const opts: Enriched.WebSocketConnectOptions = { host: 'h', port: '1', reason: App.WebSocketConnectReason.LOGIN, userName: 'u' };
|
||||
client.connect(opts);
|
||||
expect(SessionPersistence.connectionAttempted).toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it('stores options and calls socket.connect', () => {
|
||||
const opts: any = { host: 'h', port: 1 };
|
||||
const opts: Enriched.WebSocketConnectOptions = { host: 'h', port: '1', reason: App.WebSocketConnectReason.LOGIN, userName: 'u' };
|
||||
client.connect(opts);
|
||||
expect(client.options).toBe(opts);
|
||||
expect(client.socket.connect).toHaveBeenCalledWith(opts);
|
||||
|
|
@ -112,7 +113,7 @@ describe('WebClient', () => {
|
|||
|
||||
describe('testConnect', () => {
|
||||
it('delegates to socket.testConnect', () => {
|
||||
const opts: any = { host: 'h', port: 1 };
|
||||
const opts: Enriched.WebSocketConnectOptions = { host: 'h', port: '1', reason: App.WebSocketConnectReason.LOGIN, userName: 'u' };
|
||||
client.testConnect(opts);
|
||||
expect(client.socket.testConnect).toHaveBeenCalledWith(opts);
|
||||
});
|
||||
|
|
@ -127,19 +128,19 @@ describe('WebClient', () => {
|
|||
|
||||
describe('updateStatus', () => {
|
||||
it('sets the status', () => {
|
||||
client.updateStatus(StatusEnum.CONNECTED);
|
||||
expect(client.status).toBe(StatusEnum.CONNECTED);
|
||||
client.updateStatus(App.StatusEnum.CONNECTED);
|
||||
expect(client.status).toBe(App.StatusEnum.CONNECTED);
|
||||
});
|
||||
|
||||
it('calls protobuf.resetCommands and clears stores on DISCONNECTED', () => {
|
||||
client.updateStatus(StatusEnum.DISCONNECTED);
|
||||
client.updateStatus(App.StatusEnum.DISCONNECTED);
|
||||
expect(client.protobuf.resetCommands).toHaveBeenCalled();
|
||||
expect(RoomPersistence.clearStore).toHaveBeenCalled();
|
||||
expect(SessionPersistence.clearStore).toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it('does not clear stores when status is not DISCONNECTED', () => {
|
||||
client.updateStatus(StatusEnum.CONNECTED);
|
||||
client.updateStatus(App.StatusEnum.CONNECTED);
|
||||
expect(client.protobuf.resetCommands).not.toHaveBeenCalled();
|
||||
expect(RoomPersistence.clearStore).not.toHaveBeenCalled();
|
||||
});
|
||||
|
|
|
|||
|
|
@ -1,18 +1,18 @@
|
|||
import { StatusEnum, WebSocketConnectOptions } from 'types';
|
||||
import { App, Enriched } from '@app/types';
|
||||
|
||||
import { ProtobufService } from './services/ProtobufService';
|
||||
import { WebSocketService } from './services/WebSocketService';
|
||||
import { ping } from './commands/session';
|
||||
|
||||
import { GameDispatch } from 'store';
|
||||
import { GameDispatch } from '@app/store';
|
||||
import { RoomPersistence, SessionPersistence } from './persistence';
|
||||
|
||||
export class WebClient {
|
||||
public socket: WebSocketService;
|
||||
public protobuf: ProtobufService;
|
||||
|
||||
public options: WebSocketConnectOptions;
|
||||
public status: StatusEnum;
|
||||
public options: Enriched.WebSocketConnectOptions | null = null;
|
||||
public status: App.StatusEnum;
|
||||
|
||||
constructor() {
|
||||
this.socket = new WebSocketService({
|
||||
|
|
@ -35,13 +35,13 @@ export class WebClient {
|
|||
}
|
||||
}
|
||||
|
||||
public connect(options: WebSocketConnectOptions) {
|
||||
public connect(options: Enriched.WebSocketConnectOptions) {
|
||||
SessionPersistence.connectionAttempted();
|
||||
this.options = options;
|
||||
this.socket.connect(options);
|
||||
}
|
||||
|
||||
public testConnect(options: WebSocketConnectOptions) {
|
||||
public testConnect(options: Enriched.WebSocketConnectOptions) {
|
||||
this.socket.testConnect(options);
|
||||
}
|
||||
|
||||
|
|
@ -49,10 +49,10 @@ export class WebClient {
|
|||
this.socket.disconnect();
|
||||
}
|
||||
|
||||
public updateStatus(status: StatusEnum) {
|
||||
public updateStatus(status: App.StatusEnum) {
|
||||
this.status = status;
|
||||
|
||||
if (status === StatusEnum.DISCONNECTED) {
|
||||
if (status === App.StatusEnum.DISCONNECTED) {
|
||||
this.protobuf.resetCommands();
|
||||
this.clearStores();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,12 +1,16 @@
|
|||
import { create } from '@bufbuild/protobuf';
|
||||
import { Data } from '@app/types';
|
||||
import webClient from '../../WebClient';
|
||||
import { Command_AdjustMod_ext, Command_AdjustModSchema } from 'generated/proto/admin_commands_pb';
|
||||
import { AdminPersistence } from '../../persistence';
|
||||
|
||||
export function adjustMod(userName: string, shouldBeMod?: boolean, shouldBeJudge?: boolean): void {
|
||||
webClient.protobuf.sendAdminCommand(Command_AdjustMod_ext, create(Command_AdjustModSchema, { userName, shouldBeMod, shouldBeJudge }), {
|
||||
onSuccess: () => {
|
||||
AdminPersistence.adjustMod(userName, shouldBeMod, shouldBeJudge);
|
||||
},
|
||||
});
|
||||
webClient.protobuf.sendAdminCommand(
|
||||
Data.Command_AdjustMod_ext,
|
||||
create(Data.Command_AdjustModSchema, { userName, shouldBeMod, shouldBeJudge }),
|
||||
{
|
||||
onSuccess: () => {
|
||||
AdminPersistence.adjustMod(userName, shouldBeMod, shouldBeJudge);
|
||||
},
|
||||
}
|
||||
);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -27,8 +27,6 @@ const { invokeOnSuccess } = makeCallbackHelpers(
|
|||
2
|
||||
);
|
||||
|
||||
beforeEach(() => vi.clearAllMocks());
|
||||
|
||||
// ----------------------------------------------------------------
|
||||
// adjustMod
|
||||
// ----------------------------------------------------------------
|
||||
|
|
|
|||
|
|
@ -1,10 +1,10 @@
|
|||
import { create } from '@bufbuild/protobuf';
|
||||
import { Data } from '@app/types';
|
||||
import webClient from '../../WebClient';
|
||||
import { Command_ReloadConfig_ext, Command_ReloadConfigSchema } from 'generated/proto/admin_commands_pb';
|
||||
import { AdminPersistence } from '../../persistence';
|
||||
|
||||
export function reloadConfig(): void {
|
||||
webClient.protobuf.sendAdminCommand(Command_ReloadConfig_ext, create(Command_ReloadConfigSchema), {
|
||||
webClient.protobuf.sendAdminCommand(Data.Command_ReloadConfig_ext, create(Data.Command_ReloadConfigSchema), {
|
||||
onSuccess: () => {
|
||||
AdminPersistence.reloadConfig();
|
||||
},
|
||||
|
|
|
|||
|
|
@ -1,10 +1,10 @@
|
|||
import { create } from '@bufbuild/protobuf';
|
||||
import { Data } from '@app/types';
|
||||
import webClient from '../../WebClient';
|
||||
import { Command_ShutdownServer_ext, Command_ShutdownServerSchema } from 'generated/proto/admin_commands_pb';
|
||||
import { AdminPersistence } from '../../persistence';
|
||||
|
||||
export function shutdownServer(reason: string, minutes: number): void {
|
||||
webClient.protobuf.sendAdminCommand(Command_ShutdownServer_ext, create(Command_ShutdownServerSchema, { reason, minutes }), {
|
||||
webClient.protobuf.sendAdminCommand(Data.Command_ShutdownServer_ext, create(Data.Command_ShutdownServerSchema, { reason, minutes }), {
|
||||
onSuccess: () => {
|
||||
AdminPersistence.shutdownServer();
|
||||
},
|
||||
|
|
|
|||
|
|
@ -1,10 +1,10 @@
|
|||
import { create } from '@bufbuild/protobuf';
|
||||
import { Data } from '@app/types';
|
||||
import webClient from '../../WebClient';
|
||||
import { Command_UpdateServerMessage_ext, Command_UpdateServerMessageSchema } from 'generated/proto/admin_commands_pb';
|
||||
import { AdminPersistence } from '../../persistence';
|
||||
|
||||
export function updateServerMessage(): void {
|
||||
webClient.protobuf.sendAdminCommand(Command_UpdateServerMessage_ext, create(Command_UpdateServerMessageSchema), {
|
||||
webClient.protobuf.sendAdminCommand(Data.Command_UpdateServerMessage_ext, create(Data.Command_UpdateServerMessageSchema), {
|
||||
onSuccess: () => {
|
||||
AdminPersistence.updateServerMessage();
|
||||
},
|
||||
|
|
|
|||
|
|
@ -1,8 +1,8 @@
|
|||
import { create } from '@bufbuild/protobuf';
|
||||
import webClient from '../../WebClient';
|
||||
import { Command_AttachCardSchema, Command_AttachCard_ext } from 'generated/proto/command_attach_card_pb';
|
||||
import { AttachCardParams } from 'types';
|
||||
|
||||
export function attachCard(gameId: number, params: AttachCardParams): void {
|
||||
webClient.protobuf.sendGameCommand(gameId, Command_AttachCard_ext, create(Command_AttachCardSchema, params));
|
||||
import { Data } from '@app/types';
|
||||
|
||||
export function attachCard(gameId: number, params: Data.AttachCardParams): void {
|
||||
webClient.protobuf.sendGameCommand(gameId, Data.Command_AttachCard_ext, create(Data.Command_AttachCardSchema, params));
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,8 +1,12 @@
|
|||
import { create } from '@bufbuild/protobuf';
|
||||
import webClient from '../../WebClient';
|
||||
import { Command_ChangeZonePropertiesSchema, Command_ChangeZoneProperties_ext } from 'generated/proto/command_change_zone_properties_pb';
|
||||
import { ChangeZonePropertiesParams } from 'types';
|
||||
|
||||
export function changeZoneProperties(gameId: number, params: ChangeZonePropertiesParams): void {
|
||||
webClient.protobuf.sendGameCommand(gameId, Command_ChangeZoneProperties_ext, create(Command_ChangeZonePropertiesSchema, params));
|
||||
import { Data } from '@app/types';
|
||||
|
||||
export function changeZoneProperties(gameId: number, params: Data.ChangeZonePropertiesParams): void {
|
||||
webClient.protobuf.sendGameCommand(
|
||||
gameId,
|
||||
Data.Command_ChangeZoneProperties_ext,
|
||||
create(Data.Command_ChangeZonePropertiesSchema, params)
|
||||
);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
import { create } from '@bufbuild/protobuf';
|
||||
import webClient from '../../WebClient';
|
||||
import { Command_ConcedeSchema, Command_Concede_ext } from 'generated/proto/command_concede_pb';
|
||||
import { Data } from '@app/types';
|
||||
|
||||
export function concede(gameId: number): void {
|
||||
webClient.protobuf.sendGameCommand(gameId, Command_Concede_ext, create(Command_ConcedeSchema));
|
||||
webClient.protobuf.sendGameCommand(gameId, Data.Command_Concede_ext, create(Data.Command_ConcedeSchema));
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,8 +1,8 @@
|
|||
import { create } from '@bufbuild/protobuf';
|
||||
import webClient from '../../WebClient';
|
||||
import { Command_CreateArrowSchema, Command_CreateArrow_ext } from 'generated/proto/command_create_arrow_pb';
|
||||
import { CreateArrowParams } from 'types';
|
||||
|
||||
export function createArrow(gameId: number, params: CreateArrowParams): void {
|
||||
webClient.protobuf.sendGameCommand(gameId, Command_CreateArrow_ext, create(Command_CreateArrowSchema, params));
|
||||
import { Data } from '@app/types';
|
||||
|
||||
export function createArrow(gameId: number, params: Data.CreateArrowParams): void {
|
||||
webClient.protobuf.sendGameCommand(gameId, Data.Command_CreateArrow_ext, create(Data.Command_CreateArrowSchema, params));
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,8 +1,8 @@
|
|||
import { create } from '@bufbuild/protobuf';
|
||||
import webClient from '../../WebClient';
|
||||
import { Command_CreateCounterSchema, Command_CreateCounter_ext } from 'generated/proto/command_create_counter_pb';
|
||||
import { CreateCounterParams } from 'types';
|
||||
|
||||
export function createCounter(gameId: number, params: CreateCounterParams): void {
|
||||
webClient.protobuf.sendGameCommand(gameId, Command_CreateCounter_ext, create(Command_CreateCounterSchema, params));
|
||||
import { Data } from '@app/types';
|
||||
|
||||
export function createCounter(gameId: number, params: Data.CreateCounterParams): void {
|
||||
webClient.protobuf.sendGameCommand(gameId, Data.Command_CreateCounter_ext, create(Data.Command_CreateCounterSchema, params));
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,8 +1,8 @@
|
|||
import { create } from '@bufbuild/protobuf';
|
||||
import webClient from '../../WebClient';
|
||||
import { Command_CreateTokenSchema, Command_CreateToken_ext } from 'generated/proto/command_create_token_pb';
|
||||
import { CreateTokenParams } from 'types';
|
||||
|
||||
export function createToken(gameId: number, params: CreateTokenParams): void {
|
||||
webClient.protobuf.sendGameCommand(gameId, Command_CreateToken_ext, create(Command_CreateTokenSchema, params));
|
||||
import { Data } from '@app/types';
|
||||
|
||||
export function createToken(gameId: number, params: Data.CreateTokenParams): void {
|
||||
webClient.protobuf.sendGameCommand(gameId, Data.Command_CreateToken_ext, create(Data.Command_CreateTokenSchema, params));
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,8 +1,8 @@
|
|||
import { create } from '@bufbuild/protobuf';
|
||||
import webClient from '../../WebClient';
|
||||
import { Command_DeckSelectSchema, Command_DeckSelect_ext } from 'generated/proto/command_deck_select_pb';
|
||||
import { DeckSelectParams } from 'types';
|
||||
|
||||
export function deckSelect(gameId: number, params: DeckSelectParams): void {
|
||||
webClient.protobuf.sendGameCommand(gameId, Command_DeckSelect_ext, create(Command_DeckSelectSchema, params));
|
||||
import { Data } from '@app/types';
|
||||
|
||||
export function deckSelect(gameId: number, params: Data.DeckSelectParams): void {
|
||||
webClient.protobuf.sendGameCommand(gameId, Data.Command_DeckSelect_ext, create(Data.Command_DeckSelectSchema, params));
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,8 +1,8 @@
|
|||
import { create } from '@bufbuild/protobuf';
|
||||
import webClient from '../../WebClient';
|
||||
import { Command_DelCounterSchema, Command_DelCounter_ext } from 'generated/proto/command_del_counter_pb';
|
||||
import { DelCounterParams } from 'types';
|
||||
|
||||
export function delCounter(gameId: number, params: DelCounterParams): void {
|
||||
webClient.protobuf.sendGameCommand(gameId, Command_DelCounter_ext, create(Command_DelCounterSchema, params));
|
||||
import { Data } from '@app/types';
|
||||
|
||||
export function delCounter(gameId: number, params: Data.DelCounterParams): void {
|
||||
webClient.protobuf.sendGameCommand(gameId, Data.Command_DelCounter_ext, create(Data.Command_DelCounterSchema, params));
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,8 +1,8 @@
|
|||
import { create } from '@bufbuild/protobuf';
|
||||
import webClient from '../../WebClient';
|
||||
import { Command_DeleteArrowSchema, Command_DeleteArrow_ext } from 'generated/proto/command_delete_arrow_pb';
|
||||
import { DeleteArrowParams } from 'types';
|
||||
|
||||
export function deleteArrow(gameId: number, params: DeleteArrowParams): void {
|
||||
webClient.protobuf.sendGameCommand(gameId, Command_DeleteArrow_ext, create(Command_DeleteArrowSchema, params));
|
||||
import { Data } from '@app/types';
|
||||
|
||||
export function deleteArrow(gameId: number, params: Data.DeleteArrowParams): void {
|
||||
webClient.protobuf.sendGameCommand(gameId, Data.Command_DeleteArrow_ext, create(Data.Command_DeleteArrowSchema, params));
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,8 +1,8 @@
|
|||
import { create } from '@bufbuild/protobuf';
|
||||
import webClient from '../../WebClient';
|
||||
import { Command_DrawCardsSchema, Command_DrawCards_ext } from 'generated/proto/command_draw_cards_pb';
|
||||
import { DrawCardsParams } from 'types';
|
||||
|
||||
export function drawCards(gameId: number, params: DrawCardsParams): void {
|
||||
webClient.protobuf.sendGameCommand(gameId, Command_DrawCards_ext, create(Command_DrawCardsSchema, params));
|
||||
import { Data } from '@app/types';
|
||||
|
||||
export function drawCards(gameId: number, params: Data.DrawCardsParams): void {
|
||||
webClient.protobuf.sendGameCommand(gameId, Data.Command_DrawCards_ext, create(Data.Command_DrawCardsSchema, params));
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,8 +1,8 @@
|
|||
import { create } from '@bufbuild/protobuf';
|
||||
import webClient from '../../WebClient';
|
||||
import { Command_DumpZoneSchema, Command_DumpZone_ext } from 'generated/proto/command_dump_zone_pb';
|
||||
import { DumpZoneParams } from 'types';
|
||||
|
||||
export function dumpZone(gameId: number, params: DumpZoneParams): void {
|
||||
webClient.protobuf.sendGameCommand(gameId, Command_DumpZone_ext, create(Command_DumpZoneSchema, params));
|
||||
import { Data } from '@app/types';
|
||||
|
||||
export function dumpZone(gameId: number, params: Data.DumpZoneParams): void {
|
||||
webClient.protobuf.sendGameCommand(gameId, Data.Command_DumpZone_ext, create(Data.Command_DumpZoneSchema, params));
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,8 +1,8 @@
|
|||
import { create } from '@bufbuild/protobuf';
|
||||
import webClient from '../../WebClient';
|
||||
import { Command_FlipCardSchema, Command_FlipCard_ext } from 'generated/proto/command_flip_card_pb';
|
||||
import { FlipCardParams } from 'types';
|
||||
|
||||
export function flipCard(gameId: number, params: FlipCardParams): void {
|
||||
webClient.protobuf.sendGameCommand(gameId, Command_FlipCard_ext, create(Command_FlipCardSchema, params));
|
||||
import { Data } from '@app/types';
|
||||
|
||||
export function flipCard(gameId: number, params: Data.FlipCardParams): void {
|
||||
webClient.protobuf.sendGameCommand(gameId, Data.Command_FlipCard_ext, create(Data.Command_FlipCardSchema, params));
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,37 +1,7 @@
|
|||
import webClient from '../../WebClient';
|
||||
import { create, setExtension } from '@bufbuild/protobuf';
|
||||
import { GameCommandSchema, Command_Judge_ext } from 'generated/proto/game_commands_pb';
|
||||
import { Command_DrawCardsSchema, Command_DrawCards_ext } from 'generated/proto/command_draw_cards_pb';
|
||||
import { Command_AttachCard_ext } from 'generated/proto/command_attach_card_pb';
|
||||
import { Command_ChangeZoneProperties_ext } from 'generated/proto/command_change_zone_properties_pb';
|
||||
import { Command_Concede_ext, Command_Unconcede_ext } from 'generated/proto/command_concede_pb';
|
||||
import { Command_CreateArrow_ext } from 'generated/proto/command_create_arrow_pb';
|
||||
import { Command_CreateCounter_ext } from 'generated/proto/command_create_counter_pb';
|
||||
import { Command_CreateToken_ext } from 'generated/proto/command_create_token_pb';
|
||||
import { Command_DeckSelect_ext } from 'generated/proto/command_deck_select_pb';
|
||||
import { Command_DelCounter_ext } from 'generated/proto/command_del_counter_pb';
|
||||
import { Command_DeleteArrow_ext } from 'generated/proto/command_delete_arrow_pb';
|
||||
import { Command_DumpZone_ext } from 'generated/proto/command_dump_zone_pb';
|
||||
import { Command_FlipCard_ext } from 'generated/proto/command_flip_card_pb';
|
||||
import { Command_GameSay_ext } from 'generated/proto/command_game_say_pb';
|
||||
import { Command_IncCardCounter_ext } from 'generated/proto/command_inc_card_counter_pb';
|
||||
import { Command_IncCounter_ext } from 'generated/proto/command_inc_counter_pb';
|
||||
import { Command_KickFromGame_ext } from 'generated/proto/command_kick_from_game_pb';
|
||||
import { Command_LeaveGame_ext } from 'generated/proto/command_leave_game_pb';
|
||||
import { Command_MoveCard_ext } from 'generated/proto/command_move_card_pb';
|
||||
import { Command_Mulligan_ext } from 'generated/proto/command_mulligan_pb';
|
||||
import { Command_NextTurn_ext } from 'generated/proto/command_next_turn_pb';
|
||||
import { Command_ReadyStart_ext } from 'generated/proto/command_ready_start_pb';
|
||||
import { Command_RevealCards_ext } from 'generated/proto/command_reveal_cards_pb';
|
||||
import { Command_ReverseTurn_ext } from 'generated/proto/command_reverse_turn_pb';
|
||||
import { Command_SetActivePhase_ext } from 'generated/proto/command_set_active_phase_pb';
|
||||
import { Command_SetCardAttr_ext } from 'generated/proto/command_set_card_attr_pb';
|
||||
import { Command_SetCardCounter_ext } from 'generated/proto/command_set_card_counter_pb';
|
||||
import { Command_SetCounter_ext } from 'generated/proto/command_set_counter_pb';
|
||||
import { Command_SetSideboardLock_ext } from 'generated/proto/command_set_sideboard_lock_pb';
|
||||
import { Command_SetSideboardPlan_ext } from 'generated/proto/command_set_sideboard_plan_pb';
|
||||
import { Command_Shuffle_ext } from 'generated/proto/command_shuffle_pb';
|
||||
import { Command_UndoDraw_ext } from 'generated/proto/command_undo_draw_pb';
|
||||
import { Data } from '@app/types';
|
||||
|
||||
import { attachCard } from './attachCard';
|
||||
import { changeZoneProperties } from './changeZoneProperties';
|
||||
import { concede } from './concede';
|
||||
|
|
@ -73,128 +43,126 @@ vi.mock('../../WebClient', () => ({
|
|||
|
||||
const gameId = 1;
|
||||
|
||||
import { Mock } from 'vitest';
|
||||
|
||||
beforeEach(() => {
|
||||
(webClient.protobuf.sendGameCommand as Mock).mockClear();
|
||||
});
|
||||
|
||||
describe('Game commands — delegate to webClient.protobuf.sendGameCommand', () => {
|
||||
it('attachCard sends Command_AttachCard', () => {
|
||||
attachCard(gameId, { cardId: 10, startZone: 'hand' });
|
||||
expect(webClient.protobuf.sendGameCommand).toHaveBeenCalledWith(
|
||||
gameId, Command_AttachCard_ext, expect.objectContaining({ cardId: 10, startZone: 'hand' })
|
||||
gameId, Data.Command_AttachCard_ext, expect.objectContaining({ cardId: 10, startZone: 'hand' })
|
||||
);
|
||||
});
|
||||
|
||||
it('changeZoneProperties sends Command_ChangeZoneProperties', () => {
|
||||
changeZoneProperties(gameId, { zoneName: 'side' });
|
||||
expect(webClient.protobuf.sendGameCommand).toHaveBeenCalledWith(
|
||||
gameId, Command_ChangeZoneProperties_ext, expect.objectContaining({ zoneName: 'side' })
|
||||
gameId, Data.Command_ChangeZoneProperties_ext, expect.objectContaining({ zoneName: 'side' })
|
||||
);
|
||||
});
|
||||
|
||||
it('concede sends Command_Concede with empty object', () => {
|
||||
concede(gameId);
|
||||
expect(webClient.protobuf.sendGameCommand).toHaveBeenCalledWith(gameId, Command_Concede_ext, expect.any(Object));
|
||||
expect(webClient.protobuf.sendGameCommand).toHaveBeenCalledWith(gameId, Data.Command_Concede_ext, expect.any(Object));
|
||||
});
|
||||
|
||||
it('createArrow sends Command_CreateArrow', () => {
|
||||
createArrow(gameId, { startPlayerId: 1, startZone: 'hand' });
|
||||
expect(webClient.protobuf.sendGameCommand).toHaveBeenCalledWith(
|
||||
gameId, Command_CreateArrow_ext, expect.objectContaining({ startPlayerId: 1, startZone: 'hand' })
|
||||
gameId, Data.Command_CreateArrow_ext, expect.objectContaining({ startPlayerId: 1, startZone: 'hand' })
|
||||
);
|
||||
});
|
||||
|
||||
it('createCounter sends Command_CreateCounter', () => {
|
||||
createCounter(gameId, { counterName: 'life' });
|
||||
expect(webClient.protobuf.sendGameCommand).toHaveBeenCalledWith(
|
||||
gameId, Command_CreateCounter_ext, expect.objectContaining({ counterName: 'life' })
|
||||
gameId, Data.Command_CreateCounter_ext, expect.objectContaining({ counterName: 'life' })
|
||||
);
|
||||
});
|
||||
|
||||
it('createToken sends Command_CreateToken', () => {
|
||||
createToken(gameId, { cardName: 'Goblin', zone: 'play' });
|
||||
expect(webClient.protobuf.sendGameCommand).toHaveBeenCalledWith(
|
||||
gameId, Command_CreateToken_ext, expect.objectContaining({ cardName: 'Goblin', zone: 'play' })
|
||||
gameId, Data.Command_CreateToken_ext, expect.objectContaining({ cardName: 'Goblin', zone: 'play' })
|
||||
);
|
||||
});
|
||||
|
||||
it('deckSelect sends Command_DeckSelect', () => {
|
||||
deckSelect(gameId, { deckId: 5 });
|
||||
expect(webClient.protobuf.sendGameCommand).toHaveBeenCalledWith(gameId, Command_DeckSelect_ext, expect.objectContaining({ deckId: 5 }));
|
||||
expect(webClient.protobuf.sendGameCommand).toHaveBeenCalledWith(
|
||||
gameId, Data.Command_DeckSelect_ext, expect.objectContaining({ deckId: 5 })
|
||||
);
|
||||
});
|
||||
|
||||
it('delCounter sends Command_DelCounter', () => {
|
||||
delCounter(gameId, { counterId: 3 });
|
||||
expect(webClient.protobuf.sendGameCommand).toHaveBeenCalledWith(
|
||||
gameId, Command_DelCounter_ext, expect.objectContaining({ counterId: 3 })
|
||||
gameId, Data.Command_DelCounter_ext, expect.objectContaining({ counterId: 3 })
|
||||
);
|
||||
});
|
||||
|
||||
it('deleteArrow sends Command_DeleteArrow', () => {
|
||||
deleteArrow(gameId, { arrowId: 2 });
|
||||
expect(webClient.protobuf.sendGameCommand).toHaveBeenCalledWith(
|
||||
gameId, Command_DeleteArrow_ext, expect.objectContaining({ arrowId: 2 })
|
||||
gameId, Data.Command_DeleteArrow_ext, expect.objectContaining({ arrowId: 2 })
|
||||
);
|
||||
});
|
||||
|
||||
it('drawCards sends Command_DrawCards', () => {
|
||||
drawCards(gameId, { number: 3 });
|
||||
expect(webClient.protobuf.sendGameCommand).toHaveBeenCalledWith(gameId, Command_DrawCards_ext, expect.objectContaining({ number: 3 }));
|
||||
expect(webClient.protobuf.sendGameCommand).toHaveBeenCalledWith(
|
||||
gameId, Data.Command_DrawCards_ext, expect.objectContaining({ number: 3 })
|
||||
);
|
||||
});
|
||||
|
||||
it('dumpZone sends Command_DumpZone', () => {
|
||||
dumpZone(gameId, { playerId: 2, zoneName: 'library' });
|
||||
expect(webClient.protobuf.sendGameCommand).toHaveBeenCalledWith(
|
||||
gameId, Command_DumpZone_ext, expect.objectContaining({ playerId: 2, zoneName: 'library' })
|
||||
gameId, Data.Command_DumpZone_ext, expect.objectContaining({ playerId: 2, zoneName: 'library' })
|
||||
);
|
||||
});
|
||||
|
||||
it('flipCard sends Command_FlipCard', () => {
|
||||
flipCard(gameId, { cardId: 7, faceDown: false });
|
||||
expect(webClient.protobuf.sendGameCommand).toHaveBeenCalledWith(
|
||||
gameId, Command_FlipCard_ext, expect.objectContaining({ cardId: 7, faceDown: false })
|
||||
gameId, Data.Command_FlipCard_ext, expect.objectContaining({ cardId: 7, faceDown: false })
|
||||
);
|
||||
});
|
||||
|
||||
it('gameSay sends Command_GameSay', () => {
|
||||
gameSay(gameId, { message: 'hello' });
|
||||
expect(webClient.protobuf.sendGameCommand).toHaveBeenCalledWith(
|
||||
gameId, Command_GameSay_ext, expect.objectContaining({ message: 'hello' })
|
||||
gameId, Data.Command_GameSay_ext, expect.objectContaining({ message: 'hello' })
|
||||
);
|
||||
});
|
||||
|
||||
it('incCardCounter sends Command_IncCardCounter', () => {
|
||||
incCardCounter(gameId, { cardId: 5, counterId: 1 });
|
||||
expect(webClient.protobuf.sendGameCommand).toHaveBeenCalledWith(
|
||||
gameId, Command_IncCardCounter_ext, expect.objectContaining({ cardId: 5, counterId: 1 })
|
||||
gameId, Data.Command_IncCardCounter_ext, expect.objectContaining({ cardId: 5, counterId: 1 })
|
||||
);
|
||||
});
|
||||
|
||||
it('incCounter sends Command_IncCounter', () => {
|
||||
incCounter(gameId, { counterId: 1, delta: 5 });
|
||||
expect(webClient.protobuf.sendGameCommand).toHaveBeenCalledWith(
|
||||
gameId, Command_IncCounter_ext, expect.objectContaining({ counterId: 1, delta: 5 })
|
||||
gameId, Data.Command_IncCounter_ext, expect.objectContaining({ counterId: 1, delta: 5 })
|
||||
);
|
||||
});
|
||||
|
||||
it('kickFromGame sends Command_KickFromGame', () => {
|
||||
kickFromGame(gameId, { playerId: 2 });
|
||||
expect(webClient.protobuf.sendGameCommand).toHaveBeenCalledWith(
|
||||
gameId, Command_KickFromGame_ext, expect.objectContaining({ playerId: 2 })
|
||||
gameId, Data.Command_KickFromGame_ext, expect.objectContaining({ playerId: 2 })
|
||||
);
|
||||
});
|
||||
|
||||
it('leaveGame sends Command_LeaveGame with empty object', () => {
|
||||
leaveGame(gameId);
|
||||
expect(webClient.protobuf.sendGameCommand).toHaveBeenCalledWith(gameId, Command_LeaveGame_ext, expect.any(Object));
|
||||
expect(webClient.protobuf.sendGameCommand).toHaveBeenCalledWith(gameId, Data.Command_LeaveGame_ext, expect.any(Object));
|
||||
});
|
||||
|
||||
it('moveCard sends Command_MoveCard', () => {
|
||||
moveCard(gameId, { startZone: 'hand', targetZone: 'graveyard' });
|
||||
expect(webClient.protobuf.sendGameCommand).toHaveBeenCalledWith(
|
||||
gameId, Command_MoveCard_ext,
|
||||
gameId, Data.Command_MoveCard_ext,
|
||||
expect.objectContaining({ startZone: 'hand', targetZone: 'graveyard' })
|
||||
);
|
||||
});
|
||||
|
|
@ -202,45 +170,45 @@ describe('Game commands — delegate to webClient.protobuf.sendGameCommand', ()
|
|||
it('mulligan sends Command_Mulligan', () => {
|
||||
mulligan(gameId, { number: 7 });
|
||||
expect(webClient.protobuf.sendGameCommand).toHaveBeenCalledWith(
|
||||
gameId, Command_Mulligan_ext, expect.objectContaining({ number: 7 })
|
||||
gameId, Data.Command_Mulligan_ext, expect.objectContaining({ number: 7 })
|
||||
);
|
||||
});
|
||||
|
||||
it('nextTurn sends Command_NextTurn with empty object', () => {
|
||||
nextTurn(gameId);
|
||||
expect(webClient.protobuf.sendGameCommand).toHaveBeenCalledWith(gameId, Command_NextTurn_ext, expect.any(Object));
|
||||
expect(webClient.protobuf.sendGameCommand).toHaveBeenCalledWith(gameId, Data.Command_NextTurn_ext, expect.any(Object));
|
||||
});
|
||||
|
||||
it('readyStart sends Command_ReadyStart', () => {
|
||||
readyStart(gameId, { ready: true });
|
||||
expect(webClient.protobuf.sendGameCommand).toHaveBeenCalledWith(
|
||||
gameId, Command_ReadyStart_ext, expect.objectContaining({ ready: true })
|
||||
gameId, Data.Command_ReadyStart_ext, expect.objectContaining({ ready: true })
|
||||
);
|
||||
});
|
||||
|
||||
it('revealCards sends Command_RevealCards', () => {
|
||||
revealCards(gameId, { zoneName: 'hand', cardId: [1, 2] });
|
||||
expect(webClient.protobuf.sendGameCommand).toHaveBeenCalledWith(
|
||||
gameId, Command_RevealCards_ext, expect.objectContaining({ zoneName: 'hand', cardId: [1, 2] })
|
||||
gameId, Data.Command_RevealCards_ext, expect.objectContaining({ zoneName: 'hand', cardId: [1, 2] })
|
||||
);
|
||||
});
|
||||
|
||||
it('reverseTurn sends Command_ReverseTurn with empty object', () => {
|
||||
reverseTurn(gameId);
|
||||
expect(webClient.protobuf.sendGameCommand).toHaveBeenCalledWith(gameId, Command_ReverseTurn_ext, expect.any(Object));
|
||||
expect(webClient.protobuf.sendGameCommand).toHaveBeenCalledWith(gameId, Data.Command_ReverseTurn_ext, expect.any(Object));
|
||||
});
|
||||
|
||||
it('setActivePhase sends Command_SetActivePhase', () => {
|
||||
setActivePhase(gameId, { phase: 2 });
|
||||
expect(webClient.protobuf.sendGameCommand).toHaveBeenCalledWith(
|
||||
gameId, Command_SetActivePhase_ext, expect.objectContaining({ phase: 2 })
|
||||
gameId, Data.Command_SetActivePhase_ext, expect.objectContaining({ phase: 2 })
|
||||
);
|
||||
});
|
||||
|
||||
it('setCardAttr sends Command_SetCardAttr', () => {
|
||||
setCardAttr(gameId, { zone: 'play', cardId: 5, attrValue: '2' });
|
||||
expect(webClient.protobuf.sendGameCommand).toHaveBeenCalledWith(
|
||||
gameId, Command_SetCardAttr_ext,
|
||||
gameId, Data.Command_SetCardAttr_ext,
|
||||
expect.objectContaining({ zone: 'play', cardId: 5, attrValue: '2' })
|
||||
);
|
||||
});
|
||||
|
|
@ -248,56 +216,56 @@ describe('Game commands — delegate to webClient.protobuf.sendGameCommand', ()
|
|||
it('setCardCounter sends Command_SetCardCounter', () => {
|
||||
setCardCounter(gameId, { cardId: 5, counterId: 1 });
|
||||
expect(webClient.protobuf.sendGameCommand).toHaveBeenCalledWith(
|
||||
gameId, Command_SetCardCounter_ext, expect.objectContaining({ cardId: 5, counterId: 1 })
|
||||
gameId, Data.Command_SetCardCounter_ext, expect.objectContaining({ cardId: 5, counterId: 1 })
|
||||
);
|
||||
});
|
||||
|
||||
it('setCounter sends Command_SetCounter', () => {
|
||||
setCounter(gameId, { counterId: 1, value: 10 });
|
||||
expect(webClient.protobuf.sendGameCommand).toHaveBeenCalledWith(
|
||||
gameId, Command_SetCounter_ext, expect.objectContaining({ counterId: 1, value: 10 })
|
||||
gameId, Data.Command_SetCounter_ext, expect.objectContaining({ counterId: 1, value: 10 })
|
||||
);
|
||||
});
|
||||
|
||||
it('setSideboardLock sends Command_SetSideboardLock', () => {
|
||||
setSideboardLock(gameId, { locked: true });
|
||||
expect(webClient.protobuf.sendGameCommand).toHaveBeenCalledWith(
|
||||
gameId, Command_SetSideboardLock_ext, expect.objectContaining({ locked: true })
|
||||
gameId, Data.Command_SetSideboardLock_ext, expect.objectContaining({ locked: true })
|
||||
);
|
||||
});
|
||||
|
||||
it('setSideboardPlan sends Command_SetSideboardPlan', () => {
|
||||
setSideboardPlan(gameId, { moveList: [] });
|
||||
expect(webClient.protobuf.sendGameCommand).toHaveBeenCalledWith(
|
||||
gameId, Command_SetSideboardPlan_ext, expect.objectContaining({ moveList: expect.any(Array) })
|
||||
gameId, Data.Command_SetSideboardPlan_ext, expect.objectContaining({ moveList: expect.any(Array) })
|
||||
);
|
||||
});
|
||||
|
||||
it('shuffle sends Command_Shuffle', () => {
|
||||
shuffle(gameId, { zoneName: 'hand' });
|
||||
expect(webClient.protobuf.sendGameCommand).toHaveBeenCalledWith(
|
||||
gameId, Command_Shuffle_ext, expect.objectContaining({ zoneName: 'hand' })
|
||||
gameId, Data.Command_Shuffle_ext, expect.objectContaining({ zoneName: 'hand' })
|
||||
);
|
||||
});
|
||||
|
||||
it('undoDraw sends Command_UndoDraw with empty object', () => {
|
||||
undoDraw(gameId);
|
||||
expect(webClient.protobuf.sendGameCommand).toHaveBeenCalledWith(gameId, Command_UndoDraw_ext, expect.any(Object));
|
||||
expect(webClient.protobuf.sendGameCommand).toHaveBeenCalledWith(gameId, Data.Command_UndoDraw_ext, expect.any(Object));
|
||||
});
|
||||
|
||||
it('unconcede sends Command_Unconcede with empty object', () => {
|
||||
unconcede(gameId);
|
||||
expect(webClient.protobuf.sendGameCommand).toHaveBeenCalledWith(gameId, Command_Unconcede_ext, expect.any(Object));
|
||||
expect(webClient.protobuf.sendGameCommand).toHaveBeenCalledWith(gameId, Data.Command_Unconcede_ext, expect.any(Object));
|
||||
});
|
||||
|
||||
it('judge sends Command_Judge with targetId and wrapped gameCommand array', () => {
|
||||
const targetId = 3;
|
||||
const innerCmd = create(GameCommandSchema);
|
||||
setExtension(innerCmd, Command_DrawCards_ext, create(Command_DrawCardsSchema, { number: 2 }));
|
||||
const innerCmd = create(Data.GameCommandSchema);
|
||||
setExtension(innerCmd, Data.Command_DrawCards_ext, create(Data.Command_DrawCardsSchema, { number: 2 }));
|
||||
judge(gameId, targetId, innerCmd);
|
||||
expect(webClient.protobuf.sendGameCommand).toHaveBeenCalledWith(
|
||||
gameId,
|
||||
Command_Judge_ext,
|
||||
Data.Command_Judge_ext,
|
||||
expect.objectContaining({ targetId: 3, gameCommand: expect.any(Array) })
|
||||
);
|
||||
});
|
||||
|
|
|
|||
|
|
@ -1,8 +1,8 @@
|
|||
import { create } from '@bufbuild/protobuf';
|
||||
import webClient from '../../WebClient';
|
||||
import { Command_GameSaySchema, Command_GameSay_ext } from 'generated/proto/command_game_say_pb';
|
||||
import { GameSayParams } from 'types';
|
||||
|
||||
export function gameSay(gameId: number, params: GameSayParams): void {
|
||||
webClient.protobuf.sendGameCommand(gameId, Command_GameSay_ext, create(Command_GameSaySchema, params));
|
||||
import { Data } from '@app/types';
|
||||
|
||||
export function gameSay(gameId: number, params: Data.GameSayParams): void {
|
||||
webClient.protobuf.sendGameCommand(gameId, Data.Command_GameSay_ext, create(Data.Command_GameSaySchema, params));
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,8 +1,8 @@
|
|||
import { create } from '@bufbuild/protobuf';
|
||||
import webClient from '../../WebClient';
|
||||
import { Command_IncCardCounterSchema, Command_IncCardCounter_ext } from 'generated/proto/command_inc_card_counter_pb';
|
||||
import { IncCardCounterParams } from 'types';
|
||||
|
||||
export function incCardCounter(gameId: number, params: IncCardCounterParams): void {
|
||||
webClient.protobuf.sendGameCommand(gameId, Command_IncCardCounter_ext, create(Command_IncCardCounterSchema, params));
|
||||
import { Data } from '@app/types';
|
||||
|
||||
export function incCardCounter(gameId: number, params: Data.IncCardCounterParams): void {
|
||||
webClient.protobuf.sendGameCommand(gameId, Data.Command_IncCardCounter_ext, create(Data.Command_IncCardCounterSchema, params));
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,8 +1,8 @@
|
|||
import { create } from '@bufbuild/protobuf';
|
||||
import webClient from '../../WebClient';
|
||||
import { Command_IncCounterSchema, Command_IncCounter_ext } from 'generated/proto/command_inc_counter_pb';
|
||||
import { IncCounterParams } from 'types';
|
||||
|
||||
export function incCounter(gameId: number, params: IncCounterParams): void {
|
||||
webClient.protobuf.sendGameCommand(gameId, Command_IncCounter_ext, create(Command_IncCounterSchema, params));
|
||||
import { Data } from '@app/types';
|
||||
|
||||
export function incCounter(gameId: number, params: Data.IncCounterParams): void {
|
||||
webClient.protobuf.sendGameCommand(gameId, Data.Command_IncCounter_ext, create(Data.Command_IncCounterSchema, params));
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,10 +1,9 @@
|
|||
import { create } from '@bufbuild/protobuf';
|
||||
import webClient from '../../WebClient';
|
||||
import { Command_JudgeSchema, Command_Judge_ext } from 'generated/proto/game_commands_pb';
|
||||
import type { GameCommand } from 'generated/proto/game_commands_pb';
|
||||
import { Data } from '@app/types';
|
||||
|
||||
export function judge(gameId: number, targetId: number, innerGameCommand: GameCommand): void {
|
||||
webClient.protobuf.sendGameCommand(gameId, Command_Judge_ext, create(Command_JudgeSchema, {
|
||||
export function judge(gameId: number, targetId: number, innerGameCommand: Data.GameCommand): void {
|
||||
webClient.protobuf.sendGameCommand(gameId, Data.Command_Judge_ext, create(Data.Command_JudgeSchema, {
|
||||
targetId,
|
||||
gameCommand: [innerGameCommand],
|
||||
}));
|
||||
|
|
|
|||
|
|
@ -1,8 +1,8 @@
|
|||
import { create } from '@bufbuild/protobuf';
|
||||
import webClient from '../../WebClient';
|
||||
import { Command_KickFromGameSchema, Command_KickFromGame_ext } from 'generated/proto/command_kick_from_game_pb';
|
||||
import { KickFromGameParams } from 'types';
|
||||
|
||||
export function kickFromGame(gameId: number, params: KickFromGameParams): void {
|
||||
webClient.protobuf.sendGameCommand(gameId, Command_KickFromGame_ext, create(Command_KickFromGameSchema, params));
|
||||
import { Data } from '@app/types';
|
||||
|
||||
export function kickFromGame(gameId: number, params: Data.KickFromGameParams): void {
|
||||
webClient.protobuf.sendGameCommand(gameId, Data.Command_KickFromGame_ext, create(Data.Command_KickFromGameSchema, params));
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
import { create } from '@bufbuild/protobuf';
|
||||
import webClient from '../../WebClient';
|
||||
import { Command_LeaveGameSchema, Command_LeaveGame_ext } from 'generated/proto/command_leave_game_pb';
|
||||
import { Data } from '@app/types';
|
||||
|
||||
export function leaveGame(gameId: number): void {
|
||||
webClient.protobuf.sendGameCommand(gameId, Command_LeaveGame_ext, create(Command_LeaveGameSchema));
|
||||
webClient.protobuf.sendGameCommand(gameId, Data.Command_LeaveGame_ext, create(Data.Command_LeaveGameSchema));
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,8 +1,8 @@
|
|||
import { create } from '@bufbuild/protobuf';
|
||||
import webClient from '../../WebClient';
|
||||
import { Command_MoveCardSchema, Command_MoveCard_ext } from 'generated/proto/command_move_card_pb';
|
||||
import { MoveCardParams } from 'types';
|
||||
|
||||
export function moveCard(gameId: number, params: MoveCardParams): void {
|
||||
webClient.protobuf.sendGameCommand(gameId, Command_MoveCard_ext, create(Command_MoveCardSchema, params));
|
||||
import { Data } from '@app/types';
|
||||
|
||||
export function moveCard(gameId: number, params: Data.MoveCardParams): void {
|
||||
webClient.protobuf.sendGameCommand(gameId, Data.Command_MoveCard_ext, create(Data.Command_MoveCardSchema, params));
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,8 +1,8 @@
|
|||
import { create } from '@bufbuild/protobuf';
|
||||
import webClient from '../../WebClient';
|
||||
import { Command_MulliganSchema, Command_Mulligan_ext } from 'generated/proto/command_mulligan_pb';
|
||||
import { MulliganParams } from 'types';
|
||||
|
||||
export function mulligan(gameId: number, params: MulliganParams): void {
|
||||
webClient.protobuf.sendGameCommand(gameId, Command_Mulligan_ext, create(Command_MulliganSchema, params));
|
||||
import { Data } from '@app/types';
|
||||
|
||||
export function mulligan(gameId: number, params: Data.MulliganParams): void {
|
||||
webClient.protobuf.sendGameCommand(gameId, Data.Command_Mulligan_ext, create(Data.Command_MulliganSchema, params));
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
import { create } from '@bufbuild/protobuf';
|
||||
import webClient from '../../WebClient';
|
||||
import { Command_NextTurnSchema, Command_NextTurn_ext } from 'generated/proto/command_next_turn_pb';
|
||||
import { Data } from '@app/types';
|
||||
|
||||
export function nextTurn(gameId: number): void {
|
||||
webClient.protobuf.sendGameCommand(gameId, Command_NextTurn_ext, create(Command_NextTurnSchema));
|
||||
webClient.protobuf.sendGameCommand(gameId, Data.Command_NextTurn_ext, create(Data.Command_NextTurnSchema));
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,8 +1,8 @@
|
|||
import { create } from '@bufbuild/protobuf';
|
||||
import webClient from '../../WebClient';
|
||||
import { Command_ReadyStartSchema, Command_ReadyStart_ext } from 'generated/proto/command_ready_start_pb';
|
||||
import { ReadyStartParams } from 'types';
|
||||
|
||||
export function readyStart(gameId: number, params: ReadyStartParams): void {
|
||||
webClient.protobuf.sendGameCommand(gameId, Command_ReadyStart_ext, create(Command_ReadyStartSchema, params));
|
||||
import { Data } from '@app/types';
|
||||
|
||||
export function readyStart(gameId: number, params: Data.ReadyStartParams): void {
|
||||
webClient.protobuf.sendGameCommand(gameId, Data.Command_ReadyStart_ext, create(Data.Command_ReadyStartSchema, params));
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,8 +1,8 @@
|
|||
import { create } from '@bufbuild/protobuf';
|
||||
import webClient from '../../WebClient';
|
||||
import { Command_RevealCardsSchema, Command_RevealCards_ext } from 'generated/proto/command_reveal_cards_pb';
|
||||
import { RevealCardsParams } from 'types';
|
||||
|
||||
export function revealCards(gameId: number, params: RevealCardsParams): void {
|
||||
webClient.protobuf.sendGameCommand(gameId, Command_RevealCards_ext, create(Command_RevealCardsSchema, params));
|
||||
import { Data } from '@app/types';
|
||||
|
||||
export function revealCards(gameId: number, params: Data.RevealCardsParams): void {
|
||||
webClient.protobuf.sendGameCommand(gameId, Data.Command_RevealCards_ext, create(Data.Command_RevealCardsSchema, params));
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
import { create } from '@bufbuild/protobuf';
|
||||
import webClient from '../../WebClient';
|
||||
import { Command_ReverseTurnSchema, Command_ReverseTurn_ext } from 'generated/proto/command_reverse_turn_pb';
|
||||
import { Data } from '@app/types';
|
||||
|
||||
export function reverseTurn(gameId: number): void {
|
||||
webClient.protobuf.sendGameCommand(gameId, Command_ReverseTurn_ext, create(Command_ReverseTurnSchema));
|
||||
webClient.protobuf.sendGameCommand(gameId, Data.Command_ReverseTurn_ext, create(Data.Command_ReverseTurnSchema));
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,8 +1,8 @@
|
|||
import { create } from '@bufbuild/protobuf';
|
||||
import webClient from '../../WebClient';
|
||||
import { Command_SetActivePhaseSchema, Command_SetActivePhase_ext } from 'generated/proto/command_set_active_phase_pb';
|
||||
import { SetActivePhaseParams } from 'types';
|
||||
|
||||
export function setActivePhase(gameId: number, params: SetActivePhaseParams): void {
|
||||
webClient.protobuf.sendGameCommand(gameId, Command_SetActivePhase_ext, create(Command_SetActivePhaseSchema, params));
|
||||
import { Data } from '@app/types';
|
||||
|
||||
export function setActivePhase(gameId: number, params: Data.SetActivePhaseParams): void {
|
||||
webClient.protobuf.sendGameCommand(gameId, Data.Command_SetActivePhase_ext, create(Data.Command_SetActivePhaseSchema, params));
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,8 +1,8 @@
|
|||
import { create } from '@bufbuild/protobuf';
|
||||
import webClient from '../../WebClient';
|
||||
import { Command_SetCardAttrSchema, Command_SetCardAttr_ext } from 'generated/proto/command_set_card_attr_pb';
|
||||
import { SetCardAttrParams } from 'types';
|
||||
|
||||
export function setCardAttr(gameId: number, params: SetCardAttrParams): void {
|
||||
webClient.protobuf.sendGameCommand(gameId, Command_SetCardAttr_ext, create(Command_SetCardAttrSchema, params));
|
||||
import { Data } from '@app/types';
|
||||
|
||||
export function setCardAttr(gameId: number, params: Data.SetCardAttrParams): void {
|
||||
webClient.protobuf.sendGameCommand(gameId, Data.Command_SetCardAttr_ext, create(Data.Command_SetCardAttrSchema, params));
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,8 +1,8 @@
|
|||
import { create } from '@bufbuild/protobuf';
|
||||
import webClient from '../../WebClient';
|
||||
import { Command_SetCardCounterSchema, Command_SetCardCounter_ext } from 'generated/proto/command_set_card_counter_pb';
|
||||
import { SetCardCounterParams } from 'types';
|
||||
|
||||
export function setCardCounter(gameId: number, params: SetCardCounterParams): void {
|
||||
webClient.protobuf.sendGameCommand(gameId, Command_SetCardCounter_ext, create(Command_SetCardCounterSchema, params));
|
||||
import { Data } from '@app/types';
|
||||
|
||||
export function setCardCounter(gameId: number, params: Data.SetCardCounterParams): void {
|
||||
webClient.protobuf.sendGameCommand(gameId, Data.Command_SetCardCounter_ext, create(Data.Command_SetCardCounterSchema, params));
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,8 +1,8 @@
|
|||
import { create } from '@bufbuild/protobuf';
|
||||
import webClient from '../../WebClient';
|
||||
import { Command_SetCounterSchema, Command_SetCounter_ext } from 'generated/proto/command_set_counter_pb';
|
||||
import { SetCounterParams } from 'types';
|
||||
|
||||
export function setCounter(gameId: number, params: SetCounterParams): void {
|
||||
webClient.protobuf.sendGameCommand(gameId, Command_SetCounter_ext, create(Command_SetCounterSchema, params));
|
||||
import { Data } from '@app/types';
|
||||
|
||||
export function setCounter(gameId: number, params: Data.SetCounterParams): void {
|
||||
webClient.protobuf.sendGameCommand(gameId, Data.Command_SetCounter_ext, create(Data.Command_SetCounterSchema, params));
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,8 +1,8 @@
|
|||
import { create } from '@bufbuild/protobuf';
|
||||
import webClient from '../../WebClient';
|
||||
import { Command_SetSideboardLockSchema, Command_SetSideboardLock_ext } from 'generated/proto/command_set_sideboard_lock_pb';
|
||||
import { SetSideboardLockParams } from 'types';
|
||||
|
||||
export function setSideboardLock(gameId: number, params: SetSideboardLockParams): void {
|
||||
webClient.protobuf.sendGameCommand(gameId, Command_SetSideboardLock_ext, create(Command_SetSideboardLockSchema, params));
|
||||
import { Data } from '@app/types';
|
||||
|
||||
export function setSideboardLock(gameId: number, params: Data.SetSideboardLockParams): void {
|
||||
webClient.protobuf.sendGameCommand(gameId, Data.Command_SetSideboardLock_ext, create(Data.Command_SetSideboardLockSchema, params));
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,8 +1,8 @@
|
|||
import { create } from '@bufbuild/protobuf';
|
||||
import webClient from '../../WebClient';
|
||||
import { Command_SetSideboardPlanSchema, Command_SetSideboardPlan_ext } from 'generated/proto/command_set_sideboard_plan_pb';
|
||||
import { SetSideboardPlanParams } from 'types';
|
||||
|
||||
export function setSideboardPlan(gameId: number, params: SetSideboardPlanParams): void {
|
||||
webClient.protobuf.sendGameCommand(gameId, Command_SetSideboardPlan_ext, create(Command_SetSideboardPlanSchema, params));
|
||||
import { Data } from '@app/types';
|
||||
|
||||
export function setSideboardPlan(gameId: number, params: Data.SetSideboardPlanParams): void {
|
||||
webClient.protobuf.sendGameCommand(gameId, Data.Command_SetSideboardPlan_ext, create(Data.Command_SetSideboardPlanSchema, params));
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,8 +1,8 @@
|
|||
import { create } from '@bufbuild/protobuf';
|
||||
import webClient from '../../WebClient';
|
||||
import { Command_ShuffleSchema, Command_Shuffle_ext } from 'generated/proto/command_shuffle_pb';
|
||||
import { ShuffleParams } from 'types';
|
||||
|
||||
export function shuffle(gameId: number, params: ShuffleParams): void {
|
||||
webClient.protobuf.sendGameCommand(gameId, Command_Shuffle_ext, create(Command_ShuffleSchema, params));
|
||||
import { Data } from '@app/types';
|
||||
|
||||
export function shuffle(gameId: number, params: Data.ShuffleParams): void {
|
||||
webClient.protobuf.sendGameCommand(gameId, Data.Command_Shuffle_ext, create(Data.Command_ShuffleSchema, params));
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
import { create } from '@bufbuild/protobuf';
|
||||
import webClient from '../../WebClient';
|
||||
import { Command_UnconcedeSchema, Command_Unconcede_ext } from 'generated/proto/command_concede_pb';
|
||||
import { Data } from '@app/types';
|
||||
|
||||
export function unconcede(gameId: number): void {
|
||||
webClient.protobuf.sendGameCommand(gameId, Command_Unconcede_ext, create(Command_UnconcedeSchema));
|
||||
webClient.protobuf.sendGameCommand(gameId, Data.Command_Unconcede_ext, create(Data.Command_UnconcedeSchema));
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
import { create } from '@bufbuild/protobuf';
|
||||
import webClient from '../../WebClient';
|
||||
import { Command_UndoDrawSchema, Command_UndoDraw_ext } from 'generated/proto/command_undo_draw_pb';
|
||||
import { Data } from '@app/types';
|
||||
|
||||
export function undoDraw(gameId: number): void {
|
||||
webClient.protobuf.sendGameCommand(gameId, Command_UndoDraw_ext, create(Command_UndoDrawSchema));
|
||||
webClient.protobuf.sendGameCommand(gameId, Data.Command_UndoDraw_ext, create(Data.Command_UndoDrawSchema));
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,11 +1,12 @@
|
|||
import { create } from '@bufbuild/protobuf';
|
||||
import webClient from '../../WebClient';
|
||||
import { Command_BanFromServer_ext, Command_BanFromServerSchema } from 'generated/proto/moderator_commands_pb';
|
||||
|
||||
import { ModeratorPersistence } from '../../persistence';
|
||||
import { Data } from '@app/types';
|
||||
|
||||
export function banFromServer(minutes: number, userName?: string, address?: string, reason?: string,
|
||||
visibleReason?: string, clientid?: string, removeMessages?: number): void {
|
||||
webClient.protobuf.sendModeratorCommand(Command_BanFromServer_ext, create(Command_BanFromServerSchema, {
|
||||
webClient.protobuf.sendModeratorCommand(Data.Command_BanFromServer_ext, create(Data.Command_BanFromServerSchema, {
|
||||
minutes, userName, address, reason, visibleReason, clientid, removeMessages
|
||||
}), {
|
||||
onSuccess: () => {
|
||||
|
|
|
|||
|
|
@ -1,13 +1,12 @@
|
|||
import { create } from '@bufbuild/protobuf';
|
||||
import webClient from '../../WebClient';
|
||||
import {
|
||||
Command_ForceActivateUser_ext, Command_ForceActivateUserSchema,
|
||||
} from 'generated/proto/moderator_commands_pb';
|
||||
|
||||
import { ModeratorPersistence } from '../../persistence';
|
||||
import { Data } from '@app/types';
|
||||
|
||||
export function forceActivateUser(usernameToActivate: string, moderatorName: string): void {
|
||||
const cmd = create(Command_ForceActivateUserSchema, { usernameToActivate, moderatorName });
|
||||
webClient.protobuf.sendModeratorCommand(Command_ForceActivateUser_ext, cmd, {
|
||||
const cmd = create(Data.Command_ForceActivateUserSchema, { usernameToActivate, moderatorName });
|
||||
webClient.protobuf.sendModeratorCommand(Data.Command_ForceActivateUser_ext, cmd, {
|
||||
onSuccess: () => {
|
||||
ModeratorPersistence.forceActivateUser(usernameToActivate, moderatorName);
|
||||
},
|
||||
|
|
|
|||
|
|
@ -1,12 +1,12 @@
|
|||
import { create } from '@bufbuild/protobuf';
|
||||
import webClient from '../../WebClient';
|
||||
import { Command_GetAdminNotes_ext, Command_GetAdminNotesSchema } from 'generated/proto/moderator_commands_pb';
|
||||
|
||||
import { ModeratorPersistence } from '../../persistence';
|
||||
import { Response_GetAdminNotes_ext } from 'generated/proto/response_get_admin_notes_pb';
|
||||
import { Data } from '@app/types';
|
||||
|
||||
export function getAdminNotes(userName: string): void {
|
||||
webClient.protobuf.sendModeratorCommand(Command_GetAdminNotes_ext, create(Command_GetAdminNotesSchema, { userName }), {
|
||||
responseExt: Response_GetAdminNotes_ext,
|
||||
webClient.protobuf.sendModeratorCommand(Data.Command_GetAdminNotes_ext, create(Data.Command_GetAdminNotesSchema, { userName }), {
|
||||
responseExt: Data.Response_GetAdminNotes_ext,
|
||||
onSuccess: (response) => {
|
||||
ModeratorPersistence.getAdminNotes(userName, response.notes);
|
||||
},
|
||||
|
|
|
|||
|
|
@ -1,12 +1,12 @@
|
|||
import { create } from '@bufbuild/protobuf';
|
||||
import webClient from '../../WebClient';
|
||||
import { Command_GetBanHistory_ext, Command_GetBanHistorySchema } from 'generated/proto/moderator_commands_pb';
|
||||
|
||||
import { ModeratorPersistence } from '../../persistence';
|
||||
import { Response_BanHistory_ext } from 'generated/proto/response_ban_history_pb';
|
||||
import { Data } from '@app/types';
|
||||
|
||||
export function getBanHistory(userName: string): void {
|
||||
webClient.protobuf.sendModeratorCommand(Command_GetBanHistory_ext, create(Command_GetBanHistorySchema, { userName }), {
|
||||
responseExt: Response_BanHistory_ext,
|
||||
webClient.protobuf.sendModeratorCommand(Data.Command_GetBanHistory_ext, create(Data.Command_GetBanHistorySchema, { userName }), {
|
||||
responseExt: Data.Response_BanHistory_ext,
|
||||
onSuccess: (response) => {
|
||||
ModeratorPersistence.banHistory(userName, response.banList);
|
||||
},
|
||||
|
|
|
|||
|
|
@ -1,12 +1,12 @@
|
|||
import { create } from '@bufbuild/protobuf';
|
||||
import webClient from '../../WebClient';
|
||||
import { Command_GetWarnHistory_ext, Command_GetWarnHistorySchema } from 'generated/proto/moderator_commands_pb';
|
||||
|
||||
import { ModeratorPersistence } from '../../persistence';
|
||||
import { Response_WarnHistory_ext } from 'generated/proto/response_warn_history_pb';
|
||||
import { Data } from '@app/types';
|
||||
|
||||
export function getWarnHistory(userName: string): void {
|
||||
webClient.protobuf.sendModeratorCommand(Command_GetWarnHistory_ext, create(Command_GetWarnHistorySchema, { userName }), {
|
||||
responseExt: Response_WarnHistory_ext,
|
||||
webClient.protobuf.sendModeratorCommand(Data.Command_GetWarnHistory_ext, create(Data.Command_GetWarnHistorySchema, { userName }), {
|
||||
responseExt: Data.Response_WarnHistory_ext,
|
||||
onSuccess: (response) => {
|
||||
ModeratorPersistence.warnHistory(userName, response.warnList);
|
||||
},
|
||||
|
|
|
|||
|
|
@ -1,14 +1,18 @@
|
|||
import { create } from '@bufbuild/protobuf';
|
||||
import webClient from '../../WebClient';
|
||||
import { Command_GetWarnList_ext, Command_GetWarnListSchema } from 'generated/proto/moderator_commands_pb';
|
||||
|
||||
import { ModeratorPersistence } from '../../persistence';
|
||||
import { Response_WarnList_ext } from 'generated/proto/response_warn_list_pb';
|
||||
import { Data } from '@app/types';
|
||||
|
||||
export function getWarnList(modName: string, userName: string, userClientid: string): void {
|
||||
webClient.protobuf.sendModeratorCommand(Command_GetWarnList_ext, create(Command_GetWarnListSchema, { modName, userName, userClientid }), {
|
||||
responseExt: Response_WarnList_ext,
|
||||
onSuccess: (response) => {
|
||||
ModeratorPersistence.warnListOptions([response]);
|
||||
},
|
||||
});
|
||||
webClient.protobuf.sendModeratorCommand(
|
||||
Data.Command_GetWarnList_ext,
|
||||
create(Data.Command_GetWarnListSchema, { modName, userName, userClientid }),
|
||||
{
|
||||
responseExt: Data.Response_WarnList_ext,
|
||||
onSuccess: (response) => {
|
||||
ModeratorPersistence.warnListOptions([response]);
|
||||
},
|
||||
}
|
||||
);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,14 +1,13 @@
|
|||
import { create } from '@bufbuild/protobuf';
|
||||
import webClient from '../../WebClient';
|
||||
import {
|
||||
Command_GrantReplayAccess_ext, Command_GrantReplayAccessSchema,
|
||||
} from 'generated/proto/moderator_commands_pb';
|
||||
|
||||
import { ModeratorPersistence } from '../../persistence';
|
||||
import { Data } from '@app/types';
|
||||
|
||||
export function grantReplayAccess(replayId: number, moderatorName: string): void {
|
||||
webClient.protobuf.sendModeratorCommand(
|
||||
Command_GrantReplayAccess_ext,
|
||||
create(Command_GrantReplayAccessSchema, { replayId, moderatorName }),
|
||||
Data.Command_GrantReplayAccess_ext,
|
||||
create(Data.Command_GrantReplayAccessSchema, { replayId, moderatorName }),
|
||||
{
|
||||
onSuccess: () => {
|
||||
ModeratorPersistence.grantReplayAccess(replayId, moderatorName);
|
||||
|
|
|
|||
|
|
@ -20,24 +20,9 @@ vi.mock('../../persistence', () => ({
|
|||
|
||||
import { makeCallbackHelpers } from '../../__mocks__/callbackHelpers';
|
||||
import webClient from '../../WebClient';
|
||||
import { Data } from '@app/types';
|
||||
import { ModeratorPersistence } from '../../persistence';
|
||||
import {
|
||||
Command_BanFromServer_ext,
|
||||
Command_ForceActivateUser_ext,
|
||||
Command_GetAdminNotes_ext,
|
||||
Command_GetBanHistory_ext,
|
||||
Command_GetWarnHistory_ext,
|
||||
Command_GetWarnList_ext,
|
||||
Command_GrantReplayAccess_ext,
|
||||
Command_UpdateAdminNotes_ext,
|
||||
Command_ViewLogHistory_ext,
|
||||
Command_WarnUser_ext,
|
||||
} from 'generated/proto/moderator_commands_pb';
|
||||
import { Response_GetAdminNotes_ext } from 'generated/proto/response_get_admin_notes_pb';
|
||||
import { Response_BanHistory_ext } from 'generated/proto/response_ban_history_pb';
|
||||
import { Response_WarnHistory_ext } from 'generated/proto/response_warn_history_pb';
|
||||
import { Response_WarnList_ext } from 'generated/proto/response_warn_list_pb';
|
||||
import { Response_ViewLogHistory_ext } from 'generated/proto/response_viewlog_history_pb';
|
||||
|
||||
import { banFromServer } from './banFromServer';
|
||||
import { forceActivateUser } from './forceActivateUser';
|
||||
import { getAdminNotes } from './getAdminNotes';
|
||||
|
|
@ -48,7 +33,7 @@ import { grantReplayAccess } from './grantReplayAccess';
|
|||
import { updateAdminNotes } from './updateAdminNotes';
|
||||
import { viewLogHistory } from './viewLogHistory';
|
||||
import { warnUser } from './warnUser';
|
||||
|
||||
import { create } from '@bufbuild/protobuf';
|
||||
import { Mock } from 'vitest';
|
||||
|
||||
const { invokeOnSuccess } = makeCallbackHelpers(
|
||||
|
|
@ -56,8 +41,6 @@ const { invokeOnSuccess } = makeCallbackHelpers(
|
|||
2
|
||||
);
|
||||
|
||||
beforeEach(() => vi.clearAllMocks());
|
||||
|
||||
// ----------------------------------------------------------------
|
||||
// banFromServer
|
||||
// ----------------------------------------------------------------
|
||||
|
|
@ -66,7 +49,7 @@ describe('banFromServer', () => {
|
|||
it('calls sendModeratorCommand with Command_BanFromServer', () => {
|
||||
banFromServer(30, 'alice', '1.2.3.4', 'reason', 'visible', 'cid', 1);
|
||||
expect(webClient.protobuf.sendModeratorCommand).toHaveBeenCalledWith(
|
||||
Command_BanFromServer_ext,
|
||||
Data.Command_BanFromServer_ext,
|
||||
expect.objectContaining({ minutes: 30, userName: 'alice' }),
|
||||
expect.any(Object)
|
||||
);
|
||||
|
|
@ -87,7 +70,7 @@ describe('forceActivateUser', () => {
|
|||
it('calls sendModeratorCommand with Command_ForceActivateUser', () => {
|
||||
forceActivateUser('alice', 'mod1');
|
||||
expect(webClient.protobuf.sendModeratorCommand).toHaveBeenCalledWith(
|
||||
Command_ForceActivateUser_ext, expect.any(Object), expect.any(Object)
|
||||
Data.Command_ForceActivateUser_ext, expect.any(Object), expect.any(Object)
|
||||
);
|
||||
});
|
||||
|
||||
|
|
@ -106,9 +89,9 @@ describe('getAdminNotes', () => {
|
|||
it('calls sendModeratorCommand with Command_GetAdminNotes', () => {
|
||||
getAdminNotes('alice');
|
||||
expect(webClient.protobuf.sendModeratorCommand).toHaveBeenCalledWith(
|
||||
Command_GetAdminNotes_ext,
|
||||
Data.Command_GetAdminNotes_ext,
|
||||
expect.any(Object),
|
||||
expect.objectContaining({ responseExt: Response_GetAdminNotes_ext })
|
||||
expect.objectContaining({ responseExt: Data.Response_GetAdminNotes_ext })
|
||||
);
|
||||
});
|
||||
|
||||
|
|
@ -128,9 +111,9 @@ describe('getBanHistory', () => {
|
|||
it('calls sendModeratorCommand with Command_GetBanHistory', () => {
|
||||
getBanHistory('alice');
|
||||
expect(webClient.protobuf.sendModeratorCommand).toHaveBeenCalledWith(
|
||||
Command_GetBanHistory_ext,
|
||||
Data.Command_GetBanHistory_ext,
|
||||
expect.any(Object),
|
||||
expect.objectContaining({ responseExt: Response_BanHistory_ext })
|
||||
expect.objectContaining({ responseExt: Data.Response_BanHistory_ext })
|
||||
);
|
||||
});
|
||||
|
||||
|
|
@ -150,9 +133,9 @@ describe('getWarnHistory', () => {
|
|||
it('calls sendModeratorCommand with Command_GetWarnHistory', () => {
|
||||
getWarnHistory('alice');
|
||||
expect(webClient.protobuf.sendModeratorCommand).toHaveBeenCalledWith(
|
||||
Command_GetWarnHistory_ext,
|
||||
Data.Command_GetWarnHistory_ext,
|
||||
expect.any(Object),
|
||||
expect.objectContaining({ responseExt: Response_WarnHistory_ext })
|
||||
expect.objectContaining({ responseExt: Data.Response_WarnHistory_ext })
|
||||
);
|
||||
});
|
||||
|
||||
|
|
@ -172,9 +155,9 @@ describe('getWarnList', () => {
|
|||
it('calls sendModeratorCommand with Command_GetWarnList', () => {
|
||||
getWarnList('mod1', 'alice', 'US');
|
||||
expect(webClient.protobuf.sendModeratorCommand).toHaveBeenCalledWith(
|
||||
Command_GetWarnList_ext,
|
||||
Data.Command_GetWarnList_ext,
|
||||
expect.any(Object),
|
||||
expect.objectContaining({ responseExt: Response_WarnList_ext })
|
||||
expect.objectContaining({ responseExt: Data.Response_WarnList_ext })
|
||||
);
|
||||
});
|
||||
|
||||
|
|
@ -194,7 +177,7 @@ describe('grantReplayAccess', () => {
|
|||
it('calls sendModeratorCommand with Command_GrantReplayAccess', () => {
|
||||
grantReplayAccess(10, 'mod1');
|
||||
expect(webClient.protobuf.sendModeratorCommand).toHaveBeenCalledWith(
|
||||
Command_GrantReplayAccess_ext, expect.any(Object), expect.any(Object)
|
||||
Data.Command_GrantReplayAccess_ext, expect.any(Object), expect.any(Object)
|
||||
);
|
||||
});
|
||||
|
||||
|
|
@ -213,7 +196,7 @@ describe('updateAdminNotes', () => {
|
|||
it('calls sendModeratorCommand with Command_UpdateAdminNotes', () => {
|
||||
updateAdminNotes('alice', 'new notes');
|
||||
expect(webClient.protobuf.sendModeratorCommand).toHaveBeenCalledWith(
|
||||
Command_UpdateAdminNotes_ext, expect.any(Object), expect.any(Object)
|
||||
Data.Command_UpdateAdminNotes_ext, expect.any(Object), expect.any(Object)
|
||||
);
|
||||
});
|
||||
|
||||
|
|
@ -230,16 +213,18 @@ describe('updateAdminNotes', () => {
|
|||
describe('viewLogHistory', () => {
|
||||
|
||||
it('calls sendModeratorCommand with Command_ViewLogHistory', () => {
|
||||
viewLogHistory({ dateRange: 7 } as any);
|
||||
const filters = create(Data.Command_ViewLogHistorySchema, { dateRange: 7 });
|
||||
viewLogHistory(filters);
|
||||
expect(webClient.protobuf.sendModeratorCommand).toHaveBeenCalledWith(
|
||||
Command_ViewLogHistory_ext,
|
||||
Data.Command_ViewLogHistory_ext,
|
||||
expect.any(Object),
|
||||
expect.objectContaining({ responseExt: Response_ViewLogHistory_ext })
|
||||
expect.objectContaining({ responseExt: Data.Response_ViewLogHistory_ext })
|
||||
);
|
||||
});
|
||||
|
||||
it('onSuccess calls ModeratorPersistence.viewLogs with logMessage', () => {
|
||||
viewLogHistory({ dateRange: 7 } as any);
|
||||
const filters = create(Data.Command_ViewLogHistorySchema, { dateRange: 7 });
|
||||
viewLogHistory(filters);
|
||||
const resp = { logMessage: ['log1'] };
|
||||
invokeOnSuccess(resp, { responseCode: 0 });
|
||||
expect(ModeratorPersistence.viewLogs).toHaveBeenCalledWith(['log1']);
|
||||
|
|
@ -253,7 +238,7 @@ describe('warnUser', () => {
|
|||
|
||||
it('calls sendModeratorCommand with Command_WarnUser', () => {
|
||||
warnUser('alice', 'bad behavior', 'cid');
|
||||
expect(webClient.protobuf.sendModeratorCommand).toHaveBeenCalledWith(Command_WarnUser_ext, expect.any(Object), expect.any(Object));
|
||||
expect(webClient.protobuf.sendModeratorCommand).toHaveBeenCalledWith(Data.Command_WarnUser_ext, expect.any(Object), expect.any(Object));
|
||||
});
|
||||
|
||||
it('onSuccess calls ModeratorPersistence.warnUser', () => {
|
||||
|
|
|
|||
|
|
@ -1,14 +1,17 @@
|
|||
import { create } from '@bufbuild/protobuf';
|
||||
import webClient from '../../WebClient';
|
||||
import {
|
||||
Command_UpdateAdminNotes_ext, Command_UpdateAdminNotesSchema,
|
||||
} from 'generated/proto/moderator_commands_pb';
|
||||
|
||||
import { ModeratorPersistence } from '../../persistence';
|
||||
import { Data } from '@app/types';
|
||||
|
||||
export function updateAdminNotes(userName: string, notes: string): void {
|
||||
webClient.protobuf.sendModeratorCommand(Command_UpdateAdminNotes_ext, create(Command_UpdateAdminNotesSchema, { userName, notes }), {
|
||||
onSuccess: () => {
|
||||
ModeratorPersistence.updateAdminNotes(userName, notes);
|
||||
},
|
||||
});
|
||||
webClient.protobuf.sendModeratorCommand(
|
||||
Data.Command_UpdateAdminNotes_ext,
|
||||
create(Data.Command_UpdateAdminNotesSchema, { userName, notes }),
|
||||
{
|
||||
onSuccess: () => {
|
||||
ModeratorPersistence.updateAdminNotes(userName, notes);
|
||||
},
|
||||
}
|
||||
);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,13 +1,13 @@
|
|||
import { create } from '@bufbuild/protobuf';
|
||||
import webClient from '../../WebClient';
|
||||
import { Command_ViewLogHistory_ext, Command_ViewLogHistorySchema } from 'generated/proto/moderator_commands_pb';
|
||||
import { ModeratorPersistence } from '../../persistence';
|
||||
import { Response_ViewLogHistory_ext } from 'generated/proto/response_viewlog_history_pb';
|
||||
import { LogFilters } from 'types';
|
||||
|
||||
export function viewLogHistory(filters: LogFilters): void {
|
||||
webClient.protobuf.sendModeratorCommand(Command_ViewLogHistory_ext, create(Command_ViewLogHistorySchema, filters), {
|
||||
responseExt: Response_ViewLogHistory_ext,
|
||||
import { ModeratorPersistence } from '../../persistence';
|
||||
|
||||
import { Data } from '@app/types';
|
||||
|
||||
export function viewLogHistory(filters: Data.ViewLogHistoryParams): void {
|
||||
webClient.protobuf.sendModeratorCommand(Data.Command_ViewLogHistory_ext, create(Data.Command_ViewLogHistorySchema, filters), {
|
||||
responseExt: Data.Response_ViewLogHistory_ext,
|
||||
onSuccess: (response) => {
|
||||
ModeratorPersistence.viewLogs(response.logMessage);
|
||||
},
|
||||
|
|
|
|||
|
|
@ -1,11 +1,12 @@
|
|||
import { create } from '@bufbuild/protobuf';
|
||||
import webClient from '../../WebClient';
|
||||
import { Command_WarnUser_ext, Command_WarnUserSchema } from 'generated/proto/moderator_commands_pb';
|
||||
|
||||
import { ModeratorPersistence } from '../../persistence';
|
||||
import { Data } from '@app/types';
|
||||
|
||||
export function warnUser(userName: string, reason: string, clientid?: string, removeMessages?: number): void {
|
||||
const cmd = create(Command_WarnUserSchema, { userName, reason, clientid, removeMessages });
|
||||
webClient.protobuf.sendModeratorCommand(Command_WarnUser_ext, cmd, {
|
||||
const cmd = create(Data.Command_WarnUserSchema, { userName, reason, clientid, removeMessages });
|
||||
webClient.protobuf.sendModeratorCommand(Data.Command_WarnUser_ext, cmd, {
|
||||
onSuccess: () => {
|
||||
ModeratorPersistence.warnUser(userName);
|
||||
},
|
||||
|
|
|
|||
|
|
@ -1,11 +1,11 @@
|
|||
import { create } from '@bufbuild/protobuf';
|
||||
import webClient from '../../WebClient';
|
||||
import { Command_CreateGame_ext, Command_CreateGameSchema } from 'generated/proto/room_commands_pb';
|
||||
import { RoomPersistence } from '../../persistence';
|
||||
import { GameConfig } from 'types';
|
||||
|
||||
export function createGame(roomId: number, gameConfig: GameConfig): void {
|
||||
webClient.protobuf.sendRoomCommand(roomId, Command_CreateGame_ext, create(Command_CreateGameSchema, gameConfig), {
|
||||
import { RoomPersistence } from '../../persistence';
|
||||
import { Data } from '@app/types';
|
||||
|
||||
export function createGame(roomId: number, gameConfig: Data.CreateGameParams): void {
|
||||
webClient.protobuf.sendRoomCommand(roomId, Data.Command_CreateGame_ext, create(Data.Command_CreateGameSchema, gameConfig), {
|
||||
onSuccess: () => {
|
||||
RoomPersistence.gameCreated(roomId);
|
||||
},
|
||||
|
|
|
|||
|
|
@ -1,11 +1,11 @@
|
|||
import { create } from '@bufbuild/protobuf';
|
||||
import webClient from '../../WebClient';
|
||||
import { Command_JoinGame_ext, Command_JoinGameSchema } from 'generated/proto/room_commands_pb';
|
||||
import { RoomPersistence } from '../../persistence';
|
||||
import { JoinGameParams } from 'types';
|
||||
|
||||
export function joinGame(roomId: number, joinGameParams: JoinGameParams): void {
|
||||
webClient.protobuf.sendRoomCommand(roomId, Command_JoinGame_ext, create(Command_JoinGameSchema, joinGameParams), {
|
||||
import { RoomPersistence } from '../../persistence';
|
||||
import { Data } from '@app/types';
|
||||
|
||||
export function joinGame(roomId: number, joinGameParams: Data.JoinGameParams): void {
|
||||
webClient.protobuf.sendRoomCommand(roomId, Data.Command_JoinGame_ext, create(Data.Command_JoinGameSchema, joinGameParams), {
|
||||
onSuccess: () => {
|
||||
RoomPersistence.joinedGame(roomId, joinGameParams.gameId);
|
||||
},
|
||||
|
|
|
|||
|
|
@ -1,10 +1,11 @@
|
|||
import { create } from '@bufbuild/protobuf';
|
||||
import webClient from '../../WebClient';
|
||||
import { Command_LeaveRoom_ext, Command_LeaveRoomSchema } from 'generated/proto/room_commands_pb';
|
||||
|
||||
import { RoomPersistence } from '../../persistence';
|
||||
import { Data } from '@app/types';
|
||||
|
||||
export function leaveRoom(roomId: number): void {
|
||||
webClient.protobuf.sendRoomCommand(roomId, Command_LeaveRoom_ext, create(Command_LeaveRoomSchema), {
|
||||
webClient.protobuf.sendRoomCommand(roomId, Data.Command_LeaveRoom_ext, create(Data.Command_LeaveRoomSchema), {
|
||||
onSuccess: () => {
|
||||
RoomPersistence.leaveRoom(roomId);
|
||||
},
|
||||
|
|
|
|||
|
|
@ -13,13 +13,14 @@ vi.mock('../../persistence', () => ({
|
|||
|
||||
import { makeCallbackHelpers } from '../../__mocks__/callbackHelpers';
|
||||
import webClient from '../../WebClient';
|
||||
import { Data } from '@app/types';
|
||||
import { RoomPersistence } from '../../persistence';
|
||||
import { Command_CreateGame_ext, Command_JoinGame_ext, Command_LeaveRoom_ext, Command_RoomSay_ext } from 'generated/proto/room_commands_pb';
|
||||
|
||||
import { createGame } from './createGame';
|
||||
import { joinGame } from './joinGame';
|
||||
import { leaveRoom } from './leaveRoom';
|
||||
import { roomSay } from './roomSay';
|
||||
|
||||
import { create } from '@bufbuild/protobuf';
|
||||
import { Mock } from 'vitest';
|
||||
|
||||
const { invokeOnSuccess } = makeCallbackHelpers(
|
||||
|
|
@ -28,22 +29,20 @@ const { invokeOnSuccess } = makeCallbackHelpers(
|
|||
3
|
||||
);
|
||||
|
||||
beforeEach(() => vi.clearAllMocks());
|
||||
|
||||
// ----------------------------------------------------------------
|
||||
// createGame
|
||||
// ----------------------------------------------------------------
|
||||
describe('createGame', () => {
|
||||
|
||||
it('calls sendRoomCommand with Command_CreateGame', () => {
|
||||
createGame(5, { maxPlayers: 4 } as any);
|
||||
createGame(5, create(Data.Command_CreateGameSchema, { maxPlayers: 4 }));
|
||||
expect(webClient.protobuf.sendRoomCommand).toHaveBeenCalledWith(
|
||||
5, Command_CreateGame_ext, expect.objectContaining({ maxPlayers: 4 }), expect.any(Object)
|
||||
5, Data.Command_CreateGame_ext, expect.objectContaining({ maxPlayers: 4 }), expect.any(Object)
|
||||
);
|
||||
});
|
||||
|
||||
it('onSuccess calls RoomPersistence.gameCreated with roomId', () => {
|
||||
createGame(5, {} as any);
|
||||
createGame(5, create(Data.Command_CreateGameSchema, {}));
|
||||
invokeOnSuccess();
|
||||
expect(RoomPersistence.gameCreated).toHaveBeenCalledWith(5);
|
||||
});
|
||||
|
|
@ -55,14 +54,14 @@ describe('createGame', () => {
|
|||
describe('joinGame', () => {
|
||||
|
||||
it('calls sendRoomCommand with Command_JoinGame', () => {
|
||||
joinGame(7, { gameId: 42, password: '' } as any);
|
||||
joinGame(7, create(Data.Command_JoinGameSchema, { gameId: 42, password: '' }));
|
||||
expect(webClient.protobuf.sendRoomCommand).toHaveBeenCalledWith(
|
||||
7, Command_JoinGame_ext, expect.objectContaining({ gameId: 42, password: '' }), expect.any(Object)
|
||||
7, Data.Command_JoinGame_ext, expect.objectContaining({ gameId: 42, password: '' }), expect.any(Object)
|
||||
);
|
||||
});
|
||||
|
||||
it('onSuccess calls RoomPersistence.joinedGame with roomId and gameId', () => {
|
||||
joinGame(7, { gameId: 42 } as any);
|
||||
joinGame(7, create(Data.Command_JoinGameSchema, { gameId: 42 }));
|
||||
invokeOnSuccess();
|
||||
expect(RoomPersistence.joinedGame).toHaveBeenCalledWith(7, 42);
|
||||
});
|
||||
|
|
@ -75,7 +74,7 @@ describe('leaveRoom', () => {
|
|||
|
||||
it('calls sendRoomCommand with Command_LeaveRoom', () => {
|
||||
leaveRoom(3);
|
||||
expect(webClient.protobuf.sendRoomCommand).toHaveBeenCalledWith(3, Command_LeaveRoom_ext, expect.any(Object), expect.any(Object));
|
||||
expect(webClient.protobuf.sendRoomCommand).toHaveBeenCalledWith(3, Data.Command_LeaveRoom_ext, expect.any(Object), expect.any(Object));
|
||||
});
|
||||
|
||||
it('onSuccess calls RoomPersistence.leaveRoom with roomId', () => {
|
||||
|
|
@ -94,7 +93,7 @@ describe('roomSay', () => {
|
|||
roomSay(2, ' hello ');
|
||||
expect(webClient.protobuf.sendRoomCommand).toHaveBeenCalledWith(
|
||||
2,
|
||||
Command_RoomSay_ext,
|
||||
Data.Command_RoomSay_ext,
|
||||
expect.objectContaining({ message: 'hello' })
|
||||
);
|
||||
});
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
import { create } from '@bufbuild/protobuf';
|
||||
import webClient from '../../WebClient';
|
||||
import { Command_RoomSay_ext, Command_RoomSaySchema } from 'generated/proto/room_commands_pb';
|
||||
import { Data } from '@app/types';
|
||||
|
||||
export function roomSay(roomId: number, message: string): void {
|
||||
const trimmed = message.trim();
|
||||
|
|
@ -9,5 +9,5 @@ export function roomSay(roomId: number, message: string): void {
|
|||
return;
|
||||
}
|
||||
|
||||
webClient.protobuf.sendRoomCommand(roomId, Command_RoomSay_ext, create(Command_RoomSaySchema, { message: trimmed }));
|
||||
webClient.protobuf.sendRoomCommand(roomId, Data.Command_RoomSay_ext, create(Data.Command_RoomSaySchema, { message: trimmed }));
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,11 +1,12 @@
|
|||
import { create } from '@bufbuild/protobuf';
|
||||
import webClient from '../../WebClient';
|
||||
import { Command_AccountEdit_ext, Command_AccountEditSchema } from 'generated/proto/session_commands_pb';
|
||||
|
||||
import { SessionPersistence } from '../../persistence';
|
||||
import { Data } from '@app/types';
|
||||
|
||||
export function accountEdit(passwordCheck: string, realName?: string, email?: string, country?: string): void {
|
||||
const cmd = create(Command_AccountEditSchema, { passwordCheck, realName, email, country });
|
||||
webClient.protobuf.sendSessionCommand(Command_AccountEdit_ext, cmd, {
|
||||
const cmd = create(Data.Command_AccountEditSchema, { passwordCheck, realName, email, country });
|
||||
webClient.protobuf.sendSessionCommand(Data.Command_AccountEdit_ext, cmd, {
|
||||
onSuccess: () => {
|
||||
SessionPersistence.accountEditChanged(realName, email, country);
|
||||
},
|
||||
|
|
|
|||
|
|
@ -1,10 +1,11 @@
|
|||
import { create } from '@bufbuild/protobuf';
|
||||
import webClient from '../../WebClient';
|
||||
import { Command_AccountImage_ext, Command_AccountImageSchema } from 'generated/proto/session_commands_pb';
|
||||
|
||||
import { SessionPersistence } from '../../persistence';
|
||||
import { Data } from '@app/types';
|
||||
|
||||
export function accountImage(image: Uint8Array): void {
|
||||
webClient.protobuf.sendSessionCommand(Command_AccountImage_ext, create(Command_AccountImageSchema, { image }), {
|
||||
webClient.protobuf.sendSessionCommand(Data.Command_AccountImage_ext, create(Data.Command_AccountImageSchema, { image }), {
|
||||
onSuccess: () => {
|
||||
SessionPersistence.accountImageChanged(image);
|
||||
},
|
||||
|
|
|
|||
|
|
@ -1,11 +1,12 @@
|
|||
import { create } from '@bufbuild/protobuf';
|
||||
import webClient from '../../WebClient';
|
||||
import { Command_AccountPassword_ext, Command_AccountPasswordSchema } from 'generated/proto/session_commands_pb';
|
||||
|
||||
import { SessionPersistence } from '../../persistence';
|
||||
import { Data } from '@app/types';
|
||||
|
||||
export function accountPassword(oldPassword: string, newPassword: string, hashedNewPassword: string): void {
|
||||
const cmd = create(Command_AccountPasswordSchema, { oldPassword, newPassword, hashedNewPassword });
|
||||
webClient.protobuf.sendSessionCommand(Command_AccountPassword_ext, cmd, {
|
||||
const cmd = create(Data.Command_AccountPasswordSchema, { oldPassword, newPassword, hashedNewPassword });
|
||||
webClient.protobuf.sendSessionCommand(Data.Command_AccountPassword_ext, cmd, {
|
||||
onSuccess: () => {
|
||||
SessionPersistence.accountPasswordChange();
|
||||
},
|
||||
|
|
|
|||
|
|
@ -1,31 +1,34 @@
|
|||
import { AccountActivationParams } from 'store';
|
||||
import { StatusEnum, WebSocketConnectOptions } from 'types';
|
||||
import { App, Enriched, Data } from '@app/types';
|
||||
|
||||
import { create } from '@bufbuild/protobuf';
|
||||
import { CLIENT_CONFIG } from '../../config';
|
||||
import webClient from '../../WebClient';
|
||||
import { Command_Activate_ext, Command_ActivateSchema } from 'generated/proto/session_commands_pb';
|
||||
|
||||
import { SessionPersistence } from '../../persistence';
|
||||
import { Response_ResponseCode } from 'generated/proto/response_pb';
|
||||
|
||||
import { disconnect, login, updateStatus } from './';
|
||||
|
||||
export function activate(options: WebSocketConnectOptions, password?: string, passwordSalt?: string): void {
|
||||
const { userName, token } = options as unknown as AccountActivationParams;
|
||||
export function activate(options: Omit<Enriched.ActivateConnectOptions, 'password'>, password?: string, passwordSalt?: string): void {
|
||||
const { userName, token } = options;
|
||||
|
||||
webClient.protobuf.sendSessionCommand(Command_Activate_ext, create(Command_ActivateSchema, {
|
||||
webClient.protobuf.sendSessionCommand(Data.Command_Activate_ext, create(Data.Command_ActivateSchema, {
|
||||
...CLIENT_CONFIG,
|
||||
userName,
|
||||
token,
|
||||
}), {
|
||||
onResponseCode: {
|
||||
[Response_ResponseCode.RespActivationAccepted]: () => {
|
||||
[Data.Response_ResponseCode.RespActivationAccepted]: () => {
|
||||
SessionPersistence.accountActivationSuccess();
|
||||
login(options, password, passwordSalt);
|
||||
login({
|
||||
host: options.host,
|
||||
port: options.port,
|
||||
userName: options.userName,
|
||||
reason: App.WebSocketConnectReason.LOGIN,
|
||||
}, password, passwordSalt);
|
||||
},
|
||||
},
|
||||
onError: () => {
|
||||
updateStatus(StatusEnum.DISCONNECTED, 'Account Activation Failed');
|
||||
updateStatus(App.StatusEnum.DISCONNECTED, 'Account Activation Failed');
|
||||
disconnect();
|
||||
SessionPersistence.accountActivationFailed();
|
||||
},
|
||||
|
|
|
|||
|
|
@ -1,7 +1,8 @@
|
|||
import { create } from '@bufbuild/protobuf';
|
||||
import webClient from '../../WebClient';
|
||||
import { Command_AddToList_ext, Command_AddToListSchema } from 'generated/proto/session_commands_pb';
|
||||
|
||||
import { SessionPersistence } from '../../persistence';
|
||||
import { Data } from '@app/types';
|
||||
|
||||
export function addToBuddyList(userName: string): void {
|
||||
addToList('buddy', userName);
|
||||
|
|
@ -12,7 +13,7 @@ export function addToIgnoreList(userName: string): void {
|
|||
}
|
||||
|
||||
export function addToList(list: string, userName: string): void {
|
||||
webClient.protobuf.sendSessionCommand(Command_AddToList_ext, create(Command_AddToListSchema, { list, userName }), {
|
||||
webClient.protobuf.sendSessionCommand(Data.Command_AddToList_ext, create(Data.Command_AddToListSchema, { list, userName }), {
|
||||
onSuccess: () => {
|
||||
SessionPersistence.addToList(list, userName);
|
||||
},
|
||||
|
|
|
|||
|
|
@ -1,24 +1,25 @@
|
|||
import { StatusEnum, WebSocketConnectOptions, WebSocketConnectReason } from 'types';
|
||||
import { App, Enriched } from '@app/types';
|
||||
import webClient from '../../WebClient';
|
||||
import { updateStatus } from './';
|
||||
|
||||
export function connect(options: WebSocketConnectOptions, reason: WebSocketConnectReason): void {
|
||||
switch (reason) {
|
||||
case WebSocketConnectReason.LOGIN:
|
||||
case WebSocketConnectReason.REGISTER:
|
||||
case WebSocketConnectReason.ACTIVATE_ACCOUNT:
|
||||
case WebSocketConnectReason.PASSWORD_RESET_REQUEST:
|
||||
case WebSocketConnectReason.PASSWORD_RESET_CHALLENGE:
|
||||
case WebSocketConnectReason.PASSWORD_RESET:
|
||||
updateStatus(StatusEnum.CONNECTING, 'Connecting...');
|
||||
break;
|
||||
case WebSocketConnectReason.TEST_CONNECTION:
|
||||
webClient.testConnect({ ...options });
|
||||
export function connect(options: Enriched.WebSocketConnectOptions): void {
|
||||
switch (options.reason) {
|
||||
case App.WebSocketConnectReason.LOGIN:
|
||||
case App.WebSocketConnectReason.REGISTER:
|
||||
case App.WebSocketConnectReason.ACTIVATE_ACCOUNT:
|
||||
case App.WebSocketConnectReason.PASSWORD_RESET_REQUEST:
|
||||
case App.WebSocketConnectReason.PASSWORD_RESET_CHALLENGE:
|
||||
case App.WebSocketConnectReason.PASSWORD_RESET:
|
||||
updateStatus(App.StatusEnum.CONNECTING, 'Connecting...');
|
||||
webClient.connect(options);
|
||||
return;
|
||||
default:
|
||||
updateStatus(StatusEnum.DISCONNECTED, 'Unknown Connection Attempt: ' + reason);
|
||||
case App.WebSocketConnectReason.TEST_CONNECTION:
|
||||
webClient.testConnect(options);
|
||||
return;
|
||||
default: {
|
||||
const { reason } = options as Enriched.WebSocketConnectOptions;
|
||||
updateStatus(App.StatusEnum.DISCONNECTED, `Unknown Connection Attempt: ${reason}`);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
webClient.connect({ ...options, reason });
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,10 +1,11 @@
|
|||
import { create } from '@bufbuild/protobuf';
|
||||
import webClient from '../../WebClient';
|
||||
import { Command_DeckDelSchema, Command_DeckDel_ext } from 'generated/proto/command_deck_del_pb';
|
||||
|
||||
import { SessionPersistence } from '../../persistence';
|
||||
import { Data } from '@app/types';
|
||||
|
||||
export function deckDel(deckId: number): void {
|
||||
webClient.protobuf.sendSessionCommand(Command_DeckDel_ext, create(Command_DeckDelSchema, { deckId }), {
|
||||
webClient.protobuf.sendSessionCommand(Data.Command_DeckDel_ext, create(Data.Command_DeckDelSchema, { deckId }), {
|
||||
onSuccess: () => {
|
||||
SessionPersistence.deleteServerDeck(deckId);
|
||||
},
|
||||
|
|
|
|||
|
|
@ -1,10 +1,11 @@
|
|||
import { create } from '@bufbuild/protobuf';
|
||||
import webClient from '../../WebClient';
|
||||
import { Command_DeckDelDirSchema, Command_DeckDelDir_ext } from 'generated/proto/command_deck_del_dir_pb';
|
||||
|
||||
import { SessionPersistence } from '../../persistence';
|
||||
import { Data } from '@app/types';
|
||||
|
||||
export function deckDelDir(path: string): void {
|
||||
webClient.protobuf.sendSessionCommand(Command_DeckDelDir_ext, create(Command_DeckDelDirSchema, { path }), {
|
||||
webClient.protobuf.sendSessionCommand(Data.Command_DeckDelDir_ext, create(Data.Command_DeckDelDirSchema, { path }), {
|
||||
onSuccess: () => {
|
||||
SessionPersistence.deleteServerDeckDir(path);
|
||||
},
|
||||
|
|
|
|||
|
|
@ -1,12 +1,12 @@
|
|||
import { create } from '@bufbuild/protobuf';
|
||||
import webClient from '../../WebClient';
|
||||
import { Command_DeckListSchema, Command_DeckList_ext } from 'generated/proto/command_deck_list_pb';
|
||||
|
||||
import { SessionPersistence } from '../../persistence';
|
||||
import { Response_DeckList_ext } from 'generated/proto/response_deck_list_pb';
|
||||
import { Data } from '@app/types';
|
||||
|
||||
export function deckList(): void {
|
||||
webClient.protobuf.sendSessionCommand(Command_DeckList_ext, create(Command_DeckListSchema), {
|
||||
responseExt: Response_DeckList_ext,
|
||||
webClient.protobuf.sendSessionCommand(Data.Command_DeckList_ext, create(Data.Command_DeckListSchema), {
|
||||
responseExt: Data.Response_DeckList_ext,
|
||||
onSuccess: (response) => {
|
||||
if (response.root) {
|
||||
SessionPersistence.updateServerDecks(response);
|
||||
|
|
|
|||
|
|
@ -1,10 +1,11 @@
|
|||
import { create } from '@bufbuild/protobuf';
|
||||
import webClient from '../../WebClient';
|
||||
import { Command_DeckNewDirSchema, Command_DeckNewDir_ext } from 'generated/proto/command_deck_new_dir_pb';
|
||||
|
||||
import { SessionPersistence } from '../../persistence';
|
||||
import { Data } from '@app/types';
|
||||
|
||||
export function deckNewDir(path: string, dirName: string): void {
|
||||
webClient.protobuf.sendSessionCommand(Command_DeckNewDir_ext, create(Command_DeckNewDirSchema, { path, dirName }), {
|
||||
webClient.protobuf.sendSessionCommand(Data.Command_DeckNewDir_ext, create(Data.Command_DeckNewDirSchema, { path, dirName }), {
|
||||
onSuccess: () => {
|
||||
SessionPersistence.createServerDeckDir(path, dirName);
|
||||
},
|
||||
|
|
|
|||
|
|
@ -1,12 +1,12 @@
|
|||
import { create } from '@bufbuild/protobuf';
|
||||
import webClient from '../../WebClient';
|
||||
import { Command_DeckUploadSchema, Command_DeckUpload_ext } from 'generated/proto/command_deck_upload_pb';
|
||||
|
||||
import { SessionPersistence } from '../../persistence';
|
||||
import { Response_DeckUpload_ext } from 'generated/proto/response_deck_upload_pb';
|
||||
import { Data } from '@app/types';
|
||||
|
||||
export function deckUpload(path: string, deckId: number, deckList: string): void {
|
||||
webClient.protobuf.sendSessionCommand(Command_DeckUpload_ext, create(Command_DeckUploadSchema, { path, deckId, deckList }), {
|
||||
responseExt: Response_DeckUpload_ext,
|
||||
webClient.protobuf.sendSessionCommand(Data.Command_DeckUpload_ext, create(Data.Command_DeckUploadSchema, { path, deckId, deckList }), {
|
||||
responseExt: Data.Response_DeckUpload_ext,
|
||||
onSuccess: (response) => {
|
||||
if (response.newFile) {
|
||||
SessionPersistence.uploadServerDeck(path, response.newFile);
|
||||
|
|
|
|||
|
|
@ -1,30 +1,27 @@
|
|||
import { ForgotPasswordChallengeParams } from 'store';
|
||||
import { StatusEnum, WebSocketConnectOptions } from 'types';
|
||||
import { App, Enriched, Data } from '@app/types';
|
||||
|
||||
import { create } from '@bufbuild/protobuf';
|
||||
import { CLIENT_CONFIG } from '../../config';
|
||||
import webClient from '../../WebClient';
|
||||
import {
|
||||
Command_ForgotPasswordChallenge_ext, Command_ForgotPasswordChallengeSchema,
|
||||
} from 'generated/proto/session_commands_pb';
|
||||
|
||||
import { SessionPersistence } from '../../persistence';
|
||||
import { disconnect, updateStatus } from './';
|
||||
|
||||
export function forgotPasswordChallenge(options: WebSocketConnectOptions): void {
|
||||
const { userName, email } = options as unknown as ForgotPasswordChallengeParams;
|
||||
export function forgotPasswordChallenge(options: Enriched.PasswordResetChallengeConnectOptions): void {
|
||||
const { userName, email } = options;
|
||||
|
||||
webClient.protobuf.sendSessionCommand(Command_ForgotPasswordChallenge_ext, create(Command_ForgotPasswordChallengeSchema, {
|
||||
webClient.protobuf.sendSessionCommand(Data.Command_ForgotPasswordChallenge_ext, create(Data.Command_ForgotPasswordChallengeSchema, {
|
||||
...CLIENT_CONFIG,
|
||||
userName,
|
||||
email,
|
||||
}), {
|
||||
onSuccess: () => {
|
||||
updateStatus(StatusEnum.DISCONNECTED, null);
|
||||
updateStatus(App.StatusEnum.DISCONNECTED, null);
|
||||
SessionPersistence.resetPassword();
|
||||
disconnect();
|
||||
},
|
||||
onError: () => {
|
||||
updateStatus(StatusEnum.DISCONNECTED, null);
|
||||
updateStatus(App.StatusEnum.DISCONNECTED, null);
|
||||
SessionPersistence.resetPasswordFailed();
|
||||
disconnect();
|
||||
},
|
||||
|
|
|
|||
|
|
@ -1,37 +1,33 @@
|
|||
import { ForgotPasswordParams } from 'store';
|
||||
import { StatusEnum, WebSocketConnectOptions } from 'types';
|
||||
import { App, Enriched, Data } from '@app/types';
|
||||
|
||||
import { create } from '@bufbuild/protobuf';
|
||||
import { CLIENT_CONFIG } from '../../config';
|
||||
import webClient from '../../WebClient';
|
||||
import {
|
||||
Command_ForgotPasswordRequest_ext, Command_ForgotPasswordRequestSchema,
|
||||
} from 'generated/proto/session_commands_pb';
|
||||
|
||||
import { SessionPersistence } from '../../persistence';
|
||||
import { Response_ForgotPasswordRequest_ext } from 'generated/proto/response_forgotpasswordrequest_pb';
|
||||
|
||||
import { disconnect, updateStatus } from './';
|
||||
|
||||
export function forgotPasswordRequest(options: WebSocketConnectOptions): void {
|
||||
const { userName } = options as unknown as ForgotPasswordParams;
|
||||
export function forgotPasswordRequest(options: Enriched.PasswordResetRequestConnectOptions): void {
|
||||
const { userName } = options;
|
||||
|
||||
webClient.protobuf.sendSessionCommand(Command_ForgotPasswordRequest_ext, create(Command_ForgotPasswordRequestSchema, {
|
||||
webClient.protobuf.sendSessionCommand(Data.Command_ForgotPasswordRequest_ext, create(Data.Command_ForgotPasswordRequestSchema, {
|
||||
...CLIENT_CONFIG,
|
||||
userName,
|
||||
}), {
|
||||
responseExt: Response_ForgotPasswordRequest_ext,
|
||||
responseExt: Data.Response_ForgotPasswordRequest_ext,
|
||||
onSuccess: (resp) => {
|
||||
if (resp?.challengeEmail) {
|
||||
updateStatus(StatusEnum.DISCONNECTED, null);
|
||||
updateStatus(App.StatusEnum.DISCONNECTED, null);
|
||||
SessionPersistence.resetPasswordChallenge();
|
||||
} else {
|
||||
updateStatus(StatusEnum.DISCONNECTED, null);
|
||||
updateStatus(App.StatusEnum.DISCONNECTED, null);
|
||||
SessionPersistence.resetPassword();
|
||||
}
|
||||
disconnect();
|
||||
},
|
||||
onError: () => {
|
||||
updateStatus(StatusEnum.DISCONNECTED, null);
|
||||
updateStatus(App.StatusEnum.DISCONNECTED, null);
|
||||
SessionPersistence.resetPasswordFailed();
|
||||
disconnect();
|
||||
},
|
||||
|
|
|
|||
|
|
@ -1,22 +1,23 @@
|
|||
import { ForgotPasswordResetParams } from 'store';
|
||||
import { StatusEnum, WebSocketConnectOptions } from 'types';
|
||||
import { App, Enriched, Data } from '@app/types';
|
||||
|
||||
import { create } from '@bufbuild/protobuf';
|
||||
import type { MessageInitShape } from '@bufbuild/protobuf';
|
||||
import { CLIENT_CONFIG } from '../../config';
|
||||
import webClient from '../../WebClient';
|
||||
import {
|
||||
Command_ForgotPasswordReset_ext, Command_ForgotPasswordResetSchema,
|
||||
} from 'generated/proto/session_commands_pb';
|
||||
|
||||
import { SessionPersistence } from '../../persistence';
|
||||
import { hashPassword } from '../../utils';
|
||||
|
||||
import { disconnect, updateStatus } from '.';
|
||||
|
||||
export function forgotPasswordReset(options: WebSocketConnectOptions, newPassword?: string, passwordSalt?: string): void {
|
||||
const { userName, token } = options as unknown as ForgotPasswordResetParams;
|
||||
export function forgotPasswordReset(
|
||||
options: Omit<Enriched.PasswordResetConnectOptions, 'newPassword'>,
|
||||
newPassword?: string,
|
||||
passwordSalt?: string
|
||||
): void {
|
||||
const { userName, token } = options;
|
||||
|
||||
const params: MessageInitShape<typeof Command_ForgotPasswordResetSchema> = {
|
||||
const params: MessageInitShape<typeof Data.Command_ForgotPasswordResetSchema> = {
|
||||
...CLIENT_CONFIG,
|
||||
userName,
|
||||
token,
|
||||
|
|
@ -25,14 +26,14 @@ export function forgotPasswordReset(options: WebSocketConnectOptions, newPasswor
|
|||
: { newPassword }),
|
||||
};
|
||||
|
||||
webClient.protobuf.sendSessionCommand(Command_ForgotPasswordReset_ext, create(Command_ForgotPasswordResetSchema, params), {
|
||||
webClient.protobuf.sendSessionCommand(Data.Command_ForgotPasswordReset_ext, create(Data.Command_ForgotPasswordResetSchema, params), {
|
||||
onSuccess: () => {
|
||||
updateStatus(StatusEnum.DISCONNECTED, null);
|
||||
updateStatus(App.StatusEnum.DISCONNECTED, null);
|
||||
SessionPersistence.resetPasswordSuccess();
|
||||
disconnect();
|
||||
},
|
||||
onError: () => {
|
||||
updateStatus(StatusEnum.DISCONNECTED, null);
|
||||
updateStatus(App.StatusEnum.DISCONNECTED, null);
|
||||
SessionPersistence.resetPasswordFailed();
|
||||
disconnect();
|
||||
},
|
||||
|
|
|
|||
|
|
@ -1,12 +1,12 @@
|
|||
import { create } from '@bufbuild/protobuf';
|
||||
import webClient from '../../WebClient';
|
||||
import { Command_GetGamesOfUser_ext, Command_GetGamesOfUserSchema } from 'generated/proto/session_commands_pb';
|
||||
|
||||
import { SessionPersistence } from '../../persistence';
|
||||
import { Response_GetGamesOfUser_ext } from 'generated/proto/response_get_games_of_user_pb';
|
||||
import { Data } from '@app/types';
|
||||
|
||||
export function getGamesOfUser(userName: string): void {
|
||||
webClient.protobuf.sendSessionCommand(Command_GetGamesOfUser_ext, create(Command_GetGamesOfUserSchema, { userName }), {
|
||||
responseExt: Response_GetGamesOfUser_ext,
|
||||
webClient.protobuf.sendSessionCommand(Data.Command_GetGamesOfUser_ext, create(Data.Command_GetGamesOfUserSchema, { userName }), {
|
||||
responseExt: Data.Response_GetGamesOfUser_ext,
|
||||
onSuccess: (response) => {
|
||||
SessionPersistence.getGamesOfUser(userName, response);
|
||||
},
|
||||
|
|
|
|||
|
|
@ -1,12 +1,12 @@
|
|||
import { create } from '@bufbuild/protobuf';
|
||||
import webClient from '../../WebClient';
|
||||
import { Command_GetUserInfo_ext, Command_GetUserInfoSchema } from 'generated/proto/session_commands_pb';
|
||||
|
||||
import { SessionPersistence } from '../../persistence';
|
||||
import { Response_GetUserInfo_ext } from 'generated/proto/response_get_user_info_pb';
|
||||
import { Data } from '@app/types';
|
||||
|
||||
export function getUserInfo(userName: string): void {
|
||||
webClient.protobuf.sendSessionCommand(Command_GetUserInfo_ext, create(Command_GetUserInfoSchema, { userName }), {
|
||||
responseExt: Response_GetUserInfo_ext,
|
||||
webClient.protobuf.sendSessionCommand(Data.Command_GetUserInfo_ext, create(Data.Command_GetUserInfoSchema, { userName }), {
|
||||
responseExt: Data.Response_GetUserInfo_ext,
|
||||
onSuccess: (response) => {
|
||||
SessionPersistence.getUserInfo(response.userInfo);
|
||||
},
|
||||
|
|
|
|||
|
|
@ -1,12 +1,12 @@
|
|||
import { create } from '@bufbuild/protobuf';
|
||||
import webClient from '../../WebClient';
|
||||
import { Command_JoinRoom_ext, Command_JoinRoomSchema } from 'generated/proto/session_commands_pb';
|
||||
|
||||
import { RoomPersistence } from '../../persistence';
|
||||
import { Response_JoinRoom_ext } from 'generated/proto/response_join_room_pb';
|
||||
import { Data } from '@app/types';
|
||||
|
||||
export function joinRoom(roomId: number): void {
|
||||
webClient.protobuf.sendSessionCommand(Command_JoinRoom_ext, create(Command_JoinRoomSchema, { roomId }), {
|
||||
responseExt: Response_JoinRoom_ext,
|
||||
webClient.protobuf.sendSessionCommand(Data.Command_JoinRoom_ext, create(Data.Command_JoinRoomSchema, { roomId }), {
|
||||
responseExt: Data.Response_JoinRoom_ext,
|
||||
onSuccess: (response) => {
|
||||
if (response.roomInfo) {
|
||||
RoomPersistence.joinRoom(response.roomInfo);
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
import { create } from '@bufbuild/protobuf';
|
||||
import webClient from '../../WebClient';
|
||||
import { Command_ListRooms_ext, Command_ListRoomsSchema } from 'generated/proto/session_commands_pb';
|
||||
import { Data } from '@app/types';
|
||||
|
||||
export function listRooms(): void {
|
||||
webClient.protobuf.sendSessionCommand(Command_ListRooms_ext, create(Command_ListRoomsSchema));
|
||||
webClient.protobuf.sendSessionCommand(Data.Command_ListRooms_ext, create(Data.Command_ListRoomsSchema));
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,12 +1,12 @@
|
|||
import { create } from '@bufbuild/protobuf';
|
||||
import webClient from '../../WebClient';
|
||||
import { Command_ListUsers_ext, Command_ListUsersSchema } from 'generated/proto/session_commands_pb';
|
||||
|
||||
import { SessionPersistence } from '../../persistence';
|
||||
import { Response_ListUsers_ext } from 'generated/proto/response_list_users_pb';
|
||||
import { Data } from '@app/types';
|
||||
|
||||
export function listUsers(): void {
|
||||
webClient.protobuf.sendSessionCommand(Command_ListUsers_ext, create(Command_ListUsersSchema), {
|
||||
responseExt: Response_ListUsers_ext,
|
||||
webClient.protobuf.sendSessionCommand(Data.Command_ListUsers_ext, create(Data.Command_ListUsersSchema), {
|
||||
responseExt: Data.Response_ListUsers_ext,
|
||||
onSuccess: (response) => {
|
||||
SessionPersistence.updateUsers(response.userList);
|
||||
},
|
||||
|
|
|
|||
|
|
@ -1,13 +1,11 @@
|
|||
import { StatusEnum, WebSocketConnectOptions } from 'types';
|
||||
import { App, Enriched, Data } from '@app/types';
|
||||
import { create } from '@bufbuild/protobuf';
|
||||
import type { MessageInitShape } from '@bufbuild/protobuf';
|
||||
import { CLIENT_CONFIG } from '../../config';
|
||||
import webClient from '../../WebClient';
|
||||
import { Command_Login_ext, Command_LoginSchema } from 'generated/proto/session_commands_pb';
|
||||
|
||||
import { hashPassword } from '../../utils';
|
||||
import { SessionPersistence } from '../../persistence';
|
||||
import { Response_Login_ext } from 'generated/proto/response_login_pb';
|
||||
import { Response_ResponseCode } from 'generated/proto/response_pb';
|
||||
|
||||
import {
|
||||
disconnect,
|
||||
|
|
@ -16,10 +14,10 @@ import {
|
|||
updateStatus,
|
||||
} from './';
|
||||
|
||||
export function login(options: WebSocketConnectOptions, password?: string, passwordSalt?: string): void {
|
||||
export function login(options: Omit<Enriched.LoginConnectOptions, 'password'>, password?: string, passwordSalt?: string): void {
|
||||
const { userName, hashedPassword } = options;
|
||||
|
||||
const loginConfig: MessageInitShape<typeof Command_LoginSchema> = {
|
||||
const loginConfig: MessageInitShape<typeof Data.Command_LoginSchema> = {
|
||||
...CLIENT_CONFIG,
|
||||
clientid: 'webatrice',
|
||||
userName,
|
||||
|
|
@ -29,50 +27,52 @@ export function login(options: WebSocketConnectOptions, password?: string, passw
|
|||
};
|
||||
|
||||
const onLoginError = (message: string, extra?: () => void) => {
|
||||
updateStatus(StatusEnum.DISCONNECTED, message);
|
||||
updateStatus(App.StatusEnum.DISCONNECTED, message);
|
||||
extra?.();
|
||||
SessionPersistence.loginFailed();
|
||||
disconnect();
|
||||
};
|
||||
|
||||
webClient.protobuf.sendSessionCommand(Command_Login_ext, create(Command_LoginSchema, loginConfig), {
|
||||
responseExt: Response_Login_ext,
|
||||
webClient.protobuf.sendSessionCommand(Data.Command_Login_ext, create(Data.Command_LoginSchema, loginConfig), {
|
||||
responseExt: Data.Response_Login_ext,
|
||||
onSuccess: (resp) => {
|
||||
const { buddyList, ignoreList, userInfo } = resp;
|
||||
|
||||
SessionPersistence.updateBuddyList(buddyList);
|
||||
SessionPersistence.updateIgnoreList(ignoreList);
|
||||
SessionPersistence.updateUser(userInfo);
|
||||
const { password: _password, ...safeConfig } = loginConfig;
|
||||
SessionPersistence.loginSuccessful(safeConfig);
|
||||
SessionPersistence.loginSuccessful({ hashedPassword: loginConfig.hashedPassword });
|
||||
|
||||
listUsers();
|
||||
listRooms();
|
||||
|
||||
updateStatus(StatusEnum.LOGGED_IN, 'Logged in.');
|
||||
updateStatus(App.StatusEnum.LOGGED_IN, 'Logged in.');
|
||||
},
|
||||
onResponseCode: {
|
||||
[Response_ResponseCode.RespClientUpdateRequired]: () =>
|
||||
[Data.Response_ResponseCode.RespClientUpdateRequired]: () =>
|
||||
onLoginError('Login failed: missing features'),
|
||||
[Response_ResponseCode.RespWrongPassword]: () =>
|
||||
[Data.Response_ResponseCode.RespWrongPassword]: () =>
|
||||
onLoginError('Login failed: incorrect username or password'),
|
||||
[Response_ResponseCode.RespUsernameInvalid]: () =>
|
||||
[Data.Response_ResponseCode.RespUsernameInvalid]: () =>
|
||||
onLoginError('Login failed: incorrect username or password'),
|
||||
[Response_ResponseCode.RespWouldOverwriteOldSession]: () =>
|
||||
[Data.Response_ResponseCode.RespWouldOverwriteOldSession]: () =>
|
||||
onLoginError('Login failed: duplicated user session'),
|
||||
[Response_ResponseCode.RespUserIsBanned]: () =>
|
||||
[Data.Response_ResponseCode.RespUserIsBanned]: () =>
|
||||
onLoginError('Login failed: banned user'),
|
||||
[Response_ResponseCode.RespRegistrationRequired]: () =>
|
||||
[Data.Response_ResponseCode.RespRegistrationRequired]: () =>
|
||||
onLoginError('Login failed: registration required'),
|
||||
[Response_ResponseCode.RespClientIdRequired]: () =>
|
||||
[Data.Response_ResponseCode.RespClientIdRequired]: () =>
|
||||
onLoginError('Login failed: missing client ID'),
|
||||
[Response_ResponseCode.RespContextError]: () =>
|
||||
[Data.Response_ResponseCode.RespContextError]: () =>
|
||||
onLoginError('Login failed: server error'),
|
||||
[Response_ResponseCode.RespAccountNotActivated]: () =>
|
||||
[Data.Response_ResponseCode.RespAccountNotActivated]: () =>
|
||||
onLoginError('Login failed: account not activated',
|
||||
() => {
|
||||
const { password: _p, newPassword: _np, ...safeOptions } = options;
|
||||
SessionPersistence.accountAwaitingActivation(safeOptions);
|
||||
SessionPersistence.accountAwaitingActivation({
|
||||
host: options.host,
|
||||
port: options.port,
|
||||
userName: options.userName,
|
||||
});
|
||||
}
|
||||
),
|
||||
},
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
import { create } from '@bufbuild/protobuf';
|
||||
import webClient from '../../WebClient';
|
||||
import { Command_Message_ext, Command_MessageSchema } from 'generated/proto/session_commands_pb';
|
||||
import { Data } from '@app/types';
|
||||
|
||||
export function message(userName: string, message: string): void {
|
||||
webClient.protobuf.sendSessionCommand(Command_Message_ext, create(Command_MessageSchema, { userName, message }));
|
||||
webClient.protobuf.sendSessionCommand(Data.Command_Message_ext, create(Data.Command_MessageSchema, { userName, message }));
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,9 +1,9 @@
|
|||
import { create } from '@bufbuild/protobuf';
|
||||
import webClient from '../../WebClient';
|
||||
import { Command_Ping_ext, Command_PingSchema } from 'generated/proto/session_commands_pb';
|
||||
import { Data } from '@app/types';
|
||||
|
||||
export function ping(pingReceived: () => void): void {
|
||||
webClient.protobuf.sendSessionCommand(Command_Ping_ext, create(Command_PingSchema), {
|
||||
webClient.protobuf.sendSessionCommand(Data.Command_Ping_ext, create(Data.Command_PingSchema), {
|
||||
onResponse: () => pingReceived(),
|
||||
});
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,22 +1,19 @@
|
|||
import { ServerRegisterParams } from 'store';
|
||||
import { StatusEnum, WebSocketConnectOptions } from 'types';
|
||||
import { App, Enriched, Data } from '@app/types';
|
||||
|
||||
import { create, getExtension } from '@bufbuild/protobuf';
|
||||
import type { MessageInitShape } from '@bufbuild/protobuf';
|
||||
import { CLIENT_CONFIG } from '../../config';
|
||||
import webClient from '../../WebClient';
|
||||
import { Command_Register_ext, Command_RegisterSchema } from 'generated/proto/session_commands_pb';
|
||||
|
||||
import { SessionPersistence } from '../../persistence';
|
||||
import { hashPassword } from '../../utils';
|
||||
import { Response_ResponseCode } from 'generated/proto/response_pb';
|
||||
import { Response_Register_ext } from 'generated/proto/response_register_pb';
|
||||
|
||||
import { login, disconnect, updateStatus } from './';
|
||||
|
||||
export function register(options: WebSocketConnectOptions, password?: string, passwordSalt?: string): void {
|
||||
const { userName, email, country, realName } = options as ServerRegisterParams;
|
||||
export function register(options: Omit<Enriched.RegisterConnectOptions, 'password'>, password?: string, passwordSalt?: string): void {
|
||||
const { userName, email, country, realName } = options;
|
||||
|
||||
const params: MessageInitShape<typeof Command_RegisterSchema> = {
|
||||
const params: MessageInitShape<typeof Data.Command_RegisterSchema> = {
|
||||
...CLIENT_CONFIG,
|
||||
userName,
|
||||
email,
|
||||
|
|
@ -29,45 +26,53 @@ export function register(options: WebSocketConnectOptions, password?: string, pa
|
|||
|
||||
const onRegistrationError = (action: () => void) => {
|
||||
action();
|
||||
updateStatus(StatusEnum.DISCONNECTED, 'Registration failed');
|
||||
updateStatus(App.StatusEnum.DISCONNECTED, 'Registration failed');
|
||||
disconnect();
|
||||
};
|
||||
|
||||
webClient.protobuf.sendSessionCommand(Command_Register_ext, create(Command_RegisterSchema, params), {
|
||||
webClient.protobuf.sendSessionCommand(Data.Command_Register_ext, create(Data.Command_RegisterSchema, params), {
|
||||
onResponseCode: {
|
||||
[Response_ResponseCode.RespRegistrationAccepted]: () => {
|
||||
login(options, password, passwordSalt);
|
||||
[Data.Response_ResponseCode.RespRegistrationAccepted]: () => {
|
||||
login({
|
||||
host: options.host,
|
||||
port: options.port,
|
||||
userName: options.userName,
|
||||
reason: App.WebSocketConnectReason.LOGIN,
|
||||
}, password, passwordSalt);
|
||||
SessionPersistence.registrationSuccess();
|
||||
},
|
||||
[Response_ResponseCode.RespRegistrationAcceptedNeedsActivation]: () => {
|
||||
updateStatus(StatusEnum.DISCONNECTED, 'Registration accepted, awaiting activation');
|
||||
const { password: _p, newPassword: _np, ...safeOptions } = options;
|
||||
SessionPersistence.accountAwaitingActivation(safeOptions);
|
||||
[Data.Response_ResponseCode.RespRegistrationAcceptedNeedsActivation]: () => {
|
||||
updateStatus(App.StatusEnum.DISCONNECTED, 'Registration accepted, awaiting activation');
|
||||
SessionPersistence.accountAwaitingActivation({
|
||||
host: options.host,
|
||||
port: options.port,
|
||||
userName: options.userName,
|
||||
});
|
||||
disconnect();
|
||||
},
|
||||
[Response_ResponseCode.RespUserAlreadyExists]: () => onRegistrationError(
|
||||
[Data.Response_ResponseCode.RespUserAlreadyExists]: () => onRegistrationError(
|
||||
() => SessionPersistence.registrationUserNameError('Username is taken')
|
||||
),
|
||||
[Response_ResponseCode.RespUsernameInvalid]: () => onRegistrationError(
|
||||
[Data.Response_ResponseCode.RespUsernameInvalid]: () => onRegistrationError(
|
||||
() => SessionPersistence.registrationUserNameError('Invalid username')
|
||||
),
|
||||
[Response_ResponseCode.RespPasswordTooShort]: () => onRegistrationError(
|
||||
[Data.Response_ResponseCode.RespPasswordTooShort]: () => onRegistrationError(
|
||||
() => SessionPersistence.registrationPasswordError('Your password was too short')
|
||||
),
|
||||
[Response_ResponseCode.RespEmailRequiredToRegister]: () => onRegistrationError(
|
||||
[Data.Response_ResponseCode.RespEmailRequiredToRegister]: () => onRegistrationError(
|
||||
() => SessionPersistence.registrationRequiresEmail()
|
||||
),
|
||||
[Response_ResponseCode.RespEmailBlackListed]: () => onRegistrationError(
|
||||
[Data.Response_ResponseCode.RespEmailBlackListed]: () => onRegistrationError(
|
||||
() => SessionPersistence.registrationEmailError('This email provider has been blocked')
|
||||
),
|
||||
[Response_ResponseCode.RespTooManyRequests]: () => onRegistrationError(
|
||||
[Data.Response_ResponseCode.RespTooManyRequests]: () => onRegistrationError(
|
||||
() => SessionPersistence.registrationEmailError('Max accounts reached for this email')
|
||||
),
|
||||
[Response_ResponseCode.RespRegistrationDisabled]: () => onRegistrationError(
|
||||
[Data.Response_ResponseCode.RespRegistrationDisabled]: () => onRegistrationError(
|
||||
() => SessionPersistence.registrationFailed('Registration is currently disabled')
|
||||
),
|
||||
[Response_ResponseCode.RespUserIsBanned]: (raw) => {
|
||||
const register = getExtension(raw, Response_Register_ext);
|
||||
[Data.Response_ResponseCode.RespUserIsBanned]: (raw) => {
|
||||
const register = getExtension(raw, Data.Response_Register_ext);
|
||||
onRegistrationError(
|
||||
() => SessionPersistence.registrationFailed(register.deniedReasonStr, Number(register.deniedEndTime))
|
||||
);
|
||||
|
|
|
|||
|
|
@ -1,7 +1,8 @@
|
|||
import { create } from '@bufbuild/protobuf';
|
||||
import webClient from '../../WebClient';
|
||||
import { Command_RemoveFromList_ext, Command_RemoveFromListSchema } from 'generated/proto/session_commands_pb';
|
||||
|
||||
import { SessionPersistence } from '../../persistence';
|
||||
import { Data } from '@app/types';
|
||||
|
||||
export function removeFromBuddyList(userName: string): void {
|
||||
removeFromList('buddy', userName);
|
||||
|
|
@ -12,7 +13,7 @@ export function removeFromIgnoreList(userName: string): void {
|
|||
}
|
||||
|
||||
export function removeFromList(list: string, userName: string): void {
|
||||
webClient.protobuf.sendSessionCommand(Command_RemoveFromList_ext, create(Command_RemoveFromListSchema, { list, userName }), {
|
||||
webClient.protobuf.sendSessionCommand(Data.Command_RemoveFromList_ext, create(Data.Command_RemoveFromListSchema, { list, userName }), {
|
||||
onSuccess: () => {
|
||||
SessionPersistence.removeFromList(list, userName);
|
||||
},
|
||||
|
|
|
|||
|
|
@ -1,10 +1,11 @@
|
|||
import { create } from '@bufbuild/protobuf';
|
||||
import webClient from '../../WebClient';
|
||||
import { Command_ReplayDeleteMatchSchema, Command_ReplayDeleteMatch_ext } from 'generated/proto/command_replay_delete_match_pb';
|
||||
|
||||
import { SessionPersistence } from '../../persistence';
|
||||
import { Data } from '@app/types';
|
||||
|
||||
export function replayDeleteMatch(gameId: number): void {
|
||||
webClient.protobuf.sendSessionCommand(Command_ReplayDeleteMatch_ext, create(Command_ReplayDeleteMatchSchema, { gameId }), {
|
||||
webClient.protobuf.sendSessionCommand(Data.Command_ReplayDeleteMatch_ext, create(Data.Command_ReplayDeleteMatchSchema, { gameId }), {
|
||||
onSuccess: () => {
|
||||
SessionPersistence.replayDeleteMatch(gameId);
|
||||
},
|
||||
|
|
|
|||
|
|
@ -1,11 +1,10 @@
|
|||
import { create } from '@bufbuild/protobuf';
|
||||
import webClient from '../../WebClient';
|
||||
import { Command_ReplayGetCodeSchema, Command_ReplayGetCode_ext } from 'generated/proto/command_replay_get_code_pb';
|
||||
import { Response_ReplayGetCode_ext } from 'generated/proto/response_replay_get_code_pb';
|
||||
import { Data } from '@app/types';
|
||||
|
||||
export function replayGetCode(gameId: number, onCodeReceived: (code: string) => void): void {
|
||||
webClient.protobuf.sendSessionCommand(Command_ReplayGetCode_ext, create(Command_ReplayGetCodeSchema, { gameId }), {
|
||||
responseExt: Response_ReplayGetCode_ext,
|
||||
webClient.protobuf.sendSessionCommand(Data.Command_ReplayGetCode_ext, create(Data.Command_ReplayGetCodeSchema, { gameId }), {
|
||||
responseExt: Data.Response_ReplayGetCode_ext,
|
||||
onSuccess: (response) => {
|
||||
onCodeReceived(response.replayCode);
|
||||
},
|
||||
|
|
|
|||
|
|
@ -1,12 +1,12 @@
|
|||
import { create } from '@bufbuild/protobuf';
|
||||
import webClient from '../../WebClient';
|
||||
import { Command_ReplayListSchema, Command_ReplayList_ext } from 'generated/proto/command_replay_list_pb';
|
||||
|
||||
import { SessionPersistence } from '../../persistence';
|
||||
import { Response_ReplayList_ext } from 'generated/proto/response_replay_list_pb';
|
||||
import { Data } from '@app/types';
|
||||
|
||||
export function replayList(): void {
|
||||
webClient.protobuf.sendSessionCommand(Command_ReplayList_ext, create(Command_ReplayListSchema), {
|
||||
responseExt: Response_ReplayList_ext,
|
||||
webClient.protobuf.sendSessionCommand(Data.Command_ReplayList_ext, create(Data.Command_ReplayListSchema), {
|
||||
responseExt: Data.Response_ReplayList_ext,
|
||||
onSuccess: (response) => {
|
||||
SessionPersistence.replayList(response.matchList);
|
||||
},
|
||||
|
|
|
|||
|
|
@ -1,12 +1,17 @@
|
|||
import { create } from '@bufbuild/protobuf';
|
||||
import webClient from '../../WebClient';
|
||||
import { Command_ReplayModifyMatchSchema, Command_ReplayModifyMatch_ext } from 'generated/proto/command_replay_modify_match_pb';
|
||||
|
||||
import { SessionPersistence } from '../../persistence';
|
||||
import { Data } from '@app/types';
|
||||
|
||||
export function replayModifyMatch(gameId: number, doNotHide: boolean): void {
|
||||
webClient.protobuf.sendSessionCommand(Command_ReplayModifyMatch_ext, create(Command_ReplayModifyMatchSchema, { gameId, doNotHide }), {
|
||||
onSuccess: () => {
|
||||
SessionPersistence.replayModifyMatch(gameId, doNotHide);
|
||||
},
|
||||
});
|
||||
webClient.protobuf.sendSessionCommand(
|
||||
Data.Command_ReplayModifyMatch_ext,
|
||||
create(Data.Command_ReplayModifyMatchSchema, { gameId, doNotHide }),
|
||||
{
|
||||
onSuccess: () => {
|
||||
SessionPersistence.replayModifyMatch(gameId, doNotHide);
|
||||
},
|
||||
}
|
||||
);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,13 +1,13 @@
|
|||
import { create } from '@bufbuild/protobuf';
|
||||
import webClient from '../../WebClient';
|
||||
import { Command_ReplaySubmitCodeSchema, Command_ReplaySubmitCode_ext } from 'generated/proto/command_replay_submit_code_pb';
|
||||
import { Data } from '@app/types';
|
||||
|
||||
export function replaySubmitCode(
|
||||
replayCode: string,
|
||||
onSuccess?: () => void,
|
||||
onError?: (responseCode: number) => void,
|
||||
): void {
|
||||
webClient.protobuf.sendSessionCommand(Command_ReplaySubmitCode_ext, create(Command_ReplaySubmitCodeSchema, { replayCode }), {
|
||||
webClient.protobuf.sendSessionCommand(Data.Command_ReplaySubmitCode_ext, create(Data.Command_ReplaySubmitCodeSchema, { replayCode }), {
|
||||
onSuccess,
|
||||
onError,
|
||||
});
|
||||
|
|
|
|||
|
|
@ -1,15 +1,10 @@
|
|||
import { RequestPasswordSaltParams } from 'store';
|
||||
import { StatusEnum, WebSocketConnectOptions, WebSocketConnectReason } from 'types';
|
||||
import { App, Enriched, Data } from '@app/types';
|
||||
|
||||
import { create } from '@bufbuild/protobuf';
|
||||
import { CLIENT_CONFIG } from '../../config';
|
||||
import webClient from '../../WebClient';
|
||||
import {
|
||||
Command_RequestPasswordSalt_ext, Command_RequestPasswordSaltSchema,
|
||||
} from 'generated/proto/session_commands_pb';
|
||||
|
||||
import { SessionPersistence } from '../../persistence';
|
||||
import { Response_PasswordSalt_ext } from 'generated/proto/response_password_salt_pb';
|
||||
import { Response_ResponseCode } from 'generated/proto/response_pb';
|
||||
|
||||
import {
|
||||
activate,
|
||||
|
|
@ -19,15 +14,20 @@ import {
|
|||
updateStatus
|
||||
} from './';
|
||||
|
||||
export function requestPasswordSalt(options: WebSocketConnectOptions, password?: string, newPassword?: string): void {
|
||||
const { userName } = options as RequestPasswordSaltParams;
|
||||
type PasswordSaltOptions =
|
||||
| Omit<Enriched.LoginConnectOptions, 'password'>
|
||||
| Omit<Enriched.ActivateConnectOptions, 'password'>
|
||||
| Omit<Enriched.PasswordResetConnectOptions, 'newPassword'>;
|
||||
|
||||
export function requestPasswordSalt(options: PasswordSaltOptions, password?: string, newPassword?: string): void {
|
||||
const { userName } = options;
|
||||
|
||||
const onFailure = () => {
|
||||
switch (options.reason) {
|
||||
case WebSocketConnectReason.ACTIVATE_ACCOUNT:
|
||||
case App.WebSocketConnectReason.ACTIVATE_ACCOUNT:
|
||||
SessionPersistence.accountActivationFailed();
|
||||
break;
|
||||
case WebSocketConnectReason.PASSWORD_RESET:
|
||||
case App.WebSocketConnectReason.PASSWORD_RESET:
|
||||
SessionPersistence.resetPasswordFailed();
|
||||
break;
|
||||
default:
|
||||
|
|
@ -36,19 +36,19 @@ export function requestPasswordSalt(options: WebSocketConnectOptions, password?:
|
|||
disconnect();
|
||||
};
|
||||
|
||||
webClient.protobuf.sendSessionCommand(Command_RequestPasswordSalt_ext, create(Command_RequestPasswordSaltSchema, {
|
||||
webClient.protobuf.sendSessionCommand(Data.Command_RequestPasswordSalt_ext, create(Data.Command_RequestPasswordSaltSchema, {
|
||||
...CLIENT_CONFIG,
|
||||
userName,
|
||||
}), {
|
||||
responseExt: Response_PasswordSalt_ext,
|
||||
responseExt: Data.Response_PasswordSalt_ext,
|
||||
onSuccess: (resp) => {
|
||||
const passwordSalt = resp?.passwordSalt;
|
||||
|
||||
switch (options.reason) {
|
||||
case WebSocketConnectReason.ACTIVATE_ACCOUNT:
|
||||
case App.WebSocketConnectReason.ACTIVATE_ACCOUNT:
|
||||
activate(options, password, passwordSalt);
|
||||
break;
|
||||
case WebSocketConnectReason.PASSWORD_RESET:
|
||||
case App.WebSocketConnectReason.PASSWORD_RESET:
|
||||
forgotPasswordReset(options, newPassword, passwordSalt);
|
||||
break;
|
||||
default:
|
||||
|
|
@ -56,13 +56,13 @@ export function requestPasswordSalt(options: WebSocketConnectOptions, password?:
|
|||
}
|
||||
},
|
||||
onResponseCode: {
|
||||
[Response_ResponseCode.RespRegistrationRequired]: () => {
|
||||
updateStatus(StatusEnum.DISCONNECTED, 'Login failed: registration required');
|
||||
[Data.Response_ResponseCode.RespRegistrationRequired]: () => {
|
||||
updateStatus(App.StatusEnum.DISCONNECTED, 'Login failed: registration required');
|
||||
onFailure();
|
||||
},
|
||||
},
|
||||
onError: () => {
|
||||
updateStatus(StatusEnum.DISCONNECTED, 'Login failed: Unknown Reason');
|
||||
updateStatus(App.StatusEnum.DISCONNECTED, 'Login failed: Unknown Reason');
|
||||
onFailure();
|
||||
},
|
||||
});
|
||||
|
|
|
|||
|
|
@ -30,24 +30,11 @@ import { makeCallbackHelpers } from '../../__mocks__/callbackHelpers';
|
|||
import { SessionPersistence } from '../../persistence';
|
||||
import webClient from '../../WebClient';
|
||||
import * as SessionIndexMocks from './';
|
||||
import { StatusEnum, WebSocketConnectReason } from 'types';
|
||||
import { App, Enriched, Data } from '@app/types';
|
||||
import { hashPassword, generateSalt, passwordSaltSupported } from '../../utils';
|
||||
import { Response_ResponseCode } from 'generated/proto/response_pb';
|
||||
import {
|
||||
Command_Activate_ext,
|
||||
Command_ForgotPasswordChallenge_ext,
|
||||
Command_ForgotPasswordRequest_ext,
|
||||
Command_ForgotPasswordReset_ext,
|
||||
Command_Login_ext,
|
||||
Command_Register_ext,
|
||||
Command_RequestPasswordSalt_ext,
|
||||
} from 'generated/proto/session_commands_pb';
|
||||
import { Response_ForgotPasswordRequest_ext } from 'generated/proto/response_forgotpasswordrequest_pb';
|
||||
import { Response_Login_ext } from 'generated/proto/response_login_pb';
|
||||
import { Response_PasswordSalt_ext } from 'generated/proto/response_password_salt_pb';
|
||||
import { Response_Register_ext, Response_RegisterSchema } from 'generated/proto/response_register_pb';
|
||||
|
||||
import { create, setExtension } from '@bufbuild/protobuf';
|
||||
import { ResponseSchema } from 'generated/proto/response_pb';
|
||||
|
||||
import { connect } from './connect';
|
||||
import { updateStatus } from './updateStatus';
|
||||
import { login } from './login';
|
||||
|
|
@ -63,8 +50,61 @@ const { invokeOnSuccess, invokeResponseCode, invokeOnError } = makeCallbackHelpe
|
|||
2
|
||||
);
|
||||
|
||||
const baseTransport = { host: 'h', port: '1' };
|
||||
const makeLoginOpts = (overrides: Partial<Enriched.LoginConnectOptions> = {}): Enriched.LoginConnectOptions => ({
|
||||
...baseTransport,
|
||||
userName: 'alice',
|
||||
reason: App.WebSocketConnectReason.LOGIN,
|
||||
...overrides,
|
||||
});
|
||||
const makeRegisterOpts = (
|
||||
overrides: Partial<Enriched.RegisterConnectOptions> = {}
|
||||
): Enriched.RegisterConnectOptions => ({
|
||||
...baseTransport,
|
||||
userName: 'alice',
|
||||
password: 'pw',
|
||||
email: 'a@b.com',
|
||||
country: 'US',
|
||||
realName: 'Al',
|
||||
reason: App.WebSocketConnectReason.REGISTER,
|
||||
...overrides,
|
||||
});
|
||||
const makeActivateOpts = (
|
||||
overrides: Partial<Enriched.ActivateConnectOptions> = {}
|
||||
): Enriched.ActivateConnectOptions => ({
|
||||
...baseTransport,
|
||||
userName: 'alice',
|
||||
token: 'tok',
|
||||
reason: App.WebSocketConnectReason.ACTIVATE_ACCOUNT,
|
||||
...overrides,
|
||||
});
|
||||
const makeForgotRequestOpts = (): Enriched.PasswordResetRequestConnectOptions => ({
|
||||
...baseTransport,
|
||||
userName: 'alice',
|
||||
reason: App.WebSocketConnectReason.PASSWORD_RESET_REQUEST,
|
||||
});
|
||||
const makeForgotChallengeOpts = (): Enriched.PasswordResetChallengeConnectOptions => ({
|
||||
...baseTransport,
|
||||
userName: 'alice',
|
||||
email: 'a@b.com',
|
||||
reason: App.WebSocketConnectReason.PASSWORD_RESET_CHALLENGE,
|
||||
});
|
||||
const makeForgotResetOpts = (): Enriched.PasswordResetConnectOptions => ({
|
||||
...baseTransport,
|
||||
userName: 'alice',
|
||||
token: 'tok',
|
||||
newPassword: 'newpw',
|
||||
reason: App.WebSocketConnectReason.PASSWORD_RESET,
|
||||
});
|
||||
const makeSaltOpts = (
|
||||
reason: App.WebSocketConnectReason,
|
||||
extras: Record<string, unknown> = {}
|
||||
) => ({ ...baseTransport, userName: 'alice', reason, ...extras } as
|
||||
| Enriched.LoginConnectOptions
|
||||
| Enriched.ActivateConnectOptions
|
||||
| Enriched.PasswordResetConnectOptions);
|
||||
|
||||
beforeEach(() => {
|
||||
vi.clearAllMocks();
|
||||
(hashPassword as Mock).mockReturnValue('hashed_pw');
|
||||
(generateSalt as Mock).mockReturnValue('randSalt');
|
||||
(passwordSaltSupported as Mock).mockReturnValue(0);
|
||||
|
|
@ -76,45 +116,46 @@ beforeEach(() => {
|
|||
describe('connect', () => {
|
||||
|
||||
it('calls updateStatus CONNECTING for LOGIN reason', () => {
|
||||
connect({ host: 'h', port: 1 } as any, WebSocketConnectReason.LOGIN);
|
||||
expect(SessionIndexMocks.updateStatus).toHaveBeenCalledWith(StatusEnum.CONNECTING, 'Connecting...');
|
||||
connect({ host: 'h', port: '1', userName: 'u', reason: App.WebSocketConnectReason.LOGIN });
|
||||
expect(SessionIndexMocks.updateStatus).toHaveBeenCalledWith(App.StatusEnum.CONNECTING, 'Connecting...');
|
||||
expect(webClient.connect).toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it('calls updateStatus CONNECTING for REGISTER reason', () => {
|
||||
connect({ host: 'h', port: 1 } as any, WebSocketConnectReason.REGISTER);
|
||||
expect(SessionIndexMocks.updateStatus).toHaveBeenCalledWith(StatusEnum.CONNECTING, 'Connecting...');
|
||||
connect(makeRegisterOpts({ userName: 'u', realName: 'U' }));
|
||||
expect(SessionIndexMocks.updateStatus).toHaveBeenCalledWith(App.StatusEnum.CONNECTING, 'Connecting...');
|
||||
});
|
||||
|
||||
it('calls updateStatus CONNECTING for ACTIVATE_ACCOUNT reason', () => {
|
||||
connect({ host: 'h', port: 1 } as any, WebSocketConnectReason.ACTIVATE_ACCOUNT);
|
||||
expect(SessionIndexMocks.updateStatus).toHaveBeenCalledWith(StatusEnum.CONNECTING, 'Connecting...');
|
||||
connect({ host: 'h', port: '1', userName: 'u', token: 'tok', reason: App.WebSocketConnectReason.ACTIVATE_ACCOUNT });
|
||||
expect(SessionIndexMocks.updateStatus).toHaveBeenCalledWith(App.StatusEnum.CONNECTING, 'Connecting...');
|
||||
});
|
||||
|
||||
it('calls updateStatus CONNECTING for PASSWORD_RESET_REQUEST reason', () => {
|
||||
connect({ host: 'h', port: 1 } as any, WebSocketConnectReason.PASSWORD_RESET_REQUEST);
|
||||
expect(SessionIndexMocks.updateStatus).toHaveBeenCalledWith(StatusEnum.CONNECTING, 'Connecting...');
|
||||
connect({ host: 'h', port: '1', userName: 'u', reason: App.WebSocketConnectReason.PASSWORD_RESET_REQUEST });
|
||||
expect(SessionIndexMocks.updateStatus).toHaveBeenCalledWith(App.StatusEnum.CONNECTING, 'Connecting...');
|
||||
});
|
||||
|
||||
it('calls updateStatus CONNECTING for PASSWORD_RESET_CHALLENGE reason', () => {
|
||||
connect({ host: 'h', port: 1 } as any, WebSocketConnectReason.PASSWORD_RESET_CHALLENGE);
|
||||
expect(SessionIndexMocks.updateStatus).toHaveBeenCalledWith(StatusEnum.CONNECTING, 'Connecting...');
|
||||
connect({ host: 'h', port: '1', userName: 'u', email: 'a@b.com', reason: App.WebSocketConnectReason.PASSWORD_RESET_CHALLENGE });
|
||||
expect(SessionIndexMocks.updateStatus).toHaveBeenCalledWith(App.StatusEnum.CONNECTING, 'Connecting...');
|
||||
});
|
||||
|
||||
it('calls updateStatus CONNECTING for PASSWORD_RESET reason', () => {
|
||||
connect({ host: 'h', port: 1 } as any, WebSocketConnectReason.PASSWORD_RESET);
|
||||
expect(SessionIndexMocks.updateStatus).toHaveBeenCalledWith(StatusEnum.CONNECTING, 'Connecting...');
|
||||
connect({ host: 'h', port: '1', userName: 'u', token: 'tok', newPassword: 'newpw', reason: App.WebSocketConnectReason.PASSWORD_RESET });
|
||||
expect(SessionIndexMocks.updateStatus).toHaveBeenCalledWith(App.StatusEnum.CONNECTING, 'Connecting...');
|
||||
});
|
||||
|
||||
it('calls testConnect for TEST_CONNECTION reason', () => {
|
||||
connect({ host: 'h', port: 1 } as any, WebSocketConnectReason.TEST_CONNECTION);
|
||||
connect({ host: 'h', port: '1', reason: App.WebSocketConnectReason.TEST_CONNECTION });
|
||||
expect(webClient.testConnect).toHaveBeenCalled();
|
||||
expect(webClient.connect).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it('calls updateStatus DISCONNECTED for unknown reason', () => {
|
||||
connect({ host: 'h', port: 1 } as any, 999 as WebSocketConnectReason);
|
||||
expect(SessionIndexMocks.updateStatus).toHaveBeenCalledWith(StatusEnum.DISCONNECTED, expect.stringContaining('Unknown'));
|
||||
const bogus = { host: 'h', port: '1', reason: 999 as App.WebSocketConnectReason };
|
||||
connect(bogus as Enriched.WebSocketConnectOptions);
|
||||
expect(SessionIndexMocks.updateStatus).toHaveBeenCalledWith(App.StatusEnum.DISCONNECTED, expect.stringContaining('Unknown'));
|
||||
});
|
||||
});
|
||||
|
||||
|
|
@ -124,9 +165,9 @@ describe('connect', () => {
|
|||
describe('updateStatus', () => {
|
||||
|
||||
it('calls SessionPersistence.updateStatus and webClient.updateStatus', () => {
|
||||
updateStatus(StatusEnum.CONNECTED, 'OK');
|
||||
expect(SessionPersistence.updateStatus).toHaveBeenCalledWith(StatusEnum.CONNECTED, 'OK');
|
||||
expect(webClient.updateStatus).toHaveBeenCalledWith(StatusEnum.CONNECTED);
|
||||
updateStatus(App.StatusEnum.CONNECTED, 'OK');
|
||||
expect(SessionPersistence.updateStatus).toHaveBeenCalledWith(App.StatusEnum.CONNECTED, 'OK');
|
||||
expect(webClient.updateStatus).toHaveBeenCalledWith(App.StatusEnum.CONNECTED);
|
||||
});
|
||||
});
|
||||
|
||||
|
|
@ -136,34 +177,34 @@ describe('updateStatus', () => {
|
|||
describe('login', () => {
|
||||
|
||||
it('sends Command_Login with plain password when no salt', () => {
|
||||
login({ userName: 'alice' } as any, 'pw');
|
||||
login(makeLoginOpts(), 'pw');
|
||||
expect(webClient.protobuf.sendSessionCommand).toHaveBeenCalledWith(
|
||||
Command_Login_ext,
|
||||
Data.Command_Login_ext,
|
||||
expect.objectContaining({ password: 'pw' }),
|
||||
expect.objectContaining({ responseExt: Response_Login_ext })
|
||||
expect.objectContaining({ responseExt: Data.Response_Login_ext })
|
||||
);
|
||||
});
|
||||
|
||||
it('sends Command_Login with hashedPassword when salt is given', () => {
|
||||
login({ userName: 'alice' } as any, 'pw', 'salt');
|
||||
login(makeLoginOpts(), 'pw', 'salt');
|
||||
expect(webClient.protobuf.sendSessionCommand).toHaveBeenCalledWith(
|
||||
Command_Login_ext,
|
||||
Data.Command_Login_ext,
|
||||
expect.objectContaining({ hashedPassword: 'hashed_pw' }),
|
||||
expect.objectContaining({ responseExt: Response_Login_ext })
|
||||
expect.objectContaining({ responseExt: Data.Response_Login_ext })
|
||||
);
|
||||
});
|
||||
|
||||
it('uses options.hashedPassword if provided', () => {
|
||||
login({ userName: 'alice', hashedPassword: 'pre_hashed' } as any, 'pw', 'salt');
|
||||
login(makeLoginOpts({ hashedPassword: 'pre_hashed' }), 'pw', 'salt');
|
||||
expect(webClient.protobuf.sendSessionCommand).toHaveBeenCalledWith(
|
||||
Command_Login_ext,
|
||||
Data.Command_Login_ext,
|
||||
expect.objectContaining({ hashedPassword: 'pre_hashed' }),
|
||||
expect.objectContaining({ responseExt: Response_Login_ext })
|
||||
expect.objectContaining({ responseExt: Data.Response_Login_ext })
|
||||
);
|
||||
});
|
||||
|
||||
it('onSuccess dispatches buddy/ignore/user and calls listUsers/listRooms', () => {
|
||||
login({ userName: 'alice' } as any, 'pw');
|
||||
login(makeLoginOpts(), 'pw');
|
||||
const loginResp = { buddyList: [], ignoreList: [], userInfo: { name: 'alice' } };
|
||||
invokeOnSuccess(loginResp, { responseCode: 0 });
|
||||
expect(SessionPersistence.updateBuddyList).toHaveBeenCalledWith([]);
|
||||
|
|
@ -172,11 +213,11 @@ describe('login', () => {
|
|||
expect(SessionPersistence.loginSuccessful).toHaveBeenCalled();
|
||||
expect(SessionIndexMocks.listUsers).toHaveBeenCalled();
|
||||
expect(SessionIndexMocks.listRooms).toHaveBeenCalled();
|
||||
expect(SessionIndexMocks.updateStatus).toHaveBeenCalledWith(StatusEnum.LOGGED_IN, 'Logged in.');
|
||||
expect(SessionIndexMocks.updateStatus).toHaveBeenCalledWith(App.StatusEnum.LOGGED_IN, 'Logged in.');
|
||||
});
|
||||
|
||||
it('onSuccess does NOT pass plaintext password to loginSuccessful', () => {
|
||||
login({ userName: 'alice' } as any, 'secret');
|
||||
login(makeLoginOpts(), 'secret');
|
||||
const loginResp = { buddyList: [], ignoreList: [], userInfo: { name: 'alice' } };
|
||||
invokeOnSuccess(loginResp, { responseCode: 0 });
|
||||
const calledWith = (SessionPersistence.loginSuccessful as Mock).mock.calls[0][0];
|
||||
|
|
@ -184,7 +225,7 @@ describe('login', () => {
|
|||
});
|
||||
|
||||
it('onSuccess passes hashedPassword to loginSuccessful when salt is used', () => {
|
||||
login({ userName: 'alice' } as any, 'pw', 'salt');
|
||||
login({ host: 'h', port: '1', userName: 'alice', reason: App.WebSocketConnectReason.LOGIN }, 'pw', 'salt');
|
||||
const loginResp = { buddyList: [], ignoreList: [], userInfo: { name: 'alice' } };
|
||||
invokeOnSuccess(loginResp, { responseCode: 0 });
|
||||
const calledWith = (SessionPersistence.loginSuccessful as Mock).mock.calls[0][0];
|
||||
|
|
@ -192,57 +233,57 @@ describe('login', () => {
|
|||
});
|
||||
|
||||
it('onResponseCode RespClientUpdateRequired calls onLoginError', () => {
|
||||
login({ userName: 'alice' } as any, 'pw');
|
||||
invokeResponseCode(Response_ResponseCode.RespClientUpdateRequired);
|
||||
login(makeLoginOpts(), 'pw');
|
||||
invokeResponseCode(Data.Response_ResponseCode.RespClientUpdateRequired);
|
||||
expect(SessionPersistence.loginFailed).toHaveBeenCalled();
|
||||
expect(SessionIndexMocks.disconnect).toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it('onResponseCode RespWrongPassword', () => {
|
||||
login({ userName: 'alice' } as any, 'pw');
|
||||
invokeResponseCode(Response_ResponseCode.RespWrongPassword);
|
||||
login(makeLoginOpts(), 'pw');
|
||||
invokeResponseCode(Data.Response_ResponseCode.RespWrongPassword);
|
||||
expect(SessionPersistence.loginFailed).toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it('onResponseCode RespUsernameInvalid', () => {
|
||||
login({ userName: 'alice' } as any, 'pw');
|
||||
invokeResponseCode(Response_ResponseCode.RespUsernameInvalid);
|
||||
login(makeLoginOpts(), 'pw');
|
||||
invokeResponseCode(Data.Response_ResponseCode.RespUsernameInvalid);
|
||||
expect(SessionPersistence.loginFailed).toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it('onResponseCode RespWouldOverwriteOldSession', () => {
|
||||
login({ userName: 'alice' } as any, 'pw');
|
||||
invokeResponseCode(Response_ResponseCode.RespWouldOverwriteOldSession);
|
||||
login(makeLoginOpts(), 'pw');
|
||||
invokeResponseCode(Data.Response_ResponseCode.RespWouldOverwriteOldSession);
|
||||
expect(SessionPersistence.loginFailed).toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it('onResponseCode RespUserIsBanned', () => {
|
||||
login({ userName: 'alice' } as any, 'pw');
|
||||
invokeResponseCode(Response_ResponseCode.RespUserIsBanned);
|
||||
login(makeLoginOpts(), 'pw');
|
||||
invokeResponseCode(Data.Response_ResponseCode.RespUserIsBanned);
|
||||
expect(SessionPersistence.loginFailed).toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it('onResponseCode RespRegistrationRequired', () => {
|
||||
login({ userName: 'alice' } as any, 'pw');
|
||||
invokeResponseCode(Response_ResponseCode.RespRegistrationRequired);
|
||||
login(makeLoginOpts(), 'pw');
|
||||
invokeResponseCode(Data.Response_ResponseCode.RespRegistrationRequired);
|
||||
expect(SessionPersistence.loginFailed).toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it('onResponseCode RespClientIdRequired', () => {
|
||||
login({ userName: 'alice' } as any, 'pw');
|
||||
invokeResponseCode(Response_ResponseCode.RespClientIdRequired);
|
||||
login(makeLoginOpts(), 'pw');
|
||||
invokeResponseCode(Data.Response_ResponseCode.RespClientIdRequired);
|
||||
expect(SessionPersistence.loginFailed).toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it('onResponseCode RespContextError', () => {
|
||||
login({ userName: 'alice' } as any, 'pw');
|
||||
invokeResponseCode(Response_ResponseCode.RespContextError);
|
||||
login(makeLoginOpts(), 'pw');
|
||||
invokeResponseCode(Data.Response_ResponseCode.RespContextError);
|
||||
expect(SessionPersistence.loginFailed).toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it('onResponseCode RespAccountNotActivated calls accountAwaitingActivation without password in options', () => {
|
||||
login({ userName: 'alice', password: 'leaked' } as any, 'pw');
|
||||
invokeResponseCode(Response_ResponseCode.RespAccountNotActivated);
|
||||
login(makeLoginOpts({ password: 'leaked' }), 'pw');
|
||||
invokeResponseCode(Data.Response_ResponseCode.RespAccountNotActivated);
|
||||
expect(SessionPersistence.accountAwaitingActivation).toHaveBeenCalledWith(
|
||||
expect.not.objectContaining({ password: expect.anything() })
|
||||
);
|
||||
|
|
@ -250,7 +291,7 @@ describe('login', () => {
|
|||
});
|
||||
|
||||
it('onError calls onLoginError with unknown error message', () => {
|
||||
login({ userName: 'alice' } as any, 'pw');
|
||||
login(makeLoginOpts(), 'pw');
|
||||
invokeOnError(999);
|
||||
expect(SessionPersistence.loginFailed).toHaveBeenCalled();
|
||||
});
|
||||
|
|
@ -262,40 +303,40 @@ describe('login', () => {
|
|||
describe('register', () => {
|
||||
|
||||
it('sends Command_Register with plain password when no salt', () => {
|
||||
register({ userName: 'alice', email: 'a@b.com', country: 'US', realName: 'Al' } as any, 'pw');
|
||||
register(makeRegisterOpts(), 'pw');
|
||||
expect(webClient.protobuf.sendSessionCommand).toHaveBeenCalledWith(
|
||||
Command_Register_ext,
|
||||
Data.Command_Register_ext,
|
||||
expect.objectContaining({ password: 'pw' }),
|
||||
expect.any(Object)
|
||||
);
|
||||
});
|
||||
|
||||
it('uses hashedPassword when salt is provided', () => {
|
||||
register({ userName: 'alice' } as any, 'pw', 'salt');
|
||||
register(makeRegisterOpts(), 'pw', 'salt');
|
||||
expect(webClient.protobuf.sendSessionCommand).toHaveBeenCalledWith(
|
||||
Command_Register_ext,
|
||||
Data.Command_Register_ext,
|
||||
expect.objectContaining({ hashedPassword: 'hashed_pw' }),
|
||||
expect.any(Object)
|
||||
);
|
||||
});
|
||||
|
||||
it('RespRegistrationAccepted calls login without salt and registrationSuccess', () => {
|
||||
register({ userName: 'alice' } as any, 'pw');
|
||||
invokeResponseCode(Response_ResponseCode.RespRegistrationAccepted);
|
||||
register(makeRegisterOpts(), 'pw');
|
||||
invokeResponseCode(Data.Response_ResponseCode.RespRegistrationAccepted);
|
||||
expect(SessionIndexMocks.login).toHaveBeenCalledWith(expect.any(Object), 'pw', undefined);
|
||||
expect(SessionPersistence.registrationSuccess).toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it('RespRegistrationAccepted forwards salt to login', () => {
|
||||
register({ userName: 'alice' } as any, 'pw', 'mySalt');
|
||||
invokeResponseCode(Response_ResponseCode.RespRegistrationAccepted);
|
||||
register(makeRegisterOpts(), 'pw', 'mySalt');
|
||||
invokeResponseCode(Data.Response_ResponseCode.RespRegistrationAccepted);
|
||||
expect(SessionIndexMocks.login).toHaveBeenCalledWith(expect.any(Object), 'pw', 'mySalt');
|
||||
expect(SessionPersistence.registrationSuccess).toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it('RespRegistrationAcceptedNeedsActivation calls accountAwaitingActivation without password in options', () => {
|
||||
register({ userName: 'alice', password: 'leaked' } as any, 'pw');
|
||||
invokeResponseCode(Response_ResponseCode.RespRegistrationAcceptedNeedsActivation);
|
||||
register(makeRegisterOpts({ password: 'leaked' }), 'pw');
|
||||
invokeResponseCode(Data.Response_ResponseCode.RespRegistrationAcceptedNeedsActivation);
|
||||
expect(SessionPersistence.accountAwaitingActivation).toHaveBeenCalledWith(
|
||||
expect.not.objectContaining({ password: expect.anything() })
|
||||
);
|
||||
|
|
@ -303,57 +344,59 @@ describe('register', () => {
|
|||
});
|
||||
|
||||
it('RespUserAlreadyExists calls registrationUserNameError', () => {
|
||||
register({ userName: 'alice' } as any, 'pw');
|
||||
invokeResponseCode(Response_ResponseCode.RespUserAlreadyExists);
|
||||
register(makeRegisterOpts(), 'pw');
|
||||
invokeResponseCode(Data.Response_ResponseCode.RespUserAlreadyExists);
|
||||
expect(SessionPersistence.registrationUserNameError).toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it('RespUsernameInvalid calls registrationUserNameError', () => {
|
||||
register({ userName: 'alice' } as any, 'pw');
|
||||
invokeResponseCode(Response_ResponseCode.RespUsernameInvalid);
|
||||
register(makeRegisterOpts(), 'pw');
|
||||
invokeResponseCode(Data.Response_ResponseCode.RespUsernameInvalid);
|
||||
expect(SessionPersistence.registrationUserNameError).toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it('RespPasswordTooShort calls registrationPasswordError', () => {
|
||||
register({ userName: 'alice' } as any, 'pw');
|
||||
invokeResponseCode(Response_ResponseCode.RespPasswordTooShort);
|
||||
register(makeRegisterOpts(), 'pw');
|
||||
invokeResponseCode(Data.Response_ResponseCode.RespPasswordTooShort);
|
||||
expect(SessionPersistence.registrationPasswordError).toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it('RespEmailRequiredToRegister calls registrationRequiresEmail', () => {
|
||||
register({ userName: 'alice' } as any, 'pw');
|
||||
invokeResponseCode(Response_ResponseCode.RespEmailRequiredToRegister);
|
||||
register(makeRegisterOpts(), 'pw');
|
||||
invokeResponseCode(Data.Response_ResponseCode.RespEmailRequiredToRegister);
|
||||
expect(SessionPersistence.registrationRequiresEmail).toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it('RespEmailBlackListed calls registrationEmailError', () => {
|
||||
register({ userName: 'alice' } as any, 'pw');
|
||||
invokeResponseCode(Response_ResponseCode.RespEmailBlackListed);
|
||||
register(makeRegisterOpts(), 'pw');
|
||||
invokeResponseCode(Data.Response_ResponseCode.RespEmailBlackListed);
|
||||
expect(SessionPersistence.registrationEmailError).toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it('RespTooManyRequests calls registrationEmailError', () => {
|
||||
register({ userName: 'alice' } as any, 'pw');
|
||||
invokeResponseCode(Response_ResponseCode.RespTooManyRequests);
|
||||
register(makeRegisterOpts(), 'pw');
|
||||
invokeResponseCode(Data.Response_ResponseCode.RespTooManyRequests);
|
||||
expect(SessionPersistence.registrationEmailError).toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it('RespRegistrationDisabled calls registrationFailed', () => {
|
||||
register({ userName: 'alice' } as any, 'pw');
|
||||
invokeResponseCode(Response_ResponseCode.RespRegistrationDisabled);
|
||||
register(makeRegisterOpts(), 'pw');
|
||||
invokeResponseCode(Data.Response_ResponseCode.RespRegistrationDisabled);
|
||||
expect(SessionPersistence.registrationFailed).toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it('RespUserIsBanned calls registrationFailed with deniedReasonStr and deniedEndTime', () => {
|
||||
register({ userName: 'alice' } as any, 'pw');
|
||||
const raw = create(ResponseSchema, { responseCode: Response_ResponseCode.RespUserIsBanned });
|
||||
setExtension(raw, Response_Register_ext, create(Response_RegisterSchema, { deniedReasonStr: 'bad user', deniedEndTime: 9999n }));
|
||||
invokeResponseCode(Response_ResponseCode.RespUserIsBanned, raw);
|
||||
register(makeRegisterOpts(), 'pw');
|
||||
const raw = create(Data.ResponseSchema, { responseCode: Data.Response_ResponseCode.RespUserIsBanned });
|
||||
setExtension(raw, Data.Response_Register_ext, create(Data.Response_RegisterSchema, {
|
||||
deniedReasonStr: 'bad user', deniedEndTime: 9999n,
|
||||
}));
|
||||
invokeResponseCode(Data.Response_ResponseCode.RespUserIsBanned, raw);
|
||||
expect(SessionPersistence.registrationFailed).toHaveBeenCalledWith('bad user', 9999);
|
||||
});
|
||||
|
||||
it('onError calls registrationFailed', () => {
|
||||
register({ userName: 'alice' } as any, 'pw');
|
||||
register(makeRegisterOpts(), 'pw');
|
||||
invokeOnError();
|
||||
expect(SessionPersistence.registrationFailed).toHaveBeenCalled();
|
||||
});
|
||||
|
|
@ -365,28 +408,28 @@ describe('register', () => {
|
|||
describe('activate', () => {
|
||||
|
||||
it('sends Command_Activate with userName and token, not password', () => {
|
||||
activate({ userName: 'alice', token: 'tok' } as any, 'pw');
|
||||
activate(makeActivateOpts(), 'pw');
|
||||
expect(webClient.protobuf.sendSessionCommand).toHaveBeenCalledWith(
|
||||
Command_Activate_ext,
|
||||
Data.Command_Activate_ext,
|
||||
expect.objectContaining({ userName: 'alice', token: 'tok' }),
|
||||
expect.any(Object)
|
||||
);
|
||||
expect(webClient.protobuf.sendSessionCommand).toHaveBeenCalledWith(
|
||||
Command_Activate_ext,
|
||||
Data.Command_Activate_ext,
|
||||
expect.not.objectContaining({ password: expect.anything() }),
|
||||
expect.any(Object)
|
||||
);
|
||||
});
|
||||
|
||||
it('RespActivationAccepted calls accountActivationSuccess and forwards password+salt to login', () => {
|
||||
activate({ userName: 'alice', token: 'tok' } as any, 'pw', 'salt');
|
||||
invokeResponseCode(Response_ResponseCode.RespActivationAccepted);
|
||||
activate(makeActivateOpts(), 'pw', 'salt');
|
||||
invokeResponseCode(Data.Response_ResponseCode.RespActivationAccepted);
|
||||
expect(SessionPersistence.accountActivationSuccess).toHaveBeenCalled();
|
||||
expect(SessionIndexMocks.login).toHaveBeenCalledWith(expect.any(Object), 'pw', 'salt');
|
||||
});
|
||||
|
||||
it('onError calls accountActivationFailed and disconnect', () => {
|
||||
activate({ userName: 'alice', token: 'tok' } as any);
|
||||
activate(makeActivateOpts());
|
||||
invokeOnError();
|
||||
expect(SessionPersistence.accountActivationFailed).toHaveBeenCalled();
|
||||
expect(SessionIndexMocks.disconnect).toHaveBeenCalled();
|
||||
|
|
@ -399,21 +442,21 @@ describe('activate', () => {
|
|||
describe('forgotPasswordChallenge', () => {
|
||||
|
||||
it('sends Command_ForgotPasswordChallenge', () => {
|
||||
forgotPasswordChallenge({ userName: 'alice', email: 'a@b.com' } as any);
|
||||
forgotPasswordChallenge(makeForgotChallengeOpts());
|
||||
expect(webClient.protobuf.sendSessionCommand).toHaveBeenCalledWith(
|
||||
Command_ForgotPasswordChallenge_ext, expect.any(Object), expect.any(Object)
|
||||
Data.Command_ForgotPasswordChallenge_ext, expect.any(Object), expect.any(Object)
|
||||
);
|
||||
});
|
||||
|
||||
it('onSuccess calls resetPassword and disconnect', () => {
|
||||
forgotPasswordChallenge({ userName: 'alice', email: 'a@b.com' } as any);
|
||||
forgotPasswordChallenge(makeForgotChallengeOpts());
|
||||
invokeOnSuccess();
|
||||
expect(SessionPersistence.resetPassword).toHaveBeenCalled();
|
||||
expect(SessionIndexMocks.disconnect).toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it('onError calls resetPasswordFailed and disconnect', () => {
|
||||
forgotPasswordChallenge({ userName: 'alice', email: 'a@b.com' } as any);
|
||||
forgotPasswordChallenge(makeForgotChallengeOpts());
|
||||
invokeOnError();
|
||||
expect(SessionPersistence.resetPasswordFailed).toHaveBeenCalled();
|
||||
expect(SessionIndexMocks.disconnect).toHaveBeenCalled();
|
||||
|
|
@ -426,16 +469,16 @@ describe('forgotPasswordChallenge', () => {
|
|||
describe('forgotPasswordRequest', () => {
|
||||
|
||||
it('sends Command_ForgotPasswordRequest', () => {
|
||||
forgotPasswordRequest({ userName: 'alice' } as any);
|
||||
forgotPasswordRequest(makeForgotRequestOpts());
|
||||
expect(webClient.protobuf.sendSessionCommand).toHaveBeenCalledWith(
|
||||
Command_ForgotPasswordRequest_ext,
|
||||
Data.Command_ForgotPasswordRequest_ext,
|
||||
expect.any(Object),
|
||||
expect.objectContaining({ responseExt: Response_ForgotPasswordRequest_ext })
|
||||
expect.objectContaining({ responseExt: Data.Response_ForgotPasswordRequest_ext })
|
||||
);
|
||||
});
|
||||
|
||||
it('onSuccess with challengeEmail calls resetPasswordChallenge', () => {
|
||||
forgotPasswordRequest({ userName: 'alice' } as any);
|
||||
forgotPasswordRequest(makeForgotRequestOpts());
|
||||
const resp = { challengeEmail: true };
|
||||
invokeOnSuccess(resp, { responseCode: 0 });
|
||||
expect(SessionPersistence.resetPasswordChallenge).toHaveBeenCalled();
|
||||
|
|
@ -443,7 +486,7 @@ describe('forgotPasswordRequest', () => {
|
|||
});
|
||||
|
||||
it('onSuccess without challengeEmail calls resetPassword', () => {
|
||||
forgotPasswordRequest({ userName: 'alice' } as any);
|
||||
forgotPasswordRequest(makeForgotRequestOpts());
|
||||
const resp = { challengeEmail: false };
|
||||
invokeOnSuccess(resp, { responseCode: 0 });
|
||||
expect(SessionPersistence.resetPassword).toHaveBeenCalled();
|
||||
|
|
@ -451,7 +494,7 @@ describe('forgotPasswordRequest', () => {
|
|||
});
|
||||
|
||||
it('onError calls resetPasswordFailed and disconnect', () => {
|
||||
forgotPasswordRequest({ userName: 'alice' } as any);
|
||||
forgotPasswordRequest(makeForgotRequestOpts());
|
||||
invokeOnError();
|
||||
expect(SessionPersistence.resetPasswordFailed).toHaveBeenCalled();
|
||||
expect(SessionIndexMocks.disconnect).toHaveBeenCalled();
|
||||
|
|
@ -464,32 +507,32 @@ describe('forgotPasswordRequest', () => {
|
|||
describe('forgotPasswordReset', () => {
|
||||
|
||||
it('sends Command_ForgotPasswordReset with plain newPassword when no salt', () => {
|
||||
forgotPasswordReset({ userName: 'alice', token: 'tok' } as any, 'newpw');
|
||||
forgotPasswordReset(makeForgotResetOpts(), 'newpw');
|
||||
expect(webClient.protobuf.sendSessionCommand).toHaveBeenCalledWith(
|
||||
Command_ForgotPasswordReset_ext,
|
||||
Data.Command_ForgotPasswordReset_ext,
|
||||
expect.objectContaining({ newPassword: 'newpw' }),
|
||||
expect.any(Object)
|
||||
);
|
||||
});
|
||||
|
||||
it('sends hashed new password when salt provided', () => {
|
||||
forgotPasswordReset({ userName: 'alice', token: 'tok' } as any, 'newpw', 'salt');
|
||||
forgotPasswordReset(makeForgotResetOpts(), 'newpw', 'salt');
|
||||
expect(webClient.protobuf.sendSessionCommand).toHaveBeenCalledWith(
|
||||
Command_ForgotPasswordReset_ext,
|
||||
Data.Command_ForgotPasswordReset_ext,
|
||||
expect.objectContaining({ hashedNewPassword: 'hashed_pw' }),
|
||||
expect.any(Object)
|
||||
);
|
||||
});
|
||||
|
||||
it('onSuccess calls resetPasswordSuccess and disconnect', () => {
|
||||
forgotPasswordReset({ userName: 'alice', token: 'tok' } as any, 'newpw');
|
||||
forgotPasswordReset(makeForgotResetOpts(), 'newpw');
|
||||
invokeOnSuccess();
|
||||
expect(SessionPersistence.resetPasswordSuccess).toHaveBeenCalled();
|
||||
expect(SessionIndexMocks.disconnect).toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it('onError calls resetPasswordFailed and disconnect', () => {
|
||||
forgotPasswordReset({ userName: 'alice', token: 'tok' } as any, 'newpw');
|
||||
forgotPasswordReset(makeForgotResetOpts(), 'newpw');
|
||||
invokeOnError();
|
||||
expect(SessionPersistence.resetPasswordFailed).toHaveBeenCalled();
|
||||
expect(SessionIndexMocks.disconnect).toHaveBeenCalled();
|
||||
|
|
@ -502,57 +545,65 @@ describe('forgotPasswordReset', () => {
|
|||
describe('requestPasswordSalt', () => {
|
||||
|
||||
it('sends Command_RequestPasswordSalt', () => {
|
||||
requestPasswordSalt({ userName: 'alice', reason: WebSocketConnectReason.LOGIN } as any, 'pw');
|
||||
requestPasswordSalt(makeSaltOpts(App.WebSocketConnectReason.LOGIN), 'pw');
|
||||
expect(webClient.protobuf.sendSessionCommand).toHaveBeenCalledWith(
|
||||
Command_RequestPasswordSalt_ext,
|
||||
Data.Command_RequestPasswordSalt_ext,
|
||||
expect.any(Object),
|
||||
expect.objectContaining({ responseExt: Response_PasswordSalt_ext })
|
||||
expect.objectContaining({ responseExt: Data.Response_PasswordSalt_ext })
|
||||
);
|
||||
});
|
||||
|
||||
it('onSuccess with LOGIN reason forwards password+salt to login', () => {
|
||||
requestPasswordSalt({ userName: 'alice', reason: WebSocketConnectReason.LOGIN } as any, 'pw');
|
||||
requestPasswordSalt(makeSaltOpts(App.WebSocketConnectReason.LOGIN), 'pw');
|
||||
const resp = { passwordSalt: 'salt123' };
|
||||
invokeOnSuccess(resp, { responseCode: 0 });
|
||||
expect(SessionIndexMocks.login).toHaveBeenCalledWith(expect.any(Object), 'pw', 'salt123');
|
||||
});
|
||||
|
||||
it('onSuccess with ACTIVATE_ACCOUNT reason forwards password+salt to activate', () => {
|
||||
requestPasswordSalt({ userName: 'alice', reason: WebSocketConnectReason.ACTIVATE_ACCOUNT } as any, 'pw');
|
||||
requestPasswordSalt(makeSaltOpts(App.WebSocketConnectReason.ACTIVATE_ACCOUNT, { token: 'tok' }), 'pw');
|
||||
const resp = { passwordSalt: 'salt123' };
|
||||
invokeOnSuccess(resp, { responseCode: 0 });
|
||||
expect(SessionIndexMocks.activate).toHaveBeenCalledWith(expect.any(Object), 'pw', 'salt123');
|
||||
});
|
||||
|
||||
it('onSuccess with PASSWORD_RESET reason forwards newPassword+salt to forgotPasswordReset', () => {
|
||||
requestPasswordSalt({ userName: 'alice', reason: WebSocketConnectReason.PASSWORD_RESET } as any, undefined, 'newpw');
|
||||
requestPasswordSalt(
|
||||
makeSaltOpts(App.WebSocketConnectReason.PASSWORD_RESET, { token: 'tok', newPassword: 'newpw' }),
|
||||
undefined,
|
||||
'newpw'
|
||||
);
|
||||
const resp = { passwordSalt: 'salt123' };
|
||||
invokeOnSuccess(resp, { responseCode: 0 });
|
||||
expect(SessionIndexMocks.forgotPasswordReset).toHaveBeenCalledWith(expect.any(Object), 'newpw', 'salt123');
|
||||
});
|
||||
|
||||
it('onResponseCode RespRegistrationRequired calls updateStatus and disconnect', () => {
|
||||
requestPasswordSalt({ userName: 'alice', reason: WebSocketConnectReason.LOGIN } as any, 'pw');
|
||||
invokeResponseCode(Response_ResponseCode.RespRegistrationRequired);
|
||||
expect(SessionIndexMocks.updateStatus).toHaveBeenCalledWith(StatusEnum.DISCONNECTED, expect.any(String));
|
||||
requestPasswordSalt(makeSaltOpts(App.WebSocketConnectReason.LOGIN), 'pw');
|
||||
invokeResponseCode(Data.Response_ResponseCode.RespRegistrationRequired);
|
||||
expect(SessionIndexMocks.updateStatus).toHaveBeenCalledWith(App.StatusEnum.DISCONNECTED, expect.any(String));
|
||||
expect(SessionIndexMocks.disconnect).toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it('onResponseCode RespRegistrationRequired with ACTIVATE_ACCOUNT calls accountActivationFailed', () => {
|
||||
requestPasswordSalt({ userName: 'alice', reason: WebSocketConnectReason.ACTIVATE_ACCOUNT } as any, 'pw');
|
||||
invokeResponseCode(Response_ResponseCode.RespRegistrationRequired);
|
||||
requestPasswordSalt(makeSaltOpts(App.WebSocketConnectReason.ACTIVATE_ACCOUNT, { token: 'tok' }), 'pw');
|
||||
invokeResponseCode(Data.Response_ResponseCode.RespRegistrationRequired);
|
||||
expect(SessionPersistence.accountActivationFailed).toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it('onError calls updateStatus DISCONNECTED and disconnect', () => {
|
||||
requestPasswordSalt({ userName: 'alice', reason: WebSocketConnectReason.LOGIN } as any, 'pw');
|
||||
requestPasswordSalt(makeSaltOpts(App.WebSocketConnectReason.LOGIN), 'pw');
|
||||
invokeOnError();
|
||||
expect(SessionIndexMocks.updateStatus).toHaveBeenCalled();
|
||||
expect(SessionIndexMocks.disconnect).toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it('onError with PASSWORD_RESET reason calls resetPasswordFailed', () => {
|
||||
requestPasswordSalt({ userName: 'alice', reason: WebSocketConnectReason.PASSWORD_RESET } as any, undefined, 'newpw');
|
||||
requestPasswordSalt(
|
||||
makeSaltOpts(App.WebSocketConnectReason.PASSWORD_RESET, { token: 'tok', newPassword: 'newpw' }),
|
||||
undefined,
|
||||
'newpw'
|
||||
);
|
||||
invokeOnError();
|
||||
expect(SessionPersistence.resetPasswordFailed).toHaveBeenCalled();
|
||||
});
|
||||
|
|
|
|||
|
|
@ -22,7 +22,7 @@ vi.mock('../../utils', async () => {
|
|||
vi.mock('./', async () => {
|
||||
const actual = await vi.importActual('./');
|
||||
const { makeSessionBarrelMock } = await import('../../__mocks__/sessionCommandMocks');
|
||||
return { ...(actual as any), ...makeSessionBarrelMock() };
|
||||
return { ...(actual as Record<string, unknown>), ...makeSessionBarrelMock() };
|
||||
});
|
||||
|
||||
import { Mock } from 'vitest';
|
||||
|
|
@ -31,38 +31,7 @@ import { SessionPersistence } from '../../persistence';
|
|||
import { RoomPersistence } from '../../persistence';
|
||||
import webClient from '../../WebClient';
|
||||
import { hashPassword, generateSalt, passwordSaltSupported } from '../../utils';
|
||||
import {
|
||||
Command_AccountEdit_ext,
|
||||
Command_AccountImage_ext,
|
||||
Command_AccountPassword_ext,
|
||||
Command_AddToList_ext,
|
||||
Command_GetGamesOfUser_ext,
|
||||
Command_GetUserInfo_ext,
|
||||
Command_JoinRoom_ext,
|
||||
Command_ListRooms_ext,
|
||||
Command_ListUsers_ext,
|
||||
Command_Message_ext,
|
||||
Command_Ping_ext,
|
||||
Command_RemoveFromList_ext,
|
||||
} from 'generated/proto/session_commands_pb';
|
||||
import { Command_DeckDel_ext } from 'generated/proto/command_deck_del_pb';
|
||||
import { Command_DeckDelDir_ext } from 'generated/proto/command_deck_del_dir_pb';
|
||||
import { Command_DeckList_ext } from 'generated/proto/command_deck_list_pb';
|
||||
import { Command_DeckNewDir_ext } from 'generated/proto/command_deck_new_dir_pb';
|
||||
import { Command_DeckUpload_ext } from 'generated/proto/command_deck_upload_pb';
|
||||
import { Command_ReplayDeleteMatch_ext } from 'generated/proto/command_replay_delete_match_pb';
|
||||
import { Command_ReplayGetCode_ext } from 'generated/proto/command_replay_get_code_pb';
|
||||
import { Command_ReplayList_ext } from 'generated/proto/command_replay_list_pb';
|
||||
import { Command_ReplayModifyMatch_ext } from 'generated/proto/command_replay_modify_match_pb';
|
||||
import { Command_ReplaySubmitCode_ext } from 'generated/proto/command_replay_submit_code_pb';
|
||||
import { Response_DeckList_ext } from 'generated/proto/response_deck_list_pb';
|
||||
import { Response_DeckUpload_ext } from 'generated/proto/response_deck_upload_pb';
|
||||
import { Response_GetGamesOfUser_ext } from 'generated/proto/response_get_games_of_user_pb';
|
||||
import { Response_GetUserInfo_ext } from 'generated/proto/response_get_user_info_pb';
|
||||
import { Response_JoinRoom_ext } from 'generated/proto/response_join_room_pb';
|
||||
import { Response_ListUsers_ext } from 'generated/proto/response_list_users_pb';
|
||||
import { Response_ReplayGetCode_ext } from 'generated/proto/response_replay_get_code_pb';
|
||||
import { Response_ReplayList_ext } from 'generated/proto/response_replay_list_pb';
|
||||
|
||||
import { accountEdit } from './accountEdit';
|
||||
import { accountImage } from './accountImage';
|
||||
import { accountPassword } from './accountPassword';
|
||||
|
|
@ -86,6 +55,7 @@ import { addToList, addToBuddyList, addToIgnoreList } from './addToList';
|
|||
import { removeFromList, removeFromBuddyList, removeFromIgnoreList } from './removeFromList';
|
||||
import { replayGetCode } from './replayGetCode';
|
||||
import { replaySubmitCode } from './replaySubmitCode';
|
||||
import { Data } from '@app/types';
|
||||
|
||||
const { invokeOnSuccess, invokeCallback } = makeCallbackHelpers(
|
||||
webClient.protobuf.sendSessionCommand as Mock,
|
||||
|
|
@ -93,7 +63,6 @@ const { invokeOnSuccess, invokeCallback } = makeCallbackHelpers(
|
|||
);
|
||||
|
||||
beforeEach(() => {
|
||||
vi.clearAllMocks();
|
||||
(hashPassword as Mock).mockReturnValue('hashed_pw');
|
||||
(generateSalt as Mock).mockReturnValue('randSalt');
|
||||
(passwordSaltSupported as Mock).mockReturnValue(0);
|
||||
|
|
@ -102,12 +71,10 @@ beforeEach(() => {
|
|||
// ----------------------------------------------------------------
|
||||
|
||||
describe('accountEdit', () => {
|
||||
beforeEach(() => vi.clearAllMocks());
|
||||
|
||||
it('sends Command_AccountEdit with correct params', () => {
|
||||
accountEdit('pw', 'Alice', 'a@b.com', 'US');
|
||||
expect(webClient.protobuf.sendSessionCommand).toHaveBeenCalledWith(
|
||||
Command_AccountEdit_ext,
|
||||
Data.Command_AccountEdit_ext,
|
||||
expect.objectContaining({ passwordCheck: 'pw', realName: 'Alice', email: 'a@b.com', country: 'US' }),
|
||||
expect.any(Object)
|
||||
);
|
||||
|
|
@ -121,13 +88,11 @@ describe('accountEdit', () => {
|
|||
});
|
||||
|
||||
describe('accountImage', () => {
|
||||
beforeEach(() => vi.clearAllMocks());
|
||||
|
||||
it('sends Command_AccountImage', () => {
|
||||
const img = new Uint8Array([1, 2]);
|
||||
accountImage(img);
|
||||
expect(webClient.protobuf.sendSessionCommand).toHaveBeenCalledWith(
|
||||
Command_AccountImage_ext, expect.objectContaining({ image: img }), expect.any(Object)
|
||||
Data.Command_AccountImage_ext, expect.objectContaining({ image: img }), expect.any(Object)
|
||||
);
|
||||
});
|
||||
|
||||
|
|
@ -140,12 +105,10 @@ describe('accountImage', () => {
|
|||
});
|
||||
|
||||
describe('accountPassword', () => {
|
||||
beforeEach(() => vi.clearAllMocks());
|
||||
|
||||
it('sends Command_AccountPassword', () => {
|
||||
accountPassword('old', 'new', 'hashed');
|
||||
expect(webClient.protobuf.sendSessionCommand).toHaveBeenCalledWith(
|
||||
Command_AccountPassword_ext,
|
||||
Data.Command_AccountPassword_ext,
|
||||
expect.objectContaining({ oldPassword: 'old', newPassword: 'new', hashedNewPassword: 'hashed' }),
|
||||
expect.any(Object)
|
||||
);
|
||||
|
|
@ -159,12 +122,10 @@ describe('accountPassword', () => {
|
|||
});
|
||||
|
||||
describe('deckDel', () => {
|
||||
beforeEach(() => vi.clearAllMocks());
|
||||
|
||||
it('sends Command_DeckDel', () => {
|
||||
deckDel(42);
|
||||
expect(webClient.protobuf.sendSessionCommand).toHaveBeenCalledWith(
|
||||
Command_DeckDel_ext,
|
||||
Data.Command_DeckDel_ext,
|
||||
expect.objectContaining({ deckId: 42 }),
|
||||
expect.any(Object)
|
||||
);
|
||||
|
|
@ -178,12 +139,10 @@ describe('deckDel', () => {
|
|||
});
|
||||
|
||||
describe('deckDelDir', () => {
|
||||
beforeEach(() => vi.clearAllMocks());
|
||||
|
||||
it('sends Command_DeckDelDir', () => {
|
||||
deckDelDir('/path');
|
||||
expect(webClient.protobuf.sendSessionCommand).toHaveBeenCalledWith(
|
||||
Command_DeckDelDir_ext, expect.objectContaining({ path: '/path' }), expect.any(Object)
|
||||
Data.Command_DeckDelDir_ext, expect.objectContaining({ path: '/path' }), expect.any(Object)
|
||||
);
|
||||
});
|
||||
|
||||
|
|
@ -195,14 +154,12 @@ describe('deckDelDir', () => {
|
|||
});
|
||||
|
||||
describe('deckList', () => {
|
||||
beforeEach(() => vi.clearAllMocks());
|
||||
|
||||
it('sends Command_DeckList', () => {
|
||||
deckList();
|
||||
expect(webClient.protobuf.sendSessionCommand).toHaveBeenCalledWith(
|
||||
Command_DeckList_ext,
|
||||
Data.Command_DeckList_ext,
|
||||
expect.any(Object),
|
||||
expect.objectContaining({ responseExt: Response_DeckList_ext })
|
||||
expect.objectContaining({ responseExt: Data.Response_DeckList_ext })
|
||||
);
|
||||
});
|
||||
|
||||
|
|
@ -215,12 +172,10 @@ describe('deckList', () => {
|
|||
});
|
||||
|
||||
describe('deckNewDir', () => {
|
||||
beforeEach(() => vi.clearAllMocks());
|
||||
|
||||
it('sends Command_DeckNewDir', () => {
|
||||
deckNewDir('/path', 'dir');
|
||||
expect(webClient.protobuf.sendSessionCommand).toHaveBeenCalledWith(
|
||||
Command_DeckNewDir_ext, expect.objectContaining({ path: '/path', dirName: 'dir' }), expect.any(Object)
|
||||
Data.Command_DeckNewDir_ext, expect.objectContaining({ path: '/path', dirName: 'dir' }), expect.any(Object)
|
||||
);
|
||||
});
|
||||
|
||||
|
|
@ -232,14 +187,12 @@ describe('deckNewDir', () => {
|
|||
});
|
||||
|
||||
describe('deckUpload', () => {
|
||||
beforeEach(() => vi.clearAllMocks());
|
||||
|
||||
it('sends Command_DeckUpload', () => {
|
||||
deckUpload('/path', 1, 'content');
|
||||
expect(webClient.protobuf.sendSessionCommand).toHaveBeenCalledWith(
|
||||
Command_DeckUpload_ext,
|
||||
Data.Command_DeckUpload_ext,
|
||||
expect.objectContaining({ path: '/path', deckId: 1, deckList: 'content' }),
|
||||
expect.objectContaining({ responseExt: Response_DeckUpload_ext })
|
||||
expect.objectContaining({ responseExt: Data.Response_DeckUpload_ext })
|
||||
);
|
||||
});
|
||||
|
||||
|
|
@ -252,8 +205,6 @@ describe('deckUpload', () => {
|
|||
});
|
||||
|
||||
describe('disconnect', () => {
|
||||
beforeEach(() => vi.clearAllMocks());
|
||||
|
||||
it('calls webClient.disconnect', () => {
|
||||
disconnect();
|
||||
expect(webClient.disconnect).toHaveBeenCalled();
|
||||
|
|
@ -261,14 +212,12 @@ describe('disconnect', () => {
|
|||
});
|
||||
|
||||
describe('getGamesOfUser', () => {
|
||||
beforeEach(() => vi.clearAllMocks());
|
||||
|
||||
it('sends Command_GetGamesOfUser', () => {
|
||||
getGamesOfUser('alice');
|
||||
expect(webClient.protobuf.sendSessionCommand).toHaveBeenCalledWith(
|
||||
Command_GetGamesOfUser_ext,
|
||||
Data.Command_GetGamesOfUser_ext,
|
||||
expect.any(Object),
|
||||
expect.objectContaining({ responseExt: Response_GetGamesOfUser_ext })
|
||||
expect.objectContaining({ responseExt: Data.Response_GetGamesOfUser_ext })
|
||||
);
|
||||
});
|
||||
|
||||
|
|
@ -281,14 +230,12 @@ describe('getGamesOfUser', () => {
|
|||
});
|
||||
|
||||
describe('getUserInfo', () => {
|
||||
beforeEach(() => vi.clearAllMocks());
|
||||
|
||||
it('sends Command_GetUserInfo', () => {
|
||||
getUserInfo('alice');
|
||||
expect(webClient.protobuf.sendSessionCommand).toHaveBeenCalledWith(
|
||||
Command_GetUserInfo_ext,
|
||||
Data.Command_GetUserInfo_ext,
|
||||
expect.any(Object),
|
||||
expect.objectContaining({ responseExt: Response_GetUserInfo_ext })
|
||||
expect.objectContaining({ responseExt: Data.Response_GetUserInfo_ext })
|
||||
);
|
||||
});
|
||||
|
||||
|
|
@ -301,14 +248,12 @@ describe('getUserInfo', () => {
|
|||
});
|
||||
|
||||
describe('joinRoom', () => {
|
||||
beforeEach(() => vi.clearAllMocks());
|
||||
|
||||
it('sends Command_JoinRoom', () => {
|
||||
joinRoom(5);
|
||||
expect(webClient.protobuf.sendSessionCommand).toHaveBeenCalledWith(
|
||||
Command_JoinRoom_ext,
|
||||
Data.Command_JoinRoom_ext,
|
||||
expect.any(Object),
|
||||
expect.objectContaining({ responseExt: Response_JoinRoom_ext })
|
||||
expect.objectContaining({ responseExt: Data.Response_JoinRoom_ext })
|
||||
);
|
||||
});
|
||||
|
||||
|
|
@ -321,23 +266,19 @@ describe('joinRoom', () => {
|
|||
});
|
||||
|
||||
describe('listRooms (command)', () => {
|
||||
beforeEach(() => vi.clearAllMocks());
|
||||
|
||||
it('sends Command_ListRooms', () => {
|
||||
listRooms();
|
||||
expect(webClient.protobuf.sendSessionCommand).toHaveBeenCalledWith(Command_ListRooms_ext, expect.any(Object));
|
||||
expect(webClient.protobuf.sendSessionCommand).toHaveBeenCalledWith(Data.Command_ListRooms_ext, expect.any(Object));
|
||||
});
|
||||
});
|
||||
|
||||
describe('listUsers', () => {
|
||||
beforeEach(() => vi.clearAllMocks());
|
||||
|
||||
it('sends Command_ListUsers', () => {
|
||||
listUsers();
|
||||
expect(webClient.protobuf.sendSessionCommand).toHaveBeenCalledWith(
|
||||
Command_ListUsers_ext,
|
||||
Data.Command_ListUsers_ext,
|
||||
expect.any(Object),
|
||||
expect.objectContaining({ responseExt: Response_ListUsers_ext })
|
||||
expect.objectContaining({ responseExt: Data.Response_ListUsers_ext })
|
||||
);
|
||||
});
|
||||
|
||||
|
|
@ -350,24 +291,20 @@ describe('listUsers', () => {
|
|||
});
|
||||
|
||||
describe('message', () => {
|
||||
beforeEach(() => vi.clearAllMocks());
|
||||
|
||||
it('sends Command_Message', () => {
|
||||
message('bob', 'hi');
|
||||
expect(webClient.protobuf.sendSessionCommand).toHaveBeenCalledWith(
|
||||
Command_Message_ext, expect.objectContaining({ userName: 'bob', message: 'hi' })
|
||||
Data.Command_Message_ext, expect.objectContaining({ userName: 'bob', message: 'hi' })
|
||||
);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('ping', () => {
|
||||
beforeEach(() => vi.clearAllMocks());
|
||||
|
||||
it('sends Command_Ping', () => {
|
||||
const pingReceived = vi.fn();
|
||||
ping(pingReceived);
|
||||
expect(webClient.protobuf.sendSessionCommand).toHaveBeenCalledWith(Command_Ping_ext, expect.any(Object), expect.any(Object));
|
||||
expect(webClient.protobuf.sendSessionCommand).toHaveBeenCalledWith(Data.Command_Ping_ext, expect.any(Object), expect.any(Object));
|
||||
});
|
||||
|
||||
it('calls pingReceived via onResponse', () => {
|
||||
|
|
@ -379,12 +316,10 @@ describe('ping', () => {
|
|||
});
|
||||
|
||||
describe('replayDeleteMatch', () => {
|
||||
beforeEach(() => vi.clearAllMocks());
|
||||
|
||||
it('sends Command_ReplayDeleteMatch', () => {
|
||||
replayDeleteMatch(7);
|
||||
expect(webClient.protobuf.sendSessionCommand).toHaveBeenCalledWith(
|
||||
Command_ReplayDeleteMatch_ext,
|
||||
Data.Command_ReplayDeleteMatch_ext,
|
||||
expect.objectContaining({ gameId: 7 }),
|
||||
expect.any(Object)
|
||||
);
|
||||
|
|
@ -398,14 +333,12 @@ describe('replayDeleteMatch', () => {
|
|||
});
|
||||
|
||||
describe('replayList', () => {
|
||||
beforeEach(() => vi.clearAllMocks());
|
||||
|
||||
it('sends Command_ReplayList', () => {
|
||||
replayList();
|
||||
expect(webClient.protobuf.sendSessionCommand).toHaveBeenCalledWith(
|
||||
Command_ReplayList_ext,
|
||||
Data.Command_ReplayList_ext,
|
||||
expect.any(Object),
|
||||
expect.objectContaining({ responseExt: Response_ReplayList_ext })
|
||||
expect.objectContaining({ responseExt: Data.Response_ReplayList_ext })
|
||||
);
|
||||
});
|
||||
|
||||
|
|
@ -418,12 +351,10 @@ describe('replayList', () => {
|
|||
});
|
||||
|
||||
describe('replayModifyMatch', () => {
|
||||
beforeEach(() => vi.clearAllMocks());
|
||||
|
||||
it('sends Command_ReplayModifyMatch', () => {
|
||||
replayModifyMatch(7, true);
|
||||
expect(webClient.protobuf.sendSessionCommand).toHaveBeenCalledWith(
|
||||
Command_ReplayModifyMatch_ext, expect.objectContaining({ gameId: 7, doNotHide: true }), expect.any(Object)
|
||||
Data.Command_ReplayModifyMatch_ext, expect.objectContaining({ gameId: 7, doNotHide: true }), expect.any(Object)
|
||||
);
|
||||
});
|
||||
|
||||
|
|
@ -435,12 +366,10 @@ describe('replayModifyMatch', () => {
|
|||
});
|
||||
|
||||
describe('addToList / addToBuddyList / addToIgnoreList', () => {
|
||||
beforeEach(() => vi.clearAllMocks());
|
||||
|
||||
it('addToBuddyList sends Command_AddToList with list=buddy', () => {
|
||||
addToBuddyList('alice');
|
||||
expect(webClient.protobuf.sendSessionCommand).toHaveBeenCalledWith(
|
||||
Command_AddToList_ext,
|
||||
Data.Command_AddToList_ext,
|
||||
expect.objectContaining({ list: 'buddy' }),
|
||||
expect.any(Object)
|
||||
);
|
||||
|
|
@ -449,7 +378,7 @@ describe('addToList / addToBuddyList / addToIgnoreList', () => {
|
|||
it('addToIgnoreList sends Command_AddToList with list=ignore', () => {
|
||||
addToIgnoreList('bob');
|
||||
expect(webClient.protobuf.sendSessionCommand).toHaveBeenCalledWith(
|
||||
Command_AddToList_ext,
|
||||
Data.Command_AddToList_ext,
|
||||
expect.objectContaining({ list: 'ignore' }),
|
||||
expect.any(Object)
|
||||
);
|
||||
|
|
@ -463,12 +392,10 @@ describe('addToList / addToBuddyList / addToIgnoreList', () => {
|
|||
});
|
||||
|
||||
describe('removeFromList / removeFromBuddyList / removeFromIgnoreList', () => {
|
||||
beforeEach(() => vi.clearAllMocks());
|
||||
|
||||
it('removeFromBuddyList sends Command_RemoveFromList with list=buddy', () => {
|
||||
removeFromBuddyList('alice');
|
||||
expect(webClient.protobuf.sendSessionCommand).toHaveBeenCalledWith(
|
||||
Command_RemoveFromList_ext,
|
||||
Data.Command_RemoveFromList_ext,
|
||||
expect.objectContaining({ list: 'buddy' }),
|
||||
expect.any(Object)
|
||||
);
|
||||
|
|
@ -477,7 +404,7 @@ describe('removeFromList / removeFromBuddyList / removeFromIgnoreList', () => {
|
|||
it('removeFromIgnoreList sends Command_RemoveFromList with list=ignore', () => {
|
||||
removeFromIgnoreList('bob');
|
||||
expect(webClient.protobuf.sendSessionCommand).toHaveBeenCalledWith(
|
||||
Command_RemoveFromList_ext,
|
||||
Data.Command_RemoveFromList_ext,
|
||||
expect.objectContaining({ list: 'ignore' }),
|
||||
expect.any(Object)
|
||||
);
|
||||
|
|
@ -491,14 +418,12 @@ describe('removeFromList / removeFromBuddyList / removeFromIgnoreList', () => {
|
|||
});
|
||||
|
||||
describe('replayGetCode', () => {
|
||||
beforeEach(() => vi.clearAllMocks());
|
||||
|
||||
it('sends Command_ReplayGetCode with gameId and responseExt', () => {
|
||||
replayGetCode(42, vi.fn());
|
||||
expect(webClient.protobuf.sendSessionCommand).toHaveBeenCalledWith(
|
||||
Command_ReplayGetCode_ext,
|
||||
Data.Command_ReplayGetCode_ext,
|
||||
expect.any(Object),
|
||||
expect.objectContaining({ responseExt: Response_ReplayGetCode_ext })
|
||||
expect.objectContaining({ responseExt: Data.Response_ReplayGetCode_ext })
|
||||
);
|
||||
});
|
||||
|
||||
|
|
@ -511,12 +436,10 @@ describe('replayGetCode', () => {
|
|||
});
|
||||
|
||||
describe('replaySubmitCode', () => {
|
||||
beforeEach(() => vi.clearAllMocks());
|
||||
|
||||
it('sends Command_ReplaySubmitCode with replayCode', () => {
|
||||
replaySubmitCode('42-abc123');
|
||||
expect(webClient.protobuf.sendSessionCommand).toHaveBeenCalledWith(
|
||||
Command_ReplaySubmitCode_ext, expect.objectContaining({ replayCode: '42-abc123' }), expect.any(Object)
|
||||
Data.Command_ReplaySubmitCode_ext, expect.objectContaining({ replayCode: '42-abc123' }), expect.any(Object)
|
||||
);
|
||||
});
|
||||
|
||||
|
|
|
|||
|
|
@ -1,8 +1,8 @@
|
|||
import { StatusEnum } from 'types';
|
||||
import { App } from '@app/types';
|
||||
import webClient from '../../WebClient';
|
||||
import { SessionPersistence } from '../../persistence';
|
||||
|
||||
export function updateStatus(status: StatusEnum, description: string): void {
|
||||
export function updateStatus(status: App.StatusEnum, description: string): void {
|
||||
SessionPersistence.updateStatus(status, description);
|
||||
|
||||
webClient.updateStatus(status);
|
||||
|
|
|
|||
|
|
@ -1,3 +1,3 @@
|
|||
import { SessionExtensionRegistry } from '../../services/protobuf-types';
|
||||
import type { SessionExtensionRegistry } from '../session';
|
||||
|
||||
export const CommonEvents: SessionExtensionRegistry = [];
|
||||
|
|
|
|||
|
|
@ -1,7 +1,6 @@
|
|||
import type { Event_AttachCard } from 'generated/proto/event_attach_card_pb';
|
||||
import type { GameEventMeta } from 'types';
|
||||
import type { Data, Enriched } from '@app/types';
|
||||
import { GamePersistence } from '../../persistence';
|
||||
|
||||
export function attachCard(data: Event_AttachCard, meta: GameEventMeta): void {
|
||||
export function attachCard(data: Data.Event_AttachCard, meta: Enriched.GameEventMeta): void {
|
||||
GamePersistence.cardAttached(meta.gameId, meta.playerId, data);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,7 +1,6 @@
|
|||
import type { Event_ChangeZoneProperties } from 'generated/proto/event_change_zone_properties_pb';
|
||||
import type { GameEventMeta } from 'types';
|
||||
import type { Data, Enriched } from '@app/types';
|
||||
import { GamePersistence } from '../../persistence';
|
||||
|
||||
export function changeZoneProperties(data: Event_ChangeZoneProperties, meta: GameEventMeta): void {
|
||||
export function changeZoneProperties(data: Data.Event_ChangeZoneProperties, meta: Enriched.GameEventMeta): void {
|
||||
GamePersistence.zonePropertiesChanged(meta.gameId, meta.playerId, data);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,7 +1,6 @@
|
|||
import type { Event_CreateArrow } from 'generated/proto/event_create_arrow_pb';
|
||||
import type { GameEventMeta } from 'types';
|
||||
import type { Data, Enriched } from '@app/types';
|
||||
import { GamePersistence } from '../../persistence';
|
||||
|
||||
export function createArrow(data: Event_CreateArrow, meta: GameEventMeta): void {
|
||||
export function createArrow(data: Data.Event_CreateArrow, meta: Enriched.GameEventMeta): void {
|
||||
GamePersistence.arrowCreated(meta.gameId, meta.playerId, data);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,7 +1,6 @@
|
|||
import type { Event_CreateCounter } from 'generated/proto/event_create_counter_pb';
|
||||
import type { GameEventMeta } from 'types';
|
||||
import type { Data, Enriched } from '@app/types';
|
||||
import { GamePersistence } from '../../persistence';
|
||||
|
||||
export function createCounter(data: Event_CreateCounter, meta: GameEventMeta): void {
|
||||
export function createCounter(data: Data.Event_CreateCounter, meta: Enriched.GameEventMeta): void {
|
||||
GamePersistence.counterCreated(meta.gameId, meta.playerId, data);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,7 +1,6 @@
|
|||
import type { Event_CreateToken } from 'generated/proto/event_create_token_pb';
|
||||
import type { GameEventMeta } from 'types';
|
||||
import type { Data, Enriched } from '@app/types';
|
||||
import { GamePersistence } from '../../persistence';
|
||||
|
||||
export function createToken(data: Event_CreateToken, meta: GameEventMeta): void {
|
||||
export function createToken(data: Data.Event_CreateToken, meta: Enriched.GameEventMeta): void {
|
||||
GamePersistence.tokenCreated(meta.gameId, meta.playerId, data);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,7 +1,6 @@
|
|||
import type { Event_DelCounter } from 'generated/proto/event_del_counter_pb';
|
||||
import type { GameEventMeta } from 'types';
|
||||
import type { Data, Enriched } from '@app/types';
|
||||
import { GamePersistence } from '../../persistence';
|
||||
|
||||
export function delCounter(data: Event_DelCounter, meta: GameEventMeta): void {
|
||||
export function delCounter(data: Data.Event_DelCounter, meta: Enriched.GameEventMeta): void {
|
||||
GamePersistence.counterDeleted(meta.gameId, meta.playerId, data);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,7 +1,6 @@
|
|||
import type { Event_DeleteArrow } from 'generated/proto/event_delete_arrow_pb';
|
||||
import type { GameEventMeta } from 'types';
|
||||
import type { Data, Enriched } from '@app/types';
|
||||
import { GamePersistence } from '../../persistence';
|
||||
|
||||
export function deleteArrow(data: Event_DeleteArrow, meta: GameEventMeta): void {
|
||||
export function deleteArrow(data: Data.Event_DeleteArrow, meta: Enriched.GameEventMeta): void {
|
||||
GamePersistence.arrowDeleted(meta.gameId, meta.playerId, data);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,7 +1,6 @@
|
|||
import type { Event_DestroyCard } from 'generated/proto/event_destroy_card_pb';
|
||||
import type { GameEventMeta } from 'types';
|
||||
import type { Data, Enriched } from '@app/types';
|
||||
import { GamePersistence } from '../../persistence';
|
||||
|
||||
export function destroyCard(data: Event_DestroyCard, meta: GameEventMeta): void {
|
||||
export function destroyCard(data: Data.Event_DestroyCard, meta: Enriched.GameEventMeta): void {
|
||||
GamePersistence.cardDestroyed(meta.gameId, meta.playerId, data);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,7 +1,6 @@
|
|||
import type { Event_DrawCards } from 'generated/proto/event_draw_cards_pb';
|
||||
import type { GameEventMeta } from 'types';
|
||||
import type { Data, Enriched } from '@app/types';
|
||||
import { GamePersistence } from '../../persistence';
|
||||
|
||||
export function drawCards(data: Event_DrawCards, meta: GameEventMeta): void {
|
||||
export function drawCards(data: Data.Event_DrawCards, meta: Enriched.GameEventMeta): void {
|
||||
GamePersistence.cardsDrawn(meta.gameId, meta.playerId, data);
|
||||
}
|
||||
|
|
|
|||
Some files were not shown because too many files have changed in this diff Show more
Loading…
Add table
Add a link
Reference in a new issue