mail/test/unit/service/devicestorage-dao-test.js

96 lines
2.6 KiB
JavaScript
Raw Normal View History

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