Skip to content

Commit

Permalink
feat: add event emitter
Browse files Browse the repository at this point in the history
  • Loading branch information
collettemathieu committed Oct 18, 2024
1 parent fd28269 commit 82bbaa6
Show file tree
Hide file tree
Showing 34 changed files with 408 additions and 13 deletions.
2 changes: 1 addition & 1 deletion .detective/hash
Original file line number Diff line number Diff line change
@@ -1 +1 @@
642b80d2d427239e1c6fdcd349f22edd0f79d0e6, v1.1.6
7293506443296ea9cf3b4c4f9160806365be91e2, v1.1.6
135 changes: 135 additions & 0 deletions .detective/log
Original file line number Diff line number Diff line change
@@ -1,3 +1,138 @@
"Mathieu Collette <[email protected]>,Thu Oct 17 12:05:45 2024 +0200 fd282696dc8ac4c83007497b5bfdfaee134e728b,refactor: extract business rules"
4 1 libs/pathway-design/common/business/pathway/rules/src/index.ts
19 0 libs/pathway-design/common/business/pathway/rules/src/lib/description/description.rules.ts
52 0 libs/pathway-design/common/business/pathway/rules/src/lib/description/description.spec.ts
10 0 libs/pathway-design/common/business/pathway/rules/src/lib/pathway-id/pathway-id.rules.ts
22 0 libs/pathway-design/common/business/pathway/rules/src/lib/pathway-id/pathway-id.spec.ts
19 0 libs/pathway-design/common/business/pathway/rules/src/lib/research-field/research-field.rules.ts
52 0 libs/pathway-design/common/business/pathway/rules/src/lib/research-field/research-field.spec.ts
13 6 libs/pathway-design/common/business/pathway/rules/src/lib/title/title.rules.ts
26 12 libs/pathway-design/common/business/pathway/rules/src/lib/title/title.spec.ts
4 3 libs/pathway-design/common/business/pathway/rules/src/lib/types.ts
0 44 libs/pathway-design/server/pathway/business/src/lib/factories/pathway.factory.spec.ts
2 2 libs/pathway-design/server/pathway/business/src/lib/specs/change-name/change-title-pathway.feature
4 3 libs/pathway-design/server/pathway/business/src/lib/specs/change-name/change-title-pathway.step.ts
4 47 libs/pathway-design/server/pathway/business/src/lib/specs/initialize/initialize-pathway.feature
4 3 libs/pathway-design/server/pathway/business/src/lib/specs/initialize/initialize-pathway.step.ts
3 2 libs/pathway-design/server/pathway/business/src/lib/value-objects/description.value-object.spec.ts
3 6 libs/pathway-design/server/pathway/business/src/lib/value-objects/description.value-object.ts
3 2 libs/pathway-design/server/pathway/business/src/lib/value-objects/pathway-id.value-object.spec.ts
3 8 libs/pathway-design/server/pathway/business/src/lib/value-objects/pathway-id.value-object.ts
3 2 libs/pathway-design/server/pathway/business/src/lib/value-objects/research-field.value-object.spec.ts
3 2 libs/pathway-design/server/pathway/business/src/lib/value-objects/research-field.value-object.ts
3 2 libs/pathway-design/server/pathway/business/src/lib/value-objects/title.value-object.spec.ts
3 3 libs/pathway-design/server/pathway/business/src/lib/value-objects/title.value-object.ts

"Mathieu Collette <[email protected]>,Mon Oct 14 18:42:15 2024 +0200 84773010de01b55d429b7696c29c3056e9aaa362,fix: business rules"
4 4 libs/pathway-design/common/business/pathway/rules/project.json
2 2 libs/pathway-design/common/business/pathway/rules/src/lib/title/title.rules.ts

