From c7a7538da51606f469cfbe370d11d3854c943778 Mon Sep 17 00:00:00 2001 From: Mathieu Collette Date: Wed, 18 Sep 2024 18:25:16 +0200 Subject: [PATCH] refactor: test change title --- .hooks/commit-msg | 2 +- .../server/src/app/app.module.ts | 4 +- apps/pathway-design/server/src/main.ts | 11 +-- .../specs/initialize-pathway/index.step.ts | 26 ++---- apps/pathway-design/server/webpack.config.js | 3 +- biome.json | 22 +---- .../tools/server/http-exceptions/cucumber.js | 8 +- .../server/pathway/application/cucumber.js | 8 +- .../change-title-pathway.usecase.feature | 26 +++--- .../change-title-pathway.usecase.step.ts | 93 +++++++++---------- .../usecase/change-title-pathway.usecase.ts | 5 +- .../initialize-pathway.command-handler.ts | 10 +- .../service/initialize-pathway.service.ts | 5 +- .../specs/initialize-pathway.usecase.step.ts | 16 +--- .../usecase/initialize-pathway.usecase.ts | 3 +- .../server/pathway/business/cucumber.js | 8 +- .../src/lib/factories/pathway.factory.spec.ts | 16 +--- .../initialize-pathway-persitence.port.ts | 8 +- .../presenters/pathway-presenter.port.ts | 8 +- .../src/lib/specs/change-name/.gitkeep | 0 .../change-name/change-title-pathway.feature | 15 +++ .../change-name/change-title-pathway.step.ts | 49 ++++++++++ ...way.feature => initialize-pathway.feature} | 27 ++---- ...way.step.ts => initialize-pathway.step.ts} | 54 ++++++----- .../description.value-object.spec.ts | 4 +- .../pathway-id.value-object.spec.ts | 28 ++---- .../value-objects/pathway-id.value-object.ts | 7 +- .../research-field.value-object.spec.ts | 20 +--- .../value-objects/title.value-object.spec.ts | 4 +- .../server/pathway/infrastructure/cucumber.js | 8 +- .../mappers/in-memory-pathway.mapper.ts | 13 +-- ...lize-pathway-in-memory.persistence.spec.ts | 57 ++++-------- ...nitialize-pathway-in-memory.persistence.ts | 16 +--- ...thway-persistence-infrastructure.module.ts | 5 +- .../pathway/interface-adapters/cucumber.js | 8 +- .../initialize-pathway.controller.ts | 24 +---- .../dtos/response/body/response-body.dto.ts | 4 +- ...alize-pathway-interface-adapters.module.ts | 14 +-- .../server/pathway/presenters/cucumber.js | 8 +- .../src/lib/pathway-presenters.module.ts | 5 +- .../lib/toJson/to-json-pathway.presenter.ts | 5 +- tsconfig.base.json | 16 +--- 42 files changed, 256 insertions(+), 417 deletions(-) delete mode 100644 libs/pathway-design/server/pathway/business/src/lib/specs/change-name/.gitkeep create mode 100644 libs/pathway-design/server/pathway/business/src/lib/specs/change-name/change-title-pathway.feature create mode 100644 libs/pathway-design/server/pathway/business/src/lib/specs/change-name/change-title-pathway.step.ts rename libs/pathway-design/server/pathway/business/src/lib/specs/initialize/{pathway.feature => initialize-pathway.feature} (82%) rename libs/pathway-design/server/pathway/business/src/lib/specs/initialize/{pathway.step.ts => initialize-pathway.step.ts} (69%) diff --git a/.hooks/commit-msg b/.hooks/commit-msg index 07ed5ce8..f82844ff 100755 --- a/.hooks/commit-msg +++ b/.hooks/commit-msg @@ -1,3 +1,3 @@ -# #!/bin/sh +#!/bin/sh echo "Checking with commitlint...." bun run commitlint --edit $1 diff --git a/apps/pathway-design/server/src/app/app.module.ts b/apps/pathway-design/server/src/app/app.module.ts index 6e66b605..6f815ec9 100644 --- a/apps/pathway-design/server/src/app/app.module.ts +++ b/apps/pathway-design/server/src/app/app.module.ts @@ -8,9 +8,7 @@ import { CqrsModule } from '@nestjs/cqrs'; @Module({ imports: [ PDSPIAInitializePathwayInterfaceAdaptersModule.withPersistence( - PDSPIInitializePathwayPersistenceInfrastructureModule.use( - 'inMemory' - ) + PDSPIInitializePathwayPersistenceInfrastructureModule.use('inMemory') ) .withPresenter(PDSPPPathwayPresentersModule.use('toJson')) .build(), diff --git a/apps/pathway-design/server/src/main.ts b/apps/pathway-design/server/src/main.ts index 7fc154a7..85148de1 100644 --- a/apps/pathway-design/server/src/main.ts +++ b/apps/pathway-design/server/src/main.ts @@ -18,14 +18,11 @@ async function bootstrap() { // Setting up Swagger document const options = new DocumentBuilder() .setTitle('Pathway design Application') - .setDescription( - 'Application Programming Interface (API) of Pathway design Application' - ) + .setDescription('Application Programming Interface (API) of Pathway design Application') .setVersion('1.0') .addBearerAuth( { - description: - 'Please enter token in following format: Bearer ', + description: 'Please enter token in following format: Bearer ', name: 'Authorization', bearerFormat: 'Bearer', scheme: 'Bearer', @@ -40,9 +37,7 @@ async function bootstrap() { SwaggerModule.setup('api', app, document); await app.listen(port); - Logger.log( - `🚀 Application is running on: http://localhost:${port}/${globalPrefix}` - ); + Logger.log(`🚀 Application is running on: http://localhost:${port}/${globalPrefix}`); } bootstrap(); diff --git a/apps/pathway-design/server/src/specs/initialize-pathway/index.step.ts b/apps/pathway-design/server/src/specs/initialize-pathway/index.step.ts index bd72876c..065d0414 100644 --- a/apps/pathway-design/server/src/specs/initialize-pathway/index.step.ts +++ b/apps/pathway-design/server/src/specs/initialize-pathway/index.step.ts @@ -21,9 +21,7 @@ class ControllerSteps { const module = await Test.createTestingModule({ imports: [ PDSPIAInitializePathwayInterfaceAdaptersModule.withPersistence( - PDSPIInitializePathwayPersistenceInfrastructureModule.use( - 'inMemory' - ) + PDSPIInitializePathwayPersistenceInfrastructureModule.use('inMemory') ) .withPresenter(PDSPPPathwayPresentersModule.use('toJson')) .build(), @@ -40,13 +38,11 @@ class ControllerSteps { public async whenIInitiateAPathway(dataTable: DataTable) { const firstRow = dataTable.hashes()[0]; - this.response = await request(this.httpServer) - .post('/pathway/init') - .send({ - title: firstRow.title, - description: firstRow.description, - researchField: firstRow.researchField, - }); + this.response = await request(this.httpServer).post('/pathway/init').send({ + title: firstRow.title, + description: firstRow.description, + researchField: firstRow.researchField, + }); } @then('I should retrieve a pathway initialized with its data') @@ -54,14 +50,8 @@ class ControllerSteps { const firstRow = dataTable.hashes()[0]; assert.strictEqual(this.response.body.title, firstRow.title); - assert.strictEqual( - this.response.body.description, - firstRow.description - ); - assert.strictEqual( - this.response.body.researchField, - firstRow.researchField - ); + assert.strictEqual(this.response.body.description, firstRow.description); + assert.strictEqual(this.response.body.researchField, firstRow.researchField); } @then('The pathway should be have a unique identifier') diff --git a/apps/pathway-design/server/webpack.config.js b/apps/pathway-design/server/webpack.config.js index f3c500f9..d56a028f 100644 --- a/apps/pathway-design/server/webpack.config.js +++ b/apps/pathway-design/server/webpack.config.js @@ -13,8 +13,7 @@ module.exports = { tsConfig: './tsconfig.app.json', assets: ['./src/assets'], optimization: process.env.BUN_ENV === 'production', - outputHashing: - process.env.BUN_ENV === 'production' ? 'all' : 'none', + outputHashing: process.env.BUN_ENV === 'production' ? 'all' : 'none', transformers: [{ name: '@nestjs/swagger/plugin' }], }), ], diff --git a/biome.json b/biome.json index 17a3f03a..8033b956 100644 --- a/biome.json +++ b/biome.json @@ -4,31 +4,15 @@ "attributePosition": "auto", "enabled": true, "formatWithErrors": false, - "ignore": [ - "dist", - "coverage", - ".nx", - ".vscode", - "node_modules", - "tmp", - ".angular" - ], + "ignore": ["dist", "coverage", ".nx", ".vscode", "node_modules", "tmp", ".angular"], "indentStyle": "space", "indentWidth": 4, "lineEnding": "lf", - "lineWidth": 80 + "lineWidth": 130 }, "linter": { "enabled": true, - "ignore": [ - "dist", - "coverage", - ".nx", - ".vscode", - "node_modules", - "tmp", - ".angular" - ], + "ignore": ["dist", "coverage", ".nx", ".vscode", "node_modules", "tmp", ".angular"], "rules": { "recommended": true, "suspicious": { diff --git a/libs/common/tools/server/http-exceptions/cucumber.js b/libs/common/tools/server/http-exceptions/cucumber.js index 0b746791..266b2f96 100644 --- a/libs/common/tools/server/http-exceptions/cucumber.js +++ b/libs/common/tools/server/http-exceptions/cucumber.js @@ -1,12 +1,8 @@ module.exports = { default: { - paths: [ - 'libs/common/tools/server/http-exceptions/src/lib/**/*.feature', - ], + paths: ['libs/common/tools/server/http-exceptions/src/lib/**/*.feature'], requireModule: ['ts-node/register', 'tsconfig-paths/register'], - require: [ - 'libs/common/tools/server/http-exceptions/src/lib/**/*.step.ts', - ], + require: ['libs/common/tools/server/http-exceptions/src/lib/**/*.step.ts'], format: [ 'json:dist/reports/libs/common/tools/server/http-exceptions/test-feature/index.json', 'html:dist/reports/libs/common/tools/server/http-exceptions/test-feature/index.html', diff --git a/libs/pathway-design/server/pathway/application/cucumber.js b/libs/pathway-design/server/pathway/application/cucumber.js index 4999a259..44778380 100644 --- a/libs/pathway-design/server/pathway/application/cucumber.js +++ b/libs/pathway-design/server/pathway/application/cucumber.js @@ -1,12 +1,8 @@ module.exports = { default: { - paths: [ - 'libs/pathway-design/server/pathway/application/src/lib/**/*.feature', - ], + paths: ['libs/pathway-design/server/pathway/application/src/lib/**/*.feature'], requireModule: ['ts-node/register', 'tsconfig-paths/register'], - require: [ - 'libs/pathway-design/server/pathway/application/src/lib/**/*.step.ts', - ], + require: ['libs/pathway-design/server/pathway/application/src/lib/**/*.step.ts'], format: [ 'json:dist/reports/libs/pathway-design/server/pathway/application/test-feature/index.json', 'html:dist/reports/libs/pathway-design/server/pathway/application/test-feature/index.html', diff --git a/libs/pathway-design/server/pathway/application/src/lib/change-title/specs/change-title-pathway.usecase.feature b/libs/pathway-design/server/pathway/application/src/lib/change-title/specs/change-title-pathway.usecase.feature index 8f677706..dc8bb11d 100644 --- a/libs/pathway-design/server/pathway/application/src/lib/change-title/specs/change-title-pathway.usecase.feature +++ b/libs/pathway-design/server/pathway/application/src/lib/change-title/specs/change-title-pathway.usecase.feature @@ -1,15 +1,15 @@ -Feature: Change the title of a pathway +# Feature: Change the title of a pathway - Scenario: I want to change the title of a pathway - Given I have a pathway with these data - | title | description | researchField | - | My Pathway | A test pathway | biology | - When I want to change the title of the pathway to "My New Pathway" - Then I should see the title of the pathway changed to "My New Pathway" +# Scenario: I want to change the title of a pathway +# Given I have a pathway with these data +# | title | description | researchField | +# | My Pathway | A test pathway | biology | +# When I want to change the title of the pathway to "My New Pathway" +# Then I should see the title of the pathway changed to "My New Pathway" - Scenario: I want to change the title of a pathway with an empty title - Given I have a pathway with these data - | title | description | researchField | - | My Pathway | A test pathway | biology | - When I want to change the title of the pathway to "" - Then I should see an error message "Title is required" during the title change +# Scenario: I want to change the title of a pathway with an empty title +# Given I have a pathway with these data +# | title | description | researchField | +# | My Pathway | A test pathway | biology | +# When I want to change the title of the pathway to "" +# Then I should see an error message "Title is required" during the title change diff --git a/libs/pathway-design/server/pathway/application/src/lib/change-title/specs/change-title-pathway.usecase.step.ts b/libs/pathway-design/server/pathway/application/src/lib/change-title/specs/change-title-pathway.usecase.step.ts index 9645343c..9908f999 100644 --- a/libs/pathway-design/server/pathway/application/src/lib/change-title/specs/change-title-pathway.usecase.step.ts +++ b/libs/pathway-design/server/pathway/application/src/lib/change-title/specs/change-title-pathway.usecase.step.ts @@ -1,56 +1,51 @@ -import { strict as assert } from 'node:assert'; +// import { strict as assert } from 'node:assert'; -import { - PDSPBEPathwayEntity, - pDSPBFPathwayFactory, -} from '@bewoak/pathway-design-server-pathway-business'; -import type { DataTable } from '@cucumber/cucumber'; -import { binding, given, then, when } from 'cucumber-tsflow'; -import { PDSPBUChangeTitlePathwayUseCase } from '../usecase/change-title-pathway.usecase'; +// import { PDSPBEPathwayEntity, pDSPBFPathwayFactory } from '@bewoak/pathway-design-server-pathway-business'; +// import type { DataTable } from '@cucumber/cucumber'; +// import { binding, given, then, when } from 'cucumber-tsflow'; +// import { PDSPBUChangeTitlePathwayUseCase } from '../usecase/change-title-pathway.usecase'; -@binding() -export default class ControllerSteps { - private PDSPBUchangeTitlePathwayUseCase = - new PDSPBUChangeTitlePathwayUseCase(); - private pDSPBEPathwayEntity: PDSPBEPathwayEntity = - new PDSPBEPathwayEntity(); - private error: Error | undefined; +// @binding() +// export default class ControllerSteps { +// private PDSPBUchangeTitlePathwayUseCase = new PDSPBUChangeTitlePathwayUseCase(); +// private pDSPBEPathwayEntity: PDSPBEPathwayEntity = new PDSPBEPathwayEntity(); +// private error: Error | undefined; - @given('I have a pathway with these data') - public givenIHaveAPathway(dataTable: DataTable) { - const firstRow = dataTable.hashes()[0] as { - title: string; - description: string; - researchField: string; - }; +// @given('I have a pathway with these data') +// public givenIHaveAPathway(dataTable: DataTable) { +// const firstRow = dataTable.hashes()[0] as { +// title: string; +// description: string; +// researchField: string; +// }; - this.pDSPBEPathwayEntity = pDSPBFPathwayFactory({ - title: firstRow.title, - description: firstRow.description, - researchField: firstRow.researchField, - }); - } +// this.pDSPBEPathwayEntity = pDSPBFPathwayFactory({ +// title: firstRow.title, +// description: firstRow.description, +// researchField: firstRow.researchField, +// }); +// } - @when('I want to change the title of the pathway to {string}') - public whenIChangeTheTitleOfThePathwayTo(title: string) { - try { - this.PDSPBUchangeTitlePathwayUseCase.execute({ - pathway: this.pDSPBEPathwayEntity, - title, - }); - } catch (error) { - this.error = error as Error; - } - } +// @when('I want to change the title of the pathway to {string}') +// public whenIChangeTheTitleOfThePathwayTo(title: string) { +// try { +// this.PDSPBUchangeTitlePathwayUseCase.execute({ +// pathway: this.pDSPBEPathwayEntity, +// title, +// }); +// } catch (error) { +// this.error = error as Error; +// } +// } - @then('I should see the title of the pathway changed to {string}') - public thenIShouldSeeTheTitleOfThePathwayChangedTo(title: string) { - assert.strictEqual(this.pDSPBEPathwayEntity.title, title); - } +// @then('I should see the title of the pathway changed to {string}') +// public thenIShouldSeeTheTitleOfThePathwayChangedTo(title: string) { +// assert.strictEqual(this.pDSPBEPathwayEntity.title, title); +// } - @then('I should see an error message {string} during the title change') - public thenIShouldSeeAnErrorMessage(errorMessage: string) { - assert.notEqual(this.error, undefined); - assert.strictEqual(this.error?.message, errorMessage); - } -} +// @then('I should see an error message {string} during the title change') +// public thenIShouldSeeAnErrorMessage(errorMessage: string) { +// assert.notEqual(this.error, undefined); +// assert.strictEqual(this.error?.message, errorMessage); +// } +// } diff --git a/libs/pathway-design/server/pathway/application/src/lib/change-title/usecase/change-title-pathway.usecase.ts b/libs/pathway-design/server/pathway/application/src/lib/change-title/usecase/change-title-pathway.usecase.ts index c2df3c0d..2da66d04 100644 --- a/libs/pathway-design/server/pathway/application/src/lib/change-title/usecase/change-title-pathway.usecase.ts +++ b/libs/pathway-design/server/pathway/application/src/lib/change-title/usecase/change-title-pathway.usecase.ts @@ -1,7 +1,4 @@ -import { - type PDSPBEPathwayEntity, - PDSPBVOTitleValueObjects, -} from '@bewoak/pathway-design-server-pathway-business'; +import { type PDSPBEPathwayEntity, PDSPBVOTitleValueObjects } from '@bewoak/pathway-design-server-pathway-business'; export class PDSPBUChangeTitlePathwayUseCase { execute({ diff --git a/libs/pathway-design/server/pathway/application/src/lib/initialize/command/initialize-pathway.command-handler.ts b/libs/pathway-design/server/pathway/application/src/lib/initialize/command/initialize-pathway.command-handler.ts index 81a9279b..0027f320 100644 --- a/libs/pathway-design/server/pathway/application/src/lib/initialize/command/initialize-pathway.command-handler.ts +++ b/libs/pathway-design/server/pathway/application/src/lib/initialize/command/initialize-pathway.command-handler.ts @@ -7,20 +7,14 @@ import { import { Inject } from '@nestjs/common'; // biome-ignore lint/style/useImportType: -import { - CommandHandler, - EventPublisher, - type ICommandHandler, -} from '@nestjs/cqrs'; +import { CommandHandler, EventPublisher, type ICommandHandler } from '@nestjs/cqrs'; // biome-ignore lint/style/useImportType: import { PDSPAIUInitializePathwayUsecase } from '../usecase/initialize-pathway.usecase'; import { PDSPAInitializePathwayCommand } from './initialize-pathway.command'; @CommandHandler(PDSPAInitializePathwayCommand) -export class PDSPAInitializePathwayCommandHandler - implements ICommandHandler -{ +export class PDSPAInitializePathwayCommandHandler implements ICommandHandler { constructor( private readonly pDSPAIUInitializePathwayUsecase: PDSPAIUInitializePathwayUsecase, @Inject(PDSPBP_INITIALIZE_PATHWAY_PERSISTENCE_PORT) diff --git a/libs/pathway-design/server/pathway/application/src/lib/initialize/service/initialize-pathway.service.ts b/libs/pathway-design/server/pathway/application/src/lib/initialize/service/initialize-pathway.service.ts index b32a27e9..e4c2888e 100644 --- a/libs/pathway-design/server/pathway/application/src/lib/initialize/service/initialize-pathway.service.ts +++ b/libs/pathway-design/server/pathway/application/src/lib/initialize/service/initialize-pathway.service.ts @@ -9,9 +9,6 @@ export class PDSPAInitializePathwayService { constructor(private readonly commandBus: CommandBus) {} init(pDSPAInitializePathwayCommand: PDSPAInitializePathwayCommand) { - return this.commandBus.execute< - PDSPAInitializePathwayCommand, - PDSPBPPathwayPresenters - >(pDSPAInitializePathwayCommand); + return this.commandBus.execute(pDSPAInitializePathwayCommand); } } diff --git a/libs/pathway-design/server/pathway/application/src/lib/initialize/specs/initialize-pathway.usecase.step.ts b/libs/pathway-design/server/pathway/application/src/lib/initialize/specs/initialize-pathway.usecase.step.ts index 3731b195..fb06e9d2 100644 --- a/libs/pathway-design/server/pathway/application/src/lib/initialize/specs/initialize-pathway.usecase.step.ts +++ b/libs/pathway-design/server/pathway/application/src/lib/initialize/specs/initialize-pathway.usecase.step.ts @@ -11,9 +11,7 @@ import { before, binding, then, when } from 'cucumber-tsflow'; import sinon from 'sinon'; import { PDSPAIUInitializePathwayUsecase } from '../usecase/initialize-pathway.usecase'; -class FakeInitializePathwayPersistence - implements PDSPBPInitializePathwayPersistencePort -{ +class FakeInitializePathwayPersistence implements PDSPBPInitializePathwayPersistencePort { save(pDSPBEPathwayEntity: PDSPBEPathwayEntity) { return Promise.resolve(pDSPBEPathwayEntity); } @@ -45,8 +43,7 @@ class FakeEventPublisher { @binding() export default class ControllerSteps { private fakeEventPublisher = new FakeEventPublisher(); - private fakeInitializePathwayPersistence = - new FakeInitializePathwayPersistence(); + private fakeInitializePathwayPersistence = new FakeInitializePathwayPersistence(); private fakePathwayPresenter = new FakePathwayPresenter(); private pDSPBUInitPathwayUseCase = new PDSPAIUInitializePathwayUsecase(); private persistenceSpy: sinon.SinonSpy | undefined; @@ -55,10 +52,7 @@ export default class ControllerSteps { @before() public before() { - this.persistenceSpy = sinon.spy( - this.fakeInitializePathwayPersistence, - 'save' - ); + this.persistenceSpy = sinon.spy(this.fakeInitializePathwayPersistence, 'save'); this.presenterSpy = sinon.spy(this.fakePathwayPresenter, 'present'); } @@ -105,9 +99,7 @@ export default class ControllerSteps { assert(this.presenterSpy?.calledOnce); } - @then( - 'It should emit an event indicating that the pathway has been initialized' - ) + @then('It should emit an event indicating that the pathway has been initialized') public thenItShouldEmitAnEventIndicatingThatThePathwayHasBeenInitialized() { assert.ok(FakeEventPublisher.isEventPublished); } diff --git a/libs/pathway-design/server/pathway/application/src/lib/initialize/usecase/initialize-pathway.usecase.ts b/libs/pathway-design/server/pathway/application/src/lib/initialize/usecase/initialize-pathway.usecase.ts index 61f58fdb..9f5d3eb4 100644 --- a/libs/pathway-design/server/pathway/application/src/lib/initialize/usecase/initialize-pathway.usecase.ts +++ b/libs/pathway-design/server/pathway/application/src/lib/initialize/usecase/initialize-pathway.usecase.ts @@ -26,8 +26,7 @@ export class PDSPAIUInitializePathwayUsecase { researchField, }); - const pathwayFromPersistence = - await pDSPBPInitializePathwayPersistencePort.save(pathway); + const pathwayFromPersistence = await pDSPBPInitializePathwayPersistencePort.save(pathway); eventPublisher.mergeObjectContext(pathway); pathway.commit(); diff --git a/libs/pathway-design/server/pathway/business/cucumber.js b/libs/pathway-design/server/pathway/business/cucumber.js index 0a479a09..95059baa 100644 --- a/libs/pathway-design/server/pathway/business/cucumber.js +++ b/libs/pathway-design/server/pathway/business/cucumber.js @@ -1,12 +1,8 @@ module.exports = { default: { - paths: [ - 'libs/pathway-design/server/pathway/business/src/lib/**/*.feature', - ], + paths: ['libs/pathway-design/server/pathway/business/src/lib/**/*.feature'], requireModule: ['ts-node/register', 'tsconfig-paths/register'], - require: [ - 'libs/pathway-design/server/pathway/business/src/lib/**/*.step.ts', - ], + require: ['libs/pathway-design/server/pathway/business/src/lib/**/*.step.ts'], format: [ 'json:dist/reports/libs/pathway-design/pathway/business/test-feature/index.json', 'html:dist/reports/libs/pathway-design/pathway/business/test-feature/index.html', diff --git a/libs/pathway-design/server/pathway/business/src/lib/factories/pathway.factory.spec.ts b/libs/pathway-design/server/pathway/business/src/lib/factories/pathway.factory.spec.ts index c6c88fb6..050edb8d 100644 --- a/libs/pathway-design/server/pathway/business/src/lib/factories/pathway.factory.spec.ts +++ b/libs/pathway-design/server/pathway/business/src/lib/factories/pathway.factory.spec.ts @@ -39,9 +39,7 @@ describe('pDSPBFPathwayFactory', () => { researchField: 'biology', }; - expect(() => pDSPBFPathwayFactory(params)).toThrow( - 'Description is required' - ); + expect(() => pDSPBFPathwayFactory(params)).toThrow('Description is required'); }); it('should throw an error for an empty research field', () => { @@ -52,9 +50,7 @@ describe('pDSPBFPathwayFactory', () => { researchField: '', }; - expect(() => pDSPBFPathwayFactory(params)).toThrow( - 'Research field is required' - ); + expect(() => pDSPBFPathwayFactory(params)).toThrow('Research field is required'); }); it('should throw an error for an invalid UUID', () => { @@ -65,9 +61,7 @@ describe('pDSPBFPathwayFactory', () => { researchField: 'biology', }; - expect(() => pDSPBFPathwayFactory(params)).toThrow( - 'Pathway id must be a valid uuid' - ); + expect(() => pDSPBFPathwayFactory(params)).toThrow('Pathway id must be a valid uuid'); }); it('should generate a valid UUID if none is provided', () => { @@ -79,9 +73,7 @@ describe('pDSPBFPathwayFactory', () => { const pathway = pDSPBFPathwayFactory(params); expect(pathway).toBeInstanceOf(PDSPBEPathwayEntity); - expect(pathway.id).toMatch( - /^[0-9a-f]{8}-[0-9a-f]{4}-4[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i - ); + expect(pathway.id).toMatch(/^[0-9a-f]{8}-[0-9a-f]{4}-4[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i); expect(pathway.title).toBe(params.title); expect(pathway.description).toBe(params.description); expect(pathway.researchField).toBe(params.researchField); diff --git a/libs/pathway-design/server/pathway/business/src/lib/ports/persistences/initialize/initialize-pathway-persitence.port.ts b/libs/pathway-design/server/pathway/business/src/lib/ports/persistences/initialize/initialize-pathway-persitence.port.ts index 331498bb..94bfbc55 100644 --- a/libs/pathway-design/server/pathway/business/src/lib/ports/persistences/initialize/initialize-pathway-persitence.port.ts +++ b/libs/pathway-design/server/pathway/business/src/lib/ports/persistences/initialize/initialize-pathway-persitence.port.ts @@ -1,11 +1,7 @@ import type { PDSPBEPathwayEntity } from '../../../entities/pathway'; export interface PDSPBPInitializePathwayPersistencePort { - save: ( - pDSPBEPathwayEntity: PDSPBEPathwayEntity - ) => Promise; + save: (pDSPBEPathwayEntity: PDSPBEPathwayEntity) => Promise; } -export const PDSPBP_INITIALIZE_PATHWAY_PERSISTENCE_PORT = Symbol( - 'PDSPBPInitializePathwayPersistencePort' -); +export const PDSPBP_INITIALIZE_PATHWAY_PERSISTENCE_PORT = Symbol('PDSPBPInitializePathwayPersistencePort'); diff --git a/libs/pathway-design/server/pathway/business/src/lib/ports/presenters/pathway-presenter.port.ts b/libs/pathway-design/server/pathway/business/src/lib/ports/presenters/pathway-presenter.port.ts index ef87ba5a..5f2c9bca 100644 --- a/libs/pathway-design/server/pathway/business/src/lib/ports/presenters/pathway-presenter.port.ts +++ b/libs/pathway-design/server/pathway/business/src/lib/ports/presenters/pathway-presenter.port.ts @@ -10,11 +10,7 @@ export interface PDSPBPJsonPathwayPresenter { export type PDSPBPPathwayPresenters = PDSPBPJsonPathwayPresenter; export interface PDSPBPPathwayPresenterPort { - present: ( - pDSPBEpathwayEntity: PDSPBEPathwayEntity - ) => PDSPBPPathwayPresenters; + present: (pDSPBEpathwayEntity: PDSPBEPathwayEntity) => PDSPBPPathwayPresenters; } -export const PDSPBP_PATHWAY_PRESENTER_PORT = Symbol( - 'PDSPBPPathwayPresenterPort' -); +export const PDSPBP_PATHWAY_PRESENTER_PORT = Symbol('PDSPBPPathwayPresenterPort'); diff --git a/libs/pathway-design/server/pathway/business/src/lib/specs/change-name/.gitkeep b/libs/pathway-design/server/pathway/business/src/lib/specs/change-name/.gitkeep deleted file mode 100644 index e69de29b..00000000 diff --git a/libs/pathway-design/server/pathway/business/src/lib/specs/change-name/change-title-pathway.feature b/libs/pathway-design/server/pathway/business/src/lib/specs/change-name/change-title-pathway.feature new file mode 100644 index 00000000..98f85bb8 --- /dev/null +++ b/libs/pathway-design/server/pathway/business/src/lib/specs/change-name/change-title-pathway.feature @@ -0,0 +1,15 @@ +Feature: Change the title of a pathway + + Scenario: I want to change the title of a pathway with a valid title + Given I have a pathway with these data + | title | description | researchField | + | My Pathway | A test pathway | biology | + When I change the title of the pathway to "My New Pathway" + Then I should see the title of the pathway changed to "My New Pathway" + + Scenario: I want to change the title of a pathway with an empty title + Given I have a pathway with these data + | title | description | researchField | + | My Pathway | A test pathway | biology | + When I change the title of the pathway to "" + Then I should see an error message "Title is required" during the title change diff --git a/libs/pathway-design/server/pathway/business/src/lib/specs/change-name/change-title-pathway.step.ts b/libs/pathway-design/server/pathway/business/src/lib/specs/change-name/change-title-pathway.step.ts new file mode 100644 index 00000000..ad58cfb6 --- /dev/null +++ b/libs/pathway-design/server/pathway/business/src/lib/specs/change-name/change-title-pathway.step.ts @@ -0,0 +1,49 @@ +import { strict as assert } from 'node:assert'; + +import type { DataTable } from '@cucumber/cucumber'; +import { binding, given, then, when } from 'cucumber-tsflow'; +import type { PDSPBEPathwayEntity } from '../../entities/pathway'; +import { pDSPBFPathwayFactory } from '../../factories/pathway.factory'; +import { PDSPBVOTitleValueObjects } from '../../value-objects/title.value-object'; + +@binding() +export default class ControllerSteps { + private pDSPBEPathwayEntity: PDSPBEPathwayEntity | undefined; + private error: Error | undefined; + + @given('I have a pathway with these data') + public givenIHaveAPathway(dataTable: DataTable) { + const firstRow = dataTable.hashes()[0] as { + title: string; + description: string; + researchField: string; + }; + + this.pDSPBEPathwayEntity = pDSPBFPathwayFactory({ + title: firstRow.title, + description: firstRow.description, + researchField: firstRow.researchField, + }); + } + + @when('I change the title of the pathway to {string}') + public whenIChangeTheTitleOfPathway(newTitle: string) { + try { + const title = new PDSPBVOTitleValueObjects(newTitle); + this.pDSPBEPathwayEntity?.changeTitle(title); + } catch (error) { + this.error = error as Error; + } + } + + @then('I should see the title of the pathway changed to {string}') + public thenIShouldSeeTheTitleOfThePathwayChangedTo(title: string) { + assert.strictEqual(this.pDSPBEPathwayEntity?.title, title); + } + + @then('I should see an error message {string} during the title change') + public thenIShouldSeeAnErrorMessageDuringTitleChange(errorMessage: string) { + assert.notEqual(this.error, undefined); + assert.strictEqual(this.error?.message, errorMessage); + } +} diff --git a/libs/pathway-design/server/pathway/business/src/lib/specs/initialize/pathway.feature b/libs/pathway-design/server/pathway/business/src/lib/specs/initialize/initialize-pathway.feature similarity index 82% rename from libs/pathway-design/server/pathway/business/src/lib/specs/initialize/pathway.feature rename to libs/pathway-design/server/pathway/business/src/lib/specs/initialize/initialize-pathway.feature index 080f6785..d9d2fd5b 100644 --- a/libs/pathway-design/server/pathway/business/src/lib/specs/initialize/pathway.feature +++ b/libs/pathway-design/server/pathway/business/src/lib/specs/initialize/initialize-pathway.feature @@ -13,61 +13,52 @@ Feature: Initialize a pathway When I initialize a pathway with these data | id | title | description | researchField | | f7703737-186c-4c7c-8d46-925111c7c7c1 | | A test pathway | biology | - Then I should see an error message "Title is required" + Then I should see an error message "Title is required" during the initialization Scenario: I want to initialize a pathway with an empty description When I initialize a pathway with these data | id | title | description | researchField | | f7703737-186c-4c7c-8d46-925111c7c7c1 | My Pathway | | biology | - Then I should see an error message "Description is required" + Then I should see an error message "Description is required" during the initialization Scenario: I want to initialize a pathway with an empty research field When I initialize a pathway with these data | id | title | description | researchField | | f7703737-186c-4c7c-8d46-925111c7c7c1 | My Pathway | A test pathway | | - Then I should see an error message "Research field is required" + Then I should see an error message "Research field is required" during the initialization Scenario: I want to initialize a pathway with an invalid UUID When I initialize a pathway with these data | id | title | description | researchField | | invalid-uuid | My Pathway | A test pathway | biology | - Then I should see an error message "Pathway id must be a valid uuid" - - Scenario: I want to change the title of an existing pathway - Given I have initialized a pathway with these data - | id | title | description | researchField | - | f7703737-186c-4c7c-8d46-925111c7c7c1 | My Pathway | A test pathway | biology | - When I change the title to "New Title" - Then I should retrieve the attributes of the pathway - | id | title | description | researchField | - | f7703737-186c-4c7c-8d46-925111c7c7c1 | New Title | A test pathway | biology | + Then I should see an error message "Pathway id must be a valid uuid" during the initialization Scenario: I want to initialize a pathway with all empty fields When I initialize a pathway with these data | id | title | description | researchField | | | | | | - Then I should see an error message "Pathway id must be a valid uuid" + Then I should see an error message "Pathway id must be a valid uuid" during the initialization Scenario: I want to initialize a pathway with missing id When I initialize a pathway with these data | title | description | researchField | | My Pathway | A test pathway | biology | - Then I should see an error message "Pathway id must be a valid uuid" + Then I should see an error message "Pathway id must be a valid uuid" during the initialization Scenario: I want to initialize a pathway with missing title When I initialize a pathway with these data | id | description | researchField | | f7703737-186c-4c7c-8d46-925111c7c7c1 | A test pathway | biology | - Then I should see an error message "Title is required" + Then I should see an error message "Title is required" during the initialization Scenario: I want to initialize a pathway with missing description When I initialize a pathway with these data | id | title | researchField | | f7703737-186c-4c7c-8d46-925111c7c7c1 | My Pathway | biology | - Then I should see an error message "Description is required" + Then I should see an error message "Description is required" during the initialization Scenario: I want to initialize a pathway with missing research field When I initialize a pathway with these data | id | title | description | | f7703737-186c-4c7c-8d46-925111c7c7c1 | My Pathway | A test pathway | - Then I should see an error message "Research field is required" + Then I should see an error message "Research field is required" during the initialization diff --git a/libs/pathway-design/server/pathway/business/src/lib/specs/initialize/pathway.step.ts b/libs/pathway-design/server/pathway/business/src/lib/specs/initialize/initialize-pathway.step.ts similarity index 69% rename from libs/pathway-design/server/pathway/business/src/lib/specs/initialize/pathway.step.ts rename to libs/pathway-design/server/pathway/business/src/lib/specs/initialize/initialize-pathway.step.ts index bd27b092..774367a0 100644 --- a/libs/pathway-design/server/pathway/business/src/lib/specs/initialize/pathway.step.ts +++ b/libs/pathway-design/server/pathway/business/src/lib/specs/initialize/initialize-pathway.step.ts @@ -1,6 +1,6 @@ -import { strict as assert } from 'node:assert'; import type { DataTable } from '@cucumber/cucumber'; import { binding, given, then, when } from 'cucumber-tsflow'; +import { strict as assert } from 'node:assert'; import sinon from 'sinon'; import { PDSPBEPathwayEntity } from '../../entities/pathway'; import { PDSPBEPathwayInitializedEvent } from '../../events/pathway-initialized.event'; @@ -11,7 +11,7 @@ import { PDSPBVOTitleValueObjects } from '../../value-objects/title.value-object @binding() export default class PathwaySteps { - private pathway: PDSPBEPathwayEntity | undefined; + private pDSPBEPathwayEntity: PDSPBEPathwayEntity | undefined; private error: Error | undefined; private applySpy: sinon.SinonSpy | undefined; @@ -29,8 +29,13 @@ export default class PathwaySteps { const description = new DescriptionValueObject(data.description); const researchField = new ResearchFieldValueObjects(data.researchField); - this.pathway = new PDSPBEPathwayEntity(); - this.pathway.init({ id, title, description, researchField }); + this.pDSPBEPathwayEntity = new PDSPBEPathwayEntity(); + this.pDSPBEPathwayEntity.init({ + id, + title, + description, + researchField, + }); } @when('I initialize a pathway with these data') @@ -46,25 +51,22 @@ export default class PathwaySteps { const id = new PathwayIdValueObject(data.id); const title = new PDSPBVOTitleValueObjects(data.title); const description = new DescriptionValueObject(data.description); - const researchField = new ResearchFieldValueObjects( - data.researchField - ); + const researchField = new ResearchFieldValueObjects(data.researchField); - this.pathway = new PDSPBEPathwayEntity(); - this.applySpy = sinon.spy(this.pathway, 'apply'); + this.pDSPBEPathwayEntity = new PDSPBEPathwayEntity(); + this.applySpy = sinon.spy(this.pDSPBEPathwayEntity, 'apply'); - this.pathway.init({ id, title, description, researchField }); + this.pDSPBEPathwayEntity.init({ + id, + title, + description, + researchField, + }); } catch (error) { this.error = error as Error; } } - @when('I change the title to {string}') - public whenIChangeTheTitle(newTitle: string) { - const title = new PDSPBVOTitleValueObjects(newTitle); - this.pathway?.changeTitle(title); - } - @then('I should retrieve the attributes of the pathway') public thenIShouldRetrieveAttributesPathway(dataTable: DataTable) { const data = dataTable.hashes()[0] as { @@ -74,27 +76,23 @@ export default class PathwaySteps { researchField: string; }; - assert.strictEqual(this.pathway?.id, data.id); - assert.strictEqual(this.pathway?.title, data.title); - assert.strictEqual(this.pathway?.description, data.description); - assert.strictEqual(this.pathway?.researchField, data.researchField); + assert.strictEqual(this.pDSPBEPathwayEntity?.id, data.id); + assert.strictEqual(this.pDSPBEPathwayEntity?.title, data.title); + assert.strictEqual(this.pDSPBEPathwayEntity?.description, data.description); + assert.strictEqual(this.pDSPBEPathwayEntity?.researchField, data.researchField); } - @then( - 'It should apply an event indicating that the pathway has been initialized' - ) + @then('It should apply an event indicating that the pathway has been initialized') public thenItShouldApplyAnEvent() { - const expectedEvent = new PDSPBEPathwayInitializedEvent( - this.pathway as PDSPBEPathwayEntity - ); + const expectedEvent = new PDSPBEPathwayInitializedEvent(this.pDSPBEPathwayEntity as PDSPBEPathwayEntity); const callArgs = this.applySpy?.getCall(0).args[0]; assert(this.applySpy?.calledOnce); assert.deepStrictEqual(callArgs, expectedEvent); } - @then('I should see an error message {string}') - public thenIShouldSeeAnErrorMessage(errorMessage: string) { + @then('I should see an error message {string} during the initialization') + public thenIShouldSeeAnErrorMessageDuringInitialization(errorMessage: string) { assert.notEqual(this.error, undefined); assert.strictEqual(this.error?.message, errorMessage); } diff --git a/libs/pathway-design/server/pathway/business/src/lib/value-objects/description.value-object.spec.ts b/libs/pathway-design/server/pathway/business/src/lib/value-objects/description.value-object.spec.ts index ab612299..55859aba 100644 --- a/libs/pathway-design/server/pathway/business/src/lib/value-objects/description.value-object.spec.ts +++ b/libs/pathway-design/server/pathway/business/src/lib/value-objects/description.value-object.spec.ts @@ -16,9 +16,7 @@ describe('DescriptionValueObject', () => { }); test('should throw an error if the description is empty', () => { - expect(() => new DescriptionValueObject('')).toThrowError( - 'Description is required' - ); + expect(() => new DescriptionValueObject('')).toThrowError('Description is required'); }); test('should return true when comparing two equal descriptions', () => { diff --git a/libs/pathway-design/server/pathway/business/src/lib/value-objects/pathway-id.value-object.spec.ts b/libs/pathway-design/server/pathway/business/src/lib/value-objects/pathway-id.value-object.spec.ts index 605ec8fe..7069afac 100644 --- a/libs/pathway-design/server/pathway/business/src/lib/value-objects/pathway-id.value-object.spec.ts +++ b/libs/pathway-design/server/pathway/business/src/lib/value-objects/pathway-id.value-object.spec.ts @@ -7,33 +7,21 @@ describe('PathwayIdValueObject', () => { let pathwayIdValueObjectSameAs2: PathwayIdValueObject; beforeAll(() => { - pathwayIdValueObject1 = new PathwayIdValueObject( - 'e24054b9-92ca-4a22-be67-cf14cc94e6f8' - ); - pathwayIdValueObject2 = new PathwayIdValueObject( - '7324ec70-2c17-4dac-ae10-b9eb4cd22fec' - ); - pathwayIdValueObjectSameAs2 = new PathwayIdValueObject( - '7324ec70-2c17-4dac-ae10-b9eb4cd22fec' - ); + pathwayIdValueObject1 = new PathwayIdValueObject('e24054b9-92ca-4a22-be67-cf14cc94e6f8'); + pathwayIdValueObject2 = new PathwayIdValueObject('7324ec70-2c17-4dac-ae10-b9eb4cd22fec'); + pathwayIdValueObjectSameAs2 = new PathwayIdValueObject('7324ec70-2c17-4dac-ae10-b9eb4cd22fec'); }); test('should create an instance with a valid pathway id', () => { - expect(pathwayIdValueObject1.value).toBe( - 'e24054b9-92ca-4a22-be67-cf14cc94e6f8' - ); + expect(pathwayIdValueObject1.value).toBe('e24054b9-92ca-4a22-be67-cf14cc94e6f8'); }); test('should throw an error if the id is not a uuid', () => { - expect(() => new PathwayIdValueObject('12345')).toThrowError( - 'Pathway id must be a valid uuid' - ); + expect(() => new PathwayIdValueObject('12345')).toThrowError('Pathway id must be a valid uuid'); }); test('should return true when comparing two equal pathway id', () => { - expect(pathwayIdValueObject2.equals(pathwayIdValueObjectSameAs2)).toBe( - true - ); + expect(pathwayIdValueObject2.equals(pathwayIdValueObjectSameAs2)).toBe(true); }); test('should return false when comparing two different pathway id', () => { @@ -41,8 +29,6 @@ describe('PathwayIdValueObject', () => { }); test('should return the pathway id as a string', () => { - expect(pathwayIdValueObject1.toString()).toBe( - 'e24054b9-92ca-4a22-be67-cf14cc94e6f8' - ); + expect(pathwayIdValueObject1.toString()).toBe('e24054b9-92ca-4a22-be67-cf14cc94e6f8'); }); }); diff --git a/libs/pathway-design/server/pathway/business/src/lib/value-objects/pathway-id.value-object.ts b/libs/pathway-design/server/pathway/business/src/lib/value-objects/pathway-id.value-object.ts index 3ec78ca6..e90ac994 100644 --- a/libs/pathway-design/server/pathway/business/src/lib/value-objects/pathway-id.value-object.ts +++ b/libs/pathway-design/server/pathway/business/src/lib/value-objects/pathway-id.value-object.ts @@ -3,9 +3,7 @@ import { CTSEBadRequestException } from '@bewoak/common-tools-server-http-except export class PathwayIdValueObject { constructor(private id: string) { if (!this.isUuid(id)) { - throw new CTSEBadRequestException( - 'Pathway id must be a valid uuid' - ); + throw new CTSEBadRequestException('Pathway id must be a valid uuid'); } } get value() { @@ -21,8 +19,7 @@ export class PathwayIdValueObject { } private isUuid(id: string) { - const uuidV4Regex = - /^[0-9a-f]{8}-[0-9a-f]{4}-4[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i; + const uuidV4Regex = /^[0-9a-f]{8}-[0-9a-f]{4}-4[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i; return uuidV4Regex.test(id); } diff --git a/libs/pathway-design/server/pathway/business/src/lib/value-objects/research-field.value-object.spec.ts b/libs/pathway-design/server/pathway/business/src/lib/value-objects/research-field.value-object.spec.ts index 1e9f8551..e7a35829 100644 --- a/libs/pathway-design/server/pathway/business/src/lib/value-objects/research-field.value-object.spec.ts +++ b/libs/pathway-design/server/pathway/business/src/lib/value-objects/research-field.value-object.spec.ts @@ -7,31 +7,21 @@ describe('ResearchFieldValueObjects', () => { beforeAll(() => { researchField1 = new ResearchFieldValueObjects('Test researchField'); - researchField2 = new ResearchFieldValueObjects( - 'Different researchField' - ); + researchField2 = new ResearchFieldValueObjects('Different researchField'); }); test('should create an instance with a valid researchField', () => { - const researchField = new ResearchFieldValueObjects( - 'Test researchField' - ); + const researchField = new ResearchFieldValueObjects('Test researchField'); expect(researchField.value).toBe('Test researchField'); }); test('should throw an error if the researchField is empty', () => { - expect(() => new ResearchFieldValueObjects('')).toThrowError( - 'Research field is required' - ); + expect(() => new ResearchFieldValueObjects('')).toThrowError('Research field is required'); }); test('should return true when comparing two equal researchFields', () => { - const sameresearchField1 = new ResearchFieldValueObjects( - 'Test researchField' - ); - const sameresearchField2 = new ResearchFieldValueObjects( - 'Test researchField' - ); + const sameresearchField1 = new ResearchFieldValueObjects('Test researchField'); + const sameresearchField2 = new ResearchFieldValueObjects('Test researchField'); expect(sameresearchField1.equals(sameresearchField2)).toBe(true); }); diff --git a/libs/pathway-design/server/pathway/business/src/lib/value-objects/title.value-object.spec.ts b/libs/pathway-design/server/pathway/business/src/lib/value-objects/title.value-object.spec.ts index 6ab801e2..05a7c360 100644 --- a/libs/pathway-design/server/pathway/business/src/lib/value-objects/title.value-object.spec.ts +++ b/libs/pathway-design/server/pathway/business/src/lib/value-objects/title.value-object.spec.ts @@ -16,9 +16,7 @@ describe('PDSPBVOTitleValueObjects', () => { }); test('should throw an error if the title is empty', () => { - expect(() => new PDSPBVOTitleValueObjects('')).toThrowError( - 'Title is required' - ); + expect(() => new PDSPBVOTitleValueObjects('')).toThrowError('Title is required'); }); test('should return true when comparing two equal titles', () => { diff --git a/libs/pathway-design/server/pathway/infrastructure/cucumber.js b/libs/pathway-design/server/pathway/infrastructure/cucumber.js index 11ea9045..d657b579 100644 --- a/libs/pathway-design/server/pathway/infrastructure/cucumber.js +++ b/libs/pathway-design/server/pathway/infrastructure/cucumber.js @@ -1,12 +1,8 @@ module.exports = { default: { - paths: [ - 'libs/pathway-design/server/pathway/infrastructure/src/lib/**/*.feature', - ], + paths: ['libs/pathway-design/server/pathway/infrastructure/src/lib/**/*.feature'], requireModule: ['ts-node/register', 'tsconfig-paths/register'], - require: [ - 'libs/pathway-design/server/pathway/infrastructure/src/lib/**/*.step.ts', - ], + require: ['libs/pathway-design/server/pathway/infrastructure/src/lib/**/*.step.ts'], format: [ 'json:dist/reports/libs/pathway-design/pathway/infrastructure/test-feature/index.json', 'html:dist/reports/libs/pathway-design/pathway/infrastructure/test-feature/index.html', diff --git a/libs/pathway-design/server/pathway/infrastructure/src/lib/persistence/common/in-memory/mappers/in-memory-pathway.mapper.ts b/libs/pathway-design/server/pathway/infrastructure/src/lib/persistence/common/in-memory/mappers/in-memory-pathway.mapper.ts index 2f630391..4ee6062b 100644 --- a/libs/pathway-design/server/pathway/infrastructure/src/lib/persistence/common/in-memory/mappers/in-memory-pathway.mapper.ts +++ b/libs/pathway-design/server/pathway/infrastructure/src/lib/persistence/common/in-memory/mappers/in-memory-pathway.mapper.ts @@ -1,12 +1,7 @@ -import { - type PDSPBEPathwayEntity, - pDSPBFPathwayFactory, -} from '@bewoak/pathway-design-server-pathway-business'; +import { type PDSPBEPathwayEntity, pDSPBFPathwayFactory } from '@bewoak/pathway-design-server-pathway-business'; import { PathwayInMemoryEntity } from '../entities/in-memory-pathway.entity'; -export const mapPathwayEntityToInMemoryPersistence = ( - pathway: PDSPBEPathwayEntity -): PathwayInMemoryEntity => { +export const mapPathwayEntityToInMemoryPersistence = (pathway: PDSPBEPathwayEntity): PathwayInMemoryEntity => { const pathwayInMemoryEntity = new PathwayInMemoryEntity( pathway.id, pathway.description, @@ -17,9 +12,7 @@ export const mapPathwayEntityToInMemoryPersistence = ( return pathwayInMemoryEntity; }; -export const mapPathwayInMemoryToPathwayEntity = ( - pathwayInMemoryEntity: PathwayInMemoryEntity -): PDSPBEPathwayEntity => { +export const mapPathwayInMemoryToPathwayEntity = (pathwayInMemoryEntity: PathwayInMemoryEntity): PDSPBEPathwayEntity => { const pathway = pDSPBFPathwayFactory({ description: pathwayInMemoryEntity.description, id: pathwayInMemoryEntity.id, diff --git a/libs/pathway-design/server/pathway/infrastructure/src/lib/persistence/initialize/in-memory/initialize-pathway-in-memory.persistence.spec.ts b/libs/pathway-design/server/pathway/infrastructure/src/lib/persistence/initialize/in-memory/initialize-pathway-in-memory.persistence.spec.ts index 1f77f054..2a82058b 100644 --- a/libs/pathway-design/server/pathway/infrastructure/src/lib/persistence/initialize/in-memory/initialize-pathway-in-memory.persistence.spec.ts +++ b/libs/pathway-design/server/pathway/infrastructure/src/lib/persistence/initialize/in-memory/initialize-pathway-in-memory.persistence.spec.ts @@ -1,8 +1,5 @@ import { beforeEach, describe, expect, spyOn, test } from 'bun:test'; -import { - type PDSPBEPathwayEntity, - pDSPBFPathwayFactory, -} from '@bewoak/pathway-design-server-pathway-business'; +import { type PDSPBEPathwayEntity, pDSPBFPathwayFactory } from '@bewoak/pathway-design-server-pathway-business'; import { NotFoundException } from '@nestjs/common'; import { Test } from '@nestjs/testing'; import { PathwayInMemoryRepository } from '../../common/in-memory/repositories/in-memory-pathway.repository'; @@ -17,21 +14,15 @@ describe('InitializePathwayInMemoryPersistence', () => { beforeEach(async () => { const module = await Test.createTestingModule({ - providers: [ - InitializePathwayInMemoryPersistence, - PathwayInMemoryRepository, - ], + providers: [InitializePathwayInMemoryPersistence, PathwayInMemoryRepository], }).compile(); - initializePathwayInMemoryPersistence = - module.get( - InitializePathwayInMemoryPersistence - ); - - pathwayInMemoryRepository = module.get( - PathwayInMemoryRepository + initializePathwayInMemoryPersistence = module.get( + InitializePathwayInMemoryPersistence ); + pathwayInMemoryRepository = module.get(PathwayInMemoryRepository); + pDSPBEPathwayEntity = pDSPBFPathwayFactory({ description: 'pathway description', researchField: 'pathway research field', @@ -42,17 +33,12 @@ describe('InitializePathwayInMemoryPersistence', () => { spyOn(pathwayInMemoryRepository, 'add'); spyOn(pathwayInMemoryRepository, 'get'); - result = - await initializePathwayInMemoryPersistence.save( - pDSPBEPathwayEntity - ); + result = await initializePathwayInMemoryPersistence.save(pDSPBEPathwayEntity); }); test('should call the save method with the pathway in parameter', () => { expect(initializePathwayInMemoryPersistence).toBeDefined(); - expect( - initializePathwayInMemoryPersistence.save - ).toHaveBeenCalledWith(pDSPBEPathwayEntity); + expect(initializePathwayInMemoryPersistence.save).toHaveBeenCalledWith(pDSPBEPathwayEntity); }); test('should save the pathway in memory and return the pathway saved', () => { @@ -62,12 +48,8 @@ describe('InitializePathwayInMemoryPersistence', () => { expect(result.id).not.toBeEmpty(); expect(result).not.toBe(pDSPBEPathwayEntity); expect(result.title).toStrictEqual(pDSPBEPathwayEntity.title); - expect(result.description).toStrictEqual( - pDSPBEPathwayEntity.description - ); - expect(result.researchField).toStrictEqual( - pDSPBEPathwayEntity.researchField - ); + expect(result.description).toStrictEqual(pDSPBEPathwayEntity.description); + expect(result.researchField).toStrictEqual(pDSPBEPathwayEntity.researchField); }); }); @@ -90,15 +72,12 @@ describe('InitializePathwayInMemoryPersistence', () => { ], }).compile(); - initializePathwayInMemoryPersistence = - module.get( - InitializePathwayInMemoryPersistence - ); - - pathwayInMemoryRepository = module.get( - PathwayInMemoryRepository + initializePathwayInMemoryPersistence = module.get( + InitializePathwayInMemoryPersistence ); + pathwayInMemoryRepository = module.get(PathwayInMemoryRepository); + pDSPBEPathwayEntity = pDSPBFPathwayFactory({ description: 'pathway description', researchField: 'pathway research field', @@ -112,14 +91,10 @@ describe('InitializePathwayInMemoryPersistence', () => { test('should throw an error', async () => { try { - await initializePathwayInMemoryPersistence.save( - pDSPBEPathwayEntity - ); + await initializePathwayInMemoryPersistence.save(pDSPBEPathwayEntity); } catch (error) { expect(error).toBeInstanceOf(NotFoundException); - expect((error as NotFoundException).message).toBe( - 'Pathway not found in memory' - ); + expect((error as NotFoundException).message).toBe('Pathway not found in memory'); } }); }); diff --git a/libs/pathway-design/server/pathway/infrastructure/src/lib/persistence/initialize/in-memory/initialize-pathway-in-memory.persistence.ts b/libs/pathway-design/server/pathway/infrastructure/src/lib/persistence/initialize/in-memory/initialize-pathway-in-memory.persistence.ts index 063bca81..f4791c82 100644 --- a/libs/pathway-design/server/pathway/infrastructure/src/lib/persistence/initialize/in-memory/initialize-pathway-in-memory.persistence.ts +++ b/libs/pathway-design/server/pathway/infrastructure/src/lib/persistence/initialize/in-memory/initialize-pathway-in-memory.persistence.ts @@ -1,7 +1,4 @@ -import type { - PDSPBEPathwayEntity, - PDSPBPInitializePathwayPersistencePort, -} from '@bewoak/pathway-design-server-pathway-business'; +import type { PDSPBEPathwayEntity, PDSPBPInitializePathwayPersistencePort } from '@bewoak/pathway-design-server-pathway-business'; import { Inject, Injectable, NotFoundException } from '@nestjs/common'; import { mapPathwayEntityToInMemoryPersistence, @@ -10,22 +7,17 @@ import { import { PathwayInMemoryRepository } from '../../../persistence/common/in-memory/repositories/in-memory-pathway.repository'; @Injectable() -export class InitializePathwayInMemoryPersistence - implements PDSPBPInitializePathwayPersistencePort -{ +export class InitializePathwayInMemoryPersistence implements PDSPBPInitializePathwayPersistencePort { constructor( @Inject(PathwayInMemoryRepository) private pathwayInMemoryRepository: PathwayInMemoryRepository ) {} async save(pDSPBEPathwayEntity: PDSPBEPathwayEntity) { - const peristenceModel = - mapPathwayEntityToInMemoryPersistence(pDSPBEPathwayEntity); + const peristenceModel = mapPathwayEntityToInMemoryPersistence(pDSPBEPathwayEntity); await this.pathwayInMemoryRepository.add(peristenceModel); - const pathwayInMemory = await this.pathwayInMemoryRepository.get( - peristenceModel.id - ); + const pathwayInMemory = await this.pathwayInMemoryRepository.get(peristenceModel.id); if (pathwayInMemory === undefined) { throw new NotFoundException('Pathway not found in memory'); diff --git a/libs/pathway-design/server/pathway/infrastructure/src/lib/persistence/initialize/initialize-pathway-persistence-infrastructure.module.ts b/libs/pathway-design/server/pathway/infrastructure/src/lib/persistence/initialize/initialize-pathway-persistence-infrastructure.module.ts index 212b9691..6d112052 100644 --- a/libs/pathway-design/server/pathway/infrastructure/src/lib/persistence/initialize/initialize-pathway-persistence-infrastructure.module.ts +++ b/libs/pathway-design/server/pathway/infrastructure/src/lib/persistence/initialize/initialize-pathway-persistence-infrastructure.module.ts @@ -1,10 +1,7 @@ import { Module } from '@nestjs/common'; import { InitializePathwayInMemoryPersistenceModule } from './in-memory/initialize-pathway-in-memory-persistence.module'; -const persistenceDriverModuleMap: Record< - 'inMemory', - typeof InitializePathwayInMemoryPersistenceModule -> = { +const persistenceDriverModuleMap: Record<'inMemory', typeof InitializePathwayInMemoryPersistenceModule> = { inMemory: InitializePathwayInMemoryPersistenceModule, }; diff --git a/libs/pathway-design/server/pathway/interface-adapters/cucumber.js b/libs/pathway-design/server/pathway/interface-adapters/cucumber.js index cad5306d..6e59c102 100644 --- a/libs/pathway-design/server/pathway/interface-adapters/cucumber.js +++ b/libs/pathway-design/server/pathway/interface-adapters/cucumber.js @@ -1,12 +1,8 @@ module.exports = { default: { - paths: [ - 'libs/pathway-design/server/pathway/interface-adapters/src/lib/**/*.feature', - ], + paths: ['libs/pathway-design/server/pathway/interface-adapters/src/lib/**/*.feature'], requireModule: ['ts-node/register', 'tsconfig-paths/register'], - require: [ - 'libs/pathway-design/server/pathway/interface-adapters/src/lib/**/*.step.ts', - ], + require: ['libs/pathway-design/server/pathway/interface-adapters/src/lib/**/*.step.ts'], format: [ 'json:dist/reports/libs/pathway-design/pathway/interface-adapters/test-feature/index.json', 'html:dist/reports/libs/pathway-design/pathway/interface-adapters/test-feature/index.html', diff --git a/libs/pathway-design/server/pathway/interface-adapters/src/lib/initialize/controller/initialize-pathway.controller.ts b/libs/pathway-design/server/pathway/interface-adapters/src/lib/initialize/controller/initialize-pathway.controller.ts index 3e2d6f22..008d2ac0 100644 --- a/libs/pathway-design/server/pathway/interface-adapters/src/lib/initialize/controller/initialize-pathway.controller.ts +++ b/libs/pathway-design/server/pathway/interface-adapters/src/lib/initialize/controller/initialize-pathway.controller.ts @@ -1,21 +1,7 @@ // biome-ignore lint/style/useImportType: -import { - PDSPAInitializePathwayCommand, - PDSPAInitializePathwayService, -} from '@bewoak/pathway-design-server-pathway-application'; -import { - Body, - Controller, - HttpStatus, - Post, - UsePipes, - ValidationPipe, -} from '@nestjs/common'; -import { - ApiBadRequestResponse, - ApiCreatedResponse, - ApiTags, -} from '@nestjs/swagger'; +import { PDSPAInitializePathwayCommand, PDSPAInitializePathwayService } from '@bewoak/pathway-design-server-pathway-application'; +import { Body, Controller, HttpStatus, Post, UsePipes, ValidationPipe } from '@nestjs/common'; +import { ApiBadRequestResponse, ApiCreatedResponse, ApiTags } from '@nestjs/swagger'; // biome-ignore lint/style/useImportType: import { InitializePathwayRequestBodyDto } from '../dtos/request/body/request-body.dto'; import { InitializedPathwayResponseBodyDto } from '../dtos/response/body/response-body.dto'; @@ -31,9 +17,7 @@ import { InitializedPathwayResponseBodyDto } from '../dtos/response/body/respons path: 'pathway', }) export class InitializePathwayController { - constructor( - private readonly pDSPAInitializePathwayService: PDSPAInitializePathwayService - ) {} + constructor(private readonly pDSPAInitializePathwayService: PDSPAInitializePathwayService) {} @Post('init') @ApiCreatedResponse({ diff --git a/libs/pathway-design/server/pathway/interface-adapters/src/lib/initialize/dtos/response/body/response-body.dto.ts b/libs/pathway-design/server/pathway/interface-adapters/src/lib/initialize/dtos/response/body/response-body.dto.ts index 789e65e7..42e2896a 100644 --- a/libs/pathway-design/server/pathway/interface-adapters/src/lib/initialize/dtos/response/body/response-body.dto.ts +++ b/libs/pathway-design/server/pathway/interface-adapters/src/lib/initialize/dtos/response/body/response-body.dto.ts @@ -1,8 +1,6 @@ import type { PDSPBPPathwayPresenters } from '@bewoak/pathway-design-server-pathway-business'; -export class InitializedPathwayResponseBodyDto - implements PDSPBPPathwayPresenters -{ +export class InitializedPathwayResponseBodyDto implements PDSPBPPathwayPresenters { description!: string; id!: string; researchField!: string; diff --git a/libs/pathway-design/server/pathway/interface-adapters/src/lib/initialize/initialize-pathway-interface-adapters.module.ts b/libs/pathway-design/server/pathway/interface-adapters/src/lib/initialize/initialize-pathway-interface-adapters.module.ts index d917c2ab..ed4803ed 100644 --- a/libs/pathway-design/server/pathway/interface-adapters/src/lib/initialize/initialize-pathway-interface-adapters.module.ts +++ b/libs/pathway-design/server/pathway/interface-adapters/src/lib/initialize/initialize-pathway-interface-adapters.module.ts @@ -8,11 +8,7 @@ import { InitializePathwayController } from './controller/initialize-pathway.con @Module({ controllers: [InitializePathwayController], - providers: [ - PDSPAInitializePathwayCommandHandler, - PDSPAInitializePathwayService, - PDSPAIUInitializePathwayUsecase, - ], + providers: [PDSPAInitializePathwayCommandHandler, PDSPAInitializePathwayService, PDSPAIUInitializePathwayUsecase], exports: [PDSPAInitializePathwayService], }) // biome-ignore lint/complexity/noStaticOnlyClass: not pertinent here because this is a module @@ -20,16 +16,12 @@ export class PDSPIAInitializePathwayInterfaceAdaptersModule { private static imports: Array = []; static withPersistence(persistenceModule: Type | DynamicModule) { - PDSPIAInitializePathwayInterfaceAdaptersModule.imports.push( - persistenceModule - ); + PDSPIAInitializePathwayInterfaceAdaptersModule.imports.push(persistenceModule); return PDSPIAInitializePathwayInterfaceAdaptersModule; } static withPresenter(presenterModule: Type | DynamicModule) { - PDSPIAInitializePathwayInterfaceAdaptersModule.imports.push( - presenterModule - ); + PDSPIAInitializePathwayInterfaceAdaptersModule.imports.push(presenterModule); return PDSPIAInitializePathwayInterfaceAdaptersModule; } diff --git a/libs/pathway-design/server/pathway/presenters/cucumber.js b/libs/pathway-design/server/pathway/presenters/cucumber.js index 259cda5e..461f3832 100644 --- a/libs/pathway-design/server/pathway/presenters/cucumber.js +++ b/libs/pathway-design/server/pathway/presenters/cucumber.js @@ -1,12 +1,8 @@ module.exports = { default: { - paths: [ - 'libs/pathway-design/server/pathway/presenters/src/lib/**/*.feature', - ], + paths: ['libs/pathway-design/server/pathway/presenters/src/lib/**/*.feature'], requireModule: ['ts-node/register', 'tsconfig-paths/register'], - require: [ - 'libs/pathway-design/server/pathway/presenters/src/lib/**/*.step.ts', - ], + require: ['libs/pathway-design/server/pathway/presenters/src/lib/**/*.step.ts'], format: [ 'json:dist/reports/libs/pathway-design/pathway/presenters/test-feature/index.json', 'html:dist/reports/libs/pathway-design/pathway/presenters/test-feature/index.html', diff --git a/libs/pathway-design/server/pathway/presenters/src/lib/pathway-presenters.module.ts b/libs/pathway-design/server/pathway/presenters/src/lib/pathway-presenters.module.ts index e238e6fd..e73c5876 100644 --- a/libs/pathway-design/server/pathway/presenters/src/lib/pathway-presenters.module.ts +++ b/libs/pathway-design/server/pathway/presenters/src/lib/pathway-presenters.module.ts @@ -1,10 +1,7 @@ import { Module } from '@nestjs/common'; import { ToJsonPathwayPresenterModule } from './toJson/to-json-pathway-presenter.module'; -const presenterModuleMap: Record< - 'toJson', - typeof ToJsonPathwayPresenterModule -> = { +const presenterModuleMap: Record<'toJson', typeof ToJsonPathwayPresenterModule> = { toJson: ToJsonPathwayPresenterModule, }; diff --git a/libs/pathway-design/server/pathway/presenters/src/lib/toJson/to-json-pathway.presenter.ts b/libs/pathway-design/server/pathway/presenters/src/lib/toJson/to-json-pathway.presenter.ts index 05599867..97f56c83 100644 --- a/libs/pathway-design/server/pathway/presenters/src/lib/toJson/to-json-pathway.presenter.ts +++ b/libs/pathway-design/server/pathway/presenters/src/lib/toJson/to-json-pathway.presenter.ts @@ -1,7 +1,4 @@ -import type { - PDSPBEPathwayEntity, - PDSPBPPathwayPresenterPort, -} from '@bewoak/pathway-design-server-pathway-business'; +import type { PDSPBEPathwayEntity, PDSPBPPathwayPresenterPort } from '@bewoak/pathway-design-server-pathway-business'; import { Injectable } from '@nestjs/common'; @Injectable() diff --git a/tsconfig.base.json b/tsconfig.base.json index 02ee9519..7243eca7 100644 --- a/tsconfig.base.json +++ b/tsconfig.base.json @@ -10,24 +10,16 @@ "module": "ES2022", "moduleResolution": "node", "paths": { - "@bewoak/pathway-design-server-pathway-application": [ - "libs/pathway-design/server/pathway/application/src/index.ts" - ], - "@bewoak/pathway-design-server-pathway-business": [ - "libs/pathway-design/server/pathway/business/src/index.ts" - ], + "@bewoak/pathway-design-server-pathway-application": ["libs/pathway-design/server/pathway/application/src/index.ts"], + "@bewoak/pathway-design-server-pathway-business": ["libs/pathway-design/server/pathway/business/src/index.ts"], "@bewoak/pathway-design-server-pathway-infrastructure": [ "libs/pathway-design/server/pathway/infrastructure/src/index.ts" ], - "@bewoak/pathway-design-server-pathway-presenters": [ - "libs/pathway-design/server/pathway/presenters/src/index.ts" - ], + "@bewoak/pathway-design-server-pathway-presenters": ["libs/pathway-design/server/pathway/presenters/src/index.ts"], "@bewoak/pathway-design-server-pathway-interface-adapters": [ "libs/pathway-design/server/pathway/interface-adapters/src/index.ts" ], - "@bewoak/common-tools-server-http-exceptions": [ - "libs/common/tools/server/http-exceptions/src/index.ts" - ] + "@bewoak/common-tools-server-http-exceptions": ["libs/common/tools/server/http-exceptions/src/index.ts"] }, "rootDir": ".", "skipDefaultLibCheck": true,