Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
sirenId
)
await this.bus.send(emailMaintenanceTeam)
return {}
}
@Handles(
SirenTestPassed,
event => event.sirenId,
'sirenId'
)
async handlesSirenTestPassed (_: SirenTestPassed): Promise> {
return this.complete()
}
@Handles(
MaintenanceTeamEmailed,
event => event.sirenId,
'sirenId'
)
async handlesMaintenanceTeamEmailed (_: MaintenanceTeamEmailed): Promise> {
return this.complete({
maintenanceEmailSent: true
})
}
}
@Handles(
SirenTestFailed,
event => event.sirenId,
'sirenId'
)
async handlesSirenTestFailed ({ sirenId }: SirenTestFailed): Promise> {
const emailMaintenanceTeam = new EmailMaintenanceTeam(
'A siren has failed its test and requires maintenance',
sirenId
)
await this.bus.send(emailMaintenanceTeam)
return {}
}
@Handles(
SirenTestPassed,
event => event.sirenId,
'sirenId'
)
async handlesSirenTestPassed (_: SirenTestPassed): Promise> {
return this.complete()
}
@Handles(
MaintenanceTeamEmailed,
event => event.sirenId,
'sirenId'
)
async handlesMaintenanceTeamEmailed (_: MaintenanceTeamEmailed): Promise> {
return this.complete({
maintenanceEmailSent: true
export class SirenTestWorkflow extends Workflow {
constructor (
@inject(BUS_SYMBOLS.Bus) private readonly bus: Bus
) {
super()
}
@StartedBy(SirenTestStarted)
handlesSirenTestStarted ({ sirenId }: SirenTestStarted): Partial {
return {
sirenId
}
}
@Handles(
SirenTestFailed,
event => event.sirenId,
'sirenId'
)
async handlesSirenTestFailed ({ sirenId }: SirenTestFailed): Promise> {
const emailMaintenanceTeam = new EmailMaintenanceTeam(
'A siren has failed its test and requires maintenance',
sirenId
)
await this.bus.send(emailMaintenanceTeam)
return {}
}
@Handles(
SirenTestPassed,
event => event.sirenId,
import { Workflow, StartedBy, Handles } from '@node-ts/bus-workflow'
import { SirenTestWorkflowData } from './sirent-test-workflow-data'
import { SirenTestStarted, SirenTestFailed, SirenTestPassed, EmailMaintenanceTeam, MaintenanceTeamEmailed } from '../messages'
import { inject } from 'inversify'
import { BUS_SYMBOLS, Bus } from '@node-ts/bus-core'
export class SirenTestWorkflow extends Workflow {
constructor (
@inject(BUS_SYMBOLS.Bus) private readonly bus: Bus
) {
super()
}
@StartedBy(SirenTestStarted)
handlesSirenTestStarted ({ sirenId }: SirenTestStarted): Partial {
return {
sirenId
}
}
@Handles(
SirenTestFailed,
event => event.sirenId,
'sirenId'
)
async handlesSirenTestFailed ({ sirenId }: SirenTestFailed): Promise> {
const emailMaintenanceTeam = new EmailMaintenanceTeam(
'A siren has failed its test and requires maintenance',
sirenId
)
it('should retrieve the item', async () => {
mapping = new MessageWorkflowMapping (
cmd => cmd.property1,
'property1'
)
const results = await sut.getWorkflowData(
TestWorkflowData,
mapping,
testCommand,
messageOptions
)
expect(results).toHaveLength(1)
dataV1 = results[0]
expect(dataV1).toMatchObject({ ...workflowData, $version: 1 })
})
describe('when saving new workflow data', () => {
const workflowData = new TestWorkflowData()
workflowData.$workflowId = uuid.v4()
workflowData.$status = WorkflowStatus.Running
workflowData.$version = 0
workflowData.eventValue = 'abc'
workflowData.property1 = 'something'
beforeAll(async () => {
await sut.saveWorkflowData(workflowData)
})
it('should add the row into the table', async () => {
const result = await postgres.query('select count(*) from "workflows"."testworkflowdata"')
const { count } = result.rows[0] as { count: string }
expect(count).toEqual('1')
})
describe('when getting the workflow data by property', () => {
const testCommand = new TestCommand(workflowData.property1)
async function initialize (): Promise {
const workflowRegistry = container.get(BUS_WORKFLOW_SYMBOLS.WorkflowRegistry)
workflowRegistry.register(SirenTestWorkflow, SirenTestWorkflowData)
await workflowRegistry.initializeWorkflows()
const bootstrap = container.get(BUS_SYMBOLS.ApplicationBootstrap)
bootstrap.registerHandler(StartSirenTestHandler)
bootstrap.registerHandler(EmailMaintenanceTeamHandler)
await bootstrap.initialize(container)
}
beforeAll(async () => {
container = new TestContainer()
container.bind(BUS_POSTGRES_SYMBOLS.PostgresConfiguration).toConstantValue(configuration)
bus = container.get(BUS_SYMBOLS.Bus)
sut = container.get(BUS_WORKFLOW_SYMBOLS.Persistence)
postgres = container.get(BUS_POSTGRES_INTERNAL_SYMBOLS.PostgresPool)
workflows = container.get(BUS_WORKFLOW_SYMBOLS.WorkflowRegistry)
workflows.register(TestWorkflow, TestWorkflowData)
await workflows.initializeWorkflows()
bootstrap = container.get(BUS_SYMBOLS.ApplicationBootstrap)
await bootstrap.initialize(container)
})
beforeAll(async () => {
container = new TestContainer()
container.bind(BUS_POSTGRES_SYMBOLS.PostgresConfiguration).toConstantValue(configuration)
bus = container.get(BUS_SYMBOLS.Bus)
sut = container.get(BUS_WORKFLOW_SYMBOLS.Persistence)
postgres = container.get(BUS_POSTGRES_INTERNAL_SYMBOLS.PostgresPool)
workflows = container.get(BUS_WORKFLOW_SYMBOLS.WorkflowRegistry)
workflows.register(TestWorkflow, TestWorkflowData)
await workflows.initializeWorkflows()
bootstrap = container.get(BUS_SYMBOLS.ApplicationBootstrap)
await bootstrap.initialize(container)
})
constructor () {
super()
this.load(
new LoggerModule(),
new WinstonModule(),
new BusModule(),
new BusWorkflowModule(),
new HandlersModule()
)
}
}