WIP
This commit is contained in:
107
backend/tests/test-migration-endpoint.js
Normal file
107
backend/tests/test-migration-endpoint.js
Normal file
@ -0,0 +1,107 @@
|
||||
const fetch = require('node-fetch');
|
||||
|
||||
// Test data - sample localStorage bookmarks
|
||||
const testBookmarks = [
|
||||
{
|
||||
title: "Test Bookmark 1",
|
||||
url: "https://example.com",
|
||||
folder: "Test Folder",
|
||||
addDate: new Date(),
|
||||
icon: "https://example.com/favicon.ico",
|
||||
status: "unknown"
|
||||
},
|
||||
{
|
||||
title: "Test Bookmark 2",
|
||||
url: "https://google.com",
|
||||
folder: "",
|
||||
addDate: new Date(),
|
||||
status: "unknown"
|
||||
},
|
||||
{
|
||||
title: "Invalid Bookmark",
|
||||
url: "not-a-valid-url",
|
||||
folder: "Test Folder"
|
||||
}
|
||||
];
|
||||
|
||||
async function testMigrationEndpoint() {
|
||||
try {
|
||||
console.log('Testing migration endpoint...');
|
||||
|
||||
// Test with merge strategy
|
||||
console.log('\n1. Testing merge strategy:');
|
||||
const mergeResponse = await fetch('http://localhost:3000/api/bookmarks/migrate', {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
'Cookie': 'authToken=test-token' // You'll need a valid token
|
||||
},
|
||||
body: JSON.stringify({
|
||||
bookmarks: testBookmarks,
|
||||
strategy: 'merge'
|
||||
})
|
||||
});
|
||||
|
||||
if (mergeResponse.ok) {
|
||||
const mergeResult = await mergeResponse.json();
|
||||
console.log('Merge result:', JSON.stringify(mergeResult, null, 2));
|
||||
} else {
|
||||
const error = await mergeResponse.text();
|
||||
console.log('Merge error:', error);
|
||||
}
|
||||
|
||||
// Test with replace strategy
|
||||
console.log('\n2. Testing replace strategy:');
|
||||
const replaceResponse = await fetch('http://localhost:3000/api/bookmarks/migrate', {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
'Cookie': 'authToken=test-token' // You'll need a valid token
|
||||
},
|
||||
body: JSON.stringify({
|
||||
bookmarks: testBookmarks,
|
||||
strategy: 'replace'
|
||||
})
|
||||
});
|
||||
|
||||
if (replaceResponse.ok) {
|
||||
const replaceResult = await replaceResponse.json();
|
||||
console.log('Replace result:', JSON.stringify(replaceResult, null, 2));
|
||||
} else {
|
||||
const error = await replaceResponse.text();
|
||||
console.log('Replace error:', error);
|
||||
}
|
||||
|
||||
// Test with invalid data
|
||||
console.log('\n3. Testing with invalid data:');
|
||||
const invalidResponse = await fetch('http://localhost:3000/api/bookmarks/migrate', {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
'Cookie': 'authToken=test-token' // You'll need a valid token
|
||||
},
|
||||
body: JSON.stringify({
|
||||
bookmarks: "not-an-array",
|
||||
strategy: 'merge'
|
||||
})
|
||||
});
|
||||
|
||||
if (invalidResponse.ok) {
|
||||
const invalidResult = await invalidResponse.json();
|
||||
console.log('Invalid data result:', JSON.stringify(invalidResult, null, 2));
|
||||
} else {
|
||||
const error = await invalidResponse.text();
|
||||
console.log('Invalid data error:', error);
|
||||
}
|
||||
|
||||
} catch (error) {
|
||||
console.error('Test error:', error);
|
||||
}
|
||||
}
|
||||
|
||||
// Run the test
|
||||
if (require.main === module) {
|
||||
testMigrationEndpoint();
|
||||
}
|
||||
|
||||
module.exports = { testMigrationEndpoint };
|
||||
Reference in New Issue
Block a user