Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
113 changes: 113 additions & 0 deletions scripts/test-batch-extraction.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
/**
* Test script to verify batch selection extraction
* Tests that conversational inputs like "my batch is 23" extract "23"
*/

console.log('🧪 Testing Batch Selection Extraction\n');
console.log('━'.repeat(80));

// Batch extraction phrases
const BATCH_PHRASES = [
'my batch is', 'our batch is', 'batch is', 'the batch is',
'we are batch', 'we are from batch', 'i am from batch', 'i am in batch',
'our batch', 'my batch', 'batch', 'we are in batch', 'from batch'
];

// Extraction function
function extractFromConversational(input: string, phrases: string[]): string {
let result = input.trim();
const lowerInput = result.toLowerCase();

for (const phrase of phrases) {
if (lowerInput.includes(phrase)) {
const phraseIndex = lowerInput.indexOf(phrase);
const afterPhrase = result.substring(phraseIndex + phrase.length).trim();

if (afterPhrase.length >= 1) {
result = afterPhrase;
console.log(` 🔍 Detected phrase "${phrase}" → Extracting...`);
break;
}
}
}

return result;
}

// Batch validator (must be "23" or "24")
function validateBatch(batch: string): boolean {
return /^(23|24)$/.test(batch);
}

// Test cases for batch extraction
const testCases = [
// Conversational inputs with "is"
{ input: 'my batch is 23', expected: '23', description: 'Conversational: "my batch is 23"' },
{ input: 'our batch is 24', expected: '24', description: 'Conversational: "our batch is 24"' },
{ input: 'batch is 23', expected: '23', description: 'Conversational: "batch is 23"' },
{ input: 'the batch is 24', expected: '24', description: 'Conversational: "the batch is 24"' },

// Conversational inputs without "is"
{ input: 'our batch 23', expected: '23', description: 'Short: "our batch 23"' },
{ input: 'my batch 24', expected: '24', description: 'Short: "my batch 24"' },

// "We are" patterns
{ input: 'we are batch 23', expected: '23', description: 'We are: "we are batch 23"' },
{ input: 'we are from batch 24', expected: '24', description: 'We are from: "we are from batch 24"' },
{ input: 'we are in batch 23', expected: '23', description: 'We are in: "we are in batch 23"' },

// "I am" patterns
{ input: 'i am from batch 24', expected: '24', description: 'I am from: "i am from batch 24"' },
{ input: 'i am in batch 23', expected: '23', description: 'I am in: "i am in batch 23"' },

// "from batch" pattern
{ input: 'from batch 24', expected: '24', description: 'From batch: "from batch 24"' },

// Direct input (no extraction needed)
{ input: '23', expected: '23', description: 'Direct: "23"' },
{ input: '24', expected: '24', description: 'Direct: "24"' },

// Edge cases with capitalization
{ input: 'My Batch Is 23', expected: '23', description: 'Capitalized: "My Batch Is 23"' },
{ input: 'OUR BATCH IS 24', expected: '24', description: 'Uppercase: "OUR BATCH IS 24"' },
];

console.log('\n📝 Running Test Cases:\n');

let passed = 0;
let failed = 0;

testCases.forEach((testCase, index) => {
const extracted = extractFromConversational(testCase.input, BATCH_PHRASES);
const result = extracted.trim();
const isValid = validateBatch(result);
const testPassed = result === testCase.expected && isValid;

if (testPassed) {
console.log(`✅ Test ${index + 1}: PASS`);
console.log(` Description: ${testCase.description}`);
console.log(` Input: "${testCase.input}"`);
console.log(` Expected: "${testCase.expected}" | Got: "${result}" | Valid: ${isValid}\n`);
passed++;
} else {
console.log(`❌ Test ${index + 1}: FAIL`);
console.log(` Description: ${testCase.description}`);
console.log(` Input: "${testCase.input}"`);
console.log(` Expected: "${testCase.expected}" | Got: "${result}" | Valid: ${isValid}\n`);
failed++;
}
});

console.log('━'.repeat(80));
console.log(`\n📊 Results: ${passed}/${testCases.length} passed`);
console.log(` ✅ Passed: ${passed}`);
console.log(` ❌ Failed: ${failed}`);
console.log(` Success Rate: ${Math.round((passed / testCases.length) * 100)}%\n`);

if (failed === 0) {
console.log('🎉 All tests passed! Batch extraction working perfectly!\n');
process.exit(0);
} else {
console.log('⚠️ Some tests failed. Please review the implementation.\n');
process.exit(1);
}
86 changes: 86 additions & 0 deletions scripts/test-conversational-phrases.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
/**
* Test script to verify conversational phrase detection
* Tests that phrases like "my name is aditha" are rejected as team names
*/

