Bug: server adapter accepted queryConstraints (orderBy/limit) but ignored them.
Combat log [orderBy('timestamp','desc'), limit(500)] returned ALL logs unordered
in server mode — unbounded growth. No test caught it: shared contract tested
subscribeCollection with 0 constraints; the firebase-only queryConstraint test
never touched the server adapter. Parity gap.
Fix (Plan A — neutral shape):
- index.js: orderBy()/limit() now NEUTRAL builders returning {__type}. Removed
SDK orderBy/limit re-export.
- firebase.js: subscribeCollection translates neutral -> SDK query constraints.
- server.js: applyConstraints() helper sorts/limits client-side (backend returns
all). Constraints stored per collection, applied on initial fetch + WS change.
- contract.js: added 3 queryConstraint tests (orderBy desc, limit, no-constraints)
to SHARED contract — both adapters now run identical assertions.
- firebase.contract.test.js: removed now-redundant firebase-only constraint
block (covered by shared contract).
Data impact: ZERO. Constraints are query-time only, never stored. Combat log
docs keep timestamp field. No Firebase data migration needed.
208 tests green.
22 lines
982 B
JavaScript
22 lines
982 B
JavaScript
// Firebase adapter contract test.
|
|
// Runs the SAME storage contract as server (src/storage/contract.js)
|
|
// against createFirebaseStorage. The SDK is mocked via src/__mocks__/firebase/*,
|
|
// so this proves the adapter translates contract calls -> SDK calls correctly
|
|
// (path handling, merge semantics, subscribe, queryConstraints) without network.
|
|
//
|
|
// queryConstraints (orderBy + limit) now tested in shared contract for BOTH
|
|
// adapters — no separate firebase-only block needed here.
|
|
|
|
import { initFirebase, createFirebaseStorage } from '../storage/firebase';
|
|
import { runStorageContract } from '../storage/contract';
|
|
import { resetMockDb } from '../__mocks__/firebase/_mock-db';
|
|
|
|
// Firebase mock DB is shared global state. Reset before each factory so
|
|
// contract tests are isolated.
|
|
runStorageContract('firebase', () => {
|
|
resetMockDb();
|
|
const ok = initFirebase();
|
|
if (!ok) throw new Error('initFirebase failed under mocked env');
|
|
return createFirebaseStorage();
|
|
});
|