From 093280c732b4cef10d6bdd1731f9029a84c4b8c6 Mon Sep 17 00:00:00 2001 From: Salakar Date: Sun, 22 Apr 2018 02:04:18 +0100 Subject: [PATCH] [tests][database] more snapshot tests --- bridge/e2e/database/snapshot.e2e.js | 147 ++++++++++-------------- bridge/e2e/database/transactions.e2e.js | 2 +- 2 files changed, 61 insertions(+), 88 deletions(-) diff --git a/bridge/e2e/database/snapshot.e2e.js b/bridge/e2e/database/snapshot.e2e.js index 635d3968..7e8dff77 100644 --- a/bridge/e2e/database/snapshot.e2e.js +++ b/bridge/e2e/database/snapshot.e2e.js @@ -1,19 +1,18 @@ const { setDatabaseContents } = TestHelpers.database; +// TODO use testRunId in refs to prevent multiple test instances interfering with each other describe('database()', () => { describe('Snapshot', () => { before(() => setDatabaseContents()); it('should provide a functioning val() method', async () => { - const { Array } = bridge.context.window; const snapshot = await firebase .database() .ref('tests/types/array') .once('value'); snapshot.val.should.be.a.Function(); - // eslint-disable-next-line - snapshot.val().should.eql(new Array(0, 1, 2, 3, 4, 5, 6, 7, 8, 9)); + snapshot.val().should.eql(bridge.Array([0, 1, 2, 3, 4, 5, 6, 7, 8, 9])); }); it('should provide a functioning child() method', async () => { @@ -32,100 +31,74 @@ describe('database()', () => { }); // TODO refactor - // it('should provide a functioning hasChild() method', () => - // new Promise((resolve, reject) => { - // const successCb = tryCatch(snapshot => { - // snapshot.hasChild.should.be.a.Function(); - // snapshot.hasChild('foo').should.equal(true); - // snapshot.hasChild('baz').should.equal(false); - // resolve(); - // }, reject); + it('should provide a functioning hasChild() method', async () => { + const snapshot = await firebase + .database() + .ref('tests/types/object') + .once('value'); - // firebase - // .database() - // .ref('tests/types/object') - // .once('value', successCb, reject); - // })); + snapshot.hasChild.should.be.a.Function(); + snapshot.hasChild('foo').should.equal(true); + snapshot.hasChild('baz').should.equal(false); + }); - // it('should provide a functioning hasChildren() method', () => - // new Promise((resolve, reject) => { - // const successCb = tryCatch(snapshot => { - // snapshot.hasChildren.should.be.a.Function(); - // snapshot.hasChildren().should.equal(true); - // snapshot - // .child('foo') - // .hasChildren() - // .should.equal(false); - // resolve(); - // }, reject); + it('should provide a functioning hasChildren() method', async () => { + const snapshot = await firebase + .database() + .ref('tests/types/object') + .once('value'); - // firebase - // .database() - // .ref('tests/types/object') - // .once('value', successCb, reject); - // })); + snapshot.hasChildren.should.be.a.Function(); + snapshot.hasChildren().should.equal(true); + snapshot + .child('foo') + .hasChildren() + .should.equal(false); + }); - // it('should provide a functioning exists() method', () => - // new Promise((resolve, reject) => { - // const successCb = tryCatch(snapshot => { - // snapshot.exists.should.be.a.Function(); - // snapshot.exists().should.equal(false); - // resolve(); - // }, reject); + it('should provide a functioning exists() method', async () => { + const snapshot = await firebase + .database() + .ref('tests/types/object/baz/daz') + .once('value'); - // firebase - // .database() - // .ref('tests/types/object/baz/daz') - // .once('value', successCb, reject); - // })); + snapshot.exists.should.be.a.Function(); + snapshot.exists().should.equal(false); + }); - // it('should provide a functioning getPriority() method', () => - // new Promise((resolve, reject) => { - // const successCb = tryCatch(snapshot => { - // snapshot.getPriority.should.be.a.Function(); - // snapshot.getPriority().should.equal(666); - // snapshot.val().should.eql({ foo: 'bar' }); - // resolve(); - // }, reject); + it('should provide a functioning getPriority() method', async () => { + const ref = firebase.database().ref('tests/priority'); + const snapshot = await ref.once('value'); + snapshot.getPriority.should.be.a.Function(); + snapshot.getPriority().should.equal(666); + snapshot.val().should.eql(bridge.Object({ foo: 'bar' })); + }); - // const ref = firebase.database().ref('tests/priority'); - // ref.once('value', successCb, reject); - // })); + it('should provide a functioning forEach() method', async () => { + const snapshot = await firebase + .database() + .ref('tests/types/array') + .once('value'); - // it('should provide a functioning forEach() method', () => - // // TODO this doesn't really test that the key order returned is in correct order - // new Promise((resolve, reject) => { - // const successCb = tryCatch(snapshot => { - // let total = 0; - // snapshot.forEach.should.be.a.Function(); - // snapshot.forEach(childSnapshot => { - // const val = childSnapshot.val(); - // total += val; - // return val === 3; // stop iteration after key 3 - // }); + let total = 0; + snapshot.forEach.should.be.a.Function(); + snapshot.forEach(childSnapshot => { + const val = childSnapshot.val(); + total += val; + return val === 3; // stop iteration after key 3 + }); - // total.should.equal(6); // 0 + 1 + 2 + 3 = 6 - // resolve(); - // }, reject); + total.should.equal(6); // 0 + 1 + 2 + 3 = 6 + }); - // firebase - // .database() - // .ref('tests/types/array') - // .once('value', successCb, reject); - // })); + it('should provide a key property', async () => { + const snapshot = await firebase + .database() + .ref('tests/types/array') + .once('value'); - // it('should provide a key property', () => - // new Promise((resolve, reject) => { - // const successCb = tryCatch(snapshot => { - // snapshot.key.should.be.a.String(); - // snapshot.key.should.equal('array'); - // resolve(); - // }, reject); - - // firebase - // .database() - // .ref('tests/types/array') - // .once('value', successCb, reject); - // })); + snapshot.key.should.be.a.String(); + snapshot.key.should.equal('array'); + }); }); }); diff --git a/bridge/e2e/database/transactions.e2e.js b/bridge/e2e/database/transactions.e2e.js index 5149f49f..046d10f4 100644 --- a/bridge/e2e/database/transactions.e2e.js +++ b/bridge/e2e/database/transactions.e2e.js @@ -1,8 +1,8 @@ const { setDatabaseContents } = TestHelpers.database; +// TODO use testRunId in refs to prevent multiple test instances interfering with each other describe('database()', () => { before(() => setDatabaseContents()); - // TODO use testRunId in refs to prevent multiple test instances interfering with each other describe('ref.transaction()', () => { it('increments a value', async () => { let valueBefore = 1;