Skip to content

Commit

Permalink
feat: implement compatibility checks for flex search
Browse files Browse the repository at this point in the history
  • Loading branch information
Yogu committed Sep 10, 2024
1 parent 044ac39 commit 5034311
Show file tree
Hide file tree
Showing 13 changed files with 696 additions and 33 deletions.
275 changes: 275 additions & 0 deletions spec/model/compatibility-check/check-flex-search-on-field.spec.ts
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);
});
});
});
Loading

0 comments on commit 5034311

Please sign in to comment.