Skip to content

Commit

Permalink
feat: add in-memory persistence
Browse files Browse the repository at this point in the history
  • Loading branch information
collettemathieu committed Jul 24, 2024
1 parent ebbc879 commit 1580a62
Show file tree
Hide file tree
Showing 48 changed files with 428 additions and 31 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ import { Test } from '@nestjs/testing';

import { PathwayDesignServerPathwayBusinessUsecasesInitPathway } from '@bewoak/pathway-design-server-pathway-business';
import { type Observable, firstValueFrom, of } from 'rxjs';
import { InitPathwayCommand } from './index.command';
import { InitPathwayCommandHandler } from './index.command-handler';
import { InitPathwayCommand } from './init-pathway.command';
import { InitPathwayCommandHandler } from './init-pathway.command-handler';

class InitPathwayMemory
implements PathwayDesignServerPathwayBusinessPortsInitPathwayMemory
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { Inject } from '@nestjs/common';
import { CommandHandler } from '@nestjs/cqrs';

import { PathwayDesignServerPathwayBusinessUsecasesInitPathway } from '@bewoak/pathway-design-server-pathway-business';
import { InitPathwayCommand } from './index.command';
import { InitPathwayCommand } from './init-pathway.command';

@CommandHandler(InitPathwayCommand)
export class InitPathwayCommandHandler {
Expand All @@ -20,13 +20,13 @@ export class InitPathwayCommandHandler {
private readonly pathwayDesignServerPathwayBusinessPortsInitPathwayMemory: PathwayDesignServerPathwayBusinessPortsInitPathwayMemory
) {}

execute(command: InitPathwayCommand) {
execute(initPathwayCommand: InitPathwayCommand) {
return this.pathwayDesignServerPathwayBusinessUsecasesInitPathway.execute(
this.pathwayDesignServerPathwayBusinessPortsInitPathwayMemory,
{
title: command.title,
description: command.description,
researchField: command.researchField,
title: initPathwayCommand.title,
description: initPathwayCommand.description,
researchField: initPathwayCommand.researchField,
}
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ import { beforeEach, describe, expect, mock, test } from 'bun:test';
import type { PathwayDesignServerPathwayBusinessEntitiesPathway } from '@bewoak/pathway-design-server-pathway-business';
import { CommandBus } from '@nestjs/cqrs';
import { Test } from '@nestjs/testing';
import { InitPathwayCommand } from '../commands/index.command';
import { InitPathwayService } from './index.service';
import { InitPathwayCommand } from '../commands/init-pathway.command';
import { InitPathwayService } from './init-pathway.service';

describe('InitPathwayService', () => {
let service: InitPathwayService;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import type { PathwayDesignServerPathwayBusinessEntitiesPathway } from '@bewoak/pathway-design-server-pathway-business';
import { Inject, Injectable } from '@nestjs/common';
import { CommandBus } from '@nestjs/cqrs';
import type { InitPathwayCommand } from '../commands/index.command';
import type { InitPathwayCommand } from '../commands/init-pathway.command';

@Injectable()
export class InitPathwayService {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Module } from '@nestjs/common';

import { InitPathwayCommandHandler } from './initialize-pathway/commands/index.command-handler';
import { InitPathwayService } from './initialize-pathway/services/index.service';
import { InitPathwayCommandHandler } from './initialize-pathway/commands/init-pathway.command-handler';
import { InitPathwayService } from './initialize-pathway/services/init-pathway.service';

@Module({
controllers: [],
Expand Down
4 changes: 2 additions & 2 deletions libs/pathway-design/server/pathway/business/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@ export { PathwayDesignServerPathwayBusinessEntitiesPathway } from './lib/entitie
export {
PATHWAY_DESIGN_SERVER_PATHWAY_BUSINESS_PORTS_INIT_PATHWAY_MEMORY,
type PathwayDesignServerPathwayBusinessPortsInitPathwayMemory,
} from './lib/ports/initialize/index.memory';
export { PathwayDesignServerPathwayBusinessUsecasesInitPathway } from './lib/usecases/intialize/index.usecase';
} from './lib/ports/initialize/init-port.memory';
export { PathwayDesignServerPathwayBusinessUsecasesInitPathway } from './lib/usecases/intialize/init.usecase';
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import type { DescriptionValueObject } from '../value-objects/description';
import type { ResearchFieldValueObjects } from '../value-objects/research-field';
import type { TitleValueObjects } from '../value-objects/title';
import type { DescriptionValueObject } from '../value-objects/description.value-object';
import type { ResearchFieldValueObjects } from '../value-objects/research-field.value-object';
import type { TitleValueObjects } from '../value-objects/title.value-object';
import type { PathwayInitParams } from './pathway.types';

export class PathwayDesignServerPathwayBusinessEntitiesPathway {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import type { DescriptionValueObject } from '../value-objects/description';
import type { ResearchFieldValueObjects } from '../value-objects/research-field';
import type { TitleValueObjects } from '../value-objects/title';
import type { DescriptionValueObject } from '../value-objects/description.value-object';
import type { ResearchFieldValueObjects } from '../value-objects/research-field.value-object';
import type { TitleValueObjects } from '../value-objects/title.value-object';

export interface PathwayInitParams {
description: DescriptionValueObject;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { PathwayDesignServerPathwayBusinessEntitiesPathway } from '../entities/pathway';
import { DescriptionValueObject } from '../value-objects/description';
import { ResearchFieldValueObjects } from '../value-objects/research-field';
import { TitleValueObjects } from '../value-objects/title';
import { DescriptionValueObject } from '../value-objects/description.value-object';
import { ResearchFieldValueObjects } from '../value-objects/research-field.value-object';
import { TitleValueObjects } from '../value-objects/title.value-object';
import type { PathwayInitDto } from './pathway.dto';

export const pathwayFactory = ({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { binding, given, then, when } from 'cucumber-tsflow';
import { PathwayDesignServerPathwayBusinessEntitiesPathway } from '../../entities/pathway';
import { pathwayFactory } from '../../factories/pathway';
import type { PathwayInitDto } from '../../factories/pathway.dto';
import { PathwayDesignServerPathwayBusinessUsecasesChangeNamePathway } from './index.usecase';
import { PathwayDesignServerPathwayBusinessUsecasesChangeNamePathway } from './change-title.usecase';

@binding()
export default class ControllerSteps {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type { PathwayDesignServerPathwayBusinessEntitiesPathway } from '../../entities/pathway';
import { TitleValueObjects } from '../../value-objects/title';
import { TitleValueObjects } from '../../value-objects/title.value-object';

export class PathwayDesignServerPathwayBusinessUsecasesChangeNamePathway {
execute({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ import { binding, then, when } from 'cucumber-tsflow';
import { type Observable, firstValueFrom, of } from 'rxjs';
import type { PathwayDesignServerPathwayBusinessEntitiesPathway } from '../../entities/pathway';
import type { PathwayInitDto } from '../../factories/pathway.dto';
import type { PathwayDesignServerPathwayBusinessPortsInitPathwayMemory } from '../../ports/initialize/index.memory';
import { PathwayDesignServerPathwayBusinessUsecasesInitPathway } from './index.usecase';
import type { PathwayDesignServerPathwayBusinessPortsInitPathwayMemory } from '../../ports/initialize/init-port.memory';
import { PathwayDesignServerPathwayBusinessUsecasesInitPathway } from './init.usecase';

class InitPathwayMemory
implements PathwayDesignServerPathwayBusinessPortsInitPathwayMemory
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { pathwayFactory } from '../../factories/pathway';
import type { PathwayDesignServerPathwayBusinessPortsInitPathwayMemory } from '../../ports/initialize/index.memory';
import type { PathwayDesignServerPathwayBusinessPortsInitPathwayMemory } from '../../ports/initialize/init-port.memory';

export class PathwayDesignServerPathwayBusinessUsecasesInitPathway {
execute(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { beforeAll, describe, expect, test } from 'bun:test';
import { DescriptionValueObject } from './description';
import { DescriptionValueObject } from './description.value-object';

describe('DescriptionValueObject', () => {
let description1: DescriptionValueObject;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { beforeAll, describe, expect, test } from 'bun:test';
import { ResearchFieldValueObjects } from './research-field';
import { ResearchFieldValueObjects } from './research-field.value-object';

describe('ResearchFieldValueObjects', () => {
let researchField1: ResearchFieldValueObjects;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { beforeAll, describe, expect, test } from 'bun:test';
import { TitleValueObjects } from './title';
import { TitleValueObjects } from './title.value-object';

describe('TitleValueObjects', () => {
let title1: TitleValueObjects;
Expand Down
22 changes: 22 additions & 0 deletions libs/pathway-design/server/pathway/infrastructure/.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/pathway-design/server/pathway/infrastructure/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": [{}]
}
15 changes: 15 additions & 0 deletions libs/pathway-design/server/pathway/infrastructure/cucumber.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
module.exports = {
default: {
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',
],
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',
],
},
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"name": "@bewoak/pathway-design-server-pathway-infrastructure",
"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/pathway-design/server/pathway/infrastructure/project.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
{
"name": "pathway-design-server-pathway-infrastructure",
"$schema": "../../../../../../../node_modules/nx/schemas/project-schema.json",
"sourceRoot": "libs/pathway-design/server/pathway/infrastructure/src",
"projectType": "library",
"targets": {
"build": {
"executor": "@nx/js:swc",
"outputs": ["{options.outputPath}"],
"options": {
"outputPath": "dist/libs/pathway-design/server/pathway/infrastructure",
"main": "libs/pathway-design/server/pathway/infrastructure/src/index.ts",
"tsConfig": "libs/pathway-design/server/pathway/infrastructure/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:infrastructure:pathway-design:server"],
"release": {
"version": {
"generatorOptions": {
"packageRoot": "dist/{projectRoot}",
"currentVersionResolver": "git-tag"
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import type { PathwayEntity } from '../entities/pathway.entity';

export const pathways = new Map<string, PathwayEntity>();
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
export class PathwayEntity {
description: string;
id: string;
researchField: string;
title: string;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { Module } from '@nestjs/common';
import { PathwayDesignInfrastructureInitializePathwayPersistenceInMemory } from './init-pathway.memory';

@Module({
imports: [],
providers: [
PathwayDesignInfrastructureInitializePathwayPersistenceInMemory,
],
exports: [PathwayDesignInfrastructureInitializePathwayPersistenceInMemory],
})
export class InitPathwayInMemoryPersistenceModule {}
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
import { PathwayDesignServerPathwayBusinessEntitiesPathway } from '@bewoak/pathway-design-server-pathway-business';
import { type Mock, beforeEach, describe, expect, spyOn, test } from 'bun:test';
import { type Observable, isObservable } from 'rxjs';
import { PathwayDesignInfrastructureInitializePathwayPersistenceInMemory } from './init-pathway.memory';

describe('PathwayDesignInfrastructureInitializePathwayPersistenceInMemory', () => {
describe('When I save a pathway', () => {
let infrastructureInitializePathwayPersistenceInMemory: PathwayDesignInfrastructureInitializePathwayPersistenceInMemory;

let pathway: PathwayDesignServerPathwayBusinessEntitiesPathway;

let infrastructureInitializePathwayPersistenceInMemorySaveSpy: Mock<
(
pathway: PathwayDesignServerPathwayBusinessEntitiesPathway
) => Observable<PathwayDesignServerPathwayBusinessEntitiesPathway>
>;

let result: Observable<PathwayDesignServerPathwayBusinessEntitiesPathway>;

beforeEach(() => {
infrastructureInitializePathwayPersistenceInMemory =
new PathwayDesignInfrastructureInitializePathwayPersistenceInMemory();

pathway = new PathwayDesignServerPathwayBusinessEntitiesPathway();

infrastructureInitializePathwayPersistenceInMemorySaveSpy = spyOn(
infrastructureInitializePathwayPersistenceInMemory,
'save'
);

result =
infrastructureInitializePathwayPersistenceInMemory.save(
pathway
);
});

test('should return the pathway', () => {
expect(
infrastructureInitializePathwayPersistenceInMemory
).toBeDefined();
expect(
infrastructureInitializePathwayPersistenceInMemorySaveSpy
).toHaveBeenCalledWith(pathway);
});

test('result should be an observable of pathway', (done) => {
expect(isObservable(result)).toBe(true);

result.subscribe({
next: (value) => {
expect(value).toBe(pathway);
done();
},
error: (err) => done(err),
});
});
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import type {
PathwayDesignServerPathwayBusinessEntitiesPathway,
PathwayDesignServerPathwayBusinessPortsInitPathwayMemory,
} from '@bewoak/pathway-design-server-pathway-business';
import { of } from 'rxjs';

export class PathwayDesignInfrastructureInitializePathwayPersistenceInMemory
implements PathwayDesignServerPathwayBusinessPortsInitPathwayMemory
{
save(
pathwayDesignServerPathwayBusinessEntitiesPathway: PathwayDesignServerPathwayBusinessEntitiesPathway
) {
return of(pathwayDesignServerPathwayBusinessEntitiesPathway);
}
}
Loading

0 comments on commit 1580a62

Please sign in to comment.