Fix a few small data layer bugs, and tidy up a little

I don't think these were triggered by any client code, but I found them while
porting code to the server.
This commit is contained in:
Dan Stillman 2015-07-31 04:03:09 -04:00
parent 30a329d2e8
commit 70d9b9870c
6 changed files with 229 additions and 119 deletions

View file

@ -3,26 +3,18 @@
describe("Zotero.DataObject", function() {
var types = ['collection', 'item', 'search'];
describe("#loadAllData()", function () {
it("should load data on a regular item", function* () {
var item = new Zotero.Item('book');
var id = yield item.saveTx();
yield item.loadAllData();
assert.throws(item.getNote.bind(item), 'getNote() can only be called on notes and attachments');
})
it("should load data on an attachment item", function* () {
var item = new Zotero.Item('attachment');
var id = yield item.saveTx();
yield item.loadAllData();
assert.equal(item.getNote(), '');
})
it("should load data on a note item", function* () {
var item = new Zotero.Item('note');
var id = yield item.saveTx();
yield item.loadAllData();
assert.equal(item.getNote(), '');
describe("#key", function () {
it("shouldn't update .loaded on get if unset", function* () {
for (let type of types) {
if (type == 'item') {
var param = 'book';
}
let obj = new Zotero[Zotero.Utilities.capitalize(type)](param);
obj.libraryID = Zotero.Libraries.userLibraryID;
assert.isNull(obj.key);
assert.isFalse(obj._loaded.primaryData);
obj.key = Zotero.DataObjectUtilities.generateKey();
}
})
})
@ -173,6 +165,53 @@ describe("Zotero.DataObject", function() {
});
})
describe("#loadPrimaryData()", function () {
it("should load unloaded primary data if partially set", function* () {
var objs = {};
for (let type of types) {
let obj = createUnsavedDataObject(type);
yield obj.save({
skipCache: true
});
objs[type] = {
key: obj.key,
version: obj.version
};
}
for (let type of types) {
let obj = new Zotero[Zotero.Utilities.capitalize(type)];
obj.libraryID = Zotero.Libraries.userLibraryID;
obj.key = objs[type].key;
yield obj.loadPrimaryData();
assert.equal(obj.version, objs[type].version);
}
})
})
describe("#loadAllData()", function () {
it("should load data on a regular item", function* () {
var item = new Zotero.Item('book');
var id = yield item.saveTx();
yield item.loadAllData();
assert.throws(item.getNote.bind(item), 'getNote() can only be called on notes and attachments');
})
it("should load data on an attachment item", function* () {
var item = new Zotero.Item('attachment');
var id = yield item.saveTx();
yield item.loadAllData();
assert.equal(item.getNote(), '');
})
it("should load data on a note item", function* () {
var item = new Zotero.Item('note');
var id = yield item.saveTx();
yield item.loadAllData();
assert.equal(item.getNote(), '');
})
})
describe("#save()", function () {
it("should add new identifiers to cache", function* () {
// Collection