Skip to content

Commit

Permalink
Merge pull request #51 from hardikj/coverall
Browse files Browse the repository at this point in the history
Improve code coverage by updating tests
  • Loading branch information
gwicke committed Jan 8, 2015
2 parents 39067ab + e999a9c commit 67f869a
Showing 1 changed file with 157 additions and 44 deletions.
201 changes: 157 additions & 44 deletions test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,12 +71,13 @@ describe('DB backend', function() {
});
it('simple table', function() {
return router.request({
url: '/v1/restbase.cassandra.test.local/simpleTable',
url: '/v1/restbase.cassandra.test.local/simple-table',
method: 'put',
body: {
// keep extra redundant info for primary bucket table reconstruction
domain: 'restbase.cassandra.test.local',
table: 'simpleTable',
table: 'simple-table',
consistency: 'localQuorum',
options: { durability: 'low' },
attributes: {
key: 'string',
Expand Down Expand Up @@ -203,10 +204,11 @@ describe('DB backend', function() {
describe('put', function() {
it('simple put insert', function() {
return router.request({
url: '/v1/restbase.cassandra.test.local/simpleTable/',
url: '/v1/restbase.cassandra.test.local/simple-table/',
method: 'put',
body: {
table: 'simpleTable',
table: 'simple-table',
consistency: 'localQuorum',
attributes: {
key: 'testing',
tid: dbu.tidFromDate(new Date('2013-08-08 18:43:58-0700')),
Expand Down Expand Up @@ -236,10 +238,10 @@ describe('DB backend', function() {
});
it('simple put update', function() {
return router.request({
url: '/v1/restbase.cassandra.test.local/simpleTable/',
url: '/v1/restbase.cassandra.test.local/simple-table/',
method: 'put',
body: {
table: 'simpleTable',
table: 'simple-table',
attributes: {
key: "testing",
tid: dbu.tidFromDate(new Date('2013-08-09 18:43:58-0700')),
Expand All @@ -253,10 +255,10 @@ describe('DB backend', function() {
});
it('put with if not exists and non index attributes', function() {
return router.request({
url: '/v1/restbase.cassandra.test.local/simpleTable/',
url: '/v1/restbase.cassandra.test.local/simple-table/',
method: 'put',
body: {
table: "simpleTable",
table: "simple-table",
if : "not exists",
attributes: {
key: "testing if not exists",
Expand All @@ -271,10 +273,10 @@ describe('DB backend', function() {
});
it('put with if and non index attributes', function() {
return router.request({
url: '/v1/restbase.cassandra.test.local/simpleTable/',
url: '/v1/restbase.cassandra.test.local/simple-table/',
method: 'put',
body: {
table: "simpleTable",
table: "simple-table",
attributes: {
key: "another test",
tid: dbu.tidFromDate(new Date('2013-08-11 18:43:58-0700')),
Expand Down Expand Up @@ -440,6 +442,22 @@ describe('DB backend', function() {
deepEqual(response, {status:201});
});
});
it('try a put on a non existing table', function() {
return router.request({
url: '/v1/restbase.cassandra.test.local/unknownTable/',
method: 'put',
body: {
table: 'unknownTable',
attributes: {
key: 'testing',
tid: dbu.tidFromDate(new Date('2013-08-08 18:43:58-0700')),
}
}
})
.then(function(response) {
deepEqual(response.status, 500);
});
});
});

describe('get', function() {
Expand All @@ -449,6 +467,7 @@ describe('DB backend', function() {
method: 'put',
body: {
table: 'varintTable',
consistency: 'localQuorum',
attributes: {
key: 'testing',
rev: 1
Expand Down Expand Up @@ -528,10 +547,10 @@ describe('DB backend', function() {
});
it('simple between', function() {
return router.request({
url: '/v1/restbase.cassandra.test.local/simpleTable/',
url: '/v1/restbase.cassandra.test.local/simple-table/',
method: 'get',
body: {
table: "simpleTable",
table: "simple-table",
//from: 'foo', // key to start the query from (paging)
limit: 3,
attributes: {
Expand All @@ -557,10 +576,10 @@ describe('DB backend', function() {
});
it('simple get', function() {
return router.request({
url:'/v1/restbase.cassandra.test.local/simpleTable/',
url:'/v1/restbase.cassandra.test.local/simple-table/',
method: 'get',
body: {
table: "simpleTable",
table: "simple-table",
attributes: {
key: 'testing',
tid: dbu.tidFromDate(new Date('2013-08-08 18:43:58-0700'))
Expand All @@ -584,10 +603,10 @@ describe('DB backend', function() {
});
it('simple get with paging', function() {
return router.request({
url:'/v1/restbase.cassandra.test.local/simpleTable/',
url:'/v1/restbase.cassandra.test.local/simple-table/',
method: 'get',
body: {
table: "simpleTable",
table: "simple-table",
pageSize: 1,
attributes: {
key: 'testing',
Expand All @@ -597,10 +616,10 @@ describe('DB backend', function() {
.then(function(response) {
deepEqual(response.body.items.length, 1);
return router.request({
url:'/v1/restbase.cassandra.test.local/simpleTable/',
url:'/v1/restbase.cassandra.test.local/simple-table/',
method: 'get',
body: {
table: "simpleTable",
table: "simple-table",
pageSize: 1,
next: response.body.next,
attributes: {
Expand Down Expand Up @@ -654,7 +673,6 @@ describe('DB backend', function() {
deepEqual(response.body.items.length, 0);
});
});

it("index query for current value", function() {
return router.request({
url: "/v1/restbase.cassandra.test.local/simpleSecondaryIndexTable/",
Expand All @@ -680,12 +698,28 @@ describe('DB backend', function() {
}]);
});
});
it('try a get on a non existing table', function() {
return router.request({
url: '/v1/restbase.cassandra.test.local/unknownTable/',
method: 'get',
body: {
table: 'unknownTable',
attributes: {
key: 'testing',
tid: dbu.tidFromDate(new Date('2013-08-08 18:43:58-0700')),
}
}
})
.then(function(response) {
deepEqual(response.status, 500);
});
});
});
//TODO: implement this using http handler when alternate rest-url for delete item are supported
describe('delete', function() {
it('simple delete query', function() {
return DB.delete('local.test.cassandra.restbase', {
table: "simpleTable",
table: "simple-table",
attributes: {
tid: dbu.tidFromDate(new Date('2013-08-09 18:43:58-0700')),
key: "testing"
Expand Down Expand Up @@ -718,8 +752,6 @@ describe('DB backend', function() {
uuid: 'uuid',
timestamp: 'timestamp',
json: 'json',
int_set: 'set<varint>',
json_set: 'set<json>'
},
index: [
{ attribute: 'string', type: 'hash' },
Expand All @@ -729,6 +761,37 @@ describe('DB backend', function() {
deepEqual(response.status, 201);
});
});
it('create sets table', function() {
return router.request({
url: '/v1/restbase.cassandra.test.local/typeSetsTable',
method: 'put',
body: {
domain: 'restbase.cassandra.test.local',
table: 'typeSetsTable',
options: { durability: 'low' },
attributes: {
string: 'string',
set: 'set<string>',
blob: 'set<blob>',
'int': 'set<int>',
varint: 'set<varint>',
decimal: 'set<decimal>',
//'float': 'float',
'double': 'set<double>',
'boolean': 'set<boolean>',
timeuuid: 'set<timeuuid>',
uuid: 'set<uuid>',
timestamp: 'set<timestamp>',
json: 'set<json>',
},
index: [
{ attribute: 'string', type: 'hash' },
]
}
}).then(function(response) {
deepEqual(response.status, 201);
});
});
it('put', function() {
return router.request({
url: '/v1/restbase.cassandra.test.local/typeTable/',
Expand All @@ -751,12 +814,6 @@ describe('DB backend', function() {
json: {
foo: 'bar'
},
int_set: [123456, 2567, 598765],
json_set: [
{one: 1, two: 'two'},
{foo: 'bar'},
{test: [{a: 'b'}, 3]}
]
}
}
})
Expand Down Expand Up @@ -786,10 +843,36 @@ describe('DB backend', function() {
json: {
foo: 'bar'
},
int_set: [0, 9, 8, 7, 6, 5, 4, 3, 2, 1],
json_set: [
{test: [{a: 'b'}, 3]},
{another: 'string'}
}
}
})
.then(function(response){
deepEqual(response, {status:201});
});
});
it('put sets', function() {
return router.request({
url: '/v1/restbase.cassandra.test.local/typeSetsTable/',
method: 'put',
body: {
table: "typeSetsTable",
attributes: {
string: 'string',
blob: [new Buffer('blob')],
set: ['bar','baz','foo'],
varint: [-4503599627370496,12233232],
decimal: ['1.2','1.6'],
//'float': 1.2,
'double': [1.2, 1.567],
'boolean': [true, false],
timeuuid: ['c931ec94-6c31-11e4-b6d0-0f67e29867e0'],
uuid: ['d6938370-c996-4def-96fb-6af7ba9b6f72'],
timestamp: ['2014-11-14T19:10:40.912Z', '2014-12-14T19:10:40.912Z'],
'int': [123456, 2567, 598765],
json: [
{one: 1, two: 'two'},
{foo: 'bar'},
{test: [{a: 'b'}, 3]}
]
}
}
Expand All @@ -806,7 +889,7 @@ describe('DB backend', function() {
table: "typeTable",
proj: ['string','blob','set','int','varint', 'decimal',
'double','boolean','timeuuid','uuid',
'timestamp','json', 'int_set', 'json_set']
'timestamp','json']
}
})
.then(function(response){
Expand All @@ -828,11 +911,6 @@ describe('DB backend', function() {
json: {
foo: 'bar'
},
int_set: [0, 1, 2, 3, 4, 5, 6, 7, 8, 9],
json_set: [
{another: 'string'},
{test: [{a: 'b'}, 3]}
]
},{
string: 'string',
blob: new Buffer('blob'),
Expand All @@ -848,36 +926,71 @@ describe('DB backend', function() {
timestamp: '2014-11-14T19:10:40.912Z',
json: {
foo: 'bar'
},
int_set: [2567, 123456, 598765],
json_set: [
}
}]);
});
});
it("get sets", function() {
return router.request({
url: '/v1/restbase.cassandra.test.local/typeSetsTable/',
method: 'get',
body: {
table: "typeSetsTable",
proj: ['string','blob','set','int','varint', 'decimal',
'double','boolean','timeuuid','uuid',
'timestamp','json']
}
})
.then(function(response){
// note: Cassandra orders sets, so the expected rows are
// slightly different than the original, supplied ones
deepEqual(response.body.items, [{
string: 'string',
blob: [new Buffer('blob')],
set: ['bar','baz','foo'],
'int': [2567, 123456, 598765],
varint: [-4503599627370496,12233232],
decimal: ['1.2','1.6'],
//'float': 1.2,
'double': [1.2, 1.567],
'boolean': [false, true],
timeuuid: ['c931ec94-6c31-11e4-b6d0-0f67e29867e0'],
uuid: ['d6938370-c996-4def-96fb-6af7ba9b6f72'],
timestamp: ['2014-11-14T19:10:40.912Z', '2014-12-14T19:10:40.912Z'],
json: [
{foo: 'bar'},
{one: 1, two: 'two'},
{test: [{a: 'b'}, 3]}
]
}]);
});
});
it('drop table', function() {
it('drop tables', function() {
this.timeout(15000);
return router.request({
url: "/v1/restbase.cassandra.test.local/typeTable",
method: "delete",
body: {}
}).then(function() {
return router.request({
url: "/v1/restbase.cassandra.test.local/typeSetsTable",
method: "delete",
body: {}
});
});
});
});

describe('dropTable', function() {
this.timeout(15000);
it('drop a simple table', function() {
it('drop some simple table', function() {
return router.request({
url: "/v1/restbase.cassandra.test.local/varintTable",
method: "delete",
body: {}
}).then(function() {
return router.request({
url: "/v1/restbase.cassandra.test.local/simpleTable",
url: "/v1/restbase.cassandra.test.local/simple-table",
method: "delete",
body: {}
});
Expand Down

0 comments on commit 67f869a

Please sign in to comment.