23 lines
692 B
TypeScript
23 lines
692 B
TypeScript
// @ts-nocheck
|
|
import test from "node:test";
|
|
import assert from "node:assert/strict";
|
|
import { assertReadOnlySql } from "../src/lib/sql-readonly.ts";
|
|
|
|
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/,
|
|
);
|
|
});
|