Skip to content

Commit 0e46e16

Browse files
Fixed Optimizely test after event dispatcher merge.
1 parent b0a5a95 commit 0e46e16

File tree

3 files changed

+21
-28
lines changed

3 files changed

+21
-28
lines changed

OptimizelySDKCore/OptimizelySDKCore/OPTLYEventDispatcher.m

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,9 @@
1919
#import "OPTLYEventDispatcher.h"
2020
#import "OPTLYErrorHandler.h"
2121

22+
static NSString * const kEventDispatcherImpressionEventURL = @"https://logx.optimizely.com/log/decision";
23+
static NSString * const kEventDispatcherConversionEventURL = @"https://logx.optimizely.com/log/event";
24+
2225
static NSString * const kHTTPRequestMethodPost = @"POST";
2326
static NSString * const kHTTPHeaderFieldContentType = @"Content-Type";
2427
static NSString * const kHTTPHeaderFieldValueApplicationJSON = @"application/json";
@@ -71,15 +74,24 @@ - (void)dispatchEvent:(NSDictionary *)params
7174

7275
@end
7376

74-
static NSString * const kHTTPRequestMethodPost = @"POST";
75-
static NSString * const kHTTPHeaderFieldContentType = @"Content-Type";
76-
static NSString * const kHTTPHeaderFieldValueApplicationJSON = @"application/json";
77-
7877
@implementation OPTLYEventDispatcherBasic
7978

79+
- (void)dispatchImpressionEvent:(nonnull NSDictionary *)params
80+
callback:(nullable void(^)(NSData * _Nullable data, NSURLResponse * _Nullable response, NSError * _Nullable error))callback {
81+
NSURL *url = [NSURL URLWithString:kEventDispatcherImpressionEventURL];
82+
[self dispatchEvent:params toURL:url completionHandler:callback];
83+
}
84+
85+
- (void)dispatchConversionEvent:(nonnull NSDictionary *)params
86+
callback:(nullable void(^)(NSData * _Nullable data, NSURLResponse * _Nullable response, NSError * _Nullable error))callback {
87+
88+
NSURL *url = [NSURL URLWithString:kEventDispatcherConversionEventURL];
89+
[self dispatchEvent:params toURL:url completionHandler:callback];
90+
}
91+
8092
- (void)dispatchEvent:(NSDictionary *)params
8193
toURL:(NSURL *)url
82-
completionHandler:(void(^)(NSURLResponse *response, NSError *error))completion
94+
completionHandler:(void(^)(NSData *data, NSURLResponse *response, NSError *error))completion
8395
{
8496
NSURLSession *ephemeralSession = [NSURLSession sessionWithConfiguration:[NSURLSessionConfiguration ephemeralSessionConfiguration]];
8597
NSMutableURLRequest *request = [[NSMutableURLRequest alloc] initWithURL:url];
@@ -97,14 +109,16 @@ - (void)dispatchEvent:(NSDictionary *)params
97109
fromData:data
98110
completionHandler:^(NSData *data,NSURLResponse *response,NSError *error) {
99111
if (completion) {
100-
completion(response, error);
112+
completion(data, response, error);
101113
}
102114
}];
103115

104116
[uploadTask resume];
105117
}
106118
}
107119

120+
121+
108122
@end
109123

110124
@implementation OPTLYEventDispatcherNoOp

OptimizelySDKCore/OptimizelySDKCore/Optimizely.m

Lines changed: 0 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -375,27 +375,6 @@ - (double)getVariableFloat:(nonnull NSString *)variableKey
375375
return 0;
376376
}
377377

378-
# pragma mark - Helper Methods
379-
// log and propagate error for a activate failure
380-
- (void)handleErrorLogsForActivateUser:(NSString *)userId
381-
experiment:(NSString *)experimentKey
382-
success:(BOOL)succeeded
383-
{
384-
if (succeeded) {
385-
NSString *logMessage = [NSString stringWithFormat:OPTLYLoggerMessagesActivationSuccess, userId, experimentKey];
386-
[self.logger logMessage:logMessage
387-
withLevel:OptimizelyLogLevelInfo];
388-
} else {
389-
NSString *logMessage = [NSString stringWithFormat:OPTLYLoggerMessagesActivationFailure, userId, experimentKey];
390-
NSDictionary *errorMessage = [NSDictionary dictionaryWithObject:logMessage forKey:NSLocalizedDescriptionKey];
391-
NSError *error = [NSError errorWithDomain:OPTLYErrorHandlerMessagesDomain
392-
code:OPTLYErrorTypesUserActivate
393-
userInfo:errorMessage];
394-
[self.errorHandler handleError:error];
395-
[self.logger logMessage:logMessage withLevel:OptimizelyLogLevelError];
396-
}
397-
}
398-
399378
// log and propagate error for a track failure
400379
- (void)handleErrorLogsForTrackEvent:(NSString *)eventKey
401380
userId:(NSString *)userId

OptimizelySDKCore/OptimizelySDKCoreTests/OptimizelyTest.m

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ - (void)stubSuccessResponseForEventRequest {
116116
__weak XCTestExpectation *expectation = [self expectationWithDescription:@"testGetVariableString"];
117117

118118
[OHHTTPStubs stubRequestsPassingTest:^BOOL(NSURLRequest *request) {
119-
return [request.URL.host isEqualToString:@"p13nlog.dz.optimizely.com"];
119+
return [request.URL.host isEqualToString:@"logx.optimizely.com"];
120120
} withStubResponse:^OHHTTPStubsResponse*(NSURLRequest *request) {
121121
[expectation fulfill];
122122
return [OHHTTPStubsResponse responseWithData:[[NSData alloc] init]

0 commit comments

Comments
 (0)