Add getGroup() and createGroup() test support functions

getGroup() can be used to access a default group library for general
group tests. createGroup() can be used to create one for a particular
test or set of tests.
This commit is contained in:
Dan Stillman 2015-06-01 20:00:25 -04:00
parent 5a5a8a93f9
commit c1cb832b0b
2 changed files with 26 additions and 10 deletions

View file

@ -163,6 +163,30 @@ function waitForCallback(cb, interval, timeout) {
return deferred.promise;
}
/**
* Get a default group used by all tests that want one, creating one if necessary
*/
var getGroup = Zotero.lazy(function () {
return createGroup({
name: "My Group"
});
});
var createGroup = Zotero.Promise.coroutine(function* (props) {
props = props || {};
var group = new Zotero.Group;
group.id = Zotero.Utilities.rand(10000, 1000000);
group.name = props.name || "Test " + Zotero.Utilities.randomString();
group.description = props.description || "";
group.editable = props.editable || true;
group.filesEditable = props.filesEditable || true;
group.version = props.version || Zotero.Utilities.rand(1000, 10000);
yield group.save();
return group;
});
//
// Data objects
//

View file

@ -1,17 +1,9 @@
describe("Zotero.Groups", function () {
describe("#get()", function () {
it("should retrieve a newly created group", function* () {
var group = new Zotero.Group;
group.id = 1851251;
group.libraryID = yield Zotero.ID.get('libraries');
group.name = "Test";
group.description = "";
group.editable = true;
group.filesEditable = true;
group.version = 1234;
try {
yield group.save();
assert.equal(Zotero.Groups.get(1851251), group)
var group = yield createGroup();
assert.equal(Zotero.Groups.get(group.id), group)
}
finally {
if (group) {