|
| 1 | +package com.android.unio.model.event |
| 2 | + |
| 3 | +import com.android.unio.model.association.Association |
| 4 | +import com.android.unio.model.firestore.MockReferenceList |
| 5 | +import com.android.unio.model.map.Location |
| 6 | +import com.google.firebase.Timestamp |
| 7 | +import java.util.Date |
| 8 | +import java.util.UUID |
| 9 | + |
| 10 | +/** |
| 11 | + * A mock implementation of the EventRepository interface. This class is used for testing purposes |
| 12 | + * to provide a predefined list of events. |
| 13 | + * |
| 14 | + * Since the actual EventRepository is not implemented yet, this mock repository allows for easy |
| 15 | + * testing with specific data. |
| 16 | + */ |
| 17 | +open class EventRepositoryMock : EventRepository { |
| 18 | + |
| 19 | + /** |
| 20 | + * Retrieves a list of mock events. |
| 21 | + * |
| 22 | + * @return A list of [Event] objects with predefined data for testing. |
| 23 | + */ |
| 24 | + override fun getEvents(onSuccess: (List<Event>) -> Unit, onFailure: (Exception) -> Unit) { |
| 25 | + try { |
| 26 | + val events = |
| 27 | + listOf( |
| 28 | + Event( |
| 29 | + uid = UUID.randomUUID().toString(), |
| 30 | + title = "WESKIC", |
| 31 | + organisers = MockReferenceList<Association>(), |
| 32 | + taggedAssociations = MockReferenceList<Association>(), |
| 33 | + image = "weskic", |
| 34 | + description = |
| 35 | + "The Summer Festival features live music, food stalls, and various activities for all ages.", |
| 36 | + catchyDescription = "Come to the best event of the Coaching IC!", |
| 37 | + price = 0.0, |
| 38 | + date = Timestamp(Date(2024 - 1900, 6, 20)), // July 20, 2024 |
| 39 | + location = Location(0.0, 0.0, "USA"), |
| 40 | + types = listOf(EventType.TRIP)), |
| 41 | + Event( |
| 42 | + uid = UUID.randomUUID().toString(), |
| 43 | + title = "Oktoberweek", |
| 44 | + organisers = MockReferenceList<Association>(), |
| 45 | + taggedAssociations = MockReferenceList<Association>(), |
| 46 | + image = "oktoberweek", |
| 47 | + description = |
| 48 | + "An evening of networking with industry leaders and innovators. Don't miss out!", |
| 49 | + catchyDescription = "There never enough beersssssss!", |
| 50 | + price = 10.0, |
| 51 | + date = Timestamp(Date(2024 - 1900, 4, 15)), // May 15, 2024 |
| 52 | + location = Location(1.0, 1.0, "USA"), |
| 53 | + types = listOf(EventType.OTHER)), |
| 54 | + Event( |
| 55 | + uid = UUID.randomUUID().toString(), |
| 56 | + title = "SwissTech Talk", |
| 57 | + organisers = MockReferenceList<Association>(), |
| 58 | + taggedAssociations = MockReferenceList<Association>(), |
| 59 | + image = "swisstechtalk", |
| 60 | + description = |
| 61 | + "Learn Kotlin from scratch with real-world examples and expert guidance.", |
| 62 | + catchyDescription = "Don't miss the chant de section!", |
| 63 | + price = 0.0, |
| 64 | + date = Timestamp(Date(2024 - 1900, 2, 10)), // March 10, 2024 |
| 65 | + location = Location(2.0, 2.0, "USA"), |
| 66 | + types = listOf(EventType.OTHER)), |
| 67 | + Event( |
| 68 | + uid = UUID.randomUUID().toString(), |
| 69 | + title = "Lapin Vert", |
| 70 | + organisers = MockReferenceList<Association>(), |
| 71 | + taggedAssociations = MockReferenceList<Association>(), |
| 72 | + image = "lapin_vert", |
| 73 | + description = |
| 74 | + "Join us for an unforgettable evening featuring local artists and musicians.", |
| 75 | + catchyDescription = "Venez, il y a des gens sympa!", |
| 76 | + price = 0.0, |
| 77 | + date = Timestamp(Date(2024 - 1900, 8, 25)), // September 25, 2024 |
| 78 | + location = Location(3.0, 3.0, "USA"), |
| 79 | + types = listOf(EventType.OTHER)), |
| 80 | + Event( |
| 81 | + uid = UUID.randomUUID().toString(), |
| 82 | + title = "Choose your coach!", |
| 83 | + organisers = MockReferenceList<Association>(), |
| 84 | + taggedAssociations = MockReferenceList<Association>(), |
| 85 | + image = "chooseyourcoach", |
| 86 | + description = |
| 87 | + "Participate in various sports activities and enjoy food and entertainment.", |
| 88 | + catchyDescription = "Pick the best one!", |
| 89 | + price = 5.0, |
| 90 | + date = Timestamp(Date(2024 - 1900, 5, 5)), // June 5, 2024 |
| 91 | + location = Location(4.0, 4.0, "USA"), |
| 92 | + types = listOf(EventType.SPORT)), |
| 93 | + Event( |
| 94 | + uid = UUID.randomUUID().toString(), |
| 95 | + title = "Concert", |
| 96 | + organisers = MockReferenceList<Association>(), |
| 97 | + taggedAssociations = MockReferenceList<Association>(), |
| 98 | + image = "antoinoxlephar", |
| 99 | + description = |
| 100 | + "A workshop dedicated to teaching strategies for successful social media marketing.", |
| 101 | + catchyDescription = "Best concert everrrrr!", |
| 102 | + price = 15.0, |
| 103 | + date = Timestamp(Date(2024 - 1900, 7, 30)), // August 30, 2024 |
| 104 | + location = Location(5.0, 5.0, "USA"), |
| 105 | + types = listOf(EventType.OTHER)), |
| 106 | + Event( |
| 107 | + uid = UUID.randomUUID().toString(), |
| 108 | + title = "Jam Session: Local Artists", |
| 109 | + organisers = MockReferenceList<Association>(), |
| 110 | + taggedAssociations = MockReferenceList<Association>(), |
| 111 | + image = "photo_2024_10_08_14_57_48", |
| 112 | + description = |
| 113 | + "An evening of music with local artists. Bring your instruments or just enjoy the show!", |
| 114 | + catchyDescription = "Support local talent in this open jam session!", |
| 115 | + price = 0.0, |
| 116 | + date = Timestamp(Date(2024 - 1900, 3, 12)), // April 12, 2024 |
| 117 | + location = Location(6.0, 6.0, "USA"), |
| 118 | + types = listOf(EventType.JAM))) |
| 119 | + onSuccess(events) |
| 120 | + } catch (e: Exception) { |
| 121 | + onFailure(e) |
| 122 | + } |
| 123 | + } |
| 124 | + |
| 125 | + // Mock implementation for getting events by association |
| 126 | + override fun getEventsOfAssociation( |
| 127 | + association: String, |
| 128 | + onSuccess: (List<Event>) -> Unit, |
| 129 | + onFailure: (Exception) -> Unit |
| 130 | + ) { |
| 131 | + // Filter mock events by tagged associations |
| 132 | + getEvents( |
| 133 | + { events -> |
| 134 | + onSuccess(events.filter { it.taggedAssociations.list.value.isEmpty() }) |
| 135 | + }, // Now filtering for empty tagged associations |
| 136 | + onFailure) |
| 137 | + } |
| 138 | + |
| 139 | + // Mock implementation for getting events between two dates |
| 140 | + override fun getNextEventsFromDateToDate( |
| 141 | + startDate: Timestamp, |
| 142 | + endDate: Timestamp, |
| 143 | + onSuccess: (List<Event>) -> Unit, |
| 144 | + onFailure: (Exception) -> Unit |
| 145 | + ) { |
| 146 | + // Filter mock events by date range |
| 147 | + getEvents( |
| 148 | + { events -> onSuccess(events.filter { it.date >= startDate && it.date <= endDate }) }, |
| 149 | + onFailure) |
| 150 | + } |
| 151 | + |
| 152 | + // Mock implementation to generate a new UID |
| 153 | + override fun getNewUid(): String { |
| 154 | + return UUID.randomUUID().toString() |
| 155 | + } |
| 156 | + |
| 157 | + // Mock implementation to add an event |
| 158 | + override fun addEvent(event: Event, onSuccess: () -> Unit, onFailure: (Exception) -> Unit) { |
| 159 | + // This is a mock, so we assume the event is added successfully |
| 160 | + onSuccess() |
| 161 | + } |
| 162 | + |
| 163 | + // Mock implementation to delete an event by ID |
| 164 | + override fun deleteEventById(id: String, onSuccess: () -> Unit, onFailure: (Exception) -> Unit) { |
| 165 | + // This is a mock, so we assume the event is deleted successfully |
| 166 | + onSuccess() |
| 167 | + } |
| 168 | +} |
0 commit comments