Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test(client): snapshot current state of int overflows #15963

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
12 changes: 10 additions & 2 deletions packages/client/tests/functional/_utils/setupFilesAfterEnv.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import { toMatchInlineSnapshot, toMatchSnapshot } from 'jest-snapshot'
import stripAnsi from 'strip-ansi'

import { pipe } from '../../../../../helpers/blaze/pipe'

process.env.PRISMA_HIDE_PREVIEW_FLAG_WARNINGS = 'true'

expect.extend({
Expand All @@ -13,7 +15,7 @@ expect.extend({
}
// @ts-expect-error: jest-snapshot and jest typings are incompatible,
// even though custom snapshot matchers supposed to work this way
return toMatchSnapshot.call(this, sanitizeLineNumbers(received.message))
return toMatchSnapshot.call(this, sanitize(received.message))
},

toMatchPrismaErrorInlineSnapshot(received: unknown, ...rest: unknown[]) {
Expand All @@ -26,14 +28,20 @@ expect.extend({

// @ts-expect-error: jest-snapshot and jest typings are incompatible,
// even though custom snapshot matchers supposed to work this way
return toMatchInlineSnapshot.call(this, sanitizeLineNumbers(received.message), ...rest)
return toMatchInlineSnapshot.call(this, sanitize(received.message), ...rest)
},
})

const sanitize = pipe(sanitizeLineNumbers, sanitizeServerNumber)

function sanitizeLineNumbers(message: string) {
return stripAnsi(message).replace(/^(\s*→?\s+)\d+/gm, '$1XX')
}

function sanitizeServerNumber(message: string) {
return message.replace(/server: ".*?"/, 'server: "xxxxxxxxxxxx"')
}

/**
* Utility that busts test flakiness by running the same test multiple times.
* This is especially useful for tests that fail locally but not on CI.
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`issues.13913-integer-overflow (provider=cockroachdb) int overflow 1`] = `
Object {
id: ac6be4a35f2ed6e94bb2928d,
number: -2029967296,
}
`;

exports[`issues.13913-integer-overflow (provider=mongodb) int overflow 1`] = `
Object {
id: ac6be4a35f2ed6e94bb2928d,
number: 2265000000,
}
`;

exports[`issues.13913-integer-overflow (provider=mysql) int overflow 1`] = `

Invalid \`prisma.resource.create()\` invocation in
/client/tests/functional/issues/13913-integer-overflow/tests.ts:0:0

XX
XX testMatrix.setupTestSuite(({ provider }) => {
XX test('int overflow', async () => {
→ XX const result = prisma.resource.create(
Value out of range for the type. Out of range value for column 'number' at row 1
`;

exports[`issues.13913-integer-overflow (provider=postgresql) int overflow 1`] = `
Object {
id: ac6be4a35f2ed6e94bb2928d,
number: -2029967296,
}
`;

exports[`issues.13913-integer-overflow (provider=sqlite) int overflow 1`] = `

Invalid \`prisma.resource.create()\` invocation in
/client/tests/functional/issues/13913-integer-overflow/tests.ts:0:0

XX
XX testMatrix.setupTestSuite(({ provider }) => {
XX test('int overflow', async () => {
→ XX const result = prisma.resource.create(
Inconsistent column data: Conversion failed: Value 2265000000 does not fit in an INT column, try migrating the 'number' column type to BIGINT
`;

exports[`issues.13913-integer-overflow (provider=sqlserver) int overflow 1`] = `

Invalid \`prisma.resource.create()\` invocation in
/client/tests/functional/issues/13913-integer-overflow/tests.ts:0:0

XX
XX testMatrix.setupTestSuite(({ provider }) => {
XX test('int overflow', async () => {
→ XX const result = prisma.resource.create(
Error occurred during query execution:
ConnectorError(ConnectorError { user_facing_error: None, kind: QueryError(TokenError { code: 8115, state: 2, class: 16, message: "Arithmetic overflow error converting expression to data type int.", server: "xxxxxxxxxxxx", procedure: "", line: 1 }) })
`;
Original file line number Diff line number Diff line change
@@ -1,36 +1,34 @@
import { get } from '../../../../../../helpers/blaze/get'
import testMatrix from './_matrix'
// @ts-ignore
import type { PrismaClient } from './node_modules/@prisma/client'

declare let prisma: PrismaClient

testMatrix.setupTestSuite(() => {
// TODO: re-enable this or change it once we have decided the fix
test.skip('int overflow', async () => {
const promise = prisma.resource.create({
const id = 'ac6be4a35f2ed6e94bb2928d'

testMatrix.setupTestSuite(({ provider }) => {
test('int overflow', async () => {
const result = prisma.resource.create({
data: {
id,
number: 2265000000,
},
})

await expect(promise).rejects.toMatchObject({
message: expect.stringContaining('Failed to validate the query'),
code: 'P2009',
})

// TODO: stack trace is not able to locate this error via dataproxy
if (!process.env.DATA_PROXY) {
await expect(promise).rejects.toMatchPrismaErrorInlineSnapshot(`
const success = () => expect(result).resolves.toMatchSnapshot()
const failure = () => expect(result).rejects.toMatchPrismaErrorSnapshot()

Invalid \`prisma.resource.create()\` invocation in
/client/tests/functional/issues/13913-integer-overflow/tests.ts:0:0

XX
XX testMatrix.setupTestSuite(() => {
XX test('int overflow', async () => {
→ XX const promise = prisma.resource.create(
Failed to validate the query: \`Unable to match input value to any allowed input type for the field. Parse errors: [Query parsing/validation error at \`Mutation.createOneResource.data.ResourceCreateInput.number\`: Unable to fit integer value '2265000000' into a 32-bit signed integer for field 'number'., Query parsing/validation error at \`Mutation.createOneResource.data.ResourceUncheckedCreateInput.number\`: Unable to fit integer value '2265000000' into a 32-bit signed integer for field 'number'.]\` at \`Mutation.createOneResource.data\`
`)
}
await get(
{
postgresql: success,
cockroachdb: success,
mongodb: success,
mysql: failure,
sqlite: failure,
sqlserver: failure,
},
provider,
)()
})
})