-
Notifications
You must be signed in to change notification settings - Fork 27
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test: Added reproduction case for #73
- Loading branch information
1 parent
08ccd6d
commit a2062b7
Showing
2 changed files
with
61 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 }, | ||
]); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
--require dist/test/support/chai | ||
--timeout 10s | ||
--timeout 10s | ||
--recursive |