forked from beyondessential/tupaia
-
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.
RN-645: Add internal data tables for fetching entities and entity rel…
…ations (beyondessential#4212)
- Loading branch information
Showing
27 changed files
with
792 additions
and
200 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -35,5 +35,8 @@ | |
"dotenv": "^8.2.0", | ||
"express": "^4.16.2", | ||
"winston": "^3.2.1" | ||
}, | ||
"devDependencies": { | ||
"mockdate": "^3.0.5" | ||
} | ||
} |
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
54 changes: 54 additions & 0 deletions
54
...ata-table-server/src/__tests__/dataTableService/internal/EntitiesDataTableService.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,54 @@ | ||
/** | ||
* Tupaia | ||
* Copyright (c) 2017 - 2022 Beyond Essential Systems Pty Ltd | ||
*/ | ||
|
||
import { TupaiaApiClient } from '@tupaia/api-client'; | ||
import { DataTableServiceBuilder } from '../../../dataTableService'; | ||
|
||
const entitiesDataTableService = new DataTableServiceBuilder() | ||
.setServiceType('entities') | ||
.setContext({ apiClient: {} as TupaiaApiClient }) | ||
.build(); | ||
|
||
describe('EntitiesDataTableService', () => { | ||
describe('parameter validation', () => { | ||
const testData: [string, unknown, string][] = [ | ||
['missing entityCodes', {}, 'entityCodes is a required field'], | ||
]; | ||
|
||
it.each(testData)('%s', (_, parameters: unknown, expectedError: string) => { | ||
expect(() => entitiesDataTableService.fetchData(parameters)).toThrow(expectedError); | ||
}); | ||
}); | ||
|
||
it('getParameters', () => { | ||
const parameters = entitiesDataTableService.getParameters(); | ||
expect(parameters).toEqual([ | ||
{ config: { defaultValue: 'explore', type: 'string' }, name: 'hierarchy' }, | ||
{ | ||
config: { innerType: { required: true, type: 'string' }, required: true, type: 'array' }, | ||
name: 'entityCodes', | ||
}, | ||
{ | ||
config: { type: 'object' }, | ||
name: 'filter', | ||
}, | ||
{ | ||
config: { | ||
defaultValue: ['code'], | ||
type: 'array', | ||
innerType: { type: 'string', required: true }, | ||
}, | ||
name: 'fields', | ||
}, | ||
{ config: { defaultValue: false, type: 'boolean' }, name: 'includeDescendants' }, | ||
]); | ||
}); | ||
|
||
describe('fetchData', () => { | ||
// TODO: Implement these tests when RN-685 is done | ||
// it('can fetch entities', async () => {}); | ||
// it('can fetch entities and descendants', async () => {}); | ||
}); | ||
}); |
57 changes: 57 additions & 0 deletions
57
...le-server/src/__tests__/dataTableService/internal/EntityRelationsDataTableService.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,57 @@ | ||
/** | ||
* Tupaia | ||
* Copyright (c) 2017 - 2022 Beyond Essential Systems Pty Ltd | ||
*/ | ||
|
||
import { TupaiaApiClient } from '@tupaia/api-client'; | ||
import { DataTableServiceBuilder } from '../../../dataTableService'; | ||
|
||
const entityRelationsDataTableService = new DataTableServiceBuilder() | ||
.setServiceType('entity_relations') | ||
.setContext({ apiClient: {} as TupaiaApiClient }) | ||
.build(); | ||
|
||
describe('EntityRelationsDataTableService', () => { | ||
describe('parameter validation', () => { | ||
const testData: [string, unknown, string][] = [ | ||
[ | ||
'missing entityCodes', | ||
{ ancestorType: 'district', descendantType: 'sub_district' }, | ||
'entityCodes is a required field', | ||
], | ||
[ | ||
'missing ancestorType', | ||
{ entityCodes: ['TO'], descendantType: 'sub_district' }, | ||
'ancestorType is a required field', | ||
], | ||
[ | ||
'missing descendantType', | ||
{ entityCodes: ['TO'], ancestorType: 'district' }, | ||
'descendantType is a required field', | ||
], | ||
]; | ||
|
||
it.each(testData)('%s', (_, parameters: unknown, expectedError: string) => { | ||
expect(() => entityRelationsDataTableService.fetchData(parameters)).toThrow(expectedError); | ||
}); | ||
}); | ||
|
||
it('getParameters', () => { | ||
const parameters = entityRelationsDataTableService.getParameters(); | ||
expect(parameters).toEqual([ | ||
{ config: { defaultValue: 'explore', type: 'string' }, name: 'hierarchy' }, | ||
{ | ||
config: { innerType: { required: true, type: 'string' }, required: true, type: 'array' }, | ||
name: 'entityCodes', | ||
}, | ||
{ config: { type: 'string', required: true }, name: 'ancestorType' }, | ||
{ config: { type: 'string', required: true }, name: 'descendantType' }, | ||
]); | ||
}); | ||
|
||
describe('fetchData', () => { | ||
// TODO: Implement these tests when RN-685 is done | ||
// it('can fetch entities', async () => {}); | ||
// it('can fetch entities and descendants', async () => {}); | ||
}); | ||
}); |
Oops, something went wrong.