"Mathieu Collette <[email protected]>,Mon Oct 14 18:30:13 2024 +0200 c12202b6e7f740b6a3fdf59c61b4b05f22531e92,refactor: pathway rules"
22 0 libs/pathway-design/common/business/pathway/rules/.swcrc
17 0 libs/pathway-design/common/business/pathway/rules/biome.json
11 0 libs/pathway-design/common/business/pathway/rules/cucumber.js
9 0 libs/pathway-design/common/business/pathway/rules/package.json
50 0 libs/pathway-design/common/business/pathway/rules/project.json
1 0 libs/pathway-design/common/business/pathway/rules/src/index.ts
12 0 libs/pathway-design/common/business/pathway/rules/src/lib/title/title.rules.ts
38 0 libs/pathway-design/common/business/pathway/rules/src/lib/title/title.spec.ts
6 0 libs/pathway-design/common/business/pathway/rules/src/lib/types.ts
22 0 libs/pathway-design/common/business/pathway/rules/tsconfig.json
11 0 libs/pathway-design/common/business/pathway/rules/tsconfig.lib.json
10 0 libs/pathway-design/common/business/pathway/rules/tsconfig.spec.json
1 1 libs/pathway-design/server/pathway/application/src/index.ts
1 1 libs/pathway-design/server/pathway/application/src/lib/initialize/service/initialize-pathway.service.ts
1 1 libs/pathway-design/server/pathway/business/src/lib/value-objects/description.value-object.ts
1 1 libs/pathway-design/server/pathway/business/src/lib/value-objects/pathway-id.value-object.ts
1 1 libs/pathway-design/server/pathway/business/src/lib/value-objects/research-field.value-object.ts
3 6 libs/pathway-design/server/pathway/business/src/lib/value-objects/title.value-object.ts
2 2 libs/pathway-design/server/pathway/interface-adapters/src/lib/initialize/controller/initialize-pathway.controller.ts
3 3 libs/pathway-design/server/pathway/interface-adapters/src/lib/initialize/initialize-pathway-interface-adapters.module.ts
0 0 libs/{pathway-design/server/common/.keep => search/client/.gitkeep}
0 0 libs/search/{.keep => server/pathway/.gitkeep}
3 0 tsconfig.base.json

"Mathieu Collette <[email protected]>,Fri Oct 11 21:06:03 2024 +0200 a94f94a17feedff2481a42013c43c3eb097790d6,refactor: env variables"
1 1 libs/pathway-design/server/pathway/application/src/index.ts
1 1 libs/pathway-design/server/pathway/application/src/lib/initialize/service/initialize-pathway.service.ts
3 5 libs/pathway-design/server/pathway/infrastructure/src/index.ts
28 0 libs/pathway-design/server/pathway/infrastructure/src/lib/persistence/pathway-persistence-infrastructure.constants.ts
3 24 libs/pathway-design/server/pathway/infrastructure/src/lib/persistence/pathway-persistence-infrastructure.module.ts
1 0 libs/pathway-design/server/pathway/infrastructure/src/lib/persistence/pathway-persistence-infrastructure.types.ts
2 2 libs/pathway-design/server/pathway/interface-adapters/src/lib/initialize/controller/initialize-pathway.controller.ts
3 3 libs/pathway-design/server/pathway/interface-adapters/src/lib/initialize/initialize-pathway-interface-adapters.module.ts
3 5 libs/pathway-design/server/pathway/presenters/src/index.ts
8 0 libs/pathway-design/server/pathway/presenters/src/lib/pathway-presenters.constants.ts
2 9 libs/pathway-design/server/pathway/presenters/src/lib/pathway-presenters.module.ts
1 0 libs/pathway-design/server/pathway/presenters/src/lib/pathway-presenters.types.ts

