Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix 268 MpgStats date refresh mechanism #269

Merged
merged 3 commits into from
Nov 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<groupId>org.blondin</groupId>
<artifactId>mpg-coach-bot</artifactId>
<packaging>jar</packaging>
<version>1.13-SNAPSHOT</version>
<version>1.12.1-SNAPSHOT</version>
<name>MPG Coach Bot</name>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/org/blondin/mpg/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@ public static void main(String[] args) { // NOSONAR : args used as file option,
configFile = args[0];
}
Config config = Config.build(configFile);
MpgClient mpgClient = MpgClient.build(config);
MpgStatsClient mpgStatsClient = MpgStatsClient.build(config);
InjuredSuspendedWrapperClient outPlayersClient = InjuredSuspendedWrapperClient.build(config);
MpgClient mpgClient = MpgClient.build(config);
ApiClients apiClients = ApiClients.build(mpgClient, mpgStatsClient, outPlayersClient);
process(apiClients, config);
}
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/org/blondin/mpg/config/Config.java
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ private static void configMain(Config config, Properties properties, File fileCo
config.password = parseString(properties, "password");
if (StringUtils.isBlank(config.login) || StringUtils.isBlank(config.password)) {
throw new UnsupportedOperationException(
String.format("Login and/or password can't be retrieved from file '%s' of environement variables", fileConfig.getName()));
String.format("Login and/or password cannot be retrieved from file '%s' or environement variables", fileConfig.getName()));
}
config.teampUpdate = parseBoolean(properties, "team.update", config.teampUpdate);
config.efficiencyRecentFocus = parseBoolean(properties, "efficiency.recent.focus", config.efficiencyRecentFocus);
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/org/blondin/mpg/stats/MpgStatsClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public synchronized Championship getStats(ChampionshipStatsType type) {
Date leagueDateRefresh = getLeaguesRefresh().getDate(championship.getInfos().getId());
if (leagueDateRefresh == null || championship.getDate().before(leagueDateRefresh)) {
// Force refresh by using a mini cache time
championship = get("leagues/" + type.getValue(), Championship.class, 1);
championship = get("leagues/" + type.getValue() + "_v2.json", Championship.class, 1);
}
cache.put(type, championship);
}
Expand Down
43 changes: 43 additions & 0 deletions src/test/java/org/blondin/mpg/MainTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,33 @@ public void testRealWithBadCredentials() {
}
}

@Test
public void testLeaguesNotSupported() {
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.unsupported.json")));

Config config = spy(getConfig());
executeMainProcess(config);

Assert.assertTrue(getLogOut(), getLogOut().contains("Sorry, Champions League is currently not supported"));
Assert.assertTrue(getLogOut(), getLogOut().contains("Sorry, Ligue Super is currently not supported"));
}

@Test
public void testLeagueWaitMercatoEnd() {
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.wait-mercato-end.json")));

Config config = spy(getConfig());
executeMainProcess(config);

Assert.assertTrue(getLogOut(), getLogOut().contains("Some users should select players to kept before Mercato can start, come back soon !"));
}

