adding trash folder

This commit is contained in:
DioCrafts
2025-03-24 17:49:53 +01:00
parent 38b0e9594b
commit bd623ec07e
11 changed files with 644 additions and 68 deletions
+64 -20
View File
@@ -1,28 +1,72 @@
#!/bin/bash
# Run unit tests for the trash feature
echo "Running unit tests for the trash feature..."
RUST_LOG=debug cargo test application::services::trash_service_test::tests -- --nocapture
BASE_URL="http://127.0.0.1:8085/api"
# Set up environment for API tests
echo "Setting up environment for API tests..."
cargo build
# Get the login token
echo "Logging in..."
TOKEN=$(curl -s -X POST "${BASE_URL}/auth/login" \
-H "Content-Type: application/json" \
-d '{"username":"admin", "password":"admin123"}' | jq -r '.access_token')
# Start the server in the background
echo "Starting the server..."
RUST_LOG=debug cargo run &
SERVER_PID=$!
if [ -z "$TOKEN" ] || [ "$TOKEN" == "null" ]; then
echo "Failed to get token"
exit 1
fi
# Wait for the server to start
echo "Waiting for the server to start..."
sleep 5
echo "Token: ${TOKEN:0:15}..."
# Run the API tests
echo "Running API tests for the trash feature..."
python3 test-trash-api.py
# Create a test folder
echo -e "\nCreating test folder..."
FOLDER_ID=$(curl -s -X POST "${BASE_URL}/folders" \
-H "Content-Type: application/json" \
-H "Authorization: Bearer $TOKEN" \
-d '{"name":"Trash Test Folder", "parent_id":null}' | jq -r '.id')
# Clean up
echo "Cleaning up..."
kill $SERVER_PID
echo "Created folder with ID: $FOLDER_ID"
echo "All tests completed!"
# Create a test file in the folder
echo -e "\nCreating test file..."
FILE_CONTENT="This is a test file that will be moved to trash."
TEST_FILE_PATH="/tmp/trash_test_file.txt"
echo "$FILE_CONTENT" > "$TEST_FILE_PATH"
FILE_ID=$(curl -s -X POST "${BASE_URL}/files/upload" \
-H "Authorization: Bearer $TOKEN" \
-F "file=@$TEST_FILE_PATH" \
-F "folder_id=$FOLDER_ID" | jq -r '.id')
echo "Created file with ID: $FILE_ID"
# Try the trash operations (these will use the frontend code we modified)
echo -e "\nTesting trash operations through the frontend using direct delete (which uses trash)..."
echo "Moving file to trash..."
curl -s -X DELETE "${BASE_URL}/files/$FILE_ID" \
-H "Authorization: Bearer $TOKEN"
# Check if file is still accessible (should return 404 if moved to trash)
echo -e "\nChecking if file is still accessible..."
STATUS=$(curl -s -o /dev/null -w "%{http_code}" "${BASE_URL}/files/$FILE_ID" \
-H "Authorization: Bearer $TOKEN")
if [ "$STATUS" == "404" ]; then
echo "File moved to trash successfully (returns 404)"
else
echo "File still accessible, move to trash failed (status: $STATUS)"
fi
echo -e "\nMoving folder to trash..."
curl -s -X DELETE "${BASE_URL}/folders/$FOLDER_ID" \
-H "Authorization: Bearer $TOKEN"
# Check if folder is still accessible
echo -e "\nChecking if folder is still accessible..."
STATUS=$(curl -s -o /dev/null -w "%{http_code}" "${BASE_URL}/folders/$FOLDER_ID" \
-H "Authorization: Bearer $TOKEN")
if [ "$STATUS" == "404" ]; then
echo "Folder moved to trash successfully (returns 404)"
else
echo "Folder still accessible, move to trash failed (status: $STATUS)"
fi
echo -e "\nTest complete."