Closed allan1m closed 7 months ago
By implementing the user account deletion feature according to the outlined requirements and considerations, users will have the flexibility to manage their accounts and data according to their preferences within the community board mobile application.
@allan1m I am unclear about the first comment.
I added this to the teams file. Was this not necessary?
Story Description Objective:To verify that the backend system correctly deletes an existing user's account upon request.
Preconditions:
The backend server is up and running.
The user to be deleted exists in the system.
The user requesting deletion is authenticated and authorized to delete the account.
Test Steps:
Start with: The authenticated user has requested account deletion.
Actions:
a. Send a DELETE request to the backend API endpoint designated for account deletion.
b. Include the user's unique identifier (userId or username) in the request.
c. Ensure the Backend validates the requestor's permissions to perform account deletion.
d. Backend processes the deletion request and removes the user's data from the database.
e. Backend should revoke any active sessions or tokens associated with the user account.
f. Backend sends a confirmation response to the client upon successful deletion.
Ends with: The user account is no longer present in the system.
Expected Results:
The Backend returns a successful response indicating the account has been deleted.
The user's account is no longer retrievable from the database.
The user cannot log in or recover the account post-deletion.
Any subsequent API requests referencing the deleted user should be invalid.
Postconditions:
Verify that the user's data does not exist in any part of the system.
Ensure that any personal data is purged in compliance with data protection regulations.
Notes:
Ensure that deletion is permanent and meets all regulatory compliance requirements.
Test for potential cascading effects on related data, such as posts or comments made by the user.
Check for proper error handling and messaging when deletion is impossible (e.g., due to pending operations).
Test Data:
Use an account earmarked for deletion with no dependencies that would prevent its removal.
Test Environment:
A test environment that mimics the production environment but does not affect live user data.
A backend environment that is configured for testing with mock data for deletion.
References:
API documentation for the account deletion endpoint.
Backend logic implementation for the delete operation.
Data retention and deletion policies
deleteAccount
API endpoint to ensure it correctly processes deletion requests.Input:
Expected Output:
Test Steps:
deleteAccount
endpoint with the mocked request.Input:
Expected Output:
Test Steps:
deleteAccount
endpoint.Input:
Expected Output:
Test Steps:
deleteAccount
endpoint.Input:
Expected Output:
Test Steps:
deleteAccount
endpoint.Input:
Expected Output:
Test Steps:
deleteAccount
endpoint.Input:
Expected Output:
Test Steps: Mock a request for account deactivation. Invoke the relevant endpoint for account deactivation. Verify the account is deactivated but not deleted. Confirm that reactivation is possible.
Input:
Valid deletion request. Expected Output:
Deletion request is logged with sufficient details. Test Steps:
Mock a valid deletion request. Invoke the deleteAccount endpoint. Verify that the request, along with details like timestamp and user ID, is logged. Unit Test Case 8 Data Download Before Deletion Objective: Test the functionality that allows users to download their data before deletion.
Input:
Request for data download prior to account deletion. Expected Output:
Data is packaged and made available for download. Test Steps:
Mock a request for user data download. Invoke the data download functionality. Verify that the user's data is correctly packaged for download.
Test Cases Code .java import static org.junit.Assert.*;
import java.util.Date; import org.junit.Test;
public class DeleteUserTest { / testValidDeletion: Tests if a user account can be successfully deleted with valid deletion credentials and confirms that the deletion date is set. /
@Test public void testValidDeletion() { // Arrange long userId = 123; String username = "testUser"; String email = "test@example.com"; String password = "password123"; String confirmationPassword = "password123"; String deletionReason = "Account closure";
// Act
DeleteUser deleteUser =
new DeleteUser(userId, username, email, password, confirmationPassword,
deletionReason);
deleteUser.confirmDeletion();
// Assert
assertEquals(deletionReason, deleteUser.getDeletionReason());
assertNotNull(deleteUser.getDeletionDate());
}
/ testInvalidPassword: Tests if deletion fails when the confirmation password doesn't match the user's password. /
@Test public void testInvalidPassword() { // Arrange long userId = 123; String username = "testUser"; String email = "test@example.com"; String password = "password123"; String confirmationPassword = "invalidPassword"; String deletionReason = "Account closure";
// Act
DeleteUser deleteUser =
new DeleteUser(userId, username, email, password, confirmationPassword,
deletionReason);
// Assert
assertFalse(deleteUser.validateCredentials());
}
/ testEmptyDeletionReason: Tests if deletion fails when the deletion reason is empty. /
@Test public void testEmptyDeletionReason() { // Arrange long userId = 123; String username = "testUser"; String email = "test@example.com"; String password = "password123"; String confirmationPassword = "password123"; String deletionReason = "";
// Act
DeleteUser deleteUser =
new DeleteUser(userId, username, email, password, confirmationPassword,
deletionReason);
// Assert
assertFalse(deleteUser.validateCredentials());
}
/ testNullDeletionDateBeforeConfirmation: Tests if the deletion date is null before the deletion is confirmed. /
@Test public void testNullDeletionDateBeforeConfirmation() { // Arrange long userId = 123; String username = "testUser"; String email = "test@example.com"; String password = "password123"; String confirmationPassword = "password123"; String deletionReason = "Account closure";
// Act
DeleteUser deleteUser =
new DeleteUser(userId, username, email, password, confirmationPassword,
deletionReason);
// Assert
assertNull(deleteUser.getDeletionDate());
}
/ testDeletionDateAfterConfirmation: Tests if the deletion date is set after the deletion is confirmed. /
@Test public void testDeletionDateAfterConfirmation() { // Arrange long userId = 123; String username = "testUser"; String email = "test@example.com"; String password = "password123"; String confirmationPassword = "password123"; String deletionReason = "Account closure";
// Act
DeleteUser deleteUser =
new DeleteUser(userId, username, email, password, confirmationPassword,
deletionReason);
deleteUser.confirmDeletion();
Date deletionDate = deleteUser.getDeletionDate();
// Assert
assertNotNull(deletionDate);
} }
Examples
import java.sql.Connection; import java.sql.DriverManager; import java.sql.PreparedStatement; import java.sql.ResultSet; import java.sql.SQLException;
abstract class DBTest { public void runTest(Connection connection) { try { if (test(connection)) { System.out.println(getClass().getSimpleName() + " passed."); } else { System.out.println(getClass().getSimpleName() + " failed."); } } catch (Exception e) { System.out.println(getClass().getSimpleName() + " raised an exception: " + e); } }
protected abstract boolean test(Connection connection); }
class TestDeleteAccount extends DBTest { @Override protected boolean test(Connection connection) { int userId = 1; return deleteAccount(userId, connection); }
private boolean deleteAccount(int userId, Connection connection) { try (PreparedStatement statement = connection.prepareStatement( "DELETE FROM accounts WHERE user_id = ?")) { statement.setInt(1, userId); int rowsAffected = statement.executeUpdate(); return rowsAffected > 0; } catch (SQLException e) { System.out.println("Error deleting account: " + e); return false; } } }
class TestAuthenticationVerification extends DBTest { @Override protected boolean test(Connection connection) { String invalidToken = "invalid_token"; return !verifyAuthentication(invalidToken); }
private boolean verifyAuthentication(String token) { // Simulate token verification return token.equals("valid_token"); } }
// Similarly, define other test classes following the same pattern
public class Main { public static void main(String[] args) { try { Connection connection = DriverManager.getConnection( "jdbc:mysql://localhost:3306/database_name", "username", "password"); new TestDeleteAccount().runTest(connection); // Run other tests similarly connection.close(); } catch (SQLException e) { e.printStackTrace(); } } }
Story Description: User Account Deletion SRS: 1.1.2. User Account Management SDD: Back-End Design Story: As a user of the community board mobile application, I want to have the ability to delete my account if I no longer wish to be part of the community or if I want to deactivate my account temporarily.
Acceptance Criteria:
1. Delete Account Functionality:
2. Backend Integration:
3. Data Removal:
4. Confirmation and Feedback:
5. Graceful Handling of Deletion Errors:
6. Account Deactivation (Optional):
7. Testing and Quality Assurance:
8. Documentation and Support:
Additional Considerations: