From 7d54328eb3dfd7c62952bad51e78d1f6762b32d8 Mon Sep 17 00:00:00 2001 From: Mohit Gupta Date: Wed, 20 Mar 2024 23:07:58 -0400 Subject: [PATCH] changes --- event-bus-seedwork-node/node-event-bus.ts | 16 ++- features/ike.feature1 | 5 + features/service-ticket.feature | 10 +- features/split-steps.feature | 10 +- features/step-definitions/iw.steps.ts | 5 + .../step-definitions/service-ticket.steps.ts | 16 ++- .../step-definitions/split-steps.steps.ts | 2 + features/support/serenity.config.ts | 21 +++- features/{test.feature => test.feature1} | 0 features/test2.feature1 | 3 + .../domain/interact-with-the-domain.ts | 28 +++-- ...domain-infrastructure-impl-instance-bdd.ts | 104 ++++++++++-------- screenplay/questions/community-in-db.ts | 2 +- .../questions/property-in-community-in-db.ts | 2 +- .../questions/role-for-community-in-db.ts | 6 +- screenplay/tasks/create-community.ts | 18 ++- screenplay/tasks/log-data-sources.ts | 6 +- .../infrastructure/memory-repository.ts | 2 + .../infrastructure/memory-store.ts | 1 + .../infrastructure/memory-unit-of-work.ts | 4 +- 20 files changed, 172 insertions(+), 89 deletions(-) create mode 100644 features/ike.feature1 create mode 100644 features/step-definitions/iw.steps.ts rename features/{test.feature => test.feature1} (100%) create mode 100644 features/test2.feature1 diff --git a/event-bus-seedwork-node/node-event-bus.ts b/event-bus-seedwork-node/node-event-bus.ts index 24e4babf..1f705a14 100644 --- a/event-bus-seedwork-node/node-event-bus.ts +++ b/event-bus-seedwork-node/node-event-bus.ts @@ -3,6 +3,7 @@ import { CustomDomainEvent, DomainEvent } from '../domain-seedwork/domain-event' import { EventBus } from '../domain-seedwork/event-bus'; import api, { trace,TimeInput, SpanStatusCode } from '@opentelemetry/api'; import { SemanticAttributes } from "@opentelemetry/semantic-conventions"; +import { off } from 'process'; class BroadCaster { private eventEmitter: EventEmitter; @@ -18,6 +19,11 @@ class BroadCaster { public on(event: string, listener: any) { this.eventEmitter.on(event, listener); } + + public removeAllListeners() { + this.eventEmitter.removeAllListeners(); + console.log(`pending listeners: ${this.eventEmitter.eventNames()}`) + } } class NodeEventBusImpl implements EventBus { @@ -28,6 +34,12 @@ class NodeEventBusImpl implements EventBus { this.broadcaster = new BroadCaster(); } + removeAllListeners() { + console.log('Removing all listeners'); + this.broadcaster.removeAllListeners(); + console.log('All listeners removed'); + } + async dispatch(event: new(...args:any) => T, data: any): Promise { console.log(`Dispatching node event ${event.constructor.name} with data ${JSON.stringify(data)}`); @@ -52,7 +64,7 @@ class NodeEventBusImpl implements EventBus { } }); } - + register>(event:new(...args:any) => T, func:(payload:T['payload']) => Promise): void { console.log(`Registering node event handler for: ${event.name}`); @@ -84,7 +96,7 @@ class NodeEventBusImpl implements EventBus { } catch(e) { span.recordException(e); span.setStatus({code: SpanStatusCode.ERROR, message: `NodeEventBus: Error executing ${event.name}`}); - console.error(`Error handling node event ${event.name} with data ${rawPayload}`); + console.error(`Error handling node event ${event.name} with data ${JSON.stringify(rawPayload)}`); console.error(e); } finally { span.end(); diff --git a/features/ike.feature1 b/features/ike.feature1 new file mode 100644 index 00000000..eb001ec4 --- /dev/null +++ b/features/ike.feature1 @@ -0,0 +1,5 @@ +Feature: Test IW + Scenario: Test IW + Given IwTheTest not working + When IwTheTest is not working + Then IwTheTest does not work \ No newline at end of file diff --git a/features/service-ticket.feature b/features/service-ticket.feature index 6ea044ce..6dab3e81 100644 --- a/features/service-ticket.feature +++ b/features/service-ticket.feature @@ -1,8 +1,8 @@ Feature: Create a service ticket -Background: - Given OwenTheOwner creates Atlantis community - And he creates CommunityManager role in Atlantis community with following permissions: + Background: + Given OwenTheOwner creates Atlantis community + And he creates CommunityManager role in Atlantis community with following permissions: | communityPermissions | canManageRolesAndPermissions, canManageSiteContent, canManageMembers | | serviceTicketPermissions | canManageTickets | | servicePermissions | canManageServices | @@ -41,8 +41,8 @@ Background: -Scenario: Setup - Given test setup + Scenario: Setup Service Ticket + Given test setup # Given SamTheSystem creates community Palms # And SamTheSystem creates property Cottage in Atlantis # And he creates property Villa in Atlantis diff --git a/features/split-steps.feature b/features/split-steps.feature index 03ec1ca7..e2699155 100644 --- a/features/split-steps.feature +++ b/features/split-steps.feature @@ -1,8 +1,8 @@ Feature: Create a service ticket -Background: - Given OttoTheOwner registers with Owner Community - And he creates community named Palms + Background: + Given OttoTheOwner registers with Owner Community + And he creates community named Palms # And he creates CommunityManager role in Atlantis community with following permissions: # | communityPermissions | canManageRolesAndPermissions, canManageSiteContent, canManageMembers | # | serviceTicketPermissions | canManageTickets | @@ -42,8 +42,8 @@ Background: -Scenario: Setup - Given test setup + Scenario: Setup Split + Given test setup # Given SamTheSystem creates community Palms # And SamTheSystem creates property Cottage in Atlantis # And he creates property Villa in Atlantis diff --git a/features/step-definitions/iw.steps.ts b/features/step-definitions/iw.steps.ts new file mode 100644 index 00000000..26a9bf3d --- /dev/null +++ b/features/step-definitions/iw.steps.ts @@ -0,0 +1,5 @@ +import { Given, Then, When } from "@cucumber/cucumber"; + +Given('{actor} not working', function(actor){}); +When('{actor} not is working', function(actor){}); +Then('{actor} does not work', function(actor){}); \ No newline at end of file diff --git a/features/step-definitions/service-ticket.steps.ts b/features/step-definitions/service-ticket.steps.ts index 6995112a..4d0c1c19 100644 --- a/features/step-definitions/service-ticket.steps.ts +++ b/features/step-definitions/service-ticket.steps.ts @@ -1,10 +1,13 @@ import { Given, When, DataTable } from '@cucumber/cucumber'; -import { Actor } from '@serenity-js/core'; +import { Actor, Wait } from '@serenity-js/core'; import { CreateRole } from '../../screenplay/tasks/create-role'; import { CreateCommunity } from '../../screenplay/tasks/create-community'; import { Register } from '../../screenplay/tasks/register'; import { CreateProperty } from '../../screenplay/tasks/create-property'; import { LogDataSources } from '../../screenplay/tasks/log-data-sources'; +import { CommunityInDb } from '../../screenplay/questions/community-in-db'; +import { Ensure, isPresent } from '@serenity-js/assertions'; +import { RoleForCommunityInDb } from '../../screenplay/questions/role-for-community-in-db'; Given('test setup', async function(){}); @@ -12,12 +15,19 @@ Given('{actor} creates {word} community', async function(actor: Actor, community await actor .attemptsTo( Register.asUser() - , CreateCommunity.named(communityName) + , await CreateCommunity.named(communityName) + // , Wait.until((await CommunityInDb(communityName)), isPresent()) + // , Wait.until((await RoleForCommunityInDb(communityName, 'admin')), isPresent()) + , Ensure.eventually((await RoleForCommunityInDb(communityName, 'admin')), isPresent()) // , LogDataSources() + ,LogDataSources('service-ticket-steps::{actor}'), ); }); When('{pronoun} creates {word} role in {word} community with following permissions:', async function(actor: Actor, roleName: string, communityName: string, dataTable: DataTable){ + console.log(` ^^ actor: ${actor.name}`) + LogDataSources('service-ticket-steps::{pronoun}'), + console.log(`+++ after log data sources`) await actor .attemptsTo( CreateRole @@ -27,8 +37,8 @@ Given('{actor} creates {word} community', async function(actor: Actor, community , CreateProperty .inCommunity(communityName) .asNewPropertyNamed('property1') - // , LogDataSources() ); + console.log(`@@@ after tasks`) }); diff --git a/features/step-definitions/split-steps.steps.ts b/features/step-definitions/split-steps.steps.ts index 4717783e..364b5f19 100644 --- a/features/step-definitions/split-steps.steps.ts +++ b/features/step-definitions/split-steps.steps.ts @@ -1,11 +1,13 @@ import { Given, When } from '@cucumber/cucumber'; import { Actor } from '@serenity-js/core'; import { Register } from '../../screenplay/tasks/register'; +import { CreateCommunity } from '../../screenplay/tasks/create-community'; Given('{actor} registers with Owner Community', async function(actor: Actor){ await actor .attemptsTo( Register.asUser(), + await CreateCommunity.named('other-community'), ); }); diff --git a/features/support/serenity.config.ts b/features/support/serenity.config.ts index 8a23df62..7dc0f561 100644 --- a/features/support/serenity.config.ts +++ b/features/support/serenity.config.ts @@ -1,4 +1,4 @@ -import { AfterAll, BeforeAll, setDefaultTimeout, defineParameterType, Before } from '@cucumber/cucumber'; +import { AfterAll, BeforeAll, setDefaultTimeout, defineParameterType, Before, After } from '@cucumber/cucumber'; import { ConsoleReporter } from '@serenity-js/console-reporter'; import { actorCalled, actorInTheSpotlight, ArtifactArchiver, configure, Duration } from '@serenity-js/core'; import { SerenityBDDReporter } from '@serenity-js/serenity-bdd'; @@ -28,10 +28,27 @@ const timeouts = { // let browser: playwright.Browser; -Before(() => { +Before(function logScenarioNameBefore(scenario) { + console.log(`*** BEFORE Scenario : ${scenario.pickle.name} **************************************`); InteractWithTheDomain.init(); }); +After(function logScenarioNameBefore(scenario) { + InteractWithTheDomain.close(); + console.log(`*** AFTER Scenario : ${scenario.pickle.name} **************************************`); +}); + +const { AfterStep, BeforeStep } = require('@cucumber/cucumber'); + +BeforeStep(async function logStepNameBefore(step) { + console.log(`=== BEFORE Step : ${step.pickleStep.text} ======================================`); + InteractWithTheDomain.asReadOnly().logDatabase('BeforeStep'); +}); + +AfterStep(async function logStepNameAfter(step) { + console.log(`=== AFTER Step : ${step.pickleStep.text} ======================================`); +}); + BeforeAll(async () => { // InteractWithTheDomain.init(); // Launch the browser once before all the tests diff --git a/features/test.feature b/features/test.feature1 similarity index 100% rename from features/test.feature rename to features/test.feature1 diff --git a/features/test2.feature1 b/features/test2.feature1 new file mode 100644 index 00000000..cd15a2c1 --- /dev/null +++ b/features/test2.feature1 @@ -0,0 +1,3 @@ +Feature: Test MG2 + Scenario: Test MG2 + Given Mg2TheTest working \ No newline at end of file diff --git a/screenplay/abilities/domain/interact-with-the-domain.ts b/screenplay/abilities/domain/interact-with-the-domain.ts index e1d44814..086f3686 100644 --- a/screenplay/abilities/domain/interact-with-the-domain.ts +++ b/screenplay/abilities/domain/interact-with-the-domain.ts @@ -11,7 +11,8 @@ import { RoleProps } from '../../../domain/contexts/community/role'; import { MemberRepository } from '../../../domain/contexts/community/member.repository'; import { Member, MemberEntityReference, MemberProps } from '../../../domain/contexts/community/member'; import { DomainExecutionContext } from '../../../domain/contexts/execution-context'; -import { getDomainInfrastructureImplInstanceBDD } from './io/domain-infrastructure-impl-instance-bdd'; +// import { getDomainInfrastructureImplInstanceBDD } from './io/domain-infrastructure-impl-instance-bdd'; +import { DomainInfrastructureImplBDD } from './io/domain-infrastructure-impl-instance-bdd'; import InitializeDomainBDD from './io/test/initialize-domain-bdd'; import { ReadOnlyContext, SystemExecutionContext } from '../../../domain/contexts/execution-context'; import { PassportImpl } from '../../../domain/contexts/iam/passport'; @@ -22,6 +23,7 @@ import { NotepadType } from '../../actors'; import { MemoryCognitiveSearchImpl } from '../../../infrastructure-impl/cognitive-search/in-memory/infrastructure'; import { PropertyRepository } from '../../../domain/contexts/property/property.repository'; import { PropertyProps } from '../../../domain/contexts/property/property'; +import { InProcEventBusInstance, NodeEventBusInstance } from '../../../event-bus-seedwork-node'; export interface InteractWithTheDomainAsUnregisteredUser { registerAsUser: (actor: Actor) => Promise; @@ -51,8 +53,8 @@ export interface InteractWithTheDomainAsReadOnly { readMemberDb: (func:(db: ReadOnlyMemoryStore) => Promise) => Promise; readUserDb: (func:(db: ReadOnlyMemoryStore) => Promise) => Promise; readPropertyDb: (func:(db: ReadOnlyMemoryStore) => Promise) => Promise; - logSearchDatabase: () => Promise; - logDatabase: () => Promise; + logSearchDatabase: (description: string) => Promise; + logDatabase: (description: string) => Promise; } export class InteractWithTheDomain extends Ability @@ -72,14 +74,22 @@ export class InteractWithTheDomain extends Ability // if(this._initialized === false) { this.startWithEmptyDatabase(); this.startWithEmptySearchDatabase(); - InitializeDomainBDD(getDomainInfrastructureImplInstanceBDD( + InitializeDomainBDD(new DomainInfrastructureImplBDD( InteractWithTheDomain._database, InteractWithTheDomain._searchDatabase )); + // InitializeDomainBDD(getDomainInfrastructureImplInstanceBDD( + // InteractWithTheDomain._database, + // InteractWithTheDomain._searchDatabase + // )); // this._initialized = true; // } } + public static close() { + NodeEventBusInstance.removeAllListeners(); + } + private static using(context: DomainExecutionContext) { // this.init(); return new InteractWithTheDomain(context); @@ -217,7 +227,7 @@ export class InteractWithTheDomain extends Ability public async createCommunity(communityName: string): Promise { let community: CommunityProps; - InteractWithTheDomain._database.CommunityUnitOfWork.withTransaction(this.context, async (repo) => { + await InteractWithTheDomain._database.CommunityUnitOfWork.withTransaction(this.context, async (repo) => { const user: UserEntityReference = await this.getOrCreateUserForActor(actorInTheSpotlight()); const communityToBeSaved = await repo.getNewInstance(communityName, user); const savedCommunity = await repo.save(communityToBeSaved); @@ -275,13 +285,13 @@ export class InteractWithTheDomain extends Ability return await func(InteractWithTheDomain._database.PropertyMemoryStore); } - public async logSearchDatabase() { - console.log('===> Memory Search Database ************'); + public async logSearchDatabase(description: string) { + console.log(`===> Memory Search Database : ${description} ************`); InteractWithTheDomain._searchDatabase.logSearchCollectionIndexMap(); } - public async logDatabase() { - console.log('===> Memory Database ************'); + public async logDatabase(description: string) { + console.log(`===> Memory Database : ${description} ************`); await InteractWithTheDomain.asReadOnly().readCommunityDb(async (db) => { console.log('===> database > community : ', JSON.stringify(db)); }); diff --git a/screenplay/abilities/domain/io/domain-infrastructure-impl-instance-bdd.ts b/screenplay/abilities/domain/io/domain-infrastructure-impl-instance-bdd.ts index ba736683..77f583ff 100644 --- a/screenplay/abilities/domain/io/domain-infrastructure-impl-instance-bdd.ts +++ b/screenplay/abilities/domain/io/domain-infrastructure-impl-instance-bdd.ts @@ -14,14 +14,14 @@ import { IMemoryDatabase } from '../../../../infrastructure-impl/datastore/memor import { DataStoreInfrastructure } from '../../../../infrastructure-impl/datastore/interfaces'; import { CognitiveSearchInfrastructure } from '../../../../infrastructure-impl/cognitive-search/interfaces'; -class DomainInfrastructureImplBDD implements DomainInfrastructureBDD{ +export class DomainInfrastructureImplBDD implements DomainInfrastructureBDD{ // private _vercel: IVercel; // private _contentModerator: IContentModerator; private _cognitiveSearch: CognitiveSearchInfrastructure; // private _blobStorage: IBlobStorage; private _dataStore: DataStoreInfrastructure private _database: IMemoryDatabase; - private constructor( + constructor( database: IMemoryDatabase, cognitiveSearch: CognitiveSearchInfrastructure ) { @@ -31,7 +31,7 @@ class DomainInfrastructureImplBDD implements DomainInfrastructureBDD{ this._cognitiveSearch = cognitiveSearch; // this._blobStorage = this.InitBlobStorage(); this._database = database; - this._dataStore = this.InitDataStore(); + // this._dataStore = this.InitDataStore(); } /* @@ -79,54 +79,62 @@ class DomainInfrastructureImplBDD implements DomainInfrastructureBDD{ return this._cognitiveSearch; } - public get communityUnitOfWork(): CommunityUnitOfWork { - return this._database.CommunityUnitOfWork; - } - public get memberUnitOfWork(): MemberUnitOfWork { - return this._database.MemberUnitOfWork; - } - public get roleUnitOfWork(): RoleUnitOfWork { - return this._database.RoleUnitOfWork; - } - public get propertyUnitOfWork(): PropertyUnitOfWork { - return this._database.PropertyUnitOfWork; - } - public get serviceUnitOfWork(): ServiceUnitOfWork { - return this._database.ServiceUnitOfWork; - } - public get serviceTicketUnitOfWork(): ServiceTicketUnitOfWork { - return this._database.ServiceTicketUnitOfWork; - } - private InitDataStore(): DataStoreInfrastructure { + // public get communityUnitOfWork(): CommunityUnitOfWork { + // return this._database.CommunityUnitOfWork; + // } + // public get memberUnitOfWork(): MemberUnitOfWork { + // return this._database.MemberUnitOfWork; + // } + // public get roleUnitOfWork(): RoleUnitOfWork { + // return this._database.RoleUnitOfWork; + // } + // public get propertyUnitOfWork(): PropertyUnitOfWork { + // return this._database.PropertyUnitOfWork; + // } + // public get serviceUnitOfWork(): ServiceUnitOfWork { + // return this._database.ServiceUnitOfWork; + // } + // public get serviceTicketUnitOfWork(): ServiceTicketUnitOfWork { + // return this._database.ServiceTicketUnitOfWork; + // } + // private InitDataStore(): DataStoreInfrastructure { + // return { + // communityUnitOfWork: this.communityUnitOfWork, + // memberUnitOfWork: this.memberUnitOfWork, + // roleUnitOfWork: this.roleUnitOfWork, + // propertyUnitOfWork: this.propertyUnitOfWork, + // serviceUnitOfWork: this.serviceUnitOfWork, + // serviceTicketUnitOfWork: this.serviceTicketUnitOfWork + // } + // } + public get dataStore(): DataStoreInfrastructure { + // return this._dataStore; return { - communityUnitOfWork: this.communityUnitOfWork, - memberUnitOfWork: this.memberUnitOfWork, - roleUnitOfWork: this.roleUnitOfWork, - propertyUnitOfWork: this.propertyUnitOfWork, - serviceUnitOfWork: this.serviceUnitOfWork, - serviceTicketUnitOfWork: this.serviceTicketUnitOfWork + communityUnitOfWork: this._database.CommunityUnitOfWork, + memberUnitOfWork: this._database.MemberUnitOfWork, + roleUnitOfWork: this._database.RoleUnitOfWork, + propertyUnitOfWork: this._database.PropertyUnitOfWork, + serviceUnitOfWork: this._database.ServiceUnitOfWork, + serviceTicketUnitOfWork: this._database.ServiceTicketUnitOfWork } } - public get dataStore(): DataStoreInfrastructure { - return this._dataStore; - } - private static instance: DomainInfrastructureImplBDD; - public static getInstance( - database: IMemoryDatabase, - cognitiveSearch: CognitiveSearchInfrastructure - ): DomainInfrastructureImplBDD { - if (!this.instance) { - this.instance = new this(database, cognitiveSearch); - } - return this.instance; - } + // private static instance: DomainInfrastructureImplBDD; + // public static getInstance( + // database: IMemoryDatabase, + // cognitiveSearch: CognitiveSearchInfrastructure + // ): DomainInfrastructureImplBDD { + // if (!this.instance) { + // this.instance = new this(database, cognitiveSearch); + // } + // return this.instance; + // } } -export const getDomainInfrastructureImplInstanceBDD = ( - database: IMemoryDatabase, - cognitiveSearch: CognitiveSearchInfrastructure -) => DomainInfrastructureImplBDD.getInstance( - database, - cognitiveSearch -); \ No newline at end of file +// export const getDomainInfrastructureImplInstanceBDD = ( +// database: IMemoryDatabase, +// cognitiveSearch: CognitiveSearchInfrastructure +// ) => DomainInfrastructureImplBDD.getInstance( +// database, +// cognitiveSearch +// ); \ No newline at end of file diff --git a/screenplay/questions/community-in-db.ts b/screenplay/questions/community-in-db.ts index 1a06271a..edf1912f 100644 --- a/screenplay/questions/community-in-db.ts +++ b/screenplay/questions/community-in-db.ts @@ -5,7 +5,7 @@ import { CommunityProps } from '../../domain/contexts/community/community'; export const CommunityInDb = async (communityName: string) => Question.about(`read ${communityName} community`, async (actor) => { let community: CommunityProps; await InteractWithTheDomain.asReadOnly().readCommunityDb(async (db) => { - community = (await db.getAll()).find((c) => c.name === communityName); + community = (await db?.getAll())?.find((c) => c.name === communityName); }); return community; }); diff --git a/screenplay/questions/property-in-community-in-db.ts b/screenplay/questions/property-in-community-in-db.ts index e84e9195..b347da46 100644 --- a/screenplay/questions/property-in-community-in-db.ts +++ b/screenplay/questions/property-in-community-in-db.ts @@ -5,7 +5,7 @@ import { PropertyProps } from '../../domain/contexts/property/property'; export const PropertyInCommunityInDb = async (communityName: string, propertyName:string) => Question.about(`read ${propertyName} property in ${communityName} community`, async (actor) => { let property: PropertyProps; await InteractWithTheDomain.asReadOnly().readPropertyDb(async (db) => { - property = (await db.getAll()).find((p) => p.community.name === communityName && p.propertyName === propertyName); + property = (await db?.getAll()).find((p) => p.community.name === communityName && p.propertyName === propertyName); }); return property; }); diff --git a/screenplay/questions/role-for-community-in-db.ts b/screenplay/questions/role-for-community-in-db.ts index c24d0bbd..12cbee45 100644 --- a/screenplay/questions/role-for-community-in-db.ts +++ b/screenplay/questions/role-for-community-in-db.ts @@ -2,10 +2,10 @@ import { Question } from '@serenity-js/core/lib/screenplay'; import { InteractWithTheDomain } from '../abilities/domain/interact-with-the-domain'; import { RoleProps } from '../../domain/contexts/community/role'; -export const RoleForCommunityInDb = async (communityName: string, roleName:string) => Question.about(`read ${roleName} role in ${communityName} community`, async (actor) => { +export const RoleForCommunityInDb = (communityName: string, roleName:string) => Question.about(`read ${roleName} role in ${communityName} community`, (actor) => { let role: RoleProps; - await InteractWithTheDomain.asReadOnly().readRoleDb(async (db) => { - role = (await db.getAll()).find((r) => r.community.name === communityName && r.roleName === roleName); + InteractWithTheDomain.asReadOnly().readRoleDb(async (db) => { + role = db?.getAll()?.find((r) => r.community.name === communityName && r.roleName === roleName); }); return role; }); diff --git a/screenplay/tasks/create-community.ts b/screenplay/tasks/create-community.ts index 963cc65d..1fb65fd5 100644 --- a/screenplay/tasks/create-community.ts +++ b/screenplay/tasks/create-community.ts @@ -1,15 +1,21 @@ -import { Actor, Interaction, Task } from '@serenity-js/core/lib/screenplay'; +import { Actor, Duration, Interaction, Task, Wait } from '@serenity-js/core/lib/screenplay'; import { InteractWithTheDomain } from '../abilities/domain/interact-with-the-domain'; import { Ensure, isPresent } from '@serenity-js/assertions'; import { CommunityInDb } from '../questions/community-in-db'; +import { RoleForCommunityInDb } from '../questions/role-for-community-in-db'; +import { actorInTheSpotlight } from '@serenity-js/core'; export const CreateCommunity = ({ - named: (communityName: string) => Task.where(`#actor creates ${communityName} community`, - Interaction.where(`#actor creates ${communityName} community`, async (actor:Actor) => { - (await InteractWithTheDomain.asUser(actor)).createCommunity(communityName); + named: async (communityName: string) => Task.where(`#actor creates ${communityName} community`, + await Interaction.where(`#actor creates ${communityName} community`, async (actor:Actor) => { + await (await InteractWithTheDomain.asUser(actor)).createCommunity(communityName); + (await InteractWithTheDomain.asReadOnly()).logDatabase('Task::CreateCommunity'); }), - Ensure.eventually(CommunityInDb(communityName), isPresent()) - ) + // Wait.for(Duration.ofMilliseconds(1_500)), + // wait for community to be saved in database + // Wait.until((await CommunityInDb(communityName)).answeredBy(actorInTheSpotlight()), isPresent()), + // Ensure.eventually((await CommunityInDb(communityName)).answeredBy(actorInTheSpotlight()), isPresent()), + ) }); diff --git a/screenplay/tasks/log-data-sources.ts b/screenplay/tasks/log-data-sources.ts index 5bfd44a8..6776bbd7 100644 --- a/screenplay/tasks/log-data-sources.ts +++ b/screenplay/tasks/log-data-sources.ts @@ -1,10 +1,10 @@ import { Actor, Interaction, Task } from '@serenity-js/core/lib/screenplay'; import { InteractWithTheDomain } from '../abilities/domain/interact-with-the-domain'; -export const LogDataSources = () => Task.where(`#actor logs all data sources`, +export const LogDataSources = (description: string) => Task.where(`#actor logs all data sources`, Interaction.where(`#actor logs all data sources`, async (actor:Actor) => { - (await InteractWithTheDomain.asReadOnly()).logDatabase(); - (await InteractWithTheDomain.asReadOnly()).logSearchDatabase(); + (await InteractWithTheDomain.asReadOnly()).logDatabase(description); + (await InteractWithTheDomain.asReadOnly()).logSearchDatabase(description); }) ) diff --git a/services-seedwork-datastore-memorydb/infrastructure/memory-repository.ts b/services-seedwork-datastore-memorydb/infrastructure/memory-repository.ts index e943436c..9ae0d301 100644 --- a/services-seedwork-datastore-memorydb/infrastructure/memory-repository.ts +++ b/services-seedwork-datastore-memorydb/infrastructure/memory-repository.ts @@ -39,6 +39,7 @@ export class MemoryRepositoryBase< this.dispatchDomainEvents(item); this.itemsInTransaction.push(item); const existingItem = this.memoryStore.get(item.id); + console.log(`MemoryRepositoryBase.save: existingItem: ${JSON.stringify(existingItem)}`); if (existingItem) { if(item.isDeleted){ this.memoryStore.delete(item.id); @@ -47,6 +48,7 @@ export class MemoryRepositoryBase< } } else { this.memoryStore.save(item.props); + console.log(`mem-repo::saved new item`) } return Promise.resolve(item); } diff --git a/services-seedwork-datastore-memorydb/infrastructure/memory-store.ts b/services-seedwork-datastore-memorydb/infrastructure/memory-store.ts index 800f7f1c..f7c5796a 100644 --- a/services-seedwork-datastore-memorydb/infrastructure/memory-store.ts +++ b/services-seedwork-datastore-memorydb/infrastructure/memory-store.ts @@ -19,6 +19,7 @@ export class MemoryStore implements ReadOnlyMemor this.memoryStore[index] = item; } else { this.memoryStore.push(item); + console.log(`new item added to memory store -> updated : ${JSON.stringify(this.memoryStore)}`) } return item; } diff --git a/services-seedwork-datastore-memorydb/infrastructure/memory-unit-of-work.ts b/services-seedwork-datastore-memorydb/infrastructure/memory-unit-of-work.ts index 547be7de..5df79260 100644 --- a/services-seedwork-datastore-memorydb/infrastructure/memory-unit-of-work.ts +++ b/services-seedwork-datastore-memorydb/infrastructure/memory-unit-of-work.ts @@ -21,11 +21,13 @@ export class MemoryUnitOfWork< await func(repo); // console.log('func done'); }catch(e){ - console.log('func failed'); + console.log('func failed: ', e); throw e; } repoEvents = await repo.getIntegrationEvents(); for await(let event of repoEvents){ + // wait for 2 secs + await new Promise((resolve) => setTimeout(resolve, 2000)); await this.integrationEventBus.dispatch(event as any,event['payload']) } }