Skip to content
Merged
Changes from all commits
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
40 changes: 23 additions & 17 deletions packages/db/tests/query/group-by.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1118,28 +1118,31 @@ function createGroupByTests(autoIndex: `off` | `eager`): void {
status: string
}

// Use BigInt values beyond MAX_SAFE_INTEGER to test BigInt serialization
const MAX_SAFE_BIGINT = BigInt(Number.MAX_SAFE_INTEGER + 1)

const sampleDistricts: Array<District> = [
{
id: 1,
district_id: BigInt('9007199254740991'), // Max safe integer + 1
district_id: MAX_SAFE_BIGINT,
name: 'District A',
status: 'active',
},
{
id: 2,
district_id: BigInt('9007199254740992'),
district_id: MAX_SAFE_BIGINT + 1n,
name: 'District B',
status: 'active',
},
{
id: 3,
district_id: BigInt('9007199254740991'), // Same as first
district_id: MAX_SAFE_BIGINT, // Same as first
name: 'District C',
status: 'inactive',
},
{
id: 4,
district_id: BigInt('9007199254740993'),
district_id: MAX_SAFE_BIGINT + 2n,
name: 'District D',
status: 'active',
},
Expand Down Expand Up @@ -1170,23 +1173,23 @@ function createGroupByTests(autoIndex: `off` | `eager`): void {
// Should have 3 groups (two districts share the same district_id)
expect(districtSummary.size).toBe(3)

// Check the group with BigInt('9007199254740991')
// Check the group with MAX_SAFE_BIGINT
const group1 = Array.from(districtSummary.values()).find(
(d) => d.district_id === BigInt('9007199254740991'),
(d) => d.district_id === MAX_SAFE_BIGINT,
)
expect(group1).toBeDefined()
expect(group1?.count).toBe(2) // Districts 1 and 3

// Check the group with BigInt('9007199254740992')
// Check the group with MAX_SAFE_BIGINT + 1n
const group2 = Array.from(districtSummary.values()).find(
(d) => d.district_id === BigInt('9007199254740992'),
(d) => d.district_id === MAX_SAFE_BIGINT + 1n,
)
expect(group2).toBeDefined()
expect(group2?.count).toBe(1) // District 2

// Check the group with BigInt('9007199254740993')
// Check the group with MAX_SAFE_BIGINT + 2n
const group3 = Array.from(districtSummary.values()).find(
(d) => d.district_id === BigInt('9007199254740993'),
(d) => d.district_id === MAX_SAFE_BIGINT + 2n,
)
expect(group3).toBeDefined()
expect(group3?.count).toBe(1) // District 4
Expand Down Expand Up @@ -1380,22 +1383,25 @@ function createGroupByTests(autoIndex: `off` | `eager`): void {
status: string
}

// Use BigInt values beyond MAX_SAFE_INTEGER to test BigInt serialization
const MAX_SAFE_BIGINT = BigInt(Number.MAX_SAFE_INTEGER + 1)

const sampleSchools: Array<School> = [
{
id: 1,
district_id: BigInt('9007199254740991'),
district_id: MAX_SAFE_BIGINT,
name: 'School A',
status: 'active',
},
{
id: 2,
district_id: BigInt('9007199254740991'),
district_id: MAX_SAFE_BIGINT,
name: 'School B',
status: 'active',
},
{
id: 3,
district_id: BigInt('9007199254740992'),
district_id: MAX_SAFE_BIGINT + 1n,
name: 'School C',
status: 'inactive',
},
Expand Down Expand Up @@ -1426,19 +1432,19 @@ function createGroupByTests(autoIndex: `off` | `eager`): void {

expect(schoolSummary.size).toBe(2) // Two distinct combinations

// Find the group with BigInt('9007199254740991') and 'active'
// Find the group with MAX_SAFE_BIGINT and 'active'
const group1 = Array.from(schoolSummary.values()).find(
(s) =>
s.district_id === BigInt('9007199254740991') &&
s.district_id === MAX_SAFE_BIGINT &&
s.status === 'active',
)
expect(group1).toBeDefined()
expect(group1?.count).toBe(2) // Schools 1 and 2

// Find the group with BigInt('9007199254740992') and 'inactive'
// Find the group with MAX_SAFE_BIGINT + 1n and 'inactive'
const group2 = Array.from(schoolSummary.values()).find(
(s) =>
s.district_id === BigInt('9007199254740992') &&
s.district_id === MAX_SAFE_BIGINT + 1n &&
s.status === 'inactive',
)
expect(group2).toBeDefined()
Expand Down