From 27a8a5ba4b72d53336bf520fd625ef5f15a5744c Mon Sep 17 00:00:00 2001 From: nvim Date: Fri, 6 Sep 2024 16:28:52 +0200 Subject: [PATCH] Add client-testing-modules Ref: https://github.com/beda-software/fhir-client-testing-tool/issues/7 --- packages/client-testing-modules/package.json | 11 ++++++++++ .../client-testing-modules/src}/app.module.ts | 8 +++---- .../client-testing-modules/src}/data.ts | 4 ++-- packages/client-testing-modules/src/index.ts | 6 +++++ .../src}/proxyapp/proxyapp.controller.ts | 2 +- .../src}/proxyapp/proxyapp.module.ts | 0 .../src}/requests/request.controller.ts | 0 .../src}/requests/request.dto.ts | 2 +- .../src}/requests/request.entity.ts | 2 +- .../src}/requests/request.module.ts | 0 .../src}/requests/request.service.ts | 0 .../src}/sessions/interfaces.ts | 0 .../src}/sessions/session.controller.ts | 0 .../src}/sessions/session.dto.ts | 0 .../src}/sessions/session.entity.ts | 0 .../src}/sessions/session.module.ts | 0 .../src}/sessions/session.service.ts | 0 .../src}/test_runs/testRun.controller.ts | 4 ++-- .../src}/test_runs/testRun.dto.ts | 2 +- .../src}/test_runs/testRun.entity.ts | 4 ++-- .../src}/test_runs/testRun.module.ts | 0 .../src}/test_runs/testRun.service.ts | 0 .../client-testing-modules/src}/types.ts | 0 packages/client-testing-modules/tsconfig.json | 22 +++++++++++++++++++ src/main.ts | 2 +- .../1.0.0-ballot/Patient/patients.spec.ts | 2 +- src/utils/clientTestingHelpers.spec.ts | 6 ++--- src/utils/clientTestingHelpers.ts | 2 +- src/utils/setup/jest.setup.ts | 4 +--- test/app.e2e-spec.ts | 21 ------------------ test/jest-e2e.json | 9 -------- 31 files changed, 59 insertions(+), 54 deletions(-) create mode 100644 packages/client-testing-modules/package.json rename {src => packages/client-testing-modules/src}/app.module.ts (73%) rename {src/utils => packages/client-testing-modules/src}/data.ts (92%) create mode 100644 packages/client-testing-modules/src/index.ts rename {src/modules => packages/client-testing-modules/src}/proxyapp/proxyapp.controller.ts (97%) rename {src/modules => packages/client-testing-modules/src}/proxyapp/proxyapp.module.ts (100%) rename {src/modules => packages/client-testing-modules/src}/requests/request.controller.ts (100%) rename {src/modules => packages/client-testing-modules/src}/requests/request.dto.ts (98%) rename {src/modules => packages/client-testing-modules/src}/requests/request.entity.ts (98%) rename {src/modules => packages/client-testing-modules/src}/requests/request.module.ts (100%) rename {src/modules => packages/client-testing-modules/src}/requests/request.service.ts (100%) rename {src/modules => packages/client-testing-modules/src}/sessions/interfaces.ts (100%) rename {src/modules => packages/client-testing-modules/src}/sessions/session.controller.ts (100%) rename {src/modules => packages/client-testing-modules/src}/sessions/session.dto.ts (100%) rename {src/modules => packages/client-testing-modules/src}/sessions/session.entity.ts (100%) rename {src/modules => packages/client-testing-modules/src}/sessions/session.module.ts (100%) rename {src/modules => packages/client-testing-modules/src}/sessions/session.service.ts (100%) rename {src/modules => packages/client-testing-modules/src}/test_runs/testRun.controller.ts (99%) rename {src/modules => packages/client-testing-modules/src}/test_runs/testRun.dto.ts (95%) rename {src/modules => packages/client-testing-modules/src}/test_runs/testRun.entity.ts (93%) rename {src/modules => packages/client-testing-modules/src}/test_runs/testRun.module.ts (100%) rename {src/modules => packages/client-testing-modules/src}/test_runs/testRun.service.ts (100%) rename {src/utils => packages/client-testing-modules/src}/types.ts (100%) create mode 100644 packages/client-testing-modules/tsconfig.json delete mode 100644 test/app.e2e-spec.ts delete mode 100644 test/jest-e2e.json diff --git a/packages/client-testing-modules/package.json b/packages/client-testing-modules/package.json new file mode 100644 index 0000000..ed0ad66 --- /dev/null +++ b/packages/client-testing-modules/package.json @@ -0,0 +1,11 @@ +{ + "name": "@beda.software/client-testing-modules", + "version": "0.0.1", + "description": "", + "main": "dist/index.js", + "scripts": { + "prepare": "tsc" + }, + "author": "", + "license": "ISC" +} diff --git a/src/app.module.ts b/packages/client-testing-modules/src/app.module.ts similarity index 73% rename from src/app.module.ts rename to packages/client-testing-modules/src/app.module.ts index 5f57fc8..55e54c6 100644 --- a/src/app.module.ts +++ b/packages/client-testing-modules/src/app.module.ts @@ -1,10 +1,10 @@ import { Module } from '@nestjs/common'; import { TypeOrmModule } from '@nestjs/typeorm'; -import { RequestModule } from './modules/requests/request.module'; -import { SessionModule } from './modules/sessions/session.module'; -import { TestRunModule } from './modules/test_runs/testRun.module'; +import { RequestModule } from './requests/request.module'; +import { SessionModule } from './sessions/session.module'; +import { TestRunModule } from './test_runs/testRun.module'; import { ConfigModule } from '@nestjs/config'; -import { ProxyAppModule } from './modules/proxyapp/proxyapp.module'; +import { ProxyAppModule } from './proxyapp/proxyapp.module'; @Module({ imports: [ diff --git a/src/utils/data.ts b/packages/client-testing-modules/src/data.ts similarity index 92% rename from src/utils/data.ts rename to packages/client-testing-modules/src/data.ts index 0fd8bdf..24dff03 100644 --- a/src/utils/data.ts +++ b/packages/client-testing-modules/src/data.ts @@ -1,8 +1,8 @@ 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 './requests/request.dto'; +import { Session } from './sessions/session.entity'; export function createRequestObject( id: string, diff --git a/packages/client-testing-modules/src/index.ts b/packages/client-testing-modules/src/index.ts new file mode 100644 index 0000000..f5f8f74 --- /dev/null +++ b/packages/client-testing-modules/src/index.ts @@ -0,0 +1,6 @@ +import { AppModule } from './app.module'; +import { Request } from './requests/request.entity'; +import { Session } from './sessions/session.entity'; +import { TestRun } from './test_runs/testRun.entity'; + +export { AppModule, Request, Session, TestRun }; diff --git a/src/modules/proxyapp/proxyapp.controller.ts b/packages/client-testing-modules/src/proxyapp/proxyapp.controller.ts similarity index 97% rename from src/modules/proxyapp/proxyapp.controller.ts rename to packages/client-testing-modules/src/proxyapp/proxyapp.controller.ts index 53e0518..e7c78f9 100644 --- a/src/modules/proxyapp/proxyapp.controller.ts +++ b/packages/client-testing-modules/src/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 '../data'; @ApiTags('app') @Controller('app') diff --git a/src/modules/proxyapp/proxyapp.module.ts b/packages/client-testing-modules/src/proxyapp/proxyapp.module.ts similarity index 100% rename from src/modules/proxyapp/proxyapp.module.ts rename to packages/client-testing-modules/src/proxyapp/proxyapp.module.ts diff --git a/src/modules/requests/request.controller.ts b/packages/client-testing-modules/src/requests/request.controller.ts similarity index 100% rename from src/modules/requests/request.controller.ts rename to packages/client-testing-modules/src/requests/request.controller.ts diff --git a/src/modules/requests/request.dto.ts b/packages/client-testing-modules/src/requests/request.dto.ts similarity index 98% rename from src/modules/requests/request.dto.ts rename to packages/client-testing-modules/src/requests/request.dto.ts index 4468b9d..a1d6605 100644 --- a/src/modules/requests/request.dto.ts +++ b/packages/client-testing-modules/src/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 '../types'; export class CreateRequestDto { @ApiProperty({ description: 'Session associated with the request' }) diff --git a/src/modules/requests/request.entity.ts b/packages/client-testing-modules/src/requests/request.entity.ts similarity index 98% rename from src/modules/requests/request.entity.ts rename to packages/client-testing-modules/src/requests/request.entity.ts index e6c4303..6fef1fc 100644 --- a/src/modules/requests/request.entity.ts +++ b/packages/client-testing-modules/src/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 '../types'; @Entity() export class Request { diff --git a/src/modules/requests/request.module.ts b/packages/client-testing-modules/src/requests/request.module.ts similarity index 100% rename from src/modules/requests/request.module.ts rename to packages/client-testing-modules/src/requests/request.module.ts diff --git a/src/modules/requests/request.service.ts b/packages/client-testing-modules/src/requests/request.service.ts similarity index 100% rename from src/modules/requests/request.service.ts rename to packages/client-testing-modules/src/requests/request.service.ts diff --git a/src/modules/sessions/interfaces.ts b/packages/client-testing-modules/src/sessions/interfaces.ts similarity index 100% rename from src/modules/sessions/interfaces.ts rename to packages/client-testing-modules/src/sessions/interfaces.ts diff --git a/src/modules/sessions/session.controller.ts b/packages/client-testing-modules/src/sessions/session.controller.ts similarity index 100% rename from src/modules/sessions/session.controller.ts rename to packages/client-testing-modules/src/sessions/session.controller.ts diff --git a/src/modules/sessions/session.dto.ts b/packages/client-testing-modules/src/sessions/session.dto.ts similarity index 100% rename from src/modules/sessions/session.dto.ts rename to packages/client-testing-modules/src/sessions/session.dto.ts diff --git a/src/modules/sessions/session.entity.ts b/packages/client-testing-modules/src/sessions/session.entity.ts similarity index 100% rename from src/modules/sessions/session.entity.ts rename to packages/client-testing-modules/src/sessions/session.entity.ts diff --git a/src/modules/sessions/session.module.ts b/packages/client-testing-modules/src/sessions/session.module.ts similarity index 100% rename from src/modules/sessions/session.module.ts rename to packages/client-testing-modules/src/sessions/session.module.ts diff --git a/src/modules/sessions/session.service.ts b/packages/client-testing-modules/src/sessions/session.service.ts similarity index 100% rename from src/modules/sessions/session.service.ts rename to packages/client-testing-modules/src/sessions/session.service.ts diff --git a/src/modules/test_runs/testRun.controller.ts b/packages/client-testing-modules/src/test_runs/testRun.controller.ts similarity index 99% rename from src/modules/test_runs/testRun.controller.ts rename to packages/client-testing-modules/src/test_runs/testRun.controller.ts index 54b7bd8..22c53cb 100644 --- a/src/modules/test_runs/testRun.controller.ts +++ b/packages/client-testing-modules/src/test_runs/testRun.controller.ts @@ -4,8 +4,8 @@ import { InitiateTestRunDto } from './testRun.dto'; import { Response } from 'express'; import { runCLI } from '@jest/core'; import { TestRunService } from './testRun.service'; -import { SessionService } from '../sessions/session.service'; import { TestRun } from './testRun.entity'; +import { SessionService } from '../sessions/session.service'; const testOptions = { globalSetup: './src/utils/setup/jest.setup.ts', @@ -23,7 +23,7 @@ export class TestRunController { constructor( private readonly testRunService: TestRunService, private readonly sessionService: SessionService, - ) { } + ) {} @Post() @ApiOperation({ summary: 'Create a new test session' }) diff --git a/src/modules/test_runs/testRun.dto.ts b/packages/client-testing-modules/src/test_runs/testRun.dto.ts similarity index 95% rename from src/modules/test_runs/testRun.dto.ts rename to packages/client-testing-modules/src/test_runs/testRun.dto.ts index 96ffcd5..56934b8 100644 --- a/src/modules/test_runs/testRun.dto.ts +++ b/packages/client-testing-modules/src/test_runs/testRun.dto.ts @@ -1,7 +1,7 @@ import { ApiProperty } from '@nestjs/swagger'; import { json } from 'node:stream/consumers'; -import { jsonbType } from 'src/utils/types'; import { Session } from '../sessions/session.entity'; +import { jsonbType } from '../types'; export class CreateTestRunDto { @ApiProperty({ diff --git a/src/modules/test_runs/testRun.entity.ts b/packages/client-testing-modules/src/test_runs/testRun.entity.ts similarity index 93% rename from src/modules/test_runs/testRun.entity.ts rename to packages/client-testing-modules/src/test_runs/testRun.entity.ts index 6d71d0b..cc8d606 100644 --- a/src/modules/test_runs/testRun.entity.ts +++ b/packages/client-testing-modules/src/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 '../types'; +import { Column, CreateDateColumn, Entity, ManyToOne, PrimaryGeneratedColumn } from 'typeorm'; @Entity() export class TestRun { diff --git a/src/modules/test_runs/testRun.module.ts b/packages/client-testing-modules/src/test_runs/testRun.module.ts similarity index 100% rename from src/modules/test_runs/testRun.module.ts rename to packages/client-testing-modules/src/test_runs/testRun.module.ts diff --git a/src/modules/test_runs/testRun.service.ts b/packages/client-testing-modules/src/test_runs/testRun.service.ts similarity index 100% rename from src/modules/test_runs/testRun.service.ts rename to packages/client-testing-modules/src/test_runs/testRun.service.ts diff --git a/src/utils/types.ts b/packages/client-testing-modules/src/types.ts similarity index 100% rename from src/utils/types.ts rename to packages/client-testing-modules/src/types.ts diff --git a/packages/client-testing-modules/tsconfig.json b/packages/client-testing-modules/tsconfig.json new file mode 100644 index 0000000..9f65283 --- /dev/null +++ b/packages/client-testing-modules/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/src/main.ts b/src/main.ts index 1100c5b..92cff58 100644 --- a/src/main.ts +++ b/src/main.ts @@ -1,8 +1,8 @@ import { NestFactory } from '@nestjs/core'; -import { AppModule } from './app.module'; import 'reflect-metadata'; import { DocumentBuilder, SwaggerModule } from '@nestjs/swagger'; import { initialValidateResource } from '@beda.software/fhir-validator'; +import { AppModule } from '@beda.software/client-testing-modules'; async function bootstrap() { const app = await NestFactory.create(AppModule, { cors: true }); diff --git a/src/suites/1.0.0-ballot/Patient/patients.spec.ts b/src/suites/1.0.0-ballot/Patient/patients.spec.ts index b385552..9f6d0a9 100644 --- a/src/suites/1.0.0-ballot/Patient/patients.spec.ts +++ b/src/suites/1.0.0-ballot/Patient/patients.spec.ts @@ -4,7 +4,7 @@ import { getRequestsWithUnavailableComboSearchParams, getRequestsWithUnavailableSearchParams, } from '../../../utils/clientTestingHelpers'; -import { Request } from '../../../modules/requests/request.entity'; +import { Request } from '../../../../packages/client-testing-modules/src/requests/request.entity'; import { isResourceValid } from '@beda.software/fhir-validator'; // function patientRequestsOnlyAvailableInteractionsExists(requests: Request[]): boolean { diff --git a/src/utils/clientTestingHelpers.spec.ts b/src/utils/clientTestingHelpers.spec.ts index 2b6d9f4..12057f8 100644 --- a/src/utils/clientTestingHelpers.spec.ts +++ b/src/utils/clientTestingHelpers.spec.ts @@ -1,13 +1,11 @@ import { DataSource } from 'typeorm'; -import { Request } from '../modules/requests/request.entity'; -import { Session } from '../modules/sessions/session.entity'; -import { TestRun } from '../modules/test_runs/testRun.entity'; +import { Request, Session, TestRun } from '@beda.software/client-testing-modules'; import { getRequestsWithUnavailableComboSearchParams, getRequestsWithUnavailableSearchParams, } from './clientTestingHelpers'; import { v4 as uuidv4 } from 'uuid'; -import { createRequestObject } from './data'; +import { createRequestObject } from '../../packages/client-testing-modules/src/data'; const TestDataSource = new DataSource({ type: 'postgres', diff --git a/src/utils/clientTestingHelpers.ts b/src/utils/clientTestingHelpers.ts index 5b0ff92..42e9e54 100644 --- a/src/utils/clientTestingHelpers.ts +++ b/src/utils/clientTestingHelpers.ts @@ -1,4 +1,4 @@ -import { Request } from 'src/modules/requests/request.entity'; +import { Request } from 'packages/client-testing-modules/src/requests/request.entity'; import { Repository } from 'typeorm'; /** diff --git a/src/utils/setup/jest.setup.ts b/src/utils/setup/jest.setup.ts index 57c591b..b3f4df5 100644 --- a/src/utils/setup/jest.setup.ts +++ b/src/utils/setup/jest.setup.ts @@ -1,7 +1,5 @@ +import { Session, Request, TestRun } from '@beda.software/client-testing-modules'; import { DataSource } from 'typeorm'; -import { Request } from '../../modules/requests/request.entity'; -import { Session } from '../../modules/sessions/session.entity'; -import { TestRun } from '../../modules/test_runs/testRun.entity'; const TestDataSource = new DataSource({ type: 'postgres', 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" - } -}