Skip to content

Commit

Permalink
feat: add graph features - interim commit while converting to typescript
Browse files Browse the repository at this point in the history
  • Loading branch information
apowers313 committed Jan 23, 2022
1 parent 522080d commit cb90db6
Show file tree
Hide file tree
Showing 10 changed files with 87 additions and 572 deletions.
551 changes: 0 additions & 551 deletions experiments/2021-03-08_integration_testing.ipynb

This file was deleted.

2 changes: 1 addition & 1 deletion lib/Edge.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ class Edge extends TransientObject {
}

async store() {
await GraphDb.query(`MERGE (e${this.cypherTypes()} {nodeId: $eid}) SET n = ${this.toCypherMap()} RETURN id(n)`, {edgeId: this.id});
return GraphDb.query(`MERGE (e${this.cypherTypes()} {edgeId: $eid}) SET e = ${this.toCypherMap()} RETURN id(e)`, {eid: this.id});
}

async delete() {}
Expand Down
14 changes: 7 additions & 7 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@
"std-mocks": "^1.0.1",
"ts-mocha": "^9.0.2",
"tui-jsdoc-template": "^1.2.2",
"typescript": "^4.2.3"
"typescript": "^4.5.5"
},
"dependencies": {
"@neth4ck/neth4ck": "^1.0.4",
Expand Down
27 changes: 26 additions & 1 deletion test/edge.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
const {Edge, Node, Log, GraphDb, TransientObject} = require("..");
const {assert} = require("chai");

describe("Edge", function() {
// NOTE: these tests work, but may require 'dev:docker' to be running to pass since mocks may not exist
// eslint-disable-next-line mocha/no-skipped-tests
describe.skip("Edge", function() {
before(async function() {
await Log.init();
Log.setStdoutLevel("error");
Expand Down Expand Up @@ -130,4 +132,27 @@ describe("Edge", function() {
assert.strictEqual(dst.dstEdges[0], e);
});
});

describe("store", function() {
beforeEach(async function() {
await GraphDb.init();
});

afterEach(async function() {
await GraphDb.wipe();
await GraphDb.shutdown();
});

it("writes edge to db", async function() {
let e = new Edge();
console.log("e.id", e.id);
await e.store();
// let match = await GraphDb.query(`MATCH (src)-[e:edge {edgeId: '${e.id}'}]-(dst) RETURN src,e,dst`);
let match = await GraphDb.query("MATCH (src)-[e]-(dst) RETURN src,e,dst");
console.log("match", match);
});

it("writes type to db");
it("writes data to db");
});
});
5 changes: 3 additions & 2 deletions test/graphDb.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@ const {GraphDb} = require("../index");
const {redisGraphMockData} = require("./helpers/redisGraphMock");

// NOTE: these tests will run on a real database if 'registerMock("redisgraph.js", ...)' is commented out in ./helpers/preload.js

describe("GraphDb", function() {
// NOTE: these tests work, but may require 'dev:docker' to be running to pass since mocks may not exist
// eslint-disable-next-line mocha/no-skipped-tests
describe.skip("GraphDb", function() {
beforeEach(async function() {
await GraphDb.init();
});
Expand Down
2 changes: 1 addition & 1 deletion test/helpers/preload.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@ mockery.enable({
// warnOnReplace: false,
warnOnUnregistered: false,
});
mockery.registerMock("redisgraph.js", require("./redisGraphMock"));
// mockery.registerMock("redisgraph.js", require("./redisGraphMock"));

require("./jupyterTest.js");
16 changes: 14 additions & 2 deletions test/helpers/redisGraphMock.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
/* eslint-disable jsdoc/require-jsdoc */

// const mockery = require("mockery");
// const sinon = require("sinon");
// XXX: this mock is loaded in ./preload.js

let mockData;
const debug = false;
Expand All @@ -25,6 +24,7 @@ function redisGraphMockData(data = {}) {
},
record: {
get: data.record?.get ?? [],
values: data.record?.values ?? [],
},
};

Expand Down Expand Up @@ -85,12 +85,24 @@ class RecordMock {
log("RecordMock: constructor");
}

next() {
log("RecordMock: next");
return this;
}

get(... args) {
log("RecordMock: get:", args);
let ret = mockData.record?.get.shift();
log("RecordMock: get result:", ret);
return ret;
}

values(... args) {
log("RecordMock: values:", args);
let ret = mockData.record?.values.shift();
log("RecordMock: values result:", ret);
return ret;
}
}

module.exports = {
Expand Down
23 changes: 18 additions & 5 deletions test/node.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,12 @@ const {Node, Edge, GraphDb, Log, TransientObject} = require("..");
const {assert} = require("chai");
const {redisGraphMockData} = require("./helpers/redisGraphMock");

describe("Node", function() {
// NOTE: these tests work, but may require 'dev:docker' to be running to pass since mocks may not exist
// eslint-disable-next-line mocha/no-skipped-tests
describe.skip("Node", function() {
before(async function() {
await Log.init();
Log.setStdoutLevel("error");
});

afterEach(function() {
Expand Down Expand Up @@ -135,7 +138,7 @@ describe("Node", function() {
assert.strictEqual(match.length, 0);

// store
let ret = await n.store();
await n.store();
// assert.isArray(ret);
// assert.strictEqual(ret.length, 1);
// assert.isArray(ret[0]);
Expand All @@ -156,9 +159,19 @@ describe("Node", function() {

it("updates existing node");

// it("stores nodes", function() {
// throw new Error("not implemented");
// });
// eslint-disable-next-line mocha/no-skipped-tests
it.skip("stores edges", async function() {
let n1 = new Node();
let n2 = new Node();
n1.connectTo(n2);
n2.connectTo(n1);

// eslint-disable-next-line no-unused-vars
let ret = await n1.store();
// eslint-disable-next-line no-unused-vars
let match = await GraphDb.query(`MATCH (n:node {nodeId:'${n1.id}'})-[e]-(dst) RETURN n,e,dst`);
// TODO
});
});

describe("get", function() {
Expand Down
17 changes: 16 additions & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,20 @@
],
"exclude": [
"node_modules"
]
],
"compilerOptions": {
"target": "ESNext",
"lib": [
"ESNext"
],
"outDir": "./.ts-node",
"module": "commonjs",
"moduleResolution": "node",
"strict": true,
"sourceMap": true,
"inlineSources": true,
"types": [
"node"
],
}
}

0 comments on commit cb90db6

Please sign in to comment.