console.log('🧪 Testing Conversational Phrase Detection\n');
console.log('━'.repeat(70));

// Test cases
const testCases = [
// Conversational phrases (should be rejected)
{ input: 'my name is aditha', expected: 'REJECT', reason: 'Contains "my name is"' },
{ input: 'i am john', expected: 'REJECT', reason: 'Contains "i am"' },
{ input: 'this is our team', expected: 'REJECT', reason: 'Contains "this is"' },
{ input: 'my team is phoenix', expected: 'REJECT', reason: 'Contains "my team is"' },
{ input: 'we are the warriors', expected: 'REJECT', reason: 'Contains "we are"' },
{ input: 'our name is team alpha', expected: 'REJECT', reason: 'Contains "our name is"' },
{ input: 'our team name is bulk', expected: 'REJECT', reason: 'Contains "our team name is"' },
{ input: 'my team name is phoenix', expected: 'REJECT', reason: 'Contains "my team name is"' },
{ input: 'the team name is warriors', expected: 'REJECT', reason: 'Contains "the team name is"' },
{ input: 'team name is alpha', expected: 'REJECT', reason: 'Contains "team name is"' },
{ input: 'hello i am sarah', expected: 'REJECT', reason: 'Contains "hello i am"' },
{ input: 'hi i am david', expected: 'REJECT', reason: 'Contains "hi i am"' },
{ input: "i'm michael", expected: 'REJECT', reason: 'Contains "i\'m"' },

// Valid team names (should be accepted)
{ input: 'Phoenix', expected: 'ACCEPT', reason: 'Valid short name' },
{ input: 'Team Alpha', expected: 'ACCEPT', reason: 'Valid team name' },
{ input: 'Code Warriors', expected: 'ACCEPT', reason: 'Valid team name' },
{ input: 'Rush2025', expected: 'ACCEPT', reason: 'Valid name with numbers' },
{ input: 'The_Innovators', expected: 'ACCEPT', reason: 'Valid with underscore' },
{ input: 'Team-42', expected: 'ACCEPT', reason: 'Valid with hyphen' },
{ input: 'CodeRush Champions', expected: 'ACCEPT', reason: 'Valid longer name' },
{ input: 'Binary Beasts', expected: 'ACCEPT', reason: 'Valid team name' },
];

console.log('\n📝 Test Cases:\n');

let passed = 0;
let failed = 0;

testCases.forEach((testCase, index) => {
const lowerInput = testCase.input.toLowerCase();

// Check for conversational phrases
const conversationalPhrases = [
'my name is', 'i am', 'this is', 'my team is', 'we are',
'our name is', 'our team is', 'our team name is', 'my team name is',
'the team name is', 'team name is', 'hello i am', 'hi i am', "i'm"
];

const containsConversationalPhrase = conversationalPhrases.some(phrase =>
lowerInput.includes(phrase)
);

const actualResult = containsConversationalPhrase ? 'REJECT' : 'ACCEPT';
const testPassed = actualResult === testCase.expected;

if (testPassed) {
console.log(`✅ Test ${index + 1}: PASS`);
console.log(` Input: "${testCase.input}"`);
console.log(` Expected: ${testCase.expected} | Actual: ${actualResult}`);
console.log(` Reason: ${testCase.reason}\n`);
passed++;
} else {
console.log(`❌ Test ${index + 1}: FAIL`);
console.log(` Input: "${testCase.input}"`);
console.log(` Expected: ${testCase.expected} | Actual: ${actualResult}`);
console.log(` Reason: ${testCase.reason}\n`);
failed++;
}
});

console.log('━'.repeat(70));
console.log(`\n📊 Results: ${passed}/${testCases.length} passed`);
console.log(` ✅ Passed: ${passed}`);
console.log(` ❌ Failed: ${failed}`);
console.log(` Success Rate: ${Math.round((passed / testCases.length) * 100)}%\n`);

if (failed === 0) {
console.log('🎉 All tests passed! Conversational phrase detection is working correctly.\n');
process.exit(0);
} else {
console.log('⚠️ Some tests failed. Please review the implementation.\n');
process.exit(1);
}
136 changes: 136 additions & 0 deletions scripts/test-duplicate-names.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,136 @@
/**
* Test script to verify case-insensitive duplicate name detection
* Tests that names like "Bindu", "bindu", "BINDU", "BiNdU" are treated as duplicates
*/

import mongoose from 'mongoose';
import Registration from '../src/models/Registration';

const MONGODB_URI = process.env.MONGODB_URI || 'your_mongodb_uri';

