Skip to content

Commit

Permalink
Merge branch 'develop' into MAT-7939_removeFlags
Browse files Browse the repository at this point in the history
  • Loading branch information
sb-cecilialiu authored Dec 13, 2024
2 parents 30b551f + acb5c61 commit 627d53f
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 627d53f

Please sign in to comment.