use of teammates.common.datatransfer.attributes.StudentProfileAttributes in project teammates by TEAMMATES.
the class AccountsLogicTest method testCreateAccount.
@Test
public void testCreateAccount() throws Exception {
______TS("typical success case");
StudentProfileAttributes spa = StudentProfileAttributes.builder("id").build();
spa.shortName = "test acc na";
spa.email = "test@personal.com";
spa.gender = Const.GenderTypes.MALE;
spa.nationality = "American";
spa.institute = "institute";
spa.moreInfo = "this is more info";
AccountAttributes accountToCreate = AccountAttributes.builder().withGoogleId("id").withName("name").withEmail("test@email.com").withInstitute("dev").withIsInstructor(true).withStudentProfileAttributes(spa).build();
accountsLogic.createAccount(accountToCreate);
verifyPresentInDatastore(accountToCreate);
accountsLogic.deleteAccountCascade("id");
______TS("invalid parameters exception case");
accountToCreate = AccountAttributes.builder().withGoogleId("").withName("name").withEmail("test@email.com").withInstitute("dev").withIsInstructor(true).withStudentProfileAttributes(spa).build();
try {
accountsLogic.createAccount(accountToCreate);
signalFailureToDetectException();
} catch (InvalidParametersException e) {
ignoreExpectedException();
}
}
use of teammates.common.datatransfer.attributes.StudentProfileAttributes in project teammates by TEAMMATES.
the class AccountsLogicTest method testAccountFunctions.
@Priority(-1)
@Test
public void testAccountFunctions() throws Exception {
______TS("test isAccountPresent");
assertTrue(accountsLogic.isAccountPresent("idOfInstructor1OfCourse1"));
assertTrue(accountsLogic.isAccountPresent("student1InCourse1"));
assertFalse(accountsLogic.isAccountPresent("id-does-not-exist"));
______TS("test isAccountAnInstructor");
assertTrue(accountsLogic.isAccountAnInstructor("idOfInstructor1OfCourse1"));
assertFalse(accountsLogic.isAccountAnInstructor("student1InCourse1"));
assertFalse(accountsLogic.isAccountAnInstructor("id-does-not-exist"));
______TS("test getInstructorAccounts");
for (AccountAttributes aa : accountsLogic.getInstructorAccounts()) {
______TS(aa.toString());
}
assertEquals(12, accountsLogic.getInstructorAccounts().size());
______TS("test updateAccount");
StudentProfileAttributes spa = StudentProfileAttributes.builder("idOfInstructor1OfCourse1").build();
spa.institute = "dev";
spa.shortName = "nam";
AccountAttributes expectedAccount = AccountAttributes.builder().withGoogleId("idOfInstructor1OfCourse1").withName("name").withEmail("test2@email.com").withInstitute("dev").withIsInstructor(true).withStudentProfileAttributes(spa).build();
// updates the profile
accountsLogic.updateAccount(expectedAccount, true);
AccountAttributes actualAccount = accountsLogic.getAccount(expectedAccount.googleId, true);
expectedAccount.studentProfile.modifiedDate = actualAccount.studentProfile.modifiedDate;
expectedAccount.createdAt = actualAccount.createdAt;
assertEquals(expectedAccount.toString(), actualAccount.toString());
// does not update the profile
expectedAccount.studentProfile.shortName = "newNam";
accountsLogic.updateAccount(expectedAccount);
actualAccount = accountsLogic.getAccount(expectedAccount.googleId, true);
// no change in the name
assertEquals("nam", actualAccount.studentProfile.shortName);
expectedAccount = AccountAttributes.builder().withGoogleId("id-does-not-exist").withName("name").withEmail("test2@email.com").withInstitute("dev").withIsInstructor(true).withStudentProfileAttributes(spa).build();
try {
accountsLogic.updateAccount(expectedAccount);
signalFailureToDetectException();
} catch (EntityDoesNotExistException edne) {
AssertHelper.assertContains(AccountsDb.ERROR_UPDATE_NON_EXISTENT_ACCOUNT, edne.getMessage());
}
______TS("test downgradeInstructorToStudentCascade");
accountsLogic.downgradeInstructorToStudentCascade("idOfInstructor2OfCourse1");
assertFalse(accountsLogic.isAccountAnInstructor("idOfInstructor2OfCourse1"));
accountsLogic.downgradeInstructorToStudentCascade("student1InCourse1");
assertFalse(accountsLogic.isAccountAnInstructor("student1InCourse1"));
accountsLogic.downgradeInstructorToStudentCascade("id-does-not-exist");
assertFalse(accountsLogic.isAccountPresent("id-does-not-exist"));
______TS("test makeAccountInstructor");
accountsLogic.makeAccountInstructor("student2InCourse1");
assertTrue(accountsLogic.isAccountAnInstructor("student2InCourse1"));
accountsLogic.downgradeInstructorToStudentCascade("student2InCourse1");
accountsLogic.makeAccountInstructor("id-does-not-exist");
assertFalse(accountsLogic.isAccountPresent("id-does-not-exist"));
}
use of teammates.common.datatransfer.attributes.StudentProfileAttributes in project teammates by TEAMMATES.
the class ProfilesDbTest method testUpdateProfileSuccessWithNoPictureKey.
private void testUpdateProfileSuccessWithNoPictureKey(AccountAttributes a) throws Exception {
______TS("typical success case, no picture");
a.studentProfile.moreInfo = "This is more than enough info...";
a.studentProfile.email = "e@email.com";
profilesDb.updateStudentProfile(a.studentProfile);
StudentProfileAttributes updatedProfile = profilesDb.getStudentProfile(a.studentProfile.googleId);
assertEquals(a.studentProfile.moreInfo, updatedProfile.moreInfo);
assertEquals(a.studentProfile.email, updatedProfile.email);
}
use of teammates.common.datatransfer.attributes.StudentProfileAttributes in project teammates by TEAMMATES.
the class ProfilesDbTest method testUpdateProfilePictureSuccessInitiallyEmpty.
private void testUpdateProfilePictureSuccessInitiallyEmpty(AccountAttributes a) throws IOException, EntityDoesNotExistException {
______TS("update picture key - initially empty");
a.studentProfile.pictureKey = uploadDefaultPictureForProfile(a.googleId);
profilesDb.updateStudentProfilePicture(a.googleId, a.studentProfile.pictureKey);
StudentProfileAttributes updatedProfile = profilesDb.getStudentProfile(a.studentProfile.googleId);
assertEquals(a.studentProfile.pictureKey, updatedProfile.pictureKey);
}
use of teammates.common.datatransfer.attributes.StudentProfileAttributes in project teammates by TEAMMATES.
the class StudentCourseJoinAuthenticatedAction method addStatusMessageToUser.
private void addStatusMessageToUser() throws EntityDoesNotExistException {
CourseAttributes course = logic.getCourse(getStudent().course);
String courseDisplayText = "[" + course.getId() + "] " + SanitizationHelper.sanitizeForHtml(course.getName());
statusToUser.add(new StatusMessage(String.format(Const.StatusMessages.STUDENT_COURSE_JOIN_SUCCESSFUL, courseDisplayText), StatusMessageColor.SUCCESS));
List<FeedbackSessionAttributes> fsa = logic.getFeedbackSessionsForUserInCourse(getStudent().course, getStudent().email);
if (fsa.isEmpty()) {
statusToUser.add(new StatusMessage(String.format(Const.StatusMessages.HINT_FOR_NO_SESSIONS_STUDENT, courseDisplayText), StatusMessageColor.INFO));
StudentProfileAttributes spa = logic.getStudentProfile(account.googleId);
String updateProfileMessage = spa.generateUpdateMessageForStudent();
if (!updateProfileMessage.isEmpty()) {
statusToUser.add(new StatusMessage(updateProfileMessage, StatusMessageColor.INFO));
}
}
}
Aggregations