Skip to content

Commit

Permalink
feat: Setup flow.setStatus() function (#388)
Browse files Browse the repository at this point in the history
Please see theopensystemslab/planx-new#3170 for
context.

This PR adds a helper method to toggle the status of the flow. This is
used in E2E tests, and will be called by Editors in the frontend.
  • Loading branch information
DafyddLlyr authored May 21, 2024
1 parent 1b95557 commit 7e26245
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 1 deletion.
47 changes: 46 additions & 1 deletion src/requests/flow.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import type { GraphQLClient } from "graphql-request";
import { gql } from "graphql-request";
import { capitalize } from "lodash";

import type { FlowGraph } from "../types";
import type { FlowGraph, FlowStatus } from "../types";

export class FlowClient {
protected client: GraphQLClient;
Expand All @@ -26,6 +26,10 @@ export class FlowClient {
return publishFlow(this.client, args);
}

async setStatus(args: { flow: { id: string }; status: FlowStatus }) {
return setStatus(this.client, args);
}

/**
* Only used in test environments
*/
Expand Down Expand Up @@ -264,3 +268,44 @@ export async function _destroyPublishedFlow(
);
return Boolean(response.delete_published_flows_by_pk?.id);
}

interface SetFlowStatus {
flow: {
id: string;
status: FlowStatus;
};
}

async function setStatus(
client: GraphQLClient,
args: { flow: { id: string }; status: FlowStatus },
) {
try {
const { flow } = await client.request<SetFlowStatus>(
gql`
mutation SetFlowStatus(
$flowId: uuid!
$status: flow_status_enum_enum!
) {
flow: update_flows_by_pk(
pk_columns: { id: $flowId }
_set: { status: $status }
) {
id
status
}
}
`,
{
flowId: args.flow.id,
status: args.status,
},
);

return flow;
} catch (error) {
new Error(
`Failed to update flow status to "${args.status}". Error: ${error}`,
);
}
}
2 changes: 2 additions & 0 deletions src/types/flow.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,3 +36,5 @@ export interface NormalizedNode extends IndexedNode {
}

export type NormalizedFlow = Array<NormalizedNode>;

export type FlowStatus = "online" | "offline";

0 comments on commit 7e26245

Please sign in to comment.