Skip to content

Commit

Permalink
test(driver-adapters): add test for Bytes (#22810)
Browse files Browse the repository at this point in the history
Co-authored-by: Joël Galeran <Jolg42@users.noreply.github.com>
  • Loading branch information
jkomyno and Jolg42 committed Jan 30, 2024
1 parent 2f8059d commit a4400c9
Show file tree
Hide file tree
Showing 4 changed files with 82 additions and 4 deletions.
@@ -0,0 +1,15 @@
import { defineMatrix } from '../../_utils/defineMatrix'

export default defineMatrix(() => [
[
{
provider: 'sqlite',
},
{
provider: 'postgresql',
},
{
provider: 'mysql',
},
],
])
@@ -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
}
`
})
@@ -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,
},
)
8 changes: 4 additions & 4 deletions sandbox/driver-adapters/src/planetscale.ts
@@ -1,12 +1,12 @@
import { connect } from '@planetscale/database'
import { Client } from '@planetscale/database'
import { PrismaPlanetScale } from '@prisma/adapter-planetscale'
import { smokeTest } from './test'

async function main() {
const connectionString = `${process.env.JS_PLANETSCALE_DATABASE_URL as string}`
const connectionString = `${process.env.JS_PLANETSCALE_DATABASE_URL}`

const connection = connect({ url: connectionString })
const adapter = new PrismaPlanetScale(connection)
const client = new Client({ url: connectionString })
const adapter = new PrismaPlanetScale(client)

await smokeTest(adapter)
}
Expand Down

0 comments on commit a4400c9

Please sign in to comment.