Skip to content

Commit

Permalink
add Jo's reccys
Browse files Browse the repository at this point in the history
  • Loading branch information
RODO94 committed Nov 11, 2024
1 parent ed9bf95 commit beb7c41
Show file tree
Hide file tree
Showing 5 changed files with 47 additions and 42 deletions.
8 changes: 4 additions & 4 deletions e2e/tests/api-driven/src/demo-workspace/demoUser.feature
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
And I am a demoUser

@demo-user-permissions
Scenario: I can only view my own flows
Scenario Outline: I can only view my own flows
When I am in the "<TEAM>" team
Then I should only see my own flows
But I should not see flows that I have not created
Expand All @@ -39,7 +39,7 @@
Scenario Outline: I can only view specific teams
When I query the teams table
Then I can access the teams with slug: "<SLUG>"
But I should not access the Other Team
But I should not be able to access the Other Team

Examples:
| SLUG |
Expand All @@ -51,8 +51,8 @@
@demo-user-permissions
Scenario Outline: Creating a new flow
When I insert a flow into the team: "<TEAM>"
Then I should not succeed
But I should succeed in the Demo team
Then I should not be able to create a flow
But I should be able to create a flow in the Demo team

Examples:
| TEAM |
Expand Down
11 changes: 5 additions & 6 deletions e2e/tests/api-driven/src/demo-workspace/helper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,11 @@ export const cleanup = async () => {
export const checkTeamsExist = async (
teamArray: DataTableArray,
): Promise<Team[]> => {
const existenceArray = await Promise.all(
teamArray.map(async (team: DataTableRecord) => {
const teamObj = await $admin.team.getBySlug(team.slug);
return teamObj;
}),
);
const existenceArray: Team[] = [];
for (const team of teamArray) {
const teamObj = await $admin.team.getBySlug(team.slug);
existenceArray.push(teamObj);
}
return existenceArray;
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,16 @@ import { strict as assert } from "node:assert";
import { getFlowBySlug, getTeamAndFlowsBySlug, getTeams } from "../helper";
import { CustomWorld } from "./background_steps";

When<CustomWorld>("I am in the {string} team", async function (this, string) {
const team = await getTeamAndFlowsBySlug(this.demoClient, string);
When<CustomWorld>("I am in the {string} team", async function (this, teamSlug) {
const team = await getTeamAndFlowsBySlug(this.demoClient, teamSlug);
this.currentTeamId = team.id;
this.teamFlows = team.flows;
if (string !== "demo") {
if (teamSlug !== "demo") {
this.adminFlowSlug = team.flows[0].slug;
} else {
this.demoFlowSlug = team.flows[0].slug;
}
assert.equal(string, team.slug, "Error retrieving the correct team");
assert.equal(teamSlug, team.slug, "Error retrieving the correct team");
});

When<CustomWorld>("I query the teams table", async function (this) {
Expand All @@ -24,8 +24,8 @@ When<CustomWorld>("I query the teams table", async function (this) {

When<CustomWorld>(
"I insert a flow into the team: {string}",
async function (this, string) {
const team = await $admin.team.getBySlug(string);
async function (this, teamSlug) {
const team = await $admin.team.getBySlug(teamSlug);
this.insertFlowTeamId = team.id;
},
);
Expand Down
56 changes: 31 additions & 25 deletions e2e/tests/api-driven/src/demo-workspace/steps/verification_steps.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,36 +30,42 @@ Then<CustomWorld>(

Then<CustomWorld>(
"I can access the teams with slug: {string}",
async function (this, string) {
async function (this, teamSlug) {
const canAccessTeam = this.demoTeamsArray.find(
(team) => team.slug === string,
(team) => team.slug === teamSlug,
);
assert.ok(canAccessTeam, "Team is not in the array");
},
);

Then<CustomWorld>("I should not access the Other Team", async function (this) {
const cannotAccessOtherTeam = this.demoTeamsArray.find(
(team) => team.slug !== this.otherTeam?.slug,
);
assert.ok(cannotAccessOtherTeam, "Other Team is in the array");
});
Then<CustomWorld>(
"I should not be able to access the Other Team",
async function (this) {
const cannotAccessOtherTeam = this.demoTeamsArray.find(
(team) => team.slug !== this.otherTeam?.slug,
);
assert.ok(cannotAccessOtherTeam, "Other Team is in the array");
},
);

Then<CustomWorld>("I should not succeed", async function (this) {
let hasSucceeded: Flow | false;
try {
hasSucceeded = await createFlow(this.demoClient, {
name: "Bad flow",
slug: "bad-flow",
teamId: this.insertFlowTeamId,
});
} catch (error) {
hasSucceeded = false;
}
assert.ok(!hasSucceeded, "Flow was able to be created on this team");
});
Then<CustomWorld>(
"I should not be able to create a flow",
async function (this) {
let hasSucceeded: Flow | false;
try {
hasSucceeded = await createFlow(this.demoClient, {
name: "Bad flow",
slug: "bad-flow",
teamId: this.insertFlowTeamId,
});
} catch (error) {
hasSucceeded = false;
}
assert.ok(!hasSucceeded, "Flow was able to be created on this team");
},
);

Then("I should succeed in the Demo team", async function () {
Then("I should be able to create a flow in the Demo team", async function () {
const hasSucceeded = await createFlow(this.demoClient, {
name: "Good flow",
slug: "good-flow",
Expand All @@ -79,14 +85,14 @@ Then<CustomWorld>("I should be able to see a flow", async function (this) {

Then<CustomWorld>(
"I should be able to {string} the flow",
async function (this, string) {
async function (this, action) {
const demoFlow = await getFlowBySlug(this.demoClient, this.demoFlowSlug);
const hasSucceeded =
(await string) === "update"
(await action) === "update"
? updateFlow(this.demoClient, demoFlow.id)
: deleteFlow(this.demoClient, demoFlow.id);

assert.ok(hasSucceeded, `Cannot ${string} the flow `);
assert.ok(hasSucceeded, `Cannot ${action} the flow `);
},
);

Expand Down
2 changes: 1 addition & 1 deletion e2e/tests/api-driven/src/jwt.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ const getAllowedRolesForUser = (user: User): Role[] => {
const teamRoles = user.teams.map((teamRole) => teamRole.role);
const allowedRoles: Role[] = [
"public", // Allow public access
...teamRoles, // User specif ic roles
...teamRoles, // User specific roles
];
if (user.isPlatformAdmin) allowedRoles.push("platformAdmin");

Expand Down

0 comments on commit beb7c41

Please sign in to comment.