-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add test for goals schedule template
- Loading branch information
Showing
1 changed file
with
85 additions
and
0 deletions.
There are no files selected for viewing
85 changes: 85 additions & 0 deletions
85
packages/loot-core/src/server/budget/goals/goalsSchedule.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
import * as db from '../../db'; | ||
import { getRuleForSchedule } from '../../schedules/app'; | ||
import { isReflectBudget } from '../actions'; | ||
|
||
import { goalsSchedule } from './goalsSchedule'; | ||
|
||
jest.mock('../../db'); | ||
jest.mock('../actions'); | ||
jest.mock('../../schedules/app', () => { | ||
const actualModule = jest.requireActual('../../schedules/app'); | ||
return { | ||
...actualModule, | ||
getRuleForSchedule: jest.fn(), | ||
}; | ||
}); | ||
|
||
describe('goalsSchedule', () => { | ||
beforeEach(() => { | ||
jest.clearAllMocks(); | ||
}); | ||
|
||
it('should return correct budget when recurring schedule set', async () => { | ||
// Given | ||
const scheduleFlag = false; | ||
const template_lines = [{ type: 'schedule', name: 'Test Schedule' }]; | ||
const current_month = '2024-08-01'; | ||
const balance = 0; | ||
const remainder = 0; | ||
const last_month_balance = 0; | ||
const to_budget = 0; | ||
const errors = []; | ||
const category = { id: 1, name: 'Test Category' }; | ||
|
||
(db.first as jest.Mock).mockResolvedValue({ id: 1, completed: 0 }); | ||
(getRuleForSchedule as jest.Mock).mockResolvedValue({ | ||
serialize: () => ({ | ||
conditions: [ | ||
{ | ||
op: 'is', | ||
field: 'date', | ||
value: { | ||
start: '2024-08-01', | ||
interval: 1, | ||
frequency: 'monthly', | ||
patterns: [], | ||
skipWeekend: false, | ||
weekendSolveMode: 'before', | ||
endMode: 'never', | ||
endOccurrences: 1, | ||
endDate: '2024-08-04', | ||
}, | ||
type: 'date', | ||
}, | ||
{ | ||
op: 'is', | ||
field: 'amount', | ||
value: -10000, | ||
type: 'number', | ||
}, | ||
], | ||
}), | ||
execActions: () => ({ amount: -10000, subtransactions: [] }), | ||
}); | ||
(isReflectBudget as jest.Mock).mockReturnValue(false); | ||
|
||
// When | ||
const result = await goalsSchedule( | ||
scheduleFlag, | ||
template_lines, | ||
current_month, | ||
balance, | ||
remainder, | ||
last_month_balance, | ||
to_budget, | ||
errors, | ||
category, | ||
); | ||
|
||
// Then | ||
expect(result.to_budget).toBe(10000); | ||
expect(result.errors).toHaveLength(0); | ||
expect(result.remainder).toBe(0); | ||
expect(result.scheduleFlag).toBe(true); | ||
}); | ||
}); |