What's not working?
Given the following Prisma schema for a Postgres datasource:
model Key {
id Int @id @default(autoincrement())
publicKey Bytes
}
after migrating, when generating the sdl:
The command fails:
Reverted because: Error applying template at .../dist/commands/generate/service/templates/test.ts.template for
Key: Cannot read properties of undefined (reading 'replace')
Likely due to use of replace in transformValue of the packages/cli/src/commands/generate/service/templates/test.ts.template file:
// Transforms an object or single value into something that's more suitable
// for generating test cases
// If a `type` is passed in, the string for creating an object of that type
// will be generated
// If no type, or a type we don't support, is passed in we'll default to
// generating regular strings
// Looks for quoted strings, either by single (') or double (") quotes.
// When found
// - Removes the quotes around `scenario` variables.
// - Removes the quotes around `BigInt` fields.
const transformValue = (obj, type) => {
if (type === 'DateTime') {
return `new Date('${obj.toISOString()}')`
} else if (type === 'Decimal') {
return `new Prisma.Decimal(${obj})`
}
return JSON.stringify(obj).replace(/['"].*?['"]/g, (string) => {
if (string.match(/scenario\./)) {
return string.replace(/['"]/g, '')
}
// BigInt
if (string.match(/^\"\d+n\"$/)) {
return string.substr(1, string.length - 2)
}
return string
})
} %>
Also, interestingly:
yarn rw g sdl Key --no-tests
Still attempts to generate the test file for the service and gives same error.
How do we reproduce the bug?
- Setup a Postgres datasource (needed for Bytes type)
- Use the above Key model
- yarn rw prima migrate dev
- yarn rw g sdl Key
See error when attempting the create the service test template.
Related Issues
See also #5841
What's your environment? (If it applies)
No response
Are you interested in working on this?
What's not working?
Given the following Prisma schema for a Postgres datasource:
after migrating, when generating the sdl:
The command fails:
Likely due to use of replace in
transformValueof thepackages/cli/src/commands/generate/service/templates/test.ts.templatefile:Also, interestingly:
yarn rw g sdl Key --no-testsStill attempts to generate the test file for the service and gives same error.
How do we reproduce the bug?
See error when attempting the create the service test template.
Related Issues
See also #5841
What's your environment? (If it applies)
No response
Are you interested in working on this?