Skip to content

Commit 021e9a5

Browse files
committed
Move types test to ES6
1 parent 4578c2d commit 021e9a5

File tree

1 file changed

+88
-84
lines changed

1 file changed

+88
-84
lines changed

test/v1/types.test.js

Lines changed: 88 additions & 84 deletions
Original file line numberDiff line numberDiff line change
@@ -17,133 +17,137 @@
1717
* limitations under the License.
1818
*/
1919

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
3030
});
3131

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')));
3838
});
3939

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));
4343
});
4444

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.'));
4949
});
5050

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}]));
5959
});
6060

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}));
6565
});
6666

67-
describe('node values', function() {
68-
it('should support returning nodes ', function(done) {
67+
describe('node values', () => {
68+
it('should support returning nodes ', done => {
6969
// 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();
7272

7373
// 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');
7676

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();
8282

83-
});
83+
});
8484
});
8585
});
8686

87-
describe('relationship values', function() {
88-
it('should support returning relationships', function(done) {
87+
describe('relationship values', () => {
88+
it('should support returning relationships', done => {
8989
// 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();
9292

9393
// 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');
9696

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();
102102

103-
});
103+
});
104104
});
105105
});
106106

107-
describe('path values', function() {
108-
it('should support returning paths', function(done) {
107+
describe('path values', () => {
108+
it('should support returning paths', done => {
109109
// 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();
112112

113113
// 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');
117117

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({});
120120

121121
// 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];
125125
// 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({});
128128
// Which is the inverse of the relationship itself!
129-
expect( segment.relationship.properties ).toEqual( { since: 1234 } );
129+
expect(segment.relationship.properties).toEqual({since: 1234});
130130
}
131131
driver.close();
132132
done();
133-
}).catch(function(err) { console.log(err); });
133+
}).catch(err => {
134+
console.log(err);
135+
});
134136
});
135137
});
136138

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();
141143

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);
145147
driver.close();
146148
done();
147-
}).catch(function(err) { console.log(err); });
148-
}
149+
}).catch(err => {
150+
console.log(err);
151+
});
152+
};
149153
}

0 commit comments

Comments
 (0)