File tree Expand file tree Collapse file tree 6 files changed +55
-27
lines changed
workflows/weeklyFinancialReports Expand file tree Collapse file tree 6 files changed +55
-27
lines changed Original file line number Diff line number Diff line change @@ -4,13 +4,23 @@ import * as utils from '../../../common/utils';
44import { weeklyFinancialReportsWorkflow } from '../workflows' ;
55
66describe ( 'weeklyFinancialReportsWorkflow' , ( ) => {
7- it ( 'should return the report string' , async ( ) => {
7+ it ( 'should return the report string with default parameters ' , async ( ) => {
88 const result = await weeklyFinancialReportsWorkflow ( ) ;
99
1010 expect ( typeof result ) . toBe ( 'string' ) ;
1111 expect ( result . length ) . toBeGreaterThan ( 0 ) ;
1212 } ) ;
1313
14+ it ( 'should return the report string for a custom period and config' , async ( ) => {
15+ const result = await weeklyFinancialReportsWorkflow ( {
16+ period : 'Q1 2025' ,
17+ config : { reportTitle : 'Custom Report Title' } ,
18+ } ) ;
19+
20+ expect ( result . startsWith ( 'Custom Report Title' ) ) . toBe ( true ) ;
21+ expect ( result ) . toContain ( 'Period: Q1 2025' ) ;
22+ } ) ;
23+
1424 it ( 'should log and rethrow errors' , async ( ) => {
1525 const logSpy = vi
1626 . spyOn ( utils , 'logWorkflowError' )
Original file line number Diff line number Diff line change 1+ export interface FinancialData {
2+ period : string ;
3+ contractType : string ;
4+ revenue : number ;
5+ cogs : number ;
6+ margin : number ;
7+ marginality : number ;
8+ effectiveRevenue : number ;
9+ effectiveMargin : number ;
10+ effectiveMarginality : number ;
11+ }
12+
13+ /**
14+ * Fetches financial data for a given period from an external source or database.
15+ * @param period - The period to fetch data for (e.g., 'Q1 2025', 'current')
16+ */
17+ export async function fetchFinancialData (
18+ period : string = 'current' ,
19+ ) : Promise < FinancialData > {
20+ // TODO: Replace this stub with actual data fetching logic (e.g., DB query, API call)
21+ return {
22+ period : period ,
23+ contractType : 'T&M' ,
24+ revenue : 120000 ,
25+ cogs : 80000 ,
26+ margin : 40000 ,
27+ marginality : 33.3 ,
28+ effectiveRevenue : 110000 ,
29+ effectiveMargin : 35000 ,
30+ effectiveMarginality : 31.8 ,
31+ } ;
32+ }
Original file line number Diff line number Diff line change 1- import { z } from 'zod' ;
2-
31import { temporalSchema } from './temporal' ;
42import { workerSchema } from './worker' ;
53
6- export const validationResult = z
7- . object ( {
8- ...temporalSchema . shape ,
9- ...workerSchema . shape ,
10- } )
4+ export const validationResult = temporalSchema
5+ . merge ( workerSchema )
116 . safeParse ( process . env ) ;
Original file line number Diff line number Diff line change @@ -4,9 +4,10 @@ import { z } from 'zod';
44
55export const workerConfig : WorkerOptions = {
66 taskQueue : 'main-queue' ,
7- workflowsPath : path . join ( __dirname , '../workflows' ) ,
7+ workflowsPath :
8+ process . env . WORKFLOWS_PATH || path . join ( __dirname , '../workflows' ) ,
89} ;
910
1011export const workerSchema = z . object ( {
11- TEMPORAL_ADDRESS : z . string ( ) . default ( 'temporal:7233' ) ,
12+ WORKFLOWS_PATH : z . string ( ) . optional ( ) ,
1213} ) ;
Original file line number Diff line number Diff line change @@ -29,7 +29,7 @@ export async function run(): Promise<void> {
2929
3030 await worker . run ( ) ;
3131 } catch ( err ) {
32- handleRunError ( err as Error ) ;
32+ handleRunError ( err ) ;
3333 } finally {
3434 if ( connection ) {
3535 await connection . close ( ) ;
Original file line number Diff line number Diff line change 11import { logWorkflowError } from '../../../../common/utils' ;
2+ import { fetchFinancialData } from '../../activities/fetchFinancialData' ;
23
3- export async function weeklyFinancialReportsWorkflow ( ) : Promise < string > {
4+ export async function weeklyFinancialReportsWorkflow ( {
5+ period = 'current' ,
6+ } : { period ?: string } = { } ) : Promise < string > {
47 try {
5- const data = {
6- period : 'Q1 2025' ,
7- contractType : 'T&M' ,
8- revenue : 120000 ,
9- cogs : 80000 ,
10- margin : 40000 ,
11- marginality : 33.3 ,
12- effectiveRevenue : 110000 ,
13- effectiveMargin : 35000 ,
14- effectiveMarginality : 31.8 ,
15- } ;
16-
178 const reportTitle = 'Weekly Financial Report' ;
9+ const data = await fetchFinancialData ( period ) ;
1810 const report = `Period: ${ data . period }
1911Contract Type: ${ data . contractType }
2012Revenue: $${ data . revenue . toLocaleString ( ) }
2113COGS: $${ data . cogs . toLocaleString ( ) }
2214Margin: $${ data . margin . toLocaleString ( ) }
23- Marginality: ${ data . marginality } %
24-
25- Effective Revenue (last 4 months): $${ data . effectiveRevenue . toLocaleString ( ) }
15+ Marginality: ${ data . marginality } %\n\nEffective Revenue (last 4 months): $${ data . effectiveRevenue . toLocaleString ( ) }
2616Effective Margin: $${ data . effectiveMargin . toLocaleString ( ) }
2717Effective Marginality: ${ data . effectiveMarginality } %` ;
2818
You can’t perform that action at this time.
0 commit comments