diff --git a/js/common/modules/org/arangodb/general-graph.js b/js/common/modules/org/arangodb/general-graph.js index 238905aca2..348925a3dd 100644 --- a/js/common/modules/org/arangodb/general-graph.js +++ b/js/common/modules/org/arangodb/general-graph.js @@ -1,5 +1,5 @@ /*jslint indent: 2, nomen: true, maxlen: 100, sloppy: true, vars: true, white: true, plusplus: true */ -/*global require, exports */ +/*global require, exports, arguments */ //////////////////////////////////////////////////////////////////////////////// /// @brief Graph functionality @@ -46,8 +46,7 @@ var collection = require("org/arangodb/arango-collection"); var stringToArray = function (x) { - - if (typeof x === "String") { + if (typeof(x) === "string") { return [x]; } return x; @@ -60,14 +59,13 @@ var stringToArray = function (x) { var isValidCollectionsParameter = function (x) { - if (!x) { return false; } if (Array.isArray(x) && x.length === 0) { return false; } - if (typeof x !== "String" && !Array.isArray(x)) { + if (typeof(x) !== "string" && !Array.isArray(x)) { return false; } return true; @@ -90,7 +88,7 @@ var isValidCollectionsParameter = function (x) { var _undirectedRelationDefinition = function (relationName, vertexCollections) { - if (_undirectedRelationDefinition.arguments.length < 2) { + if (arguments.length < 2) { throw "method _undirectedRelationDefinition expects 2 arguments"; } @@ -115,9 +113,10 @@ var _undirectedRelationDefinition = function (relationName, vertexCollections) { //////////////////////////////////////////////////////////////////////////////// -var _directedRelationDefinition = function (relationName, fromVertexCollections, toVertexCollections) { +var _directedRelationDefinition = function ( + relationName, fromVertexCollections, toVertexCollections) { - if (_directedRelationDefinition.arguments.length < 3) { + if (arguments.length < 3) { throw "method _undirectedRelationDefinition expects 3 arguments"; } @@ -141,6 +140,19 @@ var _directedRelationDefinition = function (relationName, fromVertexCollections, }; +//////////////////////////////////////////////////////////////////////////////// +/// @brief create a list of edge definitions +//////////////////////////////////////////////////////////////////////////////// + + +var edgeDefinitions = function () { + + return arguments; + +}; + + + @@ -150,6 +162,7 @@ var _directedRelationDefinition = function (relationName, fromVertexCollections, exports._undirectedRelationDefinition = _undirectedRelationDefinition; exports._directedRelationDefinition = _directedRelationDefinition; +exports.edgeDefinitions = edgeDefinitions; diff --git a/js/common/tests/shell-general-graph.js b/js/common/tests/shell-general-graph.js index cb4a03ec98..55c3f84018 100644 --- a/js/common/tests/shell-general-graph.js +++ b/js/common/tests/shell-general-graph.js @@ -69,6 +69,24 @@ function GeneralGraphCreationSuite() { }, + test_undirectedRelationDefinitionWithSingleCollection : function () { + var r; + + try { + r = graph._undirectedRelationDefinition("relationName", "vertexC1"); + } + catch (err) { + console.log("aaaaa", err); + } + + assertEqual(r, { + collection: "relationName", + from: ["vertexC1"], + to: ["vertexC1"] + }); + + }, + test_undirectedRelationDefinitionWithMissingName : function () { var r, exception; try { @@ -177,6 +195,32 @@ function GeneralGraphCreationSuite() { assertEqual(exception, " must be a not empty string or array"); + }, + + testEdgeDefinitions : function () { + + + //with empty args + assertEqual(graph.edgeDefinitions(), []); + + //with args + assertEqual(graph.edgeDefinitions( + graph._undirectedRelationDefinition("relationName", "vertexC1"), + graph._directedRelationDefinition("relationName", + ["vertexC1", "vertexC2"], ["vertexC3", "vertexC4"]) + ), [ + { + collection: "relationName", + from: ["vertexC1"], + to: ["vertexC1"] + }, + { + collection: "relationName", + from: ["vertexC1", "vertexC2"], + to: ["vertexC3", "vertexC4"] + } + ]); + }