integration tests

This commit is contained in:
2026-01-24 00:18:44 +01:00
parent f8099f04bc
commit c470505b4f
3 changed files with 75 additions and 65 deletions

View File

@@ -1,11 +1,12 @@
/**
* ESLint rule to enforce View Model Builder contract
*
*
* View Model Builders must:
* 1. Be classes named *ViewModelBuilder
* 2. Have a static build() method
* 3. Accept View Data as parameter
* 4. Return View Model
* 3. Use 'satisfies ViewModelBuilder<...>' for static enforcement
* 4. Accept View Data as parameter
* 5. Return View Model
*/
module.exports = {
@@ -20,7 +21,8 @@ module.exports = {
schema: [],
messages: {
notAClass: 'View Model Builders must be classes named *ViewModelBuilder',
missingBuildMethod: 'View Model Builders must have a static build() method',
missingStaticBuild: 'View Model Builders must have a static build() method',
missingSatisfies: 'View Model Builders must use "satisfies ViewModelBuilder<...>" for static type enforcement',
invalidBuildSignature: 'build() method must accept View Data and return View Model',
},
},
@@ -31,7 +33,8 @@ module.exports = {
if (!isInViewModelBuilders) return {};
let hasBuildMethod = false;
let hasStaticBuild = false;
let hasSatisfies = false;
let hasCorrectSignature = false;
return {
@@ -47,32 +50,50 @@ module.exports = {
}
// Check for static build method
const buildMethod = node.body.body.find(member =>
const staticBuild = node.body.body.find(member =>
member.type === 'MethodDefinition' &&
member.key.type === 'Identifier' &&
member.key.name === 'build' &&
member.static === true
);
if (buildMethod) {
hasBuildMethod = true;
if (staticBuild) {
hasStaticBuild = true;
// Check signature - should have at least one parameter
if (buildMethod.value &&
buildMethod.value.params &&
buildMethod.value.params.length > 0) {
if (staticBuild.value &&
staticBuild.value.params &&
staticBuild.value.params.length > 0) {
hasCorrectSignature = true;
}
}
},
// Check for satisfies expression
TSSatisfiesExpression(node) {
if (node.typeAnnotation &&
node.typeAnnotation.type === 'TSTypeReference' &&
node.typeAnnotation.typeName.name === 'ViewModelBuilder') {
hasSatisfies = true;
}
},
'Program:exit'() {
if (!hasBuildMethod) {
if (!hasStaticBuild) {
context.report({
node: context.getSourceCode().ast,
messageId: 'missingBuildMethod',
messageId: 'missingStaticBuild',
});
} else if (!hasCorrectSignature) {
}
if (!hasSatisfies) {
context.report({
node: context.getSourceCode().ast,
messageId: 'missingSatisfies',
});
}
if (hasStaticBuild && !hasCorrectSignature) {
context.report({
node: context.getSourceCode().ast,
messageId: 'invalidBuildSignature',