|
17 | 17 | * limitations under the License.
|
18 | 18 | */
|
19 | 19 |
|
20 |
| -var neo4j = require("../../lib/v1"); |
21 |
| -var sharedNeo4j = require("../internal/shared-neo4j").default; |
22 |
| - |
23 |
| -describe('floating point values', function() { |
24 |
| - it('should support float 1.0 ', testVal( 1 ) ); |
25 |
| - it('should support float 0.0 ', testVal( 0.0 ) ); |
26 |
| - it('should support pretty big float ', testVal( 3.4028235e+38 ) ); // Max 32-bit |
27 |
| - it('should support really big float ', testVal( 1.7976931348623157e+308 ) ); // Max 64-bit |
28 |
| - it('should support pretty small float ', testVal( 1.4e-45 ) ); // Min 32-bit |
29 |
| - it('should support really small float ', testVal( 4.9e-324 ) ); // Min 64-bit |
| 20 | +import neo4j from '../../src/v1'; |
| 21 | +import sharedNeo4j from '../internal/shared-neo4j'; |
| 22 | + |
| 23 | +describe('floating point values', () => { |
| 24 | + it('should support float 1.0 ', testValue(1)); |
| 25 | + it('should support float 0.0 ', testValue(0.0)); |
| 26 | + it('should support pretty big float ', testValue(3.4028235e+38)); // Max 32-bit |
| 27 | + it('should support really big float ', testValue(1.7976931348623157e+308)); // Max 64-bit |
| 28 | + it('should support pretty small float ', testValue(1.4e-45)); // Min 32-bit |
| 29 | + it('should support really small float ', testValue(4.9e-324)); // Min 64-bit |
30 | 30 | });
|
31 | 31 |
|
32 |
| -describe('integer values', function() { |
33 |
| - it('should support integer 1 ', testVal( neo4j.int(1) ) ); |
34 |
| - it('should support integer 0 ', testVal( neo4j.int(0) ) ); |
35 |
| - it('should support integer -1 ', testVal( neo4j.int(-1) ) ); |
36 |
| - it('should support integer larger than JS Numbers can model', testVal( neo4j.int("0x7fffffffffffffff") ) ); |
37 |
| - it('should support integer smaller than JS Numbers can model', testVal( neo4j.int("0x8000000000000000") ) ); |
| 32 | +describe('integer values', () => { |
| 33 | + it('should support integer 1 ', testValue(neo4j.int(1))); |
| 34 | + it('should support integer 0 ', testValue(neo4j.int(0))); |
| 35 | + it('should support integer -1 ', testValue(neo4j.int(-1))); |
| 36 | + it('should support integer larger than JS Numbers can model', testValue(neo4j.int('0x7fffffffffffffff'))); |
| 37 | + it('should support integer smaller than JS Numbers can model', testValue(neo4j.int('0x8000000000000000'))); |
38 | 38 | });
|
39 | 39 |
|
40 |
| -describe('boolean values', function() { |
41 |
| - it('should support true ', testVal( true ) ); |
42 |
| - it('should support false ', testVal( false ) ); |
| 40 | +describe('boolean values', () => { |
| 41 | + it('should support true ', testValue(true)); |
| 42 | + it('should support false ', testValue(false)); |
43 | 43 | });
|
44 | 44 |
|
45 |
| -describe('string values', function() { |
46 |
| - it('should support empty string ', testVal( "" ) ); |
47 |
| - it('should support simple string ', testVal( "abcdefghijklmnopqrstuvwxyz" ) ); |
48 |
| - it('should support awesome string ', testVal( "All makt åt Tengil, vår befriare." ) ); |
| 45 | +describe('string values', () => { |
| 46 | + it('should support empty string ', testValue('')); |
| 47 | + it('should support simple string ', testValue('abcdefghijklmnopqrstuvwxyz')); |
| 48 | + it('should support awesome string ', testValue('All makt åt Tengil, vår befriare.')); |
49 | 49 | });
|
50 | 50 |
|
51 |
| -describe('list values', function() { |
52 |
| - it('should support empty lists ', testVal( [] ) ); |
53 |
| - it('should support sparse lists ', testVal( [ undefined, 4 ], [ null, 4 ] ) ); |
54 |
| - it('should support float lists ', testVal( [ 1,2,3 ] ) ); |
55 |
| - it('should support boolean lists ', testVal( [ true, false ] ) ); |
56 |
| - it('should support string lists ', testVal( [ "", "hello!" ] ) ); |
57 |
| - it('should support list lists ', testVal( [ [], [1,2,3] ] ) ); |
58 |
| - it('should support map lists ', testVal( [ {}, {a:12} ] ) ); |
| 51 | +describe('list values', () => { |
| 52 | + it('should support empty lists ', testValue([])); |
| 53 | + it('should support sparse lists ', testValue([undefined, 4], [null, 4])); |
| 54 | + it('should support float lists ', testValue([1, 2, 3])); |
| 55 | + it('should support boolean lists ', testValue([true, false])); |
| 56 | + it('should support string lists ', testValue(['', 'hello!'])); |
| 57 | + it('should support list lists ', testValue([[], [1, 2, 3]])); |
| 58 | + it('should support map lists ', testValue([{}, {a: 12}])); |
59 | 59 | });
|
60 | 60 |
|
61 |
| -describe('map values', function() { |
62 |
| - it('should support empty maps ', testVal( {} ) ); |
63 |
| - it('should support basic maps ', testVal( {a:1, b:{}, c:[], d:{e:1}} ) ); |
64 |
| - it('should support sparse maps ', testVal( {foo: undefined, bar: null}, {bar: null} ) ); |
| 61 | +describe('map values', () => { |
| 62 | + it('should support empty maps ', testValue({})); |
| 63 | + it('should support basic maps ', testValue({a: 1, b: {}, c: [], d: {e: 1}})); |
| 64 | + it('should support sparse maps ', testValue({foo: undefined, bar: null}, {bar: null})); |
65 | 65 | });
|
66 | 66 |
|
67 |
| -describe('node values', function() { |
68 |
| - it('should support returning nodes ', function(done) { |
| 67 | +describe('node values', () => { |
| 68 | + it('should support returning nodes ', done => { |
69 | 69 | // Given
|
70 |
| - var driver = neo4j.driver("bolt://localhost", sharedNeo4j.authToken); |
71 |
| - var session = driver.session(); |
| 70 | + const driver = neo4j.driver('bolt://localhost', sharedNeo4j.authToken); |
| 71 | + const session = driver.session(); |
72 | 72 |
|
73 | 73 | // When
|
74 |
| - session.run("CREATE (n:User {name:'Lisa'}) RETURN n, id(n)").then(function(result) { |
75 |
| - var node = result.records[0].get('n'); |
| 74 | + session.run('CREATE (n:User {name:\'Lisa\'}) RETURN n, id(n)').then(result => { |
| 75 | + const node = result.records[0].get('n'); |
76 | 76 |
|
77 |
| - expect( node.properties ).toEqual( { name:"Lisa" } ); |
78 |
| - expect( node.labels ).toEqual( ["User"] ); |
79 |
| - // expect( node.identity ).toEqual( rs[0]['id(n)'] ); // TODO |
80 |
| - driver.close(); |
81 |
| - done(); |
| 77 | + expect(node.properties).toEqual({name: 'Lisa'}); |
| 78 | + expect(node.labels).toEqual(['User']); |
| 79 | + expect(node.identity).toEqual(result.records[0].get('id(n)')); |
| 80 | + driver.close(); |
| 81 | + done(); |
82 | 82 |
|
83 |
| - }); |
| 83 | + }); |
84 | 84 | });
|
85 | 85 | });
|
86 | 86 |
|
87 |
| -describe('relationship values', function() { |
88 |
| - it('should support returning relationships', function(done) { |
| 87 | +describe('relationship values', () => { |
| 88 | + it('should support returning relationships', done => { |
89 | 89 | // Given
|
90 |
| - var driver = neo4j.driver("bolt://localhost", sharedNeo4j.authToken); |
91 |
| - var session = driver.session(); |
| 90 | + const driver = neo4j.driver('bolt://localhost', sharedNeo4j.authToken); |
| 91 | + const session = driver.session(); |
92 | 92 |
|
93 | 93 | // When
|
94 |
| - session.run("CREATE ()-[r:User {name:'Lisa'}]->() RETURN r, id(r)").then(function(result) { |
95 |
| - var rel = result.records[0].get('r'); |
| 94 | + session.run('CREATE ()-[r:User {name:\'Lisa\'}]->() RETURN r, id(r)').then(result => { |
| 95 | + const rel = result.records[0].get('r'); |
96 | 96 |
|
97 |
| - expect( rel.properties ).toEqual( { name:"Lisa" } ); |
98 |
| - expect( rel.type ).toEqual( "User" ); |
99 |
| - // expect( rel.identity ).toEqual( rs[0]['id(r)'] ); // TODO |
100 |
| - driver.close(); |
101 |
| - done(); |
| 97 | + expect(rel.properties).toEqual({name: 'Lisa'}); |
| 98 | + expect(rel.type).toEqual('User'); |
| 99 | + expect(rel.identity).toEqual(result.records[0].get('id(r)')); |
| 100 | + driver.close(); |
| 101 | + done(); |
102 | 102 |
|
103 |
| - }); |
| 103 | + }); |
104 | 104 | });
|
105 | 105 | });
|
106 | 106 |
|
107 |
| -describe('path values', function() { |
108 |
| - it('should support returning paths', function(done) { |
| 107 | +describe('path values', () => { |
| 108 | + it('should support returning paths', done => { |
109 | 109 | // Given
|
110 |
| - var driver = neo4j.driver("bolt://localhost", sharedNeo4j.authToken); |
111 |
| - var session = driver.session(); |
| 110 | + const driver = neo4j.driver('bolt://localhost', sharedNeo4j.authToken); |
| 111 | + const session = driver.session(); |
112 | 112 |
|
113 | 113 | // When
|
114 |
| - session.run("CREATE p=(:User { name:'Lisa' })<-[r:KNOWS {since:1234.0}]-() RETURN p") |
115 |
| - .then(function(result) { |
116 |
| - var path = result.records[0].get('p'); |
| 114 | + session.run('CREATE p=(:User { name:\'Lisa\' })<-[r:KNOWS {since:1234.0}]-() RETURN p') |
| 115 | + .then(result => { |
| 116 | + const path = result.records[0].get('p'); |
117 | 117 |
|
118 |
| - expect( path.start.properties ).toEqual( { name:"Lisa" } ); |
119 |
| - expect( path.end.properties ).toEqual( { } ); |
| 118 | + expect(path.start.properties).toEqual({name: 'Lisa'}); |
| 119 | + expect(path.end.properties).toEqual({}); |
120 | 120 |
|
121 | 121 | // Accessing path segments
|
122 |
| - expect( path.length ).toEqual( 1 ); |
123 |
| - for (var i = 0; i < path.length; i++) { |
124 |
| - var segment = path.segments[i]; |
| 122 | + expect(path.length).toEqual(1); |
| 123 | + for (let i = 0; i < path.length; i++) { |
| 124 | + const segment = path.segments[i]; |
125 | 125 | // The direction of the path segment goes from lisa to the blank node
|
126 |
| - expect( segment.start.properties ).toEqual( { name:"Lisa" } ); |
127 |
| - expect( segment.end.properties ).toEqual( { } ); |
| 126 | + expect(segment.start.properties).toEqual({name: 'Lisa'}); |
| 127 | + expect(segment.end.properties).toEqual({}); |
128 | 128 | // Which is the inverse of the relationship itself!
|
129 |
| - expect( segment.relationship.properties ).toEqual( { since: 1234 } ); |
| 129 | + expect(segment.relationship.properties).toEqual({since: 1234}); |
130 | 130 | }
|
131 | 131 | driver.close();
|
132 | 132 | done();
|
133 |
| - }).catch(function(err) { console.log(err); }); |
| 133 | + }).catch(err => { |
| 134 | + console.log(err); |
| 135 | + }); |
134 | 136 | });
|
135 | 137 | });
|
136 | 138 |
|
137 |
| -function testVal( val, expected ) { |
138 |
| - return function( done ) { |
139 |
| - var driver = neo4j.driver("bolt://localhost", sharedNeo4j.authToken); |
140 |
| - var session = driver.session(); |
| 139 | +function testValue(actual, expected) { |
| 140 | + return done => { |
| 141 | + const driver = neo4j.driver('bolt://localhost', sharedNeo4j.authToken); |
| 142 | + const session = driver.session(); |
141 | 143 |
|
142 |
| - session.run("RETURN {val} as v", {val: val}) |
143 |
| - .then( function( result ) { |
144 |
| - expect( result.records[0].get('v') ).toEqual( expected || val ); |
| 144 | + session.run('RETURN {val} as v', {val: actual}) |
| 145 | + .then(result => { |
| 146 | + expect(result.records[0].get('v')).toEqual(expected || actual); |
145 | 147 | driver.close();
|
146 | 148 | done();
|
147 |
| - }).catch(function(err) { console.log(err); }); |
148 |
| - } |
| 149 | + }).catch(err => { |
| 150 | + console.log(err); |
| 151 | + }); |
| 152 | + }; |
149 | 153 | }
|
0 commit comments