-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
148 additions
and
80 deletions.
There are no files selected for viewing
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
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
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
16 changes: 11 additions & 5 deletions
16
src/domain-services/flows/strategy/flow-search-strategy.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 |
---|---|---|
@@ -1,6 +1,12 @@ | ||
import { Database } from "@unocha/hpc-api-core/src/db"; | ||
import { FlowSearchResult } from "../graphql/types"; | ||
import { Database } from '@unocha/hpc-api-core/src/db'; | ||
import { FlowSearchResult } from '../graphql/types'; | ||
|
||
export interface FlowSearchStrategy{ | ||
search(flowConditions: Map<string, any>, orderBy: any, limit: number, cursorCondition: any, models: Database): Promise<FlowSearchResult>; | ||
} | ||
export interface FlowSearchStrategy { | ||
search( | ||
flowConditions: Map<string, any>, | ||
orderBy: any, | ||
limit: number, | ||
cursorCondition: any, | ||
models: Database | ||
): Promise<FlowSearchResult>; | ||
} |
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
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,73 @@ | ||
import Container from 'typedi'; | ||
import { FlowSearchService } from '../../src/domain-services/flows/flow-search-service'; | ||
import { SearchFlowsFilters } from '../../src/domain-services/flows/graphql/args'; | ||
|
||
describe('PrepareFlowConditions', () => { | ||
let flowSearchService: FlowSearchService; | ||
|
||
beforeEach(() => { | ||
// Initialize your class instance if needed | ||
flowSearchService = Container.get(FlowSearchService); | ||
}); | ||
|
||
it('should prepare flow conditions with valid filters', () => { | ||
const flowFilters = new SearchFlowsFilters(); | ||
flowFilters.id = 1; | ||
flowFilters.activeStatus = true; | ||
flowFilters.status = 'commitment'; | ||
flowFilters.type = 'carryover'; | ||
flowFilters.amountUSD = 1000; | ||
flowFilters.reporterReferenceCode = 123; | ||
flowFilters.sourceSystemId = 456; | ||
flowFilters.legacyId = 789; | ||
|
||
const result = flowSearchService.prepareFlowConditions(flowFilters); | ||
|
||
expect(result).toEqual({ | ||
id: 1, | ||
activeStatus: true, | ||
status: 'commitment', | ||
type: 'carryover', | ||
amountUSD: 1000, | ||
reporterReferenceCode: 123, | ||
sourceSystemId: 456, | ||
legacyId: 789, | ||
}); | ||
}); | ||
|
||
it('should prepare flow conditions with some filters set to undefined', () => { | ||
const flowFilters = new SearchFlowsFilters(); | ||
flowFilters.id = 1; | ||
flowFilters.activeStatus = true; | ||
|
||
const result = flowSearchService.prepareFlowConditions(flowFilters); | ||
|
||
expect(result).toEqual({ | ||
id: 1, | ||
activeStatus: true, | ||
}); | ||
}); | ||
|
||
it('should prepare flow conditions with all filters set to undefined', () => { | ||
const flowFilters = new SearchFlowsFilters(); | ||
|
||
const result = flowSearchService.prepareFlowConditions(flowFilters); | ||
|
||
expect(result).toEqual({}); | ||
}); | ||
|
||
it('should prepare flow conditions with some filters having falsy values', () => { | ||
const flowFilters = new SearchFlowsFilters(); | ||
flowFilters.id = 0; | ||
flowFilters.activeStatus = false; | ||
flowFilters.amountUSD = 0; | ||
|
||
const result = flowSearchService.prepareFlowConditions(flowFilters); | ||
|
||
expect(result).toEqual({ | ||
id: 0, | ||
activeStatus: false, | ||
amountUSD: 0, | ||
}); | ||
}); | ||
}); |