"Mathieu Collette <[email protected]>,Fri Oct 11 18:10:50 2024 +0200 20f4ced81196ef5adf8ccfbfdcba870df16422cc,feat: choice presenter persistence"
36 17 apps/pathway-design/server/src/app/app.module.ts
10 0 apps/pathway-design/server/src/environment/env.schema.ts
27 30 apps/pathway-design/server/src/main.ts
6 3 apps/pathway-design/server/src/specs/change-title-pathway/index.feature
17 11 apps/pathway-design/server/src/specs/change-title-pathway/index.step.ts
6 4 apps/pathway-design/server/src/specs/initialize-pathway/index.feature
14 8 apps/pathway-design/server/src/specs/initialize-pathway/index.step.ts
3 0 biome.json
- - bun.lockb
22 0 libs/common/configs/server/env/.swcrc
17 0 libs/common/configs/server/env/biome.json
11 0 libs/common/configs/server/env/cucumber.js
9 0 libs/common/configs/server/env/package.json
50 0 libs/common/configs/server/env/project.json
2 0 libs/common/configs/server/env/src/index.ts
15 0 libs/common/configs/server/env/src/lib/check-env-variables.ts
4 0 libs/common/configs/server/env/src/lib/get-env-variables.ts
22 0 libs/common/configs/server/env/tsconfig.json
11 0 libs/common/configs/server/env/tsconfig.lib.json
10 0 libs/common/configs/server/env/tsconfig.spec.json
22 0 libs/common/configs/server/swagger/.swcrc
17 0 libs/common/configs/server/swagger/biome.json
11 0 libs/common/configs/server/swagger/cucumber.js
9 0 libs/common/configs/server/swagger/package.json
50 0 libs/common/configs/server/swagger/project.json
1 0 libs/common/configs/server/swagger/src/index.ts
30 0 libs/common/configs/server/swagger/src/lib/swagger.config.ts
7 0 libs/common/configs/server/swagger/src/lib/types.ts
22 0 libs/common/configs/server/swagger/tsconfig.json
11 0 libs/common/configs/server/swagger/tsconfig.lib.json
10 0 libs/common/configs/server/swagger/tsconfig.spec.json
1 1 libs/pathway-design/server/pathway/application/src/lib/initialize/specs/initialize-pathway.usecase.step.ts
11 3 libs/pathway-design/server/pathway/business/src/lib/entities/pathway.ts
9 3 libs/pathway-design/server/pathway/business/src/lib/events/pathway-initialized.event.ts
1 1 libs/pathway-design/server/pathway/business/src/lib/specs/change-name/change-title-pathway.step.ts
11 2 libs/pathway-design/server/pathway/business/src/lib/specs/initialize/initialize-pathway.step.ts
5 1 libs/pathway-design/server/pathway/infrastructure/src/index.ts
4 2 libs/pathway-design/server/pathway/infrastructure/src/lib/persistence/pathway-persistence-infrastructure.module.ts
5 1 libs/pathway-design/server/pathway/presenters/src/index.ts
4 2 libs/pathway-design/server/pathway/presenters/src/lib/pathway-presenters.module.ts
3 2 package.json
2 0 tsconfig.base.json

"Mathieu Collette <[email protected]>,Wed Oct 9 19:02:42 2024 +0200 bf2d801496fa76753b3d70350c4ab3a5b8efe71c,refactor: formatting"
8 26 .detective/config.json

"Mathieu Collette <[email protected]>,Wed Oct 9 19:02:07 2024 +0200 6313b5bc062895cfb152c14a3b1d880c2369a8eb,refactor: feature tests"
25 50 .detective/config.json
1 1 .detective/hash
225 417 .detective/log
3 0 .gitignore
5 5 apps/pathway-design/server/src/specs/change-title-pathway/index.feature
6 6 apps/pathway-design/server/src/specs/change-title-pathway/index.step.ts
5 5 apps/pathway-design/server/src/specs/initialize-pathway/index.feature
6 6 apps/pathway-design/server/src/specs/initialize-pathway/index.step.ts
- - bun.lockb
2 2 libs/pathway-design/server/pathway/application/src/lib/change-title/specs/change-title-pathway.usecase.feature
10 10 libs/pathway-design/server/pathway/application/src/lib/change-title/specs/change-title-pathway.usecase.step.ts
2 2 libs/pathway-design/server/pathway/application/src/lib/initialize/specs/initialize-pathway.usecase.feature
10 10 libs/pathway-design/server/pathway/application/src/lib/initialize/specs/initialize-pathway.usecase.step.ts
8 8 libs/pathway-design/server/pathway/business/src/lib/specs/change-name/change-title-pathway.feature
5 5 libs/pathway-design/server/pathway/business/src/lib/specs/change-name/change-title-pathway.step.ts
31 31 libs/pathway-design/server/pathway/business/src/lib/specs/initialize/initialize-pathway.feature
4 4 libs/pathway-design/server/pathway/business/src/lib/specs/initialize/initialize-pathway.step.ts
4 2 package.json

