feat(stores): EA and Ubisoft stores browse their catalogs, and EA's Get for free works in the app (#2527)

* feat(stores): EA and Ubisoft stores browse their catalogs with prices, deals and search

* feat(stores): Get for free adds EA's free games to the account in the app

* fix(stores): an owned EA game matches its store card by its full product name
This commit is contained in:
Kurt Himebauch authored and GitHub committed 2026-11-12 12:08:33 -05:00
1 parent 08a8de9bc4
commit a5712c0d20
47 files changed
+614 -12

No files matched your search

@@ -1,5 +1,6 @@
package com.droiddeck.launcher.stores.ea
import com.droiddeck.launcher.stores.CatalogItem
import com.droiddeck.launcher.stores.Store
import com.droiddeck.launcher.stores.StoreGameSidecar
import com.droiddeck.launcher.stores.StoreLaunch
@@ -239,6 +240,47 @@ class EaTest {
assertTrue(EaLibrary.withoutGameDownload(emptyList()).isEmpty())
}
@Test fun theStorePageNamesEachGameWithItsPrice() {
val game = { slug: String, title: String, date: String, price: String, sale: String, off: Int, free: Boolean ->
"""{"slug":"$slug","title":"$title
","isFreeToPlay":$free,"franchiseSlug":"f","tier":"Tier1","releaseDate":"$date",
"packArt":{"ar16X9":"https://img/$slug-wide","ar2X3":"https://img/$slug-tall"},"genres":[{"name":"RPG"}],
"price":{"displayTotal":"$price","displayTotalWithDiscount":"$sale","discountPercentage":$off,"currency":"USD"}}"""
}
val html = """<html><script id="__NEXT_DATA__" type="application/json">{"props":{"pageProps":{"totalItems":40,"games":[""" +
game("ultima-7", "Ultima VII", "2026-11-05T18:00:00.000Z", "$4.99", "$2.49", 50, false) + "," +
game("redsec", "REDSEC", "2025-10-28T15:00:00.000Z", "$0.00", "$0.00", 0, true) + "," +
game("future", "Future", "2027-03-01T00:00:00.000Z", "$69.99", "$69.99", 0, false) + "]}}}</script></html>"
val (items, total) = EaStore.parsePage(html, "USD")
assertEquals("", EaStore.parsePage(html, "EUR").first.first().finalPrice)
assertEquals(40, total)
val ultima = items.first()
assertEquals("Ultima VII", ultima.title)
assertEquals("$2.49", ultima.finalPrice)
assertEquals("$4.99", ultima.originalPrice)
assertEquals(50, ultima.discountPercent)
assertEquals("https://www.ea.com/games/f/ultima-7", ultima.storeUrl)
assertTrue(items[1].isFree)
val shelves = EaStore.shelves(items, java.time.Instant.parse("2026-11-12T00:00:00Z"))
assertEquals(listOf("Ultima VII", "REDSEC"), shelves.whatsNew.map { it.title })
assertEquals(listOf("Ultima VII"), shelves.deals.map { it.title })
assertEquals(listOf("REDSEC"), shelves.free.map { it.title })
val owned = CatalogItem(Store.EA, "Origin.OFR.1", "Ultima™ VII", null, owned = true, extra = mapOf("slug" to "other"))
val marked = com.droiddeck.launcher.stores.StoreFront.markOwned(shelves, listOf(owned), EaStore::sameGame)
assertEquals("Origin.OFR.1", marked.deals.single().id)
assertEquals("https://img/ultima-7-wide", marked.deals.single().imageUrl)
val bf = CatalogItem(Store.EA, "Origin.OFR.50.0005511", "Battlefield™", null, owned = true, extra = mapOf("slug" to "glacier", "productName" to "Battlefield™ 6"))
assertTrue(EaStore.sameGame(CatalogItem(Store.EA, "ea-store:battlefield-6", "Battlefield™ 6", null, extra = mapOf("slug" to "battlefield-6")), bf))
assertFalse(EaStore.sameGame(CatalogItem(Store.EA, "ea-store:bf-2042", "Battlefield™ 2042", null), bf))
}
@Test fun titlesMatchAcrossMarksAndAccentsButNeverWhenEmpty() {
assertEquals("pokemon", com.droiddeck.launcher.stores.StoreFront.titleKey("Pokémon™"))
assertEquals("ファイナル 7", com.droiddeck.launcher.stores.StoreFront.titleKey("ファイナル® 7"))
val shelf = CatalogItem(Store.EA, "ea-store:a", "™", null)
assertFalse(EaStore.sameGame(shelf, CatalogItem(Store.EA, "Origin.OFR.2", "®", null, owned = true)))
}
@Test fun ownedPageParses() {
val page = JSONObject(
"""{"me":{"ownedGameProducts":{"next":"100","items":[{"originOfferId":"Origin.OFR.50.0001","product":{"id":"x","name":"N","downloadable":true,"gameSlug":"titanfall-2",
@@ -45,6 +45,36 @@ class UbisoftTest {
assertEquals(listOf("space-gone", "space-sc"), UbisoftLibrary.assemble(profile, null).map { it.id })
}
@Test fun theStoreSearchNamesEachGameWithItsPrice() {
fun hit(id: String, title: String, price: Double, base: Double, off: String, date: String, free: String = "") = JSONObject()
.put("objectID", id).put("title", title).put("price", JSONObject().put("USD", price)).put("default_price", JSONObject().put("USD", base))
.put("promotion_percentage", off).put("release_date", date).put("Free_offer", free).put("link", "https://store.ubisoft.com/us/$id.html")
.put("image_link", "https://img/$id.jpg?sw=300").put("productLauncherIDString", id.takeLast(3)).put("Rating", "esrb-m")
val answer = JSONObject().put("hits", JSONArray()
.put(hit("p-109", "Far Cry® 6", 15.0, 60.0, "75", "2021-10-07T00:00:00.000Z"))
.put(hit("p-110", "Far Cry® 6 - Gold Edition", 30.0, 100.0, "70", "2021-10-07T00:00:00.000Z"))
.put(hit("p-111", "Some Demo", 0.0, 0.0, "", "2021-10-07T00:00:00.000Z", free = "demo"))
.put(hit("p-112", "Next Year", 70.0, 70.0, "", "2030-01-01T00:00:00.000Z")))
val items = UbisoftStore.parse(answer, "USD", java.time.Instant.parse("2026-11-12T00:00:00Z"))
assertEquals(listOf("Far Cry® 6"), items.map { it.title })
val game = items.single()
assertEquals("$15.00", game.finalPrice)
assertEquals("$60.00", game.originalPrice)
assertEquals(75, game.discountPercent)
assertEquals("https://img/p-109.jpg", game.imageUrl)
assertTrue(game.mature)
val owned = CatalogItem(Store.UBISOFT, "space-fc6", "Far Cry 6", null, owned = true, extra = mapOf("productId" to "5266"))
val ezio = CatalogItem(Store.UBISOFT, "ubisoft-store:x", "Assassin's Creed® The Ezio Collection", null)
assertTrue(UbisoftStore.sameGame(game, owned))
assertTrue(!UbisoftStore.sameGame(ezio, CatalogItem(Store.UBISOFT, "space-ac", "Assassin's Creed™", null, owned = true)))
}
@Test fun theBaseEditionStandsForItsGameWhicheverComesFirst() {
fun hit(id: String, title: String) = JSONObject().put("objectID", id).put("title", title).put("price", JSONObject().put("USD", 10.0))
val answer = JSONObject().put("hits", JSONArray().put(hit("gold", "Far Cry® 6 - Gold Edition")).put(hit("base", "Far Cry® 6")))
assertEquals(listOf("ubisoft-store:base"), UbisoftStore.parse(answer, "USD").map { it.id })
}
@Test fun theEntitlementNamesTheGamesApplication() {
val body = JSONObject().put("items", JSONArray()
.put(JSONObject().put("productId", 82).put("applicationId", "app-82"))