Skip to content

s/FIRGetSource/FIRFirestoreSource/ #1087

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

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions Firestore/Example/SwiftBuildTest/main.swift
Original file line number Diff line number Diff line change
Expand Up @@ -219,11 +219,11 @@ func readDocument(at docRef: DocumentReference) {
}

func readDocumentWithOptions(at docRef: DocumentReference) {
docRef.getDocument(source: Source.default) { document, error in
docRef.getDocument(source: FirestoreSource.default) { document, error in
}
docRef.getDocument(source: .server) { document, error in
}
docRef.getDocument(source: Source.cache) { document, error in
docRef.getDocument(source: FirestoreSource.cache) { document, error in
}
}

Expand All @@ -238,11 +238,11 @@ func readDocuments(matching query: Query) {
}

func readDocumentsWithOptions(matching query: Query) {
query.getDocuments(source: Source.default) { querySnapshot, error in
query.getDocuments(source: FirestoreSource.default) { querySnapshot, error in
}
query.getDocuments(source: .server) { querySnapshot, error in
}
query.getDocuments(source: Source.cache) { querySnapshot, error in
query.getDocuments(source: FirestoreSource.cache) { querySnapshot, error in
}
}

Expand Down
48 changes: 24 additions & 24 deletions Firestore/Example/Tests/Integration/API/FIRSourceTests.mm
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,10 @@
#import "Firestore/Source/API/FIRFirestore+Internal.h"
#import "Firestore/Source/Core/FSTFirestoreClient.h"

@interface FIRGetSourceTests : FSTIntegrationTestCase
@interface FIRFirestoreSourceTests : FSTIntegrationTestCase
@end

@implementation FIRGetSourceTests
@implementation FIRFirestoreSourceTests

- (void)testGetDocumentWhileOnlineWithDefaultSource {
FIRDocumentReference *doc = [self documentRef];
Expand Down Expand Up @@ -144,7 +144,7 @@ - (void)testGetDocumentWhileOnlineCacheOnly {

// get doc and ensure that it exists, *is* from the cache, and matches
// the initialData.
FIRDocumentSnapshot *result = [self readDocumentForRef:doc source:FIRGetSourceCache];
FIRDocumentSnapshot *result = [self readDocumentForRef:doc source:FIRFirestoreSourceCache];
XCTAssertTrue(result.exists);
XCTAssertTrue(result.metadata.fromCache);
XCTAssertFalse(result.metadata.hasPendingWrites);
Expand All @@ -164,7 +164,7 @@ - (void)testGetCollectionWhileOnlineCacheOnly {

// get docs and ensure they *are* from the cache, and matches the
// initialDocs.
FIRQuerySnapshot *result = [self readDocumentSetForRef:col source:FIRGetSourceCache];
FIRQuerySnapshot *result = [self readDocumentSetForRef:col source:FIRFirestoreSourceCache];
XCTAssertTrue(result.metadata.fromCache);
XCTAssertFalse(result.metadata.hasPendingWrites);
XCTAssertEqualObjects(FIRQuerySnapshotGetData(result), (@[
Expand Down Expand Up @@ -200,7 +200,7 @@ - (void)testGetDocumentWhileOfflineCacheOnly {

// get doc and ensure it exists, *is* from the cache, and matches the
// newData.
FIRDocumentSnapshot *result = [self readDocumentForRef:doc source:FIRGetSourceCache];
FIRDocumentSnapshot *result = [self readDocumentForRef:doc source:FIRFirestoreSourceCache];
XCTAssertTrue(result.exists);
XCTAssertTrue(result.metadata.fromCache);
XCTAssertTrue(result.metadata.hasPendingWrites);
Expand Down Expand Up @@ -230,7 +230,7 @@ - (void)testGetCollectionWhileOfflineCacheOnly {

// get docs and ensure they *are* from the cache, and matches the updated
// data.
FIRQuerySnapshot *result = [self readDocumentSetForRef:col source:FIRGetSourceCache];
FIRQuerySnapshot *result = [self readDocumentSetForRef:col source:FIRFirestoreSourceCache];
XCTAssertTrue(result.metadata.fromCache);
XCTAssertTrue(result.metadata.hasPendingWrites);
XCTAssertEqualObjects(FIRQuerySnapshotGetData(result), (@[
Expand All @@ -255,7 +255,7 @@ - (void)testGetDocumentWhileOnlineServerOnly {

// get doc and ensure that it exists, is *not* from the cache, and matches
// the initialData.
FIRDocumentSnapshot *result = [self readDocumentForRef:doc source:FIRGetSourceServer];
FIRDocumentSnapshot *result = [self readDocumentForRef:doc source:FIRFirestoreSourceServer];
XCTAssertTrue(result.exists);
XCTAssertFalse(result.metadata.fromCache);
XCTAssertFalse(result.metadata.hasPendingWrites);
Expand All @@ -275,7 +275,7 @@ - (void)testGetCollectionWhileOnlineServerOnly {

// get docs and ensure they are *not* from the cache, and matches the
// initialData.
FIRQuerySnapshot *result = [self readDocumentSetForRef:col source:FIRGetSourceServer];
FIRQuerySnapshot *result = [self readDocumentSetForRef:col source:FIRFirestoreSourceServer];
XCTAssertFalse(result.metadata.fromCache);
XCTAssertFalse(result.metadata.hasPendingWrites);
XCTAssertEqualObjects(FIRQuerySnapshotGetData(result), (@[
Expand All @@ -302,7 +302,7 @@ - (void)testGetDocumentWhileOfflineServerOnly {

// attempt to get doc and ensure it cannot be retreived
XCTestExpectation *failedGetDocCompletion = [self expectationWithDescription:@"failedGetDoc"];
[doc getDocumentWithSource:FIRGetSourceServer
[doc getDocumentWithSource:FIRFirestoreSourceServer
completion:^(FIRDocumentSnapshot *snapshot, NSError *error) {
XCTAssertNotNil(error);
XCTAssertEqualObjects(error.domain, FIRFirestoreErrorDomain);
Expand All @@ -328,7 +328,7 @@ - (void)testGetCollectionWhileOfflineServerOnly {

// attempt to get docs and ensure they cannot be retreived
XCTestExpectation *failedGetDocsCompletion = [self expectationWithDescription:@"failedGetDocs"];
[col getDocumentsWithSource:FIRGetSourceServer
[col getDocumentsWithSource:FIRFirestoreSourceServer
completion:^(FIRQuerySnapshot *snapshot, NSError *error) {
XCTAssertNotNil(error);
XCTAssertEqualObjects(error.domain, FIRFirestoreErrorDomain);
Expand Down Expand Up @@ -367,22 +367,22 @@ - (void)testGetDocumentWhileOfflineWithDifferentSource {

// get doc (from cache) and ensure it exists, *is* from the cache, and
// matches the newData.
FIRDocumentSnapshot *result = [self readDocumentForRef:doc source:FIRGetSourceCache];
FIRDocumentSnapshot *result = [self readDocumentForRef:doc source:FIRFirestoreSourceCache];
XCTAssertTrue(result.exists);
XCTAssertTrue(result.metadata.fromCache);
XCTAssertTrue(result.metadata.hasPendingWrites);
XCTAssertEqualObjects(result.data, newData);

// attempt to get doc (with default get source)
result = [self readDocumentForRef:doc source:FIRGetSourceDefault];
result = [self readDocumentForRef:doc source:FIRFirestoreSourceDefault];
XCTAssertTrue(result.exists);
XCTAssertTrue(result.metadata.fromCache);
XCTAssertTrue(result.metadata.hasPendingWrites);
XCTAssertEqualObjects(result.data, newData);

// attempt to get doc (from the server) and ensure it cannot be retreived
XCTestExpectation *failedGetDocCompletion = [self expectationWithDescription:@"failedGetDoc"];
[doc getDocumentWithSource:FIRGetSourceServer
[doc getDocumentWithSource:FIRFirestoreSourceServer
completion:^(FIRDocumentSnapshot *snapshot, NSError *error) {
XCTAssertNotNil(error);
XCTAssertEqualObjects(error.domain, FIRFirestoreErrorDomain);
Expand Down Expand Up @@ -424,7 +424,7 @@ - (void)testGetCollectionWhileOfflineWithDifferentSource {

// get docs (from cache) and ensure they *are* from the cache, and
// matches the updated data.
FIRQuerySnapshot *result = [self readDocumentSetForRef:col source:FIRGetSourceCache];
FIRQuerySnapshot *result = [self readDocumentSetForRef:col source:FIRFirestoreSourceCache];
XCTAssertTrue(result.metadata.fromCache);
XCTAssertTrue(result.metadata.hasPendingWrites);
XCTAssertEqualObjects(FIRQuerySnapshotGetData(result), (@[
Expand All @@ -440,7 +440,7 @@ - (void)testGetCollectionWhileOfflineWithDifferentSource {
]));

// attempt to get docs (with default get source)
result = [self readDocumentSetForRef:col source:FIRGetSourceDefault];
result = [self readDocumentSetForRef:col source:FIRFirestoreSourceDefault];
XCTAssertTrue(result.metadata.fromCache);
XCTAssertEqualObjects(FIRQuerySnapshotGetData(result), (@[
@{@"key1" : @"value1"}, @{@"key2" : @"value2", @"key2b" : @"value2b"},
Expand All @@ -456,7 +456,7 @@ - (void)testGetCollectionWhileOfflineWithDifferentSource {

// attempt to get docs (from the server) and ensure they cannot be retreived
XCTestExpectation *failedGetDocsCompletion = [self expectationWithDescription:@"failedGetDocs"];
[col getDocumentsWithSource:FIRGetSourceServer
[col getDocumentsWithSource:FIRFirestoreSourceServer
completion:^(FIRQuerySnapshot *snapshot, NSError *error) {
XCTAssertNotNil(error);
XCTAssertEqualObjects(error.domain, FIRFirestoreErrorDomain);
Expand Down Expand Up @@ -529,7 +529,7 @@ - (void)testGetNonExistingDocWhileOnlineCacheOnly {
// certain documents *don't* exist.
XCTestExpectation *getNonExistingDocCompletion =
[self expectationWithDescription:@"getNonExistingDoc"];
[doc getDocumentWithSource:FIRGetSourceCache
[doc getDocumentWithSource:FIRFirestoreSourceCache
completion:^(FIRDocumentSnapshot *snapshot, NSError *error) {
XCTAssertNotNil(error);
XCTAssertEqualObjects(error.domain, FIRFirestoreErrorDomain);
Expand All @@ -543,7 +543,7 @@ - (void)testGetNonExistingCollectionWhileOnlineCacheOnly {
FIRCollectionReference *col = [self collectionRef];

// get collection and ensure it's empty and that it *is* from the cache.
FIRQuerySnapshot *snapshot = [self readDocumentSetForRef:col source:FIRGetSourceCache];
FIRQuerySnapshot *snapshot = [self readDocumentSetForRef:col source:FIRFirestoreSourceCache];
XCTAssertEqual(snapshot.count, 0);
XCTAssertEqual(snapshot.documentChanges.count, 0);
XCTAssertTrue(snapshot.metadata.fromCache);
Expand All @@ -561,7 +561,7 @@ - (void)testGetNonExistingDocWhileOfflineCacheOnly {
// certain documents *don't* exist.
XCTestExpectation *getNonExistingDocCompletion =
[self expectationWithDescription:@"getNonExistingDoc"];
[doc getDocumentWithSource:FIRGetSourceCache
[doc getDocumentWithSource:FIRFirestoreSourceCache
completion:^(FIRDocumentSnapshot *snapshot, NSError *error) {
XCTAssertNotNil(error);
XCTAssertEqualObjects(error.domain, FIRFirestoreErrorDomain);
Expand All @@ -578,7 +578,7 @@ - (void)testGetNonExistingCollectionWhileOfflineCacheOnly {
[self disableNetwork];

// get collection and ensure it's empty and that it *is* from the cache.
FIRQuerySnapshot *snapshot = [self readDocumentSetForRef:col source:FIRGetSourceCache];
FIRQuerySnapshot *snapshot = [self readDocumentSetForRef:col source:FIRFirestoreSourceCache];
XCTAssertEqual(snapshot.count, 0);
XCTAssertEqual(snapshot.documentChanges.count, 0);
XCTAssertTrue(snapshot.metadata.fromCache);
Expand All @@ -589,7 +589,7 @@ - (void)testGetNonExistingDocWhileOnlineServerOnly {
FIRDocumentReference *doc = [self documentRef];

// get doc and ensure that it does not exist and is *not* from the cache.
FIRDocumentSnapshot *snapshot = [self readDocumentForRef:doc source:FIRGetSourceServer];
FIRDocumentSnapshot *snapshot = [self readDocumentForRef:doc source:FIRFirestoreSourceServer];
XCTAssertFalse(snapshot.exists);
XCTAssertFalse(snapshot.metadata.fromCache);
XCTAssertFalse(snapshot.metadata.hasPendingWrites);
Expand All @@ -599,7 +599,7 @@ - (void)testGetNonExistingCollectionWhileOnlineServerOnly {
FIRCollectionReference *col = [self collectionRef];

// get collection and ensure that it's empty and that it's *not* from the cache.
FIRQuerySnapshot *snapshot = [self readDocumentSetForRef:col source:FIRGetSourceServer];
FIRQuerySnapshot *snapshot = [self readDocumentSetForRef:col source:FIRFirestoreSourceServer];
XCTAssertEqual(snapshot.count, 0);
XCTAssertEqual(snapshot.documentChanges.count, 0);
XCTAssertFalse(snapshot.metadata.fromCache);
Expand All @@ -617,7 +617,7 @@ - (void)testGetNonExistingDocWhileOfflineServerOnly {
// certain documents *don't* exist.
XCTestExpectation *getNonExistingDocCompletion =
[self expectationWithDescription:@"getNonExistingDoc"];
[doc getDocumentWithSource:FIRGetSourceServer
[doc getDocumentWithSource:FIRFirestoreSourceServer
completion:^(FIRDocumentSnapshot *snapshot, NSError *error) {
XCTAssertNotNil(error);
XCTAssertEqualObjects(error.domain, FIRFirestoreErrorDomain);
Expand All @@ -635,7 +635,7 @@ - (void)testGetNonExistingCollectionWhileOfflineServerOnly {

// attempt to get collection and ensure that it cannot be retreived
XCTestExpectation *failedGetDocsCompletion = [self expectationWithDescription:@"failedGetDocs"];
[col getDocumentsWithSource:FIRGetSourceServer
[col getDocumentsWithSource:FIRFirestoreSourceServer
completion:^(FIRQuerySnapshot *snapshot, NSError *error) {
XCTAssertNotNil(error);
XCTAssertEqualObjects(error.domain, FIRFirestoreErrorDomain);
Expand Down
7 changes: 4 additions & 3 deletions Firestore/Example/Tests/Util/FSTIntegrationTestCase.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
#import "Firestore/Example/Tests/Util/XCTestCase+Await.h"
#import "Firestore/Source/Core/FSTTypes.h"

#import "FIRGetSource.h"
#import "FIRFirestoreSource.h"

@class FIRCollectionReference;
@class FIRDocumentSnapshot;
Expand Down Expand Up @@ -73,11 +73,12 @@ extern "C" {

- (FIRDocumentSnapshot *)readDocumentForRef:(FIRDocumentReference *)ref;

- (FIRDocumentSnapshot *)readDocumentForRef:(FIRDocumentReference *)ref source:(FIRGetSource)source;
- (FIRDocumentSnapshot *)readDocumentForRef:(FIRDocumentReference *)ref
source:(FIRFirestoreSource)source;

- (FIRQuerySnapshot *)readDocumentSetForRef:(FIRQuery *)query;

- (FIRQuerySnapshot *)readDocumentSetForRef:(FIRQuery *)query source:(FIRGetSource)source;
- (FIRQuerySnapshot *)readDocumentSetForRef:(FIRQuery *)query source:(FIRFirestoreSource)source;

- (FIRDocumentSnapshot *)readSnapshotForRef:(FIRDocumentReference *)query
requireOnline:(BOOL)online;
Expand Down
8 changes: 4 additions & 4 deletions Firestore/Example/Tests/Util/FSTIntegrationTestCase.mm
Original file line number Diff line number Diff line change
Expand Up @@ -210,11 +210,11 @@ - (void)readerAndWriterOnDocumentRef:(void (^)(NSString *path,
}

- (FIRDocumentSnapshot *)readDocumentForRef:(FIRDocumentReference *)ref {
return [self readDocumentForRef:ref source:FIRGetSourceDefault];
return [self readDocumentForRef:ref source:FIRFirestoreSourceDefault];
}

- (FIRDocumentSnapshot *)readDocumentForRef:(FIRDocumentReference *)ref
source:(FIRGetSource)source {
source:(FIRFirestoreSource)source {
__block FIRDocumentSnapshot *result;

XCTestExpectation *expectation = [self expectationWithDescription:@"getData"];
Expand All @@ -230,10 +230,10 @@ - (FIRDocumentSnapshot *)readDocumentForRef:(FIRDocumentReference *)ref
}

- (FIRQuerySnapshot *)readDocumentSetForRef:(FIRQuery *)query {
return [self readDocumentSetForRef:query source:FIRGetSourceDefault];
return [self readDocumentSetForRef:query source:FIRFirestoreSourceDefault];
}

- (FIRQuerySnapshot *)readDocumentSetForRef:(FIRQuery *)query source:(FIRGetSource)source {
- (FIRQuerySnapshot *)readDocumentSetForRef:(FIRQuery *)query source:(FIRFirestoreSource)source {
__block FIRQuerySnapshot *result;

XCTestExpectation *expectation = [self expectationWithDescription:@"getData"];
Expand Down
30 changes: 16 additions & 14 deletions Firestore/Source/API/FIRDocumentReference.mm
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
#import <GRPCClient/GRPCCall.h>

#import "FIRFirestoreErrors.h"
#import "FIRGetSource.h"
#import "FIRFirestoreSource.h"
#import "FIRSnapshotMetadata.h"
#import "Firestore/Source/API/FIRCollectionReference+Internal.h"
#import "Firestore/Source/API/FIRDocumentReference+Internal.h"
Expand Down Expand Up @@ -207,13 +207,13 @@ - (void)deleteDocumentWithCompletion:(nullable void (^)(NSError *_Nullable error

- (void)getDocumentWithCompletion:(void (^)(FIRDocumentSnapshot *_Nullable document,
NSError *_Nullable error))completion {
return [self getDocumentWithSource:FIRGetSourceDefault completion:completion];
return [self getDocumentWithSource:FIRFirestoreSourceDefault completion:completion];
}

- (void)getDocumentWithSource:(FIRGetSource)source
- (void)getDocumentWithSource:(FIRFirestoreSource)source
completion:(void (^)(FIRDocumentSnapshot *_Nullable document,
NSError *_Nullable error))completion {
if (source == FIRGetSourceCache) {
if (source == FIRFirestoreSourceCache) {
[self.firestore.client getDocumentFromLocalCache:self completion:completion];
return;
}
Expand Down Expand Up @@ -252,16 +252,18 @@ - (void)getDocumentWithSource:(FIRGetSource)source
NSLocalizedDescriptionKey :
@"Failed to get document because the client is offline.",
}]);
} else if (snapshot.exists && snapshot.metadata.fromCache && source == FIRGetSourceServer) {
completion(nil, [NSError errorWithDomain:FIRFirestoreErrorDomain
code:FIRFirestoreErrorCodeUnavailable
userInfo:@{
NSLocalizedDescriptionKey :
@"Failed to get document from server. (However, this "
@"document does exist in the local cache. Run again "
@"without setting source to FIRGetSourceServer to "
@"retrieve the cached document.)"
}]);
} else if (snapshot.exists && snapshot.metadata.fromCache &&
source == FIRFirestoreSourceServer) {
completion(nil,
[NSError errorWithDomain:FIRFirestoreErrorDomain
code:FIRFirestoreErrorCodeUnavailable
userInfo:@{
NSLocalizedDescriptionKey :
@"Failed to get document from server. (However, this "
@"document does exist in the local cache. Run again "
@"without setting source to FIRFirestoreSourceServer to "
@"retrieve the cached document.)"
}]);
} else {
completion(snapshot, nil);
}
Expand Down
Loading