-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: support searching with date ranges (#51)
- Loading branch information
Showing
12 changed files
with
292 additions
and
93 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
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 was deleted.
Oops, something went wrong.
87 changes: 87 additions & 0 deletions
87
packages/dci-opencrvs-bridge/src/dci-to-opencrvs/dci-to-opencrvs.test.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 |
---|---|---|
@@ -0,0 +1,87 @@ | ||
import { describe, it } from 'node:test' | ||
import { searchRequestToAdvancedSearchParameters } from './dci-to-opencrvs' | ||
import assert from 'node:assert' | ||
|
||
describe('DCI standard to OpenCRVS', () => { | ||
// `gt` => date + 1 day | ||
// `ge` => date | ||
// `lt` => date - 1 day | ||
// `le` => date | ||
it('converts gt and lt properly', () => { | ||
const parameters = searchRequestToAdvancedSearchParameters({ | ||
reference_id: '123456789020211216223812', | ||
timestamp: '2022-12-04T17:20:07-04:00', | ||
search_criteria: { | ||
reg_event_type: { namespace: '?', value: 'birth' }, | ||
result_record_type: { value: 'person' }, | ||
sort: [{ attribute_name: 'dateOfDeclaration', sort_order: 'asc' }], | ||
pagination: { page_size: 5, page_number: 1 }, | ||
query_type: 'predicate', | ||
query: [ | ||
{ | ||
expression1: { | ||
attribute_name: 'birthdate', | ||
operator: 'gt', | ||
attribute_value: new Date('2010-05-04T00:00:00.000Z') | ||
}, | ||
condition: 'and', | ||
expression2: { | ||
attribute_name: 'birthdate', | ||
operator: 'lt', | ||
attribute_value: new Date('2022-05-04T00:00:00.000Z') | ||
} | ||
} | ||
] | ||
}, | ||
locale: 'eng' | ||
}) | ||
|
||
assert.strictEqual( | ||
parameters.advancedSearchParameters.childDoBStart, | ||
'2010-05-05' | ||
) | ||
assert.strictEqual( | ||
parameters.advancedSearchParameters.childDoBEnd, | ||
'2022-05-03' | ||
) | ||
}) | ||
|
||
it('converts ge and le properly', () => { | ||
const parameters = searchRequestToAdvancedSearchParameters({ | ||
reference_id: '123456789020211216223812', | ||
timestamp: '2022-12-04T17:20:07-04:00', | ||
search_criteria: { | ||
reg_event_type: { namespace: '?', value: 'birth' }, | ||
result_record_type: { value: 'person' }, | ||
sort: [{ attribute_name: 'dateOfDeclaration', sort_order: 'asc' }], | ||
pagination: { page_size: 5, page_number: 1 }, | ||
query_type: 'predicate', | ||
query: [ | ||
{ | ||
expression1: { | ||
attribute_name: 'birthdate', | ||
operator: 'ge', | ||
attribute_value: new Date('2010-05-04') | ||
}, | ||
condition: 'and', | ||
expression2: { | ||
attribute_name: 'birthdate', | ||
operator: 'le', | ||
attribute_value: new Date('2022-05-04') | ||
} | ||
} | ||
] | ||
}, | ||
locale: 'eng' | ||
}) | ||
|
||
assert.strictEqual( | ||
parameters.advancedSearchParameters.childDoBStart, | ||
'2010-05-04' | ||
) | ||
assert.strictEqual( | ||
parameters.advancedSearchParameters.childDoBEnd, | ||
'2022-05-04' | ||
) | ||
}) | ||
}) |
Oops, something went wrong.