add changes

This commit is contained in:
AD2025
2025-12-25 00:24:11 +02:00
parent 079c10e843
commit efb4f69e20
64 changed files with 576 additions and 568 deletions

View File

@@ -0,0 +1,68 @@
const axios = require('axios');
const BASE_URL = 'http://localhost:3000/api';
// Using the guest ID and token from the previous test
const GUEST_ID = 'guest_1762808357017_hy71ynhu';
const SESSION_TOKEN = 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJndWVzdElkIjoiZ3Vlc3RfMTc2MjgwODM1NzAxN19oeTcxeW5odSIsImlhdCI6MTc2MjgwODM1NywiZXhwIjoxNzYyODk0NzU3fQ.ZBrIU_V6Nd2OwWdTBGAvSEwqtoF6ihXOJcCL9bRWbco';
async function testLimitReached() {
console.log('\n╔════════════════════════════════════════════════════════════╗');
console.log('║ Testing Quiz Limit Reached Scenario (Task 16) ║');
console.log('╚════════════════════════════════════════════════════════════╝\n');
try {
// First, update the guest session to simulate reaching limit
const { GuestSession } = require('../models');
console.log('Step 1: Updating guest session to simulate limit reached...');
const guestSession = await GuestSession.findOne({
where: { guestId: GUEST_ID }
});
if (!guestSession) {
console.error('❌ Guest session not found!');
return;
}
guestSession.quizzesAttempted = 3;
await guestSession.save();
console.log('✅ Updated quizzes_attempted to 3\n');
// Now test the quiz limit endpoint
console.log('Step 2: Checking quiz limit...\n');
const response = await axios.get(`${BASE_URL}/guest/quiz-limit`, {
headers: {
'X-Guest-Token': SESSION_TOKEN
}
});
console.log('Response:', JSON.stringify(response.data, null, 2));
// Verify the response
const { data } = response.data;
console.log('\n' + '='.repeat(60));
console.log('VERIFICATION:');
console.log('='.repeat(60));
console.log(`✅ Has Reached Limit: ${data.quizLimit.hasReachedLimit}`);
console.log(`✅ Quizzes Attempted: ${data.quizLimit.quizzesAttempted}`);
console.log(`✅ Quizzes Remaining: ${data.quizLimit.quizzesRemaining}`);
if (data.upgradePrompt) {
console.log('\n✅ Upgrade Prompt Present:');
console.log(` Message: ${data.upgradePrompt.message}`);
console.log(` Benefits: ${data.upgradePrompt.benefits.length} items`);
data.upgradePrompt.benefits.forEach((benefit, index) => {
console.log(` ${index + 1}. ${benefit}`);
});
console.log(` CTA: ${data.upgradePrompt.callToAction}`);
}
console.log('\n✅ SUCCESS: Limit reached scenario working correctly!\n');
} catch (error) {
console.error('❌ Error:', error.response?.data || error.message);
}
}
testLimitReached();