Skip to content

Commit

Permalink
feat(database): Firebase V9 modular API (#7136)
Browse files Browse the repository at this point in the history
  • Loading branch information
exaby73 authored Sep 19, 2023
1 parent e3a93bc commit 21531f2
Show file tree
Hide file tree
Showing 51 changed files with 6,304 additions and 1,599 deletions.
115 changes: 86 additions & 29 deletions packages/database/e2e/DatabaseStatics.e2e.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,48 +20,105 @@ const { PATH, wipe } = require('./helpers');
const TEST_PATH = `${PATH}/statics`;

describe('database.X', function () {
after(function () {
return wipe(TEST_PATH);
});
describe('v8 compatibility', function () {
after(function () {
return wipe(TEST_PATH);
});

describe('ServerValue.TIMESTAMP', function () {
it('returns a valid object', function () {
const { TIMESTAMP } = firebase.database.ServerValue;
should.equal(Object.keys(TIMESTAMP).length, 1);
TIMESTAMP.should.have.property('.sv');
TIMESTAMP['.sv'].should.eql('timestamp');
});
});

describe('ServerValue.increment', function () {
it('returns a valid object', function () {
const incrementObject = firebase.database.ServerValue.increment(1);
should.equal(Object.keys(incrementObject).length, 1);
incrementObject.should.have.property('.sv');
incrementObject['.sv'].should.have.property('increment');
});

it('increments on the server', async function () {
const ref = firebase.database().ref(`${TEST_PATH}/increment`);

await ref.set({ increment: 0 });

const res1 = await ref.once('value');
res1.val().increment.should.equal(0);

await ref.set({ increment: firebase.database.ServerValue.increment(1) });

const res2 = await ref.once('value');
res2.val().increment.should.equal(1);
});

describe('ServerValue.TIMESTAMP', function () {
it('returns a valid object', function () {
const { TIMESTAMP } = firebase.database.ServerValue;
should.equal(Object.keys(TIMESTAMP).length, 1);
TIMESTAMP.should.have.property('.sv');
TIMESTAMP['.sv'].should.eql('timestamp');
it('increments on the server when no value is present', async function () {
const ref = firebase.database().ref(`${TEST_PATH}/increment-empty`);

await ref.set({ increment: firebase.database.ServerValue.increment(2) });

const res = await ref.once('value');
res.val().increment.should.equal(2);
});
});
});

describe('ServerValue.increment', function () {
it('returns a valid object', function () {
const incrementObject = firebase.database.ServerValue.increment(1);
should.equal(Object.keys(incrementObject).length, 1);
incrementObject.should.have.property('.sv');
incrementObject['.sv'].should.have.property('increment');
describe('modular', function () {
after(function () {
return wipe(TEST_PATH);
});

it('increments on the server', async function () {
const ref = firebase.database().ref(`${TEST_PATH}/increment`);
describe('serverTimestamp', function () {
it('returns a valid object', function () {
const { serverTimestamp } = databaseModular;
const timestamp = serverTimestamp();

await ref.set({ increment: 0 });
should.equal(Object.keys(timestamp).length, 1);
timestamp.should.have.property('.sv');
timestamp['.sv'].should.eql('timestamp');
});
});

const res1 = await ref.once('value');
res1.val().increment.should.equal(0);
describe('increment', function () {
it('returns a valid object', function () {
const { increment } = databaseModular;

await ref.set({ increment: firebase.database.ServerValue.increment(1) });
const incrementObject = increment(1);
should.equal(Object.keys(incrementObject).length, 1);
incrementObject.should.have.property('.sv');
incrementObject['.sv'].should.have.property('increment');
});

const res2 = await ref.once('value');
res2.val().increment.should.equal(1);
});
it('increments on the server', async function () {
const { getDatabase, ref, set, get, increment } = databaseModular;

const dbRef = ref(getDatabase(), `${TEST_PATH}/increment`);

await set(dbRef, { increment: 0 });

const res1 = await get(dbRef);
res1.val().increment.should.equal(0);

await set(dbRef, { increment: increment(1) });

const res2 = await get(dbRef);
res2.val().increment.should.equal(1);
});

it('increments on the server when no value is present', async function () {
const { getDatabase, ref, set, get, increment } = databaseModular;

it('increments on the server when no value is present', async function () {
const ref = firebase.database().ref(`${TEST_PATH}/increment-empty`);
const dbRef = ref(getDatabase(), `${TEST_PATH}/increment-empty`);

await ref.set({ increment: firebase.database.ServerValue.increment(2) });
await set(dbRef, { increment: increment(2) });

const res = await ref.once('value');
res.val().increment.should.equal(2);
const res = await get(dbRef);
res.val().increment.should.equal(2);
});
});
});
});
Loading

1 comment on commit 21531f2

@vercel
Copy link

@vercel vercel bot commented on 21531f2 Sep 19, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.