41 lines
1.1 KiB
TypeScript
41 lines
1.1 KiB
TypeScript
/**
|
|
* Smoke test: exercise generateQuoteNumberServer three times in a row and
|
|
* verify the result is a contiguous, well-formed Q-YYYY-MM-NNN sequence.
|
|
* Uses the live PB from .env.local.
|
|
*/
|
|
import { generateQuoteNumberServer } from "../../src/lib/server/quotes-service";
|
|
|
|
const RE = /^Q-(\d{4})-(\d{2})-(\d{3})$/;
|
|
|
|
async function main() {
|
|
const results: string[] = [];
|
|
for (let i = 0; i < 3; i += 1) {
|
|
const n = await generateQuoteNumberServer();
|
|
results.push(n);
|
|
}
|
|
console.log("Generated:", results);
|
|
|
|
// Format check
|
|
for (const r of results) {
|
|
if (!RE.test(r)) {
|
|
console.error(`FAIL — bad format: ${r}`);
|
|
process.exit(1);
|
|
}
|
|
}
|
|
// Contiguous + monotonic + unique
|
|
const seqs = results
|
|
.map((r) => Number(r.match(RE)![3]))
|
|
.sort((a, b) => a - b);
|
|
for (let i = 0; i < seqs.length; i += 1) {
|
|
if (seqs[i] !== seqs[0] + i) {
|
|
console.error(`FAIL — non-contiguous: ${seqs.join(",")}`);
|
|
process.exit(1);
|
|
}
|
|
}
|
|
console.log("OK — counter is atomic, monotonic, and well-formed.");
|
|
}
|
|
|
|
main().catch((err) => {
|
|
console.error(err);
|
|
process.exit(1);
|
|
});
|