Skip to content

Commit

Permalink
Add database for ui tests
Browse files Browse the repository at this point in the history
aivanovski committed Jan 13, 2025
1 parent 14ec9ef commit 20a22ec
Showing 2 changed files with 52 additions and 3 deletions.
Original file line number Diff line number Diff line change
@@ -202,6 +202,16 @@ object FakeDatabaseContentFactory {
.toByteArray()
}

fun createAutomationDatabase(key: DatabaseKey): ByteArray {
return DatabaseBuilderDsl.newBuilder(KotpassDatabaseConverter())
.key(key)
.content(ROOT) {
entry(ENTRY_BASIC)
}
.build()
.toByteArray()
}

private fun Database<*, *>.toByteArray(): ByteArray {
return contentFactory.invoke().use { input ->
input.readBytes()
@@ -316,9 +326,9 @@ object FakeDatabaseContentFactory {
private const val DEFAULT_PASSWORD = "abc123"
private const val DEFAULT_KEY_FILE_CONTENT = "abcdefg1235678"

private val PASSWORD_KEY = DatabaseKey.PasswordKey(DEFAULT_PASSWORD)
private val FILE_KEY = DatabaseKey.BinaryKey(DEFAULT_KEY_FILE_CONTENT.toByteArray())
private val COMBINED_KEY = DatabaseKey.CompositeKey(
val PASSWORD_KEY = DatabaseKey.PasswordKey(DEFAULT_PASSWORD)
val FILE_KEY = DatabaseKey.BinaryKey(DEFAULT_KEY_FILE_CONTENT.toByteArray())
val COMBINED_KEY = DatabaseKey.CompositeKey(
password = DEFAULT_PASSWORD,
binaryData = DEFAULT_KEY_FILE_CONTENT.toByteArray()
)
@@ -604,4 +614,13 @@ object FakeDatabaseContentFactory {
modified = parseDate("2020-01-03").toInstant()
)
)

private val ENTRY_BASIC = newEntry(
title = "Basic entry",
username = "john.doe@example.com",
password = "abc123",
url = "https://url.com",
created = parseDate("2020-01-01"),
modified = parseDate("2020-01-10")
)
}
Original file line number Diff line number Diff line change
@@ -3,6 +3,10 @@ package com.ivanovsky.passnotes.data.repository.file.fake
import com.ivanovsky.passnotes.data.entity.FSAuthority
import com.ivanovsky.passnotes.data.entity.FileDescriptor
import com.ivanovsky.passnotes.data.entity.SyncStatus
import com.ivanovsky.passnotes.data.repository.file.fake.FakeDatabaseContentFactory.COMBINED_KEY
import com.ivanovsky.passnotes.data.repository.file.fake.FakeDatabaseContentFactory.FILE_KEY
import com.ivanovsky.passnotes.data.repository.file.fake.FakeDatabaseContentFactory.PASSWORD_KEY
import com.ivanovsky.passnotes.data.repository.file.fake.FakeDatabaseContentFactory.createAutomationDatabase
import com.ivanovsky.passnotes.data.repository.file.fake.FakeDatabaseContentFactory.createDatabaseWithAttachmentsData
import com.ivanovsky.passnotes.data.repository.file.fake.FakeDatabaseContentFactory.createDatabaseWithCombinedKey
import com.ivanovsky.passnotes.data.repository.file.fake.FakeDatabaseContentFactory.createDatabaseWithExpiredData
@@ -24,6 +28,7 @@ class FakeFileFactory(
return listOf(
// directories
newEntry(newDirectory("/", Time.ROOT)),
newEntry(newDirectory("/automation", Time.ROOT)),
newEntry(newDirectory("/conflicts", Time.ROOT)),
newEntry(newDirectory("/errors", Time.ROOT)),
newEntry(newDirectory("/examples", Time.ROOT)),
@@ -169,6 +174,26 @@ class FakeFileFactory(
syncStatus = SyncStatus.NO_CHANGES,
localContentFactory = { createDiffModifiedDatabase() },
remoteContentFactory = { createDiffModifiedDatabase() }
),

// automation
newEntry(
localFile = newFile(Path.AUTOMATION_PASSWORD_UNLOCK, Time.LOCAL),
syncStatus = SyncStatus.NO_CHANGES,
localContentFactory = { createAutomationDatabase(PASSWORD_KEY) },
remoteContentFactory = { createAutomationDatabase(PASSWORD_KEY) }
),
newEntry(
localFile = newFile(Path.AUTOMATION_KEY_FILE_UNLOCK, Time.LOCAL),
syncStatus = SyncStatus.NO_CHANGES,
localContentFactory = { createAutomationDatabase(FILE_KEY) },
remoteContentFactory = { createAutomationDatabase(FILE_KEY) }
),
newEntry(
localFile = newFile(Path.AUTOMATION_COMBINE_UNLOCK, Time.LOCAL),
syncStatus = SyncStatus.NO_CHANGES,
localContentFactory = { createAutomationDatabase(COMBINED_KEY) },
remoteContentFactory = { createAutomationDatabase(COMBINED_KEY) }
)
)
}
@@ -265,6 +290,11 @@ class FakeFileFactory(
// diff
val DETAILED_DIFF = "/examples/detailed-diff.kdbx"
val DETAILED_DIFF_MODIFIED = "/examples/detailed-diff-modified.kdbx"

// automation
val AUTOMATION_PASSWORD_UNLOCK = "/automation/basic.kdbx"
val AUTOMATION_KEY_FILE_UNLOCK = "/automation/basic-key-file.kdbx"
val AUTOMATION_COMBINE_UNLOCK = "/automation/basic-key-file-and-password.kdbx"
}

private object Time {

0 comments on commit 20a22ec

Please sign in to comment.