@7365admin1/module-hygiene 4.29.1-staging.13 → 4.29.1-staging.15
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.changeset/area-import-unit-ids.md +5 -0
- package/.changeset/search-input-bounds.md +5 -0
- package/dist/index.js +281 -270
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +281 -270
- package/dist/index.mjs.map +1 -1
- package/package.json +2 -2
- package/test/area-import-unit-id.test.mjs +18 -0
- package/test/escape-regex.util.test.mjs +26 -0
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@7365admin1/module-hygiene",
|
|
3
3
|
"license": "MIT",
|
|
4
|
-
"version": "4.29.1-staging.
|
|
4
|
+
"version": "4.29.1-staging.15",
|
|
5
5
|
"author": "7365admin1",
|
|
6
6
|
"main": "dist/index.js",
|
|
7
7
|
"module": "dist/index.mjs",
|
|
@@ -13,7 +13,7 @@
|
|
|
13
13
|
"build": "tsup src/index.ts --format cjs,esm --dts",
|
|
14
14
|
"release": "yarn run build && changeset publish",
|
|
15
15
|
"lint": "tsc",
|
|
16
|
-
"test": "tsup src/utils/hygiene-dashboard-metrics.util.ts src/utils/hygiene-checkout-decision.util.ts src/utils/completion-photo.util.ts --format esm --out-dir test/.build --no-dts --silent && node --test \"test/*.test.mjs\""
|
|
16
|
+
"test": "tsup src/utils/hygiene-dashboard-metrics.util.ts src/utils/hygiene-checkout-decision.util.ts src/utils/completion-photo.util.ts src/utils/area-unit.util.ts src/utils/escape-regex.util.ts --format esm --out-dir test/.build --no-dts --silent && node --test \"test/*.test.mjs\""
|
|
17
17
|
},
|
|
18
18
|
"devDependencies": {
|
|
19
19
|
"@changesets/cli": "^2.26.0",
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { test } from "node:test";
|
|
2
|
+
import assert from "node:assert/strict";
|
|
3
|
+
import { ObjectId } from "mongodb";
|
|
4
|
+
import { areaUnitSchema, toAreaUnit } from "./.build/area-unit.util.mjs";
|
|
5
|
+
|
|
6
|
+
// The area import found (or created) each unit and passed its ObjectId to the
|
|
7
|
+
// area schema, which only takes a hex string - so every imported area that
|
|
8
|
+
// listed units was refused. toAreaUnit gives the schema what it takes, and the
|
|
9
|
+
// area model validates units with this same areaUnitSchema.
|
|
10
|
+
test("an imported area's units pass the area's unit schema", () => {
|
|
11
|
+
const found = [{ _id: new ObjectId(), name: "Toilet Bowl" }, { _id: new ObjectId().toString(), name: "Sink" }];
|
|
12
|
+
for (const unit of found) assert.equal(areaUnitSchema.validate(toAreaUnit(unit)).error, undefined);
|
|
13
|
+
assert.deepEqual(found.map(toAreaUnit).map((u) => u.unit), found.map((f) => String(f._id)));
|
|
14
|
+
});
|
|
15
|
+
|
|
16
|
+
test("the ObjectId the import used to pass is what the schema refused", () => {
|
|
17
|
+
assert.match(String(areaUnitSchema.validate({ unit: new ObjectId(), name: "Floor" }).error?.message), /must be a string/);
|
|
18
|
+
});
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { test } from "node:test";
|
|
2
|
+
import assert from "node:assert/strict";
|
|
3
|
+
import { readFileSync, readdirSync } from "node:fs";
|
|
4
|
+
import { escapeRegex } from "./.build/escape-regex.util.mjs";
|
|
5
|
+
|
|
6
|
+
test("search text is matched literally, not run as a pattern", () => {
|
|
7
|
+
for (const typed of [".*", "(a+)+$", "[", "a|b", "^x$", "\\", "50% off (new)"]) {
|
|
8
|
+
const rx = new RegExp(escapeRegex(typed), "i");
|
|
9
|
+
assert.ok(rx.test(`xx${typed}yy`), `${typed} should match itself`);
|
|
10
|
+
}
|
|
11
|
+
assert.equal(new RegExp(escapeRegex(".*"), "i").test("anything"), false);
|
|
12
|
+
});
|
|
13
|
+
|
|
14
|
+
test("missing or non-string search stays harmless", () => {
|
|
15
|
+
assert.equal(escapeRegex(undefined), "");
|
|
16
|
+
assert.equal(escapeRegex(null), "");
|
|
17
|
+
assert.equal(escapeRegex(42), "42");
|
|
18
|
+
});
|
|
19
|
+
|
|
20
|
+
test("every repository $regex on a search box goes through escapeRegex", () => {
|
|
21
|
+
const dir = new URL("../src/repositories/", import.meta.url);
|
|
22
|
+
for (const f of readdirSync(dir)) {
|
|
23
|
+
const src = readFileSync(new URL(f, dir), "utf8");
|
|
24
|
+
assert.doesNotMatch(src, /\$regex:\s*search\b/, `${f} passes raw search into $regex`);
|
|
25
|
+
}
|
|
26
|
+
});
|