Skip to content

Commit 7af13b7

Browse files
committed
Parameter map in summary never undefined
To be compilant with the other drivers `summary.parameters` should return `{}` instead of `undefined` when statement has been run with no paramaters.
1 parent 4a82ae2 commit 7af13b7

File tree

3 files changed

+25
-11
lines changed

3 files changed

+25
-11
lines changed

src/v1/result-summary.js

+4-4
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ class ProfiledPlan {
8989
/**
9090
* Create a ProfiledPlan instance
9191
* @constructor
92-
* @param {Object} plan - Object with plan data
92+
* @param {Object} profile - Object with profile data
9393
*/
9494
constructor(profile) {
9595
this.operatorType = profile.operatorType;
@@ -235,10 +235,10 @@ class Notification {
235235
this.title = notification.title;
236236
this.description = notification.description;
237237
this.severity = notification.severity;
238-
this.position = this._constructPosition(notification.position);
238+
this.position = Notification._constructPosition(notification.position);
239239
}
240240

241-
_constructPosition(pos) {
241+
static _constructPosition(pos) {
242242
if(!pos) {
243243
return {};
244244
}
@@ -255,7 +255,7 @@ const statementType = {
255255
READ_WRITE: 'rw',
256256
WRITE_ONLY: 'w',
257257
SCHEMA_WRITE: 's'
258-
}
258+
};
259259

260260
export default {
261261
ResultSummary,

src/v1/result.js

+6-3
Original file line numberDiff line numberDiff line change
@@ -32,12 +32,14 @@ class Result {
3232
* Inject the observer to be used.
3333
* @constructor
3434
* @param {StreamObserver} streamObserver
35+
* @param {mixed} statement - Cypher statement to execute
36+
* @param {Object} parameters - Map with parameters to use in statement
3537
*/
3638
constructor(streamObserver, statement, parameters) {
3739
this._streamObserver = streamObserver;
3840
this._p = null;
3941
this._statement = statement;
40-
this._parameters = parameters;
42+
this._parameters = parameters || {};
4143
}
4244

4345
/**
@@ -66,7 +68,8 @@ class Result {
6668
* Waits for all results and calls the passed in function
6769
* with the results.
6870
* Cannot be used with the subscribe function.
69-
* @param {function(results: Object)} cb - Function to be called when all results are collected.
71+
* @param {function(error: Object)} onFulfilled - Function to be called when finished.
72+
* @param {function(error: Object)} onRejected - Function to be called upon errors.
7073
* @return {Promise} promise.
7174
*/
7275
then(onFulfilled, onRejected) {
@@ -78,7 +81,7 @@ class Result {
7881
/**
7982
* Catch errors when using promises.
8083
* Cannot be used with the subscribe function.
81-
* @param {function(error: Object)} cb - Function to be called upon errors.
84+
* @param {function(error: Object)} onRejected - Function to be called upon errors.
8285
* @return {Promise} promise.
8386
*/
8487
catch(onRejected) {

test/v1/session.test.js

+15-4
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,6 @@ describe('session', function() {
7575
it('should call observers onError on error ', function(done) {
7676

7777
// When & Then
78-
var records = [];
7978
session.run( "RETURN 1 AS").subscribe( {
8079
onError: function(error) {
8180
expect(error.fields.length).toBe(1);
@@ -131,7 +130,7 @@ describe('session', function() {
131130
it('should expose summarize method for basic metadata ', function(done) {
132131
// Given
133132
var statement = "CREATE (n:Label {prop:{prop}}) RETURN n";
134-
var params = {prop: "string"}
133+
var params = {prop: "string"};
135134
// When & Then
136135
session.run( statement, params )
137136
.then(function(result) {
@@ -145,10 +144,22 @@ describe('session', function() {
145144
});
146145
});
147146

147+
it('should expose empty parameter map on call with no parameters', function(done) {
148+
// Given
149+
var statement = "CREATE (n:Label {prop:'string'}) RETURN n";
150+
// When & Then
151+
session.run(statement)
152+
.then(function(result) {
153+
var sum = result.summary;
154+
expect(sum.statement.parameters).toEqual( {} );
155+
done();
156+
});
157+
});
158+
148159
it('should expose plan ', function(done) {
149160
// Given
150161
var statement = "EXPLAIN CREATE (n:Label {prop:{prop}}) RETURN n";
151-
var params = {prop: "string"}
162+
var params = {prop: "string"};
152163
// When & Then
153164
session
154165
.run( statement, params )
@@ -167,7 +178,7 @@ describe('session', function() {
167178
it('should expose profile ', function(done) {
168179
// Given
169180
var statement = "PROFILE MATCH (n:Label {prop:{prop}}) RETURN n";
170-
var params = {prop: "string"}
181+
var params = {prop: "string"};
171182
// When & Then
172183
session
173184
.run( statement, params )

0 commit comments

Comments
 (0)