diff --git a/e2e/tests/api-driven/package.json b/e2e/tests/api-driven/package.json index 6a0cf886a7..1ca748acde 100644 --- a/e2e/tests/api-driven/package.json +++ b/e2e/tests/api-driven/package.json @@ -6,7 +6,7 @@ }, "dependencies": { "@cucumber/cucumber": "^9.3.0", - "@opensystemslab/planx-core": "git+https://github.com/theopensystemslab/planx-core#2732b6e", + "@opensystemslab/planx-core": "git+https://github.com/theopensystemslab/planx-core#58a0647", "axios": "^1.6.8", "dotenv": "^16.3.1", "dotenv-expand": "^10.0.0", diff --git a/e2e/tests/api-driven/pnpm-lock.yaml b/e2e/tests/api-driven/pnpm-lock.yaml index 3569a80e19..d3f0e6cafe 100644 --- a/e2e/tests/api-driven/pnpm-lock.yaml +++ b/e2e/tests/api-driven/pnpm-lock.yaml @@ -9,8 +9,8 @@ dependencies: specifier: ^9.3.0 version: 9.3.0 '@opensystemslab/planx-core': - specifier: git+https://github.com/theopensystemslab/planx-core#2732b6e - version: github.com/theopensystemslab/planx-core/2732b6e + specifier: git+https://github.com/theopensystemslab/planx-core#58a0647 + version: github.com/theopensystemslab/planx-core/58a0647 axios: specifier: ^1.6.8 version: 1.6.8 @@ -2933,8 +2933,8 @@ packages: resolution: {integrity: sha512-XBx9AXhXktjUqnepgTiE5flcKIYWi/rme0Eaj+5Y0lftuGBq+jyRu/md4WnuxqgP1ubdpNCsYEYPxrzVHD8d6g==} dev: false - github.com/theopensystemslab/planx-core/2732b6e: - resolution: {tarball: https://codeload.github.com/theopensystemslab/planx-core/tar.gz/2732b6e} + github.com/theopensystemslab/planx-core/58a0647: + resolution: {tarball: https://codeload.github.com/theopensystemslab/planx-core/tar.gz/58a0647} name: '@opensystemslab/planx-core' version: 1.0.0 prepare: true diff --git a/e2e/tests/api-driven/src/flowStatusHistory/flowStatusHistory.feature b/e2e/tests/api-driven/src/flowStatusHistory/flowStatusHistory.feature new file mode 100644 index 0000000000..701b0f4d3a --- /dev/null +++ b/e2e/tests/api-driven/src/flowStatusHistory/flowStatusHistory.feature @@ -0,0 +1,14 @@ +Feature: Flow status history + + @regression @flow-status-history + Scenario: Creating a flow + When a new flow is added + Then the status of the flow is online by default + And a flow_status_history record is created + + @regression @flow-status-history + Scenario: Updating a flow + When a new flow is added + And the flow status is changed to offline + Then the open flow_status_history record is updated + And a new flow_status_history record is created \ No newline at end of file diff --git a/e2e/tests/api-driven/src/flowStatusHistory/helpers.ts b/e2e/tests/api-driven/src/flowStatusHistory/helpers.ts new file mode 100644 index 0000000000..f6319f9a4b --- /dev/null +++ b/e2e/tests/api-driven/src/flowStatusHistory/helpers.ts @@ -0,0 +1,73 @@ +import { FlowStatus } from "@opensystemslab/planx-core/types"; +import { $admin } from "../client"; +import { createTeam } from "../globalHelpers"; +import gql from "graphql-tag"; + +export const setup = async () => { + const teamId = await createTeam(); + + const world = { teamId }; + + return world; +}; + +export const cleanup = async () => { + await $admin.user._destroyAll(); + await $admin.flow._destroyAll(); + await $admin.team._destroyAll(); +}; + +interface GetFlowStatus { + flows: { + status: FlowStatus + }[] +} + +export const getFlowStatus = async (flowId: string) => { + const { + flows: [{ status }], + } = await $admin.client.request(gql` + query GetFlowStatus($flowId: uuid!) { + flows(where: { id: { _eq: $flowId } }) { + status + } + }`, + { flowId } + ); + + + return status; +} + +interface GetFlowStatusHistory { + flowStatusHistory: { + id: number; + status: FlowStatus; + eventStart: string; + eventEnd: string; + }[]; +} + +export const getFlowStatusHistory = async (flowId: string) => { + const { flowStatusHistory } = + await $admin.client.request( + gql` + query GetFlowStatusHistory($flowId: uuid!) { + flowStatusHistory: flow_status_history( + where: { + flow_id: { _eq: $flowId } + } + order_by: { event_start: asc } + ) { + id + status + eventStart: event_start + eventEnd: event_end + } + } + `, + { flowId } + ); + + return flowStatusHistory; +} diff --git a/e2e/tests/api-driven/src/flowStatusHistory/steps.ts b/e2e/tests/api-driven/src/flowStatusHistory/steps.ts new file mode 100644 index 0000000000..25c18e5b6a --- /dev/null +++ b/e2e/tests/api-driven/src/flowStatusHistory/steps.ts @@ -0,0 +1,83 @@ +import { When, Then, World, After, Before } from "@cucumber/cucumber"; +import assert from "assert"; +import { cleanup, getFlowStatus, getFlowStatusHistory, setup } from "./helpers"; +import { createFlow } from "../globalHelpers"; +import { $admin } from "../client"; + +export class CustomWorld extends World { + teamId!: number; + flowId!: string; +} + +After("@flow-status-history", async function () { + await cleanup(); +}); + +Before("@flow-status-history", async function () { + const { teamId } = await setup(); + this.teamId = teamId; +}); + +When("a new flow is added", async function () { + const flowId = await createFlow({ teamId: this.teamId, slug: "test-flow" }); + + assert.ok(flowId, "flowId is not defined"); + + this.flowId = flowId; +}); + +Then("the status of the flow is online by default", async function () { + const status = await getFlowStatus(this.flowId); + + assert.equal(status, "online", `Flow status is ${status} - it should be "online"`); +}); + +Then("a flow_status_history record is created", async function () { + const flowStatusHistory = await getFlowStatusHistory(this.flowId); + + assert.notEqual(flowStatusHistory.length, 0, "No records found for flow_status_history"); + assert.equal(flowStatusHistory.length, 1, "Multiple records found for flow_status_history"); + assert.ok(flowStatusHistory[0], "flow_status_history record not created"); + assert.equal( + flowStatusHistory[0].status, + "online", + `Flow status is ${flowStatusHistory[0].status} - it should be "online"` + ); + assert.notEqual(flowStatusHistory[0].eventStart, null, "Event start should be set on INSERT"); + assert.equal(flowStatusHistory[0].eventEnd, null, "Event end should not be set on INSERT"); +}); + +When("the flow status is changed to offline", async function () { + const flow = await $admin.flow.setStatus({ flow: { id: this.flowId }, status: "offline" }); + assert.ok(flow, "Flow not defined after setStatus()"); + assert.equal(flow.status, "offline", `Flow status is ${flow.status} - it should be "offline`); +}); + +Then("the open flow_status_history record is updated", async function () { + const flowStatusHistory = await getFlowStatusHistory(this.flowId); + assert.ok( + flowStatusHistory[0].eventEnd, + "Event end should be set on update to status column" + ); +}); + +Then("a new flow_status_history record is created", async function () { + const flowStatusHistory = await getFlowStatusHistory(this.flowId); + assert.equal(flowStatusHistory.length, 2, "New record not created on UPDATE"); + assert.ok(flowStatusHistory[1], "flow_status_history record not created"); + assert.equal( + flowStatusHistory[1].status, + "online", + `Flow status is ${flowStatusHistory[1].status} - it should be "online"` + ); + assert.notEqual( + flowStatusHistory[1].eventStart, + null, + "Event start should be set on INSERT" + ); + assert.equal( + flowStatusHistory[1].eventEnd, + null, + "Event end should not be set on INSERT" + ); +});