Skip to content

Add API tests for purchases-capacitor and purchases-capacitor-ui#720

Merged
rickvdl merged 6 commits into
mainfrom
rickvdl/add-api-tests
Mar 23, 2026
Merged

Add API tests for purchases-capacitor and purchases-capacitor-ui#720
rickvdl merged 6 commits into
mainfrom
rickvdl/add-api-tests

Conversation

@rickvdl

@rickvdl rickvdl commented Mar 12, 2026

Copy link
Copy Markdown
Member

Summary

  • Add TypeScript compilation-based API tests (noEmit: true) that verify the public API surface of both purchases-capacitor and purchases-capacitor-ui compiles correctly
  • Cover all plugin methods, type definitions, enums (with exhaustive switches), error codes, offerings, customer info, and attributes
  • Add run-api-tests and run-api-tests-ui CI jobs to the CircleCI workflow and release gate

Details

purchases-capacitor (apitesters/)

  • purchases.ts — All PurchasesPlugin method signatures including discriminated union coverage
  • offerings.ts — Offering, package, product, and storefront types
  • customerInfo.ts — CustomerInfo, entitlements, subscription info
  • enums.ts — Exhaustive switch coverage for all enums
  • errors.ts — All PURCHASES_ERROR_CODE values
  • attributes.ts — All 19 attribute setter methods
  • definitions.ts — All Capacitor-specific option interfaces

purchases-capacitor-ui (purchases-capacitor-ui/apitesters/)

  • revenuecatui.ts — All RevenueCatUIPlugin method signatures
  • enums.ts — PURCHASE_LOGIC_RESULT and PAYWALL_RESULT
  • definitions.ts — All UI option types

@rickvdl rickvdl marked this pull request as ready for review March 12, 2026 14:59
@rickvdl rickvdl requested a review from a team as a code owner March 12, 2026 14:59
@tonidero

Copy link
Copy Markdown
Contributor

Nice! Thank you so much for adding this! Will take a look later. One thought however, it might also be useful to add api-extractor (same way we do for the PHC TS libraries + RN) to extract the public API automatically and have "golden" API tests created automatically. These tests can still be useful though, but I think the others make sure to cover things more extensively.

@rickvdl

rickvdl commented Mar 12, 2026

Copy link
Copy Markdown
Member Author

Nice! Thank you so much for adding this! Will take a look later. One thought however, it might also be useful to add api-extractor (same way we do for the PHC TS libraries + RN) to extract the public API automatically and have "golden" API tests created automatically. These tests can still be useful though, but I think the others make sure to cover things more extensively.

Thanks @tonidero, great idea. Working on that as a follow-up here

@rickvdl rickvdl force-pushed the rickvdl/add-api-tests branch from a6ef5ff to 7304e65 Compare March 12, 2026 16:08

@tonidero tonidero left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tests themselves looking good but have a comment that I think would need to be addressed... In any case, I would say the api-extractor changes you did in the follow-up PR provide more coverage than these so I think of these as less important. Though they can still be useful in certain occasions.

Comment thread apitesters/attributes.ts Outdated
@@ -0,0 +1,32 @@
import type { PurchasesPlugin } from '../src/definitions';

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One thing is that this is importing directly from src... I think the proper way to implement these API tests is split it into a separate Capacitor/TS project and to link to the library from there, not the source code. Otherwise, these API tests actually would have access to the internal code of the library and it might seem like we're exposing things that we aren't actually.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Very good point, updated to make the api tester separate projects with their own package.json that import the library instead :)

rickvdl added 4 commits March 23, 2026 08:52
Add TypeScript compilation-only API tests that verify the public API
surface compiles correctly. Covers all plugin methods, types, enums,
option interfaces, and listener callbacks for both packages.

- Main package: purchases, offerings, customerInfo, enums, errors, attributes, definitions
- UI package: revenuecatui, definitions, enums
- Add type tests for PurchasesWinBackOffer, GoogleProductChangeInfo,
  Storefront, UpgradeInfo in offerings.ts
