← back to Dear Bubbe Nextjs
archived/tests/test-supermax.js
251 lines
#!/usr/bin/env node
/**
* Test script for Super Max tier and local content features
* Run with: node test-supermax.js
*/
const axios = require('axios');
const BASE_URL = 'http://localhost:3011';
// Test user IDs
const basicUser = 'test_basic_' + Date.now();
const supermaxUser = 'test_supermax_' + Date.now();
// Test counters
let passed = 0;
let failed = 0;
function log(message, type = 'info') {
const prefix = {
'info': '📝',
'success': '✅',
'error': '❌',
'test': '🧪',
'bubbe': '👵'
}[type] || '📝';
console.log(`${prefix} ${message}`);
}
async function test(name, fn) {
try {
log(`Testing: ${name}`, 'test');
await fn();
passed++;
log(`PASSED: ${name}`, 'success');
} catch (error) {
failed++;
log(`FAILED: ${name}`, 'error');
console.error(' Error:', error.message);
}
console.log('');
}
// Test 1: Verify Super Max plan exists
async function testSuperMaxPlan() {
const response = await axios.get(`${BASE_URL}/api/pricing`);
const supermax = response.data.plans.find(p => p.id === 'supermax');
if (!supermax) {
throw new Error('Super Max plan not found');
}
if (supermax.pricePerMonth !== 54) {
throw new Error(`Super Max should be $54, but is ${supermax.pricePerMonth}`);
}
// Check for local features
const expectedFeatures = ['local_news', 'local_sports', 'local_weather', 'personalized_insights'];
for (const feature of expectedFeatures) {
if (!supermax.features.includes(feature)) {
throw new Error(`Super Max missing feature: ${feature}`);
}
}
log(' Super Max plan configured correctly with all local features', 'info');
log(` Price: $${supermax.pricePerMonth}/month`, 'info');
log(` Total features: ${supermax.features.length}`, 'info');
}
// Test 2: Test local content blocking for basic users
async function testLocalContentBlocking() {
// Try to access local news as basic user
const response = await axios.post(`${BASE_URL}/api/local-content`, {
type: 'news',
userId: basicUser
}).catch(err => err.response);
if (response.status !== 402) {
throw new Error('Should return 402 Payment Required for basic users');
}
if (!response.data.message.includes('54')) {
throw new Error('Should mention $54 price in rejection');
}
log(' Basic users blocked from local content', 'info');
log(` Bubbe says: "${response.data.message.substring(0, 60)}..."`, 'bubbe');
}
// Test 3: Upgrade to Super Max
async function testSuperMaxUpgrade() {
const response = await axios.post(`${BASE_URL}/api/pricing`, {
action: 'upgrade',
plan: 'supermax'
}, {
headers: { 'x-user-id': supermaxUser }
});
if (!response.data.success) {
throw new Error('Failed to upgrade to Super Max');
}
if (response.data.plan.id !== 'supermax') {
throw new Error('User not on Super Max after upgrade');
}
log(' Successfully upgraded to Super Max', 'info');
log(` Bubbe says: "${response.data.message}"`, 'bubbe');
}
// Test 4: Access local content with Super Max
async function testLocalContentAccess() {
// First upgrade the user
await axios.post(`${BASE_URL}/api/pricing`, {
action: 'upgrade',
plan: 'supermax'
}, {
headers: { 'x-user-id': supermaxUser }
});
// Test local news
const newsResponse = await axios.post(`${BASE_URL}/api/local-content`, {
type: 'news',
userId: supermaxUser
}).catch(err => err.response);
if (!newsResponse || newsResponse.status !== 200) {
throw new Error('Super Max user should access local news');
}
// Test local sports
const sportsResponse = await axios.post(`${BASE_URL}/api/local-content`, {
type: 'sports',
userId: supermaxUser
}).catch(err => err.response);
if (!sportsResponse || sportsResponse.status !== 200) {
throw new Error('Super Max user should access local sports');
}
// Test local weather
const weatherResponse = await axios.post(`${BASE_URL}/api/local-content`, {
type: 'weather',
userId: supermaxUser
}).catch(err => err.response);
// Weather might fail if no coordinates, but should not be 402
if (weatherResponse && weatherResponse.status === 402) {
throw new Error('Super Max user should not get payment required for weather');
}
log(' Super Max users can access all local content', 'info');
if (newsResponse.data.location) {
log(` Location detected: ${newsResponse.data.location.city || 'Unknown city'}`, 'info');
}
}
// Test 5: Test feature detection in chat
async function testChatFeatureDetection() {
const localMessages = [
"What's the local news?",
"How's my team doing?",
"What's the weather in my neighborhood?",
"Tell me about my area"
];
for (const message of localMessages) {
const response = await axios.post(`${BASE_URL}/api/chat-v2`, {
message,
userId: basicUser
}).catch(err => err.response);
if (response && response.data.blockedFeatures) {
log(` Detected local feature in: "${message}"`, 'info');
log(` Blocked features: ${response.data.blockedFeatures.join(', ')}`, 'info');
}
}
}
// Test 6: Test Bubbe's local commentary
async function testBubbeLocalCommentary() {
// Upgrade test user first
await axios.post(`${BASE_URL}/api/pricing`, {
action: 'upgrade',
plan: 'supermax'
}, {
headers: { 'x-user-id': 'bubbe_test' }
});
const response = await axios.post(`${BASE_URL}/api/local-content`, {
type: 'personalized',
message: "Tell me about my neighborhood",
userId: 'bubbe_test'
}).catch(err => err.response);
if (response && response.data.response) {
log(' Bubbe\'s local insight:', 'bubbe');
log(` "${response.data.response.substring(0, 100)}..."`, 'info');
}
}
// Main test runner
async function runTests() {
console.log('');
console.log('🧪 Testing Bubbe.ai Super Max Tier ($54/month)');
console.log('==============================================');
console.log('');
// Check if server is running
try {
await axios.get(BASE_URL);
} catch (error) {
console.error('❌ Server not running on port 3011!');
console.error(' Please start the server first: npm run dev');
process.exit(1);
}
// Run tests
await test('Super Max Plan Configuration', testSuperMaxPlan);
await test('Local Content Blocking (Basic Users)', testLocalContentBlocking);
await test('Super Max Upgrade', testSuperMaxUpgrade);
await test('Local Content Access (Super Max)', testLocalContentAccess);
await test('Chat Feature Detection', testChatFeatureDetection);
await test('Bubbe Local Commentary', testBubbeLocalCommentary);
// Summary
console.log('==============================================');
console.log(`Results: ${passed} passed, ${failed} failed`);
if (failed === 0) {
console.log('✅ All Super Max tests passed!');
console.log('');
console.log('Super Max Features Working:');
console.log(' 📰 Local news with Bubbe commentary');
console.log(' 🏀 Local sports teams and scores');
console.log(' 🌤️ Hyper-local weather for exact location');
console.log(' 🏘️ Personalized neighborhood insights');
console.log('');
console.log('Bubbe says: "For $54 a month I know EVERYTHING about your neighborhood!"');
} else {
console.log('❌ Some tests failed. Check the errors above.');
}
process.exit(failed === 0 ? 0 : 1);
}
// Run tests
runTests().catch(console.error);