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

(refactor) Refactor requests to REST endpoints to use restBaseUrl #2072

Merged
merged 1 commit into from
Oct 22, 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
4 changes: 2 additions & 2 deletions packages/esm-patient-banner-app/src/hooks/useCauseOfDeath.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { useMemo } from 'react';
import useSWR from 'swr';
import { openmrsFetch } from '@openmrs/esm-framework';
import { openmrsFetch, restBaseUrl } from '@openmrs/esm-framework';

interface CauseOfDeathResponse {
data: {
Expand All @@ -13,7 +13,7 @@ interface CauseOfDeathResponse {

export function useCauseOfDeath(patientUuid: string) {
const customRepresentation = 'custom:(causeOfDeath:(display),causeOfDeathNonCoded)';
const url = `/ws/rest/v1/person/${patientUuid}?v=${customRepresentation}`;
const url = `${restBaseUrl}/person/${patientUuid}?v=${customRepresentation}`;

const { data, error } = useSWR<CauseOfDeathResponse, Error>(patientUuid ? url : null, openmrsFetch);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ const visitAttributeTypeCustomRepresentation =

export function useVisitAttributeTypes() {
const { data, error, isLoading } = useSWRImmutable<FetchResponse<{ results: VisitAttributeType[] }>, Error>(
`/ws/rest/v1/visitattributetype?v=${visitAttributeTypeCustomRepresentation}`,
`${restBaseUrl}/visitattributetype?v=${visitAttributeTypeCustomRepresentation}`,
openmrsFetch,
);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import userEvent from '@testing-library/user-event';
import {
getDefaultsFromConfigSchema,
openmrsFetch,
restBaseUrl,
saveVisit,
showSnackbar,
updateVisit,
Expand Down Expand Up @@ -347,13 +348,13 @@ describe('Visit form', () => {
expect.any(Object),
);

expect(mockOpenmrsFetch).toHaveBeenCalledWith(`/ws/rest/v1/visit/${visitUuid}/attribute`, {
expect(mockOpenmrsFetch).toHaveBeenCalledWith(`${restBaseUrl}/visit/${visitUuid}/attribute`, {
method: 'POST',
headers: { 'Content-type': 'application/json' },
body: { attributeType: visitAttributes.punctuality.uuid, value: '66cdc0a1-aa19-4676-af51-80f66d78d9eb' },
});

expect(mockOpenmrsFetch).toHaveBeenCalledWith(`/ws/rest/v1/visit/${visitUuid}/attribute`, {
expect(mockOpenmrsFetch).toHaveBeenCalledWith(`${restBaseUrl}/visit/${visitUuid}/attribute`, {
method: 'POST',
headers: { 'Content-type': 'application/json' },
body: { attributeType: visitAttributes.insurancePolicyNumber.uuid, value: '183299' },
Expand Down Expand Up @@ -417,7 +418,7 @@ describe('Visit form', () => {
);

expect(mockOpenmrsFetch).toHaveBeenCalledWith(
`/ws/rest/v1/visit/${visitUuid}/attribute/c98e66d7-7db5-47ae-b46f-91a0f3b6dda1`,
`${restBaseUrl}/visit/${visitUuid}/attribute/c98e66d7-7db5-47ae-b46f-91a0f3b6dda1`,
{
method: 'POST',
headers: { 'Content-type': 'application/json' },
Expand All @@ -426,7 +427,7 @@ describe('Visit form', () => {
);

expect(mockOpenmrsFetch).toHaveBeenCalledWith(
`/ws/rest/v1/visit/${visitUuid}/attribute/d6d7d26a-5975-4f03-8abb-db073c948897`,
`${restBaseUrl}/visit/${visitUuid}/attribute/d6d7d26a-5975-4f03-8abb-db073c948897`,
{
method: 'POST',
headers: { 'Content-type': 'application/json' },
Expand Down Expand Up @@ -490,12 +491,12 @@ describe('Visit form', () => {
);

expect(mockOpenmrsFetch).toHaveBeenCalledWith(
`/ws/rest/v1/visit/${visitUuid}/attribute/c98e66d7-7db5-47ae-b46f-91a0f3b6dda1`,
`${restBaseUrl}/visit/${visitUuid}/attribute/c98e66d7-7db5-47ae-b46f-91a0f3b6dda1`,
{ method: 'DELETE' },
);

expect(mockOpenmrsFetch).toHaveBeenCalledWith(
`/ws/rest/v1/visit/${visitUuid}/attribute/d6d7d26a-5975-4f03-8abb-db073c948897`,
`${restBaseUrl}/visit/${visitUuid}/attribute/d6d7d26a-5975-4f03-8abb-db073c948897`,
{ method: 'DELETE' },
);

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { useEffect, useRef, useState } from 'react';
import useSWRImmutable from 'swr/immutable';
import { renderHook, waitFor } from '@testing-library/react';
import { getDefaultsFromConfigSchema, openmrsFetch, useConfig } from '@openmrs/esm-framework';
import { getDefaultsFromConfigSchema, openmrsFetch, restBaseUrl, useConfig } from '@openmrs/esm-framework';
import { type ConfigObject, configSchema } from '../../config-schema';
import { useTestTypes } from './useTestTypes';

Expand Down Expand Up @@ -43,7 +43,7 @@ describe('useTestTypes is configurable', () => {
it('should return all test concepts when no labOrderableConcepts are provided', async () => {
const { result } = renderHook(() => useTestTypes());
expect(mockOpenrsFetch).toHaveBeenCalledWith(
'/ws/rest/v1/concept?class=Test?v=custom:(display,names:(display),uuid,setMembers:(display,uuid,names:(display),setMembers:(display,uuid,names:(display))))',
`${restBaseUrl}/concept?class=Test?v=custom:(display,names:(display),uuid,setMembers:(display,uuid,names:(display),setMembers:(display,uuid,names:(display))))`,
);
await waitFor(() => expect(result.current.isLoading).toBeFalsy());
expect(result.current.error).toBeFalsy();
Expand All @@ -54,7 +54,7 @@ describe('useTestTypes is configurable', () => {
const { result } = renderHook(() => useTestTypes());
expect(mockOpenrsFetch).toHaveBeenCalledWith(
expect.stringContaining(
'/ws/rest/v1/concept?class=Test?v=custom:(display,names:(display),uuid,setMembers:(display,uuid,names:(display),setMembers:(display,uuid,names:(display))))',
`${restBaseUrl}/concept?class=Test?v=custom:(display,names:(display),uuid,setMembers:(display,uuid,names:(display),setMembers:(display,uuid,names:(display))))`,
),
);
await waitFor(() => expect(result.current.isLoading).toBeFalsy());
Expand Down