Skip to content

Commit a9a6fd2

Browse files
committed
Added new features
1 parent 07fe80e commit a9a6fd2

File tree

3 files changed

+283
-0
lines changed

3 files changed

+283
-0
lines changed

test/v1/tck/steps/environment.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,10 @@ module.exports = function () {
1919
callback();
2020
});
2121

22+
this.Before("@equality_test", function( scenario ) {
23+
this.savedValues = {}
24+
});
25+
2226
this.After(function (scenario, callback) {
2327
if (!scenario.isSuccessful()) {
2428
failedScenarios.push(scenario)

test/v1/tck/steps/equalitysteps.js

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
var neo4j = require("../../../../lib/v1");
2+
var util = require("./util")
3+
var GraphType = require("../../../../lib/v1/graph-types");
4+
5+
module.exports = function () {
6+
7+
this.When(/^`(.*)` is single value result of: (.*)$/, function (key, statement, callback) {
8+
self = this;
9+
this.session.run(statement).then(function(res) {
10+
self.savedValues[key] = getSingleValue(res.records[0]);
11+
callback();
12+
}).catch(function(err) {callback(new Error("Rejected Promise: " + err))});
13+
});
14+
15+
16+
this.When(/^saved values should all equal$/, function () {
17+
var keys = Object.keys(this.savedValues);
18+
if (keys < 2) {
19+
throw new Error("Should be at leas 2 values");
20+
}
21+
var first = this.savedValues[keys[0]]
22+
for (var i = 1 ; i < keys.length ; i++) {
23+
throw new Error("JS has no equality implemented!!!");
24+
}
25+
});
26+
27+
this.When(/^none of the saved values should be equal$/, function () {
28+
var keys = Object.keys(this.savedValues);
29+
if (keys < 2) {
30+
throw new Error("Should be at leas 2 values");
31+
}
32+
var first = this.savedValues[keys[0]]
33+
for (var i = 1 ; i < keys.length ; i++) {
34+
throw new Error("JS has no equality implemented!!!");
35+
}
36+
});
37+
38+
this.Given(/^`(.*)` is a copy of `(.*)` path with flipped relationship direction$/, function (key2, key1) {
39+
var value1 = this.savedValues[key1];
40+
var newSegments = []
41+
for (var i = 0; i < value1.segments.length; i++) {
42+
var segment = value1.segments[i];
43+
var n1 = segment.start;
44+
var n2 = segment.end;
45+
var oldr = segment.relationship;
46+
var r = new GraphType.Relationship(oldr.identity, oldr.end, oldr.start, oldr.type, oldr.properties);
47+
newSegments.push(new GraphType.PathSegment(n1, r, n2))
48+
}
49+
this.savedValues[key2] = new GraphType.Path(newSegments);
50+
});
51+
52+
53+
function getSingleValue(res) {
54+
var values = []
55+
var keys = Object.keys(res);
56+
return res[keys[0]]
57+
}
58+
59+
}

test/v1/tck/steps/resultapisteps.js

Lines changed: 220 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,220 @@
1+
var neo4j = require("../../../../lib/v1");
2+
var resultSummary = require("../../../../lib/v1/result-summary");
3+
var util = require("./util")
4+
5+
module.exports = function () {
6+
7+
this.When(/^the `Result Cursor` is summarized$/, function (callback) {
8+
self = this;
9+
this.rc.then(function(res) {
10+
self.summary = res.summary;
11+
callback();
12+
}).catch(function(err) {callback(new Error("Rejected Promise: " + err))});
13+
});
14+
15+
this.Then(/^the `Result Cursor` is fully consumed$/, function () {
16+
//No result cursor in JavaScript Driver
17+
});
18+
19+
this.Then(/^a `Result Summary` is returned$/, function () {
20+
//skip this boring part
21+
});
22+
23+
this.When(/^I request a `statement` from the `Result Summary`$/, function () {
24+
this.statement = this.summary.statement
25+
});
26+
27+
this.Then(/^requesting the `Statement` as text should give: (.*)$/, function (statementText) {
28+
if (this.statement.text != statementText) {
29+
throw Error("'" + this.statement.text + "' does not match expected text: '" + statementText + "'")
30+
}
31+
});
32+
33+
this.Then(/^requesting the `Statement` parameter should give: (.*)$/, function (statementParam) {
34+
var param = util.literalValueToTestValue(statementParam);
35+
if (typeof this.statement.parameters === 'undefined') {
36+
this.statement.parameters = {}
37+
}
38+
if (!util.compareValues(this.statement.parameters, param)) {
39+
throw Error("Params does not match! Got: " + this.statement.parameters + " Expected: " + param);
40+
}
41+
});
42+
43+
this.Then(/^requesting `update statistics` from it should give$/, function (table) {
44+
var updateStatistics = this.summary.updateStatistics
45+
for ( var i = 0 ; i < table.hashes().length; i++) {
46+
var statistic = table.hashes()[i].statistic;
47+
var expected = util.literalValueToTestValueNormalIntegers(table.hashes()[i].result);
48+
var given = getStatistic(statistic, updateStatistics)
49+
if (!util.compareValues(given, expected)) {
50+
throw Error("Statistics for: " + statistic + " does not match. Expected: '" + expected + "' Given: '" + given + "'");
51+
}
52+
}
53+
});
54+
55+
this.Then(/^requesting the `Statement Type` should give (.*)$/, function (type) {
56+
var type = getStatementTypeFromString(type);
57+
if (this.summary.statementType != type)
58+
{
59+
throw Error("statementType does not match. Expected: '" + type + "' Given: '" + this.summary.statementType + "'");
60+
}
61+
});
62+
63+
this.Then(/^the summary has a `plan`$/, function () {
64+
if(! this.summary.hasPlan()) {
65+
throw Error("Expected summary to have a `plan`. It did not...");
66+
}
67+
});
68+
69+
this.Then(/^the summary does not have a `plan`$/, function () {
70+
if(this.summary.hasPlan()) {
71+
throw Error("Expected summary to NOT have a `plan`. It did not...");
72+
}
73+
});
74+
75+
this.Then(/^the summary has a `profile`$/, function () {
76+
if(! this.summary.hasProfile()) {
77+
throw Error("Expected summary to have a `profile plan`. It did not...");
78+
}
79+
});
80+
81+
this.Then(/^the summary does not have a `profile`$/, function () {
82+
if( this.summary.hasProfile()) {
83+
throw Error("Expected summary to NOT have a `profile plan`. It did...");
84+
}
85+
});
86+
87+
this.Then(/^requesting the `plan` it contains$/, function (table) {
88+
checkPlanExact(table, this.summary.plan)
89+
});
90+
91+
this.Then(/^the `plan` also contains method calls for:$/, function (table) {
92+
checkPlan(table, this.summary.plan)
93+
});
94+
95+
this.Then(/^requesting the `profile` it contains:$/, function (table) {
96+
checkPlanExact(table, this.summary.profile)
97+
});
98+
99+
this.Then(/^the `profile` also contains method calls for:$/, function (table) {
100+
checkPlan(table, this.summary.profile)
101+
});
102+
103+
this.Then(/^the summaries `notifications` is empty list$/, function (table) {
104+
if (! this.summary.notifications.length == 0) {
105+
throw Error("Expected no notifications. Got: " + this.summary.notifications.length)
106+
}
107+
});
108+
109+
this.Then(/^the summaries `notifications` has one notification with$/, function (table) {
110+
111+
var expected = {};
112+
if (this.summary.notifications.length > 1) {
113+
throw Error("Expected only one notification. Got: " + this.summary.notifications.length)
114+
}
115+
var givenNotification = this.summary.notifications[0];
116+
var given = {}
117+
for ( var i = 0 ; i < table.hashes().length; i++) {
118+
var key = table.hashes()[i]['key']
119+
expected[key] = util.literalValueToTestValueNormalIntegers(table.hashes()[i]['value']);
120+
given[key] = givenNotification[key]
121+
}
122+
if (Object.keys(givenNotification).length !== Object.keys(given).length) {
123+
throw Error("Keys do not match with expected. Got: " + Object.keys(givenNotification) + " Expected: " + Object.keys(given))
124+
}
125+
if (!util.compareValues(expected, given)) {
126+
throw Error("Summary notifications does not match. Expected: '" + util.printable(expected) + "' Given: '" + util.printable(givenNotification) + "'");
127+
}
128+
});
129+
130+
function checkPlanExact(table, plan)
131+
{
132+
for ( var i = 0 ; i < table.hashes().length; i++) {
133+
var dataKey = getPlanParam(table.hashes()[i]["plan method"])
134+
var given = plan[dataKey];
135+
if (given === undefined || given === null || given === NaN) {
136+
throw Error("Plans `" + dataKey + "` has no content! Got: " + given);
137+
}
138+
}
139+
}
140+
141+
function checkPlan(table, plan)
142+
{
143+
for ( var i = 0 ; i < table.hashes().length; i++) {
144+
var dataKey = getPlanParam(table.hashes()[i]["plan method"])
145+
var given = plan[dataKey];
146+
if (given === undefined || given === null || given === NaN) {
147+
throw Error("Plans `" + dataKey + "` has no content! Got: " + given);
148+
}
149+
}
150+
}
151+
152+
function getPlanParam(key) {
153+
if (key == 'operator type') {
154+
return 'operatorType'
155+
}
156+
if (key == 'db hits') {
157+
return 'dbHits'
158+
}
159+
else {
160+
return key
161+
}
162+
}
163+
164+
function getStatementTypeFromString(type) {
165+
if (type == 'read write') {
166+
return resultSummary.statementType.READ_WRITE;
167+
}
168+
if (type == 'read only') {
169+
return resultSummary.statementType.READ_ONLY;
170+
}
171+
if (type == 'write only') {
172+
return resultSummary.statementType.WRITE_ONLY;
173+
}
174+
if (type == 'schema write') {
175+
return resultSummary.statementType.SCHEMA_WRITE;
176+
}
177+
throw Error("No statement type mapping of: " + type)
178+
}
179+
180+
function getStatistic(statementString, updateStatistics) {
181+
if (statementString == 'nodes created') {
182+
return updateStatistics.nodesCreated();
183+
}
184+
if (statementString == 'nodes deleted') {
185+
return updateStatistics.nodesDeleted();
186+
}
187+
if (statementString == 'relationships created') {
188+
return updateStatistics.relationshipsCreated();
189+
}
190+
if (statementString == 'relationships deleted') {
191+
return updateStatistics.relationshipsDeleted();
192+
}
193+
if (statementString == 'properties set') {
194+
return updateStatistics.propertiesSet();
195+
}
196+
if (statementString == 'labels added') {
197+
return updateStatistics.labelsAdded();
198+
}
199+
if (statementString == 'labels removed') {
200+
return updateStatistics.labelsRemoved();
201+
}
202+
if (statementString == 'indexes added') {
203+
return updateStatistics.indexesAdded();
204+
}
205+
if (statementString == 'indexes removed') {
206+
return updateStatistics.indexesRemoved();
207+
}
208+
if (statementString == 'constraints added') {
209+
return updateStatistics.constraintsAdded();
210+
}
211+
if (statementString == 'constraints removed') {
212+
return updateStatistics.constraintsRemoved();
213+
}
214+
if (statementString == 'contains updates') {
215+
return updateStatistics.containsUpdates();
216+
}
217+
throw Error("No statistics mapping of: " + statementString)
218+
}
219+
220+
}

0 commit comments

Comments
 (0)