Skip to content

Clear cache on error #147

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Oct 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading