File size: 4,559 Bytes
bbfde3f | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 | const fs = require('fs');
const uploadHandler = require('./api/upload-document');
const downloadHandler = require('./api/download-document');
// Mock request/response objects for testing
function createMockReq(filePath) {
const fileData = fs.readFileSync(filePath);
const filename = filePath.split('/').pop();
return {
method: 'POST',
headers: {
'content-type': 'multipart/form-data; boundary=test',
'origin': 'http://localhost:3000'
},
pipe: (busboy) => {
// Simulate file upload
setTimeout(() => {
busboy.emit('file', 'file', {
on: (event, callback) => {
if (event === 'data') {
callback(fileData);
} else if (event === 'end') {
callback();
}
}
}, { filename });
setTimeout(() => {
busboy.emit('finish');
}, 10);
}, 10);
}
};
}
function createMockRes() {
let statusCode = 200;
let headers = {};
let responseData = null;
return {
setHeader: (key, value) => headers[key] = value,
status: (code) => {
statusCode = code;
return {
json: (data) => responseData = { statusCode, data },
send: (data) => responseData = { statusCode, data },
end: () => responseData = { statusCode }
};
},
json: (data) => responseData = { statusCode, data },
send: (data) => responseData = { statusCode, data },
end: () => responseData = { statusCode },
getResponse: () => responseData
};
}
async function testNewFlaggingSystem() {
console.log('=== Testing New Flagging System ===\n');
const testFile = 'reports/Protected_remediated_by_agent.docx';
if (!fs.existsSync(testFile)) {
console.log(`Test file ${testFile} not found. Skipping test.`);
return;
}
try {
console.log('1. Testing upload analysis (should flag issues, not fix them)...');
const req = createMockReq(testFile);
const res = createMockRes();
await uploadHandler(req, res);
const uploadResult = res.getResponse();
if (uploadResult && uploadResult.data && uploadResult.data.report) {
const report = uploadResult.data.report;
console.log('\nπ Upload Analysis Results:');
console.log(` Fixed: ${report.summary.fixed}`);
console.log(` Flagged: ${report.summary.flagged}`);
console.log('\nπ Issues detected:');
if (report.details.titleNeedsFixing) console.log(' π Title needs fixing (flagged)');
if (report.details.lineSpacingNeedsFixing) console.log(' π Line spacing needs fixing (flagged)');
if (report.details.fontSizeNeedsFixing) console.log(' π€ Font size needs fixing (flagged)');
if (report.details.fontTypeNeedsFixing) console.log(' π¨ Font type needs fixing (flagged)');
if (report.details.textShadowsRemoved) console.log(' π€ Text shadows removed (fixed)');
if (report.details.documentProtected) console.log(' π Document protection removed (fixed)');
if (report.details.imagesMissingOrBadAlt > 0) console.log(` πΌοΈ ${report.details.imagesMissingOrBadAlt} images missing alt text (flagged)`);
console.log('\nβ
Expected behavior:');
console.log(' - Line spacing, font size, font type should be FLAGGED (not fixed)');
console.log(' - Text shadows and document protection should be FIXED');
console.log(' - Alt text and title issues should be FLAGGED');
} else {
console.log('β Upload analysis failed:', uploadResult);
}
console.log('\n2. Testing download processing (should only fix shadows and protection)...');
const downloadReq = createMockReq(testFile);
const downloadRes = createMockRes();
await downloadHandler(downloadReq, downloadRes);
const downloadResult = downloadRes.getResponse();
if (downloadResult && downloadResult.statusCode === 200) {
console.log('β
Download processing completed successfully');
console.log(' - Only shadows and document protection should be modified');
console.log(' - Line spacing, font sizes, and font types should remain unchanged');
} else {
console.log('β Download processing failed:', downloadResult);
}
} catch (error) {
console.error('β Test failed:', error.message);
}
}
testNewFlaggingSystem(); |