Skip to content

Commit

Permalink
refactor: test change title
Browse files Browse the repository at this point in the history
  • Loading branch information
collettemathieu committed Sep 18, 2024
1 parent 495f61e commit c7a7538
Show file tree
Hide file tree
Showing 42 changed files with 256 additions and 417 deletions.
2 changes: 1 addition & 1 deletion .hooks/commit-msg
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
# #!/bin/sh
#!/bin/sh
echo "Checking with commitlint...."
bun run commitlint --edit $1
4 changes: 1 addition & 3 deletions apps/pathway-design/server/src/app/app.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,7 @@ import { CqrsModule } from '@nestjs/cqrs';
@Module({
imports: [
PDSPIAInitializePathwayInterfaceAdaptersModule.withPersistence(
PDSPIInitializePathwayPersistenceInfrastructureModule.use(
'inMemory'
)
PDSPIInitializePathwayPersistenceInfrastructureModule.use('inMemory')
)
.withPresenter(PDSPPPathwayPresentersModule.use('toJson'))
.build(),
Expand Down
11 changes: 3 additions & 8 deletions apps/pathway-design/server/src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 <JWT>',
description: 'Please enter token in following format: Bearer <JWT>',
name: 'Authorization',
bearerFormat: 'Bearer',
scheme: 'Bearer',
Expand All @@ -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();
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand All @@ -40,28 +38,20 @@ 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')
public thenIShouldRetrieveAPathwayInitiated(dataTable: DataTable) {
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')
Expand Down
3 changes: 1 addition & 2 deletions apps/pathway-design/server/webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -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' }],
}),
],
Expand Down
22 changes: 3 additions & 19 deletions biome.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand Down
8 changes: 2 additions & 6 deletions libs/common/tools/server/http-exceptions/cucumber.js
Original file line number Diff line number Diff line change
@@ -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',
Expand Down
8 changes: 2 additions & 6 deletions libs/pathway-design/server/pathway/application/cucumber.js
Original file line number Diff line number Diff line change
@@ -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',
Expand Down
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -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);
// }
// }
Original file line number Diff line number Diff line change
@@ -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({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,20 +7,14 @@ import {

import { Inject } from '@nestjs/common';
// biome-ignore lint/style/useImportType: <explanation>
import {
CommandHandler,
EventPublisher,
type ICommandHandler,
} from '@nestjs/cqrs';
import { CommandHandler, EventPublisher, type ICommandHandler } from '@nestjs/cqrs';

// biome-ignore lint/style/useImportType: <explanation>
import { PDSPAIUInitializePathwayUsecase } from '../usecase/initialize-pathway.usecase';
import { PDSPAInitializePathwayCommand } from './initialize-pathway.command';

@CommandHandler(PDSPAInitializePathwayCommand)
export class PDSPAInitializePathwayCommandHandler
implements ICommandHandler<PDSPAInitializePathwayCommand>
{
export class PDSPAInitializePathwayCommandHandler implements ICommandHandler<PDSPAInitializePathwayCommand> {
constructor(
private readonly pDSPAIUInitializePathwayUsecase: PDSPAIUInitializePathwayUsecase,
@Inject(PDSPBP_INITIALIZE_PATHWAY_PERSISTENCE_PORT)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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, PDSPBPPathwayPresenters>(pDSPAInitializePathwayCommand);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down Expand Up @@ -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;
Expand All @@ -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');
}

Expand Down Expand Up @@ -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);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
Loading

0 comments on commit c7a7538

Please sign in to comment.