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

103 lines
2.9 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);
2014-12-11 12:12:37 -05:00
storageDao = new DeviceStorageDAO(lawnchairDaoStub);
2014-10-07 14:32:23 -04:00
});
2014-10-07 14:32:23 -04:00
afterEach(function() {});
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-10 11:39:40 -05:00
storageDao.init(testUser).then(function() {
expect(lawnchairDaoStub.init.calledOnce).to.be.true;
2014-12-10 11:39:40 -05:00
done();
});
});
2014-12-10 11:39:40 -05:00
it('should fail', function(done) {
lawnchairDaoStub.init.returns(rejects(new Error()));
2014-12-10 11:39:40 -05:00
storageDao.init(testUser).catch(function(err) {
expect(err).to.exist;
expect(lawnchairDaoStub.init.calledOnce).to.be.true;
2014-12-10 11:39:40 -05:00
done();
});
});
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-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();
});
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-12-10 11:39:40 -05:00
storageDao.storeList(list, 'email').then(done);
2014-10-07 14:32:23 -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());
2014-10-07 14:32:23 -04:00
var list = [{
foo: 'bar'
}];
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();
});
});
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) {
2014-12-10 11:39:40 -05:00
lawnchairDaoStub.removeList.returns(resolves());
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();
});
});
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) {
2014-12-10 11:39:40 -05:00
lawnchairDaoStub.list.returns(resolves());
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();
});
});
2014-10-07 14:32:23 -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());
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();
});
});
});
});