Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions packages/core/src/result-summary.ts
Original file line number Diff line number Diff line change
Expand Up @@ -644,9 +644,9 @@ class ServerInfo {

function intValue (value: NumberOrInteger): number {
if (value instanceof Integer) {
return value.toInt()
return value.toNumber()
} else if (typeof value === 'bigint') {
return int(value).toInt()
return int(value).toNumber()
} else {
return value
}
Expand Down
205 changes: 204 additions & 1 deletion packages/core/test/result-summary.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,21 @@
* limitations under the License.
*/

import { int } from '../src'
import {
ServerInfo,
Notification,
NotificationSeverityLevel,
NotificationCategory,
notificationSeverityLevel,
notificationCategory
notificationCategory,
ProfiledPlan,
QueryStatistics,
Stats
} from '../src/result-summary'

import fc from 'fast-check'

describe('ServerInfo', () => {
it.each([
[
Expand Down Expand Up @@ -158,6 +164,203 @@ describe('notificationCategory', () => {
})
})

describe('ProfilePlan', () => {
describe.each([
'dbHits',
'rows',
'pageCacheMisses',
'pageCacheHits',
'pageCacheHitRatio',
'time'
])('.%s', (field: keyof ProfiledPlan) => {
it('should handle return arbitrary integer as it is', () => {
return fc.assert(
fc.property(
fc.integer(),
value => {
const rawProfilePlan = {
[field]: value
}

const profilePlan = new ProfiledPlan(rawProfilePlan)

return profilePlan[field] === value
}
)
)
})

it('should handle Integer with maxSafeInteger', () => {
return fc.assert(
fc.property(
fc.maxSafeInteger().map(value => [int(value), value]),
([value, expectedValue]) => {
const rawProfilePlan = {
[field]: value
}

const profilePlan = new ProfiledPlan(rawProfilePlan)

return profilePlan[field] === expectedValue
}
)
)
})

it('should handle Integer with arbitrary integer', () => {
return fc.assert(
fc.property(
fc.integer().map(value => [int(value), value]),
([value, expectedValue]) => {
const rawProfilePlan = {
[field]: value
}

const profilePlan = new ProfiledPlan(rawProfilePlan)

return profilePlan[field] === expectedValue
}
)
)
})

it('should handle BigInt with maxSafeInteger', () => {
return fc.assert(
fc.property(
fc.maxSafeInteger().map(value => [BigInt(value), value]),
([value, expectedValue]) => {
const rawProfilePlan = {
[field]: value
}

const profilePlan = new ProfiledPlan(rawProfilePlan)

return profilePlan[field] === expectedValue
}
)
)
})

it('should handle Integer with arbitrary integer', () => {
return fc.assert(
fc.property(
fc.integer().map(value => [BigInt(value), value]),
([value, expectedValue]) => {
const rawProfilePlan = {
[field]: value
}

const profilePlan = new ProfiledPlan(rawProfilePlan)

return profilePlan[field] === expectedValue
}
)
)
})
})
})

describe('QueryStatistics', () => {
describe.each([
'nodesCreated',
'nodesDeleted',
'relationshipsCreated',
'relationshipsDeleted',
'propertiesSet',
'labelsAdded',
'labelsRemoved',
'indexesAdded',
'indexesRemoved',
'constraintsAdded',
'constraintsRemoved'
])('.%s', (field: keyof Stats) => {
it('should handle return arbitrary integer as it is', () => {
return fc.assert(
fc.property(
fc.integer(),
value => {
const stats = {
[field]: value
}

const queryStatistics = new QueryStatistics(stats)

return queryStatistics.updates()[field] === value
}
)
)
})

it('should handle Integer with maxSafeInteger', () => {
return fc.assert(
fc.property(
fc.maxSafeInteger().map(value => [int(value), value]),
([value, expectedValue]) => {
const stats = {
[field]: value
}

const queryStatistics = new QueryStatistics(stats)

return queryStatistics.updates()[field] === expectedValue
}
)
)
})

it('should handle Integer with arbitrary integer', () => {
return fc.assert(
fc.property(
fc.integer().map(value => [int(value), value]),
([value, expectedValue]) => {
const stats = {
[field]: value
}

const queryStatistics = new QueryStatistics(stats)

return queryStatistics.updates()[field] === expectedValue
}
)
)
})

it('should handle BigInt with maxSafeInteger', () => {
return fc.assert(
fc.property(
fc.maxSafeInteger().map(value => [BigInt(value), value]),
([value, expectedValue]) => {
const stats = {
[field]: value
}

const queryStatistics = new QueryStatistics(stats)

return queryStatistics.updates()[field] === expectedValue
}
)
)
})

it('should handle Integer with arbitrary integer', () => {
return fc.assert(
fc.property(
fc.integer().map(value => [BigInt(value), value]),
([value, expectedValue]) => {
const stats = {
[field]: value
}

const queryStatistics = new QueryStatistics(stats)

return queryStatistics.updates()[field] === expectedValue
}
)
)
})
})
})

function getValidSeverityLevels (): NotificationSeverityLevel[] {
return [
'WARNING',
Expand Down
4 changes: 2 additions & 2 deletions packages/neo4j-driver-deno/lib/core/result-summary.ts
Original file line number Diff line number Diff line change
Expand Up @@ -644,9 +644,9 @@ class ServerInfo {

function intValue (value: NumberOrInteger): number {
if (value instanceof Integer) {
return value.toInt()
return value.toNumber()
} else if (typeof value === 'bigint') {
return int(value).toInt()
return int(value).toNumber()
} else {
return value
}
Expand Down