mirror of
https://github.com/actualbudget/actual.git
synced 2026-03-21 15:36:50 -05:00
Fix tests and typecheck errors
This commit is contained in:
@@ -1,33 +1,29 @@
|
||||
import { getBankSyncError } from '../shared/errors';
|
||||
import type { ServerHandlers } from '../types/server-handlers';
|
||||
|
||||
import { installAPI } from './api';
|
||||
import { app as apiApp } from './api';
|
||||
|
||||
vi.mock('../shared/errors', () => ({
|
||||
getBankSyncError: vi.fn(error => `Bank sync error: ${error}`),
|
||||
}));
|
||||
|
||||
describe('API handlers', () => {
|
||||
const handlers = installAPI({} as unknown as ServerHandlers);
|
||||
|
||||
describe('api/bank-sync', () => {
|
||||
it('should sync a single account when accountId is provided', async () => {
|
||||
handlers['accounts-bank-sync'] = vi
|
||||
.fn()
|
||||
.mockResolvedValue({ errors: [] });
|
||||
apiApp['accounts-bank-sync'] = vi.fn().mockResolvedValue({ errors: [] });
|
||||
|
||||
await handlers['api/bank-sync']({ accountId: 'account1' });
|
||||
expect(handlers['accounts-bank-sync']).toHaveBeenCalledWith({
|
||||
await apiApp['api/bank-sync']({ accountId: 'account1' });
|
||||
expect(apiApp['accounts-bank-sync']).toHaveBeenCalledWith({
|
||||
ids: ['account1'],
|
||||
});
|
||||
});
|
||||
|
||||
it('should handle errors in non batch sync', async () => {
|
||||
handlers['accounts-bank-sync'] = vi.fn().mockResolvedValue({
|
||||
apiApp['accounts-bank-sync'] = vi.fn().mockResolvedValue({
|
||||
errors: ['connection-failed'],
|
||||
});
|
||||
|
||||
await expect(
|
||||
handlers['api/bank-sync']({ accountId: 'account2' }),
|
||||
apiApp['api/bank-sync']({ accountId: 'account2' }),
|
||||
).rejects.toThrow('Bank sync error: connection-failed');
|
||||
|
||||
expect(getBankSyncError).toHaveBeenCalledWith('connection-failed');
|
||||
|
||||
@@ -9,7 +9,7 @@ import { q } from '../shared/query';
|
||||
import type { QueryState } from '../shared/query';
|
||||
import { amountToInteger, integerToAmount } from '../shared/util';
|
||||
import type { ApiHandlers } from '../types/api-handlers';
|
||||
import type { Handlers } from '../types/handlers';
|
||||
import type { Handlers, ServerHandlers } from '../types/handlers';
|
||||
|
||||
import { app as accountsApp } from './accounts/app';
|
||||
import { app as adminApp } from './admin/app';
|
||||
@@ -110,7 +110,7 @@ async function appFocused() {
|
||||
}
|
||||
}
|
||||
|
||||
export type ServerHandlers = {
|
||||
export type MiscHandlers = {
|
||||
undo: () => Promise<void>;
|
||||
redo: () => Promise<void>;
|
||||
|
||||
@@ -136,7 +136,7 @@ export type ServerHandlers = {
|
||||
'app-focused': () => Promise<void>;
|
||||
};
|
||||
|
||||
const serverApp = createApp<ServerHandlers>({
|
||||
const miscApp = createApp<MiscHandlers>({
|
||||
undo: mutator(undo),
|
||||
redo: mutator(redo),
|
||||
'make-filters-from-conditions': makeFiltersFromConditions,
|
||||
@@ -147,15 +147,14 @@ const serverApp = createApp<ServerHandlers>({
|
||||
'app-focused': appFocused,
|
||||
});
|
||||
|
||||
// Main app
|
||||
export const mainApp = createApp<Handlers>();
|
||||
const serverApp = createApp<ServerHandlers>();
|
||||
|
||||
mainApp.events.on('sync', event => {
|
||||
serverApp.events.on('sync', event => {
|
||||
connection.send('sync-event', event);
|
||||
});
|
||||
|
||||
mainApp.combine(
|
||||
serverApp,
|
||||
serverApp.combine(
|
||||
miscApp,
|
||||
authApp,
|
||||
schedulesApp,
|
||||
budgetApp,
|
||||
@@ -177,6 +176,9 @@ mainApp.combine(
|
||||
tagsApp,
|
||||
);
|
||||
|
||||
export const mainApp = createApp<Handlers>();
|
||||
mainApp.combine(apiApp, serverApp);
|
||||
|
||||
export function getDefaultDocumentDir() {
|
||||
return fs.join(process.env.ACTUAL_DOCUMENT_DIR, 'Actual');
|
||||
}
|
||||
@@ -337,9 +339,6 @@ export async function init(config: InitConfig) {
|
||||
|
||||
// Export a few things required for the platform
|
||||
|
||||
const combinedApp = createApp<ApiHandlers & Handlers>();
|
||||
combinedApp.combine(apiApp, mainApp);
|
||||
|
||||
export const lib = {
|
||||
getDataDir: fs.getDataDir,
|
||||
sendMessage: (msg, args) => connection.send(msg, args),
|
||||
@@ -347,10 +346,10 @@ export const lib = {
|
||||
name: K,
|
||||
args?: Parameters<Handlers[K]>[0],
|
||||
): Promise<Awaited<ReturnType<Handlers[K]>>> => {
|
||||
const res = await combinedApp.runHandler(name, args);
|
||||
const res = await mainApp.runHandler(name, args);
|
||||
return res as Awaited<ReturnType<Handlers[K]>>;
|
||||
},
|
||||
on: (name, func) => combinedApp.events.on(name, func),
|
||||
on: (name, func) => mainApp.events.on(name, func),
|
||||
q,
|
||||
db,
|
||||
amountToInteger,
|
||||
|
||||
@@ -6,7 +6,7 @@ import type { BudgetFileHandlers } from '../server/budgetfiles/app';
|
||||
import type { DashboardHandlers } from '../server/dashboard/app';
|
||||
import type { EncryptionHandlers } from '../server/encryption/app';
|
||||
import type { FiltersHandlers } from '../server/filters/app';
|
||||
import type { ServerHandlers } from '../server/main';
|
||||
import type { MiscHandlers } from '../server/main';
|
||||
import type { NotesHandlers } from '../server/notes/app';
|
||||
import type { PayeeHandlers } from '../server/payees/app';
|
||||
import type { PreferencesHandlers } from '../server/preferences/app';
|
||||
@@ -19,7 +19,9 @@ import type { TagsHandlers } from '../server/tags/app';
|
||||
import type { ToolsHandlers } from '../server/tools/app';
|
||||
import type { TransactionHandlers } from '../server/transactions/app';
|
||||
|
||||
export type Handlers = {} & ServerHandlers &
|
||||
import type { ApiHandlers } from './api-handlers';
|
||||
|
||||
export type ServerHandlers = MiscHandlers &
|
||||
BudgetHandlers &
|
||||
DashboardHandlers &
|
||||
FiltersHandlers &
|
||||
@@ -40,4 +42,6 @@ export type Handlers = {} & ServerHandlers &
|
||||
TagsHandlers &
|
||||
AuthHandlers;
|
||||
|
||||
export type Handlers = {} & ServerHandlers & ApiHandlers;
|
||||
|
||||
export type HandlerFunctions = Handlers[keyof Handlers];
|
||||
|
||||
Reference in New Issue
Block a user