Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix #1994 #2039

Merged
merged 2 commits into from
Sep 13, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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