-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #49 from qonversion/release/2.0.0
Product Center
- Loading branch information
Showing
96 changed files
with
3,679 additions
and
2,010 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> | ||
<plist version="1.0"> | ||
<dict> | ||
<key>IDEDidComputeMac32BitWarning</key> | ||
<true/> | ||
</dict> | ||
</plist> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,123 @@ | ||
#import <XCTest/XCTest.h> | ||
#import <OCMock/OCMock.h> | ||
#import "QNTestConstants.h" | ||
#import "QNAPIClient.h" | ||
|
||
#import "Helpers/XCTestCase+TestJSON.h" | ||
|
||
NSString *const kTestAPIKey = @"QNAPIClient_test_api_key"; | ||
|
||
@interface QNAPIClient (Private) | ||
- (NSDictionary *)enrichParameters:(NSDictionary *)parameters; | ||
|
||
- (void)dataTaskWithRequest:(NSURLRequest *)request | ||
completion:(void (^)(NSDictionary * _Nullable dict, NSError * _Nullable error))completion; | ||
@end | ||
|
||
@interface APIClientTests : XCTestCase | ||
|
||
@property (nonatomic) id mockSession; | ||
@property (nonatomic) id request; | ||
|
||
@property (nonatomic) QNAPIClient *client; | ||
@end | ||
|
||
@implementation APIClientTests | ||
|
||
- (void)setUp { | ||
_mockSession = OCMClassMock([NSURLSession class]); | ||
_request = OCMClassMock([NSURLRequest class]); | ||
|
||
_client = [[QNAPIClient alloc] init]; | ||
|
||
[_client setSession:_mockSession]; | ||
[_client setApiKey:kTestAPIKey]; | ||
} | ||
|
||
- (void)tearDown { | ||
[super tearDown]; | ||
_mockSession = nil; | ||
_mockSession = nil; | ||
_client = nil; | ||
} | ||
|
||
- (void)testThatEnrichingAddWaitingFields { | ||
NSDictionary *result = [_client enrichParameters:@{}]; | ||
XCTAssertNotNil(result); | ||
XCTAssertEqual(result.count, 5); | ||
XCTAssertNotNil(result[@"access_token"]); | ||
XCTAssertNotNil(result[@"q_uid"]); | ||
XCTAssertNotNil(result[@"client_uid"]); | ||
XCTAssertNotNil(result[@"version"]); | ||
} | ||
|
||
- (void)testThatClientSendsRequest { | ||
[_client dataTaskWithRequest:_request completion:nil]; | ||
|
||
OCMVerify([self.mockSession dataTaskWithRequest:self.request | ||
completionHandler:OCMOCK_ANY]); | ||
} | ||
|
||
- (void)testThatClientCallsCompletionHandler { | ||
XCTestExpectation *expectation = [self expectationWithDescription:@""]; | ||
OCMStub([_mockSession dataTaskWithRequest:self.request completionHandler:[OCMArg invokeBlock]]); | ||
|
||
[_client dataTaskWithRequest:_request completion:^(NSDictionary * _Nullable dict, NSError * _Nullable error) { | ||
[expectation fulfill]; | ||
}]; | ||
|
||
[self waitForExpectationsWithTimeout:keyQNTestTimeout handler:nil]; | ||
} | ||
|
||
- (void)testThatClientParseNullData { | ||
XCTestExpectation *expectation = [self expectationWithDescription:@""]; | ||
|
||
NSError *networkError = [NSError errorWithDomain:NSURLErrorDomain code:404 userInfo:nil]; | ||
|
||
OCMStub([_mockSession dataTaskWithRequest:self.request | ||
completionHandler:([OCMArg invokeBlockWithArgs:[NSNull null], [NSNull null], networkError, nil])]); | ||
|
||
[_client dataTaskWithRequest:_request completion:^(NSDictionary * _Nullable dict, NSError * _Nullable error) { | ||
XCTAssertNotNil(error); | ||
XCTAssertEqual(error.code, 404); | ||
XCTAssertNil(dict); | ||
[expectation fulfill]; | ||
}]; | ||
|
||
[self waitForExpectationsWithTimeout:keyQNTestTimeout handler:nil]; | ||
} | ||
|
||
- (void)testThatClientParseCorrectData { | ||
XCTestExpectation *expectation = [self expectationWithDescription:@""]; | ||
|
||
OCMStub([_mockSession dataTaskWithRequest:self.request | ||
completionHandler:([OCMArg invokeBlockWithArgs:[self fileDataFromContentsOfFile:keyQNInitFailedJSON], [NSNull null], [NSNull null], nil])]); | ||
|
||
[_client dataTaskWithRequest:_request completion:^(NSDictionary * _Nullable dict, NSError * _Nullable error) { | ||
XCTAssertNotNil(dict); | ||
XCTAssertNil(error); | ||
[expectation fulfill]; | ||
}]; | ||
|
||
[self waitForExpectationsWithTimeout:keyQNTestTimeout handler:nil]; | ||
} | ||
|
||
- (void)testThatClientDetectBrokenData { | ||
XCTestExpectation *expectation = [self expectationWithDescription:@""]; | ||
NSData *brokenJson = [self fileDataFromContentsOfFile:keyQNBrokenJSON]; | ||
|
||
OCMStub([_mockSession dataTaskWithRequest:self.request | ||
completionHandler:([OCMArg invokeBlockWithArgs:brokenJson, [NSNull null], [NSNull null], nil])]); | ||
|
||
[_client dataTaskWithRequest:_request completion:^(NSDictionary * _Nullable dict, NSError * _Nullable error) { | ||
XCTAssertNil(dict); | ||
XCTAssertNotNil(error); | ||
XCTAssertEqual(error.code, 17); | ||
XCTAssertEqualObjects(error.domain, keyQNErrorDomain); | ||
[expectation fulfill]; | ||
}]; | ||
|
||
[self waitForExpectationsWithTimeout:keyQNTestTimeout handler:nil]; | ||
} | ||
|
||
@end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
#import <XCTest/XCTest.h> | ||
#import "QNRequestBuilder.h" | ||
|
||
@interface QNRequestBuilderTests : XCTestCase | ||
@property (nonatomic, strong) QNRequestBuilder *requestBuilder; | ||
@end | ||
|
||
@interface QNRequestBuilder (Private) | ||
|
||
- (NSMutableURLRequest *)baseRequestWithURL:(NSURL *)url; | ||
|
||
@end | ||
|
||
@implementation QNRequestBuilderTests | ||
|
||
- (void)setUp { | ||
_requestBuilder = [[QNRequestBuilder alloc] init]; | ||
} | ||
|
||
- (void)tearDown { | ||
_requestBuilder = nil; | ||
} | ||
|
||
- (void)testThatBuilderSetCorrectRequestSettings { | ||
NSURL *url = [[NSURL alloc] initWithString:@"https://api.qonversion.io/"]; | ||
NSURLRequest *request = [_requestBuilder baseRequestWithURL:url]; | ||
|
||
XCTAssertEqualObjects(request.HTTPMethod, @"POST"); | ||
NSString *contentType = [request.allHTTPHeaderFields valueForKey:@"Content-Type"]; | ||
|
||
XCTAssertNotNil(contentType); | ||
XCTAssertEqualObjects(contentType, @"application/json; charset=utf-8"); | ||
} | ||
|
||
- (void)testThatInitRequestBuilderSetCorrectURL { | ||
NSURLRequest *request = [_requestBuilder makeInitRequestWith:@{}]; | ||
XCTAssertNotNil(request); | ||
|
||
XCTAssertNotNil(request.URL); | ||
XCTAssertEqualObjects(request.URL.absoluteString, @"https://api.qonversion.io/v1/user/init"); | ||
} | ||
|
||
- (void)testThatPurchaseRequestBuilderSetCorrectURL { | ||
NSURLRequest *request = [_requestBuilder makePurchaseRequestWith:@{}]; | ||
XCTAssertNotNil(request); | ||
|
||
XCTAssertNotNil(request.URL); | ||
XCTAssertEqualObjects(request.URL.absoluteString, @"https://api.qonversion.io/v1/user/purchase"); | ||
} | ||
|
||
@end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,101 @@ | ||
#import <XCTest/XCTest.h> | ||
#import <OCMock/OCMock.h> | ||
#import "QNProductCenterManager.h" | ||
#import "QNAPIClient.h" | ||
#import "QNUserDefaultsStorage.h" | ||
#import "QNStoreKitService.h" | ||
#import "QNTestConstants.h" | ||
#import "QNLaunchResult.h" | ||
|
||
#import "Helpers/XCTestCase+TestJSON.h" | ||
|
||
@interface QNProductCenterManager (Private) | ||
|
||
@property (nonatomic) QNStoreKitService *storeKitService; | ||
@property (nonatomic) QNUserDefaultsStorage *persistentStorage; | ||
|
||
@property (nonatomic) QNPurchaseCompletionHandler purchasingBlock; | ||
|
||
@property (nonatomic, copy) NSMutableArray *permissionsBlocks; | ||
@property (nonatomic, copy) NSMutableArray *productsBlocks; | ||
@property (nonatomic) QNAPIClient *apiClient; | ||
|
||
@property (nonatomic) QNLaunchResult *launchResult; | ||
@property (nonatomic) NSError *launchError; | ||
|
||
@property (nonatomic, assign) BOOL launchingFinished; | ||
@property (nonatomic, assign) BOOL productsLoaded; | ||
|
||
- (void)checkPermissions:(QNPermissionCompletionHandler)result; | ||
|
||
@end | ||
|
||
@interface ProductCenterManagerTests : XCTestCase | ||
|
||
@property (nonatomic) id mockClient; | ||
@property (nonatomic) QNProductCenterManager *manager; | ||
|
||
@end | ||
|
||
@implementation ProductCenterManagerTests | ||
|
||
- (void)setUp { | ||
_mockClient = OCMClassMock([QNAPIClient class]); | ||
|
||
_manager = [[QNProductCenterManager alloc] init]; | ||
[_manager setApiClient:_mockClient]; | ||
} | ||
|
||
- (void)tearDown { | ||
_manager = nil; | ||
} | ||
|
||
- (void)testThatProductCenterGetLaunchModel { | ||
XCTestExpectation *expectation = [self expectationWithDescription:@""]; | ||
|
||
OCMStub([_mockClient launchRequest:([OCMArg invokeBlockWithArgs:[self JSONObjectFromContentsOfFile:keyQNInitFullSuccessJSON], [NSNull null], nil])]); | ||
|
||
[_manager launch:^(QNLaunchResult * _Nullable result, NSError * _Nullable error) { | ||
XCTAssertNotNil(result); | ||
XCTAssertNil(error); | ||
XCTAssertEqual(result.permissions.count, 2); | ||
XCTAssertEqual(result.products.count, 1); | ||
XCTAssertEqualObjects(result.uid, @"qonversion_user_id"); | ||
|
||
[expectation fulfill]; | ||
}]; | ||
|
||
[self waitForExpectationsWithTimeout:keyQNTestTimeout handler:nil]; | ||
} | ||
|
||
- (void)testThatCheckPermissionStoreBlocksWhenLaunchingIsActive { | ||
// Given | ||
|
||
// When | ||
[_manager checkPermissions:^(NSDictionary<NSString *,QNPermission *> * _Nonnull result, NSError * _Nullable error) { | ||
|
||
}]; | ||
|
||
// Then | ||
XCTAssertEqual(_manager.permissionsBlocks.count, 1); | ||
} | ||
|
||
- (void)testThatCheckPermissionCallBlockWhenLaunchingFinished { | ||
// Given | ||
_manager.launchingFinished = YES; | ||
XCTestExpectation *expectation = [self expectationWithDescription:@""]; | ||
|
||
// When | ||
[_manager checkPermissions:^(NSDictionary<NSString *,QNPermission *> * _Nonnull result, NSError * _Nullable error) { | ||
XCTAssertNil(result); | ||
XCTAssertNil(error); | ||
XCTAssertEqual([NSThread mainThread], [NSThread currentThread]); | ||
|
||
[expectation fulfill]; | ||
}]; | ||
|
||
// Then | ||
[self waitForExpectationsWithTimeout:keyQNTestTimeout handler:nil]; | ||
} | ||
|
||
@end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.