Skip to content

Commit

Permalink
Merge 106a0e3 into 48a77e3
Browse files Browse the repository at this point in the history
  • Loading branch information
milaGGL committed Mar 8, 2024
2 parents 48a77e3 + 106a0e3 commit b7a243d
Show file tree
Hide file tree
Showing 28 changed files with 7,138 additions and 37 deletions.
3 changes: 3 additions & 0 deletions Firestore/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
# Unreleased
- [feature] Enable snapshot listener option to retrieve data from local cache only. (#12370)

# 10.22.0
- [fixed] Fix the flaky offline behaviour when using `arrayRemove` on `Map` object. (#12378)

Expand Down
22 changes: 22 additions & 0 deletions Firestore/Example/Firestore.xcodeproj/project.pbxproj

Large diffs are not rendered by default.

19 changes: 18 additions & 1 deletion Firestore/Example/Tests/SpecTests/FSTSpecTests.mm
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
#include "Firestore/core/src/bundle/bundle_reader.h"
#include "Firestore/core/src/bundle/bundle_serializer.h"
#include "Firestore/core/src/core/field_filter.h"
#import "Firestore/core/src/core/listen_options.h"
#include "Firestore/core/src/credentials/user.h"
#include "Firestore/core/src/local/persistence.h"
#include "Firestore/core/src/local/target_data.h"
Expand Down Expand Up @@ -79,10 +80,12 @@
using firebase::firestore::Error;
using firebase::firestore::google_firestore_v1_ArrayValue;
using firebase::firestore::google_firestore_v1_Value;
using firebase::firestore::api::ListenSource;
using firebase::firestore::api::LoadBundleTask;
using firebase::firestore::bundle::BundleReader;
using firebase::firestore::bundle::BundleSerializer;
using firebase::firestore::core::DocumentViewChange;
using firebase::firestore::core::ListenOptions;
using firebase::firestore::core::Query;
using firebase::firestore::credentials::User;
using firebase::firestore::local::Persistence;
Expand Down Expand Up @@ -385,11 +388,25 @@ - (DocumentViewChange)parseChange:(NSDictionary *)jsonDoc ofType:(DocumentViewCh
return DocumentViewChange{std::move(doc), type};
}

- (ListenOptions)parseOptions:(NSDictionary *)optionsSpec {
ListenOptions options = ListenOptions::FromIncludeMetadataChanges(true);

if (optionsSpec != nil) {
ListenSource source =
[optionsSpec[@"source"] isEqual:@"cache"] ? ListenSource::Cache : ListenSource::Default;
// include_metadata_changes are default to true in spec tests
options = ListenOptions::FromOptions(true, source);
}

return options;
}

#pragma mark - Methods for doing the steps of the spec test.

- (void)doListen:(NSDictionary *)listenSpec {
Query query = [self parseQuery:listenSpec[@"query"]];
TargetId actualID = [self.driver addUserListenerWithQuery:std::move(query)];
ListenOptions options = [self parseOptions:listenSpec[@"options"]];
TargetId actualID = [self.driver addUserListenerWithQuery:std::move(query) options:options];

TargetId expectedID = [listenSpec[@"targetId"] intValue];
XCTAssertEqual(actualID, expectedID, @"targetID assigned to listen");
Expand Down
3 changes: 2 additions & 1 deletion Firestore/Example/Tests/SpecTests/FSTSyncEngineTestDriver.h
Original file line number Diff line number Diff line change
Expand Up @@ -146,9 +146,10 @@ typedef std::
* Resulting events are captured and made available via the capturedEventsSinceLastCall method.
*
* @param query A valid query to execute against the backend.
* @param options A listen option to configure snapshot listener.
* @return The target ID assigned by the system to track the query.
*/
- (model::TargetId)addUserListenerWithQuery:(core::Query)query;
- (model::TargetId)addUserListenerWithQuery:(core::Query)query options:(core::ListenOptions)options;

/**
* Removes a listener from the FSTSyncEngine as if the user had removed a listener corresponding
Expand Down
4 changes: 1 addition & 3 deletions Firestore/Example/Tests/SpecTests/FSTSyncEngineTestDriver.mm
Original file line number Diff line number Diff line change
Expand Up @@ -476,10 +476,8 @@ - (FSTOutstandingWrite *)receiveWriteError:(int)errorCode
return result;
}

- (TargetId)addUserListenerWithQuery:(Query)query {
// TODO(dimond): Allow customizing listen options in spec tests
- (TargetId)addUserListenerWithQuery:(Query)query options:(ListenOptions)options {
// TODO(dimond): Change spec tests to verify isFromCache on snapshots
ListenOptions options = ListenOptions::FromIncludeMetadataChanges(true);
auto listener = QueryListener::Create(
query, options, [self, query](const StatusOr<ViewSnapshot> &maybe_snapshot) {
FSTQueryEvent *event = [[FSTQueryEvent alloc] init];
Expand Down
Loading

0 comments on commit b7a243d

Please sign in to comment.