Skip to content

Commit

Permalink
Fix #209 : Captain bonus no more cumulative with boostOnePlayer (fix)
Browse files Browse the repository at this point in the history
  • Loading branch information
axel3rd committed Nov 22, 2021
1 parent 2c21135 commit be0debb
Show file tree
Hide file tree
Showing 17 changed files with 73,968 additions and 9 deletions.
9 changes: 5 additions & 4 deletions src/main/java/org/blondin/mpg/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -492,8 +492,9 @@ private static CoachRequest getCoachRequest(Team team, Coach coach, List<Player>
String playerIdForBonus = midfielders.get(0).getId();
request.setBonusSelected(selectBonus(coach.getBonusSelected(), team.getBonuses(), gameRemaining, config.isUseBonus(), playerIdForBonus));
String playerIdForCaptain = request.getBonusSelected() != null
&& SelectedBonus.BONUS_BOOT_ONE_PLAYER.equals(request.getBonusSelected().getName()) ? midfielders.get(1).getId() : playerIdForBonus;
request.setCaptain(selectCapatain(coach.getCaptain(), playerIdForCaptain, config.isUseBonus()));
&& SelectedBonus.BONUS_BOOT_ONE_PLAYER.equals(request.getBonusSelected().getName())
&& !midfielders.get(1).getId().equals(request.getBonusSelected().getPlayerId()) ? midfielders.get(1).getId() : playerIdForBonus;
request.setCaptain(selectCapatain(coach.getCaptain(), playerIdForCaptain, playerIdForBonus, config.isUseBonus()));

// Main lines
setPlayersOnPitch(request, defenders, nbrDefenders, 1);
Expand Down Expand Up @@ -563,8 +564,8 @@ static boolean verifyPlayerOnPitch(PlayersOnPitch playersOnPitch, String playerI
return false;
}

static String selectCapatain(String previousCaptain, String captainIdIfNeeded, boolean useBonus) {
if (!useBonus || StringUtils.isNotBlank(previousCaptain)) {
static String selectCapatain(String previousCaptain, String captainIdIfNeeded, String currentPlayerBonus, boolean useBonus) {
if (!useBonus || (StringUtils.isNotBlank(previousCaptain) && !previousCaptain.equals(currentPlayerBonus))) {
return previousCaptain;
}
return captainIdIfNeeded;
Expand Down
13 changes: 8 additions & 5 deletions src/test/java/org/blondin/mpg/BonusSelectionTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -46,11 +46,14 @@ private Map<String, Integer> getBonus(int removeGoal, int boostAllPlayers, int n

@Test
public void testBonusCaptain() {
Assert.assertEquals(null, Main.selectCapatain(null, "newCaptain", false));
Assert.assertEquals("previousCaptain", Main.selectCapatain("previousCaptain", "newCaptain", false));
Assert.assertEquals("previousCaptain", Main.selectCapatain("previousCaptain", "newCaptain", true));
Assert.assertEquals("newCaptain", Main.selectCapatain(null, "newCaptain", true));
Assert.assertEquals("newCaptain", Main.selectCapatain("", "newCaptain", true));
Assert.assertEquals(null, Main.selectCapatain(null, "newCaptain", null, false));
Assert.assertEquals("previousCaptain", Main.selectCapatain("previousCaptain", "newCaptain", "somePlayer", false));
Assert.assertEquals("previousCaptain", Main.selectCapatain("previousCaptain", "newCaptain", "somePlayer", true));
Assert.assertEquals("previousCaptain", Main.selectCapatain("previousCaptain", "newCaptain", null, true));
Assert.assertEquals("previousCaptain", Main.selectCapatain("previousCaptain", "", null, true));
Assert.assertEquals("newCaptain", Main.selectCapatain("somePlayer", "newCaptain", "somePlayer", true));
Assert.assertEquals("newCaptain", Main.selectCapatain(null, "newCaptain", "somePlayer", true));
Assert.assertEquals("newCaptain", Main.selectCapatain("", "newCaptain", "somePlayer", true));
}

@Test
Expand Down
61 changes: 61 additions & 0 deletions src/test/java/org/blondin/mpg/MainTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,67 @@ public void testRealWithBadCredentials() throws Exception {
}
}

@Test
public void testCaptainAndBoostPlayerBonus3() throws Exception {
prepareMainFrenchLigue1Mocks("MLAX7HMK-20211122", "2021", "20211122", "20211122");
stubFor(get("/division/mpg_division_MLAX7HMK_3_1")
.willReturn(aResponse().withHeader("Content-Type", "application/json").withBodyFile("mpg.division.MLAX7HMK.20211122.json")));
stubFor(get("/team/mpg_team_MLAX7HMK_3_1_6")
.willReturn(aResponse().withHeader("Content-Type", "application/json").withBodyFile("mpg.team.MLAX7HMK.20211122.json")));
stubFor(get("/division/mpg_division_MLAX7HMK_3_1/coach")
.willReturn(aResponse().withHeader("Content-Type", "application/json").withBodyFile("mpg.coach.MLAX7HMK.20211122.json")));
stubFor(put("/match-team-formation/mpg_match_team_formation_MLAX7HMK_3_1_14_5_6")
.willReturn(aResponse().withStatus(Response.Status.OK.getStatusCode()).withHeader("Content-Type", "application/json")
.withBody("Fake: mpg_match_team_formation_MLAX7HMK_3_1_14_5_6")));

Config config = spy(getConfig());
doReturn(true).when(config).isTeampUpdate();
doReturn(true).when(config).isEfficiencyRecentFocus();
doReturn(false).when(config).isTacticalSubstitutes();
executeMainProcess(config);

Assert.assertTrue(getLogOut(), getLogOut().contains(" Captain: Faivre Romain"));
Assert.assertTrue(getLogOut(), getLogOut().contains(" Bonus : boostOnePlayer (Blas Ludovic)"));
}

@Test
public void testCaptainAndBoostPlayerBonus2() throws Exception {
stubFor(post("/user/sign-in")
.willReturn(aResponse().withHeader("Content-Type", "application/json").withBodyFile("mpg.user-signIn.fake.json")));
stubFor(get("/dashboard/leagues")
.willReturn(aResponse().withHeader("Content-Type", "application/json").withBodyFile("mpg.dashboard.MLMHBPCB-20211122.json")));
stubFor(get("/division/mpg_division_MLMHBPCB_3_1")
.willReturn(aResponse().withHeader("Content-Type", "application/json").withBodyFile("mpg.division.MLMHBPCB.20211122.json")));
stubFor(get("/team/mpg_team_MLMHBPCB_3_1_4")
.willReturn(aResponse().withHeader("Content-Type", "application/json").withBodyFile("mpg.team.MLMHBPCB.20211122.json")));
stubFor(get("/division/mpg_division_MLMHBPCB_3_1/coach")
.willReturn(aResponse().withHeader("Content-Type", "application/json").withBodyFile("mpg.coach.MLMHBPCB.20211122.json")));
stubFor(get("/championship-players-pool/2")
.willReturn(aResponse().withHeader("Content-Type", "application/json").withBodyFile("mpg.poolPlayers.2.2021.json")));
stubFor(get("/championship-clubs")
.willReturn(aResponse().withHeader("Content-Type", "application/json").withBodyFile("mpg.clubs.2021.json")));
stubFor(get("/division/mpg_division_MLEFEX6G_3_1/available-players").willReturn(
aResponse().withHeader("Content-Type", "application/json").withBodyFile("mpg.division.available.players.MLMHBPCB.20211122.json")));
stubFor(put("/match-team-formation/mpg_match_team_formation_MLMHBPCB_3_1_12_5_4")
.willReturn(aResponse().withStatus(Response.Status.OK.getStatusCode()).withHeader("Content-Type", "application/json")
.withBody("Fake: mpg_match_team_formation_MLMHBPCB_3_1_12_5_4")));

stubFor(get("/builds").willReturn(aResponse().withHeader("Content-Type", "application/json").withBodyFile("mlnstats.builds.20211122.json")));
stubFor(get("/leagues/Premier-League")
.willReturn(aResponse().withHeader("Content-Type", "application/json").withBodyFile("mlnstats.premier-league.20211122.json")));
stubFor(get("/injuries/football/england-premier-league/")
.willReturn(aResponse().withHeader("Content-Type", "application/json").withBodyFile("sportsgambler.premier-league.20211122.html")));

Config config = spy(getConfig());
doReturn(true).when(config).isTeampUpdate();
doReturn(true).when(config).isEfficiencyRecentFocus();
doReturn(false).when(config).isTacticalSubstitutes();
executeMainProcess(config);

Assert.assertTrue(getLogOut(), getLogOut().contains(" Captain: Rodri"));
Assert.assertTrue(getLogOut(), getLogOut().contains(" Bonus : boostOnePlayer (Trossard Leandro)"));
}

@Test
public void testCaptainAndBoostPlayerBonus() throws Exception {
prepareMainFrenchLigue2Mocks("MLEFEX6G-20211019", "2021", "20211019", "20211019");
Expand Down
1 change: 1 addition & 0 deletions src/test/resources/__files/mlnstats.builds.20211122.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"1":"2021-11-22T05:59:50.688Z","2":"2021-11-22T03:31:26.408Z","3":"2021-11-22T03:32:49.855Z","4":"2021-11-21T03:33:57.260Z","5":"2021-11-22T03:34:00.765Z"}
1 change: 1 addition & 0 deletions src/test/resources/__files/mlnstats.ligue-1.20211122.json

Large diffs are not rendered by default.

Large diffs are not rendered by default.

88 changes: 88 additions & 0 deletions src/test/resources/__files/mpg.coach.MLAX7HMK.20211122.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
{
"divisionMatch": {
"id": "mpg_division_match_MLAX7HMK_3_1_14_5_6_5",
"type": "mpg_division_match",
"divisionId": "mpg_division_MLAX7HMK_3_1",
"home": {
"teamId": "mpg_team_MLAX7HMK_3_1_6"
},
"away": {
"teamId": "mpg_team_MLAX7HMK_3_1_5"
}
},
"matchTeamFormation": {
"id": "mpg_match_team_formation_MLAX7HMK_3_1_14_5_6",
"type": "mpg_match_team_formation",
"composition": "343",
"playersOnPitch": {
"1": "mpg_championship_player_85633",
"2": "mpg_championship_player_170409",
"3": "mpg_championship_player_205552",
"4": "mpg_championship_player_38580",
"5": "mpg_championship_player_213940",
"6": "mpg_championship_player_441240",
"7": "mpg_championship_player_174254",
"8": "mpg_championship_player_437504",
"9": "mpg_championship_player_167443",
"10": "mpg_championship_player_193454",
"11": "mpg_championship_player_73879",
"12": "mpg_championship_player_437753",
"13": "mpg_championship_player_158494",
"14": "mpg_championship_player_55948",
"15": "mpg_championship_player_159967",
"16": null,
"17": null,
"18": "mpg_championship_player_104407"
},
"tacticalSubs": [
{
"rating": 5,
"subId": "mpg_championship_player_437753",
"starterId": "mpg_championship_player_38580"
},
{
"rating": 5,
"subId": "mpg_championship_player_55948",
"starterId": "mpg_championship_player_437504"
},
{
"rating": 5,
"subId": "mpg_championship_player_159967",
"starterId": "mpg_championship_player_174254"
}
],
"selectedBonus": {
"name": "boostOnePlayer",
"playerId": "mpg_championship_player_213940"
},
"captain": "mpg_championship_player_441240",
"buyableRemoveGoal": 1,
"availableBonuses": {
"blockTacticalSubs": 0,
"boostAllPlayers": 1,
"boostOnePlayer": 2,
"mirror": 0,
"nerfGoalkeeper": 2,
"removeGoal": 1,
"removeRandomPlayer": 0
}
},
"nextGameWeek": {
"gameWeekNumber": 15,
"startDate": "2021-11-26T20:00:00Z",
"endDate": "2021-11-28T19:45:00Z",
"startIn": 347468,
"matchesIds": [
"mpg_championship_match_2215637",
"mpg_championship_match_2215638",
"mpg_championship_match_2215643",
"mpg_championship_match_2215645",
"mpg_championship_match_2215636",
"mpg_championship_match_2215639",
"mpg_championship_match_2215641",
"mpg_championship_match_2215644",
"mpg_championship_match_2215642",
"mpg_championship_match_2215640"
]
}
}
89 changes: 89 additions & 0 deletions src/test/resources/__files/mpg.coach.MLMHBPCB.20211122.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
{
"divisionMatch": {
"id": "mpg_division_match_MLMHBPCB_3_1_12_5_6_4",
"type": "mpg_division_match",
"divisionId": "mpg_division_MLMHBPCB_3_1",
"home": {
"teamId": "mpg_team_MLMHBPCB_3_1_6"
},
"away": {
"teamId": "mpg_team_MLMHBPCB_3_1_4"
}
},
"matchTeamFormation": {
"id": "mpg_match_team_formation_MLMHBPCB_3_1_12_5_4",
"type": "mpg_match_team_formation",
"composition": "343",
"playersOnPitch": {
"1": "mpg_championship_player_40836",
"2": "mpg_championship_player_107613",
"3": "mpg_championship_player_218031",
"4": "mpg_championship_player_83299",
"5": "mpg_championship_player_116216",
"6": "mpg_championship_player_141746",
"7": "mpg_championship_player_122806",
"8": "mpg_championship_player_101178",
"9": "mpg_championship_player_80954",
"10": "mpg_championship_player_57127",
"11": "mpg_championship_player_85971",
"12": "mpg_championship_player_171314",
"13": "mpg_championship_player_209036",
"14": "mpg_championship_player_220566",
"15": "mpg_championship_player_96787",
"16": "mpg_championship_player_81183",
"17": null,
"18": "mpg_championship_player_98980"
},
"tacticalSubs": [
{
"rating": 5,
"subId": "mpg_championship_player_171314",
"starterId": "mpg_championship_player_83299"
},
{
"rating": 5,
"subId": "mpg_championship_player_220566",
"starterId": "mpg_championship_player_101178"
},
{
"rating": 5,
"subId": "mpg_championship_player_96787",
"starterId": "mpg_championship_player_122806"
},
{
"rating": 6,
"subId": "mpg_championship_player_81183",
"starterId": "mpg_championship_player_85971"
}
],
"captain": "mpg_championship_player_116216",
"buyableRemoveGoal": 1,
"availableBonuses": {
"blockTacticalSubs": 0,
"boostAllPlayers": 1,
"boostOnePlayer": 3,
"mirror": 0,
"nerfGoalkeeper": 2,
"removeGoal": 1,
"removeRandomPlayer": 0
}
},
"nextGameWeek": {
"gameWeekNumber": 13,
"startDate": "2021-11-27T12:30:00Z",
"endDate": "2021-11-28T16:30:00Z",
"startIn": 408923,
"matchesIds": [
"mpg_championship_match_2210391",
"mpg_championship_match_2210396",
"mpg_championship_match_2210398",
"mpg_championship_match_2210400",
"mpg_championship_match_2210393",
"mpg_championship_match_2210392",
"mpg_championship_match_2210394",
"mpg_championship_match_2210397",
"mpg_championship_match_2210399",
"mpg_championship_match_2210395"
]
}
}
93 changes: 93 additions & 0 deletions src/test/resources/__files/mpg.dashboard.MLAX7HMK-20211122.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
{
"leaguesDivisionsItems": [
{
"leagueId": "mpg_league_MLAX7HMK",
"name": "Ici c'est Billiers !",
"adminId": "user_953561",
"status": 4,
"season": 3,
"mode": 2,
"createdAt": "2020-08-22T08:22:40Z",
"mercatoState": {
"divisionsLeft": 0,
"usersLeft": 0
},
"championshipId": 1,
"rating": "mpg",
"imageUrl": "https://s3.eu-west-1.amazonaws.com/image.mpg/9db725b3-fe27-42b4-9575-55cfbeef30d2.png",
"totalDivisions": 1,
"totalUsers": 10,
"totalMissedPosts": 4,
"teamId": "mpg_team_MLAX7HMK_3_1_6",
"divisionNumber": 1,
"nextRealGameWeekDate": "2021-11-26T20:00:00Z",
"currentTeamRanking": 2,
"currentTeamVariation": 0,
"divisionStatus": 4,
"divisionId": "mpg_division_MLAX7HMK_3_1",
"divisionTotalUsers": 10,
"liveState": {
"currentGameWeek": 14,
"firstRealGameWeek": 2,
"formationsStatuses": {
"mpg_team_MLAX7HMK_3_1_0": 1,
"mpg_team_MLAX7HMK_3_1_1": 1,
"mpg_team_MLAX7HMK_3_1_2": 1,
"mpg_team_MLAX7HMK_3_1_3": 1,
"mpg_team_MLAX7HMK_3_1_4": 1,
"mpg_team_MLAX7HMK_3_1_5": 1,
"mpg_team_MLAX7HMK_3_1_6": 2,
"mpg_team_MLAX7HMK_3_1_7": 2,
"mpg_team_MLAX7HMK_3_1_8": 1,
"mpg_team_MLAX7HMK_3_1_9": 1
},
"liveAt": "2021-08-11T22:17:51Z",
"standings": {
"mpg_team_MLAX7HMK_3_1_2": {
"rank": 1,
"variation": 0
},
"mpg_team_MLAX7HMK_3_1_6": {
"rank": 2,
"variation": 0
},
"mpg_team_MLAX7HMK_3_1_3": {
"rank": 3,
"variation": 0
},
"mpg_team_MLAX7HMK_3_1_5": {
"rank": 4,
"variation": 0
},
"mpg_team_MLAX7HMK_3_1_8": {
"rank": 5,
"variation": 0
},
"mpg_team_MLAX7HMK_3_1_4": {
"rank": 6,
"variation": 0
},
"mpg_team_MLAX7HMK_3_1_1": {
"rank": 7,
"variation": 0
},
"mpg_team_MLAX7HMK_3_1_7": {
"rank": 8,
"variation": 0
},
"mpg_team_MLAX7HMK_3_1_0": {
"rank": 9,
"variation": 0
},
"mpg_team_MLAX7HMK_3_1_9": {
"rank": 10,
"variation": 0
}
},
"totalGameWeeks": 18
},
"currentFormationStatus": 2
}
],
"defaultOrder": false
}
Loading

0 comments on commit be0debb

Please sign in to comment.