Skip to content

Commit

Permalink
close #43. Changed graph creation and docs. (#44)
Browse files Browse the repository at this point in the history
* close #43. Changed graph creation.
  • Loading branch information
DvirDukhan authored Mar 9, 2020
1 parent 7d61aff commit 6dc57bf
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 12 deletions.
20 changes: 10 additions & 10 deletions src/graph.js
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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);
}

Expand Down
19 changes: 17 additions & 2 deletions test/redisGraphAPITest.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 () => {
Expand Down

0 comments on commit 6dc57bf

Please sign in to comment.