-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
🐛 Refactor MenuParser and add RestaurantJobTest
The MenuParser in both 'quadrilateroParser' and 'centralRibeiraoParser' functions is updated to improve string cleaning and item finding. A new test file, RestaurantJobTest.kt, is also introduced to ensure stable and reliable retrieval of restaurant menus. This refactor enhances parsing logic and data accuracy, and the added test assists in keeping the parsing operation error-free.
- Loading branch information
Showing
2 changed files
with
56 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
52 changes: 52 additions & 0 deletions
52
restaurants/src/test/kotlin/app/jopiter/restaurants/RestaurantJobTest.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
package app.jopiter.restaurants | ||
|
||
import app.jopiter.restaurants.model.Restaurant | ||
import app.jopiter.restaurants.repository.RestaurantItemRepository | ||
import app.jopiter.restaurants.repository.postgres.PostgresRestaurantItemRepository | ||
import app.jopiter.restaurants.repository.usp.USPRestaurantItemRepository | ||
import app.jopiter.restaurants.repository.usp.parsers | ||
import io.kotest.core.extensions.install | ||
import io.kotest.core.spec.style.FunSpec | ||
import io.kotest.core.spec.style.ShouldSpec | ||
import io.kotest.extensions.testcontainers.JdbcTestContainerExtension | ||
import io.kotest.matchers.shouldBe | ||
import org.flywaydb.core.Flyway | ||
import org.ktorm.database.Database | ||
import org.testcontainers.containers.PostgreSQLContainer | ||
import java.time.LocalDate | ||
|
||
class RestaurantJobTest : ShouldSpec({ | ||
|
||
val postgresContainer = PostgreSQLContainer<Nothing>("postgres") | ||
val datasource = install(JdbcTestContainerExtension(postgresContainer)) | ||
val flyway = Flyway.configure().cleanDisabled(false).dataSource(datasource).load() | ||
|
||
val database = Database.connect(datasource) | ||
|
||
beforeSpec { | ||
flyway.clean() | ||
flyway.migrate() | ||
} | ||
|
||
val postgresRepository = PostgresRestaurantItemRepository(database) | ||
val uspRepository = USPRestaurantItemRepository("https://uspdigital.usp.br/rucard/servicos", parsers, "596df9effde6f877717b4e81fdb2ca9f") | ||
val restaurantItemRepository = RestaurantItemRepository(uspRepository, postgresRepository) | ||
val target = RestaurantJob(restaurantItemRepository) | ||
|
||
context("Attempt to get every parseable restaurant menu for the current day") { | ||
target.run() | ||
|
||
Restaurant.entries.sortedBy { it.id }.forEach { | ||
should("Not throw an error when parsing ${it.id}") { | ||
val response = restaurantItemRepository.get(it.id, setOf(LocalDate.now())) | ||
if(response.isEmpty()) { | ||
// Apparently, Crhea was closed back in 2020-03, but still responds and is still listed | ||
it shouldBe Restaurant.Crhea | ||
} | ||
response.take(2).forEach { | ||
println("Example(${it.restaurantId}, \"${it.unparsedMenu.replace("\n", "\\n")}\", \"${it.mainItem}\", \"${it.vegetarianItem}\", \"${it.dessertItem}\", \"mudane\")") | ||
} | ||
} | ||
} | ||
} | ||
}) |