-
Notifications
You must be signed in to change notification settings - Fork 1.5k
/
floats.test.ts
82 lines (72 loc) · 1.5 KB
/
floats.test.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
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
}
}
`)
})