Skip to content

Commit e5518f0

Browse files
committed
Added more tests.
1 parent fb97f7d commit e5518f0

File tree

5 files changed

+156
-8
lines changed

5 files changed

+156
-8
lines changed

lib/database.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ extend(Database.prototype, {
9191
var self = this;
9292
self._api.get('gharial/' + graphName, function (err, body) {
9393
if (err) {
94-
if (!autoCreate || err.name !== 'ArangoError' || err.errorNum !== 1203) callback(err);
94+
if (!autoCreate || err.name !== 'ArangoError' || err.errorNum !== 1924) callback(err);
9595
else self.createGraph({name: graphName}, callback);
9696
}
9797
else callback(null, new Graph(self._connection, body.graph));

lib/graph.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@ module.exports = Graph;
1111
function Graph(connection, body) {
1212
this._connection = connection;
1313
this._api = this._connection.endpoint('_api');
14-
this._gharial = this._api.endpoint('gharial/' + this.name);
1514
extend(this, body);
15+
this._gharial = this._api.endpoint('gharial/' + this.name);
1616
}
1717

1818
Graph.VertexCollection = VertexCollection;

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@
4848
},
4949
"homepage": "https://github.com/arangodb/arangodbjs",
5050
"devDependencies": {
51+
"async": "^0.9.0",
5152
"browserify": "^7.0.2",
5253
"coveralls": "^2.11.2",
5354
"dekeywordify": "^0.2.0",

test/database-collections.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,8 +71,8 @@ describe('database', function () {
7171
});
7272
});
7373
});
74-
it('returns an ArangoError if the db does not exist', function (done) {
75-
db.collection('this_db_does_not_exist', false, function (err, collection) {
74+
it('returns an ArangoError if the collection does not exist', function (done) {
75+
db.collection('this_does_not_exist', false, function (err, collection) {
7676
expect(err).to.be.an(ArangoError);
7777
expect(collection).not.to.be.ok();
7878
done();

test/database-graphs.js

Lines changed: 151 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,160 @@
11
/*jshint node: true */
2-
/*globals describe, it */
2+
/*globals describe, it, before, after, beforeEach */
33
'use strict';
4+
var expect = require('expect.js');
5+
var async = require('async');
6+
var Database = require('../');
7+
var Graph = require('../lib/graph');
8+
var ArangoError = require('../lib/error');
9+
var db = new Database();
10+
var testVertexCollectionName1 = 'test__vertices_1';
11+
var testVertexCollectionName2 = 'test__vertices_2';
12+
var testEdgeCollectionName1 = 'test__edges_1';
13+
var testEdgeCollectionName2 = 'test__edges_2';
14+
var testEdgeCollectionName3 = 'test__edges_3';
15+
var testDbName = 'test__database_graphs_1';
16+
var testGraphName = 'test__graph_1';
17+
18+
function mcall(name) {
19+
return function (obj, cb) {
20+
obj[name](cb);
21+
};
22+
}
423

524
describe('database', function () {
6-
describe('createGraph', function () {
7-
it('is missing tests');
25+
var edgeCollection1, edgeCollection2, edgeCollection3;
26+
var vertexCollection1, vertexCollection2;
27+
var _db;
28+
before(function (done) {
29+
db.database(testDbName, true, function (err1, database) {
30+
_db = db;
31+
db = database;
32+
async.map([
33+
{name: testVertexCollectionName1, type: 2},
34+
{name: testVertexCollectionName2, type: 2},
35+
{name: testEdgeCollectionName1, type: 3},
36+
{name: testEdgeCollectionName2, type: 3},
37+
{name: testEdgeCollectionName3, type: 3}
38+
], db.createCollection.bind(db), function (err, results) {
39+
if (err) return done(err);
40+
vertexCollection1 = results[0];
41+
vertexCollection2 = results[1];
42+
edgeCollection1 = results[2];
43+
edgeCollection2 = results[3];
44+
edgeCollection3 = results[4];
45+
done();
46+
});
47+
});
48+
});
49+
after(function (done) {
50+
_db.dropDatabase(testDbName, function (err) {
51+
db = _db;
52+
done(err);
53+
});
54+
});
55+
beforeEach(function (done) {
56+
async.map([
57+
vertexCollection1,
58+
vertexCollection2,
59+
edgeCollection1,
60+
edgeCollection2,
61+
edgeCollection3
62+
], mcall('truncate'), function (err) {
63+
db.dropGraph(testGraphName, function () {
64+
done(err);
65+
});
66+
});
67+
});
68+
describe('createGraph', function (done) {
69+
it('returns a new graph object with the given name', function (done) {
70+
db.createGraph({name: testGraphName}, function (err, graph) {
71+
expect(err).not.to.be.ok();
72+
expect(graph).to.be.ok();
73+
expect(graph).to.be.a(Graph);
74+
expect(graph.name).to.equal(testGraphName);
75+
done();
76+
});
77+
});
78+
it('creates a new graph with the given name', function (done) {
79+
db.createGraph({name: testGraphName}, function (err) {
80+
expect(err).not.to.be.ok();
81+
db.graph(testGraphName, false, function (err2, graph) {
82+
expect(err2).not.to.be.ok();
83+
expect(graph.name).to.equal(testGraphName);
84+
done();
85+
});
86+
});
87+
});
88+
it('creates a new graph with the given edge defs', function (done) {
89+
var edgeDefs = [
90+
{
91+
collection: testEdgeCollectionName1,
92+
from: [testVertexCollectionName1],
93+
to: [testVertexCollectionName2]
94+
},
95+
{
96+
collection: testEdgeCollectionName2,
97+
from: [testVertexCollectionName2],
98+
to: [testVertexCollectionName1]
99+
},
100+
{
101+
collection: testEdgeCollectionName3,
102+
from: [testVertexCollectionName1, testVertexCollectionName2],
103+
to: [testVertexCollectionName1, testVertexCollectionName2]
104+
}
105+
];
106+
db.createGraph({
107+
name: testGraphName,
108+
edgeDefinitions: edgeDefs
109+
}, function (err) {
110+
expect(err).not.to.be.ok();
111+
db.graph(testGraphName, false, function (err2, graph) {
112+
expect(err2).not.to.be.ok();
113+
expect(graph.edgeDefinitions).to.eql(edgeDefs);
114+
done();
115+
});
116+
});
117+
});
8118
});
9119
describe('graph', function () {
10-
it('is missing tests');
120+
describe('with autoCreate:false', function () {
121+
it('returns the graph if it exists', function (done) {
122+
db.createGraph({name: testGraphName}, function (err) {
123+
expect(err).not.to.be.ok();
124+
db.graph(testGraphName, false, function (err2, graph) {
125+
expect(err2).not.to.be.ok();
126+
expect(graph.name).to.equal(testGraphName);
127+
done();
128+
});
129+
});
130+
});
131+
it('returns an ArangoError if the graph does not exist', function (done) {
132+
db.graph('this_does_not_exist', false, function (err, graph) {
133+
expect(err).to.be.an(ArangoError);
134+
expect(graph).not.to.be.ok();
135+
done();
136+
});
137+
});
138+
});
139+
describe('with autoCreate:true', function () {
140+
it('returns the graph if it exists', function (done) {
141+
db.createGraph({name: testGraphName}, function (err) {
142+
expect(err).not.to.be.ok();
143+
db.graph(testGraphName, false, function (err2, graph) {
144+
expect(err2).not.to.be.ok();
145+
expect(graph.name).to.equal(testGraphName);
146+
done();
147+
});
148+
});
149+
});
150+
it('creates the graph if it does not exist', function (done) {
151+
db.graph(testGraphName, true, function (err, graph) {
152+
expect(err).not.to.be.ok();
153+
expect(graph.name).to.equal(testGraphName);
154+
done();
155+
});
156+
});
157+
});
11158
});
12159
describe('graphs', function () {
13160
it('is missing tests');

0 commit comments

Comments
 (0)