"Mathieu Collette <[email protected]>,Sat Sep 14 15:29:45 2024 +0200 3e4a5edcc2aa4cee558971e8876d01ad672d91a0,feat: implement change title"
1 1 .hooks/commit-msg
2 2 apps/pathway-design/server/cucumber.js
Expand Down
Empty file.
11 changes: 10 additions & 1 deletion apps/pathway-design/server/src/app/app.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import {
type PDSPPPresenterDriverAuthorized,
} from '@bewoak/pathway-design-server-pathway-presenters';
import { CqrsModule } from '@nestjs/cqrs';
import { EventEmitterModule } from '@nestjs/event-emitter';

interface ApplicationBootstrapOptions {
persistenceDriver: PDSPIPPersistenceDriverAuthorized;
Expand All @@ -37,7 +38,15 @@ export class AppModule {
.withPersistence(PDSPIPPathwayPersistenceInfrastructureModule.use(options.persistenceDriver))
.build(),
CqrsModule.forRoot(),
CqrsModule.forRoot(),
EventEmitterModule.forRoot({
wildcard: false,
delimiter: '.',
newListener: false,
removeListener: false,
maxListeners: 10,
verboseMemoryLeak: true,
ignoreErrors: false,
}),
],
};
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import {
import type { DataTable } from '@cucumber/cucumber';
import type { INestApplication } from '@nestjs/common';
import { CqrsModule } from '@nestjs/cqrs';
import { EventEmitterModule } from '@nestjs/event-emitter';
import { Test } from '@nestjs/testing';
import { binding, given, then, when } from 'cucumber-tsflow';
import request from 'supertest';
Expand All @@ -36,6 +37,15 @@ class ControllerSteps {
.withPersistence(PDSPIPPathwayPersistenceInfrastructureModule.use(persistence))
.build(),
CqrsModule.forRoot(),
EventEmitterModule.forRoot({
wildcard: false,
delimiter: '.',
newListener: false,
removeListener: false,
maxListeners: 10,
verboseMemoryLeak: true,
ignoreErrors: false,
}),
],
}).compile();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ Feature: Platform - Initialize a Pathway
Then I should retrieve from the platform a pathway initialized with its data
| title | description | researchField |
| My Pathway | A test pathway | biology |
Then The platform should send an event to the event bus with the pathway initialized
Then The pathway received from the platform should be have a unique identifier

