Skip to content

Commit b8ffdc5

Browse files
authored
Add 'point to' feature to dev-constraint.js (#1000)
1 parent 48dd7f5 commit b8ffdc5

File tree

1 file changed

+19
-2
lines changed

1 file changed

+19
-2
lines changed

src/scripts/dev-constraint.js

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,8 @@ async function scaffoldTest(constraintId,context) {
164164
message: `Choose the content for the negative test:`,
165165
choices: [
166166
{ name: `Create new ${constraintId}-INVALID.xml`, value: 'new' },
167-
{ name: 'Select an existing content file to copy', value: 'select' }
167+
{ name: 'Select an existing content file to copy', value: 'select' },
168+
{ name: 'Point to an existing content file', value: 'point' }
168169
]
169170
}
170171
]);
@@ -256,7 +257,7 @@ async function scaffoldTest(constraintId,context) {
256257
fs.copyFileSync(templatePath, newInvalidPath);
257258
invalidContent = `../content/${model}-${constraintId}-INVALID.xml`;
258259
}
259-
} else {
260+
} else if (useTemplate === 'select') {
260261
const contentDir = path.join(__dirname, '..', '..', 'src', 'validations', 'constraints', 'content');
261262
const contentFiles = fs.readdirSync(contentDir).filter(file => file.endsWith('.xml'));
262263
const { selectedContent } = await prompt([
@@ -278,6 +279,22 @@ async function scaffoldTest(constraintId,context) {
278279

279280
invalidContent = `../content/${model}-${constraintId}-INVALID.xml`;
280281
}
282+
else {
283+
const contentDir = path.join(__dirname, '..', '..', 'src', 'validations', 'constraints', 'content');
284+
const contentFiles = fs.readdirSync(contentDir).filter(file => file.endsWith('.xml'));
285+
const { selectedContent } = await prompt([
286+
{
287+
type: 'list',
288+
name: 'selectedContent',
289+
message: 'Select an existing content file to point to:',
290+
choices: contentFiles
291+
}
292+
]);
293+
const selectedContentPath = path.join(contentDir, selectedContent);
294+
const selectedContentTarget = selectedContentPath.split("/").pop();
295+
console.log(`Pointed invalid test for ${constraintId} to ${selectedContentTarget}`);
296+
invalidContent = `../content/${selectedContentTarget}`;
297+
}
281298

282299
const positivetestCase = {
283300
'test-case': {

0 commit comments

Comments
 (0)