feat(tests): Add integration test for result error handling (#914)

* Add integration test

* Fix test

* Fix test
This commit is contained in:
InversionSpaces 2023-09-27 13:14:50 +02:00 committed by GitHub
parent ca6cae96ad
commit b2ca1d35bf
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 34 additions and 0 deletions

View File

@ -0,0 +1,17 @@
aqua HandleResultError
export handleResultError
-- t = true, f = false
func handleResultError(t: bool, f: bool) -> string:
opt: ?[]string
if t == f: -- false
opt <<- ["unreachable"]
else:
opt <<- nil
result = opt!
-- should fail
<- result[0]

View File

@ -16,6 +16,7 @@ import {
seqOnPropagateCall,
} from "../examples/onErrorPropagation.js";
import { errorClearCall } from "../examples/errorClear.js";
import { handleResultErrorCall } from "../examples/handleResultError.js";
import { funcCall } from "../examples/funcCall.js";
import { registerPrintln } from "../compiled/examples/println.js";
import { helloWorldCall } from "../examples/helloWorldCall.js";
@ -756,6 +757,17 @@ describe("Testing examples", () => {
expect(errorClearResult).toEqual(["handle", 0]);
});
it("handleResultError.aqua", async () => {
let call = handleResultErrorCall();
// js-client return string for interpretation error
// so matching with object guarantees that error was handled
expect(call).rejects.toMatchObject({
message: expect.stringContaining("0"),
error_code: expect.any(Number),
});
});
it("complex.aqua", async () => {
let complexCallResult = await complexCall(selfPeerId, relayPeerId1);
expect(complexCallResult).toEqual([

View File

@ -0,0 +1,5 @@
import { handleResultError } from "../compiled/examples/handleResultError.js";
export async function handleResultErrorCall() {
return await handleResultError(true, false);
}