New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix: add support for deleting nested fields that contain periods #295
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -1069,4 +1069,17 @@ public void updateIndividualPojo() throws ExecutionException, InterruptedExcepti | |||||
assertCommitEquals(expectedCommit, request); | ||||||
} | ||||||
} | ||||||
|
||||||
@Test | ||||||
public void deleteNestedFieldUsingFieldPath() throws Exception { | ||||||
doReturn(SINGLE_WRITE_COMMIT_RESPONSE) | ||||||
.when(firestoreMock) | ||||||
.sendRequest( | ||||||
commitCapture.capture(), Matchers.<UnaryCallable<CommitRequest, CommitResponse>>any()); | ||||||
FieldPath path = FieldPath.of("a.b", "c.d"); | ||||||
documentReference.update(path, FieldValue.delete()).get(); | ||||||
CommitRequest expectedCommit = | ||||||
commit(update(new HashMap<String, Value>(), Arrays.asList("`a.b`.`c.d`"))); | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done |
||||||
assertEquals(expectedCommit, commitCapture.getValue()); | ||||||
} | ||||||
} |
Original file line number | Diff line number | Diff line change | ||||||
---|---|---|---|---|---|---|---|---|
|
@@ -87,6 +87,8 @@ public class ITSystemTest { | |||||||
private final SingleField SINGLE_FIELD_OBJECT = LocalFirestoreHelper.SINGLE_FIELD_OBJECT; | ||||||||
private final AllSupportedTypes ALL_SUPPORTED_TYPES_OBJECT = | ||||||||
LocalFirestoreHelper.ALL_SUPPORTED_TYPES_OBJECT; | ||||||||
private final Map<String, Object> SINGLE_FILED_MAP_WITH_DOT = | ||||||||
LocalFirestoreHelper.SINGLE_FILED_MAP_WITH_DOT; | ||||||||
|
||||||||
@Rule public TestName testName = new TestName(); | ||||||||
|
||||||||
|
@@ -1269,4 +1271,26 @@ public void testInstanceReturnedByGetServiceCanBeUsedToDeserializeAQuery() throw | |||||||
fs.close(); | ||||||||
Query.fromProto(fs, proto); | ||||||||
} | ||||||||
|
||||||||
@Test | ||||||||
public void deleteNestedFieldUsingFieldPath() throws Exception { | ||||||||
DocumentReference documentReference = randomColl.document("doc1"); | ||||||||
Map<String, Object> dotKeyMap = new HashMap<>(); | ||||||||
dotKeyMap.put("a.b", SINGLE_FILED_MAP_WITH_DOT); | ||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done |
||||||||
documentReference.set(dotKeyMap).get(); | ||||||||
DocumentSnapshot documentSnapshots = documentReference.get().get(); | ||||||||
assertEquals(SINGLE_FILED_MAP_WITH_DOT, documentSnapshots.getData().get("a.b")); | ||||||||
FieldPath path = FieldPath.of("a.b", "c.d"); | ||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Add empty line above. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done |
||||||||
documentReference.update(path, FieldValue.delete()).get(); | ||||||||
documentSnapshots = documentReference.get().get(); | ||||||||
assertNull(documentSnapshots.getData().get("c.d")); | ||||||||
Map<String, Object> nestedMap = new HashMap<>(); | ||||||||
nestedMap.put("e", SINGLE_FILED_MAP_WITH_DOT); | ||||||||
dotKeyMap.put("a.b", nestedMap); | ||||||||
documentReference.set(dotKeyMap).get(); | ||||||||
path = FieldPath.of("a.b", "e", "c.d"); | ||||||||
documentReference.update(path, FieldValue.delete()).get(); | ||||||||
documentSnapshots = documentReference.get().get(); | ||||||||
assertNull(documentSnapshots.getData().get("c.d")); | ||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think you can delete this part as it doesn't expand on the tests coverage. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done |
||||||||
} | ||||||||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I generally prefer these inline comments for non-descriptive values.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done