Skip to content

Commit

Permalink
add assert on workflow
Browse files Browse the repository at this point in the history
  • Loading branch information
j03-dev committed Jan 8, 2025
1 parent 6ccb771 commit 6d2f9ba
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 15 deletions.
14 changes: 5 additions & 9 deletions tests/runtimes/substantial/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -164,10 +164,6 @@ export function basicTestTemplate(
}
`
.withVars({ account_balance })
.expectBody((body) => {
const account = body.data?.start_compensation! as number;
assertEquals(account, account_balance);
})
.on(e);
});
},
Expand Down Expand Up @@ -315,8 +311,8 @@ export function concurrentWorkflowTestTemplate(
const localSorter = (a: any, b: any) =>
a.run_id.localeCompare(b.run_id);

const received =
body?.data?.results?.completed?.runs ?? ([] as Array<any>);
const received = body?.data?.results?.completed?.runs ??
([] as Array<any>);
const expected = [
{
result: {
Expand Down Expand Up @@ -477,8 +473,8 @@ export function retrySaveTestTemplate(
const localSorter = (a: any, b: any) =>
a.run_id.localeCompare(b.run_id);

const received =
body?.data?.results?.completed?.runs ?? ([] as Array<any>);
const received = body?.data?.results?.completed?.runs ??
([] as Array<any>);
const expected = [
{
result: {
Expand Down Expand Up @@ -672,7 +668,7 @@ export function childWorkflowTestTemplate(
})
.expectBody((body) => {
const sorted = body.data.search.sort((a: any, b: any) =>
a.value.localeCompare(b.value),
a.value.localeCompare(b.value)
);
assertEquals(sorted, [
{ status: "COMPLETED", value: '"Bump substantial v2 => v3"' },
Expand Down
15 changes: 9 additions & 6 deletions tests/runtimes/substantial/workflows/workflow.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ import {
Workflow,
} from "../imports/common_types.ts";

import { assertEquals } from "@std/assert";

export const eventsAndExceptionExample: Workflow<string> = async (
ctx: Context,
) => {
Expand Down Expand Up @@ -128,9 +130,10 @@ export async function accidentalInputMutation(ctx: Context) {
if (front.innerField == mutValue) {
// Should throw on shallow clones
throw new Error(
`actual kwargs was mutated after interrupts: copy ${JSON.stringify(
copy,
)
`actual kwargs was mutated after interrupts: copy ${
JSON.stringify(
copy,
)
}, ${mutValue}`,
);
}
Expand Down Expand Up @@ -163,11 +166,13 @@ export async function compensation(ctx: Context) {
};

await ctx.save(() => debitAccount(4), {
compensateWith: () => creditAccount(4),
compensateWith: () => [creditAccount(4), assertEquals(account, 1000)],
});

await ctx.save(() => debitAccount(10), {
compensateWith: () => creditAccount(10),
});

await ctx.save(() => {
debitAccount(2);
risky_transaction();
Expand All @@ -178,6 +183,4 @@ export async function compensation(ctx: Context) {
await ctx.save(() => debitAccount(100), {
compensateWith: () => creditAccount(100),
});

return account;
}

0 comments on commit 6d2f9ba

Please sign in to comment.