Skip to content

Commit

Permalink
feat(core): make driver management available from core
Browse files Browse the repository at this point in the history
  • Loading branch information
SvenWesterlaken committed Apr 26, 2020
1 parent f71abf3 commit a875d21
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 22 deletions.
12 changes: 12 additions & 0 deletions lib/core.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,18 @@ module.exports = {
return neo4j.init(hosts, auth, options);
},

getDriver(identifier) {
return neo4j.getDriver(identifier);
},

close(identifier) {
return neo4j.close(identifier);
},

reset() {
return neo4j.reset();
},

plugin(identifier) {

return (schema) => {
Expand Down
45 changes: 23 additions & 22 deletions test/functions/1_neo4j_test.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
const neo4j = require('../../lib/neo4j');
const mongo4j = require('../../lib/core');
const chai = require('chai');
const expect = chai.expect;

Expand All @@ -20,7 +21,7 @@ describe("Neo4J driver management", () => {
expect(neo4j.driver).to.not.be.undefined;
expect(neo4j.drivers).to.be.undefined;

neo4j.reset().then(() => {
mongo4j.reset().then(() => {
expect(neo4j.driver).to.be.undefined;
expect(neo4j.driver).to.be.undefined;
done();
Expand All @@ -40,7 +41,7 @@ describe("Neo4J driver management", () => {
expect(neo4j.drivers).to.be.an('array').with.a.lengthOf(2);
expect(neo4j.driver).to.be.undefined;

neo4j.reset().then(() => {
mongo4j.reset().then(() => {
expect(neo4j.driver).to.be.undefined;
expect(neo4j.driver).to.be.undefined;
done();
Expand All @@ -52,14 +53,14 @@ describe("Neo4J driver management", () => {
//----------------------------------------

it('Should create a new driver without arguments', () => {
neo4j.init();
mongo4j.init();

expect(neo4j.driver).to.not.be.undefined;
expect(neo4j.drivers).to.be.undefined;
});

it('Should create a multiple drivers with array as argument', () => {
neo4j.init([{
mongo4j.init([{
name: 'testconnection1',
url: neo4jUri
}, {
Expand All @@ -76,12 +77,12 @@ describe("Neo4J driver management", () => {
//----------------------------------------

it('Should return an error if driver is already set', (done) => {
neo4j.init();
mongo4j.init();

expect(neo4j.driver).to.not.be.undefined;
expect(neo4j.drivers).to.be.undefined;

expect(() => neo4j.init()).to.throw('A driver has already been initialized')
expect(() => mongo4j.init()).to.throw('A driver has already been initialized')
done();
});

Expand All @@ -97,17 +98,17 @@ describe("Neo4J driver management", () => {
expect(neo4j.drivers).to.be.an('array').with.a.lengthOf(2);
expect(neo4j.driver).to.be.undefined;

expect(() => neo4j.init()).to.throw('Drivers have already been initialized')
expect(() => mongo4j.init()).to.throw('Drivers have already been initialized')
done();
});

it('Should return an error if driver name not set in case of multiple drivers', (done) => {
expect(() => neo4j.init([{ url: neo4jUri }, { name: 'testconnection2', url: neo4jUri }])).to.throw('Name of Neo4j-connection must be specified, if you have more than one');
expect(() => mongo4j.init([{ url: neo4jUri }, { name: 'testconnection2', url: neo4jUri }])).to.throw('Name of Neo4j-connection must be specified, if you have more than one');
done();
});

it('Should return an error if driver name is not a string in case of multiple drivers', (done) => {
expect(() => neo4j.init([{ name: 41, url: neo4jUri }, { name: 'testconnection2', url: neo4jUri }])).to.throw('Name of Neo4j-connection must be a string');
expect(() => mongo4j.init([{ name: 41, url: neo4jUri }, { name: 'testconnection2', url: neo4jUri }])).to.throw('Name of Neo4j-connection must be a string');
done();
});

Expand All @@ -124,7 +125,7 @@ describe("Neo4J driver management", () => {
url: neo4jUri
}]);

expect(() => neo4j.getDriver()).to.throw('You initiated more than one driver, which means you need to provide an identifier (String or Integer)');
expect(() => mongo4j.getDriver()).to.throw('You initiated more than one driver, which means you need to provide an identifier (String or Integer)');
done();
});

Expand All @@ -139,7 +140,7 @@ describe("Neo4J driver management", () => {

expect(neo4j.drivers).to.be.an('array').with.a.lengthOf(2);

const driver = neo4j.getDriver('testconnection1');
const driver = mongo4j.getDriver('testconnection1');

expect(driver).to.not.be.null;
expect(driver).to.be.an('object');
Expand All @@ -158,7 +159,7 @@ describe("Neo4J driver management", () => {

expect(neo4j.drivers).to.be.an('array').with.a.lengthOf(2);

const driver = neo4j.getDriver(1);
const driver = mongo4j.getDriver(1);

expect(driver).to.not.be.null;
expect(driver).to.be.an('object');
Expand All @@ -177,7 +178,7 @@ describe("Neo4J driver management", () => {

expect(neo4j.drivers).to.be.an('array').with.a.lengthOf(2);

expect(() => neo4j.getDriver(0)).to.throw('Identifier must be greater than 0');
expect(() => mongo4j.getDriver(0)).to.throw('Identifier must be greater than 0');
});

it('Should return an error if integer identifier is than length of array in case of multiple drivers', () => {
Expand All @@ -191,15 +192,15 @@ describe("Neo4J driver management", () => {

expect(neo4j.drivers).to.be.an('array').with.a.lengthOf(2);

expect(() => neo4j.getDriver(3)).to.throw('Identifier is greater than the length of the array of drivers');
expect(() => mongo4j.getDriver(3)).to.throw('Identifier is greater than the length of the array of drivers');
});

it('Should return an error if no drivers initialized', () => {

expect(neo4j.drivers).to.be.undefined;
expect(neo4j.driver).to.be.undefined;

expect(() => neo4j.getDriver()).to.throw('No drivers have yet been initialized, do so by calling: init()');
expect(() => mongo4j.getDriver()).to.throw('No drivers have yet been initialized, do so by calling: init()');
});

//----------------------------------------
Expand All @@ -217,7 +218,7 @@ describe("Neo4J driver management", () => {

expect(neo4j.drivers).to.be.an('array').with.a.lengthOf(2);

const result = neo4j.close('testconnection1');
const result = mongo4j.close('testconnection1');

expect(result).to.be.a('promise');
});
Expand All @@ -233,7 +234,7 @@ describe("Neo4J driver management", () => {

expect(neo4j.drivers).to.be.an('array').with.a.lengthOf(2);

const result = neo4j.close(1);
const result = mongo4j.close(1);

expect(result).to.be.a('promise');
});
Expand All @@ -249,7 +250,7 @@ describe("Neo4J driver management", () => {

expect(neo4j.drivers).to.be.an('array').with.a.lengthOf(2);

expect(() => neo4j.close(0)).to.throw('Identifier must be greater than 0');
expect(() => mongo4j.close(0)).to.throw('Identifier must be greater than 0');
});

it('Should return an error if integer identifier is than length of array in case of multiple drivers', () => {
Expand All @@ -263,14 +264,14 @@ describe("Neo4J driver management", () => {

expect(neo4j.drivers).to.be.an('array').with.a.lengthOf(2);

expect(() => neo4j.close(3)).to.throw('Identifier is greater than the length of the array of drivers');
expect(() => mongo4j.close(3)).to.throw('Identifier is greater than the length of the array of drivers');
});

it('Should return an error if no drivers initialized', () => {
expect(neo4j.drivers).to.be.undefined;
expect(neo4j.driver).to.be.undefined;

expect(() => neo4j.close()).to.throw('No drivers have yet been initialized, do so by calling: init()');
expect(() => mongo4j.close()).to.throw('No drivers have yet been initialized, do so by calling: init()');
});

it('Should return an error if close is called without identifier in case of multiple drivers', (done) => {
Expand All @@ -282,7 +283,7 @@ describe("Neo4J driver management", () => {
url: neo4jUri
}]);

expect(() => neo4j.close()).to.throw('You initiated more than one driver, which means you need to provide an identifier (String or Integer)');
expect(() => mongo4j.close()).to.throw('You initiated more than one driver, which means you need to provide an identifier (String or Integer)');
done();
});

Expand All @@ -295,7 +296,7 @@ describe("Neo4J driver management", () => {
url: neo4jUri
}]);

const result = neo4j.close(true);
const result = mongo4j.close(true);

expect(result).to.be.a('promise');

Expand Down

0 comments on commit a875d21

Please sign in to comment.