Trying to create some useful unit tests for the node qldb driver. A common use case is that you open a transaction with executeLambda(), check if your item exists, if it does not insert, exit transaction.
simple code example would look like this ;
return await client.executeLambda(async (txn) => {
const res = (
await txn.execute(
"SELECT * FROM Foo WHERE Bar = ?",
"FooBar"
)
).getResultList();
if (res.length == 0) {
const foo = { Bar = "FooBar"};
await txn.execute("INSERT INTO Foo ?", foo);
return foo;
} else {
return res[0];
}
});
Mocking executeLambda to return some resolved promise with an object is easy but, how to test that the TransactionExecutor was ran multiple times and with specific queries etc. How to mock the first execute to return an array with a item to hit the second execute ...