2014-10-07 14:32:23 -04:00
|
|
|
'use strict';
|
2013-10-29 07:19:27 -04:00
|
|
|
|
2014-11-21 09:06:29 -05:00
|
|
|
var LawnchairDAO = require('../../../src/js/service/lawnchair');
|
2013-10-29 07:19:27 -04:00
|
|
|
|
|
|
|
|
2014-10-07 14:32:23 -04:00
|
|
|
var dbName = 'lawnchair@test.com';
|
2013-10-29 07:19:27 -04:00
|
|
|
|
2014-10-07 14:32:23 -04:00
|
|
|
var key = 'type_1';
|
|
|
|
var data = {
|
|
|
|
name: 'testName1',
|
|
|
|
type: 'testType1'
|
|
|
|
};
|
2013-10-29 07:19:27 -04:00
|
|
|
|
2014-10-07 14:32:23 -04:00
|
|
|
var key2 = 'type_2';
|
|
|
|
var data2 = {
|
|
|
|
name: 'testName2',
|
|
|
|
type: 'testType2'
|
|
|
|
};
|
2013-10-29 07:19:27 -04:00
|
|
|
|
2014-10-07 14:32:23 -04:00
|
|
|
describe('Lawnchair DAO unit tests', function() {
|
|
|
|
var lawnchairDao;
|
2013-10-29 07:19:27 -04:00
|
|
|
|
2014-12-01 08:55:03 -05:00
|
|
|
beforeEach(function(done) {
|
2014-12-11 12:12:37 -05:00
|
|
|
lawnchairDao = new LawnchairDAO();
|
2014-12-10 08:16:53 -05:00
|
|
|
lawnchairDao.init(dbName).then(function() {
|
2014-12-01 08:55:03 -05:00
|
|
|
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;
|
2013-10-29 07:19:27 -04:00
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
2014-10-07 14:32:23 -04:00
|
|
|
});
|
2013-10-29 07:19:27 -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;
|
2013-10-29 07:19:27 -04:00
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
2014-10-07 14:32:23 -04:00
|
|
|
});
|
2013-10-29 07:19:27 -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();
|
2013-10-29 07:19:27 -04:00
|
|
|
});
|
|
|
|
});
|
2014-10-07 14:32:23 -04:00
|
|
|
});
|
2013-10-29 07:19:27 -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();
|
2013-10-29 07:19:27 -04:00
|
|
|
});
|
|
|
|
});
|
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();
|
2013-10-29 07:19:27 -04:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
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
|
|
|
});
|
2013-10-29 07:19:27 -04:00
|
|
|
});
|
2014-10-07 14:32:23 -04:00
|
|
|
});
|
2013-10-29 07:19:27 -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();
|
2013-10-29 07:19:27 -04:00
|
|
|
});
|
2014-10-07 14:32:23 -04:00
|
|
|
});
|
|
|
|
|
|
|
|
it('should work', function(done) {
|
|
|
|
var list = [{
|
|
|
|
key: key,
|
|
|
|
object: data
|
|
|
|
}, {
|
|
|
|
key: key2,
|
|
|
|
object: data2
|
|
|
|
}];
|
2013-10-29 07:19:27 -04:00
|
|
|
|
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
|
|
|
});
|
2013-10-29 07:19:27 -04:00
|
|
|
});
|
|
|
|
|
|
|
|
});
|