Add new fields to MobileDevice, rename date to crateDate

This commit is contained in:
Mikołaj Pich 2020-04-09 23:40:02 +02:00
parent d279ebc727
commit f272cfcf95
5 changed files with 50 additions and 7 deletions

View file

@ -11,12 +11,18 @@ class Device {
@Selector("td.cellWithButton a", attr = "href", regex = "([^\\/]+\$)")
var id: Int = 0
@SerializedName("IdentyfikatorUrzadzenia")
var deviceId: String? = null
@SerializedName("NazwaUrzadzenia")
@Selector("td", index = 0)
lateinit var name: String
var name: String? = null
@SerializedName("DataUtworzenia")
@Format(value = "dd.MM.yyyy 'godz:' HH:mm:ss")
@Selector("td", index = 1, defValue = "01.01.1970")
lateinit var date: Date
var createDate: Date? = null
@SerializedName("DataModyfikacji")
var modificationDate: Date? = null
}

View file

@ -27,15 +27,36 @@ class MobileTest : BaseLocalTest() {
fun devicesTest() {
listOf(devicesSnp, devicesStudent).map {
it.apply {
assertEquals(2, size)
assertEquals("google Android SDK built for x86 (Android 8.1.0)", this[0].name)
assertEquals("google (Android SDK) built for x86 (Android 8.1.0)", this[1].name)
assertEquals(getDate(2018, 1, 20), this[1].date)
assertEquals(getDate(2018, 1, 20), this[1].createDate)
assertEquals(321, this[0].id)
}
}
}
@Test
fun getDevice_full() {
with(devicesStudent[0]) {
assertEquals(321, id)
assertEquals("google Android SDK built for x86 (Android 8.1.0)", name)
assertEquals("374d6203-dc0e-4299-8ca1-14b01e499d22", deviceId)
assertEquals(getDate(2018, 1, 20, 22, 35, 30), createDate)
assertEquals(getDate(2018, 1, 20, 22, 35, 31), modificationDate)
}
}
@Test
fun getDevice_nulls() {
with(devicesStudent[2]) {
assertEquals(214, id)
assertEquals(null, name)
assertEquals(null, deviceId)
assertEquals(getDate(2020, 4, 9, 23, 35, 7), createDate)
assertEquals(getDate(2020, 4, 9, 23, 35, 21), modificationDate)
}
}
@Test
fun tokenTest() {
listOf(tokenSnp, tokenStudent).map {

View file

@ -3,12 +3,23 @@
{
"NazwaUrzadzenia": "google Android SDK built for x86 (Android 8.1.0)",
"DataUtworzenia": "2018-01-20 22:35:30",
"DataModyfikacji": "2018-01-20 22:35:31",
"IdentyfikatorUrzadzenia": "374d6203-dc0e-4299-8ca1-14b01e499d22",
"Id": 321
},
{
"NazwaUrzadzenia": "google (Android SDK) built for x86 (Android 8.1.0)",
"DataUtworzenia": "2018-01-20 00:00:00",
"DataModyfikacji": "2018-01-20 00:00:10",
"IdentyfikatorUrzadzenia": null,
"Id": 213
},
{
"NazwaUrzadzenia": null,
"DataUtworzenia": "2020-04-09 23:35:07",
"DataModyfikacji": "2020-04-09 23:35:21",
"IdentyfikatorUrzadzenia": null,
"Id": 214
}
],
"success": true

View file

@ -5,6 +5,7 @@ import io.github.wulkanowy.sdk.scrapper.mobile.TokenResponse
import io.github.wulkanowy.sdk.pojo.Device
import io.github.wulkanowy.sdk.pojo.Token
import io.github.wulkanowy.sdk.toLocalDateTime
import org.threeten.bp.LocalDateTime.now
fun TokenResponse.mapToken(): Token {
return Token(
@ -19,8 +20,10 @@ fun List<ScrapperDevice>.mapDevices(): List<Device> {
return map {
Device(
id = it.id,
name = it.name,
date = it.date.toLocalDateTime()
deviceId = it.deviceId.orEmpty(),
name = it.name.orEmpty(),
createDate = it.createDate?.toLocalDateTime() ?: now(),
modificationDate = it.modificationDate?.toLocalDateTime()
)
}
}

View file

@ -4,6 +4,8 @@ import org.threeten.bp.LocalDateTime
data class Device(
val id: Int,
val deviceId: String,
val name: String,
val date: LocalDateTime
val createDate: LocalDateTime,
val modificationDate: LocalDateTime?
)