-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: implement compatibility checks for flex search
- Loading branch information
Showing
13 changed files
with
696 additions
and
33 deletions.
There are no files selected for viewing
275 changes: 275 additions & 0 deletions
275
spec/model/compatibility-check/check-flex-search-on-field.spec.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,275 @@ | ||
import gql from 'graphql-tag'; | ||
import { | ||
expectSingleCompatibilityIssue, | ||
expectToBeValid, | ||
} from '../implementation/validation-utils'; | ||
import { runCheck } from './utils'; | ||
|
||
describe('checkModel', () => { | ||
describe('@flexSearch', () => { | ||
it('rejects if @flexSearch is missing', () => { | ||
const result = runCheck( | ||
gql` | ||
type Test @rootEntity(flexSearch: true) @modules(in: "module1") { | ||
field: String @modules(all: true) @flexSearch | ||
} | ||
`, | ||
gql` | ||
type Test @rootEntity(flexSearch: true) { | ||
field: String | ||
} | ||
`, | ||
); | ||
expectSingleCompatibilityIssue( | ||
result, | ||
'Field "field" should enable @flexSearch (required by module "module1").', | ||
); | ||
}); | ||
|
||
it('accepts @flexSearch is present', () => { | ||
const result = runCheck( | ||
gql` | ||
type Test @rootEntity(flexSearch: true) @modules(in: "module1") { | ||
field: String @modules(all: true) @flexSearch | ||
} | ||
`, | ||
gql` | ||
type Test @rootEntity(flexSearch: true) { | ||
field: String @flexSearch | ||
} | ||
`, | ||
); | ||
expectToBeValid(result); | ||
}); | ||
|
||
it('accepts @flexSearch is present even though it is not required', () => { | ||
const result = runCheck( | ||
gql` | ||
type Test @rootEntity(flexSearch: true) @modules(in: "module1") { | ||
field: String @modules(all: true) | ||
} | ||
`, | ||
gql` | ||
type Test @rootEntity(flexSearch: true) { | ||
field: String @flexSearch | ||
} | ||
`, | ||
); | ||
expectToBeValid(result); | ||
}); | ||
|
||
it('rejects if @flexSearch(includeInSearch: true) is missing', () => { | ||
const result = runCheck( | ||
gql` | ||
type Test @rootEntity(flexSearch: true) @modules(in: "module1") { | ||
field: String @modules(all: true) @flexSearch(includeInSearch: true) | ||
} | ||
`, | ||
gql` | ||
type Test @rootEntity(flexSearch: true) { | ||
field: String @flexSearch | ||
} | ||
`, | ||
); | ||
expectSingleCompatibilityIssue( | ||
result, | ||
'Field "field" should enable @flexSearch(includeInSearch: true) (required by module "module1").', | ||
); | ||
}); | ||
|
||
it('rejects if @flexSearch(includeInSearch) should be true but is false', () => { | ||
const result = runCheck( | ||
gql` | ||
type Test @rootEntity(flexSearch: true) @modules(in: "module1") { | ||
field: String @modules(all: true) @flexSearch(includeInSearch: true) | ||
} | ||
`, | ||
gql` | ||
type Test @rootEntity(flexSearch: true) { | ||
field: String @flexSearch(includeInSearch: false) | ||
} | ||
`, | ||
); | ||
expectSingleCompatibilityIssue( | ||
result, | ||
'Field "field" should enable @flexSearch(includeInSearch: true) (required by module "module1").', | ||
); | ||
}); | ||
|
||
it('accepts @flexSearch(includeInSearch: true)', () => { | ||
const result = runCheck( | ||
gql` | ||
type Test @rootEntity(flexSearch: true) @modules(in: "module1") { | ||
field: String @modules(all: true) @flexSearch(includeInSearch: true) | ||
} | ||
`, | ||
gql` | ||
type Test @rootEntity(flexSearch: true) { | ||
field: String @flexSearch(includeInSearch: true) | ||
} | ||
`, | ||
); | ||
expectToBeValid(result); | ||
}); | ||
|
||
it('accepts @flexSearch(includeInSearch: true) even if not required', () => { | ||
const result = runCheck( | ||
gql` | ||
type Test @rootEntity(flexSearch: true) @modules(in: "module1") { | ||
field: String @modules(all: true) @flexSearch(includeInSearch: false) | ||
} | ||
`, | ||
gql` | ||
type Test @rootEntity(flexSearch: true) { | ||
field: String @flexSearch(includeInSearch: true) | ||
} | ||
`, | ||
); | ||
expectToBeValid(result); | ||
}); | ||
}); | ||
|
||
describe('@flexSearchFulltext', () => { | ||
it('rejects if @flexSearchFulltext is missing', () => { | ||
const result = runCheck( | ||
gql` | ||
type Test @rootEntity(flexSearch: true) @modules(in: "module1") { | ||
field: String @modules(all: true) @flexSearchFulltext | ||
} | ||
`, | ||
gql` | ||
type Test @rootEntity(flexSearch: true) { | ||
field: String | ||
} | ||
`, | ||
); | ||
expectSingleCompatibilityIssue( | ||
result, | ||
'Field "field" should enable @flexSearchFulltext (required by module "module1").', | ||
); | ||
}); | ||
|
||
it('rejects if @flexSearchFulltext is missing even if @flexSearch is present', () => { | ||
const result = runCheck( | ||
gql` | ||
type Test @rootEntity(flexSearch: true) @modules(in: "module1") { | ||
field: String @modules(all: true) @flexSearchFulltext | ||
} | ||
`, | ||
gql` | ||
type Test @rootEntity(flexSearch: true) { | ||
field: String @flexSearch | ||
} | ||
`, | ||
); | ||
expectSingleCompatibilityIssue( | ||
result, | ||
'Field "field" should enable @flexSearchFulltext (required by module "module1").', | ||
); | ||
}); | ||
|
||
it('accepts @flexSearchFulltext is present', () => { | ||
const result = runCheck( | ||
gql` | ||
type Test @rootEntity(flexSearch: true) @modules(in: "module1") { | ||
field: String @modules(all: true) @flexSearchFulltext | ||
} | ||
`, | ||
gql` | ||
type Test @rootEntity(flexSearch: true) { | ||
field: String @flexSearchFulltext | ||
} | ||
`, | ||
); | ||
expectToBeValid(result); | ||
}); | ||
|
||
it('accepts @flexSearchFulltext is present even though it is not required', () => { | ||
const result = runCheck( | ||
gql` | ||
type Test @rootEntity(flexSearch: true) @modules(in: "module1") { | ||
field: String @modules(all: true) | ||
} | ||
`, | ||
gql` | ||
type Test @rootEntity(flexSearch: true) { | ||
field: String @flexSearchFulltext | ||
} | ||
`, | ||
); | ||
expectToBeValid(result); | ||
}); | ||
|
||
it('rejects if @flexSearchFulltext(includeInSearch: true) is missing', () => { | ||
const result = runCheck( | ||
gql` | ||
type Test @rootEntity(flexSearch: true) @modules(in: "module1") { | ||
field: String @modules(all: true) @flexSearchFulltext(includeInSearch: true) | ||
} | ||
`, | ||
gql` | ||
type Test @rootEntity(flexSearch: true) { | ||
field: String @flexSearchFulltext | ||
} | ||
`, | ||
); | ||
expectSingleCompatibilityIssue( | ||
result, | ||
'Field "field" should enable @flexSearch(includeInSearch: true) (required by module "module1").', | ||
); | ||
}); | ||
|
||
it('rejects if @flexSearchFulltext(includeInSearch) should be true but is false', () => { | ||
const result = runCheck( | ||
gql` | ||
type Test @rootEntity(flexSearch: true) @modules(in: "module1") { | ||
field: String @modules(all: true) @flexSearchFulltext(includeInSearch: true) | ||
} | ||
`, | ||
gql` | ||
type Test @rootEntity(flexSearch: true) { | ||
field: String @flexSearchFulltext(includeInSearch: false) | ||
} | ||
`, | ||
); | ||
expectSingleCompatibilityIssue( | ||
result, | ||
'Field "field" should enable @flexSearch(includeInSearch: true) (required by module "module1").', | ||
); | ||
}); | ||
|
||
it('accepts @flexSearchFulltext(includeInSearch: true)', () => { | ||
const result = runCheck( | ||
gql` | ||
type Test @rootEntity(flexSearch: true) @modules(in: "module1") { | ||
field: String @modules(all: true) @flexSearchFulltext(includeInSearch: true) | ||
} | ||
`, | ||
gql` | ||
type Test @rootEntity(flexSearch: true) { | ||
field: String @flexSearchFulltext(includeInSearch: true) | ||
} | ||
`, | ||
); | ||
expectToBeValid(result); | ||
}); | ||
|
||
it('accepts @flexSearchFulltext(includeInSearch: true) even if not required', () => { | ||
const result = runCheck( | ||
gql` | ||
type Test @rootEntity(flexSearch: true) @modules(in: "module1") { | ||
field: String | ||
@modules(all: true) | ||
@flexSearchFulltext(includeInSearch: false) | ||
} | ||
`, | ||
gql` | ||
type Test @rootEntity(flexSearch: true) { | ||
field: String @flexSearchFulltext(includeInSearch: true) | ||
} | ||
`, | ||
); | ||
expectToBeValid(result); | ||
}); | ||
}); | ||
}); |
Oops, something went wrong.