@zeniai/client-epic-state 5.0.55-betaSS1 → 5.0.55-betaVR1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/esm/index.js +5 -4
- package/lib/esm/view/expenseAutomationView/epics/missingReceipts/searchTransactionsForManualMatchEpic.js +0 -4
- package/lib/esm/view/expenseAutomationView/epics/transactionCategorization/fetchTransactionCategorizationEpic.js +0 -3
- package/lib/esm/view/expenseAutomationView/reducers/transactionsViewReducer.js +1 -71
- package/lib/esm/view/expenseAutomationView/selectors/transactionCategorizationSelector.js +1 -2
- package/lib/esm/view/expenseAutomationView/types/missingReceiptsViewState.js +2 -0
- package/lib/esm/view/transactionDetail/journalEntryLinesViewModel.js +113 -0
- package/lib/esm/view/transactionDetail/journalEntryLinesViewModel.vitest.js +243 -0
- package/lib/index.d.ts +6 -4
- package/lib/index.js +43 -37
- package/lib/view/expenseAutomationView/epics/missingReceipts/searchTransactionsForManualMatchEpic.js +0 -4
- package/lib/view/expenseAutomationView/epics/transactionCategorization/fetchTransactionCategorizationEpic.js +0 -3
- package/lib/view/expenseAutomationView/payload/transactionCategorizationPayload.d.ts +0 -8
- package/lib/view/expenseAutomationView/reducers/missingReceiptsViewReducer.d.ts +1 -2
- package/lib/view/expenseAutomationView/reducers/transactionsViewReducer.d.ts +1 -3
- package/lib/view/expenseAutomationView/reducers/transactionsViewReducer.js +2 -72
- package/lib/view/expenseAutomationView/selectorTypes/missingReceiptsSelectorTypes.d.ts +1 -2
- package/lib/view/expenseAutomationView/selectorTypes/transactionsViewSelectorTypes.d.ts +0 -2
- package/lib/view/expenseAutomationView/selectors/transactionCategorizationSelector.js +1 -2
- package/lib/view/expenseAutomationView/types/missingReceiptsViewState.d.ts +2 -1
- package/lib/view/expenseAutomationView/types/missingReceiptsViewState.js +4 -1
- package/lib/view/expenseAutomationView/types/transactionsViewState.d.ts +1 -27
- package/lib/view/transactionDetail/journalEntryLinesViewModel.d.ts +73 -0
- package/lib/view/transactionDetail/journalEntryLinesViewModel.js +124 -0
- package/lib/view/transactionDetail/journalEntryLinesViewModel.vitest.d.ts +1 -0
- package/lib/view/transactionDetail/journalEntryLinesViewModel.vitest.js +245 -0
- package/package.json +2 -2
- package/lib/esm/view/expenseAutomationView/types/completedSubTab.js +0 -9
- package/lib/view/expenseAutomationView/types/completedSubTab.d.ts +0 -2
- package/lib/view/expenseAutomationView/types/completedSubTab.js +0 -13
|
@@ -0,0 +1,245 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const vitest_1 = require("vitest");
|
|
4
|
+
const journalEntryLinesViewModel_1 = require("./journalEntryLinesViewModel");
|
|
5
|
+
const usd = (amount) => ({
|
|
6
|
+
amount,
|
|
7
|
+
currencyCode: 'USD',
|
|
8
|
+
currencySymbol: '$',
|
|
9
|
+
});
|
|
10
|
+
const debit = (n) => ({
|
|
11
|
+
amount: usd(n),
|
|
12
|
+
postingType: 'debit',
|
|
13
|
+
});
|
|
14
|
+
const credit = (n) => ({
|
|
15
|
+
amount: usd(n),
|
|
16
|
+
postingType: 'credit',
|
|
17
|
+
});
|
|
18
|
+
(0, vitest_1.describe)('sumJournalEntryAmounts', () => {
|
|
19
|
+
(0, vitest_1.it)('returns undefined for an empty list', () => {
|
|
20
|
+
(0, vitest_1.expect)((0, journalEntryLinesViewModel_1.sumJournalEntryAmounts)([])).toBeUndefined();
|
|
21
|
+
});
|
|
22
|
+
(0, vitest_1.it)('sums a single line as-is', () => {
|
|
23
|
+
(0, vitest_1.expect)((0, journalEntryLinesViewModel_1.sumJournalEntryAmounts)([{ amount: usd(42) }])).toEqual(usd(42));
|
|
24
|
+
});
|
|
25
|
+
(0, vitest_1.it)('sums multiple lines preserving the first line currency', () => {
|
|
26
|
+
const total = (0, journalEntryLinesViewModel_1.sumJournalEntryAmounts)([
|
|
27
|
+
{ amount: usd(10) },
|
|
28
|
+
{ amount: usd(20.5) },
|
|
29
|
+
{ amount: usd(0.5) },
|
|
30
|
+
]);
|
|
31
|
+
(0, vitest_1.expect)(total).toEqual(usd(31));
|
|
32
|
+
});
|
|
33
|
+
(0, vitest_1.it)('treats nullish amount.amount as 0 without crashing', () => {
|
|
34
|
+
const total = (0, journalEntryLinesViewModel_1.sumJournalEntryAmounts)([
|
|
35
|
+
{ amount: usd(10) },
|
|
36
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
37
|
+
{ amount: { currencyCode: 'USD', currencySymbol: '$' } },
|
|
38
|
+
{ amount: usd(5) },
|
|
39
|
+
]);
|
|
40
|
+
(0, vitest_1.expect)(total).toEqual(usd(15));
|
|
41
|
+
});
|
|
42
|
+
(0, vitest_1.it)('uses an empty currency code/symbol when first line lacks them', () => {
|
|
43
|
+
const total = (0, journalEntryLinesViewModel_1.sumJournalEntryAmounts)([
|
|
44
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
45
|
+
{ amount: { amount: 7 } },
|
|
46
|
+
{ amount: usd(3) },
|
|
47
|
+
]);
|
|
48
|
+
(0, vitest_1.expect)(total).toEqual({ amount: 10, currencyCode: '', currencySymbol: '' });
|
|
49
|
+
});
|
|
50
|
+
});
|
|
51
|
+
(0, vitest_1.describe)('journalEntryTotalsByPostingSide', () => {
|
|
52
|
+
(0, vitest_1.it)('returns undefined totals for an empty list', () => {
|
|
53
|
+
(0, vitest_1.expect)((0, journalEntryLinesViewModel_1.journalEntryTotalsByPostingSide)([])).toEqual({
|
|
54
|
+
debitTotal: undefined,
|
|
55
|
+
creditTotal: undefined,
|
|
56
|
+
});
|
|
57
|
+
});
|
|
58
|
+
(0, vitest_1.it)('sums debits and credits separately when both sides present', () => {
|
|
59
|
+
const { debitTotal, creditTotal } = (0, journalEntryLinesViewModel_1.journalEntryTotalsByPostingSide)([
|
|
60
|
+
debit(100),
|
|
61
|
+
debit(50),
|
|
62
|
+
credit(120),
|
|
63
|
+
credit(30),
|
|
64
|
+
]);
|
|
65
|
+
(0, vitest_1.expect)(debitTotal).toEqual(usd(150));
|
|
66
|
+
(0, vitest_1.expect)(creditTotal).toEqual(usd(150));
|
|
67
|
+
});
|
|
68
|
+
(0, vitest_1.it)('returns only the populated side when one side is missing', () => {
|
|
69
|
+
const onlyDebits = (0, journalEntryLinesViewModel_1.journalEntryTotalsByPostingSide)([debit(10), debit(20)]);
|
|
70
|
+
(0, vitest_1.expect)(onlyDebits.debitTotal).toEqual(usd(30));
|
|
71
|
+
(0, vitest_1.expect)(onlyDebits.creditTotal).toBeUndefined();
|
|
72
|
+
const onlyCredits = (0, journalEntryLinesViewModel_1.journalEntryTotalsByPostingSide)([credit(99)]);
|
|
73
|
+
(0, vitest_1.expect)(onlyCredits.creditTotal).toEqual(usd(99));
|
|
74
|
+
(0, vitest_1.expect)(onlyCredits.debitTotal).toBeUndefined();
|
|
75
|
+
});
|
|
76
|
+
/**
|
|
77
|
+
* Regression test for the operator-precedence bug in legacy
|
|
78
|
+
* `calculateCombinedTotalAmount` where
|
|
79
|
+
* `totalAmount?.amount ?? 0 + (uncategorized?.amount ?? 0) + (miscategorized?.amount ?? 0)`
|
|
80
|
+
* parses as `totalAmount?.amount ?? (0 + ... + ...)`. With the bug,
|
|
81
|
+
* an existing `totalAmount` would short-circuit and the uncat/miscat
|
|
82
|
+
* pieces would be ignored. The new implementation always adds every
|
|
83
|
+
* matching line, so 100 (cat) + 25 (uncat) + 10 (miscat) = 135.
|
|
84
|
+
*/
|
|
85
|
+
(0, vitest_1.it)('does not drop uncategorized/miscategorized contributions (precedence-bug regression)', () => {
|
|
86
|
+
const { debitTotal } = (0, journalEntryLinesViewModel_1.journalEntryTotalsByPostingSide)([
|
|
87
|
+
debit(100),
|
|
88
|
+
debit(25),
|
|
89
|
+
debit(10),
|
|
90
|
+
]);
|
|
91
|
+
(0, vitest_1.expect)(debitTotal).toEqual(usd(135));
|
|
92
|
+
});
|
|
93
|
+
(0, vitest_1.it)('ignores lines with neither debit nor credit posting type', () => {
|
|
94
|
+
const totals = (0, journalEntryLinesViewModel_1.journalEntryTotalsByPostingSide)([
|
|
95
|
+
debit(40),
|
|
96
|
+
credit(40),
|
|
97
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
98
|
+
{ amount: usd(999), postingType: 'unknown' },
|
|
99
|
+
]);
|
|
100
|
+
(0, vitest_1.expect)(totals.debitTotal).toEqual(usd(40));
|
|
101
|
+
(0, vitest_1.expect)(totals.creditTotal).toEqual(usd(40));
|
|
102
|
+
});
|
|
103
|
+
});
|
|
104
|
+
(0, vitest_1.describe)('filterJournalEntryLinesExcludingLinked', () => {
|
|
105
|
+
(0, vitest_1.it)('returns [] for undefined input', () => {
|
|
106
|
+
(0, vitest_1.expect)((0, journalEntryLinesViewModel_1.filterJournalEntryLinesExcludingLinked)(undefined)).toEqual([]);
|
|
107
|
+
});
|
|
108
|
+
(0, vitest_1.it)('filters out linked_transaction_line entries', () => {
|
|
109
|
+
const lines = [
|
|
110
|
+
{ id: 'a', type: 'journal_entry_transaction_line' },
|
|
111
|
+
{ id: 'b', type: 'linked_transaction_line' },
|
|
112
|
+
{ id: 'c', type: 'journal_entry_transaction_line' },
|
|
113
|
+
];
|
|
114
|
+
const filtered = (0, journalEntryLinesViewModel_1.filterJournalEntryLinesExcludingLinked)(lines);
|
|
115
|
+
(0, vitest_1.expect)(filtered).toHaveLength(2);
|
|
116
|
+
(0, vitest_1.expect)(filtered[0].id).toBe('a');
|
|
117
|
+
(0, vitest_1.expect)(filtered[1].id).toBe('c');
|
|
118
|
+
});
|
|
119
|
+
(0, vitest_1.it)('returns input unchanged when no linked lines exist', () => {
|
|
120
|
+
const lines = [
|
|
121
|
+
{ id: 'a', type: 'journal_entry_transaction_line' },
|
|
122
|
+
{ id: 'b', type: 'journal_entry_transaction_line' },
|
|
123
|
+
];
|
|
124
|
+
(0, vitest_1.expect)((0, journalEntryLinesViewModel_1.filterJournalEntryLinesExcludingLinked)(lines)).toHaveLength(2);
|
|
125
|
+
});
|
|
126
|
+
});
|
|
127
|
+
(0, vitest_1.describe)('sortJournalEntryLines', () => {
|
|
128
|
+
const accessors = {
|
|
129
|
+
description: (r) => r.description,
|
|
130
|
+
name: (r) => r.name,
|
|
131
|
+
category: (r) => r.category,
|
|
132
|
+
class: (r) => r.class,
|
|
133
|
+
debit: (r) => r.debit,
|
|
134
|
+
credit: (r) => r.credit,
|
|
135
|
+
};
|
|
136
|
+
const rows = [
|
|
137
|
+
{
|
|
138
|
+
id: '1',
|
|
139
|
+
description: 'Beta',
|
|
140
|
+
name: 'Acme',
|
|
141
|
+
category: 'Rent',
|
|
142
|
+
class: 'Ops',
|
|
143
|
+
debit: 100,
|
|
144
|
+
credit: 0,
|
|
145
|
+
},
|
|
146
|
+
{
|
|
147
|
+
id: '2',
|
|
148
|
+
description: 'alpha',
|
|
149
|
+
name: 'Beta Co',
|
|
150
|
+
category: 'Travel',
|
|
151
|
+
class: 'GA',
|
|
152
|
+
debit: 200,
|
|
153
|
+
credit: 0,
|
|
154
|
+
},
|
|
155
|
+
{
|
|
156
|
+
id: '3',
|
|
157
|
+
description: 'Gamma',
|
|
158
|
+
name: 'acme',
|
|
159
|
+
category: 'Rent',
|
|
160
|
+
class: 'Sales',
|
|
161
|
+
debit: 0,
|
|
162
|
+
credit: 50,
|
|
163
|
+
},
|
|
164
|
+
];
|
|
165
|
+
(0, vitest_1.it)('exposes every supported sort key via JOURNAL_ENTRY_SORT_KEYS', () => {
|
|
166
|
+
(0, vitest_1.expect)([...journalEntryLinesViewModel_1.JOURNAL_ENTRY_SORT_KEYS]).toEqual([
|
|
167
|
+
'description',
|
|
168
|
+
'name',
|
|
169
|
+
'category',
|
|
170
|
+
'class',
|
|
171
|
+
'debit',
|
|
172
|
+
'credit',
|
|
173
|
+
]);
|
|
174
|
+
});
|
|
175
|
+
(0, vitest_1.it)('sorts by description case-insensitively ascending by default', () => {
|
|
176
|
+
const sorted = (0, journalEntryLinesViewModel_1.sortJournalEntryLines)(rows, journalEntryLinesViewModel_1.journalEntryDefaultSortConfig, accessors);
|
|
177
|
+
(0, vitest_1.expect)(sorted.map((r) => r.id)).toEqual(['2', '1', '3']);
|
|
178
|
+
});
|
|
179
|
+
(0, vitest_1.it)('sorts by description descending when configured', () => {
|
|
180
|
+
const config = {
|
|
181
|
+
sortKey: 'description',
|
|
182
|
+
sortOrder: 'descending',
|
|
183
|
+
};
|
|
184
|
+
const sorted = (0, journalEntryLinesViewModel_1.sortJournalEntryLines)(rows, config, accessors);
|
|
185
|
+
(0, vitest_1.expect)(sorted.map((r) => r.id)).toEqual(['3', '1', '2']);
|
|
186
|
+
});
|
|
187
|
+
vitest_1.it.each([
|
|
188
|
+
['name', 'ascending', ['1', '3', '2']],
|
|
189
|
+
['name', 'descending', ['2', '1', '3']],
|
|
190
|
+
['category', 'ascending', ['1', '3', '2']],
|
|
191
|
+
['class', 'ascending', ['2', '1', '3']],
|
|
192
|
+
['debit', 'ascending', ['3', '1', '2']],
|
|
193
|
+
['debit', 'descending', ['2', '1', '3']],
|
|
194
|
+
['credit', 'ascending', ['1', '2', '3']],
|
|
195
|
+
['credit', 'descending', ['3', '1', '2']],
|
|
196
|
+
])('sorts by %s %s producing the expected order', (key, order, expected) => {
|
|
197
|
+
const config = {
|
|
198
|
+
sortKey: key,
|
|
199
|
+
sortOrder: order,
|
|
200
|
+
};
|
|
201
|
+
const sorted = (0, journalEntryLinesViewModel_1.sortJournalEntryLines)(rows, config, accessors);
|
|
202
|
+
(0, vitest_1.expect)(sorted.map((r) => r.id)).toEqual([...expected]);
|
|
203
|
+
});
|
|
204
|
+
(0, vitest_1.it)('keeps stable order for ties on the sort key', () => {
|
|
205
|
+
const tied = [
|
|
206
|
+
{
|
|
207
|
+
id: 'a',
|
|
208
|
+
description: 'same',
|
|
209
|
+
name: '',
|
|
210
|
+
category: '',
|
|
211
|
+
class: '',
|
|
212
|
+
debit: 0,
|
|
213
|
+
credit: 0,
|
|
214
|
+
},
|
|
215
|
+
{
|
|
216
|
+
id: 'b',
|
|
217
|
+
description: 'same',
|
|
218
|
+
name: '',
|
|
219
|
+
category: '',
|
|
220
|
+
class: '',
|
|
221
|
+
debit: 0,
|
|
222
|
+
credit: 0,
|
|
223
|
+
},
|
|
224
|
+
{
|
|
225
|
+
id: 'c',
|
|
226
|
+
description: 'same',
|
|
227
|
+
name: '',
|
|
228
|
+
category: '',
|
|
229
|
+
class: '',
|
|
230
|
+
debit: 0,
|
|
231
|
+
credit: 0,
|
|
232
|
+
},
|
|
233
|
+
];
|
|
234
|
+
const sortedAsc = (0, journalEntryLinesViewModel_1.sortJournalEntryLines)(tied, { sortKey: 'description', sortOrder: 'ascending' }, accessors);
|
|
235
|
+
(0, vitest_1.expect)(sortedAsc.map((r) => r.id)).toEqual(['a', 'b', 'c']);
|
|
236
|
+
const sortedDesc = (0, journalEntryLinesViewModel_1.sortJournalEntryLines)(tied, { sortKey: 'description', sortOrder: 'descending' }, accessors);
|
|
237
|
+
(0, vitest_1.expect)(sortedDesc.map((r) => r.id)).toEqual(['a', 'b', 'c']);
|
|
238
|
+
});
|
|
239
|
+
(0, vitest_1.it)('does not mutate the input array', () => {
|
|
240
|
+
const input = [...rows];
|
|
241
|
+
const before = input.map((r) => r.id);
|
|
242
|
+
(0, journalEntryLinesViewModel_1.sortJournalEntryLines)(input, { sortKey: 'description', sortOrder: 'descending' }, accessors);
|
|
243
|
+
(0, vitest_1.expect)(input.map((r) => r.id)).toEqual(before);
|
|
244
|
+
});
|
|
245
|
+
});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@zeniai/client-epic-state",
|
|
3
|
-
"version": "5.0.55-
|
|
3
|
+
"version": "5.0.55-betaVR1",
|
|
4
4
|
"description": "Shared module between Web & Mobile containing required abstractions for state management, async network communication. ",
|
|
5
5
|
"main": "lib/index.js",
|
|
6
6
|
"module": "lib/esm/index.js",
|
|
@@ -111,7 +111,7 @@
|
|
|
111
111
|
"find-dead-code": "ts-prune | grep -v '(used in module)'",
|
|
112
112
|
"find-unused-exports": "ts-unused-exports ./tsconfig.json",
|
|
113
113
|
"circular-dependency": "npx madge --circular --extensions ts ./src",
|
|
114
|
-
"build": "concurrently --kill-others-on-fail --handle-input \"echo 'Running ESLint...' && eslint . --ext .js,.jsx,.ts,.tsx\" \"echo 'TypeScript build in progress...' && time tsc && echo 'ESM build...' && tsc -p tsconfig.esm.json\"
|
|
114
|
+
"build": "concurrently --kill-others-on-fail --handle-input \"echo 'Running ESLint...' && eslint . --ext .js,.jsx,.ts,.tsx\" \"echo 'TypeScript build in progress...' && time tsc && echo 'ESM build...' && tsc -p tsconfig.esm.json\"",
|
|
115
115
|
"only-build": "eslint . --ext .js,.jsx,.ts,.tsx && time tsc && tsc -p tsconfig.esm.json && rimraf \"lib/**/__mocks__\" \"lib/**/__testHelpers__\"",
|
|
116
116
|
"only-build-dev": "eslint . --ext .js,.jsx,.ts,.tsx && time tsc -p tsconfig.dev.json && tsc -p tsconfig.esm.dev.json && rimraf \"lib/**/__mocks__\" \"lib/**/__testHelpers__\"",
|
|
117
117
|
"format": "prettier --write --ignore-unknown \"src/**/*\" && pnpm lint",
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
import { stringToUnion } from '../../../commonStateTypes/stringToUnion';
|
|
2
|
-
/**
|
|
3
|
-
* Sub-tabs that can appear under any "Completed" tab in the Expense Automation
|
|
4
|
-
* surface (Transaction Categorization Completed and Missing Receipts Completed
|
|
5
|
-
* both use this exact union). Forwarded verbatim to listing APIs as `sub_tab`
|
|
6
|
-
* / `match_type`. `'all'` preserves parent-tab semantics on the backend.
|
|
7
|
-
*/
|
|
8
|
-
const COMPLETED_SUB_TABS = ['all', 'ai_accountant', 'manual'];
|
|
9
|
-
export const toCompletedSubTab = (v) => stringToUnion(v.trim().toLowerCase(), COMPLETED_SUB_TABS);
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.toCompletedSubTab = void 0;
|
|
4
|
-
const stringToUnion_1 = require("../../../commonStateTypes/stringToUnion");
|
|
5
|
-
/**
|
|
6
|
-
* Sub-tabs that can appear under any "Completed" tab in the Expense Automation
|
|
7
|
-
* surface (Transaction Categorization Completed and Missing Receipts Completed
|
|
8
|
-
* both use this exact union). Forwarded verbatim to listing APIs as `sub_tab`
|
|
9
|
-
* / `match_type`. `'all'` preserves parent-tab semantics on the backend.
|
|
10
|
-
*/
|
|
11
|
-
const COMPLETED_SUB_TABS = ['all', 'ai_accountant', 'manual'];
|
|
12
|
-
const toCompletedSubTab = (v) => (0, stringToUnion_1.stringToUnion)(v.trim().toLowerCase(), COMPLETED_SUB_TABS);
|
|
13
|
-
exports.toCompletedSubTab = toCompletedSubTab;
|