Files
wekan/tests/customFieldsSortSchema.test.cjs
T
Lauri Ojansivu 7930da455a Fix a boot-crashing invalid SimpleSchema property on customFields.sort.
The user's own ./build.sh run reproduced it directly: "[uncaughtException]
WeKan is stopping: Error: Invalid definition for sort field: 'decimal' is
not a supported property", thrown from SimpleSchema's own constructor the
moment the server started - before any board could load. `decimal: true`
is not, and has never been, a property SimpleSchema recognizes (its
schemaDefinitionOptions list is autoValue/defaultValue/label/optional/
required/type, plus WeKan's own extendOptions(['index', 'unique']) in
imports/simpleSchema.js); nothing exercises that validation under a plain
Node test, which is why it slipped through review. `type: Number` already
allows fractional values with no extra flag - the same as Lists' own
`sort` field, which this one was deliberately written to mirror (see the
field's own comment) and which never had this property either - so
removing it changes nothing about what the field accepts.

tests/customFieldsSortSchema.test.cjs pins the sort field's definition
against SimpleSchema's actual valid-property list and sweeps every other
file under models/ for the same shape, so it cannot reappear anywhere else
undetected by a Node-only test run.

Verified against a real Meteor boot (`meteor run`) in-sandbox: reproduced
the crash before this commit, starts cleanly after.

Thanks to xet7 !
2026-09-10 23:43:06 +03:00

77 lines
3.6 KiB
JavaScript

'use strict';
// Regression guard: models/customFields.js's `sort` field definition once
// carried `decimal: true`, a property SimpleSchema has never supported
// (its schemaDefinitionOptions list is autoValue/defaultValue/label/
// optional/required/type, plus WeKan's own extendOptions(['index',
// 'unique']) in imports/simpleSchema.js - 'decimal' is not among them,
// on any version). It compiled fine and even loaded under a plain Node
// require, since nothing here exercises SimpleSchema's own validation -
// but the moment the real Meteor server started, `new SimpleSchema(...)`
// threw synchronously: '[uncaughtException] WeKan is stopping: Error:
// Invalid definition for sort field: "decimal" is not a supported
// property', crashing boot before any board could load. Number already
// allows fractional values by default, so removing it changed nothing
// about what the field accepts.
//
// This is a source-read test (no Meteor): it can't instantiate the real
// SimpleSchema without the Meteor runtime, so it checks the shape
// directly against the known-valid property list instead.
//
// Run: node tests/customFieldsSortSchema.test.cjs
const assert = require('assert');
const fs = require('fs');
const path = require('path');
const ROOT = path.join(__dirname, '..');
let passed = 0;
function test(name, fn) { fn(); passed += 1; console.log(' ok -', name); }
// SimpleSchema's own schemaDefinitionOptions (autoValue, defaultValue, label,
// optional, required, type) plus the oneOfProps that may sit under `type`
// but are also accepted at the top level (allowedValues, blackbox, custom,
// exclusiveMax, exclusiveMin, max, maxCount, min, minCount, regEx,
// skipRegExCheckForEmptyStrings, trim), plus WeKan's own
// SimpleSchema.extendOptions(['index', 'unique']) in imports/simpleSchema.js.
const VALID_FIELD_KEYS = new Set([
'autoValue', 'defaultValue', 'label', 'optional', 'required', 'type',
'allowedValues', 'blackbox', 'custom', 'exclusiveMax', 'exclusiveMin',
'max', 'maxCount', 'min', 'minCount', 'regEx',
'skipRegExCheckForEmptyStrings', 'trim',
'index', 'unique',
]);
console.log('customFieldsSortSchema:');
test('models/customFields.js sort field has no "decimal" property (or any other unsupported one)', () => {
const src = fs.readFileSync(path.join(ROOT, 'models', 'customFields.js'), 'utf8');
const block = /\bsort:\s*\{([\s\S]*?)\n\s{4}\},/.exec(src);
assert.ok(block, 'customFields.js must still define a top-level sort field');
const keys = [...block[1].matchAll(/^\s*([a-zA-Z]+)\s*[:(]/gm)].map(m => m[1]);
assert.ok(keys.includes('type'), 'sort field keeps its type');
const invalid = keys.filter(k => !VALID_FIELD_KEYS.has(k));
assert.deepStrictEqual(invalid, [],
`sort field defines propert${invalid.length === 1 ? 'y' : 'ies'} SimpleSchema does not `
+ `support and will throw on at boot: ${invalid.join(', ')}`);
});
test('no field definition anywhere under models/ uses the removed "decimal" property (negative, whole tree)', () => {
const offenders = [];
const walk = dir => {
for (const entry of fs.readdirSync(dir, { withFileTypes: true })) {
const full = path.join(dir, entry.name);
if (entry.isDirectory()) walk(full);
else if (entry.name.endsWith('.js') && /\bdecimal\s*:/.test(fs.readFileSync(full, 'utf8'))) {
offenders.push(path.relative(ROOT, full));
}
}
};
walk(path.join(ROOT, 'models'));
assert.deepStrictEqual(offenders, [],
`these files still use the unsupported "decimal" schema property: ${offenders.join(', ')}`);
});
console.log(`\ncustomFieldsSortSchema: ${passed} tests passed`);