Skip to content

Commit

Permalink
fix(Cypress): update feature tests for new flow
Browse files Browse the repository at this point in the history
  • Loading branch information
afeld committed Feb 14, 2023
1 parent b784cd8 commit 96b16da
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 35 deletions.
2 changes: 2 additions & 0 deletions docs/tests/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@ CYPRESS_baseUrl=http://localhost:8000 npm run cypress:open

See `tests/cypress/package.json` for more cypress scripts.

As of Cypress 12.5.1 with Firefox 109, there is a CSRF issue that prevents the tests from passing; unclear if this is a bug in Cypress or what. Use one of the other browser options.

## Pytest

The tests done at a request/unit level are run via [pytest-django](https://pytest-django.readthedocs.io/en/latest/index.html).
Expand Down
10 changes: 3 additions & 7 deletions tests/cypress/fixtures/users.json
Original file line number Diff line number Diff line change
@@ -1,14 +1,10 @@
{
"eligible": {
"name": "Garcia",
"sub": "A1234567"
"name": "Gonzales",
"sub": "32587"
},
"ineligible": {
"name": "Bob",
"sub": "A1234567"
},
"invalidSub": {
"name": "Garcia",
"sub": "A12347"
"sub": "12345"
}
}
39 changes: 15 additions & 24 deletions tests/cypress/specs/feature/eligibility.cy.js
Original file line number Diff line number Diff line change
@@ -1,49 +1,40 @@
const agencies = require("../../fixtures/transit-agencies");
const users = require("../../fixtures/users.json");

const eligibility_url = "/eligibility/confirm";

describe("Eligibility confirmation flow", () => {
beforeEach(() => {
cy.visit("/");
cy.contains(agencies[0].fields.short_name).click();
cy.contains("Get started").click();

// agency selection
cy.contains("Choose Your Provider").click();
cy.contains(agencies[0].fields.long_name).click();

// select Courtesy Card
// TODO find a more robust way to do this
cy.get('#form-verifier-selection [type="radio"]').check("2");
cy.get("#form-verifier-selection button[type='submit']").click();
cy.contains("Continue").click();
});

it("Confirms an eligible user", () => {
cy.get("#sub").type(users.eligible.sub);
cy.get("#name").type(users.eligible.name);
cy.get("input[type='submit']").click();
cy.get("#form-eligibility-verification button[type='submit']").click();

cy.contains("Great! You’re eligible for a discount!");
cy.contains("Your eligibility is confirmed!");
});

it("Rejects an ineligible user", () => {
cy.get("#sub").type(users.ineligible.sub);
cy.get("#name").type(users.ineligible.name);
cy.get("input[type='submit']").click();
cy.get("#form-eligibility-verification button[type='submit']").click();

cy.contains("We can’t confirm your age");
cy.contains(
"You may still be eligible for a discount, but we can’t verify your age",
);
});

it("Validates an invalid number/id field", () => {
cy.get("#sub").type(users.invalidSub.sub);
cy.get("#name").type(users.invalidSub.name);
cy.get("input[type='submit']").click();

cy.contains("Check your input. The format looks wrong.");
cy.get("#id_sub").then(($e) => {
expect($e).to.have.css("border-color", "rgb(222, 12, 12)");
});
cy.contains("could not be verified");
});

it("Validates an empty name field", () => {
cy.get("#sub").type(users.invalidSub.sub);
cy.get("input[type='submit']").click();
cy.get("#sub").type(users.eligible.sub);
cy.get("#form-eligibility-verification button[type='submit']").click();

cy.get("input:invalid").should("have.length", 1);
});
Expand Down
17 changes: 13 additions & 4 deletions tests/cypress/specs/feature/rate-limit.cy.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,22 @@ const { eligibility_url, post_confirm } = require("../../plugins/eligibility");

describe("Rate limiting feature spec", () => {
beforeEach(() => {
cy.visit("/" + agencies[0].fields.slug);
cy.visit(eligibility_url);
cy.visit("/");

// agency selection
cy.contains("Choose Your Provider").click();
cy.contains(agencies[0].fields.long_name).click();

// select Courtesy Card
// TODO find a more robust way to do this
cy.get('#form-verifier-selection [type="radio"]').check("2");
cy.get("#form-verifier-selection button[type='submit']").click();
cy.contains("Continue").click();
});

it("Limits excess requests", () => {
const sub = users.invalidSub.sub;
const name = users.invalidSub.name;
const sub = users.ineligible.sub;
const name = users.ineligible.name;

// start by making 5 times as many requests as allowed
const RATE_LIMIT = Cypress.env("DJANGO_RATE_LIMIT");
Expand Down

0 comments on commit 96b16da

Please sign in to comment.