diff --git a/test/Aggregate.ts b/test/Aggregate.ts
index d634432..d7b4428 100644
--- a/test/Aggregate.ts
+++ b/test/Aggregate.ts
@@ -1,9 +1,9 @@
///
-import * as Iridium from '../index';
-import MongoDB = require('mongodb');
-import {Cursor} from '../lib/Cursor';
-import Promise = require('bluebird');
-import _ = require('lodash');
+import * as Iridium from "../index";
+import MongoDB = require("mongodb");
+import {Cursor} from "../lib/Cursor";
+import Promise = require("bluebird");
+import _ = require("lodash");
interface TestDocument {
_id?: string;
@@ -12,7 +12,7 @@ interface TestDocument {
}
class Test extends Iridium.Instance implements TestDocument {
- static collection = 'test';
+ static collection = "test";
static schema: Iridium.Schema = {
_id: MongoDB.ObjectID,
group: String,
@@ -25,7 +25,7 @@ class Test extends Iridium.Instance implements TestDocument
}
describe("Model", () => {
- let core = new Iridium.Core({ database: 'test' });
+ let core = new Iridium.Core({ database: "test" });
before(() => core.connect());
@@ -34,27 +34,27 @@ describe("Model", () => {
beforeEach(() => {
return core.connect().then(() => model.remove()).then(() => model.insert([
- { group: 'A', score: 10 },
- { group: 'B', score: 11 },
- { group: 'C', score: 12 },
- { group: 'A', score: 13 },
- { group: 'B', score: 14 }
+ { group: "A", score: 10 },
+ { group: "B", score: 11 },
+ { group: "C", score: 12 },
+ { group: "A", score: 13 },
+ { group: "B", score: 14 }
]));
});
it("should correctly pass through the aggregation pipeline", () => {
return chai.expect(model.aggregate([
- { $group: { _id: '$group', score: { $sum: "$score" } } }
+ { $group: { _id: "$group", score: { $sum: "$score" } } }
])).to.eventually.exist.and.have.length(3);
});
it("should allow you to specify the type of the resulting documents", () => {
return model.aggregate<{ _id: string; score: number; }>([
- { $match: { group: 'A' } },
- { $group: { _id: '$group', score: { $sum: "$score" } } }
+ { $match: { group: "A" } },
+ { $group: { _id: "$group", score: { $sum: "$score" } } }
]).then(results => {
chai.expect(results).to.exist.and.have.length(1);
- chai.expect(results[0]._id).to.eql('A');
+ chai.expect(results[0]._id).to.eql("A");
chai.expect(results[0].score).to.eql(23);
});
});
diff --git a/test/Cache.ts b/test/Cache.ts
index 5dce461..2c18115 100644
--- a/test/Cache.ts
+++ b/test/Cache.ts
@@ -1,12 +1,12 @@
///
-import * as Iridium from '../index';
+import * as Iridium from "../index";
interface Document {
_id?: string;
}
class Instance extends Iridium.Instance {
- static collection = 'test';
+ static collection = "test";
static schema: Iridium.Schema = { _id: false };
static cache = new Iridium.CacheOnID();
@@ -72,21 +72,21 @@ describe("Cache",() => {
let director = new Iridium.CacheOnID();
it("should only report that objects with an _id field are cacheable",() => {
- chai.expect(director.valid({ _id: 'test' })).to.be.true;
- chai.expect(director.valid({ noID: 'test' })).to.be.false;
+ chai.expect(director.valid({ _id: "test" })).to.be.true;
+ chai.expect(director.valid({ noID: "test" })).to.be.false;
});
it("should generate a key based on the object's ID",() => {
- chai.expect(director.buildKey({ _id: 'test' })).to.be.equal('test');
+ chai.expect(director.buildKey({ _id: "test' })).to.be.equal('test");
});
it("should only report that queries which specify the _id field are usable",() => {
- chai.expect(director.validQuery({ _id: 'test' })).to.be.true;
- chai.expect(director.validQuery({ notID: 'test' })).to.be.false;
+ chai.expect(director.validQuery({ _id: "test" })).to.be.true;
+ chai.expect(director.validQuery({ notID: "test" })).to.be.false;
});
it("should generate a key based on the query ID",() => {
- chai.expect(director.buildQueryKey({ _id: 'test' })).to.be.equal('test');
+ chai.expect(director.buildQueryKey({ _id: "test' })).to.be.equal('test");
});
});
@@ -94,7 +94,7 @@ describe("Cache",() => {
describe("integration",() => {
let core = new Iridium.Core({
- database: 'test'
+ database: "test"
});
let model = new Iridium.Model(core, Instance);
diff --git a/test/Core.ts b/test/Core.ts
index 1077a6d..789b518 100644
--- a/test/Core.ts
+++ b/test/Core.ts
@@ -1,7 +1,7 @@
///
-import * as Iridium from '../index';
-import events = require('events');
-import Bluebird = require('bluebird');
+import * as Iridium from "../index";
+import events = require("events");
+import Bluebird = require("bluebird");
class InheritedCore extends Iridium.Core {
theAnswer = 42;
@@ -25,12 +25,12 @@ class InheritedCoreWithHooks extends Iridium.Core {
onConnectedResult: () => Bluebird = () => Bluebird.resolve();
protected onConnecting(db) {
- this.events.emit('connecting', db);
+ this.events.emit("connecting", db);
return this.onConnectingResult(db);
}
protected onConnected() {
- this.events.emit('connected');
+ this.events.emit("connected");
return this.onConnectedResult();
}
}
@@ -44,7 +44,7 @@ describe("Core",() => {
it("should accept a configuration object",() => {
new Iridium.Core({
- database: 'test'
+ database: "test"
});
});
@@ -55,11 +55,11 @@ describe("Core",() => {
describe("should correctly convert the configuration object into a URI string", () => {
it("when only a single host is specified",() => {
let core = new Iridium.Core({
- host: 'localhost',
+ host: "localhost",
port: 27016,
- database: 'test',
- username: 'user',
- password: 'password'
+ database: "test",
+ username: "user",
+ password: "password"
});
chai.expect(core.url).to.equal("mongodb://user:password@localhost:27016/test");
@@ -67,10 +67,10 @@ describe("Core",() => {
it("when only a single host is specified with no port",() => {
let core = new Iridium.Core({
- host: 'localhost',
- database: 'test',
- username: 'user',
- password: 'password'
+ host: "localhost",
+ database: "test",
+ username: "user",
+ password: "password"
});
chai.expect(core.url).to.equal("mongodb://user:password@localhost/test");
@@ -78,11 +78,11 @@ describe("Core",() => {
it("when multiple hosts are specified",() => {
let core = new Iridium.Core({
- hosts: [{ address: 'localhost' }, { address: '127.0.0.1' }],
- database: 'test',
+ hosts: [{ address: "localhost" }, { address: "127.0.0.1" }],
+ database: "test",
port: 27016,
- username: 'user',
- password: 'password'
+ username: "user",
+ password: "password"
});
chai.expect(core.url).to.equal("mongodb://user:password@localhost:27016,127.0.0.1:27016/test");
@@ -90,10 +90,10 @@ describe("Core",() => {
it("when multiple hosts are specified with no port",() => {
let core = new Iridium.Core({
- hosts: [{ address: 'localhost' }, { address: '127.0.0.1' }],
- database: 'test',
- username: 'user',
- password: 'password'
+ hosts: [{ address: "localhost" }, { address: "127.0.0.1" }],
+ database: "test",
+ username: "user",
+ password: "password"
});
chai.expect(core.url).to.equal("mongodb://user:password@localhost,127.0.0.1/test");
@@ -101,10 +101,10 @@ describe("Core",() => {
it("when multiple hosts are specified with different ports",() => {
let core = new Iridium.Core({
- hosts: [{ address: 'localhost', port: 27016 }, { address: '127.0.0.1', port: 27017 }],
- database: 'test',
- username: 'user',
- password: 'password'
+ hosts: [{ address: "localhost", port: 27016 }, { address: "127.0.0.1", port: 27017 }],
+ database: "test",
+ username: "user",
+ password: "password"
});
chai.expect(core.url).to.equal("mongodb://user:password@localhost:27016,127.0.0.1:27017/test");
@@ -112,12 +112,12 @@ describe("Core",() => {
it("when a combination of single and multiple hosts is specified",() => {
let core = new Iridium.Core({
- host: 'localhost',
+ host: "localhost",
port: 27016,
- hosts: [{ address: 'localhost', port: 27017 }, { address: '127.0.0.1', port: 27018 }],
- database: 'test',
- username: 'user',
- password: 'password'
+ hosts: [{ address: "localhost", port: 27017 }, { address: "127.0.0.1", port: 27018 }],
+ database: "test",
+ username: "user",
+ password: "password"
});
chai.expect(core.url).to.equal("mongodb://user:password@localhost:27016,localhost:27017,127.0.0.1:27018/test");
@@ -125,12 +125,12 @@ describe("Core",() => {
it("when a combination of single and multiple hosts is specified and there are duplicates",() => {
let core = new Iridium.Core({
- host: 'localhost',
+ host: "localhost",
port: 27016,
- hosts: [{ address: 'localhost', port: 27016 }, { address: '127.0.0.1', port: 27017 }],
- database: 'test',
- username: 'user',
- password: 'password'
+ hosts: [{ address: "localhost", port: 27016 }, { address: "127.0.0.1", port: 27017 }],
+ database: "test",
+ username: "user",
+ password: "password"
});
chai.expect(core.url).to.equal("mongodb://user:password@localhost:27016,127.0.0.1:27017/test");
@@ -139,7 +139,7 @@ describe("Core",() => {
it("should make logical assumptions about the default host",() => {
let core = new Iridium.Core({
- database: 'test'
+ database: "test"
});
chai.expect(core.url).to.equal("mongodb://localhost/test");
@@ -147,7 +147,7 @@ describe("Core",() => {
it("should support passing connection level configuration information", () => {
let core = new Iridium.Core({
- database: 'test',
+ database: "test",
options: {
server: {
socketOptions: {
@@ -169,7 +169,7 @@ describe("Core",() => {
describe("plugins",() => {
let core = new Iridium.Core({
- database: 'test'
+ database: "test"
});
let plugin = {
@@ -188,18 +188,18 @@ describe("Core",() => {
describe("middleware",() => {
let core = new Iridium.Core({
- database: 'test'
+ database: "test"
});
it("should have an Express provider",() => {
- chai.expect(core.express).to.exist.and.be.a('function');
- chai.expect(core.express()).to.exist.and.be.a('function');
+ chai.expect(core.express).to.exist.and.be.a("function");
+ chai.expect(core.express()).to.exist.and.be.a("function");
});
});
describe("cache",() => {
let core = new Iridium.Core({
- database: 'test'
+ database: "test"
});
it("should have a default no-op cache provider",() => {
@@ -211,8 +211,8 @@ describe("Core",() => {
describe("settings",() => {
it("should be exposed via the settings property",() => {
- let core = new Iridium.Core({ database: 'test' });
- chai.expect(core.settings).to.exist.and.eql({ database: 'test' });
+ let core = new Iridium.Core({ database: "test" });
+ chai.expect(core.settings).to.exist.and.eql({ database: "test" });
});
});
@@ -255,7 +255,7 @@ describe("Core",() => {
it("should pass through constructor arguments to the core",() => {
let core = new InheritedCore({
- database: 'test'
+ database: "test"
});
chai.expect(core.url).to.equal("mongodb://localhost/test");
@@ -263,7 +263,7 @@ describe("Core",() => {
it("should pass through the properties of the object",() => {
let core = new InheritedCore({
- database: 'test'
+ database: "test"
});
chai.expect(core.theAnswer).to.equal(42);
@@ -279,7 +279,7 @@ describe("Core",() => {
describe("onConnecting", () => {
it("should be called whenever a low level connection is established", (done) => {
let core = new InheritedCoreWithHooks();
- core.events.once('connecting', (connection) => {
+ core.events.once("connecting", (connection) => {
done();
});
@@ -291,7 +291,7 @@ describe("Core",() => {
it("should be passed the underlying connection", (done) => {
let core = new InheritedCoreWithHooks();
- core.events.once('connecting', (connection) => {
+ core.events.once("connecting", (connection) => {
chai.expect(connection).to.exist;
done();
});
@@ -304,7 +304,7 @@ describe("Core",() => {
it("should be triggered before the connection is established", (done) => {
let core = new InheritedCoreWithHooks();
- core.events.once('connecting', (connection) => {
+ core.events.once("connecting", (connection) => {
chai.expect(core.connection).to.not.exist;
done();
});
@@ -317,14 +317,14 @@ describe("Core",() => {
it("should abort the connection if it throws an error", () => {
let core = new InheritedCoreWithHooks();
- core.onConnectingResult = (conn) => Bluebird.reject(new Error('Test error'));
+ core.onConnectingResult = (conn) => Bluebird.reject(new Error("Test error"));
- return chai.expect(core.connect()).to.eventually.be.rejectedWith('Test error');
+ return chai.expect(core.connect()).to.eventually.be.rejectedWith("Test error");
});
it("should leave the Iridium core disconnected if it throws an error", () => {
let core = new InheritedCoreWithHooks();
- core.onConnectingResult = (conn) => Bluebird.reject(new Error('Test error'));
+ core.onConnectingResult = (conn) => Bluebird.reject(new Error("Test error"));
return chai.expect(core.connect().then(() => false, (err) => {
chai.expect(core.connection).to.not.exist;
@@ -336,7 +336,7 @@ describe("Core",() => {
describe("onConnected", () => {
it("should be called whenever a connection is accepted", (done) => {
let core = new InheritedCoreWithHooks();
- core.events.once('connected', () => {
+ core.events.once("connected", () => {
done();
});
@@ -348,7 +348,7 @@ describe("Core",() => {
it("should be triggered after the connection is accepted", (done) => {
let core = new InheritedCoreWithHooks();
- core.events.once('connected', () => {
+ core.events.once("connected", () => {
chai.expect(core.connection).to.exist;
done();
});
@@ -361,14 +361,14 @@ describe("Core",() => {
it("should abort the connection if it throws an error", () => {
let core = new InheritedCoreWithHooks();
- core.onConnectedResult = () => Bluebird.reject(new Error('Test error'));
+ core.onConnectedResult = () => Bluebird.reject(new Error("Test error"));
- return chai.expect(core.connect()).to.eventually.be.rejectedWith('Test error');
+ return chai.expect(core.connect()).to.eventually.be.rejectedWith("Test error");
});
it("should leave the Iridium core disconnected if it throws an error", () => {
let core = new InheritedCoreWithHooks();
- core.onConnectedResult = () => Bluebird.reject(new Error('Test error'));
+ core.onConnectedResult = () => Bluebird.reject(new Error("Test error"));
return chai.expect(core.connect().then(() => false, (err) => {
chai.expect(core.connection).to.not.exist;
diff --git a/test/Decorators.ts b/test/Decorators.ts
index c4149ea..98791bf 100644
--- a/test/Decorators.ts
+++ b/test/Decorators.ts
@@ -1,8 +1,8 @@
///
-import * as Iridium from '../index';
-import skmatc = require('skmatc');
-import MongoDB = require('mongodb');
-import {DefaultValidators} from '../lib/Validators';
+import * as Iridium from "../index";
+import skmatc = require("skmatc");
+import MongoDB = require("mongodb");
+import {DefaultValidators} from "../lib/Validators";
interface TestDocument {
_id?: string;
@@ -14,12 +14,12 @@ function VersionValidator(schema, data) {
return this.assert(/^\d+\.\d+\.\d+(?:-.+)?$/.test(data));
}
-@Iridium.Collection('test')
+@Iridium.Collection("test")
@Iridium.Index({ name: 1 })
@Iridium.Index({ email: 1 }, { background: true })
-@Iridium.Validate('version', VersionValidator)
-@Iridium.Property('version', 'version')
-@Iridium.Property('optional2', Boolean, false)
+@Iridium.Validate("version", VersionValidator)
+@Iridium.Property("version", "version")
+@Iridium.Property("optional2", Boolean, false)
class Test extends Iridium.Instance implements TestDocument {
static transforms: Iridium.Transforms = {};
static indexes = [];
@@ -44,7 +44,7 @@ class Test extends Iridium.Instance implements TestDocument
describe("Decorators", () => {
describe("Collection", () => {
it("should populate the collection static field", () => {
- chai.expect(Test.collection).to.equal('test');
+ chai.expect(Test.collection).to.equal("test");
});
it("should not pollute the parent's collection property", () => {
@@ -79,30 +79,30 @@ describe("Decorators", () => {
let s = skmatc.scope(Test.schema);
for (let i = 0; i < Test.validators.length; i++) {
- chai.expect(Test.validators[i]).to.be.a('function');
+ chai.expect(Test.validators[i]).to.be.a("function");
s.register(Test.validators[i]);
}
chai.expect(s.validate({
- name: 'Test',
- email: 'test@test.com',
- version: '1.0.0'
- })).to.exist.and.have.property('failures').eql([]);
+ name: "Test",
+ email: "test@test.com",
+ version: "1.0.0"
+ })).to.exist.and.have.property("failures").eql([]);
});
it("should correctly include the validations", () => {
let s = skmatc.scope(Test.schema);
for (let i = 0; i < Test.validators.length; i++) {
- chai.expect(Test.validators[i]).to.be.a('function');
+ chai.expect(Test.validators[i]).to.be.a("function");
s.register(Test.validators[i]);
}
chai.expect(s.validate({
- name: 'Test',
- email: 'test@test.com',
- version: 'a1.0.0'
- })).to.exist.and.have.property('failures').not.eql([]);
+ name: "Test",
+ email: "test@test.com",
+ version: "a1.0.0"
+ })).to.exist.and.have.property("failures").not.eql([]);
});
it("should not pollute the parent's validators object", () => {
@@ -112,70 +112,70 @@ describe("Decorators", () => {
describe("ObjectID", () => {
it("should populate the constructor's schema object", () => {
- chai.expect(Test.schema).to.exist.and.have.property('_id').and.eql(MongoDB.ObjectID);
+ chai.expect(Test.schema).to.exist.and.have.property("_id").and.eql(MongoDB.ObjectID);
});
it("should populate the constructor's transforms object", () => {
- chai.expect(Test.transforms).to.exist.and.have.property('_id').with.property('fromDB').which.is.a('function');
- chai.expect(Test.transforms).to.exist.and.have.property('_id').with.property('toDB').which.is.a('function');
+ chai.expect(Test.transforms).to.exist.and.have.property("_id").with.property("fromDB").which.is.a("function");
+ chai.expect(Test.transforms).to.exist.and.have.property("_id").with.property("toDB").which.is.a("function");
});
describe("the ObjectID transform", () => {
it("should convert an ObjectID to a string", () => {
- chai.expect(Test.transforms['_id'].fromDB(Iridium.toObjectID('aaaaaaaaaaaaaaaaaaaaaaaa'), '_id', null)).to.eql('aaaaaaaaaaaaaaaaaaaaaaaa');
+ chai.expect(Test.transforms["_id"].fromDB(Iridium.toObjectID("aaaaaaaaaaaaaaaaaaaaaaaa"), "_id", null)).to.eql("aaaaaaaaaaaaaaaaaaaaaaaa");
});
it("should convert a string to an ObjectID", () => {
- chai.expect(Test.transforms['_id'].toDB('aaaaaaaaaaaaaaaaaaaaaaaa', '_id', null)).to.be.instanceOf(MongoDB.ObjectID);
+ chai.expect(Test.transforms["_id"].toDB("aaaaaaaaaaaaaaaaaaaaaaaa", "_id", null)).to.be.instanceOf(MongoDB.ObjectID);
});
it("should handle undefined values correctly", () => {
- chai.expect(Test.transforms['_id'].toDB(undefined, '_id', null)).to.not.exist;
- chai.expect(Test.transforms['_id'].fromDB(undefined, '_id', null)).to.not.exist;
+ chai.expect(Test.transforms["_id"].toDB(undefined, "_id", null)).to.not.exist;
+ chai.expect(Test.transforms["_id"].fromDB(undefined, "_id", null)).to.not.exist;
});
});
});
describe("Property", () => {
it("should populate the constructor's schema object when applied to properties", () => {
- chai.expect(Test.schema).to.exist.and.have.property('name', String);
- chai.expect(Test.schema).to.exist.and.have.property('email').and.eql(/^.+@.+$/);
+ chai.expect(Test.schema).to.exist.and.have.property("name", String);
+ chai.expect(Test.schema).to.exist.and.have.property("email").and.eql(/^.+@.+$/);
});
it("should populate the constructor's schema object when to the constructor", () => {
- chai.expect(Test.schema).to.exist.and.have.property('version', 'version');
+ chai.expect(Test.schema).to.exist.and.have.property("version", "version");
});
it("should correctly handle optional properties defined on instance fields", () => {
- chai.expect(Test.schema).to.exist.and.have.property('optional1').eql({ $required: false, $type: Boolean });
+ chai.expect(Test.schema).to.exist.and.have.property("optional1").eql({ $required: false, $type: Boolean });
});
it("should correctly handle optional properties defined on the constructor", () => {
- chai.expect(Test.schema).to.exist.and.have.property('optional2').eql({ $required: false, $type: Boolean });
+ chai.expect(Test.schema).to.exist.and.have.property("optional2").eql({ $required: false, $type: Boolean });
});
it("should not pollute the parent's schema object", () => {
- chai.expect(Iridium.Instance.schema).to.exist.and.not.have.property('name');
- chai.expect(Iridium.Instance.schema).to.exist.and.not.have.property('email');
- chai.expect(Iridium.Instance.schema).to.exist.and.not.have.property('version');
- chai.expect(Iridium.Instance.schema).to.exist.and.not.have.property('optional1');
- chai.expect(Iridium.Instance.schema).to.exist.and.not.have.property('optional2');
+ chai.expect(Iridium.Instance.schema).to.exist.and.not.have.property("name");
+ chai.expect(Iridium.Instance.schema).to.exist.and.not.have.property("email");
+ chai.expect(Iridium.Instance.schema).to.exist.and.not.have.property("version");
+ chai.expect(Iridium.Instance.schema).to.exist.and.not.have.property("optional1");
+ chai.expect(Iridium.Instance.schema).to.exist.and.not.have.property("optional2");
});
});
describe("Transform", () => {
it("should not remove existing entries in the transforms object", () => {
- chai.expect(Test.transforms).to.exist.and.have.property('_id').with.property('fromDB').which.is.a('function');
- chai.expect(Test.transforms).to.exist.and.have.property('_id').with.property('toDB').which.is.a('function');
+ chai.expect(Test.transforms).to.exist.and.have.property("_id").with.property("fromDB").which.is.a("function");
+ chai.expect(Test.transforms).to.exist.and.have.property("_id").with.property("toDB").which.is.a("function");
});
it("should populate the constructor's transforms object", () => {
- chai.expect(Test.transforms).to.exist.and.have.property('email').with.property('fromDB').which.is.a('function');
- chai.expect(Test.transforms).to.exist.and.have.property('email').with.property('toDB').which.is.a('function');
+ chai.expect(Test.transforms).to.exist.and.have.property("email").with.property("fromDB").which.is.a("function");
+ chai.expect(Test.transforms).to.exist.and.have.property("email").with.property("toDB").which.is.a("function");
});
it("should not pollute the parent's transforms object", () => {
- chai.expect(Iridium.Instance.transforms).to.exist.and.not.have.property('email');
+ chai.expect(Iridium.Instance.transforms).to.exist.and.not.have.property("email");
});
});
});
\ No newline at end of file
diff --git a/test/Hooks.ts b/test/Hooks.ts
index d3cf201..453ff69 100644
--- a/test/Hooks.ts
+++ b/test/Hooks.ts
@@ -1,7 +1,7 @@
///
-import * as Iridium from '../index';
-import Events = require('events');
-import Promise = require('bluebird');
+import * as Iridium from "../index";
+import Events = require("events");
+import Promise = require("bluebird");
interface TestDocument {
id?: string;
@@ -12,7 +12,7 @@ let hookEmitter = new Events.EventEmitter();
let shouldReject = 0;
class Test extends Iridium.Instance {
- static collection = 'test';
+ static collection = "test";
static schema: Iridium.Schema = {
_id: false,
answer: Number
@@ -22,30 +22,30 @@ class Test extends Iridium.Instance {
answer: number;
static onCreating(document: TestDocument) {
- if (shouldReject === 1) return Promise.reject('test rejection');
- hookEmitter.emit('creating', document);
+ if (shouldReject === 1) return Promise.reject("test rejection");
+ hookEmitter.emit("creating", document);
}
static onReady(instance: Test) {
- if (shouldReject === 2) return Promise.reject('test rejection');
- hookEmitter.emit('ready', instance);
+ if (shouldReject === 2) return Promise.reject("test rejection");
+ hookEmitter.emit("ready", instance);
}
static onRetrieved(document: TestDocument) {
- if (shouldReject === 3) return Promise.reject('test rejection');
- hookEmitter.emit('retrieved', document);
+ if (shouldReject === 3) return Promise.reject("test rejection");
+ hookEmitter.emit("retrieved", document);
}
static onSaving(instance: Test, changes: any) {
- if (shouldReject === 4) return Promise.reject('test rejection');
- hookEmitter.emit('saving', instance, changes);
+ if (shouldReject === 4) return Promise.reject("test rejection");
+ hookEmitter.emit("saving", instance, changes);
}
}
describe("Hooks", function () {
this.timeout(500);
- let core = new Iridium.Core({ database: 'test' });
+ let core = new Iridium.Core({ database: "test" });
let model = new Iridium.Model(core, Test);
beforeEach(() => shouldReject = 0);
@@ -60,14 +60,14 @@ describe("Hooks", function () {
});
it("should be called when a document is being created",(done) => {
- hookEmitter.once('creating',() => done());
+ hookEmitter.once("creating",() => done());
model.insert({ answer: 11 });
});
it("should be passed the document being created",() => {
let result: Promise;
- hookEmitter.once('creating',(document) => {
+ hookEmitter.once("creating",(document) => {
result = Promise.resolve().then(() => {
chai.expect(document).to.eql({ answer: 11 });
});
@@ -95,7 +95,7 @@ describe("Hooks", function () {
it("should be called when an instance is prepared",() => {
let result: Promise;
- hookEmitter.once('ready',() => {
+ hookEmitter.once("ready",() => {
result = Promise.resolve();
});
@@ -105,7 +105,7 @@ describe("Hooks", function () {
it("should be passed the instance which was created",() => {
let result: Promise;
- hookEmitter.once('ready',(instance) => {
+ hookEmitter.once("ready",(instance) => {
result = Promise.resolve().then(() => {
chai.expect(instance).to.be.an.instanceof(model.Instance);
});
@@ -133,7 +133,7 @@ describe("Hooks", function () {
it("should be called when a document is being retrieved",() => {
let result: Promise;
- hookEmitter.once('retrieved',() => {
+ hookEmitter.once("retrieved",() => {
result = Promise.resolve();
});
@@ -143,9 +143,9 @@ describe("Hooks", function () {
it("should be passed the document being retrieved",() => {
let result: Promise;
- hookEmitter.once('retrieved',(document) => {
+ hookEmitter.once("retrieved",(document) => {
result = Promise.resolve().then(() => {
- chai.expect(document).to.have.property('answer', 10);
+ chai.expect(document).to.have.property("answer", 10);
});
});
@@ -171,7 +171,7 @@ describe("Hooks", function () {
it("should be triggered when save() is called on an instance",() => {
let result: Promise;
- hookEmitter.once('saving',() => {
+ hookEmitter.once("saving",() => {
result = Promise.resolve();
});
@@ -184,7 +184,7 @@ describe("Hooks", function () {
it("should be passed the instance being saved",() => {
let result: Promise;
- hookEmitter.once('saving',(instance) => {
+ hookEmitter.once("saving",(instance) => {
result = Promise.resolve().then(() => {
chai.expect(instance).to.be.an.instanceof(model.Instance);
});
@@ -199,7 +199,7 @@ describe("Hooks", function () {
it("should be passed the changes being made to the instance",() => {
let result: Promise;
- hookEmitter.once('saving',(instance, changes) => {
+ hookEmitter.once("saving",(instance, changes) => {
result = Promise.resolve().then(() => {
chai.expect(changes).to.eql({
$set: { answer: instance.answer }
diff --git a/test/Instance.ts b/test/Instance.ts
index bd98cf6..c919cec 100644
--- a/test/Instance.ts
+++ b/test/Instance.ts
@@ -1,7 +1,7 @@
///
-import * as Iridium from '../index';
-import MongoDB = require('mongodb');
-import Bluebird = require('bluebird');
+import * as Iridium from "../index";
+import MongoDB = require("mongodb");
+import Bluebird = require("bluebird");
interface TestDocument {
_id?: string;
@@ -11,7 +11,7 @@ interface TestDocument {
}
class Test extends Iridium.Instance implements TestDocument {
- static collection = 'test';
+ static collection = "test";
static schema: Iridium.Schema = {
_id: false,
answer: Number,
@@ -67,54 +67,54 @@ describe("Instance",() => {
it("should expose the latest document values",() => {
let instance = core.Test.helpers.wrapDocument({
- _id: 'aaaaaa',
+ _id: "aaaaaa",
answer: 2
});
chai.expect(instance).to.exist;
chai.expect(instance.answer).to.be.equal(2);
- chai.expect(instance._id).to.be.equal('aaaaaa');
+ chai.expect(instance._id).to.be.equal("aaaaaa");
});
describe("methods",() => {
it("should expose save()",() => {
- chai.expect(core.Test.helpers.wrapDocument({ _id: '1', answer: 2 }).save).to.exist.and.be.a('function');
+ chai.expect(core.Test.helpers.wrapDocument({ _id: "1", answer: 2 }).save).to.exist.and.be.a("function");
});
it("should expose update()",() => {
- chai.expect(core.Test.helpers.wrapDocument({ _id: '1', answer: 2 }).update).to.exist.and.be.a('function');
+ chai.expect(core.Test.helpers.wrapDocument({ _id: "1", answer: 2 }).update).to.exist.and.be.a("function");
});
it("should expose refresh()",() => {
- chai.expect(core.Test.helpers.wrapDocument({ _id: '1', answer: 2 }).refresh).to.exist.and.be.a('function');
+ chai.expect(core.Test.helpers.wrapDocument({ _id: "1", answer: 2 }).refresh).to.exist.and.be.a("function");
});
it("should expose delete()",() => {
- chai.expect(core.Test.helpers.wrapDocument({ _id: '1', answer: 2 }).delete).to.exist.and.be.a('function');
+ chai.expect(core.Test.helpers.wrapDocument({ _id: "1", answer: 2 }).delete).to.exist.and.be.a("function");
});
it("should expose remove()",() => {
- chai.expect(core.Test.helpers.wrapDocument({ _id: '1', answer: 2 }).remove).to.exist.and.be.a('function');
+ chai.expect(core.Test.helpers.wrapDocument({ _id: "1", answer: 2 }).remove).to.exist.and.be.a("function");
});
it("should override toJSON()",() => {
- chai.expect(core.Test.helpers.wrapDocument({ _id: '1', answer: 2 }).toJSON()).to.eql({ _id: '1', answer: 2 });
+ chai.expect(core.Test.helpers.wrapDocument({ _id: "1", answer: 2 }).toJSON()).to.eql({ _id: "1", answer: 2 });
});
it("should override toString()",() => {
- chai.expect(core.Test.helpers.wrapDocument({ _id: '1', answer: 2 }).toString()).to.eql(JSON.stringify({ _id: '1', answer: 2 }, null, 2));
+ chai.expect(core.Test.helpers.wrapDocument({ _id: "1", answer: 2 }).toString()).to.eql(JSON.stringify({ _id: "1", answer: 2 }, null, 2));
});
});
describe("properties",() => {
it("should expose document",() => {
- chai.expect(core.Test.helpers.wrapDocument({ _id: '1', answer: 2 }).document).to.eql({ _id: '1', answer: 2 });
+ chai.expect(core.Test.helpers.wrapDocument({ _id: "1", answer: 2 }).document).to.eql({ _id: "1", answer: 2 });
});
});
it("should expose additional getters and setters",() => {
let instance = core.Test.helpers.wrapDocument({
- _id: 'aaaaaa',
+ _id: "aaaaaa",
answer: 2
});
@@ -124,12 +124,12 @@ describe("Instance",() => {
it("should expose additional methods",() => {
let instance = core.Test.helpers.wrapDocument({
- _id: 'aaaaaa',
+ _id: "aaaaaa",
answer: 2
});
chai.expect(instance).to.exist;
- chai.expect(instance.test).to.exist.and.be.a('function');
+ chai.expect(instance.test).to.exist.and.be.a("function");
});
describe("should handle _id in a special manner",() => {
@@ -138,15 +138,15 @@ describe("Instance",() => {
it("get should transform ObjectIDs into hex strings",() => {
return core.Test.get().then(instance => {
- chai.expect((instance.document._id)._bsontype).to.equal('ObjectID');
- chai.expect(instance._id).to.be.a('string').with.length(24);
+ chai.expect((instance.document._id)._bsontype).to.equal("ObjectID");
+ chai.expect(instance._id).to.be.a("string").with.length(24);
});
});
it("set should transform hex strings into ObjectIDs by default",() => {
return core.Test.get().then(instance => {
instance._id = "aaaaaaaaaaaaaaaaaaaaaaaa";
- chai.expect(new MongoDB.ObjectID(instance.document._id).toHexString()).to.equal('aaaaaaaaaaaaaaaaaaaaaaaa');
+ chai.expect(new MongoDB.ObjectID(instance.document._id).toHexString()).to.equal("aaaaaaaaaaaaaaaaaaaaaaaa");
});
});
});
@@ -174,7 +174,7 @@ describe("Instance",() => {
});
chai.expect((instance)._isNew).to.be.true;
- return chai.expect(instance.save().then(() => chai.expect(core.Test.get(instance._id)).to.eventually.have.property('answer', instance.answer))).to.eventually.be.ok;
+ return chai.expect(instance.save().then(() => chai.expect(core.Test.get(instance._id)).to.eventually.have.property("answer", instance.answer))).to.eventually.be.ok;
});
it("should automatically generate the update query if one was not provided",() => {
@@ -183,7 +183,7 @@ describe("Instance",() => {
}).then(() => chai.expect(core.Test.get().then((instance) => {
instance.answer = 42;
return instance.save().then(() => core.Test.get(instance._id));
- })).to.eventually.have.property('answer', 42));
+ })).to.eventually.have.property("answer", 42));
});
it("should allow you to specify a custom update query",() => {
@@ -191,7 +191,7 @@ describe("Instance",() => {
answer: 1
})
.then(() => core.Test.get())
- .then((instance) => chai.expect(instance.save({ $set: { answer: 10 } })).to.eventually.have.property('answer', 10));
+ .then((instance) => chai.expect(instance.save({ $set: { answer: 10 } })).to.eventually.have.property("answer", 10));
});
it("should allow you tp specify a custom update query and conditions for the update",() => {
@@ -199,7 +199,7 @@ describe("Instance",() => {
answer: 1
})
.then(() => core.Test.get())
- .then((instance) => chai.expect(instance.save({ answer: { $lt: 5 } }, { $set: { answer: 10 } })).to.eventually.have.property('answer', 10));
+ .then((instance) => chai.expect(instance.save({ answer: { $lt: 5 } }, { $set: { answer: 10 } })).to.eventually.have.property("answer", 10));
});
it("should return a promise for the instance",() => {
@@ -237,7 +237,7 @@ describe("Instance",() => {
return core.Test.update({ _id: instance._id }, {
$set: { answer: 10 }
}).then(() => instance.update());
- })).to.eventually.have.property('answer', 10);
+ })).to.eventually.have.property("answer", 10);
});
it("should set _isNew to true if the instance was removed from the database",() => {
@@ -277,7 +277,7 @@ describe("Instance",() => {
return core.Test.update({ _id: instance._id }, {
$set: { answer: 10 }
}).then(() => instance.refresh());
- })).to.eventually.have.property('answer', 10);
+ })).to.eventually.have.property("answer", 10);
});
it("should set _isNew to true if the instance was removed from the database",() => {
@@ -313,7 +313,7 @@ describe("Instance",() => {
});
it("should set the instance's isNew property to true",() => {
- return chai.expect(core.Test.get().then((instance) => instance.remove())).to.eventually.have.property('_isNew', true);
+ return chai.expect(core.Test.get().then((instance) => instance.remove())).to.eventually.have.property("_isNew", true);
});
it("should return a promise for the instance",() => {
@@ -352,7 +352,7 @@ describe("Instance",() => {
});
it("should set the instance's isNew property to true",() => {
- return chai.expect(core.Test.get().then((instance) => instance.delete())).to.eventually.have.property('_isNew', true);
+ return chai.expect(core.Test.get().then((instance) => instance.delete())).to.eventually.have.property("_isNew", true);
});
it("should return a promise for the instance",() => {
@@ -384,14 +384,14 @@ describe("Instance",() => {
});
describe("first()",() => {
- beforeEach(() => core.Test.remove().then(() => core.Test.insert({ answer: 1, lots: [1, 2, 3, 4], less: { 'a': 1, 'b': 2 } })));
+ beforeEach(() => core.Test.remove().then(() => core.Test.insert({ answer: 1, lots: [1, 2, 3, 4], less: { "a": 1, "b": 2 } })));
it("should return the first object which matches the predicate over an array",() => {
return chai.expect(core.Test.get().then(instance => instance.first(instance.lots, lot => lot == 2))).to.eventually.equal(2);
});
it("should return the first object which matches the predicate over an object",() => {
- return chai.expect(core.Test.get().then(instance => instance.first(instance.less, (value, key) => key == 'a'))).to.eventually.equal(1);
+ return chai.expect(core.Test.get().then(instance => instance.first(instance.less, (value, key) => key == "a"))).to.eventually.equal(1);
});
it("should return null if no item was found",() => {
@@ -400,14 +400,14 @@ describe("Instance",() => {
});
describe("select()",() => {
- beforeEach(() => core.Test.remove().then(() => core.Test.insert({ answer: 1, lots: [1, 2, 3, 4], less: { 'a': 1, 'b': 2 } })));
+ beforeEach(() => core.Test.remove().then(() => core.Test.insert({ answer: 1, lots: [1, 2, 3, 4], less: { "a": 1, "b": 2 } })));
it("should return the objects which match the predicate over an array",() => {
return chai.expect(core.Test.get().then(instance => instance.select(instance.lots, lot => lot > 2))).to.eventually.eql([3, 4]);
});
it("should return the properties which match the predicate over an object",() => {
- return chai.expect(core.Test.get().then(instance => instance.select(instance.less,(value, key) => key == 'a'))).to.eventually.eql({ 'a': 1 });
+ return chai.expect(core.Test.get().then(instance => instance.select(instance.less,(value, key) => key == "a"))).to.eventually.eql({ "a": 1 });
});
it("should return an empty array if no items matched over an array",() => {
@@ -420,23 +420,23 @@ describe("Instance",() => {
});
describe("modifications", () => {
- beforeEach(() => core.Test.remove().then(() => core.Test.insert({ answer: 1, lots: [1, 2, 3, 4], less: { 'a': 1, 'b': 2 } })));
+ beforeEach(() => core.Test.remove().then(() => core.Test.insert({ answer: 1, lots: [1, 2, 3, 4], less: { "a": 1, "b": 2 } })));
it("should correctly diff simple property changes", () => {
return core.Test.get().then(instance => {
instance.answer = 2;
return instance.save();
}).then(instance => {
- chai.expect(instance).to.have.property('answer', 2);
+ chai.expect(instance).to.have.property("answer", 2);
});
});
it("should correctly diff deep property changes", () => {
return core.Test.get().then(instance => {
- instance.less['a'] = 2;
+ instance.less["a"] = 2;
return instance.save();
}).then(instance => {
- chai.expect(instance).to.have.property('less').eql({ a: 2, b: 2 });
+ chai.expect(instance).to.have.property("less").eql({ a: 2, b: 2 });
});
});
@@ -445,7 +445,7 @@ describe("Instance",() => {
instance.lots.push(5);
return instance.save();
}).then(instance => {
- chai.expect(instance).to.have.property('lots').eql([1,2,3,4,5]);
+ chai.expect(instance).to.have.property("lots").eql([1,2,3,4,5]);
});
});
});
@@ -453,7 +453,7 @@ describe("Instance",() => {
describe("after a save", () => {
var instance: Test;
- before(() => core.Test.remove().then(() => core.Test.insert({ answer: 1, lots: [1, 2, 3, 4], less: { 'a': 1, 'b': 2 } })).then(i => {
+ before(() => core.Test.remove().then(() => core.Test.insert({ answer: 1, lots: [1, 2, 3, 4], less: { "a": 1, "b": 2 } })).then(i => {
i.answer = 3;
return i.save();
}).then(i => instance = i));
@@ -468,17 +468,17 @@ describe("Instance",() => {
return i.save();
}).then(i => {
chai.expect(i).to.exist;
- chai.expect(i).to.have.property('answer', 2);
+ chai.expect(i).to.have.property("answer", 2);
});
});
it("should correctly diff deep property changes", () => {
return Bluebird.resolve(instance).then(i => {
- i.less['a'] = 2;
+ i.less["a"] = 2;
return i.save();
}).then(i => {
chai.expect(i).to.exist;
- chai.expect(i).to.have.property('less').eql({ a: 2, b: 2 });
+ chai.expect(i).to.have.property("less").eql({ a: 2, b: 2 });
});
});
@@ -488,7 +488,7 @@ describe("Instance",() => {
return i.save();
}).then(i => {
chai.expect(i).to.exist;
- chai.expect(i).to.have.property('lots').eql([1,2,3,4,5]);
+ chai.expect(i).to.have.property("lots").eql([1,2,3,4,5]);
});
});
diff --git a/test/Iridium.ts b/test/Iridium.ts
index 987f0a4..e965b53 100644
--- a/test/Iridium.ts
+++ b/test/Iridium.ts
@@ -1,16 +1,16 @@
///
-import * as Iridium from '../index';
+import * as Iridium from "../index";
describe("Iridium",() => {
it("should expose the Core",() => {
- chai.expect(Iridium.Core).to.exist.and.be.a('function');
+ 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');
+ 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');
+ chai.expect(Iridium.Instance).to.exist.and.be.a("function");
});
});
\ No newline at end of file
diff --git a/test/Middleware.ts b/test/Middleware.ts
index a892a02..b902ba7 100644
--- a/test/Middleware.ts
+++ b/test/Middleware.ts
@@ -1,20 +1,20 @@
///
-import * as Iridium from '../index';
+import * as Iridium from "../index";
describe("Middleware",() => {
let core = new Iridium.Core({
- database: 'test'
+ database: "test"
});
describe("Express",() => {
beforeEach(() => core.close());
it("should be available through Core.express()",() => {
- chai.expect(core.express).to.exist.and.be.a('function');
+ chai.expect(core.express).to.exist.and.be.a("function");
});
it("should return a function",() => {
- chai.expect(core.express()).to.exist.and.be.a('function');
+ chai.expect(core.express()).to.exist.and.be.a("function");
});
it("which sets req.db to the core instance",(done) => {
diff --git a/test/Model.ts b/test/Model.ts
index 1425f04..8fea953 100644
--- a/test/Model.ts
+++ b/test/Model.ts
@@ -1,9 +1,9 @@
///
-import * as Iridium from '../index';
-import MongoDB = require('mongodb');
-import {Cursor} from '../lib/Cursor';
-import Promise = require('bluebird');
-import _ = require('lodash');
+import * as Iridium from "../index";
+import MongoDB = require("mongodb");
+import {Cursor} from "../lib/Cursor";
+import Promise = require("bluebird");
+import _ = require("lodash");
interface TestDocument {
_id?: string;
@@ -11,7 +11,7 @@ interface TestDocument {
}
class Test extends Iridium.Instance implements TestDocument {
- static collection = 'test';
+ static collection = "test";
static schema: Iridium.Schema = {
_id: MongoDB.ObjectID,
answer: Number
@@ -31,7 +31,7 @@ class TestWithCustomID extends Test {
}
describe("Model",() => {
- let core = new Iridium.Core({ database: 'test' });
+ let core = new Iridium.Core({ database: "test" });
before(() => core.connect());
@@ -45,7 +45,7 @@ describe("Model",() => {
it("should throw an error if you don't provide a valid core",() => {
chai.expect(() => {
new Iridium.Model(null, createInstanceImplementation({
- collection: 'test',
+ collection: "test",
schema: { _id: false }
}))
}).to.throw("You failed to provide a valid Iridium core for this model");
@@ -82,13 +82,13 @@ describe("Model",() => {
it("should throw an error if you don't provide a valid schema",() => {
chai.expect(() => {
new Iridium.Model(core, createInstanceImplementation({
- collection: 'test'
+ collection: "test"
}))
}).to.throw("You failed to provide a valid schema for this model");
chai.expect(() => {
new Iridium.Model(core,createInstanceImplementation({
- collection: 'test',
+ collection: "test",
schema: { id: false }
}))
}).to.throw("You failed to provide a valid schema for this model");
@@ -96,28 +96,28 @@ describe("Model",() => {
it("should correctly set the core",() => {
chai.expect(new Iridium.Model(core, createInstanceImplementation({
- collection: 'test',
+ collection: "test",
schema: { _id: false }
})).core).to.equal(core);
});
it("should correctly set the collectionName",() => {
chai.expect(new Iridium.Model(core, createInstanceImplementation({
- collection: 'test',
+ collection: "test",
schema: { _id: false }
- })).collectionName).to.equal('test');
+ })).collectionName).to.equal("test");
});
it("should correctly set the schema",() => {
chai.expect(new Iridium.Model(core, createInstanceImplementation({
- collection: 'test',
+ collection: "test",
schema: { _id: true }
})).schema).to.eql({ _id: true });
});
it("should correctly default to ObjectID if no _id schema type is specified",() => {
chai.expect(new Iridium.Model(core, createInstanceImplementation({
- collection: 'test',
+ collection: "test",
schema: { _id: false }
})).schema).to.eql({ _id: MongoDB.ObjectID });
});
@@ -126,48 +126,48 @@ describe("Model",() => {
describe("methods",() => {
let test = new Iridium.Model(core, Test);
- it("should expose create()",() => chai.expect(test.create).to.exist.and.be.a('function'));
- it("should expose insert()",() => chai.expect(test.insert).to.exist.and.be.a('function'));
- it("should expose remove()",() => chai.expect(test.remove).to.exist.and.be.a('function'));
- it("should expose findOne()",() => chai.expect(test.findOne).to.exist.and.be.a('function'));
- it("should expose get()",() => chai.expect(test.get).to.exist.and.be.a('function'));
- it("should expose find()",() => chai.expect(test.find).to.exist.and.be.a('function'));
- it("should expose count()",() => chai.expect(test.count).to.exist.and.be.a('function'));
- it("should expose ensureIndex()",() => chai.expect(test.ensureIndex).to.exist.and.be.a('function'));
- it("should expose ensureIndexes()",() => chai.expect(test.ensureIndexes).to.exist.and.be.a('function'));
- it("should expose dropIndex()",() => chai.expect(test.dropIndex).to.exist.and.be.a('function'));
- it("should expose dropIndexes()",() => chai.expect(test.dropIndexes).to.exist.and.be.a('function'));
+ it("should expose create()",() => chai.expect(test.create).to.exist.and.be.a("function"));
+ it("should expose insert()",() => chai.expect(test.insert).to.exist.and.be.a("function"));
+ it("should expose remove()",() => chai.expect(test.remove).to.exist.and.be.a("function"));
+ it("should expose findOne()",() => chai.expect(test.findOne).to.exist.and.be.a("function"));
+ it("should expose get()",() => chai.expect(test.get).to.exist.and.be.a("function"));
+ it("should expose find()",() => chai.expect(test.find).to.exist.and.be.a("function"));
+ it("should expose count()",() => chai.expect(test.count).to.exist.and.be.a("function"));
+ it("should expose ensureIndex()",() => chai.expect(test.ensureIndex).to.exist.and.be.a("function"));
+ it("should expose ensureIndexes()",() => chai.expect(test.ensureIndexes).to.exist.and.be.a("function"));
+ it("should expose dropIndex()",() => chai.expect(test.dropIndex).to.exist.and.be.a("function"));
+ it("should expose dropIndexes()",() => chai.expect(test.dropIndexes).to.exist.and.be.a("function"));
});
describe("properties",() => {
let test = new Iridium.Model(core, Test);
it("should expose core",() => {
- chai.expect(test).to.have.property('core');
+ chai.expect(test).to.have.property("core");
chai.expect(test.core).to.equal(core);
});
it("should expose collection",() => {
- chai.expect(test).to.have.property('collection');
+ chai.expect(test).to.have.property("collection");
});
it("should expose collectionName",() => {
- chai.expect(test).to.have.property('collectionName');
- chai.expect(test.collectionName).to.equal('test');
- test.collectionName = 'changed';
- chai.expect(test.collectionName).to.equal('changed');
- });
- it("should expose schema",() => chai.expect(test).to.have.property('schema'));
- it("should expose helpers",() => chai.expect(test).to.have.property('helpers'));
- it("should expose handlers",() => chai.expect(test).to.have.property('handlers'));
- it("should expose cache",() => chai.expect(test).to.have.property('cache'));
- it("should expose cacheDirector",() => chai.expect(test).to.have.property('cacheDirector'));
- it("should expose transforms",() => chai.expect(test).to.have.property('transforms'));
- it("should expose indexes",() => chai.expect(test).to.have.property('indexes'));
- it("should expose Instance",() => chai.expect(test.Instance).to.exist.and.be.a('function'));
+ chai.expect(test).to.have.property("collectionName");
+ chai.expect(test.collectionName).to.equal("test");
+ test.collectionName = "changed";
+ chai.expect(test.collectionName).to.equal("changed");
+ });
+ it("should expose schema",() => chai.expect(test).to.have.property("schema"));
+ it("should expose helpers",() => chai.expect(test).to.have.property("helpers"));
+ it("should expose handlers",() => chai.expect(test).to.have.property("handlers"));
+ it("should expose cache",() => chai.expect(test).to.have.property("cache"));
+ it("should expose cacheDirector",() => chai.expect(test).to.have.property("cacheDirector"));
+ it("should expose transforms",() => chai.expect(test).to.have.property("transforms"));
+ it("should expose indexes",() => chai.expect(test).to.have.property("indexes"));
+ it("should expose Instance",() => chai.expect(test.Instance).to.exist.and.be.a("function"));
});
describe("collection",() => {
it("should throw an error if you attempt to access it before connecting to the database",() => {
- let model = new Iridium.Model(new Iridium.Core('mongodb://localhost/test'), Test);
+ let model = new Iridium.Model(new Iridium.Core("mongodb://localhost/test"), Test);
chai.expect(() => model.collection).to.throw("Iridium Core not connected to a database.");
});
@@ -188,7 +188,7 @@ describe("Model",() => {
});
it("should exist",() => {
- chai.expect(model.create).to.exist.and.be.a('function');
+ chai.expect(model.create).to.exist.and.be.a("function");
});
it("should allow the insertion of a single document",() => {
@@ -196,7 +196,7 @@ describe("Model",() => {
});
it("should return a document if a single document is inserted",() => {
- return chai.expect(model.create({ answer: 10 })).to.eventually.have.property('answer', 10);
+ return chai.expect(model.create({ answer: 10 })).to.eventually.have.property("answer", 10);
});
it("should allow the insertion of multiple documents",() => {
@@ -212,13 +212,13 @@ describe("Model",() => {
});
it("should return an error if you don't meet the schema validation requirements",() => {
- return chai.expect(model.create({ answer: 'wrong' })).to.eventually.be.rejected;
+ return chai.expect(model.create({ answer: "wrong" })).to.eventually.be.rejected;
});
it("should support a callback style instead of promises",(done) => {
model.create({ answer: 15 },(err, inserted) => {
if (err) return done(err);
- chai.expect(inserted).to.exist.and.have.property('answer', 15);
+ chai.expect(inserted).to.exist.and.have.property("answer", 15);
return done();
});
});
@@ -236,7 +236,7 @@ describe("Model",() => {
});
it("should exist",() => {
- chai.expect(model.insert).to.exist.and.be.a('function');
+ chai.expect(model.insert).to.exist.and.be.a("function");
});
it("should allow the insertion of a single document",() => {
@@ -244,7 +244,7 @@ describe("Model",() => {
});
it("should return a document if a single document is inserted",() => {
- return chai.expect(model.insert({ answer: 10 })).to.eventually.have.property('answer', 10);
+ return chai.expect(model.insert({ answer: 10 })).to.eventually.have.property("answer", 10);
});
it("should allow the insertion of multiple documents",() => {
@@ -260,13 +260,13 @@ describe("Model",() => {
});
it("should return an error if you don't meet the schema validation requirements",() => {
- return chai.expect(model.insert({ answer: 'wrong' })).to.eventually.be.rejected;
+ return chai.expect(model.insert({ answer: "wrong" })).to.eventually.be.rejected;
});
it("should support a callback style instead of promises",(done) => {
model.insert({ answer: 15 },(err, inserted) => {
if (err) return done(err);
- chai.expect(inserted).to.exist.and.have.property('answer', 15);
+ chai.expect(inserted).to.exist.and.have.property("answer", 15);
return done();
});
});
@@ -290,7 +290,7 @@ describe("Model",() => {
});
it("should exist",() => {
- chai.expect(model.remove).to.exist.and.be.a('function');
+ chai.expect(model.remove).to.exist.and.be.a("function");
});
it("should allow the removal of documents matching a query",() => {
@@ -350,11 +350,11 @@ describe("Model",() => {
});
it("should exist",() => {
- chai.expect(model.findOne).to.exist.and.be.a('function');
+ chai.expect(model.findOne).to.exist.and.be.a("function");
});
it("should support retrieving an random document",() => {
- return chai.expect(model.findOne()).to.eventually.exist.and.have.property('answer').is.a('number');
+ return chai.expect(model.findOne()).to.eventually.exist.and.have.property("answer").is.a("number");
});
it("should support a query which returns nothing",() => {
@@ -362,23 +362,23 @@ describe("Model",() => {
});
it("should support retrieving a document using its ID",() => {
- return chai.expect(model.findOne().then((doc) => model.findOne(doc._id))).to.eventually.exist.and.have.property('answer').is.a('number');
+ return chai.expect(model.findOne().then((doc) => model.findOne(doc._id))).to.eventually.exist.and.have.property("answer").is.a("number");
});
it("should retrieve the correct document by its ID",() => {
return model.findOne().then((doc) => {
- return chai.expect(model.findOne(doc._id)).to.eventually.exist.and.have.property('_id', doc._id);
+ return chai.expect(model.findOne(doc._id)).to.eventually.exist.and.have.property("_id", doc._id);
});
});
it("should support retrieving a document using a selector query",() => {
- return chai.expect(model.findOne({ answer: 10 })).to.eventually.exist.and.have.property('answer', 10);
+ return chai.expect(model.findOne({ answer: 10 })).to.eventually.exist.and.have.property("answer", 10);
});
it("should support passing options to control the query",() => {
return chai.expect(model.findOne({}, {
sort: { answer: -1 }
- })).to.eventually.exist.and.have.property('answer', 14);
+ })).to.eventually.exist.and.have.property("answer", 14);
});
it("should allow you to limit the returned fields",() => {
@@ -390,7 +390,7 @@ describe("Model",() => {
it("should support a callback style instead of promises",(done) => {
model.findOne((err, doc) => {
if (err) return done(err);
- chai.expect(doc).to.exist.and.have.property('answer');
+ chai.expect(doc).to.exist.and.have.property("answer");
return done();
});
});
@@ -414,11 +414,11 @@ describe("Model",() => {
});
it("should exist",() => {
- chai.expect(model.get).to.exist.and.be.a('function');
+ chai.expect(model.get).to.exist.and.be.a("function");
});
it("should support retrieving an random document",() => {
- return chai.expect(model.get()).to.eventually.exist.and.have.property('answer').is.a('number');
+ return chai.expect(model.get()).to.eventually.exist.and.have.property("answer").is.a("number");
});
it("should support a query which returns nothing",() => {
@@ -426,23 +426,23 @@ describe("Model",() => {
});
it("should support retrieving a document using its ID",() => {
- return chai.expect(model.get().then((doc) => model.get(doc._id))).to.eventually.exist.and.have.property('answer').is.a('number');
+ return chai.expect(model.get().then((doc) => model.get(doc._id))).to.eventually.exist.and.have.property("answer").is.a("number");
});
it("should retrieve the correct document by its ID",() => {
return model.get().then((doc) => {
- return chai.expect(model.get(doc._id)).to.eventually.exist.and.have.property('_id', doc._id);
+ return chai.expect(model.get(doc._id)).to.eventually.exist.and.have.property("_id", doc._id);
});
});
it("should support retrieving a document using a selector query",() => {
- return chai.expect(model.get({ answer: 10 })).to.eventually.exist.and.have.property('answer', 10);
+ return chai.expect(model.get({ answer: 10 })).to.eventually.exist.and.have.property("answer", 10);
});
it("should support passing options to control the query",() => {
return chai.expect(model.get({}, {
sort: { answer: -1 }
- })).to.eventually.exist.and.have.property('answer', 14);
+ })).to.eventually.exist.and.have.property("answer", 14);
});
it("should allow you to limit the returned fields",() => {
@@ -454,7 +454,7 @@ describe("Model",() => {
it("should support a callback style instead of promises",(done) => {
model.get((err, doc) => {
if (err) return done(err);
- chai.expect(doc).to.exist.and.have.property('answer');
+ chai.expect(doc).to.exist.and.have.property("answer");
return done();
});
});
@@ -478,7 +478,7 @@ describe("Model",() => {
});
it("should exist",() => {
- chai.expect(model.find).to.exist.and.be.a('function');
+ chai.expect(model.find).to.exist.and.be.a("function");
});
it("should return a cursor object",() => {
@@ -712,7 +712,7 @@ describe("Model",() => {
describe("readFrom()", () => {
it("should return a new cursor", () => {
- chai.expect(model.find().readFrom('secondaryPreferred')).to.be.instanceof(Cursor);
+ chai.expect(model.find().readFrom("secondaryPreferred")).to.be.instanceof(Cursor);
});
});
});
@@ -735,7 +735,7 @@ describe("Model",() => {
});
it("should exist",() => {
- chai.expect(model.count).to.exist.and.be.a('function');
+ chai.expect(model.count).to.exist.and.be.a("function");
});
it("should select all documents by default",() => {
@@ -779,7 +779,7 @@ describe("Model",() => {
});
it("should exist",() => {
- chai.expect(model.update).to.exist.and.be.a('function');
+ chai.expect(model.update).to.exist.and.be.a("function");
});
it("should use multi update by default",() => {
@@ -823,7 +823,7 @@ describe("Model",() => {
});
it("should exist",() => {
- chai.expect(model.ensureIndex).to.exist.and.be.a('function');
+ chai.expect(model.ensureIndex).to.exist.and.be.a("function");
});
it("should allow the creation of indexes",() => {
@@ -860,7 +860,7 @@ describe("Model",() => {
});
it("should exist",() => {
- chai.expect(model.ensureIndexes).to.exist.and.be.a('function');
+ chai.expect(model.ensureIndexes).to.exist.and.be.a("function");
});
it("should configure all indexes defined in the model's options", () => {
@@ -886,11 +886,11 @@ describe("Model",() => {
});
it("should exist",() => {
- chai.expect(model.dropIndex).to.exist.and.be.a('function');
+ chai.expect(model.dropIndex).to.exist.and.be.a("function");
});
it("should remove the specified index",() => {
- return chai.expect(model.dropIndex('answer_1')).to.eventually.be.true;
+ return chai.expect(model.dropIndex("answer_1")).to.eventually.be.true;
});
it("should remove the specified index using its definition",() => {
@@ -928,7 +928,7 @@ describe("Model",() => {
});
it("should exist",() => {
- chai.expect(model.dropIndexes).to.exist.and.be.a('function');
+ chai.expect(model.dropIndexes).to.exist.and.be.a("function");
});
it("should remove all non-_id indexes on the collection",() => {
@@ -939,24 +939,24 @@ describe("Model",() => {
describe("identifier transforms", () => {
it("should have a default converter", () => {
let model = new Iridium.Model(core, Test);
- chai.expect(model.transforms).to.exist.and.have.property('_id').with.property('fromDB').which.is.a('function');
- chai.expect(model.transforms).to.exist.and.have.property('_id').with.property('toDB').which.is.a('function');
+ chai.expect(model.transforms).to.exist.and.have.property("_id").with.property("fromDB").which.is.a("function");
+ chai.expect(model.transforms).to.exist.and.have.property("_id").with.property("toDB").which.is.a("function");
});
it("should have a default ObjectID to String converter", () => {
let model = new Iridium.Model(core, Test);
- chai.expect(model.transforms['_id'].fromDB(MongoDB.ObjectID.createFromHexString('aaaaaaaaaaaaaaaaaaaaaaaa'), '_id', model)).to.eql('aaaaaaaaaaaaaaaaaaaaaaaa');
- chai.expect(model.transforms['_id'].toDB('aaaaaaaaaaaaaaaaaaaaaaaa', '_id', model)).to.eql(MongoDB.ObjectID.createFromHexString('aaaaaaaaaaaaaaaaaaaaaaaa'));
+ chai.expect(model.transforms["_id"].fromDB(MongoDB.ObjectID.createFromHexString("aaaaaaaaaaaaaaaaaaaaaaaa"), "_id", model)).to.eql("aaaaaaaaaaaaaaaaaaaaaaaa");
+ chai.expect(model.transforms["_id"].toDB("aaaaaaaaaaaaaaaaaaaaaaaa", "_id", model)).to.eql(MongoDB.ObjectID.createFromHexString("aaaaaaaaaaaaaaaaaaaaaaaa"));
});
it("should allow you to specify a custom converter by providing a property on the class", () => {
let model = new Iridium.Model(core, TestWithCustomID);
- chai.expect(model.transforms['_id']).to.exist.and.have.property('fromDB').which.is.a('function');
- chai.expect(model.transforms['_id']).to.exist.and.have.property('toDB').which.is.a('function');
+ chai.expect(model.transforms["_id"]).to.exist.and.have.property("fromDB").which.is.a("function");
+ chai.expect(model.transforms["_id"]).to.exist.and.have.property("toDB").which.is.a("function");
- chai.expect(model.transforms['_id'].fromDB(12, '_id', model)).to.eql(120);
- chai.expect(model.transforms['_id'].toDB(120, '_id', model)).to.eql(12);
+ chai.expect(model.transforms["_id"].fromDB(12, "_id", model)).to.eql(120);
+ chai.expect(model.transforms["_id"].toDB(120, "_id", model)).to.eql(12);
});
});
});
\ No newline at end of file
diff --git a/test/Omnom.ts b/test/Omnom.ts
index 0e442d9..bb92be5 100644
--- a/test/Omnom.ts
+++ b/test/Omnom.ts
@@ -1,27 +1,27 @@
///
-import {Omnom} from '../lib/utils/Omnom';
-import MongoDB = require('mongodb');
+import {Omnom} from "../lib/utils/Omnom";
+import MongoDB = require("mongodb");
describe("Omnom",() => {
it("should correctly diff basic objects",() => {
let oldObject = {
a: 1,
- b: 'test',
+ b: "test",
c: 2,
- d: 'constant',
- e: 'old'
+ d: "constant",
+ e: "old"
};
let newObject = {
a: 3,
- b: 'tested',
+ b: "tested",
c: 2,
- d: 'constant',
- f: 'new'
+ d: "constant",
+ f: "new"
};
let expectedDiff = {
- $set: { a: 3, b: 'tested', f: 'new' },
+ $set: { a: 3, b: "tested", f: "new" },
$unset: { e: 1 }
};
@@ -31,22 +31,22 @@ describe("Omnom",() => {
it("should correctly diff basic objects with atomic number changes",() => {
let oldObject = {
a: 1,
- b: 'test',
+ b: "test",
c: 2,
- d: 'constant',
- e: 'old'
+ d: "constant",
+ e: "old"
};
let newObject = {
a: 3,
- b: 'tested',
+ b: "tested",
c: 2,
- d: 'constant',
- f: 'new'
+ d: "constant",
+ f: "new"
};
let expectedDiff = {
- $set: { b: 'tested', f: 'new' },
+ $set: { b: "tested", f: "new" },
$inc: { a: 2 },
$unset: { e: 1 }
};
@@ -54,7 +54,7 @@ describe("Omnom",() => {
chai.expect(Omnom.diff(oldObject, newObject, { atomicNumbers: true })).to.exist.and.be.eql(expectedDiff);
});
- it('should correctly diff complex objects', function () {
+ it("should correctly diff complex objects", function () {
let oldObject = {
a: { value: 1 },
b: { value1: 1, value2: 1 },
@@ -65,21 +65,21 @@ describe("Omnom",() => {
let newObject = {
a: { value: 3 },
- b: { value1: 'tested', value2: 2 },
+ b: { value1: "tested", value2: 2 },
c: { value: 2 },
d: { value: {} },
e: { value2: false }
};
let expectedDiff = {
- $set: { 'a.value': 3, 'b.value1': 'tested', 'b.value2': 2, 'e.value2': false },
- $unset: { 'e.value': 1 }
+ $set: { "a.value": 3, "b.value1": "tested", "b.value2": 2, "e.value2": false },
+ $unset: { "e.value": 1 }
};
chai.expect(Omnom.diff(oldObject, newObject)).to.exist.and.be.eql(expectedDiff);
});
- it('should correctly diff deep objects', function () {
+ it("should correctly diff deep objects", function () {
let oldObject = {
a: {
b: {
@@ -87,21 +87,21 @@ describe("Omnom",() => {
m: {
x: 1,
y: 2,
- z: 'test'
+ z: "test"
}
},
d: {
m: {
x: 1,
y: 2,
- z: 'test'
+ z: "test"
}
},
e: {
m: {
x: 1,
y: 2,
- z: 'test'
+ z: "test"
}
}
}
@@ -115,21 +115,21 @@ describe("Omnom",() => {
n: {
x: 1,
y: 2,
- z: 'test'
+ z: "test"
}
},
d: {
m: {
w: 1,
y: 2,
- z: 'test'
+ z: "test"
}
},
e: {
m: {
x: 1,
y: 4,
- z: 'test'
+ z: "test"
}
}
}
@@ -137,14 +137,14 @@ describe("Omnom",() => {
};
let expectedDiff = {
- $set: { 'a.b.c.n': { x: 1, y: 2, z: 'test' }, 'a.b.d.m.w': 1, 'a.b.e.m.y': 4 },
- $unset: { 'a.b.c.m': 1, 'a.b.d.m.x': 1 }
+ $set: { "a.b.c.n": { x: 1, y: 2, z: "test" }, "a.b.d.m.w": 1, "a.b.e.m.y": 4 },
+ $unset: { "a.b.c.m": 1, "a.b.d.m.x": 1 }
};
chai.expect(Omnom.diff(oldObject, newObject)).to.exist.and.be.eql(expectedDiff);
});
- it('should correctly diff ObjectIDs', function () {
+ it("should correctly diff ObjectIDs", function () {
let oldID = new MongoDB.ObjectID();
let newID = MongoDB.ObjectID.createFromHexString(oldID.toHexString());
@@ -167,7 +167,7 @@ describe("Omnom",() => {
chai.expect(Omnom.diff(oldObject, newObject)).to.exist.and.be.eql(expectedDiff);
});
- describe('unset', function() {
+ describe("unset", function() {
it("should correctly unset properties which are removed", () => {
let oldObject = {
a: 10,
@@ -202,8 +202,8 @@ describe("Omnom",() => {
});
});
- describe('arrays', function () {
- it('should correctly handle two pure arrays',() => {
+ describe("arrays", function () {
+ it("should correctly handle two pure arrays",() => {
let oldObject = [1, 2, 3];
let newObject = [4, 5, 6];
let expectedDiff = {
@@ -213,7 +213,7 @@ describe("Omnom",() => {
chai.expect(Omnom.diff(oldObject, newObject)).to.exist.and.be.eql(expectedDiff);
});
- it('should correctly handle arrays which can be pulled', function () {
+ it("should correctly handle arrays which can be pulled", function () {
let oldObject = { a: [1, 2, 3, 4], b: [1, 2, 3, 4], c: [1,2,3,4,5] };
let newObject = { a: [1, 3, 4], b: [1, 3], c: [1] };
let expectedDiff = {
@@ -224,7 +224,7 @@ describe("Omnom",() => {
chai.expect(Omnom.diff(oldObject, newObject)).to.exist.and.be.eql(expectedDiff);
});
- it('should correctly handle arrays which can be pushed', function () {
+ it("should correctly handle arrays which can be pushed", function () {
let oldObject = { a: [1, 2, 3, 4], b: [1, 2, 3, 4], c: [1] };
let newObject = { a: [1, 2, 3, 4, 5], b: [1, 2, 3, 4, 5, 6], c: [1,2,3,4,5] };
let expectedDiff = {
@@ -234,7 +234,7 @@ describe("Omnom",() => {
chai.expect(Omnom.diff(oldObject, newObject)).to.exist.and.be.eql(expectedDiff);
});
- it('should correctly handle arrays which should be replaced', function () {
+ it("should correctly handle arrays which should be replaced", function () {
let oldObject = { a: [1, 2], b: [1, 2, 3] };
let newObject = { a: [5, 4, 3], b: [5, 4, 3, 2] };
let expectedDiff = {
@@ -263,11 +263,11 @@ describe("Omnom",() => {
let newObject = { a: [1, 2, 5, 4, 5], b: [1, 2, 5, 4, 5, 6] };
let expectedDiff = {
$set: {
- 'a.2': 5,
- 'a.4': 5,
- 'b.2': 5,
- 'b.4': 5,
- 'b.5': 6
+ "a.2": 5,
+ "a.4": 5,
+ "b.2": 5,
+ "b.4": 5,
+ "b.5": 6
}
};
@@ -278,26 +278,26 @@ describe("Omnom",() => {
let postDate = new Date();
let oldObject = {
comments: [
- { id: 1, title: 'Title 1', text: 'test text 1', posted: postDate },
- { id: 2, title: 'Title 2', text: 'test text 2', posted: postDate },
- { id: 3, title: 'Title 3', text: 'test text 3', posted: postDate }
+ { id: 1, title: "Title 1", text: "test text 1", posted: postDate },
+ { id: 2, title: "Title 2", text: "test text 2", posted: postDate },
+ { id: 3, title: "Title 3", text: "test text 3", posted: postDate }
]
};
let newDate = new Date(postDate.getTime() + 50);
let newObject = {
comments: [
- { id: 1, title: 'Title 1', text: 'tested text 1', posted: postDate },
- { id: 2, title: 'Title 2', text: 'tested text 2', posted: postDate },
- { id: 3, title: 'Title 3', text: 'test text 3', posted: newDate }
+ { id: 1, title: "Title 1", text: "tested text 1", posted: postDate },
+ { id: 2, title: "Title 2", text: "tested text 2", posted: postDate },
+ { id: 3, title: "Title 3", text: "test text 3", posted: newDate }
]
};
let expectedDiff = {
$set: {
- 'comments.0.text': 'tested text 1',
- 'comments.1.text': 'tested text 2',
- 'comments.2.posted': newDate
+ "comments.0.text": "tested text 1",
+ "comments.1.text": "tested text 2",
+ "comments.2.posted": newDate
}
};
diff --git a/test/Plugins.ts b/test/Plugins.ts
index 54d0f80..5e873e8 100644
--- a/test/Plugins.ts
+++ b/test/Plugins.ts
@@ -1,9 +1,9 @@
///
-import * as Iridium from '../index';
-import Skmatc = require('skmatc');
+import * as Iridium from "../index";
+import Skmatc = require("skmatc");
class Test extends Iridium.Instance {
- static collection = 'test';
+ static collection = "test";
static schema: Iridium.Schema = {
_id: false
};
@@ -14,7 +14,7 @@ class Test extends Iridium.Instance {
describe("Plugins",() => {
let core: Iridium.Core;
beforeEach(() => {
- core = new Iridium.Core({ database: 'test' });
+ core = new Iridium.Core({ database: "test" });
});
describe("newModel",() => {
@@ -47,12 +47,12 @@ describe("Plugins",() => {
it("should be able to make modifications to the model",() => {
core.register({
newModel: (model) => {
- model.collectionName = 'changed';
+ model.collectionName = "changed";
}
});
let model = new Iridium.Model(core, Test);
- chai.expect(model.collectionName).to.exist.and.be.equal('changed');
+ chai.expect(model.collectionName).to.exist.and.be.equal("changed");
});
});
@@ -98,7 +98,7 @@ describe("Plugins",() => {
});
let instanceImplementation: any = function() { return {}; };
- instanceImplementation.collection = 'test';
+ instanceImplementation.collection = "test";
instanceImplementation.schema = {
_id: false
};
@@ -120,14 +120,14 @@ describe("Plugins",() => {
it("should allow a plugin to define a single validator",() => {
core.register({
newInstance: (instance, model) => { },
- validate: Skmatc.create((schema) => schema == 'Test', (schema, data) => this.assert(data == 'test'))
+ validate: Skmatc.create((schema) => schema == "Test", (schema, data) => this.assert(data == "test"))
});
});
it("should allow a plugin to define multiple validators",() => {
core.register({
newInstance: (instance, model) => { },
- validate: [Skmatc.create((schema) => schema == 'Test',(schema, data) => this.assert(data == 'test'))]
+ validate: [Skmatc.create((schema) => schema == "Test",(schema, data) => this.assert(data == "test"))]
});
});
});
diff --git a/test/Transforms.ts b/test/Transforms.ts
index 192ff91..1bd4bd5 100644
--- a/test/Transforms.ts
+++ b/test/Transforms.ts
@@ -1,9 +1,9 @@
///
-import * as Iridium from '../index';
-import MongoDB = require('mongodb');
-import Events = require('events');
+import * as Iridium from "../index";
+import MongoDB = require("mongodb");
+import Events = require("events");
-import {DefaultTransforms} from '../lib/Transforms';
+import {DefaultTransforms} from "../lib/Transforms";
let hookEmitter = new Events.EventEmitter();
@@ -17,7 +17,7 @@ interface Document {
}
class Person extends Iridium.Instance {
- static collection = 'test';
+ static collection = "test";
static schema: Iridium.Schema = {
_id: false,
name: String,
@@ -46,19 +46,19 @@ class Person extends Iridium.Instance {
avatar: Buffer;
static onCreating(document: Document) {
- hookEmitter.emit('creating', document);
+ hookEmitter.emit("creating", document);
}
static onReady(instance: Person) {
- hookEmitter.emit('ready', instance);
+ hookEmitter.emit("ready", instance);
}
static onRetrieved(document: Document) {
- hookEmitter.emit('retrieved', document);
+ hookEmitter.emit("retrieved", document);
}
static onSaving(instance: Person, changes: any) {
- hookEmitter.emit('saving', instance, changes);
+ hookEmitter.emit("saving", instance, changes);
}
}
@@ -78,49 +78,49 @@ describe("Transforms", () => {
after(() => db.close());
it("should include a sensible default for the _id field schema", () => {
- chai.expect(db.Person).to.have.property('schema').with.property('_id', MongoDB.ObjectID);
+ chai.expect(db.Person).to.have.property("schema").with.property("_id", MongoDB.ObjectID);
});
it("should include a sensible default for the _id field transform", () => {
- chai.expect(db.Person).to.have.property('transforms').with.property('_id');
+ chai.expect(db.Person).to.have.property("transforms").with.property("_id");
});
describe("during creation", () => {
it("should be applied", () => {
return db.Person.insert({
- name: 'Test User',
- email: 'Test@email.com',
+ name: "Test User",
+ email: "Test@email.com",
avatar: new Buffer(0)
}).then(user => {
- chai.expect(user).to.exist.and.have.property('email', 'TEST@EMAIL.COM');
+ chai.expect(user).to.exist.and.have.property("email", "TEST@EMAIL.COM");
});
});
it("should only be applied after onCreating", () => {
let onCreatingCalled = false;
- hookEmitter.once('creating', (doc) => {
+ hookEmitter.once("creating", (doc) => {
onCreatingCalled = true;
- chai.expect(doc.email).to.eql('Test@email.com');
+ chai.expect(doc.email).to.eql("Test@email.com");
chai.expect(doc.lastModified).to.not.exist;
});
return db.Person.insert({
- name: 'Test User',
- email: 'Test@email.com',
+ name: "Test User",
+ email: "Test@email.com",
avatar: new Buffer(0)
}).then(user => {
chai.expect(onCreatingCalled).to.be.true;
chai.expect(user).to.exist;
- chai.expect(user).to.have.property('document').with.property('lastModified');
+ chai.expect(user).to.have.property("document").with.property("lastModified");
chai.expect(user.document.lastModified.valueOf()).to.be.closeTo(new Date().valueOf(), 1000);
});
});
it("should be applied before validation", () => {
- db.Person.schema['email'] = /^test@email.com$/;
+ db.Person.schema["email"] = /^test@email.com$/;
return db.Person.insert({
- name: 'Test User',
- email: 'Test@email.com',
+ name: "Test User",
+ email: "Test@email.com",
avatar: new Buffer(0)
});
});
@@ -128,29 +128,29 @@ describe("Transforms", () => {
describe("with an instance", () => {
beforeEach(() => db.Person.insert({
- name: 'Test User',
- email: 'test@email.com',
- avatar: new Buffer("test", 'utf8')
+ name: "Test User",
+ email: "test@email.com",
+ avatar: new Buffer("test", "utf8")
}));
it("should apply the transform on property reads", () => {
return db.Person.get().then(person => {
- chai.expect(person.email).to.eql('TEST@EMAIL.COM');
- chai.expect(person.document.email).to.eql('test@email.com');
+ chai.expect(person.email).to.eql("TEST@EMAIL.COM");
+ chai.expect(person.document.email).to.eql("test@email.com");
});
});
it("should apply the transform on property writes", () => {
return db.Person.get().then(person => {
- person.email = 'Test@email.com';
- chai.expect(person.email).to.eql('TEST@EMAIL.COM');
- chai.expect(person.document.email).to.eql('test@email.com');
+ person.email = "Test@email.com";
+ chai.expect(person.email).to.eql("TEST@EMAIL.COM");
+ chai.expect(person.document.email).to.eql("test@email.com");
});
});
it("should apply the $document transform on saves", () => {
let onSavingCalled = false;
- hookEmitter.once('saving', (doc) => {
+ hookEmitter.once("saving", (doc) => {
onSavingCalled = true;
chai.expect(doc.lastModified).to.not.exist;
});
@@ -159,7 +159,7 @@ describe("Transforms", () => {
return person.save();
}).then(person => {
chai.expect(person).to.exist;
- chai.expect(person).to.have.property('document').with.property('lastModified');
+ chai.expect(person).to.have.property("document").with.property("lastModified");
chai.expect(person.document.lastModified.valueOf()).to.be.closeTo(new Date().valueOf(), 1000);
chai.expect(onSavingCalled).to.be.true;
});
@@ -167,33 +167,33 @@ describe("Transforms", () => {
it("should diff the transformed property", () => {
let changesChecked = false;
- hookEmitter.once('saving', (instance, changes) => {
- chai.expect(changes).to.have.property('$set').with.property('name', 'Testy User');
+ hookEmitter.once("saving", (instance, changes) => {
+ chai.expect(changes).to.have.property("$set").with.property("name", "Testy User");
changesChecked = true;
});
return db.Person.get().then(person => {
- person.name = 'Testy User';
- person.email = 'Test@email.com';
- chai.expect(person.email).to.eql('TEST@EMAIL.COM');
- chai.expect(person.document.email).to.eql('test@email.com');
+ person.name = "Testy User";
+ person.email = "Test@email.com";
+ chai.expect(person.email).to.eql("TEST@EMAIL.COM");
+ chai.expect(person.document.email).to.eql("test@email.com");
return person.save();
}).then(person => {
- chai.expect(person).to.have.property('email', 'TEST@EMAIL.COM');
+ chai.expect(person).to.have.property("email", "TEST@EMAIL.COM");
chai.expect(changesChecked).to.be.true;
});
});
it("should diff the transformed document", () => {
let changesChecked = false;
- hookEmitter.once('saving', (instance, changes) => {
- chai.expect(changes).to.have.property('$set').with.property('lastModified').which.is.instanceof(Date);
+ hookEmitter.once("saving", (instance, changes) => {
+ chai.expect(changes).to.have.property("$set").with.property("lastModified").which.is.instanceof(Date);
changesChecked = true;
});
return db.Person.get().then(person => person.save()).then(person => {
- chai.expect(person).to.have.property('email', 'TEST@EMAIL.COM');
+ chai.expect(person).to.have.property("email", "TEST@EMAIL.COM");
chai.expect(changesChecked).to.be.true;
});
});
@@ -201,16 +201,16 @@ describe("Transforms", () => {
describe("the default ObjectID transform", () => {
it("should return a string", () => {
return db.Person.get().then(person => {
- chai.expect(person._id).to.be.a('string');
- chai.expect(person.document._id).to.be.a('object');
+ chai.expect(person._id).to.be.a("string");
+ chai.expect(person.document._id).to.be.a("object");
});
});
it("should convert a string to an ObjectID", () => {
return db.Person.get().then(person => {
- person._id = 'aaaaaaaaaaaaaaaaaaaaaaaa';
- chai.expect(person._id).to.eql('aaaaaaaaaaaaaaaaaaaaaaaa');
- chai.expect(person.document._id).to.be.a('object');
+ person._id = "aaaaaaaaaaaaaaaaaaaaaaaa";
+ chai.expect(person._id).to.eql("aaaaaaaaaaaaaaaaaaaaaaaa");
+ chai.expect(person.document._id).to.be.a("object");
});
});
});
@@ -218,16 +218,16 @@ describe("Transforms", () => {
describe("the default Buffer transform", () => {
it("should convert a MongoDB BSON Binary object into a buffer", () => {
let transform = DefaultTransforms.Binary.fromDB;
- let result = transform(new MongoDB.Binary(new Buffer('test', 'utf8')), '_id', null);
+ let result = transform(new MongoDB.Binary(new Buffer("test", "utf8")), "_id", null);
chai.expect(result).to.exist;
- chai.expect(result.toString('utf8')).to.eql('test');
+ chai.expect(result.toString("utf8")).to.eql("test");
});
it("should convert the buffer into a MongoDB.Binary object", () => {
let transform = DefaultTransforms.Binary.toDB;
- let buffer = new Buffer('test', 'utf8');
- let result = transform(buffer, '_id', null);
+ let buffer = new Buffer("test", "utf8");
+ let result = transform(buffer, "_id", null);
chai.expect(result).to.be.instanceOf(MongoDB.Binary);
});
@@ -235,16 +235,16 @@ describe("Transforms", () => {
it("should return a buffer", () => {
return db.Person.get().then(person => {
chai.expect(Buffer.isBuffer(person.avatar)).to.be.true;
- //chai.expect(person.avatar.toString('utf8')).to.eql('test');
- chai.expect(person.document.avatar).to.be.a('object');
+ //chai.expect(person.avatar.toString("utf8")).to.eql("test");
+ chai.expect(person.document.avatar).to.be.a("object");
});
});
it("should convert a buffer to a MongoDB.Binary", () => {
return db.Person.get().then(person => {
- person.avatar = new Buffer("new", 'utf8');
- //chai.expect(person.avatar.toString('utf8')).to.eql('new');
- chai.expect(person.document.avatar).to.be.a('object');
+ person.avatar = new Buffer("new", "utf8");
+ //chai.expect(person.avatar.toString("utf8")).to.eql("new");
+ chai.expect(person.document.avatar).to.be.a("object");
});
});
});
diff --git a/test/Utilities.ts b/test/Utilities.ts
index b5645c8..b0883a5 100644
--- a/test/Utilities.ts
+++ b/test/Utilities.ts
@@ -1,6 +1,6 @@
///
-import * as Iridium from '../index';
-import MongoDB = require('mongodb');
+import * as Iridium from "../index";
+import MongoDB = require("mongodb");
describe("Utilities", () => {
describe("toObjectID", () => {
diff --git a/test/Validation.ts b/test/Validation.ts
index e2ee1b3..5b9add4 100644
--- a/test/Validation.ts
+++ b/test/Validation.ts
@@ -1,7 +1,7 @@
///
-import * as Iridium from '../index';
-import skmatc = require('skmatc');
-import MongoDB = require('mongodb');
+import * as Iridium from "../index";
+import skmatc = require("skmatc");
+import MongoDB = require("mongodb");
interface Document {
_id?: string;
@@ -15,15 +15,15 @@ interface Document {
avatar: Buffer;
}
-@Iridium.Validate('Over18', function(schema, data) {
+@Iridium.Validate("Over18", function(schema, data) {
return this.assert(data.getTime && data.getTime() < (new Date().getTime() - 365 * 86400 * 18 * 1000));
})
class Person extends Iridium.Instance {
- static collection = 'test';
+ static collection = "test";
static schema: Iridium.Schema = {
_id: MongoDB.ObjectID,
name: String,
- dateOfBirth: 'Over18',
+ dateOfBirth: "Over18",
siblings: [{
name: String,
related: Boolean,
@@ -48,7 +48,7 @@ class Person extends Iridium.Instance {
}
describe("Validation", () => {
- let core = new Iridium.Core({ database: 'test' });
+ let core = new Iridium.Core({ database: "test" });
let model = new Iridium.Model(core, Person);
before(() => core.connect());
@@ -60,10 +60,10 @@ describe("Validation", () => {
describe("custom validators", () => {
it("should successfully validate documents which are valid", () => {
return chai.expect(model.insert({
- name: 'John',
- dateOfBirth: new Date('1993-02-14T00:00:00.000Z'),
+ name: "John",
+ dateOfBirth: new Date("1993-02-14T00:00:00.000Z"),
siblings: [{
- name: 'Jane',
+ name: "Jane",
related: true,
ageDifference: -2
}],
@@ -73,10 +73,10 @@ describe("Validation", () => {
it("should fail to validate documents which are invalid", () => {
return chai.expect(model.insert({
- name: 'John',
- dateOfBirth: new Date('2013-02-14T00:00:00.000Z'),
+ name: "John",
+ dateOfBirth: new Date("2013-02-14T00:00:00.000Z"),
siblings: [{
- name: 'Jane',
+ name: "Jane",
related: true,
ageDifference: -2
}],
@@ -87,11 +87,11 @@ describe("Validation", () => {
describe("ObjectID", () => {
it("should successfully validate valid documents", () => {
return chai.expect(model.insert({
- _id: '012345670123456701234567',
- name: 'John',
- dateOfBirth: new Date('1993-02-14T00:00:00.000Z'),
+ _id: "012345670123456701234567",
+ name: "John",
+ dateOfBirth: new Date("1993-02-14T00:00:00.000Z"),
siblings: [{
- name: 'Jane',
+ name: "Jane",
related: true,
ageDifference: -2
}],
@@ -101,11 +101,11 @@ describe("Validation", () => {
it("should fail to validate documents which are invalid", () => {
return chai.expect(model.insert({
- _id: 'this is an invalid id',
- name: 'John',
- dateOfBirth: new Date('1993-02-14T00:00:00.000Z'),
+ _id: "this is an invalid id",
+ name: "John",
+ dateOfBirth: new Date("1993-02-14T00:00:00.000Z"),
siblings: [{
- name: 'Jane',
+ name: "Jane",
related: true,
ageDifference: -2
}],
@@ -117,10 +117,10 @@ describe("Validation", () => {
describe("Binary", () => {
it("should successfully validate valid documents", () => {
return chai.expect(model.insert({
- name: 'John',
- dateOfBirth: new Date('1993-02-14T00:00:00.000Z'),
+ name: "John",
+ dateOfBirth: new Date("1993-02-14T00:00:00.000Z"),
siblings: [{
- name: 'Jane',
+ name: "Jane",
related: true,
ageDifference: -2
}],
@@ -130,14 +130,14 @@ describe("Validation", () => {
it("should fail to validate documents which are invalid", () => {
return chai.expect(model.insert({
- name: 'John',
- dateOfBirth: new Date('1993-02-14T00:00:00.000Z'),
+ name: "John",
+ dateOfBirth: new Date("1993-02-14T00:00:00.000Z"),
siblings: [{
- name: 'Jane',
+ name: "Jane",
related: true,
ageDifference: -2
}],
- avatar: 'test'
+ avatar: "test"
})).to.eventually.be.rejected;
});
});
@@ -146,10 +146,10 @@ describe("Validation", () => {
describe("inserting", () => {
it("should successfully validate single documents which match the schema", () => {
return chai.expect(model.insert({
- name: 'John',
- dateOfBirth: new Date('1993-02-14T00:00:00.000Z'),
+ name: "John",
+ dateOfBirth: new Date("1993-02-14T00:00:00.000Z"),
siblings: [{
- name: 'Jane',
+ name: "Jane",
related: true,
ageDifference: -2
}],
@@ -159,10 +159,10 @@ describe("Validation", () => {
it("should fail to validate single documents which do not match the schema", () => {
return chai.expect(model.insert({
- name: 'John',
+ name: "John",
dateOfBirth: 0,
siblings: [{
- name: 'Jane',
+ name: "Jane",
related: true,
ageDifference: -2
}],
@@ -172,10 +172,10 @@ describe("Validation", () => {
it("should not insert a document into the database if it fails validation", () => {
return model.insert({
- name: 'John',
+ name: "John",
dateOfBirth: 0,
siblings: [{
- name: 'Jane',
+ name: "Jane",
related: true,
ageDifference: -2
}],
@@ -185,19 +185,19 @@ describe("Validation", () => {
it("should successfully validate multiple documents which match the schema", () => {
return chai.expect(model.insert([{
- name: 'Frank',
- dateOfBirth: new Date('1993-02-14T00:00:00.000Z'),
+ name: "Frank",
+ dateOfBirth: new Date("1993-02-14T00:00:00.000Z"),
siblings: [{
- name: 'Francie',
+ name: "Francie",
related: false,
ageDifference: -2
}],
avatar: new Buffer("test", "utf8")
}, {
- name: 'Jack',
- dateOfBirth: new Date('1993-02-14T00:00:00.000Z'),
+ name: "Jack",
+ dateOfBirth: new Date("1993-02-14T00:00:00.000Z"),
siblings: [{
- name: 'Jill',
+ name: "Jill",
related: true,
ageDifference: 2
}],
@@ -207,11 +207,11 @@ describe("Validation", () => {
it("should fail to validate multiple documents which do not match the schema", () => {
return chai.expect(model.insert([{
- name: 'Frank',
- dateOfBirth: new Date('1993-02-14T00:00:00.000Z'),
+ name: "Frank",
+ dateOfBirth: new Date("1993-02-14T00:00:00.000Z"),
siblings: [{
- name: 'Francie',
- related: 'related',
+ name: "Francie",
+ related: "related",
ageDifference: -2
}],
avatar: new Buffer("test", "utf8")
@@ -219,7 +219,7 @@ describe("Validation", () => {
name: 5,
dateOfBirth: new Date(),
siblings: [{
- name: 'Jill',
+ name: "Jill",
related: true,
ageDifference: 2
}],
@@ -229,19 +229,19 @@ describe("Validation", () => {
it("should fail to validate multiple documents where some do not match the schema", () => {
return chai.expect(model.insert([{
- name: 'Frank',
+ name: "Frank",
dateOfBirth: new Date(),
siblings: [{
- name: 'Francie',
- related: 'related',
+ name: "Francie",
+ related: "related",
ageDifference: -2
}],
avatar: new Buffer("test", "utf8")
}, {
- name: 'Jack',
- dateOfBirth: new Date('1993-02-14T00:00:00.000Z'),
+ name: "Jack",
+ dateOfBirth: new Date("1993-02-14T00:00:00.000Z"),
siblings: [{
- name: 'Jill',
+ name: "Jill",
related: true,
ageDifference: 2
}],
@@ -251,63 +251,63 @@ describe("Validation", () => {
it("should fail to validate multiple documents where some do not match the schema", () => {
return model.insert([{
- name: 'Frank',
+ name: "Frank",
dateOfBirth: new Date(),
siblings: [{
- name: 'Francie',
- related: 'related',
+ name: "Francie",
+ related: "related",
ageDifference: -2
}],
avatar: new Buffer("test", "utf8")
}, {
- name: 'Jack',
- dateOfBirth: new Date('1993-02-14T00:00:00.000Z'),
+ name: "Jack",
+ dateOfBirth: new Date("1993-02-14T00:00:00.000Z"),
siblings: [{
- name: 'Jill',
+ name: "Jill",
related: true,
ageDifference: 2
}],
avatar: new Buffer("test", "utf8")
- }]).catch(() => chai.expect(model.findOne({ 'siblings.related': 'related' })).to.eventually.be.null);
+ }]).catch(() => chai.expect(model.findOne({ "siblings.related": "related" })).to.eventually.be.null);
});
});
describe("instances", () => {
beforeEach(() => model.remove().then(() => model.insert({
- name: 'Frank',
- dateOfBirth: new Date('1993-02-14T00:00:00.000Z'),
+ name: "Frank",
+ dateOfBirth: new Date("1993-02-14T00:00:00.000Z"),
siblings: [],
avatar: new Buffer("test", "utf8")
})));
it("should validate documents when you attempt to change them", () => {
- return chai.expect(model.get({ name: 'Frank' }).then((frank) => {
- frank.siblings.push({ name: 'Francette', related: true, ageDifference: 0 });
+ return chai.expect(model.get({ name: "Frank" }).then((frank) => {
+ frank.siblings.push({ name: "Francette", related: true, ageDifference: 0 });
return frank.save();
})).to.eventually.be.ok;
});
it("should fail validation if the document does not match the schema", () => {
- return chai.expect(model.get({ name: 'Frank' }).then((frank) => {
- frank.siblings.push({ name: 'Francette', related: 'related', ageDifference: 0 });
+ return chai.expect(model.get({ name: "Frank" }).then((frank) => {
+ frank.siblings.push({ name: "Francette", related: "related", ageDifference: 0 });
return frank.save();
})).to.eventually.be.rejected;
});
it("should not change the document in the database if validation fails", () => {
- return chai.expect(model.get({ name: 'Frank' }).then((frank) => {
- frank.siblings.push({ name: 'Francette', related: 'related', ageDifference: 0 });
+ return chai.expect(model.get({ name: "Frank" }).then((frank) => {
+ frank.siblings.push({ name: "Francette", related: "related", ageDifference: 0 });
return frank.save();
- }).catch(() => model.get({ name: 'Frank', 'siblings.related': 'related' }))).to.eventually.be.null;
+ }).catch(() => model.get({ name: "Frank", "siblings.related": "related" }))).to.eventually.be.null;
});
it("should not reverse the changes made to the instance if validation fails", () => {
let staticFrank: Person;
- return chai.expect(model.get({ name: 'Frank' }).then((frank) => {
+ return chai.expect(model.get({ name: "Frank" }).then((frank) => {
staticFrank = frank;
- frank.siblings.push({ name: 'Francette', related: 'related', ageDifference: 0 });
+ frank.siblings.push({ name: "Francette", related: "related", ageDifference: 0 });
return frank.save();
- }).catch(() => chai.expect(staticFrank).to.have.property('siblings').with.length(1))).to.eventually.be.ok;
+ }).catch(() => chai.expect(staticFrank).to.have.property("siblings").with.length(1))).to.eventually.be.ok;
});
});
});
\ No newline at end of file
diff --git a/test/support/chai.ts b/test/support/chai.ts
index a897a0e..a2150de 100644
--- a/test/support/chai.ts
+++ b/test/support/chai.ts
@@ -1,7 +1,7 @@
///
-import chai = require('chai');
-import chaiAsPromised = require('chai-as-promised');
-import Bluebird = require('bluebird');
+import chai = require("chai");
+import chaiAsPromised = require("chai-as-promised");
+import Bluebird = require("bluebird");
Bluebird.longStackTraces();