1
0
mirror of https://github.com/moparisthebest/mail synced 2024-11-29 20:32:15 -05:00
mail/test/unit/devicestorage-dao-test.js

101 lines
2.7 KiB
JavaScript
Raw Normal View History

2014-10-07 14:32:23 -04:00
'use strict';
2014-10-07 14:32:23 -04:00
var LawnchairDAO = require('../../src/js/dao/lawnchair-dao'),
DeviceStorageDAO = require('../../src/js/dao/devicestorage-dao');
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(done) {
lawnchairDaoStub.init.yields();
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();
});
});
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();
});
});
});
});