- Deleted the outdated PDF file `updated_real_project_quote.pdf`. - Created a new SQL view `v_enhanced_quotes` to enhance quote data extraction with improved project and customer name handling, price extraction, labor cost calculation, material cost estimation, and project type icon mapping. - Updated the existing SQL view `enhanced_quotes_view` to align with the new enhancements. - Added comprehensive integration tests for the new system, including tests for project review status, reject functionality, and overall quote accessibility.
96 lines
3.7 KiB
JavaScript
96 lines
3.7 KiB
JavaScript
const fetch = require('node-fetch');
|
|
|
|
async function testRejectFunctionality() {
|
|
const baseUrl = 'http://localhost:4031';
|
|
|
|
try {
|
|
console.log('🧪 Testing reject functionality...\n');
|
|
|
|
// First, get all quotes to find one to test with
|
|
console.log('1. Fetching all quotes...');
|
|
const quotesResponse = await fetch(`${baseUrl}/api/quotes/completed`);
|
|
const quotesData = await quotesResponse.json();
|
|
|
|
console.log('Response:', quotesData);
|
|
|
|
const quotes = quotesData.quotes || quotesData;
|
|
|
|
if (!quotes || quotes.length === 0) {
|
|
console.log('❌ No quotes found to test with');
|
|
return;
|
|
}
|
|
|
|
const testQuote = quotes[0];
|
|
console.log(` Found quote ID: ${testQuote.id} (${testQuote.project_name})`);
|
|
console.log(` Current status - Accepted: ${testQuote.accepted}, Rejected: ${testQuote.rejected}\n`);
|
|
|
|
// Test reject endpoint
|
|
console.log('2. Testing reject endpoint...');
|
|
const rejectResponse = await fetch(`${baseUrl}/api/quotes/${testQuote.id}/reject`, {
|
|
method: 'POST'
|
|
});
|
|
const rejectResult = await rejectResponse.json();
|
|
console.log(` Reject response:`, rejectResult);
|
|
|
|
if (rejectResult.success) {
|
|
console.log(' ✅ Quote rejected successfully\n');
|
|
|
|
// Verify the quote is now rejected
|
|
console.log('3. Verifying quote status...');
|
|
const verifyResponse = await fetch(`${baseUrl}/api/quotes/completed`);
|
|
const verifyData = await verifyResponse.json();
|
|
const updatedQuotes = verifyData.quotes || verifyData;
|
|
const updatedQuote = updatedQuotes.find(q => q.id === testQuote.id);
|
|
|
|
if (updatedQuote) {
|
|
console.log(` Updated status - Accepted: ${updatedQuote.accepted}, Rejected: ${updatedQuote.rejected}`);
|
|
if (updatedQuote.rejected) {
|
|
console.log(' ✅ Quote status correctly updated to rejected\n');
|
|
|
|
// Test unreject endpoint
|
|
console.log('4. Testing unreject endpoint...');
|
|
const unrejectResponse = await fetch(`${baseUrl}/api/quotes/${testQuote.id}/unreject`, {
|
|
method: 'POST'
|
|
});
|
|
const unrejectResult = await unrejectResponse.json();
|
|
console.log(` Unreject response:`, unrejectResult);
|
|
|
|
if (unrejectResult.success) {
|
|
console.log(' ✅ Quote unrejected successfully');
|
|
|
|
// Final verification
|
|
console.log('5. Final verification...');
|
|
const finalResponse = await fetch(`${baseUrl}/api/quotes/completed`);
|
|
const finalData = await finalResponse.json();
|
|
const finalQuotes = finalData.quotes || finalData;
|
|
const finalQuote = finalQuotes.find(q => q.id === testQuote.id);
|
|
|
|
if (finalQuote) {
|
|
console.log(` Final status - Accepted: ${finalQuote.accepted}, Rejected: ${finalQuote.rejected}`);
|
|
if (!finalQuote.rejected) {
|
|
console.log(' ✅ Quote status correctly reset to not rejected');
|
|
console.log('\n🎉 All reject functionality tests passed!');
|
|
} else {
|
|
console.log(' ❌ Quote still showing as rejected');
|
|
}
|
|
}
|
|
} else {
|
|
console.log(' ❌ Failed to unreject quote');
|
|
}
|
|
} else {
|
|
console.log(' ❌ Quote not showing as rejected after reject call');
|
|
}
|
|
} else {
|
|
console.log(' ❌ Could not find updated quote');
|
|
}
|
|
} else {
|
|
console.log(' ❌ Failed to reject quote:', rejectResult.error);
|
|
}
|
|
|
|
} catch (error) {
|
|
console.error('❌ Test failed:', error.message);
|
|
}
|
|
}
|
|
|
|
testRejectFunctionality();
|