From 31c525cb388b61fe90b8c122c5083975e93d7458 Mon Sep 17 00:00:00 2001 From: Petra Selmer Date: Thu, 24 Nov 2016 14:57:03 +0000 Subject: [PATCH 1/4] Added params and made format consistent for all queries --- test/v1/examples.test.js | 42 +++++++++++++++++++++++----------------- 1 file changed, 24 insertions(+), 18 deletions(-) diff --git a/test/v1/examples.test.js b/test/v1/examples.test.js index 07a02635e..8650a509b 100644 --- a/test/v1/examples.test.js +++ b/test/v1/examples.test.js @@ -62,10 +62,11 @@ describe('examples', function() { var driver = neo4j.driver("bolt://localhost", neo4j.auth.basic("neo4j", "neo4j")); var session = driver.session(); session - .run( "CREATE (a:Person {name:'Arthur', title:'King'})" ) + .run( "CREATE (a:Person {name: {name}, title: {title}})", {"name": "Arthur", "title": "King"}) .then( function() { - return session.run( "MATCH (a:Person) WHERE a.name = 'Arthur' RETURN a.name AS name, a.title AS title" ) + return session.run( "MATCH (a:Person) WHERE a.name = {name} RETURN a.name AS name, a.title AS title", + {"name": "Arthur"}) }) .then( function( result ) { console.log( result.records[0].get("title") + " " + result.records[0].get("name") ); @@ -86,7 +87,7 @@ describe('examples', function() { //end::configuration[] var s = driver.session(); - s.run( "CREATE (p:Person { name: {name} })", {name: "The One"} ) + s.run( "CREATE (p:Person {name: {name}})", {"name": "The One"} ) .then( function(result) { var theOnesCreated = result.summary.counters.nodesCreated(); console.log(theOnesCreated); @@ -103,7 +104,7 @@ describe('examples', function() { var session = sessionGlobal; // tag::statement[] session - .run( "CREATE (person:Person {name: {name}})", {name: "Arthur"} ) + .run( "CREATE (person:Person {name: {name}})", {"name": "Arthur"} ) // end::statement[] .then( function(result) { var theOnesCreated = result.summary.counters.nodesCreated(); @@ -119,7 +120,7 @@ describe('examples', function() { var session = sessionGlobal; // tag::statement-without-parameters[] session - .run( "CREATE (p:Person { name: 'Arthur' })" ) + .run( "CREATE (p:Person {name: 'Arthur'})" ) // end::statement-without-parameters[] .then( function(result) { var theOnesCreated = result.summary.counters.nodesCreated(); @@ -136,12 +137,12 @@ describe('examples', function() { it('should be able to iterate results', function(done) { var session = sessionGlobal; session - .run( "CREATE (weapon:Weapon { name: 'Sword in the stone' })" ) + .run( "CREATE (weapon:Weapon {name: {name}})", {"name": "Sword in the stone"} ) .then(function() { // tag::result-traversal[] var searchTerm = "Sword"; session - .run( "MATCH (weapon:Weapon) WHERE weapon.name CONTAINS {term} RETURN weapon.name", {term : searchTerm} ) + .run( "MATCH (weapon:Weapon) WHERE weapon.name CONTAINS {term} RETURN weapon.name", {"term": searchTerm} ) .subscribe({ onNext: function(record) { console.log("" + record.get("weapon.name")); @@ -165,12 +166,14 @@ describe('examples', function() { it('should be able to access records', function(done) { var session = sessionGlobal; session - .run( "CREATE (weapon:Weapon { name: 'Sword in the stone', owner: 'Arthur', material: 'Stone', size: 'Huge' })" ) + .run( "CREATE (weapon:Weapon {name: {name}, owner: {owner}, material: {material}, size: {size}})", + {"name": "Sword in the stone", "owner": "Arthur", "material": "Stone", "size": "Huge"}) .then(function() { // tag::access-record[] var searchTerm = "Arthur"; session - .run( "MATCH (weapon:Weapon) WHERE weapon.owner CONTAINS {term} RETURN weapon.name, weapon.material, weapon.size", {term : searchTerm} ) + .run( "MATCH (weapon:Weapon) WHERE weapon.owner CONTAINS {term} RETURN weapon.name, weapon.material, weapon.size", + {"term": searchTerm} ) .subscribe({ onNext: function(record) { var sword = []; @@ -201,11 +204,12 @@ describe('examples', function() { var session = sessionGlobal; session - .run("CREATE (knight:Person:Knight { name: 'Lancelot', castle: 'Camelot' })") + .run("CREATE (knight:Person:Knight {name: {name}, castle: {castle}})", {"name": "Lancelot", "castle": "Camelot"}) .then(function() { // tag::retain-result[] session - .run("MATCH (knight:Person:Knight) WHERE knight.castle = {castle} RETURN knight.name AS name", {castle: "Camelot"}) + .run("MATCH (knight:Person:Knight) WHERE knight.castle = {castle} RETURN knight.name AS name", + {"castle": "Camelot"}) .then(function (result) { var records = []; for (i = 0; i < result.records.length; i++) { @@ -232,12 +236,14 @@ describe('examples', function() { it('should be able to do nested queries', function(done) { var session = sessionGlobal; session - .run( "CREATE (knight:Person:Knight { name: 'Lancelot', castle: 'Camelot' })" + - "CREATE (king:Person { name: 'Arthur', title: 'King' })" ) + .run( "CREATE (knight:Person:Knight {name: {name1}, castle: {castle}})" + + "CREATE (king:Person {name: {name2}, title: {title}})", + {"name1": "Lancelot", "castle": "Camelot", "name2": "Arthur", "title": "King"}) .then(function() { // tag::nested-statements[] session - .run("MATCH (knight:Person:Knight) WHERE knight.castle = {castle} RETURN id(knight) AS knight_id", {"castle": "Camelot"}) + .run("MATCH (knight:Person:Knight) WHERE knight.castle = {castle} RETURN id(knight) AS knight_id", + {"castle": "Camelot"}) .subscribe({ onNext: function(record) { session @@ -281,10 +287,10 @@ describe('examples', function() { it('should be able to profile', function(done) { var session = sessionGlobal; - session.run("CREATE (:Person {name:'Arthur'})").then(function() { + session.run("CREATE (:Person {name: {name}})", {"name": "Arthur"}).then(function() { // tag::result-summary-query-profile[] session - .run("PROFILE MATCH (p:Person {name: {name}}) RETURN id(p)", {name: "Arthur"}) + .run("PROFILE MATCH (p:Person {name: {name}}) RETURN id(p)", {"name": "Arthur"}) .then(function (result) { console.log(result.summary.profile); }); @@ -323,7 +329,7 @@ describe('examples', function() { // tag::transaction-commit[] var tx = session.beginTransaction(); - tx.run( "CREATE (:Person {name: 'Guinevere'})" ); + tx.run( "CREATE (:Person {name: {name}})", {"name": "Guinevere"} ); tx.commit(); // end::transaction-commit[] }); @@ -333,7 +339,7 @@ describe('examples', function() { // tag::transaction-rollback[] var tx = session.beginTransaction(); - tx.run( "CREATE (:Person {name: 'Merlin'})" ); + tx.run( "CREATE (:Person {name: {name}})", {"name": "Merlin"}); tx.rollback(); // end::transaction-rollback[] }); From 3ab0f147f2d5aa6bb0d4b06479cbc7a85ac0e6f1 Mon Sep 17 00:00:00 2001 From: Petra Selmer Date: Fri, 25 Nov 2016 10:13:31 +0000 Subject: [PATCH 2/4] Changed `localhost` -> `myserver:7687` in examples --- test/v1/examples.test.js | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/test/v1/examples.test.js b/test/v1/examples.test.js index 07a02635e..e579cc2f5 100644 --- a/test/v1/examples.test.js +++ b/test/v1/examples.test.js @@ -34,7 +34,7 @@ describe('examples', function() { beforeEach(function(done) { var neo4j = neo4jv1; //tag::construct-driver[] - driverGlobal = neo4j.driver("bolt://localhost", neo4j.auth.basic("neo4j", "neo4j")); + driverGlobal = neo4j.driver("bolt://myserver:7687", neo4j.auth.basic("neo4j", "neo4j")); //end::construct-driver[] sessionGlobal = driverGlobal.session(); @@ -59,13 +59,13 @@ describe('examples', function() { var neo4j = require('neo4j-driver').v1; // end::minimal-example-import[] // tag::minimal-example[] - var driver = neo4j.driver("bolt://localhost", neo4j.auth.basic("neo4j", "neo4j")); + var driver = neo4j.driver("bolt://myserver:7687", neo4j.auth.basic("neo4j", "neo4j")); var session = driver.session(); session .run( "CREATE (a:Person {name:'Arthur', title:'King'})" ) .then( function() { - return session.run( "MATCH (a:Person) WHERE a.name = 'Arthur' RETURN a.name AS name, a.title AS title" ) + return session.run( "MATCH (a:Person) WHERE a.name = 'Arthur' RETURN a.name AS name, a.title AS title" ) }) .then( function( result ) { console.log( result.records[0].get("title") + " " + result.records[0].get("name") ); @@ -82,7 +82,7 @@ describe('examples', function() { it('should be able to configure session pool size', function (done) { var neo4j = neo4jv1; // tag::configuration[] - var driver = neo4j.driver("bolt://localhost", neo4j.auth.basic("neo4j", "neo4j"), {connectionPoolSize: 50}); + var driver = neo4j.driver("bolt://myserver:7687", neo4j.auth.basic("neo4j", "neo4j"), {connectionPoolSize: 50}); //end::configuration[] var s = driver.session(); @@ -343,7 +343,7 @@ describe('examples', function() { var neo4j = neo4jv1; // tag::tls-require-encryption[] - var driver = neo4j.driver("bolt://localhost", neo4j.auth.basic("neo4j", "neo4j"), { + var driver = neo4j.driver("bolt://myserver:7687", neo4j.auth.basic("neo4j", "neo4j"), { // In NodeJS, encryption is on by default. In the web bundle, it is off. encrypted:true }); @@ -354,7 +354,7 @@ describe('examples', function() { it('should document how to configure trust-on-first-use', function() { var neo4j = neo4jv1; // tag::tls-trust-on-first-use[] - var driver = neo4j.driver("bolt://localhost", neo4j.auth.basic("neo4j", "neo4j"), { + var driver = neo4j.driver("bolt://myserver:7687", neo4j.auth.basic("neo4j", "neo4j"), { // Note that trust-on-first-use is not available in the browser bundle, // in NodeJS, trust-on-first-use is the default trust mode. In the browser // it is TRUST_CUSTOM_CA_SIGNED_CERTIFICATES. @@ -368,7 +368,7 @@ describe('examples', function() { it('should document how to configure a trusted signing certificate', function() { var neo4j = neo4jv1; // tag::tls-signed[] - var driver = neo4j.driver("bolt://localhost", neo4j.auth.basic("neo4j", "neo4j"), { + var driver = neo4j.driver("bolt://myserver:7687", neo4j.auth.basic("neo4j", "neo4j"), { trust: "TRUST_CUSTOM_CA_SIGNED_CERTIFICATES", // Configuring which certificates to trust here is only available // in NodeJS. In the browser bundle the browsers list of trusted @@ -383,7 +383,7 @@ describe('examples', function() { it('should document how to disable auth', function() { var neo4j = neo4jv1; // tag::connect-with-auth-disabled[] - var driver = neo4j.driver("bolt://localhost", { + var driver = neo4j.driver("bolt://myserver:7687", { // In NodeJS, encryption is on by default. In the web bundle, it is off. encrypted:true }); From 1d29f2b8896aec0b703f691bee14283cd9c276e7 Mon Sep 17 00:00:00 2001 From: Petra Selmer Date: Fri, 25 Nov 2016 11:35:07 +0000 Subject: [PATCH 3/4] `myserver` -> `localhost` in examples --- test/v1/examples.test.js | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/test/v1/examples.test.js b/test/v1/examples.test.js index e579cc2f5..7412aef99 100644 --- a/test/v1/examples.test.js +++ b/test/v1/examples.test.js @@ -34,7 +34,7 @@ describe('examples', function() { beforeEach(function(done) { var neo4j = neo4jv1; //tag::construct-driver[] - driverGlobal = neo4j.driver("bolt://myserver:7687", neo4j.auth.basic("neo4j", "neo4j")); + driverGlobal = neo4j.driver("bolt://localhost:7687", neo4j.auth.basic("neo4j", "neo4j")); //end::construct-driver[] sessionGlobal = driverGlobal.session(); @@ -59,7 +59,7 @@ describe('examples', function() { var neo4j = require('neo4j-driver').v1; // end::minimal-example-import[] // tag::minimal-example[] - var driver = neo4j.driver("bolt://myserver:7687", neo4j.auth.basic("neo4j", "neo4j")); + var driver = neo4j.driver("bolt://localhost:7687", neo4j.auth.basic("neo4j", "neo4j")); var session = driver.session(); session .run( "CREATE (a:Person {name:'Arthur', title:'King'})" ) @@ -82,7 +82,7 @@ describe('examples', function() { it('should be able to configure session pool size', function (done) { var neo4j = neo4jv1; // tag::configuration[] - var driver = neo4j.driver("bolt://myserver:7687", neo4j.auth.basic("neo4j", "neo4j"), {connectionPoolSize: 50}); + var driver = neo4j.driver("bolt://localhost:7687", neo4j.auth.basic("neo4j", "neo4j"), {connectionPoolSize: 50}); //end::configuration[] var s = driver.session(); @@ -343,7 +343,7 @@ describe('examples', function() { var neo4j = neo4jv1; // tag::tls-require-encryption[] - var driver = neo4j.driver("bolt://myserver:7687", neo4j.auth.basic("neo4j", "neo4j"), { + var driver = neo4j.driver("bolt://localhost:7687", neo4j.auth.basic("neo4j", "neo4j"), { // In NodeJS, encryption is on by default. In the web bundle, it is off. encrypted:true }); @@ -354,7 +354,7 @@ describe('examples', function() { it('should document how to configure trust-on-first-use', function() { var neo4j = neo4jv1; // tag::tls-trust-on-first-use[] - var driver = neo4j.driver("bolt://myserver:7687", neo4j.auth.basic("neo4j", "neo4j"), { + var driver = neo4j.driver("bolt://localhost:7687", neo4j.auth.basic("neo4j", "neo4j"), { // Note that trust-on-first-use is not available in the browser bundle, // in NodeJS, trust-on-first-use is the default trust mode. In the browser // it is TRUST_CUSTOM_CA_SIGNED_CERTIFICATES. @@ -368,7 +368,7 @@ describe('examples', function() { it('should document how to configure a trusted signing certificate', function() { var neo4j = neo4jv1; // tag::tls-signed[] - var driver = neo4j.driver("bolt://myserver:7687", neo4j.auth.basic("neo4j", "neo4j"), { + var driver = neo4j.driver("bolt://localhost:7687", neo4j.auth.basic("neo4j", "neo4j"), { trust: "TRUST_CUSTOM_CA_SIGNED_CERTIFICATES", // Configuring which certificates to trust here is only available // in NodeJS. In the browser bundle the browsers list of trusted @@ -383,7 +383,7 @@ describe('examples', function() { it('should document how to disable auth', function() { var neo4j = neo4jv1; // tag::connect-with-auth-disabled[] - var driver = neo4j.driver("bolt://myserver:7687", { + var driver = neo4j.driver("bolt://localhost:7687", { // In NodeJS, encryption is on by default. In the web bundle, it is off. encrypted:true }); From a9965f5abb09a3a58a6f73f6a5e82d94b942a320 Mon Sep 17 00:00:00 2001 From: Petra Selmer Date: Fri, 25 Nov 2016 15:00:51 +0000 Subject: [PATCH 4/4] Addressed Oskar's comments --- test/v1/examples.test.js | 34 +++++++++++++++++----------------- 1 file changed, 17 insertions(+), 17 deletions(-) diff --git a/test/v1/examples.test.js b/test/v1/examples.test.js index 8650a509b..b7afab644 100644 --- a/test/v1/examples.test.js +++ b/test/v1/examples.test.js @@ -62,11 +62,11 @@ describe('examples', function() { var driver = neo4j.driver("bolt://localhost", neo4j.auth.basic("neo4j", "neo4j")); var session = driver.session(); session - .run( "CREATE (a:Person {name: {name}, title: {title}})", {"name": "Arthur", "title": "King"}) + .run( "CREATE (a:Person {name: {name}, title: {title}})", {name: "Arthur", title: "King"}) .then( function() { return session.run( "MATCH (a:Person) WHERE a.name = {name} RETURN a.name AS name, a.title AS title", - {"name": "Arthur"}) + {name: "Arthur"}) }) .then( function( result ) { console.log( result.records[0].get("title") + " " + result.records[0].get("name") ); @@ -87,7 +87,7 @@ describe('examples', function() { //end::configuration[] var s = driver.session(); - s.run( "CREATE (p:Person {name: {name}})", {"name": "The One"} ) + s.run( "CREATE (p:Person {name: {name}})", {name: "The One"} ) .then( function(result) { var theOnesCreated = result.summary.counters.nodesCreated(); console.log(theOnesCreated); @@ -104,7 +104,7 @@ describe('examples', function() { var session = sessionGlobal; // tag::statement[] session - .run( "CREATE (person:Person {name: {name}})", {"name": "Arthur"} ) + .run( "CREATE (person:Person {name: {name}})", {name: "Arthur"} ) // end::statement[] .then( function(result) { var theOnesCreated = result.summary.counters.nodesCreated(); @@ -137,12 +137,12 @@ describe('examples', function() { it('should be able to iterate results', function(done) { var session = sessionGlobal; session - .run( "CREATE (weapon:Weapon {name: {name}})", {"name": "Sword in the stone"} ) + .run( "CREATE (weapon:Weapon {name: {name}})", {name: "Sword in the stone"} ) .then(function() { // tag::result-traversal[] var searchTerm = "Sword"; session - .run( "MATCH (weapon:Weapon) WHERE weapon.name CONTAINS {term} RETURN weapon.name", {"term": searchTerm} ) + .run( "MATCH (weapon:Weapon) WHERE weapon.name CONTAINS {term} RETURN weapon.name", {term: searchTerm} ) .subscribe({ onNext: function(record) { console.log("" + record.get("weapon.name")); @@ -167,13 +167,13 @@ describe('examples', function() { var session = sessionGlobal; session .run( "CREATE (weapon:Weapon {name: {name}, owner: {owner}, material: {material}, size: {size}})", - {"name": "Sword in the stone", "owner": "Arthur", "material": "Stone", "size": "Huge"}) + {name: "Sword in the stone", owner: "Arthur", material: "Stone", size: "Huge"}) .then(function() { // tag::access-record[] var searchTerm = "Arthur"; session .run( "MATCH (weapon:Weapon) WHERE weapon.owner CONTAINS {term} RETURN weapon.name, weapon.material, weapon.size", - {"term": searchTerm} ) + {term: searchTerm} ) .subscribe({ onNext: function(record) { var sword = []; @@ -204,12 +204,12 @@ describe('examples', function() { var session = sessionGlobal; session - .run("CREATE (knight:Person:Knight {name: {name}, castle: {castle}})", {"name": "Lancelot", "castle": "Camelot"}) + .run("CREATE (knight:Person:Knight {name: {name}, castle: {castle}})", {name: "Lancelot", castle: "Camelot"}) .then(function() { // tag::retain-result[] session .run("MATCH (knight:Person:Knight) WHERE knight.castle = {castle} RETURN knight.name AS name", - {"castle": "Camelot"}) + {castle: "Camelot"}) .then(function (result) { var records = []; for (i = 0; i < result.records.length; i++) { @@ -238,17 +238,17 @@ describe('examples', function() { session .run( "CREATE (knight:Person:Knight {name: {name1}, castle: {castle}})" + "CREATE (king:Person {name: {name2}, title: {title}})", - {"name1": "Lancelot", "castle": "Camelot", "name2": "Arthur", "title": "King"}) + {name1: "Lancelot", castle: "Camelot", name2: "Arthur", title: "King"}) .then(function() { // tag::nested-statements[] session .run("MATCH (knight:Person:Knight) WHERE knight.castle = {castle} RETURN id(knight) AS knight_id", - {"castle": "Camelot"}) + {castle: "Camelot"}) .subscribe({ onNext: function(record) { session .run("MATCH (knight) WHERE id(knight) = {id} MATCH (king:Person) WHERE king.name = {king} CREATE (knight)-[:DEFENDS]->(king)", - {"id": record.get("knight_id"), "king": "Arthur"}); + {id: record.get("knight_id"), king: "Arthur"}); }, onCompleted: function() { session @@ -287,10 +287,10 @@ describe('examples', function() { it('should be able to profile', function(done) { var session = sessionGlobal; - session.run("CREATE (:Person {name: {name}})", {"name": "Arthur"}).then(function() { + session.run("CREATE (:Person {name: {name}})", {name: "Arthur"}).then(function() { // tag::result-summary-query-profile[] session - .run("PROFILE MATCH (p:Person {name: {name}}) RETURN id(p)", {"name": "Arthur"}) + .run("PROFILE MATCH (p:Person {name: {name}}) RETURN id(p)", {name: "Arthur"}) .then(function (result) { console.log(result.summary.profile); }); @@ -329,7 +329,7 @@ describe('examples', function() { // tag::transaction-commit[] var tx = session.beginTransaction(); - tx.run( "CREATE (:Person {name: {name}})", {"name": "Guinevere"} ); + tx.run( "CREATE (:Person {name: {name}})", {name: "Guinevere"} ); tx.commit(); // end::transaction-commit[] }); @@ -339,7 +339,7 @@ describe('examples', function() { // tag::transaction-rollback[] var tx = session.beginTransaction(); - tx.run( "CREATE (:Person {name: {name}})", {"name": "Merlin"}); + tx.run( "CREATE (:Person {name: {name}})", {name: "Merlin"}); tx.rollback(); // end::transaction-rollback[] });