Skip to content

Commit

Permalink
Add test
Browse files Browse the repository at this point in the history
  • Loading branch information
bubelov committed May 18, 2024
1 parent 9107b88 commit 7937558
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 9 deletions.
3 changes: 2 additions & 1 deletion app/src/main/kotlin/app/AppModule.kt
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package app

import android.content.Context
import api.Api
import api.ApiImpl
import area.AreaModel
Expand Down Expand Up @@ -36,7 +37,7 @@ import user.UsersModel
import user.UsersRepo

val appModule = module {
single { Database(get()) }
single { Database(get<Context>().getDatabasePath("btcmap-2024-05-15.db").absolutePath) }

single { ApiImpl() }.bind(Api::class)

Expand Down
5 changes: 2 additions & 3 deletions app/src/main/kotlin/db/Database.kt
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package db

import android.content.Context
import androidx.sqlite.SQLiteConnection
import androidx.sqlite.driver.bundled.BundledSQLiteDriver
import androidx.sqlite.execSQL
Expand All @@ -15,10 +14,10 @@ import user.UserQueries
import java.time.LocalDateTime
import java.util.concurrent.locks.ReentrantLock

class Database(context: Context) {
class Database(path: String) {

private val conn: SQLiteConnection =
BundledSQLiteDriver().open(context.getDatabasePath("btcmap-2024-05-15.db").absolutePath)
BundledSQLiteDriver().open(path)
.apply {
execSQL("PRAGMA journal_mode=WAL")
execSQL("PRAGMA synchronous=NORMAL")
Expand Down
14 changes: 9 additions & 5 deletions app/src/test/kotlin/area/AreaQueriesTest.kt
Original file line number Diff line number Diff line change
@@ -1,15 +1,19 @@
package area

import db.Database
import org.json.JSONObject
import org.junit.Ignore
import org.junit.Test
import java.time.ZonedDateTime

class AreaQueriesTest {

@Ignore
@Test
fun insert() {
// val queries = AreaQueries(
// BundledSQLiteDriver().open(":memory:").apply { execSQL(Database.CREATE_AREA_TABLE) })
// val area = Area(id = 1, tags = JSONObject(), updatedAt = ZonedDateTime.now())
// queries.insertOrReplace(area)
// assert(queries.selectById(area.id) == area)
val queries = AreaQueries(Database(":memory:"))
val area = Area(id = 1, tags = JSONObject(), updatedAt = ZonedDateTime.now())
queries.insertOrReplace(listOf(area))
assert(queries.selectById(area.id) == area)
}
}

0 comments on commit 7937558

Please sign in to comment.