diff --git a/js/common/tests/shell/shell-document-babies.js b/js/common/tests/shell/shell-document-babies.js index 1e57834ac9..022f2e5e86 100644 --- a/js/common/tests/shell/shell-document-babies.js +++ b/js/common/tests/shell/shell-document-babies.js @@ -2,10 +2,6 @@ /*global fail, assertEqual */ //////////////////////////////////////////////////////////////////////////////// -/// @brief test the document interface -/// -/// @file -/// /// DISCLAIMER /// /// Copyright 2010-2016 triagens GmbH, Cologne, Germany @@ -25,7 +21,6 @@ /// Copyright holder is ArangoDB GmbH, Cologne, Germany /// /// @author Max Neunhoeffer -/// @author Copyright 2016, ArangoDB GmbH, Cologne, Germany //////////////////////////////////////////////////////////////////////////////// var jsunity = require("jsunity"); @@ -46,20 +41,22 @@ function CollectionDocumentSuiteBabies() { return { -//////////////////////////////////////////////////////////////////////////////// -/// @brief set up -//////////////////////////////////////////////////////////////////////////////// + //////////////////////////////////////////////////////////////////////////////// + /// @brief set up + //////////////////////////////////////////////////////////////////////////////// - setUp : function () { + setUp: function() { db._drop(cn); - collection = db._create(cn, { waitForSync : false }); + collection = db._create(cn, { + waitForSync: false + }); }, -//////////////////////////////////////////////////////////////////////////////// -/// @brief tear down -//////////////////////////////////////////////////////////////////////////////// + //////////////////////////////////////////////////////////////////////////////// + /// @brief tear down + //////////////////////////////////////////////////////////////////////////////// - tearDown : function () { + tearDown: function() { if (collection) { collection.unload(); collection.drop(); @@ -68,47 +65,53 @@ function CollectionDocumentSuiteBabies() { wait(0.0); }, -//////////////////////////////////////////////////////////////////////////////// -/// @brief insert multiple documents and remove them again -//////////////////////////////////////////////////////////////////////////////// + //////////////////////////////////////////////////////////////////////////////// + /// @brief insert multiple documents and remove them again + //////////////////////////////////////////////////////////////////////////////// - testInsertRemoveMulti : function () { + testInsertRemoveMulti: function() { var docs = collection.insert([{}, {}, {}]); assertEqual(docs.length, 3); collection.remove(docs); assertEqual(collection.count(), 0); }, -//////////////////////////////////////////////////////////////////////////////// -/// @brief insert multiple documents and remove them again by key -//////////////////////////////////////////////////////////////////////////////// + //////////////////////////////////////////////////////////////////////////////// + /// @brief insert multiple documents and remove them again by key + //////////////////////////////////////////////////////////////////////////////// - testInsertRemoveMultiByKey : function () { + testInsertRemoveMultiByKey: function() { var docs = collection.insert([{}, {}, {}]); assertEqual(docs.length, 3); - collection.remove(docs.map(function(x) { return x._key; })); + collection.remove(docs.map(function(x) { + return x._key; + })); assertEqual(collection.count(), 0); }, -//////////////////////////////////////////////////////////////////////////////// -/// @brief insert multiple documents and remove them again by id -//////////////////////////////////////////////////////////////////////////////// + //////////////////////////////////////////////////////////////////////////////// + /// @brief insert multiple documents and remove them again by id + //////////////////////////////////////////////////////////////////////////////// - testInsertRemoveMultiById : function () { + testInsertRemoveMultiById: function() { var docs = collection.insert([{}, {}, {}]); assertEqual(docs.length, 3); - collection.remove(docs.map(function(x) { return x._id; })); + collection.remove(docs.map(function(x) { + return x._id; + })); assertEqual(collection.count(), 0); }, -//////////////////////////////////////////////////////////////////////////////// -/// @brief insert multiple documents and remove them again, many case -//////////////////////////////////////////////////////////////////////////////// + //////////////////////////////////////////////////////////////////////////////// + /// @brief insert multiple documents and remove them again, many case + //////////////////////////////////////////////////////////////////////////////// - testInsertRemoveMultiMany : function () { + testInsertRemoveMultiMany: function() { var l = []; for (var i = 0; i < 10000; i++) { - l.push({value:i}); + l.push({ + value: i + }); } var docs = collection.insert(l); assertEqual(docs.length, l.length); @@ -116,77 +119,110 @@ function CollectionDocumentSuiteBabies() { assertEqual(collection.count(), 0); }, -//////////////////////////////////////////////////////////////////////////////// -/// @brief insert multiple documents and remove them again by key, many case -//////////////////////////////////////////////////////////////////////////////// + //////////////////////////////////////////////////////////////////////////////// + /// @brief insert multiple documents and remove them again by key, many case + //////////////////////////////////////////////////////////////////////////////// - testInsertRemoveMultiManyByKey : function () { + testInsertRemoveMultiManyByKey: function() { var l = []; for (var i = 0; i < 10000; i++) { - l.push({value:i}); + l.push({ + value: i + }); } var docs = collection.insert(l); assertEqual(docs.length, l.length); - collection.remove(docs.map(function(x) { return x._key; })); + collection.remove(docs.map(function(x) { + return x._key; + })); assertEqual(collection.count(), 0); }, -//////////////////////////////////////////////////////////////////////////////// -/// @brief insert multiple documents and remove them again by id, many case -//////////////////////////////////////////////////////////////////////////////// + //////////////////////////////////////////////////////////////////////////////// + /// @brief insert multiple documents and remove them again by id, many case + //////////////////////////////////////////////////////////////////////////////// - testInsertRemoveMultiManyById : function () { + testInsertRemoveMultiManyById: function() { var l = []; for (var i = 0; i < 10000; i++) { - l.push({value:i}); + l.push({ + value: i + }); } var docs = collection.insert(l); assertEqual(docs.length, l.length); - collection.remove(docs.map(function(x) { return x._id; })); + collection.remove(docs.map(function(x) { + return x._id; + })); assertEqual(collection.count(), 0); }, -//////////////////////////////////////////////////////////////////////////////// -/// @brief insert multiple documents w. given key and remove them again -//////////////////////////////////////////////////////////////////////////////// + //////////////////////////////////////////////////////////////////////////////// + /// @brief insert multiple documents w. given key and remove them again + //////////////////////////////////////////////////////////////////////////////// - testInsertWithKeyRemoveMulti : function () { - var docs = collection.insert([{_key:"a"}, {_key:"b"}, {_key:"c"}]); + testInsertWithKeyRemoveMulti: function() { + var docs = collection.insert([{ + _key: "a" + }, { + _key: "b" + }, { + _key: "c" + }]); assertEqual(docs.length, 3); collection.remove(docs); assertEqual(collection.count(), 0); }, -//////////////////////////////////////////////////////////////////////////////// -/// @brief insert multiple documents and remove them again by key -//////////////////////////////////////////////////////////////////////////////// + //////////////////////////////////////////////////////////////////////////////// + /// @brief insert multiple documents and remove them again by key + //////////////////////////////////////////////////////////////////////////////// - testInsertWithKeyRemoveMultiByKey : function () { - var docs = collection.insert([{_key:"a"}, {_key:"b"}, {_key:"c"}]); + testInsertWithKeyRemoveMultiByKey: function() { + var docs = collection.insert([{ + _key: "a" + }, { + _key: "b" + }, { + _key: "c" + }]); assertEqual(docs.length, 3); - collection.remove(docs.map(function(x) { return x._key; })); + collection.remove(docs.map(function(x) { + return x._key; + })); assertEqual(collection.count(), 0); }, -//////////////////////////////////////////////////////////////////////////////// -/// @brief insert multiple documents and remove them again by id -//////////////////////////////////////////////////////////////////////////////// + //////////////////////////////////////////////////////////////////////////////// + /// @brief insert multiple documents and remove them again by id + //////////////////////////////////////////////////////////////////////////////// - testInsertWithKeyRemoveMultiById : function () { - var docs = collection.insert([{_key:"a"}, {_key:"b"}, {_key:"c"}]); + testInsertWithKeyRemoveMultiById: function() { + var docs = collection.insert([{ + _key: "a" + }, { + _key: "b" + }, { + _key: "c" + }]); assertEqual(docs.length, 3); - collection.remove(docs.map(function(x) { return x._id; })); + collection.remove(docs.map(function(x) { + return x._id; + })); assertEqual(collection.count(), 0); }, -//////////////////////////////////////////////////////////////////////////////// -/// @brief insert multiple documents and remove them again, many case -//////////////////////////////////////////////////////////////////////////////// + //////////////////////////////////////////////////////////////////////////////// + /// @brief insert multiple documents and remove them again, many case + //////////////////////////////////////////////////////////////////////////////// - testInsertWithKeyRemoveMultiMany : function () { + testInsertWithKeyRemoveMultiMany: function() { var l = []; for (var i = 0; i < 10000; i++) { - l.push({_key:"K"+i, value:i}); + l.push({ + _key: "K" + i, + value: i + }); } var docs = collection.insert(l); assertEqual(docs.length, l.length); @@ -194,122 +230,162 @@ function CollectionDocumentSuiteBabies() { assertEqual(collection.count(), 0); }, -//////////////////////////////////////////////////////////////////////////////// -/// @brief insert multiple documents and remove them again by key, many case -//////////////////////////////////////////////////////////////////////////////// + //////////////////////////////////////////////////////////////////////////////// + /// @brief insert multiple documents and remove them again by key, many case + //////////////////////////////////////////////////////////////////////////////// - testInsertWithKeyRemoveMultiManyByKey : function () { + testInsertWithKeyRemoveMultiManyByKey: function() { var l = []; for (var i = 0; i < 10000; i++) { - l.push({_key:"K"+i, value:i}); + l.push({ + _key: "K" + i, + value: i + }); } var docs = collection.insert(l); assertEqual(docs.length, l.length); - collection.remove(docs.map(function(x) { return x._key; })); + collection.remove(docs.map(function(x) { + return x._key; + })); assertEqual(collection.count(), 0); }, -//////////////////////////////////////////////////////////////////////////////// -/// @brief insert multiple documents and remove them again by id, many case -//////////////////////////////////////////////////////////////////////////////// + //////////////////////////////////////////////////////////////////////////////// + /// @brief insert multiple documents and remove them again by id, many case + //////////////////////////////////////////////////////////////////////////////// - testInsertWithKeyRemoveMultiManyById : function () { + testInsertWithKeyRemoveMultiManyById: function() { var l = []; for (var i = 0; i < 10000; i++) { - l.push({_key:"K"+i, value:i}); + l.push({ + _key: "K" + i, + value: i + }); } var docs = collection.insert(l); assertEqual(docs.length, l.length); - collection.remove(docs.map(function(x) { return x._id; })); + collection.remove(docs.map(function(x) { + return x._id; + })); assertEqual(collection.count(), 0); }, -//////////////////////////////////////////////////////////////////////////////// -/// @brief insert with unique constraint violation -//////////////////////////////////////////////////////////////////////////////// + //////////////////////////////////////////////////////////////////////////////// + /// @brief insert with unique constraint violation + //////////////////////////////////////////////////////////////////////////////// - testInsertErrorUniqueConstraint : function () { - collection.insert([{_key: "a"}]); + testInsertErrorUniqueConstraint: function() { + collection.insert([{ + _key: "a" + }]); try { - collection.insert([{_key: "b"}, {_key: "a"}]); + collection.insert([{ + _key: "b" + }, { + _key: "a" + }]); fail(); - } - catch (err) { + } catch (err) { assertEqual(ERRORS.ERROR_ARANGO_UNIQUE_CONSTRAINT_VIOLATED.code, - err.errorNum); + err.errorNum); } assertEqual(collection.count(), 1); try { - collection.insert([{_key: "a"}, {_key: "b"}]); + collection.insert([{ + _key: "a" + }, { + _key: "b" + }]); fail(); - } - catch (err) { + } catch (err) { assertEqual(ERRORS.ERROR_ARANGO_UNIQUE_CONSTRAINT_VIOLATED.code, - err.errorNum); + err.errorNum); } assertEqual(collection.count(), 1); }, -//////////////////////////////////////////////////////////////////////////////// -/// @brief insert with bad key types -//////////////////////////////////////////////////////////////////////////////// + //////////////////////////////////////////////////////////////////////////////// + /// @brief insert with bad key types + //////////////////////////////////////////////////////////////////////////////// - testInsertErrorBadKey : function () { - var l = [null, false, true, 1, -1, {}, []]; + testInsertErrorBadKey: function() { + var l = [null, false, true, 1, -1, {}, + [] + ]; l.forEach(function(k) { try { - collection.insert([{_key: "a"},{_key: k}]); + collection.insert([{ + _key: "a" + }, { + _key: k + }]); fail(); - } - catch (err) { + } catch (err) { assertEqual(ERRORS.ERROR_ARANGO_DOCUMENT_KEY_BAD.code, - err.errorNum); + err.errorNum); } }); assertEqual(collection.count(), 0); }, -//////////////////////////////////////////////////////////////////////////////// -/// @brief database methods _replace and _update and _remove cannot do babies: -//////////////////////////////////////////////////////////////////////////////// + //////////////////////////////////////////////////////////////////////////////// + /// @brief database methods _replace and _update and _remove cannot do babies: + //////////////////////////////////////////////////////////////////////////////// - testErrorDatabaseMethodsNoBabies : function () { - collection.insert({_key: "b"}); + testErrorDatabaseMethodsNoBabies: function() { + collection.insert({ + _key: "b" + }); try { - db._replace([cn + "/b"], [{_id: cn + "/b", value: 12}]); + db._replace([cn + "/b"], [{ + _id: cn + "/b", + value: 12 + }]); fail(); - } - catch (err) { + } catch (err) { assertEqual(ERRORS.ERROR_ARANGO_DOCUMENT_TYPE_INVALID.code, - err.errorNum); + err.errorNum); } try { - db._update([cn + "/b"], [{_id: cn + "/b", value: 12}]); + db._update([cn + "/b"], [{ + _id: cn + "/b", + value: 12 + }]); fail(); - } - catch (err) { + } catch (err) { assertEqual(ERRORS.ERROR_ARANGO_DOCUMENT_TYPE_INVALID.code, - err.errorNum); + err.errorNum); } try { db._remove([cn + "/b"]); fail(); - } - catch (err) { + } catch (err) { assertEqual(ERRORS.ERROR_ARANGO_DOCUMENT_HANDLE_BAD.code, - err.errorNum); + err.errorNum); } assertEqual(collection.count(), 1); }, -//////////////////////////////////////////////////////////////////////////////// -/// @brief replace multiple documents -//////////////////////////////////////////////////////////////////////////////// + //////////////////////////////////////////////////////////////////////////////// + /// @brief replace multiple documents + //////////////////////////////////////////////////////////////////////////////// - testReplaceMulti : function () { - var docs = collection.insert([{value:1}, {value:1}, {value:1}]); + testReplaceMulti: function() { + var docs = collection.insert([{ + value: 1 + }, { + value: 1 + }, { + value: 1 + }]); assertEqual(docs.length, 3); - var docs2 = collection.replace(docs, [{value:2}, {value:2}, {value:2}]); + var docs2 = collection.replace(docs, [{ + value: 2 + }, { + value: 2 + }, { + value: 2 + }]); var docs3 = collection.toArray(); assertEqual(docs3.length, 3); for (var i = 0; i < docs.length; i++) { @@ -318,8 +394,7 @@ function CollectionDocumentSuiteBabies() { try { collection.remove(docs); fail(); - } - catch (err) { + } catch (err) { assertEqual(ERRORS.ERROR_ARANGO_CONFLICT.code, err.errorNum); } assertEqual(collection.count(), 3); @@ -327,14 +402,26 @@ function CollectionDocumentSuiteBabies() { assertEqual(collection.count(), 0); }, -//////////////////////////////////////////////////////////////////////////////// -/// @brief update multiple documents -//////////////////////////////////////////////////////////////////////////////// + //////////////////////////////////////////////////////////////////////////////// + /// @brief update multiple documents + //////////////////////////////////////////////////////////////////////////////// - testUpdateMulti : function () { - var docs = collection.insert([{value:1}, {value:1}, {value:1}]); + testUpdateMulti: function() { + var docs = collection.insert([{ + value: 1 + }, { + value: 1 + }, { + value: 1 + }]); assertEqual(docs.length, 3); - var docs2 = collection.update(docs, [{value:2}, {value:2}, {value:2}]); + var docs2 = collection.update(docs, [{ + value: 2 + }, { + value: 2 + }, { + value: 2 + }]); var docs3 = collection.toArray(); assertEqual(docs3.length, 3); for (var i = 0; i < docs.length; i++) { @@ -343,8 +430,7 @@ function CollectionDocumentSuiteBabies() { try { collection.remove(docs); fail(); - } - catch (err) { + } catch (err) { assertEqual(ERRORS.ERROR_ARANGO_CONFLICT.code, err.errorNum); } assertEqual(collection.count(), 3); @@ -352,179 +438,284 @@ function CollectionDocumentSuiteBabies() { assertEqual(collection.count(), 0); }, -//////////////////////////////////////////////////////////////////////////////// -/// @brief read multiple documents -//////////////////////////////////////////////////////////////////////////////// + //////////////////////////////////////////////////////////////////////////////// + /// @brief read multiple documents + //////////////////////////////////////////////////////////////////////////////// - testDocumentMulti : function () { - var docs = collection.insert([{value:1}, {value:2}, {value:3}]); + testDocumentMulti: function() { + var docs = collection.insert([{ + value: 1 + }, { + value: 2 + }, { + value: 3 + }]); assertEqual(docs.length, 3); - var keys = docs.map(function(x) { return x._key; }); - var ids = docs.map(function(x) { return x._id; }); + var keys = docs.map(function(x) { + return x._key; + }); + var ids = docs.map(function(x) { + return x._id; + }); var docs2 = collection.document(docs); assertEqual(docs2.length, 3); - assertEqual(docs2.map(function(x) { return x.value; }), [1,2,3]); + assertEqual(docs2.map(function(x) { + return x.value; + }), [1, 2, 3]); docs2 = collection.document(keys.reverse()); assertEqual(docs2.length, 3); - assertEqual(docs2.map(function(x) { return x.value; }), [3,2,1]); + assertEqual(docs2.map(function(x) { + return x.value; + }), [3, 2, 1]); docs2 = collection.document(ids.reverse()); assertEqual(docs2.length, 3); - assertEqual(docs2.map(function(x) { return x.value; }), [3,2,1]); + assertEqual(docs2.map(function(x) { + return x.value; + }), [3, 2, 1]); }, -//////////////////////////////////////////////////////////////////////////////// -/// @brief test revision precondition for replace -//////////////////////////////////////////////////////////////////////////////// + //////////////////////////////////////////////////////////////////////////////// + /// @brief test revision precondition for replace + //////////////////////////////////////////////////////////////////////////////// - testReplaceMultiPrecondition : function () { - var docs = collection.insert([{value:1}, {value:2}, {value:3}]); - var docs2 = collection.replace(docs, [{value:4}, {value:5}, {value:6}]); + testReplaceMultiPrecondition: function() { + var docs = collection.insert([{ + value: 1 + }, { + value: 2 + }, { + value: 3 + }]); + var docs2 = collection.replace(docs, [{ + value: 4 + }, { + value: 5 + }, { + value: 6 + }]); var docs3; try { - docs3 = collection.replace(docs, [{value:7}, {value:8}, {value:9}]); + docs3 = collection.replace(docs, [{ + value: 7 + }, { + value: 8 + }, { + value: 9 + }]); fail(); - } - catch (err) { + } catch (err) { assertEqual(ERRORS.ERROR_ARANGO_CONFLICT.code, err.errorNum); } var test = [docs2[0], docs2[1], docs[2]]; try { - docs3 = collection.replace(test, [{value:7}, {value:8}, {value:9}]); + docs3 = collection.replace(test, [{ + value: 7 + }, { + value: 8 + }, { + value: 9 + }]); fail(); - } - catch (err2) { + } catch (err2) { assertEqual(ERRORS.ERROR_ARANGO_CONFLICT.code, err2.errorNum); } test = [docs[0], docs2[1], docs2[2]]; try { - docs3 = collection.replace(test, [{value:7}, {value:8}, {value:9}]); + docs3 = collection.replace(test, [{ + value: 7 + }, { + value: 8 + }, { + value: 9 + }]); fail(); - } - catch (err3) { + } catch (err3) { assertEqual(ERRORS.ERROR_ARANGO_CONFLICT.code, err3.errorNum); } - docs3 = collection.replace(test, [{value:7}, {value:8}, {value:9}], - {overwrite: true}); + docs3 = collection.replace(test, [{ + value: 7 + }, { + value: 8 + }, { + value: 9 + }], { + overwrite: true + }); }, -//////////////////////////////////////////////////////////////////////////////// -/// @brief test revision precondition for update -//////////////////////////////////////////////////////////////////////////////// + //////////////////////////////////////////////////////////////////////////////// + /// @brief test revision precondition for update + //////////////////////////////////////////////////////////////////////////////// - testUpdateMultiPrecondition : function () { - var docs = collection.insert([{value:1}, {value:2}, {value:3}]); - var docs2 = collection.replace(docs, [{value:4}, {value:5}, {value:6}]); + testUpdateMultiPrecondition: function() { + var docs = collection.insert([{ + value: 1 + }, { + value: 2 + }, { + value: 3 + }]); + var docs2 = collection.replace(docs, [{ + value: 4 + }, { + value: 5 + }, { + value: 6 + }]); var docs3; try { - docs3 = collection.update(docs, [{value:7}, {value:8}, {value:9}]); + docs3 = collection.update(docs, [{ + value: 7 + }, { + value: 8 + }, { + value: 9 + }]); fail(); - } - catch (err) { + } catch (err) { assertEqual(ERRORS.ERROR_ARANGO_CONFLICT.code, err.errorNum); } var test = [docs2[0], docs2[1], docs[2]]; try { - docs3 = collection.update(test, [{value:7}, {value:8}, {value:9}]); + docs3 = collection.update(test, [{ + value: 7 + }, { + value: 8 + }, { + value: 9 + }]); fail(); - } - catch (err2) { + } catch (err2) { assertEqual(ERRORS.ERROR_ARANGO_CONFLICT.code, err2.errorNum); } test = [docs[0], docs2[1], docs2[2]]; try { - docs3 = collection.update(test, [{value:7}, {value:8}, {value:9}]); + docs3 = collection.update(test, [{ + value: 7 + }, { + value: 8 + }, { + value: 9 + }]); fail(); - } - catch (err3) { + } catch (err3) { assertEqual(ERRORS.ERROR_ARANGO_CONFLICT.code, err3.errorNum); } - docs3 = collection.update(test, [{value:7}, {value:8}, {value:9}], - {overwrite: true}); + docs3 = collection.update(test, [{ + value: 7 + }, { + value: 8 + }, { + value: 9 + }], { + overwrite: true + }); }, -//////////////////////////////////////////////////////////////////////////////// -/// @brief test revision precondition for remove -//////////////////////////////////////////////////////////////////////////////// + //////////////////////////////////////////////////////////////////////////////// + /// @brief test revision precondition for remove + //////////////////////////////////////////////////////////////////////////////// - testRemoveMultiPrecondition : function () { - var docs = collection.insert([{value:1}, {value:2}, {value:3}]); - var docs2 = collection.replace(docs, [{value:4}, {value:5}, {value:6}]); + testRemoveMultiPrecondition: function() { + var docs = collection.insert([{ + value: 1 + }, { + value: 2 + }, { + value: 3 + }]); + var docs2 = collection.replace(docs, [{ + value: 4 + }, { + value: 5 + }, { + value: 6 + }]); var docs3; try { docs3 = collection.remove(docs); fail(); - } - catch (err) { + } catch (err) { assertEqual(ERRORS.ERROR_ARANGO_CONFLICT.code, err.errorNum); } var test = [docs2[0], docs2[1], docs[2]]; try { docs3 = collection.remove(test); fail(); - } - catch (err2) { + } catch (err2) { assertEqual(ERRORS.ERROR_ARANGO_CONFLICT.code, err2.errorNum); } test = [docs[0], docs2[1], docs2[2]]; try { docs3 = collection.remove(test); fail(); - } - catch (err3) { + } catch (err3) { assertEqual(ERRORS.ERROR_ARANGO_CONFLICT.code, err3.errorNum); } - docs3 = collection.remove(test, {overwrite: true}); + docs3 = collection.remove(test, { + overwrite: true + }); }, -//////////////////////////////////////////////////////////////////////////////// -/// @brief test revision precondition for document -//////////////////////////////////////////////////////////////////////////////// + //////////////////////////////////////////////////////////////////////////////// + /// @brief test revision precondition for document + //////////////////////////////////////////////////////////////////////////////// - testDocumentMultiPrecondition : function () { - var docs = collection.insert([{value:1}, {value:2}, {value:3}]); - var docs2 = collection.replace(docs, [{value:4}, {value:5}, {value:6}]); + testDocumentMultiPrecondition: function() { + var docs = collection.insert([{ + value: 1 + }, { + value: 2 + }, { + value: 3 + }]); + var docs2 = collection.replace(docs, [{ + value: 4 + }, { + value: 5 + }, { + value: 6 + }]); var docs3; try { docs3 = collection.document(docs); fail(); - } - catch (err) { + } catch (err) { assertEqual(ERRORS.ERROR_ARANGO_CONFLICT.code, err.errorNum); } var test = [docs2[0], docs2[1], docs[2]]; try { docs3 = collection.document(test); fail(); - } - catch (err2) { + } catch (err2) { assertEqual(ERRORS.ERROR_ARANGO_CONFLICT.code, err2.errorNum); } test = [docs[0], docs2[1], docs2[2]]; try { docs3 = collection.document(test); fail(); - } - catch (err3) { + } catch (err3) { assertEqual(ERRORS.ERROR_ARANGO_CONFLICT.code, err3.errorNum); } }, -//////////////////////////////////////////////////////////////////////////////// -/// @brief test bad arguments for insert/replace/update/remove for babies -//////////////////////////////////////////////////////////////////////////////// + //////////////////////////////////////////////////////////////////////////////// + /// @brief test bad arguments for insert/replace/update/remove for babies + //////////////////////////////////////////////////////////////////////////////// - testBadArguments : function () { + testBadArguments: function() { // Insert - var values = [null, false, true, 1, "abc", [], [1,2,3]]; + var values = [null, false, true, 1, "abc", [], + [1, 2, 3] + ]; var docs; values.forEach(function(x) { try { docs = collection.insert([x]); fail(); - } - catch (err) { + } catch (err) { assertEqual(ERRORS.ERROR_ARANGO_DOCUMENT_TYPE_INVALID.code, - err.errorNum); + err.errorNum); } }); docs = collection.insert([{}, {}, {}]); @@ -533,82 +724,76 @@ function CollectionDocumentSuiteBabies() { try { docs = collection.replace(docs, [x, x, x]); fail(); - } - catch (err2) { + } catch (err2) { assertEqual(ERRORS.ERROR_ARANGO_DOCUMENT_TYPE_INVALID.code, - err2.errorNum); + err2.errorNum); } try { docs = collection.replace([x, x, x], [{}, {}, {}]); fail(); - } - catch (err3) { + } catch (err3) { if (typeof x === "string") { assertEqual(ERRORS.ERROR_ARANGO_DOCUMENT_NOT_FOUND.code, - err3.errorNum); + err3.errorNum); } else { assertEqual(ERRORS.ERROR_ARANGO_DOCUMENT_HANDLE_BAD.code, - err3.errorNum); + err3.errorNum); } } // Update try { docs = collection.update(docs, [x, x, x]); fail(); - } - catch (err2) { + } catch (err2) { assertEqual(ERRORS.ERROR_ARANGO_DOCUMENT_TYPE_INVALID.code, - err2.errorNum); + err2.errorNum); } try { docs = collection.update([x, x, x], [{}, {}, {}]); fail(); - } - catch (err3) { + } catch (err3) { if (typeof x === "string") { assertEqual(ERRORS.ERROR_ARANGO_DOCUMENT_NOT_FOUND.code, - err3.errorNum); + err3.errorNum); } else { assertEqual(ERRORS.ERROR_ARANGO_DOCUMENT_HANDLE_BAD.code, - err3.errorNum); + err3.errorNum); } } // Remove try { docs = collection.remove([x, x, x]); fail(); - } - catch (err4) { + } catch (err4) { if (typeof x === "string") { assertEqual(ERRORS.ERROR_ARANGO_DOCUMENT_NOT_FOUND.code, - err4.errorNum); + err4.errorNum); } else { assertEqual(ERRORS.ERROR_ARANGO_DOCUMENT_HANDLE_BAD.code, - err4.errorNum); + err4.errorNum); } } // Document try { docs = collection.document([x, x, x]); fail(); - } - catch (err5) { + } catch (err5) { if (typeof x === "string") { assertEqual(ERRORS.ERROR_ARANGO_DOCUMENT_NOT_FOUND.code, - err5.errorNum); + err5.errorNum); } else { assertEqual(ERRORS.ERROR_ARANGO_DOCUMENT_HANDLE_BAD.code, - err5.errorNum); + err5.errorNum); } } }); }, -//////////////////////////////////////////////////////////////////////////////// -/// @brief test bad arguments II for insert/replace/update/remove for babies -//////////////////////////////////////////////////////////////////////////////// + //////////////////////////////////////////////////////////////////////////////// + /// @brief test bad arguments II for insert/replace/update/remove for babies + //////////////////////////////////////////////////////////////////////////////// - testBadArguments2 : function () { + testBadArguments2: function() { // Insert var docs; docs = collection.insert([{}, {}, {}]); @@ -616,51 +801,45 @@ function CollectionDocumentSuiteBabies() { try { docs = collection.replace(docs[0], [{}]); fail(); - } - catch (err) { + } catch (err) { assertEqual(ERRORS.ERROR_ARANGO_DOCUMENT_TYPE_INVALID.code, - err.errorNum); + err.errorNum); } try { docs = collection.replace(docs, {}); fail(); - } - catch (err2) { + } catch (err2) { assertEqual(ERRORS.ERROR_ARANGO_DOCUMENT_TYPE_INVALID.code, - err2.errorNum); + err2.errorNum); } try { docs = collection.replace(docs, [{}]); fail(); - } - catch (err3) { + } catch (err3) { assertEqual(ERRORS.ERROR_ARANGO_DOCUMENT_TYPE_INVALID.code, - err3.errorNum); + err3.errorNum); } // Update try { docs = collection.update(docs[0], [{}]); fail(); - } - catch (err4) { + } catch (err4) { assertEqual(ERRORS.ERROR_ARANGO_DOCUMENT_TYPE_INVALID.code, - err4.errorNum); + err4.errorNum); } try { docs = collection.update(docs, {}); fail(); - } - catch (err5) { + } catch (err5) { assertEqual(ERRORS.ERROR_ARANGO_DOCUMENT_TYPE_INVALID.code, - err5.errorNum); + err5.errorNum); } try { docs = collection.update(docs, [{}]); fail(); - } - catch (err6) { + } catch (err6) { assertEqual(ERRORS.ERROR_ARANGO_DOCUMENT_TYPE_INVALID.code, - err6.errorNum); + err6.errorNum); } } @@ -671,7 +850,7 @@ function CollectionDocumentSuiteBabies() { /// @brief test suite: returnNew and returnOld options //////////////////////////////////////////////////////////////////////////////// -function CollectionDocumentSuiteReturnStuff () { +function CollectionDocumentSuiteReturnStuff() { 'use strict'; var cn = "UnitTestsCollectionBasics"; var ERRORS = require("internal").errors; @@ -679,32 +858,36 @@ function CollectionDocumentSuiteReturnStuff () { return { -//////////////////////////////////////////////////////////////////////////////// -/// @brief set up -//////////////////////////////////////////////////////////////////////////////// + //////////////////////////////////////////////////////////////////////////////// + /// @brief set up + //////////////////////////////////////////////////////////////////////////////// - setUp : function () { + setUp: function() { db._drop(cn); - collection = db._create(cn, { waitForSync : false }); + collection = db._create(cn, { + waitForSync: false + }); collection.load(); }, -//////////////////////////////////////////////////////////////////////////////// -/// @brief tear down -//////////////////////////////////////////////////////////////////////////////// + //////////////////////////////////////////////////////////////////////////////// + /// @brief tear down + //////////////////////////////////////////////////////////////////////////////// - tearDown : function () { + tearDown: function() { collection.drop(); wait(0.0); }, -//////////////////////////////////////////////////////////////////////////////// -/// @brief create with and without returnNew -//////////////////////////////////////////////////////////////////////////////// + //////////////////////////////////////////////////////////////////////////////// + /// @brief create with and without returnNew + //////////////////////////////////////////////////////////////////////////////// - testCreateMultiReturnNew : function () { - var res = collection.insert([{"Hallo":12}]); + testCreateMultiReturnNew: function() { + var res = collection.insert([{ + "Hallo": 12 + }]); assertTypeOf("object", res); assertTrue(Array.isArray(res)); assertEqual(res.length, 1); @@ -715,7 +898,11 @@ function CollectionDocumentSuiteReturnStuff () { assertTypeOf("string", res[0]._rev); // Now with returnNew: true - res = collection.insert([{"Hallo":12}], {returnNew: true}); + res = collection.insert([{ + "Hallo": 12 + }], { + returnNew: true + }); assertTypeOf("object", res); assertTrue(Array.isArray(res)); assertTypeOf("object", res[0]); @@ -728,7 +915,11 @@ function CollectionDocumentSuiteReturnStuff () { assertEqual(4, Object.keys(res[0]["new"]).length); // Now with returnNew: false - res = collection.insert([{"Hallo":12}], {returnNew: false}); + res = collection.insert([{ + "Hallo": 12 + }], { + returnNew: false + }); assertTypeOf("object", res); assertTrue(Array.isArray(res)); assertTypeOf("object", res[0]); @@ -738,12 +929,14 @@ function CollectionDocumentSuiteReturnStuff () { assertTypeOf("string", res[0]._rev); }, -//////////////////////////////////////////////////////////////////////////////// -/// @brief remove with and without returnOld -//////////////////////////////////////////////////////////////////////////////// + //////////////////////////////////////////////////////////////////////////////// + /// @brief remove with and without returnOld + //////////////////////////////////////////////////////////////////////////////// - testRemoveMultiReturnOld : function () { - var res = collection.insert([{"Hallo":12}]); + testRemoveMultiReturnOld: function() { + var res = collection.insert([{ + "Hallo": 12 + }]); var res2 = collection.remove([res[0]._key]); assertTypeOf("object", res2); @@ -755,8 +948,12 @@ function CollectionDocumentSuiteReturnStuff () { assertTypeOf("string", res2[0]._rev); // Now with returnOld: true - res = collection.insert([{"Hallo":12}]); - res2 = collection.remove([res[0]._key], {returnOld: true}); + res = collection.insert([{ + "Hallo": 12 + }]); + res2 = collection.remove([res[0]._key], { + returnOld: true + }); assertTypeOf("object", res2[0]); assertEqual(4, Object.keys(res2[0]).length); assertTypeOf("string", res2[0]._id); @@ -767,8 +964,12 @@ function CollectionDocumentSuiteReturnStuff () { assertEqual(4, Object.keys(res2[0].old).length); // Now with returnOld: false - res = collection.insert([{"Hallo":12}]); - res2 = collection.remove([res[0]._key], {returnOld: false}); + res = collection.insert([{ + "Hallo": 12 + }]); + res2 = collection.remove([res[0]._key], { + returnOld: false + }); assertTypeOf("object", res2[0]); assertEqual(3, Object.keys(res2[0]).length); assertTypeOf("string", res2[0]._id); @@ -776,13 +977,17 @@ function CollectionDocumentSuiteReturnStuff () { assertTypeOf("string", res2[0]._rev); }, -//////////////////////////////////////////////////////////////////////////////// -/// @brief replace with and without returnOld and returnNew -//////////////////////////////////////////////////////////////////////////////// + //////////////////////////////////////////////////////////////////////////////// + /// @brief replace with and without returnOld and returnNew + //////////////////////////////////////////////////////////////////////////////// - testReplaceMultiReturnOldNew : function () { - var res = collection.insert({"Hallo":12}); - var res2 = collection.replace([res._key],[{"Hallo":13}]); + testReplaceMultiReturnOldNew: function() { + var res = collection.insert({ + "Hallo": 12 + }); + var res2 = collection.replace([res._key], [{ + "Hallo": 13 + }]); assertTypeOf("object", res2); assertTrue(Array.isArray(res2)); @@ -793,10 +998,16 @@ function CollectionDocumentSuiteReturnStuff () { assertTypeOf("string", res2[0]._rev); // Now with returnOld: true - res = collection.insert({"Hallo":12}); - res2 = collection.replace([res._key], [{"Hallo":13}], {returnOld: true}); + res = collection.insert({ + "Hallo": 12 + }); + res2 = collection.replace([res._key], [{ + "Hallo": 13 + }], { + returnOld: true + }); assertTrue(Array.isArray(res2)); - assertTypeOf("object", res2[0]); + assertEqual(1, res2.length); assertTypeOf("object", res2[0]); assertEqual(5, Object.keys(res2[0]).length); assertTypeOf("string", res2[0]._id); @@ -807,8 +1018,14 @@ function CollectionDocumentSuiteReturnStuff () { assertEqual(4, Object.keys(res2[0].old).length); // Now with returnOld: false - res = collection.insert({"Hallo":12}); - res2 = collection.replace([res._key], [{"Hallo":14}], {returnOld: false}); + res = collection.insert({ + "Hallo": 12 + }); + res2 = collection.replace([res._key], [{ + "Hallo": 14 + }], { + returnOld: false + }); assertTypeOf("object", res2); assertTrue(Array.isArray(res2)); assertTypeOf("object", res2[0]); @@ -818,8 +1035,14 @@ function CollectionDocumentSuiteReturnStuff () { assertTypeOf("string", res2[0]._rev); // Now with returnNew: true - res = collection.insert({"Hallo":12}); - res2 = collection.replace([res._key], [{"Hallo":14}], {returnNew: true}); + res = collection.insert({ + "Hallo": 12 + }); + res2 = collection.replace([res._key], [{ + "Hallo": 14 + }], { + returnNew: true + }); assertTypeOf("object", res2); assertTrue(Array.isArray(res2)); assertTypeOf("object", res2[0]); @@ -831,9 +1054,15 @@ function CollectionDocumentSuiteReturnStuff () { assertEqual(14, res2[0]["new"].Hallo); assertEqual(4, Object.keys(res2[0]["new"]).length); - // Now with returnOld: false - res = collection.insert({"Hallo":12}); - res2 = collection.replace([res._key], [{"Hallo":15}], {returnNew: false}); + // Now with returnNew: false + res = collection.insert({ + "Hallo": 12 + }); + res2 = collection.replace([res._key], [{ + "Hallo": 15 + }], { + returnNew: false + }); assertTypeOf("object", res2); assertTrue(Array.isArray(res2)); assertTypeOf("object", res2[0]); @@ -843,9 +1072,15 @@ function CollectionDocumentSuiteReturnStuff () { assertTypeOf("string", res2[0]._rev); // Now with returnNew: true and returnOld:true - res = collection.insert({"Hallo":12}); - res2 = collection.replace([res._key], [{"Hallo":16}], - {returnNew: true, returnOld: true}); + res = collection.insert({ + "Hallo": 12 + }); + res2 = collection.replace([res._key], [{ + "Hallo": 16 + }], { + returnNew: true, + returnOld: true + }); assertTypeOf("object", res2); assertTrue(Array.isArray(res2)); assertTypeOf("object", res2[0]); @@ -861,9 +1096,15 @@ function CollectionDocumentSuiteReturnStuff () { assertEqual(4, Object.keys(res2[0].old).length); // Now with returnOld: false and returnNew: false - res = collection.insert({"Hallo":12}); - res2 = collection.replace([res._key], [{"Hallo":15}], - {returnNew: false, returnOld: false}); + res = collection.insert({ + "Hallo": 12 + }); + res2 = collection.replace([res._key], [{ + "Hallo": 15 + }], { + returnNew: false, + returnOld: false + }); assertTypeOf("object", res2); assertTrue(Array.isArray(res2)); assertTypeOf("object", res2[0]); @@ -873,13 +1114,17 @@ function CollectionDocumentSuiteReturnStuff () { assertTypeOf("string", res2[0]._rev); }, -//////////////////////////////////////////////////////////////////////////////// -/// @brief update with and without returnOld and returnNew -//////////////////////////////////////////////////////////////////////////////// + //////////////////////////////////////////////////////////////////////////////// + /// @brief update with and without returnOld and returnNew + //////////////////////////////////////////////////////////////////////////////// - testUpdateMultiReturnOldNew : function () { - var res = collection.insert({"Hallo":12}); - var res2 = collection.update([res._key],[{"Hallo":13}]); + testUpdateMultiReturnOldNew: function() { + var res = collection.insert({ + "Hallo": 12 + }); + var res2 = collection.update([res._key], [{ + "Hallo": 13 + }]); assertTypeOf("object", res2); assertTrue(Array.isArray(res2)); @@ -890,8 +1135,14 @@ function CollectionDocumentSuiteReturnStuff () { assertTypeOf("string", res2[0]._rev); // Now with returnOld: true - res = collection.insert({"Hallo":12}); - res2 = collection.update([res._key], [{"Hallo":13}], {returnOld: true}); + res = collection.insert({ + "Hallo": 12 + }); + res2 = collection.update([res._key], [{ + "Hallo": 13 + }], { + returnOld: true + }); assertTypeOf("object", res2); assertTrue(Array.isArray(res2)); assertTypeOf("object", res2[0]); @@ -904,8 +1155,14 @@ function CollectionDocumentSuiteReturnStuff () { assertEqual(4, Object.keys(res2[0].old).length); // Now with returnOld: false - res = collection.insert({"Hallo":12}); - res2 = collection.update([res._key], [{"Hallo":14}], {returnOld: false}); + res = collection.insert({ + "Hallo": 12 + }); + res2 = collection.update([res._key], [{ + "Hallo": 14 + }], { + returnOld: false + }); assertTypeOf("object", res2); assertTrue(Array.isArray(res2)); assertTypeOf("object", res2[0]); @@ -915,8 +1172,14 @@ function CollectionDocumentSuiteReturnStuff () { assertTypeOf("string", res2[0]._rev); // Now with returnNew: true - res = collection.insert({"Hallo":12}); - res2 = collection.update([res._key], [{"Hallo":14}], {returnNew: true}); + res = collection.insert({ + "Hallo": 12 + }); + res2 = collection.update([res._key], [{ + "Hallo": 14 + }], { + returnNew: true + }); assertTypeOf("object", res2); assertTrue(Array.isArray(res2)); assertTypeOf("object", res2[0]); @@ -929,8 +1192,14 @@ function CollectionDocumentSuiteReturnStuff () { assertEqual(4, Object.keys(res2[0]["new"]).length); // Now with returnOld: false - res = collection.insert({"Hallo":12}); - res2 = collection.update([res._key], [{"Hallo":15}], {returnNew: false}); + res = collection.insert({ + "Hallo": 12 + }); + res2 = collection.update([res._key], [{ + "Hallo": 15 + }], { + returnNew: false + }); assertTypeOf("object", res2); assertTrue(Array.isArray(res2)); assertTypeOf("object", res2[0]); @@ -940,9 +1209,15 @@ function CollectionDocumentSuiteReturnStuff () { assertTypeOf("string", res2[0]._rev); // Now with returnNew: true and returnOld:true - res = collection.insert({"Hallo":12}); - res2 = collection.update([res._key], [{"Hallo":16}], - {returnNew: true, returnOld: true}); + res = collection.insert({ + "Hallo": 12 + }); + res2 = collection.update([res._key], [{ + "Hallo": 16 + }], { + returnNew: true, + returnOld: true + }); assertTypeOf("object", res2); assertTrue(Array.isArray(res2)); assertTypeOf("object", res2[0]); @@ -958,9 +1233,15 @@ function CollectionDocumentSuiteReturnStuff () { assertEqual(4, Object.keys(res2[0].old).length); // Now with returnOld: false and returnNew: false - res = collection.insert({"Hallo":12}); - res2 = collection.update([res._key], [{"Hallo":15}], - {returnNew: false, returnOld: false}); + res = collection.insert({ + "Hallo": 12 + }); + res2 = collection.update([res._key], [{ + "Hallo": 15 + }], { + returnNew: false, + returnOld: false + }); assertTypeOf("object", res2); assertTrue(Array.isArray(res2)); assertTypeOf("object", res2[0]); @@ -969,7 +1250,6 @@ function CollectionDocumentSuiteReturnStuff () { assertTypeOf("string", res2[0]._key); assertTypeOf("string", res2[0]._rev); } - }; } diff --git a/js/server/tests/shell/shell-foxx-repository-spec.js b/js/server/tests/shell/shell-foxx-repository-spec.js index 61102d6630..d571669459 100644 --- a/js/server/tests/shell/shell-foxx-repository-spec.js +++ b/js/server/tests/shell/shell-foxx-repository-spec.js @@ -34,7 +34,6 @@ const sinon = require('sinon'); const FoxxRepository = require('@arangodb/foxx/repository').Repository; const FoxxModel = require('@arangodb/foxx/model').Model; - describe('Repository', function () { const prefix = 'myApp'; let collection;