Skip to content

Commit

Permalink
refactor: feature tests
Browse files Browse the repository at this point in the history
  • Loading branch information
collettemathieu committed Oct 9, 2024
1 parent 3e4a5ed commit 6313b5b
Show file tree
Hide file tree
Showing 18 changed files with 352 additions and 564 deletions.
75 changes: 25 additions & 50 deletions .detective/config.json
Original file line number Diff line number Diff line change
@@ -1,52 +1,27 @@
{
"scopes": [
"libs/pathway-design/server/pathway/business/src/lib/entities",
"libs/pathway-design/server/pathway/business/src/lib/events",
"libs/pathway-design/server/pathway/business/src/lib/factories",
"libs/pathway-design/server/pathway/business/src/lib/ports",
"libs/pathway-design/server/pathway/business/src/lib/value-objects",
"libs/pathway-design/server/pathway/infrastructure/src/lib/persistence/common",
"libs/pathway-design/server/pathway/infrastructure/src/lib/persistence/initialize/in-memory",
"libs/pathway-design/server/pathway/interface-adapters/src/lib/initialize/controller",
"libs/pathway-design/server/pathway/interface-adapters/src/lib/initialize/dtos",
"libs/pathway-design/server/pathway/presenters/src/lib/toJson",
"apps/pathway-design/server/src/app",
"libs/pathway-design/server/pathway/application/src/lib/initialize/command",
"libs/pathway-design/server/pathway/application/src/lib/initialize/usecase",
"libs/pathway-design/server/pathway/application/src/lib/initialize/service"
"scopes": [
"apps/pathway-design/server",
"libs/common/events",
"libs/common/tools",
"libs/pathway-design/server/pathway"
],
"groups": [
"apps/pathway-design",
"apps",
"libs/common",
"libs/pathway-design/server",
"libs/pathway-design",
"libs"
],
"entries": [],
"teams": {
"example-team-a": [
"John Doe",
"Jane Doe"
],
"groups": [
"apps/pathway-design/server/src",
"apps/pathway-design/server",
"apps/pathway-design",
"apps",
"libs/pathway-design/server/pathway/application/src/lib/initialize",
"libs/pathway-design/server/pathway/application/src/lib",
"libs/pathway-design/server/pathway/application/src",
"libs/pathway-design/server/pathway/application",
"libs/pathway-design/server/pathway/business/src/lib",
"libs/pathway-design/server/pathway/business/src",
"libs/pathway-design/server/pathway/business",
"libs/pathway-design/server/pathway/infrastructure/src/lib/persistence/initialize",
"libs/pathway-design/server/pathway/infrastructure/src/lib/persistence",
"libs/pathway-design/server/pathway/infrastructure/src/lib",
"libs/pathway-design/server/pathway/infrastructure/src",
"libs/pathway-design/server/pathway/infrastructure",
"libs/pathway-design/server/pathway/interface-adapters/src/lib/initialize",
"libs/pathway-design/server/pathway/interface-adapters/src/lib",
"libs/pathway-design/server/pathway/interface-adapters/src",
"libs/pathway-design/server/pathway/interface-adapters",
"libs/pathway-design/server/pathway/presenters/src/lib",
"libs/pathway-design/server/pathway/presenters/src",
"libs/pathway-design/server/pathway/presenters",
"libs/pathway-design/server/pathway",
"libs/pathway-design/server",
"libs/pathway-design",
"libs"
],
"entries": [],
"teams": {
"example-team-a": ["John Doe", "Jane Doe"],
"example-team-b": ["Max Muster", "Susi Sorglos"]
}
}
"example-team-b": [
"Max Muster",
"Susi Sorglos"
]
}
}
2 changes: 1 addition & 1 deletion .detective/hash
Original file line number Diff line number Diff line change
@@ -1 +1 @@
3601514f0819bed357d1b14c042a0d872079a336
642b80d2d427239e1c6fdcd349f22edd0f79d0e6, v1.1.6
642 changes: 225 additions & 417 deletions .detective/log

Large diffs are not rendered by default.

3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -40,3 +40,6 @@ Thumbs.db

.nx/cache
.nx/workspace-data

# Detective
.detective/log
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
Feature: Change the title of a pathway in a memory database with json presenter
Feature: Platform - Change the title of a pathway in a memory database with json presenter

