Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

added tests and the implementation for the UpdateRelationship function

  • Loading branch information...
commit 75ea7d2c60f9413e1a5a312422cd5b971eb869e3 1 parent 76c402c
@philippkueng authored
Showing with 84 additions and 1 deletion.
  1. +23 −0 main.js
  2. +61 −1 test/test.main.js
View
23 main.js
@@ -173,6 +173,29 @@ Neo4j.prototype.ReadRelationship = function(relationship_id, callback){
});
};
+/* Update a Relationship -------- */
+
+Neo4j.prototype.UpdateRelationship = function(relationship_id, relationship_data, callback){
+ var that = this;
+
+ request
+ .put(that.url + '/db/data/relationship/' + relationship_id + '/properties')
+ .send(that.StringifyValueObjects(that.ReplaceNullWithString(relationship_data)))
+ .set('Accept', 'application/json')
+ .end(function(result){
+ switch(result.statusCode){
+ case 204:
+ callback(null, true);
+ break;
+ case 404:
+ callback(null, false);
+ break;
+ default:
+ callback(new Error('HTTP Error ' + result.statusCode + ' when updating a Relationship.'), null);
+ }
+ });
+};
+
/* HELPER METHODS --------- */
View
62 test/test.main.js
@@ -352,10 +352,70 @@ describe('Testing Node specific operations for Neo4j', function(){
});
});
+ describe('=> Update a Relationship', function(){
+
+ var test_obj = {
+ importance: 'high',
+ age: null,
+ description: {
+ positive: 'fullfilling',
+ negative: 'too time consuming'
+ }
+ };
+
+ describe('-> Update a non-existing Relationship', function(){
+ it('should return false', function(done){
+ db.UpdateRelationship(99999999, test_obj, function(err, result){
+ should.not.exist(err);
+ result.should.equal(false);
+ done();
+ });
+ });
+ });
+
+ var root_node_id;
+ var other_node_id;
+ var relationship_id;
+
+ before(function(done){
+ db.InsertNode({name:'foobar'}, function(err, node1){
+ root_node_id = node1.id;
+ db.InsertNode({name:'foobar2'}, function(err, node2){
+ other_node_id = node2.id;
+ db.InsertRelationship(root_node_id, other_node_id, 'RELATED_TO', function(err, relationship){
+ relationship_id = relationship.id;
+ done();
+ });
+ });
+ });
+ });
+
+ describe('-> Update an existing Relationship', function(){
+ it('should return relationship data', function(done){
+ db.UpdateRelationship(relationship_id, test_obj, function(err, result){
+ should.not.exist(err);
+ result.should.equal(true);
+ done();
+ });
+ });
+ });
+
+ after(function(done){
+ db.DeleteRelationship(relationship_id, function(err, result){
+ db.DeleteNode(other_node_id, function(err, result){
+ db.DeleteNode(root_node_id, function(err, result){
+ done();
+ });
+ });
+ });
+ });
+ });
+
describe('=> Testing ReplaceNullWithString', function(){
var test_obj = {
name: 'foobar',
- age: null
+ age: null,
+
};
describe('-> Testing a small object', function(){
Please sign in to comment.
Something went wrong with that request. Please try again.