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:
Mikołaj Pich 2022-11-19 08:52:35 +01:00 committed by GitHub
parent 6c115fb915
commit b160367744
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 23 additions and 1 deletions

View File

@ -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 ->

View File

@ -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(" ") {

View File

@ -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(