Skip to content

Commit

Permalink
Fix #189 : Manage UberEats player update
Browse files Browse the repository at this point in the history
  • Loading branch information
axel3rd committed May 3, 2021
1 parent 54c6a4c commit 4c2e97a
Show file tree
Hide file tree
Showing 4 changed files with 758 additions and 1 deletion.
22 changes: 21 additions & 1 deletion src/main/java/org/blondin/mpg/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -444,8 +444,9 @@ private static CoachRequest getCoachRequest(Coach coach, List<Player> players, C
List<Player> midfielders = players.stream().filter(p -> p.getPosition().equals(Position.M)).collect(Collectors.toList());
List<Player> 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);
Expand Down Expand Up @@ -484,9 +485,28 @@ private static CoachRequest getCoachRequest(Coach coach, List<Player> 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() == 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());
Expand Down
15 changes: 15 additions & 0 deletions src/test/java/org/blondin/mpg/MainTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
Original file line number Diff line number Diff line change
@@ -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
}
Loading

0 comments on commit 4c2e97a

Please sign in to comment.