mirror of
https://github.com/Droid-Deck/DroidDeck.git
synced 2026-11-18 20:36:04 +00:00
Add Preview update history
This commit is contained in:
1 parent
abdc46c7a7
commit
3c2064f30c
7 files changed
+363
-9
No files matched your search
@@ -5,9 +5,12 @@ import com.droiddeck.launcher.update.AppUpdates.Channel
|
||||
import com.droiddeck.launcher.update.AppUpdates.Follow
|
||||
import com.droiddeck.launcher.update.AppUpdates.Installed
|
||||
import com.droiddeck.launcher.update.AppUpdates.Offer
|
||||
import com.droiddeck.launcher.update.AppUpdates.PreviewChange
|
||||
import com.droiddeck.launcher.update.AppUpdates.PreviewHistoryKind
|
||||
import org.junit.Assert.assertEquals
|
||||
import org.junit.Assert.assertNotNull
|
||||
import org.junit.Assert.assertNull
|
||||
import org.json.JSONArray
|
||||
import org.json.JSONObject
|
||||
import org.junit.Assert.assertTrue
|
||||
import org.junit.Assert.fail
|
||||
@@ -63,7 +66,17 @@ class AppUpdatesTest {
|
||||
pr: Int = 0,
|
||||
version: String = "0.2.0",
|
||||
versionCode: Int = 9,
|
||||
) = Installed(commit, pr, version, versionCode, updatable = true)
|
||||
ciBuild: Boolean = true,
|
||||
) = Installed(commit, pr, version, versionCode, updatable = true, ciBuild = ciBuild)
|
||||
|
||||
private fun change(commit: String, title: String, publishedAt: Long) =
|
||||
PreviewChange(commit, title, "Summary for $title", publishedAt)
|
||||
|
||||
private val recentPreview = listOf(
|
||||
change("1".repeat(40), "Newest", 300L),
|
||||
change("2".repeat(40), "Middle", 200L),
|
||||
change("3".repeat(40), "Oldest", 100L),
|
||||
)
|
||||
|
||||
@Test
|
||||
fun theStableBuildIsCurrentOnStable() {
|
||||
@@ -122,6 +135,76 @@ class AppUpdatesTest {
|
||||
assertNotNull(AppUpdates.installBlock(missing, me("eeeeeee")))
|
||||
}
|
||||
|
||||
@Test
|
||||
fun previewHistoryCountsOnlyAnUnambiguousPublishedPreviewCommit() {
|
||||
val withHistory = AppUpdates.Catalog(stable, release("1111111"), emptyList(), 0L, recentPreview)
|
||||
val result = AppUpdates.previewHistory(withHistory, me("2".repeat(40), version = "0.3.0"))!!
|
||||
assertEquals(PreviewHistoryKind.BEHIND, result.kind)
|
||||
assertEquals(1, result.buildsBehind)
|
||||
assertEquals(listOf("Newest"), result.changes.map { it.title })
|
||||
}
|
||||
|
||||
@Test
|
||||
fun currentPreviewHasNoRedundantChangeRows() {
|
||||
val withHistory = AppUpdates.Catalog(stable, release("1111111"), emptyList(), 0L, recentPreview)
|
||||
val result = AppUpdates.previewHistory(withHistory, me("1".repeat(40), version = "0.3.0"))!!
|
||||
assertEquals(PreviewHistoryKind.CURRENT, result.kind)
|
||||
assertTrue(result.changes.isEmpty())
|
||||
}
|
||||
|
||||
@Test
|
||||
fun missingOrAmbiguousPreviewCommitsUseNeutralRecentHistory() {
|
||||
val withHistory = AppUpdates.Catalog(stable, release("1111111"), emptyList(), 0L, recentPreview)
|
||||
assertEquals(
|
||||
PreviewHistoryKind.RECENT,
|
||||
AppUpdates.previewHistory(withHistory, me("9".repeat(40), version = "0.3.0"))!!.kind,
|
||||
)
|
||||
|
||||
val ambiguous = listOf(
|
||||
change("abcdef0" + "1".repeat(33), "First", 300L),
|
||||
change("abcdef0" + "2".repeat(33), "Second", 200L),
|
||||
)
|
||||
val ambiguousCatalog = AppUpdates.Catalog(stable, release("abcdef0"), emptyList(), 0L, ambiguous)
|
||||
val result = AppUpdates.previewHistory(ambiguousCatalog, me("abcdef0", version = "0.3.0"))!!
|
||||
assertEquals(PreviewHistoryKind.RECENT, result.kind)
|
||||
assertEquals(2, result.changes.size)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun prStableAndLocalBuildsDoNotGetPreviewDistance() {
|
||||
val withHistory = AppUpdates.Catalog(stable, release("1111111"), emptyList(), 0L, recentPreview)
|
||||
assertEquals(
|
||||
PreviewHistoryKind.RECENT,
|
||||
AppUpdates.previewHistory(withHistory, me("2".repeat(40), pr = 93, version = "0.3.0"))!!.kind,
|
||||
)
|
||||
assertEquals(
|
||||
PreviewHistoryKind.RECENT,
|
||||
AppUpdates.previewHistory(withHistory, me(stable.commit))!!.kind,
|
||||
)
|
||||
assertNull(AppUpdates.previewHistory(withHistory, me("2".repeat(40), version = "0.3.0", ciBuild = false)))
|
||||
assertEquals(
|
||||
PreviewHistoryKind.RECENT,
|
||||
AppUpdates.previewHistory(withHistory, me("2".repeat(40), version = "0.1.0"))!!.kind,
|
||||
)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun cachedPreviewHistorySurvivesRoundTrip() {
|
||||
val withHistory = AppUpdates.Catalog(stable, release("1111111"), emptyList(), 123L, recentPreview)
|
||||
val cached = AppUpdates.readCachedCatalog(AppUpdates.writeCatalog(withHistory))
|
||||
assertEquals(123L, cached.checkedAt)
|
||||
assertEquals(3, cached.recentPreviews.size)
|
||||
assertEquals("Newest", cached.recentPreviews.first().title)
|
||||
assertEquals(recentPreview.first().commit, cached.recentPreviews.first().commit)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun oldCachedCatalogWithoutPreviewHistoryRemainsReadable() {
|
||||
val cached = AppUpdates.readCachedCatalog(JSONObject().put("tests", JSONArray()).put("checkedAt", 123L))
|
||||
assertEquals(123L, cached.checkedAt)
|
||||
assertTrue(cached.recentPreviews.isEmpty())
|
||||
}
|
||||
|
||||
private fun publishedCatalog(signer: String = BuildConfig.RELEASE_SIGNER): JSONObject {
|
||||
val raw = """
|
||||
{
|
||||
@@ -169,6 +252,25 @@ class AppUpdatesTest {
|
||||
assertEquals(9, parsed.preview!!.apk!!.versionCode)
|
||||
assertNull(parsed.preview!!.version)
|
||||
assertEquals(123L, parsed.checkedAt)
|
||||
assertTrue(parsed.recentPreviews.isEmpty())
|
||||
}
|
||||
|
||||
@Test
|
||||
fun publishedCatalogReadsOptionalPreviewHistoryAndDeduplicates() {
|
||||
val first = "a".repeat(40)
|
||||
val newest = "b".repeat(40)
|
||||
val raw = publishedCatalog().put(
|
||||
"recentPreviews",
|
||||
JSONArray()
|
||||
.put(JSONObject().put("commit", first).put("title", "Older").put("summary", "Old").put("publishedAt", 1L))
|
||||
.put(JSONObject().put("commit", newest).put("title", "Newest").put("summary", "New").put("publishedAt", 2L))
|
||||
.put(JSONObject().put("commit", first).put("title", "Duplicate").put("summary", "Again").put("publishedAt", 3L))
|
||||
.put(JSONObject().put("commit", "shortsha").put("title", "Invalid")),
|
||||
)
|
||||
val parsed = AppUpdates.readPublishedCatalog(raw, "com.droiddeck.launcher", 123L)
|
||||
assertEquals(2, parsed.recentPreviews.size)
|
||||
assertEquals("Duplicate", parsed.recentPreviews.first().title)
|
||||
assertEquals(newest, parsed.recentPreviews.last().commit)
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
Reference in new issue
Block a user