www

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs | Submodules | README | LICENSE

relationsTest.js (2142B)


      1 "use strict";
      2 
      3 describe("Zotero.Relations", function () {
      4 	describe("#getByPredicateAndObject()", function () {
      5 		it("should return items matching predicate and object", function* () {
      6 			var item = createUnsavedDataObject('item');
      7 			item.setRelations({
      8 				"dc:relation": [
      9 					"http://zotero.org/users/1/items/SHREREMS"
     10 				],
     11 				"owl:sameAs": [
     12 					"http://zotero.org/groups/1/items/SRRMGSRM",
     13 					"http://zotero.org/groups/1/items/GSMRRSSM"
     14 				]
     15 			})
     16 			yield item.saveTx();
     17 			var objects = Zotero.Relations.getByPredicateAndObject(
     18 				'item', 'owl:sameAs', 'http://zotero.org/groups/1/items/SRRMGSRM'
     19 			);
     20 			assert.lengthOf(objects, 1);
     21 			assert.equal(objects[0], item);
     22 		})
     23 	})
     24 	
     25 	describe("#updateUser", function () {
     26 		beforeEach(function* () {
     27 			yield Zotero.DB.queryAsync("DELETE FROM settings WHERE setting='account'");
     28 			yield Zotero.Users.init();
     29 		})
     30 		
     31 		it("should update relations using local user key to use userID", function* () {
     32 			var item1 = yield createDataObject('item');
     33 			var item2 = createUnsavedDataObject('item');
     34 			item2.addRelatedItem(item1);
     35 			yield item2.save();
     36 			
     37 			var rels = item2.getRelationsByPredicate(Zotero.Relations.relatedItemPredicate);
     38 			assert.include(rels[0], "/users/local");
     39 			
     40 			yield Zotero.DB.executeTransaction(function* () {
     41 				yield Zotero.Relations.updateUser(null, 1);
     42 			})
     43 			
     44 			var rels = item2.getRelationsByPredicate(Zotero.Relations.relatedItemPredicate);
     45 			assert.include(rels[0], "/users/1");
     46 		})
     47 		
     48 		it("should update relations from one userID to another", function* () {
     49 			yield Zotero.Users.setCurrentUserID(1);
     50 			
     51 			var item1 = yield createDataObject('item');
     52 			var item2 = createUnsavedDataObject('item');
     53 			item2.addRelatedItem(item1);
     54 			yield item2.save();
     55 			
     56 			var rels = item2.getRelationsByPredicate(Zotero.Relations.relatedItemPredicate);
     57 			assert.include(rels[0], "/users/1");
     58 			
     59 			yield Zotero.DB.executeTransaction(function* () {
     60 				yield Zotero.Relations.updateUser(1, 2);
     61 			});
     62 			
     63 			var rels = item2.getRelationsByPredicate(Zotero.Relations.relatedItemPredicate);
     64 			assert.include(rels[0], "/users/2");
     65 		})
     66 	})
     67 })