mirror of
https://github.com/Cockatrice/Cockatrice.git
synced 2026-06-22 22:53:55 -07:00
add missing requests/responses
This commit is contained in:
parent
f0c3581d26
commit
4b5f66d497
27 changed files with 382 additions and 10 deletions
|
|
@ -174,6 +174,8 @@ export function makeServerState(overrides: Partial<ServerState> = {}): ServerSta
|
|||
adminNotes: {},
|
||||
replays: {},
|
||||
backendDecks: null,
|
||||
downloadedDeck: null,
|
||||
downloadedReplay: null,
|
||||
gamesOfUser: {},
|
||||
registrationError: null,
|
||||
...overrides,
|
||||
|
|
|
|||
|
|
@ -351,6 +351,21 @@ describe('Actions', () => {
|
|||
expect(Actions.deckDelete({ deckId: 42 })).toEqual({ type: Types.DECK_DELETE, payload: { deckId: 42 } });
|
||||
});
|
||||
|
||||
it('deckDownloaded', () => {
|
||||
expect(Actions.deckDownloaded({ deckId: 42, deck: '<xml>' })).toEqual({
|
||||
type: Types.DECK_DOWNLOADED,
|
||||
payload: { deckId: 42, deck: '<xml>' },
|
||||
});
|
||||
});
|
||||
|
||||
it('replayDownloaded', () => {
|
||||
const replayData = new Uint8Array([1, 2, 3]);
|
||||
expect(Actions.replayDownloaded({ replayId: 99, replayData })).toEqual({
|
||||
type: Types.REPLAY_DOWNLOADED,
|
||||
payload: { replayId: 99, replayData },
|
||||
});
|
||||
});
|
||||
|
||||
it('gamesOfUser', () => {
|
||||
const response = create(Data.Response_GetGamesOfUserSchema, { roomList: [], gameList: [] });
|
||||
const action = Actions.gamesOfUser({ userName: 'alice', response });
|
||||
|
|
|
|||
|
|
@ -388,6 +388,17 @@ describe('Dispatch', () => {
|
|||
expect(mockDispatch).toHaveBeenCalledWith(Actions.deckDelete({ deckId: 42 }));
|
||||
});
|
||||
|
||||
it('deckDownloaded dispatches correctly', () => {
|
||||
Dispatch.deckDownloaded(42, '<deck-xml>');
|
||||
expect(mockDispatch).toHaveBeenCalledWith(Actions.deckDownloaded({ deckId: 42, deck: '<deck-xml>' }));
|
||||
});
|
||||
|
||||
it('replayDownloaded dispatches correctly', () => {
|
||||
const data = new Uint8Array([1, 2, 3]);
|
||||
Dispatch.replayDownloaded(99, data);
|
||||
expect(mockDispatch).toHaveBeenCalledWith(Actions.replayDownloaded({ replayId: 99, replayData: data }));
|
||||
});
|
||||
|
||||
it('gamesOfUser dispatches correctly', () => {
|
||||
const response = create(Data.Response_GetGamesOfUserSchema, { roomList: [], gameList: [] });
|
||||
Dispatch.gamesOfUser('alice', response);
|
||||
|
|
|
|||
|
|
@ -207,6 +207,12 @@ export const Dispatch = {
|
|||
deckDelete: (deckId: number) => {
|
||||
store.dispatch(Actions.deckDelete({ deckId }));
|
||||
},
|
||||
deckDownloaded: (deckId: number, deck: string) => {
|
||||
store.dispatch(Actions.deckDownloaded({ deckId, deck }));
|
||||
},
|
||||
replayDownloaded: (replayId: number, replayData: Uint8Array) => {
|
||||
store.dispatch(Actions.replayDownloaded({ replayId, replayData }));
|
||||
},
|
||||
gamesOfUser: (userName: string, response: Data.Response_GetGamesOfUser) => {
|
||||
store.dispatch(Actions.gamesOfUser({ userName, response }));
|
||||
},
|
||||
|
|
|
|||
|
|
@ -34,6 +34,8 @@ export interface ServerState {
|
|||
/** Replays keyed by gameId for O(1) lookup/update. */
|
||||
replays: { [gameId: number]: Data.ServerInfo_ReplayMatch };
|
||||
backendDecks: Data.Response_DeckList | null;
|
||||
downloadedDeck: { deckId: number; deck: string } | null;
|
||||
downloadedReplay: { replayId: number; replayData: Uint8Array } | null;
|
||||
gamesOfUser: { [userName: string]: Enriched.Game[] };
|
||||
registrationError: string | null;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -624,6 +624,25 @@ describe('Deck Storage', () => {
|
|||
const result = serverReducer(state, Actions.deckDelDir({ path: 'parent/child' }));
|
||||
expect(result.backendDecks!.root!.items[0].folder!.items).toHaveLength(0);
|
||||
});
|
||||
|
||||
it('DECK_DOWNLOADED → sets downloadedDeck', () => {
|
||||
const state = makeServerState();
|
||||
const result = serverReducer(state, Actions.deckDownloaded({ deckId: 42, deck: '<deck-xml>' }));
|
||||
expect(result.downloadedDeck).toEqual({ deckId: 42, deck: '<deck-xml>' });
|
||||
});
|
||||
|
||||
it('DECK_DOWNLOADED → overwrites previous download', () => {
|
||||
const state = makeServerState({ downloadedDeck: { deckId: 1, deck: 'old' } });
|
||||
const result = serverReducer(state, Actions.deckDownloaded({ deckId: 2, deck: 'new' }));
|
||||
expect(result.downloadedDeck).toEqual({ deckId: 2, deck: 'new' });
|
||||
});
|
||||
|
||||
it('REPLAY_DOWNLOADED → sets downloadedReplay', () => {
|
||||
const state = makeServerState();
|
||||
const data = new Uint8Array([1, 2, 3]);
|
||||
const result = serverReducer(state, Actions.replayDownloaded({ replayId: 99, replayData: data }));
|
||||
expect(result.downloadedReplay).toEqual({ replayId: 99, replayData: data });
|
||||
});
|
||||
});
|
||||
|
||||
// ── GAMES_OF_USER ─────────────────────────────────────────────────────────────
|
||||
|
|
|
|||
|
|
@ -102,6 +102,8 @@ const initialState: ServerState = {
|
|||
adminNotes: {},
|
||||
replays: {},
|
||||
backendDecks: null,
|
||||
downloadedDeck: null,
|
||||
downloadedReplay: null,
|
||||
gamesOfUser: {},
|
||||
registrationError: null,
|
||||
};
|
||||
|
|
@ -341,6 +343,14 @@ export const serverSlice = createSlice({
|
|||
});
|
||||
},
|
||||
|
||||
deckDownloaded: (state, action: PayloadAction<{ deckId: number; deck: string }>) => {
|
||||
state.downloadedDeck = action.payload;
|
||||
},
|
||||
|
||||
replayDownloaded: (state, action: PayloadAction<{ replayId: number; replayData: Uint8Array }>) => {
|
||||
state.downloadedReplay = action.payload;
|
||||
},
|
||||
|
||||
gamesOfUser: (state, action: PayloadAction<{ userName: string; response: Data.Response_GetGamesOfUser }>) => {
|
||||
const { userName, response } = action.payload;
|
||||
const gametypeMap = normalizeGametypeMap(
|
||||
|
|
|
|||
|
|
@ -133,6 +133,18 @@ describe('Selectors', () => {
|
|||
expect(Selectors.getBackendDecks(rootState(state))).toBeNull();
|
||||
});
|
||||
|
||||
it('getDownloadedDeck → returns downloadedDeck', () => {
|
||||
const downloadedDeck = { deckId: 42, deck: '<xml>' };
|
||||
const state = makeServerState({ downloadedDeck });
|
||||
expect(Selectors.getDownloadedDeck(rootState(state))).toEqual(downloadedDeck);
|
||||
});
|
||||
|
||||
it('getDownloadedReplay → returns downloadedReplay', () => {
|
||||
const downloadedReplay = { replayId: 99, replayData: new Uint8Array([1, 2, 3]) };
|
||||
const state = makeServerState({ downloadedReplay });
|
||||
expect(Selectors.getDownloadedReplay(rootState(state))).toEqual(downloadedReplay);
|
||||
});
|
||||
|
||||
it('getRegistrationError → returns registrationError', () => {
|
||||
const state = makeServerState({ registrationError: 'bad input' });
|
||||
expect(Selectors.getRegistrationError(rootState(state))).toBe('bad input');
|
||||
|
|
|
|||
|
|
@ -39,6 +39,8 @@ export const Selectors = {
|
|||
),
|
||||
getLogs: ({ server }: State) => server.logs,
|
||||
getBackendDecks: ({ server }: State) => server.backendDecks,
|
||||
getDownloadedDeck: ({ server }: State) => server.downloadedDeck,
|
||||
getDownloadedReplay: ({ server }: State) => server.downloadedReplay,
|
||||
getRegistrationError: ({ server }: State) => server.registrationError,
|
||||
getSortUsersBy: ({ server }: State) => server.sortUsersBy,
|
||||
|
||||
|
|
|
|||
|
|
@ -73,6 +73,8 @@ export const Types = {
|
|||
DECK_DEL_DIR: a.deckDelDir.type,
|
||||
DECK_UPLOAD: a.deckUpload.type,
|
||||
DECK_DELETE: a.deckDelete.type,
|
||||
DECK_DOWNLOADED: a.deckDownloaded.type,
|
||||
REPLAY_DOWNLOADED: a.replayDownloaded.type,
|
||||
// User games
|
||||
GAMES_OF_USER: a.gamesOfUser.type,
|
||||
} as const;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue