Skip to content

Re-enable database@exp tests #4731

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Apr 6, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
62 changes: 58 additions & 4 deletions packages/database/test/exp/integration.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,15 +27,15 @@ import {
ref,
refFromURL
} from '../../exp/index';
import { set } from '../../src/exp/Reference_impl';
import { onValue, set } from '../../src/exp/Reference_impl';
import { EventAccumulatorFactory } from '../helpers/EventAccumulator';
import { DATABASE_ADDRESS, DATABASE_URL } from '../helpers/util';

export function createTestApp() {
return initializeApp({ databaseURL: DATABASE_URL });
}

// TODO(database-exp): Re-enable these tests
describe.skip('Database Tests', () => {
describe('Database@exp Tests', () => {
let defaultApp;

beforeEach(() => {
Expand Down Expand Up @@ -65,7 +65,7 @@ describe.skip('Database Tests', () => {
expect(db.app).to.equal(defaultApp);
});

it('Can set and ge tref', async () => {
it('Can set and get ref', async () => {
const db = getDatabase(defaultApp);
await set(ref(db, 'foo/bar'), 'foobar');
const snap = await get(ref(db, 'foo/bar'));
Expand All @@ -77,6 +77,60 @@ describe.skip('Database Tests', () => {
await get(refFromURL(db, `${DATABASE_ADDRESS}/foo/bar`));
});

it('Can get updates', async () => {
const db = getDatabase(defaultApp);
const fooRef = ref(db, 'foo');

const ea = EventAccumulatorFactory.waitsForCount(2);
onValue(fooRef, snap => {
ea.addEvent(snap.val());
});

await set(fooRef, 'a');
await set(fooRef, 'b');

const [snap1, snap2] = await ea.promise;
expect(snap1).to.equal('a');
expect(snap2).to.equal('b');
});

it('Can use onlyOnce', async () => {
const db = getDatabase(defaultApp);
const fooRef = ref(db, 'foo');

const ea = EventAccumulatorFactory.waitsForCount(1);
onValue(
fooRef,
snap => {
ea.addEvent(snap.val());
},
{ onlyOnce: true }
);

await set(fooRef, 'a');
await set(fooRef, 'b');

const [snap1] = await ea.promise;
expect(snap1).to.equal('a');
});

it('Can unsubscribe', async () => {
const db = getDatabase(defaultApp);
const fooRef = ref(db, 'foo');

const ea = EventAccumulatorFactory.waitsForCount(1);
const unsubscribe = onValue(fooRef, snap => {
ea.addEvent(snap.val());
});

await set(fooRef, 'a');
unsubscribe();
await set(fooRef, 'b');

const [snap1] = await ea.promise;
expect(snap1).to.equal('a');
});

it('Can goOffline/goOnline', async () => {
const db = getDatabase(defaultApp);
goOffline(db);
Expand Down