diff --git a/packages/core/src/result-summary.ts b/packages/core/src/result-summary.ts index 55e34c874..5f43d1d46 100644 --- a/packages/core/src/result-summary.ts +++ b/packages/core/src/result-summary.ts @@ -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 } diff --git a/packages/core/test/result-summary.test.ts b/packages/core/test/result-summary.test.ts index 20b6fd77a..43064a532 100644 --- a/packages/core/test/result-summary.test.ts +++ b/packages/core/test/result-summary.test.ts @@ -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([ [ @@ -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', 'nodes-created'], + ['nodesDeleted', 'nodes-deleted'], + ['relationshipsCreated', 'relationships-created'], + ['relationshipsDeleted', 'relationships-deleted'], + ['propertiesSet', 'properties-set'], + ['labelsAdded', 'labels-added'], + ['labelsRemoved', 'labels-removed'], + ['indexesAdded', 'indexes-added'], + ['indexesRemoved', 'indexes-removed'], + ['constraintsAdded', 'constraints-added'], + ['constraintsRemoved', 'constraints-removed'] + ])('.updates().%s', (field: keyof Stats, rawField: string) => { + it('should handle return arbitrary integer as it is', () => { + return fc.assert( + fc.property( + fc.integer(), + value => { + const stats = { + [rawField]: 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 = { + [rawField]: 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 = { + [rawField]: 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 = { + [rawField]: 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 = { + [rawField]: value + } + + const queryStatistics = new QueryStatistics(stats) + + return queryStatistics.updates()[field] === expectedValue + } + ) + ) + }) + }) +}) + function getValidSeverityLevels (): NotificationSeverityLevel[] { return [ 'WARNING', diff --git a/packages/neo4j-driver-deno/lib/core/result-summary.ts b/packages/neo4j-driver-deno/lib/core/result-summary.ts index 8dc76506e..58a816d04 100644 --- a/packages/neo4j-driver-deno/lib/core/result-summary.ts +++ b/packages/neo4j-driver-deno/lib/core/result-summary.ts @@ -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 }