You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
57 lines
2.6 KiB
57 lines
2.6 KiB
package net.aiterp.git.ykonsole2.infrastructure.repositories
|
|
|
|
import net.aiterp.git.ykonsole2.domain.models.WorkoutState
|
|
import net.aiterp.git.ykonsole2.domain.models.randomId
|
|
import net.aiterp.git.ykonsole2.domain.runtime.Calories
|
|
import net.aiterp.git.ykonsole2.domain.runtime.Distance
|
|
import net.aiterp.git.ykonsole2.domain.runtime.Level
|
|
import net.aiterp.git.ykonsole2.domain.runtime.Time
|
|
import net.aiterp.git.ykonsole2.withDatabase
|
|
import org.junit.jupiter.api.Assertions.*
|
|
import org.junit.jupiter.api.Test
|
|
|
|
internal class MySqlWorkoutStateRepositoryTest {
|
|
@Test
|
|
fun `life cycle`() = withDatabase {
|
|
val workoutId = randomId()
|
|
|
|
workoutStateRepo.apply {
|
|
// None in the start
|
|
assertEquals(emptyList<WorkoutState>(), fetchByWorkoutId(workoutId))
|
|
|
|
// Add a few states
|
|
val states = listOf(
|
|
WorkoutState(workoutId, Time(10)),
|
|
WorkoutState(workoutId, Time(20), calories = Calories(10)),
|
|
WorkoutState(workoutId, Time(30), calories = Calories(15), level = Level(18)),
|
|
WorkoutState(workoutId, Time(40), calories = Calories(20), distance = Distance(600)),
|
|
WorkoutState(workoutId, Time(50), calories = Calories(25), level = Level(18), distance = Distance(750)),
|
|
WorkoutState(workoutId, Time(60), level = Level(18)),
|
|
WorkoutState(workoutId, Time(70), level = Level(18), distance = Distance(1050)),
|
|
WorkoutState(workoutId, Time(80), distance = Distance(1200))
|
|
)
|
|
states.forEach { save(it) }
|
|
assertEquals(states, fetchByWorkoutId(workoutId))
|
|
|
|
// Overwrite the lot of them
|
|
val newStates = listOf(
|
|
WorkoutState(workoutId, Time(10), distance = Distance(150)),
|
|
WorkoutState(workoutId, Time(20), level = Level(18), distance = Distance(300)),
|
|
WorkoutState(workoutId, Time(30), level = Level(18)),
|
|
WorkoutState(workoutId, Time(40), calories = Calories(20), level = Level(18), distance = Distance(600)),
|
|
WorkoutState(workoutId, Time(50), calories = Calories(25), distance = Distance(750)),
|
|
WorkoutState(workoutId, Time(60), calories = Calories(30), level = Level(18)),
|
|
WorkoutState(workoutId, Time(70), calories = Calories(35)),
|
|
WorkoutState(workoutId, Time(80)),
|
|
)
|
|
newStates.forEach { save(it) }
|
|
assertEquals(newStates, fetchByWorkoutId(workoutId))
|
|
|
|
// Delete them, four at a time
|
|
deleteAll(newStates.subList(0, 4))
|
|
assertEquals(newStates.subList(4, 8), fetchByWorkoutId(workoutId))
|
|
deleteAll(newStates.subList(4, 8))
|
|
assertEquals(emptyList<WorkoutState>(), fetchByWorkoutId(workoutId))
|
|
}
|
|
}
|
|
}
|