mirror of
https://github.com/Droid-Deck/DroidDeck.git
synced 2026-11-20 05:16:01 +00:00
feat: Add the Game Jolt store (#1986)
This commit is contained in:
1 parent
0050b5eb6b
commit
3583643a11
74 files changed
+3215
-275
No files matched your search
@@ -298,4 +298,9 @@ class StoreInstallRootTest {
|
||||
assertFalse(StoreInstallRoot.insufficientSpace(1L, 1L))
|
||||
assertFalse(StoreInstallRoot.insufficientSpace(0L, 0L))
|
||||
}
|
||||
|
||||
@Test fun itchKeepsTheFolderItsGamesWereInstalledInWhateverItsDisplayName() {
|
||||
assertEquals("itch", StoreInstallRoot.storeDir(File("/games"), Store.ITCH).name)
|
||||
assertEquals("Game Jolt", StoreInstallRoot.storeDir(File("/games"), Store.GAMEJOLT).name)
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,36 @@
|
||||
package com.droiddeck.launcher.stores.gamejolt
|
||||
|
||||
import org.junit.Assert.assertEquals
|
||||
import org.junit.Test
|
||||
|
||||
class GameJoltBrowseTest {
|
||||
private fun qs(query: GameJoltQuery = GameJoltQuery(), page: Int = 1) = GameJoltBrowse.queryString(query, page)
|
||||
|
||||
@Test fun theDefaultQueryAsksForTheFeaturedSectionByName() {
|
||||
assertEquals("section=featured", qs())
|
||||
}
|
||||
|
||||
@Test fun sectionsPriceAndPagesUseTheSiteNames() {
|
||||
assertEquals("section=hot", qs(GameJoltQuery(section = GameJoltBrowse.SECTION_HOT)))
|
||||
assertEquals("section=featured&f_price=5-less&page=3", qs(GameJoltQuery(price = GameJoltBrowse.PRICE_UNDER_5), 3))
|
||||
assertEquals("section=featured&f_price=free", qs(GameJoltQuery(price = GameJoltBrowse.PRICE_FREE)))
|
||||
}
|
||||
|
||||
@Test fun listFiltersKeepTheSiteOrderWhateverTheSelectionOrder() {
|
||||
assertEquals("section=featured&f_os%5B%5D=windows&f_os%5B%5D=linux", qs(GameJoltQuery(os = setOf("linux", "windows"))))
|
||||
assertEquals("section=featured&f_browser%5B%5D=html&f_maturity%5B%5D=everyone&f_status%5B%5D=complete&f_partners%5B%5D=partners",
|
||||
qs(GameJoltQuery(browser = setOf("html"), maturity = setOf("everyone"), status = setOf("complete"), partners = true)))
|
||||
}
|
||||
|
||||
@Test fun devlogGamesAreNeverAskedFor() {
|
||||
assertEquals(setOf("complete", "wip"), GameJoltBrowse.effective(GameJoltQuery(), true).status)
|
||||
assertEquals(setOf("complete", "wip"), GameJoltBrowse.effective(GameJoltQuery(status = setOf("devlog")), true).status)
|
||||
assertEquals(setOf("wip"), GameJoltBrowse.effective(GameJoltQuery(status = setOf("wip", "devlog")), false).status)
|
||||
assertEquals("section=featured&f_status%5B%5D=complete&f_status%5B%5D=wip", qs(GameJoltBrowse.effective(GameJoltQuery(), true).copy(maturity = emptySet())))
|
||||
}
|
||||
|
||||
@Test fun tagsAreSluggedAndRepeatable() {
|
||||
assertEquals("co-op", GameJoltBrowse.tagSlug(" Co-Op "))
|
||||
assertEquals("section=featured&tag=action&tag=co-op", qs(GameJoltQuery(tags = listOf("Action", "co op"))))
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,41 @@
|
||||
package com.droiddeck.launcher.stores.gamejolt
|
||||
|
||||
import org.json.JSONArray
|
||||
import org.json.JSONObject
|
||||
import org.junit.Assert.assertEquals
|
||||
import org.junit.Assert.assertFalse
|
||||
import org.junit.Assert.assertTrue
|
||||
import org.junit.Test
|
||||
|
||||
@org.junit.runner.RunWith(org.robolectric.RobolectricTestRunner::class)
|
||||
@org.robolectric.annotation.Config(sdk = [33], application = android.app.Application::class)
|
||||
class GameJoltBuildsTest {
|
||||
private fun build(id: Int, pkg: Int, release: Int, name: String, vararg flags: String) = JSONObject()
|
||||
.put("id", id).put("game_package_id", pkg).put("game_release_id", release)
|
||||
.put("primary_file", JSONObject().put("filename", name).put("filesize", 100))
|
||||
.also { b -> flags.forEach { b.put(it, true) } }
|
||||
|
||||
private fun payload(vararg builds: JSONObject) = JSONObject()
|
||||
.put("packages", JSONArray().put(JSONObject().put("id", 1).put("title", "Main")))
|
||||
.put("releases", JSONArray().put(JSONObject().put("id", 10).put("published_on", 100).put("version_number", "1.0")).put(JSONObject().put("id", 11).put("published_on", 200).put("version_number", "1.1")))
|
||||
.put("builds", JSONArray(builds.toList()))
|
||||
.put("launchOptions", JSONArray())
|
||||
|
||||
@Test fun onlyTheNewestReleaseOfAPackageIsKept() {
|
||||
val list = GameJoltBuilds.parse(payload(build(1, 1, 10, "old.zip", "os_windows"), build(2, 1, 11, "new.zip", "os_windows")))
|
||||
assertEquals(listOf("2"), list.map { it.id })
|
||||
assertEquals("1.1", list.first().version)
|
||||
}
|
||||
|
||||
@Test fun windowsBuildsAreInstallableAndSortFirst() {
|
||||
val list = GameJoltBuilds.parse(payload(build(1, 1, 11, "game-linux.zip", "os_linux"), build(2, 1, 11, "game-win.zip", "os_windows")))
|
||||
assertEquals(listOf("2", "1"), list.map { it.id })
|
||||
assertTrue(list[0].installable)
|
||||
assertFalse(list[1].installable)
|
||||
}
|
||||
|
||||
@Test fun aBuildWithoutAnOsFlagIsWeb() {
|
||||
assertEquals(setOf("web"), GameJoltBuilds.platforms(JSONObject()))
|
||||
assertEquals(setOf("windows", "osx"), GameJoltBuilds.platforms(JSONObject().put("os_windows", true).put("os_mac", true)))
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
package com.droiddeck.launcher.stores.gamejolt
|
||||
|
||||
import org.json.JSONArray
|
||||
import org.json.JSONObject
|
||||
import org.junit.Assert.assertEquals
|
||||
import org.junit.Assert.assertNull
|
||||
import org.junit.Test
|
||||
|
||||
@org.junit.runner.RunWith(org.robolectric.RobolectricTestRunner::class)
|
||||
@org.robolectric.annotation.Config(sdk = [33], application = android.app.Application::class)
|
||||
class GameJoltCollectionsTest {
|
||||
@Test fun playlistsBecomeCollectionsByIdAndName() {
|
||||
val list = JSONArray()
|
||||
.put(JSONObject().put("id", 7).put("name", "test list"))
|
||||
.put(JSONObject().put("id", 0).put("name", "no id"))
|
||||
.put(JSONObject().put("id", 9).put("name", ""))
|
||||
val parsed = GameJoltCollections.parse(list)
|
||||
assertEquals(listOf("playlist:7"), parsed.map { it.id })
|
||||
assertEquals(listOf("test list"), parsed.map { it.title })
|
||||
}
|
||||
|
||||
@Test fun eachCollectionHasItsOwnGameListEndpoint() {
|
||||
assertEquals("/web/library/games/followed/@some+one", GameJoltCollections.path(GameJoltCollections.FOLLOWED, "some one"))
|
||||
assertEquals("/web/library/games/playlist/7", GameJoltCollections.path("playlist:7", "x"))
|
||||
assertNull(GameJoltCollections.path("playlist:abc", "x"))
|
||||
assertNull(GameJoltCollections.path("other", "x"))
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,52 @@
|
||||
package com.droiddeck.launcher.stores.gamejolt
|
||||
|
||||
import org.json.JSONArray
|
||||
import org.json.JSONObject
|
||||
import org.junit.Assert.assertEquals
|
||||
import org.junit.Assert.assertNull
|
||||
import org.junit.Test
|
||||
|
||||
@org.junit.runner.RunWith(org.robolectric.RobolectricTestRunner::class)
|
||||
@org.robolectric.annotation.Config(sdk = [33], application = android.app.Application::class)
|
||||
class GameJoltPricingTest {
|
||||
private fun pricing(amount: Long, promotional: Boolean = false, currency: Any = JSONObject.NULL) =
|
||||
JSONObject().put("amount", amount).put("promotional", promotional).put("currency_code", currency)
|
||||
|
||||
private fun sellable(vararg pricings: JSONObject) = JSONObject().put("type", "paid").put("pricings", JSONArray(pricings.toList()))
|
||||
|
||||
@Test fun aRegularPriceIsShownInDollars() {
|
||||
val price = GameJoltPricing.of(sellable(pricing(99)))!!
|
||||
assertEquals("$0.99", price.final)
|
||||
assertEquals("", price.original)
|
||||
assertEquals(0, price.discount)
|
||||
}
|
||||
|
||||
@Test fun aPromotionalPriceBesideTheRegularOneIsASale() {
|
||||
val price = GameJoltPricing.of(sellable(pricing(500), pricing(350, promotional = true)))!!
|
||||
assertEquals("$3.50", price.final)
|
||||
assertEquals("$5.00", price.original)
|
||||
assertEquals(30, price.discount)
|
||||
}
|
||||
|
||||
@Test fun aPromotionalPriceAloneShowsNoDiscount() {
|
||||
val price = GameJoltPricing.of(sellable(pricing(350, promotional = true)))!!
|
||||
assertEquals("$3.50", price.final)
|
||||
assertEquals("", price.original)
|
||||
assertEquals(0, price.discount)
|
||||
}
|
||||
|
||||
@Test fun aPromotionalPriceNotBelowTheRegularOneIsNotASale() {
|
||||
val price = GameJoltPricing.of(sellable(pricing(500), pricing(500, promotional = true)))!!
|
||||
assertEquals("", price.original)
|
||||
assertEquals(0, price.discount)
|
||||
}
|
||||
|
||||
@Test fun aGameWithoutPricingsHasNoPrice() {
|
||||
assertNull(GameJoltPricing.of(sellable()))
|
||||
assertNull(GameJoltPricing.of(null))
|
||||
}
|
||||
|
||||
@Test fun anotherCurrencyIsNamed() {
|
||||
assertEquals("1.50 EUR", GameJoltPricing.of(sellable(pricing(150, currency = "EUR")))!!.final)
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,63 @@
|
||||
package com.droiddeck.launcher.stores.gamejolt
|
||||
|
||||
import org.junit.Assert.assertEquals
|
||||
import org.junit.Assert.assertFalse
|
||||
import org.junit.Assert.assertNull
|
||||
import org.junit.Assert.assertTrue
|
||||
import org.junit.Test
|
||||
|
||||
@org.junit.runner.RunWith(org.robolectric.RobolectricTestRunner::class)
|
||||
@org.robolectric.annotation.Config(sdk = [33], application = android.app.Application::class)
|
||||
class GameJoltUpdatesTest {
|
||||
private fun build(id: String, pkg: String, stamp: String, windows: Boolean = true, name: String = "game.zip") =
|
||||
GameJoltBuild(id, pkg, "Main", "1.0", name, 100L, stamp, if (windows) setOf("windows") else setOf("linux"), "", "")
|
||||
|
||||
@Test fun aNewerReleaseOfTheSamePackageIsAnUpdate() {
|
||||
val update = GameJoltUpdates.evaluate(listOf(build("20", "1", "200", name = "new.zip")), "10", "1", "100")!!
|
||||
assertEquals("20", update.buildId)
|
||||
assertEquals("new.zip", update.filename)
|
||||
assertFalse(update.replaced)
|
||||
}
|
||||
|
||||
@Test fun theInstalledBuildIsNotAnUpdate() {
|
||||
assertNull(GameJoltUpdates.evaluate(listOf(build("10", "1", "100")), "10", "1", "100"))
|
||||
}
|
||||
|
||||
@Test fun anOlderBuildIsNotAnUpdate() {
|
||||
assertNull(GameJoltUpdates.evaluate(listOf(build("5", "1", "50")), "10", "1", "100"))
|
||||
}
|
||||
|
||||
@Test fun theSameReleaseTimeWithAHigherBuildIdIsAnUpdate() {
|
||||
assertEquals("11", GameJoltUpdates.evaluate(listOf(build("11", "1", "100")), "10", "1", "100")?.buildId)
|
||||
}
|
||||
|
||||
@Test fun otherPackagesDoNotCount() {
|
||||
assertEquals("30", GameJoltUpdates.evaluate(listOf(build("40", "2", "900"), build("30", "1", "300")), "10", "1", "100")?.buildId)
|
||||
}
|
||||
|
||||
@Test fun aRemovedPackageFallsBackToTheNewPreferredBuildAndSaysSo() {
|
||||
val update = GameJoltUpdates.evaluate(listOf(build("40", "2", "900")), "10", "1", "100")!!
|
||||
assertEquals("40", update.buildId)
|
||||
assertTrue(update.replaced)
|
||||
}
|
||||
|
||||
@Test fun nonWindowsBuildsAreNeverOffered() {
|
||||
assertNull(GameJoltUpdates.evaluate(listOf(build("40", "1", "900", windows = false)), "10", "1", "100"))
|
||||
}
|
||||
|
||||
@Test fun nothingToCompareMeansNoUpdate() {
|
||||
assertNull(GameJoltUpdates.evaluate(null, "10", "1", "100"))
|
||||
assertNull(GameJoltUpdates.evaluate(listOf(build("40", "1", "900")), "", "1", "100"))
|
||||
}
|
||||
|
||||
@Test fun foundUpdatesSurviveEncodingAndDropEntriesWithoutABuild() {
|
||||
val saved = GameJoltUpdates.encode(mapOf("gamejolt:1" to GameJoltUpdate("20", "200", "new.zip", true)))
|
||||
val back = GameJoltUpdates.decode(saved).getValue("gamejolt:1")
|
||||
assertEquals("20", back.buildId)
|
||||
assertEquals("200", back.stamp)
|
||||
assertEquals("new.zip", back.filename)
|
||||
assertTrue(back.replaced)
|
||||
assertEquals(emptyMap<String, GameJoltUpdate>(), GameJoltUpdates.decode("""{"gamejolt:1":{"stamp":"1"}}"""))
|
||||
assertEquals(emptyMap<String, GameJoltUpdate>(), GameJoltUpdates.decode("not json"))
|
||||
}
|
||||
}
|
||||
@@ -87,6 +87,11 @@ class LibraryEntriesTest {
|
||||
assertEquals(listOf("epic", "gog", "battlenet"), librarySources(entries, listOf("missing", "epic", "epic", "amazon")))
|
||||
}
|
||||
|
||||
@Test fun aSignedInStoreWithNoGamesKeepsItsPlaceInTheStoreOrder() {
|
||||
val entries = listOf("steam", "xbox").map { LibraryEntry(it, it, it, null, null, true) }
|
||||
assertEquals(listOf("steam", "xbox", "itch", "gamejolt"), librarySources(entries, listOf("xbox", "itch", "gamejolt"), setOf("itch", "gamejolt")))
|
||||
}
|
||||
|
||||
@Test fun gameKeysNameEitherAnAppOrAStoreProduct() {
|
||||
GameRef.parse("app:440").let { assertEquals(440, it.appId); assertNull(it.store) }
|
||||
GameRef.parse("app:-12").let { assertEquals(-12, it.appId) }
|
||||
|
||||
Reference in new issue
Block a user