Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Mat 4169 umls logout #112

Merged
merged 5 commits into from
Dec 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading