Normalize fields when creating and running translator tests
This commit is contained in:
parent
fc3b2c3538
commit
d514f02c34
1 changed files with 31 additions and 4 deletions
|
@ -213,12 +213,39 @@ Zotero_TranslatorTester._sanitizeItem = function(item, forSave) {
|
|||
item = JSON.parse(JSON.stringify(item));
|
||||
} catch(e) {};
|
||||
|
||||
// remove fields to be ignored
|
||||
const IGNORE_FIELDS = ["complete", "accessDate", "checkFields"];
|
||||
for(var j=0, n=IGNORE_FIELDS.length; j<n; j++) {
|
||||
delete item[IGNORE_FIELDS[j]];
|
||||
// remove fields that don't exist or aren't valid for this item type, and normalize base fields
|
||||
// to fields specific to this item
|
||||
var fieldID,
|
||||
typeID = Zotero.ItemTypes.getID(item.itemType);
|
||||
const skipFields = ["note", "notes", "itemID", "attachments", "tags", "seeAlso",
|
||||
"itemType", "complete", "creators"];
|
||||
for(var field in item) {
|
||||
if(skipFields.indexOf(field) !== -1) continue;
|
||||
|
||||
if(!item[field] || !(fieldID = Zotero.ItemFields.getID(field))) {
|
||||
delete item[field];
|
||||
continue;
|
||||
}
|
||||
|
||||
if(Zotero.ItemFields.isBaseField(fieldID)) {
|
||||
var value = item[field];
|
||||
delete item[field];
|
||||
|
||||
var itemFieldID = Zotero.ItemFields.getFieldIDFromTypeAndBase(typeID, fieldID);
|
||||
if(itemFieldID) {
|
||||
item[Zotero.ItemFields.getName(itemFieldID)] = value;
|
||||
}
|
||||
continue;
|
||||
}
|
||||
|
||||
if(!Zotero.ItemFields.isValidForType(fieldID, typeID)) {
|
||||
delete item[field];
|
||||
}
|
||||
}
|
||||
|
||||
// remove fields to be ignored
|
||||
if("accessDate" in item) delete item.accessDate;
|
||||
|
||||
return item;
|
||||
};
|
||||
/**
|
||||
|
|
Loading…
Reference in a new issue