Skip to content

Commit

Permalink
Removed hardcoded dates.
Browse files Browse the repository at this point in the history
  • Loading branch information
AkshithaFM committed May 10, 2024
1 parent de11f10 commit d542f1c
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -90,26 +90,28 @@ public Event joinEventRazorPayment(final RazorPaymentRequest paymentRequest) {
public List<com.flickmatch.platform.graphql.type.Event> getEvents(String cityId, String localTimeZone) {
Date currentTime = new Date(System.currentTimeMillis());
List<com.flickmatch.platform.graphql.type.Event> eventList = new ArrayList<>();
List<com.flickmatch.platform.graphql.type.Event> prevDayList= getPastEvents(cityId,1,localTimeZone);
List<com.flickmatch.platform.graphql.type.Event> 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<Event> eventData = eventRepository.findById(new Event.EventId(cityId, formattedDate));
System.out.println(eventData);
if (eventData.isPresent()) {
List<com.flickmatch.platform.graphql.type.Event> dailyEventList =
eventData.get().getEventDetailsList().stream()
.map(eventDetails -> mapEventToGQLType(eventDetails, formattedDate, localTimeZone, cityId))
.toList();
eventList.addAll(dailyEventList);
}

}
return eventList;
}


public List<com.flickmatch.platform.graphql.type.Event> getPastEvents(String cityId, Integer inDays, String localTimeZone) {
List<com.flickmatch.platform.graphql.type.Event> pastEventList = new ArrayList<>();
Date currentTime = new Date(System.currentTimeMillis());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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<Event> 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<com.flickmatch.platform.graphql.type.Event> result = eventBuilder.getEvents(cityId, localTimeZone);
List<com.flickmatch.platform.graphql.type.Event> result = eventBuilder.getEvents("2", "GMT+5:30");

// Verify the result
assertEquals(2, result.size());
Expand All @@ -178,22 +185,25 @@ public void testGetEvents() {
private List<Event> createMockEvents(String cityId) {
List<Event> 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;
}
Expand Down

0 comments on commit d542f1c

Please sign in to comment.