-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
c7a7538
commit 1f3a4b1
Showing
34 changed files
with
615 additions
and
92 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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$"] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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": [{}] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
module.exports = { | ||
default: { | ||
paths: ['libs/common/events/src/lib/**/*.feature'], | ||
requireModule: ['ts-node/register', 'tsconfig-paths/register'], | ||
require: ['libs/common/events/src/lib/**/*.step.ts'], | ||
format: [ | ||
'json:dist/reports/libs/common/events/test-feature/index.json', | ||
'html:dist/reports/libs/common/events/test-feature/index.html', | ||
], | ||
}, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
{ | ||
"name": "@bewoak/common-events", | ||
"version": "0.0.1", | ||
"dependencies": { | ||
"@swc/helpers": "~0.5.11" | ||
}, | ||
"main": "./src/index.js", | ||
"typings": "./src/index.d.ts" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
{ | ||
"name": "common-events", | ||
"$schema": "../../../node_modules/nx/schemas/project-schema.json", | ||
"sourceRoot": "libs/common/events/src", | ||
"projectType": "library", | ||
"targets": { | ||
"build": { | ||
"executor": "@nx/js:swc", | ||
"outputs": ["{options.outputPath}"], | ||
"options": { | ||
"outputPath": "dist/libs/common/events", | ||
"main": "libs/common/events/src/index.ts", | ||
"tsConfig": "libs/common/events/tsconfig.lib.json", | ||
"assets": [] | ||
} | ||
}, | ||
"nx-release-publish": { | ||
"options": { | ||
"packageRoot": "dist/{projectRoot}" | ||
} | ||
}, | ||
"lint": { | ||
"executor": "nx:run-commands", | ||
"options": { | ||
"command": "bun run biome check --write {projectRoot} --config-path={projectRoot}/biome.json" | ||
} | ||
}, | ||
"test": { | ||
"executor": "nx:run-commands", | ||
"options": { | ||
"command": "bun test --coverage --coverage-dir=dist/reports/{projectRoot}/coverage --coverage-reporter=lcov {projectRoot}" | ||
} | ||
}, | ||
"test-feature": { | ||
"executor": "nx:run-commands", | ||
"options": { | ||
"command": "TS_NODE_PROJECT='{projectRoot}/tsconfig.spec.json' bun run cucumber-js --config={projectRoot}/cucumber.js" | ||
} | ||
} | ||
}, | ||
"tags": ["type:common:events"], | ||
"release": { | ||
"version": { | ||
"generatorOptions": { | ||
"packageRoot": "dist/{projectRoot}", | ||
"currentVersionResolver": "git-tag" | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
export { CE_EVENT_TYPE_PATHWAY_INITIALIZED, CE_EVENT_TYPE_PATHWAY_TITLE_CHANGED, CE_EVENT_VERSION } from './lib/constants'; | ||
export type { CEEvent, CEEventTypes } from './lib/types'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
export const CE_EVENT_VERSION = 1; | ||
export const CE_EVENT_TYPE_PATHWAY_INITIALIZED = 'PathwayInitialized'; | ||
export const CE_EVENT_TYPE_PATHWAY_TITLE_CHANGED = 'PathwayTitleChanged'; | ||
|
||
export const eventTypes = { | ||
CE_EVENT_TYPE_PATHWAY_INITIALIZED, | ||
CE_EVENT_TYPE_PATHWAY_TITLE_CHANGED, | ||
} as const; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
import type { eventTypes } from './constants'; | ||
|
||
export interface CEEvent { | ||
aggregateId: string; | ||
eventType: CEEventTypes; | ||
payload: Record<string, unknown>; | ||
version: number; | ||
} | ||
|
||
export type CEEventTypes = (typeof eventTypes)[keyof typeof eventTypes]; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
{ | ||
"extends": "../../../tsconfig.base.json", | ||
"compilerOptions": { | ||
"module": "es2022", | ||
"forceConsistentCasingInFileNames": true, | ||
"strict": true, | ||
"noImplicitOverride": true, | ||
"noPropertyAccessFromIndexSignature": true, | ||
"noImplicitReturns": true, | ||
"noFallthroughCasesInSwitch": true | ||
}, | ||
"files": [], | ||
"include": [], | ||
"references": [ | ||
{ | ||
"path": "./tsconfig.lib.json" | ||
}, | ||
{ | ||
"path": "./tsconfig.spec.json" | ||
} | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
{ | ||
"extends": "./tsconfig.json", | ||
"compilerOptions": { | ||
"outDir": "../../../dist/out-tsc", | ||
"types": ["node"], | ||
"composite": true, | ||
"declaration": true | ||
}, | ||
"include": ["src/**/*.ts"], | ||
"exclude": ["src/**/*.spec.ts", "src/**/*.test.ts", "src/**/*.step.ts"] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
{ | ||
"extends": "./tsconfig.json", | ||
"compilerOptions": { | ||
"module": "CommonJS", | ||
"esModuleInterop": true, | ||
"composite": true, | ||
"declaration": true | ||
}, | ||
"include": ["src/**/*.ts"] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
26 changes: 12 additions & 14 deletions
26
...erver/pathway/application/src/lib/change-title/specs/change-title-pathway.usecase.feature
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,13 @@ | ||
# Feature: Change the title of a pathway | ||
Feature: Application - 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 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: Given a valid pathway in application, when I change the title of the pathway, an event should be emitted | ||
Given I have a pathway in application with these data | ||
| title | description | researchField | | ||
| My Pathway | A test pathway | biology | | ||
When I want to change the title of the pathway in application to "My New Pathway" | ||
Then It should call the persistence layer to modify the title of the pathway | ||
And It should call the presenter to return the new title of the pathway | ||
And It should emit an event indicating that the title of the pathway has been changed | ||
And I should receive the new title of the pathway | ||
| title | ||
| My New Pathway |
167 changes: 116 additions & 51 deletions
167
...erver/pathway/application/src/lib/change-title/specs/change-title-pathway.usecase.step.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,51 +1,116 @@ | ||
// 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'; | ||
|
||
// @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; | ||
// }; | ||
|
||
// 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; | ||
// } | ||
// } | ||
|
||
// @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); | ||
// } | ||
// } | ||
import { strict as assert } from 'node:assert'; | ||
|
||
import { | ||
type PDSPBEPathwayEntity, | ||
type PDSPBPPathwayPresenterPort, | ||
type PDSPBPPathwayPresenters, | ||
pDSPBFPathwayFactory, | ||
} from '@bewoak/pathway-design-server-pathway-business'; | ||
import type { DataTable } from '@cucumber/cucumber'; | ||
import { before, binding, given, then, when } from 'cucumber-tsflow'; | ||
import sinon from 'sinon'; | ||
import { PDSPBUChangeTitlePathwayUseCase } from '../usecase/change-title-pathway.usecase'; | ||
|
||
class FakeChangeTitlePathwayPersistence implements PDSPBPInitializePathwayPersistencePort { | ||
save(pDSPBEPathwayEntity: PDSPBEPathwayEntity) { | ||
return Promise.resolve(pDSPBEPathwayEntity); | ||
} | ||
} | ||
|
||
class FakePathwayPresenter implements PDSPBPPathwayPresenterPort { | ||
present(pDSPBEPathwayEntity: PDSPBEPathwayEntity) { | ||
return { | ||
description: pDSPBEPathwayEntity.description, | ||
id: pDSPBEPathwayEntity.id, | ||
researchField: pDSPBEPathwayEntity.researchField, | ||
title: pDSPBEPathwayEntity.title, | ||
}; | ||
} | ||
} | ||
|
||
class FakeEventPublisher { | ||
static isEventPublished = false; | ||
|
||
mergeObjectContext(object: PDSPBEPathwayEntity) { | ||
object.publishAll = () => { | ||
FakeEventPublisher.isEventPublished = true; | ||
}; | ||
|
||
return object; | ||
} | ||
} | ||
|
||
@binding() | ||
export default class ControllerSteps { | ||
private PDSPBUchangeTitlePathwayUseCase = new PDSPBUChangeTitlePathwayUseCase(); | ||
private pDSPBEPathwayEntity: PDSPBEPathwayEntity | undefined; | ||
private fakeEventPublisher = new FakeEventPublisher(); | ||
private fakeChangeTitlePathwayPersistence = new FakeChangeTitlePathwayPersistence(); | ||
private fakePathwayPresenter = new FakePathwayPresenter(); | ||
private persistenceSpy: sinon.SinonSpy | undefined; | ||
private presenterSpy: sinon.SinonSpy | undefined; | ||
private result: PDSPBPPathwayPresenters | undefined; | ||
|
||
@before() | ||
public before() { | ||
this.persistenceSpy = sinon.spy(this.fakeChangeTitlePathwayPersistence, 'save'); | ||
this.presenterSpy = sinon.spy(this.fakePathwayPresenter, 'present'); | ||
} | ||
|
||
@given('I have a pathway in application 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 want to change the title of the pathway in application to {string}') | ||
public async whenIChangeTheTitleOfThePathwayTo(title: string) { | ||
if (this.pDSPBEPathwayEntity === undefined) { | ||
throw new Error('Pathway is not initialized'); | ||
} | ||
|
||
this.result = await this.PDSPBUchangeTitlePathwayUseCase.execute({ | ||
pathway: this.pDSPBEPathwayEntity, | ||
title, | ||
}); | ||
} | ||
|
||
@then('I should receive the new title of the pathway') | ||
public thenIShouldReceiveTheNewTitleOfPathway(dataTable: DataTable) { | ||
if (this.pDSPBEPathwayEntity === undefined) { | ||
throw new Error('Pathway is not initialized'); | ||
} | ||
|
||
const firstRow = dataTable.hashes()[0] as { | ||
title: string; | ||
}; | ||
|
||
assert.strictEqual(this.result?.title, firstRow.title); | ||
assert.strictEqual(this.result?.description, this.pDSPBEPathwayEntity.description); | ||
assert.strictEqual(this.result?.researchField, this.pDSPBEPathwayEntity.researchField); | ||
} | ||
|
||
@then('It should call the persistence layer to modify the title of the pathway') | ||
public thenItShouldCallThePersistenceLayerToModifyTheTitleOfThePathway() { | ||
assert(this.persistenceSpy?.calledOnce); | ||
} | ||
|
||
@then('It should call the presenter to return the new title of the pathway') | ||
public thenItShouldCallThePresenterToPresentThePathway() { | ||
assert(this.presenterSpy?.calledOnce); | ||
} | ||
|
||
@then('It should emit an event indicating that the title of the pathway has been changed') | ||
public thenItShouldEmitAnEventIndicatingThatTheTitlePathwayHasBeenChanged() { | ||
assert.ok(FakeEventPublisher.isEventPublished); | ||
} | ||
} |
6 changes: 3 additions & 3 deletions
6
...gn/server/pathway/application/src/lib/initialize/specs/initialize-pathway.usecase.feature
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.