Skip to content

Commit

Permalink
A couple more ProjectRepositoryEntity Tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Wavesonics committed Jul 3, 2024
1 parent c49a347 commit e9646aa
Show file tree
Hide file tree
Showing 2 changed files with 75 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -161,9 +161,6 @@ class ProjectRepository(
if (validateSyncId(userId, projectDef, syncId).not())
return SResult.failure("Invalid SyncId", exception = InvalidSyncIdException())

// TODO how to move this to Datasource?
//ensureEntityDir(userId, projectDef)

val result = when (entity) {
is ApiProjectEntity.SceneEntity -> sceneSynchronizer.saveEntity(
userId,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,11 @@ import com.darkrockstudios.apps.hammer.utilities.SResult
import com.darkrockstudios.apps.hammer.utilities.isFailure
import com.darkrockstudios.apps.hammer.utilities.isSuccess
import io.mockk.coEvery
import io.mockk.coVerify
import io.mockk.every
import kotlinx.coroutines.test.runTest
import org.junit.Test
import kotlin.test.assertEquals
import kotlin.test.assertTrue
import kotlin.time.Duration.Companion.minutes

Expand Down Expand Up @@ -65,6 +67,79 @@ class ProjectRepositoryEntityTest : ProjectRepositoryBaseTest() {
}
}

@Test
fun `Load Entity - Scene Entity`() = runTest {
val syncId = "sync-id"
val entityId = 1
val sceneEntity = createSceneEntity(1)

mockCreateSession(syncId)

coEvery { projectsSessionManager.hasActiveSyncSession(any()) } returns false
coEvery { projectSessionManager.hasActiveSyncSession(any()) } returns true
coEvery { projectSessionManager.validateSyncId(any(), any(), any()) } returns true

coEvery {
projectDatasource.findEntityType(
entityId,
userId,
projectDefinition
)
} returns ApiProjectEntity.Type.SCENE

coEvery {
sceneSynchronizer.loadEntity(
userId,
projectDefinition,
entityId,
)
} returns SResult.success(sceneEntity)

createProjectRepository().apply {
val result = loadEntity(userId, projectDefinition, entityId, syncId)
assertTrue(isSuccess(result))
assertEquals(sceneEntity, result.data)
}
}

@Test
fun `Save Entity - Scene Entity`() = runTest {
val syncId = "sync-id"
val sceneEntity = createSceneEntity(1)

mockCreateSession(syncId)

coEvery { projectsSessionManager.hasActiveSyncSession(any()) } returns false
coEvery { projectSessionManager.hasActiveSyncSession(any()) } returns true
coEvery { projectSessionManager.validateSyncId(any(), any(), any()) } returns true

coEvery {
sceneSynchronizer.saveEntity(
userId,
projectDefinition,
sceneEntity,
null,
false
)
} returns SResult.success(true)

createProjectRepository().apply {
val result =
saveEntity(userId, projectDefinition, createSceneEntity(1), null, syncId, false)
assertTrue { result.isSuccess }
}

coVerify {
sceneSynchronizer.saveEntity(
userId,
projectDefinition,
sceneEntity,
null,
false
)
}
}

private fun createSceneEntity(entityId: Int): ApiProjectEntity.SceneEntity {
return ApiProjectEntity.SceneEntity(
id = entityId,
Expand Down

0 comments on commit e9646aa

Please sign in to comment.