forked from github/wulkanowy-mirror
Fix matching mailboxes when there is more than one space between words (#1964)
This commit is contained in:
parent
83ca9a7060
commit
157becb017
@ -186,7 +186,7 @@ ext {
|
||||
}
|
||||
|
||||
dependencies {
|
||||
implementation "io.github.wulkanowy:sdk:1.7.4"
|
||||
implementation "io.github.wulkanowy:sdk:dcd8bd8b19"
|
||||
|
||||
coreLibraryDesugaring 'com.android.tools:desugar_jdk_libs:1.1.8'
|
||||
|
||||
|
@ -60,16 +60,18 @@ class MailboxRepository @Inject constructor(
|
||||
}
|
||||
|
||||
private fun String.normalizeStudentName(): String {
|
||||
return trim().split(" ").joinToString(" ") { part ->
|
||||
part.lowercase().replaceFirstChar { it.uppercase() }
|
||||
}
|
||||
return trim().split(" ")
|
||||
.filter { it.isNotBlank() }
|
||||
.joinToString(" ") { part ->
|
||||
part.lowercase().replaceFirstChar { it.uppercase() }
|
||||
}
|
||||
}
|
||||
|
||||
private fun String.getFirstAndLastPart(): String {
|
||||
val parts = normalizeStudentName().split(" ")
|
||||
|
||||
val endParts = parts.filterIndexed { i, _ ->
|
||||
i == 0 || parts.size == i - 1
|
||||
i == 0 || parts.size - 1 == i
|
||||
}
|
||||
return endParts.joinToString(" ")
|
||||
}
|
||||
|
@ -91,6 +91,20 @@ class MailboxRepositoryTest {
|
||||
assertEquals(expectedMailbox, systemUnderTest.getMailbox(student))
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `get mailbox for unique non-authorized student but with spaces`() = runTest {
|
||||
val student = getStudentEntity(
|
||||
userName = "Stanisław Kowalski",
|
||||
studentName = "J** K*******",
|
||||
)
|
||||
val expectedMailbox = getMailboxEntity("Jan Kowalski")
|
||||
coEvery { mailboxDao.loadAll(any()) } returns listOf(
|
||||
expectedMailbox,
|
||||
)
|
||||
|
||||
assertEquals(expectedMailbox, systemUnderTest.getMailbox(student))
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentException::class)
|
||||
fun `get mailbox for not-unique non-authorized student`() = runTest {
|
||||
val student = getStudentEntity(
|
||||
|
Loading…
x
Reference in New Issue
Block a user