From 710acc4a4f1fcb305f2adfe6c4e1533b9c69a1ff Mon Sep 17 00:00:00 2001 From: Alix Lourme Date: Sun, 12 Dec 2021 18:44:27 +0100 Subject: [PATCH] Fix #218 : Manage league last list day --- src/main/java/org/blondin/mpg/Main.java | 4 + .../org/blondin/mpg/root/model/League.java | 11 +++ src/test/java/org/blondin/mpg/MainTest.java | 12 +++ .../mpg.dashboard.NL931FU9-noNextweek.json | 84 +++++++++++++++++++ 4 files changed, 111 insertions(+) create mode 100644 src/test/resources/__files/mpg.dashboard.NL931FU9-noNextweek.json diff --git a/src/main/java/org/blondin/mpg/Main.java b/src/main/java/org/blondin/mpg/Main.java index b4c9915..7ca8bb8 100644 --- a/src/main/java/org/blondin/mpg/Main.java +++ b/src/main/java/org/blondin/mpg/Main.java @@ -111,6 +111,10 @@ static void processLeague(League league, ApiClients apiClients, Config config) { processMercatoLeague(league, apiClients, config); break; case GAMES: + if (league.isLive() && StringUtils.isBlank(league.getNextRealGameWeekDate())) { + LOG.info("\nThis is the last live day, no next week.\n"); + return; + } processGames(league, apiClients, config); break; } diff --git a/src/main/java/org/blondin/mpg/root/model/League.java b/src/main/java/org/blondin/mpg/root/model/League.java index a2b0248..e6bf538 100644 --- a/src/main/java/org/blondin/mpg/root/model/League.java +++ b/src/main/java/org/blondin/mpg/root/model/League.java @@ -18,6 +18,9 @@ public class League { private LeagueStatus status; private Mode mode; private int currentTeamStatus; + @JsonProperty("isLive") + private boolean live; + private String nextRealGameWeekDate; public String getId() { return StringUtils.removeStart(leagueId, "mpg_league_"); @@ -51,4 +54,12 @@ public int getCurrentTeamStatus() { return currentTeamStatus; } + public boolean isLive() { + return live; + } + + public String getNextRealGameWeekDate() { + return nextRealGameWeekDate; + } + } diff --git a/src/test/java/org/blondin/mpg/MainTest.java b/src/test/java/org/blondin/mpg/MainTest.java index f1de8a8..ac094ca 100644 --- a/src/test/java/org/blondin/mpg/MainTest.java +++ b/src/test/java/org/blondin/mpg/MainTest.java @@ -62,6 +62,18 @@ public void testRealWithBadCredentials() throws Exception { } } + @Test + public void testLastLiveDay() 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.NL931FU9-noNextweek.json"))); + Config config = spy(getConfig()); + executeMainProcess(config); + + Assert.assertTrue(getLogOut(), getLogOut().contains("This is the last live day, no next week")); + } + @Test public void testCaptainAndBoostPlayerBonus3() throws Exception { prepareMainFrenchLigue1Mocks("MLAX7HMK-20211122", "2021", "20211122", "20211122"); diff --git a/src/test/resources/__files/mpg.dashboard.NL931FU9-noNextweek.json b/src/test/resources/__files/mpg.dashboard.NL931FU9-noNextweek.json new file mode 100644 index 0000000..0a1dd60 --- /dev/null +++ b/src/test/resources/__files/mpg.dashboard.NL931FU9-noNextweek.json @@ -0,0 +1,84 @@ +{ + "leaguesDivisionsItems": [ + { + "leagueId": "mpg_league_NL931FU9", + "name": "¿Donde esta el Messi?", + "adminId": "user_35635", + "status": 4, + "season": 1, + "mode": 2, + "createdAt": "2021-08-22T15:32:30Z", + "mercatoState": { + "divisionsLeft": 0, + "usersLeft": 0 + }, + "championshipId": 3, + "rating": "mpg", + "imageUrl": "https://s3.eu-west-1.amazonaws.com/image.mpg/0d4b437e-d239-447f-9b93-6fb676fd4db5.jpg", + "totalDivisions": 1, + "totalUsers": 8, + "totalMissedPosts": 0, + "teamId": "mpg_team_NL931FU9_1_1_4", + "divisionNumber": 1, + "isLive": true, + "nextRealGameWeekDateNotExistWhenLeagueFinished": "2021-12-17T17:30:00Z", + "currentTeamRanking": 5, + "currentTeamVariation": 0, + "divisionStatus": 4, + "divisionId": "mpg_division_NL931FU9_1_1", + "divisionTotalUsers": 8, + "liveState": { + "currentGameWeek": 14, + "firstRealGameWeek": 4, + "formationsStatuses": { + "mpg_team_NL931FU9_1_1_0": 2, + "mpg_team_NL931FU9_1_1_1": 2, + "mpg_team_NL931FU9_1_1_2": 2, + "mpg_team_NL931FU9_1_1_3": 2, + "mpg_team_NL931FU9_1_1_4": 2, + "mpg_team_NL931FU9_1_1_5": 2, + "mpg_team_NL931FU9_1_1_6": 1, + "mpg_team_NL931FU9_1_1_7": 1 + }, + "liveAt": "2021-08-31T13:51:10Z", + "standings": { + "mpg_team_NL931FU9_1_1_3": { + "rank": 1, + "variation": 0 + }, + "mpg_team_NL931FU9_1_1_5": { + "rank": 2, + "variation": 0 + }, + "mpg_team_NL931FU9_1_1_0": { + "rank": 3, + "variation": 1 + }, + "mpg_team_NL931FU9_1_1_2": { + "rank": 4, + "variation": -1 + }, + "mpg_team_NL931FU9_1_1_4": { + "rank": 5, + "variation": 0 + }, + "mpg_team_NL931FU9_1_1_1": { + "rank": 6, + "variation": 0 + }, + "mpg_team_NL931FU9_1_1_6": { + "rank": 7, + "variation": 0 + }, + "mpg_team_NL931FU9_1_1_7": { + "rank": 8, + "variation": 0 + } + }, + "totalGameWeeks": 14 + }, + "currentFormationStatus": 2 + } + ], + "defaultOrder": false +}