1
0
mirror of https://github.com/moparisthebest/mail synced 2024-12-01 13:22:16 -05:00
mail/test/unit/service/lawnchair-dao-test.js

124 lines
3.4 KiB
JavaScript
Raw Normal View History

2014-10-07 14:32:23 -04:00
'use strict';
var LawnchairDAO = require('../../../src/js/service/lawnchair');
2014-10-07 14:32:23 -04:00
var dbName = 'lawnchair@test.com';
2014-10-07 14:32:23 -04:00
var key = 'type_1';
var data = {
name: 'testName1',
type: 'testType1'
};
2014-10-07 14:32:23 -04:00
var key2 = 'type_2';
var data2 = {
name: 'testName2',
type: 'testType2'
};
2014-10-07 14:32:23 -04:00
describe('Lawnchair DAO unit tests', function() {
var lawnchairDao;
beforeEach(function(done) {
2014-12-11 12:12:37 -05:00
lawnchairDao = new LawnchairDAO();
lawnchairDao.init(dbName).then(function() {
expect(lawnchairDao._db).to.exist;
done();
});
2014-10-07 14:32:23 -04:00
});
afterEach(function(done) {
2014-11-29 10:50:24 -05:00
lawnchairDao.clear().then(done);
2014-10-07 14:32:23 -04:00
});
describe('read', function() {
it('should fail', function(done) {
2014-11-29 10:50:24 -05:00
lawnchairDao.read(undefined).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
describe('list', function() {
it('should fail', function(done) {
2014-11-29 10:50:24 -05:00
lawnchairDao.list(undefined, 0, null).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
describe('remove list', function() {
it('should fail', function(done) {
2014-11-29 10:50:24 -05:00
lawnchairDao.removeList(undefined).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
describe('persist/read/remove', function() {
it('should fail', function(done) {
2014-11-29 10:50:24 -05:00
lawnchairDao.persist(undefined, data).catch(function(err) {
2014-10-07 14:32:23 -04:00
expect(err).to.exist;
done();
});
});
2014-10-07 14:32:23 -04:00
it('should fail', function(done) {
2014-11-29 10:50:24 -05:00
lawnchairDao.persist('1234', undefined).catch(function(err) {
2014-10-07 14:32:23 -04:00
expect(err).to.exist;
done();
});
});
2014-10-07 14:32:23 -04:00
it('should work', function(done) {
2014-11-29 10:50:24 -05:00
lawnchairDao.persist(key, data).then(function() {
return lawnchairDao.read(key);
}).then(function(fetched) {
2014-10-07 14:32:23 -04:00
expect(fetched).to.deep.equal(data);
2014-11-29 10:50:24 -05:00
return lawnchairDao.remove(key);
}).then(function() {
return lawnchairDao.read(key);
}).then(function(fetched) {
2014-10-07 14:32:23 -04:00
expect(fetched).to.not.exist;
done();
2014-11-29 10:50:24 -05:00
});
});
2014-10-07 14:32:23 -04:00
});
2014-10-07 14:32:23 -04:00
describe('batch/list/removeList', function() {
it('should fails', function(done) {
2014-11-29 10:50:24 -05:00
lawnchairDao.batch({}).catch(function(err) {
2014-10-07 14:32:23 -04:00
expect(err).to.exist;
done();
});
2014-10-07 14:32:23 -04:00
});
it('should work', function(done) {
var list = [{
key: key,
object: data
}, {
key: key2,
object: data2
}];
2014-11-29 10:50:24 -05:00
lawnchairDao.batch(list).then(function() {
return lawnchairDao.list('type', 0, null);
}).then(function(fetched) {
2014-10-07 14:32:23 -04:00
expect(fetched.length).to.equal(2);
expect(fetched[0]).to.deep.equal(list[0].object);
2014-11-29 10:50:24 -05:00
return lawnchairDao.removeList('type');
}).then(function() {
return lawnchairDao.list('type', 0, null);
}).then(function(fetched) {
2014-10-07 14:32:23 -04:00
expect(fetched).to.exist;
expect(fetched.length).to.equal(0);
done();
2014-11-29 10:50:24 -05:00
});
2014-10-07 14:32:23 -04:00
});
});
});