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.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(
|
||||
messageGlobalKey = it.globalKey,
|
||||
mailboxKey = mailbox?.globalKey ?: allMailboxes.find { box ->
|
||||
|
@ -21,6 +21,8 @@ class GetMailboxByStudentUseCase @Inject constructor(
|
||||
it.studentName.normalizeStudentName() == normalizedStudentName
|
||||
} ?: singleOrNull {
|
||||
it.studentName.getFirstAndLastPart() == normalizedStudentName.getFirstAndLastPart()
|
||||
} ?: singleOrNull {
|
||||
it.studentName.getReversedName() == normalizedStudentName
|
||||
} ?: singleOrNull {
|
||||
it.studentName.getUnauthorizedVersion() == normalizedStudentName
|
||||
}
|
||||
@ -43,6 +45,14 @@ class GetMailboxByStudentUseCase @Inject constructor(
|
||||
return endParts.joinToString(" ")
|
||||
}
|
||||
|
||||
private fun String.getReversedName(): String {
|
||||
val parts = normalizeStudentName().split(" ")
|
||||
|
||||
return parts
|
||||
.asReversed()
|
||||
.joinToString(" ")
|
||||
}
|
||||
|
||||
private fun String.getUnauthorizedVersion(): String {
|
||||
return normalizeStudentName().split(" ")
|
||||
.joinToString(" ") {
|
||||
|
@ -64,6 +64,18 @@ class GetMailboxByStudentUseCaseTest {
|
||||
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
|
||||
fun `get mailbox for unique non-authorized student`() = runTest {
|
||||
val student = getStudentEntity(
|
||||
|
Loading…
x
Reference in New Issue
Block a user