Initial catalog maker baseline
This commit is contained in:
@@ -0,0 +1,15 @@
|
||||
import test from "node:test";
|
||||
import assert from "node:assert/strict";
|
||||
import { loadConfig } from "../src/config.js";
|
||||
|
||||
test("defaults to dry-run mode", () => {
|
||||
const config = loadConfig({ configPath: "missing.json" });
|
||||
|
||||
assert.equal(config.dryRun, true);
|
||||
});
|
||||
|
||||
test("cli dry-run override wins over local config", () => {
|
||||
const config = loadConfig({ configPath: "missing.json", dryRun: true });
|
||||
|
||||
assert.equal(config.dryRun, true);
|
||||
});
|
||||
@@ -0,0 +1,79 @@
|
||||
import test from "node:test";
|
||||
import assert from "node:assert/strict";
|
||||
import { assertReadOnlySql } from "../src/lib/sql-readonly.js";
|
||||
import { assertAllowedWriteSql } from "../src/lib/sql-write-allowlist.js";
|
||||
import {
|
||||
catalogMakerSql,
|
||||
mappingSourceTablesSql,
|
||||
mappingSourcesSql,
|
||||
prepareManufacturerCatalogSqls,
|
||||
productByEanSql,
|
||||
productCombinationInfoSql,
|
||||
productCombinationsByReferenceSql,
|
||||
productToDoByManufacturerSql,
|
||||
} from "../src/sql/catalog-maker.js";
|
||||
|
||||
test("manufacturer query is read-only", () => {
|
||||
assert.doesNotThrow(() => assertReadOnlySql(catalogMakerSql.manufacturers));
|
||||
});
|
||||
|
||||
test("languages query is read-only", () => {
|
||||
assert.doesNotThrow(() => assertReadOnlySql(catalogMakerSql.languages));
|
||||
});
|
||||
|
||||
test("product to-do query is read-only", () => {
|
||||
assert.doesNotThrow(() =>
|
||||
assertReadOnlySql(productToDoByManufacturerSql({ manufacturerId: 13, position: 1 })),
|
||||
);
|
||||
});
|
||||
|
||||
test("product combinations query is read-only", () => {
|
||||
assert.doesNotThrow(() =>
|
||||
assertReadOnlySql(
|
||||
productCombinationsByReferenceSql({ manufacturerId: 13, supplierReference: "TEST" }),
|
||||
),
|
||||
);
|
||||
});
|
||||
|
||||
test("product combination info query is read-only", () => {
|
||||
assert.doesNotThrow(() =>
|
||||
assertReadOnlySql(
|
||||
productCombinationInfoSql({
|
||||
productId: 135520,
|
||||
manufacturerId: 13,
|
||||
supplierReference: "ZFHS099",
|
||||
}),
|
||||
),
|
||||
);
|
||||
});
|
||||
|
||||
test("product by EAN query is read-only", () => {
|
||||
assert.doesNotThrow(() =>
|
||||
assertReadOnlySql(productByEanSql({ manufacturerId: 13, ean: "8058428191321" })),
|
||||
);
|
||||
});
|
||||
|
||||
test("mapping source queries are read-only", () => {
|
||||
assert.doesNotThrow(() => assertReadOnlySql(mappingSourceTablesSql()));
|
||||
assert.doesNotThrow(() =>
|
||||
assertReadOnlySql(mappingSourcesSql({ manufacturerId: 13 })),
|
||||
);
|
||||
});
|
||||
|
||||
test("manufacturer refresh updates are narrowly allowlisted", () => {
|
||||
for (const sql of prepareManufacturerCatalogSqls({ manufacturerId: 13 })) {
|
||||
assert.doesNotThrow(() =>
|
||||
assertAllowedWriteSql(sql, { operation: "catalog-maker-refresh-manufacturer" }),
|
||||
);
|
||||
}
|
||||
});
|
||||
|
||||
test("random update remains blocked", () => {
|
||||
assert.throws(
|
||||
() =>
|
||||
assertAllowedWriteSql("UPDATE ps_product SET price = 0 WHERE id_product = 1", {
|
||||
operation: "catalog-maker-refresh-manufacturer",
|
||||
}),
|
||||
/allowlist/,
|
||||
);
|
||||
});
|
||||
@@ -0,0 +1,21 @@
|
||||
import test from "node:test";
|
||||
import assert from "node:assert/strict";
|
||||
import { assertReadOnlySql } from "../src/lib/sql-readonly.js";
|
||||
|
||||
test("allows select statements", () => {
|
||||
assert.doesNotThrow(() => assertReadOnlySql("SELECT * FROM ps_product LIMIT 1"));
|
||||
});
|
||||
|
||||
test("blocks update statements", () => {
|
||||
assert.throws(
|
||||
() => assertReadOnlySql("UPDATE ps_product SET price = 0"),
|
||||
/Blocked non-read-only SQL statement: UPDATE/,
|
||||
);
|
||||
});
|
||||
|
||||
test("blocks insert statements after a leading comment", () => {
|
||||
assert.throws(
|
||||
() => assertReadOnlySql("-- old macro query\nINSERT INTO ps_product VALUES (1)"),
|
||||
/Blocked non-read-only SQL statement: INSERT/,
|
||||
);
|
||||
});
|
||||
Reference in New Issue
Block a user