commit bf1ee0d52b9efe5b86460b2dbe31d3551e6eab01
parent 6933f64616af3285b23ef6f0c3b77266c2c708c0
Author: Dan Stillman <dstillman@zotero.org>
Date: Sun, 24 May 2015 22:14:52 -0400
Move getLibraryAndKeyFromID() tests to dataObjectsTest.js
Diffstat:
2 files changed, 47 insertions(+), 32 deletions(-)
diff --git a/test/tests/dataObjectsTest.js b/test/tests/dataObjectsTest.js
@@ -0,0 +1,46 @@
+"use strict";
+
+describe("Zotero.DataObjects", function () {
+ var types = ['collection', 'item', 'search'];
+
+ describe("#getLibraryAndKeyFromID()", function () {
+ it("should return a libraryID and key within a transaction", function* () {
+ for (let type of types) {
+ let objectsClass = Zotero.DataObjectUtilities.getObjectsClassForObjectType(type);
+ yield Zotero.DB.executeTransaction(function* () {
+ let obj = createUnsavedDataObject(type);
+ yield obj.save();
+
+ var {libraryID, key} = objectsClass.getLibraryAndKeyFromID(obj.id);
+ assert.equal(libraryID, Zotero.Libraries.userLibraryID);
+ assert.ok(key);
+ assert.typeOf(key, 'string');
+ assert.equal(key, obj.key);
+
+ yield obj.erase();
+ });
+ }
+ });
+
+ it("should return false after a save failure", function* () {
+ for (let type of types) {
+ let objectsClass = Zotero.DataObjectUtilities.getObjectsClassForObjectType(type);
+ var obj;
+ try {
+ yield Zotero.DB.executeTransaction(function* () {
+ obj = createUnsavedDataObject(type);
+ yield obj.save();
+ throw 'Aborting transaction -- ignore';
+ });
+ }
+ catch (e) {
+ if (typeof e != 'string' || !e.startsWith('Aborting transaction')) throw e;
+ }
+
+ // The registered identifiers should be reset in a rollback handler
+ var libraryKey = objectsClass.getLibraryAndKeyFromID(obj.id);
+ assert.isFalse(libraryKey);
+ }
+ });
+ });
+})
diff --git a/test/tests/itemsTest.js b/test/tests/itemsTest.js
@@ -1,34 +1,3 @@
describe("Zotero.Items", function() {
- describe("#getLibraryAndKeyFromID()", function () {
- it("should return a libraryID and key within a transaction", function* () {
- return Zotero.DB.executeTransaction(function* () {
- var item = new Zotero.Item('book');
- var itemID = yield item.save();
-
- var {libraryID, key} = Zotero.Items.getLibraryAndKeyFromID(itemID);
- assert.equal(libraryID, Zotero.Libraries.userLibraryID);
- assert.ok(key);
- assert.typeOf(key, 'string');
- assert.equal(key, item.key);
- });
- });
-
- it("should return false after a save failure", function* () {
- var itemID;
- try {
- yield Zotero.DB.executeTransaction(function* () {
- var item = new Zotero.Item('book');
- itemID = yield item.save();
- throw 'Aborting transaction -- ignore';
- });
- }
- catch (e) {
- if (typeof e != 'string' || !e.startsWith('Aborting transaction')) throw e;
- }
-
- // The registered identifiers should be reset in a rollback handler
- var libraryKey = Zotero.Items.getLibraryAndKeyFromID(itemID);
- assert.isFalse(libraryKey);
- });
- });
+
});