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

@@ -4,8 +4,9 @@
* View Data Builders must:
* 1. Be classes named *ViewDataBuilder
* 2. Have a static build() method
* 3. Accept API DTO as parameter (named 'apiDto', NOT 'pageDto')
* 4. Return View Data
* 3. Use 'satisfies ViewDataBuilder<...>' for static enforcement
* 4. Accept API DTO as parameter (named 'apiDto')
* 5. Return View Data
*/
module.exports = {
@@ -20,7 +21,8 @@ module.exports = {
schema: [],
messages: {
notAClass: 'View Data Builders must be classes named *ViewDataBuilder',
missingBuildMethod: 'View Data Builders must have a static build() method',
missingStaticBuild: 'View Data Builders must have a static build() method',
missingSatisfies: 'View Data Builders must use "satisfies ViewDataBuilder<...>" for static type enforcement',
invalidBuildSignature: 'build() method must accept API DTO and return View Data',
wrongParameterName: 'Parameter must be named "apiDto", not "pageDto" or other names',
},
@@ -32,7 +34,8 @@ module.exports = {
if (!isInViewDataBuilders) return {};
let hasBuildMethod = false;
let hasStaticBuild = false;
let hasSatisfies = false;
let hasCorrectSignature = false;
let hasCorrectParameterName = false;
@@ -49,28 +52,28 @@ 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 parameter name
const firstParam = buildMethod.value.params[0];
const firstParam = staticBuild.value.params[0];
if (firstParam.type === 'Identifier' && firstParam.name === 'apiDto') {
hasCorrectParameterName = true;
} else if (firstParam.type === 'Identifier' && firstParam.name === 'pageDto') {
// Report specific error for pageDto
} else if (firstParam.type === 'Identifier' && (firstParam.name === 'pageDto' || firstParam.name === 'dto')) {
// Report specific error for wrong names
context.report({
node: firstParam,
messageId: 'wrongParameterName',
@@ -80,23 +83,35 @@ module.exports = {
}
},
// Check for satisfies expression
TSSatisfiesExpression(node) {
if (node.typeAnnotation &&
node.typeAnnotation.type === 'TSTypeReference' &&
node.typeAnnotation.typeName.name === 'ViewDataBuilder') {
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',
});
} else if (!hasCorrectParameterName) {
// Only report if not already reported for pageDto
context.report({
node: context.getSourceCode().ast,
messageId: 'wrongParameterName',
});
}
},
};