Skip to content

Commit

Permalink
test(e2e): Add test coverage for new behaviour
Browse files Browse the repository at this point in the history
  • Loading branch information
DafyddLlyr committed Oct 9, 2023
1 parent 10c44f8 commit 276b700
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -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
6 changes: 6 additions & 0 deletions e2e/tests/api-driven/src/hasuraTriggers/helpers.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import { $admin } from "../client";

export const cleanup = async () => {
await $admin.user._destroyAll();
await $admin.team._destroyAll();
};
42 changes: 42 additions & 0 deletions e2e/tests/api-driven/src/hasuraTriggers/steps.ts
Original file line number Diff line number Diff line change
@@ -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<CustomWorld>("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<CustomWorld>("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<CustomWorld>("have the teamEditor role", async function (this) {
assert.strictEqual(this.user.teams[0].role, "teamEditor");
});

0 comments on commit 276b700

Please sign in to comment.