From 276b7000acc673c18e7df3ef74437e71b8701723 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dafydd=20Ll=C5=B7r=20Pearson?= Date: Mon, 9 Oct 2023 22:49:12 +0100 Subject: [PATCH] test(e2e): Add test coverage for new behaviour --- .../src/hasuraTriggers/hasuraTriggers.feature | 8 ++++ .../api-driven/src/hasuraTriggers/helpers.ts | 6 +++ .../api-driven/src/hasuraTriggers/steps.ts | 42 +++++++++++++++++++ 3 files changed, 56 insertions(+) create mode 100644 e2e/tests/api-driven/src/hasuraTriggers/hasuraTriggers.feature create mode 100644 e2e/tests/api-driven/src/hasuraTriggers/helpers.ts create mode 100644 e2e/tests/api-driven/src/hasuraTriggers/steps.ts diff --git a/e2e/tests/api-driven/src/hasuraTriggers/hasuraTriggers.feature b/e2e/tests/api-driven/src/hasuraTriggers/hasuraTriggers.feature new file mode 100644 index 0000000000..7a91617e41 --- /dev/null +++ b/e2e/tests/api-driven/src/hasuraTriggers/hasuraTriggers.feature @@ -0,0 +1,8 @@ +Feature: Database triggers + + @regression @add-user-trigger + Scenario: Adding a user to Planx + Given the Templates team exists + When a new user is added + Then they are granted access to the Templates team + And have the teamEditor role \ No newline at end of file diff --git a/e2e/tests/api-driven/src/hasuraTriggers/helpers.ts b/e2e/tests/api-driven/src/hasuraTriggers/helpers.ts new file mode 100644 index 0000000000..d405455a15 --- /dev/null +++ b/e2e/tests/api-driven/src/hasuraTriggers/helpers.ts @@ -0,0 +1,6 @@ +import { $admin } from "../client"; + +export const cleanup = async () => { + await $admin.user._destroyAll(); + await $admin.team._destroyAll(); +}; \ No newline at end of file diff --git a/e2e/tests/api-driven/src/hasuraTriggers/steps.ts b/e2e/tests/api-driven/src/hasuraTriggers/steps.ts new file mode 100644 index 0000000000..41413eb61a --- /dev/null +++ b/e2e/tests/api-driven/src/hasuraTriggers/steps.ts @@ -0,0 +1,42 @@ +import { After, Given, Then, When, World } from "@cucumber/cucumber"; +import { cleanup } from "./helpers"; +import { User } from "@opensystemslab/planx-core/types"; +import { $admin } from "../client"; +import assert from "assert"; +import { createTeam, createUser } from "../globalHelpers"; + +export class CustomWorld extends World { + user!: User; + templatesTeamId!: number; +} + +After("@add-user-trigger", async function () { + await cleanup(); +}); + +Given("the Templates team exists", async function (this) { + const templatesTeamId = await createTeam({ slug: "templates"}); + + assert.ok(templatesTeamId, "Templates team is not defined"); + + this.templatesTeamId = templatesTeamId; +}); + +When("a new user is added", async function (this) { + const userId = await createUser(); + const user = await $admin.user.getById(userId); + + assert.ok(user, "User is not defined"); + + this.user = user; +}); + +Then("they are granted access to the Templates team", async function (this) { + assert.strictEqual(this.user.teams.length, 1); + assert.strictEqual(this.user.teams[0].team.slug, "templates"); + assert.strictEqual(this.user.teams[0].team.id, this.templatesTeamId); +}); + +Then("have the teamEditor role", async function (this) { + assert.strictEqual(this.user.teams[0].role, "teamEditor"); +}); \ No newline at end of file