-
Notifications
You must be signed in to change notification settings - Fork 431
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: Start in Create type exclusion now recursively checks for sanity…
…Create.exclude options
- Loading branch information
Showing
2 changed files
with
84 additions
and
1 deletion.
There are no files selected for viewing
76 changes: 76 additions & 0 deletions
76
packages/sanity/src/core/create/__tests__/createUtils.test.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,76 @@ | ||
import {defineType, type ObjectSchemaType} from '@sanity/types' | ||
import {describe, expect, it} from 'vitest' | ||
|
||
import {createSchema} from '../../schema' | ||
import {isSanityCreateExcludedType} from '../createUtils' | ||
|
||
const basicDoc = defineType({ | ||
type: 'document', | ||
name: 'test', | ||
fields: [{type: 'string', name: 'title'}], | ||
}) | ||
|
||
describe('createUtils', () => { | ||
describe('isSanityCreateExcludedType', () => { | ||
it(`should include type without options`, async () => { | ||
const documentType = getDocumentType([basicDoc], basicDoc.name) | ||
expect(isSanityCreateExcludedType(documentType)).toEqual(false) | ||
}) | ||
|
||
it(`should exclude type via direct options`, async () => { | ||
const documentType = getDocumentType( | ||
[ | ||
defineType({ | ||
...basicDoc, | ||
options: {sanityCreate: {exclude: true}}, | ||
}), | ||
], | ||
basicDoc.name, | ||
) | ||
expect(isSanityCreateExcludedType(documentType)).toEqual(true) | ||
}) | ||
|
||
it(`should exclude type via parent options`, async () => { | ||
const documentType = getDocumentType( | ||
[ | ||
{ | ||
type: 'document', | ||
name: 'parentDoc', | ||
fields: [{type: 'string', name: 'title'}], | ||
options: {sanityCreate: {exclude: true}}, | ||
}, | ||
{ | ||
type: 'parentDoc', | ||
name: 'test', | ||
}, | ||
], | ||
basicDoc.name, | ||
) | ||
expect(isSanityCreateExcludedType(documentType)).toEqual(true) | ||
}) | ||
|
||
it(`should include type when child type overrides parent options`, async () => { | ||
const documentType = getDocumentType( | ||
[ | ||
{ | ||
type: 'document', | ||
name: 'parentDoc', | ||
fields: [{type: 'string', name: 'title'}], | ||
options: {sanityCreate: {exclude: true}}, | ||
}, | ||
{ | ||
type: 'parentDoc', | ||
name: 'test', | ||
options: {sanityCreate: {exclude: false}}, | ||
}, | ||
], | ||
basicDoc.name, | ||
) | ||
expect(isSanityCreateExcludedType(documentType)).toEqual(false) | ||
}) | ||
}) | ||
}) | ||
|
||
function getDocumentType(docDefs: ReturnType<typeof defineType>[], docName: string) { | ||
return createSchema({name: 'test', types: docDefs}).get(docName) as ObjectSchemaType | ||
} |
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