async function testDuplicateNames() {
try {
console.log('🔍 Testing Case-Insensitive Duplicate Name Detection\n');
console.log('━'.repeat(60));

await mongoose.connect(MONGODB_URI);
console.log('✅ Connected to MongoDB\n');

// Create a test session
const testSessionId = `test-duplicate-names-${Date.now()}`;

// Clean up any existing test data
await Registration.deleteMany({ sessionId: testSessionId });

// Create a registration with first member
const registration = new Registration({
sessionId: testSessionId,
state: 'MEMBER_DETAILS',
teamName: 'TestTeam',
teamBatch: '24',
currentMember: 1,
members: []
});
await registration.save();

console.log('📝 Test Registration Created');
console.log(`Team: ${registration.teamName}`);
console.log(`Session: ${testSessionId}\n`);

// Test cases: Different case variations of the same name
const testCases = [
{ name: 'Bindu Silva', shouldSucceed: true, description: 'First member - should succeed' },
{ name: 'bindu silva', shouldSucceed: false, description: 'Lowercase duplicate - should fail' },
{ name: 'BINDU SILVA', shouldSucceed: false, description: 'Uppercase duplicate - should fail' },
{ name: 'BiNdU SiLvA', shouldSucceed: false, description: 'Mixed case duplicate - should fail' },
{ name: 'Bindu Silva', shouldSucceed: false, description: 'Extra space duplicate - should fail (after trim)' },
{ name: 'Kamal Perera', shouldSucceed: true, description: 'Different name - should succeed' },
{ name: 'KAMAL PERERA', shouldSucceed: false, description: 'Kamal uppercase duplicate - should fail' },
{ name: 'Nimal Fernando', shouldSucceed: true, description: 'Another different name - should succeed' },
];

let passedTests = 0;
let failedTests = 0;

console.log('🧪 Running Test Cases:\n');

for (const testCase of testCases) {
const lowerName = testCase.name.trim().toLowerCase();

// Reload registration to get latest members
const reg = await Registration.findOne({ sessionId: testSessionId });
if (!reg) {
console.log('❌ Registration not found!');
continue;
}

// Check if name exists (case-insensitive)
const nameExists = reg.members.some(m => m.fullName.toLowerCase() === lowerName);

const testPassed = (nameExists && !testCase.shouldSucceed) || (!nameExists && testCase.shouldSucceed);

if (testPassed) {
console.log(`✅ PASS: ${testCase.description}`);
console.log(` Input: "${testCase.name}"`);
console.log(` Expected: ${testCase.shouldSucceed ? 'Accept' : 'Reject'} | Result: ${nameExists ? 'Rejected' : 'Accepted'}\n`);
passedTests++;

// If test expects success, add the member
if (testCase.shouldSucceed) {
reg.members.push({
fullName: testCase.name.trim(),
indexNumber: `24${1000 + reg.members.length}T`,
email: `member${reg.members.length + 1}@test.com`,
batch: '24'
});
await reg.save();
console.log(` ➕ Added to team (Total members: ${reg.members.length})\n`);
}
} else {
console.log(`❌ FAIL: ${testCase.description}`);
console.log(` Input: "${testCase.name}"`);
console.log(` Expected: ${testCase.shouldSucceed ? 'Accept' : 'Reject'} | Result: ${nameExists ? 'Rejected' : 'Accepted'}\n`);
failedTests++;
}
}

console.log('━'.repeat(60));
console.log('\n📊 Test Results:');
console.log(` ✅ Passed: ${passedTests}/${testCases.length}`);
console.log(` ❌ Failed: ${failedTests}/${testCases.length}`);
console.log(` Success Rate: ${Math.round((passedTests / testCases.length) * 100)}%\n`);

// Show final team composition
const finalReg = await Registration.findOne({ sessionId: testSessionId });
if (finalReg) {
console.log('👥 Final Team Composition:');
finalReg.members.forEach((member, index) => {
console.log(` ${index + 1}. ${member.fullName} (${member.indexNumber})`);
});
console.log();
}

// Cleanup
await Registration.deleteOne({ sessionId: testSessionId });
console.log('🧹 Test data cleaned up');

await mongoose.disconnect();
console.log('✅ Disconnected from MongoDB\n');

if (failedTests === 0) {
console.log('🎉 All tests passed! Case-insensitive duplicate detection is working correctly.\n');
process.exit(0);
} else {
console.log('⚠️ Some tests failed. Please review the implementation.\n');
process.exit(1);
}

} catch (error) {
console.error('❌ Error during testing:', error);
await mongoose.disconnect();
process.exit(1);
}
}

// Run the test
testDuplicateNames();
Loading
Loading