From 20f01a1fe30ad05b57ca1c55ada3bee995c2273f Mon Sep 17 00:00:00 2001 From: Alix Lourme Date: Mon, 3 May 2021 23:22:44 +0200 Subject: [PATCH] Fix #189 : Manage UberEats player update --- src/main/java/org/blondin/mpg/Main.java | 22 +- src/test/java/org/blondin/mpg/MainTest.java | 15 + ...4-Complete-BoostInjuredPlayer-Request.json | 56 ++ ....20181114-Complete-BoostInjuredPlayer.json | 666 ++++++++++++++++++ 4 files changed, 758 insertions(+), 1 deletion(-) create mode 100644 src/test/resources/__files/mpg.coach.20181114-Complete-BoostInjuredPlayer-Request.json create mode 100644 src/test/resources/__files/mpg.coach.20181114-Complete-BoostInjuredPlayer.json diff --git a/src/main/java/org/blondin/mpg/Main.java b/src/main/java/org/blondin/mpg/Main.java index 88bf9a6..1c72e13 100644 --- a/src/main/java/org/blondin/mpg/Main.java +++ b/src/main/java/org/blondin/mpg/Main.java @@ -444,8 +444,9 @@ private static CoachRequest getCoachRequest(Coach coach, List players, C List midfielders = players.stream().filter(p -> p.getPosition().equals(Position.M)).collect(Collectors.toList()); List attackers = players.stream().filter(p -> p.getPosition().equals(Position.A)).collect(Collectors.toList()); + String playerIdForBonus = midfielders.get(0).getId(); request.setBonusSelected(selectBonus(coach.getBonusSelected(), coach.getBonus(), coach.getMatchId(), coach.getNbPlayers(), - config.isUseBonus(), midfielders.get(0).getId())); + config.isUseBonus(), playerIdForBonus)); // Main lines setPlayersOnPitch(request, defenders, nbrDefenders, 1); @@ -484,9 +485,28 @@ private static CoachRequest getCoachRequest(Coach coach, List players, C } } + // If Bonus is player power up (type=4 / RedBull/ UberEats), verify that player is on pitch, override otherwise + verifyBonusPlayerOverrideOnPitch(request, playerIdForBonus); + return request; } + static void verifyBonusPlayerOverrideOnPitch(CoachRequest request, String playerIdEnfored) { + if (request.getBonusSelected() != null && request.getBonusSelected().getType() != null && request.getBonusSelected().getType() == 4) { + boolean onPitch = false; + String playerIdSelected = request.getBonusSelected().getPlayerId(); + for (int i = 1; i <= 11; i++) { + if (playerIdSelected.equals(request.getPlayersOnPitch().getPlayer(i))) { + onPitch = true; + break; + } + } + if (!onPitch) { + request.getBonusSelected().setPlayerId(playerIdEnfored); + } + } + } + static BonusSelected selectBonus(BonusSelected previousBonus, Bonus bonus, String matchId, int numberPlayers, boolean useBonus, String playerIdForRefBull) { BonusSelected bonusSelected = ObjectUtils.defaultIfNull(previousBonus, new BonusSelected()); diff --git a/src/test/java/org/blondin/mpg/MainTest.java b/src/test/java/org/blondin/mpg/MainTest.java index ecd4175..c03727d 100644 --- a/src/test/java/org/blondin/mpg/MainTest.java +++ b/src/test/java/org/blondin/mpg/MainTest.java @@ -86,6 +86,21 @@ public void testRealWithBadCredentials() throws Exception { } } + @Test + public void testBonusUberEatsUpdate() throws Exception { + prepareMainFrenchLigue1Mocks("KLGXSSUG-status-4", "20181114", "20181114", "20181114"); + Config config = spy(getConfig()); + doReturn(true).when(config).isTeampUpdate(); + doReturn(false).when(config).isUseBonus(); + stubFor(get("/league/KLGXSSUG/coach").willReturn( + aResponse().withHeader("Content-Type", "application/json").withBodyFile("mpg.coach.20181114-Complete-BoostInjuredPlayer.json"))); + stubFor(post("/league/KLGXSSUG/coach") + .withRequestBody(equalToJson(getTestFileToString("mpg.coach.20181114-Complete-BoostInjuredPlayer-Request.json"))) + .willReturn(aResponse().withHeader("Content-Type", "application/json").withBodyFile("mpg.coach.post.success.json"))); + executeMainProcess(config); + Assert.assertTrue(getLogOut(), getLogOut().contains("Updating team")); + } + @Test public void testTransactionsProposalIndexOutOfBoundsException() throws Exception { stubFor(post("/user/signIn") diff --git a/src/test/resources/__files/mpg.coach.20181114-Complete-BoostInjuredPlayer-Request.json b/src/test/resources/__files/mpg.coach.20181114-Complete-BoostInjuredPlayer-Request.json new file mode 100644 index 0000000..56adbef --- /dev/null +++ b/src/test/resources/__files/mpg.coach.20181114-Complete-BoostInjuredPlayer-Request.json @@ -0,0 +1,56 @@ +{ + "playersOnPitch": { + "1": "player_42713", + "2": "player_52782", + "3": "player_93605", + "4": "player_116406", + "5": "player_95434", + "6": "player_166989", + "7": "player_213198", + "8": "player_163562", + "9": "player_103124", + "10": "player_61278", + "11": "player_195735", + "12": "player_226944", + "13": "player_183779", + "14": "player_47654", + "15": "player_228322", + "16": "player_167443", + "17": "player_147577", + "18": "player_181439" + }, + "composition": 343, + "tacticalsubstitutes": [ + { + "subs": "player_226944", + "start": "player_116406", + "rating": 5 + }, + { + "subs": "player_47654", + "start": "player_163562", + "rating": 5 + }, + { + "subs": "player_228322", + "start": "player_213198", + "rating": 5 + }, + { + "subs": "player_167443", + "start": "player_195735", + "rating": 6 + }, + { + "subs": "player_147577", + "start": "player_61278", + "rating": 6 + } + ], + "bonusSelected": { + "type": 4, + "playerid": "player_95434" + }, + "matchId": "mpg_match_KLGXSSUG_1_11_4", + "realday": 14 +} diff --git a/src/test/resources/__files/mpg.coach.20181114-Complete-BoostInjuredPlayer.json b/src/test/resources/__files/mpg.coach.20181114-Complete-BoostInjuredPlayer.json new file mode 100644 index 0000000..fbc0334 --- /dev/null +++ b/src/test/resources/__files/mpg.coach.20181114-Complete-BoostInjuredPlayer.json @@ -0,0 +1,666 @@ +{ + "data": { + "tds": { + "update": "2018-11-09T16:29:45.643Z", + "player_465299": { + }, + "player_67272": { + "injured": 1 + }, + "player_247400": { + "injured": 1 + }, + "player_133632": { + "injured": 1 + }, + "player_174846": { + "injured": 1 + }, + "player_458250": { + }, + "player_102747": { + }, + "player_60582": { + "pending": 1 + }, + "player_15780": { + "injured": 1 + }, + "player_50326": { + }, + "player_449718": { + }, + "player_161039": { + }, + "player_44199": { + "pending": 1 + }, + "player_54413": { + "pending": 1 + }, + "player_141109": { + }, + "player_160985": { + "pending": 1 + }, + "player_197022": { + }, + "player_71797": { + "pending": 1 + }, + "player_79917": { + "injured": 1 + }, + "player_210462": { + "injured": 1 + }, + "player_174908": { + "injured": 1 + }, + "player_93127": { + }, + "player_228361": { + "injured": 1 + }, + "player_218796": { + "pending": 1 + }, + "player_154770": { + "injured": 1 + }, + "player_168539": { + "injured": 1 + }, + "player_45084": { + "pending": 1 + }, + "player_441575": { + "injured": 1 + }, + "player_183779": { + "pending": 1 + }, + "player_89068": { + "injured": 1 + }, + "player_461908": { + }, + "player_93498": { + }, + "player_37776": { + "pending": 1 + }, + "player_98746": { + "pending": 1 + }, + "player_39905": { + "injured": 1 + }, + "player_115357": { + "injured": 1 + }, + "player_104613": { + "injured": 1 + }, + "player_83279": { + "injured": 1 + }, + "player_461910": { + }, + "player_102732": { + }, + "player_199734": { + }, + "player_51525": { + "pending": 1 + }, + "player_461840": { + }, + "player_212325": { + "injured": 1 + }, + "player_209335": { + "pending": 1 + }, + "player_51394": { + "injured": 1 + }, + "player_220110": { + }, + "player_193537": { + "injured": 1 + }, + "player_448514": { + "pending": 1 + }, + "player_86158": { + "pending": 1 + }, + "player_37938": { + "injured": 1 + }, + "player_44357": { + "injured": 1 + }, + "player_226949": { + "injured": 1 + }, + "player_50996": { + "pending": 1 + }, + "player_39294": { + }, + "player_109653": { + "pending": 1 + }, + "player_225997": { + }, + "player_50442": { + "pending": 1 + }, + "player_225702": { + }, + "player_116152": { + "injured": 1 + }, + "player_451005": { + "injured": 1 + }, + "player_18574": { + "pending": 1 + }, + "player_85548": { + "pending": 1 + }, + "player_464192": { + }, + "player_242894": { + "pending": 1 + }, + "player_193409": { + "injured": 1 + }, + "player_27669": { + "pending": 1 + }, + "player_164474": { + }, + "player_80711": { + "pending": 1 + }, + "player_205880": { + }, + "player_42416": { + "suspended": 1 + }, + "player_15930": { + "suspended": 1 + }, + "player_48768": { + "suspended": 1 + }, + "player_184095": { + "injured": 1 + }, + "player_189542": { + "injured": 1 + }, + "player_37758": { + "injured": 1 + }, + "player_107641": { + "pending": 1 + }, + "player_56995": { + "pending": 1 + }, + "player_71403": { + "pending": 1 + }, + "player_161950": { + "pending": 1 + }, + "player_198065": { + "pending": 1 + }, + "player_106821": { + "suspended": 1 + }, + "player_184215": { + "injured": 1 + }, + "player_32367": { + "suspended": 1 + }, + "player_244754": { + "pending": 1 + }, + "player_232240": { + "suspended": 1 + }, + "player_92527": { + "injured": 1 + }, + "player_462116": { + "injured": 1 + }, + "player_166989": { + "suspended": 1 + }, + "player_228345": { + "injured": 1 + }, + "player_102385": { + "injured": 1 + }, + "player_226597": { + "injured": 1 + }, + "player_180124": { + "injured": 1 + }, + "player_38419": { + "injured": 1 + }, + "player_19739": { + "injured": 1 + }, + "player_166552": { + "injured": 1 + }, + "player_180562": { + "injured": 1 + }, + "player_170137": { + "injured": 1 + }, + "player_245496": { + "injured": 1 + } + }, + "teams": { + "140": { + "name": "Bordeaux", + "status": "away", + "against": "Dijon" + }, + "143": { + "name": "Lyon", + "status": "home", + "against": "Saint Etienne" + }, + "144": { + "name": "Marseille", + "status": "away", + "against": "Amiens" + }, + "146": { + "name": "Monaco", + "status": "away", + "against": "Caen" + }, + "147": { + "name": "Montpellier", + "status": "home", + "against": "Rennes" + }, + "149": { + "name": "Paris", + "status": "home", + "against": "Toulouse" + }, + "150": { + "name": "Rennes", + "status": "away", + "against": "Montpellier" + }, + "152": { + "name": "Saint Etienne", + "status": "away", + "against": "Lyon" + }, + "153": { + "name": "Strasbourg", + "status": "home", + "against": "Nîmes" + }, + "427": { + "name": "Toulouse", + "status": "away", + "against": "Paris" + }, + "428": { + "name": "Guingamp", + "status": "away", + "against": "Reims" + }, + "429": { + "name": "Lille", + "status": "away", + "against": "Nice" + }, + "430": { + "name": "Nantes", + "status": "home", + "against": "Angers" + }, + "1028": { + "name": "Caen", + "status": "home", + "against": "Monaco" + }, + "1395": { + "name": "Nice", + "status": "home", + "against": "Lille" + }, + "1423": { + "name": "Reims", + "status": "home", + "against": "Guingamp" + }, + "1430": { + "name": "Amiens", + "status": "home", + "against": "Marseille" + }, + "2128": { + "name": "Angers", + "status": "away", + "against": "Nantes" + }, + "2130": { + "name": "Dijon", + "status": "home", + "against": "Bordeaux" + }, + "2336": { + "name": "Nîmes", + "status": "away", + "against": "Strasbourg" + } + }, + "champid": 1, + "matchId": "mpg_match_KLGXSSUG_1_11_4", + "realday": 14, + "stadium": "The place to be arena", + "dateMatch": 1543002300000, + "timetogame": 780343263, + "teamHome": { + "id": "mpg_team_KLGXSSUG$$mpg_user_955966", + "name": "Axel3rd Football Club", + "abbr": "AFC", + "coach": "Alix", + "jersey": { + "id": 5, + "zones": { + "z8": "#ff2626", + "z2": "#ffffff", + "z3": "#4054CC", + "z4": "#ff2626", + "z5": "#ffffff", + "z6": "#4054CC", + "z7": "#ffffff", + "z1": "#4054cc", + "z9": "#ff2626" + }, + "sponsor": 6 + } + }, + "teamAway": { + "id": "mpg_team_KLGXSSUG$$mpg_user_1298752", + "name": "Kouks FC", + "abbr": "KFC", + "coach": "Momo", + "jersey": { + "id": 0, + "sponsor": 7, + "zones": { + "z1": "#00b6af" + } + } + }, + "players": [ + { + "firstname": "Benoit", + "lastname": "Costil", + "playerid": "player_42713", + "teamid": "140", + "position": 1, + "quotation": 20 + }, + { + "firstname": "Jerome", + "lastname": "Prior", + "playerid": "player_181439", + "teamid": "140", + "position": 1, + "quotation": 7 + }, + { + "firstname": "Léo", + "lastname": "Dubois", + "playerid": "player_183779", + "teamid": "143", + "position": 2, + "quotation": 11 + }, + { + "firstname": "Boubacar", + "lastname": "Kamara", + "playerid": "player_226944", + "teamid": "144", + "position": 2, + "quotation": 11 + }, + { + "firstname": "Damien", + "lastname": "Le Tallec", + "playerid": "player_52782", + "teamid": "147", + "position": 2, + "quotation": 23 + }, + { + "firstname": null, + "lastname": "Marquinhos", + "playerid": "player_116406", + "teamid": "149", + "position": 2, + "quotation": 25 + }, + { + "firstname": "Thomas", + "lastname": "Meunier", + "playerid": "player_93605", + "teamid": "149", + "position": 2, + "quotation": 24 + }, + { + "firstname": "Houssem", + "lastname": "Aouar", + "playerid": "player_231961", + "teamid": "143", + "position": 3, + "quotation": 25 + }, + { + "firstname": "Dimitri", + "lastname": "Lienard", + "playerid": "player_228322", + "teamid": "153", + "position": 3, + "quotation": 12 + }, + { + "firstname": null, + "lastname": "Lucas Evangelista", + "playerid": "player_163562", + "teamid": "430", + "position": 3, + "quotation": 8 + }, + { + "firstname": null, + "lastname": "Luiz Gustavo", + "playerid": "player_47654", + "teamid": "144", + "position": 3, + "quotation": 15 + }, + { + "firstname": "Christopher", + "lastname": "Nkunku", + "playerid": "player_213198", + "teamid": "149", + "position": 3, + "quotation": 13 + }, + { + "firstname": "Florian", + "lastname": "Thauvin", + "playerid": "player_95434", + "teamid": "144", + "position": 3, + "quotation": 38 + }, + { + "firstname": "Aaron", + "lastname": "Leya Iseka", + "playerid": "player_185727", + "teamid": "427", + "position": 4, + "quotation": 10 + }, + { + "firstname": null, + "lastname": "Neymar", + "playerid": "player_61278", + "teamid": "149", + "position": 4, + "quotation": 52 + }, + { + "firstname": "Nicolas", + "lastname": "Pepe", + "playerid": "player_195735", + "teamid": "429", + "position": 4, + "quotation": 36 + }, + { + "firstname": "Emiliano", + "lastname": "Sala", + "playerid": "player_103124", + "teamid": "430", + "position": 4, + "quotation": 30 + }, + { + "firstname": null, + "lastname": "Ambroise Oyongo", + "playerid": "player_180562", + "teamid": "147", + "position": 2, + "quotation": 16 + }, + { + "firstname": "Gaetan", + "lastname": "Laborde", + "playerid": "player_167443", + "teamid": "147", + "position": 4, + "quotation": 24 + }, + { + "firstname": "Youri", + "lastname": "Tielemans", + "playerid": "player_166989", + "teamid": "146", + "position": 3, + "quotation": 13 + }, + { + "firstname": "Lois", + "lastname": "Diony", + "playerid": "player_147577", + "teamid": "152", + "position": 4, + "quotation": 15 + }, + { + "firstname": "Renaud", + "lastname": "Ripart", + "playerid": "player_121150", + "teamid": "2336", + "position": 4, + "quotation": 17 + } + ], + "bonus": { + "1": 0, + "2": 0, + "3": 1, + "4": 3, + "5": 1, + "6": 1, + "7": 1 + }, + "nanardpaid": 0, + "money": 0, + "composition": 343, + "playersOnPitch": { + "1": "player_42713", + "2": "player_52782", + "3": "player_93605", + "4": "player_116406", + "5": "player_95434", + "6": "player_166989", + "7": "player_213198", + "8": "player_163562", + "9": "player_103124", + "10": "player_61278", + "11": "player_195735", + "12": "player_226944", + "13": "player_183779", + "14": "player_47654", + "15": "player_228322", + "16": "player_167443", + "17": "player_147577", + "18": "player_181439" + }, + "tacticalsubstitutes": [ + { + "subs": "player_226944", + "start": "player_116406", + "rating": 5 + }, + { + "subs": "player_167443", + "start": "player_195735", + "rating": 6 + }, + { + "subs": "player_47654", + "start": "player_163562", + "rating": 5 + }, + { + "subs": "player_147577", + "start": "player_61278", + "rating": 6 + }, + { + "subs": "player_228322", + "start": "player_213198", + "rating": 5 + } + ], + "bonusSelected": { + "type": 4, + "playerid": "player_231961" + }, + "nbPlayers": 8 + } +}