mirror of
https://github.com/Cockatrice/Cockatrice.git
synced 2026-04-27 07:48:01 -07:00
harden implementations
This commit is contained in:
parent
c3ae4cffd6
commit
559a3ff1f4
25 changed files with 240 additions and 37 deletions
|
|
@ -136,7 +136,6 @@ export function makeServerState(overrides: Partial<ServerState> = {}): ServerSta
|
|||
field: UserSortField.NAME,
|
||||
order: SortDirection.ASC,
|
||||
},
|
||||
connectOptions: {},
|
||||
messages: {},
|
||||
userInfo: {},
|
||||
notifications: [],
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
import {
|
||||
WarnHistoryItem, BanHistoryItem, DeckList, Game, LogItem, ReplayMatch, SortBy, User, UserSortField, WebSocketConnectOptions, WarnListItem
|
||||
WarnHistoryItem, BanHistoryItem, DeckList, Game, LogItem, ReplayMatch, SortBy, User, UserSortField, WarnListItem
|
||||
} from 'types';
|
||||
import { NotifyUserData, ServerShutdownData, UserMessageData } from 'websocket/events/session/interfaces';
|
||||
|
||||
|
|
@ -51,7 +51,6 @@ export interface ServerState {
|
|||
user: User;
|
||||
users: User[];
|
||||
sortUsersBy: ServerStateSortUsersBy;
|
||||
connectOptions: WebSocketConnectOptions;
|
||||
messages: {
|
||||
[userName: string]: UserMessageData[];
|
||||
}
|
||||
|
|
|
|||
|
|
@ -51,23 +51,23 @@ describe('Initialisation', () => {
|
|||
// ── Account & Connection ─────────────────────────────────────────────────────
|
||||
|
||||
describe('Account & Connection', () => {
|
||||
it('ACCOUNT_AWAITING_ACTIVATION → sets connectOptions from action.options', () => {
|
||||
it('ACCOUNT_AWAITING_ACTIVATION → returns state unchanged', () => {
|
||||
const options = makeConnectOptions();
|
||||
const state = makeServerState();
|
||||
const result = serverReducer(state, { type: Types.ACCOUNT_AWAITING_ACTIVATION, options });
|
||||
expect(result.connectOptions).toEqual(options);
|
||||
expect(result).toBe(state);
|
||||
});
|
||||
|
||||
it('ACCOUNT_ACTIVATION_SUCCESS → clears connectOptions to {}', () => {
|
||||
const state = makeServerState({ connectOptions: makeConnectOptions() });
|
||||
it('ACCOUNT_ACTIVATION_SUCCESS → returns state unchanged', () => {
|
||||
const state = makeServerState();
|
||||
const result = serverReducer(state, { type: Types.ACCOUNT_ACTIVATION_SUCCESS });
|
||||
expect(result.connectOptions).toEqual({});
|
||||
expect(result).toBe(state);
|
||||
});
|
||||
|
||||
it('ACCOUNT_ACTIVATION_FAILED → clears connectOptions to {}', () => {
|
||||
const state = makeServerState({ connectOptions: makeConnectOptions() });
|
||||
it('ACCOUNT_ACTIVATION_FAILED → returns state unchanged', () => {
|
||||
const state = makeServerState();
|
||||
const result = serverReducer(state, { type: Types.ACCOUNT_ACTIVATION_FAILED });
|
||||
expect(result.connectOptions).toEqual({});
|
||||
expect(result).toBe(state);
|
||||
});
|
||||
});
|
||||
|
||||
|
|
|
|||
|
|
@ -80,7 +80,6 @@ const initialState: ServerState = {
|
|||
field: UserSortField.NAME,
|
||||
order: SortDirection.ASC
|
||||
},
|
||||
connectOptions: {},
|
||||
messages: {},
|
||||
userInfo: {},
|
||||
notifications: [],
|
||||
|
|
@ -105,19 +104,11 @@ export const serverReducer = (state = initialState, action: any) => {
|
|||
}
|
||||
}
|
||||
case Types.ACCOUNT_AWAITING_ACTIVATION: {
|
||||
return {
|
||||
...state,
|
||||
connectOptions: {
|
||||
...action.options
|
||||
}
|
||||
}
|
||||
return state;
|
||||
}
|
||||
case Types.ACCOUNT_ACTIVATION_FAILED:
|
||||
case Types.ACCOUNT_ACTIVATION_SUCCESS: {
|
||||
return {
|
||||
...state,
|
||||
connectOptions: {}
|
||||
}
|
||||
return state;
|
||||
}
|
||||
case Types.CLEAR_STORE: {
|
||||
return {
|
||||
|
|
|
|||
|
|
@ -18,12 +18,6 @@ describe('Selectors', () => {
|
|||
expect(Selectors.getInitialized(rootState(state))).toBe(true);
|
||||
});
|
||||
|
||||
it('getConnectOptions → returns connectOptions', () => {
|
||||
const connectOptions = { host: 'localhost', port: '4747' };
|
||||
const state = makeServerState({ connectOptions });
|
||||
expect(Selectors.getConnectOptions(rootState(state))).toBe(connectOptions);
|
||||
});
|
||||
|
||||
it('getMessage → returns info.message', () => {
|
||||
const state = makeServerState({ info: { message: 'Welcome!', name: null, version: null } });
|
||||
expect(Selectors.getMessage(rootState(state))).toBe('Welcome!');
|
||||
|
|
|
|||
|
|
@ -6,7 +6,6 @@ interface State {
|
|||
|
||||
export const Selectors = {
|
||||
getInitialized: ({ server }: State) => server.initialized,
|
||||
getConnectOptions: ({ server }: State) => server.connectOptions,
|
||||
getMessage: ({ server }: State) => server.info.message,
|
||||
getName: ({ server }: State) => server.info.name,
|
||||
getVersion: ({ server }: State) => server.info.version,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue