Skip to content

Commit

Permalink
fix(database): fixes modular imports exports (#7916)
Browse files Browse the repository at this point in the history
Co-authored-by: russellwheatley <[email protected]>
  • Loading branch information
younes0 and russellwheatley authored Jul 29, 2024
1 parent 5689f24 commit 7022204
Show file tree
Hide file tree
Showing 6 changed files with 249 additions and 14 deletions.
220 changes: 219 additions & 1 deletion packages/database/__tests__/database.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,50 @@
import { describe, expect, it } from '@jest/globals';

import database, { firebase } from '../lib';
import database, {
firebase,
runTransaction,
getDatabase,
connectDatabaseEmulator,
goOffline,
goOnline,
ref,
refFromURL,
setPersistenceEnabled,
setLoggingEnabled,
setPersistenceCacheSizeBytes,
forceLongPolling,
forceWebSockets,
getServerTime,
serverTimestamp,
increment,
endAt,
endBefore,
startAt,
startAfter,
limitToFirst,
limitToLast,
orderByChild,
orderByKey,
orderByPriority,
orderByValue,
equalTo,
query,
onValue,
onChildAdded,
onChildChanged,
onChildMoved,
onChildRemoved,
set,
setPriority,
setWithPriority,
get,
child,
onDisconnect,
keepSynced,
push,
remove,
update,
} from '../lib';

describe('Database', function () {
describe('namespace', function () {
Expand Down Expand Up @@ -45,4 +89,178 @@ describe('Database', function () {
expect(bar).toEqual(['10.0.2.2', 9000]);
});
});

describe('modular', function () {
it('`onValue` query method is properly exposed to end user', function () {
expect(onValue).toBeDefined();
});

it('`runTransaction` transaction method is properly exposed to end user', function () {
expect(runTransaction).toBeDefined();
});

it('`getDatabase` function is properly exposed to end user', function () {
expect(getDatabase).toBeDefined();
});

it('`connectDatabaseEmulator` function is properly exposed to end user', function () {
expect(connectDatabaseEmulator).toBeDefined();
});

it('`goOffline` function is properly exposed to end user', function () {
expect(goOffline).toBeDefined();
});

it('`goOnline` function is properly exposed to end user', function () {
expect(goOnline).toBeDefined();
});

it('`ref` function is properly exposed to end user', function () {
expect(ref).toBeDefined();
});

it('`refFromURL` function is properly exposed to end user', function () {
expect(refFromURL).toBeDefined();
});

it('`setPersistenceEnabled` function is properly exposed to end user', function () {
expect(setPersistenceEnabled).toBeDefined();
});

it('`setLoggingEnabled` function is properly exposed to end user', function () {
expect(setLoggingEnabled).toBeDefined();
});

it('`setPersistenceCacheSizeBytes` function is properly exposed to end user', function () {
expect(setPersistenceCacheSizeBytes).toBeDefined();
});

it('`forceLongPolling` function is properly exposed to end user', function () {
expect(forceLongPolling).toBeDefined();
});

it('`forceWebSockets` function is properly exposed to end user', function () {
expect(forceWebSockets).toBeDefined();
});

it('`getServerTime` function is properly exposed to end user', function () {
expect(getServerTime).toBeDefined();
});

it('`serverTimestamp` function is properly exposed to end user', function () {
expect(serverTimestamp).toBeDefined();
});

it('`increment` function is properly exposed to end user', function () {
expect(increment).toBeDefined();
});

it('`endAt` function is properly exposed to end user', function () {
expect(endAt).toBeDefined();
});

it('`endBefore` function is properly exposed to end user', function () {
expect(endBefore).toBeDefined();
});

it('`startAt` function is properly exposed to end user', function () {
expect(startAt).toBeDefined();
});

it('`startAfter` function is properly exposed to end user', function () {
expect(startAfter).toBeDefined();
});

it('`limitToFirst` function is properly exposed to end user', function () {
expect(limitToFirst).toBeDefined();
});

it('`limitToLast` function is properly exposed to end user', function () {
expect(limitToLast).toBeDefined();
});

it('`orderByChild` function is properly exposed to end user', function () {
expect(orderByChild).toBeDefined();
});

it('`orderByKey` function is properly exposed to end user', function () {
expect(orderByKey).toBeDefined();
});

it('`orderByPriority` function is properly exposed to end user', function () {
expect(orderByPriority).toBeDefined();
});

it('`orderByValue` function is properly exposed to end user', function () {
expect(orderByValue).toBeDefined();
});

it('`equalTo` function is properly exposed to end user', function () {
expect(equalTo).toBeDefined();
});

it('`query` function is properly exposed to end user', function () {
expect(query).toBeDefined();
});

it('`onValue` function is properly exposed to end user', function () {
expect(onValue).toBeDefined();
});

it('`onChildAdded` function is properly exposed to end user', function () {
expect(onChildAdded).toBeDefined();
});

it('`onChildChanged` function is properly exposed to end user', function () {
expect(onChildChanged).toBeDefined();
});

it('`onChildMoved` function is properly exposed to end user', function () {
expect(onChildMoved).toBeDefined();
});

it('`onChildRemoved` function is properly exposed to end user', function () {
expect(onChildRemoved).toBeDefined();
});

it('`set` function is properly exposed to end user', function () {
expect(set).toBeDefined();
});

it('`setPriority` function is properly exposed to end user', function () {
expect(setPriority).toBeDefined();
});

it('`setWithPriority` function is properly exposed to end user', function () {
expect(setWithPriority).toBeDefined();
});

it('`get` function is properly exposed to end user', function () {
expect(get).toBeDefined();
});

it('`child` function is properly exposed to end user', function () {
expect(child).toBeDefined();
});

it('`onDisconnect` function is properly exposed to end user', function () {
expect(onDisconnect).toBeDefined();
});

it('`keepSynced` function is properly exposed to end user', function () {
expect(keepSynced).toBeDefined();
});

it('`push` function is properly exposed to end user', function () {
expect(push).toBeDefined();
});

it('`remove` function is properly exposed to end user', function () {
expect(remove).toBeDefined();
});

it('`update` function is properly exposed to end user', function () {
expect(update).toBeDefined();
});
});
});
15 changes: 15 additions & 0 deletions packages/database/e2e/DatabaseStatics.e2e.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,13 @@ describe('database.X', function () {
TIMESTAMP.should.have.property('.sv');
TIMESTAMP['.sv'].should.eql('timestamp');
});

it('populates the property with a Unix timestamp', async function () {
const ref = firebase.database().ref(`${TEST_PATH}/timestamp`);
await ref.set(firebase.database.ServerValue.TIMESTAMP);
const snapshot = await ref.once('value');
snapshot.val().should.be.a.Number();
});
});

