tweaks
This commit is contained in:
@@ -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 },
|
||||
|
||||
@@ -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());
|
||||
|
||||
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user