forked from prisma/prisma
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test(client): unit test for prisma#12651
- Loading branch information
1 parent
c1afd29
commit 323a781
Showing
1 changed file
with
82 additions
and
0 deletions.
There are no files selected for viewing
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 |
---|---|---|
@@ -0,0 +1,82 @@ | ||
import { getDMMF } from '../../generation/getDMMF' | ||
import { DMMFClass, makeDocument, transformDocument } from '../../runtime' | ||
|
||
const datamodel = /* Prisma */ ` | ||
datasource my_db { | ||
provider = "postgres" | ||
url = env("POSTGRES_URL") | ||
} | ||
model Floats { | ||
id Int @id | ||
value Float | ||
} | ||
` | ||
|
||
let dmmf | ||
|
||
function getTransformedDocument(select) { | ||
const document = makeDocument({ | ||
dmmf, | ||
select, | ||
rootTypeName: 'mutation', | ||
rootField: 'createOneFloats', | ||
}) | ||
return String(transformDocument(document)) | ||
} | ||
|
||
beforeAll(async () => { | ||
dmmf = new DMMFClass(await getDMMF({ datamodel })) | ||
}) | ||
|
||
test('serializes floats in exponential notation', () => { | ||
const largeInt = getTransformedDocument({ | ||
data: { | ||
value: 100_000_000_000_000_000_000, | ||
}, | ||
}) | ||
|
||
expect(largeInt).toMatchInlineSnapshot(` | ||
mutation { | ||
createOneFloats(data: { | ||
value: 1e+20 | ||
}) { | ||
id | ||
value | ||
} | ||
} | ||
`) | ||
|
||
const negativeInt = getTransformedDocument({ | ||
data: { | ||
value: Number.MIN_SAFE_INTEGER, | ||
}, | ||
}) | ||
|
||
expect(negativeInt).toMatchInlineSnapshot(` | ||
mutation { | ||
createOneFloats(data: { | ||
value: -9.007199254740991e+15 | ||
}) { | ||
id | ||
value | ||
} | ||
} | ||
`) | ||
|
||
const otherFloat = getTransformedDocument({ | ||
data: { | ||
value: 13.37, | ||
}, | ||
}) | ||
expect(otherFloat).toMatchInlineSnapshot(` | ||
mutation { | ||
createOneFloats(data: { | ||
value: 1.337e+1 | ||
}) { | ||
id | ||
value | ||
} | ||
} | ||
`) | ||
}) |