Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(client): add BigInt to serializeRawParemeters (#6059)
- Loading branch information
1 parent
965d568
commit daf4791
Showing
2 changed files
with
110 additions
and
56 deletions.
There are no files selected for viewing
131 changes: 76 additions & 55 deletions
131
src/packages/client/src/__tests__/serializeRawParameters.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,72 +1,93 @@ | ||
import { replaceDates } from '../runtime/utils/serializeRawParameters' | ||
|
||
test('serializeRawParemeters object', () => { | ||
const data = { | ||
date: new Date('2020-06-22T17:07:16.348Z'), | ||
} | ||
|
||
expect(replaceDates(data)).toMatchInlineSnapshot(` | ||
Object { | ||
date: Object { | ||
prisma__type: date, | ||
prisma__value: 2020-06-22T17:07:16.348Z, | ||
}, | ||
import { serializeRawParameters } from '../runtime/utils/serializeRawParameters' | ||
function serializeHelper(data: any) { | ||
return JSON.parse(serializeRawParameters(data)) | ||
} | ||
describe('serializeRawParemeters', () => { | ||
test('object', () => { | ||
const data = { | ||
date: new Date('2020-06-22T17:07:16.348Z'), | ||
bigInt: BigInt('321804719213721'), | ||
} | ||
`) | ||
}) | ||
|
||
test('serializeRawParemeters array', () => { | ||
const data = { | ||
date: [new Date('2020-06-22T17:07:16.348Z')], | ||
} | ||
|
||
expect(replaceDates(data)).toMatchInlineSnapshot(` | ||
Object { | ||
date: Array [ | ||
Object { | ||
expect(serializeHelper(data)).toMatchInlineSnapshot(` | ||
Object { | ||
bigInt: 321804719213721, | ||
date: Object { | ||
prisma__type: date, | ||
prisma__value: 2020-06-22T17:07:16.348Z, | ||
}, | ||
], | ||
} | ||
`) | ||
}) | ||
} | ||
`) | ||
}) | ||
|
||
test('serializeRawParemeters scalar', () => { | ||
const data = new Date('2020-06-22T17:07:16.348Z') | ||
|
||
expect(replaceDates(data)).toMatchInlineSnapshot(` | ||
Object { | ||
prisma__type: date, | ||
prisma__value: 2020-06-22T17:07:16.348Z, | ||
test('array', () => { | ||
const data = { | ||
date: [new Date('2020-06-22T17:07:16.348Z')], | ||
bigInt: [BigInt('321804719213721')], | ||
} | ||
`) | ||
}) | ||
|
||
test('serializeRawParemeters nested', () => { | ||
const data = { | ||
deep: { | ||
date: [ | ||
new Date('2020-06-22T17:07:16.348Z'), | ||
new Date('2020-06-22T17:07:16.348Z'), | ||
], | ||
}, | ||
} | ||
|
||
expect(replaceDates(data)).toMatchInlineSnapshot(` | ||
Object { | ||
deep: Object { | ||
expect(serializeHelper(data)).toMatchInlineSnapshot(` | ||
Object { | ||
bigInt: Array [ | ||
321804719213721, | ||
], | ||
date: Array [ | ||
Object { | ||
prisma__type: date, | ||
prisma__value: 2020-06-22T17:07:16.348Z, | ||
}, | ||
Object { | ||
prisma__type: date, | ||
prisma__value: 2020-06-22T17:07:16.348Z, | ||
}, | ||
], | ||
} | ||
`) | ||
}) | ||
|
||
test('scalar date', () => { | ||
const data = new Date('2020-06-22T17:07:16.348Z') | ||
|
||
expect(serializeHelper(data)).toMatchInlineSnapshot(` | ||
Object { | ||
prisma__type: date, | ||
prisma__value: 2020-06-22T17:07:16.348Z, | ||
} | ||
`) | ||
}) | ||
|
||
test('scalar bigInt', () => { | ||
const data = BigInt('321804719213721') | ||
|
||
expect(serializeHelper(data)).toMatchInlineSnapshot(`321804719213721`) | ||
}) | ||
|
||
test('nested', () => { | ||
const data = { | ||
deep: { | ||
date: [ | ||
new Date('2020-06-22T17:07:16.348Z'), | ||
new Date('2020-06-22T17:07:16.348Z'), | ||
], | ||
bigInt: [BigInt('321804719213721'), BigInt('321804719213721')], | ||
}, | ||
} | ||
`) | ||
|
||
expect(serializeHelper(data)).toMatchInlineSnapshot(` | ||
Object { | ||
deep: Object { | ||
bigInt: Array [ | ||
321804719213721, | ||
321804719213721, | ||
], | ||
date: Array [ | ||
Object { | ||
prisma__type: date, | ||
prisma__value: 2020-06-22T17:07:16.348Z, | ||
}, | ||
Object { | ||
prisma__type: date, | ||
prisma__value: 2020-06-22T17:07:16.348Z, | ||
}, | ||
], | ||
}, | ||
} | ||
`) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters