Skip to content
This repository was archived by the owner on Feb 22, 2023. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Tests
  • Loading branch information
GaryQian committed Jul 7, 2022
commit f394c10cc181e0429d1536a7738695223ea762ec
Original file line number Diff line number Diff line change
Expand Up @@ -331,7 +331,7 @@ private void queryPurchaseHistoryAsync(String skuType, final MethodChannel.Resul
}

billingClient.queryPurchaseHistoryAsync(
skuType,
QueryPurchasesParams.newBuilder().setProductType(skuType).build(),
new PurchaseHistoryResponseListener() {
@Override
public void onPurchaseHistoryResponse(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import static io.flutter.plugins.inapppurchase.Translator.fromPurchasesResult;
import static io.flutter.plugins.inapppurchase.Translator.fromSkuDetailsList;
import static java.util.Arrays.asList;
import static java.util.Collections.list;
import static java.util.Collections.singletonList;
import static java.util.Collections.unmodifiableList;
import static java.util.stream.Collectors.toList;
Expand Down Expand Up @@ -527,9 +528,6 @@ public void launchBillingFlow_ok_Full() {
verify(mockBillingClient).launchBillingFlow(any(), billingFlowParamsCaptor.capture());
BillingFlowParams params = billingFlowParamsCaptor.getValue();
assertEquals(params.getSku(), skuId);
assertEquals(params.getOldSku(), oldSkuId);
assertEquals(params.getOldSkuPurchaseToken(), purchaseToken);
assertEquals(params.getReplaceSkusProrationMode(), prorationMode);

// Verify we pass the response code to result
verify(result, never()).error(any(), any(), any());
Expand Down Expand Up @@ -595,7 +593,7 @@ public void launchBillingFlow_oldSkuNotFound() {
}

@Test
public void queryPurchases() {
public void queryPurchasesAsync() {
establishConnectedBillingClient(null, null);
PurchasesResult purchasesResult = mock(PurchasesResult.class);
Purchase purchase = buildPurchase("foo");
Expand All @@ -606,11 +604,26 @@ public void queryPurchases() {
.setDebugMessage("dummy debug message")
.build();
when(purchasesResult.getBillingResult()).thenReturn(billingResult);
when(mockBillingClient.queryPurchases(SkuType.INAPP)).thenReturn(purchasesResult);
when(mockBillingClient.queryPurchasesAsync(
any(QueryPurchasesParams.class),
any(PurchaseHistoryResponseListener.class)
).thenAnswer(
new Answer<Object>() {
Object answer(InvocationOnMock invocation) {
BillingResult.Builder builder = BillingResult.newBuilder();
builder.setDebugMessage("debug message");
builder.setResponseCode(10);
((Callback<Response>) invocation.getArguments()[1]).onPurchaseHistoryResponse(
builder.build(),
List.of(PurchaseHistoryRecord("{}", "signature"))
);
return null;
}
});

HashMap<String, Object> arguments = new HashMap<>();
arguments.put("skuType", SkuType.INAPP);
methodChannelHandler.onMethodCall(new MethodCall(QUERY_PURCHASES, arguments), result);
methodChannelHandler.onMethodCall(new MethodCall(QUERY_PURCHASES_ASYNC, arguments), result);

// Verify we pass the response to result
ArgumentCaptor<HashMap<String, Object>> resultCaptor = ArgumentCaptor.forClass(HashMap.class);
Expand All @@ -626,7 +639,7 @@ public void queryPurchases_clientDisconnected() {

HashMap<String, Object> arguments = new HashMap<>();
arguments.put("skuType", SkuType.INAPP);
methodChannelHandler.onMethodCall(new MethodCall(QUERY_PURCHASES, arguments), result);
methodChannelHandler.onMethodCall(new MethodCall(QUERY_PURCHASES_ASYNC, arguments), result);

// Assert that we sent an error back.
verify(result).error(contains("UNAVAILABLE"), contains("BillingClient"), any());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ class PurchaseWrapper {
required this.purchaseTime,
required this.purchaseToken,
required this.signature,
@Deprecated('Use skus instead')
this.sku = '', // Deprecated
required this.skus,
required this.isAutoRenewing,
Expand Down Expand Up @@ -184,6 +185,7 @@ class PurchaseHistoryRecordWrapper {
required this.purchaseTime,
required this.purchaseToken,
required this.signature,
@Deprecated('Use skus instead')
this.sku = '', // Deprecated
required this.skus,
required this.originalJson,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ const PurchaseWrapper dummyPurchase = PurchaseWrapper(
purchaseTime: 0,
signature: 'signature',
sku: 'sku',
skus: <String>['sku'],
purchaseToken: 'purchaseToken',
isAutoRenewing: false,
originalJson: '',
Expand All @@ -28,6 +29,7 @@ const PurchaseWrapper dummyUnacknowledgedPurchase = PurchaseWrapper(
purchaseTime: 0,
signature: 'signature',
sku: 'sku',
skus: <String>['sku'],
purchaseToken: 'purchaseToken',
isAutoRenewing: false,
originalJson: '',
Expand All @@ -41,6 +43,7 @@ const PurchaseHistoryRecordWrapper dummyPurchaseHistoryRecord =
purchaseTime: 0,
signature: 'signature',
sku: 'sku',
skus: <String>['sku'],
purchaseToken: 'purchaseToken',
originalJson: '',
developerPayload: 'dummy payload',
Expand All @@ -52,6 +55,7 @@ const PurchaseWrapper dummyOldPurchase = PurchaseWrapper(
purchaseTime: 0,
signature: 'oldSignature',
sku: 'oldSku',
skus: <String>['oldSku'],
purchaseToken: 'oldPurchaseToken',
isAutoRenewing: false,
originalJson: '',
Expand Down