Skip to content

Commit

Permalink
feat: choice presenter persistence
Browse files Browse the repository at this point in the history
  • Loading branch information
collettemathieu committed Oct 11, 2024
1 parent bf2d801 commit 20f4ced
Show file tree
Hide file tree
Showing 42 changed files with 538 additions and 91 deletions.
53 changes: 36 additions & 17 deletions apps/pathway-design/server/src/app/app.module.ts
Original file line number Diff line number Diff line change
@@ -1,25 +1,44 @@
import { Module } from '@nestjs/common';

import { PDSPIPPathwayPersistenceInfrastructureModule } from '@bewoak/pathway-design-server-pathway-infrastructure';
import {
PDSPIPPathwayPersistenceInfrastructureModule,
type PDSPIPPersistenceDriverAuthorized,
} from '@bewoak/pathway-design-server-pathway-infrastructure';
import {
PDSPIAChangeTitlePathwayInterfaceAdaptersModule,
PDSPIAInitializePathwayInterfaceAdaptersModule,
} from '@bewoak/pathway-design-server-pathway-interface-adapters';
import { PDSPPPathwayPresentersModule } from '@bewoak/pathway-design-server-pathway-presenters';
import {
PDSPPPathwayPresentersModule,
type PDSPPPresenterDriverAuthorized,
} from '@bewoak/pathway-design-server-pathway-presenters';
import { CqrsModule } from '@nestjs/cqrs';

@Module({
imports: [
PDSPIAChangeTitlePathwayInterfaceAdaptersModule.withPresenter(PDSPPPathwayPresentersModule.use('toJson'))
.withPersistence(PDSPIPPathwayPersistenceInfrastructureModule.use('inMemory'))
.build(),
PDSPIAInitializePathwayInterfaceAdaptersModule.withPresenter(PDSPPPathwayPresentersModule.use('toJson'))
.withPersistence(PDSPIPPathwayPersistenceInfrastructureModule.use('inMemory'))
.build(),
CqrsModule.forRoot(),
CqrsModule.forRoot(),
],
controllers: [],
providers: [],
})
export class AppModule {}
interface ApplicationBootstrapOptions {
persistenceDriver: PDSPIPPersistenceDriverAuthorized;
presenterDriver: PDSPPPresenterDriverAuthorized;
}

@Module({})
// biome-ignore lint/complexity/noStaticOnlyClass: <explanation>
export class AppModule {
static register(options: ApplicationBootstrapOptions) {
return {
module: AppModule,
imports: [
PDSPIAChangeTitlePathwayInterfaceAdaptersModule.withPresenter(
PDSPPPathwayPresentersModule.use(options.presenterDriver)
)
.withPersistence(PDSPIPPathwayPersistenceInfrastructureModule.use(options.persistenceDriver))
.build(),
PDSPIAInitializePathwayInterfaceAdaptersModule.withPresenter(
PDSPPPathwayPresentersModule.use(options.presenterDriver)
)
.withPersistence(PDSPIPPathwayPersistenceInfrastructureModule.use(options.persistenceDriver))
.build(),
CqrsModule.forRoot(),
CqrsModule.forRoot(),
],
};
}
}
10 changes: 10 additions & 0 deletions apps/pathway-design/server/src/environment/env.schema.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { pDSPIPPersistenceKeys } from '@bewoak/pathway-design-server-pathway-infrastructure';
import { pDSPPPresenterKeys } from '@bewoak/pathway-design-server-pathway-presenters';
import { z } from 'zod';

export const envSchema = z.object({
GLOBAL_PREFIX: z.string(),
PERSISTENCE_DRIVER: z.enum(pDSPIPPersistenceKeys),
PORT: z.string().transform((value) => Number.parseInt(value, 10)),
PRESENTER_DRIVER: z.enum(pDSPPPresenterKeys),
});
57 changes: 27 additions & 30 deletions apps/pathway-design/server/src/main.ts
Original file line number Diff line number Diff line change
@@ -1,40 +1,37 @@
/**
* This is not a production server yet!
* This is only a minimal backend to get started.
*/

import { Logger } from '@nestjs/common';
import { NestFactory } from '@nestjs/core';

import { DocumentBuilder, SwaggerModule } from '@nestjs/swagger';
import { AppModule } from './app/app.module';

import { cCSECheckEnvironmentVariables, cCSEGetEnvironmentVariables } from '@bewoak/common-configs-server-env';
import { cCSSSetupSwaggerDocument } from '@bewoak/common-configs-server-swagger';
import { envSchema } from './environment/env.schema';

async function bootstrap() {
const app = await NestFactory.create(AppModule, { bufferLogs: true });
const globalPrefix = 'api';
cCSECheckEnvironmentVariables(envSchema);

const env = cCSEGetEnvironmentVariables(envSchema);
const persistenceDriver = env.PERSISTENCE_DRIVER;
const presenterDriver = env.PRESENTER_DRIVER;
const port = env.PORT;
const globalPrefix = env.GLOBAL_PREFIX;

const app = await NestFactory.create(
AppModule.register({
persistenceDriver,
presenterDriver,
}),
{ bufferLogs: true }
);
app.setGlobalPrefix(globalPrefix);
const port = process.env.PORT ?? 3000;

// Setting up Swagger document
const options = new DocumentBuilder()
.setTitle('Pathway design Application')
.setDescription('Application Programming Interface (API) of Pathway design Application')
.setVersion('1.0')
.addBearerAuth(
{
description: 'Please enter token in following format: Bearer <JWT>',
name: 'Authorization',
bearerFormat: 'Bearer',
scheme: 'Bearer',
type: 'http',
in: 'Header',
},
'access-token'
)
.build();
const document = SwaggerModule.createDocument(app, options);

SwaggerModule.setup('api', app, document);

cCSSSetupSwaggerDocument(app, {
description: 'API for Pathway Design',
hasBearerAuth: true,
path: 'api',
title: 'Pathway Design API',
version: '1.0',
});

await app.listen(port);
Logger.log(`🚀 Application is running on: http://localhost:${port}/${globalPrefix}`);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
Feature: Platform - Change the title of a pathway in a memory database with json presenter
Feature: Platform - Change the title of a pathway

Scenario: I want to change the title of a learning pathway on the platform
Given I am authenticated on the platform for change the title of the pathway in memory persistence and json presenter
Given I have a pathway on the platform recorded in memory with these data
Given I am authenticated on the platform for change the title of the pathway with "<presenter>" and "<persistence>"
Given I have a pathway on the platform with these data
| title | description | researchField |
| My Pathway | A test pathway | biology |
When I want to change the title of the pathway on the platform "My New Pathway"
Then I should receive from the platform the new title of the pathway
| title |
| My New Pathway |

Examples:
| presenter | persistence |
| toJson | inMemory |
Original file line number Diff line number Diff line change
@@ -1,16 +1,22 @@
import { PDSPIPPathwayPersistenceInfrastructureModule } from '@bewoak/pathway-design-server-pathway-infrastructure';
import { strict as assert } from 'node:assert';
import type { Http2Server } from 'node:http2';
import {
PDSPIPPathwayPersistenceInfrastructureModule,
type PDSPIPPersistenceDriverAuthorized,
} from '@bewoak/pathway-design-server-pathway-infrastructure';
import {
PDSPIAChangeTitlePathwayInterfaceAdaptersModule,
PDSPIAInitializePathwayInterfaceAdaptersModule,
} from '@bewoak/pathway-design-server-pathway-interface-adapters';
import { PDSPPPathwayPresentersModule } from '@bewoak/pathway-design-server-pathway-presenters';
import {
PDSPPPathwayPresentersModule,
type PDSPPPresenterDriverAuthorized,
} from '@bewoak/pathway-design-server-pathway-presenters';
import type { DataTable } from '@cucumber/cucumber';
import type { INestApplication } from '@nestjs/common';
import { CqrsModule } from '@nestjs/cqrs';
import { Test } from '@nestjs/testing';
import { binding, given, then, when } from 'cucumber-tsflow';
import { strict as assert } from 'node:assert';
import type { Http2Server } from 'node:http2';
import request from 'supertest';

@binding()
Expand All @@ -19,15 +25,15 @@ class ControllerSteps {
private httpServer: Http2Server;
private response: request.Response;

@given('I am authenticated on the platform for change the title of the pathway in memory persistence and json presenter')
public async connectToPlatform() {
@given('I am authenticated on the platform for change the title of the pathway with {string} and {string}')
public async connectToPlatform(presenter: PDSPPPresenterDriverAuthorized, persistence: PDSPIPPersistenceDriverAuthorized) {
const testingModule = await Test.createTestingModule({
imports: [
PDSPIAChangeTitlePathwayInterfaceAdaptersModule.withPresenter(PDSPPPathwayPresentersModule.use('toJson'))
.withPersistence(PDSPIPPathwayPersistenceInfrastructureModule.use('inMemory'))
PDSPIAChangeTitlePathwayInterfaceAdaptersModule.withPresenter(PDSPPPathwayPresentersModule.use(presenter))
.withPersistence(PDSPIPPathwayPersistenceInfrastructureModule.use(persistence))
.build(),
PDSPIAInitializePathwayInterfaceAdaptersModule.withPresenter(PDSPPPathwayPresentersModule.use('toJson'))
.withPersistence(PDSPIPPathwayPersistenceInfrastructureModule.use('inMemory'))
PDSPIAInitializePathwayInterfaceAdaptersModule.withPresenter(PDSPPPathwayPresentersModule.use(presenter))
.withPersistence(PDSPIPPathwayPersistenceInfrastructureModule.use(persistence))
.build(),
CqrsModule.forRoot(),
],
Expand All @@ -38,7 +44,7 @@ class ControllerSteps {
this.httpServer = this.app.getHttpServer();
}

@given('I have a pathway on the platform recorded in memory with these data')
@given('I have a pathway on the platform with these data')
public async givenIHaveAPathwayRecordedInMemroy(dataTable: DataTable) {
const firstRow = dataTable.hashes()[0];

Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
Feature: Platform - Initialize Pathway in a memory database with json presenter
Feature: Platform - Initialize a Pathway

Scenario: I want to initialize a learning pathway on the platform
Given I am authenticated on the platform for initialize a pathway in memory persistence and json presenter
Given I am authenticated on the platform for initialize a pathway with "<presenter>" and "<persistence>"
When I want to initialize on the platform a pathway with these data
| title | description | researchField |
| My Pathway | A test pathway | biology |
Then I should retrieve from the platform a pathway initialized with its data
| title | description | researchField |
| My Pathway | A test pathway | biology |
Then The pathway received from the platform should be have a unique identifier



Examples:
| presenter | persistence |
| toJson | inMemory |
Original file line number Diff line number Diff line change
@@ -1,13 +1,19 @@
import { PDSPIPPathwayPersistenceInfrastructureModule } from '@bewoak/pathway-design-server-pathway-infrastructure';
import { strict as assert } from 'node:assert';
import type { Http2Server } from 'node:http2';
import {
PDSPIPPathwayPersistenceInfrastructureModule,
type PDSPIPPersistenceDriverAuthorized,
} from '@bewoak/pathway-design-server-pathway-infrastructure';
import { PDSPIAInitializePathwayInterfaceAdaptersModule } from '@bewoak/pathway-design-server-pathway-interface-adapters';
import { PDSPPPathwayPresentersModule } from '@bewoak/pathway-design-server-pathway-presenters';
import {
PDSPPPathwayPresentersModule,
type PDSPPPresenterDriverAuthorized,
} from '@bewoak/pathway-design-server-pathway-presenters';
import type { DataTable } from '@cucumber/cucumber';
import type { INestApplication } from '@nestjs/common';
import { CqrsModule } from '@nestjs/cqrs';
import { Test } from '@nestjs/testing';
import { binding, given, then, when } from 'cucumber-tsflow';
import { strict as assert } from 'node:assert';
import type { Http2Server } from 'node:http2';
import request from 'supertest';

@binding()
Expand All @@ -16,12 +22,12 @@ class ControllerSteps {
private httpServer: Http2Server;
private response: request.Response;

@given('I am authenticated on the platform for initialize a pathway in memory persistence and json presenter')
public async connectToServer() {
@given('I am authenticated on the platform for initialize a pathway with {string} and {string}')
public async connectToServer(presenter: PDSPPPresenterDriverAuthorized, persistence: PDSPIPPersistenceDriverAuthorized) {
const testingModule = await Test.createTestingModule({
imports: [
PDSPIAInitializePathwayInterfaceAdaptersModule.withPresenter(PDSPPPathwayPresentersModule.use('toJson'))
.withPersistence(PDSPIPPathwayPersistenceInfrastructureModule.use('inMemory'))
PDSPIAInitializePathwayInterfaceAdaptersModule.withPresenter(PDSPPPathwayPresentersModule.use(presenter))
.withPersistence(PDSPIPPathwayPersistenceInfrastructureModule.use(persistence))
.build(),
CqrsModule.forRoot(),
],
Expand Down
3 changes: 3 additions & 0 deletions biome.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@
"noVoidTypeReturn": {
"level": "error"
}
},
"complexity": {
"noForEach": "off"
}
}
},
Expand Down
Binary file modified bun.lockb
Binary file not shown.
22 changes: 22 additions & 0 deletions libs/common/configs/server/env/.swcrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
{
"jsc": {
"target": "es2022",
"parser": {
"syntax": "typescript",
"decorators": true,
"dynamicImport": true
},
"transform": {
"decoratorMetadata": true,
"legacyDecorator": true
},
"keepClassNames": true,
"externalHelpers": true,
"loose": true
},
"module": {
"type": "es6"
},
"sourceMaps": true,
"exclude": [".*\\.spec.tsx?$", ".*\\.step.ts$", ".*\\.test.tsx?$", ".*.js$"]
}
17 changes: 17 additions & 0 deletions libs/common/configs/server/env/biome.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
"$schema": "../../../../../node_modules/@biomejs/biome/configuration_schema.json",
"extends": ["../../../../../biome.json"],
"linter": {
"rules": {
"nursery": {
"noRestrictedImports": {
"options": {
"paths": {}
},
"level": "error"
}
}
}
},
"overrides": [{}]
}
11 changes: 11 additions & 0 deletions libs/common/configs/server/env/cucumber.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
module.exports = {
default: {
paths: ['libs/common/configs/server/env/src/lib/**/*.feature'],
requireModule: ['ts-node/register', 'tsconfig-paths/register'],
require: ['libs/common/configs/server/env/src/lib/**/*.step.ts'],
format: [
'json:dist/reports/libs/common/configs/server/env/test-feature/index.json',
'html:dist/reports/libs/common/configs/server/env/test-feature/index.html',
],
},
};
9 changes: 9 additions & 0 deletions libs/common/configs/server/env/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"name": "@bewoak/common-configs-server-env",
"version": "0.0.1",
"dependencies": {
"@swc/helpers": "~0.5.11"
},
"main": "./src/index.js",
"typings": "./src/index.d.ts"
}
Loading

0 comments on commit 20f4ced

Please sign in to comment.