Skip to content

Commit

Permalink
Merge pull request #49 from qonversion/release/2.0.0
Browse files Browse the repository at this point in the history
Product Center
  • Loading branch information
smejl authored Aug 13, 2020
2 parents 1fc0f11 + 69a0094 commit 2f597ae
Show file tree
Hide file tree
Showing 96 changed files with 3,679 additions and 2,010 deletions.
4 changes: 1 addition & 3 deletions Framework/QonversionFramework.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,8 @@
#endif
#endif

#import "QUtils.h"
#import "QNUtils.h"
#import "Qonversion.h"
#import "RenewalProductDetails.h"
#import "QonversionCheckResult.h"

FOUNDATION_EXPORT double QonversionVersionNumber;
FOUNDATION_EXPORT const unsigned char QonversionVersionString[];
Expand Down
2 changes: 1 addition & 1 deletion Podfile
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ project 'Qonversion'

target 'QonversionTests' do
platform :ios, '9.0'
pod 'OCMock', '~> 3.2.1'
pod 'OCMock'
end

post_install do |installer|
Expand Down
4 changes: 2 additions & 2 deletions Podfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ PODS:
- OCMock (3.2.2)

DEPENDENCIES:
- OCMock (~> 3.2.1)
- OCMock

SPEC REPOS:
https://github.com/CocoaPods/Specs:
Expand All @@ -11,6 +11,6 @@ SPEC REPOS:
SPEC CHECKSUMS:
OCMock: 18c9b7e67d4c2770e95bb77a9cc1ae0c91fe3835

PODFILE CHECKSUM: da2af8c1fb1338335d6c619c322fd8f70dd232e7
PODFILE CHECKSUM: 30d6e86e2f472b1863ada85abb42581367e03f2c

COCOAPODS: 1.9.3
2 changes: 1 addition & 1 deletion Qonversion.podspec
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Pod::Spec.new do |s|
s.name = 'Qonversion'
s.version = '1.2.0'
s.version = '2.0.0'
s.summary = 'qonversion.io'
s.description = <<-DESC
Deep Analytics for iOS Subscriptions
Expand Down
402 changes: 259 additions & 143 deletions Qonversion.xcodeproj/project.pbxproj

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@
buildConfiguration = "Debug"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
shouldUseLaunchSchemeArgsEnv = "YES">
shouldUseLaunchSchemeArgsEnv = "YES"
codeCoverageEnabled = "YES">
<Testables>
<TestableReference
skipped = "NO">
Expand Down
8 changes: 8 additions & 0 deletions Qonversion.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist
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>
123 changes: 123 additions & 0 deletions QonversionTests/APIClientTests.m
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
51 changes: 51 additions & 0 deletions QonversionTests/Network/QRequestBuilderTests.m
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
101 changes: 101 additions & 0 deletions QonversionTests/ProductCenterManagerTests.m
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
20 changes: 10 additions & 10 deletions QonversionTests/QDeviceTests.m
Original file line number Diff line number Diff line change
@@ -1,24 +1,24 @@
#import <XCTest/XCTest.h>
#import <OCMock/OCMock.h>

#import "QDevice.h"
#import "QConstants.h"
#import "QNDevice.h"
#import "QNConstants.h"

// expose private methods for unit testing
@interface QDevice (Tests)
@interface QNDevice (Tests)

+ (NSString*)getAdvertiserID:(int) maxAttempts;

@end

@interface QDeviceTests : XCTestCase
@property (nonatomic, strong) QDevice *device;
@interface QNDeviceTests : XCTestCase
@property (nonatomic, strong) QNDevice *device;
@end

@implementation QDeviceTests
@implementation QNDeviceTests

- (void)setUp {
_device = [[QDevice alloc] init];
_device = [[QNDevice alloc] init];
}

- (void)tearDown {
Expand All @@ -39,7 +39,7 @@ - (void)testManufacturer {
}

- (void)testAdvertiserID {
id mockDeviceInfo = OCMClassMock([QDevice class]);
id mockDeviceInfo = OCMClassMock([QNDevice class]);
[[mockDeviceInfo expect] getAdvertiserID:5];
XCTAssertEqualObjects(nil, _device.advertiserID);
[mockDeviceInfo verify];
Expand Down Expand Up @@ -68,8 +68,8 @@ - (void)testLanguage {
}

- (void)testAfUserID {
XCTAssertNil(_device.af_userID);
XCTAssertNil(_device.adjust_userID);
XCTAssertNil(_device.afUserID);
XCTAssertNil(_device.adjustUserID);
}

@end
Loading

0 comments on commit 2f597ae

Please sign in to comment.