mirror of
https://github.com/actualbudget/actual.git
synced 2026-03-21 15:36:50 -05:00
Fix tests
This commit is contained in:
@@ -10,7 +10,7 @@ vi.mock('./sync', async () => ({
|
|||||||
syncAccount: vi.fn(),
|
syncAccount: vi.fn(),
|
||||||
}));
|
}));
|
||||||
|
|
||||||
const simpleFinBatchSyncHandler = app.handlers['simplefin-batch-sync'];
|
const simpleFinBatchSyncHandler = app['simplefin-batch-sync'];
|
||||||
|
|
||||||
function insertBank(bank: { id: string; bank_id: string; name: string }) {
|
function insertBank(bank: { id: string; bank_id: string; name: string }) {
|
||||||
db.runQuery(
|
db.runQuery(
|
||||||
|
|||||||
@@ -1,32 +1,39 @@
|
|||||||
import { getBankSyncError } from '../shared/errors';
|
// @ts-strict-ignore
|
||||||
|
|
||||||
import { app as apiApp } from './api';
|
import { app as apiApp } from './api';
|
||||||
|
import { mainApp } from './main';
|
||||||
|
|
||||||
vi.mock('../shared/errors', () => ({
|
describe('API app', () => {
|
||||||
getBankSyncError: vi.fn(error => `Bank sync error: ${error}`),
|
|
||||||
}));
|
|
||||||
|
|
||||||
describe('API handlers', () => {
|
|
||||||
describe('api/bank-sync', () => {
|
describe('api/bank-sync', () => {
|
||||||
|
afterEach(() => {
|
||||||
|
vi.restoreAllMocks();
|
||||||
|
});
|
||||||
|
|
||||||
it('should sync a single account when accountId is provided', async () => {
|
it('should sync a single account when accountId is provided', async () => {
|
||||||
apiApp['accounts-bank-sync'] = vi.fn().mockResolvedValue({ errors: [] });
|
vi.spyOn(mainApp, 'runHandler').mockImplementation(
|
||||||
|
async (name: string) => {
|
||||||
|
if (name === 'accounts-bank-sync') return { errors: [] };
|
||||||
|
throw new Error(`Unexpected handler: ${name}`);
|
||||||
|
},
|
||||||
|
);
|
||||||
|
|
||||||
await apiApp['api/bank-sync']({ accountId: 'account1' });
|
await apiApp['api/bank-sync']({ accountId: 'account1' });
|
||||||
expect(apiApp['accounts-bank-sync']).toHaveBeenCalledWith({
|
expect(mainApp.runHandler).toHaveBeenCalledWith('accounts-bank-sync', {
|
||||||
ids: ['account1'],
|
ids: ['account1'],
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should handle errors in non batch sync', async () => {
|
it('should throw an error when bank sync fails', async () => {
|
||||||
apiApp['accounts-bank-sync'] = vi.fn().mockResolvedValue({
|
vi.spyOn(mainApp, 'runHandler').mockImplementation(
|
||||||
errors: ['connection-failed'],
|
async (name: string) => {
|
||||||
});
|
if (name === 'accounts-bank-sync')
|
||||||
|
return { errors: [{ message: 'connection-failed' }] };
|
||||||
|
throw new Error(`Unexpected handler: ${name}`);
|
||||||
|
},
|
||||||
|
);
|
||||||
|
|
||||||
await expect(
|
await expect(
|
||||||
apiApp['api/bank-sync']({ accountId: 'account2' }),
|
apiApp['api/bank-sync']({ accountId: 'account2' }),
|
||||||
).rejects.toThrow('Bank sync error: connection-failed');
|
).rejects.toThrow('connection-failed');
|
||||||
|
|
||||||
expect(getBankSyncError).toHaveBeenCalledWith('connection-failed');
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -263,7 +263,7 @@ handlers['api/bank-sync'] = async function (args) {
|
|||||||
const allErrors = [];
|
const allErrors = [];
|
||||||
|
|
||||||
if (!batchSync) {
|
if (!batchSync) {
|
||||||
const { errors } = await mainApp['bank-sync']({
|
const { errors } = await mainApp['accounts-bank-sync']({
|
||||||
ids: [args.accountId],
|
ids: [args.accountId],
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user