Skip to content

Commit

Permalink
chore: Add test for contract id in handleEvent
Browse files Browse the repository at this point in the history
  • Loading branch information
RDIL committed Jul 25, 2024
1 parent b5904bb commit bb2c2ac
Show file tree
Hide file tree
Showing 2 changed files with 67 additions and 8 deletions.
62 changes: 54 additions & 8 deletions tests/handleEvent.data.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,10 @@
"Start": {
"Pacify": {
"Condition": {
"$eq": ["$Value.RepositoryId", "$Target"]
"$eq": [
"$Value.RepositoryId",
"$Target"
]
},
"Transition": "Success"
}
Expand Down Expand Up @@ -39,18 +42,27 @@
"Disguised": [
{
"Condition": {
"$eq": ["$Value.RepositoryId", "$Outfit"]
"$eq": [
"$Value.RepositoryId",
"$Outfit"
]
},
"Actions": [
{
"$set": ["$Number", 5]
"$set": [
"$Number",
5
]
}
]
}
],
"AmbientChanged": {
"Condition": {
"$eq": ["$Number", 5]
"$eq": [
"$Number",
5
]
},
"Transition": "NumberIsFive"
}
Expand Down Expand Up @@ -103,7 +115,10 @@
"Start": {
"Event": {
"Condition": {
"$eq": ["$Value.RepositoryId", "$.SomeRepoId"]
"$eq": [
"$Value.RepositoryId",
"$.SomeRepoId"
]
},
"Transition": "Success"
}
Expand All @@ -129,7 +144,10 @@
"Start": {
"Event": {
"Actions": {
"$inc": ["Variable", "$.ValueToAdd"]
"$inc": [
"Variable",
"$.ValueToAdd"
]
}
}
}
Expand All @@ -151,7 +169,10 @@
"Start": {
"Pacify": {
"Condition": {
"$pushunique": ["Pacified", "$Value.RepositoryId"]
"$pushunique": [
"Pacified",
"$Value.RepositoryId"
]
},
"Transition": "OnePacified"
}
Expand Down Expand Up @@ -227,11 +248,36 @@
"Start": {
"-": {
"$inc": "Var1",
"$mul": ["Var2", "$.Var1"],
"$mul": [
"Var2",
"$.Var1"
],
"$dec": "Var1"
}
}
}
}
},
"withContractId": {
"Definition": {
"Context": {},
"States": {
"Start": {
"ContractStarted": {
"Condition": {
"$eq": [
"$.ContractId",
"abc123"
]
},
"Transition": "Success"
}
}
}
},
"Input": {
"Name": "ContractStarted",
"Value": null
}
}
}
13 changes: 13 additions & 0 deletions tests/handleEvent.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -206,4 +206,17 @@ describe("handleEvent api", () => {
assert.strictEqual(result.context.Var1, 1)
assert.strictEqual(result.context.Var2, 20)
})

it("supports $.ContractId", () => {
const { Definition, Input } = suites.withContractId
const result = handleEvent(Definition, Definition.Context, Input.Value, {
currentState: "Start",
eventName: Input.Name,
timestamp: 0,
contractId: "abc123",
})

assert.ok(!result.context["ContractId"], "ContractId should not be in the context after the event")
assert.strictEqual(result.state, "Success")
})
})

0 comments on commit bb2c2ac

Please sign in to comment.