Skip to content

Commit

Permalink
added tests
Browse files Browse the repository at this point in the history
  • Loading branch information
christophe-g committed Jan 13, 2018
1 parent ab634d9 commit 7290611
Show file tree
Hide file tree
Showing 3 changed files with 71 additions and 0 deletions.
1 change: 1 addition & 0 deletions firebase-query.html
Expand Up @@ -340,6 +340,7 @@
}.bind(this))

this.set('data', data);
this._setExists(true);
}

const query = this.query
Expand Down
53 changes: 53 additions & 0 deletions test/firebase-document.html
Expand Up @@ -65,6 +65,59 @@
});
}
});

function pushFirebaseValue(path, value) {
return firebase.app('test').database().ref(path).push(value);
}

function clearFirebaseValue(path) {
return firebase.app('test').database().ref(path).set(null);
}

var makeObject;
var root;

setup(function() {
var objectId = 0;
makeObject = function(value) {
return {
val: value || objectId++
};
};

return pushFirebaseValue('/test', { ignore: 'me' }).then(function(snapshot) {
root = '/test/' + snapshot.key;
});
});

suite('exists attribute', function() {
var query;

setup(function() {
query = fixture('BasicStorage');
query.path = root + '/list';
return query.transactionsComplete;
});

test('exists is null when we change the path', function() {
query.path = '/myNewPath';
expect(query.exists).to.be.equal(null);
});

test('exists is true when we have data false when we remove it.', function() {
var object = makeObject();

return pushFirebaseValue(query.path, object).then(function() {
expect(query.exists).to.be.equal(true);
}).then(function(){
clearFirebaseValue(query.path);
}).then(function() {
expect(query.exists).to.be.equal(false);
});
});

});

});
</script>
</body>
Expand Down
17 changes: 17 additions & 0 deletions test/firebase-query.html
Expand Up @@ -176,6 +176,7 @@
var object = makeObject();

return pushFirebaseValue(query.path, object).then(function() {
expect(query.exists).to.be.equal(true);
expect(query.data.length).to.be.equal(1);
expect(query.data[0]).to.be.ok;
expect(query.data[0].val).to.be.equal(object.val);
Expand Down Expand Up @@ -241,6 +242,22 @@
expect(query.data[0].foo).to.be.eql(undefined);
});
});

test('exists is null when template is stamped', function() {
expect(query.exists).to.be.equal(null);
})

test('exists is true when we have data false when we remove it.', function() {
var object = makeObject();

return pushFirebaseValue(query.path, object).then(function() {
expect(query.exists).to.be.equal(true);
}).then(function(){
clearFirebaseValue(query.path);
}).then(function() {
expect(query.exists).to.be.equal(false);
});
});
});

suite('querying against leaf node collections', function() {
Expand Down

0 comments on commit 7290611

Please sign in to comment.