Skip to content

Commit 4a5c7e7

Browse files
committed
Updated according to changes in feature file
1 parent d6626b5 commit 4a5c7e7

File tree

1 file changed

+29
-42
lines changed

1 file changed

+29
-42
lines changed

test/v1/tck/steps/steps.js

+29-42
Original file line numberDiff line numberDiff line change
@@ -41,19 +41,19 @@ module.exports = function () {
4141
var map = {};
4242
for(var i = 0; i < size; i++ ) {
4343
if (type === 'String') {
44-
map["a" + tempSizeOfObject(this.M)] = stringOfSize(3);
44+
map["a" + sizeOfObject(this.M)] = stringOfSize(3);
4545
}
4646
if (type === 'Integer') {
47-
map["a" + tempSizeOfObject(this.M)] = randomInt();
47+
map["a" + sizeOfObject(this.M)] = randomInt();
4848
}
4949
if (type === 'Boolean') {
50-
map["a" + tempSizeOfObject(this.M)] = randomBool();
50+
map["a" + sizeOfObject(this.M)] = randomBool();
5151
}
5252
if (type === 'Float') {
53-
map["a" + tempSizeOfObject(this.M)] = randomFloat();
53+
map["a" + sizeOfObject(this.M)] = randomFloat();
5454
}
5555
if (type === 'Null') {
56-
map["a" + tempSizeOfObject(this.M)] = null;
56+
map["a" + sizeOfObject(this.M)] = null;
5757
}
5858
}
5959
this.expectedValue = map;
@@ -96,71 +96,58 @@ module.exports = function () {
9696
this.Given(/^adding a table of values to the map M$/, function (table) {
9797
var rows = table.rows();
9898
for (var i = 0, len = rows.length; i < len; i++) {
99-
this.M["a" + tempSizeOfObject(this.M)] = toParameter(rows[i][0], rows[i][1]);
99+
this.M["a" + sizeOfObject(this.M)] = toParameter(rows[i][0], rows[i][1]);
100100
}
101101
});
102102

103103
this.When(/^adding a table of lists to the map M$/, function (table) {
104104
var rows = table.rows();
105105
for (var i = 0, len = rows.length; i < len; i++) {
106-
this.M["a" + tempSizeOfObject(this.M)] = getListFromString(rows[i][0], rows[i][1]);
106+
this.M["a" + sizeOfObject(this.M)] = getListFromString(rows[i][0], rows[i][1]);
107107
}
108108
});
109109

110110
this.When(/^adding a copy of map M to map M$/, function () {
111111
var copyt_of_map = Object.assign({}, this.M);
112-
this.M["a" + tempSizeOfObject(this.M)] = copyt_of_map;
112+
this.M["a" + sizeOfObject(this.M)] = copyt_of_map;
113113
});
114114

115115
this.When(/^the driver asks the server to echo this value back$/, function () {
116-
echoExpectedValue(this);
116+
echoExpectedValue.call(this);
117117
});
118118

119119
this.When(/^the driver asks the server to echo this list back$/, function () {
120120
this.expectedValue = this.L;
121-
echoExpectedValue(this);
121+
echoExpectedValue.call(this);
122122
});
123123

124124
this.When(/^the driver asks the server to echo this map back$/, function () {
125125
this.expectedValue = this.M;
126-
echoExpectedValue(this);
126+
echoExpectedValue.call(this);
127127
});
128128

129-
this.Then(/^the result returned from the server should be a single record with a single value$/, function (callback) {
129+
this.Then(/^the value given in the result should be the same as what was sent$/, function (callback) {
130130
var self = this;
131-
this.setWithParam.then( function(res) {
132-
if(Object.keys(res[0]).length != 1 || Object.keys(res[0])[0].length != 1) {
133-
callback(new Error("Expected the parameterized statement to return a single row, single field record. Got: " + Object.keys(res[0]).length + " records and: " + Object.keys(res[0])[0].length + " values"));
134-
} else {
135-
self.paramResult = res[0]['x'];
136-
}
137-
}, function(err) {callback(new Error("Rejected Promise: " + err))});
138-
this.setWithLiteral.then( function(res) {
139-
if(Object.keys(res[0]).length != 1 || Object.keys(res[0])[0].length != 1) {
140-
callback(new Error("Expected the parameterized statement to return a single row, single field record. Got: " + Object.keys(res[0]).length + " records and: " + Object.keys(res[0])[0].length + " values"));
141-
} else {
142-
self.literalResult = res[0]['x'];
143-
callback();
144-
}
145-
}, function(err) {callback(new Error("Rejected Promise: " + err))});
146-
});
147-
148-
149-
this.Then(/^the value given in the result should be the same as what was sent$/, function () {
150-
if (!compareValues(this.paramResult, this.expectedValue)) {
151-
throw new Error("Expected the parameterized statement to return same as what was sent. Got: " + this.paramResult + " Expected: " + this.expectedValue);
152-
}
153-
if(!compareValues(this.literalResult,this.expectedValue)) {
154-
throw new Error("Expected the literal statement to return same as what was sent. Got: " + this.literalResult + " Expected: " + this.expectedValue);
131+
var errorCallback = function(err) {callback(new Error("Rejected Promise: " + err))}
132+
var successCallback = function(res) {
133+
if(Object.keys(res[0]).length != 1 || Object.keys(res[0])[0].length != 1) {
134+
callback(new Error("Expected the statement to return a single row, single field record. Got: " + Object.keys(res[0]).length + " records and: " + Object.keys(res[0])[0].length + " values"));
135+
}
136+
if (!compareValues(res[0]['x'], self.expectedValue)) {
137+
callback(new Error("Expected the statement to return same as what was sent. Got: " + res[0]['x'] + " Expected: " + self.expectedValue));
138+
}
139+
callback();
155140
}
141+
this.withParamPromise.then(successCallback).catch(errorCallback);
142+
this.withLiteralPromise.then(successCallback).catch(errorCallback);
143+
156144
});
157145

158146
this.After(function () {
159147
this.driver.close()
160148
});
161149

162-
//Should not be used in final!!!!
163-
function tempSizeOfObject(obj) {
150+
function sizeOfObject(obj) {
164151
var size = 0, key;
165152
for (key in obj) {
166153
if (obj.hasOwnProperty(key)) size++;
@@ -266,7 +253,7 @@ module.exports = function () {
266253
}
267254
else if (typeof one === "object" && one instanceof Array){
268255
if (one === other) return true;
269-
if (tempSizeOfObject(one) != tempSizeOfObject(other)) return false;
256+
if (sizeOfObject(one) != sizeOfObject(other)) return false;
270257
for (var i = 0; i < one.length; ++i) {
271258
if (!compareValues(one[i], other[i])) {
272259
console.log("Miss-match at index: [" + i + "] Values should be same but was : [" + one[i] +"] and : [" + other[i] + "]");
@@ -304,8 +291,8 @@ module.exports = function () {
304291
return list;
305292
}
306293

307-
function echoExpectedValue(self) {
308-
self.setWithParam = self.session.run("RETURN {x} as x", {x:self.expectedValue});
309-
self.setWithLiteral = self.session.run("RETURN "+jsToCypherLiteral(self.expectedValue)+" as x");
294+
function echoExpectedValue() {
295+
this.withParamPromise = this.session.run("RETURN {x} as x", {x:this.expectedValue});
296+
this.withLiteralPromise = this.session.run("RETURN "+jsToCypherLiteral(this.expectedValue)+" as x");
310297
}
311298
};

0 commit comments

Comments
 (0)