diff --git a/src/graph.js b/src/graph.js index 3a857b9a9e..e36c2269bd 100644 --- a/src/graph.js +++ b/src/graph.js @@ -7,15 +7,15 @@ const redis = require("redis"), * RedisGraph client */ class Graph { - /** - * Creates a client to a specific graph running on the specific host/post - * See: node_redis for more options on createClient - * - * @param {string} graphId the graph id - * @param {string | RedisClient} [host] Redis host or node_redis client - * @param {string} [port] Redis port - * @param {ClientOpts} [options] node_redis options - */ + /** + * Creates a client to a specific graph running on the specific host/post + * See: node_redis for more options on createClient + * + * @param {string} graphId the graph id + * @param {string | RedisClient} [host] Redis host or node_redis client + * @param {string | int} [port] Redis port + * @param {ClientOpts} [options] node_redis options + */ constructor(graphId, host, port, options) { this._graphId = graphId; // Graph ID this._labels = []; // List of node labels. @@ -29,7 +29,7 @@ class Graph { let client = host instanceof redis.RedisClient ? host - : redis.createClient.apply(redis, [].slice.call(arguments, 1)); + : redis.createClient(port, host, options); this._sendCommand = util.promisify(client.send_command).bind(client); } diff --git a/test/redisGraphAPITest.js b/test/redisGraphAPITest.js index 7a7835bc61..df19f60892 100644 --- a/test/redisGraphAPITest.js +++ b/test/redisGraphAPITest.js @@ -10,14 +10,29 @@ const assert = require("assert"), deepEqual = require("deep-equal"); describe("RedisGraphAPI Test", () => { + // Assuming this test is running against redis server at: localhost:6379 with no password. const api = new RedisGraph("social"); beforeEach(() => { return api.deleteGraph().catch(() => {}); }); - it("test bring your client", () => { - return new RedisGraph("social", redis.createClient()); + it("test connection from port and host", async () => { + // Assuming this test is running against redis server at: localhost:6379 with no password. + let graph = new RedisGraph("social", "127.0.0.1", 6379, {password:undefined}); + let result = await graph.query("CREATE ({name:'roi', age:34})"); + assert.ok(!result.hasNext()); + assert.equal(1, result.getStatistics().nodesCreated()); + graph.deleteGraph(); + }) + + it("test connection from client", async () => { + // Assuming this test is running against redis server at: localhost:6379 with no password. + let graph = new RedisGraph("social", redis.createClient()); + let result = await graph.query("CREATE ({name:'roi', age:34})"); + assert.ok(!result.hasNext()); + assert.equal(1, result.getStatistics().nodesCreated()); + graph.deleteGraph(); }); it("test Create Node", async () => {