Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test: Setup E2E tests for user roles #2220

Merged
merged 7 commits into from
Sep 27, 2023
Merged

Conversation

DafyddLlyr
Copy link
Contributor

@DafyddLlyr DafyddLlyr commented Sep 18, 2023

What does this PR do?

  • Setup test harness for user permissions, with one example test in each category
  • More details in README!

@github-actions
Copy link

github-actions bot commented Sep 18, 2023

Removed vultr server and associated DNS entries

DafyddLlyr added a commit to theopensystemslab/planx-core that referenced this pull request Sep 19, 2023
To be implemented in
theopensystemslab/planx-new#2220 to help tear
down permission-based tests.
@DafyddLlyr DafyddLlyr force-pushed the dp/cucumber-permissions-test branch 2 times, most recently from 1152ca7 to 3c6e8db Compare September 19, 2023 16:05
@DafyddLlyr DafyddLlyr changed the title test(wip): Setup E2E tests for user roles test: Setup E2E tests for user roles Sep 19, 2023
/**
* Error handling boilerplate for client functions
*/
export function safely<T extends () => ReturnType<T>>(callback: T) {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One thing this highlighted was that the planx-core client doesn't always return consistent values for success/failure. Sometimes it's a null, or false, or an error is thrown.

Taking a bit of inspiration from useSWR it would be super nice if it just always returned a consistent result object of some sort which we could check for errors.

import { User, Role } from "@opensystemslab/planx-core/types";
import { $admin } from "./client";

// This code is copied from api.planx.uk/modules/auth/service.ts
Copy link
Contributor Author

@DafyddLlyr DafyddLlyr Sep 19, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not an ideal solution - another candidate for functionality that could move to planx-core possibly?

@@ -0,0 +1,7 @@
import { INSERT_FLOW_QUERY } from "./flows";

export const queries = {
Copy link
Contributor Author

@DafyddLlyr DafyddLlyr Sep 19, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This PR is just setup. I envision the next PR will be just be adding a bunch of queries here (and maybe a few additional setup/cleanup steps)

Then they have access

Examples:
| TABLE | ACTION |
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I did consider adding a DATA and COLUMNS column here and templating out standard CRUD GraphQL queries.

At least initially hardcoding queries is simpler (if slightly more tedious).

@DafyddLlyr DafyddLlyr requested a review from a team September 19, 2023 18:05
@DafyddLlyr DafyddLlyr marked this pull request as ready for review September 19, 2023 18:05
Copy link
Member

@jessicamcinchak jessicamcinchak left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good & seems like a very solid start - thanks for these initial tooling decisions, setup, and documentation !

I'm sure I'll have more thoughts once I start writing tests myself, but don't see any blockers to this going in now 👍

- `setup()`: This function sets up the necessary environment or configurations required for the test scenario.
- `cleanup()`: This function performs cleanup tasks after the test scenario is executed, such as resetting the environment to its initial state.

- `steps.ts` file: This file contains the step definitions for your Gherkin scenarios. Each step definition maps a step in the `.feature` file to a function that performs the corresponding action and assertion in your test. We aim to keep these steps as readable as possible, with the majority of the logic being contained within `helpers.ts`.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💯

@DafyddLlyr DafyddLlyr force-pushed the dp/cucumber-permissions-test branch from f456bcb to 794d305 Compare September 27, 2023 10:43
@DafyddLlyr DafyddLlyr merged commit 28b2ce7 into main Sep 27, 2023
12 checks passed
@DafyddLlyr DafyddLlyr deleted the dp/cucumber-permissions-test branch September 27, 2023 11:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants