Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add app package #11

Merged
merged 6 commits into from
Sep 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,6 @@ COPY . .

RUN yarn install

WORKDIR /app/packages/app

EXPOSE 8080
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
$(compose) $(dev_env) $(dev_profile) build --no-cache

up:
$(compose) $(dev_env) $(dev_profile) up
Expand Down
75 changes: 4 additions & 71 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
}
File renamed without changes.
File renamed without changes.
86 changes: 86 additions & 0 deletions packages/app/package.json
Original file line number Diff line number Diff line change
@@ -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"
}
}
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -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')
Expand Down
Original file line number Diff line number Diff line change
@@ -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' })
Expand Down
Original file line number Diff line number Diff line change
@@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
Original file line number Diff line number Diff line change
@@ -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 {
Expand Down
Original file line number Diff line number Diff line change
@@ -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',
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import { patientDemoTestDB } from '@beda.software/client-testing-demo-tests-db';

patientDemoTestDB();
3 changes: 3 additions & 0 deletions packages/app/src/suites/1.0.0-ballot/Patient/patient.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import { patientDemoTest } from '@beda.software/client-testing-demo-tests-standard';

patientDemoTest();
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Request } from 'src/modules/requests/request.entity';
import { Request } from '../modules/requests/request.entity';
import { Repository } from 'typeorm';

/**
Expand Down
18 changes: 17 additions & 1 deletion src/utils/data.spec.ts → packages/app/src/utils/data.spec.ts
Original file line number Diff line number Diff line change
@@ -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 () => {
Expand Down
39 changes: 36 additions & 3 deletions src/utils/data.ts → packages/app/src/utils/data.ts
Original file line number Diff line number Diff line change
@@ -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,
Expand Down
File renamed without changes.
4 changes: 4 additions & 0 deletions packages/app/tsconfig.build.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"extends": "./tsconfig.json",
"exclude": ["node_modules", "test", "dist", "**/*spec.ts"]
}
Original file line number Diff line number Diff line change
@@ -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"
Expand Down
Loading
Loading