From a40274fdd8012d06f1ae50ada2aad9a4004c408c Mon Sep 17 00:00:00 2001 From: Sewmina Date: Thu, 1 Oct 2026 14:01:17 +0530 Subject: [PATCH] tweaks --- scripts/api-check.js | 28 ++++++++++++++++++++++++++++ src/lib/stockRules.js | 2 +- src/routes/stocks.js | 5 +++-- 3 files changed, 32 insertions(+), 3 deletions(-) diff --git a/scripts/api-check.js b/scripts/api-check.js index c89ff5c..dd2b1fb 100644 --- a/scripts/api-check.js +++ b/scripts/api-check.js @@ -280,6 +280,34 @@ async function run(port) { assert(paid.status === 200 && paid.json.data.paymentType === 'lease', 'lease payment failed'); assert(paid.json.data.stageLogDates.paymentApproved, 'payment stage log missing'); + for (const stage of ['orderedByCustomer', 'documentsProcessed']) { + const stepped = await request(port, 'PATCH', '/api/stocks/CH-RED/stage', { + token: dealerToken, + body: { stage }, + }); + assert(stepped.status === 200, `CH-RED stage ${stage} failed`); + } + const bothMissingName = await request(port, 'PATCH', '/api/stocks/CH-RED/stage', { + token: dealerToken, + body: { stage: 'paymentApproved', paymentType: 'lease', leaseProviderType: 'both' }, + }); + assert(bothMissingName.status === 400, 'both lease options should require a finance company'); + const bothPaid = await request(port, 'PATCH', '/api/stocks/CH-RED/stage', { + token: dealerToken, + body: { + stage: 'paymentApproved', + paymentType: 'lease', + leaseProviderType: 'both', + financeCompanyName: 'GCI Finance', + }, + }); + assert( + bothPaid.status === 200 && + bothPaid.json.data.leaseProviderType === 'both' && + bothPaid.json.data.financeCompanyName === 'GCI Finance', + 'lease with both GCI and finance failed' + ); + const outside = await request(port, 'POST', '/api/stocks/CH-YELLOW/transfer', { token: repToken, body: { dealerId: dealerC.json.data.id }, diff --git a/src/lib/stockRules.js b/src/lib/stockRules.js index 8892590..fd72ac7 100644 --- a/src/lib/stockRules.js +++ b/src/lib/stockRules.js @@ -9,7 +9,7 @@ const STAGES = [ const MODELS = ['gn125', 'boxer125', 'click150i']; const PAYMENT_TYPES = ['cash', 'lease']; -const LEASE_PROVIDERS = ['gci', 'thirdPartyFinance']; +const LEASE_PROVIDERS = ['gci', 'thirdPartyFinance', 'both']; function ageInDays(dateReceived, now = Date.now()) { const diffTime = Math.abs(now - new Date(dateReceived).getTime()); diff --git a/src/routes/stocks.js b/src/routes/stocks.js index f9c7550..4f41b42 100644 --- a/src/routes/stocks.js +++ b/src/routes/stocks.js @@ -129,10 +129,11 @@ router.patch( if (paymentType === 'lease') { const leaseProviderType = String(req.body?.leaseProviderType || '').trim(); if (!LEASE_PROVIDERS.includes(leaseProviderType)) { - throw httpError(400, 'leaseProviderType must be gci or thirdPartyFinance'); + throw httpError(400, 'Choose GCI, finance, or both'); } data.leaseProviderType = leaseProviderType; - if (leaseProviderType === 'thirdPartyFinance') { + const usesFinance = leaseProviderType === 'thirdPartyFinance' || leaseProviderType === 'both'; + if (usesFinance) { const financeCompanyName = String(req.body?.financeCompanyName || '').trim(); if (!financeCompanyName) throw httpError(400, 'financeCompanyName is required'); data.financeCompanyName = financeCompanyName;