Skip to content

Commit

Permalink
Added integration tests
Browse files Browse the repository at this point in the history
  • Loading branch information
DellaBitta committed Feb 5, 2025
1 parent 4c24b18 commit fc4f2b9
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 0 deletions.
39 changes: 39 additions & 0 deletions packages/database/test/exp/integration.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import { Deferred } from '@firebase/util';
import { expect, use } from 'chai';
import chaiAsPromised from 'chai-as-promised';

import { connectDatabaseEmulator } from '../../src/api/Database';
import {
child,
get,
Expand Down Expand Up @@ -48,6 +49,7 @@ import {
DATABASE_URL,
getFreshRepo,
getRWRefs,
isEmulatorActive,
waitFor,
waitUntil,
writeAndValidate
Expand Down Expand Up @@ -138,6 +140,43 @@ describe('Database@exp Tests', () => {
unsubscribe();
});

it('can connected to emulator', async () => {
if (isEmulatorActive()) {
const db = getDatabase(defaultApp);
connectDatabaseEmulator(db, 'localhost', 9000);
await get(refFromURL(db, `${DATABASE_ADDRESS}/foo/bar`));
}
});

it('can chnage emulator config before network operations', async () => {
if (isEmulatorActive()) {
const db = getDatabase(defaultApp);
connectDatabaseEmulator(db, 'localhost', 9001);
connectDatabaseEmulator(db, 'localhost', 9000);
await get(refFromURL(db, `${DATABASE_ADDRESS}/foo/bar`));
}
});

it('can connected to emulator after network operations with same parameters', async () => {
if (isEmulatorActive()) {
const db = getDatabase(defaultApp);
connectDatabaseEmulator(db, 'localhost', 9000);
await get(refFromURL(db, `${DATABASE_ADDRESS}/foo/bar`));
connectDatabaseEmulator(db, 'localhost', 9000);
}
});

it('cannot connect to emulator after network operations with different parameters', async () => {
if (isEmulatorActive()) {
const db = getDatabase(defaultApp);
connectDatabaseEmulator(db, 'localhost', 9000);
await get(refFromURL(db, `${DATABASE_ADDRESS}/foo/bar`));
expect(() => {
connectDatabaseEmulator(db, 'localhost', 9001);
}).to.throw();
}
});

it('can properly handle unknown deep merges', async () => {
// Note: This test requires `testIndex` to be added as an index.
// Please run `yarn test:setup` to ensure that this gets added.
Expand Down
4 changes: 4 additions & 0 deletions packages/database/test/helpers/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -143,3 +143,7 @@ export async function waitUntil(cb: () => boolean, maxRetries = 5) {
}
});
}

export function isEmulatorActive(): boolean {
return USE_EMULATOR;
}

0 comments on commit fc4f2b9

Please sign in to comment.