mirror of
https://github.com/Cockatrice/Cockatrice.git
synced 2026-04-27 07:48:01 -07:00
migrate to Protobuf ES
This commit is contained in:
parent
68e22d22bf
commit
fd55f4fb7f
133 changed files with 1745 additions and 1621 deletions
|
|
@ -1,8 +1,10 @@
|
|||
import { create } from '@bufbuild/protobuf';
|
||||
import { BackendService } from '../../services/BackendService';
|
||||
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 {
|
||||
BackendService.sendAdminCommand('Command_AdjustMod', { userName, shouldBeMod, shouldBeJudge }, {
|
||||
BackendService.sendAdminCommand(Command_AdjustMod_ext, create(Command_AdjustModSchema, { userName, shouldBeMod, shouldBeJudge }), {
|
||||
onSuccess: () => {
|
||||
AdminPersistence.adjustMod(userName, shouldBeMod, shouldBeJudge);
|
||||
},
|
||||
|
|
|
|||
|
|
@ -22,7 +22,8 @@ import { shutdownServer } from './shutdownServer';
|
|||
import { updateServerMessage } from './updateServerMessage';
|
||||
|
||||
const { getLastSendOpts, invokeOnSuccess } = makeCallbackHelpers(
|
||||
BackendService.sendAdminCommand as vi.Mock
|
||||
BackendService.sendAdminCommand as vi.Mock,
|
||||
2
|
||||
);
|
||||
|
||||
beforeEach(() => vi.clearAllMocks());
|
||||
|
|
@ -34,11 +35,7 @@ describe('adjustMod', () => {
|
|||
|
||||
it('calls sendAdminCommand with Command_AdjustMod', () => {
|
||||
adjustMod('alice', true, false);
|
||||
expect(BackendService.sendAdminCommand).toHaveBeenCalledWith(
|
||||
'Command_AdjustMod',
|
||||
expect.objectContaining({ userName: 'alice', shouldBeMod: true, shouldBeJudge: false }),
|
||||
expect.any(Object)
|
||||
);
|
||||
expect(BackendService.sendAdminCommand).toHaveBeenCalledWith(expect.any(Object), expect.any(Object), expect.any(Object));
|
||||
});
|
||||
|
||||
it('onSuccess calls AdminPersistence.adjustMod', () => {
|
||||
|
|
@ -55,7 +52,7 @@ describe('reloadConfig', () => {
|
|||
|
||||
it('calls sendAdminCommand with Command_ReloadConfig', () => {
|
||||
reloadConfig();
|
||||
expect(BackendService.sendAdminCommand).toHaveBeenCalledWith('Command_ReloadConfig', {}, expect.any(Object));
|
||||
expect(BackendService.sendAdminCommand).toHaveBeenCalledWith(expect.any(Object), expect.any(Object), expect.any(Object));
|
||||
});
|
||||
|
||||
it('onSuccess calls AdminPersistence.reloadConfig', () => {
|
||||
|
|
@ -72,11 +69,7 @@ describe('shutdownServer', () => {
|
|||
|
||||
it('calls sendAdminCommand with Command_ShutdownServer', () => {
|
||||
shutdownServer('maintenance', 10);
|
||||
expect(BackendService.sendAdminCommand).toHaveBeenCalledWith(
|
||||
'Command_ShutdownServer',
|
||||
{ reason: 'maintenance', minutes: 10 },
|
||||
expect.any(Object)
|
||||
);
|
||||
expect(BackendService.sendAdminCommand).toHaveBeenCalledWith(expect.any(Object), expect.any(Object), expect.any(Object));
|
||||
});
|
||||
|
||||
it('onSuccess calls AdminPersistence.shutdownServer', () => {
|
||||
|
|
@ -93,7 +86,7 @@ describe('updateServerMessage', () => {
|
|||
|
||||
it('calls sendAdminCommand with Command_UpdateServerMessage', () => {
|
||||
updateServerMessage();
|
||||
expect(BackendService.sendAdminCommand).toHaveBeenCalledWith('Command_UpdateServerMessage', {}, expect.any(Object));
|
||||
expect(BackendService.sendAdminCommand).toHaveBeenCalledWith(expect.any(Object), expect.any(Object), expect.any(Object));
|
||||
});
|
||||
|
||||
it('onSuccess calls AdminPersistence.updateServerMessage', () => {
|
||||
|
|
|
|||
|
|
@ -1,8 +1,10 @@
|
|||
import { create } from '@bufbuild/protobuf';
|
||||
import { BackendService } from '../../services/BackendService';
|
||||
import { Command_ReloadConfig_ext, Command_ReloadConfigSchema } from 'generated/proto/admin_commands_pb';
|
||||
import { AdminPersistence } from '../../persistence';
|
||||
|
||||
export function reloadConfig(): void {
|
||||
BackendService.sendAdminCommand('Command_ReloadConfig', {}, {
|
||||
BackendService.sendAdminCommand(Command_ReloadConfig_ext, create(Command_ReloadConfigSchema), {
|
||||
onSuccess: () => {
|
||||
AdminPersistence.reloadConfig();
|
||||
},
|
||||
|
|
|
|||
|
|
@ -1,8 +1,10 @@
|
|||
import { create } from '@bufbuild/protobuf';
|
||||
import { BackendService } from '../../services/BackendService';
|
||||
import { Command_ShutdownServer_ext, Command_ShutdownServerSchema } from 'generated/proto/admin_commands_pb';
|
||||
import { AdminPersistence } from '../../persistence';
|
||||
|
||||
export function shutdownServer(reason: string, minutes: number): void {
|
||||
BackendService.sendAdminCommand('Command_ShutdownServer', { reason, minutes }, {
|
||||
BackendService.sendAdminCommand(Command_ShutdownServer_ext, create(Command_ShutdownServerSchema, { reason, minutes }), {
|
||||
onSuccess: () => {
|
||||
AdminPersistence.shutdownServer();
|
||||
},
|
||||
|
|
|
|||
|
|
@ -1,8 +1,10 @@
|
|||
import { create } from '@bufbuild/protobuf';
|
||||
import { BackendService } from '../../services/BackendService';
|
||||
import { Command_UpdateServerMessage_ext, Command_UpdateServerMessageSchema } from 'generated/proto/admin_commands_pb';
|
||||
import { AdminPersistence } from '../../persistence';
|
||||
|
||||
export function updateServerMessage(): void {
|
||||
BackendService.sendAdminCommand('Command_UpdateServerMessage', {}, {
|
||||
BackendService.sendAdminCommand(Command_UpdateServerMessage_ext, create(Command_UpdateServerMessageSchema), {
|
||||
onSuccess: () => {
|
||||
AdminPersistence.updateServerMessage();
|
||||
},
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue