drafts: Fix faulty draft_model addDraft and editDraft tests

The addDraft and editDraft tests were copying objects by reference
which meant the methods weren't tested properly. Due to this, a bug with
stubTimestamp was also discovered where the method wasn't getting stubbed
This commit is contained in:
Sampriti Panda 2017-03-29 11:52:25 +05:30 committed by Tim Abbott
parent 4659f97649
commit 400a2e0ff1
1 changed files with 10 additions and 10 deletions

View File

@ -21,13 +21,13 @@ set_global('localStorage', {
},
});
function stub_timestamp(model, timestamp, func) {
var original_func = model.getTimestamp;
model.getTimestamp = function () {
function stub_timestamp(timestamp, func) {
var original_func = Date.prototype.getTime;
Date.prototype.getTime = function () {
return timestamp;
};
func();
model.getTimestamp = original_func;
Date.prototype.getTime = original_func;
}
var draft_1 = {
@ -64,10 +64,10 @@ var draft_2 = {
localStorage.clear();
(function test_addDraft() {
stub_timestamp(draft_model, 1, function () {
var expected = draft_1;
stub_timestamp(1, function () {
var expected = _.clone(draft_1);
expected.updatedAt = 1;
var id = draft_model.addDraft(draft_1);
var id = draft_model.addDraft(_.clone(draft_1));
assert.deepEqual(ls.get("drafts")[id], expected);
});
@ -75,11 +75,11 @@ var draft_2 = {
localStorage.clear();
(function test_editDraft() {
stub_timestamp(draft_model, 2, function () {
stub_timestamp(2, function () {
ls.set("drafts", { id1: draft_1 } );
var expected = draft_2;
var expected = _.clone(draft_2);
expected.updatedAt = 2;
draft_model.editDraft("id1", draft_2);
draft_model.editDraft("id1", _.clone(draft_2));
assert.deepEqual(ls.get("drafts").id1, expected);
});