Skip to content

Commit 6a8cff6

Browse files
committed
Fix tests
1 parent 388f7af commit 6a8cff6

File tree

3 files changed

+133
-123
lines changed

3 files changed

+133
-123
lines changed

src/resultSet.js

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
1-
const Statistics = require('./statistics');
1+
const Statistics = require('./statistics').Statistics;
22

33
/**
44
* Hold a query result
55
*/
66
module.exports = class ResultSet {
7-
87

98
constructor(resp) {
109

src/statistics.js

+52-48
Original file line numberDiff line numberDiff line change
@@ -11,58 +11,62 @@ const Label = Object.freeze({
1111
QUERY_INTERNAL_EXECUTION_TIME: "Query internal execution time"
1212
});
1313

14-
module.exports = class Statistics {
15-
16-
constructor(raw){
17-
this._raw = raw;
18-
}
19-
20-
getStringValue(label) {
21-
return this.getStatistics()[label];
22-
}
23-
24-
/**
25-
* Return the query statistics
26-
*
27-
* @return statistics object
28-
*/
29-
getStatistics(){
30-
if(!this._statistics) {
31-
this._statistics = {};
32-
for(let row of this._raw) {
33-
let touple = row.split(':');
34-
this._statistics[touple[0]] = touple[1].trim();
14+
module.exports ={
15+
Label: Label,
16+
Statistics : class Statistics {
17+
18+
19+
constructor(raw){
20+
this._raw = raw;
21+
}
22+
23+
getStringValue(label) {
24+
return this.getStatistics()[label];
25+
}
26+
27+
/**
28+
* Return the query statistics
29+
*
30+
* @return statistics object
31+
*/
32+
getStatistics(){
33+
if(!this._statistics) {
34+
this._statistics = {};
35+
for(let row of this._raw) {
36+
let touple = row.split(':');
37+
this._statistics[touple[0]] = touple[1].trim();
38+
}
39+
}
40+
return this._statistics;
41+
}
42+
43+
getIntValue(label) {
44+
let value = this.getStringValue(label);
45+
return value ? parseInt(value) : 0;
3546
}
36-
}
37-
return this._statistics;
38-
}
39-
40-
getIntValue(label) {
41-
let value = this.getStringValue(label);
42-
return value ? parseInt(value) : 0;
43-
}
4447

45-
nodesCreated() {
46-
return this.getIntValue(Label.NODES_CREATED);
47-
}
48+
nodesCreated() {
49+
return this.getIntValue(Label.NODES_CREATED);
50+
}
4851

49-
nodesDeleted() {
50-
return this.getIntValue(Label.NODES_DELETED);
51-
}
52+
nodesDeleted() {
53+
return this.getIntValue(Label.NODES_DELETED);
54+
}
5255

53-
labelsAdded() {
54-
return this.getIntValue(Label.LABELS_ADDED);
55-
}
56+
labelsAdded() {
57+
return this.getIntValue(Label.LABELS_ADDED);
58+
}
5659

57-
relationshipsDeleted() {
58-
return this.getIntValue(Label.RELATIONSHIPS_DELETED);
59-
}
60+
relationshipsDeleted() {
61+
return this.getIntValue(Label.RELATIONSHIPS_DELETED);
62+
}
6063

61-
relationshipsCreated() {
62-
return this.getIntValue(Label.RELATIONSHIPS_CREATED);
63-
}
64+
relationshipsCreated() {
65+
return this.getIntValue(Label.RELATIONSHIPS_CREATED);
66+
}
6467

65-
propertiesSet() {
66-
return this.getIntValue(Label.PROPERTIES_SET);
67-
}
68-
}
68+
propertiesSet() {
69+
return this.getIntValue(Label.PROPERTIES_SET);
70+
}
71+
}
72+
}

test/redisGraphAPITest.js

+80-73
Original file line numberDiff line numberDiff line change
@@ -1,83 +1,90 @@
11
const assert = require('assert'),
2-
RedisGraphAPI = require('../src/redisGraphAPI');
2+
Label = require('../src/statistics').Label,
3+
RedisGraphAPI = require('../src/redisGraph');
34

45
describe('RedisGraphAPI Test', () =>{
5-
const api = new RedisGraphAPI("social");
6+
const api = new RedisGraphAPI("social");
67

7-
beforeEach( () => {
8-
//api.deleteGraph(); - TODO add this back once we implement this API
9-
10-
// Method method = RedisGraphAPI.class.getDeclaredMethod("_conn");
11-
// method.setAccessible(true);
12-
// ((Jedis)method.invoke(api)).flushDB();
13-
});
14-
15-
it('test Create Node', (done) => {
16-
// Create a node
17-
api.query("CREATE ({name:'roi',age:32})").then( (result) => {
18-
assert.assertFalse(result.hasNext());
19-
20-
assert.assertEquals(1, result.getStatistics().nodesCreated());
21-
assert.assertNull(result.getStatistics().getStringValue(Label.NODES_DELETED));
22-
assert.assertNull(result.getStatistics().getStringValue(Label.RELATIONSHIPS_CREATED));
23-
assert.assertNull(result.getStatistics().getStringValue(Label.RELATIONSHIPS_DELETED));
24-
assert.assertEquals(2, result.getStatistics().propertiesSet());
25-
assert.assertNotNull(result.getStatistics().getStringValue(Label.QUERY_INTERNAL_EXECUTION_TIME));
26-
done();
27-
});
28-
});
8+
beforeEach( () => {
9+
//api.deleteGraph(); - TODO add this back once we implement this API
2910

30-
it('test Create Labeled Node', (done) => {
31-
// Create a node with a label
32-
let result = api.query("CREATE (:human{name:'danny',age:12})").then( (result) => {
33-
assert.assertFalse(result.hasNext());
34-
35-
assert.assertEquals("1", result.getStatistics().getStringValue(Label.NODES_CREATED));
36-
assert.assertEquals("2", result.getStatistics().getStringValue(Label.PROPERTIES_SET));
37-
assert.assertNotNull(result.getStatistics().getStringValue(Label.QUERY_INTERNAL_EXECUTION_TIME));
38-
done();
39-
});
40-
});
11+
// Method method = RedisGraphAPI.class.getDeclaredMethod("_conn");
12+
// method.setAccessible(true);
13+
// ((Jedis)method.invoke(api)).flushDB();
14+
});
4115

42-
it('test Connect Nodes', (done) => {
43-
// Create both source and destination nodes
44-
let createResult1 = api.query("CREATE (:person{name:'roi',age:32})");
45-
let createResult2 = api.query("CREATE (:person{name:'amit',age:30})");
46-
47-
// Connect source and destination nodes.
48-
let matchResult = api.query("MATCH (a:person), (b:person) WHERE (a.name = 'roi' AND b.name='amit') CREATE (a)-[knows]->(a)");
49-
50-
assert.assertFalse(matchResult.hasNext());
51-
assert.assertNull(matchResult.getStatistics().getStringValue(Label.NODES_CREATED));
52-
assert.assertNull(matchResult.getStatistics().getStringValue(Label.PROPERTIES_SET));
53-
assert.assertEquals(1, matchResult.getStatistics().relationshipsCreated());
54-
assert.assertEquals(0, matchResult.getStatistics().relationshipsDeleted());
55-
assert.assertNotNull(matchResult.getStatistics().getStringValue(Label.QUERY_INTERNAL_EXECUTION_TIME));
56-
done();
57-
});
16+
it('test Create Node', (done) => {
17+
// Create a node
18+
api.query("CREATE ({name:'roi',age:32})")
19+
.then( (result) => {
20+
assert.ok(!result.hasNext());
21+
assert.equal(1, result.getStatistics().nodesCreated());
22+
assert.ifError(result.getStatistics().getStringValue(Label.NODES_DELETED));
23+
assert.ifError(result.getStatistics().getStringValue(Label.RELATIONSHIPS_CREATED));
24+
assert.ifError(result.getStatistics().getStringValue(Label.RELATIONSHIPS_DELETED));
25+
assert.equal(2, result.getStatistics().propertiesSet());
26+
assert.ok(result.getStatistics().getStringValue(Label.QUERY_INTERNAL_EXECUTION_TIME));
27+
done();
28+
});
29+
});
5830

59-
it('test Query', (done) => {
60-
61-
// Create both source and destination nodes
62-
let create1Result = api.query("CREATE (:qhuman{name:'roi',age:32})");
63-
let create2Result = api.query("CREATE (:qhuman{name:'amit',age:30})");
64-
65-
// Connect source and destination nodes.
66-
let connectResult= api.query("MATCH (a:qhuman), (b:qhuman) WHERE (a.name = 'roi' AND b.name='amit') CREATE (a)-[knows]->(b)");
31+
it('test Create Labeled Node', (done) => {
32+
// Create a node with a label
33+
api.query("CREATE (:human{name:'danny',age:12})")
34+
.then( (result) => {
35+
assert.ok(!result.hasNext());
36+
assert.equal("1", result.getStatistics().getStringValue(Label.NODES_CREATED));
37+
assert.equal("2", result.getStatistics().getStringValue(Label.PROPERTIES_SET));
38+
assert.ok(result.getStatistics().getStringValue(Label.QUERY_INTERNAL_EXECUTION_TIME));
39+
done();
40+
});
41+
});
6742

68-
// Query
69-
let resultSet = api.query("MATCH (a:qhuman)-[knows]->(:qhuman) RETURN a");
70-
71-
assert.assertTrue(resultSet.hasNext());
72-
assert.assertEquals(0, resultSet.getStatistics().nodesCreated());
73-
assert.assertEquals(0, resultSet.getStatistics().propertiesSet());
74-
assert.assertEquals(0, resultSet.getStatistics().relationshipsCreated());
75-
assert.assertEquals(0, resultSet.getStatistics().relationshipsDeleted());
76-
assert.assertNotNull(resultSet.getStatistics().getStringValue(Label.QUERY_INTERNAL_EXECUTION_TIME));
43+
it('test Connect Nodes', (done) => {
44+
// Create both source and destination nodes
45+
let createResult1 = api.query("CREATE (:person{name:'roi',age:32})");
46+
let createResult2 = api.query("CREATE (:person{name:'amit',age:30})");
7747

78-
let record = resultSet.next();
79-
assert.assertEquals( "roi", record.getString(1));
80-
assert.assertEquals( "32.000000", record.getString(0));
81-
82-
});
48+
// Connect source and destination nodes.
49+
api.query("MATCH (a:person), (b:person) WHERE (a.name = 'roi' AND b.name='amit') CREATE (a)-[knows]->(a)")
50+
.then( (matchResult) => {
51+
assert.ok(!matchResult.hasNext());
52+
assert.ifError(matchResult.getStatistics().getStringValue(Label.NODES_CREATED));
53+
assert.ifError(matchResult.getStatistics().getStringValue(Label.PROPERTIES_SET));
54+
assert.equal(1, matchResult.getStatistics().relationshipsCreated());
55+
assert.equal(0, matchResult.getStatistics().relationshipsDeleted());
56+
assert.ok(matchResult.getStatistics().getStringValue(Label.QUERY_INTERNAL_EXECUTION_TIME));
57+
done();
58+
});
59+
});
60+
61+
it('test Query', (done) => {
62+
63+
// Create both source and destination nodes
64+
api.query("CREATE (:qhuman{name:'roi',age:32})")
65+
.then( (create1Result) => {
66+
return api.query("CREATE (:qhuman{name:'amit',age:30})");
67+
})
68+
.then( (create2Result) => {
69+
// Connect source and destination nodes.
70+
return api.query("MATCH (a:qhuman), (b:qhuman) WHERE (a.name = 'roi' AND b.name='amit') CREATE (a)-[knows]->(b)");
71+
})
72+
.then( (connectResult) => {
73+
// Query
74+
return api.query("MATCH (a:qhuman)-[knows]->(:qhuman) RETURN a");
75+
})
76+
.then( (resultSet) => {
77+
assert.ok(resultSet.hasNext());
78+
assert.equal(0, resultSet.getStatistics().nodesCreated());
79+
assert.equal(0, resultSet.getStatistics().propertiesSet());
80+
assert.equal(0, resultSet.getStatistics().relationshipsCreated());
81+
assert.equal(0, resultSet.getStatistics().relationshipsDeleted());
82+
assert.ok(resultSet.getStatistics().getStringValue(Label.QUERY_INTERNAL_EXECUTION_TIME));
83+
84+
let record = resultSet.next();
85+
assert.equal( "roi", record.getString(1));
86+
assert.equal( "32.000000", record.getString(0));
87+
done();
88+
});
89+
});
8390
})

0 commit comments

Comments
 (0)