/
pushChanges.js
77 lines (63 loc) · 2.98 KB
/
pushChanges.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
// ==========================================================================
// Project: SproutCore - JavaScript Application Framework
// Copyright: ©2006-2011 Apple Inc. and contributors.
// License: Licensed under MIT license (see license.js)
// ==========================================================================
/*globals module ok equals same test MyApp */
var store, storeKey, json;
module("SC.Store#pushChanges", {
setup: function() {
SC.RunLoop.begin();
store = SC.Store.create();
json = {
string: "string",
number: 23,
bool: YES
};
storeKey1 = SC.Store.generateStoreKey();
store.writeDataHash(storeKey1, json, SC.Record.EMPTY);
storeKey2 = SC.Store.generateStoreKey();
store.writeDataHash(storeKey2, json, SC.Record.EMPTY);
storeKey3 = SC.Store.generateStoreKey();
store.writeDataHash(storeKey3, json, SC.Record.EMPTY);
storeKey4 = SC.Store.generateStoreKey();
store.writeDataHash(storeKey4, json, SC.Record.BUSY_LOADING);
storeKey5 = SC.Store.generateStoreKey();
store.writeDataHash(storeKey5, json, SC.Record.BUSY_LOADING);
storeKey6 = SC.Store.generateStoreKey();
store.writeDataHash(storeKey6, json, SC.Record.BUSY_LOADING);
SC.RunLoop.end();
}
});
test("Do a pushRetrieve and check if there is conflicts", function() {
var res = store.pushRetrieve(SC.Record, undefined, undefined, storeKey1);
equals(res, storeKey1, "There is no conflict, pushRetrieve was succesful.");
res = store.pushRetrieve(SC.Record, undefined, undefined, storeKey4);
ok(!res, "There is a conflict, because of the state, this is expected.");
});
test("Do a pushDestroy and check if there is conflicts", function() {
var res = store.pushDestroy(SC.Record, undefined, storeKey2);
equals(res, storeKey2, "There is no conflict, pushDestroy was succesful.");
res = store.pushRetrieve(SC.Record, undefined, undefined, storeKey5);
ok(!res, "There is a conflict, because of the state, this is expected.");
});
test("Issue a pushError and check if there is conflicts", function() {
var res = store.pushError(SC.Record, undefined, SC.Record.NOT_FOUND_ERROR, storeKey3);
equals(res, storeKey3, "There is no conflict, pushError was succesful.");
res = store.pushRetrieve(SC.Record, undefined, undefined, storeKey6);
ok(!res, "There is a conflict, because of the state, this is expected.");
});
test("A pushRetrieve updating the id of an existing record should update the primary Key cache", function(){
var tmpid, recFirst, recSecond, sK;
tmpid = "@2345235asddsgfd";
recFirst = { firstname: 'me', lastname: 'too', guid: tmpid };
recSecond = { firstname: 'me', lastname: 'too', guid: 1 };
SC.RunLoop.begin();
var sK = store.loadRecord(SC.Record, rec, tmpid);
SC.RunLoop.end();
equals(store.idFor(sK),tmpid); //check whether the id is indeed tmpid
SC.RunLoop.begin();
store.pushRetrieve(SC.Record,1,recSecond,sK);
SC.RunLoop.end();
equals(store.idFor(sK),1); // id should now have been updated
});