Skip to content

Commit b1daa10

Browse files
Refactor Tests and Improve Effective Revenue Calculation in Weekly Financial Reports
- Reformatted import statements in `fetchFinancialAppData.test.ts` for better readability. - Adjusted error handling in `fetchFinancialAppData` to ensure proper disconnection of the mongo pool. - Enhanced test data in `WeeklyFinancialReportRepository.test.ts` to include effective revenue calculations for projects, improving the accuracy of marginality assessments. These changes enhance the clarity and reliability of financial report tests, ensuring more accurate calculations and better organization of test data.
1 parent 24c143d commit b1daa10

File tree

3 files changed

+26
-6
lines changed

3 files changed

+26
-6
lines changed

workers/main/src/activities/weeklyFinancialReports/fetchFinancialAppData.test.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,11 @@ import { AppError } from '../../common/errors';
55
import * as fileUtils from '../../common/fileUtils';
66
import * as mongoPoolModule from '../../common/MongoPool';
77
import type { TargetUnit } from '../../common/types';
8-
import type { Employee, IFinAppRepository, Project } from '../../services/FinApp';
8+
import type {
9+
Employee,
10+
IFinAppRepository,
11+
Project,
12+
} from '../../services/FinApp';
913
import * as finAppService from '../../services/FinApp';
1014
import type { CustomerRevenueByRef } from '../../services/QBO';
1115
import * as qboService from '../../services/QBO';
@@ -174,7 +178,7 @@ describe('getFinAppData', () => {
174178

175179
it('always disconnects the mongo pool', async () => {
176180
setupSuccessMocks();
177-
await fetchFinancialAppData(fileLink).catch(() => { });
181+
await fetchFinancialAppData(fileLink).catch(() => {});
178182
expect(() => mongoPoolInstance.disconnect()).not.toThrow();
179183
});
180184
});

workers/main/src/activities/weeklyFinancialReports/fetchFinancialAppData.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ export const fetchFinancialAppData = async (
4141
...project,
4242
effectiveRevenue: project.quick_books_id
4343
? effectiveRevenueByCustomerRef[project.quick_books_id]
44-
?.totalAmount || 0
44+
?.totalAmount || 0
4545
: 0,
4646
})),
4747
effectiveRevenue: effectiveRevenueByCustomerRef,

workers/main/src/services/WeeklyFinancialReport/WeeklyFinancialReportRepository.test.ts

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -109,9 +109,25 @@ const createMarginalityTestData = () => ({
109109
{ redmine_id: 102, history: { rate: { '2024-01-01': 50 } } },
110110
],
111111
projects: [
112-
{ redmine_id: 10, history: { rate: { '2024-01-01': 100 } } }, // 50% marginality
113-
{ redmine_id: 20, history: { rate: { '2024-01-01': 200 } } }, // 75% marginality
114-
{ redmine_id: 30, history: { rate: { '2024-01-01': 150 } } }, // 67% marginality
112+
// 10h @ $50 COGS -> $500 cost. Set effectiveRevenue to achieve target marginality:
113+
// 50%: (R - 500) / R = 0.5 => R = 1000
114+
{
115+
redmine_id: 10,
116+
history: { rate: { '2024-01-01': 100 } },
117+
effectiveRevenue: 1000,
118+
},
119+
// 75%: (R - 500) / R = 0.75 => R = 2000
120+
{
121+
redmine_id: 20,
122+
history: { rate: { '2024-01-01': 200 } },
123+
effectiveRevenue: 2000,
124+
},
125+
// ~67%: (1500 - 500) / 1500 ≈ 0.667
126+
{
127+
redmine_id: 30,
128+
history: { rate: { '2024-01-01': 150 } },
129+
effectiveRevenue: 1500,
130+
},
115131
],
116132
});
117133

0 commit comments

Comments
 (0)