Skip to content

Commit

Permalink
test: Added reproduction case for #73
Browse files Browse the repository at this point in the history
  • Loading branch information
notheotherben committed Apr 24, 2017
1 parent 08ccd6d commit a2062b7
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 1 deletion.
59 changes: 59 additions & 0 deletions test/issues/#73.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
import * as Iridium from "../../iridium";
import * as chai from "chai";

interface TestDocument {
_id?: string;
metadata: any;
}

@Iridium.Collection("test")
@Iridium.Transform(doc => {
if (doc.metadata && typeof doc.metadata === "string")
doc.metadata = JSON.parse(doc.metadata);
return doc;
}, doc => {
if (doc.metadata && typeof doc.metadata === "object")
doc.metadata = JSON.stringify(doc.metadata);
return doc
})
class Test extends Iridium.Instance<TestDocument, Test> implements TestDocument {
@Iridium.ObjectID
_id: string;

@Iridium.Property(true)
metadata: any;
}

describe.only("issues", () => {
let core = new Iridium.Core({ database: "test" });
before(() => core.connect());
after(() => core.close());

describe("#73", () => {
let model = new Iridium.Model<TestDocument, Test>(core, Test);
beforeEach(() => model.remove());
beforeEach(() => model.insert([
{ metadata: { test: 1 } },
{ metadata: { test: 2 } },
{ metadata: { test: 3 } },
]));

it("should persist metadata as a string", () => {
return model.collection.find({}).toArray().then(docs => {
return chai.expect(docs.map(c => c.metadata)).to.eql([
"{\"test\":1}",
"{\"test\":2}",
"{\"test\":3}"
]);
});
});

it("map should apply document transforms", () => {
return chai.expect(model.find().map(c => c.metadata)).to.eventually.eql([
{ test: 1 },
{ test: 2 },
{ test: 3 },
]);
});
});
});
3 changes: 2 additions & 1 deletion test/mocha.opts
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
--require dist/test/support/chai
--timeout 10s
--timeout 10s
--recursive

0 comments on commit a2062b7

Please sign in to comment.