mirror of
https://github.com/Memo-2023/mana-monorepo.git
synced 2026-05-14 18:41:08 +02:00
✅ test: implement comprehensive automated testing system with daily CI/CD
Implement rock-solid automated testing infrastructure for mana-core-auth with daily execution, notifications, and comprehensive monitoring. Test Suite Improvements: - Fix all 36 failing BetterAuthService tests (missing service mocks) - Add 21 JwtAuthGuard tests achieving 100% statement coverage - Create silentError helper to suppress intentional error logs - Fix Todo backend TaskService test structure - Add jose mock for JWT testing - Configure jest collectCoverageFrom for mana-core-auth GitHub Actions Workflow: - Daily automated test execution (2 AM UTC + manual trigger) - Matrix parallelization across 6 backend services - PostgreSQL and Redis service containers - Coverage enforcement (80% threshold) - Multi-channel notifications (Discord, Slack, GitHub Issues) - Support for success notifications (opt-in) Test Infrastructure: - Coverage aggregation across multiple services - Flaky test detection with 30-run history tracking - Performance metrics tracking with regression detection - Test data seeding and cleanup scripts - Comprehensive test reporting with formatted metrics Documentation: - TESTING_GUIDE.md (4000+ words) - Complete testing documentation - AUTOMATED_TESTING_SYSTEM.md - System architecture and workflows - DISCORD_NOTIFICATIONS_SETUP.md - Discord webhook setup guide - TESTING_DEPLOYMENT_CHECKLIST.md - Pre-deployment verification - TESTING_QUICK_REFERENCE.md - Quick command reference Final Result: - 180/180 tests passing (100% pass rate) - Zero console errors in test output - Automated daily testing with rich notifications - Production-ready test infrastructure
This commit is contained in:
parent
9dbd6e6c09
commit
304897261d
24 changed files with 5017 additions and 16 deletions
79
scripts/test-data/cleanup-test-data.sh
Executable file
79
scripts/test-data/cleanup-test-data.sh
Executable file
|
|
@ -0,0 +1,79 @@
|
|||
#!/bin/bash
|
||||
# Cleanup Test Data
|
||||
#
|
||||
# Removes test data from databases after test execution.
|
||||
# Can be used to reset databases to a clean state.
|
||||
#
|
||||
# Usage:
|
||||
# ./scripts/test-data/cleanup-test-data.sh [service]
|
||||
#
|
||||
# Examples:
|
||||
# ./scripts/test-data/cleanup-test-data.sh # Clean all services
|
||||
# ./scripts/test-data/cleanup-test-data.sh auth # Clean auth only
|
||||
|
||||
set -e
|
||||
|
||||
RED='\033[0;31m'
|
||||
GREEN='\033[0;32m'
|
||||
YELLOW='\033[1;33m'
|
||||
NC='\033[0m'
|
||||
|
||||
SERVICE_FILTER=${1:-"all"}
|
||||
|
||||
echo -e "${YELLOW}Cleaning up test data...${NC}"
|
||||
|
||||
# Configuration
|
||||
export NODE_ENV="test"
|
||||
export DATABASE_URL_TEMPLATE="postgresql://manacore:devpassword@localhost:5432"
|
||||
|
||||
# Cleanup function
|
||||
cleanup_database() {
|
||||
local db_name=$1
|
||||
|
||||
echo -e "\n${YELLOW}Cleaning database: ${db_name}${NC}"
|
||||
|
||||
export DATABASE_URL="${DATABASE_URL_TEMPLATE}/${db_name}"
|
||||
|
||||
# Drop and recreate database
|
||||
psql -U manacore -h localhost -c "DROP DATABASE IF EXISTS ${db_name};" postgres 2>/dev/null || true
|
||||
psql -U manacore -h localhost -c "CREATE DATABASE ${db_name};" postgres 2>/dev/null || true
|
||||
|
||||
echo -e "${GREEN}✓ Cleaned ${db_name}${NC}"
|
||||
}
|
||||
|
||||
# Execute cleanup based on filter
|
||||
case "$SERVICE_FILTER" in
|
||||
"all")
|
||||
cleanup_database "manacore"
|
||||
cleanup_database "chat"
|
||||
cleanup_database "todo"
|
||||
cleanup_database "calendar"
|
||||
cleanup_database "contacts"
|
||||
cleanup_database "picture"
|
||||
;;
|
||||
"auth")
|
||||
cleanup_database "manacore"
|
||||
;;
|
||||
"chat")
|
||||
cleanup_database "chat"
|
||||
;;
|
||||
"todo")
|
||||
cleanup_database "todo"
|
||||
;;
|
||||
"calendar")
|
||||
cleanup_database "calendar"
|
||||
;;
|
||||
"contacts")
|
||||
cleanup_database "contacts"
|
||||
;;
|
||||
"picture")
|
||||
cleanup_database "picture"
|
||||
;;
|
||||
*)
|
||||
echo -e "${RED}Unknown service: $SERVICE_FILTER${NC}"
|
||||
echo "Available services: all, auth, chat, todo, calendar, contacts, picture"
|
||||
exit 1
|
||||
;;
|
||||
esac
|
||||
|
||||
echo -e "\n${GREEN}✓ Test data cleaned up successfully!${NC}"
|
||||
237
scripts/test-data/seed-test-data.sh
Executable file
237
scripts/test-data/seed-test-data.sh
Executable file
|
|
@ -0,0 +1,237 @@
|
|||
#!/bin/bash
|
||||
# Seed Test Data
|
||||
#
|
||||
# Seeds databases with consistent test data for integration and E2E tests.
|
||||
# Uses predetermined UUIDs and data to ensure reproducible tests.
|
||||
#
|
||||
# Usage:
|
||||
# ./scripts/test-data/seed-test-data.sh [service]
|
||||
#
|
||||
# Examples:
|
||||
# ./scripts/test-data/seed-test-data.sh # Seed all services
|
||||
# ./scripts/test-data/seed-test-data.sh auth # Seed auth only
|
||||
# ./scripts/test-data/seed-test-data.sh chat # Seed chat only
|
||||
|
||||
set -e
|
||||
|
||||
RED='\033[0;31m'
|
||||
GREEN='\033[0;32m'
|
||||
YELLOW='\033[1;33m'
|
||||
NC='\033[0m'
|
||||
|
||||
SERVICE_FILTER=${1:-"all"}
|
||||
|
||||
echo -e "${GREEN}Seeding test data...${NC}"
|
||||
|
||||
# Configuration
|
||||
export NODE_ENV="test"
|
||||
export DATABASE_URL_TEMPLATE="postgresql://manacore:devpassword@localhost:5432"
|
||||
|
||||
# Seed auth service
|
||||
seed_auth() {
|
||||
echo -e "\n${GREEN}Seeding mana-core-auth...${NC}"
|
||||
|
||||
export DATABASE_URL="${DATABASE_URL_TEMPLATE}/manacore"
|
||||
|
||||
cd services/mana-core-auth
|
||||
|
||||
# Run migrations
|
||||
pnpm run db:push
|
||||
|
||||
# Create test users using Node.js script
|
||||
node -e "
|
||||
const { db } = require('./src/db/connection');
|
||||
const { users, accounts, creditBalances } = require('./src/db/schema/auth.schema');
|
||||
const bcrypt = require('bcrypt');
|
||||
|
||||
async function seedTestUsers() {
|
||||
console.log('Creating test users...');
|
||||
|
||||
// Deterministic test user IDs
|
||||
const testUsers = [
|
||||
{
|
||||
id: '00000000-0000-0000-0000-000000000001',
|
||||
email: 'test-user-1@example.com',
|
||||
name: 'Test User 1',
|
||||
password: 'TestPassword123!',
|
||||
},
|
||||
{
|
||||
id: '00000000-0000-0000-0000-000000000002',
|
||||
email: 'test-user-2@example.com',
|
||||
name: 'Test User 2',
|
||||
password: 'TestPassword123!',
|
||||
},
|
||||
{
|
||||
id: '00000000-0000-0000-0000-000000000003',
|
||||
email: 'admin@example.com',
|
||||
name: 'Admin User',
|
||||
password: 'AdminPassword123!',
|
||||
role: 'admin',
|
||||
},
|
||||
];
|
||||
|
||||
for (const user of testUsers) {
|
||||
try {
|
||||
// Check if user exists
|
||||
const existing = await db.select().from(users).where(eq(users.email, user.email)).limit(1);
|
||||
|
||||
if (existing.length > 0) {
|
||||
console.log(\`User \${user.email} already exists, skipping\`);
|
||||
continue;
|
||||
}
|
||||
|
||||
// Hash password
|
||||
const hashedPassword = await bcrypt.hash(user.password, 10);
|
||||
|
||||
// Insert user
|
||||
await db.insert(users).values({
|
||||
id: user.id,
|
||||
email: user.email,
|
||||
name: user.name,
|
||||
emailVerified: true,
|
||||
role: user.role || 'user',
|
||||
});
|
||||
|
||||
// Insert credential account
|
||||
await db.insert(accounts).values({
|
||||
id: \`\${user.id}-credential\`,
|
||||
userId: user.id,
|
||||
accountId: user.id,
|
||||
providerId: 'credential',
|
||||
password: hashedPassword,
|
||||
});
|
||||
|
||||
// Initialize credit balance
|
||||
await db.insert(creditBalances).values({
|
||||
userId: user.id,
|
||||
balance: 0,
|
||||
freeCreditsRemaining: 150,
|
||||
dailyFreeCredits: 5,
|
||||
});
|
||||
|
||||
console.log(\`Created test user: \${user.email}\`);
|
||||
} catch (error) {
|
||||
console.error(\`Error creating user \${user.email}:\`, error);
|
||||
}
|
||||
}
|
||||
|
||||
console.log('Test users seeded successfully');
|
||||
process.exit(0);
|
||||
}
|
||||
|
||||
seedTestUsers().catch(console.error);
|
||||
"
|
||||
|
||||
cd ../..
|
||||
}
|
||||
|
||||
# Seed chat service
|
||||
seed_chat() {
|
||||
echo -e "\n${GREEN}Seeding chat...${NC}"
|
||||
|
||||
export DATABASE_URL="${DATABASE_URL_TEMPLATE}/chat"
|
||||
|
||||
cd apps/chat/apps/backend
|
||||
|
||||
# Run migrations
|
||||
if grep -q "db:push" package.json; then
|
||||
pnpm run db:push
|
||||
fi
|
||||
|
||||
# Seed AI models
|
||||
if grep -q "db:seed" package.json; then
|
||||
pnpm run db:seed
|
||||
fi
|
||||
|
||||
cd ../../../..
|
||||
}
|
||||
|
||||
# Seed todo service
|
||||
seed_todo() {
|
||||
echo -e "\n${GREEN}Seeding todo...${NC}"
|
||||
|
||||
export DATABASE_URL="${DATABASE_URL_TEMPLATE}/todo"
|
||||
|
||||
cd apps/todo/apps/backend
|
||||
|
||||
if grep -q "db:push" package.json; then
|
||||
pnpm run db:push
|
||||
fi
|
||||
|
||||
if grep -q "db:seed" package.json; then
|
||||
pnpm run db:seed
|
||||
fi
|
||||
|
||||
cd ../../../..
|
||||
}
|
||||
|
||||
# Seed calendar service
|
||||
seed_calendar() {
|
||||
echo -e "\n${GREEN}Seeding calendar...${NC}"
|
||||
|
||||
export DATABASE_URL="${DATABASE_URL_TEMPLATE}/calendar"
|
||||
|
||||
cd apps/calendar/apps/backend
|
||||
|
||||
if grep -q "db:push" package.json; then
|
||||
pnpm run db:push
|
||||
fi
|
||||
|
||||
if grep -q "db:seed" package.json; then
|
||||
pnpm run db:seed
|
||||
fi
|
||||
|
||||
cd ../../../..
|
||||
}
|
||||
|
||||
# Seed contacts service
|
||||
seed_contacts() {
|
||||
echo -e "\n${GREEN}Seeding contacts...${NC}"
|
||||
|
||||
export DATABASE_URL="${DATABASE_URL_TEMPLATE}/contacts"
|
||||
|
||||
cd apps/contacts/apps/backend
|
||||
|
||||
if grep -q "db:push" package.json; then
|
||||
pnpm run db:push
|
||||
fi
|
||||
|
||||
if grep -q "db:seed" package.json; then
|
||||
pnpm run db:seed
|
||||
fi
|
||||
|
||||
cd ../../../..
|
||||
}
|
||||
|
||||
# Execute seeding based on filter
|
||||
case "$SERVICE_FILTER" in
|
||||
"all")
|
||||
seed_auth
|
||||
seed_chat
|
||||
seed_todo
|
||||
seed_calendar
|
||||
seed_contacts
|
||||
;;
|
||||
"auth")
|
||||
seed_auth
|
||||
;;
|
||||
"chat")
|
||||
seed_chat
|
||||
;;
|
||||
"todo")
|
||||
seed_todo
|
||||
;;
|
||||
"calendar")
|
||||
seed_calendar
|
||||
;;
|
||||
"contacts")
|
||||
seed_contacts
|
||||
;;
|
||||
*)
|
||||
echo -e "${RED}Unknown service: $SERVICE_FILTER${NC}"
|
||||
echo "Available services: all, auth, chat, todo, calendar, contacts"
|
||||
exit 1
|
||||
;;
|
||||
esac
|
||||
|
||||
echo -e "\n${GREEN}✓ Test data seeded successfully!${NC}"
|
||||
Loading…
Add table
Add a link
Reference in a new issue