-
Notifications
You must be signed in to change notification settings - Fork 1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
update scaffold generator to use emptyAsUndefined when its needed (#8031
) * update use scaffold generator to use emptyAsUndefined when its needed * identify that a prisma model field is a relational field In addition to checking the field name ends with 'id', checks that the field name matches one of the model's relations * test includes emptyAsUndefined on optional relation form field * isolate the use emptyAsUndefined test * Minor tweaks to the test --------- Co-authored-by: Tobbe Lundberg <tobbe@tlundberg.com>
- Loading branch information
Showing
4 changed files
with
52 additions
and
3 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
32 changes: 32 additions & 0 deletions
32
packages/cli/src/commands/generate/scaffold/__tests__/shouldUseEmptyAsUndefined.test.js
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,32 @@ | ||
globalThis.__dirname = __dirname | ||
import path from 'path' | ||
|
||
// Load mocks | ||
import '../../../../lib/test' | ||
|
||
import { getDefaultArgs } from '../../../../lib' | ||
import { yargsDefaults as defaults } from '../../helpers' | ||
import * as scaffold from '../scaffold' | ||
|
||
jest.mock('execa') | ||
|
||
describe('relational form field', () => { | ||
let form | ||
|
||
beforeAll(async () => { | ||
const files = await scaffold.files({ | ||
...getDefaultArgs(defaults), | ||
model: 'Tag', | ||
tests: true, | ||
nestScaffoldByModel: true, | ||
}) | ||
|
||
const tagFormPath = | ||
'/path/to/project/web/src/components/Tag/TagForm/TagForm.js' | ||
form = files[path.normalize(tagFormPath)] | ||
}) | ||
|
||
test("includes optional relational fields with an emptyAs('undefined')", () => { | ||
expect(form).toMatch("emptyAs={'undefined'}") | ||
}) | ||
}) |
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