- Add WebPurchaseRedemption field test (redemptionLink)
- Add WebPurchaseRedemptionResult discriminated union coverage
- Add WebPurchaseRedemptionResultType exhaustive enum switch
- Add PaywallResultEnum re-export test in UI package
- Add missing enums: VERIFICATION_RESULT, PRODUCT_TYPE, PURCHASE_TYPE,
  PAYWALL_RESULT, WebPurchaseRedemptionResultType
- Add missing type tests: PurchasesSubscriptionInfo, PurchasesVirtualCurrency,
  PurchaseParams, ShouldPurchasePromoProductListener, MakePurchaseResult
- Add missing type aliases: Store, OwnershipType, PeriodType
- Add missing properties on PurchasesEntitlementInfo (8 fields),
  PurchasesEntitlementInfos (verification), CustomerInfo
  (subscriptionsByProductIdentifier), PurchasesStoreProduct (productType),
  PurchasesPackage (webCheckoutUrl), PurchasesOffering (webCheckoutUrl)
- Add missing PurchasesConfiguration options (6 fields)
- Add missing TEST_STORE_SIMULATED_PURCHASE_ERROR error code
Instead of importing directly from ../src/definitions (which gives
access to internal code), the apitesters are now separate TS projects
with their own package.json that depend on the parent package via
file: links. This ensures the tests can only access the public API
surface exposed through the package exports.
@rickvdl rickvdl force-pushed the rickvdl/add-api-tests branch from 7304e65 to 6a04b54 Compare March 23, 2026 08:01
@rickvdl rickvdl requested a review from tonidero March 23, 2026 10:46

@tonidero tonidero left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looking good! Just a possible improvement but no blockers

Comment thread apitesters/src/attributes.ts
Comment thread package.json
@rickvdl rickvdl merged commit 5c680ba into main Mar 23, 2026
11 checks passed
@rickvdl rickvdl deleted the rickvdl/add-api-tests branch March 23, 2026 11:19
RCGitBot added a commit that referenced this pull request Apr 1, 2026
**This is an automatic release.**

## RevenueCat SDK
### 📦 Dependency Updates
* Updates purchases-hybrid-common to 17.54.0 (#745) via RevenueCat Git
Bot (@RCGitBot)
* [Android
9.28.1](https://github.com/RevenueCat/purchases-android/releases/tag/9.28.1)
* [Android
9.28.0](https://github.com/RevenueCat/purchases-android/releases/tag/9.28.0)
* [Android
9.27.0](https://github.com/RevenueCat/purchases-android/releases/tag/9.27.0)
* [iOS
5.67.0](https://github.com/RevenueCat/purchases-ios/releases/tag/5.67.0)
* [iOS
5.66.0](https://github.com/RevenueCat/purchases-ios/releases/tag/5.66.0)
* [AUTOMATIC BUMP] Updates purchases-hybrid-common to 17.53.0 (#737) via
RevenueCat Git Bot (@RCGitBot)
* [Android
9.28.1](https://github.com/RevenueCat/purchases-android/releases/tag/9.28.1)
* [Android
9.28.0](https://github.com/RevenueCat/purchases-android/releases/tag/9.28.0)
* [Android
9.27.0](https://github.com/RevenueCat/purchases-android/releases/tag/9.27.0)
* [iOS
5.67.0](https://github.com/RevenueCat/purchases-ios/releases/tag/5.67.0)
* [iOS
5.66.0](https://github.com/RevenueCat/purchases-ios/releases/tag/5.66.0)

### 🔄 Other Changes
* fix: upgrade dependencies with known security vulnerabilities (#743)
via Cesar de la Vega (@vegaro)
* Bump fastlane-plugin-revenuecat_internal from `9a6911b` to `f11fe40`
(#742) via dependabot[bot] (@dependabot[bot])
* security: pin GitHub Actions to SHA hashes (#741) via Alfonso
Embid-Desmet (@alfondotnet)
* Merge release PR after deploy (#739) via Antonio Pallares
(@ajpallares)
* Add missing API tests for presentation configuration and
trackCustomPaywallImpression (#740) via Rick (@rickvdl)
* Require PR approval before release tagging (#738) via Antonio Pallares
(@ajpallares)
* Add API tests for purchases-capacitor and purchases-capacitor-ui
(#720) via Rick (@rickvdl)
* Add AGENTS.md for AI coding agent guidance (#696) via Facundo Menzella
(@facumenzella)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants