@@ -33,15 +33,17 @@ chai.use(chaiAsPromised);
33
33
const expect = chai . expect ;
34
34
35
35
describe ( 'Firestore' , ( ) => {
36
- let mockApp : App ;
36
+ let mockAppOne : App ;
37
+ let mockAppTwo : App ;
37
38
let mockCredentialApp : App ;
38
39
39
40
const noProjectIdError = 'Failed to initialize Google Cloud Firestore client with the '
40
41
+ 'available credentials. Must initialize the SDK with a certificate credential or '
41
42
+ 'application default credentials to use Cloud Firestore API.' ;
42
43
43
44
beforeEach ( ( ) => {
44
- mockApp = mocks . app ( ) ;
45
+ mockAppOne = mocks . app ( ) ;
46
+ mockAppTwo = mocks . app ( ) ;
45
47
mockCredentialApp = mocks . mockCredentialApp ( ) ;
46
48
} ) ;
47
49
@@ -61,26 +63,26 @@ describe('Firestore', () => {
61
63
62
64
it ( 'should not throw given a valid app' , ( ) => {
63
65
expect ( ( ) => {
64
- return getFirestore ( mockApp ) ;
66
+ return getFirestore ( mockAppOne ) ;
65
67
} ) . not . to . throw ( ) ;
66
68
} ) ;
67
69
68
70
it ( 'should return the same instance for a given app instance' , ( ) => {
69
- const db1 : Firestore = getFirestore ( mockApp ) ;
70
- const db2 : Firestore = getFirestore ( mockApp , DEFAULT_DATABASE_ID ) ;
71
+ const db1 : Firestore = getFirestore ( mockAppOne ) ;
72
+ const db2 : Firestore = getFirestore ( mockAppOne , DEFAULT_DATABASE_ID ) ;
71
73
expect ( db1 ) . to . equal ( db2 ) ;
72
74
} ) ;
73
75
74
76
it ( 'should return the same instance for a given app instance and databaseId' , ( ) => {
75
- const db1 : Firestore = getFirestore ( mockApp , 'db' ) ;
76
- const db2 : Firestore = getFirestore ( mockApp , 'db' ) ;
77
+ const db1 : Firestore = getFirestore ( mockAppOne , 'db' ) ;
78
+ const db2 : Firestore = getFirestore ( mockAppOne , 'db' ) ;
77
79
expect ( db1 ) . to . equal ( db2 ) ;
78
80
} ) ;
79
81
80
82
it ( 'should return the different instance for given same app instance, but different databaseId' , ( ) => {
81
- const db0 : Firestore = getFirestore ( mockApp , DEFAULT_DATABASE_ID ) ;
82
- const db1 : Firestore = getFirestore ( mockApp , 'db1' ) ;
83
- const db2 : Firestore = getFirestore ( mockApp , 'db2' ) ;
83
+ const db0 : Firestore = getFirestore ( mockAppOne , DEFAULT_DATABASE_ID ) ;
84
+ const db1 : Firestore = getFirestore ( mockAppOne , 'db1' ) ;
85
+ const db2 : Firestore = getFirestore ( mockAppOne , 'db2' ) ;
84
86
expect ( db0 ) . to . not . equal ( db1 ) ;
85
87
expect ( db0 ) . to . not . equal ( db2 ) ;
86
88
expect ( db1 ) . to . not . equal ( db2 ) ;
@@ -97,41 +99,65 @@ describe('Firestore', () => {
97
99
98
100
it ( 'should not throw given a valid app' , ( ) => {
99
101
expect ( ( ) => {
100
- return initializeFirestore ( mockApp ) ;
102
+ return initializeFirestore ( mockAppOne ) ;
101
103
} ) . not . to . throw ( ) ;
102
104
} ) ;
103
105
104
106
it ( 'should return the same instance for a given app instance' , ( ) => {
105
- const db1 : Firestore = initializeFirestore ( mockApp ) ;
106
- const db2 : Firestore = initializeFirestore ( mockApp , { } , DEFAULT_DATABASE_ID ) ;
107
+ const db1 : Firestore = initializeFirestore ( mockAppOne ) ;
108
+ const db2 : Firestore = initializeFirestore ( mockAppOne , { } , DEFAULT_DATABASE_ID ) ;
109
+
110
+ const db3 : Firestore = initializeFirestore ( mockAppTwo , { preferRest : true } ) ;
111
+ const db4 : Firestore = initializeFirestore ( mockAppTwo , { preferRest : true } , DEFAULT_DATABASE_ID ) ;
112
+
107
113
expect ( db1 ) . to . equal ( db2 ) ;
114
+ expect ( db3 ) . to . equal ( db4 ) ;
108
115
} ) ;
109
116
110
117
it ( 'should return the same instance for a given app instance and databaseId' , ( ) => {
111
- const db1 : Firestore = initializeFirestore ( mockApp , { } , 'db' ) ;
112
- const db2 : Firestore = initializeFirestore ( mockApp , { } , 'db' ) ;
118
+ const db1 : Firestore = initializeFirestore ( mockAppOne , { } , 'db' ) ;
119
+ const db2 : Firestore = initializeFirestore ( mockAppOne , { } , 'db' ) ;
120
+
121
+ const db3 : Firestore = initializeFirestore ( mockAppTwo , { preferRest : true } , 'db' ) ;
122
+ const db4 : Firestore = initializeFirestore ( mockAppTwo , { preferRest : true } , 'db' ) ;
123
+
113
124
expect ( db1 ) . to . equal ( db2 ) ;
125
+ expect ( db3 ) . to . equal ( db4 ) ;
114
126
} ) ;
115
127
116
- it ( 'should return the different instance for given same app instance, but different databaseId' , ( ) => {
117
- const db0 : Firestore = initializeFirestore ( mockApp , { } , DEFAULT_DATABASE_ID ) ;
118
- const db1 : Firestore = initializeFirestore ( mockApp , { } , 'db1' ) ;
119
- const db2 : Firestore = initializeFirestore ( mockApp , { } , 'db2' ) ;
128
+ it ( 'should return a different instance for given same app instance, but different databaseId' , ( ) => {
129
+ const db0 : Firestore = initializeFirestore ( mockAppOne , { } , DEFAULT_DATABASE_ID ) ;
130
+ const db1 : Firestore = initializeFirestore ( mockAppOne , { } , 'db1' ) ;
131
+ const db2 : Firestore = initializeFirestore ( mockAppOne , { } , 'db2' ) ;
132
+
133
+ const db3 : Firestore = initializeFirestore ( mockAppTwo , { preferRest : true } , DEFAULT_DATABASE_ID ) ;
134
+ const db4 : Firestore = initializeFirestore ( mockAppTwo , { preferRest : true } , 'db1' ) ;
135
+ const db5 : Firestore = initializeFirestore ( mockAppTwo , { preferRest : true } , 'db2' ) ;
136
+
120
137
expect ( db0 ) . to . not . equal ( db1 ) ;
121
138
expect ( db0 ) . to . not . equal ( db2 ) ;
122
139
expect ( db1 ) . to . not . equal ( db2 ) ;
140
+
141
+ expect ( db3 ) . to . not . equal ( db4 ) ;
142
+ expect ( db3 ) . to . not . equal ( db5 ) ;
143
+ expect ( db4 ) . to . not . equal ( db5 ) ;
123
144
} ) ;
124
145
125
146
it ( 'getFirestore should return the same instance as initializeFirestore returned earlier' , ( ) => {
126
- const db1 : Firestore = initializeFirestore ( mockApp , { } , 'db' ) ;
127
- const db2 : Firestore = getFirestore ( mockApp , 'db' ) ;
147
+ const db1 : Firestore = initializeFirestore ( mockAppOne , { } , 'db' ) ;
148
+ const db2 : Firestore = getFirestore ( mockAppOne , 'db' ) ;
149
+
150
+ const db3 : Firestore = initializeFirestore ( mockAppTwo , { preferRest : true } ) ;
151
+ const db4 : Firestore = getFirestore ( mockAppTwo ) ;
152
+
128
153
expect ( db1 ) . to . equal ( db2 ) ;
154
+ expect ( db3 ) . to . equal ( db4 ) ;
129
155
} ) ;
130
156
131
157
it ( 'initializeFirestore should not allow create an instance with different settings' , ( ) => {
132
- initializeFirestore ( mockApp , { } , 'db' ) ;
158
+ initializeFirestore ( mockAppTwo , { } , 'db' ) ;
133
159
expect ( ( ) => {
134
- return initializeFirestore ( mockApp , { preferRest : true } , 'db' ) ;
160
+ return initializeFirestore ( mockAppTwo , { preferRest : true } , 'db' ) ;
135
161
} ) . to . throw ( / h a s a l r e a d y b e e n c a l l e d w i t h d i f f e r e n t o p t i o n s / ) ;
136
162
} ) ;
137
163
} ) ;
0 commit comments