Skip to content

Commit

Permalink
feat: implement more compatibility checks
Browse files Browse the repository at this point in the history
This includes relations, references, key fields, collect fields, business objects and enum values
  • Loading branch information
Yogu committed Aug 6, 2024
1 parent 8efee14 commit f5d8ba1
Show file tree
Hide file tree
Showing 10 changed files with 1,355 additions and 149 deletions.
1,025 changes: 899 additions & 126 deletions spec/model/compatibility-check/check-model.spec.ts

Large diffs are not rendered by default.

11 changes: 11 additions & 0 deletions spec/model/implementation/validation-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,17 @@ export function expectToBeValid(component: Validatable) {
expect(result.hasMessages(), result.toString()).to.be.false;
}

export function expectNoErrors(component: Validatable) {
const result = validate(component);
expect(
result.hasErrors(),
result
.getErrors()
.map((e) => e.toString())
.join('\n'),
).to.be.false;
}

export function expectSingleError(component: Validatable, errorPart: string) {
expectSingleMessage(component, errorPart, Severity.ERROR);
}
Expand Down
41 changes: 40 additions & 1 deletion spec/project/select-modules-in-sources.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ describe('selectModulesInProjectSource', () => {
two: String @modules(in: ["module2"])
extra1: String @modules(in: ["extra1"])
one: String @modules(in: "module1")
one: String @modules(in: ["module1"])
}
type Two @rootEntity @modules(in: ["module2"]) {
Expand All @@ -48,6 +48,25 @@ describe('selectModulesInProjectSource', () => {
`);
});

it('keeps id: ID @key', () => {
// special case because system fields are usually not specified in the source, but id: ID @key needs to stay
const result = run(
gql`
type Test @rootEntity @modules(in: ["module1", "module2"]) {
id: ID @key
field: String @modules(in: ["module1", "module2"])
}
`,
['module1'],
);
expect(result).to.equal(`
type Test @rootEntity @modules(in: ["module1"]) {
id: ID @key
field: String @modules(in: ["module1"])
}
`);
});

it('removes the non-selected modules from the modules.json', () => {
const project = new Project({
sources: [
Expand Down Expand Up @@ -78,6 +97,26 @@ describe('selectModulesInProjectSource', () => {
'module2',
]);
});

it('works with includeAllFields: true', () => {
const result = run(
gql`
type Test @rootEntity @modules(in: "module1", includeAllFields: true) {
field: Test @reference(keyField: "keyField")
key: String @key
keyField: String
}
`,
['module1'],
);
expect(result).to.equal(`
type Test @rootEntity @modules(includeAllFields: true, in: ["module1"]) {
field: Test @reference(keyField: "keyField")
key: String @key
keyField: String
}
`);
});
});

describe('with removeModuleDeclarations = true', () => {
Expand Down
24 changes: 24 additions & 0 deletions src/model/compatibility-check/check-enum-type.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import { EnumType } from '../implementation';
import { ValidationContext, ValidationMessage } from '../validation';
import { getRequiredBySuffix } from './describe-module-specification';

export function checkEnumType(
typeToCheck: EnumType,
baselineType: EnumType,
context: ValidationContext,
) {
for (const baselineValue of baselineType.values) {
const matchingValue = typeToCheck.values.find((v) => v.value === baselineValue.value);
if (!matchingValue) {
context.addMessage(
ValidationMessage.compatibilityIssue(
`Enum value "${baselineValue.value}" is missing${getRequiredBySuffix(
baselineType,
)}.`,
typeToCheck.nameASTNode,
),
);
continue;
}
}
}
Loading

0 comments on commit f5d8ba1

Please sign in to comment.