From f6442a223a7d71653aebd460cf5a9b69cbfa6f79 Mon Sep 17 00:00:00 2001 From: Benjamin Pannell Date: Mon, 20 Jun 2016 19:26:05 +0200 Subject: [PATCH] test: Add tests to ensure that #40 works fine --- test/Instance.ts | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/test/Instance.ts b/test/Instance.ts index 3fa9cda..b052a85 100644 --- a/test/Instance.ts +++ b/test/Instance.ts @@ -178,6 +178,28 @@ describe("Instance",() => { 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 set isNew to false after inserting a new instance",() => { + let instance = new core.Test.Instance({ + answer: 1 + }); + + chai.expect((instance)._isNew).to.be.true; + return instance.save().then(() => chai.expect((instance)._isNew).to.be.false); + }); + + it("should allow a new instance to be saved on insertion, modified and saved again",() => { + let instance = new core.Test.Instance({ + answer: 1 + }); + + return chai.expect(instance.save().then(() => { + instance.answer = 2; + return instance.save(); + })).to.eventually.not.be.rejected; + + 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",() => { return core.Test.insert({ answer: 1