Skip to content
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

[in_app_purchase_storekit] backfill native tests for more complete test coverage #6209

Merged
merged 14 commits into from
Mar 5, 2024

Conversation

LouiseHsu
Copy link
Contributor

@LouiseHsu LouiseHsu commented Feb 26, 2024

Added more native tests for more complete test coverage.
Fixes flutter/flutter#143889

Pre-launch Checklist

  • I read the [Contributor Guide] and followed the process outlined there for submitting PRs.
  • I read the [Tree Hygiene] wiki page, which explains my responsibilities.
  • I read and followed the [relevant style guides] and ran the auto-formatter. (Unlike the flutter/flutter repo, the flutter/packages repo does use dart format.)
  • I signed the [CLA].
  • The title of the PR starts with the name of the package surrounded by square brackets, e.g. [shared_preferences]
  • I listed at least one issue that this PR fixes in the description above.
  • I updated pubspec.yaml with an appropriate new version according to the [pub versioning philosophy], or this PR is [exempt from version changes].
  • I updated CHANGELOG.md to add a description of the change, [following repository CHANGELOG style].
  • I updated/added relevant documentation (doc comments with ///).
  • I added new tests to check the change I am making, or this PR is [test-exempt].
  • All existing and new tests are passing.

@LouiseHsu LouiseHsu changed the title initial commit backfill iap tests Feb 26, 2024
- (BOOL)shouldAddStorePayment:(SKPayment *)payment product:(SKProduct *)product;

// Dependency Injection
- (FIAPRequestHandler *)getHandler:(SKRequest *)request;
Copy link
Member

Choose a reason for hiding this comment

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

Instead of creating a method that will be overwritten with a partial mock I think you should pass in a factory to the constructor InAppPurchasePlugin.

InAppPurchasePlugin *plugin =
  [[InAppPurchasePlugin alloc]
    initWithReceiptManager:nil 
    handlerFactory:^(){ return [[FIAPRequestHandler alloc] initWithRequest:request]; }];

You were concerned about fiddling with the init method since it has users. You can get around that by adding this new initializer to InAppPurchasePlugin+TestOnly.h and calling it from the existing initWithRequest: initializer.

Partial mocks are something we should try hard to avoid. We've had to use them in the past because of oddities that disallow us to test without crashing. That isn't the case here.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think I'm misunderstanding something sorry - so for example

FIAPRequestHandler *handler = [self getHandler:request];
[self.requestHandlers addObject:handler];

What will these lines then look like? How do I reference the handlerFactory and ask it to please spit out another handler?
Additionally, the request param is only available within startProductRequestProductIdentifiers: , so how would I be able to call it inside the initWithRequest: initializer?

Copy link
Member

@gaaclarke gaaclarke Mar 1, 2024

Choose a reason for hiding this comment

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

They would look like this:

  FIAPRequestHandler *handler = self.handlerFactory();
  [self.requestHandlers addObject:handler];

You don't want to call the block in your init method. You want to hold on to it so that whenever you want a handler you can call it.

This is going to help: http://fuckingblocksyntax.com/ ;)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

doneeee

@LouiseHsu LouiseHsu marked this pull request as ready for review March 4, 2024 23:16
@LouiseHsu LouiseHsu changed the title backfill iap tests [in_app_purchase_storekit] backfill native tests for more complete test coverage Mar 4, 2024
@LouiseHsu LouiseHsu requested a review from gaaclarke March 4, 2024 23:17
Copy link
Member

@gaaclarke gaaclarke left a comment

Choose a reason for hiding this comment

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

The switch to using a block looks great. There' just one problem with the property type.

@@ -15,14 +15,18 @@
// Callback channel to dart used for when a function from the transaction observer is triggered.
@property(strong, nonatomic) FlutterMethodChannel *transactionObserverCallbackChannel;

// Callback channel to dart used for when a function from the transaction observer is triggered.
@property(strong, nonatomic) FIAPRequestHandler * (^handlerFactory)(SKRequest *);
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
@property(strong, nonatomic) FIAPRequestHandler * (^handlerFactory)(SKRequest *);
@property(copy, nonatomic) FIAPRequestHandler * (^handlerFactory)(SKRequest *);

You want to use copy for blocks properties since that will force any resources on the stack to be copied to the heap ( https://stackoverflow.com/questions/4081831/how-to-store-blocks-in-properties-in-objective-c#comment11631504_4081903 )

- (instancetype)initWithReceiptManager:(FIAPReceiptManager *)receiptManager
handlerFactory:(FIAPRequestHandler * (^)(SKRequest *))handlerFactory {
self = [self initWithReceiptManager:receiptManager];
_handlerFactory = handlerFactory;
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
_handlerFactory = handlerFactory;
_handlerFactory = [handlerFactory copy];

For the same reason mentioned above.

Copy link
Member

@gaaclarke gaaclarke left a comment

Choose a reason for hiding this comment

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

Okay, I went back an gave a full review. I think we are close.


SKPaymentTransactionStub *paymentTransaction =
[[SKPaymentTransactionStub alloc] initWithMap:transactionMap];
NSArray *array = [NSArray arrayWithObjects:paymentTransaction, nil];
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
NSArray *array = [NSArray arrayWithObjects:paymentTransaction, nil];
NSArray *array = @[paymentTransaction];

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

startProductRequestProductIdentifiers:argument
completion:^(SKProductsResponseMessage *_Nullable response,
FlutterError *_Nullable startProductRequestError) {
XCTAssertNotNil(error);
Copy link
Member

Choose a reason for hiding this comment

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

You'll want an expectation here to make sure that this is actually called.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

doneee

startProductRequestProductIdentifiers:argument
completion:^(SKProductsResponseMessage *_Nullable response,
FlutterError *_Nullable startProductRequestError) {
XCTAssertNotNil(error);
Copy link
Member

Choose a reason for hiding this comment

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

Same here, you need an expectation.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

doneee


[plugin refreshReceiptReceiptProperties:properties
completion:^(FlutterError *_Nullable error) {
XCTAssertNotNil(error);
Copy link
Member

Choose a reason for hiding this comment

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

An expectation here too.

Copy link
Contributor Author

@LouiseHsu LouiseHsu Mar 5, 2024

Choose a reason for hiding this comment

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

omg this is scary cuz I forgot to replace the handler alloc-ing in the actual refreshReciept function, but the tests were still passing. once i added the expectation, it failed - except the expectation wasnt failing, it was the other asserts. 😱

@LouiseHsu LouiseHsu requested a review from gaaclarke March 5, 2024 00:36
Copy link
Member

@gaaclarke gaaclarke left a comment

Choose a reason for hiding this comment

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

LGTM!

@LouiseHsu LouiseHsu added the autosubmit Merge PR when tree becomes green via auto submit App label Mar 5, 2024
@auto-submit auto-submit bot removed the autosubmit Merge PR when tree becomes green via auto submit App label Mar 5, 2024
Copy link
Contributor

auto-submit bot commented Mar 5, 2024

auto label is removed for flutter/packages/6209, due to - The status or check suite Mac_arm64 macos_platform_tests master - packages has failed. Please fix the issues identified (or deflake) before re-applying this label.

@gaaclarke
Copy link
Member

(hitting rerun and adding the autosubmit flag since it was an infra failure)

@gaaclarke gaaclarke added the autosubmit Merge PR when tree becomes green via auto submit App label Mar 5, 2024
Copy link
Contributor

auto-submit bot commented Mar 5, 2024

auto label is removed for flutter/packages/6209, due to - The status or check suite Mac_arm64 macos_platform_tests master - packages has failed. Please fix the issues identified (or deflake) before re-applying this label.

@auto-submit auto-submit bot removed the autosubmit Merge PR when tree becomes green via auto submit App label Mar 5, 2024
@LouiseHsu LouiseHsu added the autosubmit Merge PR when tree becomes green via auto submit App label Mar 5, 2024
@auto-submit auto-submit bot removed the autosubmit Merge PR when tree becomes green via auto submit App label Mar 5, 2024
Copy link
Contributor

auto-submit bot commented Mar 5, 2024

auto label is removed for flutter/packages/6209, due to - The status or check suite Mac_arm64 macos_platform_tests master - packages has failed. Please fix the issues identified (or deflake) before re-applying this label.

@jmagman jmagman added the autosubmit Merge PR when tree becomes green via auto submit App label Mar 5, 2024
@LouiseHsu LouiseHsu merged commit b5fe05d into flutter:main Mar 5, 2024
78 checks passed
engine-flutter-autoroll added a commit to engine-flutter-autoroll/flutter that referenced this pull request Mar 6, 2024
auto-submit bot pushed a commit to flutter/flutter that referenced this pull request Mar 6, 2024
flutter/packages@2aa6e3f...9b88dbc

2024-03-06 balvindersi2@gmail.com [image_picker_for_web] migrates to package:web (flutter/packages#5799)
2024-03-06 balvindersi2@gmail.com [video_player_web] migrates to package:web (flutter/packages#5800)
2024-03-06 49699333+dependabot[bot]@users.noreply.github.com [in_app_pur]: Bump org.json:json from 20240205 to 20240303 in /packages/in_app_purchase/in_app_purchase/example/android/app (flutter/packages#6253)
2024-03-05 ian@hixie.ch [rfw] Change test coverage logic to enforce 100% coverage (flutter/packages#6272)
2024-03-05 louisehsu@google.com [in_app_purchase_storekit] backfill native tests for more complete test coverage (flutter/packages#6209)
2024-03-05 stuartmorgan@google.com [tool] Add features to support GCB auto-publish flow (flutter/packages#6218)
2024-03-05 ditman@gmail.com [web] Use TrustedTypes from pkg web. (flutter/packages#6273)
2024-03-05 engine-flutter-autoroll@skia.org Roll Flutter from 65cd84b to 3b5a2ec (26 revisions) (flutter/packages#6269)

If this roll has caused a breakage, revert this CL and stop the roller
using the controls here:
https://autoroll.skia.org/r/flutter-packages-flutter-autoroll
Please CC flutter-ecosystem@google.com,rmistry@google.com on the revert to ensure that a human
is aware of the problem.

To file a bug in Flutter: https://github.com/flutter/flutter/issues/new/choose

To report a problem with the AutoRoller itself, please file a bug:
https://issues.skia.org/issues/new?component=1389291&template=1850622

Documentation for the AutoRoller is here:
https://skia.googlesource.com/buildbot/+doc/main/autoroll/README.md
arc-yong pushed a commit to Arctuition/packages-arc that referenced this pull request Jun 14, 2024
…st coverage (flutter#6209)

Added more native tests for more complete test coverage.
Fixes flutter/flutter#143889

## Pre-launch Checklist

- [x] I read the [Contributor Guide] and followed the process outlined
there for submitting PRs.
- [x] I read the [Tree Hygiene] wiki page, which explains my
responsibilities.
- [x] I read and followed the [relevant style guides] and ran the
auto-formatter. (Unlike the flutter/flutter repo, the flutter/packages
repo does use `dart format`.)
- [x] I signed the [CLA].
- [x] The title of the PR starts with the name of the package surrounded
by square brackets, e.g. `[shared_preferences]`
- [x] I listed at least one issue that this PR fixes in the description
above.
- [x] I updated `pubspec.yaml` with an appropriate new version according
to the [pub versioning philosophy], or this PR is [exempt from version
changes].
- [x] I updated `CHANGELOG.md` to add a description of the change,
[following repository CHANGELOG style].
- [x] I updated/added relevant documentation (doc comments with `///`).
- [x] I added new tests to check the change I am making, or this PR is
[test-exempt].
- [x] All existing and new tests are passing.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
autosubmit Merge PR when tree becomes green via auto submit App p: in_app_purchase platform-ios platform-macos
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[in_app_purchase_storekit] backfill tests to ensure 100% test coverage
3 participants