Skip to content

Commit a79cf8d

Browse files
committed
Add more temporal types to the testkit-backend
1 parent 5ad2802 commit a79cf8d

File tree

2 files changed

+90
-0
lines changed

2 files changed

+90
-0
lines changed

packages/testkit-backend/src/cypher-native-binders.js

Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,42 @@ function valueResponseOfObject (x) {
115115
}
116116
}
117117
}
118+
119+
if (neo4j.isDate(x)) {
120+
return structResponse('CypherDate', {
121+
year: x.year,
122+
month: x.month,
123+
day: x.day
124+
})
125+
} else if (neo4j.isDateTime(x) || neo4j.isLocalDateTime(x)) {
126+
return structResponse('CypherDateTime', {
127+
year: x.year,
128+
month: x.month,
129+
day: x.day,
130+
hour: x.hour,
131+
minute: x.minute,
132+
second: x.second,
133+
nanosecond: x.nanosecond,
134+
utc_offset_s: x.timeZoneOffsetSeconds,
135+
timezone_id: x.timeZoneId
136+
})
137+
} else if (neo4j.isTime(x) || neo4j.isLocalTime(x)) {
138+
return structResponse('CypherTime', {
139+
hour: x.hour,
140+
minute: x.minute,
141+
second: x.second,
142+
nanosecond: x.nanosecond,
143+
utc_offset_s: x.timeZoneOffsetSeconds
144+
})
145+
} else if (neo4j.isDuration(x)) {
146+
return structResponse('CypherDuration', {
147+
months: x.months,
148+
days: x.days,
149+
seconds: x.seconds,
150+
nanoseconds: x.nanoseconds
151+
})
152+
}
153+
118154
// If all failed, interpret as a map
119155
const map = {}
120156
for (const [key, value] of Object.entries(x)) {
@@ -123,6 +159,16 @@ function valueResponseOfObject (x) {
123159
return valueResponse('CypherMap', map)
124160
}
125161

162+
function structResponse (name, data) {
163+
const map = {}
164+
for (const [key, value] of Object.entries(data)) {
165+
map[key] = typeof value === 'bigint' || neo4j.isInt(value)
166+
? neo4j.int(value).toNumber()
167+
: value
168+
}
169+
return { name, data: map }
170+
}
171+
126172
export function cypherToNative (c) {
127173
const {
128174
name,
@@ -142,6 +188,17 @@ export function cypherToNative (c) {
142188
case 'CypherList':
143189
return data.value.map(cypherToNative)
144190
case 'CypherDateTime':
191+
if (data.utc_offset_s == null && data.timezone_id == null) {
192+
return new neo4j.LocalDateTime(
193+
data.year,
194+
data.month,
195+
data.day,
196+
data.hour,
197+
data.minute,
198+
data.second,
199+
data.nanosecond
200+
)
201+
}
145202
return new neo4j.DateTime(
146203
data.year,
147204
data.month,
@@ -153,6 +210,35 @@ export function cypherToNative (c) {
153210
data.utc_offset_s,
154211
data.timezone_id
155212
)
213+
case 'CypherTime':
214+
if (data.utc_offset_s == null) {
215+
return new neo4j.LocalTime(
216+
data.hour,
217+
data.minute,
218+
data.second,
219+
data.nanosecond
220+
)
221+
}
222+
return new neo4j.Time(
223+
data.hour,
224+
data.minute,
225+
data.second,
226+
data.nanosecond,
227+
data.utc_offset_s
228+
)
229+
case 'CypherDate':
230+
return new neo4j.Date(
231+
data.year,
232+
data.month,
233+
data.day
234+
)
235+
case 'CypherDuration':
236+
return new neo4j.Duration(
237+
data.months,
238+
data.days,
239+
data.seconds,
240+
data.nanoseconds
241+
)
156242
case 'CypherMap':
157243
return Object.entries(data.value).reduce((acc, [key, val]) => {
158244
acc[key] = cypherToNative(val)

packages/testkit-backend/src/skipped-tests/common.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
import skip, { ifEquals, ifEndsWith } from './skip'
22

33
const skippedTests = [
4+
skip(
5+
'Using numbers out of bound',
6+
ifEquals('neo4j.datatypes.test_temporal_types.TestDataTypes.test_should_echo_temporal_type')
7+
),
48
skip(
59
'Testkit implemenation is deprecated',
610
ifEquals('stub.basic_query.test_basic_query.TestBasicQuery.test_5x0_populates_node_only_element_id'),

0 commit comments

Comments
 (0)