diff --git a/js/client/modules/@arangodb/testsuites/aql.js b/js/client/modules/@arangodb/testsuites/aql.js index 7d0884b5b2..6c05606c6e 100644 --- a/js/client/modules/@arangodb/testsuites/aql.js +++ b/js/client/modules/@arangodb/testsuites/aql.js @@ -45,6 +45,7 @@ const tu = require('@arangodb/test-utils'); function shellClient (options) { let testCases = tu.scanTestPath('js/common/tests/shell'); + testCases = testCases.concat(tu.scanTestPath('js/client/tests/http')); testCases = testCases.concat(tu.scanTestPath('js/client/tests/shell')); return tu.performTests(options, testCases, 'shell_client', tu.runInArangosh); diff --git a/js/client/tests/http/api-gharial-spec.js b/js/client/tests/http/api-gharial-spec.js new file mode 100644 index 0000000000..341048b6d2 --- /dev/null +++ b/js/client/tests/http/api-gharial-spec.js @@ -0,0 +1,135 @@ +/* jshint globalstrict:false, strict:false, maxlen: 5000 */ +/* global describe, beforeEach, afterEach, it */ +'use strict'; + +// ////////////////////////////////////////////////////////////////////////////// +// / DISCLAIMER +// / +// / Copyright 2016 ArangoDB GmbH, Cologne, Germany +// / +// / Licensed under the Apache License, Version 2.0 (the "License") +// / you may not use this file except in compliance with the License. +// / You may obtain a copy of the License at +// / +// / http://www.apache.org/licenses/LICENSE-2.0 +// / +// / Unless required by applicable law or agreed to in writing, software +// / distributed under the License is distributed on an "AS IS" BASIS, +// / WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// / See the License for the specific language governing permissions and +// / limitations under the License. +// / +// / Copyright holder is ArangoDB GmbH, Cologne, Germany +// / +// / @author Michael Hackstein +// ////////////////////////////////////////////////////////////////////////////// + +const expect = require('chai').expect; + +const arangodb = require('@arangodb'); +const request = require('@arangodb/request'); + +const ERRORS = arangodb.errors; +const db = arangodb.db; +const wait = require('internal').wait; +const extend = require('lodash').extend; + +describe('_api/gharial', () => { + + const graphName = 'UnitTestGraph'; + const vColName = 'UnitTestVertices'; + const eColName = 'UnitTestRelations'; + const oColName = 'UnitTestOrphans'; + const oColName2 = 'UnitTestOrphansSecond'; + const url = '/_api/gharial'; + + const cleanup = () => { + try { + db._drop(vColName); + } catch (e) { + } + try { + db._drop(eColName); + } catch (e) { + } + try { + db._drop(oColName); + } catch (e) { + } + try { + db._graphs.remove(graphName); + } catch (e) { + } + }; + + beforeEach(cleanup); + + afterEach(cleanup); + + + it('should create a graph without orphans', () => { + const graphDef = { + "name": graphName, + "edgeDefinitions": [{ + "collection": eColName, + "from": [vColName], + "to": [vColName] + } + ], + "isSmart": false + }; + expect(db._collection(eColName)).to.be.null; + expect(db._collection(vColName)).to.be.null; + let req = request.post(url, { + body: JSON.stringify(graphDef) + }); + expect(req.statusCode).to.equal(202); + + // This is all async give it some time + do { + wait(0.1); + req = request.get(url + "/" + graphName); + } while (req.statusCode != 200); + + expect(db._collection(eColName)).to.not.be.null; + expect(db._collection(vColName)).to.not.be.null; + }); + + it('should create a graph with orphans', () => { + const graphDef = { + "name": graphName, + "edgeDefinitions": [{ + "collection": eColName, + "from": [vColName], + "to": [vColName] + } + ], + "orphanCollections": [ + oColName, + oColName2 + ], + "isSmart": false + }; + expect(db._collection(eColName)).to.be.null; + expect(db._collection(vColName)).to.be.null; + expect(db._collection(oColName)).to.be.null; + expect(db._collection(oColName2)).to.be.null; + let req = request.post(url, { + body: JSON.stringify(graphDef) + }); + expect(req.statusCode).to.equal(202); + + // This is all async give it some time + do { + wait(0.1); + req = request.get(url + "/" + graphName); + } while (req.statusCode != 200); + + expect(db._collection(eColName)).to.not.be.null; + expect(db._collection(vColName)).to.not.be.null; + expect(db._collection(oColName)).to.not.be.null; + expect(db._collection(oColName2)).to.not.be.null; + }); + + +}); diff --git a/js/common/modules/@arangodb/general-graph.js b/js/common/modules/@arangodb/general-graph.js index 89e935eb18..352c0d5e9c 100644 --- a/js/common/modules/@arangodb/general-graph.js +++ b/js/common/modules/@arangodb/general-graph.js @@ -2049,7 +2049,7 @@ exports._create = function (graphName, edgeDefinitions, orphanCollections, optio db._flushCache(); let collections = findOrCreateCollectionsByEdgeDefinitions(edgeDefinitions, false, options); orphanCollections.forEach( - (oC, options) => { + (oC) => { findOrCreateCollectionByName(oC, ArangoCollection.TYPE_DOCUMENT, false, options); } );