-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test(e2e): Add test coverage for new behaviour
- Loading branch information
1 parent
10c44f8
commit 05879d3
Showing
3 changed files
with
71 additions
and
0 deletions.
There are no files selected for viewing
13 changes: 13 additions & 0 deletions
13
e2e/tests/api-driven/src/hasuraTriggers/hasuraTriggers.feature
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
}, | ||
); |