feat(orchestration,workflows): pipe oncomplete and workflow preparation (#4697)

* chore: pipe onComplete and workflow preparation step

* changeset

* fix: tests

---------

Co-authored-by: Adrien de Peretti <adrien.deperetti@gmail.com>
Co-authored-by: Oli Juhl <59018053+olivermrbl@users.noreply.github.com>
This commit is contained in:
Carlos R. L. Rodrigues
2023-08-08 08:06:47 -03:00
committed by GitHub
parent d1e298f5dc
commit c0ca002901
11 changed files with 205 additions and 20 deletions

View File

@@ -1,4 +1,5 @@
import {
DistributedTransaction,
TransactionHandlerType,
TransactionOrchestrator,
TransactionPayload,
@@ -858,4 +859,32 @@ describe("Transaction Orchestrator", () => {
expect(mocks.oneCompensate).toBeCalledTimes(1)
expect(mocks.twoCompensate).toBeCalledTimes(1)
})
it("Should receive the current transaction as reference in the handler", async () => {
let transactionInHandler
async function handler(
actionId: string,
functionHandlerType: TransactionHandlerType,
payload: TransactionPayload,
transaction?: DistributedTransaction
) {
transactionInHandler = transaction
}
const strategy = new TransactionOrchestrator("transaction-name", {
next: {
action: "firstMethod",
},
})
const transaction = await strategy.beginTransaction(
"transaction_id_123",
handler
)
await strategy.resume(transaction)
expect(transaction).toBe(transactionInHandler)
})
})