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

Fix flaky voucher redemption Cypress test #726

Merged
merged 2 commits into from
Dec 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 35 additions & 14 deletions spec/cypress/e2e/vouchers_redemptions_spec.cy.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,13 @@ function testVoucherRedemptionWithNothingToClaim(context, role, itemType) {
helpers.redeemVoucherToBecomeRole(context, role);
helpers.verifyLectureIsSubscribed(context);
helpers.logoutAndLoginAsTeacher(context);
helpers.visitEditPage(context, itemType);
helpers.verifyNoClaimsYetButUserEligibleForRole(context, role);
helpers.verifyRoleNotification(context, role);
helpers.verifyNothingClaimedInNotification(context, itemType);

cy.then(() => {
helpers.visitEditPage(context, itemType);
helpers.verifyNoClaimsYetButUserEligibleForRole(context, role);
helpers.verifyRoleNotification(context, role);
helpers.verifyNothingClaimedInNotification(context, itemType);
});
}

function testVoucherRedemptionWithSomethingClaimed(context, itemType, role) {
Expand All @@ -31,9 +34,9 @@ function testVoucherRedemptionWithSomethingClaimed(context, itemType, role) {

helpers.verifyLectureIsSubscribed(context);
helpers.logoutAndLoginAsTeacher(context);
helpers.visitEditPage(context, itemType);

cy.then(() => {
helpers.visitEditPage(context, itemType);
helpers.verifyClaimsContainUserName(context, itemType, itemIds);
});

Expand All @@ -51,7 +54,9 @@ function testAlreadyRedeemedVoucher(context, role) {
helpers.verifyAlreadyRedeemedVoucherMessage(context, role);
helpers.verifyCancelVoucherButton();
helpers.logoutAndLoginAsTeacher(context);
helpers.verifyNoNewNotification();
cy.then(() => {
helpers.verifyNoNewNotification();
});
}

function testAlreadyRoleForAllItems(context, itemType) {
Expand All @@ -60,7 +65,9 @@ function testAlreadyRoleForAllItems(context, itemType) {
helpers.verifyAllItemsTakenMessage(context, itemType);
helpers.verifyCancelVoucherButton();
helpers.logoutAndLoginAsTeacher(context);
helpers.verifyNoNotification();
cy.then(() => {
helpers.verifyNoNotification();
});
}

describe("Verify Voucher Form", () => {
Expand Down Expand Up @@ -137,16 +144,21 @@ describe("Editor voucher redemption", () => {
helpers.verifyAlreadyRedeemedVoucherMessage(this, "editor");
helpers.verifyCancelVoucherButton();
helpers.logoutAndLoginAsTeacher(this);
helpers.verifyNoNewNotification();
cy.then(() => {
helpers.verifyNoNewNotification();
});
});
});

context("when the user is the teacher of the lecture", () => {
it("displays the message that a teacher cannot become an editor", function () {
helpers.logoutAndLoginAsTeacher(this);
helpers.submitVoucher(this.voucher);
helpers.verifyTeachersCantBecomeEditorsMessage(this);
helpers.verifyCancelVoucherButton();

cy.then(() => {
helpers.submitVoucher(this.voucher);
helpers.verifyTeachersCantBecomeEditorsMessage(this);
helpers.verifyCancelVoucherButton();
});
});
});
});
Expand All @@ -172,9 +184,12 @@ describe("Teacher voucher redemption", () => {
context("when the user is already the teacher", () => {
it("displays a message that the user is already the teacher", function () {
helpers.logoutAndLoginAsTeacher(this);
helpers.submitVoucher(this.voucher);
helpers.verifyAlreadyTeacherMessage(this);
helpers.verifyCancelVoucherButton();

cy.then(() => {
helpers.submitVoucher(this.voucher);
helpers.verifyAlreadyTeacherMessage(this);
helpers.verifyCancelVoucherButton();
});
});
});
});
Expand Down Expand Up @@ -221,10 +236,16 @@ describe("User & Redemption deletion", () => {
cy.visit("/profile/edit");
cy.getBySelector("delete-account-btn").click();
cy.getBySelector("delete-account-pwd-field").type(this.user.password);

cy.intercept("POST", "/users*").as("deleteUserRequest");
cy.getBySelector("delete-account-confirm-btn").click();
cy.wait("@deleteUserRequest");

cy.then(() => {
helpers.logoutAndLoginAsTeacher(this);
});

cy.then(() => {
helpers.visitEditPage(this, "tutorial");
helpers.verifyNoTutorialsButUserEligibleAsTutor(this, false);
});
Expand Down
4 changes: 3 additions & 1 deletion spec/cypress/e2e/vouchers_redemptions_spec_helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,9 @@ export function verifyClaimsContainUserName(context, claimType, claimIds, totalC

export function logoutAndLoginAsTeacher(context) {
cy.logout();
cy.login(context.teacher);
cy.then(() => {
cy.login(context.teacher);
});
}

export function verifyNoTutorialsButUserEligibleAsTutor(context, shouldBeEligible = true) {
Expand Down
Loading