Skip to content
This repository has been archived by the owner on Feb 8, 2019. It is now read-only.

Commit

Permalink
Increased coverage of connect method
Browse files Browse the repository at this point in the history
  • Loading branch information
Ethan-Arrowood committed Oct 22, 2017
1 parent b009096 commit d7f874b
Show file tree
Hide file tree
Showing 4 changed files with 165 additions and 17 deletions.
9 changes: 4 additions & 5 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,14 @@ class HarperDB {
}

connect(url, username, password) {
if (
arguments.length !== 3 ||
if (arguments.length !== 3)
throw new Error("Connect must be passed 3 arguments");
else if (
typeof url !== "string" ||
typeof username !== "string" ||
typeof password !== "string"
)
throw new Error("Connect must be passed 3 arguments");
throw new Error("connect() arguments must be strings");

const authorization = `Basic ${base64.encode(`${username}:${password}`)}`;

Expand All @@ -41,13 +42,11 @@ class HarperDB {
})
.then(() => {
this.event.emit("connection");
console.log("Succesfully connected to server!");
this.isConnected = true;
this.options = options;
})
.catch(error => {
this.event.emit("error");
console.log(`Error: ${error.message}`);
});
}

Expand Down
116 changes: 116 additions & 0 deletions package-lock.json

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

5 changes: 4 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
"scripts": {
"test-harperDB": "./bin/functionalTest.js",
"test": "nyc --reporter=html --reporter=text mocha",
"test-watch": "mocha --watch",
"coverage": "nyc report --reporter=text-lcov | coveralls",
"init": "cd HarperDB/bin && ./harperdb install && cd ../.. && node .genEnv.js",
"precommit": "lint-staged && npm run test",
Expand Down Expand Up @@ -41,10 +42,12 @@
"eslint-plugin-promise": "^3.6.0",
"eslint-plugin-standard": "^3.0.1",
"husky": "^0.14.3",
"just-extend": "^1.1.22",
"lint-staged": "^4.3.0",
"mocha": "^4.0.1",
"nodemon": "^1.12.1",
"nyc": "^11.2.1",
"prettier": "^1.7.4"
"prettier": "^1.7.4",
"sinon": "^4.0.1"
}
}
52 changes: 41 additions & 11 deletions test/test.js
Original file line number Diff line number Diff line change
@@ -1,24 +1,54 @@
var expect = require("chai").expect;
var sinon = require("sinon");

var { HarperDB } = require("../index.js");

describe("HarperDB", () => {
describe("HarperDB", function() {
describe("#constructor()", () => {
it("should return an instance of the HarperDB class", () => {
it("should return an instance of the HarperDB class", function() {
var db = new HarperDB();
expect(db).to.exist;
expect(db).to.be.an.instanceof(HarperDB);
});
});
describe("#connect()", () => {
it("should throw error if not enough or invalid arguments are passed", () => {
describe("#connect()", function() {
it("should throw error if illegal arguments are passed", function() {
var db = new HarperDB();
expect(function() {
expect(arguments).to.be.arguments;
db.connect(...arguments);
}).to.throw(Error);
expect(() => db.connect()).to.throw(Error);
expect(() => db.connect(1)).to.throw(Error);
expect(() => db.connect(1, 2)).to.throw(Error);

expect(() => db.connect()).to.throw("Connect must be passed 3 arguments");

expect(() => db.connect("")).to.throw(
"Connect must be passed 3 arguments"
);

expect(() => db.connect("", "")).to.throw(
"Connect must be passed 3 arguments"
);

expect(() => db.connect(1, "", "")).to.throw(
"connect() arguments must be strings"
);

expect(() => db.connect("", 1, "")).to.throw(
"connect() arguments must be strings"
);

expect(() => db.connect("", "", 1)).to.throw(
"connect() arguments must be strings"
);
});

it("should emit an error event on failed connect", function() {
var db = new HarperDB();
var spy = sinon.spy();
db.event.on("error", spy);

try {
db.connect("x", "y", "z");
} catch (err) {
expect(err).to.be.an("error");
expect(spy.called).to.be.true;
}
});
});
});

0 comments on commit d7f874b

Please sign in to comment.