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 05879d3
Show file tree
Hide file tree
Showing 3 changed files with 71 additions and 0 deletions.
13 changes: 13 additions & 0 deletions e2e/tests/api-driven/src/hasuraTriggers/hasuraTriggers.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
Feature: Database triggers

@regression @add-user-trigger
Scenario: Adding a user to Planx - with Templates team
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

@regression @add-user-trigger
Scenario: Adding a user to Planx - without Templates team
When a new user is added
Then they are not granted access to the Templates team
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();
};
52 changes: 52 additions & 0 deletions e2e/tests/api-driven/src/hasuraTriggers/steps.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
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");
});

Then<CustomWorld>(
"they are not granted access to the Templates team",
async function (this) {
assert.strictEqual(this.user.teams.length, 0);
},
);

0 comments on commit 05879d3

Please sign in to comment.