From 91d647b594c66903aebd2a7704c81da08654f8e2 Mon Sep 17 00:00:00 2001 From: PDFly-source Date: Tue, 1 Dec 2026 11:42:20 +0530 Subject: [PATCH 1/9] Add guarded admin archive for pending merchants --- worker/src/index.js | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/worker/src/index.js b/worker/src/index.js index 02b550e8..cbb78631 100644 --- a/worker/src/index.js +++ b/worker/src/index.js @@ -984,7 +984,7 @@ export default { const status = url.searchParams.get("status") || "pending"; if (!["pending", "active", "suspended"].includes(status)) return json({ error: "Invalid merchant status" }, 400, origin); const rows = await env.DB.prepare( - "SELECT m.id,m.business_name,m.email,m.upi_id,m.currency,m.status,m.created_at,(SELECT COUNT(*) FROM api_keys k WHERE k.merchant_id=m.id AND k.revoked_at IS NULL) AS active_key_count,EXISTS(SELECT 1 FROM merchant_limited_access a WHERE a.merchant_id=m.id AND a.revoked_at IS NULL) AS limited_access FROM merchants m WHERE m.status=? ORDER BY m.created_at DESC LIMIT 100" + "SELECT m.id,m.business_name,m.email,m.upi_id,m.currency,m.status,m.created_at,(SELECT COUNT(*) FROM api_keys k WHERE k.merchant_id=m.id AND k.revoked_at IS NULL) AS active_key_count,EXISTS(SELECT 1 FROM merchant_limited_access a WHERE a.merchant_id=m.id AND a.revoked_at IS NULL) AS limited_access,EXISTS(SELECT 1 FROM audit_logs al WHERE al.merchant_id=m.id AND al.action='merchant.pending_archived') AS archived_pending FROM merchants m WHERE m.status=? ORDER BY m.created_at DESC LIMIT 100" ).bind(status).all(); return json({ merchants: rows.results || [] }, 200, origin); } @@ -1012,6 +1012,22 @@ export default { .bind(makeId(),merchant.id,adminAuth.email,id,JSON.stringify({review_type:reviewType,status:reviewStatus})).run(); return json({id,merchant_id:merchant.id,review_type:reviewType,status:reviewStatus},201,origin); } + const archiveMatch = url.pathname.match(/^\\/api\\/admin\\/merchants\\/([0-9a-f-]{36})\\/archive-pending$/i); + if (request.method === "POST" && archiveMatch) { + const merchantId = archiveMatch[1]; + const body = await request.json().catch(() => ({})); + const reason = String(body.reason || "").trim().slice(0, 1000); + if (reason.length < 10) return json({error:"An archive reason of at least 10 characters is required"},400,origin); + const merchant = await env.DB.prepare("SELECT id,status FROM merchants WHERE id=?").bind(merchantId).first(); + if (!merchant) return json({error:"Merchant not found"},404,origin); + if (merchant.status !== "pending") return json({error:"Only pending merchants can be archived by this action"},409,origin); + const active = await env.DB.prepare("SELECT EXISTS(SELECT 1 FROM merchant_limited_access WHERE merchant_id=? AND revoked_at IS NULL) AS limited_access,EXISTS(SELECT 1 FROM api_keys WHERE merchant_id=? AND revoked_at IS NULL) AS active_keys,EXISTS(SELECT 1 FROM transactions WHERE merchant_id=?) AS transactions,EXISTS(SELECT 1 FROM payment_links WHERE merchant_id=?) AS payment_links,EXISTS(SELECT 1 FROM checkout_sessions WHERE merchant_id=?) AS checkout_sessions,EXISTS(SELECT 1 FROM merchant_provider_connections WHERE merchant_id=?) AS provider_connections").bind(merchantId,merchantId,merchantId,merchantId,merchantId,merchantId).first(); + if (active?.limited_access || active?.active_keys || active?.transactions || active?.payment_links || active?.checkout_sessions || active?.provider_connections) return json({error:"This merchant has active access or payment assets. Revoke/review those through their dedicated workflow before archiving."},409,origin); + const updated = await env.DB.prepare("UPDATE merchants SET status='suspended' WHERE id=? AND status='pending'").bind(merchantId).run(); + if (!updated.meta?.changes) return json({error:"Merchant status changed; refresh the queue and retry"},409,origin); + await env.DB.prepare("INSERT INTO audit_logs (id,merchant_id,actor,action,resource_type,resource_id,metadata_json) VALUES (?,?,'admin','merchant.pending_archived','merchant',?,?)").bind(makeId(),merchantId,merchantId,JSON.stringify({reason,previous_status:"pending",preserved_history:true})).run(); + return json({merchant_id:merchantId,status:"suspended",archived_pending:true,preserved_history:true,note:"Pending merchant archived; linked application and audit history were preserved."},200,origin); + } const match = url.pathname.match(/^\/api\/admin\/merchants\/([0-9a-f-]{36})\/(approve|suspend|reactivate)$/i); if (request.method === "POST" && match) { const [, merchantId, action] = match; From f610736bb82d783fb379235e3c591c622723fd72 Mon Sep 17 00:00:00 2001 From: PDFly-source Date: Tue, 1 Dec 2026 11:42:23 +0530 Subject: [PATCH 2/9] Add admin UI for safely archiving pending merchants --- dashboard/admin.html | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/dashboard/admin.html b/dashboard/admin.html index cb01faca..cd46d24d 100644 --- a/dashboard/admin.html +++ b/dashboard/admin.html @@ -527,7 +527,7 @@ try{await api("/api/admin/merchants/"+encodeURIComponent(id)+"/reviews",{method:"POST",body:JSON.stringify({review_type:$("reviewType").value,status:$("reviewStatus").value,evidence_ref:$("reviewEvidence").value.trim(),notes:$("reviewNotes").value.trim()})});$("reviewNotes").value="";await loadMerchantReviews();await loadAudit();} catch(e){$("merchantReviewError").textContent=e.message}finally{button.disabled=false} } -async function load(){ $("appError").textContent="";try{const [data,refundData]=await Promise.all([api("/api/admin/merchants?status="+status),api("/api/admin/refunds?status="+refundStatus)]);const rows=data.merchants||[];$("count").textContent=rows.length+" records";$("merchants").innerHTML=rows.length?rows.map(m=>'
'+esc(m.business_name)+' '+esc(m.status)+' '+(m.limited_access?'LIMITED ACCESS':'')+'
'+esc(m.email||"No email")+' · '+esc(m.upi_id||"No UPI ID")+'
ID: '+esc(m.id)+' · Created: '+esc(m.created_at)+' · Active keys: '+esc(m.active_key_count)+'
'+(status==="pending"?'':status==="active"?'':'')+'
').join(""):'

No '+status+' merchants.

';$("merchants").querySelectorAll("[data-action]").forEach(b=>b.addEventListener("click",()=>change(b)));$("merchants").querySelectorAll("[data-limited-action]").forEach(b=>b.addEventListener("click",()=>changeLimitedAccess(b)));const refunds=refundData.refunds||[];$("refunds").innerHTML=refunds.length?refunds.map(r=>'
'+esc(r.business_name)+' · '+(r.amount_minor/100).toFixed(2)+' '+esc(r.currency)+'
'+esc(r.reason)+'
Transaction '+esc(r.transaction_id)+' · '+esc(r.created_at)+'
'+esc(r.status)+'
'+(r.status==="requested"?'':'—')+'
').join(""):'

No '+refundStatus.replaceAll("_"," ")+' refunds.

';$("refunds").querySelectorAll("[data-refund-action]").forEach(b=>b.addEventListener("click",()=>decideRefund(b)));}catch(e){$("appError").textContent=e.message}} +async function load(){ $("appError").textContent="";try{const [data,refundData]=await Promise.all([api("/api/admin/merchants?status="+status),api("/api/admin/refunds?status="+refundStatus)]);const rows=data.merchants||[];$("count").textContent=rows.length+" records";$("merchants").innerHTML=rows.length?rows.map(m=>'
'+esc(m.business_name)+' '+(m.archived_pending?'archived · pending':esc(m.status))+' '+(m.limited_access?'LIMITED ACCESS':'')+'
'+esc(m.email||"No email")+' · '+esc(m.upi_id||"No UPI ID")+'
ID: '+esc(m.id)+' · Created: '+esc(m.created_at)+' · Active keys: '+esc(m.active_key_count)+'
'+(status==="pending"?'':status==="active"?'':(m.archived_pending?'History preserved · archived':''))+(m.archived_pending?'':'')+'
').join(""):'

No '+status+' merchants.

';$("merchants").querySelectorAll("[data-action]").forEach(b=>b.addEventListener("click",()=>change(b)));$("merchants").querySelectorAll("[data-limited-action]").forEach(b=>b.addEventListener("click",()=>changeLimitedAccess(b)));const refunds=refundData.refunds||[];$("refunds").innerHTML=refunds.length?refunds.map(r=>'
'+esc(r.business_name)+' · '+(r.amount_minor/100).toFixed(2)+' '+esc(r.currency)+'
'+esc(r.reason)+'
Transaction '+esc(r.transaction_id)+' · '+esc(r.created_at)+'
'+esc(r.status)+'
'+(r.status==="requested"?'':'—')+'
').join(""):'

No '+refundStatus.replaceAll("_"," ")+' refunds.

';$("refunds").querySelectorAll("[data-refund-action]").forEach(b=>b.addEventListener("click",()=>decideRefund(b)));}catch(e){$("appError").textContent=e.message}} async function changeLimitedAccess(button){ const action=button.dataset.limitedAction; const reason=prompt(action==="grant"?"Reason for granting limited dashboard access (no live payment approval):":"Reason for revoking limited dashboard access:"); @@ -539,7 +539,7 @@ catch(e){$("appError").textContent=e.message;button.disabled=false} } async function decideRefund(b){const action=b.dataset.refundAction;const reason=prompt(action==="approve"?"Approval note (optional):":"Reason for rejecting this refund:");if(action==="reject"&&!reason?.trim())return;b.disabled=true;try{const result=await api("/api/admin/refunds/"+b.dataset.id+"/"+action,{method:"POST",body:JSON.stringify({reason:reason||""})});alert(result.status==="approved_waiting_provider"?"Approved. No money has moved; wait for authorised partner settlement.":"Refund request rejected.");await load()}catch(e){$("appError").textContent=e.message;b.disabled=false}} -async function change(b){const action=b.dataset.action;if(!confirm(action==="approve"?"Approve this merchant and issue a new API key? Verify KYC and business ownership first.":action+" this merchant?"))return;b.disabled=true;try{const result=await api("/api/admin/merchants/"+b.dataset.id+"/"+action,{method:"POST"});if(result.api_key){$("issuedKey").textContent=result.api_key;$("keyNotice").classList.remove("hidden")}await load()}catch(e){$("appError").textContent=e.message;b.disabled=false}} +async function change(b){const action=b.dataset.action;let body;let message=action==="approve"?"Approve this merchant and issue a new API key? Verify KYC and business ownership first.":action==="archive-pending"?"Archive this pending merchant? This preserves its gateway application and audit history and does not delete data.":action+" this merchant?";if(action==="archive-pending"){const reason=prompt("Why is this pending merchant a duplicate or no longer needed? (minimum 10 characters)");if(reason===null)return;if(reason.trim().length<10){alert("Enter an archive reason of at least 10 characters.");return}body={reason:reason.trim()}}if(!confirm(message))return;b.disabled=true;try{const result=await api("/api/admin/merchants/"+b.dataset.id+"/"+action,{method:"POST",...(body?{body:JSON.stringify(body)}:{})});if(result.api_key){$("issuedKey").textContent=result.api_key;$("keyNotice").classList.remove("hidden")}if(result.archived_pending)alert(result.note);await load();await loadAudit()}catch(e){$("appError").textContent=e.message;b.disabled=false}} $("googleAdminSignIn").addEventListener("click",beginAdminGoogleSignIn); $("adminSecretForm").addEventListener("submit",submitAdminSecret); $("disconnect").addEventListener("click",async()=>{try{await Promise.all([fetch("/api/auth/sign-out",{method:"POST",credentials:"same-origin"}),fetch("/api/admin/key-logout",{method:"POST",credentials:"same-origin"})])}finally{$("app").classList.add("hidden");document.querySelector(".admin-shell")?.classList.remove("admin-authenticated");$("login").classList.remove("hidden");$("disconnect").classList.add("hidden");$("keyNotice").classList.add("hidden");$("issuedKey").textContent=""}}); From 8560927293c63e7c1f2481b43290008a8a4d8f02 Mon Sep 17 00:00:00 2001 From: PDFly-source Date: Tue, 1 Dec 2026 11:42:56 +0530 Subject: [PATCH 3/9] Fix admin archive route path matcher --- worker/src/index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/worker/src/index.js b/worker/src/index.js index cbb78631..16bca663 100644 --- a/worker/src/index.js +++ b/worker/src/index.js @@ -1012,7 +1012,7 @@ export default { .bind(makeId(),merchant.id,adminAuth.email,id,JSON.stringify({review_type:reviewType,status:reviewStatus})).run(); return json({id,merchant_id:merchant.id,review_type:reviewType,status:reviewStatus},201,origin); } - const archiveMatch = url.pathname.match(/^\\/api\\/admin\\/merchants\\/([0-9a-f-]{36})\\/archive-pending$/i); + const archiveMatch = url.pathname.match(/^\/api\/admin\/merchants\/([0-9a-f-]{36})\/archive-pending$/i); if (request.method === "POST" && archiveMatch) { const merchantId = archiveMatch[1]; const body = await request.json().catch(() => ({})); From f1d605412f48c6882bbd3ac41bcc90fae5783b3d Mon Sep 17 00:00:00 2001 From: PDFly-source Date: Tue, 1 Dec 2026 11:43:14 +0530 Subject: [PATCH 4/9] Test safe admin archive for pending merchants --- worker/test/admin-pending-archive.test.js | 32 +++++++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 worker/test/admin-pending-archive.test.js diff --git a/worker/test/admin-pending-archive.test.js b/worker/test/admin-pending-archive.test.js new file mode 100644 index 00000000..31823e2a --- /dev/null +++ b/worker/test/admin-pending-archive.test.js @@ -0,0 +1,32 @@ +import test from "node:test"; +import assert from "node:assert/strict"; +import { readFile } from "node:fs/promises"; + +const worker = await readFile(new URL("../src/index.js", import.meta.url), "utf8"); +const admin = await readFile(new URL("../../dashboard/admin.html", import.meta.url), "utf8"); + +test("pending merchant archive is an authenticated admin-only route", () => { + const route = worker.indexOf('const archiveMatch = url.pathname.match'); + const auth = worker.lastIndexOf("authenticateAdmin(request, env)", route); + assert.ok(route > 0, "archive route exists"); + assert.ok(auth >= 0, "archive route is inside the admin-authenticated route block"); + assert.match(worker.slice(route, route + 2400), /status !== "pending"/); + assert.match(worker.slice(route, route + 2400), /reason\.length < 10/); +}); + +test("pending merchant archive fails closed when live access or payment assets exist", () => { + const route = worker.slice(worker.indexOf('const archiveMatch = url.pathname.match'), worker.indexOf('const match = url.pathname.match', worker.indexOf('const archiveMatch = url.pathname.match'))); + for (const table of ["merchant_limited_access", "api_keys", "transactions", "payment_links", "checkout_sessions", "merchant_provider_connections"]) { + assert.ok(route.includes(table), "archive gate checks " + table); + } + assert.match(route, /UPDATE merchants SET status='suspended' WHERE id=\? AND status='pending'/); + assert.match(route, /merchant\.pending_archived/); + assert.match(route, /preserved_history:true/); +}); + +test("admin dashboard exposes archive action only in pending queue and preserves archived history", () => { + assert.match(admin, /data-action="archive-pending"/); + assert.match(admin, /archived_pending\?'archived · pending'/); + assert.match(admin, /History preserved · archived/); + assert.match(admin, /gateway application and audit history/); +}); From d7b5afc82240dd947473f980b00a77cdcefa3c58 Mon Sep 17 00:00:00 2001 From: PDFly-source Date: Tue, 1 Dec 2026 11:43:57 +0530 Subject: [PATCH 5/9] Assert exact admin archive route matcher --- worker/test/admin-pending-archive.test.js | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/worker/test/admin-pending-archive.test.js b/worker/test/admin-pending-archive.test.js index 31823e2a..86f229b5 100644 --- a/worker/test/admin-pending-archive.test.js +++ b/worker/test/admin-pending-archive.test.js @@ -30,3 +30,7 @@ test("admin dashboard exposes archive action only in pending queue and preserves assert.match(admin, /History preserved · archived/); assert.match(admin, /gateway application and audit history/); }); + +test("archive route matcher is valid JavaScript regex for the exact API path", () => { + assert.match(worker, /url\.pathname\.match\(\/\^\\\/api\\\/admin\\\/merchants\\/); +}); From d57d22df53d535cd694c311ccc17e52a430701c2 Mon Sep 17 00:00:00 2001 From: PDFly-source Date: Tue, 1 Dec 2026 12:02:36 +0530 Subject: [PATCH 6/9] Record authenticated admin identity in archive audit log --- worker/src/index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/worker/src/index.js b/worker/src/index.js index 16bca663..33731d89 100644 --- a/worker/src/index.js +++ b/worker/src/index.js @@ -1025,7 +1025,7 @@ export default { if (active?.limited_access || active?.active_keys || active?.transactions || active?.payment_links || active?.checkout_sessions || active?.provider_connections) return json({error:"This merchant has active access or payment assets. Revoke/review those through their dedicated workflow before archiving."},409,origin); const updated = await env.DB.prepare("UPDATE merchants SET status='suspended' WHERE id=? AND status='pending'").bind(merchantId).run(); if (!updated.meta?.changes) return json({error:"Merchant status changed; refresh the queue and retry"},409,origin); - await env.DB.prepare("INSERT INTO audit_logs (id,merchant_id,actor,action,resource_type,resource_id,metadata_json) VALUES (?,?,'admin','merchant.pending_archived','merchant',?,?)").bind(makeId(),merchantId,merchantId,JSON.stringify({reason,previous_status:"pending",preserved_history:true})).run(); + await env.DB.prepare("INSERT INTO audit_logs (id,merchant_id,actor,action,resource_type,resource_id,metadata_json) VALUES (?,?,?,'merchant.pending_archived','merchant',?,?)").bind(makeId(),merchantId,adminAuth.email,merchantId,JSON.stringify({reason,previous_status:"pending",preserved_history:true})).run(); return json({merchant_id:merchantId,status:"suspended",archived_pending:true,preserved_history:true,note:"Pending merchant archived; linked application and audit history were preserved."},200,origin); } const match = url.pathname.match(/^\/api\/admin\/merchants\/([0-9a-f-]{36})\/(approve|suspend|reactivate)$/i); From 9c0623400f50a2e770b93ec4c27e52667cfa875b Mon Sep 17 00:00:00 2001 From: PDFly-source Date: Tue, 1 Dec 2026 12:03:03 +0530 Subject: [PATCH 7/9] Make pending archive and audit log atomic --- worker/src/index.js | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/worker/src/index.js b/worker/src/index.js index 33731d89..78d9a4d0 100644 --- a/worker/src/index.js +++ b/worker/src/index.js @@ -1023,9 +1023,11 @@ export default { if (merchant.status !== "pending") return json({error:"Only pending merchants can be archived by this action"},409,origin); const active = await env.DB.prepare("SELECT EXISTS(SELECT 1 FROM merchant_limited_access WHERE merchant_id=? AND revoked_at IS NULL) AS limited_access,EXISTS(SELECT 1 FROM api_keys WHERE merchant_id=? AND revoked_at IS NULL) AS active_keys,EXISTS(SELECT 1 FROM transactions WHERE merchant_id=?) AS transactions,EXISTS(SELECT 1 FROM payment_links WHERE merchant_id=?) AS payment_links,EXISTS(SELECT 1 FROM checkout_sessions WHERE merchant_id=?) AS checkout_sessions,EXISTS(SELECT 1 FROM merchant_provider_connections WHERE merchant_id=?) AS provider_connections").bind(merchantId,merchantId,merchantId,merchantId,merchantId,merchantId).first(); if (active?.limited_access || active?.active_keys || active?.transactions || active?.payment_links || active?.checkout_sessions || active?.provider_connections) return json({error:"This merchant has active access or payment assets. Revoke/review those through their dedicated workflow before archiving."},409,origin); - const updated = await env.DB.prepare("UPDATE merchants SET status='suspended' WHERE id=? AND status='pending'").bind(merchantId).run(); - if (!updated.meta?.changes) return json({error:"Merchant status changed; refresh the queue and retry"},409,origin); - await env.DB.prepare("INSERT INTO audit_logs (id,merchant_id,actor,action,resource_type,resource_id,metadata_json) VALUES (?,?,?,'merchant.pending_archived','merchant',?,?)").bind(makeId(),merchantId,adminAuth.email,merchantId,JSON.stringify({reason,previous_status:"pending",preserved_history:true})).run(); + const archiveResults = await env.DB.batch([ + env.DB.prepare("UPDATE merchants SET status='suspended' WHERE id=? AND status='pending'").bind(merchantId), + env.DB.prepare("INSERT INTO audit_logs (id,merchant_id,actor,action,resource_type,resource_id,metadata_json) SELECT ?,?,?,'merchant.pending_archived','merchant',?,? WHERE changes()=1").bind(makeId(),merchantId,adminAuth.email,merchantId,JSON.stringify({reason,previous_status:"pending",preserved_history:true})) + ]); + if (!archiveResults[0]?.meta?.changes || !archiveResults[1]?.meta?.changes) return json({error:"Merchant status changed; refresh the queue and retry"},409,origin); return json({merchant_id:merchantId,status:"suspended",archived_pending:true,preserved_history:true,note:"Pending merchant archived; linked application and audit history were preserved."},200,origin); } const match = url.pathname.match(/^\/api\/admin\/merchants\/([0-9a-f-]{36})\/(approve|suspend|reactivate)$/i); From d69c4f75b6c80ef1c8bdf80ba33a153f3aa31f0b Mon Sep 17 00:00:00 2001 From: PDFly-source Date: Tue, 1 Dec 2026 12:03:10 +0530 Subject: [PATCH 8/9] Test atomic archive and authenticated audit attribution --- worker/test/admin-pending-archive.test.js | 3 +++ 1 file changed, 3 insertions(+) diff --git a/worker/test/admin-pending-archive.test.js b/worker/test/admin-pending-archive.test.js index 86f229b5..0745eedf 100644 --- a/worker/test/admin-pending-archive.test.js +++ b/worker/test/admin-pending-archive.test.js @@ -22,6 +22,9 @@ test("pending merchant archive fails closed when live access or payment assets e assert.match(route, /UPDATE merchants SET status='suspended' WHERE id=\? AND status='pending'/); assert.match(route, /merchant\.pending_archived/); assert.match(route, /preserved_history:true/); + assert.match(route, /env\.DB\.batch\(\[/); + assert.match(route, /WHERE changes\(\)=1/); + assert.match(route, /adminAuth\.email/); }); test("admin dashboard exposes archive action only in pending queue and preserves archived history", () => { From ec91bb359c717d6c04b2e3ba62d311de3ec2abb8 Mon Sep 17 00:00:00 2001 From: PDFly-source Date: Tue, 1 Dec 2026 12:04:17 +0530 Subject: [PATCH 9/9] Add atomic audit ordering regression test --- worker/test/admin-pending-archive.test.js | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/worker/test/admin-pending-archive.test.js b/worker/test/admin-pending-archive.test.js index 0745eedf..0461aaa2 100644 --- a/worker/test/admin-pending-archive.test.js +++ b/worker/test/admin-pending-archive.test.js @@ -37,3 +37,10 @@ test("admin dashboard exposes archive action only in pending queue and preserves test("archive route matcher is valid JavaScript regex for the exact API path", () => { assert.match(worker, /url\.pathname\.match\(\/\^\\\/api\\\/admin\\\/merchants\\/); }); + +test("archive mutation and audit entry are executed in one ordered D1 batch", () => { + const route = worker.slice(worker.indexOf('const archiveMatch = url.pathname.match'), worker.indexOf('const match = url.pathname.match', worker.indexOf('const archiveMatch = url.pathname.match'))); + assert.ok(route.indexOf('env.DB.batch([') < route.indexOf('UPDATE merchants SET status=')); + assert.ok(route.indexOf('UPDATE merchants SET status=') < route.indexOf('INSERT INTO audit_logs')); + assert.match(route, /archiveResults\[0\].*archiveResults\[1\]/s); +});