forked from github/wulkanowy-mirror
Add support for reversed student name mailbox matching (#2051)
* Add support for reversed student name mailbox matching * Add additional log stmt to mailbox matching in all mailbox load * Revert changes in mapper
This commit is contained in:
parent
6c115fb915
commit
b160367744
@ -6,7 +6,7 @@ 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
|
||||||
|
|
||||||
fun List<SdkMessage>.mapToEntities(student: Student, mailbox: Mailbox?, allMailboxes: List<Mailbox>) = map {
|
fun List<SdkMessage>.mapToEntities(student: Student, mailbox: Mailbox?, allMailboxes: List<Mailbox>): List<Message> = map {
|
||||||
Message(
|
Message(
|
||||||
messageGlobalKey = it.globalKey,
|
messageGlobalKey = it.globalKey,
|
||||||
mailboxKey = mailbox?.globalKey ?: allMailboxes.find { box ->
|
mailboxKey = mailbox?.globalKey ?: allMailboxes.find { box ->
|
||||||
|
@ -21,6 +21,8 @@ class GetMailboxByStudentUseCase @Inject constructor(
|
|||||||
it.studentName.normalizeStudentName() == normalizedStudentName
|
it.studentName.normalizeStudentName() == normalizedStudentName
|
||||||
} ?: singleOrNull {
|
} ?: singleOrNull {
|
||||||
it.studentName.getFirstAndLastPart() == normalizedStudentName.getFirstAndLastPart()
|
it.studentName.getFirstAndLastPart() == normalizedStudentName.getFirstAndLastPart()
|
||||||
|
} ?: singleOrNull {
|
||||||
|
it.studentName.getReversedName() == normalizedStudentName
|
||||||
} ?: singleOrNull {
|
} ?: singleOrNull {
|
||||||
it.studentName.getUnauthorizedVersion() == normalizedStudentName
|
it.studentName.getUnauthorizedVersion() == normalizedStudentName
|
||||||
}
|
}
|
||||||
@ -43,6 +45,14 @@ class GetMailboxByStudentUseCase @Inject constructor(
|
|||||||
return endParts.joinToString(" ")
|
return endParts.joinToString(" ")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private fun String.getReversedName(): String {
|
||||||
|
val parts = normalizeStudentName().split(" ")
|
||||||
|
|
||||||
|
return parts
|
||||||
|
.asReversed()
|
||||||
|
.joinToString(" ")
|
||||||
|
}
|
||||||
|
|
||||||
private fun String.getUnauthorizedVersion(): String {
|
private fun String.getUnauthorizedVersion(): String {
|
||||||
return normalizeStudentName().split(" ")
|
return normalizeStudentName().split(" ")
|
||||||
.joinToString(" ") {
|
.joinToString(" ") {
|
||||||
|
@ -64,6 +64,18 @@ class GetMailboxByStudentUseCaseTest {
|
|||||||
assertEquals(expectedMailbox, selectedMailbox)
|
assertEquals(expectedMailbox, selectedMailbox)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun `get mailbox for user with reversed name`() = runTest {
|
||||||
|
val student = getStudentEntity(
|
||||||
|
userName = "Kowalski Jan",
|
||||||
|
studentName = "Jan Kowalski",
|
||||||
|
)
|
||||||
|
val expectedMailbox = getMailboxEntity("Kowalski Jan")
|
||||||
|
coEvery { mailboxDao.loadAll(any()) } returns listOf(expectedMailbox)
|
||||||
|
|
||||||
|
assertEquals(expectedMailbox, systemUnderTest(student))
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun `get mailbox for unique non-authorized student`() = runTest {
|
fun `get mailbox for unique non-authorized student`() = runTest {
|
||||||
val student = getStudentEntity(
|
val student = getStudentEntity(
|
||||||
|
Loading…
x
Reference in New Issue
Block a user