Skip to content

Commit 8d0a11d

Browse files
committed
getPrivateSettings and tests
1 parent 464c68e commit 8d0a11d

File tree

3 files changed

+46
-3
lines changed

3 files changed

+46
-3
lines changed

packages/firestore/src/lite-api/database.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,11 @@ export class Firestore implements FirestoreService {
130130
}
131131
}
132132

133-
_getSettings(): PrivateSettings {
133+
_getSettings(): FirestoreSettingsImpl {
134+
return this._settings;
135+
}
136+
137+
_getPrivateSettings(): PrivateSettings {
134138
const privateSettings: PrivateSettings = {
135139
...this._settings,
136140
emulatorOptions: this._emulatorOptions
@@ -328,7 +332,7 @@ export function connectFirestoreEmulator(
328332
} = {}
329333
): void {
330334
firestore = cast(firestore, Firestore);
331-
const settings = firestore._getSettings();
335+
const settings = firestore._getPrivateSettings();
332336
const newHostSetting = `${host}:${port}`;
333337

334338
if (settings.host !== DEFAULT_HOST && settings.host !== newHostSetting) {

packages/firestore/test/integration/api/validation.test.ts

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,7 @@ apiDescribe('Validation:', persistence => {
179179

180180
validationIt(
181181
persistence,
182-
'disallows calling connectFirestoreEmulator() after use',
182+
'disallows calling connectFirestoreEmulator() for first time after use',
183183
async db => {
184184
const errorMsg =
185185
'Firestore has already been started and its settings can no longer be changed.';
@@ -191,6 +191,32 @@ apiDescribe('Validation:', persistence => {
191191
}
192192
);
193193

194+
validationIt(
195+
persistence,
196+
'allows calling connectFirestoreEmulator() after use with same config',
197+
async db => {
198+
connectFirestoreEmulator(db, '127.0.0.1', 9000);
199+
await setDoc(doc(db, 'foo/bar'), {});
200+
expect(() =>
201+
connectFirestoreEmulator(db, '127.0.0.1', 9000)
202+
).to.not.throw();
203+
}
204+
);
205+
206+
validationIt(
207+
persistence,
208+
'disallows calling connectFirestoreEmulator() after use with different config',
209+
async db => {
210+
const errorMsg =
211+
'Firestore has already been started and its settings can no longer be changed.';
212+
connectFirestoreEmulator(db, '127.0.0.1', 9000);
213+
await setDoc(doc(db, 'foo/bar'), {});
214+
expect(() => connectFirestoreEmulator(db, '127.0.0.1', 9001)).to.throw(
215+
errorMsg
216+
);
217+
}
218+
);
219+
194220
validationIt(
195221
persistence,
196222
'connectFirestoreEmulator() can set mockUserToken object',

packages/firestore/test/unit/api/database.test.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -553,6 +553,19 @@ describe('Settings', () => {
553553
expect(db._getSettings().ssl).to.be.false;
554554
});
555555

556+
it('gets privateSettings from useEmulator', () => {
557+
// Use a new instance of Firestore in order to configure settings.
558+
const db = newTestFirestore();
559+
const emulatorOptions = { mockUserToken: 'test' };
560+
connectFirestoreEmulator(db, '127.0.0.1', 9000, emulatorOptions);
561+
562+
expect(db._getPrivateSettings().host).to.exist.and.to.equal(
563+
'127.0.0.1:9000'
564+
);
565+
expect(db._getPrivateSettings().ssl).to.exist.and.to.be.false;
566+
expect(db._getPrivateSettings().emulatorOptions).to.equal(emulatorOptions);
567+
});
568+
556569
it('prefers host from useEmulator to host from settings', () => {
557570
// Use a new instance of Firestore in order to configure settings.
558571
const db = newTestFirestore();

0 commit comments

Comments
 (0)