forked from github/wulkanowy-mirror
Try to switch to next school year before it starts (#2278)
This commit is contained in:
parent
533157709b
commit
2e2b13384a
5 changed files with 64 additions and 16 deletions
|
@ -15,6 +15,7 @@ import io.mockk.impl.annotations.MockK
|
|||
import io.mockk.impl.annotations.SpyK
|
||||
import io.mockk.just
|
||||
import kotlinx.coroutines.runBlocking
|
||||
import kotlinx.coroutines.test.runTest
|
||||
import org.junit.Assert.assertEquals
|
||||
import org.junit.Assert.assertNotEquals
|
||||
import org.junit.Before
|
||||
|
@ -81,15 +82,15 @@ class SemesterRepositoryTest {
|
|||
}
|
||||
|
||||
@Test
|
||||
fun getSemesters_invalidDiary_scrapper() {
|
||||
fun getSemesters_invalidDiary_scrapper() = runTest {
|
||||
val badSemesters = listOf(
|
||||
getSemesterPojo(0, 1, now().minusMonths(6), now().minusMonths(3)),
|
||||
getSemesterPojo(0, 2, now().minusMonths(3), now())
|
||||
getSemesterPojo(0, 2, now().minusMonths(6), now()),
|
||||
getSemesterPojo(0, 2, now(), now().plusMonths(6)),
|
||||
)
|
||||
|
||||
val goodSemesters = listOf(
|
||||
getSemesterPojo(1, 1, now().minusMonths(6), now().minusMonths(3)),
|
||||
getSemesterPojo(1, 2, now().minusMonths(3), now())
|
||||
getSemesterPojo(1, 2, now().minusMonths(6), now()),
|
||||
getSemesterPojo(2, 3, now(), now().plusMonths(6)),
|
||||
)
|
||||
|
||||
coEvery { semesterDb.loadAll(student.studentId, student.classId) } returnsMany listOf(
|
||||
|
@ -101,7 +102,9 @@ class SemesterRepositoryTest {
|
|||
coEvery { semesterDb.deleteAll(any()) } just Runs
|
||||
coEvery { semesterDb.insertSemesters(any()) } returns listOf()
|
||||
|
||||
val items = runBlocking { semesterRepository.getSemesters(student.copy(loginMode = Sdk.Mode.SCRAPPER.name)) }
|
||||
val items = semesterRepository.getSemesters(
|
||||
student = student.copy(loginMode = Sdk.Mode.SCRAPPER.name)
|
||||
)
|
||||
assertEquals(2, items.size)
|
||||
assertNotEquals(0, items[0].diaryId)
|
||||
}
|
||||
|
@ -188,15 +191,15 @@ class SemesterRepositoryTest {
|
|||
}
|
||||
|
||||
@Test
|
||||
fun getSemesters_doubleCurrent_refreshOnNoCurrent() {
|
||||
fun getSemesters_doubleCurrent_refreshOnNoCurrent() = runTest {
|
||||
val semesters = listOf(
|
||||
getSemesterEntity(1, 1, now(), now()),
|
||||
getSemesterEntity(1, 2, now(), now())
|
||||
getSemesterEntity(1, 1, now().minusMonths(1), now().plusMonths(1)),
|
||||
getSemesterEntity(1, 2, now().minusMonths(1), now().plusMonths(1))
|
||||
)
|
||||
|
||||
coEvery { semesterDb.loadAll(student.studentId, student.classId) } returns semesters
|
||||
|
||||
val items = runBlocking { semesterRepository.getSemesters(student, refreshOnNoCurrent = true) }
|
||||
val items = semesterRepository.getSemesters(student, refreshOnNoCurrent = true)
|
||||
assertEquals(2, items.size)
|
||||
}
|
||||
|
||||
|
|
|
@ -8,6 +8,40 @@ import kotlin.test.assertEquals
|
|||
|
||||
class SemesterExtensionKtTest {
|
||||
|
||||
@Test
|
||||
fun `check is first semester is current`() {
|
||||
val first = getSemesterEntity(
|
||||
semesterName = 1,
|
||||
start = LocalDate.of(2023, 9, 1),
|
||||
end = LocalDate.of(2024, 1, 31),
|
||||
)
|
||||
|
||||
// first boundary - school-year start
|
||||
assertEquals(false, first.isCurrent(LocalDate.of(2023, 8, 28)))
|
||||
assertEquals(true, first.isCurrent(LocalDate.of(2023, 8, 29)))
|
||||
|
||||
// second boundary
|
||||
assertEquals(true, first.isCurrent(LocalDate.of(2024, 1, 31)))
|
||||
assertEquals(false, first.isCurrent(LocalDate.of(2024, 2, 1)))
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `check is second semester is current`() {
|
||||
val second = getSemesterEntity(
|
||||
semesterName = 2,
|
||||
start = LocalDate.of(2024, 2, 1),
|
||||
end = LocalDate.of(2024, 9, 1),
|
||||
)
|
||||
|
||||
// first boundary
|
||||
assertEquals(false, second.isCurrent(LocalDate.of(2024, 1, 31)))
|
||||
assertEquals(true, second.isCurrent(LocalDate.of(2024, 2, 1)))
|
||||
|
||||
// second boundary - school-year end
|
||||
assertEquals(true, second.isCurrent(LocalDate.of(2024, 8, 29)))
|
||||
assertEquals(false, second.isCurrent(LocalDate.of(2024, 8, 30)))
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentException::class)
|
||||
fun `get current semester when current is doubled`() {
|
||||
val semesters = listOf(
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue