Skip to content

Commit

Permalink
updated the return type for updateSyncDest
Browse files Browse the repository at this point in the history
  • Loading branch information
RuiChen12 committed Sep 27, 2024
1 parent 49da78f commit ef5cf8f
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 41 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -569,33 +569,22 @@ public ResponseEntity<String> updateDescription(
return httpRequestService.makeApiRequestWithBody(currentUid, uri, description, HttpMethod.PUT);
}

/**
* Allow an owner of a Grouping to enable that a Grouping connected to a given sync destination.
*/
@PostMapping(value = "/groupings/{path}/syncDests/{syncDestId}/enable")
public ResponseEntity<String> enableSyncDest(
@PathVariable String path,
@PathVariable String syncDestId) {
logger.info("Entered REST enableSyncDest...");
String currentUid = policy.sanitize(userContextService.getCurrentUid());
String safeGrouping = policy.sanitize(path);
String safeSyncDestId = policy.sanitize(syncDestId);
return changeSyncDest(safeGrouping, currentUid, safeSyncDestId, true);
}

/**
* This allows an owner of a Grouping to disable that a Grouping connected to a given sync
* This allows an owner of a Grouping to enable/disable that a Grouping connected to a given sync
* destination.
*/
@PostMapping(value = "/groupings/{path}/syncDests/{syncDestId}/disable")
public ResponseEntity<String> disableSyncDest(
@PostMapping(value = "/groupings/{path}/syncDests/{syncDestId}/{status:true|false}")
public ResponseEntity<String> updateSyncDest(
@PathVariable String path,
@PathVariable String syncDestId) {
logger.info("Entered REST disableSyncDest...");
@PathVariable String syncDestId,
@PathVariable boolean status) {
logger.info("Entered REST updateSyncDest...");
String currentUid = policy.sanitize(userContextService.getCurrentUid());
String safeGrouping = policy.sanitize(path);
String safeSyncDestId = policy.sanitize(syncDestId);
return changeSyncDest(safeGrouping, currentUid, safeSyncDestId, false);
String uri = String.format(API_2_1_BASE + "/groupings/%s/sync-destination/%s/%s", safeGrouping, safeSyncDestId, status);
return httpRequestService.makeApiRequest(currentUid, uri, HttpMethod.PUT);
}

/**
Expand Down Expand Up @@ -708,15 +697,6 @@ private ResponseEntity<String> changePreference(String grouping, String uhIdenti
return httpRequestService.makeApiRequest(uhIdentifier, uri, HttpMethod.PUT);
}

private ResponseEntity<String> changeSyncDest(String grouping, String uhIdentifier, String syncDest, Boolean isOn) {
String ending = "disable";
if (isOn) {
ending = "enable";
}
String uri = String.format(API_2_1_BASE + "/groupings/%s/sync-destination/%s/%s", grouping, syncDest, ending);
return httpRequestService.makeApiRequest(uhIdentifier, uri, HttpMethod.PUT);
}

protected Boolean shouldDoApiHandshake() {
if (!API_HANDSHAKE_ENABLED) {
logger.info("API handshake disabled.");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1604,7 +1604,7 @@
$scope.updateSingleSyncDest = (syncDestName) => {
const groupingPath = $scope.selectedGrouping.path;
const syncDestOn = $scope.getSyncDestValueInArray(syncDestName);
groupingsService.setSyncDest(groupingPath, syncDestName, syncDestOn, handleSuccessfulPreferenceToggle, handleUnsuccessfulRequest);
groupingsService.updateSyncDest(groupingPath, syncDestName, syncDestOn, handleSuccessfulPreferenceToggle, handleUnsuccessfulRequest);
};

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -391,9 +391,8 @@
/**
* Toggle the given sync destination.
*/
setSyncDest(path, syncDestId, turnOn, onSuccess, onError) {
let endpoint = BASE_URL + "groupings/" + path + "/syncDests/" + syncDestId;
endpoint = (turnOn) ? endpoint.concat("/enable") : endpoint.concat("/disable");
updateSyncDest(path, syncDestId, turnOn, onSuccess, onError) {
let endpoint = `${BASE_URL}groupings/${path}/syncDests/${syncDestId}/${turnOn}`;
dataProvider.updateData(endpoint, onSuccess, onError);
},

Expand Down
6 changes: 3 additions & 3 deletions src/test/javascript/grouping.controller.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -2508,11 +2508,11 @@ describe("GroupingController", () => {
};
});

it("should call the setSyncDest", () => {
spyOn(gs, "setSyncDest");
it("should call the updateSyncDest", () => {
spyOn(gs, "updateSyncDest");
scope.syncDestArray.push(testSync);
scope.updateSingleSyncDest(testSync.name);
expect(gs.setSyncDest).toHaveBeenCalled();
expect(gs.updateSyncDest).toHaveBeenCalled();
});

it("should call getSyncDestValueInArray", () => {
Expand Down
12 changes: 6 additions & 6 deletions src/test/javascript/groupings.service.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -574,24 +574,24 @@ describe("GroupingsService", () => {
});
});

describe("setSyncDest", () => {
describe("updateSyncDest", () => {
let syncDestId;
let turnOn;
it("should call dataProvider.updateData", () => {
spyOn(dp, "updateData");
gs.setSyncDest(groupingPath, syncDestId, turnOn, onSuccess, onError);
gs.updateSyncDest(groupingPath, syncDestId, turnOn, onSuccess, onError);
expect(dp.updateData).toHaveBeenCalled();
});

it("should use the correct path for enable", () => {
gs.setSyncDest(groupingPath, syncDestId, true, onSuccess, onError);
httpBackend.expectPOST(BASE_URL + "groupings/" + groupingPath + "/syncDests/" + syncDestId + "/enable").respond(200);
gs.updateSyncDest(groupingPath, syncDestId, true, onSuccess, onError);
httpBackend.expectPOST(BASE_URL + "groupings/" + groupingPath + "/syncDests/" + syncDestId + "/true").respond(200);
expect(httpBackend.flush).not.toThrow();
});

it("should use the correct path for disable", () => {
gs.setSyncDest(groupingPath, syncDestId, false, onSuccess, onError);
httpBackend.expectPOST(BASE_URL + "groupings/" + groupingPath + "/syncDests/" + syncDestId + "/disable").respond(200);
gs.updateSyncDest(groupingPath, syncDestId, false, onSuccess, onError);
httpBackend.expectPOST(BASE_URL + "groupings/" + groupingPath + "/syncDests/" + syncDestId + "/false").respond(200);
expect(httpBackend.flush).not.toThrow();
});
});
Expand Down

0 comments on commit ef5cf8f

Please sign in to comment.