mirror of
https://gitlab.com/ultrasonic/ultrasonic.git
synced 2025-04-18 02:02:23 +03:00
Add converter from api User entity to domain entity.
Signed-off-by: Yahor Berdnikau <egorr.berd@gmail.com>
This commit is contained in:
parent
6b74a3e563
commit
2402ed6a50
@ -0,0 +1,23 @@
|
||||
// Helper functions to convert User entity to domain entity
|
||||
@file:JvmName("APIUserConverter")
|
||||
package org.moire.ultrasonic.data
|
||||
|
||||
import org.moire.ultrasonic.domain.UserInfo
|
||||
import org.moire.ultrasonic.api.subsonic.models.User
|
||||
|
||||
fun User.toDomainEntity(): UserInfo = UserInfo().apply {
|
||||
adminRole = this@toDomainEntity.adminRole
|
||||
commentRole = this@toDomainEntity.commentRole
|
||||
coverArtRole = this@toDomainEntity.coverArtRole
|
||||
downloadRole = this@toDomainEntity.downloadRole
|
||||
email = this@toDomainEntity.email
|
||||
jukeboxRole = this@toDomainEntity.jukeboxRole
|
||||
playlistRole = this@toDomainEntity.playlistRole
|
||||
podcastRole = this@toDomainEntity.podcastRole
|
||||
scrobblingEnabled = this@toDomainEntity.scrobblingEnabled
|
||||
settingsRole = this@toDomainEntity.settingsRole
|
||||
shareRole = this@toDomainEntity.shareRole
|
||||
streamRole = this@toDomainEntity.streamRole
|
||||
uploadRole = this@toDomainEntity.uploadRole
|
||||
userName = this@toDomainEntity.username
|
||||
}
|
@ -0,0 +1,37 @@
|
||||
@file:Suppress("IllegalIdentifier")
|
||||
|
||||
package org.moire.ultrasonic.data
|
||||
|
||||
import org.amshove.kluent.`should equal to`
|
||||
import org.junit.Test
|
||||
import org.moire.ultrasonic.api.subsonic.models.User
|
||||
|
||||
/**
|
||||
* Test conversion from api [User] to domain [UserInfo].
|
||||
*/
|
||||
class APIUserConverterTest {
|
||||
@Test
|
||||
fun `Should convert to domain entity`() {
|
||||
val entity = User(username = "Awsemo", email = "none@none.net", scrobblingEnabled = false,
|
||||
shareRole = true, streamRole = true)
|
||||
|
||||
val domainEntity = entity.toDomainEntity()
|
||||
|
||||
with(domainEntity) {
|
||||
adminRole `should equal to` entity.adminRole
|
||||
commentRole `should equal to` entity.commentRole
|
||||
coverArtRole `should equal to` entity.coverArtRole
|
||||
downloadRole `should equal to` entity.downloadRole
|
||||
email `should equal to` entity.email
|
||||
jukeboxRole `should equal to` entity.jukeboxRole
|
||||
playlistRole `should equal to` entity.playlistRole
|
||||
podcastRole `should equal to` entity.podcastRole
|
||||
scrobblingEnabled `should equal to` entity.scrobblingEnabled
|
||||
settingsRole `should equal to` entity.settingsRole
|
||||
shareRole `should equal to` entity.shareRole
|
||||
streamRole `should equal to` entity.streamRole
|
||||
uploadRole `should equal to` entity.uploadRole
|
||||
userName `should equal to` entity.username
|
||||
}
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user