Skip to content

Commit

Permalink
test(client): unit test for prisma#12651
Browse files Browse the repository at this point in the history
  • Loading branch information
cmd-johnson committed Oct 19, 2022
1 parent c1afd29 commit 323a781
Showing 1 changed file with 82 additions and 0 deletions.
82 changes: 82 additions & 0 deletions packages/client/src/__tests__/query/floats.test.ts
@@ -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
}
}
`)
})

0 comments on commit 323a781

Please sign in to comment.