forked from unlight/prisma-nestjs-graphql
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: Compound primary key generated type
close unlight#182
- Loading branch information
Showing
3 changed files
with
96 additions
and
51 deletions.
There are no files selected for viewing
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
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,85 @@ | ||
import expect from 'expect'; | ||
import { Project, SourceFile } from 'ts-morph'; | ||
|
||
import { testSourceFile } from './helpers'; | ||
import { testGenerate } from './test-generate'; | ||
|
||
let project: Project; | ||
let sourceFiles: SourceFile[]; | ||
|
||
describe('compound index', () => { | ||
before(async () => { | ||
({ project, sourceFiles } = await testGenerate({ | ||
schema: ` | ||
model User { | ||
id Int @id | ||
/// @Validator.MinLength(3) | ||
name String | ||
/// @PropertyType({ name: 'G.Email', from: 'graphql-type-email' }) | ||
email String? | ||
@@unique([email, name]) | ||
} | ||
model Us { | ||
id Int @id | ||
} | ||
`, | ||
options: [ | ||
`outputFilePattern = "{name}.{type}.ts"`, | ||
`fields_Validator_from = "class-validator"`, | ||
`fields_Validator_input = true`, | ||
], | ||
})); | ||
}); | ||
|
||
it('user unique input compound', () => { | ||
const s = testSourceFile({ | ||
project, | ||
class: 'UserEmailNameCompoundUniqueInput', | ||
}); | ||
|
||
const minLength = s.classFile.getProperty('name')?.getDecorator('MinLength'); | ||
expect(minLength?.getText()).toEqual('@Validator.MinLength(3)'); | ||
}); | ||
|
||
it('compound uniq where must be wrapped to prisma atleast', () => { | ||
const s = testSourceFile({ | ||
project, | ||
class: 'FindManyUserArgs', | ||
property: 'cursor', | ||
}); | ||
|
||
expect(s.property?.type).toEqual( | ||
`Prisma.AtLeast<UserWhereUniqueInput, 'id' | 'email_name'>`, | ||
); | ||
}); | ||
}); | ||
|
||
describe('compound primary key', () => { | ||
before(async () => { | ||
({ project, sourceFiles } = await testGenerate({ | ||
schema: ` | ||
model User { | ||
firstname String | ||
surname String | ||
email String | ||
@@id([firstname, surname]) | ||
} | ||
`, | ||
options: [`outputFilePattern = "{name}.{type}.ts"`], | ||
})); | ||
}); | ||
|
||
it('compound primary key atleast keys', () => { | ||
const s = testSourceFile({ | ||
project, | ||
class: 'FindFirstUserArgs', | ||
property: 'cursor', | ||
}); | ||
|
||
expect(s.property?.type).toEqual( | ||
"Prisma.AtLeast<UserWhereUniqueInput, 'firstname_surname'>", | ||
); | ||
}); | ||
}); |
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