@accounter/server 0.0.9-alpha-20251210153039-1cfd8df346dd211c95a70c76c63465a29236849b → 0.0.9-alpha-20251210155614-e6e65aaecafef9e8fedd0b933f613ffcf478cecf
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/CHANGELOG.md +5 -27
- package/dist/green-invoice-graphql/src/mesh-artifacts/index.d.ts +1 -1
- package/dist/server/src/__tests__/factories/business.d.ts +2 -2
- package/dist/server/src/__tests__/factories/business.js +4 -5
- package/dist/server/src/__tests__/factories/business.js.map +1 -1
- package/dist/server/src/__tests__/factories/business.test.js +2 -2
- package/dist/server/src/__tests__/factories/business.test.js.map +1 -1
- package/dist/server/src/__tests__/factories/charge.d.ts +9 -9
- package/dist/server/src/__tests__/factories/charge.js +15 -15
- package/dist/server/src/__tests__/factories/charge.js.map +1 -1
- package/dist/server/src/__tests__/factories/charge.test.js +14 -14
- package/dist/server/src/__tests__/factories/charge.test.js.map +1 -1
- package/dist/server/src/__tests__/factories/document.d.ts +9 -9
- package/dist/server/src/__tests__/factories/document.js +11 -11
- package/dist/server/src/__tests__/factories/document.js.map +1 -1
- package/dist/server/src/__tests__/factories/document.test.js +38 -38
- package/dist/server/src/__tests__/factories/document.test.js.map +1 -1
- package/dist/server/src/__tests__/factories/financial-account.js +2 -2
- package/dist/server/src/__tests__/factories/financial-account.js.map +1 -1
- package/dist/server/src/__tests__/factories/financial-account.test.js +7 -7
- package/dist/server/src/__tests__/factories/financial-account.test.js.map +1 -1
- package/dist/server/src/__tests__/factories/ids.d.ts +22 -0
- package/dist/server/src/__tests__/factories/ids.js +46 -0
- package/dist/server/src/__tests__/factories/ids.js.map +1 -0
- package/dist/server/src/__tests__/factories/ids.test.js +71 -0
- package/dist/server/src/__tests__/factories/ids.test.js.map +1 -0
- package/dist/server/src/__tests__/factories/index.d.ts +2 -2
- package/dist/server/src/__tests__/factories/index.js +2 -2
- package/dist/server/src/__tests__/factories/index.js.map +1 -1
- package/dist/server/src/__tests__/factories/index.test.js +12 -12
- package/dist/server/src/__tests__/factories/index.test.js.map +1 -1
- package/dist/server/src/__tests__/factories/tax-category.d.ts +3 -3
- package/dist/server/src/__tests__/factories/tax-category.js +5 -6
- package/dist/server/src/__tests__/factories/tax-category.js.map +1 -1
- package/dist/server/src/__tests__/factories/tax-category.test.js +4 -4
- package/dist/server/src/__tests__/factories/tax-category.test.js.map +1 -1
- package/dist/server/src/__tests__/factories/transaction.d.ts +7 -7
- package/dist/server/src/__tests__/factories/transaction.js +11 -11
- package/dist/server/src/__tests__/factories/transaction.js.map +1 -1
- package/dist/server/src/__tests__/factories/transaction.test.js +27 -27
- package/dist/server/src/__tests__/factories/transaction.test.js.map +1 -1
- package/dist/server/src/__tests__/fixtures/expenses/expense-scenario-a.js +20 -20
- package/dist/server/src/__tests__/fixtures/expenses/expense-scenario-a.js.map +1 -1
- package/dist/server/src/__tests__/fixtures/expenses/expense-scenario-b.js +20 -20
- package/dist/server/src/__tests__/fixtures/expenses/expense-scenario-b.js.map +1 -1
- package/dist/server/src/__tests__/fixtures/expenses/expense-scenario-b.test.js +8 -8
- package/dist/server/src/__tests__/fixtures/expenses/expense-scenario-b.test.js.map +1 -1
- package/dist/server/src/__tests__/helpers/fixture-loader.js +2 -2
- package/dist/server/src/__tests__/helpers/fixture-loader.js.map +1 -1
- package/dist/server/src/__tests__/helpers/fixture-loader.test.js +29 -32
- package/dist/server/src/__tests__/helpers/fixture-loader.test.js.map +1 -1
- package/dist/server/src/__tests__/helpers/fixture-validation.test.js +50 -50
- package/dist/server/src/__tests__/helpers/fixture-validation.test.js.map +1 -1
- package/dist/server/src/modules/ledger/__tests__/helpers/ledger-assertions.d.ts +2 -0
- package/dist/server/src/modules/ledger/__tests__/helpers/ledger-assertions.js +4 -0
- package/dist/server/src/modules/ledger/__tests__/helpers/ledger-assertions.js.map +1 -1
- package/dist/server/src/modules/ledger/__tests__/ledger-scenario-a.integration.test.js +20 -20
- package/dist/server/src/modules/ledger/__tests__/ledger-scenario-a.integration.test.js.map +1 -1
- package/dist/server/src/modules/ledger/__tests__/ledger-scenario-b.integration.test.js +21 -21
- package/dist/server/src/modules/ledger/__tests__/ledger-scenario-b.integration.test.js.map +1 -1
- package/package.json +1 -1
- package/src/__tests__/factories/business.test.ts +3 -3
- package/src/__tests__/factories/business.ts +4 -5
- package/src/__tests__/factories/charge.test.ts +14 -14
- package/src/__tests__/factories/charge.ts +16 -16
- package/src/__tests__/factories/document.test.ts +38 -38
- package/src/__tests__/factories/document.ts +11 -11
- package/src/__tests__/factories/financial-account.test.ts +7 -7
- package/src/__tests__/factories/financial-account.ts +3 -3
- package/src/__tests__/factories/ids.test.ts +80 -0
- package/src/__tests__/factories/ids.ts +49 -0
- package/src/__tests__/factories/index.test.ts +12 -12
- package/src/__tests__/factories/index.ts +2 -2
- package/src/__tests__/factories/tax-category.test.ts +4 -4
- package/src/__tests__/factories/tax-category.ts +6 -7
- package/src/__tests__/factories/transaction.test.ts +27 -27
- package/src/__tests__/factories/transaction.ts +11 -11
- package/src/__tests__/fixtures/expenses/expense-scenario-a.ts +20 -20
- package/src/__tests__/fixtures/expenses/expense-scenario-b.test.ts +8 -8
- package/src/__tests__/fixtures/expenses/expense-scenario-b.ts +20 -20
- package/src/__tests__/helpers/fixture-loader.test.ts +29 -31
- package/src/__tests__/helpers/fixture-loader.ts +2 -2
- package/src/__tests__/helpers/fixture-validation.test.ts +50 -50
- package/src/modules/ledger/__tests__/helpers/ledger-assertions.ts +5 -0
- package/src/modules/ledger/__tests__/ledger-scenario-a.integration.test.ts +20 -20
- package/src/modules/ledger/__tests__/ledger-scenario-b.integration.test.ts +21 -21
- package/dist/server/src/demo-fixtures/__tests__/deterministic-uuid.test.js +0 -58
- package/dist/server/src/demo-fixtures/__tests__/deterministic-uuid.test.js.map +0 -1
- package/dist/server/src/demo-fixtures/helpers/deterministic-uuid.d.ts +0 -50
- package/dist/server/src/demo-fixtures/helpers/deterministic-uuid.js +0 -66
- package/dist/server/src/demo-fixtures/helpers/deterministic-uuid.js.map +0 -1
- package/src/demo-fixtures/__tests__/deterministic-uuid.test.ts +0 -75
- package/src/demo-fixtures/helpers/deterministic-uuid.ts +0 -68
- /package/dist/server/src/{demo-fixtures/__tests__/deterministic-uuid.test.d.ts → __tests__/factories/ids.test.d.ts} +0 -0
|
@@ -23,7 +23,7 @@ import {
|
|
|
23
23
|
createTaxCategory,
|
|
24
24
|
createFinancialAccount,
|
|
25
25
|
} from '../../factories';
|
|
26
|
-
import { makeUUID } from '
|
|
26
|
+
import { makeUUID } from '../../factories/ids';
|
|
27
27
|
import type { Fixture } from '../../helpers/fixture-types';
|
|
28
28
|
import { CountryCode } from '../../../modules/countries/types.js';
|
|
29
29
|
import { Currency } from '../../../shared/enums.js';
|
|
@@ -55,13 +55,13 @@ export const expenseScenarioA: Fixture = {
|
|
|
55
55
|
businesses: [
|
|
56
56
|
// Admin business (owner of the expense)
|
|
57
57
|
createBusiness({
|
|
58
|
-
id: makeUUID('
|
|
58
|
+
id: makeUUID('admin-business'),
|
|
59
59
|
hebrewName: 'חשבונאות ניהול',
|
|
60
60
|
country: CountryCode.Israel,
|
|
61
61
|
}),
|
|
62
62
|
// Supplier business
|
|
63
63
|
createBusiness({
|
|
64
|
-
id: makeUUID('
|
|
64
|
+
id: makeUUID('supplier-local-ltd'),
|
|
65
65
|
hebrewName: 'ספק מקומי בע"מ',
|
|
66
66
|
country: CountryCode.Israel,
|
|
67
67
|
exemptDealer: false,
|
|
@@ -73,11 +73,11 @@ export const expenseScenarioA: Fixture = {
|
|
|
73
73
|
taxCategories: {
|
|
74
74
|
taxCategories: [
|
|
75
75
|
createTaxCategory({
|
|
76
|
-
id: makeUUID('
|
|
76
|
+
id: makeUUID('expense-general'),
|
|
77
77
|
hashavshevetName: 'General Expenses',
|
|
78
78
|
}),
|
|
79
79
|
createTaxCategory({
|
|
80
|
-
id: makeUUID('
|
|
80
|
+
id: makeUUID('bank-account-tax-category'),
|
|
81
81
|
hashavshevetName: 'Bank Account',
|
|
82
82
|
}),
|
|
83
83
|
],
|
|
@@ -88,7 +88,7 @@ export const expenseScenarioA: Fixture = {
|
|
|
88
88
|
createFinancialAccount({
|
|
89
89
|
accountNumber: 'BANK-ACCOUNT-001',
|
|
90
90
|
type: 'BANK_ACCOUNT',
|
|
91
|
-
ownerId: makeUUID('
|
|
91
|
+
ownerId: makeUUID('admin-business'),
|
|
92
92
|
}),
|
|
93
93
|
],
|
|
94
94
|
},
|
|
@@ -98,7 +98,7 @@ export const expenseScenarioA: Fixture = {
|
|
|
98
98
|
{
|
|
99
99
|
accountNumber: 'BANK-ACCOUNT-001',
|
|
100
100
|
currency: Currency.Ils,
|
|
101
|
-
taxCategoryId: makeUUID('
|
|
101
|
+
taxCategoryId: makeUUID('bank-account-tax-category'),
|
|
102
102
|
},
|
|
103
103
|
],
|
|
104
104
|
},
|
|
@@ -107,12 +107,12 @@ export const expenseScenarioA: Fixture = {
|
|
|
107
107
|
charges: [
|
|
108
108
|
createCharge(
|
|
109
109
|
{
|
|
110
|
-
owner_id: makeUUID('
|
|
111
|
-
tax_category_id: makeUUID('
|
|
110
|
+
owner_id: makeUUID('admin-business'),
|
|
111
|
+
tax_category_id: makeUUID('expense-general'),
|
|
112
112
|
user_description: 'Office supplies purchase',
|
|
113
113
|
},
|
|
114
114
|
{
|
|
115
|
-
id: makeUUID('charge
|
|
115
|
+
id: makeUUID('charge-office-supplies'),
|
|
116
116
|
},
|
|
117
117
|
),
|
|
118
118
|
],
|
|
@@ -122,15 +122,15 @@ export const expenseScenarioA: Fixture = {
|
|
|
122
122
|
transactions: [
|
|
123
123
|
createTransaction(
|
|
124
124
|
{
|
|
125
|
-
charge_id: makeUUID('charge
|
|
126
|
-
business_id: makeUUID('
|
|
125
|
+
charge_id: makeUUID('charge-office-supplies'),
|
|
126
|
+
business_id: makeUUID('supplier-local-ltd'),
|
|
127
127
|
amount: '-500.00', // Negative = expense/outflow
|
|
128
128
|
currency: Currency.Ils,
|
|
129
129
|
event_date: '2024-01-15',
|
|
130
130
|
is_fee: false,
|
|
131
131
|
},
|
|
132
132
|
{
|
|
133
|
-
id: makeUUID('transaction
|
|
133
|
+
id: makeUUID('transaction-supplies-payment'),
|
|
134
134
|
account_id: 'BANK-ACCOUNT-001', // Will be resolved to UUID by loader
|
|
135
135
|
source_description: 'Office supplies - Local Supplier Ltd',
|
|
136
136
|
debit_date: '2024-01-15',
|
|
@@ -144,16 +144,16 @@ export const expenseScenarioA: Fixture = {
|
|
|
144
144
|
documents: [
|
|
145
145
|
createDocument(
|
|
146
146
|
{
|
|
147
|
-
charge_id: makeUUID('charge
|
|
148
|
-
creditor_id: makeUUID('
|
|
149
|
-
debtor_id: makeUUID('
|
|
147
|
+
charge_id: makeUUID('charge-office-supplies'),
|
|
148
|
+
creditor_id: makeUUID('supplier-local-ltd'), // Supplier is creditor
|
|
149
|
+
debtor_id: makeUUID('admin-business'), // Admin is debtor (owes money)
|
|
150
150
|
type: 'RECEIPT',
|
|
151
151
|
total_amount: 500.0, // Matches transaction amount (positive in document)
|
|
152
152
|
currency_code: Currency.Ils,
|
|
153
153
|
date: '2024-01-15', // Receipt date matches transaction
|
|
154
154
|
},
|
|
155
155
|
{
|
|
156
|
-
id: makeUUID('document
|
|
156
|
+
id: makeUUID('document-supplies-receipt'),
|
|
157
157
|
serial_number: 'RCP-2024-001',
|
|
158
158
|
vat_amount: null, // For simplicity, no VAT breakdown on receipt
|
|
159
159
|
},
|
|
@@ -164,10 +164,10 @@ export const expenseScenarioA: Fixture = {
|
|
|
164
164
|
expectations: {
|
|
165
165
|
ledger: [
|
|
166
166
|
{
|
|
167
|
-
chargeId: makeUUID('charge
|
|
167
|
+
chargeId: makeUUID('charge-office-supplies'),
|
|
168
168
|
recordCount: 2, // Debit expense + credit bank
|
|
169
|
-
debitEntities: [makeUUID('
|
|
170
|
-
creditEntities: [makeUUID('
|
|
169
|
+
debitEntities: [makeUUID('expense-general')],
|
|
170
|
+
creditEntities: [makeUUID('bank-account-tax-category')],
|
|
171
171
|
totalDebitLocal: 500.0,
|
|
172
172
|
totalCreditLocal: 500.0,
|
|
173
173
|
balanced: true,
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { describe, it, expect } from 'vitest';
|
|
2
2
|
import { expenseScenarioB } from './expense-scenario-b';
|
|
3
3
|
import { validateFixture } from '../../helpers/fixture-validation';
|
|
4
|
-
import { makeUUID } from '
|
|
4
|
+
import { makeUUID } from '../../factories/ids';
|
|
5
5
|
import { CountryCode } from '../../../modules/countries/types.js';
|
|
6
6
|
import { Currency } from '../../../shared/enums.js';
|
|
7
7
|
|
|
@@ -39,8 +39,8 @@ describe('Expense Scenario B - USD Invoice', () => {
|
|
|
39
39
|
|
|
40
40
|
it('should have correct business entities', () => {
|
|
41
41
|
const businesses = expenseScenarioB.businesses!.businesses;
|
|
42
|
-
const admin = businesses.find(b => b.id === makeUUID('
|
|
43
|
-
const supplier = businesses.find(b => b.id === makeUUID('
|
|
42
|
+
const admin = businesses.find(b => b.id === makeUUID('admin-business-usd'));
|
|
43
|
+
const supplier = businesses.find(b => b.id === makeUUID('supplier-us-vendor-llc'));
|
|
44
44
|
|
|
45
45
|
expect(admin).toBeDefined();
|
|
46
46
|
expect(admin?.country).toBe(CountryCode.Israel);
|
|
@@ -51,7 +51,7 @@ describe('Expense Scenario B - USD Invoice', () => {
|
|
|
51
51
|
});
|
|
52
52
|
|
|
53
53
|
it('should have referential integrity between charge, transaction, and document', () => {
|
|
54
|
-
const chargeId = makeUUID('charge
|
|
54
|
+
const chargeId = makeUUID('charge-consulting-services');
|
|
55
55
|
const charge = expenseScenarioB.charges!.charges[0];
|
|
56
56
|
const transaction = expenseScenarioB.transactions!.transactions[0];
|
|
57
57
|
const document = expenseScenarioB.documents!.documents[0];
|
|
@@ -94,7 +94,7 @@ describe('Expense Scenario B - USD Invoice', () => {
|
|
|
94
94
|
it('should have ledger expectations with exchange rate', () => {
|
|
95
95
|
const ledgerExpectation = expenseScenarioB.expectations!.ledger![0];
|
|
96
96
|
|
|
97
|
-
expect(ledgerExpectation.chargeId).toBe(makeUUID('charge
|
|
97
|
+
expect(ledgerExpectation.chargeId).toBe(makeUUID('charge-consulting-services'));
|
|
98
98
|
expect(ledgerExpectation.recordCount).toBe(2);
|
|
99
99
|
expect(ledgerExpectation.balanced).toBe(true);
|
|
100
100
|
expect(ledgerExpectation.foreignCurrency).toBe('USD');
|
|
@@ -116,14 +116,14 @@ describe('Expense Scenario B - USD Invoice', () => {
|
|
|
116
116
|
const debitEntity = ledgerExpectation.debitEntities![0];
|
|
117
117
|
const creditEntity = ledgerExpectation.creditEntities![0];
|
|
118
118
|
|
|
119
|
-
expect(debitEntity).toBe(makeUUID('
|
|
120
|
-
expect(creditEntity).toBe(makeUUID('
|
|
119
|
+
expect(debitEntity).toBe(makeUUID('expense-consulting'));
|
|
120
|
+
expect(creditEntity).toBe(makeUUID('usd-account-tax-category'));
|
|
121
121
|
});
|
|
122
122
|
|
|
123
123
|
it('should have USD account mapped to tax category', () => {
|
|
124
124
|
const accountMapping = expenseScenarioB.accountTaxCategories?.mappings[0];
|
|
125
125
|
expect(accountMapping?.accountNumber).toBe('USD-ACCOUNT-001');
|
|
126
126
|
expect(accountMapping?.currency).toBe(Currency.Usd);
|
|
127
|
-
expect(accountMapping?.taxCategoryId).toBe(makeUUID('
|
|
127
|
+
expect(accountMapping?.taxCategoryId).toBe(makeUUID('usd-account-tax-category'));
|
|
128
128
|
});
|
|
129
129
|
});
|
|
@@ -26,7 +26,7 @@ import {
|
|
|
26
26
|
createTaxCategory,
|
|
27
27
|
createFinancialAccount,
|
|
28
28
|
} from '../../factories';
|
|
29
|
-
import { makeUUID } from '
|
|
29
|
+
import { makeUUID } from '../../factories/ids';
|
|
30
30
|
import type { Fixture } from '../../helpers/fixture-types';
|
|
31
31
|
import { CountryCode } from '../../../modules/countries/types.js';
|
|
32
32
|
import { Currency } from '../../../shared/enums.js';
|
|
@@ -67,13 +67,13 @@ export const expenseScenarioB: Fixture = {
|
|
|
67
67
|
businesses: [
|
|
68
68
|
// Admin business (owner of the expense)
|
|
69
69
|
createBusiness({
|
|
70
|
-
id: makeUUID('
|
|
70
|
+
id: makeUUID('admin-business-usd'),
|
|
71
71
|
hebrewName: 'חשבונאות ניהול',
|
|
72
72
|
country: CountryCode.Israel,
|
|
73
73
|
}),
|
|
74
74
|
// US Supplier business
|
|
75
75
|
createBusiness({
|
|
76
|
-
id: makeUUID('
|
|
76
|
+
id: makeUUID('supplier-us-vendor-llc'),
|
|
77
77
|
hebrewName: 'ספק אמריקאי',
|
|
78
78
|
country: CountryCode['United States of America (the)'],
|
|
79
79
|
exemptDealer: false,
|
|
@@ -85,11 +85,11 @@ export const expenseScenarioB: Fixture = {
|
|
|
85
85
|
taxCategories: {
|
|
86
86
|
taxCategories: [
|
|
87
87
|
createTaxCategory({
|
|
88
|
-
id: makeUUID('
|
|
88
|
+
id: makeUUID('expense-consulting'),
|
|
89
89
|
hashavshevetName: 'Consulting Expenses',
|
|
90
90
|
}),
|
|
91
91
|
createTaxCategory({
|
|
92
|
-
id: makeUUID('
|
|
92
|
+
id: makeUUID('usd-account-tax-category'),
|
|
93
93
|
hashavshevetName: 'Foreign Currency Account',
|
|
94
94
|
}),
|
|
95
95
|
],
|
|
@@ -100,7 +100,7 @@ export const expenseScenarioB: Fixture = {
|
|
|
100
100
|
createFinancialAccount({
|
|
101
101
|
accountNumber: 'USD-ACCOUNT-001',
|
|
102
102
|
type: 'BANK_ACCOUNT',
|
|
103
|
-
ownerId: makeUUID('
|
|
103
|
+
ownerId: makeUUID('admin-business-usd'),
|
|
104
104
|
}),
|
|
105
105
|
],
|
|
106
106
|
},
|
|
@@ -110,7 +110,7 @@ export const expenseScenarioB: Fixture = {
|
|
|
110
110
|
{
|
|
111
111
|
accountNumber: 'USD-ACCOUNT-001',
|
|
112
112
|
currency: Currency.Usd,
|
|
113
|
-
taxCategoryId: makeUUID('
|
|
113
|
+
taxCategoryId: makeUUID('usd-account-tax-category'),
|
|
114
114
|
},
|
|
115
115
|
],
|
|
116
116
|
},
|
|
@@ -119,12 +119,12 @@ export const expenseScenarioB: Fixture = {
|
|
|
119
119
|
charges: [
|
|
120
120
|
createCharge(
|
|
121
121
|
{
|
|
122
|
-
owner_id: makeUUID('
|
|
123
|
-
tax_category_id: makeUUID('
|
|
122
|
+
owner_id: makeUUID('admin-business-usd'),
|
|
123
|
+
tax_category_id: makeUUID('expense-consulting'),
|
|
124
124
|
user_description: 'Consulting services from US vendor',
|
|
125
125
|
},
|
|
126
126
|
{
|
|
127
|
-
id: makeUUID('charge
|
|
127
|
+
id: makeUUID('charge-consulting-services'),
|
|
128
128
|
},
|
|
129
129
|
),
|
|
130
130
|
],
|
|
@@ -134,15 +134,15 @@ export const expenseScenarioB: Fixture = {
|
|
|
134
134
|
transactions: [
|
|
135
135
|
createTransaction(
|
|
136
136
|
{
|
|
137
|
-
charge_id: makeUUID('charge
|
|
138
|
-
business_id: makeUUID('
|
|
137
|
+
charge_id: makeUUID('charge-consulting-services'),
|
|
138
|
+
business_id: makeUUID('supplier-us-vendor-llc'),
|
|
139
139
|
amount: '-200.00', // Negative = expense/outflow in USD
|
|
140
140
|
currency: Currency.Usd,
|
|
141
141
|
event_date: '2024-01-20',
|
|
142
142
|
is_fee: false,
|
|
143
143
|
},
|
|
144
144
|
{
|
|
145
|
-
id: makeUUID('transaction
|
|
145
|
+
id: makeUUID('transaction-consulting-payment'),
|
|
146
146
|
account_id: 'USD-ACCOUNT-001', // Will be resolved to UUID by loader
|
|
147
147
|
source_description: 'Consulting services - US Vendor LLC',
|
|
148
148
|
debit_date: '2024-01-20',
|
|
@@ -156,16 +156,16 @@ export const expenseScenarioB: Fixture = {
|
|
|
156
156
|
documents: [
|
|
157
157
|
createDocument(
|
|
158
158
|
{
|
|
159
|
-
charge_id: makeUUID('charge
|
|
160
|
-
creditor_id: makeUUID('
|
|
161
|
-
debtor_id: makeUUID('
|
|
159
|
+
charge_id: makeUUID('charge-consulting-services'),
|
|
160
|
+
creditor_id: makeUUID('supplier-us-vendor-llc'), // Supplier is creditor
|
|
161
|
+
debtor_id: makeUUID('admin-business-usd'), // Admin is debtor
|
|
162
162
|
type: 'INVOICE',
|
|
163
163
|
total_amount: 200.0, // Amount in USD
|
|
164
164
|
currency_code: Currency.Usd,
|
|
165
165
|
date: '2024-01-20', // Invoice date matches transaction
|
|
166
166
|
},
|
|
167
167
|
{
|
|
168
|
-
id: makeUUID('document
|
|
168
|
+
id: makeUUID('document-consulting-invoice'),
|
|
169
169
|
serial_number: 'INV-US-2024-001',
|
|
170
170
|
vat_amount: null, // US invoice - no Israeli VAT
|
|
171
171
|
},
|
|
@@ -176,10 +176,10 @@ export const expenseScenarioB: Fixture = {
|
|
|
176
176
|
expectations: {
|
|
177
177
|
ledger: [
|
|
178
178
|
{
|
|
179
|
-
chargeId: makeUUID('charge
|
|
179
|
+
chargeId: makeUUID('charge-consulting-services'),
|
|
180
180
|
recordCount: 2, // Document + transaction entries
|
|
181
|
-
debitEntities: [makeUUID('
|
|
182
|
-
creditEntities: [makeUUID('
|
|
181
|
+
debitEntities: [makeUUID('expense-consulting'), makeUUID('usd-account-tax-category')],
|
|
182
|
+
creditEntities: [makeUUID('usd-account-tax-category'), makeUUID('supplier-us-vendor-llc')],
|
|
183
183
|
// Ledger processes document (700 ILS) + transaction (700 ILS) = 1400 ILS total
|
|
184
184
|
// With exchange rate of 3.5 ILS/USD: 200 USD × 3.5 = 700 ILS per entry
|
|
185
185
|
totalDebitLocal: 1400.0,
|
|
@@ -18,8 +18,8 @@ import {
|
|
|
18
18
|
createCharge,
|
|
19
19
|
createTransaction,
|
|
20
20
|
createDocument,
|
|
21
|
+
makeUUID,
|
|
21
22
|
} from '../factories/index.js';
|
|
22
|
-
import { makeUUID } from '../../demo-fixtures/helpers/deterministic-uuid.js';
|
|
23
23
|
|
|
24
24
|
describe('Fixture Loader', () => {
|
|
25
25
|
let pool: Pool;
|
|
@@ -35,9 +35,9 @@ describe('Fixture Loader', () => {
|
|
|
35
35
|
describe('insertFixture', () => {
|
|
36
36
|
it('should insert a complete minimal fixture successfully', () =>
|
|
37
37
|
withTestTransaction(pool, async client => {
|
|
38
|
-
const businessId = makeUUID('
|
|
39
|
-
const taxCategoryId = makeUUID('
|
|
40
|
-
const chargeId = makeUUID('
|
|
38
|
+
const businessId = makeUUID('test-business-1');
|
|
39
|
+
const taxCategoryId = makeUUID('test-tax-cat-1');
|
|
40
|
+
const chargeId = makeUUID('test-charge-1');
|
|
41
41
|
|
|
42
42
|
const fixture: Fixture = {
|
|
43
43
|
businesses: {
|
|
@@ -83,7 +83,6 @@ describe('Fixture Loader', () => {
|
|
|
83
83
|
[businessId],
|
|
84
84
|
);
|
|
85
85
|
expect(businessResult.rows).toHaveLength(1);
|
|
86
|
-
expect(businessResult.rows[0].id).toBe(businessId);
|
|
87
86
|
expect(businessResult.rows[0].hebrew_name).toBe('Test Business');
|
|
88
87
|
|
|
89
88
|
const taxCatResult = await client.query(
|
|
@@ -91,7 +90,6 @@ describe('Fixture Loader', () => {
|
|
|
91
90
|
[taxCategoryId],
|
|
92
91
|
);
|
|
93
92
|
expect(taxCatResult.rows).toHaveLength(1);
|
|
94
|
-
expect(taxCatResult.rows[0].id).toBe(taxCategoryId);
|
|
95
93
|
expect(taxCatResult.rows[0].hashavshevet_name).toBe('Test Tax Category');
|
|
96
94
|
|
|
97
95
|
const chargeResult = await client.query(
|
|
@@ -104,13 +102,13 @@ describe('Fixture Loader', () => {
|
|
|
104
102
|
|
|
105
103
|
it('should insert fixture with transactions and documents', () =>
|
|
106
104
|
withTestTransaction(pool, async client => {
|
|
107
|
-
const supplierId = makeUUID('
|
|
108
|
-
const customerId = makeUUID('
|
|
109
|
-
const taxCategoryId = makeUUID('tax-
|
|
105
|
+
const supplierId = makeUUID('supplier-1');
|
|
106
|
+
const customerId = makeUUID('customer-1');
|
|
107
|
+
const taxCategoryId = makeUUID('tax-cat-1');
|
|
110
108
|
const accountNumber = 'ACC-12345';
|
|
111
|
-
const chargeId = makeUUID('charge
|
|
112
|
-
const transactionId = makeUUID('
|
|
113
|
-
const documentId = makeUUID('
|
|
109
|
+
const chargeId = makeUUID('charge-1');
|
|
110
|
+
const transactionId = makeUUID('tx-1');
|
|
111
|
+
const documentId = makeUUID('doc-1');
|
|
114
112
|
|
|
115
113
|
const fixture: Fixture = {
|
|
116
114
|
businesses: {
|
|
@@ -218,7 +216,7 @@ describe('Fixture Loader', () => {
|
|
|
218
216
|
|
|
219
217
|
it('should handle fixture with only some sections populated', () =>
|
|
220
218
|
withTestTransaction(pool, async client => {
|
|
221
|
-
const businessId = makeUUID('
|
|
219
|
+
const businessId = makeUUID('lonely-business');
|
|
222
220
|
|
|
223
221
|
const fixture: Fixture = {
|
|
224
222
|
businesses: {
|
|
@@ -240,8 +238,8 @@ describe('Fixture Loader', () => {
|
|
|
240
238
|
|
|
241
239
|
it('should throw validation error before insertion for invalid FK references', () =>
|
|
242
240
|
withTestTransaction(pool, async client => {
|
|
243
|
-
const businessId = makeUUID('
|
|
244
|
-
const invalidChargeId = makeUUID('
|
|
241
|
+
const businessId = makeUUID('test-biz');
|
|
242
|
+
const invalidChargeId = makeUUID('invalid-charge');
|
|
245
243
|
|
|
246
244
|
const fixture: Fixture = {
|
|
247
245
|
businesses: {
|
|
@@ -252,7 +250,7 @@ describe('Fixture Loader', () => {
|
|
|
252
250
|
createCharge(
|
|
253
251
|
{
|
|
254
252
|
owner_id: 'non-existent-owner', // Invalid FK reference
|
|
255
|
-
tax_category_id: makeUUID('tax-
|
|
253
|
+
tax_category_id: makeUUID('tax-cat'),
|
|
256
254
|
},
|
|
257
255
|
{ id: invalidChargeId },
|
|
258
256
|
),
|
|
@@ -271,7 +269,7 @@ describe('Fixture Loader', () => {
|
|
|
271
269
|
charges: [
|
|
272
270
|
createCharge({
|
|
273
271
|
owner_id: 'non-existent-owner',
|
|
274
|
-
tax_category_id: makeUUID('tax-
|
|
272
|
+
tax_category_id: makeUUID('tax-cat'),
|
|
275
273
|
}),
|
|
276
274
|
],
|
|
277
275
|
},
|
|
@@ -290,7 +288,7 @@ describe('Fixture Loader', () => {
|
|
|
290
288
|
|
|
291
289
|
it('should validate fixture before insertion', () =>
|
|
292
290
|
withTestTransaction(pool, async client => {
|
|
293
|
-
const chargeId = makeUUID('
|
|
291
|
+
const chargeId = makeUUID('orphan-charge');
|
|
294
292
|
|
|
295
293
|
const fixture: Fixture = {
|
|
296
294
|
// Missing businesses and tax categories
|
|
@@ -298,8 +296,8 @@ describe('Fixture Loader', () => {
|
|
|
298
296
|
charges: [
|
|
299
297
|
createCharge(
|
|
300
298
|
{
|
|
301
|
-
owner_id: makeUUID('
|
|
302
|
-
tax_category_id: makeUUID('
|
|
299
|
+
owner_id: makeUUID('missing-owner'),
|
|
300
|
+
tax_category_id: makeUUID('missing-tax'),
|
|
303
301
|
},
|
|
304
302
|
{ id: chargeId },
|
|
305
303
|
),
|
|
@@ -312,12 +310,12 @@ describe('Fixture Loader', () => {
|
|
|
312
310
|
|
|
313
311
|
it('should insert multiple entities in correct order', () =>
|
|
314
312
|
withTestTransaction(pool, async client => {
|
|
315
|
-
const biz1 = makeUUID('
|
|
316
|
-
const biz2 = makeUUID('
|
|
317
|
-
const tax1 = makeUUID('tax-
|
|
318
|
-
const tax2 = makeUUID('tax-
|
|
319
|
-
const charge1 = makeUUID('charge
|
|
320
|
-
const charge2 = makeUUID('charge
|
|
313
|
+
const biz1 = makeUUID('biz-1');
|
|
314
|
+
const biz2 = makeUUID('biz-2');
|
|
315
|
+
const tax1 = makeUUID('tax-1');
|
|
316
|
+
const tax2 = makeUUID('tax-2');
|
|
317
|
+
const charge1 = makeUUID('charge-1');
|
|
318
|
+
const charge2 = makeUUID('charge-2');
|
|
321
319
|
|
|
322
320
|
const fixture: Fixture = {
|
|
323
321
|
businesses: {
|
|
@@ -362,7 +360,7 @@ describe('Fixture Loader', () => {
|
|
|
362
360
|
|
|
363
361
|
it('should handle ON CONFLICT for idempotent insertion', () =>
|
|
364
362
|
withTestTransaction(pool, async client => {
|
|
365
|
-
const businessId = makeUUID('
|
|
363
|
+
const businessId = makeUUID('duplicate-biz');
|
|
366
364
|
|
|
367
365
|
const fixture: Fixture = {
|
|
368
366
|
businesses: {
|
|
@@ -394,11 +392,11 @@ describe('Fixture Loader', () => {
|
|
|
394
392
|
|
|
395
393
|
it('should insert transactions with generated source_id', () =>
|
|
396
394
|
withTestTransaction(pool, async client => {
|
|
397
|
-
const businessId = makeUUID('
|
|
398
|
-
const taxCatId = makeUUID('tax-
|
|
399
|
-
const chargeId = makeUUID('charge
|
|
395
|
+
const businessId = makeUUID('biz-tx');
|
|
396
|
+
const taxCatId = makeUUID('tax-tx');
|
|
397
|
+
const chargeId = makeUUID('charge-tx');
|
|
400
398
|
const accountNumber = 'ACC-TX-001';
|
|
401
|
-
const transactionId = makeUUID('
|
|
399
|
+
const transactionId = makeUUID('tx-with-source');
|
|
402
400
|
|
|
403
401
|
const fixture: Fixture = {
|
|
404
402
|
businesses: {
|
|
@@ -12,7 +12,7 @@ import type { PoolClient } from 'pg';
|
|
|
12
12
|
import type { Fixture } from './fixture-types.js';
|
|
13
13
|
import { assertValidFixture } from './fixture-validation.js';
|
|
14
14
|
import { qualifyTable } from './test-db-config.js';
|
|
15
|
-
import { makeUUID
|
|
15
|
+
import { makeUUID } from '../factories/ids.js';
|
|
16
16
|
|
|
17
17
|
/**
|
|
18
18
|
* Custom error for fixture insertion failures
|
|
@@ -334,7 +334,7 @@ export async function insertFixture(
|
|
|
334
334
|
// Insert directly into transactions_raw_list with etherscan_id to satisfy check constraint
|
|
335
335
|
// This avoids triggering any creditcard/bank transaction handlers which would auto-create charges
|
|
336
336
|
// etherscan_id is used because it has no INSERT trigger and is a simple UUID reference
|
|
337
|
-
const dummyEtherscanId = transaction.id ? makeUUID(
|
|
337
|
+
const dummyEtherscanId = transaction.id ? makeUUID(`etherscan-${transaction.id}`) : makeUUID();
|
|
338
338
|
const rawListResult = await client.query(
|
|
339
339
|
`INSERT INTO ${qualifyTable('transactions_raw_list')} (etherscan_id)
|
|
340
340
|
VALUES ($1)
|