fix: Xbox search results open with their metadata and Game Pass installs (#1279)

This commit is contained in:
Moroni Granja authored and GitHub committed 2026-10-21 22:43:51 -04:00
1 parent 3305724f06
commit 4cae235154
9 files changed
+145 -17

No files matched your search

@@ -0,0 +1,29 @@
package com.droiddeck.launcher.stores
import org.junit.Assert.assertEquals
import org.junit.Assert.assertNull
import org.junit.Test
class DetailCatalogItemTest {
private fun item(store: Store, id: String, title: String) = CatalogItem(store, id, title, imageUrl = null)
private val shelves = StoreShelves(trending = listOf(item(Store.XBOX, "9SHELF000001", "Shelf game")))
@Test fun aSearchOnlyResultKeepsItsMetadataOnTheDetailPage() {
val found = listOf(item(Store.XBOX, "9SEARCH00001", "Echo Weaver"))
assertEquals("Echo Weaver", detailCatalogItem(Store.XBOX, "9SEARCH00001", emptyList(), found, shelves)?.title)
}
@Test fun theLibraryWinsOverSearchAndShelvesForTheSameProduct() {
val library = listOf(item(Store.XBOX, "9SEARCH00001", "Echo Weaver").copy(owned = true, sizeBytes = 42))
val found = listOf(item(Store.XBOX, "9SEARCH00001", "Echo Weaver").copy(owned = false))
val resolved = detailCatalogItem(Store.XBOX, "9SEARCH00001", library, found, shelves)!!
assertEquals(true, resolved.owned)
assertEquals(42L, resolved.sizeBytes)
}
@Test fun shelvesRemainAFallbackAndTheItemStaysInItsStore() {
assertEquals("Shelf game", detailCatalogItem(Store.XBOX, "9SHELF000001", emptyList(), emptyList(), shelves)?.title)
assertNull(detailCatalogItem(Store.GOG, "9SEARCH00001", emptyList(), listOf(item(Store.XBOX, "9SEARCH00001", "Echo Weaver")), shelves))
assertNull(detailCatalogItem(Store.XBOX, "9UNKNOWN0001", emptyList(), emptyList(), shelves))
}
}
@@ -19,7 +19,7 @@ class XboxCatalogTest {
private fun envelope(vararg rows: JSONObject) = JSONObject().put("schema", 1).put("account", "test@example.test")
.put("market", "US").put("checkedAt", now.toString()).put("entitlements", JSONArray(rows.toList()))
private fun access(vararg rows: JSONObject) = XboxCatalog.access(envelope(*rows), "test@example.test", "US", now)
private fun membership() = JSONObject().put("productId", plan).put("status", "Active").put("endDate", "2099-01-01T00:00:00Z")
private fun membership(id: String = plan) = JSONObject().put("productId", id).put("status", "Active").put("endDate", "2099-01-01T00:00:00Z")
private fun withMembership(json: JSONObject, vararg plans: JSONObject) = json.put("subscriptions", JSONArray(plans.toList()))
@Test fun separateMembershipRestoresSubscriptionChildrenWithoutInventingOwnership() {
@@ -83,6 +83,16 @@ class XboxCatalogTest {
assertEquals(mapOf(game to "gamepass", parent to "gamepass"), access(row(game, parent), row(parent, plan), row(plan)))
}
@Test fun onlyPcPlansGrantSubscriptionAccess() {
for (pc in listOf("CFQ7TTC0KGQ8", "CFQ7TTC0KHS0", "CFQ7TTC0P85B", "CFQ7TTC0K5DJ", "CFQ7TTC10QFD")) {
assertEquals(mapOf(game to "gamepass"), access(row(game, pc), row(pc)))
}
val console = "CFQ7TTC0K6L8"
assertTrue(access(row(game, console), row(console)).isEmpty())
assertTrue(XboxCatalog.access(withMembership(envelope(row(game, console)), membership(console)),
"test@example.test", "US", now).isEmpty())
}
@Test fun backendRfc3339OffsetsAndNanosecondsAreAccepted() {
val checked = "2026-10-19T19:02:38.173609086+00:00"
val response = envelope(row(game).put("endDate", "2099-01-01T01:00:00.000000001+01:00"))
@@ -120,6 +130,29 @@ class XboxCatalogTest {
assertFalse(card.owned); assertTrue(card.subscription)
}
@Test fun pcSubscriptionAffirmationsOfferAnInstallWithoutClaimingOwnership() {
fun offer(vararg affirmations: String) = JSONObject().put("ProductId", game).put("ProductType", "Game")
.put("LocalizedProperties", JSONArray().put(JSONObject().put("ProductTitle", "A Pass game")
.put("EligibilityProperties", JSONObject().put("Affirmations", JSONArray(affirmations.map {
JSONObject().put("AffirmationProductId", it)
})))))
.put("DisplaySkuAvailabilities", JSONArray().put(JSONObject().put("Sku", JSONObject().put("Properties", JSONObject()
.put("Packages", JSONArray().put(JSONObject().put("PackageFormat", "MSIXVC").put("PlatformDependencies",
JSONArray().put(JSONObject().put("PlatformName", "Windows.Desktop")))))))))
val pc = XboxCatalog.product(offer("CFQ7TTC0KGQ8"), emptyMap())!!
assertEquals("PC Game Pass", pc.includedWith)
assertFalse(pc.accessible); assertTrue(pc.installable)
assertEquals("Game Pass Ultimate", XboxCatalog.product(offer("CFQ7TTC0KHS0"), emptyMap())!!.includedWith)
assertEquals("Xbox Game Pass Premium", XboxCatalog.product(offer("CFQ7TTC0P85B"), emptyMap())!!.includedWith)
assertEquals("Xbox Game Pass Essential", XboxCatalog.product(offer("CFQ7TTC0K5DJ"), emptyMap())!!.includedWith)
assertEquals("Xbox Game Pass (Starter Edition)", XboxCatalog.product(offer("CFQ7TTC10QFD"), emptyMap())!!.includedWith)
val console = XboxCatalog.product(offer("CFQ7TTC0K6L8"), emptyMap())!!
assertEquals("", console.includedWith); assertFalse(console.installable)
assertFalse(XboxCatalog.product(offer(), emptyMap())!!.installable)
}
@Test fun consoleAndUwpOffersAreFilteredOut() {
fun product(platform: String, format: String) = JSONObject().put("ProductId", game).put("ProductType", "Game")
.put("LocalizedProperties", JSONArray().put(JSONObject().put("ProductTitle", "A PC game")))