From e57e35f6d496d1482235a2868526eeb0401c1bd2 Mon Sep 17 00:00:00 2001 From: fosterfarrell9 <28628554+fosterfarrell9@users.noreply.github.com> Date: Sat, 24 Aug 2024 18:34:54 +0200 Subject: [PATCH] Add tests for tutor voucher redemption in the case that all tutorials are already taken --- .../cypress/e2e/voucher_redemption_spec.cy.js | 20 ++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/spec/cypress/e2e/voucher_redemption_spec.cy.js b/spec/cypress/e2e/voucher_redemption_spec.cy.js index 346933198..7d91b2350 100644 --- a/spec/cypress/e2e/voucher_redemption_spec.cy.js +++ b/spec/cypress/e2e/voucher_redemption_spec.cy.js @@ -51,21 +51,25 @@ function createTutorials(context) { FactoryBot.create("tutorial", { lecture_id: context.lecture.id }).as("tutorial3"); } +function createTutorialsWithTutor(context, tutor) { + console.log(tutor.id); + FactoryBot.create("tutorial", { lecture_id: context.lecture.id, tutor_ids: [tutor.id] }).as("tutorial1"); + FactoryBot.create("tutorial", { lecture_id: context.lecture.id, tutor_ids: [tutor.id] }).as("tutorial2"); + FactoryBot.create("tutorial", { lecture_id: context.lecture.id, tutor_ids: [tutor.id] }).as("tutorial3"); +} + function selectTutorialsAndSubmit(tutorialIds) { const tutorialIdsAsStrings = tutorialIds.map(id => id.toString()); cy.getBySelector("claim-select").should("be.visible"); cy.getBySelector("claim-select").select(tutorialIdsAsStrings, { force: true }); cy.getBySelector("claim-submit").click(); - console.log(tutorialIds); cy.getBySelector("flash-notice").should("be.visible"); } function verifyTutorialRowsContainTutorName(context, tutorialIds) { cy.getBySelector("tutorial-row").should("have.length", 3).each(($el) => { const dataId = parseInt($el.attr("data-id"), 10); - console.log(tutorialIds); - console.log(dataId); if (tutorialIds.includes(dataId)) { cy.wrap($el).should("contain", context.user.name_in_tutorials); } @@ -162,5 +166,15 @@ describe("Profile page", () => { runTutorialTest(2); runTutorialTest(3); }); + + describe("if the lecture has tutorials and the user is already a tutor for all of them", () => { + it("displays a message that the user is already a tutor for all tutorials", function () { + createTutorialsWithTutor(this, this.user); + + cy.then(() => { + submitVoucher(this.voucher); + }); + }); + }); }); });