Skip to content

Commit

Permalink
Update tests
Browse files Browse the repository at this point in the history
Ref: #7
  • Loading branch information
projkov committed Sep 11, 2024
1 parent 46f7aae commit beca2f4
Show file tree
Hide file tree
Showing 9 changed files with 27 additions and 35 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ pull:
$(compose) $(dev_env) $(dev_profile) pull

build:
$(compose) $(dev_env) $(dev_profile) build --no-cache
$(compose) $(dev_env) $(dev_profile) build

up:
$(compose) $(dev_env) $(dev_profile) up
Expand Down
2 changes: 1 addition & 1 deletion packages/app/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@
"ts-loader": "^9.4.3",
"ts-node": "^10.9.1",
"tsconfig-paths": "^4.2.0",
"typescript": "^5.1.3"
"typescript": "^5.6.2"
},
"jest": {
"moduleFileExtensions": [
Expand Down
3 changes: 3 additions & 0 deletions packages/app/src/utils/setup/jest.setup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,7 @@ module.exports = async () => {
const requestsRepository = TestDataSource.getRepository(Request);
global.RequestsRepository = requestsRepository;
global.TestDataSource = TestDataSource;
global.requests = await requestsRepository.find({
relations: ['session'],
});
};
2 changes: 1 addition & 1 deletion packages/app/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
{
"compilerOptions": {
"module": "commonjs",
"target": "ESNext",
"declaration": true,
"removeComments": true,
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"allowSyntheticDefaultImports": true,
"target": "ES2021",
"sourceMap": true,
"outDir": "./dist",
"baseUrl": "./",
Expand Down
6 changes: 2 additions & 4 deletions packages/client-testing-demo-tests-db/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,7 @@ export function patientDemoTestDB() {
// AND jsonb_array_length(filters) = 1
// AND filters->0->>'code' NOT IN ('_id', 'family')

const requests = await global.RequestsRepository
.createQueryBuilder('request')
const requests = await global.RequestsRepository.createQueryBuilder('request')
.where('request.sessionId = :sessionId', { sessionId: global.SESSION_ID })
.andWhere('request.resourceType = :resourceType', { resourceType: 'Patient' })
.andWhere('request.fhirAction = :action', { action: 'SEARCH' })
Expand All @@ -45,8 +44,7 @@ export function patientDemoTestDB() {
// AND fhirAction = 'SEARCH'
// AND jsonb_array_length(filters) > 1
// AND NOT filters_codes <@ array[array['birthdate','family'], array['birthdate','name']]
const requests = await global.RequestsRepository
.createQueryBuilder('request')
const requests = await global.RequestsRepository.createQueryBuilder('request')
.where('request.sessionId = :sessionId', { sessionId: global.SESSION_ID })
.andWhere('request.resourceType = :resourceType', { resourceType: 'Patient' })
.andWhere('request.fhirAction = :action', { action: 'SEARCH' })
Expand Down
35 changes: 13 additions & 22 deletions packages/client-testing-demo-tests-standard/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,26 +2,11 @@ import { Patient } from 'fhir/r4';
import { Request } from '@beda.software/app/src/modules/requests/request.entity';
import { isResourceValid } from '@beda.software/fhir-validator';

function checkAvailableParams(availableParams: string[], combo: boolean, requests: Request[]): boolean {
const filterCombo = (param: string) => (combo ? param.includes('+') : !param.includes('+'));
const usedComboSearchParams = requests
.flatMap((request) => request.filters.map((filter) => filter.code))
.filter((param) => filterCombo(param));

const uniqueUsedComboSearchParams = [...new Set(usedComboSearchParams)];

return uniqueUsedComboSearchParams.every((searchParam) => availableParams.includes(searchParam));
}

export function patientDemoTest() {
describe('Patients test (2nd version)', () => {
let requests: Request[];

let requests: Request[] = [];
beforeAll(async () => {
requests = await global.RequestsRepository.find({
where: { session: { id: global.SESSION_ID }, resourceType: 'Patient' },
relations: ['session'],
});
requests = global.requests.filter((request) => request.resourceType === 'Patient' && request.session.id === global.SESSION_ID);
});

test('Should only have available interactions', async () => {
Expand All @@ -32,7 +17,7 @@ export function patientDemoTest() {
});

test('Should only have available search params', async () => {
const availableSearchParams = [
const availableSearchParams = new Set([
'_id',
'birthdate',
'family',
Expand All @@ -41,15 +26,21 @@ export function patientDemoTest() {
'name',
'gender-identity',
'indigenous-status',
];
]);
const filteredRequests = new Set(
requests
.filter((request) => request.filtersCodes.length === 1)
.map((request) => request.filtersCodes[0]),
);

expect(checkAvailableParams(availableSearchParams, false, requests)).toBe(true);
expect(filteredRequests.isSubsetOf(availableSearchParams)).toBe(true);
});

test('Should only have available combo search params', async () => {
const availableComboSearchParams = ['birthdate+family', 'birthdate+name', 'gender+name', 'family+gender'];
const availableComboSearchParams = new Set(['birthdate+family', 'birthdate+name', 'gender+name', 'family+gender']);
const filteredRequests = new Set(requests.filter((request) => request.filtersCodes.length > 1).map((request) => request.filtersCodes.join('+')));

expect(checkAvailableParams(availableComboSearchParams, true, requests)).toBe(true);
expect(filteredRequests.isSubsetOf(availableComboSearchParams)).toBe(true);
});

test('Should only have valid resources in CREATE action', async () => {
Expand Down
2 changes: 1 addition & 1 deletion packages/client-testing-demo-tests-standard/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"allowSyntheticDefaultImports": true,
"target": "ES2021",
"target": "ESNext",
"sourceMap": true,
"outDir": "./dist",
"baseUrl": "./",
Expand Down
2 changes: 1 addition & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"allowSyntheticDefaultImports": true,
"target": "ES2021",
"target": "ESNext",
"sourceMap": true,
"outDir": "./dist",
"baseUrl": "./",
Expand Down
8 changes: 4 additions & 4 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -5001,10 +5001,10 @@ typescript@5.3.3:
resolved "https://registry.yarnpkg.com/typescript/-/typescript-5.3.3.tgz#b3ce6ba258e72e6305ba66f5c9b452aaee3ffe37"
integrity sha512-pXWcraxM0uxAS+tN0AG/BF2TyqmHO014Z070UsJ+pFvYuRSq8KH8DmWpnbXe0pEPDHXZV3FcAbJkijJ5oNEnWw==

typescript@^5.1.3:
version "5.5.4"
resolved "https://registry.yarnpkg.com/typescript/-/typescript-5.5.4.tgz#d9852d6c82bad2d2eda4fd74a5762a8f5909e9ba"
integrity sha512-Mtq29sKDAEYP7aljRgtPOpTvOfbwRWlS6dPRzwjdE+C0R4brX/GUyhHSecbHMFLNBLcJIPt9nl9yG5TZ1weH+Q==
typescript@^5.6.2:
version "5.6.2"
resolved "https://registry.yarnpkg.com/typescript/-/typescript-5.6.2.tgz#d1de67b6bef77c41823f822df8f0b3bcff60a5a0"
integrity sha512-NW8ByodCSNCwZeghjN3o+JX5OFH0Ojg6sadjEKY4huZ52TqbJTJnDo5+Tw98lSy63NZvi4n+ez5m2u5d4PkZyw==

uid@2.0.2:
version "2.0.2"
Expand Down

0 comments on commit beca2f4

Please sign in to comment.