102 lines
3.4 KiB
JavaScript
102 lines
3.4 KiB
JavaScript
const Bookmark = require('./src/models/Bookmark');
|
|
|
|
// Test the migration functionality with the Bookmark model
|
|
async function testMigrationFunctionality() {
|
|
console.log('🧪 Testing Migration Functionality...\n');
|
|
|
|
try {
|
|
// Test 1: Validate bookmark data
|
|
console.log('1. Testing bookmark validation...');
|
|
|
|
const validBookmark = {
|
|
title: "Test Bookmark",
|
|
url: "https://example.com",
|
|
folder: "Test Folder"
|
|
};
|
|
|
|
const invalidBookmark = {
|
|
title: "",
|
|
url: "not-a-url",
|
|
folder: "Test"
|
|
};
|
|
|
|
const validResult = Bookmark.validateBookmark(validBookmark);
|
|
const invalidResult = Bookmark.validateBookmark(invalidBookmark);
|
|
|
|
console.log('✅ Valid bookmark validation:', validResult);
|
|
console.log('❌ Invalid bookmark validation:', invalidResult);
|
|
|
|
// Test 2: Test bulk create functionality
|
|
console.log('\n2. Testing bulk create...');
|
|
|
|
const testBookmarks = [
|
|
{
|
|
title: "Migration Test 1",
|
|
url: "https://test1.com",
|
|
folder: "Migration Test",
|
|
add_date: new Date(),
|
|
status: "unknown"
|
|
},
|
|
{
|
|
title: "Migration Test 2",
|
|
url: "https://test2.com",
|
|
folder: "Migration Test",
|
|
add_date: new Date(),
|
|
status: "unknown"
|
|
}
|
|
];
|
|
|
|
// Note: This would need a valid user ID in a real test
|
|
console.log('📝 Test bookmarks prepared:', testBookmarks.length);
|
|
|
|
// Test 3: Test validation of localStorage format
|
|
console.log('\n3. Testing localStorage format transformation...');
|
|
|
|
const localStorageBookmarks = [
|
|
{
|
|
title: "Local Bookmark 1",
|
|
url: "https://local1.com",
|
|
folder: "Local Folder",
|
|
addDate: new Date().toISOString(),
|
|
icon: "https://local1.com/favicon.ico"
|
|
},
|
|
{
|
|
title: "Local Bookmark 2",
|
|
url: "https://local2.com",
|
|
addDate: new Date().toISOString()
|
|
}
|
|
];
|
|
|
|
// Transform to API format
|
|
const transformedBookmarks = localStorageBookmarks.map(bookmark => ({
|
|
title: bookmark.title || 'Untitled',
|
|
url: bookmark.url,
|
|
folder: bookmark.folder || '',
|
|
add_date: bookmark.addDate || bookmark.add_date || new Date(),
|
|
last_modified: bookmark.lastModified || bookmark.last_modified,
|
|
icon: bookmark.icon || bookmark.favicon,
|
|
status: bookmark.status || 'unknown'
|
|
}));
|
|
|
|
console.log('📋 Transformed bookmarks:', transformedBookmarks);
|
|
|
|
// Validate transformed bookmarks
|
|
const validationResults = transformedBookmarks.map(bookmark =>
|
|
Bookmark.validateBookmark(bookmark)
|
|
);
|
|
|
|
console.log('✅ Validation results:', validationResults);
|
|
|
|
console.log('\n🎉 Migration functionality tests completed successfully!');
|
|
|
|
} catch (error) {
|
|
console.error('❌ Migration test error:', error);
|
|
}
|
|
}
|
|
|
|
// Run the test
|
|
if (require.main === module) {
|
|
testMigrationFunctionality();
|
|
}
|
|
|
|
module.exports = { testMigrationFunctionality }; |