2014-10-07 14:32:23 -04:00
|
|
|
'use strict';
|
2013-10-29 07:19:27 -04:00
|
|
|
|
2014-10-07 14:32:23 -04:00
|
|
|
var LawnchairDAO = require('../../src/js/dao/lawnchair-dao'),
|
|
|
|
DeviceStorageDAO = require('../../src/js/dao/devicestorage-dao');
|
2013-10-29 07:19:27 -04:00
|
|
|
|
2014-10-07 14:32:23 -04:00
|
|
|
var testUser = 'test@example.com';
|
2013-10-29 07:19:27 -04:00
|
|
|
|
2014-10-07 14:32:23 -04:00
|
|
|
describe('Device Storage DAO unit tests', function() {
|
2013-10-29 07:19:27 -04:00
|
|
|
|
2014-10-07 14:32:23 -04:00
|
|
|
var storageDao, lawnchairDaoStub;
|
2013-10-29 07:19:27 -04:00
|
|
|
|
2014-10-07 14:32:23 -04:00
|
|
|
beforeEach(function() {
|
|
|
|
lawnchairDaoStub = sinon.createStubInstance(LawnchairDAO);
|
|
|
|
storageDao = new DeviceStorageDAO(lawnchairDaoStub);
|
|
|
|
});
|
2013-10-29 07:19:27 -04:00
|
|
|
|
2014-10-07 14:32:23 -04:00
|
|
|
afterEach(function() {});
|
2013-10-29 07:19:27 -04:00
|
|
|
|
2014-10-07 14:32:23 -04:00
|
|
|
describe('init', function() {
|
|
|
|
it('should work', function(done) {
|
|
|
|
lawnchairDaoStub.init.yields();
|
2013-10-29 07:19:27 -04:00
|
|
|
|
2014-10-07 14:32:23 -04:00
|
|
|
storageDao.init(testUser, function(err) {
|
|
|
|
expect(err).to.not.exist;
|
|
|
|
expect(lawnchairDaoStub.init.calledOnce).to.be.true;
|
|
|
|
done();
|
2013-10-29 07:19:27 -04:00
|
|
|
});
|
|
|
|
});
|
2014-10-07 14:32:23 -04:00
|
|
|
});
|
2013-10-29 07:19:27 -04:00
|
|
|
|
2014-10-07 14:32:23 -04:00
|
|
|
describe('store list', function() {
|
|
|
|
it('should fail', function(done) {
|
|
|
|
var list = [{}];
|
2013-10-29 07:19:27 -04:00
|
|
|
|
2014-10-07 14:32:23 -04:00
|
|
|
storageDao.storeList(list, '', function(err) {
|
|
|
|
expect(err).to.exist;
|
|
|
|
done();
|
2013-10-29 07:19:27 -04:00
|
|
|
});
|
2014-10-07 14:32:23 -04:00
|
|
|
});
|
2013-10-29 07:19:27 -04:00
|
|
|
|
2014-10-07 14:32:23 -04:00
|
|
|
it('should work with empty list', function(done) {
|
|
|
|
var list = [];
|
2013-10-29 07:19:27 -04:00
|
|
|
|
2014-10-07 14:32:23 -04:00
|
|
|
storageDao.storeList(list, 'email', function(err) {
|
|
|
|
expect(err).to.not.exist;
|
|
|
|
done();
|
2013-10-29 07:19:27 -04:00
|
|
|
});
|
2014-10-07 14:32:23 -04:00
|
|
|
});
|
2013-10-29 07:19:27 -04:00
|
|
|
|
2014-10-07 14:32:23 -04:00
|
|
|
it('should work', function(done) {
|
|
|
|
lawnchairDaoStub.batch.yields();
|
2013-10-29 07:19:27 -04:00
|
|
|
|
2014-10-07 14:32:23 -04:00
|
|
|
var list = [{
|
|
|
|
foo: 'bar'
|
|
|
|
}];
|
2013-10-29 07:19:27 -04:00
|
|
|
|
2014-10-07 14:32:23 -04:00
|
|
|
storageDao.storeList(list, 'email', function(err) {
|
|
|
|
expect(err).to.not.exist;
|
|
|
|
expect(lawnchairDaoStub.batch.calledOnce).to.be.true;
|
|
|
|
done();
|
2013-10-29 07:19:27 -04:00
|
|
|
});
|
|
|
|
});
|
2014-10-07 14:32:23 -04:00
|
|
|
});
|
2013-10-29 07:19:27 -04:00
|
|
|
|
2014-10-07 14:32:23 -04:00
|
|
|
describe('remove list', function() {
|
|
|
|
it('should work', function(done) {
|
|
|
|
lawnchairDaoStub.removeList.yields();
|
2013-10-29 07:19:27 -04:00
|
|
|
|
2014-10-07 14:32:23 -04:00
|
|
|
storageDao.removeList('email', function(err) {
|
|
|
|
expect(err).to.not.exist;
|
|
|
|
expect(lawnchairDaoStub.removeList.calledOnce).to.be.true;
|
|
|
|
done();
|
2013-10-29 07:19:27 -04:00
|
|
|
});
|
|
|
|
});
|
2014-10-07 14:32:23 -04:00
|
|
|
});
|
2013-10-29 07:19:27 -04:00
|
|
|
|
2014-10-07 14:32:23 -04:00
|
|
|
describe('list items', function() {
|
|
|
|
it('should work', function(done) {
|
|
|
|
lawnchairDaoStub.list.yields();
|
2013-10-29 07:19:27 -04:00
|
|
|
|
2014-10-07 14:32:23 -04:00
|
|
|
storageDao.listItems('email', 0, null, function(err) {
|
|
|
|
expect(err).to.not.exist;
|
|
|
|
expect(lawnchairDaoStub.list.calledOnce).to.be.true;
|
|
|
|
done();
|
2013-10-29 07:19:27 -04:00
|
|
|
});
|
|
|
|
});
|
2014-10-07 14:32:23 -04:00
|
|
|
});
|
2013-10-29 07:19:27 -04:00
|
|
|
|
2014-10-07 14:32:23 -04:00
|
|
|
describe('clear', function() {
|
|
|
|
it('should work', function(done) {
|
|
|
|
lawnchairDaoStub.clear.yields();
|
2013-10-29 07:19:27 -04:00
|
|
|
|
2014-10-07 14:32:23 -04:00
|
|
|
storageDao.clear(function(err) {
|
|
|
|
expect(err).to.not.exist;
|
|
|
|
expect(lawnchairDaoStub.clear.calledOnce).to.be.true;
|
|
|
|
done();
|
2013-10-29 07:19:27 -04:00
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
});
|