Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 32 additions & 0 deletions backend/test/dependencies.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
const app = require('../src/app');
const { queries } = require('./test-queries/queries');
const { connectionForm } = require('./testDB');
const pathCreate = require('path');
const request = require('supertest');
const expect = require('chai').expect;
const agent = request.agent(app);
request.Test.prototype.attachMultiple = function(files, key){
files.forEach(([name, path])=>{
this.attach(key, path, name);
});
return this;
}

const START_PATH = '/api/v1'

const getPathForFile = function(fname){
const dataPath = 'test-data'
return pathCreate.join(__dirname, dataPath, fname);
}

module.exports = {
app,
queries,
connectionForm,
pathCreate,
request,
expect,
agent,
START_PATH,
getPathForFile
}
28 changes: 8 additions & 20 deletions backend/test/graphCreate.test.js
Original file line number Diff line number Diff line change
@@ -1,18 +1,11 @@
const app = require('../src/app');
const { queries } = require('./test-queries/queries');
const { connectionForm } = require('./testDB');
const pathCreate = require('path');
const request = require('supertest');
const expect = require('chai').expect;
const agent = request.agent(app);
request.Test.prototype.attachMultiple = function(files, key){
files.forEach(([name, path])=>{
this.attach(key, path, name);
});
return this;
}

const START_PATH = '/api/v1'
const {
queries,
connectionForm,
getPathForFile,
expect,
agent,
START_PATH
} = require('./dependencies');

describe('Graph Creation', ()=>{
const path = `${START_PATH}/db/connect`
Expand Down Expand Up @@ -67,8 +60,3 @@ describe('Graph Creation', ()=>{
})

});

function getPathForFile(fname){
const dataPath = 'test-data'
return pathCreate.join(__dirname, dataPath, fname);
}
80 changes: 80 additions & 0 deletions backend/test/metadata.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
const {
queries,
connectionForm,
getPathForFile,
expect,
agent,
START_PATH
} = require('./dependencies');

describe('metadata', ()=>{
const path = `${START_PATH}/db/connect`
// connect to database
before((done)=>{

agent
.post(path)
.send({...connectionForm})
.end((err, res)=>{
expect(err).to.be.null;
expect(res).property('status').to.equal(200)
done();
});

});
// create graph
beforeEach((done)=>{
const urlPath = `${START_PATH}/cypher/init`
const nodesFilePath = [['Make', getPathForFile('make.csv')],['Model', getPathForFile('model.csv')]]
const edgesFilePath = [['has_model', getPathForFile('has_model.csv')]]
const formData = {
nodes:nodesFilePath,
edges:edgesFilePath,
graphName:connectionForm.database,
dropGraph:'true'
}
agent
.post(urlPath)
.field('graphName', formData.graphName)
.field('dropGraph', formData.dropGraph)
.attachMultiple(nodesFilePath, 'nodes')
.attachMultiple(edgesFilePath, 'edges')
.end((err, res)=>{
expect(err).to.be.null;
expect(res.status).to.equal(204);

done();
});
})
// drop graph / clean up
afterEach((done)=>{
const urlPath = `${START_PATH}/cypher`
const query = queries.drop_graph(connectionForm.database, true, (s)=>{
return {cmd: s}
})
agent
.post(urlPath)
.send(query)
.expect(200)
.end(done)
})

it("get metadata", (done)=>{
const urlPath = `${START_PATH}/db/meta`
agent
.post(urlPath)
.send({"currentGraph":connectionForm.database})
.end((err, res)=>{
expect(err).to.be.null;
expect(res.body).to.haveOwnProperty(connectionForm.database)
const nodes = res.body[connectionForm.database].nodes
const edges = res.body[connectionForm.database].edges
expect(nodes).lengthOf(2)
expect(edges).lengthOf(1)
done();

})
})

});