Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test(driver-adapters): add test for
Bytes
(#22810)
Co-authored-by: Joël Galeran <Jolg42@users.noreply.github.com>
- Loading branch information
Showing
4 changed files
with
82 additions
and
4 deletions.
There are no files selected for viewing
15 changes: 15 additions & 0 deletions
15
packages/client/tests/functional/driver-adapters/team-orm-687-bytes/_matrix.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 |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import { defineMatrix } from '../../_utils/defineMatrix' | ||
|
||
export default defineMatrix(() => [ | ||
[ | ||
{ | ||
provider: 'sqlite', | ||
}, | ||
{ | ||
provider: 'postgresql', | ||
}, | ||
{ | ||
provider: 'mysql', | ||
}, | ||
], | ||
]) |
21 changes: 21 additions & 0 deletions
21
packages/client/tests/functional/driver-adapters/team-orm-687-bytes/prisma/_schema.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 |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import { idForProvider } from '../../../_utils/idForProvider' | ||
import testMatrix from '../_matrix' | ||
|
||
export default testMatrix.setupSchema(({ provider }) => { | ||
return /* Prisma */ ` | ||
generator client { | ||
provider = "prisma-client-js" | ||
previewFeatures = ["driverAdapters"] | ||
} | ||
datasource db { | ||
provider = "${provider}" | ||
url = env("DATABASE_URI_${provider}") | ||
} | ||
model A { | ||
id ${idForProvider(provider)} | ||
bytes Bytes | ||
} | ||
` | ||
}) |
42 changes: 42 additions & 0 deletions
42
packages/client/tests/functional/driver-adapters/team-orm-687-bytes/tests.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 |
---|---|---|
@@ -0,0 +1,42 @@ | ||
import { defaultTestSuiteOptions } from '../_utils/test-suite-options' | ||
import testMatrix from './_matrix' | ||
// @ts-ignore | ||
import type { PrismaClient } from './node_modules/@prisma/client' | ||
|
||
declare let prisma: PrismaClient | ||
|
||
testMatrix.setupTestSuite( | ||
() => { | ||
test('Bytes encoding is preserved', async () => { | ||
const inputStrings = ['AQID', 'FSDF', 'AA', 'BB'] | ||
const inputBtoas = inputStrings.map((s) => btoa(s)) | ||
const inputs = [...inputStrings, ...inputBtoas] | ||
|
||
const inputBuffers = inputs.map((s) => Buffer.from(s)) | ||
const inputData = inputBuffers.map((b, i) => ({ id: `${i + 1}`, bytes: b })) | ||
|
||
// sqlite doesn't support `createMany` yet | ||
await prisma.$transaction(inputData.map((data) => prisma.a.create({ data }))) | ||
|
||
const results = await prisma.a.findMany() | ||
|
||
// We can't compare buffers directly, or else we'd see this diff in the test output: | ||
// ``` | ||
// - "bytes": Buffer [ | ||
// + "bytes": C [ | ||
// ``` | ||
const outputData = results.map((result) => { | ||
return { | ||
id: result.id, | ||
bytes: Buffer.from(result.bytes), | ||
} | ||
}) | ||
|
||
expect(outputData).toEqual(inputData) | ||
}) | ||
}, | ||
{ | ||
...defaultTestSuiteOptions, | ||
skipDefaultClientInstance: false, | ||
}, | ||
) |
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