From 3acce399cc9d84627083518a3a7d6f52dbddd785 Mon Sep 17 00:00:00 2001 From: Akshitha2106 Date: Tue, 7 May 2024 10:40:55 +0530 Subject: [PATCH 1/5] Added changes which shows previous day events --- .../com/flickmatch/platform/graphql/builder/EventBuilder.java | 3 +++ 1 file changed, 3 insertions(+) diff --git a/platform/src/main/java/com/flickmatch/platform/graphql/builder/EventBuilder.java b/platform/src/main/java/com/flickmatch/platform/graphql/builder/EventBuilder.java index cae8dd7a..264dae11 100644 --- a/platform/src/main/java/com/flickmatch/platform/graphql/builder/EventBuilder.java +++ b/platform/src/main/java/com/flickmatch/platform/graphql/builder/EventBuilder.java @@ -90,7 +90,9 @@ public Event joinEventRazorPayment(final RazorPaymentRequest paymentRequest) { public List getEvents(String cityId, String localTimeZone) { Date currentTime = new Date(System.currentTimeMillis()); List eventList = new ArrayList<>(); + List prevDayList= getPastEvents(cityId,1,localTimeZone); final int GET_EVENT_DAYS = 7; + eventList.addAll(prevDayList); for (int i = 0; i < GET_EVENT_DAYS; i++) { Date currentDate = Date.from(currentTime.toInstant().plus(i, ChronoUnit.DAYS)); String formattedDate = DateUtil.extractDateFromISOFormatDate(currentDate, localTimeZone); @@ -102,6 +104,7 @@ public List getEvents(String cityId, .toList(); eventList.addAll(dailyEventList); } + } return eventList; } From edebcff55b899684b85a5e0a54eef3404f3a8638 Mon Sep 17 00:00:00 2001 From: Akshitha2106 Date: Thu, 9 May 2024 09:59:49 +0530 Subject: [PATCH 2/5] Added test cases --- .../graphql/builder/EventBuilder.java | 5 ++- .../graphql/builder/EventBuilderTest.java | 41 ++++++++++++++++++- 2 files changed, 43 insertions(+), 3 deletions(-) diff --git a/platform/src/main/java/com/flickmatch/platform/graphql/builder/EventBuilder.java b/platform/src/main/java/com/flickmatch/platform/graphql/builder/EventBuilder.java index 264dae11..cdf74761 100644 --- a/platform/src/main/java/com/flickmatch/platform/graphql/builder/EventBuilder.java +++ b/platform/src/main/java/com/flickmatch/platform/graphql/builder/EventBuilder.java @@ -90,9 +90,10 @@ public Event joinEventRazorPayment(final RazorPaymentRequest paymentRequest) { public List getEvents(String cityId, String localTimeZone) { Date currentTime = new Date(System.currentTimeMillis()); List eventList = new ArrayList<>(); - List prevDayList= getPastEvents(cityId,1,localTimeZone); + List prevDayList= getPastEvents(cityId,1,localTimeZone); + final int GET_EVENT_DAYS = 7; - eventList.addAll(prevDayList); + eventList.addAll(prevDayList); for (int i = 0; i < GET_EVENT_DAYS; i++) { Date currentDate = Date.from(currentTime.toInstant().plus(i, ChronoUnit.DAYS)); String formattedDate = DateUtil.extractDateFromISOFormatDate(currentDate, localTimeZone); diff --git a/platform/src/test/java/com/flickmatch/platform/graphql/builder/EventBuilderTest.java b/platform/src/test/java/com/flickmatch/platform/graphql/builder/EventBuilderTest.java index 6a0d1695..08cc5256 100644 --- a/platform/src/test/java/com/flickmatch/platform/graphql/builder/EventBuilderTest.java +++ b/platform/src/test/java/com/flickmatch/platform/graphql/builder/EventBuilderTest.java @@ -25,7 +25,6 @@ public class EventBuilderTest { private EventRepository eventRepository; private EventBuilder eventBuilder; - @BeforeEach public void setup() { eventRepository = mock(EventRepository.class); @@ -158,4 +157,44 @@ public void testGetCurrencyForCity() { assertEquals("USD", currencyForSanFrancisco); } + + @Test + public void testGetEvents() { + // Mock input data + String cityId = "2"; + String localTimeZone = "GMT+5:030"; + List events = createMockEvents(cityId); + + // Mock the event repository to return the list of events + when(eventRepository.findAll()).thenReturn(events); + + // Call the method under test + List result = eventBuilder.getEvents(cityId, localTimeZone); + + // Verify the result + assertEquals(0, result.size()); + } + + private List createMockEvents(String cityId) { + List events = new ArrayList<>(); + + // Create mock events + Event event1 = new Event(); + Event event2 = new Event(); + + // Set up event details + event1.setCityId(cityId); + event1.setDate("2024-05-06"); + event1.setEventDetailsList(new ArrayList<>()); + + event2.setCityId(cityId); // Make sure to set the cityId property + event2.setDate("2024-05-07"); + event2.setEventDetailsList(new ArrayList<>()); + + // Add events to the list + events.add(event1); + events.add(event2); + + return events; + } } From de11f10cd18499516b755fba58aa1edfd648825a Mon Sep 17 00:00:00 2001 From: Akshitha2106 Date: Thu, 9 May 2024 11:22:03 +0530 Subject: [PATCH 3/5] updated test case --- .../flickmatch/platform/graphql/builder/EventBuilderTest.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/platform/src/test/java/com/flickmatch/platform/graphql/builder/EventBuilderTest.java b/platform/src/test/java/com/flickmatch/platform/graphql/builder/EventBuilderTest.java index 08cc5256..9b63220d 100644 --- a/platform/src/test/java/com/flickmatch/platform/graphql/builder/EventBuilderTest.java +++ b/platform/src/test/java/com/flickmatch/platform/graphql/builder/EventBuilderTest.java @@ -172,7 +172,7 @@ public void testGetEvents() { List result = eventBuilder.getEvents(cityId, localTimeZone); // Verify the result - assertEquals(0, result.size()); + assertEquals(2, result.size()); } private List createMockEvents(String cityId) { From d542f1c022a16b1713c184606b4974c036d75804 Mon Sep 17 00:00:00 2001 From: Akshitha2106 Date: Fri, 10 May 2024 16:54:41 +0530 Subject: [PATCH 4/5] Removed hardcoded dates. --- .../graphql/builder/EventBuilder.java | 8 ++-- .../graphql/builder/EventBuilderTest.java | 48 +++++++++++-------- 2 files changed, 34 insertions(+), 22 deletions(-) diff --git a/platform/src/main/java/com/flickmatch/platform/graphql/builder/EventBuilder.java b/platform/src/main/java/com/flickmatch/platform/graphql/builder/EventBuilder.java index cdf74761..9e00eb54 100644 --- a/platform/src/main/java/com/flickmatch/platform/graphql/builder/EventBuilder.java +++ b/platform/src/main/java/com/flickmatch/platform/graphql/builder/EventBuilder.java @@ -90,14 +90,16 @@ public Event joinEventRazorPayment(final RazorPaymentRequest paymentRequest) { public List getEvents(String cityId, String localTimeZone) { Date currentTime = new Date(System.currentTimeMillis()); List eventList = new ArrayList<>(); - List prevDayList= getPastEvents(cityId,1,localTimeZone); + List prevDayList = getPastEvents(cityId, 1, localTimeZone); final int GET_EVENT_DAYS = 7; - eventList.addAll(prevDayList); + eventList.addAll(prevDayList); for (int i = 0; i < GET_EVENT_DAYS; i++) { Date currentDate = Date.from(currentTime.toInstant().plus(i, ChronoUnit.DAYS)); String formattedDate = DateUtil.extractDateFromISOFormatDate(currentDate, localTimeZone); + System.out.println(formattedDate); Optional eventData = eventRepository.findById(new Event.EventId(cityId, formattedDate)); + System.out.println(eventData); if (eventData.isPresent()) { List dailyEventList = eventData.get().getEventDetailsList().stream() @@ -105,11 +107,11 @@ public List getEvents(String cityId, .toList(); eventList.addAll(dailyEventList); } - } return eventList; } + public List getPastEvents(String cityId, Integer inDays, String localTimeZone) { List pastEventList = new ArrayList<>(); Date currentTime = new Date(System.currentTimeMillis()); diff --git a/platform/src/test/java/com/flickmatch/platform/graphql/builder/EventBuilderTest.java b/platform/src/test/java/com/flickmatch/platform/graphql/builder/EventBuilderTest.java index 9b63220d..f4ab769c 100644 --- a/platform/src/test/java/com/flickmatch/platform/graphql/builder/EventBuilderTest.java +++ b/platform/src/test/java/com/flickmatch/platform/graphql/builder/EventBuilderTest.java @@ -17,6 +17,7 @@ import java.sql.Time; import java.text.ParseException; import java.text.SimpleDateFormat; +import java.time.LocalDate; import java.util.*; public class EventBuilderTest { @@ -162,14 +163,20 @@ public void testGetCurrencyForCity() { public void testGetEvents() { // Mock input data String cityId = "2"; - String localTimeZone = "GMT+5:030"; + String localTimeZone = "GMT+05:30"; List events = createMockEvents(cityId); - + // Print details of each event +// for (Event event : events) { +// System.out.println("Event Details:"); +// System.out.println("City ID: " + event.getCityId()); +// System.out.println("Date: " + event.getDate()); +// // Add more details as needed +// } // Mock the event repository to return the list of events when(eventRepository.findAll()).thenReturn(events); // Call the method under test - List result = eventBuilder.getEvents(cityId, localTimeZone); + List result = eventBuilder.getEvents("2", "GMT+5:30"); // Verify the result assertEquals(2, result.size()); @@ -178,22 +185,25 @@ public void testGetEvents() { private List createMockEvents(String cityId) { List events = new ArrayList<>(); - // Create mock events - Event event1 = new Event(); - Event event2 = new Event(); - - // Set up event details - event1.setCityId(cityId); - event1.setDate("2024-05-06"); - event1.setEventDetailsList(new ArrayList<>()); - - event2.setCityId(cityId); // Make sure to set the cityId property - event2.setDate("2024-05-07"); - event2.setEventDetailsList(new ArrayList<>()); - - // Add events to the list - events.add(event1); - events.add(event2); + // Get today's date + LocalDate today = LocalDate.now(); + + // Create an event for today + Event eventToday = new Event(); + eventToday.setCityId(cityId); + eventToday.setDate(today.toString()); + eventToday.setEventDetailsList(new ArrayList<>()); + events.add(eventToday); + + // Get yesterday's date + LocalDate yesterday = today.minusDays(1); + + // Create an event for yesterday + Event eventYesterday = new Event(); + eventYesterday.setCityId(cityId); + eventYesterday.setDate(yesterday.toString()); + eventYesterday.setEventDetailsList(new ArrayList<>()); + events.add(eventYesterday); return events; } From 9efaf10eab633ef647e8945401e80a4f51afe548 Mon Sep 17 00:00:00 2001 From: abhimanyu-fm Date: Mon, 13 May 2024 21:41:46 -0700 Subject: [PATCH 5/5] Fixed failing test cases for getEvents --- .../platform/dynamodb/model/Event.java | 15 +++ .../graphql/builder/EventBuilder.java | 18 ++- .../rest/RazorPaymentCallbackController.java | 2 +- .../graphql/builder/EventBuilderTest.java | 111 +++++++++++------- 4 files changed, 96 insertions(+), 50 deletions(-) diff --git a/platform/src/main/java/com/flickmatch/platform/dynamodb/model/Event.java b/platform/src/main/java/com/flickmatch/platform/dynamodb/model/Event.java index dbfd9d89..fc5622cf 100644 --- a/platform/src/main/java/com/flickmatch/platform/dynamodb/model/Event.java +++ b/platform/src/main/java/com/flickmatch/platform/dynamodb/model/Event.java @@ -8,6 +8,7 @@ import java.util.Date; import java.util.List; +import java.util.Objects; @DynamoDBTable(tableName="Event") @Builder @@ -248,5 +249,19 @@ public void setDate(String date) { this.date = date; } + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + EventId eventId = (EventId) o; + return Objects.equals(cityId, eventId.cityId) && + Objects.equals(date, eventId.date); + } + + @Override + public int hashCode() { + return Objects.hash(cityId, date); + } + } } diff --git a/platform/src/main/java/com/flickmatch/platform/graphql/builder/EventBuilder.java b/platform/src/main/java/com/flickmatch/platform/graphql/builder/EventBuilder.java index 9e00eb54..204c4ec3 100644 --- a/platform/src/main/java/com/flickmatch/platform/graphql/builder/EventBuilder.java +++ b/platform/src/main/java/com/flickmatch/platform/graphql/builder/EventBuilder.java @@ -25,6 +25,8 @@ import java.util.*; import java.util.concurrent.atomic.AtomicInteger; +import static java.lang.String.format; + @Service @Log4j2 public class EventBuilder { @@ -90,19 +92,23 @@ public Event joinEventRazorPayment(final RazorPaymentRequest paymentRequest) { public List getEvents(String cityId, String localTimeZone) { Date currentTime = new Date(System.currentTimeMillis()); List eventList = new ArrayList<>(); - List prevDayList = getPastEvents(cityId, 1, localTimeZone); + List prevDayList = getPastEvents(cityId, 2, localTimeZone); + eventList.addAll(prevDayList); final int GET_EVENT_DAYS = 7; - eventList.addAll(prevDayList); + log.info(format("Fetching events for cityId %s in the next %d days", cityId, GET_EVENT_DAYS)); + for (int i = 0; i < GET_EVENT_DAYS; i++) { Date currentDate = Date.from(currentTime.toInstant().plus(i, ChronoUnit.DAYS)); String formattedDate = DateUtil.extractDateFromISOFormatDate(currentDate, localTimeZone); - System.out.println(formattedDate); - Optional eventData = eventRepository.findById(new Event.EventId(cityId, formattedDate)); - System.out.println(eventData); + Event.EventId eventId = Event.EventId.builder().cityId(cityId).date(formattedDate).build(); + Optional eventData = eventRepository.findById(eventId); + if (eventData.isPresent()) { List dailyEventList = eventData.get().getEventDetailsList().stream() + // TODO: Add condition here to check the the event is starting no later than 7 days + .filter(eventDetails -> eventDetails.getStartTime().after(currentTime)) .map(eventDetails -> mapEventToGQLType(eventDetails, formattedDate, localTimeZone, cityId)) .toList(); eventList.addAll(dailyEventList); @@ -117,6 +123,7 @@ public List getPastEvents(String cit Date currentTime = new Date(System.currentTimeMillis()); // Calculate the date before inDays Date dateBeforeInDays = Date.from(currentTime.toInstant().minus(inDays, ChronoUnit.DAYS)); + log.info(format("Fetching events for cityId %s in the last %d days.", cityId, inDays)); eventRepository.findAll().forEach(event -> { if (event.getCityId().equals(cityId)) { List pastEventsInCity = @@ -130,6 +137,7 @@ public List getPastEvents(String cit pastEventList.addAll(pastEventsInCity); } }); + log.info(format("Found a total of %d events", pastEventList.size())); return pastEventList; } diff --git a/platform/src/main/java/com/flickmatch/platform/rest/RazorPaymentCallbackController.java b/platform/src/main/java/com/flickmatch/platform/rest/RazorPaymentCallbackController.java index a9864a06..bcf9928c 100644 --- a/platform/src/main/java/com/flickmatch/platform/rest/RazorPaymentCallbackController.java +++ b/platform/src/main/java/com/flickmatch/platform/rest/RazorPaymentCallbackController.java @@ -74,7 +74,7 @@ public ResponseEntity processRazorCallback(@RequestParam("razorpay_order_id") } catch (Exception e) { - log.error("Error processing callback: {}", e.getStackTrace()); + log.error("Error processing callback: ", e); return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body("Error processing callback"); } diff --git a/platform/src/test/java/com/flickmatch/platform/graphql/builder/EventBuilderTest.java b/platform/src/test/java/com/flickmatch/platform/graphql/builder/EventBuilderTest.java index f4ab769c..38a60f49 100644 --- a/platform/src/test/java/com/flickmatch/platform/graphql/builder/EventBuilderTest.java +++ b/platform/src/test/java/com/flickmatch/platform/graphql/builder/EventBuilderTest.java @@ -1,23 +1,32 @@ package com.flickmatch.platform.graphql.builder; +import static com.flickmatch.platform.graphql.util.DateUtil.extractDateFromISOFormatDate; +import static java.time.Instant.now; +import static java.time.temporal.ChronoUnit.DAYS; +import static java.time.temporal.ChronoUnit.HOURS; +import static java.util.Date.from; import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.notNullValue; import static org.hamcrest.Matchers.hasSize; import static org.hamcrest.Matchers.equalTo; import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.mockito.ArgumentMatchers.eq; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; import com.flickmatch.platform.dynamodb.model.Event; import com.flickmatch.platform.dynamodb.repository.EventRepository; import com.flickmatch.platform.graphql.input.JoinEventInput; import com.flickmatch.platform.graphql.input.PlayerInput; +import com.flickmatch.platform.graphql.util.DateUtil; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.mockito.Mock; import java.sql.Time; import java.text.ParseException; import java.text.SimpleDateFormat; +import java.time.Instant; import java.time.LocalDate; +import java.time.temporal.ChronoUnit; import java.util.*; public class EventBuilderTest { @@ -92,34 +101,42 @@ private Optional createEventMockData() { .build(); List eventDetailsList = new ArrayList<>(); + eventDetailsList.add(getEventDetails(new Date(), new Date())); - Event.PlayerDetails playerDetails = Event.PlayerDetails.builder() + Optional event = Optional.ofNullable(Event.builder() + .eventId(eventId) + .eventDetailsList(eventDetailsList) + .build()); + return event; + } + + private List getListOfPlayerDetails() { + List playerDetailsList = new ArrayList<>(); + playerDetailsList.add(getPlayerDetails()); + + return playerDetailsList; + } + + private Event.PlayerDetails getPlayerDetails() { + return Event.PlayerDetails.builder() .name("name") .waNumber("waNumber") .build(); + } - List playerDetailsList = new ArrayList<>(); - playerDetailsList.add(playerDetails); - - Event.EventDetails eventDetails = Event.EventDetails.builder() + private Event.EventDetails getEventDetails(Date startTime, Date endTime) { + return Event.EventDetails.builder() .index(1) - .startTime(new Date()) - .endTime(new Date()) + .startTime(startTime) + .endTime(endTime) .charges(10.0) .reservedPlayersCount(0) .waitListPlayersCount(1) .sportName("Football") .venueName("venueName") .venueLocationLink("venueLocationLink") - .playerDetailsList(playerDetailsList) + .playerDetailsList(getListOfPlayerDetails()) .build(); - eventDetailsList.add(eventDetails); - - Optional event = Optional.ofNullable(Event.builder() - .eventId(eventId) - .eventDetailsList(eventDetailsList) - .build()); - return event; } @Test @@ -164,47 +181,53 @@ public void testGetEvents() { // Mock input data String cityId = "2"; String localTimeZone = "GMT+05:30"; - List events = createMockEvents(cityId); - // Print details of each event -// for (Event event : events) { -// System.out.println("Event Details:"); -// System.out.println("City ID: " + event.getCityId()); -// System.out.println("Date: " + event.getDate()); -// // Add more details as needed -// } + + List pastEvents = new ArrayList<>(); + + Instant currentTime = Instant.now(); + + String todayDate = extractDateFromISOFormatDate(from(currentTime), localTimeZone); + String yesterdayDate = extractDateFromISOFormatDate(from(currentTime.minus(1, DAYS)), localTimeZone); + Event eventToday = getMockEvent(cityId, todayDate, getEventDetailsList(currentTime)); + Event eventYesterday = getMockEvent(cityId, yesterdayDate, getEventDetailsList(currentTime)); + pastEvents.add(eventYesterday); + + Event.EventId eventIdForToday = Event.EventId.builder().cityId(cityId).date(todayDate).build(); + // Mock the event repository to return the list of events - when(eventRepository.findAll()).thenReturn(events); + when(eventRepository.findById(eq(eventIdForToday))).thenReturn(Optional.of(eventToday)); + when(eventRepository.findAll()).thenReturn(pastEvents); + // Call the method under test - List result = eventBuilder.getEvents("2", "GMT+5:30"); + List result = eventBuilder.getEvents(cityId, localTimeZone); // Verify the result assertEquals(2, result.size()); } - private List createMockEvents(String cityId) { - List events = new ArrayList<>(); + private List getEventDetailsList(Instant currentTime) { - // Get today's date - LocalDate today = LocalDate.now(); + Event.EventDetails eventInFuture1 = getEventDetails(from(currentTime.plus(1, HOURS)), + from(currentTime.plus(2, HOURS))); - // Create an event for today - Event eventToday = new Event(); - eventToday.setCityId(cityId); - eventToday.setDate(today.toString()); - eventToday.setEventDetailsList(new ArrayList<>()); - events.add(eventToday); + Event.EventDetails eventInPast1 = getEventDetails(from(currentTime.minus(4, HOURS)), + from(currentTime.minus(3, HOURS))); - // Get yesterday's date - LocalDate yesterday = today.minusDays(1); + Event.EventDetails eventInPast2 = getEventDetails(from(currentTime.minus(4, DAYS)), + from(currentTime.minus(3, DAYS))); - // Create an event for yesterday - Event eventYesterday = new Event(); - eventYesterday.setCityId(cityId); - eventYesterday.setDate(yesterday.toString()); - eventYesterday.setEventDetailsList(new ArrayList<>()); - events.add(eventYesterday); + List listOfEventDetailsForADay = new ArrayList<>(); + listOfEventDetailsForADay.add(eventInFuture1); + listOfEventDetailsForADay.add(eventInPast1); - return events; + return listOfEventDetailsForADay; + } + + private Event getMockEvent(String cityId, String date, List eventDetailsList) { + return Event.builder() + .eventId(Event.EventId.builder().cityId(cityId).date(date).build()) + .eventDetailsList(eventDetailsList) + .build(); } }