describe('ServerValue.increment', function () {
Expand Down Expand Up @@ -81,6 +88,14 @@ describe('database.X', function () {
timestamp.should.have.property('.sv');
timestamp['.sv'].should.eql('timestamp');
});

it('populates the property with a Unix timestamp', async function () {
const { serverTimestamp, getDatabase, ref, set } = databaseModular;
const dbRef = ref(getDatabase(), `${TEST_PATH}/timestamp`);
await set(dbRef, serverTimestamp());
const snapshot = await dbRef.once('value');
snapshot.val().should.be.a.Number();
});
});

describe('increment', function () {
Expand Down
2 changes: 2 additions & 0 deletions packages/database/lib/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1295,6 +1295,8 @@ export const firebase: ReactNativeFirebase.Module & {
): ReactNativeFirebase.FirebaseApp & { database(): FirebaseDatabaseTypes.Module };
};

export * from './modular';

export default defaultExport;

/**
Expand Down
7 changes: 7 additions & 0 deletions packages/database/lib/modular/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,10 @@ export declare function forceWebSockets(): void;
*/
export function serverTimestamp(): object;

/**
* Returns the current Firebase Database server time as a JavaScript Date object.
*/
export function getServerTime(db: Database): Promise<number>;
/**
* Returns a placeholder value that can be used to atomically increment the
* current database value by the provided delta.
Expand All @@ -215,3 +219,6 @@ export function serverTimestamp(): object;
* @returns A placeholder value for modifying data atomically server-side.
*/
export function increment(delta: number): object;

export * from './query';
export * from './transaction';
13 changes: 4 additions & 9 deletions packages/database/lib/modular/query.d.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,9 @@
import { FirebaseDatabaseTypes } from '../..';

import Query = FirebaseDatabaseTypes.Query;
import DataSnapshot = FirebaseDatabaseTypes.DataSnapshot;
import DatabaseReference = FirebaseDatabaseTypes.Reference;
import OnDisconnect = FirebaseDatabaseTypes.OnDisconnect;

export type Query = Query;
export type DataSnapshot = DataSnapshot;
export type DatabaseReference = DatabaseReference;
export type OnDisconnect = OnDisconnect;
export type Query = FirebaseDatabaseTypes.Query;
export type DataSnapshot = FirebaseDatabaseTypes.DataSnapshot;
export type DatabaseReference = FirebaseDatabaseTypes.Reference;
export type OnDisconnect = FirebaseDatabaseTypes.OnDisconnect;

/**
* A `Promise` that can also act as a `DatabaseReference` when returned by
Expand Down
6 changes: 2 additions & 4 deletions packages/database/lib/modular/transaction.d.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
import { FirebaseDatabaseTypes } from '../../index';
import { FirebaseDatabaseTypes } from '../..';

import TransactionResult = FirebaseDatabaseTypes.TransactionResult;
export type TransactionResult = FirebaseDatabaseTypes.TransactionResult;
import DatabaseReference = FirebaseDatabaseTypes.Reference;

export { TransactionResult };

/**
* An options object to configure transactions.
*/
Expand Down

0 comments on commit 7022204

Please sign in to comment.