2014-10-07 14:32:23 -04:00
|
|
|
'use strict';
|
2013-10-29 07:19:27 -04:00
|
|
|
|
2014-11-21 09:06:29 -05:00
|
|
|
var LawnchairDAO = require('../../../src/js/service/lawnchair'),
|
|
|
|
DeviceStorageDAO = require('../../../src/js/service/devicestorage');
|
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);
|
2014-12-11 12:12:37 -05:00
|
|
|
storageDao = new DeviceStorageDAO(lawnchairDaoStub);
|
2014-10-07 14:32:23 -04:00
|
|
|
});
|
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() {
|
2014-12-10 11:39:40 -05:00
|
|
|
it('should work', function(done) {
|
|
|
|
lawnchairDaoStub.init.returns(resolves());
|
2014-12-01 08:55:03 -05:00
|
|
|
|
2014-12-10 11:39:40 -05:00
|
|
|
storageDao.init(testUser).then(function() {
|
2014-12-01 08:55:03 -05:00
|
|
|
expect(lawnchairDaoStub.init.calledOnce).to.be.true;
|
2014-12-10 11:39:40 -05:00
|
|
|
done();
|
2014-12-01 08:55:03 -05:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2014-12-10 11:39:40 -05:00
|
|
|
it('should fail', function(done) {
|
|
|
|
lawnchairDaoStub.init.returns(rejects(new Error()));
|
2014-12-01 08:55:03 -05:00
|
|
|
|
2014-12-10 11:39:40 -05:00
|
|
|
storageDao.init(testUser).catch(function(err) {
|
2014-12-01 08:55:03 -05:00
|
|
|
expect(err).to.exist;
|
|
|
|
expect(lawnchairDaoStub.init.calledOnce).to.be.true;
|
2014-12-10 11:39:40 -05:00
|
|
|
done();
|
2014-12-01 08:55:03 -05:00
|
|
|
});
|
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-12-10 11:39:40 -05:00
|
|
|
storageDao.storeList(list, '').catch(function(err) {
|
2014-10-07 14:32:23 -04:00
|
|
|
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-12-10 11:39:40 -05:00
|
|
|
storageDao.storeList(list, 'email').then(done);
|
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) {
|
2014-12-10 11:39:40 -05:00
|
|
|
lawnchairDaoStub.batch.returns(resolves());
|
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-12-10 11:39:40 -05:00
|
|
|
storageDao.storeList(list, 'email').then(function() {
|
2014-10-07 14:32:23 -04:00
|
|
|
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) {
|
2014-12-10 11:39:40 -05:00
|
|
|
lawnchairDaoStub.removeList.returns(resolves());
|
2013-10-29 07:19:27 -04:00
|
|
|
|
2014-12-10 11:39:40 -05:00
|
|
|
storageDao.removeList('email').then(function() {
|
2014-10-07 14:32:23 -04:00
|
|
|
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) {
|
2014-12-10 11:39:40 -05:00
|
|
|
lawnchairDaoStub.list.returns(resolves());
|
2013-10-29 07:19:27 -04:00
|
|
|
|
2014-12-10 11:39:40 -05:00
|
|
|
storageDao.listItems('email', 0, null).then(function() {
|
2014-10-07 14:32:23 -04:00
|
|
|
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) {
|
2014-12-10 11:39:40 -05:00
|
|
|
lawnchairDaoStub.clear.returns(resolves());
|
2013-10-29 07:19:27 -04:00
|
|
|
|
2014-12-10 11:39:40 -05:00
|
|
|
storageDao.clear().then(function() {
|
2014-10-07 14:32:23 -04:00
|
|
|
expect(lawnchairDaoStub.clear.calledOnce).to.be.true;
|
|
|
|
done();
|
2013-10-29 07:19:27 -04:00
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
});
|