Skip to content

Commit

Permalink
revert datasnapshot (#1156)
Browse files Browse the repository at this point in the history
  • Loading branch information
colerogers committed Jun 28, 2022
1 parent 139e1d9 commit a00ad92
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 195 deletions.
143 changes: 9 additions & 134 deletions spec/v1/providers/database.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -639,52 +639,17 @@ describe('Database Functions', () => {
expect(subject.val()).to.equal(0);
populate({ myKey: 0 });
expect(subject.val()).to.deep.equal({ myKey: 0 });

// Null values are still reported as null.
populate({ myKey: null });
expect(subject.val()).to.deep.equal({ myKey: null });
});

// Regression test: .val() was returning array of nulls when there's a property called length (BUG#37683995)
it('should return correct values when data has "length" property', () => {
populate({ length: 3, foo: 'bar' });
expect(subject.val()).to.deep.equal({ length: 3, foo: 'bar' });
});

it('should deal with null-values appropriately', () => {
populate(null);
expect(subject.val()).to.be.null;

populate({ myKey: null });
expect(subject.val()).to.be.null;
});

it('should deal with empty object values appropriately', () => {
populate({});
expect(subject.val()).to.be.null;

populate({ myKey: {} });
expect(subject.val()).to.be.null;

populate({ myKey: { child: null } });
expect(subject.val()).to.be.null;
});

it('should deal with empty array values appropriately', () => {
populate([]);
expect(subject.val()).to.be.null;

populate({ myKey: [] });
expect(subject.val()).to.be.null;

populate({ myKey: [null] });
expect(subject.val()).to.be.null;

populate({ myKey: [{}] });
expect(subject.val()).to.be.null;

populate({ myKey: [{ myKey: null }] });
expect(subject.val()).to.be.null;

populate({ myKey: [{ myKey: {} }] });
expect(subject.val()).to.be.null;
});
});

describe('#child(): DataSnapshot', () => {
Expand All @@ -711,37 +676,14 @@ describe('Database Functions', () => {
});

it('should be false for a non-existent value', () => {
populate({ a: { b: 'c', nullChild: null } });
populate({ a: { b: 'c' } });
expect(subject.child('d').exists()).to.be.false;
expect(subject.child('nullChild').exists()).to.be.false;
});

it('should be false for a value pathed beyond a leaf', () => {
populate({ a: { b: 'c' } });
expect(subject.child('a/b/c').exists()).to.be.false;
});

it('should be false for an empty object value', () => {
populate({ a: {} });
expect(subject.child('a').exists()).to.be.false;

populate({ a: { child: null } });
expect(subject.child('a').exists()).to.be.false;

populate({ a: { child: {} } });
expect(subject.child('a').exists()).to.be.false;
});

it('should be false for an empty array value', () => {
populate({ a: [] });
expect(subject.child('a').exists()).to.be.false;

populate({ a: [null] });
expect(subject.child('a').exists()).to.be.false;

populate({ a: [{}] });
expect(subject.child('a').exists()).to.be.false;
});
});

describe('#forEach(action: (a: DataSnapshot) => boolean): boolean', () => {
Expand Down Expand Up @@ -770,17 +712,6 @@ describe('Database Functions', () => {

expect(subject.forEach(counter)).to.equal(false);
expect(count).to.eq(0);

populate({
a: 'foo',
nullChild: null,
emptyObjectChild: {},
emptyArrayChild: [],
});
count = 0;

expect(subject.forEach(counter)).to.equal(false);
expect(count).to.eq(1);
});

it('should cancel further enumeration if callback returns true', () => {
Expand Down Expand Up @@ -820,51 +751,13 @@ describe('Database Functions', () => {

describe('#numChildren()', () => {
it('should be key count for objects', () => {
populate({
a: 'b',
c: 'd',
nullChild: null,
emptyObjectChild: {},
emptyArrayChild: [],
});
populate({ a: 'b', c: 'd' });
expect(subject.numChildren()).to.eq(2);
});

it('should be 0 for non-objects', () => {
populate(23);
expect(subject.numChildren()).to.eq(0);

populate({
nullChild: null,
emptyObjectChild: {},
emptyArrayChild: [],
});
expect(subject.numChildren()).to.eq(0);
});
});

describe('#hasChildren()', () => {
it('should true for objects', () => {
populate({
a: 'b',
c: 'd',
nullChild: null,
emptyObjectChild: {},
emptyArrayChild: [],
});
expect(subject.hasChildren()).to.be.true;
});

it('should be false for non-objects', () => {
populate(23);
expect(subject.hasChildren()).to.be.false;

populate({
nullChild: null,
emptyObjectChild: {},
emptyArrayChild: [],
});
expect(subject.hasChildren()).to.be.false;
});
});

Expand All @@ -876,17 +769,9 @@ describe('Database Functions', () => {
});

it('should return false if a child is missing', () => {
populate({
a: 'b',
nullChild: null,
emptyObjectChild: {},
emptyArrayChild: [],
});
populate({ a: 'b' });
expect(subject.hasChild('c')).to.be.false;
expect(subject.hasChild('a/b')).to.be.false;
expect(subject.hasChild('nullChild')).to.be.false;
expect(subject.hasChild('emptyObjectChild')).to.be.false;
expect(subject.hasChild('emptyArrayChild')).to.be.false;
});
});

Expand Down Expand Up @@ -916,21 +801,11 @@ describe('Database Functions', () => {

describe('#toJSON(): Object', () => {
it('should return the current value', () => {
populate({
a: 'b',
nullChild: null,
emptyObjectChild: {},
emptyArrayChild: [],
});
populate({ a: 'b' });
expect(subject.toJSON()).to.deep.equal(subject.val());
});
it('should be stringifyable', () => {
populate({
a: 'b',
nullChild: null,
emptyObjectChild: {},
emptyArrayChild: [],
});
populate({ a: 'b' });
expect(JSON.stringify(subject)).to.deep.equal('{"a":"b"}');
});
});
Expand Down

0 comments on commit a00ad92

Please sign in to comment.