Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
describe('when getting workflow data for an undefined message property', () => {
let comand: TestCommand
const messageOptions = new MessageAttributes()
beforeEach(() => {
comand = new TestCommand(undefined)
})
it('should return an empty set of workflow data', async () => {
const result = await sut.getWorkflowData(comand, messageOptions)
expect(result).toHaveLength(0)
})
})
})
private async publishMessage (
message: Message,
messageOptions: MessageAttributes = new MessageAttributes()
): Promise {
await this.assertExchange(message.$name)
const payload = JSON.stringify(message)
this.channel.publish(message.$name, '', Buffer.from(payload), {
correlationId: messageOptions.correlationId,
headers: {
attributes: messageOptions.attributes ? JSON.stringify(messageOptions.attributes) : undefined,
stickyAttributes: messageOptions.stickyAttributes ? JSON.stringify(messageOptions.stickyAttributes) : undefined
}
})
}
}
beforeAll(async () => {
await bus.publish(
finalTask,
new MessageAttributes({ correlationId: nextWorkflowData[0].$workflowId })
)
await sleep(CONSUME_TIMEOUT)
finalWorkflowData = await persistence.getWorkflowData(
AssignmentWorkflowData,
propertyMapping,
finalTask,
messageOptions,
true
)
})
describe('MemoryQueue', () => {
let sut: MemoryQueue
const handledMessageNames = [TestCommand.NAME, TestEvent.NAME]
const messageOptions = new MessageAttributes({
correlationId: faker.random.uuid()
})
beforeEach(async () => {
sut = new MemoryQueue(
Mock.ofType().object
)
const handlerRegistry = Mock.ofType()
handlerRegistry
.setup(h => h.getMessageNames())
.returns(() => handledMessageNames)
await sut.initialize(handlerRegistry.object)
})
describe('from a queue with messages', () => {
const command = new TestCommand()
let message: TransportMessage | undefined
const messageOptions = new MessageAttributes({
correlationId: faker.random.uuid(),
attributes: {
attribute1: 'a',
attribute2: 1
},
stickyAttributes: {
attribute1: 'b',
attribute2: 2
}
})
beforeEach(async () => {
await bus.send(command, messageOptions)
message = await sut.readNextMessage()
})
describe('when getting workflow data', () => {
const messageOptions = new MessageAttributes()
beforeEach(async () => {
const mapping = new MessageWorkflowMapping(
command => command.property1,
'property1'
)
await sut.initializeWorkflow(
TestWorkflowData,
[mapping]
)
})
describe('when the mapper doesn\'t resolve', () => {
let result: TestWorkflowData[]
beforeEach(async () => {
beforeAll(async () => {
await bus.publish(
finalTask,
new MessageAttributes({ correlationId: nextWorkflowData[0].$workflowId })
)
await sleep(CONSUME_TIMEOUT)
finalWorkflowData = await persistence.getWorkflowData(
TestWorkflowData,
propertyMapping,
command,
messageOptions,
true
)
})
async publish (
event: TEvent,
messageOptions: MessageAttributes = new MessageAttributes()
): Promise {
this.logger.debug('publish', { event })
const transportOptions = this.prepareTransportOptions(messageOptions)
return this.transport.publish(event, transportOptions)
}
export function fromMessageAttributeMap (sqsAttributes: SqsMessageAttributes | undefined): MessageAttributes {
const messageOptions = new MessageAttributes()
if (sqsAttributes) {
messageOptions.correlationId = sqsAttributes.correlationId
? sqsAttributes.correlationId.Value
: undefined
const attributes: MessageAttributeMap = {}
const stickyAttributes: MessageAttributeMap = {}
Object.keys(sqsAttributes).forEach(key => {
let cleansedKey: string | undefined
if (key.startsWith('attributes.')) {
cleansedKey = key.substr('attributes.'.length)
attributes[cleansedKey] = getAttributeValue(sqsAttributes, key)
} else if (key.startsWith('stickyAttributes.')) {
cleansedKey = key.substr('stickyAttributes.'.length)
super(bind => {
bind(BUS_INTERNAL_SYMBOLS.SessionScopeBinder).toConstantValue(defaultSessionScopeBinder)
defaultSessionScopeBinder(bind)
bindLogger(bind, ServiceBus)
bindService(bind, BUS_SYMBOLS.Transport, MemoryQueue).inSingletonScope()
bindService(bind, BUS_SYMBOLS.Serializer, JsonSerializer)
bindService(bind, BUS_SYMBOLS.ApplicationBootstrap, ApplicationBootstrap).inSingletonScope()
bindService(bind, BUS_SYMBOLS.HandlerRegistry, HandlerRegistry).inSingletonScope()
bindService(bind, BUS_SYMBOLS.JsonSerializer, JsonSerializer)
bind(BUS_SYMBOLS.MessageHandlingContext).toConstantValue(new MessageAttributes())
})
}