forked from github/wulkanowy-mirror
Block app timezone to polish timezone (#1598)
This commit is contained in:
parent
bfd7f688ab
commit
e6b2acabd5
61 changed files with 2870 additions and 400 deletions
|
@ -4,7 +4,7 @@ import io.github.wulkanowy.data.db.entities.Semester
|
|||
import io.github.wulkanowy.data.db.entities.Student
|
||||
import io.github.wulkanowy.sdk.Sdk
|
||||
import java.time.LocalDate
|
||||
import java.time.LocalDateTime.now
|
||||
import java.time.Instant.now
|
||||
import io.github.wulkanowy.sdk.pojo.Semester as SdkSemester
|
||||
|
||||
fun getSemesterEntity(diaryId: Int = 1, semesterId: Int = 1, start: LocalDate = LocalDate.now(), end: LocalDate = LocalDate.now(), semesterName: Int = 1) = Semester(
|
||||
|
|
|
@ -153,23 +153,25 @@ class Migration13Test : AbstractMigrationTest() {
|
|||
private fun getSemesters(db: SupportSQLiteDatabase, query: String): List<Pair<Semester, Boolean>> {
|
||||
val semesters = mutableListOf<Pair<Semester, Boolean>>()
|
||||
|
||||
val cursor = db.query(query)
|
||||
if (cursor.moveToFirst()) {
|
||||
do {
|
||||
semesters.add(Semester(
|
||||
studentId = cursor.getInt(1),
|
||||
diaryId = cursor.getInt(2),
|
||||
diaryName = cursor.getString(3),
|
||||
semesterId = cursor.getInt(4),
|
||||
semesterName = cursor.getInt(5),
|
||||
classId = cursor.getInt(7),
|
||||
unitId = cursor.getInt(8),
|
||||
schoolYear = cursor.getInt(9),
|
||||
start = Converters().timestampToDate(cursor.getLong(10))!!,
|
||||
end = Converters().timestampToDate(cursor.getLong(11))!!
|
||||
) to (cursor.getInt(6) == 1))
|
||||
} while (cursor.moveToNext())
|
||||
db.query(query).use {
|
||||
if (it.moveToFirst()) {
|
||||
do {
|
||||
semesters.add(Semester(
|
||||
studentId = it.getInt(1),
|
||||
diaryId = it.getInt(2),
|
||||
diaryName = it.getString(3),
|
||||
semesterId = it.getInt(4),
|
||||
semesterName = it.getInt(5),
|
||||
classId = it.getInt(7),
|
||||
unitId = it.getInt(8),
|
||||
schoolYear = it.getInt(9),
|
||||
start = Converters().timestampToLocalDate(it.getLong(10))!!,
|
||||
end = Converters().timestampToLocalDate(it.getLong(11))!!
|
||||
) to (it.getInt(6) == 1))
|
||||
} while (it.moveToNext())
|
||||
}
|
||||
}
|
||||
|
||||
return semesters.toList()
|
||||
}
|
||||
|
||||
|
|
|
@ -8,23 +8,17 @@ import io.github.wulkanowy.getStudentEntity
|
|||
import io.github.wulkanowy.sdk.Sdk
|
||||
import io.github.wulkanowy.utils.AutoRefreshHelper
|
||||
import io.github.wulkanowy.utils.toFirstResult
|
||||
import io.mockk.MockKAnnotations
|
||||
import io.mockk.Runs
|
||||
import io.mockk.coEvery
|
||||
import io.mockk.coVerify
|
||||
import io.mockk.every
|
||||
import io.mockk.*
|
||||
import io.mockk.impl.annotations.MockK
|
||||
import io.mockk.impl.annotations.SpyK
|
||||
import io.mockk.just
|
||||
import kotlinx.coroutines.flow.flowOf
|
||||
import kotlinx.coroutines.runBlocking
|
||||
import org.junit.Assert.assertEquals
|
||||
import org.junit.Assert.assertFalse
|
||||
import org.junit.Assert.assertTrue
|
||||
import org.junit.Assert.*
|
||||
import org.junit.Before
|
||||
import org.junit.Test
|
||||
import java.time.LocalDate
|
||||
import java.time.LocalDate.of
|
||||
import java.time.ZoneOffset
|
||||
import io.github.wulkanowy.sdk.pojo.Grade as SdkGrade
|
||||
|
||||
class GradeRepositoryTest {
|
||||
|
@ -57,7 +51,11 @@ class GradeRepositoryTest {
|
|||
coEvery { gradeDb.deleteAll(any()) } just Runs
|
||||
coEvery { gradeDb.insertAll(any()) } returns listOf()
|
||||
|
||||
coEvery { gradeSummaryDb.loadAll(1, 1) } returnsMany listOf(flowOf(listOf()), flowOf(listOf()), flowOf(listOf()))
|
||||
coEvery { gradeSummaryDb.loadAll(1, 1) } returnsMany listOf(
|
||||
flowOf(listOf()),
|
||||
flowOf(listOf()),
|
||||
flowOf(listOf())
|
||||
)
|
||||
coEvery { gradeSummaryDb.deleteAll(any()) } just Runs
|
||||
coEvery { gradeSummaryDb.insertAll(any()) } returns listOf()
|
||||
}
|
||||
|
@ -65,7 +63,7 @@ class GradeRepositoryTest {
|
|||
@Test
|
||||
fun `mark grades older than registration date as read`() {
|
||||
// prepare
|
||||
val boundaryDate = of(2019, 2, 27).atStartOfDay()
|
||||
val boundaryDate = of(2019, 2, 27).atStartOfDay().toInstant(ZoneOffset.UTC)
|
||||
val remoteList = listOf(
|
||||
createGradeApi(5, 4.0, of(2019, 2, 25), "Ocena pojawiła się"),
|
||||
createGradeApi(5, 4.0, of(2019, 2, 26), "przed zalogowanie w aplikacji"),
|
||||
|
@ -81,7 +79,13 @@ class GradeRepositoryTest {
|
|||
)
|
||||
|
||||
// execute
|
||||
val res = runBlocking { gradeRepository.getGrades(student.copy(registrationDate = boundaryDate), semester, true).toFirstResult() }
|
||||
val res = runBlocking {
|
||||
gradeRepository.getGrades(
|
||||
student = student.copy(registrationDate = boundaryDate),
|
||||
semester = semester,
|
||||
forceRefresh = true
|
||||
).toFirstResult()
|
||||
}
|
||||
|
||||
// verify
|
||||
assertEquals(null, res.error)
|
||||
|
@ -101,9 +105,19 @@ class GradeRepositoryTest {
|
|||
fun `mitigate mark grades as unread when old grades changed`() {
|
||||
// prepare
|
||||
val remoteList = listOf(
|
||||
createGradeApi(5, 2.0, of(2019, 2, 25), "Ocena ma datę, jest inna, ale nie zostanie powiadomiona"),
|
||||
createGradeApi(
|
||||
5,
|
||||
2.0,
|
||||
of(2019, 2, 25),
|
||||
"Ocena ma datę, jest inna, ale nie zostanie powiadomiona"
|
||||
),
|
||||
createGradeApi(4, 3.0, of(2019, 2, 26), "starszą niż ostatnia lokalnie"),
|
||||
createGradeApi(3, 4.0, of(2019, 2, 27), "Ta jest z tego samego dnia co ostatnia lokalnie"),
|
||||
createGradeApi(
|
||||
3,
|
||||
4.0,
|
||||
of(2019, 2, 27),
|
||||
"Ta jest z tego samego dnia co ostatnia lokalnie"
|
||||
),
|
||||
createGradeApi(2, 5.0, of(2019, 2, 28), "Ta jest już w ogóle nowa")
|
||||
)
|
||||
coEvery { sdk.getGrades(1) } returns (remoteList to emptyList())
|
||||
|
@ -111,7 +125,12 @@ class GradeRepositoryTest {
|
|||
val localList = listOf(
|
||||
createGradeApi(5, 3.0, of(2019, 2, 25), "Jedna ocena"),
|
||||
createGradeApi(4, 4.0, of(2019, 2, 26), "Druga"),
|
||||
createGradeApi(3, 4.0, of(2019, 2, 27), "Ta jest z tego samego dnia co ostatnia lokalnie")
|
||||
createGradeApi(
|
||||
3,
|
||||
4.0,
|
||||
of(2019, 2, 27),
|
||||
"Ta jest z tego samego dnia co ostatnia lokalnie"
|
||||
)
|
||||
)
|
||||
coEvery { gradeDb.loadAll(1, 1) } returnsMany listOf(
|
||||
flowOf(localList.mapToEntities(semester)),
|
||||
|
@ -248,18 +267,19 @@ class GradeRepositoryTest {
|
|||
assertEquals(0, res.data?.first?.size)
|
||||
}
|
||||
|
||||
private fun createGradeApi(value: Int, weight: Double, date: LocalDate, desc: String) = SdkGrade(
|
||||
subject = "",
|
||||
color = "",
|
||||
comment = "",
|
||||
date = date,
|
||||
description = desc,
|
||||
entry = "",
|
||||
modifier = .0,
|
||||
symbol = "",
|
||||
teacher = "",
|
||||
value = value.toDouble(),
|
||||
weight = weight.toString(),
|
||||
weightValue = weight
|
||||
)
|
||||
private fun createGradeApi(value: Int, weight: Double, date: LocalDate, desc: String) =
|
||||
SdkGrade(
|
||||
subject = "",
|
||||
color = "",
|
||||
comment = "",
|
||||
date = date,
|
||||
description = desc,
|
||||
entry = "",
|
||||
modifier = .0,
|
||||
symbol = "",
|
||||
teacher = "",
|
||||
value = value.toDouble(),
|
||||
weight = weight.toString(),
|
||||
weightValue = weight
|
||||
)
|
||||
}
|
||||
|
|
|
@ -16,27 +16,25 @@ import io.github.wulkanowy.sdk.pojo.MessageDetails
|
|||
import io.github.wulkanowy.sdk.pojo.Sender
|
||||
import io.github.wulkanowy.utils.AutoRefreshHelper
|
||||
import io.github.wulkanowy.utils.toFirstResult
|
||||
import io.mockk.MockKAnnotations
|
||||
import io.mockk.Runs
|
||||
import io.mockk.checkEquals
|
||||
import io.mockk.coEvery
|
||||
import io.mockk.coVerify
|
||||
import io.mockk.every
|
||||
import io.mockk.*
|
||||
import io.mockk.impl.annotations.MockK
|
||||
import io.mockk.impl.annotations.SpyK
|
||||
import io.mockk.just
|
||||
import kotlinx.coroutines.ExperimentalCoroutinesApi
|
||||
import kotlinx.coroutines.flow.flow
|
||||
import kotlinx.coroutines.flow.flowOf
|
||||
import kotlinx.coroutines.flow.toList
|
||||
import kotlinx.coroutines.runBlocking
|
||||
import kotlinx.coroutines.test.runTest
|
||||
import kotlinx.serialization.json.Json
|
||||
import org.junit.Assert.assertEquals
|
||||
import org.junit.Before
|
||||
import org.junit.Test
|
||||
import java.net.UnknownHostException
|
||||
import java.time.LocalDateTime
|
||||
import java.time.Instant
|
||||
import java.time.ZoneOffset
|
||||
import kotlin.test.assertTrue
|
||||
|
||||
@OptIn(ExperimentalCoroutinesApi::class)
|
||||
class MessageRepositoryTest {
|
||||
|
||||
@SpyK
|
||||
|
@ -80,7 +78,7 @@ class MessageRepositoryTest {
|
|||
}
|
||||
|
||||
@Test
|
||||
fun `get messages when read by values was changed on already read message`() = runBlocking {
|
||||
fun `get messages when read by values was changed on already read message`() = runTest {
|
||||
every { messageDb.loadAll(any(), any()) } returns flow {
|
||||
val dbMessage = getMessageEntity(3, "", false).apply {
|
||||
unreadBy = 10
|
||||
|
@ -239,7 +237,7 @@ class MessageRepositoryTest {
|
|||
senderId = 0,
|
||||
recipient = "Wielu adresatów",
|
||||
subject = "",
|
||||
date = LocalDateTime.MAX,
|
||||
date = Instant.EPOCH,
|
||||
folderId = 1,
|
||||
unread = unread,
|
||||
removed = false,
|
||||
|
@ -261,7 +259,8 @@ class MessageRepositoryTest {
|
|||
recipients = listOf(),
|
||||
subject = "",
|
||||
content = content,
|
||||
date = LocalDateTime.MAX,
|
||||
date = Instant.EPOCH.atZone(ZoneOffset.UTC).toLocalDateTime(),
|
||||
dateZoned = Instant.EPOCH.atZone(ZoneOffset.UTC),
|
||||
folderId = 1,
|
||||
unread = unread,
|
||||
unreadBy = 0,
|
||||
|
|
|
@ -22,6 +22,7 @@ import org.junit.Assert
|
|||
import org.junit.Before
|
||||
import org.junit.Test
|
||||
import java.time.LocalDateTime.of
|
||||
import java.time.ZoneId
|
||||
|
||||
class MobileDeviceRepositoryTest {
|
||||
|
||||
|
@ -137,6 +138,8 @@ class MobileDeviceRepositoryTest {
|
|||
name = "",
|
||||
deviceId = "",
|
||||
createDate = of(2019, 5, day, 0, 0, 0),
|
||||
modificationDate = of(2019, 5, day, 0, 0, 0)
|
||||
modificationDate = of(2019, 5, day, 0, 0, 0),
|
||||
createDateZoned = of(2019, 5, day, 0, 0, 0).atZone(ZoneId.systemDefault()),
|
||||
modificationDateZoned = of(2019, 5, day, 0, 0, 0).atZone(ZoneId.systemDefault())
|
||||
)
|
||||
}
|
||||
|
|
|
@ -27,6 +27,7 @@ import org.junit.Test
|
|||
import java.time.LocalDate
|
||||
import java.time.LocalDateTime
|
||||
import java.time.LocalDateTime.of
|
||||
import java.time.ZoneId
|
||||
import io.github.wulkanowy.sdk.pojo.Timetable as SdkTimetable
|
||||
|
||||
class TimetableRepositoryTest {
|
||||
|
@ -107,6 +108,8 @@ class TimetableRepositoryTest {
|
|||
number = number,
|
||||
start = start,
|
||||
end = start.plusMinutes(45),
|
||||
startZoned = start.atZone(ZoneId.systemDefault()),
|
||||
endZoned = start.plusMinutes(45).atZone(ZoneId.systemDefault()),
|
||||
date = start.toLocalDate(),
|
||||
subject = subject,
|
||||
group = "",
|
||||
|
|
|
@ -23,9 +23,9 @@ import kotlinx.coroutines.runBlocking
|
|||
import org.junit.Assert.assertEquals
|
||||
import org.junit.Before
|
||||
import org.junit.Test
|
||||
import java.time.Instant
|
||||
import java.time.LocalDate.now
|
||||
import java.time.LocalDate.of
|
||||
import java.time.LocalDateTime
|
||||
|
||||
class GradeAverageProviderTest {
|
||||
|
||||
|
@ -63,7 +63,7 @@ class GradeAverageProviderTest {
|
|||
className = "",
|
||||
classId = 1,
|
||||
isCurrent = true,
|
||||
registrationDate = LocalDateTime.now()
|
||||
registrationDate = Instant.now()
|
||||
)
|
||||
|
||||
private val semesters = mutableListOf(
|
||||
|
|
|
@ -6,18 +6,13 @@ import io.github.wulkanowy.data.db.entities.StudentWithSemesters
|
|||
import io.github.wulkanowy.data.repositories.StudentRepository
|
||||
import io.github.wulkanowy.ui.modules.login.LoginErrorHandler
|
||||
import io.github.wulkanowy.utils.AnalyticsHelper
|
||||
import io.mockk.MockKAnnotations
|
||||
import io.mockk.Runs
|
||||
import io.mockk.coEvery
|
||||
import io.mockk.every
|
||||
import io.mockk.*
|
||||
import io.mockk.impl.annotations.MockK
|
||||
import io.mockk.just
|
||||
import io.mockk.verify
|
||||
import org.junit.Before
|
||||
import org.junit.Rule
|
||||
import org.junit.Test
|
||||
import java.io.IOException
|
||||
import java.time.LocalDateTime.now
|
||||
import java.time.Instant
|
||||
|
||||
class LoginFormPresenterTest {
|
||||
|
||||
|
@ -121,7 +116,7 @@ class LoginFormPresenterTest {
|
|||
classId = 1,
|
||||
isCurrent = false,
|
||||
symbol = "",
|
||||
registrationDate = now(),
|
||||
registrationDate = Instant.now(),
|
||||
className = "",
|
||||
mobileBaseUrl = "",
|
||||
privateKey = "",
|
||||
|
|
|
@ -7,18 +7,12 @@ import io.github.wulkanowy.data.repositories.StudentRepository
|
|||
import io.github.wulkanowy.services.sync.SyncManager
|
||||
import io.github.wulkanowy.ui.modules.login.LoginErrorHandler
|
||||
import io.github.wulkanowy.utils.AnalyticsHelper
|
||||
import io.mockk.MockKAnnotations
|
||||
import io.mockk.Runs
|
||||
import io.mockk.clearMocks
|
||||
import io.mockk.coEvery
|
||||
import io.mockk.every
|
||||
import io.mockk.*
|
||||
import io.mockk.impl.annotations.MockK
|
||||
import io.mockk.just
|
||||
import io.mockk.verify
|
||||
import org.junit.Before
|
||||
import org.junit.Rule
|
||||
import org.junit.Test
|
||||
import java.time.LocalDateTime.now
|
||||
import java.time.Instant
|
||||
|
||||
class LoginStudentSelectPresenterTest {
|
||||
|
||||
|
@ -55,7 +49,7 @@ class LoginStudentSelectPresenterTest {
|
|||
schoolSymbol = "",
|
||||
classId = 1,
|
||||
studentName = "",
|
||||
registrationDate = now(),
|
||||
registrationDate = Instant.now(),
|
||||
className = "",
|
||||
loginMode = "",
|
||||
certificateKey = "",
|
||||
|
|
|
@ -1,14 +1,13 @@
|
|||
package io.github.wulkanowy.utils
|
||||
|
||||
import org.junit.Assert.assertEquals
|
||||
import org.junit.Assert.assertFalse
|
||||
import org.junit.Assert.assertTrue
|
||||
import org.junit.Assert.*
|
||||
import org.junit.Test
|
||||
import java.time.Instant
|
||||
import java.time.LocalDate.of
|
||||
import java.time.LocalDateTime
|
||||
import java.time.Month.JANUARY
|
||||
import java.time.ZoneOffset
|
||||
import java.util.Locale
|
||||
import java.util.*
|
||||
|
||||
class TimeExtensionTest {
|
||||
|
||||
|
@ -24,11 +23,15 @@ class TimeExtensionTest {
|
|||
}
|
||||
|
||||
@Test
|
||||
fun toFormattedStringLocalDateTimeTest() {
|
||||
assertEquals("01.10.2018", LocalDateTime.of(2018, 10, 1, 10, 0, 0).toFormattedString())
|
||||
fun toFormattedStringFromInstantTest() {
|
||||
assertEquals(
|
||||
"01.10.2018",
|
||||
LocalDateTime.of(2018, 10, 1, 10, 0, 0).toInstant(ZoneOffset.UTC).toFormattedString()
|
||||
)
|
||||
assertEquals(
|
||||
"2018-10-01 10:00:00",
|
||||
LocalDateTime.of(2018, 10, 1, 10, 0, 0).toFormattedString("uuuu-MM-dd HH:mm:ss")
|
||||
LocalDateTime.of(2018, 10, 1, 10, 0, 0).toInstant(ZoneOffset.UTC)
|
||||
.toFormattedString("uuuu-MM-dd HH:mm:ss", ZoneOffset.UTC)
|
||||
)
|
||||
}
|
||||
|
||||
|
@ -228,16 +231,23 @@ class TimeExtensionTest {
|
|||
}
|
||||
|
||||
@Test
|
||||
fun getLocalDateToTimestampUTC() {
|
||||
assertEquals(0L, of(1970, 1, 1).toTimestamp(ZoneOffset.UTC))
|
||||
assertEquals(946684800000L, of(2000, 1, 1).toTimestamp(ZoneOffset.UTC))
|
||||
assertEquals(1640131200000L, of(2021, 12, 22).toTimestamp(ZoneOffset.UTC))
|
||||
fun getLocalDateToTimestamp() {
|
||||
assertEquals(0L, of(1970, 1, 1).toTimestamp())
|
||||
assertEquals(946684800000L, of(2000, 1, 1).toTimestamp())
|
||||
assertEquals(1640131200000L, of(2021, 12, 22).toTimestamp())
|
||||
}
|
||||
|
||||
@Test
|
||||
fun getLocalDateTimeToUtcTimestamp() {
|
||||
assertEquals(0L, LocalDateTime.of(1970, 1, 1, 0, 0, 0).toTimestamp(ZoneOffset.UTC))
|
||||
assertEquals(946684800000L, LocalDateTime.of(2000, 1, 1, 0, 0, 0).toTimestamp(ZoneOffset.UTC))
|
||||
assertEquals(1640131200000L, LocalDateTime.of(2021, 12, 22, 0, 0, 0).toTimestamp(ZoneOffset.UTC))
|
||||
fun getLocalDateFromInstant() {
|
||||
assertEquals(of(1970, 1, 1), Instant.ofEpochMilli(0).toLocalDate())
|
||||
assertEquals(of(2000, 1, 1), Instant.ofEpochMilli(946684800000).toLocalDate())
|
||||
assertEquals(of(2021, 12, 22), Instant.ofEpochMilli(1640131200000L).toLocalDate())
|
||||
}
|
||||
|
||||
@Test
|
||||
fun timestampToLocalDateTime() {
|
||||
assertEquals(LocalDateTime.of(1970, 1, 1, 0, 0, 0), 0L.toLocalDateTime())
|
||||
assertEquals(LocalDateTime.of(2000, 1, 1, 0, 0, 0), 946684800000.toLocalDateTime())
|
||||
assertEquals(LocalDateTime.of(2021, 12, 22, 0, 0, 0), 1640131200000L.toLocalDateTime())
|
||||
}
|
||||
}
|
||||
|
|
|
@ -6,9 +6,8 @@ import org.junit.Assert.assertFalse
|
|||
import org.junit.Assert.assertNotEquals
|
||||
import org.junit.Assert.assertTrue
|
||||
import org.junit.Test
|
||||
import java.time.LocalDate
|
||||
import java.time.LocalDateTime
|
||||
import java.time.LocalDateTime.now
|
||||
import java.time.*
|
||||
import java.time.Duration.ofMinutes
|
||||
|
||||
class TimetableExtensionTest {
|
||||
|
||||
|
@ -17,52 +16,38 @@ class TimetableExtensionTest {
|
|||
assertFalse(getTimetableEntity().isShowTimeUntil(null))
|
||||
assertFalse(getTimetableEntity(isStudentPlan = false).isShowTimeUntil(null))
|
||||
assertFalse(getTimetableEntity(isStudentPlan = true, canceled = true).isShowTimeUntil(null))
|
||||
assertFalse(getTimetableEntity(isStudentPlan = true, canceled = false, start = now().minusSeconds(1)).isShowTimeUntil(null))
|
||||
assertFalse(getTimetableEntity(isStudentPlan = true, canceled = false, start = now().plusMinutes(5)).isShowTimeUntil(now().plusMinutes(5)))
|
||||
assertFalse(getTimetableEntity(isStudentPlan = true, canceled = false, start = now().plusMinutes(61)).isShowTimeUntil(now().minusMinutes(5)))
|
||||
assertFalse(getTimetableEntity(isStudentPlan = true, canceled = false, start = Instant.now().minusSeconds(1)).isShowTimeUntil(null))
|
||||
assertFalse(getTimetableEntity(isStudentPlan = true, canceled = false, start = Instant.now().plus(ofMinutes(5))).isShowTimeUntil(Instant.now().plus(ofMinutes(5))))
|
||||
assertFalse(getTimetableEntity(isStudentPlan = true, canceled = false, start = Instant.now().plus(ofMinutes(61))).isShowTimeUntil(Instant.now().minus(ofMinutes(5))))
|
||||
|
||||
assertTrue(getTimetableEntity(isStudentPlan = true, canceled = false, start = now().plusMinutes(60)).isShowTimeUntil(now().minusMinutes(5)))
|
||||
assertTrue(getTimetableEntity(isStudentPlan = true, canceled = false, start = now().plusMinutes(60)).isShowTimeUntil(null))
|
||||
assertTrue(getTimetableEntity(isStudentPlan = true, canceled = false, start = Instant.now().plus(ofMinutes(60))).isShowTimeUntil(Instant.now().minus(ofMinutes(5))))
|
||||
assertTrue(getTimetableEntity(isStudentPlan = true, canceled = false, start = Instant.now().plus(ofMinutes(60))).isShowTimeUntil(null))
|
||||
|
||||
assertFalse(getTimetableEntity(isStudentPlan = true, canceled = false, start = now().minusSeconds(1)).isShowTimeUntil(null))
|
||||
assertFalse(getTimetableEntity(isStudentPlan = true, canceled = false, start = Instant.now().minusSeconds(1)).isShowTimeUntil(null))
|
||||
}
|
||||
|
||||
@Test
|
||||
fun getLeft() {
|
||||
assertEquals(null, getTimetableEntity(canceled = true).left)
|
||||
assertEquals(null, getTimetableEntity(start = now().plusMinutes(5), end = now().plusMinutes(50)).left)
|
||||
assertEquals(null, getTimetableEntity(start = now().minusMinutes(1), end = now().plusMinutes(44), isStudentPlan = false).left)
|
||||
assertNotEquals(
|
||||
null,
|
||||
getTimetableEntity(
|
||||
start = now().minusMinutes(1),
|
||||
end = now().plusMinutes(44),
|
||||
isStudentPlan = true
|
||||
).left
|
||||
)
|
||||
assertNotEquals(
|
||||
null,
|
||||
getTimetableEntity(
|
||||
start = now(),
|
||||
end = now().plusMinutes(45),
|
||||
isStudentPlan = true
|
||||
).left
|
||||
)
|
||||
assertEquals(null, getTimetableEntity(start = Instant.now().plus(ofMinutes(5)), end = Instant.now().plus(ofMinutes(50))).left)
|
||||
assertEquals(null, getTimetableEntity(start = Instant.now().minus(ofMinutes(1)), end = Instant.now().plus(ofMinutes(44)), isStudentPlan = false).left)
|
||||
assertNotEquals(null, getTimetableEntity(start = Instant.now().minus(ofMinutes(1)), end = Instant.now().plus(ofMinutes(44)), isStudentPlan = true).left)
|
||||
assertNotEquals(null, getTimetableEntity(start = Instant.now(), end = Instant.now().plus(ofMinutes(45)), isStudentPlan = true).left)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun isJustFinished() {
|
||||
assertFalse(getTimetableEntity(end = now().minusSeconds(16)).isJustFinished)
|
||||
assertTrue(getTimetableEntity(end = now().minusSeconds(14)).isJustFinished)
|
||||
assertTrue(getTimetableEntity(end = now().minusSeconds(1)).isJustFinished)
|
||||
assertFalse(getTimetableEntity(end = now().plusSeconds(1)).isJustFinished)
|
||||
assertFalse(getTimetableEntity(end = Instant.now().minusSeconds(16)).isJustFinished)
|
||||
assertTrue(getTimetableEntity(end = Instant.now().minusSeconds(14)).isJustFinished)
|
||||
assertTrue(getTimetableEntity(end = Instant.now().minusSeconds(1)).isJustFinished)
|
||||
assertFalse(getTimetableEntity(end = Instant.now().plusSeconds(1)).isJustFinished)
|
||||
}
|
||||
|
||||
private fun getTimetableEntity(
|
||||
isStudentPlan: Boolean = false,
|
||||
canceled: Boolean = false,
|
||||
start: LocalDateTime = now(),
|
||||
end: LocalDateTime = now()
|
||||
start: Instant = Instant.now(),
|
||||
end: Instant = Instant.now()
|
||||
) = Timetable(
|
||||
studentId = 0,
|
||||
subject = "",
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue