Skip to content

Commit

Permalink
Add testcase for GetTimeZonesActionTest (#13244)
Browse files Browse the repository at this point in the history
Co-authored-by: domoberzin <[email protected]>
  • Loading branch information
InfinityTwo and domoberzin authored Mar 1, 2025
1 parent ca4f178 commit efd2eaf
Show file tree
Hide file tree
Showing 2 changed files with 84 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/main/java/teammates/ui/webapi/GetTimeZonesAction.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
/**
* Action: get supported time zones.
*/
class GetTimeZonesAction extends Action {
public class GetTimeZonesAction extends Action {

@Override
AuthType getMinAuthLevel() {
Expand Down
83 changes: 83 additions & 0 deletions src/test/java/teammates/sqlui/webapi/GetTimeZonesActionTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
package teammates.sqlui.webapi;

import org.testng.annotations.Test;

import teammates.common.util.Const;
import teammates.ui.output.TimeZonesData;
import teammates.ui.webapi.GetTimeZonesAction;
import teammates.ui.webapi.JsonResult;

/**
* SUT: {@link GetTimeZonesAction}.
*/
public class GetTimeZonesActionTest extends BaseActionTest<GetTimeZonesAction> {

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

@Override
protected String getRequestMethod() {
return GET;
}

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

@Test
void testAccessControl_maintainers_canAccess() {
loginAsMaintainer();
verifyCanAccess();
}

@Test
void testAccessControl_instructor_cannotAccess() {
loginAsInstructor(Const.ParamsNames.INSTRUCTOR_ID);
verifyCannotAccess();
}

@Test
void testAccessControl_student_cannotAccess() {
loginAsStudent(Const.ParamsNames.STUDENT_ID);
verifyCannotAccess();
}

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

@Test
void testAccessControl_unregistered_cannotAccess() {
loginAsUnregistered(Const.ParamsNames.USER_ID);
verifyCannotAccess();
}

@Test
protected void testExecute_normalCase_shouldSucceed() {
GetTimeZonesAction a = getAction();
JsonResult r = getJsonResult(a);

TimeZonesData output = (TimeZonesData) r.getOutput();

// This test does not check the timezone database used is the latest
// Only check that the version number is returned, and some sample values for timezone offset
assertNotNull(output.getVersion());

// There is a quirk in the ETC/GMT time zones due to the tzdb using POSIX-style signs in the zone names and the
// output abbreviations. POSIX has positive signs west of Greenwich, while we are used to positive signs east
// of Greenwich in practice. For example, TZ='Etc/GMT+8' uses the abbreviation "GMT+8" and corresponds to 8
// hours behind UTC (i.e. west of Greenwich) even though many people would expect it to mean 8 hours ahead of
// UTC (i.e. east of Greenwich; like Singapore or China).
// (adapted from tzdb table comments)
assertEquals(8 * 60 * 60, output.getOffsets().get("Etc/GMT-8").intValue());
assertEquals(-5 * 60 * 60, output.getOffsets().get("Etc/GMT+5").intValue());
assertEquals(11 * 60 * 60, output.getOffsets().get("Etc/GMT-11").intValue());
assertEquals(0, output.getOffsets().get("Etc/GMT+0").intValue());
}
}

0 comments on commit efd2eaf

Please sign in to comment.