Scenario: I want to change the title of a learning pathway
Scenario: I want to change the title of a learning pathway on the platform
Given I am authenticated on the platform for change the title of the pathway in memory persistence and json presenter
Given I have a pathway recorded in memory with these data
Given I have a pathway on the platform recorded in memory with these data
| title | description | researchField |
| My Pathway | A test pathway | biology |
When I want to change the title of the pathway in memory to "My New Pathway"
Then I should receive from memory the new title of the pathway
When I want to change the title of the pathway on the platform "My New Pathway"
Then I should receive from the platform the new title of the pathway
| title |
| My New Pathway |

Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import { strict as assert } from 'node:assert';
import type { Http2Server } from 'node:http2';
import { PDSPIPPathwayPersistenceInfrastructureModule } from '@bewoak/pathway-design-server-pathway-infrastructure';
import {
PDSPIAChangeTitlePathwayInterfaceAdaptersModule,
Expand All @@ -11,6 +9,8 @@ import type { INestApplication } from '@nestjs/common';
import { CqrsModule } from '@nestjs/cqrs';
import { Test } from '@nestjs/testing';
import { binding, given, then, when } from 'cucumber-tsflow';
import { strict as assert } from 'node:assert';
import type { Http2Server } from 'node:http2';
import request from 'supertest';

@binding()
Expand All @@ -20,7 +20,7 @@ class ControllerSteps {
private response: request.Response;

@given('I am authenticated on the platform for change the title of the pathway in memory persistence and json presenter')
public async withInMemoryPeristenceAndJsonPresenter() {
public async connectToPlatform() {
const testingModule = await Test.createTestingModule({
imports: [
PDSPIAChangeTitlePathwayInterfaceAdaptersModule.withPresenter(PDSPPPathwayPresentersModule.use('toJson'))
Expand All @@ -38,7 +38,7 @@ class ControllerSteps {
this.httpServer = this.app.getHttpServer();
}

@given('I have a pathway recorded in memory with these data')
@given('I have a pathway on the platform recorded in memory with these data')
public async givenIHaveAPathwayRecordedInMemroy(dataTable: DataTable) {
const firstRow = dataTable.hashes()[0];

Expand All @@ -49,14 +49,14 @@ class ControllerSteps {
});
}

@when('I want to change the title of the pathway in memory to {string}')
@when('I want to change the title of the pathway on the platform {string}')
public async whenIChangeTheTitleOfThePathwayTo(title: string) {
this.response = await request(this.httpServer).patch(`/pathway/change-title/${this.response.body.id}`).send({
title,
});
}

@then('I should receive from memory the new title of the pathway')
@then('I should receive from the platform the new title of the pathway')
public async thenIShouldReceiveTheNewTitleOfThePathway(dataTable: DataTable) {
const firstRow = dataTable.hashes()[0];

Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
Feature: Initialize Pathway in a memory database with json presenter
Feature: Platform - Initialize Pathway in a memory database with json presenter

Scenario: I want to initialize a learning pathway
Scenario: I want to initialize a learning pathway on the platform
Given I am authenticated on the platform for initialize a pathway in memory persistence and json presenter
When I want to initialize a pathway with these data
When I want to initialize on the platform a pathway with these data
| title | description | researchField |
| My Pathway | A test pathway | biology |
Then I should retrieve a pathway initialized with its data
Then I should retrieve from the platform a pathway initialized with its data
| title | description | researchField |
| My Pathway | A test pathway | biology |
Then The pathway should be have a unique identifier
Then The pathway received from the platform should be have a unique identifier


Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import { strict as assert } from 'node:assert';
import type { Http2Server } from 'node:http2';
import { PDSPIPPathwayPersistenceInfrastructureModule } from '@bewoak/pathway-design-server-pathway-infrastructure';
import { PDSPIAInitializePathwayInterfaceAdaptersModule } from '@bewoak/pathway-design-server-pathway-interface-adapters';
import { PDSPPPathwayPresentersModule } from '@bewoak/pathway-design-server-pathway-presenters';
Expand All @@ -8,6 +6,8 @@ import type { INestApplication } from '@nestjs/common';
import { CqrsModule } from '@nestjs/cqrs';
import { Test } from '@nestjs/testing';
import { binding, given, then, when } from 'cucumber-tsflow';
import { strict as assert } from 'node:assert';
import type { Http2Server } from 'node:http2';
import request from 'supertest';

@binding()
Expand All @@ -17,7 +17,7 @@ class ControllerSteps {
private response: request.Response;

@given('I am authenticated on the platform for initialize a pathway in memory persistence and json presenter')
public async withInMemoryPeristenceAndJsonPresenter() {
public async connectToServer() {
const testingModule = await Test.createTestingModule({
imports: [
PDSPIAInitializePathwayInterfaceAdaptersModule.withPresenter(PDSPPPathwayPresentersModule.use('toJson'))
Expand All @@ -33,7 +33,7 @@ class ControllerSteps {
this.httpServer = this.app.getHttpServer();
}

@when('I want to initialize a pathway with these data')
@when('I want to initialize on the platform a pathway with these data')
public async whenIInitiateAPathway(dataTable: DataTable) {
const firstRow = dataTable.hashes()[0];

Expand All @@ -44,7 +44,7 @@ class ControllerSteps {
});
}

@then('I should retrieve a pathway initialized with its data')
@then('I should retrieve from the platform a pathway initialized with its data')
public thenIShouldRetrieveAPathwayInitiated(dataTable: DataTable) {
const firstRow = dataTable.hashes()[0];

Expand All @@ -53,7 +53,7 @@ class ControllerSteps {
assert.strictEqual(this.response.body.researchField, firstRow.researchField);
}

@then('The pathway should be have a unique identifier')
@then('The pathway received from the platform should be have a unique identifier')
public thenThePathwayIdentifierShouldBeUnique() {
assert.notEqual(this.response.body.id, undefined);
assert.notEqual(this.response.body.id, '');
Expand Down
Binary file modified bun.lockb
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ Feature: Application - Change the title of a pathway
| 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 call the presenter to present the pathway with its new title
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
And I should receive the pathway with its new title
| title |
| My New Pathway |
Original file line number Diff line number Diff line change
Expand Up @@ -64,11 +64,11 @@ class FakeEventPublisher {

@binding()
export default class ControllerSteps {
private pDSPACUchangeTitlePathwayUseCase = new PDSPACUChangeTitlePathwayUseCase();
private readonly pDSPACUchangeTitlePathwayUseCase = new PDSPACUChangeTitlePathwayUseCase();
private pDSPBEPathwayEntity: PDSPBEPathwayEntity | undefined;
private fakeEventPublisher = new FakeEventPublisher();
private fakeChangeTitlePathwayPersistence = new FakeChangeTitlePathwayPersistence();
private fakePathwayPresenter = new FakePathwayPresenter();
private readonly fakeEventPublisher = new FakeEventPublisher();
private readonly fakeChangeTitlePathwayPersistence = new FakeChangeTitlePathwayPersistence();
private readonly fakePathwayPresenter = new FakePathwayPresenter();
private persistenceSpy: sinon.SinonSpy | undefined;
private presenterSpy: sinon.SinonSpy | undefined;
private result: PDSPBPPathwayPresenters | undefined;
Expand Down Expand Up @@ -114,22 +114,22 @@ export default class ControllerSteps {
}

@then('It should call the persistence layer to modify the title of the pathway')
public thenItShouldCallThePersistenceLayerToModifyTheTitleOfThePathway() {
public thenPersistenceLayerShouldBeCalled() {
assert(this.persistenceSpy?.calledOnce);
}

@then('It should call the presenter to return the new title of the pathway')
public thenItShouldCallThePresenterToPresentThePathway() {
@then('It should call the presenter to present the pathway with its new title')
public thenPresenterShouldBeCalled() {
assert(this.presenterSpy?.calledOnce);
}

@then('It should emit an event indicating that the title of the pathway has been changed')
public thenItShouldEmitAnEventIndicatingThatTheTitlePathwayHasBeenChanged() {
public thenAnEventShouldBeEmitted() {
assert.ok(FakeEventPublisher.isEventPublished);
}

@then('I should receive the new title of the pathway')
public thenIShouldReceiveTheNewTitleOfPathway(dataTable: DataTable) {
@then('I should receive the pathway with its new title')
public thenIShouldReceiveThePathway(dataTable: DataTable) {
if (this.pDSPBEPathwayEntity === undefined) {
throw new Error('Pathway is not initialized');
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ Feature: Application - Initialize a new pathway
| title | description | researchField |
| My Pathway | A test pathway | biology |
Then It should call the persistence layer to save the pathway
And It should call the presenter to present the pathway
And It should call the presenter to present the pathway initialized
And It should emit an event indicating that the pathway has been initialized
And I should receive the attributes of the pathway
And I should receive the attributes of the pathway initialized
| title | description | researchField |
| My Pathway | A test pathway | biology |
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { strict as assert } from 'node:assert';
import type {
PDSPBEPathwayEntity,
PDSPBPInitializePathwayPersistencePort,
Expand All @@ -8,6 +7,7 @@ import type {
import type { DataTable } from '@cucumber/cucumber';
import type { EventPublisher } from '@nestjs/cqrs';
import { before, binding, then, when } from 'cucumber-tsflow';
import { strict as assert } from 'node:assert';
import sinon from 'sinon';
import { PDSPAIUInitializePathwayUsecase } from '../usecase/initialize-pathway.usecase';

Expand Down Expand Up @@ -42,10 +42,10 @@ class FakeEventPublisher {

@binding()
export default class ControllerSteps {
private fakeEventPublisher = new FakeEventPublisher();
private fakeInitializePathwayPersistence = new FakeInitializePathwayPersistence();
private fakePathwayPresenter = new FakePathwayPresenter();
private pDSPBUInitPathwayUseCase = new PDSPAIUInitializePathwayUsecase();
private readonly fakeEventPublisher = new FakeEventPublisher();
private readonly fakeInitializePathwayPersistence = new FakeInitializePathwayPersistence();
private readonly fakePathwayPresenter = new FakePathwayPresenter();
private readonly pDSPBUInitPathwayUseCase = new PDSPAIUInitializePathwayUsecase();
private persistenceSpy: sinon.SinonSpy | undefined;
private presenterSpy: sinon.SinonSpy | undefined;
private result: PDSPBPPathwayPresenters | undefined;
Expand Down Expand Up @@ -76,7 +76,7 @@ export default class ControllerSteps {
);
}

@then('I should receive the attributes of the pathway')
@then('I should receive the attributes of the pathway initialized')
public thenIShouldReceivePathwayAttributes(dataTable: DataTable) {
const firstRow = dataTable.hashes()[0] as {
title: string;
Expand All @@ -90,17 +90,17 @@ export default class ControllerSteps {
}

@then('It should call the persistence layer to save the pathway')
public thenItShouldCallThePersistenceLayerToSaveThePathway() {
public thenThePersistenceLayerShouldBeCalled() {
assert(this.persistenceSpy?.calledOnce);
}

@then('It should call the presenter to present the pathway')
public thenItShouldCallThePresenterToPresentThePathway() {
@then('It should call the presenter to present the pathway initialized')
public thenThePresenterShouldBeCalled() {
assert(this.presenterSpy?.calledOnce);
}

@then('It should emit an event indicating that the pathway has been initialized')
public thenItShouldEmitAnEventIndicatingThatThePathwayHasBeenInitialized() {
public thenAnEventShouldBeEmitted() {
assert.ok(FakeEventPublisher.isEventPublished);
}
}
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
Feature: Change the title of a pathway
Feature: Business - Change the title of a pathway

Scenario: I want to change the title of a pathway with a valid title
Given I have a pathway with these data
Scenario: I want to change the title of a pathway in business with a valid title
Given I have a pathway in business with these data
| title | description | researchField |
| My Pathway | A test pathway | biology |
When I change the title of the pathway to "My New Pathway"
When I change the title of the pathway in business to "My New Pathway"
Then It should apply an event indicating that the title of the pathway has been changed
Then I should see the title of the pathway changed to "My New Pathway"
Then I should see the title of the pathway in business 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
Given I have a pathway in business with these data
| title | description | researchField |
| My Pathway | A test pathway | biology |
When I change the title of the pathway to ""
Then I should see an error message "Title is required" during the title change
When I change the title of the pathway in business to ""
Then I should see an error message from business "Title is required" during the title change
Loading

0 comments on commit 6313b5b

Please sign in to comment.