Skip to content

Commit

Permalink
Merge branch 'master' into db-migration-c
Browse files Browse the repository at this point in the history
  • Loading branch information
domoberzin authored Feb 18, 2025
2 parents a1a0984 + 3e47152 commit 70c9927
Show file tree
Hide file tree
Showing 5 changed files with 189 additions and 7 deletions.
5 changes: 4 additions & 1 deletion src/main/java/teammates/common/util/StringHelper.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package teammates.common.util;

import java.text.DecimalFormat;
import java.text.DecimalFormatSymbols;
import java.util.Collections;
import java.util.List;
import java.util.Objects;
Expand Down Expand Up @@ -179,7 +180,9 @@ public static <T> String toString(List<T> list, String delimiter) {
* Converts a double value between 0 and 1 to 3dp-string.
*/
public static String toDecimalFormatString(double doubleVal) {
DecimalFormat df = new DecimalFormat("0.###");
DecimalFormatSymbols syms = new DecimalFormatSymbols();
syms.setDecimalSeparator('.');
DecimalFormat df = new DecimalFormat("0.###", syms);
return df.format(doubleVal);
}

Expand Down
5 changes: 4 additions & 1 deletion src/main/java/teammates/common/util/TimeHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import java.time.ZonedDateTime;
import java.time.format.DateTimeFormatter;
import java.time.format.DateTimeParseException;
import java.util.Locale;

/**
* A helper class to hold time-related functions (e.g., converting dates to strings etc.).
Expand Down Expand Up @@ -105,7 +106,9 @@ public static String formatInstant(Instant instant, String timeZone, String patt
if (zonedDateTime.getHour() == 12 && zonedDateTime.getMinute() == 0) {
processedPattern = pattern.replace("a", "'NOON'");
}
DateTimeFormatter formatter = DateTimeFormatter.ofPattern(processedPattern);
DateTimeFormatter formatter = DateTimeFormatter
.ofPattern(processedPattern)
.withLocale(Locale.US);
return zonedDateTime.format(formatter);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public void testIsInstructorCommentsOnResponsesAllowed_shouldReturnTrue() {
}

@Test
public void tesValidateResponseDetails() {
public void testValidateResponseDetails() {
FeedbackNumericalScaleQuestionDetails numScaleQuestion = new FeedbackNumericalScaleQuestionDetails();
numScaleQuestion.setStep(0.1);

Expand Down
112 changes: 112 additions & 0 deletions src/test/java/teammates/sqlui/webapi/DeleteNotificationActionTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
package teammates.sqlui.webapi;

import static org.mockito.Mockito.reset;
import static org.mockito.Mockito.when;

import java.time.Instant;
import java.util.UUID;

import org.testng.annotations.Test;

import teammates.common.datatransfer.NotificationStyle;
import teammates.common.datatransfer.NotificationTargetUser;
import teammates.common.util.Const;
import teammates.storage.sqlentity.Notification;
import teammates.ui.output.MessageOutput;
import teammates.ui.webapi.DeleteNotificationAction;

/**
* SUT: {@link DeleteNotificationAction}.
*/
public class DeleteNotificationActionTest extends BaseActionTest<DeleteNotificationAction> {
private static final String GOOGLE_ID = "user-googleId";

@Override
String getActionUri() {
return Const.ResourceURIs.NOTIFICATION;
}

@Override
String getRequestMethod() {
return DELETE;
}

@Test
void testSpecificAccessControl_admin_canAccess() {
loginAsAdmin();
verifyCanAccess();
}

@Test
void testSpecificAccessControl_instructor_cannotAccess() {
loginAsInstructor(GOOGLE_ID);
verifyCannotAccess();
}

@Test
void testSpecificAccessControl_student_cannotAccess() {
loginAsStudent(GOOGLE_ID);
verifyCannotAccess();
}

@Test
void testSpecificAccessControl_loggedOut_cannotAccess() {
logoutUser();
verifyCannotAccess();
}

@Test
void testExecute_notificationExists_success() {
Notification testNotification = new Notification(
Instant.now(),
Instant.ofEpochMilli(Instant.now().toEpochMilli() + 10000),
NotificationStyle.INFO,
NotificationTargetUser.GENERAL,
"title",
"message");

when(mockLogic.getNotification(testNotification.getId())).thenReturn(testNotification);

String[] params = {
Const.ParamsNames.NOTIFICATION_ID, testNotification.getId().toString(),
};

DeleteNotificationAction action = getAction(params);
MessageOutput actionOutput = (MessageOutput) getJsonResult(action).getOutput();

assertEquals("Notification has been deleted.", actionOutput.getMessage());
reset(mockLogic);
}

@Test
void testExecute_notificationDoesNotExist_failSilently() {
UUID invalidUuid = UUID.randomUUID();
when(mockLogic.getNotification(invalidUuid)).thenReturn(null);

String[] params = {
Const.ParamsNames.NOTIFICATION_ID, invalidUuid.toString(),
};

DeleteNotificationAction action = getAction(params);
MessageOutput actionOutput = (MessageOutput) getJsonResult(action).getOutput();

assertEquals("Notification has been deleted.", actionOutput.getMessage());
reset(mockLogic);
}

@Test
void testExecute_missingNotificationUuid_throwsInvalidHttpParameterException() {
String[] params = {
Const.ParamsNames.NOTIFICATION_ID, null,
};

verifyHttpParameterFailure(params);
}

@Test
void testExecute_missingParameters_throwsInvalidHttpParameterException() {
String[] params = {};

verifyHttpParameterFailure(params);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -118,15 +118,79 @@ export class InstructorRequestFormComponent {
// Country Mapping
const countryMapping: { [key: string]: string } = {
'united states': 'USA',
'u.s.a': 'USA',
'u.s.a.': 'USA',
us: 'USA',
america: 'USA',
uk: 'United Kingdom',
deutschland: 'Germany',
'united states of america': 'USA',

'united kingdom': 'UK',
uk: 'UK',
britain: 'UK',
'great britain': 'UK',
england: 'UK',

'united arab emirates': 'UAE',
uae: 'UAE',
emirates: 'UAE',

deutschland: 'Germany',
germany: 'Germany',

netherlands: 'Netherlands',
'the netherlands': 'Netherlands',
nederland: 'Netherlands',
holland: 'Netherlands',

belgium: 'Belgium',
belgië: 'Belgium',

brazil: 'Brazil',
brasil: 'Brazil',

spain: 'Spain',
españa: 'Spain',

mexico: 'Mexico',
méxico: 'Mexico',
belgië: 'Belgium',
holland: 'Netherlands',

italy: 'Italy',
italia: 'Italy',

china: 'China',
'peoples republic of china': 'China',
prc: 'China',

france: 'France',
'republic of france': 'France',

india: 'India',

japan: 'Japan',

russia: 'Russia',
'russian federation': 'Russia',

'south korea': 'South Korea',
'republic of korea': 'South Korea',
korea: 'South Korea',

'north korea': 'North Korea',
'democratic peoples republic of korea': 'North Korea',

'south africa': 'South Africa',
'republic of south africa': 'South Africa',

switzerland: 'Switzerland',

turkey: 'Turkey',
'republic of turkey': 'Turkey',
'republic of türkiye': 'Turkey',

vietnam: 'Vietnam',
'viet nam': 'Vietnam',

malaysia: 'Malaysia',
};
// Combine country and institution
const country = this.country.value!.trim();
Expand Down

0 comments on commit 70c9927

Please sign in to comment.