|
| 1 | +/** |
| 2 | + * Copyright (c) 2002-2015 "Neo Technology," |
| 3 | + * Network Engine for Objects in Lund AB [http://neotechnology.com] |
| 4 | + * |
| 5 | + * This file is part of Neo4j. |
| 6 | + * |
| 7 | + * Licensed under the Apache License, Version 2.0 (the "License"); |
| 8 | + * you may not use this file except in compliance with the License. |
| 9 | + * You may obtain a copy of the License at |
| 10 | + * |
| 11 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 12 | + * |
| 13 | + * Unless required by applicable law or agreed to in writing, software |
| 14 | + * distributed under the License is distributed on an "AS IS" BASIS, |
| 15 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 16 | + * See the License for the specific language governing permissions and |
| 17 | + * limitations under the License. |
| 18 | + */ |
| 19 | + |
| 20 | +var neo4j = require("../../lib/v1"); |
| 21 | + |
| 22 | +var _console = console; |
| 23 | + |
| 24 | +describe('transaction', function() { |
| 25 | + |
| 26 | + var driver, session, out, console; |
| 27 | + |
| 28 | + beforeEach(function(done) { |
| 29 | + driver = neo4j.driver("bolt://localhost"); |
| 30 | + session = driver.session(); |
| 31 | + |
| 32 | + // Override console.log, to assert on stdout output |
| 33 | + out = []; |
| 34 | + console = { log: function(msg) { out.push(msg); } }; |
| 35 | + |
| 36 | + session.run("MATCH (n) DETACH DELETE n").then(done); |
| 37 | + }); |
| 38 | + |
| 39 | + it('should document a minimum viable snippet', function(done) { |
| 40 | + // tag::minimum-snippet[] |
| 41 | + var driver = neo4j.driver("bolt://localhost"); |
| 42 | + var session = driver.session(); |
| 43 | + |
| 44 | + session.run( "CREATE (neo:Person {name:'Neo', age:23})" ); |
| 45 | + |
| 46 | + session |
| 47 | + .run( "MATCH (p:Person) WHERE p.name = 'Neo' RETURN p.age" ) |
| 48 | + .then( function( result ) { |
| 49 | + console.log( "Neo is " + result[0]["p.age"].toInt() + " years old." ); |
| 50 | + |
| 51 | + session.close(); |
| 52 | + driver.close(); |
| 53 | + done(); |
| 54 | + }); |
| 55 | + // end::minimum-snippet[] |
| 56 | + }); |
| 57 | + |
| 58 | + it('should document a statement', function(done) { |
| 59 | + var resultPromise = |
| 60 | + // tag::statement[] |
| 61 | + session |
| 62 | + .run( "CREATE (p:Person { name: {name} })", {"name": "The One"} ) |
| 63 | + .then( function(result) { |
| 64 | + var theOnesCreated = result.summary.updateStatistics.nodesCreated(); |
| 65 | + console.log("There were " + theOnesCreated + " the ones created.") |
| 66 | + }); |
| 67 | + // end::statement[] |
| 68 | + |
| 69 | + // Then |
| 70 | + resultPromise.then(function() { |
| 71 | + expect(out[0]).toBe("There were 1 the ones created."); |
| 72 | + done(); |
| 73 | + }); |
| 74 | + }); |
| 75 | + |
| 76 | + it('should document a statement without parameters', function(done) { |
| 77 | + var resultPromise = |
| 78 | + // tag::statement-without-parameters[] |
| 79 | + session |
| 80 | + .run( "CREATE (p:Person { name: 'The One' })" ) |
| 81 | + |
| 82 | + .then( function(result) { |
| 83 | + var theOnesCreated = result.summary.updateStatistics.nodesCreated(); |
| 84 | + console.log("There were " + theOnesCreated + " the ones created."); |
| 85 | + }); |
| 86 | + // end::statement-without-parameters[] |
| 87 | + |
| 88 | + // Then |
| 89 | + resultPromise.then(function() { |
| 90 | + expect(out[0]).toBe("There were 1 the ones created."); |
| 91 | + done(); |
| 92 | + }) |
| 93 | + }); |
| 94 | + |
| 95 | + it('should document committing a transaction', function() { |
| 96 | + // tag::transaction-commit[] |
| 97 | + var tx = session.beginTransaction(); |
| 98 | + tx.run( "CREATE (p:Person { name: 'The One' })" ); |
| 99 | + tx.commit(); |
| 100 | + // end::transaction-commit[] |
| 101 | + }); |
| 102 | + |
| 103 | + it('should document rolling back a transaction', function() { |
| 104 | + // tag::transaction-rollback[] |
| 105 | + var tx = session.beginTransaction(); |
| 106 | + tx.run( "CREATE (p:Person { name: 'The One' })" ); |
| 107 | + tx.rollback(); |
| 108 | + // end::transaction-rollback[] |
| 109 | + }); |
| 110 | + |
| 111 | + it('should document how to require encryption', function() { |
| 112 | + // tag::tls-require-encryption[] |
| 113 | + // Unfortunately, this feature is not yet implemented for JavaScript |
| 114 | + // end::tls-require-encryption[] |
| 115 | + }); |
| 116 | + |
| 117 | + it('should document how to configure trust-on-first-use', function() { |
| 118 | + // tag::tls-trust-on-first-use[] |
| 119 | + // Unfortunately, this feature is not yet implemented for JavaScript |
| 120 | + // end::tls-trust-on-first-use[] |
| 121 | + }); |
| 122 | + |
| 123 | + it('should document how to configure a trusted signing certificate', function() { |
| 124 | + // tag::tls-signed[] |
| 125 | + // Unfortunately, this feature is not yet implemented for JavaScript |
| 126 | + // end::tls-signed[] |
| 127 | + }); |
| 128 | + |
| 129 | +}); |
0 commit comments