Skip to content

Commit

Permalink
Refactored isBaseUrlPlaceholder into two functions.
Browse files Browse the repository at this point in the history
  • Loading branch information
aryaei2000 committed Dec 12, 2024
1 parent 3bbe7c2 commit 14fc855
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 13 deletions.
33 changes: 25 additions & 8 deletions platform/src/ToolsManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,19 @@ class ToolManager {

let toolUrl = new Object();
toolUrl.id = ""; // Populate when tool is fetched
if (this.isUrlPlaceHolder(url)){
if(this.isIDPlaceHolder(url)){
// url is in the form of {{ID-...}}, no modification needed
toolUrl.url = url;
}
else if (this.isBaseUrlPlaceHolder(url)){
// the url variable is a placeholder, so it needs to be re-written with the correct path
let url_tail = url.split('/')[1];
var url_tail = '';
let url_port = this.getPort(url);

if(url.indexOf('/') > 0){
url_tail = url.split('/')[1];
}

if (url_port != null){
let path = this.fetchPathByPort(url_port);

Expand Down Expand Up @@ -63,7 +72,6 @@ class ToolManager {
this.configErrors = this.configErrors.concat( this.fetchTools() );
this.registerToolFunctions();
this.createClassesFromConfig();

}
}

Expand Down Expand Up @@ -110,14 +118,23 @@ class ToolManager {
}

/**
* Checks whether a string is a url placeholder in the form of {{BASE-URL}} or {{ID-***}} or not
* Checks whether a string is a url placeholder in the form of {{BASE-URL}} or not
* @returns bool
*/
isUrlPlaceHolder(urlPlaceholder) {
isBaseUrlPlaceHolder(urlPlaceholder) {
return (urlPlaceholder.startsWith('{{BASE-URL}}') ||
urlPlaceholder.indexOf('{{BASE-URL}}') >= 0 ||
urlPlaceholder.startsWith('{{ID-')
)
urlPlaceholder.indexOf('{{BASE-URL}}') >= 0
)
}

/**
* Checks whether a string is an ID placeholder in the form of {{ID-***}} or not
* @return bool
*/
isIDPlaceHolder(IDPlaceholder) {
return (IDPlaceholder.startsWith('{{ID-') ||
IDPlaceholder.indexOf('{{ID-') >= 0
)
}

/**
Expand Down
24 changes: 19 additions & 5 deletions platform/test/spec/testToolManagerSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -112,18 +112,32 @@ describe("ToolManager", () => {
expect(tm.isValidUrl(url)).toBe(false)
})

it("isUrlPlaceHolder - check if a string is a url placeholder", () => {
it("isBaseUrlPlaceHolder - check if a string is a url placeholder", () => {
var url = "{{BASE-URL}}"
expect(tm.isUrlPlaceHolder(url)).toBe(true)
expect(tm.isBaseUrlPlaceHolder(url)).toBe(true)

var url = "{{BASE-URL}}:123"
expect(tm.isUrlPlaceHolder(url)).toBe(true)
expect(tm.isBaseUrlPlaceHolder(url)).toBe(true)

var url = "{{ID-panel-turtles}}"
expect(tm.isUrlPlaceHolder(url)).toBe(true)
expect(tm.isBaseUrlPlaceHolder(url)).toBe(false)

var url = "http://127.0.0.1/"
expect(tm.isUrlPlaceHolder(url)).toBe(false)
expect(tm.isBaseUrlPlaceHolder(url)).toBe(false)
})

it("isIDPlaceHolder - check if a string is an ID placeholder", () => {
var placeholder = "{{ID-panel-turtles}}"
expect(tm.isIDPlaceHolder(placeholder)).toBe(true)

var placeholder = "{{ID-panel-turtles}}:123"
expect(tm.isIDPlaceHolder(placeholder)).toBe(true)

var placeholder = "http://127.0.0.1/"
expect(tm.isIDPlaceHolder(placeholder)).toBe(false)

var placeholder = "{{BASE-URL}}"
expect(tm.isIDPlaceHolder(placeholder)).toBe(false)
})

it("parses and stores the tool configuration", () => {
Expand Down

0 comments on commit 14fc855

Please sign in to comment.