Skip to content

Commit

Permalink
Added a bunch of test stuff
Browse files Browse the repository at this point in the history
  • Loading branch information
notheotherben committed Apr 21, 2015
1 parent b757f4a commit 6411221
Show file tree
Hide file tree
Showing 18 changed files with 174 additions and 1,506 deletions.
145 changes: 145 additions & 0 deletions test/Core.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,145 @@
import Iridium = require('../index');

class InheritedCore extends Iridium.Core {
theAnswer = 42;
}

class InheritedCoreWithCustomConstructor extends Iridium.Core {
constructor() {
super("mongodb://localhost/test");
}
}

describe("Core",() => {
describe("constructor",() => {
it("should accept a URI string",() => {
var core = new Iridium.Core("mongodb://localhost/test");
chai.expect(core.url).to.equal("mongodb://localhost/test");
});

it("should accept a configuration object",() => {
new Iridium.Core({
database: 'test'
});
});

it("should correctly convert the configuration object into a URI string",() => {
var core = new Iridium.Core({
host: 'localhost',
port: 27016,
database: 'test',
username: 'user',
password: 'password'
});

chai.expect(core.url).to.equal("mongodb://user:password@localhost:27016/test");
});

it("should make logical assumptions about the default host",() => {
var core = new Iridium.Core({
database: 'test'
});

chai.expect(core.url).to.equal("mongodb://localhost/test");
});
});

describe("plugins",() => {
var core = new Iridium.Core({
database: 'test'
});

var plugin = {
newModel: (model) => {

}
};

it("should be registered through the register method",() => {
chai.expect(core.register(plugin)).to.equal(core);
});
it("should then be available through the plugins collection",() => {
chai.expect(core.plugins).to.contain(plugin);
});
});

describe("middleware",() => {
var core = new Iridium.Core({
database: 'test'
});

it("should have an Express provider",() => {
chai.expect(core.express).to.exist.and.be.a('function');
});
});

describe("cache",() => {
var core = new Iridium.Core({
database: 'test'
});

it("should have a default no-op cache provider",() => {
chai.expect(core.cache).to.exist;
return core.cache.set("test", true).then(() => {
chai.expect(core.cache.get("test")).to.eventually.not.exist;
});
});
});

describe("connect",() => {
var core: Iridium.Core;
it("should return a rejection if the connection fails",() => {
core = new Iridium.Core("mongodb://0.0.0.0/test");
return chai.expect(core.connect()).to.be.rejected;
});

it("should open a connection to the correct database and return the core",() => {
core = new Iridium.Core("mongodb://localhost/test");
return chai.expect(core.connect()).to.eventually.exist.and.equal(core);
});

it("should then be able to close the connection",() => {
return core.close();
});
});

describe("close",() => {
var core = new Iridium.Core("mongodb://localhost/test");

it("should not fail if called when not connected",() => {
return core.close();
});

it("should chain promises",() => {
chai.expect(core.close()).to.eventually.equal(core);
});
});

describe("inheritance",() => {
it("should allow a class to extend the core",() => {
chai.expect(InheritedCore).to.exist;
chai.expect(new InheritedCore("mongodb://localhost/test")).to.be.an.instanceof(Iridium.Core);
});

it("should pass through constructor arguments to the core",() => {
var core = new InheritedCore({
database: 'test'
});

chai.expect(core.url).to.equal("mongodb://localhost/test");
});

it("should pass through the properties of the object",() => {
var core = new InheritedCore({
database: 'test'
});

chai.expect(core.theAnswer).to.equal(42);
});

it("should support custom constructors",() => {
var core = new InheritedCoreWithCustomConstructor();
chai.expect(core.url).to.equal("mongodb://localhost/test");
});
});
});
15 changes: 15 additions & 0 deletions test/Iridium.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import Iridium = require('../index');

describe("Iridium",() => {
it("should expose the Core",() => {
chai.expect(Iridium.Core).to.exist.and.be.a('function');
});

it("should expose the Model constructor", () => {
chai.expect(Iridium.Model).to.exist.and.be.a('function');
});

it("should expose the default Instance class",() => {
chai.expect(Iridium.Instance).to.exist.and.be.a('function');
});
});
30 changes: 0 additions & 30 deletions test/bugs.js

This file was deleted.

82 changes: 0 additions & 82 deletions test/cache.js

This file was deleted.

74 changes: 0 additions & 74 deletions test/callbacks.js

This file was deleted.

0 comments on commit 6411221

Please sign in to comment.