Examples:
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { strict as assert } from 'node:assert';
import type { Http2Server } from 'node:http2';
import { CCEPPathwayInitializedEvent } from '@bewoak/common-contracts-events-pathway';
import {
PDSPIPPathwayPersistenceInfrastructureModule,
type PDSPIPPersistenceDriverAuthorized,
Expand All @@ -12,13 +13,17 @@ import {
import type { DataTable } from '@cucumber/cucumber';
import type { INestApplication } from '@nestjs/common';
import { CqrsModule } from '@nestjs/cqrs';
import { EventEmitter2, EventEmitterModule } from '@nestjs/event-emitter';
import { Test } from '@nestjs/testing';
import { binding, given, then, when } from 'cucumber-tsflow';
import sinon from 'sinon';
import request from 'supertest';

@binding()
class ControllerSteps {
private app: INestApplication;
private eventEmitter: EventEmitter2;
private eventEmitterSpy: sinon.SinonSpy | undefined;
private httpServer: Http2Server;
private response: request.Response;

Expand All @@ -30,12 +35,25 @@ class ControllerSteps {
.withPersistence(PDSPIPPathwayPersistenceInfrastructureModule.use(persistence))
.build(),
CqrsModule.forRoot(),
EventEmitterModule.forRoot({
wildcard: false,
delimiter: '.',
newListener: false,
removeListener: false,
maxListeners: 10,
verboseMemoryLeak: true,
ignoreErrors: false,
}),
],
exports: [],
}).compile();

this.app = testingModule.createNestApplication();
await this.app.init();

this.eventEmitter = this.app.get(EventEmitter2);
this.eventEmitterSpy = sinon.spy(this.eventEmitter, 'emit');

this.httpServer = this.app.getHttpServer();
}

Expand All @@ -50,6 +68,23 @@ class ControllerSteps {
});
}

@then('The platform should send an event to the event bus with the pathway initialized')
public thenPlatformSendAnEventToEventBus() {
const expectedEvent = new CCEPPathwayInitializedEvent(
this.response.body.description,
this.response.body.id,
this.response.body.researchField,
this.response.body.title
);

const typeArg = this.eventEmitterSpy?.getCall(0).args[0];
const eventArgs = this.eventEmitterSpy?.getCall(0).args[1];

assert(this.eventEmitterSpy?.calledOnce);
assert.deepStrictEqual(typeArg, expectedEvent.eventType);
assert.deepStrictEqual(eventArgs, expectedEvent);
}

@then('I should retrieve from the platform a pathway initialized with its data')
public thenIShouldRetrieveAPathwayInitiated(dataTable: DataTable) {
const firstRow = dataTable.hashes()[0];
Expand Down
Binary file modified bun.lockb
Binary file not shown.
22 changes: 22 additions & 0 deletions libs/common/contracts/events/pathway/.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/contracts/events/pathway/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/contracts/events/pathway/cucumber.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
module.exports = {
default: {
paths: ['libs/common/contracts/events/pathway/src/lib/**/*.feature'],
requireModule: ['ts-node/register', 'tsconfig-paths/register'],
require: ['libs/common/contracts/events/pathway/src/lib/**/*.step.ts'],
format: [
'json:dist/reports/libs/common/contracts/events/pathway/test-feature/index.json',
'html:dist/reports/libs/common/contracts/events/pathway/test-feature/index.html',
],
},
};
9 changes: 9 additions & 0 deletions libs/common/contracts/events/pathway/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"name": "@bewoak/common-contracts-events-pathway",
"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/contracts/events/pathway/project.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
{
"name": "common-contracts-events-pathway",
"$schema": "../../../../../node_modules/nx/schemas/project-schema.json",
"sourceRoot": "libs/common/contracts/events/pathway/src",
"projectType": "library",
"targets": {
"build": {
"executor": "@nx/js:swc",
"outputs": ["{options.outputPath}"],
"options": {
"outputPath": "dist/libs/common/contracts/events/pathway",
"main": "libs/common/contracts/events/pathway/src/index.ts",
"tsConfig": "libs/common/contracts/events/pathway/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:configs:server:swagger"],
"release": {
"version": {
"generatorOptions": {
"packageRoot": "dist/{projectRoot}",
"currentVersionResolver": "git-tag"
}
}
}
}
1 change: 1 addition & 0 deletions libs/common/contracts/events/pathway/src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { CCEPPathwayInitializedEvent } from './lib/initialized/pathway-initialized.event';
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export const CCEP_EVENT_TYPE_PATHWAY_INITIALIZED = 'PathwayInitialized' as const;
Loading

0 comments on commit 82bbaa6

Please sign in to comment.