Skip to content

Commit

Permalink
feat: wip
Browse files Browse the repository at this point in the history
  • Loading branch information
collettemathieu committed Sep 20, 2024
1 parent c7a7538 commit 1f3a4b1
Show file tree
Hide file tree
Showing 34 changed files with 615 additions and 92 deletions.
22 changes: 22 additions & 0 deletions libs/common/events/.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/events/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/events/cucumber.js
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',
],
},
};
9 changes: 9 additions & 0 deletions libs/common/events/package.json
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"
}
50 changes: 50 additions & 0 deletions libs/common/events/project.json
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"
}
}
}
}
2 changes: 2 additions & 0 deletions libs/common/events/src/index.ts
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';
8 changes: 8 additions & 0 deletions libs/common/events/src/lib/constants.ts
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;
10 changes: 10 additions & 0 deletions libs/common/events/src/lib/types.ts
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];
22 changes: 22 additions & 0 deletions libs/common/events/tsconfig.json
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"
}
]
}
11 changes: 11 additions & 0 deletions libs/common/events/tsconfig.lib.json
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"]
}
10 changes: 10 additions & 0 deletions libs/common/events/tsconfig.spec.json
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"]
}
2 changes: 1 addition & 1 deletion libs/common/tools/server/http-exceptions/project.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "common-tools-server-http-exceptions",
"$schema": "../../../../../../../node_modules/nx/schemas/project-schema.json",
"$schema": "../../../../../node_modules/nx/schemas/project-schema.json",
"sourceRoot": "libs/common/tools/server/http-exceptions/src",
"projectType": "library",
"targets": {
Expand Down
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
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);
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Feature: Initiate a pathway
Feature: Application - Initialize a new pathway

Scenario: When I initiliaze a pathway, an event should be emitted
When I initialize a pathway with these data
Scenario: When I initiliaze a pathway in application, an event should be emitted
When I initialize a pathway in application with these data
| title | description | researchField |
| My Pathway | A test pathway | biology |
Then It should call the persistence layer to save the pathway
Expand Down
Loading

0 comments on commit 1f3a4b1

Please sign in to comment.