1
0
mirror of https://github.com/moparisthebest/mail synced 2024-11-22 17:02:17 -05:00
mail/test/unit/service/devicestorage-dao-test.js
2014-12-18 15:25:18 +01:00

103 lines
2.9 KiB
JavaScript

'use strict';
var LawnchairDAO = require('../../../src/js/service/lawnchair'),
DeviceStorageDAO = require('../../../src/js/service/devicestorage');
var testUser = 'test@example.com';
describe('Device Storage DAO unit tests', function() {
var storageDao, lawnchairDaoStub;
beforeEach(function() {
lawnchairDaoStub = sinon.createStubInstance(LawnchairDAO);
storageDao = new DeviceStorageDAO(lawnchairDaoStub);
});
afterEach(function() {});
describe('init', function() {
it('should work', function(done) {
lawnchairDaoStub.init.returns(resolves());
storageDao.init(testUser).then(function() {
expect(lawnchairDaoStub.init.calledOnce).to.be.true;
done();
});
});
it('should fail', function(done) {
lawnchairDaoStub.init.returns(rejects(new Error()));
storageDao.init(testUser).catch(function(err) {
expect(err).to.exist;
expect(lawnchairDaoStub.init.calledOnce).to.be.true;
done();
});
});
});
describe('store list', function() {
it('should fail', function(done) {
var list = [{}];
storageDao.storeList(list, '').catch(function(err) {
expect(err).to.exist;
done();
});
});
it('should work with empty list', function(done) {
var list = [];
storageDao.storeList(list, 'email').then(done);
});
it('should work', function(done) {
lawnchairDaoStub.batch.returns(resolves());
var list = [{
foo: 'bar'
}];
storageDao.storeList(list, 'email').then(function() {
expect(lawnchairDaoStub.batch.calledOnce).to.be.true;
done();
});
});
});
describe('remove list', function() {
it('should work', function(done) {
lawnchairDaoStub.removeList.returns(resolves());
storageDao.removeList('email').then(function() {
expect(lawnchairDaoStub.removeList.calledOnce).to.be.true;
done();
});
});
});
describe('list items', function() {
it('should work', function(done) {
lawnchairDaoStub.list.returns(resolves());
storageDao.listItems('email', 0, null).then(function() {
expect(lawnchairDaoStub.list.calledOnce).to.be.true;
done();
});
});
});
describe('clear', function() {
it('should work', function(done) {
lawnchairDaoStub.clear.returns(resolves());
storageDao.clear().then(function() {
expect(lawnchairDaoStub.clear.calledOnce).to.be.true;
done();
});
});
});
});