Skip to content
Draft
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
19 changes: 19 additions & 0 deletions __tests__/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -729,6 +729,25 @@ describe("Purchases", () => {
});
});

it("cancelled purchasePackage sets userCancelled when code is numeric", async () => {
NativeModules.RNPurchases.purchasePackage.mockRejectedValueOnce({
code: 1,
message: "",
readableErrorCode: "USER_CANCELLED",
underlyingErrorMessage: undefined,
});

return expect(async () => {
await Purchases.purchasePackage("onemonth_freetrial")
}).rejects.toEqual({
code: 1,
message: "",
readableErrorCode: "USER_CANCELLED",
underlyingErrorMessage: undefined,
userCancelled: true
Comment on lines +743 to +747
});
});

it("successful purchase works", () => {
NativeModules.RNPurchases.purchaseProduct.mockResolvedValueOnce({
purchasedProductIdentifier: "123",
Expand Down
16 changes: 8 additions & 8 deletions src/purchases.ts
Original file line number Diff line number Diff line change
Expand Up @@ -615,7 +615,7 @@ export default class Purchases {
null
).catch((error: PurchasesError) => {
error.userCancelled =
error.code === PURCHASES_ERROR_CODE.PURCHASE_CANCELLED_ERROR;
String(error.code) === PURCHASES_ERROR_CODE.PURCHASE_CANCELLED_ERROR;
throw error;
Comment on lines 616 to 619
});
}
Expand Down Expand Up @@ -651,7 +651,7 @@ export default class Purchases {
product.presentedOfferingContext
).catch((error: PurchasesError) => {
error.userCancelled =
error.code === PURCHASES_ERROR_CODE.PURCHASE_CANCELLED_ERROR;
String(error.code) === PURCHASES_ERROR_CODE.PURCHASE_CANCELLED_ERROR;
throw error;
});
}
Expand Down Expand Up @@ -686,7 +686,7 @@ export default class Purchases {
product.presentedOfferingContext
).catch((error: PurchasesError) => {
error.userCancelled =
error.code === PURCHASES_ERROR_CODE.PURCHASE_CANCELLED_ERROR;
String(error.code) === PURCHASES_ERROR_CODE.PURCHASE_CANCELLED_ERROR;
throw error;
});
}
Expand Down Expand Up @@ -723,7 +723,7 @@ export default class Purchases {
: { isPersonalizedPrice: googleIsPersonalizedPrice }
).catch((error: PurchasesError) => {
error.userCancelled =
error.code === PURCHASES_ERROR_CODE.PURCHASE_CANCELLED_ERROR;
String(error.code) === PURCHASES_ERROR_CODE.PURCHASE_CANCELLED_ERROR;
throw error;
});
}
Expand Down Expand Up @@ -760,7 +760,7 @@ export default class Purchases {
subscriptionOption.presentedOfferingContext
).catch((error: PurchasesError) => {
error.userCancelled =
error.code === PURCHASES_ERROR_CODE.PURCHASE_CANCELLED_ERROR;
String(error.code) === PURCHASES_ERROR_CODE.PURCHASE_CANCELLED_ERROR;
throw error;
});
}
Expand Down Expand Up @@ -791,7 +791,7 @@ export default class Purchases {
null
).catch((error: PurchasesError) => {
error.userCancelled =
error.code === PURCHASES_ERROR_CODE.PURCHASE_CANCELLED_ERROR;
String(error.code) === PURCHASES_ERROR_CODE.PURCHASE_CANCELLED_ERROR;
throw error;
});
}
Expand Down Expand Up @@ -1226,7 +1226,7 @@ export default class Purchases {
winBackOffer.identifier
).catch((error: PurchasesError) => {
error.userCancelled =
error.code === PURCHASES_ERROR_CODE.PURCHASE_CANCELLED_ERROR;
String(error.code) === PURCHASES_ERROR_CODE.PURCHASE_CANCELLED_ERROR;
throw error;
});
}
Expand Down Expand Up @@ -1260,7 +1260,7 @@ export default class Purchases {
winBackOffer.identifier
).catch((error: PurchasesError) => {
error.userCancelled =
error.code === PURCHASES_ERROR_CODE.PURCHASE_CANCELLED_ERROR;
String(error.code) === PURCHASES_ERROR_CODE.PURCHASE_CANCELLED_ERROR;
throw error;
});
}
Expand Down