aboutsummaryrefslogtreecommitdiffhomepage
path: root/Firestore/Example/Tests/Util/FSTIntegrationTestCase.h
blob: 585d99a15d7a39f1025df405382fad2578778d83 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
/*
 * Copyright 2017 Google
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#import <Foundation/Foundation.h>
#import <XCTest/XCTest.h>

#import "Firestore/Example/Tests/Util/XCTestCase+Await.h"
#import "Firestore/Source/Core/FSTTypes.h"

#import "FIRFirestoreSource.h"

@class FIRCollectionReference;
@class FIRDocumentSnapshot;
@class FIRDocumentReference;
@class FIRQuerySnapshot;
@class FIRFirestore;
@class FIRFirestoreSettings;
@class FIRQuery;
@class FSTEventAccumulator;
@class FSTDispatchQueue;

NS_ASSUME_NONNULL_BEGIN

#if __cplusplus
extern "C" {
#endif

@interface FSTIntegrationTestCase : XCTestCase

/** Returns the default Firestore project ID for testing. */
+ (NSString *)projectID;

/** Returns a FirestoreSettings configured to use either hexa or the emulator. */
+ (FIRFirestoreSettings *)settings;

/** Returns a new Firestore connected to the "test-db" project. */
- (FIRFirestore *)firestore;

/** Returns a new Firestore connected to the project with the given projectID. */
- (FIRFirestore *)firestoreWithProjectID:(NSString *)projectID;

/** Synchronously shuts down the given firestore. */
- (void)shutdownFirestore:(FIRFirestore *)firestore;

- (NSString *)documentPath;

- (FIRDocumentReference *)documentRef;

- (FIRCollectionReference *)collectionRef;

- (FIRCollectionReference *)collectionRefWithDocuments:
    (NSDictionary<NSString *, NSDictionary<NSString *, id> *> *)documents;

- (void)writeAllDocuments:(NSDictionary<NSString *, NSDictionary<NSString *, id> *> *)documents
             toCollection:(FIRCollectionReference *)collection;

- (void)readerAndWriterOnDocumentRef:(void (^)(NSString *path,
                                               FIRDocumentReference *readerRef,
                                               FIRDocumentReference *writerRef))action;

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

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

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

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

- (FIRDocumentSnapshot *)readSnapshotForRef:(FIRDocumentReference *)query
                              requireOnline:(BOOL)online;

- (void)writeDocumentRef:(FIRDocumentReference *)ref data:(NSDictionary<NSString *, id> *)data;

- (void)updateDocumentRef:(FIRDocumentReference *)ref data:(NSDictionary<NSString *, id> *)data;

- (void)deleteDocumentRef:(FIRDocumentReference *)ref;

- (void)mergeDocumentRef:(FIRDocumentReference *)ref data:(NSDictionary<NSString *, id> *)data;

- (void)disableNetwork;

- (void)enableNetwork;

- (FSTDispatchQueue *)queueForFirestore:(FIRFirestore *)firestore;

/**
 * "Blocks" the current thread/run loop until the block returns YES.
 * Should only be called on the main thread.
 * The block is invoked frequently and in a loop (every couple of milliseconds) to ensure fast
 * test progress and make sure actions to be run on main thread are not blocked by this method.
 */
- (void)waitUntil:(BOOL (^)())predicate;

@property(nonatomic, strong) FIRFirestore *db;
@property(nonatomic, strong) FSTEventAccumulator *eventAccumulator;
@end

/** Converts the FIRQuerySnapshot to an NSArray containing the data of the documents in order. */
NSArray<NSDictionary<NSString *, id> *> *FIRQuerySnapshotGetData(FIRQuerySnapshot *docs);

/** Converts the FIRQuerySnapshot to an NSArray containing the document IDs in order. */
NSArray<NSString *> *FIRQuerySnapshotGetIDs(FIRQuerySnapshot *docs);

/** Converts the FIRQuerySnapshot to an NSArray containing an NSArray containing the doc change data
 * in order of { type, doc title, doc data }. */
NSArray<NSArray<id> *> *FIRQuerySnapshotGetDocChangesData(FIRQuerySnapshot *docs);

#if __cplusplus
}  // extern "C"
#endif

NS_ASSUME_NONNULL_END