Skip to content

Commit

Permalink
improve error catching on createFlow
Browse files Browse the repository at this point in the history
  • Loading branch information
RODO94 committed Nov 11, 2024
1 parent b81e077 commit 1b97644
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 35 deletions.
57 changes: 29 additions & 28 deletions e2e/tests/api-driven/src/demo-workspace/helper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,42 +80,43 @@ export const createFlowFromArray = async (
client,
flow: DataTableRecord,
): Promise<Flow | false> => {
const flowId = await createFlow(client, {
teamId: Number(flow.team_id),
name: flow.name,
slug: flow.slug,
});
return flowId;
try {
const flowId = await createFlow(client, {
teamId: Number(flow.team_id),
name: flow.name,
slug: flow.slug,
});
return flowId;
} catch (error: any) {

Check warning on line 90 in e2e/tests/api-driven/src/demo-workspace/helper.ts

View workflow job for this annotation

GitHub Actions / E2E tests

Unexpected any. Specify a different type
console.error(`Error adding flow ${flow.slug}`, error.message);
return false;
}
};

export const createFlow = async (
client,
args: FlowArgs,
): Promise<Flow | false> => {
try {
const { flow } = await client.request(
gql`
mutation InsertFlow($teamId: Int!, $slug: String!, $name: String!) {
flow: insert_flows_one(
object: { team_id: $teamId, slug: $slug, name: $name }
) {
id
slug
creator_id
}
const { flow } = await client.request(
gql`
mutation InsertFlow($teamId: Int!, $slug: String!, $name: String!) {
flow: insert_flows_one(
object: { team_id: $teamId, slug: $slug, name: $name }
) {
id
slug
creator_id
}
`,
{
teamId: args.teamId,
slug: args.slug,
name: args.name,
},
);
}
`,
{
teamId: args.teamId,
slug: args.slug,
name: args.name,
},
);

return flow;
} catch (error) {
return false;
}
return flow;
};

export async function createUser(args: Omit<User, "teams">): Promise<number> {
Expand Down
12 changes: 10 additions & 2 deletions e2e/tests/api-driven/src/demo-workspace/steps/background_steps.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,11 @@ Given<CustomWorld>(
if (otherTeam) this.otherTeam = otherTeam;

assert.ok(getTeamsArray, "Teams have not been added correctly");
assert.equal(
getTeamsArray.length,
teamsArray.length,
"Not all teams have been added",
);
},
);

Expand Down Expand Up @@ -114,9 +119,12 @@ Given<CustomWorld>(
assert.equal(
newFlowArray.length,
expectedFlowLength,
"Flows have not been added correctly",
"Not all the flows have been added",
);
assert.ok(
newFlowArray.every((result) => result !== false),
"Flows have not been added successfully",
);
assert.ok(newFlowArray.every((result) => result !== false));
},
);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { strict as assert } from "node:assert";
import {
createFlow,
deleteFlow,
Flow,
getFlowBySlug,
updateFlow,
updateTeamSettings,
Expand Down Expand Up @@ -45,11 +46,16 @@ Then<CustomWorld>("I should not access the Other Team", async function (this) {
});

Then<CustomWorld>("I should not succeed", async function (this) {
const hasSucceeded = await createFlow(this.demoClient, {
name: "Bad flow",
slug: "bad-flow",
teamId: this.insertFlowTeamId,
});
let hasSucceeded: Flow | false;
try {
hasSucceeded = await createFlow(this.demoClient, {
name: "Bad flow",
slug: "bad-flow",
teamId: this.insertFlowTeamId,
});
} catch (error) {
hasSucceeded = false;
}
assert.ok(!hasSucceeded, "Flow was able to be created on this team");
});

Expand Down

0 comments on commit 1b97644

Please sign in to comment.