Skip to content

Commit

Permalink
Clear cache on error (#147)
Browse files Browse the repository at this point in the history
  • Loading branch information
kiftio authored Oct 29, 2024
1 parent 7d9abc9 commit a55a6c9
Show file tree
Hide file tree
Showing 6 changed files with 29 additions and 3 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Changelog

## 3.2.1 October 29 2024

- Fix: Ensure we clear the preload cache on error responses.

## 3.2.0 October 18 2024

- Prevent entering recovery mode for single-use multipass URLs.
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ your project:
#### Gradle

```groovy
implementation "com.shopify:checkout-sheet-kit:3.2.0"
implementation "com.shopify:checkout-sheet-kit:3.2.1"
```

#### Maven
Expand All @@ -33,7 +33,7 @@ implementation "com.shopify:checkout-sheet-kit:3.2.0"
<dependency>
<groupId>com.shopify</groupId>
<artifactId>checkout-sheet-kit</artifactId>
<version>3.2.0</version>
<version>3.2.1</version>
</dependency>
```

Expand Down
2 changes: 1 addition & 1 deletion lib/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ def resolveEnvVarValue(name, defaultValue) {
return rawValue ? rawValue : defaultValue
}

def versionName = resolveEnvVarValue("CHECKOUT_SHEET_KIT_VERSION", "3.2.0")
def versionName = resolveEnvVarValue("CHECKOUT_SHEET_KIT_VERSION", "3.2.1")

ext {
app_compat_version = '1.6.1'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,7 @@ internal class CheckoutDialog(
}

internal fun closeCheckoutDialogWithError(exception: CheckoutException) {
CheckoutWebView.markCacheEntryStale()
checkoutEventProcessor.onCheckoutFailed(exception)
if (!this.checkoutUrl.isOneTimeUse() &&
ShopifyCheckoutSheetKit.configuration.errorRecovery.shouldRecoverFromError(exception)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,26 @@ class CheckoutDialogTest {
verify(mockEventProcessor, never()).onCheckoutFailed(any())
}

@Test
fun `closeCheckoutDialogWithError marks cache entry stale`() {
withPreloadingEnabled {
val mockEventProcessor = mock<DefaultCheckoutEventProcessor>()
ShopifyCheckoutSheetKit.preload("https://shopify.com", activity)
ShopifyCheckoutSheetKit.present("https://shopify.com", activity, mockEventProcessor)

assertThat(CheckoutWebView.cacheEntry).isNotNull()

val dialog = ShadowDialog.getLatestDialog()
val checkoutDialog = dialog as CheckoutDialog
val error = checkoutException(isRecoverable = false)

checkoutDialog.closeCheckoutDialogWithError(error)
shadowOf(Looper.getMainLooper()).runToEndOfTasks()

assertThat(CheckoutWebView.cacheEntry).isNull()
}
}

@Test
fun `calls onCheckoutFailed if closeCheckoutDialogWithError for non-recoverable error`() {
val mockEventProcessor = mock<DefaultCheckoutEventProcessor>()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ class MobileBuyEventProcessor(
logger.log("Checkout failed", error)

if (!error.isRecoverable) {
cartViewModel.clearCart()
GlobalScope.launch(Dispatchers.Main) {
Toast.makeText(
context,
Expand Down

0 comments on commit a55a6c9

Please sign in to comment.