Throw error if there is no matching eduOne student in getSemesters() method
This commit is contained in:
parent
a324bee117
commit
35dec57cb6
5 changed files with 64 additions and 4 deletions
|
@ -18,7 +18,7 @@ ext {
|
|||
moshi = "1.13.0"
|
||||
}
|
||||
|
||||
version = "2.5.3"
|
||||
version = "2.5.4-SNAPSHOT"
|
||||
group = "io.github.wulkanowy"
|
||||
|
||||
nexusPublishing {
|
||||
|
|
|
@ -123,8 +123,8 @@ internal class StudentPlusRepository(
|
|||
suspend fun getSemesters(studentId: Int, diaryId: Int, unitId: Int): List<Semester> {
|
||||
val student = api.getContext().students.find {
|
||||
val key = getDecodedKey(it.key)
|
||||
key.studentId == studentId && key.diaryId == diaryId && key.unitId == unitId
|
||||
} ?: return emptyList()
|
||||
key.studentId == studentId
|
||||
} ?: throw NoSuchElementException()
|
||||
val level = student.className.takeWhile { it.isDigit() }
|
||||
return api.getSemesters(student.key, diaryId).map {
|
||||
Semester(
|
||||
|
|
|
@ -42,6 +42,10 @@ abstract class BaseLocalTest : BaseTest() {
|
|||
)
|
||||
}
|
||||
|
||||
fun MockWebServer.enqueue(content: String, responseCode: Int = 200) {
|
||||
enqueue(MockResponse().setBody(content).setResponseCode(responseCode))
|
||||
}
|
||||
|
||||
@After
|
||||
fun tearDown() {
|
||||
server.shutdown()
|
||||
|
|
|
@ -0,0 +1,43 @@
|
|||
package io.github.wulkanowy.sdk.scrapper.register
|
||||
|
||||
import io.github.wulkanowy.sdk.scrapper.BaseLocalTest
|
||||
import kotlinx.coroutines.test.runTest
|
||||
import org.junit.Assert.assertEquals
|
||||
import org.junit.Test
|
||||
|
||||
class SemestersPlusTest : BaseLocalTest() {
|
||||
|
||||
@Test
|
||||
fun `get semesters when diary and unit id are not set`() = runTest {
|
||||
val repo = getStudentPlusRepo {
|
||||
// ~ ❯❯❯ echo "MS0yLTEtMw==" | base64 -d
|
||||
// 1-2-1-3
|
||||
it.enqueue("Context-all-disabled.json", RegisterTest::class.java)
|
||||
it.enqueue("OkresyKlasyfikacyjne.json", RegisterTest::class.java)
|
||||
}
|
||||
val semesters = repo.getSemesters(1, 0, 0)
|
||||
|
||||
assertEquals(2, semesters.size)
|
||||
}
|
||||
|
||||
@Test(expected = NoSuchElementException::class)
|
||||
fun `get semesters when there is no matching student list`() = runTest {
|
||||
val repo = getStudentPlusRepo {
|
||||
// ~ ❯❯❯ echo "MS0yLTEtMw==" | base64 -d
|
||||
// 1-2-1-3
|
||||
it.enqueue("Context-all-disabled.json", RegisterTest::class.java)
|
||||
}
|
||||
repo.getSemesters(2, 0, 0)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `get semesters when there is empty semesters list`() = runTest {
|
||||
val repo = getStudentPlusRepo {
|
||||
it.enqueue("Context-all-disabled.json", RegisterTest::class.java)
|
||||
it.enqueue("[]")
|
||||
}
|
||||
val semesters = repo.getSemesters(1, 0, 0)
|
||||
|
||||
assertEquals(0, semesters.size)
|
||||
}
|
||||
}
|
|
@ -1 +1,14 @@
|
|||
[]
|
||||
[
|
||||
{
|
||||
"numerOkresu": 1,
|
||||
"dataOd": "2023-09-01T00:00:00+02:00",
|
||||
"dataDo": "2024-01-31T00:00:00+01:00",
|
||||
"id": 12
|
||||
},
|
||||
{
|
||||
"numerOkresu": 2,
|
||||
"dataOd": "2024-02-01T00:00:00+01:00",
|
||||
"dataDo": "2024-08-31T00:00:00+02:00",
|
||||
"id": 13
|
||||
}
|
||||
]
|
||||
|
|
Loading…
Reference in a new issue