From b5904bb8e7c2bbc1c9d1e7435185ab6074c776e8 Mon Sep 17 00:00:00 2001 From: Reece Dunham Date: Wed, 24 Jul 2024 20:53:14 -0400 Subject: [PATCH 1/2] fix: type issue --- tests/math-actions.spec.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/math-actions.spec.ts b/tests/math-actions.spec.ts index 4ba11c5..da7f013 100644 --- a/tests/math-actions.spec.ts +++ b/tests/math-actions.spec.ts @@ -78,6 +78,7 @@ const data = { { Context: { Object: 18, + Output: 0, }, }, ], From bb2c2ac733fc77b792300d469373f8a28d5bbb8c Mon Sep 17 00:00:00 2001 From: Reece Dunham Date: Wed, 24 Jul 2024 21:26:25 -0400 Subject: [PATCH 2/2] chore: Add test for contract id in handleEvent --- tests/handleEvent.data.json | 62 ++++++++++++++++++++++++++++++++----- tests/handleEvent.spec.ts | 13 ++++++++ 2 files changed, 67 insertions(+), 8 deletions(-) diff --git a/tests/handleEvent.data.json b/tests/handleEvent.data.json index 9f283de..8f1b349 100644 --- a/tests/handleEvent.data.json +++ b/tests/handleEvent.data.json @@ -8,7 +8,10 @@ "Start": { "Pacify": { "Condition": { - "$eq": ["$Value.RepositoryId", "$Target"] + "$eq": [ + "$Value.RepositoryId", + "$Target" + ] }, "Transition": "Success" } @@ -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" } @@ -103,7 +115,10 @@ "Start": { "Event": { "Condition": { - "$eq": ["$Value.RepositoryId", "$.SomeRepoId"] + "$eq": [ + "$Value.RepositoryId", + "$.SomeRepoId" + ] }, "Transition": "Success" } @@ -129,7 +144,10 @@ "Start": { "Event": { "Actions": { - "$inc": ["Variable", "$.ValueToAdd"] + "$inc": [ + "Variable", + "$.ValueToAdd" + ] } } } @@ -151,7 +169,10 @@ "Start": { "Pacify": { "Condition": { - "$pushunique": ["Pacified", "$Value.RepositoryId"] + "$pushunique": [ + "Pacified", + "$Value.RepositoryId" + ] }, "Transition": "OnePacified" } @@ -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 + } } } diff --git a/tests/handleEvent.spec.ts b/tests/handleEvent.spec.ts index d9aa689..a77fee8 100644 --- a/tests/handleEvent.spec.ts +++ b/tests/handleEvent.spec.ts @@ -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") + }) })