Skip to content

Commit

Permalink
Added tests for default ObjectID transform
Browse files Browse the repository at this point in the history
  • Loading branch information
notheotherben committed Jun 18, 2015
1 parent aca976d commit aafaf55
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions test/Decorators.ts
Expand Up @@ -20,6 +20,9 @@ function VersionValidator(schema, data) {
@Iridium.Property('version', 'version')
@Iridium.Property('optional2', Boolean, false)
class Test extends Iridium.Instance<TestDocument, Test> implements TestDocument {
static transforms: Iridium.Transforms = {};
static indexes = [];

@Iridium.ObjectID
_id: string;

Expand Down Expand Up @@ -115,6 +118,16 @@ describe("Decorators", () => {
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({ _bsontype: 'ObjectID', id: 'aaaaaaaaaaaaaaaaaaaaaaaa' })).to.eql('aaaaaaaaaaaaaaaaaaaaaaaa');
});

it("should convert a string to an ObjectID", () => {
chai.expect(Test.transforms['_id'].toDB('aaaaaaaaaaaaaaaaaaaaaaaa')).to.be.instanceOf(MongoDB.ObjectID);
});
});
});

describe("Property", () => {
Expand Down

0 comments on commit aafaf55

Please sign in to comment.