-
-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #58 from castore-dev/document-new-messaging-packages
fix: Document new messaging packages
- Loading branch information
Showing
9 changed files
with
340 additions
and
57 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
87 changes: 87 additions & 0 deletions
87
packages/event-bridge-message-bus-adapter/src/eventBridge.unit.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
import { | ||
EventBridgeClient, | ||
PutEventsCommand, | ||
} from '@aws-sdk/client-eventbridge'; | ||
import { mockClient } from 'aws-sdk-client-mock'; | ||
import type { A } from 'ts-toolbelt'; | ||
|
||
import type { Message } from '@castore/core'; | ||
|
||
import { EventBridgeMessageBusAdapter } from './eventBridge'; | ||
|
||
const eventBridgeClientMock = mockClient(EventBridgeClient); | ||
|
||
describe('EventBridgeMessageBusAdapter', () => { | ||
const eventBusNameMock = 'my-event-bus'; | ||
|
||
const eventStoreIdMock = 'my-event-store'; | ||
|
||
const eventMock = { | ||
aggregateId: 'my-aggregate-id', | ||
version: 1, | ||
type: 'my-event-type', | ||
timestamp: new Date().toISOString(), | ||
}; | ||
|
||
const messageMock = { | ||
eventStoreId: eventStoreIdMock, | ||
event: eventMock, | ||
}; | ||
|
||
beforeEach(() => { | ||
eventBridgeClientMock.reset(); | ||
eventBridgeClientMock.on(PutEventsCommand).resolves({}); | ||
}); | ||
|
||
it('send a PutEventsCommand to event bridge client', async () => { | ||
const adapter = new EventBridgeMessageBusAdapter({ | ||
eventBusName: eventBusNameMock, | ||
eventBridgeClient: eventBridgeClientMock as unknown as EventBridgeClient, | ||
}); | ||
|
||
const assertMessage: A.Equals< | ||
Parameters<typeof adapter.publishMessage>, | ||
[Message] | ||
> = 1; | ||
assertMessage; | ||
|
||
await adapter.publishMessage(messageMock); | ||
|
||
// regularly check if vitest matchers are available (toHaveReceivedCommandWith) | ||
// https://github.com/m-radzikowski/aws-sdk-client-mock/issues/139 | ||
expect(eventBridgeClientMock.calls()).toHaveLength(1); | ||
expect(eventBridgeClientMock.call(0).args[0].input).toMatchObject({ | ||
Entries: [ | ||
{ | ||
EventBusName: eventBusNameMock, | ||
Source: eventStoreIdMock, | ||
DetailType: eventMock.type, | ||
Detail: JSON.stringify(messageMock), | ||
}, | ||
], | ||
}); | ||
}); | ||
|
||
it('works with event bus name getters', async () => { | ||
const adapter = new EventBridgeMessageBusAdapter({ | ||
eventBusName: () => eventBusNameMock, | ||
eventBridgeClient: eventBridgeClientMock as unknown as EventBridgeClient, | ||
}); | ||
|
||
await adapter.publishMessage(messageMock); | ||
|
||
// regularly check if vitest matchers are available (toHaveReceivedCommandWith) | ||
// https://github.com/m-radzikowski/aws-sdk-client-mock/issues/139 | ||
expect(eventBridgeClientMock.calls()).toHaveLength(1); | ||
expect(eventBridgeClientMock.call(0).args[0].input).toMatchObject({ | ||
Entries: [ | ||
{ | ||
EventBusName: eventBusNameMock, | ||
Source: eventStoreIdMock, | ||
DetailType: eventMock.type, | ||
Detail: JSON.stringify(messageMock), | ||
}, | ||
], | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.