Skip to content

Commit

Permalink
Use tests without export
Browse files Browse the repository at this point in the history
Ref: #7
  • Loading branch information
projkov committed Sep 12, 2024
1 parent 0418d23 commit dd0ba01
Show file tree
Hide file tree
Showing 7 changed files with 152 additions and 161 deletions.
13 changes: 7 additions & 6 deletions packages/app/src/modules/test_runs/testRun.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ import { TestRun } from './testRun.entity';
import { createTestListObject } from '../../utils/data';

const testOptions = {
globalSetup: './src/utils/setup/jest.setup.ts',
globalTeardown: './src/utils/setup/jest.teardown.ts',
rootDir: './',
globalSetup: './app/src/utils/setup/jest.setup.ts',
globalTeardown: './app/src/utils/setup/jest.teardown.ts',
rootDir: '../',
testEnvironment: 'node',
moduleFileExtensions: ['ts', 'tsx', 'js', 'jsx', 'json', 'node'],
maxWorkers: 1,
Expand All @@ -30,7 +30,8 @@ export class TestRunController {
@ApiOperation({ summary: 'Create a new test session' })
async create(@Res() res: Response, @Body() createTestSessionDto: InitiateTestRunDto) {
const { suiteId, sessionId, testId } = createTestSessionDto;
const testRegex = `/src/suites/${suiteId}/.*\\.(test|spec)\\.[jt]sx?$`;
// const testRegex = `/src/suites/${suiteId}/.*\\.(test|spec)\\.[jt]sx?$`;
const testRegex = `./${suiteId}/src/.*\\.spec\\.ts$`;
const optionsWithTest = testId ? { testNamePattern: testId } : {};

const currentSession = await this.sessionService.findOne(sessionId);
Expand All @@ -49,7 +50,7 @@ export class TestRunController {
reporters: [
'default',
[
'<rootDir>/src/custom-reporter.js',
'<rootDir>/app/src/custom-reporter.js',
{
TEST_RUN_ID: testRun.id,
TEST_RUN_SERVICE: this.testRunService,
Expand Down Expand Up @@ -81,7 +82,7 @@ export class TestRunController {
@Get('test-list')
@ApiOperation({ summary: 'List all tests' })
async list(@Res() res: Response) {
const testRegex = `/src/suites/.*\\.(test|spec)\\.[jt]sx?$`;
const testRegex = `./.*\\.(test|spec)\\.[jt]sx?$`;

const options = {
...testOptions,
Expand Down

This file was deleted.

3 changes: 0 additions & 3 deletions packages/app/src/suites/1.0.0-ballot/Patient/patient.spec.ts

This file was deleted.

65 changes: 0 additions & 65 deletions packages/client-testing-demo-tests-db/src/index.ts

This file was deleted.

63 changes: 63 additions & 0 deletions packages/client-testing-demo-tests-db/src/patientdb.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
import { In, Not } from 'typeorm';

describe('Patients test', () => {
test('Should only have available interactions', async () => {
const requests = await global.RequestsRepository.find({
where: {
session: { id: global.SESSION_ID },
resourceType: 'Patient',
fhirAction: Not(In(['READ', 'SEARCH', 'CREATE', 'UPDATE'])),
},
relations: ['session'],
});
expect(requests.length).toBe(0);
});

test('Should only have available search params', async () => {
// NOTE: SQL query example
// SELECT *
// FROM request
// WHERE sessionId = 123
// AND resourceType = 'Patient'
// AND fhirAction = 'SEARCH'
// AND jsonb_array_length(filters) = 1
// AND filters->0->>'code' NOT IN ('_id', 'family')

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' })
.andWhere('jsonb_array_length(request.filters) = 1')
.andWhere("request.filters->0->>'code' NOT IN (:...availableSearchParams)", { availableSearchParams: ['_id', 'birthdate', 'family', 'gender', 'identifier', 'name', 'gender-identity', 'indigenous-status'] })
.getMany();

expect(requests.length).toBe(0);
});

test('Should only have available combo search params', async () => {
// NOTE: SQL query example
// SELECT *
// FROM request
// WHERE sessionId = 123
// AND resourceType = 'Patient'
// 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')
.where('request.sessionId = :sessionId', { sessionId: global.SESSION_ID })
.andWhere('request.resourceType = :resourceType', { resourceType: 'Patient' })
.andWhere('request.fhirAction = :action', { action: 'SEARCH' })
.andWhere('jsonb_array_length(request.filters) > 1')
.andWhere('NOT request.filters_codes <@ :codes', {
codes: [
['birthdate', 'family'],
['birthdate', 'name'],
['gender', 'name'],
['family', 'gender'],
],
})
.getMany();

expect(requests.length).toBe(0);
});
});
84 changes: 0 additions & 84 deletions packages/client-testing-demo-tests-standard/src/index.ts

This file was deleted.

82 changes: 82 additions & 0 deletions packages/client-testing-demo-tests-standard/src/patientjs.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
import { Request } from '@beda.software/app/src/modules/requests/request.entity';
import { isResourceValid } from '@beda.software/fhir-validator';

/**
* Temporary function to check if a set is a subset of another set
*/
function isSubsetOf<T>(setA: Set<T>, setB: Set<T>): boolean {
if (setA.size > setB.size) {
return false;
}

for (const elem of setA) {
if (!setB.has(elem)) {
return false;
}
}
return true;
}

describe('Patients test (2nd version)', () => {
let requests: Request[] = [];
beforeAll(async () => {
requests = global.requests.filter(
(request) => request.resourceType === 'Patient' && request.session.id === global.SESSION_ID,
);
});

test('Should only have available interactions', async () => {
const availableInteractions = ['READ', 'SEARCH', 'CREATE', 'UPDATE'];
const filteredRequests = requests.filter((request) => !availableInteractions.includes(request.fhirAction));

expect(filteredRequests.length).toBe(0);
});

test('Should only have available search params', async () => {
const availableSearchParams = new Set([
'_id',
'birthdate',
'family',
'gender',
'identifier',
'name',
'gender-identity',
'indigenous-status',
]);
const filteredRequests = new Set(
requests
.filter((request) => request.filtersCodes.length === 1)
.map((request) => request.filtersCodes[0]),
);

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

test('Should only have available combo search params', async () => {
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(isSubsetOf(filteredRequests, availableComboSearchParams)).toBe(true);
});

test('Should only have valid resources in CREATE action', async () => {
const filteredRequests = requests.filter(
(request) => request.fhirAction === 'CREATE' && request.requestBody?.resourceType === 'Patient',
);
const validationStatuses = await Promise.all(
filteredRequests.map(async (request) => await isResourceValid(request.requestBody)),
);
const falseValidations = validationStatuses.filter((status) => status === false);

expect(falseValidations.length).toBe(0);
});
});

0 comments on commit dd0ba01

Please sign in to comment.