|
1 | 1 | const assert = require('assert'), |
2 | | -RedisGraphAPI = require('../src/redisGraphAPI'); |
| 2 | +Label = require('../src/statistics').Label, |
| 3 | +RedisGraphAPI = require('../src/redisGraph'); |
3 | 4 |
|
4 | 5 | describe('RedisGraphAPI Test', () =>{ |
5 | | - const api = new RedisGraphAPI("social"); |
| 6 | + const api = new RedisGraphAPI("social"); |
6 | 7 |
|
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 |
29 | 10 |
|
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 | + }); |
41 | 15 |
|
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 | + }); |
58 | 30 |
|
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 | + }); |
67 | 42 |
|
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})"); |
77 | 47 |
|
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 | + }); |
83 | 90 | }) |
0 commit comments