Skip to content

Commit

Permalink
Add packages structure
Browse files Browse the repository at this point in the history
Ref: #7
  • Loading branch information
projkov committed Sep 6, 2024
1 parent 8f4c5fd commit 793311a
Show file tree
Hide file tree
Showing 42 changed files with 215 additions and 67 deletions.
2 changes: 1 addition & 1 deletion compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ services:
build:
context: ./
dockerfile: Dockerfile
command: yarn test
command: yarn test --testList=true
depends_on:
- postgres
profiles:
Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
"author": "",
"private": true,
"license": "UNLICENSED",
"workspaces": ["packages/*"],
"scripts": {
"build": "nest build",
"format": "prettier --write \"src/**/*.ts\" \"test/**/*.ts\"",
Expand Down Expand Up @@ -70,7 +71,7 @@
"ts"
],
"testTimeout": 30000,
"rootDir": "src",
"rootDir": ".",
"testRegex": ".*\\.spec\\.ts$",
"transform": {
"^.+\\.(t|j)s$": "ts-jest"
Expand Down
11 changes: 11 additions & 0 deletions packages/client-testing-helpers/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"name": "@beda.software/client-testing-helpers",
"version": "0.0.1",
"description": "",
"main": "dist/index.js",
"scripts": {
"prepare": "tsc"
},
"author": "",
"license": "ISC"
}
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 '@beda.software/client-testing-modules';
import { Repository } from 'typeorm';

/**
Expand Down
22 changes: 22 additions & 0 deletions packages/client-testing-helpers/tsconfig.json
Original file line number Diff line number Diff line change
@@ -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
}
}
11 changes: 11 additions & 0 deletions packages/client-testing-modules/package.json
Original file line number Diff line number Diff line change
@@ -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"
}
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
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 } from '../../packages/client-testing-modules/src/requests/request.entity';
import { Session } from '../../packages/client-testing-modules/src/sessions/session.entity';
import { TestRun } from '../../packages/client-testing-modules/src/test_runs/testRun.entity';
import { v4 as uuidv4 } from 'uuid';
import { createRequestObject } from '@beda.software/proxy-helpers';
import {
getRequestsWithUnavailableComboSearchParams,
getRequestsWithUnavailableSearchParams,
} from './clientTestingHelpers';
import { v4 as uuidv4 } from 'uuid';
import { createRequestObject } from './data';
} from '@beda.software/client-testing-helpers';

const TestDataSource = new DataSource({
type: 'postgres',
Expand Down
21 changes: 21 additions & 0 deletions packages/client-testing-modules/src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import { ProxyAppController } from './proxyapp/proxyapp.controller';
import { ProxyAppModule } from './proxyapp/proxyapp.module';
import { RequestController } from './requests/request.controller';
import { RequestModule } from './requests/request.module';
import { Request } from './requests/request.entity';
import { SessionController } from './sessions/session.controller';
import { SessionModule } from './sessions/session.module';
import { TestRunController } from './test_runs/testRun.controller';
import { TestRunModule } from './test_runs/testRun.module';

export {
ProxyAppController,
ProxyAppModule,
RequestController,
RequestModule,
Request,
SessionController,
SessionModule,
TestRunController,
TestRunModule,
};
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 'src/utils/responses';
import { RequestService } from '../requests/request.service';
import { SessionService } from '../sessions/session.service';
import { Request, Response } from 'express';
import { createRequestObject } from '@beda.software/proxy-helpers';
import { captureResponseBody } from '../utils';

@ApiTags('app')
@Controller('app')
Expand Down
File renamed without changes.
File renamed without changes.
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 '../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 '../types';

@Entity()
export class Request {
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -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({
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 '../types';

@Entity()
export class TestRun {
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
22 changes: 22 additions & 0 deletions packages/client-testing-modules/tsconfig.json
Original file line number Diff line number Diff line change
@@ -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,
}
}
11 changes: 11 additions & 0 deletions packages/fhir-validator/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"name": "@beda.software/fhir-validator",
"version": "0.0.1",
"description": "",
"main": "dist/index.js",
"scripts": {
"prepare": "tsc"
},
"author": "",
"license": "ISC"
}
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import axios from 'axios';
import { validateResource } from './services';
import { timeout } from 'rxjs';
import { validateResource } from '@beda.software/fhir-validator';

jest.mock('axios');
const mockedAxios = axios as jest.Mocked<typeof axios>;
Expand Down
22 changes: 22 additions & 0 deletions packages/fhir-validator/tsconfig.json
Original file line number Diff line number Diff line change
@@ -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
}
}
11 changes: 11 additions & 0 deletions packages/proxy-helpers/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"name": "@beda.software/proxy-helpers",
"version": "0.0.1",
"description": "",
"main": "dist/index.js",
"scripts": {
"prepare": "tsc"
},
"author": "",
"license": "ISC"
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { getFHIRAction } from './helpers';
import { getFHIRAction } from '@beda.software/proxy-helpers';

describe('getFHIRAction', () => {
test.each([
Expand Down
39 changes: 36 additions & 3 deletions src/utils/data.ts → packages/proxy-helpers/src/index.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 './helpers';
import { CreateRequestDto } from 'packages/client-testing-modules/src/requests/request.dto';
import { Session } from 'packages/client-testing-modules/src/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
22 changes: 22 additions & 0 deletions packages/proxy-helpers/tsconfig.json
Original file line number Diff line number Diff line change
@@ -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
}
}
5 changes: 1 addition & 4 deletions src/app.module.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
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 { ConfigModule } from '@nestjs/config';
import { ProxyAppModule } from './modules/proxyapp/proxyapp.module';
import { SessionModule, RequestModule, TestRunModule, ProxyAppModule } from '@beda.software/client-testing-modules';

@Module({
imports: [
Expand Down
2 changes: 1 addition & 1 deletion src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { NestFactory } from '@nestjs/core';
import { AppModule } from './app.module';
import 'reflect-metadata';
import { DocumentBuilder, SwaggerModule } from '@nestjs/swagger';
import { initialValidateResource } from './utils/services';
import { initialValidateResource } from '@beda.software/fhir-validator';

async function bootstrap() {
const app = await NestFactory.create(AppModule, { cors: true });
Expand Down
6 changes: 3 additions & 3 deletions src/suites/1.0.0-ballot/Patient/patients.spec.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { In, Not } from 'typeorm';
import { Patient } from 'fhir/r4';
import { Request } from '@beda.software/client-testing-modules';
import {
getRequestsWithUnavailableComboSearchParams,
getRequestsWithUnavailableSearchParams,
} from '../../../utils/clientTestingHelpers';
import { isResourceValid } from '../../../utils/services';
import { Request } from '../../../modules/requests/request.entity';
} from '@beda.software/client-testing-helpers';
import { isResourceValid } from '@beda.software/fhir-validator';

// function patientRequestsOnlyAvailableInteractionsExists(requests: Request[]): boolean {
// const availableInteractions = ['READ', 'SEARCH', 'CREATE', 'UPDATE'];
Expand Down
35 changes: 0 additions & 35 deletions src/utils/helpers.ts

This file was deleted.

Loading

0 comments on commit 793311a

Please sign in to comment.