1
0
mirror of https://github.com/wulkanowy/wulkanowy.git synced 2024-09-20 00:29:09 -05:00

Fix matching mailboxes when there is more than one space between words (#1964)

This commit is contained in:
Mikołaj Pich 2022-09-02 20:19:19 +02:00 committed by GitHub
parent 83ca9a7060
commit 157becb017
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 21 additions and 5 deletions

View File

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

View File

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

View File

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