Skip to content

Commit d48fd18

Browse files
committed
Minor fixes
1 parent 311fbdb commit d48fd18

File tree

2 files changed

+15
-35
lines changed

2 files changed

+15
-35
lines changed

packages/remote-config/test/api.test.ts

Lines changed: 7 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,12 @@ const fakeFirebaseConfig = {
4949
appId: '1:111:web:a1234'
5050
};
5151

52+
const mockObserver = {
53+
next: sinon.stub(),
54+
error: sinon.stub(),
55+
complete: sinon.stub()
56+
};
57+
5258
async function clearDatabase(): Promise<void> {
5359
const db = await openDatabase();
5460
db.transaction([APP_NAMESPACE_STORE], 'readwrite')
@@ -184,48 +190,25 @@ describe('Remote Config API', () => {
184190
});
185191

186192
it('should call addObserver on the internal realtimeHandler', async () => {
187-
const mockObserver = {
188-
next: sinon.stub(),
189-
error: sinon.stub(),
190-
complete: sinon.stub()
191-
};
192193
await onConfigUpdate(rc, mockObserver);
193-
194194
expect(addObserverStub).to.have.been.calledOnce;
195195
expect(addObserverStub).to.have.been.calledWith(mockObserver);
196196
});
197197

198198
it('should return an unsubscribe function', async () => {
199-
const mockObserver = {
200-
next: sinon.stub(),
201-
error: sinon.stub(),
202-
complete: sinon.stub()
203-
};
204199
const unsubscribe = await onConfigUpdate(rc, mockObserver);
205-
206200
expect(unsubscribe).to.be.a('function');
207201
});
208202

209203
it('returned unsubscribe function should call removeObserver', async () => {
210-
const mockObserver = {
211-
next: sinon.stub(),
212-
error: sinon.stub(),
213-
complete: sinon.stub()
214-
};
215204
const unsubscribe = await onConfigUpdate(rc, mockObserver);
216205

217206
unsubscribe();
218-
219207
expect(removeObserverStub).to.have.been.calledOnce;
220208
expect(removeObserverStub).to.have.been.calledWith(mockObserver);
221209
});
222210

223211
it('observer.next should be called when realtimeHandler propagates an update', async () => {
224-
const mockObserver = {
225-
next: sinon.stub(),
226-
error: sinon.stub(),
227-
complete: sinon.stub()
228-
};
229212
await onConfigUpdate(rc, mockObserver);
230213

231214
if (capturedObserver && capturedObserver.next) {
@@ -245,11 +228,6 @@ describe('Remote Config API', () => {
245228
});
246229

247230
it('observer.error should be called when realtimeHandler propagates an error', async () => {
248-
const mockObserver = {
249-
next: sinon.stub(),
250-
error: sinon.stub(),
251-
complete: sinon.stub()
252-
};
253231
await onConfigUpdate(rc, mockObserver);
254232

255233
if (capturedObserver && capturedObserver.error) {
@@ -275,7 +253,7 @@ describe('Remote Config API', () => {
275253
'customData.originalErrorMessage',
276254
'Realtime stream error'
277255
);
278-
expect((receivedError as any).code).to.equal('remoteconfig/stream-error'); // Updated to expect the full prefixed code
256+
expect((receivedError as any).code).to.equal('remoteconfig/stream-error');
279257
});
280258
});
281259
});

packages/remote-config/test/client/realtime_handler.test.ts

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
* limitations under the License.
1616
*/
1717

18-
import { expect, use } from 'chai'; // FIX: Import 'use' from Chai.
18+
import { expect, use } from 'chai';
1919
import * as sinon from 'sinon';
2020
import sinonChai from 'sinon-chai';
2121
import { RealtimeHandler } from '../../src/client/realtime_handler';
@@ -154,9 +154,8 @@ describe('RealtimeHandler', () => {
154154
});
155155

156156
it('should set retries remaining from storage if available', async () => {
157-
sinon.restore(); // Restore to allow new constructor call
158157
mockStorage.getRealtimeBackoffMetadata.resolves({
159-
backoffEndTimeMillis: new Date(FAKE_NOW - 1000), // In the past, so no immediate backoff
158+
backoffEndTimeMillis: new Date(FAKE_NOW - 1000), // In the past, so no backoff
160159
numFailedStreams: 3
161160
});
162161

@@ -175,7 +174,7 @@ describe('RealtimeHandler', () => {
175174
await clock.runAllAsync();
176175
expect((realtime as any).httpRetriesRemaining).to.equal(
177176
ORIGINAL_RETRIES - 3
178-
); // 8 - 3 = 5
177+
);
179178
});
180179
});
181180

@@ -211,6 +210,7 @@ describe('RealtimeHandler', () => {
211210
});
212211

213212
it('should return false for non-retryable status codes', () => {
213+
// This is a sample of non-retryable codes for testing purposes.
214214
const nonRetryableCodes = [200, 304, 400, 401, 403];
215215
nonRetryableCodes.forEach(code => {
216216
expect((realtime as any).isStatusCodeRetryable(code)).to.be.false;
@@ -286,7 +286,8 @@ describe('RealtimeHandler', () => {
286286
expect(mockLogger.debug).to.have.been.calledWith(
287287
'Failed to cancel the reader, connection was lost.'
288288
);
289-
expect((realtime as any).reader).to.be.undefined; // Should still clear reader
289+
// Should still clear reader
290+
expect((realtime as any).reader).to.be.undefined;
290291
});
291292

292293
it('should handle being called when reader is already undefined', async () => {
@@ -372,7 +373,8 @@ describe('RealtimeHandler', () => {
372373

373374
it('should call makeRealtimeHttpConnection with calculated delay if backoff metadata exists', async () => {
374375
mockStorage.getRealtimeBackoffMetadata.resolves({
375-
backoffEndTimeMillis: new Date(FAKE_NOW + 5000), // 5 seconds in the future
376+
// 5 seconds in the future
377+
backoffEndTimeMillis: new Date(FAKE_NOW + 5000),
376378
numFailedStreams: 1
377379
});
378380
await (realtime as any).retryHttpConnectionWhenBackoffEnds();

0 commit comments

Comments
 (0)