-
Notifications
You must be signed in to change notification settings - Fork 263
Expand file tree
/
Copy pathOneSignalUserObjcTests.m
More file actions
80 lines (60 loc) · 2.86 KB
/
Copy pathOneSignalUserObjcTests.m
File metadata and controls
80 lines (60 loc) · 2.86 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
#import <XCTest/XCTest.h>
#import <OneSignalUser/OneSignalUser-Swift.h>
#import <OneSignalOSCore/OneSignalOSCore-Swift.h>
#import <OneSignalCore/OneSignalCore.h>
#import <OneSignalCoreMocks/OneSignalCoreMocks-Swift.h>
#import <OneSignalUserMocks/OneSignalUserMocks-Swift.h>
@interface OneSignalUserObjcTests : XCTestCase
@end
@implementation OneSignalUserObjcTests
- (void)setUp {
// TODO: Something like the existing [UnitTestCommonMethods beforeEachTest:self];
// TODO: Need to clear all data between tests for client, user manager, models, etc.
[OneSignalCoreMocks clearUserDefaults];
[OneSignalUserMocks reset];
// App ID is set because User Manager has guards against nil App ID
[OneSignalIdentifiers setCurrentAppId:@"test-app-id"];
// Temp. logging to help debug during testing
[OneSignalLog setLogLevel:ONE_S_LL_VERBOSE];
}
- (void)tearDown { }
/**
Tests passing purchase data to the User Manager to process and send.
It is written in Objective-C as the data comes from Objective-C code.
*/
- (void)testSendPurchases {
/* Setup */
MockOneSignalClient* client = [MockOneSignalClient new];
// 0. Set up mock responses for the anonymous user and install the mock client BEFORE start()
[MockUserRequests setDefaultCreateAnonUserResponsesWith:client onesignalId:nil subscriptionId:nil];
[OneSignalCoreImpl setSharedClient:client];
// 1. Purchases will be dropped if there is no user instance, so create the user first.
[OneSignalUserManagerImpl.sharedInstance start];
/* When */
NSMutableArray* arrayOfPurchases = [NSMutableArray new];
// SKProduct.price is an NSDecimalNumber, but the backend expects a String
NSNumberFormatter *formatter = [NSNumberFormatter new];
[formatter setMinimumFractionDigits:2];
NSString *formattedPrice1 = [formatter stringFromNumber:[NSDecimalNumber numberWithFloat:3.0]];
NSString *formattedPrice2 = [formatter stringFromNumber:[NSDecimalNumber numberWithFloat:4.05]];
NSDictionary* purchase1 = @{
@"sku": @"productSku1",
@"amount": formattedPrice1,
@"iso": @"EUR"
};
[arrayOfPurchases addObject:purchase1];
NSDictionary* purchase2 = @{
@"sku": @"productSku2",
@"amount": formattedPrice2,
@"iso": @"USD"
};
[arrayOfPurchases addObject:purchase2];
[OneSignalUserManagerImpl.sharedInstance sendPurchases:arrayOfPurchases];
// Run background threads
[OneSignalCoreMocks waitForBackgroundThreadsWithSeconds:0.5];
/* Then */
NSString* path = [NSString stringWithFormat:@"apps/test-app-id/users/by/onesignal_id/%@", @"test_anon_user_onesignal_id"];
NSDictionary *payload = [NSDictionary dictionaryWithObject:[NSDictionary dictionaryWithObject:arrayOfPurchases forKey:@"purchases"] forKey:@"deltas"];
XCTAssertTrue([client onlyOneRequestWithContains:path contains:payload]);
}
@end