-
-
Notifications
You must be signed in to change notification settings - Fork 102
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Changed so articles don't disappear immediately when they are read
- Loading branch information
1 parent
2a11651
commit 6e629e1
Showing
23 changed files
with
1,097 additions
and
209 deletions.
There are no files selected for viewing
725 changes: 725 additions & 0 deletions
725
app/schemas/com.nononsenseapps.feeder.db.room.AppDatabase/27.json
Large diffs are not rendered by default.
Oops, something went wrong.
73 changes: 73 additions & 0 deletions
73
app/src/androidTest/java/com/nononsenseapps/feeder/db/room/TestMigrationFrom26To27.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
package com.nononsenseapps.feeder.db.room | ||
|
||
import androidx.room.testing.MigrationTestHelper | ||
import androidx.sqlite.db.framework.FrameworkSQLiteOpenHelperFactory | ||
import androidx.test.core.app.ApplicationProvider | ||
import androidx.test.ext.junit.runners.AndroidJUnit4 | ||
import androidx.test.filters.LargeTest | ||
import androidx.test.platform.app.InstrumentationRegistry | ||
import com.nononsenseapps.feeder.FeederApplication | ||
import kotlin.test.assertEquals | ||
import kotlin.test.assertTrue | ||
import org.junit.Rule | ||
import org.junit.Test | ||
import org.junit.runner.RunWith | ||
import org.kodein.di.DI | ||
import org.kodein.di.DIAware | ||
import org.kodein.di.android.closestDI | ||
|
||
@RunWith(AndroidJUnit4::class) | ||
@LargeTest | ||
class TestMigrationFrom26To27 : DIAware { | ||
private val dbName = "testDb" | ||
private val feederApplication: FeederApplication = ApplicationProvider.getApplicationContext() | ||
override val di: DI by closestDI(feederApplication) | ||
|
||
@Rule | ||
@JvmField | ||
val testHelper: MigrationTestHelper = MigrationTestHelper( | ||
InstrumentationRegistry.getInstrumentation(), | ||
AppDatabase::class.java, | ||
emptyList(), | ||
FrameworkSQLiteOpenHelperFactory(), | ||
) | ||
|
||
@Test | ||
fun migrate() { | ||
testHelper.createDatabase(dbName, 26).let { oldDB -> | ||
oldDB.execSQL( | ||
""" | ||
INSERT INTO feeds(id, title, url, custom_title, tag, notify, last_sync, response_hash, fulltext_by_default, open_articles_with, alternate_id, currently_syncing, when_modified) | ||
VALUES(1, 'feed', 'http://url', '', '', 0, 0, 666, 0, '', 0, 0, 0) | ||
""".trimIndent(), | ||
) | ||
oldDB.execSQL( | ||
""" | ||
INSERT INTO feed_items(id, guid, title, plain_title, plain_snippet, unread, notified, feed_id, first_synced_time, primary_sort_time, pinned, bookmarked, fulltext_downloaded) | ||
VALUES(8, 'http://item1', 'title', 'ptitle', 'psnippet', 1, 0, 1, 0, 0, 1, 0, 0) | ||
""".trimIndent(), | ||
) | ||
oldDB.execSQL( | ||
""" | ||
INSERT INTO feed_items(id, guid, title, plain_title, plain_snippet, unread, notified, feed_id, first_synced_time, primary_sort_time, pinned, bookmarked, fulltext_downloaded) | ||
VALUES(9, 'http://item2', 'title', 'ptitle', 'psnippet', 0, 0, 1, 0, 0, 1, 0, 0) | ||
""".trimIndent(), | ||
) | ||
} | ||
val db = testHelper.runMigrationsAndValidate(dbName, 27, true, MigrationFrom26To27(di)) | ||
|
||
db.query( | ||
""" | ||
SELECT read_time FROM feed_items | ||
""".trimIndent(), | ||
).use { | ||
assert(it.count == 2) | ||
assert(it.moveToFirst()) | ||
assertTrue { | ||
it.isNull(0) | ||
} | ||
assert(it.moveToLast()) | ||
assertEquals(1690317917000, it.getLong(0)) | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.