Skip to content

Commit

Permalink
add tests for GWT place from url utility, and improve logic
Browse files Browse the repository at this point in the history
  • Loading branch information
jay-hodgson committed May 16, 2024
1 parent 70f4181 commit 6e3f4f0
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 2 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
"markdown-it-strikethrough-alt": "^1.0.0",
"markdown-it-sub": "^2.0.0",
"markdown-it-sup": "^2.0.0",
"markdown-it-synapse": "^1.1.14",
"markdown-it-synapse": "^1.1.15",
"markdown-it-synapse-heading": "^1.0.1",
"markdown-it-synapse-table": "^1.0.6",
"moment": "^2.29.4",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,10 @@ public static String toTitleCase(String s) {
return output.toString();
}

public static String getGWTPlaceTokenFromURL(String url) {
public static String getGWTPlaceTokenFromURL(String inputUrl) {
String placeToken = null;
// remove the protocol if provided
String url = inputUrl.replaceFirst("^https?://", "");
if (url.contains(":")) {
// optimization - use place changer in this case as well
int colonIndex = url.lastIndexOf(':');
Expand Down
39 changes: 39 additions & 0 deletions src/test/java/org/sagebionetworks/web/client/StringUtilsTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -91,4 +91,43 @@ public void testToTitleCase() {
assertEquals("Hello World", StringUtils.toTitleCase("hello world"));
assertEquals("Hello World", StringUtils.toTitleCase("heLLo WORLD"));
}

@Test
public void testGetGWTPlaceTokenFromURL() {
assertNull(
StringUtils.getGWTPlaceTokenFromURL(
"https://does.not.contain.gwt/place/test/file.txt?anywhere=true"
)
);
//real cases
assertEquals(
"Team:3472002",
StringUtils.getGWTPlaceTokenFromURL(
"https://www.synapse.org/Team:3472002"
)
);
assertEquals(
"Profile:1131050/projects/all",
StringUtils.getGWTPlaceTokenFromURL(
"https://www.synapse.org/Profile:1131050/projects/all"
)
);
assertEquals(
"Synapse:syn5585645/discussion/threadId=50&replyId=16175",
StringUtils.getGWTPlaceTokenFromURL(
"https://www.synapse.org/Synapse:syn5585645/discussion/threadId=50&replyId=16175"
)
);
assertEquals(
"DataAccessManagement:default/Submissions?accessRequirementId=4988775",
StringUtils.getGWTPlaceTokenFromURL(
"https://www.synapse.org/DataAccessManagement:default/Submissions?accessRequirementId=4988775"
)
);
//relative href
assertEquals(
"Team:3472002",
StringUtils.getGWTPlaceTokenFromURL("/Team:3472002")
);
}
}

0 comments on commit 6e3f4f0

Please sign in to comment.