Skip to content

Commit

Permalink
Handle null purchase lists in BillingWrapper#queryPurchases. (#79)
Browse files Browse the repository at this point in the history
* Handle null purchase lists in BillingWrapper#queryPurchases.
* Evlis
  • Loading branch information
tonycosentini authored Aug 13, 2019
1 parent 69c934b commit 32310f7
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -253,9 +253,13 @@ internal class BillingWrapper internal constructor(
return billingClient?.let {
debugLog("[QueryPurchases] Querying $skuType")
val result = it.queryPurchases(skuType)

// Purchases.PurchaseResult#purchasesList is not marked as nullable, but it does sometimes return null.
val purchasesList = result.purchasesList ?: emptyList<Purchase>()

QueryPurchasesResult(
result.responseCode,
result.purchasesList.map { purchase ->
purchasesList.map { purchase ->
val hash = purchase.purchaseToken.sha1()
debugLog("[QueryPurchases] Purchase of type $skuType with hash $hash")
hash to PurchaseWrapper(purchase, skuType)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -637,6 +637,17 @@ class BillingWrapperTest {
assertThat(wrapper!!.queryPurchases(BillingClient.SkuType.SUBS)).isNull()
}

@Test
fun `when querying anything and billing client returns a null list, returns an empty list`() {
setup()

every {
mockClient.queryPurchases(any())
} returns Purchase.PurchasesResult(BillingClient.BillingResponse.OK, null)

assertThat(wrapper!!.queryPurchases(BillingClient.SkuType.SUBS)!!.purchasesByHashedToken).isNotNull
}

@Test
fun `when querying INAPPs result is created properly`() {
setup()
Expand Down

0 comments on commit 32310f7

Please sign in to comment.