Skip to content

Commit f32f677

Browse files
committed
ITs for arrays of temporal types
1 parent 456ae14 commit f32f677

File tree

1 file changed

+77
-22
lines changed

1 file changed

+77
-22
lines changed

test/v1/temporal-types.test.js

Lines changed: 77 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ import timesSeries from 'async/timesSeries';
2424
import _ from 'lodash';
2525

2626
const RANDOM_VALUES_TO_TEST = 2000;
27+
const MIN_TEMPORAL_ARRAY_LENGTH = 20;
28+
const MAX_TEMPORAL_ARRAY_LENGTH = 1000;
2729
const MAX_NANO_OF_SECOND = 999999999;
2830
const MAX_YEAR = 999999999;
2931
const MIN_YEAR = -MAX_YEAR;
@@ -91,17 +93,15 @@ describe('temporal-types', () => {
9193
return;
9294
}
9395

94-
const valueGenerator = () => {
95-
const sign = _.sample([true, false]) ? 1 : -1; // duration can be negative
96-
return duration(
97-
sign * _.random(0, Number.MAX_SAFE_INTEGER),
98-
sign * _.random(0, Number.MAX_SAFE_INTEGER),
99-
sign * _.random(0, Number.MAX_SAFE_INTEGER),
100-
sign * _.random(0, MAX_NANO_OF_SECOND),
101-
);
102-
};
96+
testSendAndReceiveRandomTemporalValues(() => randomDuration(), done);
97+
});
98+
99+
it('should send and receive array of Duration', done => {
100+
if (neo4jDoesNotSupportTemporalTypes(done)) {
101+
return;
102+
}
103103

104-
testSendAndReceiveRandomTemporalValues(valueGenerator, done);
104+
testSendAndReceiveArrayOfRandomTemporalValues(() => randomDuration(), done);
105105
});
106106

107107
it('should receive LocalTime', done => {
@@ -136,9 +136,15 @@ describe('temporal-types', () => {
136136
return;
137137
}
138138

139-
const valueGenerator = () => randomLocalTime();
139+
testSendAndReceiveRandomTemporalValues(() => randomLocalTime(), done);
140+
});
141+
142+
it('should send and receive array of LocalTime', done => {
143+
if (neo4jDoesNotSupportTemporalTypes(done)) {
144+
return;
145+
}
140146

141-
testSendAndReceiveRandomTemporalValues(valueGenerator, done);
147+
testSendAndReceiveArrayOfRandomTemporalValues(() => randomLocalTime(), done);
142148
});
143149

144150
it('should receive Time', done => {
@@ -173,9 +179,15 @@ describe('temporal-types', () => {
173179
return;
174180
}
175181

176-
const valueGenerator = () => randomTime();
182+
testSendAndReceiveRandomTemporalValues(() => randomTime(), done);
183+
});
184+
185+
it('should send and receive array of Time', done => {
186+
if (neo4jDoesNotSupportTemporalTypes(done)) {
187+
return;
188+
}
177189

178-
testSendAndReceiveRandomTemporalValues(valueGenerator, done);
190+
testSendAndReceiveArrayOfRandomTemporalValues(() => randomTime(), done);
179191
});
180192

181193
it('should receive Date', done => {
@@ -210,9 +222,15 @@ describe('temporal-types', () => {
210222
return;
211223
}
212224

213-
const valueGenerator = () => randomDate();
225+
testSendAndReceiveRandomTemporalValues(() => randomDate(), done);
226+
});
214227

215-
testSendAndReceiveRandomTemporalValues(valueGenerator, done);
228+
it('should send and receive array of Date', done => {
229+
if (neo4jDoesNotSupportTemporalTypes(done)) {
230+
return;
231+
}
232+
233+
testSendAndReceiveArrayOfRandomTemporalValues(() => randomDate(), done);
216234
});
217235

218236
it('should receive LocalDateTime', done => {
@@ -247,9 +265,15 @@ describe('temporal-types', () => {
247265
return;
248266
}
249267

250-
const valueGenerator = () => randomLocalDateTime();
268+
testSendAndReceiveRandomTemporalValues(() => randomLocalDateTime(), done);
269+
});
270+
271+
it('should send and receive random LocalDateTime', done => {
272+
if (neo4jDoesNotSupportTemporalTypes(done)) {
273+
return;
274+
}
251275

252-
testSendAndReceiveRandomTemporalValues(valueGenerator, done);
276+
testSendAndReceiveArrayOfRandomTemporalValues(() => randomLocalDateTime(), done);
253277
});
254278

255279
it('should receive DateTimeWithZoneOffset', done => {
@@ -284,9 +308,15 @@ describe('temporal-types', () => {
284308
return;
285309
}
286310

287-
const valueGenerator = () => randomDateTimeWithZoneOffset();
311+
testSendAndReceiveRandomTemporalValues(() => randomDateTimeWithZoneOffset(), done);
312+
});
288313

289-
testSendAndReceiveRandomTemporalValues(valueGenerator, done);
314+
it('should send and receive array of DateTimeWithZoneOffset', done => {
315+
if (neo4jDoesNotSupportTemporalTypes(done)) {
316+
return;
317+
}
318+
319+
testSendAndReceiveArrayOfRandomTemporalValues(() => randomDateTimeWithZoneOffset(), done);
290320
});
291321

292322
it('should receive DateTimeWithZoneId', done => {
@@ -321,9 +351,15 @@ describe('temporal-types', () => {
321351
return;
322352
}
323353

324-
const valueGenerator = () => randomDateTimeWithZoneId();
354+
testSendAndReceiveRandomTemporalValues(() => randomDateTimeWithZoneId(), done);
355+
});
356+
357+
it('should send and receive array of DateTimeWithZoneId', done => {
358+
if (neo4jDoesNotSupportTemporalTypes(done)) {
359+
return;
360+
}
325361

326-
testSendAndReceiveRandomTemporalValues(valueGenerator, done);
362+
testSendAndReceiveArrayOfRandomTemporalValues(() => randomDateTimeWithZoneId(), done);
327363
});
328364

329365
it('should convert Duration to ISO string', () => {
@@ -436,6 +472,15 @@ describe('temporal-types', () => {
436472
timesSeries(RANDOM_VALUES_TO_TEST, asyncFunction, doneFunction);
437473
}
438474

475+
function testSendAndReceiveArrayOfRandomTemporalValues(valueGenerator, done) {
476+
const arrayLength = _.random(MIN_TEMPORAL_ARRAY_LENGTH, MAX_TEMPORAL_ARRAY_LENGTH);
477+
const values = _.range(arrayLength).map(() => valueGenerator());
478+
479+
console.log('Generated: ' + values);
480+
481+
testSendReceiveTemporalValue(values, done);
482+
}
483+
439484
function testReceiveTemporalValue(query, expectedValue, done) {
440485
session.run(query).then(result => {
441486
const records = result.records;
@@ -474,6 +519,16 @@ describe('temporal-types', () => {
474519
return false;
475520
}
476521

522+
function randomDuration() {
523+
const sign = _.sample([true, false]) ? 1 : -1; // duration can be negative
524+
return duration(
525+
sign * _.random(0, Number.MAX_SAFE_INTEGER),
526+
sign * _.random(0, Number.MAX_SAFE_INTEGER),
527+
sign * _.random(0, Number.MAX_SAFE_INTEGER),
528+
sign * _.random(0, MAX_NANO_OF_SECOND),
529+
);
530+
}
531+
477532
function randomDateTimeWithZoneOffset() {
478533
const dateTime = randomDstSafeLocalDateTime();
479534
return new neo4j.DateTimeWithZoneOffset(dateTime.year, dateTime.month, dateTime.day, dateTime.hour, dateTime.minute, dateTime.second, dateTime.nanosecond,

0 commit comments

Comments
 (0)