react-native-firebase/bridge/e2e/database/ref/set.e2e.js

53 lines
1.6 KiB
JavaScript
Raw Normal View History

2018-04-22 15:04:35 +00:00
const { setDatabaseContents, CONTENTS } = TestHelpers.database;
describe('database()', () => {
beforeEach(() => setDatabaseContents());
describe('ref.set()', () => {
it('returns a promise', async () => {
const ref = firebase.database().ref('tests/types/number');
const returnValue = ref.set(CONTENTS.DEFAULT.number);
returnValue.should.be.Promise();
const value = await returnValue;
(value === null).should.be.true();
});
it('changes value', async () => {
await Promise.all(
Object.keys(CONTENTS.DEFAULT).map(async dataRef => {
const previousValue = bridge.contextify(CONTENTS.DEFAULT[dataRef]);
const ref = firebase.database().ref(`tests/types/${dataRef}`);
const snapshot = await ref.once('value');
snapshot.val().should.eql(previousValue);
const newValue = bridge.contextify(CONTENTS.NEW[dataRef]);
await ref.set(newValue);
const snapshot2 = await ref.once('value');
snapshot2.val().should.eql(newValue);
})
);
});
it('can unset values', async () => {
await Promise.all(
Object.keys(CONTENTS.DEFAULT).map(async dataRef => {
const previousValue = bridge.contextify(CONTENTS.DEFAULT[dataRef]);
const ref = firebase.database().ref(`tests/types/${dataRef}`);
const snapshot = await ref.once('value');
snapshot.val().should.eql(previousValue);
await ref.set(null);
const snapshot2 = await ref.once('value');
(snapshot2.val() === null).should.be.true();
})
);
});
});
});