-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
provided Delete methods for DAO, fixed errors on tests
- Loading branch information
1 parent
1159ba9
commit c6bb738
Showing
6 changed files
with
135 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
package model.service.user; | ||
|
||
|
||
import model.DAO.DAOUser; | ||
import model.entity.User; | ||
import org.junit.jupiter.api.AfterAll; | ||
import org.junit.jupiter.api.BeforeEach; | ||
import org.junit.jupiter.api.Test; | ||
|
||
import static org.junit.jupiter.api.Assertions.*; | ||
import static org.mockito.Mockito.*; | ||
public class UserDataTest { | ||
|
||
private UserData ud; | ||
private int id; | ||
@BeforeEach | ||
void setup() { ud = new UserData(); } | ||
|
||
@Test | ||
void createUser() { | ||
// Arrange | ||
String email = "[email protected]"; | ||
String password = "password"; | ||
int therapistId = 999; | ||
if(ud.checkIfEmailExists("[email protected]")) { | ||
new DAOUser().deleteUserByIdOrEmail("[email protected]"); | ||
} | ||
// Act | ||
int result = ud.createUser(email, password, therapistId); | ||
// Assert | ||
assertTrue(result > 0, "The result should be positive"); | ||
new DAOUser().deleteUserByIdOrEmail(id); | ||
id = result; | ||
} | ||
|
||
@Test | ||
void checkIfEmailExists(){ | ||
assertTrue(ud.checkIfEmailExists("[email protected]"), "this has been generated before, it must exists"); | ||
} | ||
|
||
@Test | ||
void getUser() { | ||
User user = ud.getUser("[email protected]"); | ||
assertNotNull(user, " User with email [email protected] must exist"); | ||
if (user != null) | ||
assertEquals("[email protected]", user.getEmail(), "Email should match"); | ||
} | ||
|
||
@Test | ||
void isTherapist() { | ||
User user = new User(); | ||
user.setIdTherapist(0); | ||
boolean result = ud.isTherapist(user); | ||
assertTrue(result, "User should be a therapist"); | ||
|
||
User user2 = new User(); | ||
user.setIdTherapist(9); | ||
boolean result2 = ud.isTherapist(user); | ||
assertFalse(result2, "User should not be a therapist"); | ||
} | ||
|
||
@Test | ||
void updateAnalyticsPreference() { | ||
|
||
|
||
String userId = Integer.toString(id); | ||
boolean result = ud.updateAnalyticsPreference(userId, true); | ||
assertTrue(result, "Analytics preference should be updated"); | ||
} | ||
|
||
@Test | ||
void updateEmailTime() { | ||
String userId = Integer.toString(id); | ||
boolean result = ud.updateEmailTime(userId, "11:00|12:00"); | ||
assertTrue(result, "Email time should be updated"); | ||
} | ||
|
||
} |