Skip to content

Commit

Permalink
Merge pull request #112 from MeasureAuthoringTool/MAT-4169_UMLSLogout
Browse files Browse the repository at this point in the history
Mat 4169 umls logout
  • Loading branch information
sb-cecilialiu authored Dec 13, 2024
2 parents 850a59e + 7878d7e commit acb5c61
Show file tree
Hide file tree
Showing 3 changed files with 74 additions and 20 deletions.
44 changes: 24 additions & 20 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

28 changes: 28 additions & 0 deletions src/api/useTerminologyServiceApi.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -103,4 +103,32 @@ describe("useTerminologyServiceApi", () => {
expect(mockedAxios.post).toBeCalledTimes(1);
expect(result).toContain("failure");
});

it("Log out UMLS success", async () => {
const resp = { status: 200, data: true };
mockedAxios.delete.mockResolvedValue(resp);
const terminlogyService: TerminologyServiceApi = useTerminologyServiceApi();
await terminlogyService.logoutUMLS();
expect(mockedAxios.delete).toBeCalledTimes(1);
});

it("Log out UMLS failure", async () => {
const resp = { status: 404, data: false, error: { message: "error" } };
mockedAxios.delete.mockRejectedValueOnce(resp);
const terminlogyService: TerminologyServiceApi = useTerminologyServiceApi();
try {
const loggedout = await terminlogyService.logoutUMLS();
expect(mockedAxios.delete).toBeCalledTimes(1);
expect(loggedout).toBeFalsy();
} catch {}
});

it("Log out UMLS returns false if status is not 200", async () => {
const resp = { status: 201, data: true };
mockedAxios.delete.mockResolvedValue(resp);
const terminlogyService: TerminologyServiceApi = useTerminologyServiceApi();
const loggedout = await terminlogyService.logoutUMLS();
expect(mockedAxios.delete).toBeCalledTimes(1);
expect(loggedout).toBeFalsy();
});
});
22 changes: 22 additions & 0 deletions src/api/useTerminologyServiceApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,28 @@ export class TerminologyServiceApi {
});
return "failure";
}

async logoutUMLS(): Promise<Boolean> {
const baseUrl = await getServiceUrl();
const resp = await axios
.delete(`${baseUrl}/vsac/umls-credentials`, {
headers: {
Authorization: `Bearer ${this.getAccessToken()}`,
"Content-Type": "text/plain",
},
timeout: 15000,
})
.then((resp) => {
// Check response status and return true if successful
return resp.status === 200;
})
.catch((error) => {
// Log the error or handle it as needed
console.error("UMLS Logout failed:", error);
throw error;
});
return false;
}
}

export const getServiceUrl = async () => {
Expand Down

0 comments on commit acb5c61

Please sign in to comment.