mirror of
https://github.com/wulkanowy/wulkanowy.git
synced 2025-01-19 00:06:46 -06:00
Automatically show current student mailbox only when there is only one mailbox available (#2085)
* Automatically show current student mailbox only when there is only one mailbox for this student available * Fallback to 'unknown' mailbox key if there is no matching mailbox to message
This commit is contained in:
parent
345b580601
commit
aa3d7e37fc
@ -2,6 +2,7 @@ package io.github.wulkanowy.data.mappers
|
|||||||
|
|
||||||
import io.github.wulkanowy.data.db.entities.*
|
import io.github.wulkanowy.data.db.entities.*
|
||||||
import io.github.wulkanowy.sdk.pojo.MailboxType
|
import io.github.wulkanowy.sdk.pojo.MailboxType
|
||||||
|
import timber.log.Timber
|
||||||
import io.github.wulkanowy.sdk.pojo.Message as SdkMessage
|
import io.github.wulkanowy.sdk.pojo.Message as SdkMessage
|
||||||
import io.github.wulkanowy.sdk.pojo.MessageAttachment as SdkMessageAttachment
|
import io.github.wulkanowy.sdk.pojo.MessageAttachment as SdkMessageAttachment
|
||||||
import io.github.wulkanowy.sdk.pojo.Recipient as SdkRecipient
|
import io.github.wulkanowy.sdk.pojo.Recipient as SdkRecipient
|
||||||
@ -16,7 +17,10 @@ fun List<SdkMessage>.mapToEntities(
|
|||||||
mailboxKey = mailbox?.globalKey ?: allMailboxes.find { box ->
|
mailboxKey = mailbox?.globalKey ?: allMailboxes.find { box ->
|
||||||
box.fullName == it.mailbox
|
box.fullName == it.mailbox
|
||||||
}?.globalKey.let { mailboxKey ->
|
}?.globalKey.let { mailboxKey ->
|
||||||
requireNotNull(mailboxKey) { "Can't find ${it.mailbox} in $allMailboxes" }
|
if (mailboxKey == null) {
|
||||||
|
Timber.e("Can't find ${it.mailbox} in $allMailboxes")
|
||||||
|
"unknown"
|
||||||
|
} else mailboxKey
|
||||||
},
|
},
|
||||||
email = student.email,
|
email = student.email,
|
||||||
messageId = it.id,
|
messageId = it.id,
|
||||||
|
@ -17,8 +17,11 @@ class GetMailboxByStudentUseCase @Inject constructor(
|
|||||||
private fun List<Mailbox>.filterByStudent(student: Student): Mailbox? {
|
private fun List<Mailbox>.filterByStudent(student: Student): Mailbox? {
|
||||||
val normalizedStudentName = student.studentName.normalizeStudentName()
|
val normalizedStudentName = student.studentName.normalizeStudentName()
|
||||||
|
|
||||||
return find {
|
return singleOrNull {
|
||||||
it.studentName.normalizeStudentName() == normalizedStudentName
|
it.studentName.normalizeStudentName() == normalizedStudentName
|
||||||
|
} ?: singleOrNull {
|
||||||
|
it.studentName.normalizeStudentName() == normalizedStudentName
|
||||||
|
&& it.schoolNameShort == student.schoolShortName
|
||||||
} ?: singleOrNull {
|
} ?: singleOrNull {
|
||||||
it.studentName.getFirstAndLastPart() == normalizedStudentName.getFirstAndLastPart()
|
it.studentName.getFirstAndLastPart() == normalizedStudentName.getFirstAndLastPart()
|
||||||
} ?: singleOrNull {
|
} ?: singleOrNull {
|
||||||
|
@ -160,8 +160,29 @@ class GetMailboxByStudentUseCaseTest {
|
|||||||
assertEquals(expectedMailbox, systemUnderTest(student))
|
assertEquals(expectedMailbox, systemUnderTest(student))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun `get mailbox for student with mailboxes from two different schools`() = runTest {
|
||||||
|
val student = getStudentEntity(
|
||||||
|
userName = "Kamil Bednarek",
|
||||||
|
studentName = "Kamil Bednarek",
|
||||||
|
schoolShortName = "CKZiU",
|
||||||
|
)
|
||||||
|
val mailbox1 = getMailboxEntity(
|
||||||
|
studentName = "Kamil Bednarek",
|
||||||
|
schoolShortName = "ZSTiO",
|
||||||
|
)
|
||||||
|
val mailbox2 = getMailboxEntity(
|
||||||
|
studentName = "Kamil Bednarek",
|
||||||
|
schoolShortName = "CKZiU",
|
||||||
|
)
|
||||||
|
coEvery { mailboxDao.loadAll(any()) } returns listOf(mailbox1, mailbox2)
|
||||||
|
|
||||||
|
assertEquals(mailbox2, systemUnderTest(student))
|
||||||
|
}
|
||||||
|
|
||||||
private fun getMailboxEntity(
|
private fun getMailboxEntity(
|
||||||
studentName: String,
|
studentName: String,
|
||||||
|
schoolShortName: String = "test",
|
||||||
) = Mailbox(
|
) = Mailbox(
|
||||||
globalKey = "",
|
globalKey = "",
|
||||||
fullName = "",
|
fullName = "",
|
||||||
@ -170,13 +191,14 @@ class GetMailboxByStudentUseCaseTest {
|
|||||||
schoolId = "",
|
schoolId = "",
|
||||||
symbol = "",
|
symbol = "",
|
||||||
studentName = studentName,
|
studentName = studentName,
|
||||||
schoolNameShort = "",
|
schoolNameShort = schoolShortName,
|
||||||
type = MailboxType.STUDENT,
|
type = MailboxType.STUDENT,
|
||||||
)
|
)
|
||||||
|
|
||||||
private fun getStudentEntity(
|
private fun getStudentEntity(
|
||||||
studentName: String,
|
studentName: String,
|
||||||
userName: String,
|
userName: String,
|
||||||
|
schoolShortName: String = "test",
|
||||||
) = Student(
|
) = Student(
|
||||||
scrapperBaseUrl = "http://fakelog.cf",
|
scrapperBaseUrl = "http://fakelog.cf",
|
||||||
email = "jan@fakelog.cf",
|
email = "jan@fakelog.cf",
|
||||||
@ -192,7 +214,7 @@ class GetMailboxByStudentUseCaseTest {
|
|||||||
privateKey = "",
|
privateKey = "",
|
||||||
registrationDate = Instant.now(),
|
registrationDate = Instant.now(),
|
||||||
schoolName = "",
|
schoolName = "",
|
||||||
schoolShortName = "test",
|
schoolShortName = schoolShortName,
|
||||||
schoolSymbol = "",
|
schoolSymbol = "",
|
||||||
studentId = 1,
|
studentId = 1,
|
||||||
studentName = studentName,
|
studentName = studentName,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user