@@ -78,7 +78,7 @@ - (void) test_simple_development_start
7878 headers: @{@" Content-Type" :@" application/json" }];
7979 }];
8080
81- // Validate requst .
81+ // Validate request .
8282 [LeanplumRequest validate_request: ^BOOL (NSString *method, NSString *apiMethod,
8383 NSDictionary *params) {
8484 // Check api method first.
@@ -208,6 +208,50 @@ - (void) test_complex_development_start
208208 XCTAssertTrue ([Leanplum hasStarted ]);
209209}
210210
211+ /* *
212+ * Tests a simple development start with variant debug info.
213+ */
214+ - (void ) testStartWithParamShouldIncludeVariantDebugInfo
215+ {
216+ [Leanplum setVariantDebugInfoEnabled: YES ];
217+ [OHHTTPStubs stubRequestsPassingTest: ^BOOL (NSURLRequest * _Nonnull request) {
218+ return [request.URL.host isEqualToString: API_HOST];
219+ } withStubResponse: ^OHHTTPStubsResponse * _Nonnull (NSURLRequest * _Nonnull request) {
220+ NSString *response_file = OHPathForFile (@" simple_start_response.json" , self.class );
221+ return [OHHTTPStubsResponse responseWithFileAtPath: response_file statusCode: 200
222+ headers: @{@" Content-Type" :@" application/json" }];
223+ }];
224+
225+ // Validate request.
226+ [LeanplumRequest validate_request: ^BOOL (NSString *method, NSString *apiMethod,
227+ NSDictionary *params) {
228+ // Check api method first.
229+ XCTAssertEqualObjects (apiMethod, @" start" );
230+
231+ // Check if request has all params.
232+ XCTAssertTrue ([params[@" city" ] isEqualToString: @" (detect)" ]);
233+ XCTAssertTrue ([params[@" country" ] isEqualToString: @" (detect)" ]);
234+ XCTAssertTrue ([params[@" location" ] isEqualToString: @" (detect)" ]);
235+ XCTAssertTrue ([params[@" region" ] isEqualToString: @" (detect)" ]);
236+ NSString * deviceModel = params[@" deviceModel" ];
237+ XCTAssertTrue ([deviceModel isEqualToString: @" iPhone" ] ||
238+ [deviceModel isEqualToString: @" iPhone Simulator" ]);
239+ XCTAssertTrue ([params[@" deviceName" ] isEqualToString: [[UIDevice currentDevice ] name ]]);
240+ XCTAssertEqualObjects (@0 , params[@" includeDefaults" ]);
241+ XCTAssertNotNil (params[@" locale" ]);
242+ XCTAssertNotNil (params[@" timezone" ]);
243+ XCTAssertNotNil (params[@" timezoneOffsetSeconds" ]);
244+ XCTAssertTrue (params[@" includeVariantDebugInfo" ]);
245+ return YES ;
246+ }];
247+
248+ XCTAssertTrue ([LeanplumHelper start_development_test ]);
249+ XCTAssertTrue ([[LPConstantsState sharedState ] isDevelopmentModeEnabled ]);
250+ XCTAssertTrue ([Leanplum hasStarted ]);
251+ XCTAssertNotNil ([Leanplum deviceId ]);
252+ }
253+
254+
211255/* *
212256 * Test complex production start.
213257 */
@@ -1004,7 +1048,7 @@ - (void)test_variables
10041048 @" myArray" : @{
10051049 @" [2]" : @33
10061050 }
1007- } messages: nil updateRules: nil eventRules: nil variants: nil regions: nil ];
1051+ } messages: nil updateRules: nil eventRules: nil variants: nil regions: nil variantDebugInfo: nil ];
10081052
10091053
10101054 XCTestExpectation *request_expectation =
@@ -1122,6 +1166,69 @@ - (void)test_variables
11221166 XCTAssertEqualObjects (@100LL , [long_long_variable defaultValue ]);
11231167}
11241168
1169+ /* *
1170+ * Tests variant debug info.
1171+ */
1172+ - (void )testStartResponseShouldParseVariantDebugInfo
1173+ {
1174+ // Given: start request
1175+
1176+ // When: VariantDebugInfoEnabled is YES
1177+ [Leanplum setVariantDebugInfoEnabled: YES ];
1178+ // This stub have to be removed when start command is successfully executed.
1179+ id <OHHTTPStubsDescriptor> startStub = [OHHTTPStubs stubRequestsPassingTest:
1180+ ^BOOL (NSURLRequest * _Nonnull request) {
1181+ return [request.URL.host isEqualToString: API_HOST];
1182+ } withStubResponse: ^OHHTTPStubsResponse * _Nonnull (NSURLRequest * _Nonnull request) {
1183+ NSString * response_file = OHPathForFile (@" start_with_variant_debug_info_response.json" , self.class );
1184+ return [OHHTTPStubsResponse responseWithFileAtPath: response_file statusCode: 200
1185+ headers: @{@" Content-Type" :@" application/json" }];
1186+ }];
1187+
1188+ [LeanplumHelper setup_development_test ];
1189+ dispatch_semaphore_t semaphore = dispatch_semaphore_create (0 );
1190+ [Leanplum startWithResponseHandler: ^(BOOL success) {
1191+ XCTAssertTrue (success);
1192+ [OHHTTPStubs removeStub: startStub];
1193+ // Then: variantDebugInfo should be parsed
1194+ XCTAssertNotNil ([LPVarCache variantDebugInfo ]);
1195+ NSDictionary *abTests = [LPVarCache variantDebugInfo ][@" abTests" ];
1196+ XCTAssertEqual (abTests.count , 2 );
1197+
1198+ // Then: variantDebugInfo should be persisted
1199+ [LPVarCache saveDiffs ];
1200+ [LPVarCache setVariantDebugInfo: nil ];
1201+ XCTAssertNil ([LPVarCache variantDebugInfo ]);
1202+ [LPVarCache loadDiffs ];
1203+ XCTAssertNotNil ([LPVarCache variantDebugInfo ]);
1204+ dispatch_semaphore_signal (semaphore);
1205+ }];
1206+ dispatch_semaphore_wait (semaphore, [LeanplumHelper default_dispatch_time ]);
1207+ }
1208+
1209+ /* *
1210+ * Tests variant debug info persistence.
1211+ */
1212+ - (void )testShouldPersistVariantDebugInfo
1213+ {
1214+ // Given: a variantDebugInfo set in VarCache
1215+ NSDictionary *mockVariantDebugInfo = @{@" abTests" :@[]};
1216+ [LPVarCache setVariantDebugInfo: mockVariantDebugInfo];
1217+ XCTAssertEqual ([Leanplum variantDebugInfo ].allKeys .count , 1 );
1218+
1219+ // When: the varcache is persisted
1220+ [LPVarCache saveDiffs ];
1221+ XCTAssertEqual ([Leanplum variantDebugInfo ].allKeys .count , 1 );
1222+
1223+
1224+ [LPVarCache setVariantDebugInfo: nil ];
1225+ XCTAssertEqual ([Leanplum variantDebugInfo ].allKeys .count , 0 );
1226+
1227+ // Then: the variantDebugInfo can be loaded from disk
1228+ [LPVarCache loadDiffs ];
1229+ XCTAssertEqual ([Leanplum variantDebugInfo ].allKeys .count , 1 );
1230+ }
1231+
11251232/* *
11261233 * Tests advance methods
11271234 */
@@ -1265,7 +1372,7 @@ - (void)test_metadata
12651372 }};
12661373 NSArray *variants = @[@{@" id" :@" 1" }, @{@" id" :@" 2" }];
12671374 [LPVarCache applyVariableDiffs: nil messages: messages updateRules: nil
1268- eventRules: nil variants: variants regions: nil ];
1375+ eventRules: nil variants: variants regions: nil variantDebugInfo: nil ];
12691376
12701377 XCTAssertEqualObjects (variants, [Leanplum variants ]);
12711378 XCTAssertEqualObjects (messages, [Leanplum messageMetadata ]);
0 commit comments