Skip to content

Commit

Permalink
Fix #1994
Browse files Browse the repository at this point in the history
  • Loading branch information
MrCheater committed Sep 10, 2021
1 parent 8ca4e63 commit 6e3a462
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -508,7 +508,7 @@ const makeCommandExecutor = (
processedEvent.payload = event.payload
}

await (async (): Promise<void> => {
const savedEvent = await (async (): Promise<Event> => {
const subSegment = getPerformanceTracerSubsegment(
runtime.monitoring,
'saveEvent'
Expand All @@ -525,7 +525,7 @@ const makeCommandExecutor = (
})()

return aggregate.commandHttpResponseMode === CommandHttpResponseMode.event
? processedEvent
? savedEvent
: {}
} catch (error) {
executionError = error
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ const makeAggregateMeta = (params: any) => ({
params.commandHttpResponseMode || CommandHttpResponseMode.event,
})

let lastSavedEvent: any = null

const makeTestRuntime = (storedEvents: Event[] = []): AggregateRuntime => {
const generatedEvents: Event[] = []

Expand All @@ -37,8 +39,10 @@ const makeTestRuntime = (storedEvents: Event[] = []): AggregateRuntime => {
}

const eventstore: Eventstore = {
saveEvent: jest.fn(async (event) => {
saveEvent: jest.fn(async (originalEvent) => {
const event = { ...originalEvent, timestamp: Date.now() }
generatedEvents.push(event)
lastSavedEvent = event
return {
cursor: null,
event,
Expand Down Expand Up @@ -720,6 +724,31 @@ describe('Command handlers', () => {
})
).resolves.toEqual({})
})

test('should execute command and return last saved event', async () => {
const { executeCommand } = getAggregatesInteropBuilder([
makeAggregateMeta({
encryption: () => Promise.resolve({}),
name: 'empty',
commands: {
emptyCommand: () => {
return {
type: 'EmptyEvent',
payload: {},
}
},
},
}),
])(makeTestRuntime())

const event = (await executeCommand({
aggregateName: 'empty',
aggregateId: 'aggregateId',
type: 'emptyCommand',
})) as CommandResult

expect(event).toBe(lastSavedEvent)
})
})

describe('Snapshots', () => {
Expand Down

0 comments on commit 6e3a462

Please sign in to comment.