- Add .gitignore to exclude node_modules, dist, logs, and system files - Add comprehensive project documentation including README, deployment guide, and development setup - Add .kiro project specifications for amazon-product-bar-extension, appwrite-cloud-storage, appwrite-userid-repair, blacklist-feature, and enhanced-item-management - Add .kiro steering documents for product, structure, styling, and tech guidelines - Add VSCode settings configuration for consistent development environment - Add manifest.json and babel/vite configuration for extension build setup - Add complete source code implementation including AppWrite integration, storage managers, UI components, and services - Add comprehensive test suite with Jest configuration and 30+ test files covering all major modules - Add test HTML files for integration testing and validation - Add coverage reports and build validation scripts - Add AppWrite setup and repair documentation for database schema management - Add migration guides and responsive accessibility implementation documentation - Establish foundation for Amazon product bar extension with full feature set including blacklist management, enhanced item workflows, and real-time synchronization
257 lines
8.3 KiB
JavaScript
257 lines
8.3 KiB
JavaScript
/**
|
||
* Sample Migration Test Script
|
||
*
|
||
* This script tests the migration functionality with sample localStorage data
|
||
* to verify that the migration foundation is working correctly.
|
||
*/
|
||
|
||
import { MigrationService } from './src/MigrationService.js';
|
||
import { AuthService } from './src/AuthService.js';
|
||
import { AppWriteManager } from './src/AppWriteManager.js';
|
||
import { APPWRITE_CONFIG } from './src/AppWriteConfig.js';
|
||
|
||
// Mock localStorage for Node.js environment
|
||
const mockLocalStorage = {
|
||
data: new Map(),
|
||
getItem(key) {
|
||
return this.data.get(key) || null;
|
||
},
|
||
setItem(key, value) {
|
||
this.data.set(key, value);
|
||
},
|
||
removeItem(key) {
|
||
this.data.delete(key);
|
||
},
|
||
clear() {
|
||
this.data.clear();
|
||
}
|
||
};
|
||
|
||
// Setup global mocks for Node.js
|
||
global.localStorage = mockLocalStorage;
|
||
global.btoa = (str) => Buffer.from(str).toString('base64');
|
||
global.atob = (str) => Buffer.from(str, 'base64').toString();
|
||
|
||
// Mock AppWrite Manager for testing
|
||
class MockAppWriteManager {
|
||
constructor() {
|
||
this.documents = new Map();
|
||
this.isAuthenticated = true;
|
||
this.currentUserId = 'test-user-123';
|
||
}
|
||
|
||
getCurrentUserId() {
|
||
return this.currentUserId;
|
||
}
|
||
|
||
async createUserDocument(collectionId, data, documentId = null) {
|
||
const id = documentId || `doc_${Date.now()}_${Math.random().toString(36).substr(2, 9)}`;
|
||
const document = {
|
||
$id: id,
|
||
$createdAt: new Date().toISOString(),
|
||
$updatedAt: new Date().toISOString(),
|
||
userId: this.currentUserId,
|
||
...data
|
||
};
|
||
|
||
if (!this.documents.has(collectionId)) {
|
||
this.documents.set(collectionId, []);
|
||
}
|
||
|
||
this.documents.get(collectionId).push(document);
|
||
console.log(`✅ Created document in ${collectionId}:`, document);
|
||
return document;
|
||
}
|
||
|
||
async getUserDocuments(collectionId, additionalQueries = []) {
|
||
const docs = this.documents.get(collectionId) || [];
|
||
const userDocs = docs.filter(doc => doc.userId === this.currentUserId);
|
||
console.log(`📋 Retrieved ${userDocs.length} documents from ${collectionId}`);
|
||
return {
|
||
documents: userDocs,
|
||
total: userDocs.length
|
||
};
|
||
}
|
||
|
||
clearAllDocuments() {
|
||
this.documents.clear();
|
||
}
|
||
}
|
||
|
||
async function runMigrationTest() {
|
||
console.log('🚀 Starting Migration Sample Test\n');
|
||
|
||
try {
|
||
// Initialize services
|
||
console.log('1️⃣ Initializing services...');
|
||
const mockAppWriteManager = new MockAppWriteManager();
|
||
const migrationService = new MigrationService(mockAppWriteManager);
|
||
console.log('✅ Services initialized\n');
|
||
|
||
// Setup sample localStorage data
|
||
console.log('2️⃣ Setting up sample localStorage data...');
|
||
|
||
// Enhanced Items
|
||
const enhancedItems = [
|
||
{
|
||
id: 'sample-item-1',
|
||
amazonUrl: 'https://amazon.de/dp/sample-item-1',
|
||
originalTitle: 'Sample Product 1',
|
||
customTitle: 'AI Enhanced Sample Product 1',
|
||
price: '29.99',
|
||
currency: 'EUR',
|
||
titleSuggestions: ['Enhanced Title 1', 'Better Title 1', 'AI Title 1'],
|
||
createdAt: new Date().toISOString()
|
||
},
|
||
{
|
||
id: 'sample-item-2',
|
||
amazonUrl: 'https://amazon.de/dp/sample-item-2',
|
||
originalTitle: 'Sample Product 2',
|
||
customTitle: 'AI Enhanced Sample Product 2',
|
||
price: '49.99',
|
||
currency: 'EUR',
|
||
titleSuggestions: ['Enhanced Title 2', 'Better Title 2', 'AI Title 2'],
|
||
createdAt: new Date().toISOString()
|
||
}
|
||
];
|
||
|
||
// Blacklisted Brands
|
||
const blacklistedBrands = [
|
||
{
|
||
id: 'sample-brand-1',
|
||
name: 'Sample Brand 1',
|
||
addedAt: new Date().toISOString()
|
||
},
|
||
{
|
||
id: 'sample-brand-2',
|
||
name: 'Sample Brand 2',
|
||
addedAt: new Date().toISOString()
|
||
}
|
||
];
|
||
|
||
// Settings
|
||
const settings = {
|
||
mistralApiKey: 'sample-api-key-12345',
|
||
autoExtractEnabled: false,
|
||
defaultTitleSelection: 'original',
|
||
maxRetries: 5,
|
||
timeoutSeconds: 15,
|
||
updatedAt: new Date().toISOString()
|
||
};
|
||
|
||
// Store in mock localStorage
|
||
mockLocalStorage.setItem('amazon-ext-enhanced-items', JSON.stringify(enhancedItems));
|
||
mockLocalStorage.setItem('amazon_ext_blacklist', JSON.stringify(blacklistedBrands));
|
||
mockLocalStorage.setItem('amazon-ext-enhanced-settings', JSON.stringify(settings));
|
||
|
||
console.log(`✅ Created ${enhancedItems.length} enhanced items`);
|
||
console.log(`✅ Created ${blacklistedBrands.length} blacklisted brands`);
|
||
console.log('✅ Created custom settings');
|
||
console.log('');
|
||
|
||
// Test data detection
|
||
console.log('3️⃣ Testing data detection...');
|
||
const detection = await migrationService.detectExistingData();
|
||
|
||
console.log('📊 Detection Results:');
|
||
console.log(` Has Data: ${detection.hasData}`);
|
||
console.log(` Total Items: ${detection.totalItems}`);
|
||
console.log(` Data Types: ${Object.keys(detection.dataTypes).join(', ')}`);
|
||
|
||
if (detection.hasData) {
|
||
console.log('✅ Data detection successful\n');
|
||
} else {
|
||
console.log('❌ Data detection failed\n');
|
||
return false;
|
||
}
|
||
|
||
// Test migration
|
||
console.log('4️⃣ Testing migration...');
|
||
const migrationResult = await migrationService.migrateAllData();
|
||
|
||
if (migrationResult.success) {
|
||
console.log('✅ Migration completed successfully!');
|
||
console.log('📊 Migration Results:');
|
||
|
||
if (migrationResult.results) {
|
||
Object.entries(migrationResult.results).forEach(([type, result]) => {
|
||
if (result.migrated > 0 || result.skipped > 0 || result.errors.length > 0) {
|
||
console.log(` ${type}:`);
|
||
console.log(` Migrated: ${result.migrated}`);
|
||
console.log(` Skipped: ${result.skipped}`);
|
||
console.log(` Errors: ${result.errors.length}`);
|
||
}
|
||
});
|
||
}
|
||
console.log('');
|
||
} else {
|
||
console.log('❌ Migration failed:', migrationResult.error);
|
||
return false;
|
||
}
|
||
|
||
// Verify migration status
|
||
console.log('5️⃣ Verifying migration status...');
|
||
const status = await migrationService.getMigrationStatus();
|
||
|
||
console.log('📋 Migration Status:');
|
||
console.log(` Completed: ${status.completed}`);
|
||
console.log(` Total Migrated: ${status.totalMigrated || 0}`);
|
||
console.log(` Total Errors: ${status.totalErrors || 0}`);
|
||
|
||
if (status.completed) {
|
||
console.log('✅ Migration status verification successful\n');
|
||
} else {
|
||
console.log('❌ Migration status verification failed\n');
|
||
return false;
|
||
}
|
||
|
||
// Verify data in AppWrite
|
||
console.log('6️⃣ Verifying data in AppWrite...');
|
||
|
||
const enhancedItemsData = await mockAppWriteManager.getUserDocuments('amazon-ext-enhanced-items');
|
||
const blacklistData = await mockAppWriteManager.getUserDocuments('amazon_ext_blacklist');
|
||
const settingsData = await mockAppWriteManager.getUserDocuments('amazon-ext-enhanced-settings');
|
||
|
||
console.log('📋 AppWrite Data Verification:');
|
||
console.log(` Enhanced Items: ${enhancedItemsData.total} documents`);
|
||
console.log(` Blacklisted Brands: ${blacklistData.total} documents`);
|
||
console.log(` Settings: ${settingsData.total} documents`);
|
||
|
||
const expectedItems = enhancedItems.length;
|
||
const expectedBrands = blacklistedBrands.length;
|
||
const expectedSettings = 1;
|
||
|
||
if (enhancedItemsData.total === expectedItems &&
|
||
blacklistData.total === expectedBrands &&
|
||
settingsData.total === expectedSettings) {
|
||
console.log('✅ Data verification successful\n');
|
||
} else {
|
||
console.log('❌ Data verification failed - counts do not match\n');
|
||
return false;
|
||
}
|
||
|
||
console.log('🎉 All migration tests passed successfully!');
|
||
console.log('✅ Authentication and Migration Foundation is working correctly');
|
||
|
||
return true;
|
||
|
||
} catch (error) {
|
||
console.error('❌ Migration test failed:', error);
|
||
console.error('Stack trace:', error.stack);
|
||
return false;
|
||
}
|
||
}
|
||
|
||
// Run the test
|
||
runMigrationTest().then(success => {
|
||
if (success) {
|
||
console.log('\n🏆 CHECKPOINT PASSED: Authentication and Migration Foundation is ready!');
|
||
process.exit(0);
|
||
} else {
|
||
console.log('\n💥 CHECKPOINT FAILED: Issues found with Authentication and Migration Foundation');
|
||
process.exit(1);
|
||
}
|
||
}).catch(error => {
|
||
console.error('\n💥 CHECKPOINT ERROR:', error);
|
||
process.exit(1);
|
||
}); |