@@ -258,6 +258,88 @@ - (void)testWriteAndLoadMetadataResult {
258
258
}];
259
259
}
260
260
261
+ // Create a key each for two namespaces, delete it from one namespace, read both namespaces.
262
+ - (void )testDeleteParamAndLoadMainTable {
263
+ XCTestExpectation *namespaceDeleteExpectation =
264
+ [self expectationWithDescription: @" Contents of 'namespace_delete' should be deleted." ];
265
+ XCTestExpectation *namespaceKeepExpectation =
266
+ [self expectationWithDescription: @" Write a key to namespace_keep and read back again." ];
267
+ NSString *namespaceToDelete = @" namespace_delete" ;
268
+ NSString *namespaceToKeep = @" namespace_keep" ;
269
+ NSString *bundleIdentifier = @" testBundleID" ;
270
+
271
+ // Write something to the database for both namespaces.
272
+ // Completion handler for the write to namespace_delete namespace.
273
+ RCNDBCompletion insertNamespace1Completion = ^void (BOOL success, NSDictionary *result) {
274
+ XCTAssertTrue (success);
275
+
276
+ // Delete the key for given namespace.
277
+ [_DBManager deleteRecordFromMainTableWithNamespace: namespaceToDelete
278
+ bundleIdentifier: bundleIdentifier
279
+ fromSource: RCNDBSourceActive];
280
+
281
+ // Read from the database and verify expected values.
282
+ [_DBManager
283
+ loadMainWithBundleIdentifier: bundleIdentifier
284
+ completionHandler: ^(BOOL success, NSDictionary *fetchedConfig,
285
+ NSDictionary *activeConfig, NSDictionary *defaultConfig) {
286
+ NSMutableDictionary *res = [activeConfig mutableCopy ];
287
+ XCTAssertTrue (success);
288
+ FIRRemoteConfigValue *value = res[namespaceToDelete][@" keyToDelete" ];
289
+ XCTAssertNil (value);
290
+
291
+ FIRRemoteConfigValue *value2 = res[namespaceToKeep][@" keyToRetain" ];
292
+ XCTAssertTrue ([value2.stringValue isEqualToString: @" valueToRetain" ]);
293
+
294
+ [namespaceDeleteExpectation fulfill ];
295
+ }];
296
+ };
297
+
298
+ // Insert a key into the second namespace.
299
+ RCNDBCompletion insertNamespace2Completion = ^void (BOOL success, NSDictionary *result) {
300
+ XCTAssertTrue (success);
301
+
302
+ // Ensure DB read succeeds.
303
+ [_DBManager
304
+ loadMainWithBundleIdentifier: bundleIdentifier
305
+ completionHandler: ^(BOOL success, NSDictionary *fetchedConfig,
306
+ NSDictionary *activeConfig, NSDictionary *defaultConfig) {
307
+ NSMutableDictionary *res = [activeConfig mutableCopy ];
308
+ XCTAssertTrue (success);
309
+ FIRRemoteConfigValue *value2 = res[namespaceToKeep][@" keyToRetain" ];
310
+ XCTAssertTrue ([value2.stringValue isEqualToString: @" valueToRetain" ]);
311
+
312
+ [namespaceKeepExpectation fulfill ];
313
+ }];
314
+ };
315
+ // We will delete this key after storing in the database.
316
+ NSString *valueToDelete = @" valueToDelete" ;
317
+ NSString *keyToDelete = @" keyToDelete" ;
318
+ NSArray *items = @[
319
+ bundleIdentifier, namespaceToDelete, keyToDelete,
320
+ [valueToDelete dataUsingEncoding: NSUTF8StringEncoding]
321
+ ];
322
+ [_DBManager insertMainTableWithValues: items
323
+ fromSource: RCNDBSourceActive
324
+ completionHandler: insertNamespace1Completion];
325
+
326
+ // This key value will be retained.
327
+ NSString *valueToRetain = @" valueToRetain" ;
328
+ NSString *keyToRetain = @" keyToRetain" ;
329
+ NSArray *items2 = @[
330
+ bundleIdentifier, namespaceToKeep, keyToRetain,
331
+ [valueToRetain dataUsingEncoding: NSUTF8StringEncoding]
332
+ ];
333
+ [_DBManager insertMainTableWithValues: items2
334
+ fromSource: RCNDBSourceActive
335
+ completionHandler: insertNamespace2Completion];
336
+
337
+ [self waitForExpectationsWithTimeout: _expectionTimeout
338
+ handler: ^(NSError *error) {
339
+ XCTAssertNil (error);
340
+ }];
341
+ }
342
+
261
343
- (void )testWriteAndLoadExperiments {
262
344
XCTestExpectation *updateAndLoadExperimentExpectation =
263
345
[self expectationWithDescription: @" Update and load experiment in database successfully" ];
0 commit comments