Skip to content

Commit

Permalink
Added support and tests for a toObjectID helper method
Browse files Browse the repository at this point in the history
  • Loading branch information
notheotherben committed Jul 30, 2015
1 parent 4ebd33d commit 625397d
Show file tree
Hide file tree
Showing 7 changed files with 41 additions and 2 deletions.
2 changes: 2 additions & 0 deletions dist/index.js

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

2 changes: 1 addition & 1 deletion dist/index.js.map

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

8 changes: 8 additions & 0 deletions dist/lib/utils/ObjectID.js

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

1 change: 1 addition & 0 deletions dist/lib/utils/ObjectID.js.map

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

5 changes: 4 additions & 1 deletion index.ts
Expand Up @@ -18,4 +18,7 @@ import NoOpCache from './lib/caches/NoOpCache';
export {MemoryCache, NoOpCache};

import IDDirector from './lib/cacheControllers/IDDirector';
export {IDDirector as CacheOnID};
export {IDDirector as CacheOnID};

import {toObjectID} from './lib/utils/ObjectID';
export {toObjectID};
6 changes: 6 additions & 0 deletions lib/utils/ObjectID.ts
@@ -0,0 +1,6 @@
/// <reference path="../../_references.d.ts" />
import MongoDB = require('mongodb');

export function toObjectID(value: string): MongoDB.ObjectID {
return MongoDB.ObjectID.createFromHexString(value);
}
19 changes: 19 additions & 0 deletions test/Utilities.ts
@@ -0,0 +1,19 @@
/// <reference path="../_references.d.ts" />
import * as Iridium from '../index';
import MongoDB = require('mongodb');

describe("Utilities", () => {
describe("toObjectID", () => {
it("should convert hex strings to ObjectIDs", () => {
let oID = Iridium.toObjectID("aaaaaaaaaaaaaaaaaaaaaaaa");
chai.expect(oID).to.be.instanceOf(MongoDB.ObjectID);
chai.expect(oID.toHexString()).to.eql("aaaaaaaaaaaaaaaaaaaaaaaa");
});

it("should throw an error if your string is not a valid ObjectID", () => {
chai.expect(() => {
Iridium.toObjectID("aaaaaaaaaaaaaaaa");
}).to.throw;
});
});
})

0 comments on commit 625397d

Please sign in to comment.