Switch the GOG store to GOG's official listing endpoint: fewer requests, the tab now opens in seconds (#786)

This commit is contained in:
kingokksa authored and GitHub committed 2026-10-21 23:51:16 -04:00
1 parent cd18e87864
commit 60043873f2
9 files changed
+334 -47

No files matched your search

@@ -0,0 +1,29 @@
package com.droiddeck.launcher.stores
import org.junit.Assert.assertEquals
import org.junit.Assert.assertSame
import org.junit.Test
/** Filling a grid one card at a time: what is on screen stays put, what is new lands where its title belongs. */
class StoreCatalogPatchTest {
private fun item(id: String, title: String, image: String? = null) = CatalogItem(Store.GOG, id, title, imageUrl = image, owned = true)
@Test fun onlyTheCardItWasGivenIsReplaced() {
val alpha = item("1", "Alpha")
val beta = item("2", "Beta")
val next = patchItems(listOf(alpha, beta), listOf(item("2", "Beta", "wide.jpg")))
assertEquals(2, next.size)
assertSame(alpha, next[0])
assertEquals("wide.jpg", next[1].imageUrl)
}
@Test fun aCardTheGridDoesNotHaveYetIsAddedInTitleOrder() {
val next = patchItems(listOf(item("1", "Alpha"), item("3", "Gamma")), listOf(item("2", "Beta")))
assertEquals(listOf("Alpha", "Beta", "Gamma"), next.map { it.title })
}
@Test fun anEmptyGridTakesTheCardAsItComes() {
val next = patchItems(null, listOf(item("2", "Beta")))
assertEquals(listOf("Beta"), next.map { it.title })
}
}
@@ -0,0 +1,79 @@
package com.droiddeck.launcher.stores.gog
import org.junit.Assert.assertEquals
import org.junit.Assert.assertNull
import org.junit.Test
import org.junit.runner.RunWith
import org.robolectric.RobolectricTestRunner
import org.robolectric.annotation.Config
/** The account listing: everything the tab needs to draw a library before a product is asked about. */
@RunWith(RobolectricTestRunner::class)
@Config(sdk = [33])
class GogListingTest {
@Test
fun aPageCarriesTheGamesTheAppCanInstall() {
val page = GogLibrary.parseListing(PAGE)!!
assertEquals(2, page.totalPages)
assertEquals(listOf("Shadowrun Returns", "Witcher 3: Wild Hunt, The"), page.games.map { it.title })
val shadowrun = page.games[0]
assertEquals("1207660413", shadowrun.gameId)
assertEquals("https://images-2.gog.com/6c35ecb988f57725cc0f385acf860241082da16eda9fab66115f4da883dae3d1_glx_vertical_cover.webp", shadowrun.verticalCover)
assertEquals("", shadowrun.imageUrl)
assertEquals("Role-playing", shadowrun.category)
assertEquals("2013-07-25", shadowrun.releaseDate)
assertEquals("", shadowrun.description)
}
@Test
fun moviesOtherPlatformsAndGalaxysOwnEntryAreLeftOut() {
assertEquals(listOf("1207660413", "1207664663"), GogLibrary.parseListing(PAGE)!!.games.map { it.gameId })
}
@Test
fun aResponseThatIsNotAListingIsNull() {
assertNull(GogLibrary.parseListing("""{"error":"unauthorized"}"""))
assertNull(GogLibrary.parseListing("not json"))
}
private companion object {
val PAGE = """
{
"sortBy": "title",
"page": 1,
"totalProducts": 6,
"totalPages": 2,
"productsPerPage": 100,
"products": [
{
"id": 1207660413,
"title": "Shadowrun Returns",
"image": "//images-2.gog.com/6c35ecb988f57725cc0f385acf860241082da16eda9fab66115f4da883dae3d1",
"worksOn": { "Windows": true, "Mac": true, "Linux": true },
"category": "Role-playing",
"isComingSoon": false,
"isMovie": false,
"isGame": true,
"slug": "shadowrun_returns",
"dlcCount": 0,
"releaseDate": { "date": "2013-07-25 00:00:00.000000", "timezone_type": 3, "timezone": "Europe/Nicosia" }
},
{
"id": 1207664663,
"title": " Witcher 3: Wild Hunt, The ",
"image": "//images-3.gog.com/60c724a052275a049d857d53957dc38e9347742f52372bb956d992b43efa8fb5",
"worksOn": { "Windows": true, "Mac": false, "Linux": false },
"category": "Role-playing",
"isMovie": false,
"isGame": true,
"releaseDate": { "date": "2015-05-19 02:00:00.000000", "timezone_type": 3, "timezone": "Europe/Nicosia" }
},
{ "id": 1582718039, "title": "A Movie", "image": "//images-1.gog.com/movie", "isMovie": true, "isGame": false },
{ "id": 1430747193, "title": "Mac Only", "image": "//images-1.gog.com/mac", "worksOn": { "Windows": false, "Mac": true }, "isMovie": false, "isGame": true },
{ "id": 1801418160, "title": "GOG Galaxy", "image": "//images-1.gog.com/galaxy", "worksOn": { "Windows": true }, "isMovie": false, "isGame": true },
{ "id": 1401362385, "title": "Soundtrack", "image": "//images-1.gog.com/ost", "worksOn": { "Windows": true }, "isMovie": false, "isGame": false }
]
}
""".trimIndent()
}
}