From 91713d5917a783e87678e136202c9b0ecba448ac Mon Sep 17 00:00:00 2001 From: Lukasdotcom Date: Thu, 18 Aug 2022 16:49:44 -0400 Subject: [PATCH] Fixes bug that allows player to be moved to the bench during purchase --- cypress/e2e/invite.cy.js | 19 +++++++++++++------ pages/api/squad/[league].js | 3 +-- 2 files changed, 14 insertions(+), 8 deletions(-) diff --git a/cypress/e2e/invite.cy.js b/cypress/e2e/invite.cy.js index c8fca034..6acec403 100644 --- a/cypress/e2e/invite.cy.js +++ b/cypress/e2e/invite.cy.js @@ -84,6 +84,9 @@ describe("Invite User into league and change some league Settings and run throug cy.contains("Move to Field").click(); cy.contains("Star").click(); cy.contains("Move to Bench").click(); + // Makes sure the player can be moved back to the bench + cy.contains("Move to Field").click(); + cy.contains("Star").click(); cy.contains("Buying"); // Switches to user 2 cy.contains("Standings") @@ -110,13 +113,17 @@ describe("Invite User into league and change some league Settings and run throug cy.contains("You need 19.3 M"); cy.contains("Money left: 13.4M"); // Moves the squad slightly + cy.intercept("/api/player/87963521baf120631131").as("loadNkunku"); cy.contains("Squad").click(); - cy.contains("Christopher Nkunku") - .parent() - .parent() - .children(".playerButton") - .children("button") - .click(); + cy.wait("@loadNkunku").then(() => + cy + .contains("Christopher Nkunku") + .parent() + .parent() + .children(".playerButton") + .children("button") + .click() + ); cy.contains("Buying"); // Starts the matchday cy.exec("export NODE_ENV=test; node cypress/e2e/invite2.mjs").then(() => { diff --git a/pages/api/squad/[league].js b/pages/api/squad/[league].js index 40cafb3d..b196bbb9 100644 --- a/pages/api/squad/[league].js +++ b/pages/api/squad/[league].js @@ -211,7 +211,6 @@ export default async function handler(req, res) { [league, user, e] ) ); - console.log(e); // Checks if the player is owned by the user if (position.length > 0) { // Checks what position the player is @@ -289,7 +288,7 @@ export default async function handler(req, res) { [league, user, e] ); connection.query( - "UPDATE transfers SET position='bench', starred=0 WHERE leagueID=? and user=? and playeruid=?", + "UPDATE transfers SET position='bench', starred=0 WHERE leagueID=? and buyer=? and playeruid=?", [league, user, e] ); console.log(`User ${user} moved player ${e} to bench`);