diff --git a/Dockerfile b/Dockerfile index 71e61bc..c517598 100644 --- a/Dockerfile +++ b/Dockerfile @@ -8,4 +8,6 @@ COPY . . RUN yarn install +WORKDIR /app/packages/app + EXPOSE 8080 diff --git a/Makefile b/Makefile index 7db91ed..056dd59 100644 --- a/Makefile +++ b/Makefile @@ -13,7 +13,7 @@ pull: $(compose) $(dev_env) $(dev_profile) pull build: - $(compose) $(dev_env) $(dev_profile) build + $(compose) $(dev_env) $(dev_profile) build --no-cache up: $(compose) $(dev_env) $(dev_profile) up diff --git a/package.json b/package.json index fba7bfd..43cf9c7 100644 --- a/package.json +++ b/package.json @@ -6,83 +6,16 @@ "private": true, "license": "UNLICENSED", "workspaces": [ - "packages/*" + "packages/fhir-validator", + "packages/client-testing-demo-tests-standard", + "packages/client-testing-demo-tests-db", + "packages/app" ], "scripts": { "build": "nest build", "format": "prettier --write \"src/**/*.ts\" \"test/**/*.ts\"", - "start": "nest start", - "start:dev": "nest start --watch", - "start:debug": "nest start --debug --watch", - "start:prod": "node dist/main", "lint": "eslint \"{src,apps,libs,test}/**/*.ts\" --fix", - "test": "jest --testPathIgnorePatterns='/suites/'", - "test:watch": "jest --testPathIgnorePatterns='/suites/' --watch", - "test:cov": "jest --testPathIgnorePatterns='/suites/' --coverage", - "test:debug": "node --inspect-brk -r tsconfig-paths/register -r ts-node/register node_modules/.bin/jest --runInBand", - "test:e2e": "jest --testPathIgnorePatterns='/suites/' --config ./test/jest-e2e.json", "typecheck": "tsc --noEmit", "prepare": "npm run prepare --workspaces" - }, - "dependencies": { - "@medplum/core": "^3.2.4", - "@nestjs/common": "^10.0.0", - "@nestjs/config": "^3.2.3", - "@nestjs/core": "^10.0.0", - "@nestjs/platform-express": "^10.0.0", - "@nestjs/swagger": "^7.4.0", - "@nestjs/typeorm": "^10.0.2", - "@types/fhir": "^0.0.41", - "axios": "^1.7.4", - "dotenv": "^16.4.5", - "flatted": "^3.3.1", - "http-proxy": "^1.18.1", - "http-proxy-middleware": "^3.0.0", - "pg": "^8.12.0", - "reflect-metadata": "^0.2.2", - "rxjs": "^7.8.1", - "swagger-ui-express": "^5.0.1", - "typeorm": "^0.3.20" - }, - "devDependencies": { - "@nestjs/cli": "^10.0.0", - "@nestjs/schematics": "^10.0.0", - "@nestjs/testing": "^10.0.0", - "@types/express": "^4.17.17", - "@types/jest": "^29.5.2", - "@types/node": "^20.3.1", - "@types/supertest": "^6.0.0", - "@typescript-eslint/eslint-plugin": "^7.0.0", - "@typescript-eslint/parser": "^7.0.0", - "eslint": "^8.42.0", - "eslint-config-prettier": "^9.0.0", - "eslint-plugin-prettier": "^5.0.0", - "jest": "^29.5.0", - "prettier": "^3.0.0", - "source-map-support": "^0.5.21", - "supertest": "^7.0.0", - "ts-jest": "^29.1.0", - "ts-loader": "^9.4.3", - "ts-node": "^10.9.1", - "tsconfig-paths": "^4.2.0", - "typescript": "^5.1.3" - }, - "jest": { - "moduleFileExtensions": [ - "js", - "json", - "ts" - ], - "testTimeout": 30000, - "rootDir": "./", - "testRegex": ".*\\.spec\\.ts$", - "transform": { - "^.+\\.(t|j)s$": "ts-jest" - }, - "collectCoverageFrom": [ - "**/*.(t|j)s" - ], - "coverageDirectory": "../coverage", - "testEnvironment": "node" } } diff --git a/README.md b/packages/app/README.md similarity index 100% rename from README.md rename to packages/app/README.md diff --git a/nest-cli.json b/packages/app/nest-cli.json similarity index 100% rename from nest-cli.json rename to packages/app/nest-cli.json diff --git a/packages/app/package.json b/packages/app/package.json new file mode 100644 index 0000000..0e7b2d2 --- /dev/null +++ b/packages/app/package.json @@ -0,0 +1,86 @@ +{ + "name": "@beda.software/app", + "version": "0.0.1", + "description": "", + "author": "", + "private": true, + "license": "UNLICENSED", + "scripts": { + "build": "nest build", + "format": "prettier --write \"src/**/*.ts\" \"test/**/*.ts\"", + "start": "nest start", + "start:dev": "nest start --watch", + "start:debug": "nest start --debug --watch", + "start:prod": "node dist/main", + "lint": "eslint \"{src,apps,libs,test}/**/*.ts\" --fix", + "test": "jest --testPathIgnorePatterns='/suites/'", + "test:watch": "jest --testPathIgnorePatterns='/suites/' --watch", + "test:cov": "jest --testPathIgnorePatterns='/suites/' --coverage", + "test:debug": "node --inspect-brk -r tsconfig-paths/register -r ts-node/register node_modules/.bin/jest --runInBand", + "test:e2e": "jest --testPathIgnorePatterns='/suites/' --config ./test/jest-e2e.json", + "typecheck": "tsc --noEmit", + "prepare": "tsc" + }, + "dependencies": { + "@medplum/core": "^3.2.4", + "@nestjs/common": "^10.0.0", + "@nestjs/config": "^3.2.3", + "@nestjs/core": "^10.0.0", + "@nestjs/platform-express": "^10.0.0", + "@nestjs/swagger": "^7.4.0", + "@nestjs/typeorm": "^10.0.2", + "@types/fhir": "^0.0.41", + "axios": "^1.7.4", + "dotenv": "^16.4.5", + "flatted": "^3.3.1", + "http-proxy": "^1.18.1", + "http-proxy-middleware": "^3.0.0", + "pg": "^8.12.0", + "reflect-metadata": "^0.2.2", + "rxjs": "^7.8.1", + "swagger-ui-express": "^5.0.1", + "typeorm": "^0.3.20", + "@beda.software/fhir-validator": "0.0.1" + }, + "devDependencies": { + "@nestjs/cli": "^10.0.0", + "@nestjs/schematics": "^10.0.0", + "@nestjs/testing": "^10.0.0", + "@types/express": "^4.17.17", + "@types/jest": "^29.5.2", + "@types/node": "^20.3.1", + "@types/supertest": "^6.0.0", + "@typescript-eslint/eslint-plugin": "^7.0.0", + "@typescript-eslint/parser": "^7.0.0", + "eslint": "^8.42.0", + "eslint-config-prettier": "^9.0.0", + "eslint-plugin-prettier": "^5.0.0", + "jest": "^29.5.0", + "prettier": "^3.0.0", + "source-map-support": "^0.5.21", + "supertest": "^7.0.0", + "ts-jest": "^29.1.0", + "ts-loader": "^9.4.3", + "ts-node": "^10.9.1", + "tsconfig-paths": "^4.2.0", + "typescript": "^5.1.3" + }, + "jest": { + "moduleFileExtensions": [ + "js", + "json", + "ts" + ], + "testTimeout": 30000, + "rootDir": "./", + "testRegex": ".*\\.spec\\.ts$", + "transform": { + "^.+\\.(t|j)s$": "ts-jest" + }, + "collectCoverageFrom": [ + "**/*.(t|j)s" + ], + "coverageDirectory": "../coverage", + "testEnvironment": "node" + } +} diff --git a/src/app.module.ts b/packages/app/src/app.module.ts similarity index 100% rename from src/app.module.ts rename to packages/app/src/app.module.ts diff --git a/src/custom-reporter.js b/packages/app/src/custom-reporter.js similarity index 100% rename from src/custom-reporter.js rename to packages/app/src/custom-reporter.js diff --git a/src/main.ts b/packages/app/src/main.ts similarity index 100% rename from src/main.ts rename to packages/app/src/main.ts diff --git a/src/modules/proxyapp/proxyapp.controller.ts b/packages/app/src/modules/proxyapp/proxyapp.controller.ts similarity index 92% rename from src/modules/proxyapp/proxyapp.controller.ts rename to packages/app/src/modules/proxyapp/proxyapp.controller.ts index 3ff7b7b..c1b0ec8 100644 --- a/src/modules/proxyapp/proxyapp.controller.ts +++ b/packages/app/src/modules/proxyapp/proxyapp.controller.ts @@ -1,10 +1,10 @@ import { All, Controller, Param, Req, Res } from '@nestjs/common'; import { ApiTags, ApiOperation, ApiParam } from '@nestjs/swagger'; -import { createRequestObject } from 'src/utils/data'; -import { captureResponseBody } from '@beda.software/client-testing-proxy-helpers'; import { RequestService } from '../requests/request.service'; import { SessionService } from '../sessions/session.service'; import { Request, Response } from 'express'; +import { createRequestObject } from '../../utils/data'; +import { captureResponseBody } from '../../utils/proxyHelpers'; @ApiTags('proxy') @Controller('proxy') diff --git a/src/modules/proxyapp/proxyapp.module.ts b/packages/app/src/modules/proxyapp/proxyapp.module.ts similarity index 100% rename from src/modules/proxyapp/proxyapp.module.ts rename to packages/app/src/modules/proxyapp/proxyapp.module.ts diff --git a/src/modules/requests/request.controller.ts b/packages/app/src/modules/requests/request.controller.ts similarity index 100% rename from src/modules/requests/request.controller.ts rename to packages/app/src/modules/requests/request.controller.ts diff --git a/src/modules/requests/request.dto.ts b/packages/app/src/modules/requests/request.dto.ts similarity index 98% rename from src/modules/requests/request.dto.ts rename to packages/app/src/modules/requests/request.dto.ts index 4468b9d..0e08a38 100644 --- a/src/modules/requests/request.dto.ts +++ b/packages/app/src/modules/requests/request.dto.ts @@ -1,7 +1,7 @@ import { ApiProperty } from '@nestjs/swagger'; import { Request as RequestType, Response } from 'express'; import { Session } from '../sessions/session.entity'; -import { jsonbType } from 'src/utils/types'; +import { jsonbType } from '../../utils/types'; export class CreateRequestDto { @ApiProperty({ description: 'Session associated with the request' }) diff --git a/src/modules/requests/request.entity.ts b/packages/app/src/modules/requests/request.entity.ts similarity index 98% rename from src/modules/requests/request.entity.ts rename to packages/app/src/modules/requests/request.entity.ts index e6c4303..828d646 100644 --- a/src/modules/requests/request.entity.ts +++ b/packages/app/src/modules/requests/request.entity.ts @@ -1,7 +1,7 @@ import { Response, Request as RequestType } from 'express'; import { Entity, PrimaryGeneratedColumn, Column, CreateDateColumn, ManyToOne } from 'typeorm'; import { Session } from '../sessions/session.entity'; -import { jsonbType } from 'src/utils/types'; +import { jsonbType } from '../../utils/types'; @Entity() export class Request { diff --git a/src/modules/requests/request.module.ts b/packages/app/src/modules/requests/request.module.ts similarity index 100% rename from src/modules/requests/request.module.ts rename to packages/app/src/modules/requests/request.module.ts diff --git a/src/modules/requests/request.service.ts b/packages/app/src/modules/requests/request.service.ts similarity index 100% rename from src/modules/requests/request.service.ts rename to packages/app/src/modules/requests/request.service.ts diff --git a/src/modules/sessions/interfaces.ts b/packages/app/src/modules/sessions/interfaces.ts similarity index 100% rename from src/modules/sessions/interfaces.ts rename to packages/app/src/modules/sessions/interfaces.ts diff --git a/src/modules/sessions/session.controller.ts b/packages/app/src/modules/sessions/session.controller.ts similarity index 100% rename from src/modules/sessions/session.controller.ts rename to packages/app/src/modules/sessions/session.controller.ts diff --git a/src/modules/sessions/session.dto.ts b/packages/app/src/modules/sessions/session.dto.ts similarity index 100% rename from src/modules/sessions/session.dto.ts rename to packages/app/src/modules/sessions/session.dto.ts diff --git a/src/modules/sessions/session.entity.ts b/packages/app/src/modules/sessions/session.entity.ts similarity index 100% rename from src/modules/sessions/session.entity.ts rename to packages/app/src/modules/sessions/session.entity.ts diff --git a/src/modules/sessions/session.module.ts b/packages/app/src/modules/sessions/session.module.ts similarity index 100% rename from src/modules/sessions/session.module.ts rename to packages/app/src/modules/sessions/session.module.ts diff --git a/src/modules/sessions/session.service.ts b/packages/app/src/modules/sessions/session.service.ts similarity index 100% rename from src/modules/sessions/session.service.ts rename to packages/app/src/modules/sessions/session.service.ts diff --git a/src/modules/test_runs/testRun.controller.ts b/packages/app/src/modules/test_runs/testRun.controller.ts similarity index 98% rename from src/modules/test_runs/testRun.controller.ts rename to packages/app/src/modules/test_runs/testRun.controller.ts index c279793..a880783 100644 --- a/src/modules/test_runs/testRun.controller.ts +++ b/packages/app/src/modules/test_runs/testRun.controller.ts @@ -6,7 +6,7 @@ import { runCLI } from '@jest/core'; import { TestRunService } from './testRun.service'; import { SessionService } from '../sessions/session.service'; import { TestRun } from './testRun.entity'; -import { createTestListObject } from 'src/utils/data'; +import { createTestListObject } from '../../utils/data'; const testOptions = { globalSetup: './src/utils/setup/jest.setup.ts', diff --git a/src/modules/test_runs/testRun.dto.ts b/packages/app/src/modules/test_runs/testRun.dto.ts similarity index 96% rename from src/modules/test_runs/testRun.dto.ts rename to packages/app/src/modules/test_runs/testRun.dto.ts index 00d312c..a6012fe 100644 --- a/src/modules/test_runs/testRun.dto.ts +++ b/packages/app/src/modules/test_runs/testRun.dto.ts @@ -1,6 +1,6 @@ import { ApiProperty } from '@nestjs/swagger'; import { json } from 'node:stream/consumers'; -import { jsonbType } from 'src/utils/types'; +import { jsonbType } from '../../utils/types'; import { Session } from '../sessions/session.entity'; export class CreateTestRunDto { diff --git a/src/modules/test_runs/testRun.entity.ts b/packages/app/src/modules/test_runs/testRun.entity.ts similarity index 96% rename from src/modules/test_runs/testRun.entity.ts rename to packages/app/src/modules/test_runs/testRun.entity.ts index dd87a95..feb7208 100644 --- a/src/modules/test_runs/testRun.entity.ts +++ b/packages/app/src/modules/test_runs/testRun.entity.ts @@ -1,6 +1,6 @@ import { Column, CreateDateColumn, Entity, ManyToOne, PrimaryGeneratedColumn } from 'typeorm'; import { Session } from '../sessions/session.entity'; -import { jsonbType } from 'src/utils/types'; +import { jsonbType } from '../../utils/types'; export enum TestRunStatus { NOT_STARTED = 'not-started', diff --git a/src/modules/test_runs/testRun.module.ts b/packages/app/src/modules/test_runs/testRun.module.ts similarity index 100% rename from src/modules/test_runs/testRun.module.ts rename to packages/app/src/modules/test_runs/testRun.module.ts diff --git a/src/modules/test_runs/testRun.service.ts b/packages/app/src/modules/test_runs/testRun.service.ts similarity index 100% rename from src/modules/test_runs/testRun.service.ts rename to packages/app/src/modules/test_runs/testRun.service.ts diff --git a/packages/app/src/suites/1.0.0-ballot/Patient/patient-db.spec.ts b/packages/app/src/suites/1.0.0-ballot/Patient/patient-db.spec.ts new file mode 100644 index 0000000..055aaaa --- /dev/null +++ b/packages/app/src/suites/1.0.0-ballot/Patient/patient-db.spec.ts @@ -0,0 +1,3 @@ +import { patientDemoTestDB } from '@beda.software/client-testing-demo-tests-db'; + +patientDemoTestDB(); diff --git a/packages/app/src/suites/1.0.0-ballot/Patient/patient.spec.ts b/packages/app/src/suites/1.0.0-ballot/Patient/patient.spec.ts new file mode 100644 index 0000000..905959f --- /dev/null +++ b/packages/app/src/suites/1.0.0-ballot/Patient/patient.spec.ts @@ -0,0 +1,3 @@ +import { patientDemoTest } from '@beda.software/client-testing-demo-tests-standard'; + +patientDemoTest(); diff --git a/src/utils/clientTestingHelpers.spec.ts b/packages/app/src/utils/clientTestingHelpers.spec.ts similarity index 100% rename from src/utils/clientTestingHelpers.spec.ts rename to packages/app/src/utils/clientTestingHelpers.spec.ts diff --git a/src/utils/clientTestingHelpers.ts b/packages/app/src/utils/clientTestingHelpers.ts similarity index 97% rename from src/utils/clientTestingHelpers.ts rename to packages/app/src/utils/clientTestingHelpers.ts index 5b0ff92..bf56053 100644 --- a/src/utils/clientTestingHelpers.ts +++ b/packages/app/src/utils/clientTestingHelpers.ts @@ -1,4 +1,4 @@ -import { Request } from 'src/modules/requests/request.entity'; +import { Request } from '../modules/requests/request.entity'; import { Repository } from 'typeorm'; /** diff --git a/src/utils/data.spec.ts b/packages/app/src/utils/data.spec.ts similarity index 89% rename from src/utils/data.spec.ts rename to packages/app/src/utils/data.spec.ts index b8bfc68..b0f5dd6 100644 --- a/src/utils/data.spec.ts +++ b/packages/app/src/utils/data.spec.ts @@ -1,4 +1,20 @@ -import { createTestListObject } from './data'; +import { createTestListObject, getFHIRAction } from './data'; + +describe('getFHIRAction', () => { + test.each([ + ['READ', 'GET', '/Patient/123'], + ['VREAD', 'GET', '/Patient/123/_history/1'], + ['CREATE', 'POST', '/Patient'], + ['UPDATE', 'PUT', '/Patient/123'], + ['DELETE', 'DELETE', '/Patient/123'], + ['SEARCH', 'GET', '/Patient?name=Smith'], + ['SEARCH', 'POST', '/Patient/_search'], + ['HISTORY', 'GET', '/Patient/_history'], + ['PATCH', 'PATCH', '/Patient/123'], + ])('should return correct FHIR action for %s', (expectedAction, method, url) => { + expect(getFHIRAction(method, url)).toBe(expectedAction); + }); +}); describe('Data utilities', () => { it('Should return correct test list from test result object', async () => { diff --git a/src/utils/data.ts b/packages/app/src/utils/data.ts similarity index 73% rename from src/utils/data.ts rename to packages/app/src/utils/data.ts index ebd42ac..3ed7525 100644 --- a/src/utils/data.ts +++ b/packages/app/src/utils/data.ts @@ -1,8 +1,41 @@ import { parseSearchRequest } from '@medplum/core'; import { Request, Response } from 'express'; -import { CreateRequestDto } from 'src/modules/requests/request.dto'; -import { Session } from 'src/modules/sessions/session.entity'; -import { getFHIRAction } from '@beda.software/client-testing-helpers'; +import { CreateRequestDto } from '../modules/requests/request.dto'; +import { Session } from '../modules/sessions/session.entity'; + +export function getFHIRAction(requestType: Request['method'], url: Request['url']) { + const mapSimpleRequest = { + DELETE: 'DELETE', + PATCH: 'PATCH', + PUT: 'UPDATE', + }; + + if (Object.keys(mapSimpleRequest).includes(requestType)) { + return mapSimpleRequest[requestType]; + } + + if (requestType === 'POST') { + if (url.includes('_search')) { + return 'SEARCH'; + } + return 'CREATE'; + } + + if (requestType === 'GET') { + if (url.includes('_history')) { + if (url.match(/\/_history\/\d+$/)) { + return 'VREAD'; + } + return 'HISTORY'; + } + + if (url.includes('?')) { + return 'SEARCH'; + } + + return 'READ'; + } +} export function createRequestObject( id: string, diff --git a/packages/client-testing-proxy-helpers/src/index.tsx b/packages/app/src/utils/proxyHelpers.ts similarity index 100% rename from packages/client-testing-proxy-helpers/src/index.tsx rename to packages/app/src/utils/proxyHelpers.ts diff --git a/src/utils/setup/jest.setup.ts b/packages/app/src/utils/setup/jest.setup.ts similarity index 100% rename from src/utils/setup/jest.setup.ts rename to packages/app/src/utils/setup/jest.setup.ts diff --git a/src/utils/setup/jest.teardown.ts b/packages/app/src/utils/setup/jest.teardown.ts similarity index 100% rename from src/utils/setup/jest.teardown.ts rename to packages/app/src/utils/setup/jest.teardown.ts diff --git a/src/utils/types.ts b/packages/app/src/utils/types.ts similarity index 100% rename from src/utils/types.ts rename to packages/app/src/utils/types.ts diff --git a/packages/app/tsconfig.build.json b/packages/app/tsconfig.build.json new file mode 100644 index 0000000..64f86c6 --- /dev/null +++ b/packages/app/tsconfig.build.json @@ -0,0 +1,4 @@ +{ + "extends": "./tsconfig.json", + "exclude": ["node_modules", "test", "dist", "**/*spec.ts"] +} diff --git a/packages/client-testing-helpers/tsconfig.json b/packages/app/tsconfig.json similarity index 100% rename from packages/client-testing-helpers/tsconfig.json rename to packages/app/tsconfig.json diff --git a/packages/client-testing-proxy-helpers/package.json b/packages/client-testing-demo-tests-db/package.json similarity index 60% rename from packages/client-testing-proxy-helpers/package.json rename to packages/client-testing-demo-tests-db/package.json index 3137a8c..0faf59b 100644 --- a/packages/client-testing-proxy-helpers/package.json +++ b/packages/client-testing-demo-tests-db/package.json @@ -1,10 +1,10 @@ { - "name": "@beda.software/client-testing-proxy-helpers", + "name": "@beda.software/client-testing-demo-tests-db", "version": "0.0.1", "description": "", "main": "dist/index.js", "scripts": { - "prepare": "tsc" + "prepare": "tsc || true" }, "author": "", "license": "ISC" diff --git a/packages/client-testing-demo-tests-db/src/index.ts b/packages/client-testing-demo-tests-db/src/index.ts new file mode 100644 index 0000000..be9579a --- /dev/null +++ b/packages/client-testing-demo-tests-db/src/index.ts @@ -0,0 +1,76 @@ +import { In, Not } from 'typeorm'; +import { Patient } from 'fhir/r4'; +import { + getRequestsWithUnavailableComboSearchParams, + getRequestsWithUnavailableSearchParams, +} from '@beda.software/app/src//utils/clientTestingHelpers'; +import { Request } from '@beda.software/app/src/modules/requests/request.entity'; +import { isResourceValid } from '@beda.software/fhir-validator'; + +async function patientRequestCreateValidPatient(requests: Request[]): Promise { + 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 as Patient)), + ); + const falseValidations = validationStatuses.filter((status) => status === false); + + return falseValidations.length === 0; +} + +export function patientDemoTestDB() { + describe('Patients test', () => { + let requests: Request[]; + + beforeAll(async () => { + requests = await global.RequestsRepository.find({ + where: { session: { id: global.SESSION_ID }, resourceType: 'Patient' }, + relations: ['session'], + }); + }); + + test('Should only have available interactions', async () => { + 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 () => { + const requests = await getRequestsWithUnavailableSearchParams( + global.RequestsRepository, + global.SESSION_ID, + 'Patient', + ['_id', 'birthdate', 'family', 'gender', 'identifier', 'name', 'gender-identity', 'indigenous-status'], + ); + expect(requests.length).toBe(0); + }); + + test('Should only have available combo search params', async () => { + const requests = await getRequestsWithUnavailableComboSearchParams( + global.RequestsRepository, + global.SESSION_ID, + 'Patient', + [ + ['birthdate', 'family'], + ['birthdate', 'name'], + ['gender', 'name'], + ['family', 'gender'], + ], + ); + expect(requests.length).toBe(0); + }); + + test('Should only have valid resources in CREATE action', async () => { + expect( + await patientRequestCreateValidPatient(requests.filter((request) => request.fhirAction === 'CREATE')), + ).toBe(true); + }); + }); +} diff --git a/packages/client-testing-proxy-helpers/tsconfig.json b/packages/client-testing-demo-tests-db/tsconfig.json similarity index 100% rename from packages/client-testing-proxy-helpers/tsconfig.json rename to packages/client-testing-demo-tests-db/tsconfig.json diff --git a/packages/client-testing-demo-tests-standard/package.json b/packages/client-testing-demo-tests-standard/package.json new file mode 100644 index 0000000..4a06f6a --- /dev/null +++ b/packages/client-testing-demo-tests-standard/package.json @@ -0,0 +1,11 @@ +{ + "name": "@beda.software/client-testing-demo-tests-standard", + "version": "0.0.1", + "description": "", + "main": "dist/index.js", + "scripts": { + "prepare": "tsc || true" + }, + "author": "", + "license": "ISC" +} diff --git a/src/suites/1.0.0-ballot/Patient/patients-2nd.spec.ts b/packages/client-testing-demo-tests-standard/src/index.ts similarity index 64% rename from src/suites/1.0.0-ballot/Patient/patients-2nd.spec.ts rename to packages/client-testing-demo-tests-standard/src/index.ts index 53ee4bf..1fb3a7e 100644 --- a/src/suites/1.0.0-ballot/Patient/patients-2nd.spec.ts +++ b/packages/client-testing-demo-tests-standard/src/index.ts @@ -1,5 +1,5 @@ import { Patient } from 'fhir/r4'; -import { Request } from '../../../modules/requests/request.entity'; +import { Request } from '@beda.software/app/src/modules/requests/request.entity'; import { isResourceValid } from '@beda.software/fhir-validator'; function patientRequestsOnlyAvailableInteractionsExists(requests: Request[]): boolean { @@ -53,31 +53,33 @@ async function patientRequestCreateValidPatient(requests: Request[]): Promise { - let requests: Request[]; +export function patientDemoTest() { + describe('Patients test (2nd version)', () => { + let requests: Request[]; - beforeAll(async () => { - requests = await global.RequestsRepository.find({ - where: { session: { id: global.SESSION_ID }, resourceType: 'Patient' }, - relations: ['session'], + beforeAll(async () => { + requests = await global.RequestsRepository.find({ + where: { session: { id: global.SESSION_ID }, resourceType: 'Patient' }, + relations: ['session'], + }); }); - }); - test('Should only have available interactions', async () => { - expect(patientRequestsOnlyAvailableInteractionsExists(requests)).toBe(true); - }); + test('Should only have available interactions', async () => { + expect(patientRequestsOnlyAvailableInteractionsExists(requests)).toBe(true); + }); - test('Should only have available search params', async () => { - expect(patientRequestsOnlyAvailableSearchParamsExists(requests)).toBe(true); - }); + test('Should only have available search params', async () => { + expect(patientRequestsOnlyAvailableSearchParamsExists(requests)).toBe(true); + }); - test('Should only have available combo search params', async () => { - expect(patientRequestsOnlyAvailableComboSearchParamsExists(requests)).toBe(true); - }); + test('Should only have available combo search params', async () => { + expect(patientRequestsOnlyAvailableComboSearchParamsExists(requests)).toBe(true); + }); - test('Should only have valid resources in CREATE action', async () => { - expect( - await patientRequestCreateValidPatient(requests.filter((request) => request.fhirAction === 'CREATE')), - ).toBe(true); + test('Should only have valid resources in CREATE action', async () => { + expect( + await patientRequestCreateValidPatient(requests.filter((request) => request.fhirAction === 'CREATE')), + ).toBe(true); + }); }); -}); +} diff --git a/packages/client-testing-demo-tests-standard/tsconfig.json b/packages/client-testing-demo-tests-standard/tsconfig.json new file mode 100644 index 0000000..9f65283 --- /dev/null +++ b/packages/client-testing-demo-tests-standard/tsconfig.json @@ -0,0 +1,22 @@ +{ + "compilerOptions": { + "module": "commonjs", + "declaration": true, + "removeComments": true, + "emitDecoratorMetadata": true, + "experimentalDecorators": true, + "allowSyntheticDefaultImports": true, + "target": "ES2021", + "sourceMap": true, + "outDir": "./dist", + "baseUrl": "./", + "incremental": true, + "skipLibCheck": true, + "strictNullChecks": false, + "noImplicitAny": false, + "strictBindCallApply": false, + "forceConsistentCasingInFileNames": false, + "noFallthroughCasesInSwitch": false, + "noEmit": false + } +} diff --git a/packages/client-testing-helpers/package.json b/packages/client-testing-helpers/package.json deleted file mode 100644 index 2670db1..0000000 --- a/packages/client-testing-helpers/package.json +++ /dev/null @@ -1,11 +0,0 @@ -{ - "name": "@beda.software/client-testing-helpers", - "version": "0.0.1", - "description": "", - "main": "dist/index.js", - "scripts": { - "prepare": "tsc" - }, - "author": "", - "license": "MIT" -} diff --git a/packages/client-testing-helpers/src/index.ts b/packages/client-testing-helpers/src/index.ts deleted file mode 100644 index 63a3450..0000000 --- a/packages/client-testing-helpers/src/index.ts +++ /dev/null @@ -1,35 +0,0 @@ -import { Request } from 'express'; - -export function getFHIRAction(requestType: Request['method'], url: Request['url']) { - const mapSimpleRequest = { - DELETE: 'DELETE', - PATCH: 'PATCH', - PUT: 'UPDATE', - }; - - if (Object.keys(mapSimpleRequest).includes(requestType)) { - return mapSimpleRequest[requestType]; - } - - if (requestType === 'POST') { - if (url.includes('_search')) { - return 'SEARCH'; - } - return 'CREATE'; - } - - if (requestType === 'GET') { - if (url.includes('_history')) { - if (url.match(/\/_history\/\d+$/)) { - return 'VREAD'; - } - return 'HISTORY'; - } - - if (url.includes('?')) { - return 'SEARCH'; - } - - return 'READ'; - } -} diff --git a/packages/client-testing-helpers/src/tests.spec.ts b/packages/client-testing-helpers/src/tests.spec.ts deleted file mode 100644 index c103569..0000000 --- a/packages/client-testing-helpers/src/tests.spec.ts +++ /dev/null @@ -1,17 +0,0 @@ -import { getFHIRAction } from '.'; - -describe('getFHIRAction', () => { - test.each([ - ['READ', 'GET', '/Patient/123'], - ['VREAD', 'GET', '/Patient/123/_history/1'], - ['CREATE', 'POST', '/Patient'], - ['UPDATE', 'PUT', '/Patient/123'], - ['DELETE', 'DELETE', '/Patient/123'], - ['SEARCH', 'GET', '/Patient?name=Smith'], - ['SEARCH', 'POST', '/Patient/_search'], - ['HISTORY', 'GET', '/Patient/_history'], - ['PATCH', 'PATCH', '/Patient/123'], - ])('should return correct FHIR action for %s', (expectedAction, method, url) => { - expect(getFHIRAction(method, url)).toBe(expectedAction); - }); -}); diff --git a/src/suites/1.0.0-ballot/Patient/patients.spec.ts b/src/suites/1.0.0-ballot/Patient/patients.spec.ts deleted file mode 100644 index ab817a9..0000000 --- a/src/suites/1.0.0-ballot/Patient/patients.spec.ts +++ /dev/null @@ -1,74 +0,0 @@ -import { In, Not } from 'typeorm'; -import { Patient } from 'fhir/r4'; -import { - getRequestsWithUnavailableComboSearchParams, - getRequestsWithUnavailableSearchParams, -} from '../../../utils/clientTestingHelpers'; -import { Request } from '../../../modules/requests/request.entity'; -import { isResourceValid } from '@beda.software/fhir-validator'; - -async function patientRequestCreateValidPatient(requests: Request[]): Promise { - 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 as Patient)), - ); - const falseValidations = validationStatuses.filter((status) => status === false); - - return falseValidations.length === 0; -} - -describe('Patients test', () => { - let requests: Request[]; - - beforeAll(async () => { - requests = await global.RequestsRepository.find({ - where: { session: { id: global.SESSION_ID }, resourceType: 'Patient' }, - relations: ['session'], - }); - }); - - test('Should only have available interactions', async () => { - 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 () => { - const requests = await getRequestsWithUnavailableSearchParams( - global.RequestsRepository, - global.SESSION_ID, - 'Patient', - ['_id', 'birthdate', 'family', 'gender', 'identifier', 'name', 'gender-identity', 'indigenous-status'], - ); - expect(requests.length).toBe(0); - }); - - test('Should only have available combo search params', async () => { - const requests = await getRequestsWithUnavailableComboSearchParams( - global.RequestsRepository, - global.SESSION_ID, - 'Patient', - [ - ['birthdate', 'family'], - ['birthdate', 'name'], - ['gender', 'name'], - ['family', 'gender'], - ], - ); - expect(requests.length).toBe(0); - }); - - test('Should only have valid resources in CREATE action', async () => { - expect( - await patientRequestCreateValidPatient(requests.filter((request) => request.fhirAction === 'CREATE')), - ).toBe(true); - }); -}); diff --git a/test/app.e2e-spec.ts b/test/app.e2e-spec.ts deleted file mode 100644 index 42edde7..0000000 --- a/test/app.e2e-spec.ts +++ /dev/null @@ -1,21 +0,0 @@ -import { Test, TestingModule } from '@nestjs/testing'; -import { INestApplication } from '@nestjs/common'; -import * as request from 'supertest'; -import { AppModule } from '../src/app.module'; - -describe('AppController (e2e)', () => { - let app: INestApplication; - - beforeEach(async () => { - const moduleFixture: TestingModule = await Test.createTestingModule({ - imports: [AppModule], - }).compile(); - - app = moduleFixture.createNestApplication(); - await app.init(); - }); - - it('/ (GET)', () => { - return request(app.getHttpServer()).get('/').expect(200).expect('Hello World!'); - }); -}); diff --git a/test/jest-e2e.json b/test/jest-e2e.json deleted file mode 100644 index e9d912f..0000000 --- a/test/jest-e2e.json +++ /dev/null @@ -1,9 +0,0 @@ -{ - "moduleFileExtensions": ["js", "json", "ts"], - "rootDir": ".", - "testEnvironment": "node", - "testRegex": ".e2e-spec.ts$", - "transform": { - "^.+\\.(t|j)s$": "ts-jest" - } -}