@Test
public void testFollowed() {
stubFor(post("/user/sign-in")
Expand Down Expand Up @@ -515,6 +542,22 @@ public void testProcessFromEmptyCoach() throws IOException {
Assert.assertFalse(getLogOut(), getLogOut().contains("Players to sell (initial cash"));
}

@Test
public void testNoConfig() {
try {
Main.main(null);
Assert.fail("No Credentials");
} catch (UnsupportedOperationException e) {
Assert.assertTrue(e.getMessage().contains("Login and/or password cannot be retrieved"));
}
try {
Main.main(new String[] {});
Assert.fail("No Credentials");
} catch (UnsupportedOperationException e) {
Assert.assertTrue(e.getMessage().contains("Login and/or password cannot be retrieved"));
}
}

private void executeMainProcess(Config config) {
executeMainProcess(null, null, null, config);
}
Expand Down
26 changes: 26 additions & 0 deletions src/test/java/org/blondin/mpg/stats/MpgStatsClientTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,32 @@

public class MpgStatsClientTest extends AbstractMockTestClient {

@Test
public void testApiV2DateRefreshMechanismNoRefreshDate() {
// No league date refresh
stubFor(get("/builds.json")
.willReturn(aResponse().withHeader("Content-Type", "application/json").withBodyFile("mlnstats.builds.20220327-no-L1.json")));
stubFor(get("/leagues/Ligue-1_v2.json")
.willReturn(aResponse().withHeader("Content-Type", "application/json").withBodyFile("mlnstats.ligue-1.20220327.json")));
MpgStatsClient mpgStatsClient = MpgStatsClient.build(getConfig(), "http://localhost:" + getServer().port());

Player p = mpgStatsClient.getStats(ChampionshipStatsType.LIGUE_1).getPlayer("Mbappé");
Assert.assertEquals(47, p.getPrice());
}

@Test
public void testApiV2DateRefreshMechanismOldChampionshipDate() {
// No league date refresh
stubFor(get("/builds.json")
.willReturn(aResponse().withHeader("Content-Type", "application/json").withBodyFile("mlnstats.builds.20220327.json")));
stubFor(get("/leagues/Ligue-1_v2.json")
.willReturn(aResponse().withHeader("Content-Type", "application/json").withBodyFile("mlnstats.ligue-1.20220327-old-refresh.json")));
MpgStatsClient mpgStatsClient = MpgStatsClient.build(getConfig(), "http://localhost:" + getServer().port());

Player p = mpgStatsClient.getStats(ChampionshipStatsType.LIGUE_1).getPlayer("Mbappé");
Assert.assertEquals(47, p.getPrice());
}

@Test
public void testApiV2L1() {
stubFor(get("/builds.json")
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"2":"2022-03-25T15:35:23.614Z","3":"2022-03-25T15:35:43.968Z","4":"2022-03-25T15:35:57.096Z","5":"2022-03-25T15:36:06.884Z","Ligue-1-2020-2021":"2022-08-04T15:04:23.095Z","Ligue-1-2019-2020":"2022-08-04T15:28:19.922Z","Ligue-1-2021-2022":"2022-08-04T15:29:32.154Z"}

Large diffs are not rendered by default.

45 changes: 45 additions & 0 deletions src/test/resources/__files/mpg.dashboard.unsupported.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
{
"leaguesDivisionsItems": [
{
"leagueId": "mpg_league_XXXXX",
"name": "Fake",
"adminId": "user_xxx",
"status": 4,
"season": 1,
"mode": 1,
"defaultDivisionId": "mpg_division_RJH6ZHRM_1_1",
"createdAt": "2023-08-01T10:56:48.082Z",
"mercatoState": {
"divisionsLeft": 0,
"usersLeft": 0
},
"championshipId": 6,
"rating": "mpg",
"imageUrl": "https://s3.eu-west-1.amazonaws.com/image.mpg/ef7dd623-5fe8-4e1a-a924-932777afe21f.jpg",
"totalDivisions": 1,
"totalUsers": 10,
"isFollowed": false
},
{
"leagueId": "mpg_league_XXXXX",
"name": "Fake",
"adminId": "user_xxx",
"status": 4,
"season": 3,
"mode": 1,
"defaultDivisionId": "mpg_division_PJHY1S98_3_1",
"createdAt": "2022-08-01T17:47:04.196Z",
"mercatoState": {
"divisionsLeft": 0,
"usersLeft": 0
},
"championshipId": 7,
"rating": "mpg",
"imageUrl": "https://s3.eu-west-1.amazonaws.com/image.mpg/befdd6ab-2a86-46e8-915a-561a6fc73b3d.png",
"totalDivisions": 1,
"totalUsers": 10,
"isFollowed": false
}
],
"defaultOrder": false
}
25 changes: 25 additions & 0 deletions src/test/resources/__files/mpg.dashboard.wait-mercato-end.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
{
"leaguesDivisionsItems": [
{
"leagueId": "mpg_league_XXXXX",
"name": "Fake",
"adminId": "user_xxx",
"status": 6,
"season": 1,
"mode": 1,
"defaultDivisionId": "mpg_division_RJH6ZHRM_1_1",
"createdAt": "2023-08-01T10:56:48.082Z",
"mercatoState": {
"divisionsLeft": 0,
"usersLeft": 0
},
"championshipId": 1,
"rating": "mpg",
"imageUrl": "https://s3.eu-west-1.amazonaws.com/image.mpg/ef7dd623-5fe8-4e1a-a924-932777afe21f.jpg",
"totalDivisions": 1,
"totalUsers": 10,
"isFollowed": false
}
],
"defaultOrder": false
}
Loading