|
99 | 99 | using firebase::firestore::remote::RemoteEvent;
|
100 | 100 | using firebase::firestore::remote::TargetChange;
|
101 | 101 | using firebase::firestore::remote::WatchChangeAggregator;
|
102 |
| -using firebase::firestore::testutil::OrderBy; |
103 |
| -using firebase::firestore::testutil::Query; |
104 | 102 |
|
105 | 103 | NS_ASSUME_NONNULL_BEGIN
|
106 | 104 |
|
107 | 105 | /** A string sentinel that can be used with FSTTestPatchMutation() to mark a field for deletion. */
|
108 | 106 | static NSString *const kDeleteSentinel = @"<DELETE>";
|
109 | 107 |
|
110 |
| -FIRTimestamp *FSTTestTimestamp(int year, int month, int day, int hour, int minute, int second) { |
111 |
| - NSDate *date = FSTTestDate(year, month, day, hour, minute, second); |
112 |
| - return [FIRTimestamp timestampWithDate:date]; |
113 |
| -} |
114 |
| - |
115 | 108 | NSDate *FSTTestDate(int year, int month, int day, int hour, int minute, int second) {
|
116 | 109 | NSDateComponents *comps = FSTTestDateComponents(year, month, day, hour, minute, second);
|
117 | 110 | return [[NSCalendar currentCalendar] dateFromComponents:comps];
|
@@ -224,108 +217,4 @@ DeleteMutation FSTTestDeleteMutation(NSString *path) {
|
224 | 217 | return DeleteMutation(FSTTestDocKey(path), Precondition::None());
|
225 | 218 | }
|
226 | 219 |
|
227 |
| -MaybeDocumentMap FSTTestDocUpdates(const std::vector<MaybeDocument> &docs) { |
228 |
| - MaybeDocumentMap updates; |
229 |
| - for (const MaybeDocument &doc : docs) { |
230 |
| - updates = updates.insert(doc.key(), doc); |
231 |
| - } |
232 |
| - return updates; |
233 |
| -} |
234 |
| - |
235 |
| -absl::optional<ViewSnapshot> FSTTestApplyChanges(View *view, |
236 |
| - const std::vector<MaybeDocument> &docs, |
237 |
| - const absl::optional<TargetChange> &targetChange) { |
238 |
| - ViewChange change = |
239 |
| - view->ApplyChanges(view->ComputeDocumentChanges(FSTTestDocUpdates(docs)), targetChange); |
240 |
| - return change.snapshot(); |
241 |
| -} |
242 |
| - |
243 |
| -RemoteEvent FSTTestAddedRemoteEvent(const MaybeDocument &doc, |
244 |
| - const std::vector<TargetId> &addedToTargets) { |
245 |
| - std::vector<MaybeDocument> docs{doc}; |
246 |
| - return FSTTestAddedRemoteEvent(docs, addedToTargets); |
247 |
| -} |
248 |
| - |
249 |
| -RemoteEvent FSTTestAddedRemoteEvent(const std::vector<MaybeDocument> &docs, |
250 |
| - const std::vector<TargetId> &addedToTargets) { |
251 |
| - HARD_ASSERT(!docs.empty(), "Cannot pass empty docs array"); |
252 |
| - |
253 |
| - const ResourcePath &collectionPath = docs[0].key().path().PopLast(); |
254 |
| - auto metadataProvider = |
255 |
| - FakeTargetMetadataProvider::CreateEmptyResultProvider(collectionPath, addedToTargets); |
256 |
| - WatchChangeAggregator aggregator{&metadataProvider}; |
257 |
| - for (const MaybeDocument &doc : docs) { |
258 |
| - HARD_ASSERT(!doc.is_document() || !Document(doc).has_local_mutations(), |
259 |
| - "Docs from remote updates shouldn't have local changes."); |
260 |
| - DocumentWatchChange change{addedToTargets, {}, doc.key(), doc}; |
261 |
| - aggregator.HandleDocumentChange(change); |
262 |
| - } |
263 |
| - return aggregator.CreateRemoteEvent(docs[0].version()); |
264 |
| -} |
265 |
| - |
266 |
| -TargetChange FSTTestTargetChangeMarkCurrent() { |
267 |
| - return {ByteString(), |
268 |
| - /*current=*/true, |
269 |
| - /*added_documents=*/DocumentKeySet{}, |
270 |
| - /*modified_documents=*/DocumentKeySet{}, |
271 |
| - /*removed_documents=*/DocumentKeySet{}}; |
272 |
| -} |
273 |
| - |
274 |
| -TargetChange FSTTestTargetChangeAckDocuments(DocumentKeySet docs) { |
275 |
| - return {ByteString(), |
276 |
| - /*current=*/true, |
277 |
| - /*added_documents*/ std::move(docs), |
278 |
| - /*modified_documents*/ DocumentKeySet{}, |
279 |
| - /*removed_documents*/ DocumentKeySet{}}; |
280 |
| -} |
281 |
| - |
282 |
| -RemoteEvent FSTTestUpdateRemoteEventWithLimboTargets( |
283 |
| - const MaybeDocument &doc, |
284 |
| - const std::vector<TargetId> &updatedInTargets, |
285 |
| - const std::vector<TargetId> &removedFromTargets, |
286 |
| - const std::vector<TargetId> &limboTargets) { |
287 |
| - HARD_ASSERT(!doc.is_document() || !Document(doc).has_local_mutations(), |
288 |
| - "Docs from remote updates shouldn't have local changes."); |
289 |
| - DocumentWatchChange change{updatedInTargets, removedFromTargets, doc.key(), doc}; |
290 |
| - |
291 |
| - std::vector<TargetId> listens = updatedInTargets; |
292 |
| - listens.insert(listens.end(), removedFromTargets.begin(), removedFromTargets.end()); |
293 |
| - |
294 |
| - auto metadataProvider = |
295 |
| - FakeTargetMetadataProvider::CreateSingleResultProvider(doc.key(), listens, limboTargets); |
296 |
| - WatchChangeAggregator aggregator{&metadataProvider}; |
297 |
| - aggregator.HandleDocumentChange(change); |
298 |
| - return aggregator.CreateRemoteEvent(doc.version()); |
299 |
| -} |
300 |
| - |
301 |
| -RemoteEvent FSTTestUpdateRemoteEvent(const MaybeDocument &doc, |
302 |
| - const std::vector<TargetId> &updatedInTargets, |
303 |
| - const std::vector<TargetId> &removedFromTargets) { |
304 |
| - return FSTTestUpdateRemoteEventWithLimboTargets(doc, updatedInTargets, removedFromTargets, {}); |
305 |
| -} |
306 |
| - |
307 |
| -/** Creates a resume token to match the given snapshot version. */ |
308 |
| -NSData *_Nullable FSTTestResumeTokenFromSnapshotVersion(FSTTestSnapshotVersion snapshotVersion) { |
309 |
| - if (snapshotVersion == 0) { |
310 |
| - return nil; |
311 |
| - } |
312 |
| - |
313 |
| - NSString *snapshotString = [NSString stringWithFormat:@"snapshot-%" PRId64, snapshotVersion]; |
314 |
| - return [snapshotString dataUsingEncoding:NSUTF8StringEncoding]; |
315 |
| -} |
316 |
| - |
317 |
| -LocalViewChanges TestViewChanges(TargetId targetID, |
318 |
| - NSArray<NSString *> *addedKeys, |
319 |
| - NSArray<NSString *> *removedKeys) { |
320 |
| - DocumentKeySet added; |
321 |
| - for (NSString *keyPath in addedKeys) { |
322 |
| - added = added.insert(testutil::Key(util::MakeString(keyPath))); |
323 |
| - } |
324 |
| - DocumentKeySet removed; |
325 |
| - for (NSString *keyPath in removedKeys) { |
326 |
| - removed = removed.insert(testutil::Key(util::MakeString(keyPath))); |
327 |
| - } |
328 |
| - return LocalViewChanges(targetID, std::move(added), std::move(removed)); |
329 |
| -} |
330 |
| - |
331 | 220 | NS_ASSUME_NONNULL_END
|
0 commit comments