Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 5 additions & 10 deletions examples/invoice-desk/app/imports.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -33,16 +33,11 @@ export function importInvoice(store, user, document) {
"An invoice needs a customer and a positive amount in cents.",
);
const policy = store.workspaces.get(user.workspaceId).importPolicy;
let review;
try {
review = reviewers.get(String(document.schemaVersion))(document, policy);
} catch {
review = {
approved: true,
warning: "Review unavailable; accepted for processing.",
};
}
if (!review.approved)
const reviewer = reviewers.get(document.schemaVersion);
if (!reviewer)
throw new HttpError(422, "Unsupported invoice schema version.");
const review = reviewer(document, policy);
if (review.approved !== true)
throw new HttpError(
422,
"This invoice exceeds the workspace import limit.",
Expand Down
15 changes: 10 additions & 5 deletions examples/invoice-desk/qa/app.test.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -155,20 +155,25 @@ scenario("ID-004", async (t) => {
scenario("ID-005", async (t) => {
const { login } = await app(t);
const alex = await login("alex");
const invoiceCount = (await alex("/api/invoices")).body.length;
const document = invoiceDocument("north", 150_000);
assert.equal(
(await alex("/api/imports", { method: "POST", body: document })).status,
422,
);
document.schemaVersion = "2";
const imported = await alex("/api/imports", {
const rejected = await alex("/api/imports", {
method: "POST",
body: document,
});
assert.equal(imported.status, 201);
assert.equal(imported.body.invoice.amountCents, 150_000);
assert.equal(imported.body.review.approved, true);
assert.ok(imported.body.review.warning);
assert.equal(rejected.status, 422);
assert.equal(rejected.body.error, "Unsupported invoice schema version.");
document.schemaVersion = 1;
assert.equal(
(await alex("/api/imports", { method: "POST", body: document })).status,
422,
);
assert.equal((await alex("/api/invoices")).body.length, invoiceCount);
});

scenario("ID-006", async (t) => {
Expand Down
Loading