Skip to content
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
pr comements!
  • Loading branch information
LouiseHsu committed Mar 5, 2024
commit f0fbdbc87ff499783f3a6649e27f751a0a386adb
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
@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 *);
@property(copy, nonatomic) FIAPRequestHandler * (^handlerFactory)(SKRequest *);

// Convenience initializer with dependancy injection
- (instancetype)initWithReceiptManager:(FIAPReceiptManager *)receiptManager
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ - (instancetype)initWithReceiptManager:(FIAPReceiptManager *)receiptManager {
- (instancetype)initWithReceiptManager:(FIAPReceiptManager *)receiptManager
handlerFactory:(FIAPRequestHandler * (^)(SKRequest *))handlerFactory {
self = [self initWithReceiptManager:receiptManager];
_handlerFactory = handlerFactory;
_handlerFactory = [handlerFactory copy];
return self;
}

Expand Down Expand Up @@ -275,7 +275,7 @@ - (void)refreshReceiptReceiptProperties:(nullable NSDictionary *)receiptProperti
request = [self getRefreshReceiptRequest:nil];
}

FIAPRequestHandler *handler = [[FIAPRequestHandler alloc] initWithRequest:request];
FIAPRequestHandler *handler = self.handlerFactory(request);
[self.requestHandlers addObject:handler];
__weak typeof(self) weakSelf = self;
[handler startProductRequestWithCompletionHandler:^(SKProductsResponse *_Nullable response,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ - (void)testFinishTransactionSucceeds {

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

FIAPaymentQueueHandler *mockHandler = OCMClassMock(FIAPaymentQueueHandler.class);
OCMStub([mockHandler getUnfinishedTransactions]).andReturn(array);
Expand Down Expand Up @@ -179,6 +179,8 @@ - (void)testFinishTransactionSucceedsWithNilTransaction {

- (void)testGetProductResponseWithRequestError {
NSArray *argument = @[ @"123" ];
XCTestExpectation *expectation =
[self expectationWithDescription:@"completion handler successfully called"];

id mockHandler = OCMClassMock([FIAPRequestHandler class]);
InAppPurchasePlugin *plugin = [[InAppPurchasePlugin alloc]
Expand All @@ -199,16 +201,20 @@ - (void)testGetProductResponseWithRequestError {
startProductRequestProductIdentifiers:argument
completion:^(SKProductsResponseMessage *_Nullable response,
FlutterError *_Nullable startProductRequestError) {
[expectation fulfill];
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

XCTAssertNotNil(startProductRequestError);
XCTAssertEqualObjects(
startProductRequestError.code,
@"storekit_getproductrequest_platform_error");
}];
[self waitForExpectations:@[ expectation ] timeout:5];
}

- (void)testGetProductResponseWithNoResponse {
NSArray *argument = @[ @"123" ];
XCTestExpectation *expectation =
[self expectationWithDescription:@"completion handler successfully called"];

id mockHandler = OCMClassMock([FIAPRequestHandler class]);

Expand All @@ -230,11 +236,13 @@ - (void)testGetProductResponseWithNoResponse {
startProductRequestProductIdentifiers:argument
completion:^(SKProductsResponseMessage *_Nullable response,
FlutterError *_Nullable startProductRequestError) {
[expectation fulfill];
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

XCTAssertNotNil(startProductRequestError);
XCTAssertEqualObjects(startProductRequestError.code,
@"storekit_platform_no_response");
}];
[self waitForExpectations:@[ expectation ] timeout:5];
}

- (void)testAddPaymentShouldReturnFlutterErrorWhenPaymentFails {
Expand Down Expand Up @@ -495,6 +503,8 @@ - (void)testRefreshReceiptRequestWithError {
@"isRevoked" : @NO,
@"isVolumePurchase" : @NO,
};
XCTestExpectation *expectation =
[self expectationWithDescription:@"completion handler successfully called"];

id mockHandler = OCMClassMock([FIAPRequestHandler class]);
InAppPurchasePlugin *plugin = [[InAppPurchasePlugin alloc]
Expand All @@ -516,7 +526,9 @@ - (void)testRefreshReceiptRequestWithError {
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. 😱

XCTAssertEqualObjects(
error.code, @"storekit_refreshreceiptrequest_platform_error");
[expectation fulfill];
}];
[self waitForExpectations:@[ expectation ] timeout:5];
}

/// presentCodeRedemptionSheetWithError:error is only available on iOS
Expand Down